--- deluge-1.3.0.orig/deluge/ui/gtkui/systemtray.py 2010-09-18 19:31:31.000000000 +0100 +++ deluge-1.3.0/deluge/ui/gtkui/systemtray.py 2010-11-19 13:21:33.000000000 +0000 @@ -33,6 +33,10 @@ # # +try: + import appindicator +except: + appindicator = None import gtk import pkg_resources @@ -77,23 +81,31 @@ def enable(self): """Enables the system tray icon.""" - log.debug("Enabling the system tray icon..") + if appindicator: + log.debug("Enabling the Application Indicator..") + else: + log.debug("Enabling the system tray icon..") self.tray_glade = gtk.glade.XML( pkg_resources.resource_filename("deluge.ui.gtkui", "glade/tray_menu.glade")) - if deluge.common.windows_check() or deluge.common.osx_check(): - self.tray = gtk.status_icon_new_from_pixbuf( - common.get_logo(32)) + if appindicator: + self.indicator = appindicator.Indicator ("deluge", + "deluge", + appindicator.CATEGORY_APPLICATION_STATUS) else: - try: - self.tray = gtk.status_icon_new_from_icon_name("deluge") - except: - log.warning("Update PyGTK to 2.10 or greater for SystemTray..") - return + if deluge.common.windows_check() or deluge.common.osx_check(): + self.tray = gtk.status_icon_new_from_pixbuf( + common.get_logo(32)) + else: + try: + self.tray = gtk.status_icon_new_from_icon_name("deluge") + except: + log.warning("Update PyGTK to 2.10 or greater for SystemTray..") + return - self.tray.connect("activate", self.on_tray_clicked) - self.tray.connect("popup-menu", self.on_tray_popup) + self.tray.connect("activate", self.on_tray_clicked) + self.tray.connect("popup-menu", self.on_tray_popup) self.tray_glade.signal_autoconnect({ @@ -123,6 +135,26 @@ for widget in self.hide_widget_list: self.tray_glade.get_widget(widget).hide() + if appindicator: + # Pass the menu to the Application Indicator + self.indicator.set_menu(self.tray_menu) + + # Make sure the status of the Show Window MenuItem is correct + self._sig_win_hide = self.window.window.connect("hide", self._on_window_hide) + self._sig_win_show = self.window.window.connect("show", self._on_window_show) + if self.window.visible(): + self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) + else: + self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) + + # Show the Application Indicator + self.indicator.set_status(appindicator.STATUS_ACTIVE) + + #dl = gtk.MenuItem(_("Download Speed Limit")) + #up = gtk.MenuItem(_("Upload Speed Limit")) + #self.tray_menu.insert(dl,len(self.tray_menu.get_children())-1) + #self.tray_menu.insert(up,len(self.tray_menu.get_children())-1) + if client.connected(): # We're connected so we need to get some values from the core self.__start() @@ -166,7 +198,10 @@ def shutdown(self): if self.config["enable_system_tray"]: - self.tray.set_visible(False) + if appindicator: + self.indicator.set_status(appindicator.STATUS_PASSIVE) + else: + self.tray.set_visible(False) def send_status_request(self): client.core.get_session_status([ @@ -198,25 +233,26 @@ if not self.config["enable_system_tray"]: return - # Set the tool tip text - max_download_speed = self.max_download_speed - max_upload_speed = self.max_upload_speed + if not appindicator: + # Set the tool tip text + max_download_speed = self.max_download_speed + max_upload_speed = self.max_upload_speed - if max_download_speed == -1: - max_download_speed = _("Unlimited") - else: - max_download_speed = "%s %s" % (max_download_speed, _("KiB/s")) - if max_upload_speed == -1: - max_upload_speed = _("Unlimited") - else: - max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s")) + if max_download_speed == -1: + max_download_speed = _("Unlimited") + else: + max_download_speed = "%s %s" % (max_download_speed, _("KiB/s")) + if max_upload_speed == -1: + max_upload_speed = _("Unlimited") + else: + max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s")) - msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (\ - _("Deluge"), _("Down"), self.download_rate, \ - max_download_speed, _("Up"), self.upload_rate, max_upload_speed) + msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (\ + _("Deluge"), _("Down"), self.download_rate, \ + max_download_speed, _("Up"), self.upload_rate, max_upload_speed) - # Set the tooltip - self.tray.set_tooltip(msg) + # Set the tooltip + self.tray.set_tooltip(msg) self.send_status_request() @@ -243,12 +279,26 @@ submenu_bwdownset.show_all() submenu_bwupset.show_all() + # Re-set the menu to partly work around bug #608219 + if appindicator: + self.indicator.set_menu(self.tray_menu) + def disable(self): - """Disables the system tray icon.""" - log.debug("Disabling the system tray icon..") + """Disables the system tray icon or appindicator.""" + if appindicator: + if hasattr(self, "_sig_win_hide"): + self.window.window.disconnect(self._sig_win_hide) + self.window.window.disconnect(self._sig_win_show) + log.debug("Disabling the application indicator..") + else: + log.debug("Disabling the system tray icon..") try: - self.tray.set_visible(False) - del self.tray + if appindicator: + self.indicator.set_status(appindicator.STATUS_PASSIVE) + del self.indicator + else: + self.tray.set_visible(False) + del self.tray del self.tray_glade del self.tray_menu except Exception, e: @@ -340,6 +390,16 @@ self.setbwlimit(widget, _("Set Maximum Download Speed"), "max_download_speed", "tray_download_speed_list", self.max_download_speed, "downloading.svg") + def _on_window_hide(self, widget, data=None): + """_on_window_hide - update the menuitem's status""" + log.debug("_on_window_hide") + self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) + + def _on_window_show(self, widget, data=None): + """_on_window_show - update the menuitem's status""" + log.debug("_on_window_show") + self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) + def tray_setbwup(self, widget, data=None): self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed", "tray_upload_speed_list", self.max_upload_speed, "seeding.svg") @@ -347,6 +407,8 @@ def setbwlimit(self, widget, string, core_key, ui_key, default, image): """Sets the bandwidth limit based on the user selection.""" value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s")) + + if value == _("Unlimited"): value = -1