* Remove old code to update status to current track.

* Don't bind the track listener when not enabled anymore.
* Remove the signal / add the signal when changed in preferences.
This commit is contained in:
js 2008-05-15 19:52:04 +00:00
parent 129c115837
commit 96a5b497a8
5 changed files with 22 additions and 67 deletions

View File

@ -151,7 +151,6 @@ class Config:
'before_nickname': [ opt_str, '', _('Characters that are printed before the nickname in conversations') ],
'after_nickname': [ opt_str, ':', _('Characters that are printed after the nickname in conversations') ],
'send_os_info': [ opt_bool, True ],
'set_status_msg_from_lastfm': [ opt_bool, False, _('If checked, Gajim can regularly poll a Last.fm account and sends recently played songs through PEP.') ],
'lastfm_username': [ opt_str, '', _('The username used to identify the Last.fm account.')],
'notify_on_new_gmail_email': [ opt_bool, True ],
'notify_on_new_gmail_email_extra': [ opt_bool, False ],

View File

@ -195,8 +195,7 @@ class Connection(ConnectionHandlers):
# We are doing disconnect at so many places, better use one function in all
def disconnect(self, on_purpose=False):
#FIXME: set the Tune to None before disconnection per account
#gajim.interface.roster._music_track_changed(None, None)
gajim.interface.roster.music_track_changed(None, None)
self.on_purpose = on_purpose
self.connected = 0
self.time_to_reconnect = None

View File

@ -820,7 +820,7 @@ class ConnectionDisco:
listener = MusicTrackListener.get()
track = listener.get_playing_track()
if gajim.config.get('publish_tune'):
gajim.interface.roster._music_track_changed(listener,
gajim.interface.roster.music_track_changed(listener,
track, self.name)
break
if features.__contains__(common.xmpp.NS_BYTESTREAM):

View File

@ -54,6 +54,10 @@ from common import pep
from common.exceptions import GajimGeneralException
if dbus_support.supported:
from music_track_listener import MusicTrackListener
import dbus
#---------- PreferencesWindow class -------------#
class PreferencesWindow:
'''Class for Preferences window'''
@ -555,7 +559,15 @@ class PreferencesWindow:
helpers.update_optional_features()
def on_publish_tune_checkbutton_toggled(self, widget):
if not widget.get_active():
if widget.get_active():
listener = MusicTrackListener.get()
gajim.interface.roster.music_track_changed_signal = listener.connect(
'music-track-changed', gajim.interface.roster.music_track_changed)
track = listener.get_playing_track()
gajim.interface.roster.music_track_changed(listener, track)
else:
gajim.interface.roster.music_track_changed_signal = None
for account in gajim.connections:
if gajim.connections[account].pep_supported:
# As many implementations don't support retracting items, we send a "Stopped" event first
@ -563,8 +575,6 @@ class PreferencesWindow:
pep.user_retract_tune(account)
self.on_checkbutton_toggled(widget, 'publish_tune')
helpers.update_optional_features()
gajim.interface.roster.enable_syncing_status_msg_from_current_music_track(
widget.get_active())
def on_publish_nick_checkbutton_toggled(self, widget):
if not widget.get_active():
@ -1169,13 +1179,6 @@ class PreferencesWindow:
gajim.interface.instances['advanced_config'] = \
dialogs.AdvancedConfigurationWindow()
def set_status_msg_from_current_music_track_checkbutton_toggled(self,
widget):
self.on_checkbutton_toggled(widget,
'set_status_msg_from_current_music_track')
gajim.interface.roster.enable_syncing_status_msg_from_current_music_track(
widget.get_active())
#---------- ManageProxiesWindow class -------------#
class ManageProxiesWindow:
def __init__(self):

View File

@ -1549,50 +1549,6 @@ class RosterWindow:
for chat_control in gajim.interface.msg_win_mgr.get_chat_controls(ji, account):
chat_control.contact = contact1
def enable_syncing_status_msg_from_current_music_track(self, enabled):
'''enable setting status msg from currently playing music track
if enabled is True, we listen to events from music players about
currently played music track, and we update our
status message accordinly'''
if not dbus_support.supported:
# do nothing if user doesn't have D-Bus bindings
return
if enabled:
listener = MusicTrackListener.get()
if self._music_track_changed_signal is None:
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)
else:
if self._music_track_changed_signal is not None:
listener = MusicTrackListener.get()
listener.disconnect(self._music_track_changed_signal)
self._music_track_changed_signal = None
self._music_track_changed(None, None)
def enable_syncing_status_msg_from_lastfm(self, enabled):
''' enable setting status msg from a Last.fm account
if enabled is True, we start polling the Last.fm server,
and we update our status message accordinly'''
if enabled:
if self._music_track_changed_signal is None:
listener = LastFMTrackListener.get(
gajim.config.get('lastfm_username'))
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)
else:
if self._music_track_changed_signal is not None:
listener = LastFMTrackListener.get(
gajim.config.get('lastfm_username'))
listener.disconnect(self._music_track_changed_signal)
self._music_track_changed_signal = None
self._music_track_changed(None, None)
def _change_awn_icon_status(self, status):
if not dbus_support.supported:
# do nothing if user doesn't have D-Bus bindings
@ -1619,7 +1575,7 @@ class RosterWindow:
except Exception, e:
pass
def _music_track_changed(self, unused_listener, music_track_info,
def music_track_changed(self, unused_listener, music_track_info,
account=''):
from common import pep
if account == '':
@ -1655,7 +1611,6 @@ class RosterWindow:
pep.user_send_tune(account, artist, title, source)
self._music_track_info = music_track_info
def connected_rooms(self, account):
if account in gajim.gc_connected[account].values():
return True
@ -5711,7 +5666,7 @@ 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
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)
@ -5915,12 +5870,11 @@ class RosterWindow:
publish_tune = gajim.config.get('publish_tune')
if publish_tune:
if gajim.config.get('set_status_msg_from_lastfm'):
self.enable_syncing_status_msg_from_lastfm(True)
else:
self.enable_syncing_status_msg_from_current_music_track(True)
else:
self.enable_syncing_status_msg_from_current_music_track(False)
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)
if gajim.config.get('show_roster_on_startup'):
self.window.show_all()