1. Rémy HUBSCHER
  2. sonata

Commits

Rémy HUBSCHER  committed db47d7d

Add AppIndicator Support

  • Participants
  • Parent commits e4470ea
  • Branches default

Comments (0)

Files changed (1)

File sonata/main.py

View file
  • Ignore whitespace
 # Reset so that we can see any other deprecation warnings
 warnings.simplefilter('default', DeprecationWarning)
 
+try:
+    import appindicator
+    HAVE_APPINDICATOR = True
+except ImportError:
+    HAVE_APPINDICATOR = False
+
 # Default to no sugar, then test...
 HAVE_SUGAR = False
 VOLUME_ICON_SIZE = 4
         self.remote_dest_filename = None
         self.remotefilelist = None
         self.seekidle = None
+        self.ind = None
         self.statusicon = None
         self.trayeventbox = None
         self.trayicon = None
         self.iterate_now()
         if self.window_owner:
             if self.config.withdrawn:
-                if (HAVE_EGG and self.trayicon.get_property('visible')) or (HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible()):
+                if (HAVE_EGG and self.trayicon.get_property('visible')) or (HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible()) or (HAVE_APPINDICATOR and self.ind is not None):
                     ui.hide(self.window)
         self.window.show_all()
 
         self.iterate_handler = gobject.timeout_add(self.iterate_time, self.iterate) # Repeat ad infitum..
 
         if self.config.show_trayicon:
-            if HAVE_STATUS_ICON:
+            if HAVE_APPINDICATOR:
+                if self.ind is None:
+                    self.systemtray_initialize()
+            elif HAVE_STATUS_ICON:
                 if self.statusicon.is_embedded() and not self.statusicon.get_visible():
                     # Systemtray appears, add icon:
                     self.systemtray_initialize()
             elif self.current_tab == self.TAB_CURRENT and self.current.filterbox_visible:
                 self.current.searchfilter_toggle(None)
             elif self.config.minimize_to_systray:
-                if HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible():
+                if HAVE_APPINDICATOR and self.ind is not None:
+                    self.withdraw_app()
+                elif HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible():
                     self.withdraw_app()
                 elif HAVE_EGG and self.trayicon.get_property('visible'):
                     self.withdraw_app()
             self.currentdata.clear()
             if self.current_treeview.get_model():
                 self.current_treeview.get_model().clear()
-            if HAVE_STATUS_ICON:
+            if HAVE_APPINDICATOR:
+                self.ind.set_icon(self.find_path('sonata_disconnect.png'))
+            elif HAVE_STATUS_ICON:
                 self.statusicon.set_from_file(self.find_path('sonata_disconnect.png'))
             elif HAVE_EGG and self.eggtrayheight:
                 self.eggtrayfile = self.find_path('sonata_disconnect.png')
                 self.ppbutton.get_child().get_child().get_children()[1].set_text('')
                 self.UIManager.get_widget('/traymenu/playmenu').show()
                 self.UIManager.get_widget('/traymenu/pausemenu').hide()
-                if HAVE_STATUS_ICON:
+                if HAVE_APPINDICATOR:
+                    self.ind.set_icon(self.find_path('sonata.png'))
+                elif HAVE_STATUS_ICON:
                     self.statusicon.set_from_file(self.find_path('sonata.png'))
                 elif HAVE_EGG and self.eggtrayheight:
                     self.eggtrayfile = self.find_path('sonata.png')
                 self.ppbutton.set_image(ui.image(stock=gtk.STOCK_MEDIA_PLAY, stocksize=gtk.ICON_SIZE_BUTTON))
                 self.ppbutton.get_child().get_child().get_children()[1].set_text('')
                 self.UIManager.get_widget('/traymenu/playmenu').show()
-                self.UIManager.get_widget('/traymenu/pausemenu').hide()
-                if HAVE_STATUS_ICON:
+                self.UIManager.get_widget('/traymenu/pausemenu').hide()                
+                if HAVE_APPINDICATOR:
+                    self.ind.set_icon(self.find_path('sonata_pause.png'))
+                elif HAVE_STATUS_ICON:
                     self.statusicon.set_from_file(self.find_path('sonata_pause.png'))
                 elif HAVE_EGG and self.eggtrayheight:
                     self.eggtrayfile = self.find_path('sonata_pause.png')
                     if self.prevstatus['state'] == 'pause':
                         # Forces the notification to popup if specified
                         self.on_currsong_notify()
-                if HAVE_STATUS_ICON:
+                if HAVE_APPINDICATOR:
+                    self.ind.set_icon(self.find_path('sonata_play.png'))
+                elif HAVE_STATUS_ICON:
                     self.statusicon.set_from_file(self.find_path('sonata_play.png'))
                 elif HAVE_EGG and self.eggtrayheight:
                     self.eggtrayfile = self.find_path('sonata_play.png')
                     try:
                         self.traytips.notifications_location = self.config.traytips_notifications_location
                         self.traytips.use_notifications_location = True
-                        if HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible():
+                        if HAVE_APPINDICATOR and self.ind is not None:
+                            self.traytips._real_display(self.ind)
+                        elif HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible():
                             self.traytips._real_display(self.statusicon)
                         elif HAVE_EGG and self.trayicon.get_property('visible'):
                             self.traytips._real_display(self.trayeventbox)
 
     # This one makes sure the program exits when the window is closed
     def on_delete_event(self, _widget, _data=None):
-        if not self.exit_now and self.config.minimize_to_systray:
-            if HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible():
+        if not self.exit_now and self.config.minimize_to_systray:            
+            if HAVE_APPINDICATOR and self.ind is not None:
+                self.withdraw_app()
+                return True
+            elif HAVE_STATUS_ICON and self.statusicon.is_embedded() and self.statusicon.get_visible():
                 self.withdraw_app()
                 return True
             elif HAVE_EGG and self.trayicon.get_property('visible'):
             self.traytips._remove_timer()
         elif not self.traytips.notif_handler:
             _pscreen, px, py, _mods = self.window.get_screen().get_display().get_pointer()
-            _icon_screen, icon_rect, _icon_orient = self.statusicon.get_geometry()
+            if HAVE_APPINDICATOR:
+                _icon_screen, icon_rect, _icon_orient = self.ind.get_geometry()
+            else:
+                _icon_screen, icon_rect, _icon_orient = self.statusicon.get_geometry()
             x = icon_rect[0]
             y = icon_rect[1]
             width = icon_rect[2]
             height = icon_rect[3]
             if px >= x and px <= x+width and py >= y and py <= y+height:
-                self.traytips._start_delay(self.statusicon)
+                if HAVE_APPINDICATOR:
+                    self.traytips._start_delay(self.ind)
+                else:
+                    self.traytips._start_delay(self.statusicon)
             else:
                 self.traytips._remove_timer()
 
                    self.statusicon.is_embedded() and
                    self.statusicon.get_visible())
                    or
+                   (HAVE_APPINDICATOR and self.ind is not None)
+                   or
                    (HAVE_EGG and
                     self.trayicon.get_property('visible')))
 
         # CheckButton to reflect if the trayicon is visible.
         if button.get_active():
             self.config.show_trayicon = True
-            if HAVE_STATUS_ICON:
+            if HAVE_APPINDICATOR:
+                self.systemtray_initialize()
+                self.handle_change_status()
+                if self.ind is not None:
+                    minimize.set_sensitive(True)
+            elif HAVE_STATUS_ICON:
                 self.statusicon.set_visible(True)
                 if self.statusicon.is_embedded() or self.statusicon.get_visible():
                     minimize.set_sensitive(True)
         else:
             self.config.show_trayicon = False
             minimize.set_sensitive(False)
-            if HAVE_STATUS_ICON:
+            if HAVE_APPINDICATOR:
+                del self.ind
+            elif HAVE_STATUS_ICON:
                 self.statusicon.set_visible(False)
             elif HAVE_EGG:
                 self.trayicon.hide_all()
 
     def systemtray_initialize(self):
         # Make system tray 'icon' to sit in the system tray
-        if HAVE_STATUS_ICON:
+        if HAVE_APPINDICATOR:
+            self.ind = appindicator.Indicator("sonata","sonata", 
+                                       appindicator.CATEGORY_APPLICATION_STATUS)
+            self.ind.set_status (appindicator.STATUS_ACTIVE)
+            self.ind.set_icon(self.find_path('sonata.png'))
+            self.ind.set_menu(self.traymenu)
+        elif HAVE_STATUS_ICON:
             self.statusicon = gtk.StatusIcon()
             self.statusicon.set_from_file(self.find_path('sonata.png'))
             self.statusicon.set_visible(self.config.show_trayicon)