From 67add964de95c8408ee9adff59e8dac191e23536 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 22 Mar 2011 17:16:03 -0700 Subject: [PATCH] Apply patch from #1581 to add an option to enable the app indicator interface --- .../ui/gtkui/glade/preferences_dialog.glade | 24 +++++++++++++-- deluge/ui/gtkui/gtkui.py | 1 + deluge/ui/gtkui/preferences.py | 5 ++++ deluge/ui/gtkui/systemtray.py | 29 ++++++++++++++----- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/deluge/ui/gtkui/glade/preferences_dialog.glade b/deluge/ui/gtkui/glade/preferences_dialog.glade index d4cdc6115..76c71ce58 100644 --- a/deluge/ui/gtkui/glade/preferences_dialog.glade +++ b/deluge/ui/gtkui/glade/preferences_dialog.glade @@ -2068,6 +2068,26 @@ Disabled 2 + + + True + 10 + + + Enable Application Indicator + True + False + False + False + True + True + + + + + 3 + + True @@ -2088,7 +2108,7 @@ Disabled False - 3 + 4 @@ -2131,7 +2151,7 @@ Disabled - 4 + 5 diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index 1609a2869..1efbda3ba 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -116,6 +116,7 @@ DEFAULT_PREFS = { "enable_system_tray": True, "close_to_tray": True, "start_in_tray": False, + "enable_appindicator": False, "lock_tray": False, "tray_password": "", "check_new_releases": True, diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index edc253e1b..a13937a2d 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -471,6 +471,8 @@ class Preferences(component.Component): self.gtkui_config["close_to_tray"]) self.glade.get_widget("chk_start_in_tray").set_active( self.gtkui_config["start_in_tray"]) + self.glade.get_widget("chk_enable_appindicator").set_active( + self.gtkui_config["enable_appindicator"]) self.glade.get_widget("chk_lock_tray").set_active( self.gtkui_config["lock_tray"]) self.glade.get_widget("chk_classic_mode").set_active( @@ -637,6 +639,8 @@ class Preferences(component.Component): self.glade.get_widget("chk_min_on_close").get_active() new_gtkui_config["start_in_tray"] = \ self.glade.get_widget("chk_start_in_tray").get_active() + new_gtkui_config["enable_appindicator"] = \ + self.glade.get_widget("chk_enable_appindicator").get_active() new_gtkui_config["lock_tray"] = \ self.glade.get_widget("chk_lock_tray").get_active() passhex = sha_hash(\ @@ -782,6 +786,7 @@ class Preferences(component.Component): "spin_outgoing_port_max": False}, "chk_use_tray": {"chk_min_on_close": True, "chk_start_in_tray": True, + "chk_enable_appindicator": True, "chk_lock_tray": True}, "chk_lock_tray": {"txt_tray_password": True, "password_label": True}, diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index c4bce4928..b465c5423 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -70,6 +70,10 @@ class SystemTray(component.Component): ] self.config.register_set_function("enable_system_tray", self.on_enable_system_tray_set) + # bit of a hack to prevent function from doing something on startup + self.__enabled_set_once = False + self.config.register_set_function("enable_appindicator", + self.on_enable_appindicator_set) self.max_download_speed = -1.0 self.download_rate = 0.0 @@ -103,7 +107,7 @@ class SystemTray(component.Component): self.tray_menu = self.tray_glade.get_widget("tray_menu") - if appindicator: + if appindicator and self.config["enable_appindicator"]: log.debug("Enabling the Application Indicator..") self.indicator = appindicator.Indicator ( "deluge", "deluge", appindicator.CATEGORY_APPLICATION_STATUS) @@ -162,7 +166,7 @@ class SystemTray(component.Component): # These do not work with appindicator currently and can crash Deluge. # Related to Launchpad bug #608219 - if appindicator: + if appindicator and self.config["enable_appindicator"]: self.hide_widget_list.remove("menuitem_download_limit") self.hide_widget_list.remove("menuitem_upload_limit") self.hide_widget_list.remove("separatormenuitem3") @@ -200,7 +204,7 @@ class SystemTray(component.Component): def shutdown(self): if self.config["enable_system_tray"]: - if appindicator: + if appindicator and self.config["enable_appindicator"]: self.indicator.set_status(appindicator.STATUS_PASSIVE) else: self.tray.set_visible(False) @@ -236,7 +240,7 @@ class SystemTray(component.Component): return # Tool tip text not available for appindicator - if appindicator: + if appindicator and self.config["enable_appindicator"]: return # Set the tool tip text @@ -285,13 +289,17 @@ class SystemTray(component.Component): submenu_bwupset.show_all() # Re-set the menu to partly work around Launchpad bug #608219 - if appindicator: + if appindicator and self.config["enable_appindicator"]: self.indicator.set_menu(self.tray_menu) - def disable(self): + def disable(self,invert_app_ind_conf=False): """Disables the system tray icon or appindicator.""" try: - if appindicator: + if invert_app_ind_conf: + app_ind_conf = not self.config["enable_appindicator"] + else: + app_ind_conf = self.config["enable_appindicator"] + if appindicator and app_ind_conf: if hasattr(self, "_sig_win_hide"): self.window.window.disconnect(self._sig_win_hide) self.window.window.disconnect(self._sig_win_show) @@ -323,6 +331,13 @@ class SystemTray(component.Component): else: self.disable() + def on_enable_appindicator_set(self, key, value): + """Called whenever the 'enable_appindicator' config key is modified""" + if self.__enabled_set_once: + self.disable(True) + self.enable() + self.__enabled_set_once = True + def on_tray_clicked(self, icon): """Called when the tray icon is left clicked.""" self.blink(False)