mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-10 02:18:41 +00:00
Fix last commit.
Use 'config_value_changed' signal from core to get config value updates instead of polling every update for StatusBar and SystemTray.
This commit is contained in:
parent
f0b6833d17
commit
80514ad829
8 changed files with 77 additions and 19 deletions
|
@ -48,6 +48,7 @@ class Config:
|
||||||
self.config = {}
|
self.config = {}
|
||||||
self.previous_config = {}
|
self.previous_config = {}
|
||||||
self.set_functions = {}
|
self.set_functions = {}
|
||||||
|
self._change_callback = None
|
||||||
|
|
||||||
# If defaults is not None then we need to use "defaults".
|
# If defaults is not None then we need to use "defaults".
|
||||||
if defaults != None:
|
if defaults != None:
|
||||||
|
@ -121,9 +122,13 @@ class Config:
|
||||||
self.config[key] = value
|
self.config[key] = value
|
||||||
# Run the set_function for this key if any
|
# Run the set_function for this key if any
|
||||||
try:
|
try:
|
||||||
self.set_functions[key](key, value)
|
gobject.idle_add(self.set_functions[key], key, value)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
gobject.idle_add(self._change_callback, key, value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
"""Get the value of 'key'. If it is an invalid key then get() will
|
"""Get the value of 'key'. If it is an invalid key then get() will
|
||||||
|
@ -146,6 +151,10 @@ class Config:
|
||||||
"""Returns the config prior to the last set()"""
|
"""Returns the config prior to the last set()"""
|
||||||
return self.previous_config
|
return self.previous_config
|
||||||
|
|
||||||
|
def register_change_callback(self, callback):
|
||||||
|
"""Registers a callback that will be called when a value is changed"""
|
||||||
|
self._change_callback = callback
|
||||||
|
|
||||||
def register_set_function(self, key, function, apply_now=True):
|
def register_set_function(self, key, function, apply_now=True):
|
||||||
"""Register a function to be run when a config value changes."""
|
"""Register a function to be run when a config value changes."""
|
||||||
log.debug("Registering function for %s key..", key)
|
log.debug("Registering function for %s key..", key)
|
||||||
|
|
|
@ -223,6 +223,7 @@ class Core(
|
||||||
self.config.register_set_function("max_upload_slots_global",
|
self.config.register_set_function("max_upload_slots_global",
|
||||||
self._on_set_max_upload_slots_global)
|
self._on_set_max_upload_slots_global)
|
||||||
|
|
||||||
|
self.config.register_change_callback(self._on_config_value_change)
|
||||||
# Start the AlertManager
|
# Start the AlertManager
|
||||||
self.alerts = AlertManager(self.session)
|
self.alerts = AlertManager(self.session)
|
||||||
|
|
||||||
|
@ -500,7 +501,15 @@ class Core(
|
||||||
log.debug("torrent_all_resumed signal emitted")
|
log.debug("torrent_all_resumed signal emitted")
|
||||||
self.signals.emit("torrent_all_resumed", torrent_id)
|
self.signals.emit("torrent_all_resumed", torrent_id)
|
||||||
|
|
||||||
|
def config_value_changed(self, key, value):
|
||||||
|
"""Emitted when a config value has changed"""
|
||||||
|
log.debug("config_value_changed signal emitted")
|
||||||
|
self.signals.emit("config_value_changed", key, value)
|
||||||
|
|
||||||
# Config set functions
|
# Config set functions
|
||||||
|
def _on_config_value_change(self, key, value):
|
||||||
|
self.config_value_changed(key, value)
|
||||||
|
|
||||||
def _on_set_torrentfiles_location(self, key, value):
|
def _on_set_torrentfiles_location(self, key, value):
|
||||||
try:
|
try:
|
||||||
old = self.config.get_previous_config()["torrentfiles_location"]
|
old = self.config.get_previous_config()["torrentfiles_location"]
|
||||||
|
|
|
@ -61,13 +61,13 @@ class SignalManager(component.Component):
|
||||||
log.debug("Registering %s as a signal reciever..", uri)
|
log.debug("Registering %s as a signal reciever..", uri)
|
||||||
self.clients[uri] = xmlrpclib.ServerProxy(uri)
|
self.clients[uri] = xmlrpclib.ServerProxy(uri)
|
||||||
|
|
||||||
def emit(self, signal, data):
|
def emit(self, signal, *data):
|
||||||
for client in self.clients.values():
|
for client in self.clients.values():
|
||||||
gobject.idle_add(self._emit, client, signal, data)
|
gobject.idle_add(self._emit, client, signal, *data)
|
||||||
|
|
||||||
def _emit(self, client, signal, data):
|
def _emit(self, client, signal, *data):
|
||||||
try:
|
try:
|
||||||
client.emit_signal(signal, data)
|
client.emit_signal(signal, *data)
|
||||||
except (socket.error, Exception), e:
|
except (socket.error, Exception), e:
|
||||||
log.warning("Unable to emit signal to client %s: %s", client, e)
|
log.warning("Unable to emit signal to client %s: %s", client, e)
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ class Signals(component.Component):
|
||||||
self.torrent_all_paused)
|
self.torrent_all_paused)
|
||||||
self.receiver.connect_to_signal("torrent_all_resumed",
|
self.receiver.connect_to_signal("torrent_all_resumed",
|
||||||
self.torrent_all_resumed)
|
self.torrent_all_resumed)
|
||||||
|
self.receiver.connect_to_signal("config_value_changed",
|
||||||
|
self.config_value_changed)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.receiver.shutdown()
|
self.receiver.shutdown()
|
||||||
|
@ -95,3 +97,7 @@ class Signals(component.Component):
|
||||||
component.get("TorrentView").update()
|
component.get("TorrentView").update()
|
||||||
component.get("ToolBar").update_buttons("resumed")
|
component.get("ToolBar").update_buttons("resumed")
|
||||||
|
|
||||||
|
def config_value_changed(self, key, value):
|
||||||
|
log.debug("config_value_changed signal received..")
|
||||||
|
component.get("StatusBar").config_value_changed(key, value)
|
||||||
|
component.get("SystemTray").config_value_changed(key, value)
|
||||||
|
|
|
@ -105,6 +105,11 @@ class StatusBar(component.Component):
|
||||||
self.max_upload_speed = -1.0
|
self.max_upload_speed = -1.0
|
||||||
self.upload_rate = 0.0
|
self.upload_rate = 0.0
|
||||||
|
|
||||||
|
self.config_value_changed_dict = {
|
||||||
|
"max_connections_global": self._on_max_connections_global,
|
||||||
|
"max_download_speed": self._on_max_download_speed,
|
||||||
|
"max_upload_speed": self._on_max_upload_speed
|
||||||
|
}
|
||||||
# Add a HBox to the statusbar after removing the initial label widget
|
# Add a HBox to the statusbar after removing the initial label widget
|
||||||
self.hbox = gtk.HBox()
|
self.hbox = gtk.HBox()
|
||||||
self.hbox.set_spacing(5)
|
self.hbox.set_spacing(5)
|
||||||
|
@ -131,6 +136,14 @@ class StatusBar(component.Component):
|
||||||
self.hbox.pack_start(
|
self.hbox.pack_start(
|
||||||
self.upload_item.get_eventbox(), expand=False, fill=False)
|
self.upload_item.get_eventbox(), expand=False, fill=False)
|
||||||
|
|
||||||
|
# Get some config values
|
||||||
|
client.get_config_value(
|
||||||
|
self._on_max_connections_global, "max_connections_global")
|
||||||
|
client.get_config_value(
|
||||||
|
self._on_max_download_speed, "max_download_speed")
|
||||||
|
client.get_config_value(
|
||||||
|
self._on_max_upload_speed, "max_upload_speed")
|
||||||
|
|
||||||
self.send_status_request()
|
self.send_status_request()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@ -167,16 +180,17 @@ class StatusBar(component.Component):
|
||||||
|
|
||||||
def send_status_request(self):
|
def send_status_request(self):
|
||||||
# Sends an async request for data from the core
|
# Sends an async request for data from the core
|
||||||
client.get_config_value(
|
|
||||||
self._on_max_connections_global, "max_connections_global")
|
|
||||||
client.get_num_connections(self._on_get_num_connections)
|
client.get_num_connections(self._on_get_num_connections)
|
||||||
client.get_config_value(
|
|
||||||
self._on_max_download_speed, "max_download_speed")
|
|
||||||
client.get_download_rate(self._on_get_download_rate)
|
client.get_download_rate(self._on_get_download_rate)
|
||||||
client.get_config_value(
|
|
||||||
self._on_max_upload_speed, "max_upload_speed")
|
|
||||||
client.get_upload_rate(self._on_get_upload_rate)
|
client.get_upload_rate(self._on_get_upload_rate)
|
||||||
|
|
||||||
|
def config_value_changed(self, key, value):
|
||||||
|
"""This is called when we received a config_value_changed signal from
|
||||||
|
the core."""
|
||||||
|
|
||||||
|
if key in self.config_value_changed_dict.keys():
|
||||||
|
self.config_value_changed_dict[key](value)
|
||||||
|
|
||||||
def _on_max_connections_global(self, max_connections):
|
def _on_max_connections_global(self, max_connections):
|
||||||
self.max_connections = max_connections
|
self.max_connections = max_connections
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ class SystemTray(component.Component):
|
||||||
self.max_upload_speed = -1.0
|
self.max_upload_speed = -1.0
|
||||||
self.upload_rate = 0.0
|
self.upload_rate = 0.0
|
||||||
|
|
||||||
|
self.config_value_changed_dict = {
|
||||||
|
"max_download_speed": self._on_max_download_speed,
|
||||||
|
"max_upload_speed": self._on_max_upload_speed
|
||||||
|
}
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
"""Enables the system tray icon."""
|
"""Enables the system tray icon."""
|
||||||
log.debug("Enabling the system tray icon..")
|
log.debug("Enabling the system tray icon..")
|
||||||
|
@ -117,6 +122,11 @@ class SystemTray(component.Component):
|
||||||
# Build the bandwidth speed limit menus
|
# Build the bandwidth speed limit menus
|
||||||
self.build_tray_bwsetsubmenu()
|
self.build_tray_bwsetsubmenu()
|
||||||
|
|
||||||
|
# Get some config values
|
||||||
|
client.get_config_value(
|
||||||
|
self._on_max_download_speed, "max_download_speed")
|
||||||
|
client.get_config_value(
|
||||||
|
self._on_max_upload_speed, "max_upload_speed")
|
||||||
self.send_status_request()
|
self.send_status_request()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@ -128,13 +138,16 @@ class SystemTray(component.Component):
|
||||||
log.debug("Unable to hide system tray menu widgets: %s", e)
|
log.debug("Unable to hide system tray menu widgets: %s", e)
|
||||||
|
|
||||||
def send_status_request(self):
|
def send_status_request(self):
|
||||||
client.get_config_value(
|
|
||||||
self._on_max_download_speed, "max_download_speed")
|
|
||||||
client.get_download_rate(self._on_get_download_rate)
|
client.get_download_rate(self._on_get_download_rate)
|
||||||
client.get_config_value(
|
|
||||||
self._on_max_upload_speed, "max_upload_speed")
|
|
||||||
client.get_upload_rate(self._on_get_upload_rate)
|
client.get_upload_rate(self._on_get_upload_rate)
|
||||||
|
|
||||||
|
def config_value_changed(self, key, value):
|
||||||
|
"""This is called when we received a config_value_changed signal from
|
||||||
|
the core."""
|
||||||
|
|
||||||
|
if key in self.config_value_changed_dict.keys():
|
||||||
|
self.config_value_changed_dict[key](value)
|
||||||
|
|
||||||
def _on_max_download_speed(self, max_download_speed):
|
def _on_max_download_speed(self, max_download_speed):
|
||||||
if self.max_download_speed != max_download_speed:
|
if self.max_download_speed != max_download_speed:
|
||||||
self.max_download_speed = max_download_speed
|
self.max_download_speed = max_download_speed
|
||||||
|
@ -158,8 +171,12 @@ class SystemTray(component.Component):
|
||||||
|
|
||||||
if max_download_speed == -1:
|
if max_download_speed == -1:
|
||||||
max_download_speed = _("Unlimited")
|
max_download_speed = _("Unlimited")
|
||||||
|
else:
|
||||||
|
max_download_speed = "%s KiB/s" % (max_download_speed)
|
||||||
if max_upload_speed == -1:
|
if max_upload_speed == -1:
|
||||||
max_upload_speed = _("Unlimited")
|
max_upload_speed = _("Unlimited")
|
||||||
|
else:
|
||||||
|
max_upload_speed = "%s KiB/s" % (max_upload_speed)
|
||||||
|
|
||||||
msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (
|
msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (
|
||||||
_("Deluge Bittorrent Client"), _("Down Speed"),
|
_("Deluge Bittorrent Client"), _("Down Speed"),
|
||||||
|
|
|
@ -108,13 +108,13 @@ class SignalReceiver(
|
||||||
self._shutdown = False
|
self._shutdown = False
|
||||||
self.server_close()
|
self.server_close()
|
||||||
|
|
||||||
def emit_signal(self, signal, data):
|
def emit_signal(self, signal, *data):
|
||||||
"""Exported method used by the core to emit a signal to the client"""
|
"""Exported method used by the core to emit a signal to the client"""
|
||||||
try:
|
try:
|
||||||
if data != None:
|
if data != None:
|
||||||
for callback in self.signals[signal]:
|
for callback in self.signals[signal]:
|
||||||
try:
|
try:
|
||||||
gobject.idle_add(callback, data)
|
gobject.idle_add(callback, *data)
|
||||||
except:
|
except:
|
||||||
log.warning("Unable to call callback for signal %s",
|
log.warning("Unable to call callback for signal %s",
|
||||||
signal)
|
signal)
|
||||||
|
|
|
@ -989,6 +989,9 @@ class MultiCall:
|
||||||
|
|
||||||
return MultiCallIterator(self.__server.system.multicall(marshalled_list))
|
return MultiCallIterator(self.__server.system.multicall(marshalled_list))
|
||||||
|
|
||||||
|
def get_call_list(self):
|
||||||
|
return self.__call_list
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# convenience functions
|
# convenience functions
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue