From 44e98585edfca4f7785dabf2db0b8384d533e210 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 9 Sep 2009 13:26:53 +0200 Subject: [PATCH] move music track listener things from roster_window.py to gajim.py. see #3643 --- src/common/connection.py | 2 +- src/common/connection_handlers.py | 4 +-- src/gajim.py | 50 ++++++++++++++++++++++++++++ src/roster_window.py | 55 ++----------------------------- 4 files changed, 55 insertions(+), 56 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index b49149a08..27b840f7b 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -219,7 +219,7 @@ class Connection(ConnectionHandlers): # We are doing disconnect at so many places, better use one function in all def disconnect(self, on_purpose=False): - gajim.interface.roster.music_track_changed(None, None, self.name) + gajim.interface.music_track_changed(None, None, self.name) self.on_purpose = on_purpose self.connected = 0 self.time_to_reconnect = None diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index f4304d976..0cfab7a2b 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -899,8 +899,8 @@ class ConnectionDisco: track = listener.get_playing_track() if gajim.config.get_per('accounts', self.name, 'publish_tune'): - gajim.interface.roster.music_track_changed(listener, - track, self.name) + gajim.interface.music_track_changed(listener, track, + self.name) break if features.__contains__(common.xmpp.NS_VCARD): self.vcard_supported = True diff --git a/src/gajim.py b/src/gajim.py index 3645c1c1f..3e65fac01 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -156,6 +156,7 @@ except exceptions.DatabaseMalformed: else: from common import dbus_support if dbus_support.supported: + from music_track_listener import MusicTrackListener import dbus if os.name == 'posix': # dl module is Unix Only @@ -243,6 +244,7 @@ from common import helpers from common import optparser from common import dataforms from common import passwords +from common import pep gajimpaths = common.configpaths.gajimpaths @@ -2961,6 +2963,48 @@ class Interface: ### Other Methods ################################################################################ + def enable_music_listener(self): + if not self.music_track_changed_signal: + listener = MusicTrackListener.get() + self.music_track_changed_signal = listener.connect( + 'music-track-changed', self.music_track_changed) + track = listener.get_playing_track() + self.music_track_changed(listener, track) + + def disable_music_listener(self): + listener = MusicTrackListener.get() + listener.disconnect(self.music_track_changed_signal) + self.music_track_changed_signal = None + + def music_track_changed(self, unused_listener, music_track_info, account=''): + if account == '': + accounts = gajim.connections.keys() + else: + accounts = [account] + if music_track_info is None: + artist = '' + title = '' + source = '' + elif hasattr(music_track_info, 'paused') and music_track_info.paused == 0: + artist = '' + title = '' + source = '' + else: + artist = music_track_info.artist + title = music_track_info.title + source = music_track_info.album + for acct in accounts: + if acct not in gajim.connections: + continue + if not gajim.account_is_connected(acct): + continue + if not gajim.connections[acct].pep_supported: + continue + if gajim.connections[acct].music_track_info == music_track_info: + continue + pep.user_send_tune(acct, artist, title, source) + gajim.connections[acct].music_track_info = music_track_info + def read_sleepy(self): '''Check idle status and change that status if needed''' if not self.sleeper.poll(): @@ -3516,6 +3560,12 @@ class Interface: except Exception: pass gobject.timeout_add_seconds(5, remote_init) + self.music_track_changed_signal = None + for account in gajim.connections: + if gajim.config.get_per('accounts', account, 'publish_tune') and \ + dbus_support.supported: + self.enable_music_listener() + break if __name__ == '__main__': def sigint_cb(num, stack): diff --git a/src/roster_window.py b/src/roster_window.py index b9358f07b..37269b414 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -62,7 +62,6 @@ from message_window import MessageWindowMgr from common import dbus_support if dbus_support.supported: - from music_track_listener import MusicTrackListener import dbus from common.xmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC @@ -1762,38 +1761,6 @@ class RosterWindow: except Exception: pass - def music_track_changed(self, unused_listener, music_track_info, - account=''): - if account == '': - accounts = gajim.connections.keys() - if music_track_info is None: - artist = '' - title = '' - source = '' - elif hasattr(music_track_info, 'paused') and music_track_info.paused == 0: - artist = '' - title = '' - source = '' - else: - artist = music_track_info.artist - title = music_track_info.title - source = music_track_info.album - if account == '': - for account in accounts: - if not gajim.account_is_connected(account): - continue - if not gajim.connections[account].pep_supported: - continue - if gajim.connections[account].music_track_info == music_track_info: - continue - pep.user_send_tune(account, artist, title, source) - gajim.connections[account].music_track_info = music_track_info - elif account in gajim.connections and \ - gajim.connections[account].pep_supported: - if gajim.connections[account].music_track_info != music_track_info: - pep.user_send_tune(account, artist, title, source) - gajim.connections[account].music_track_info = music_track_info - def connected_rooms(self, account): if account in gajim.gc_connected[account].values(): return True @@ -3354,21 +3321,14 @@ class RosterWindow: act = widget.get_active() gajim.config.set_per('accounts', account, 'publish_tune', act) if act: - listener = MusicTrackListener.get() - if not self.music_track_changed_signal: - self.music_track_changed_signal = listener.connect( - 'music-track-changed', self.music_track_changed) - track = listener.get_playing_track() - self.music_track_changed(listener, track) + gajim.interface.enable_music_listener() else: # disable it only if no other account use it for acct in gajim.connections: if gajim.config.get_per('accounts', acct, 'publish_tune'): break else: - listener = MusicTrackListener.get() - listener.disconnect(self.music_track_changed_signal) - self.music_track_changed_signal = None + gajim.interface.disable_music_listener() if gajim.connections[account].pep_supported: # As many implementations don't support retracting items, we send a @@ -6190,7 +6150,6 @@ class RosterWindow: self.xml = gtkgui_helpers.get_glade('roster_window.glade') self.window = self.xml.get_widget('roster_window') self.hpaned = self.xml.get_widget('roster_hpaned') - self.music_track_changed_signal = None gajim.interface.msg_win_mgr = MessageWindowMgr(self.window, self.hpaned) gajim.interface.msg_win_mgr.connect('window-delete', self.on_message_window_delete) @@ -6411,16 +6370,6 @@ class RosterWindow: self._toggeling_row = False self.setup_and_draw_roster() - for account in gajim.connections: - if gajim.config.get_per('accounts', account, 'publish_tune') and \ - dbus_support.supported: - listener = MusicTrackListener.get() - self.music_track_changed_signal = listener.connect( - 'music-track-changed', self.music_track_changed) - track = listener.get_playing_track() - self.music_track_changed(listener, track) - break - if gajim.config.get('show_roster_on_startup'): self.window.show_all() else: