Various pep-related cleanups.

Most important change is that pep send/retract functions no reside on the ConnectionPEP object.
This commit is contained in:
Stephan Erb 2009-11-16 19:31:17 +01:00
parent a3ea00f4ea
commit 10428555aa
4 changed files with 139 additions and 168 deletions

View File

@ -410,7 +410,7 @@ class UserActivityPEP(AbstractPEP):
markuptext += ': ' + gobject.markup_escape_text(subactivity) markuptext += ': ' + gobject.markup_escape_text(subactivity)
markuptext += '</b>' markuptext += '</b>'
if text: if text:
markuptext += ' (%s)' + gobject.markup_escape_text(text) markuptext += ' (%s)' % gobject.markup_escape_text(text)
return markuptext return markuptext
@ -446,9 +446,10 @@ class UserNicknamePEP(AbstractPEP):
common.gajim.nicks[account] = self._pep_specific_data 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): def _pubsubEventCB(self, xmpp_dispatcher, msg):
''' Called when we receive <message /> with pubsub event. ''' ''' Called when we receive <message /> with pubsub event. '''
@ -456,8 +457,6 @@ class ConnectionPEP:
log.warning('PubsubEventCB received error stanza') log.warning('PubsubEventCB received error stanza')
return 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) jid = helpers.get_full_jid_from_iq(msg)
event_tag = msg.getTag('event') event_tag = msg.getTag('event')
@ -467,36 +466,18 @@ class ConnectionPEP:
self.dispatch('PEP_RECEIVED', (jid, pep.type)) self.dispatch('PEP_RECEIVED', (jid, pep.type))
items = event_tag.getTag('items') items = event_tag.getTag('items')
if items is None: if items:
return
for item in items.getTags('item'): for item in items.getTags('item'):
entry = item.getTag('entry') entry = item.getTag('entry')
if entry: if entry:
# for each entry in feed (there shouldn't be more than one, # for each entry in feed (there shouldn't be more than one,
# but to be sure... # but to be sure...
self.dispatch('ATOM_ENTRY', (atom.OldEntry(node=entry),)) self.dispatch('ATOM_ENTRY', (atom.OldEntry(node=entry),))
continue
# unknown type... probably user has another client who understands that event
raise common.xmpp.NodeProcessed raise common.xmpp.NodeProcessed
def send_activity(self, activity, subactivity=None, message=None):
def user_send_mood(account, mood, message=''): if not self.pep_supported:
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)
common.gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item,
'0')
def user_send_activity(account, activity, subactivity='', message=''):
if not common.gajim.connections[account].pep_supported:
return return
item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY}) item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY})
if activity: if activity:
@ -506,14 +487,35 @@ def user_send_activity(account, activity, subactivity='', message=''):
if message: if message:
i = item.addChild('text') i = item.addChild('text')
i.addData(message) i.addData(message)
self.send_pb_publish('', xmpp.NS_ACTIVITY, item, '0')
common.gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item, def retract_activity(self):
'0') 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 user_send_tune(account, artist='', title='', source='', track=0, length=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): items=None):
if not (common.gajim.config.get_per('accounts', account, 'publish_tune') and\ if not self.pep_supported:
common.gajim.connections[account].pep_supported):
return return
item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE}) item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE})
if artist: if artist:
@ -533,48 +535,28 @@ items=None):
i.addData(length) i.addData(length)
if items: if items:
item.addChild(payload=items) item.addChild(payload=items)
self.send_pb_publish('', xmpp.NS_TUNE, item, '0')
common.gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, def retract_tune(self):
'0') 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')
def user_send_nickname(account, nick): def send_nickname(self, nick):
if not common.gajim.connections[account].pep_supported: if not self.pep_supported:
return return
item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK}) item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK})
item.addData(nick) item.addData(nick)
self.send_pb_publish('', xmpp.NS_NICK, item, '0')
common.gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item, def retract_nickname(self):
'0') if not self.pep_supported:
return
def user_retract_mood(account): # not all server support retract, so send empty pep first
common.gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0') self.send_tune(None)
self.send_pb_retract('', xmpp.NS_NICK, '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()
# vim: se ts=3: # vim: se ts=3:

View File

@ -2796,33 +2796,27 @@ class Interface:
listener.disconnect(self.music_track_changed_signal) listener.disconnect(self.music_track_changed_signal)
self.music_track_changed_signal = None self.music_track_changed_signal = None
def music_track_changed(self, unused_listener, music_track_info, account=''): def music_track_changed(self, unused_listener, music_track_info, account=None):
if account == '': if not account:
accounts = gajim.connections.keys() accounts = gajim.connections.keys()
else: else:
accounts = [account] accounts = [account]
if music_track_info is None:
artist = '' is_paused = hasattr(music_track_info, 'paused') and music_track_info.paused == 0
title = '' if not music_track_info or is_paused:
source = '' artist = title = source = ''
elif hasattr(music_track_info, 'paused') and music_track_info.paused == 0:
artist = ''
title = ''
source = ''
else: else:
artist = music_track_info.artist artist = music_track_info.artist
title = music_track_info.title title = music_track_info.title
source = music_track_info.album source = music_track_info.album
for acct in accounts: for acct in accounts:
if acct not in gajim.connections:
continue
if not gajim.account_is_connected(acct): if not gajim.account_is_connected(acct):
continue continue
if not gajim.connections[acct].pep_supported: if not gajim.config.get_per('accounts', acct, 'publish_tune'):
continue continue
if gajim.connections[acct].music_track_info == music_track_info: if gajim.connections[acct].music_track_info == music_track_info:
continue 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 gajim.connections[acct].music_track_info = music_track_info
def get_bg_fg_colors(self): def get_bg_fg_colors(self):

View File

@ -322,8 +322,7 @@ class ProfileWindow:
nick = '' nick = ''
if 'NICKNAME' in vcard_: if 'NICKNAME' in vcard_:
nick = vcard_['NICKNAME'] nick = vcard_['NICKNAME']
from common import pep gajim.connections[self.account].send_nickname(self.account, nick)
pep.user_send_nickname(self.account, nick)
if nick == '': if nick == '':
nick = gajim.config.get_per('accounts', self.account, 'name') nick = gajim.config.get_per('accounts', self.account, 'name')
gajim.nicks[self.account] = nick gajim.nicks[self.account] = nick

View File

@ -1896,36 +1896,36 @@ class RosterWindow:
self.send_status_continue(account, status, txt, auto, to) self.send_status_continue(account, status, txt, auto, to)
def send_pep(self, account, pep_dict=None): def send_pep(self, account, pep_dict):
'''Sends pep information (activity, mood)''' connection = gajim.connections[account]
if not pep_dict:
return
# activity
if 'activity' in pep_dict and pep_dict['activity'] in pep.ACTIVITIES:
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)
else:
pep.user_send_activity(account, '')
# mood if 'activity' in pep_dict:
if 'mood' in pep_dict and pep_dict['mood'] in pep.MOODS: activity = pep_dict['activity']
subactivity = pep_dict.get('subactivity', None)
activity_text = pep_dict.get('activity_text', None)
connection.send_activity(activity, subactivity, activity_text)
else:
connection.retract_activity()
if 'mood' in pep_dict:
mood = pep_dict['mood'] mood = pep_dict['mood']
if 'mood_text' in pep_dict: mood_text = pep_dict.get('mood_text', None)
mood_text = pep_dict['mood_text'] connection.send_mood(mood, mood_text)
else: else:
mood_text = '' connection.retract_mood()
pep.user_send_mood(account, mood, mood_text)
else: def delete_pep(self, jid, account):
pep.user_send_mood(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): def send_status_continue(self, account, status, txt, auto, to):
if gajim.account_is_connected(account) and not 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) gajim.connections[account].send_custom_status(status, txt, to)
else: else:
if status in ('invisible', 'offline'): 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 == \ was_invisible = gajim.connections[account].connected == \
gajim.SHOW_LIST.index('invisible') gajim.SHOW_LIST.index('invisible')
gajim.connections[account].change_status(status, txt, auto) gajim.connections[account].change_status(status, txt, auto)
@ -2018,7 +2018,7 @@ class RosterWindow:
contact_instances) contact_instances)
if not keep_pep and contact.jid != gajim.get_jid_from_account(account) \ if not keep_pep and contact.jid != gajim.get_jid_from_account(account) \
and not contact.is_groupchat(): and not contact.is_groupchat():
pep.delete_pep(contact.jid, account) self.delete_pep(contact.jid, account)
# Redraw everything and select the sender # Redraw everything and select the sender
self.adjust_and_draw_contact_context(contact.jid, account) self.adjust_and_draw_contact_context(contact.jid, account)
@ -3318,23 +3318,19 @@ class RosterWindow:
gajim.interface.instances['preferences'] = config.PreferencesWindow() gajim.interface.instances['preferences'] = config.PreferencesWindow()
def on_publish_tune_toggled(self, widget, account): def on_publish_tune_toggled(self, widget, account):
act = widget.get_active() active = widget.get_active()
gajim.config.set_per('accounts', account, 'publish_tune', act) gajim.config.set_per('accounts', account, 'publish_tune', active)
if act: if active:
gajim.interface.enable_music_listener() gajim.interface.enable_music_listener()
else: else:
# disable it only if no other account use it gajim.connections[account].retract_tune()
for acct in gajim.connections: # disable music listener only if no other account uses it
if gajim.config.get_per('accounts', acct, 'publish_tune'): for acc in gajim.connections:
if gajim.config.get_per('accounts', acc, 'publish_tune'):
break break
else: else:
gajim.interface.disable_music_listener() 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) helpers.update_optional_features(account)
def on_pep_services_menuitem_activate(self, widget, 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, self._pep_type_to_model_column = {'mood': C_MOOD_PIXBUF,
'activity': C_ACTIVITY_PIXBUF, 'activity': C_ACTIVITY_PIXBUF,
'tune': C_ACTIVITY_PIXBUF} 'tune': C_TUNE_PIXBUF}
if gajim.config.get('avatar_position_in_roster') == 'right': if gajim.config.get('avatar_position_in_roster') == 'right':
add_avatar_renderer() add_avatar_renderer()