diff --git a/src/common/pep.py b/src/common/pep.py index fa4a31a3a..21861c5e2 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -400,17 +400,17 @@ class UserActivityPEP(AbstractPEP): text = pep['text'] if 'text' in pep else None if activity in ACTIVITIES: - # Translate standard activities - if subactivity in ACTIVITIES[activity]: - subactivity = ACTIVITIES[activity][subactivity] - activity = ACTIVITIES[activity]['category'] + # Translate standard activities + if subactivity in ACTIVITIES[activity]: + subactivity = ACTIVITIES[activity][subactivity] + activity = ACTIVITIES[activity]['category'] markuptext = '' + gobject.markup_escape_text(activity) if subactivity: markuptext += ': ' + gobject.markup_escape_text(subactivity) markuptext += '' if text: - markuptext += ' (%s)' + gobject.markup_escape_text(text) + markuptext += ' (%s)' % gobject.markup_escape_text(text) return markuptext @@ -446,18 +446,17 @@ class UserNicknamePEP(AbstractPEP): common.gajim.nicks[account] = self._pep_specific_data -SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP, UserNicknamePEP] +SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP, + UserNicknamePEP] -class ConnectionPEP: - +class ConnectionPEP(object): + def _pubsubEventCB(self, xmpp_dispatcher, msg): ''' Called when we receive with pubsub event. ''' if msg.getTag('error'): log.warning('PubsubEventCB received error stanza') return - - # TODO: Logging? (actually services where logging would be useful, should - # TODO: allow to access archives remotely...) + jid = helpers.get_full_jid_from_iq(msg) event_tag = msg.getTag('event') @@ -467,114 +466,97 @@ class ConnectionPEP: self.dispatch('PEP_RECEIVED', (jid, pep.type)) items = event_tag.getTag('items') - if items is None: - return - - for item in items.getTags('item'): - entry = item.getTag('entry') - if entry: - # for each entry in feed (there shouldn't be more than one, - # but to be sure... - self.dispatch('ATOM_ENTRY', (atom.OldEntry(node=entry),)) - continue - # unknown type... probably user has another client who understands that event + if items: + for item in items.getTags('item'): + entry = item.getTag('entry') + if entry: + # for each entry in feed (there shouldn't be more than one, + # but to be sure... + self.dispatch('ATOM_ENTRY', (atom.OldEntry(node=entry),)) raise common.xmpp.NodeProcessed + + def send_activity(self, activity, subactivity=None, message=None): + if not self.pep_supported: + return + item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY}) + if activity: + i = item.addChild(activity) + if subactivity: + i.addChild(subactivity) + if message: + i = item.addChild('text') + i.addData(message) + self.send_pb_publish('', xmpp.NS_ACTIVITY, item, '0') + + def retract_activity(self): + if not self.pep_supported: + return + # not all server support retract, so send empty pep first + self.send_activity(None) + self.send_pb_retract('', xmpp.NS_ACTIVITY, '0') + def send_mood(self, mood, message=None): + if not self.pep_supported: + return + item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD}) + if mood: + item.addChild(mood) + if message: + i = item.addChild('text') + i.addData(message) + self.send_pb_publish('', xmpp.NS_MOOD, item, '0') + + def retract_mood(self): + if not self.pep_supported: + return + self.send_mood(None) + self.send_pb_retract('', xmpp.NS_MOOD, '0') + + def send_tune(self, artist='', title='', source='', track=0, length=0, + items=None): + if not self.pep_supported: + return + item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE}) + if artist: + i = item.addChild('artist') + i.addData(artist) + if title: + i = item.addChild('title') + i.addData(title) + if source: + i = item.addChild('source') + i.addData(source) + if track: + i = item.addChild('track') + i.addData(track) + if length: + i = item.addChild('length') + i.addData(length) + if items: + item.addChild(payload=items) + self.send_pb_publish('', xmpp.NS_TUNE, item, '0') -def user_send_mood(account, mood, message=''): - if not common.gajim.connections[account].pep_supported: - return - item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD}) - if mood: - item.addChild(mood) - if message: - i = item.addChild('text') - i.addData(message) + def retract_tune(self): + if not self.pep_supported: + return + # not all server support retract, so send empty pep first + self.send_tune(None) + self.send_pb_retract('', xmpp.NS_TUNE, '0') - common.gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item, - '0') + def send_nickname(self, nick): + if not self.pep_supported: + return + item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK}) + item.addData(nick) + self.send_pb_publish('', xmpp.NS_NICK, item, '0') -def user_send_activity(account, activity, subactivity='', message=''): - if not common.gajim.connections[account].pep_supported: - return - item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY}) - if activity: - i = item.addChild(activity) - if subactivity: - i.addChild(subactivity) - if message: - i = item.addChild('text') - i.addData(message) - - common.gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item, - '0') - -def user_send_tune(account, artist='', title='', source='', track=0, length=0, -items=None): - if not (common.gajim.config.get_per('accounts', account, 'publish_tune') and\ - common.gajim.connections[account].pep_supported): - return - item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE}) - if artist: - i = item.addChild('artist') - i.addData(artist) - if title: - i = item.addChild('title') - i.addData(title) - if source: - i = item.addChild('source') - i.addData(source) - if track: - i = item.addChild('track') - i.addData(track) - if length: - i = item.addChild('length') - i.addData(length) - if items: - item.addChild(payload=items) - - common.gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, - '0') - -def user_send_nickname(account, nick): - if not common.gajim.connections[account].pep_supported: - return - item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK}) - item.addData(nick) - - common.gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item, - '0') - -def user_retract_mood(account): - common.gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0') - -def user_retract_activity(account): - common.gajim.connections[account].send_pb_retract('', xmpp.NS_ACTIVITY, '0') - -def user_retract_tune(account): - common.gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0') - -def user_retract_nickname(account): - common.gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0') - -def delete_pep(jid, name): - user = common.gajim.get_room_and_nick_from_fjid(jid)[0] - - if jid == common.gajim.get_jid_from_account(name): - acc = common.gajim.connections[name] - acc.pep = {} - - for contact in common.gajim.contacts.get_contacts(name, user): - contact.pep = {} - - if jid == common.gajim.get_jid_from_account(name): - common.gajim.interface.roster.draw_account(name) - - common.gajim.interface.roster.draw_all_pep_types(jid, name) - ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) - if ctrl: - ctrl.update_all_pep_types() + def retract_nickname(self): + if not self.pep_supported: + return + # not all server support retract, so send empty pep first + self.send_tune(None) + self.send_pb_retract('', xmpp.NS_NICK, '0') # vim: se ts=3: diff --git a/src/gui_interface.py b/src/gui_interface.py index f33e769e3..98c1f3298 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -2796,33 +2796,27 @@ class Interface: 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 == '': + def music_track_changed(self, unused_listener, music_track_info, account=None): + if not 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 = '' + + is_paused = hasattr(music_track_info, 'paused') and music_track_info.paused == 0 + if not music_track_info or is_paused: + 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: + if not gajim.config.get_per('accounts', acct, 'publish_tune'): continue if gajim.connections[acct].music_track_info == music_track_info: continue - pep.user_send_tune(acct, artist, title, source) + gajim.connections[acct].send_tune(artist, title, source) gajim.connections[acct].music_track_info = music_track_info def get_bg_fg_colors(self): diff --git a/src/profile_window.py b/src/profile_window.py index a417ede08..f3fe1faa4 100644 --- a/src/profile_window.py +++ b/src/profile_window.py @@ -322,8 +322,7 @@ class ProfileWindow: nick = '' if 'NICKNAME' in vcard_: nick = vcard_['NICKNAME'] - from common import pep - pep.user_send_nickname(self.account, nick) + gajim.connections[self.account].send_nickname(self.account, nick) if nick == '': nick = gajim.config.get_per('accounts', self.account, 'name') gajim.nicks[self.account] = nick diff --git a/src/roster_window.py b/src/roster_window.py index 17697b3dd..6cef52f35 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1896,36 +1896,36 @@ class RosterWindow: self.send_status_continue(account, status, txt, auto, to) - def send_pep(self, account, pep_dict=None): - '''Sends pep information (activity, mood)''' - if not pep_dict: - return - # activity - if 'activity' in pep_dict and pep_dict['activity'] in pep.ACTIVITIES: + def send_pep(self, account, pep_dict): + connection = gajim.connections[account] + + if 'activity' in pep_dict: activity = pep_dict['activity'] - if 'subactivity' in pep_dict and \ - pep_dict['subactivity'] in pep.ACTIVITIES[activity]: - subactivity = pep_dict['subactivity'] - else: - subactivity = 'other' - if 'activity_text' in pep_dict: - activity_text = pep_dict['activity_text'] - else: - activity_text = '' - pep.user_send_activity(account, activity, subactivity, activity_text) + subactivity = pep_dict.get('subactivity', None) + activity_text = pep_dict.get('activity_text', None) + connection.send_activity(activity, subactivity, activity_text) else: - pep.user_send_activity(account, '') + connection.retract_activity() - # mood - if 'mood' in pep_dict and pep_dict['mood'] in pep.MOODS: + if 'mood' in pep_dict: mood = pep_dict['mood'] - if 'mood_text' in pep_dict: - mood_text = pep_dict['mood_text'] - else: - mood_text = '' - pep.user_send_mood(account, mood, mood_text) + mood_text = pep_dict.get('mood_text', None) + connection.send_mood(mood, mood_text) else: - pep.user_send_mood(account, '') + connection.retract_mood() + + def delete_pep(self, jid, account): + if jid == gajim.get_jid_from_account(account): + gajim.connections[account].pep = {} + self.draw_account(account) + + for contact in gajim.contacts.get_contacts(account, jid): + contact.pep = {} + + self.draw_all_pep_types(jid, account) + ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) + if ctrl: + ctrl.update_all_pep_types() def send_status_continue(self, account, status, txt, auto, to): if gajim.account_is_connected(account) and not to: @@ -1940,7 +1940,7 @@ class RosterWindow: gajim.connections[account].send_custom_status(status, txt, to) else: if status in ('invisible', 'offline'): - pep.delete_pep(gajim.get_jid_from_account(account), account) + self.delete_pep(gajim.get_jid_from_account(account), account) was_invisible = gajim.connections[account].connected == \ gajim.SHOW_LIST.index('invisible') gajim.connections[account].change_status(status, txt, auto) @@ -2018,7 +2018,7 @@ class RosterWindow: contact_instances) if not keep_pep and contact.jid != gajim.get_jid_from_account(account) \ and not contact.is_groupchat(): - pep.delete_pep(contact.jid, account) + self.delete_pep(contact.jid, account) # Redraw everything and select the sender self.adjust_and_draw_contact_context(contact.jid, account) @@ -3318,23 +3318,19 @@ class RosterWindow: gajim.interface.instances['preferences'] = config.PreferencesWindow() def on_publish_tune_toggled(self, widget, account): - act = widget.get_active() - gajim.config.set_per('accounts', account, 'publish_tune', act) - if act: + active = widget.get_active() + gajim.config.set_per('accounts', account, 'publish_tune', active) + if active: 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'): + gajim.connections[account].retract_tune() + # disable music listener only if no other account uses it + for acc in gajim.connections: + if gajim.config.get_per('accounts', acc, 'publish_tune'): break else: gajim.interface.disable_music_listener() - if gajim.connections[account].pep_supported: - # As many implementations don't support retracting items, we send a - # "Stopped" event first - pep.user_send_tune(account, '') - pep.user_retract_tune(account) helpers.update_optional_features(account) def on_pep_services_menuitem_activate(self, widget, account): @@ -5761,7 +5757,7 @@ class RosterWindow: self._pep_type_to_model_column = {'mood': C_MOOD_PIXBUF, 'activity': C_ACTIVITY_PIXBUF, - 'tune': C_ACTIVITY_PIXBUF} + 'tune': C_TUNE_PIXBUF} if gajim.config.get('avatar_position_in_roster') == 'right': add_avatar_renderer()