From 0779618917b0c55b34e8532f428c232944723614 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 2 Jul 2008 20:04:57 +0000 Subject: [PATCH] Remove DBUS dependency for Windows port --- deluge/ui/gtkui/dbusinterface.py | 37 ++------------------------------ deluge/ui/gtkui/gtkui.py | 17 ++++++--------- deluge/ui/gtkui/menubar.py | 2 +- deluge/ui/gtkui/signals.py | 8 +++++++ deluge/ui/signalreceiver.py | 6 +++++- 5 files changed, 23 insertions(+), 47 deletions(-) diff --git a/deluge/ui/gtkui/dbusinterface.py b/deluge/ui/gtkui/dbusinterface.py index e5e68f907..7ccc3b69b 100644 --- a/deluge/ui/gtkui/dbusinterface.py +++ b/deluge/ui/gtkui/dbusinterface.py @@ -34,8 +34,6 @@ import sys import os -import gtk -import gobject # Import DBUS import dbus, dbus.service @@ -46,15 +44,12 @@ elif dbus.version >= (0,80,0): DBusGMainLoop(set_as_default=True) import deluge.component as component -from deluge.ui.client import aclient as client import deluge.common -from deluge.configmanager import ConfigManager from deluge.log import LOG as log class DbusInterface(dbus.service.Object, component.Component): def __init__(self, args, path="/org/deluge_torrent/Deluge"): component.Component.__init__(self, "DbusInterface") - self.config = ConfigManager("gtkui.conf") # Check to see if the daemon is already running and if not, start it bus = dbus.SessionBus() obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") @@ -92,34 +87,6 @@ class DbusInterface(dbus.service.Object, component.Component): @dbus.service.method("org.deluge_torrent.Deluge", in_signature="as") def process_args(self, args): """Process arguments sent to already running Deluge""" - # Pythonize the values from Dbus - dbus_args = args - args = [] - for arg in dbus_args: - args.append(str(arg)) - 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 - - for arg in args: - if deluge.common.is_url(arg): - log.debug("Attempting to add %s from external source..", - arg) - if self.config["interactive_add"]: - component.get("AddTorrentDialog").add_from_url(arg) - component.get("AddTorrentDialog").show(self.config["focus_add_dialog"]) - else: - client.add_torrent_url(arg) - else: - # Just a file - log.debug("Attempting to add %s from external source..", - os.path.abspath(arg)) - if self.config["interactive_add"]: - component.get("AddTorrentDialog").add_from_files([os.path.abspath(arg)]) - component.get("AddTorrentDialog").show(self.config["focus_add_dialog"]) - else: - client.add_torrent_file([os.path.abspath(arg)]) + from ipcinterface import process_args + process_args(args) diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index dd808837d..a2338318d 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -57,10 +57,7 @@ from statusbar import StatusBar from connectionmanager import ConnectionManager from signals import Signals from pluginmanager import PluginManager -try: - from dbusinterface import DbusInterface -except Exception, e: - log.error("Unable to load DBUS component. This will limit functionality!") +from ipcinterface import IPCInterface from queuedtorrents import QueuedTorrents from addtorrentdialog import AddTorrentDialog @@ -98,7 +95,8 @@ DEFAULT_PREFS = { "autoadd_location": "", "choose_directory_dialog_path": deluge.common.get_default_download_dir(), "classic_mode": False, - "show_new_releases": True + "show_new_releases": True, + "signal_port": 40000 } class GtkUI: @@ -150,11 +148,9 @@ class GtkUI: # Start the Dbus Interface before anything else.. Just in case we are # already running. self.queuedtorrents = QueuedTorrents() - try: - self.dbusinterface = DbusInterface(args) - except Exception, e: - log.warning("Unable to start DBUS component. This will limit functionality!") - + + self.ipcinterface = IPCInterface(args) + # We make sure that the UI components start once we get a core URI client.connect_on_new_core(self._on_new_core) client.connect_on_no_core(self._on_no_core) @@ -205,6 +201,7 @@ class GtkUI: except: pass + def _on_new_core(self, data): component.start() diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index cdbce2573..0b38a5b7b 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -147,7 +147,7 @@ class MenuBar(component.Component): self.on_menuitem_remove_both_activate, "on_menuitem_recheck_activate": self.on_menuitem_recheck_activate, - "on_menuitem_open_folder": self.on_menuitem_open_folder_activate, + "on_menuitem_open_folder_activate": self.on_menuitem_open_folder_activate, "on_menuitem_move_activate": self.on_menuitem_move_activate, "on_menuitem_queue_top_activate": self.on_menuitem_queue_top_activate, "on_menuitem_queue_up_activate": self.on_menuitem_queue_up_activate, diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index e6cf7c2f3..db046f574 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -50,6 +50,7 @@ class Signals(component.Component): self.receiver.set_remote(True) self.receiver.run() + self.config["signal_port"] = self.receiver.get_port() self.receiver.connect_to_signal("torrent_added", self.torrent_added_signal) self.receiver.connect_to_signal("torrent_removed", @@ -69,6 +70,8 @@ class Signals(component.Component): self.torrent_resume_at_stop_ratio) self.receiver.connect_to_signal("new_version_available", self.new_version_available) + self.receiver.connect_to_signal("args_from_external", + self.args_from_external) def stop(self): try: @@ -135,4 +138,9 @@ class Signals(component.Component): if self.config["show_new_releases"]: from deluge.ui.gtkui.new_release_dialog import NewReleaseDialog NewReleaseDialog().show(value) + + def args_from_external(self, value): + log.debug("args_from_external: %s", value) + import ipcinterface + ipcinterface.process_args(value) diff --git a/deluge/ui/signalreceiver.py b/deluge/ui/signalreceiver.py index 3aab91b05..dce443077 100644 --- a/deluge/ui/signalreceiver.py +++ b/deluge/ui/signalreceiver.py @@ -125,7 +125,11 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): self._shutdown = False except Exception, e: log.debug("handle_thread: %s", e) - + + def get_port(self): + """Get the port that the SignalReceiver is listening on""" + return self.port + def emit_signal(self, signal, *data): """Exported method used by the core to emit a signal to the client""" self.emitted_signals.append((signal, data))