* 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') ], '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') ], 'after_nickname': [ opt_str, ':', _('Characters that are printed after the nickname in conversations') ],
'send_os_info': [ opt_bool, True ], '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.')], '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': [ opt_bool, True ],
'notify_on_new_gmail_email_extra': [ opt_bool, False ], '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 # We are doing disconnect at so many places, better use one function in all
def disconnect(self, on_purpose=False): 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.on_purpose = on_purpose
self.connected = 0 self.connected = 0
self.time_to_reconnect = None self.time_to_reconnect = None

View File

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

View File

@ -54,6 +54,10 @@ from common import pep
from common.exceptions import GajimGeneralException from common.exceptions import GajimGeneralException
if dbus_support.supported:
from music_track_listener import MusicTrackListener
import dbus
#---------- PreferencesWindow class -------------# #---------- PreferencesWindow class -------------#
class PreferencesWindow: class PreferencesWindow:
'''Class for Preferences window''' '''Class for Preferences window'''
@ -555,7 +559,15 @@ class PreferencesWindow:
helpers.update_optional_features() helpers.update_optional_features()
def on_publish_tune_checkbutton_toggled(self, widget): 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: for account in gajim.connections:
if gajim.connections[account].pep_supported: if gajim.connections[account].pep_supported:
# As many implementations don't support retracting items, we send a "Stopped" event first # 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) pep.user_retract_tune(account)
self.on_checkbutton_toggled(widget, 'publish_tune') self.on_checkbutton_toggled(widget, 'publish_tune')
helpers.update_optional_features() 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): def on_publish_nick_checkbutton_toggled(self, widget):
if not widget.get_active(): if not widget.get_active():
@ -1169,13 +1179,6 @@ class PreferencesWindow:
gajim.interface.instances['advanced_config'] = \ gajim.interface.instances['advanced_config'] = \
dialogs.AdvancedConfigurationWindow() 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 -------------# #---------- ManageProxiesWindow class -------------#
class ManageProxiesWindow: class ManageProxiesWindow:
def __init__(self): def __init__(self):

View File

@ -1548,50 +1548,6 @@ class RosterWindow:
# instance # instance
for chat_control in gajim.interface.msg_win_mgr.get_chat_controls(ji, account): for chat_control in gajim.interface.msg_win_mgr.get_chat_controls(ji, account):
chat_control.contact = contact1 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): def _change_awn_icon_status(self, status):
if not dbus_support.supported: if not dbus_support.supported:
@ -1619,7 +1575,7 @@ class RosterWindow:
except Exception, e: except Exception, e:
pass pass
def _music_track_changed(self, unused_listener, music_track_info, def music_track_changed(self, unused_listener, music_track_info,
account=''): account=''):
from common import pep from common import pep
if account == '': if account == '':
@ -1655,7 +1611,6 @@ class RosterWindow:
pep.user_send_tune(account, artist, title, source) pep.user_send_tune(account, artist, title, source)
self._music_track_info = music_track_info self._music_track_info = music_track_info
def connected_rooms(self, account): def connected_rooms(self, account):
if account in gajim.gc_connected[account].values(): if account in gajim.gc_connected[account].values():
return True return True
@ -5711,7 +5666,7 @@ class RosterWindow:
self.xml = gtkgui_helpers.get_glade('roster_window.glade') self.xml = gtkgui_helpers.get_glade('roster_window.glade')
self.window = self.xml.get_widget('roster_window') self.window = self.xml.get_widget('roster_window')
self.hpaned = self.xml.get_widget('roster_hpaned') 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 = MessageWindowMgr(self.window, self.hpaned)
gajim.interface.msg_win_mgr.connect('window-delete', gajim.interface.msg_win_mgr.connect('window-delete',
self.on_message_window_delete) self.on_message_window_delete)
@ -5915,12 +5870,11 @@ class RosterWindow:
publish_tune = gajim.config.get('publish_tune') publish_tune = gajim.config.get('publish_tune')
if publish_tune: if publish_tune:
if gajim.config.get('set_status_msg_from_lastfm'): listener = MusicTrackListener.get()
self.enable_syncing_status_msg_from_lastfm(True) self.music_track_changed_signal = listener.connect(
else: 'music-track-changed', self.music_track_changed)
self.enable_syncing_status_msg_from_current_music_track(True) track = listener.get_playing_track()
else: self.music_track_changed(listener, track)
self.enable_syncing_status_msg_from_current_music_track(False)
if gajim.config.get('show_roster_on_startup'): if gajim.config.get('show_roster_on_startup'):
self.window.show_all() self.window.show_all()