diff options
Diffstat (limited to 'media-sound/sonata/files/sonata-zeroconf-support.patch')
-rw-r--r-- | media-sound/sonata/files/sonata-zeroconf-support.patch | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/media-sound/sonata/files/sonata-zeroconf-support.patch b/media-sound/sonata/files/sonata-zeroconf-support.patch new file mode 100644 index 0000000..b5adc4b --- /dev/null +++ b/media-sound/sonata/files/sonata-zeroconf-support.patch @@ -0,0 +1,153 @@ +--- sonata/main.py.orig 2008-11-22 01:40:44.000000000 +0100 ++++ sonata/main.py 2008-11-22 01:44:34.000000000 +0100 +@@ -88,6 +88,16 @@ + except: + HAVE_DBUS = False + ++try: ++ if HAVE_DBUS: ++ import avahi ++ HAVE_AVAHI = True ++ AVAHI_TYPE = '_mpd._tcp' ++ else: ++ raise ImportError ++except: ++ HAVE_AVAHI = False ++ + if not skip_gui: + import warnings, gobject, urllib, urllib2, re, gc, locale, shutil + import gtk, pango, threading, time, ui, img, tray +@@ -626,6 +636,9 @@ + uiDescription = uiDescription + "<menuitem action=\"" + tab + "\"/>" + uiDescription = uiDescription + "</popup></ui>" + ++ # Avahi ++ self.avahi_init() ++ + # Try to connect to MPD: + self.mpd_connect(blocking=True) + if self.conn: +@@ -635,7 +648,7 @@ + self.artwork.update_songinfo(self.songinfo) + elif self.initial_run: + show_prefs = True +- ++ + # Audioscrobbler + self.scrobbler_import() + self.scrobbler_init() +@@ -1513,6 +1526,10 @@ + action_name = self.profile_menu_name(i) + actions.append((action_name, None, "[" + str(i+1) + "] " + self.profile_names[i].replace("_", "__"), None, None, i)) + actions.append(('disconnect', None, _('Disconnect'), None, None, len(self.profile_names))) ++ # avahi connectioms ++ for i in range(len(self.avahi_names)): ++ action_name = self.avahi_menu_name(i) ++ actions.append((action_name, None, '[' + self.avahi_host[i] + '] ' + self.avahi_names[i].replace("_", "__"), None, None, -1 * i - 1)) + active_radio = self.profile_num + if not self.conn: + active_radio = len(self.profile_names) +@@ -1531,6 +1548,10 @@ + for i in range(len(self.profile_names)): + action_name = self.profile_menu_name(len(self.profile_names)-i-1) + uiDescription = uiDescription + """<menuitem action=\"""" + action_name + """\" position="top"/>""" ++ uiDescription = uiDescription + """<separator name="FM1" position="top"/>""" ++ for i in range(len(self.avahi_names)): ++ action_name = self.avahi_menu_name(len(self.avahi_names)-i-1) ++ uiDescription = uiDescription + """<menuitem action=\"""" + action_name + """\" position="top"/>""" + uiDescription = uiDescription + """</menu></popup></ui>""" + self.merge_id = self.UIManager.add_ui_from_string(uiDescription) + self.UIManager.insert_action_group(self.actionGroupProfiles, 0) +@@ -1542,7 +1563,12 @@ + if current.get_name() == 'disconnect': + self.on_disconnectkey_pressed(None) + else: +- self.profile_num = current.get_current_value() ++ if current.get_current_value() < 0: ++ self.profile_num = 0 ++ self.avahi_num = -1 * current.get_current_value() - 1 ++ else: ++ self.profile_num = current.get_current_value() ++ self.avahi_num = None + self.on_connectkey_pressed(None) + + def mpd_connect(self, blocking=False, force=False): +@@ -1560,9 +1586,14 @@ + if self.user_connect or force: + mpdh.call(self.client, 'disconnect') + host, port, password = misc.mpd_env_vars() +- if not host: host = self.host[self.profile_num] +- if not port: port = self.port[self.profile_num] +- if not password: password = self.password[self.profile_num] ++ if self.avahi_num is not None: ++ if not host: host = self.avahi_host[self.avahi_num] ++ if not port: port = self.avahi_port[self.avahi_num] ++ if not password: password = '' ++ else: ++ if not host: host = self.host[self.profile_num] ++ if not port: port = self.port[self.profile_num] ++ if not password: password = self.password[self.profile_num] + mpdh.call(self.client, 'connect', host, port) + if len(password) > 0: + mpdh.call(self.client, 'password', password) +@@ -1594,8 +1625,14 @@ + if host or port: + self.actionGroupProfiles.list_actions()[0].activate() + else: ++ if self.avahi_num is not None: ++ menu_name = self.avahi_menu_name ++ num = self.avahi_num ++ else: ++ menu_name = self.profile_menu_name ++ num = self.profile_num + for gtkAction in self.actionGroupProfiles.list_actions(): +- if gtkAction.get_name() == self.profile_menu_name(self.profile_num): ++ if gtkAction.get_name() == menu_name(num): + gtkAction.activate() + break + self.skip_on_profiles_click = False +@@ -5350,6 +5387,44 @@ + or (HAVE_EGG and self.trayicon.get_property('visible'))) + self.preferences.on_prefs_real(self.window, self.popuptimes, audioscrobbler is not None, self.scrobbler_import, self.scrobbler_init, self.scrobbler_auth_changed, trayicon_available, trayicon_in_use, self.on_connectkey_pressed, self.on_currsong_notify, self.update_infofile, self.prefs_notif_toggled, self.prefs_stylized_toggled, self.prefs_art_toggled, self.prefs_playback_toggled, self.prefs_progress_toggled, self.prefs_statusbar_toggled, self.prefs_lyrics_toggled, self.prefs_trayicon_toggled, self.prefs_window_response) + ++ def avahi_init(self): ++ self.avahi_names = [] ++ self.avahi_host = [] ++ self.avahi_port = [] ++ self.avahi_num = None ++ if HAVE_AVAHI: ++ bus = dbus.SystemBus() ++ self.server = dbus.Interface( bus.get_object(avahi.DBUS_NAME, '/'), 'org.freedesktop.Avahi.Server') ++ sbrowser = dbus.Interface(bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, AVAHI_TYPE, 'local', dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER) ++ sbrowser.connect_to_signal("ItemNew", self.on_avahi_service_add) ++ sbrowser.connect_to_signal("ItemRemove", self.on_avahi_service_remove) ++ sbrowser.connect_to_signal('Failure', self.on_avahi_service_error) ++ ++ def avahi_menu_name(self, num): ++ return _("ZeroConf") + ": " + self.avahi_names[num].replace("&", "") ++ ++ def avahi_resolve_service(self, *args): ++ if not args[2] in self.avahi_names: ++ self.avahi_names.append(args[2]) ++ self.avahi_host.append(args[5]) ++ self.avahi_port.append(args[8]) ++ self.populate_profiles_for_menu() ++ return ++ ++ def on_avahi_service_error(*args): ++ print 'Error resolving ZeroConf service: ', args[0] ++ ++ def on_avahi_service_add(self, interface, protocol, name, stype, domain, flags): ++ self.server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), reply_handler=self.avahi_resolve_service, error_handler=self.on_avahi_service_error) ++ ++ def on_avahi_service_remove(self, interface, protocol, name, stype, domain, flags): ++ if name in self.avahi_names: ++ index = self.avahi_names.index(name) ++ self.avahi_names.pop(index) ++ self.avahi_host.pop(index) ++ self.avahi_port.pop(index) ++ self.populate_profiles_for_menu() ++ + def scrobbler_init(self): + if audioscrobbler is not None and self.as_enabled and len(self.as_username) > 0 and len(self.as_password_md5) > 0: + thread = threading.Thread(target=self.scrobbler_init_thread) |