From 8f62df07323636eb2b75e9bfbf87eda769001216 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 22 Sep 2007 23:02:58 +0000 Subject: [PATCH] Inital import of SystemTray --- deluge/configmanager.py | 2 + deluge/core/core.py | 41 ++++++++++- deluge/core/torrentmanager.py | 25 ++++++- deluge/ui/functions.py | 8 +++ deluge/ui/gtkui/glade/dgtkpopups.glade | 97 +++----------------------- deluge/ui/gtkui/glade/tray_menu.glade | 92 ++++++++++-------------- deluge/ui/gtkui/gtkui.py | 4 +- deluge/ui/gtkui/mainwindow.py | 15 +++- deluge/ui/gtkui/signals.py | 19 ++++- 9 files changed, 158 insertions(+), 145 deletions(-) diff --git a/deluge/configmanager.py b/deluge/configmanager.py index cdb8081f7..163fcdc1f 100644 --- a/deluge/configmanager.py +++ b/deluge/configmanager.py @@ -58,6 +58,8 @@ class _ConfigManager: """Saves all the configs to disk.""" for key in self.config_files.keys(): self.config_files[key].save() + # We need to return True to keep the timer active + return True def get_config(self, config_file, defaults=None): """Get a reference to the Config object for this filename""" diff --git a/deluge/core/core.py b/deluge/core/core.py index 1201ff276..468379e29 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -224,7 +224,21 @@ class Core(dbus.service.Object): log.debug("Pausing torrent %s", torrent_id) if self.torrents.pause(torrent_id): self.torrent_paused(torrent_id) + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge") + def pause_all_torrents(self): + """Pause all torrents in the session""" + if self.torrents.pause_all(): + # Emit 'torrent_all_paused' signal + self.torrent_all_paused() + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge") + def resume_all_torrents(self): + """Resume all torrents in the session""" + if self.torrents.resume_all(): + # Emit the 'torrent_all_resumed' signal + self.torrent_all_resumed() + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="s", out_signature="") def resume_torrent(self, torrent_id): @@ -282,6 +296,19 @@ class Core(dbus.service.Object): config = pickle.dumps(config) return config + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", + in_signature="s", + out_signature="ay") + def get_config_value(self, key): + """Get the config value for key""" + try: + value = self.config[key] + except KeyError: + return None + + value = pickle.dumps(value) + return value + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="ay") def set_config(self, config): @@ -317,10 +344,22 @@ class Core(dbus.service.Object): def torrent_paused(self, torrent_id): """Emitted when a torrent is paused""" log.debug("torrent_paused signal emitted") - + + @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", + signature="s") def torrent_resumed(self, torrent_id): """Emitted when a torrent is resumed""" log.debug("torrent_resumed signal emitted") + + @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge") + def torrent_all_paused(self): + """Emitted when all torrents have been paused""" + log.debug("torrent_all_paused signal emitted") + + @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge") + def torrent_all_resumed(self): + """Emitted when all torrents have been resumed""" + log.debug("torrent_all_resumed signal emitted") # Config set functions def on_set_listen_ports(self, key, value): diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 9e7d0fb69..7a763f64e 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -187,6 +187,18 @@ class TorrentManager: return False return True + + def pause_all(self): + """Pauses all torrents.. Returns a list of torrents paused.""" + torrent_was_paused = False + for key in self.torrents.keys(): + try: + self.torrents[key].handle.pause() + torrent_was_paused = True + except: + log.warning("Unable to pause torrent %s", key) + + return torrent_was_paused def resume(self, torrent_id): """Resume a torrent""" @@ -197,6 +209,18 @@ class TorrentManager: return True + def resume_all(self): + """Resumes all torrents.. Returns a list of torrents resumed""" + torrent_was_resumed = False + for key in self.torrents.keys(): + try: + self.torrents[key].handle.resume() + torrent_was_resumed = True + except: + log.warning("Unable to resume torrent %s", key) + + return torrent_was_resumed + def force_reannounce(self, torrent_id): """Force a tracker reannounce""" try: @@ -206,7 +230,6 @@ class TorrentManager: return True - def load_state(self): """Load the state of the TorrentManager from the torrents.state file""" state = TorrentManagerState() diff --git a/deluge/ui/functions.py b/deluge/ui/functions.py index b05f29208..65f26b2e0 100644 --- a/deluge/ui/functions.py +++ b/deluge/ui/functions.py @@ -156,6 +156,14 @@ def get_config(core=None): config = pickle.loads(config) return config +def get_config_value(key, core=None): + if core is None: + core = get_core() + config = core.get_config_value(key) + config = "".join(chr(b) for b in config) + config = pickle.loads(config) + return config + def set_config(config, core=None): if config == {}: return diff --git a/deluge/ui/gtkui/glade/dgtkpopups.glade b/deluge/ui/gtkui/glade/dgtkpopups.glade index 63279d9a9..cdb19036d 100644 --- a/deluge/ui/gtkui/glade/dgtkpopups.glade +++ b/deluge/ui/gtkui/glade/dgtkpopups.glade @@ -1,86 +1,11 @@ - + - - True - - - True - Size - True - True - - - - - - True - Status - True - True - - - - - - True - Seeders - True - True - - - - - - True - Peers - True - True - - - - - - True - Download Speed - True - True - - - - - - True - Upload Speed - True - True - - - - - - True - Time Remaining - True - True - - - - - - True - Share Ratio - True - True - - - - Remove Torrent - True - GDK_WINDOW_TYPE_HINT_DIALOG + GTK_WIN_POS_CENTER + GDK_WINDOW_TYPE_HINT_NORMAL True True False @@ -309,14 +234,15 @@ - + + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 5 - GTK_WIN_POS_MOUSE - True - GDK_WINDOW_TYPE_HINT_DIALOG + Speed + GTK_WIN_POS_CENTER + GDK_WINDOW_TYPE_HINT_NORMAL True - False + True False @@ -329,17 +255,16 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 10 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Rate: False - + True True True diff --git a/deluge/ui/gtkui/glade/tray_menu.glade b/deluge/ui/gtkui/glade/tray_menu.glade index 22411c91d..6caae77ed 100644 --- a/deluge/ui/gtkui/glade/tray_menu.glade +++ b/deluge/ui/gtkui/glade/tray_menu.glade @@ -6,12 +6,12 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Show Deluge True - + @@ -21,12 +21,12 @@ - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Add Torrent True - + True @@ -38,17 +38,40 @@ - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Clear Finished + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Pause All True - + - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-clear + gtk-media-pause + 1 + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Resume All + True + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-media-play 1 @@ -61,17 +84,11 @@ - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Download Limit + _Download Speed Limit True - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - True @@ -83,10 +100,10 @@ - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Upload Limit + _Upload Speed Limit True @@ -105,45 +122,12 @@ - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-preferences - True - True - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Plu_gins - True - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-disconnect - 1 - - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Quit True - + True diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index d1783d1d7..bed11ca51 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -63,7 +63,9 @@ DEFAULT_PREFS = { "window_x_pos": 0, "window_y_pos": 0, "window_width": 640, - "window_height": 480 + "window_height": 480, + "tray_download_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0], + "tray_upload_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0] } class GtkUI: diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index 47913791d..1d1d4c931 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -43,6 +43,7 @@ from toolbar import ToolBar from torrentview import TorrentView from torrentdetails import TorrentDetails from preferences import Preferences +from systemtray import SystemTray import deluge.common from deluge.log import LOG as log @@ -74,6 +75,7 @@ class MainWindow: self.torrentview = TorrentView(self) self.torrentdetails = TorrentDetails(self) self.preferences = Preferences(self) + self.systemtray = SystemTray(self) gobject.timeout_add(1000, self.update) @@ -86,11 +88,22 @@ class MainWindow: return True def show(self): - self.window.show_all() + self.window.show() def hide(self): self.window.hide() + + def present(self): + self.window.present() + + 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 quit(self): del self.menubar del self.toolbar diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index ddcc0d551..3ae091c0c 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -42,7 +42,12 @@ class Signals: self.core.connect_to_signal("torrent_removed", self.torrent_removed_signal) self.core.connect_to_signal("torrent_paused", self.torrent_paused) - + self.core.connect_to_signal("torrent_resumed", self.torrent_resumed) + self.core.connect_to_signal("torrent_all_paused", + self.torrent_all_paused) + self.core.connect_to_signal("torrent_all_resumed", + self.torrent_all_resumed) + def torrent_added_signal(self, torrent_id): log.debug("torrent_added signal received..") log.debug("torrent id: %s", torrent_id) @@ -58,3 +63,15 @@ class Signals: def torrent_paused(self, torrent_id): log.debug("torrent_paused signal received..") self.ui.mainwindow.torrentview.update() + + def torrent_resumed(self, torrent_id): + log.debug("torrent_resumed signal received..") + self.ui.mainwindow.torrentview.update() + + def torrent_all_paused(self): + log.debug("torrent_all_paused signal received..") + self.ui.mainwindow.torrentview.update() + + def torrent_all_resumed(self): + log.debug("torrent_all_resumed signal received..") + self.ui.mainwindow.torrentview.update()