#! /usr/bin/python
# -*- coding=utf-8 -*-

"""
    This file is part of Torrent Search.
    
    Torrent Search is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Torrent Search is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from TorrentSearch import clp as optparse
from TorrentSearch import Application
from TorrentSearch.informations import *
from TorrentSearch.lang import _
from TorrentSearch.DBusHandler import *
import sys, os, tempfile
from TorrentSearch.constants import APPDATA_PATH

sys.stderr = open(tempfile.mktemp(), "w")

if __name__=='__main__':
   optparser=optparse.OptionParser()
   options,args=optparser.parse_args()
   if options.show_help:
      optparser.print_help()
      exit(0)
   if options.show_version:
      optparser.print_version()
      exit(0)
   if args:
      optparser.print_help()
      exit(1)
   bus=init_dbus()
   if not try_dbus_connection(bus, options.search_pattern):
      app=Application(options)
      open_dbus_controller(bus,app)
      app.run()
