# Path: deluge/ui/client.py
# RPC_RESPONSE = 1
# RPC_ERROR = 2
# RPC_EVENT = 3
# def format_kwargs(kwargs):
#     def __init__(self, method, args, kwargs, exception_type, exception_msg, traceback):
#     def __repr__(self):
#     def format_message(self):
#     def connectionMade(self):
#     def dataReceived(self, data):
#     def send_request(self, request):
#     def __init__(self, daemon, event_handlers):
#     def startedConnecting(self, connector):
#     def clientConnectionFailed(self, connector, reason):
#     def clientConnectionLost(self, connector, reason):
#     def __init__(self, event_handlers={}):
#     def connect(self, host, port, username, password):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def pop_deferred(self, request_id):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __rpcError(self, error_data):
#     def __on_connect(self, result, username, password):
#     def __on_connect_fail(self, reason):
#     def __on_login(self, result, username):
#     def __on_login_fail(self, result):
#     def set_disconnect_callback(self, cb):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
#     def __init__(self, event_handlers={}):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __init__(self, daemon, method):
#     def __call__(self, *args, **kwargs):
#     def __getattr__(self, name):
#     def __call__(self, *args, **kwargs):
#     def __init__(self):
#     def connect(self, host="127.0.0.1", port=58846, username="", password=""):
#         def on_connect_fail(result):
#     def disconnect(self):
#     def start_classic_mode(self):
#     def start_daemon(self, port, config):
#     def is_localhost(self):
#     def is_classicmode(self):
#     def connected(self):
#     def connection_info(self):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def force_call(self, block=False):
#     def __getattr__(self, method):
#     def set_disconnect_callback(self, cb):
#     def __on_disconnect(self):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
# class DelugeRPCError(object):
# class DelugeRPCRequest(object):
# class DelugeRPCProtocol(Protocol):
# class DelugeRPCClientFactory(ClientFactory):
# class DaemonProxy(object):
# class DaemonSSLProxy(DaemonProxy):
# class DaemonClassicProxy(DaemonProxy):
# class DottedObject(object):
# class RemoteMethod(DottedObject):
# class Client(object):
# 
# Path: deluge/ui/gtkui/ipcinterface.py
# def process_args(args):
#     """Process arguments sent to already running Deluge"""
#     # Make sure args is a list
#     args = list(args)
#     log.debug("Processing args from other process: %s", args)
#     if not client.connected():
#         # We're not connected so add these to the queue
#         log.debug("Not connected to host.. Adding to queue.")
#         component.get("QueuedTorrents").add_to_queue(args)
#         return
#     config = ConfigManager("gtkui.conf")
#     for arg in args:
#         if not arg:
#             continue
#         log.debug("arg: %s", arg)
#         if deluge.common.is_url(arg):
#             log.debug("Attempting to add %s from external source..",
#                 arg)
#             if config["interactive_add"]:
#                 component.get("AddTorrentDialog").add_from_url(arg)
#                 component.get("AddTorrentDialog").show(config["focus_add_dialog"])
#             else:
#                 client.core.add_torrent_url(arg, None)
#         elif deluge.common.is_magnet(arg):
#             log.debug("Attempting to add %s from external source..", arg)
#             if config["interactive_add"]:
#                 component.get("AddTorrentDialog").add_from_magnets([arg])
#                 component.get("AddTorrentDialog").show(config["focus_add_dialog"])
#             else:
#                 client.core.add_torrent_magnet(arg, {})
#         else:
#             # Just a file
#             log.debug("Attempting to add %s from external source..",
#                 os.path.abspath(arg))
#             if config["interactive_add"]:
#                 component.get("AddTorrentDialog").add_from_files([os.path.abspath(arg)])
#                 component.get("AddTorrentDialog").show(config["focus_add_dialog"])
#             else:
#                 path = os.path.abspath(arg)
#                 client.core.add_torrent_file(os.path.split(path)[-1], base64.encodestring(open(path, "rb").read()), None)


import pygtk
import gtk, gtk.glade
import gobject
import pkg_resources
import urllib
import deluge.component as component
import deluge.common
import common
from urlparse import urlparse
from deluge.ui.client import client
from deluge.configmanager import ConfigManager
from deluge.ui.gtkui.ipcinterface import process_args
from twisted.internet import reactor
from deluge.log import LOG as log
            from deluge.ui.gtkui.new_release_dialog import NewReleaseDialog
        from deluge.ui.gtkui.notification import Notification
        try:
            component.resume("TorrentView")
            component.resume("StatusBar")
            component.resume("TorrentDetails")
        except:
            pass

        self.window.present()
        self.load_window_state()

    def active(self):
        """Returns True if the window is active, False if not."""
        return self.window.is_active()

    def visible(self):
        """Returns True if window is visible, False if not."""
        return self.window.get_property("visible")

    def get_glade(self):
        """Returns a reference to the main window glade object."""
        return self.main_glade

    def quit(self, shutdown=False):
        """
        Quits the GtkUI

        :param shutdown: whether or not to shutdown the daemon as well
        :type shutdown: boolean
        """
        if shutdown:

# Path: deluge/ui/client.py
# RPC_RESPONSE = 1
# RPC_ERROR = 2
# RPC_EVENT = 3
# def format_kwargs(kwargs):
#     def __init__(self, method, args, kwargs, exception_type, exception_msg, traceback):
#     def __repr__(self):
#     def format_message(self):
#     def connectionMade(self):
#     def dataReceived(self, data):
#     def send_request(self, request):
#     def __init__(self, daemon, event_handlers):
#     def startedConnecting(self, connector):
#     def clientConnectionFailed(self, connector, reason):
#     def clientConnectionLost(self, connector, reason):
#     def __init__(self, event_handlers={}):
#     def connect(self, host, port, username, password):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def pop_deferred(self, request_id):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __rpcError(self, error_data):
#     def __on_connect(self, result, username, password):
#     def __on_connect_fail(self, reason):
#     def __on_login(self, result, username):
#     def __on_login_fail(self, result):
#     def set_disconnect_callback(self, cb):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
#     def __init__(self, event_handlers={}):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __init__(self, daemon, method):
#     def __call__(self, *args, **kwargs):
#     def __getattr__(self, name):
#     def __call__(self, *args, **kwargs):
#     def __init__(self):
#     def connect(self, host="127.0.0.1", port=58846, username="", password=""):
#         def on_connect_fail(result):
#     def disconnect(self):
#     def start_classic_mode(self):
#     def start_daemon(self, port, config):
#     def is_localhost(self):
#     def is_classicmode(self):
#     def connected(self):
#     def connection_info(self):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def force_call(self, block=False):
#     def __getattr__(self, method):
#     def set_disconnect_callback(self, cb):
#     def __on_disconnect(self):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
# class DelugeRPCError(object):
# class DelugeRPCRequest(object):
# class DelugeRPCProtocol(Protocol):
# class DelugeRPCClientFactory(ClientFactory):
# class DaemonProxy(object):
# class DaemonSSLProxy(DaemonProxy):
# class DaemonClassicProxy(DaemonProxy):
# class DottedObject(object):
# class RemoteMethod(DottedObject):
# class Client(object):
# 
# Path: deluge/ui/gtkui/ipcinterface.py
# def process_args(args):
#     """Process arguments sent to already running Deluge"""
#     # Make sure args is a list
#     args = list(args)
#     log.debug("Processing args from other process: %s", args)
#     if not client.connected():
#         # We're not connected so add these to the queue
#         log.debug("Not connected to host.. Adding to queue.")
#         component.get("QueuedTorrents").add_to_queue(args)
#         return
#     config = ConfigManager("gtkui.conf")
#     for arg in args:
#         if not arg:
#             continue
#         log.debug("arg: %s", arg)
#         if deluge.common.is_url(arg):
#             log.debug("Attempting to add %s from external source..",
#                 arg)
#             if config["interactive_add"]:
#                 component.get("AddTorrentDialog").add_from_url(arg)
#                 component.get("AddTorrentDialog").show(config["focus_add_dialog"])
#             else:
#                 client.core.add_torrent_url(arg, None)
#         elif deluge.common.is_magnet(arg):
#             log.debug("Attempting to add %s from external source..", arg)
#             if config["interactive_add"]:
#                 component.get("AddTorrentDialog").add_from_magnets([arg])
#                 component.get("AddTorrentDialog").show(config["focus_add_dialog"])
#             else:
#                 client.core.add_torrent_magnet(arg, {})
#         else:
#             # Just a file
#             log.debug("Attempting to add %s from external source..",
#                 os.path.abspath(arg))
#             if config["interactive_add"]:
#                 component.get("AddTorrentDialog").add_from_files([os.path.abspath(arg)])
#                 component.get("AddTorrentDialog").show(config["focus_add_dialog"])
#             else:
#                 path = os.path.abspath(arg)
#                 client.core.add_torrent_file(os.path.split(path)[-1], base64.encodestring(open(path, "rb").read()), None)


# Path: deluge/ui/gtkui/mainwindow.py
import pygtk
import gtk, gtk.glade
import gobject
import pkg_resources
import urllib
import deluge.component as component
import deluge.common
import common
from urlparse import urlparse
from deluge.ui.client import client
from deluge.configmanager import ConfigManager
from deluge.ui.gtkui.ipcinterface import process_args
from twisted.internet import reactor
from deluge.log import LOG as log
            from deluge.ui.gtkui.new_release_dialog import NewReleaseDialog
        from deluge.ui.gtkui.notification import Notification

        try:
            component.resume("TorrentView")
            component.resume("StatusBar")
            component.resume("TorrentDetails")
        except:
            pass

        self.window.present()
        self.load_window_state()

    def active(self):
        """Returns True if the window is active, False if not."""
        return self.window.is_active()

    def visible(self):
        """Returns True if window is visible, False if not."""
        return self.window.get_property("visible")

    def get_glade(self):
        """Returns a reference to the main window glade object."""
        return self.main_glade

    def quit(self, shutdown=False):
        """
        Quits the GtkUI

        :param shutdown: whether or not to shutdown the daemon as well
        :type shutdown: boolean
        """
        if shutdown:

            client.daemon.shutdown()