diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index 4be953391..bd5101295 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -430,6 +430,8 @@ class ConnectionManager(component.Component): uri = "http://" + uri if status == HOSTLIST_STATUS.index("Connected"): + # Stop all the components first. + component.stop() # If we are connected to this host, then we will disconnect. client.set_core_uri(None) self._update() diff --git a/deluge/ui/gtkui/removetorrentdialog.py b/deluge/ui/gtkui/removetorrentdialog.py index 8e8b88917..8f2555585 100644 --- a/deluge/ui/gtkui/removetorrentdialog.py +++ b/deluge/ui/gtkui/removetorrentdialog.py @@ -79,10 +79,10 @@ class RemoveTorrentDialog: self.dialog.show() def on_button_ok_clicked(self, widget): - #data = self.glade.get_widget("chk_data").get_active() - #torrent = self.glade.get_widget("chk_torrents").get_active() client.remove_torrent( self.torrent_ids, self.remove_torrentfile, self.remove_data) + # Unselect all to avoid issues with the selection changed event + component.get("TorrentView").treeview.get_selection().unselect_all() self.dialog.destroy() def on_button_cancel_clicked(self, widget): diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index ede2dccf8..0c06d14c9 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -87,24 +87,27 @@ class Signals(component.Component): log.debug("torrent id: %s", torrent_id) # Remove the torrent from the treeview component.get("TorrentView").remove_row(torrent_id) - component.get("TorrentDetails").clear() def torrent_paused(self, torrent_id): log.debug("torrent_paused signal received..") component.get("TorrentView").update() + component.get("ToolBar").update_buttons() def torrent_resumed(self, torrent_id): log.debug("torrent_resumed signal received..") component.get("TorrentView").update() - + component.get("ToolBar").update_buttons() + def torrent_all_paused(self): log.debug("torrent_all_paused signal received..") component.get("TorrentView").update() - + component.get("ToolBar").update_buttons() + def torrent_all_resumed(self): log.debug("torrent_all_resumed signal received..") component.get("TorrentView").update() - + component.get("ToolBar").update_buttons() + def config_value_changed(self, key, value): log.debug("config_value_changed signal received..") component.get("StatusBar").config_value_changed(key, value) diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 62ffcc667..47d3c2911 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -38,9 +38,6 @@ pygtk.require('2.0') import gtk, gtk.glade import gettext import gobject -import cPickle as pickle -import time -import traceback import deluge.common import deluge.component as component @@ -357,14 +354,13 @@ class TorrentView(listview.ListView, component.Component): def remove_row(self, torrent_id): """Removes a row with torrent_id""" for row in self.liststore: - # Check if this row is the row we want to remove if row[0] == torrent_id: self.liststore.remove(row.iter) # Force an update of the torrentview self.update() self.update_filter() break - + def get_selected_torrent(self): """Returns a torrent_id or None. If multiple torrents are selected, it will return the torrent_id of the first one.""" @@ -433,4 +429,3 @@ class TorrentView(listview.ListView, component.Component): component.get("TorrentDetails").update() component.get("ToolBar").update_buttons() - diff --git a/deluge/ui/signalreceiver.py b/deluge/ui/signalreceiver.py index 910057e0e..610ece94a 100644 --- a/deluge/ui/signalreceiver.py +++ b/deluge/ui/signalreceiver.py @@ -42,22 +42,22 @@ import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer from SocketServer import ThreadingMixIn import deluge.xmlrpclib as xmlrpclib import threading +import socket from deluge.log import LOG as log -class SignalReceiver( - ThreadingMixIn, - SimpleXMLRPCServer.SimpleXMLRPCServer): +class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): def __init__(self): log.debug("SignalReceiver init..") - gobject.threads_init() + # gobject.threads_init() # Set to true so that the receiver thread will exit self._shutdown = False self.signals = {} - + self.emitted_signals = [] + self.remote = False @@ -68,19 +68,13 @@ class SignalReceiver( try: client.deregister_client() client.force_call() - except: - pass + except Exception, e: + log.debug("Unable to deregister client from server: %s", e) + log.debug("Shutting down signalreceiver") - # Hacky.. sends a request to our local receiver to ensure that it - # shutdowns.. This is because handle_request() is a blocking call. - receiver = xmlrpclib.ServerProxy("http://localhost:" + str(self.port), - allow_none=True) - try: - receiver.emit_signal("shutdown", None) - except: - # We don't care about errors at this point - pass + self.socket.shutdown(socket.SHUT_RDWR) + return def set_remote(self, remote): self.remote = remote @@ -114,6 +108,9 @@ class SignalReceiver( client.register_client(str(self.port)) t = threading.Thread(target=self.handle_thread) + + gobject.timeout_add(50, self.handle_signals) + try: t.start() except Exception, e: @@ -129,23 +126,20 @@ class SignalReceiver( def emit_signal(self, signal, *data): """Exported method used by the core to emit a signal to the client""" - try: - if data != None: + self.emitted_signals.append((signal, data)) + return + + def handle_signals(self): + for signal, data in self.emitted_signals: + try: for callback in self.signals[signal]: - try: - gobject.idle_add(callback, *data) - except: - log.warning("Unable to call callback for signal %s", - signal) - else: - for callback in self.signals[signal]: - try: - gobject.idle_add(callback) - except: - log.warning("Unable to call callback for signal %s", - signal) - except KeyError: - log.debug("There are no callbacks registered for signal '%s'", signal) + gobject.idle_add(callback, *data) + + except Exception, e: + log.warning("Unable to call callback for signal %s: %s", signal, e) + + self.emitted_signals = [] + return True def connect_to_signal(self, signal, callback): """Connect to a signal""" @@ -154,5 +148,4 @@ class SignalReceiver( self.signals[signal].append(callback) except KeyError: self.signals[signal] = [callback] -