From 4dc601c8459ead46e04b5c5a82c1108ba4ba6a3e Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 10 Nov 2007 06:00:23 +0000 Subject: [PATCH] System tray updates. --- deluge/config.py | 1 + deluge/ui/client.py | 14 ++ deluge/ui/gtkui/connectionmanager.py | 15 ++ deluge/ui/gtkui/glade/dgtkpopups.glade | 6 +- .../ui/gtkui/glade/preferences_dialog.glade | 228 +++++++++--------- deluge/ui/gtkui/glade/tray_menu.glade | 13 +- deluge/ui/gtkui/systemtray.py | 54 ++++- deluge/ui/gtkui/toolbar.py | 1 + 8 files changed, 201 insertions(+), 131 deletions(-) diff --git a/deluge/config.py b/deluge/config.py index c9b0ed893..6bfcf408e 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -35,6 +35,7 @@ import cPickle +import gobject import deluge.common from deluge.log import LOG as log diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 9b2cb393a..329a995b2 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -194,6 +194,20 @@ def pause_torrent(torrent_ids): except (AttributeError, socket.error): set_core_uri(None) +def pause_all_torrents(): + """Pauses all torrents""" + try: + get_core().pause_all_torrents() + except (AttributeError, socket.error): + set_core_uri(None) + +def resume_all_torrents(): + """Resumes all torrents""" + try: + get_core().resume_all_torrents() + except (AttributeError, socket.error): + set_core_uri(None) + def resume_torrent(torrent_ids): """Resume torrent_ids""" try: diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index f586e993b..780e05bf8 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -127,6 +127,9 @@ class ConnectionManager(component.Component): uri[7:].split(":")[0] == "127.0.0.1": # This is a localhost, so lets try to start it port = uri[7:].split(":")[1] + # First add it to the list + self.add_host("localhost", port) + os.popen("deluged -p %s" % port) # We need to wait for the host to start before connecting while not self.test_online_status(uri): @@ -328,6 +331,18 @@ class ConnectionManager(component.Component): # Get the port and concatenate the hostname string hostname = hostname + ":" + str(port) + + # Check to see if there is already an entry for this host and return + # if thats the case + self.hosts_liststore = [] + def each_row(model, path, iter, data): + self.hosts_liststore.append( + model.get_value(iter, HOSTLIST_COL_URI)) + self.liststore.foreach(each_row, None) + if hostname in self.hosts_liststore: + return + + # Host isn't in the list, so lets add it row = self.liststore.append() self.liststore.set_value(row, HOSTLIST_COL_URI, hostname) # Save the host list to file diff --git a/deluge/ui/gtkui/glade/dgtkpopups.glade b/deluge/ui/gtkui/glade/dgtkpopups.glade index cdb19036d..1022651f5 100644 --- a/deluge/ui/gtkui/glade/dgtkpopups.glade +++ b/deluge/ui/gtkui/glade/dgtkpopups.glade @@ -1,6 +1,6 @@ - + Remove Torrent @@ -239,10 +239,12 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 5 Speed - GTK_WIN_POS_CENTER + GTK_WIN_POS_MOUSE + True GDK_WINDOW_TYPE_HINT_NORMAL True True + False False diff --git a/deluge/ui/gtkui/glade/preferences_dialog.glade b/deluge/ui/gtkui/glade/preferences_dialog.glade index b745de87d..c3025ac0e 100644 --- a/deluge/ui/gtkui/glade/preferences_dialog.glade +++ b/deluge/ui/gtkui/glade/preferences_dialog.glade @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -640,8 +640,8 @@ True True - µTorrent Peer-Exchange - µTorrent-PeX + Peer Exchange + Peer Exchange True 0 True @@ -883,71 +883,40 @@ Either 2 15 - + True - The maximum upload speed for all torrents. Set -1 for unlimited. - 0 - Maximum Upload Speed (KiB/s): - - - 2 - 3 - GTK_FILL - - - - - True - The maximum number of connections allowed. Set -1 for unlimited. - 0 - Maximum Connections: - - - GTK_FILL - - - - - True - The maximum upload speed for all torrents. Set -1 for unlimited. - 0 - Maximum Upload Slots: + True + The maximum upload slots for all torrents. Set -1 for unlimited. + 1 + -1 -1 9000 1 10 10 + 1 + True + True + 1 + 2 3 4 GTK_FILL - + True True - The maximum number of connections allowed. Set -1 for unlimited. - 4 + The maximum upload speed for all torrents. Set -1 for unlimited. 1 -1 -1 9000 1 10 10 1 - True + 1 True - GTK_UPDATE_IF_VALID 1 2 - GTK_FILL - - - - - True - The maximum download speed for all torrents. Set -1 for unlimited. - 0 - Maximum Download Speed (KiB/s): - - - 1 - 2 + 2 + 3 GTK_FILL @@ -972,43 +941,74 @@ Either - + True - True - The maximum upload speed for all torrents. Set -1 for unlimited. - 1 - -1 -1 9000 1 10 10 - 1 - 1 - True + The maximum download speed for all torrents. Set -1 for unlimited. + 0 + Maximum Download Speed (KiB/s): - 1 - 2 - 2 - 3 + 1 + 2 GTK_FILL - + True True - The maximum upload slots for all torrents. Set -1 for unlimited. + The maximum number of connections allowed. Set -1 for unlimited. + 4 1 -1 -1 9000 1 10 10 1 True True + GTK_UPDATE_IF_VALID 1 2 + GTK_FILL + + + + + True + The maximum upload speed for all torrents. Set -1 for unlimited. + 0 + Maximum Upload Slots: + + 3 4 GTK_FILL + + + True + The maximum number of connections allowed. Set -1 for unlimited. + 0 + Maximum Connections: + + + GTK_FILL + + + + + True + The maximum upload speed for all torrents. Set -1 for unlimited. + 0 + Maximum Upload Speed (KiB/s): + + + 2 + 3 + GTK_FILL + + @@ -1052,29 +1052,24 @@ Either 2 15 - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Maximum Upload Slots: + True + The maximum upload slots per torrent. Set -1 for unlimited. + 1 + -1 -1 9000 1 10 10 + 1 + True + True + 1 + 2 1 2 GTK_FILL - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Maximum Connections: - - - GTK_FILL - - True @@ -1092,19 +1087,24 @@ Either - + True - True - The maximum upload slots per torrent. Set -1 for unlimited. - 1 - -1 -1 9000 1 10 10 - 1 - True - True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + Maximum Connections: + + + GTK_FILL + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + Maximum Upload Slots: - 1 - 2 1 2 GTK_FILL @@ -1356,15 +1356,33 @@ Either 2 10 - + True - False True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Open folder with: + 0 + True + True + + + + GTK_FILL + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Custom: + 0 + True + True + radio_open_folder_stock + - 1 - 2 1 2 GTK_FILL @@ -1394,38 +1412,20 @@ Thunar - + True + False True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Custom: - 0 - True - True - radio_open_folder_stock - + 1 + 2 1 2 GTK_FILL - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Open folder with: - 0 - True - True - - - - GTK_FILL - - diff --git a/deluge/ui/gtkui/glade/tray_menu.glade b/deluge/ui/gtkui/glade/tray_menu.glade index d54b82ca2..eaca5a191 100644 --- a/deluge/ui/gtkui/glade/tray_menu.glade +++ b/deluge/ui/gtkui/glade/tray_menu.glade @@ -17,7 +17,6 @@ True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -38,9 +37,8 @@ - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -80,7 +78,6 @@ True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -118,11 +115,10 @@ 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 & Shutdown Daemon @@ -138,6 +134,11 @@ + + + True + + True diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index 8edeabfa8..0159bfea4 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -45,13 +45,26 @@ class SystemTray(component.Component): component.Component.__init__(self, "SystemTray") self.window = component.get("MainWindow") self.config = ConfigManager("gtkui.conf") + # List of widgets that need to be hidden when not connected to a host + self.hide_widget_list = [ + "menuitem_add_torrent", + "menuitem_pause_all", + "menuitem_resume_all", + "menuitem_download_limit", + "menuitem_upload_limit", + "menuitem_quitdaemon", + "separatormenuitem1", + "separatormenuitem2", + "separatormenuitem3", + "separatormenuitem4" + ] self.config.register_set_function("enable_system_tray", self.on_enable_system_tray_set) def enable(self): """Enables the system tray icon.""" log.debug("Enabling the system tray icon..") - self.tray = gtk.status_icon_new_from_icon_name('deluge') + self.tray = gtk.status_icon_new_from_icon_name("deluge") self.tray.connect("activate", self.on_tray_clicked) self.tray.connect("popup-menu", self.on_tray_popup) @@ -73,18 +86,37 @@ class SystemTray(component.Component): self.on_menuitem_quitdaemon_activate }) - self.tray_menu = self.tray_glade.get_widget("tray_menu") + self.tray_menu = self.tray_glade.get_widget("tray_menu") self.tray_glade.get_widget("download-limit-image").set_from_file( deluge.common.get_pixmap("downloading16.png")) self.tray_glade.get_widget("upload-limit-image").set_from_file( deluge.common.get_pixmap("seeding16.png")) + # Hide widgets now because we're not sure if we'll be connected to a + # host + for widget in self.hide_widget_list: + self.tray_glade.get_widget(widget).hide() + def start(self): log.debug("SystemTray start..") - # Build the bandwidth speed limit menus - self.build_tray_bwsetsubmenu() - + # Show widgets in the hide list because we've connected to a host + for widget in self.hide_widget_list: + self.tray_glade.get_widget(widget).show() + + if self.config["enable_system_tray"]: + # Build the bandwidth speed limit menus + self.build_tray_bwsetsubmenu() + + def stop(self): + log.debug("SystemTray stop..") + try: + # Hide widgets in hide list because we're not connected to a host + for widget in self.hide_widget_list: + self.tray_glade.get_widget(widget).hide() + except Exception, e: + log.debug("Unable to hide system tray menu widgets: %s", e) + def build_tray_bwsetsubmenu(self): # Create the Download speed list sub-menu submenu_bwdownset = self.build_menu_radio_list( @@ -111,10 +143,14 @@ class SystemTray(component.Component): def disable(self): """Disables the system tray icon.""" log.debug("Disabling the system tray icon..") - self.tray.set_visible(False) - del self.tray - del self.tray_glade - del self.tray_menu + try: + self.tray.set_visible(False) + del self.tray + del self.tray_glade + del self.tray_menu + except Exception, e: + log.warning( + "Unable to disable system tray, probably wasn't enabled: %s", e) def on_enable_system_tray_set(self, key, value): """Called whenever the 'enable_system_tray' config key is modified""" diff --git a/deluge/ui/gtkui/toolbar.py b/deluge/ui/gtkui/toolbar.py index a4f4bb716..8d083dedc 100644 --- a/deluge/ui/gtkui/toolbar.py +++ b/deluge/ui/gtkui/toolbar.py @@ -73,6 +73,7 @@ class ToolBar(component.Component): def start(self): for widget in self.change_sensitivity: self.window.main_glade.get_widget(widget).set_sensitive(True) + self.update_buttons() gobject.idle_add(self.update_buttons) def stop(self):