Unify updating of accounts and contact pep information. Implement and use asMarkupText() for tunes.
This commit is contained in:
parent
234a6520dd
commit
5f4db2eed9
|
@ -1434,11 +1434,10 @@ class ChatControl(ChatControlBase):
|
||||||
def update_mood(self):
|
def update_mood(self):
|
||||||
if isinstance(self.contact, GC_Contact):
|
if isinstance(self.contact, GC_Contact):
|
||||||
return
|
return
|
||||||
|
|
||||||
pep = self.contact.pep
|
pep = self.contact.pep
|
||||||
if 'mood' in pep and not pep['mood'].was_retracted():
|
if 'mood' in pep:
|
||||||
self._mood_image.set_from_pixbuf(pep['mood'].asPixbufIcon())
|
self._mood_image.set_from_pixbuf(pep['mood'].asPixbufIcon())
|
||||||
self._mood_image.set_tooltip_markup(pep['mood'].asMarkup())
|
self._mood_image.set_tooltip_markup(pep['mood'].asMarkupText())
|
||||||
self._mood_image.show()
|
self._mood_image.show()
|
||||||
else:
|
else:
|
||||||
self._mood_image.hide()
|
self._mood_image.hide()
|
||||||
|
@ -1489,35 +1488,12 @@ class ChatControl(ChatControlBase):
|
||||||
self._activity_image.hide()
|
self._activity_image.hide()
|
||||||
|
|
||||||
def update_tune(self):
|
def update_tune(self):
|
||||||
artist = None
|
|
||||||
title = None
|
|
||||||
source = None
|
|
||||||
|
|
||||||
if isinstance(self.contact, GC_Contact):
|
if isinstance(self.contact, GC_Contact):
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'artist' in self.contact.tune:
|
pep = self.contact.pep
|
||||||
artist = self.contact.tune['artist'].strip()
|
if 'tune' in pep:
|
||||||
artist = gobject.markup_escape_text(artist)
|
self._tune_image.set_tooltip_markup(pep['tune'].asMarkupText())
|
||||||
if 'title' in self.contact.tune:
|
|
||||||
title = self.contact.tune['title'].strip()
|
|
||||||
title = gobject.markup_escape_text(title)
|
|
||||||
if 'source' in self.contact.tune:
|
|
||||||
source = self.contact.tune['source'].strip()
|
|
||||||
source = gobject.markup_escape_text(source)
|
|
||||||
|
|
||||||
if artist or title:
|
|
||||||
if not artist:
|
|
||||||
artist = _('Unknown Artist')
|
|
||||||
if not title:
|
|
||||||
title = _('Unknown Title')
|
|
||||||
if not source:
|
|
||||||
source = _('Unknown Source')
|
|
||||||
|
|
||||||
self._tune_image.set_tooltip_markup(
|
|
||||||
_('<b>"%(title)s"</b> by <i>%(artist)s</i>\n'
|
|
||||||
'from <i>%(source)s</i>') % {'title': title, 'artist': artist,
|
|
||||||
'source': source})
|
|
||||||
self._tune_image.show()
|
self._tune_image.show()
|
||||||
else:
|
else:
|
||||||
self._tune_image.hide()
|
self._tune_image.hide()
|
||||||
|
|
|
@ -171,6 +171,7 @@ class Connection(ConnectionHandlers):
|
||||||
self.mood = {}
|
self.mood = {}
|
||||||
self.tune = {}
|
self.tune = {}
|
||||||
self.activity = {}
|
self.activity = {}
|
||||||
|
self.pep = {}
|
||||||
# Do we continue connection when we get roster (send presence,get vcard..)
|
# Do we continue connection when we get roster (send presence,get vcard..)
|
||||||
self.continue_connect_info = None
|
self.continue_connect_info = None
|
||||||
# Do we auto accept insecure connection
|
# Do we auto accept insecure connection
|
||||||
|
|
|
@ -203,6 +203,13 @@ import gtkgui_helpers
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
|
|
||||||
|
def translate_mood(mood):
|
||||||
|
if mood in MOODS:
|
||||||
|
return MOODS[mood]
|
||||||
|
else:
|
||||||
|
return mood
|
||||||
|
|
||||||
|
|
||||||
class AbstractPEP(object):
|
class AbstractPEP(object):
|
||||||
|
|
||||||
type = ''
|
type = ''
|
||||||
|
@ -219,14 +226,49 @@ class AbstractPEP(object):
|
||||||
|
|
||||||
def __init__(self, jid, account, items):
|
def __init__(self, jid, account, items):
|
||||||
self._pep_specific_data, self._retracted = self._extract_info(items)
|
self._pep_specific_data, self._retracted = self._extract_info(items)
|
||||||
|
|
||||||
|
self._update_contacts(jid, account)
|
||||||
|
if jid == common.gajim.get_jid_from_account(account):
|
||||||
|
self._update_account(account)
|
||||||
|
|
||||||
self.do(jid, account)
|
self.do(jid, account)
|
||||||
|
|
||||||
def _extract_info(self, items):
|
def _extract_info(self, items):
|
||||||
'''To be implemented by subclasses'''
|
'''To be implemented by subclasses'''
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def was_rectacted(self):
|
def _update_contacts(self, jid, account):
|
||||||
return self._retracted
|
dict = {} if self._retracted else self._pep_specific_data
|
||||||
|
|
||||||
|
for contact in common.gajim.contacts.get_contacts(account, jid):
|
||||||
|
setattr(contact, self.type, dict)
|
||||||
|
|
||||||
|
if self._retracted:
|
||||||
|
if self.type in contact.pep:
|
||||||
|
del contact.pep[self.type]
|
||||||
|
else:
|
||||||
|
contact.pep[self.type] = self
|
||||||
|
|
||||||
|
def _update_account(self, account):
|
||||||
|
dict = {} if self._retracted else self._pep_specific_data
|
||||||
|
|
||||||
|
acc = common.gajim.connections[account]
|
||||||
|
setattr(acc, self.type, dict)
|
||||||
|
|
||||||
|
if self._retracted:
|
||||||
|
if self.type in acc.pep:
|
||||||
|
del acc.pep[self.type]
|
||||||
|
else:
|
||||||
|
acc.pep[self.type] = self
|
||||||
|
|
||||||
|
def asPixbufIcon(self):
|
||||||
|
'''To be implemented by subclasses'''
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def asMarkupText(self):
|
||||||
|
'''To be implemented by subclasses'''
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class UserMoodPEP(AbstractPEP):
|
class UserMoodPEP(AbstractPEP):
|
||||||
'''XEP-0107: User Mood'''
|
'''XEP-0107: User Mood'''
|
||||||
|
@ -251,44 +293,30 @@ class UserMoodPEP(AbstractPEP):
|
||||||
return (mood_dict, retracted)
|
return (mood_dict, retracted)
|
||||||
|
|
||||||
def do(self, jid, name):
|
def do(self, jid, name):
|
||||||
mood_dict = {} if self._retracted else self._pep_specific_data
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
|
||||||
acc = common.gajim.connections[name]
|
|
||||||
acc.mood = mood_dict
|
|
||||||
|
|
||||||
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
|
||||||
for contact in common.gajim.contacts.get_contacts(name, user):
|
|
||||||
contact.mood = mood_dict
|
|
||||||
contact.pep['mood'] = self
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
common.gajim.interface.roster.draw_account(name)
|
common.gajim.interface.roster.draw_account(name)
|
||||||
common.gajim.interface.roster.draw_mood(user, name)
|
common.gajim.interface.roster.draw_mood(jid, name)
|
||||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
|
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, name)
|
||||||
if ctrl:
|
if ctrl:
|
||||||
ctrl.update_mood()
|
ctrl.update_mood()
|
||||||
|
|
||||||
|
|
||||||
def asPixbufIcon(self):
|
def asPixbufIcon(self):
|
||||||
if self._retracted:
|
assert not self._retracted
|
||||||
return None
|
|
||||||
else:
|
|
||||||
received_mood = self._pep_specific_data['mood']
|
received_mood = self._pep_specific_data['mood']
|
||||||
mood = received_mood if received_mood in MOODS else 'unknown'
|
mood = received_mood if received_mood in MOODS else 'unknown'
|
||||||
pixbuf = gtkgui_helpers.load_mood_icon(mood).get_pixbuf()
|
pixbuf = gtkgui_helpers.load_mood_icon(mood).get_pixbuf()
|
||||||
return pixbuf
|
return pixbuf
|
||||||
|
|
||||||
def asMarkupText(self):
|
def asMarkupText(self):
|
||||||
if self._retracted:
|
assert not self._retracted
|
||||||
return None
|
|
||||||
else:
|
|
||||||
untranslated_mood = self._pep_specific_data['mood']
|
untranslated_mood = self._pep_specific_data['mood']
|
||||||
mood = MOODS[untranslated_mood] if untranslated_mood in MOODS else untranslated_mood
|
mood = translate_mood(untranslated_mood)
|
||||||
markuptext = '<b>%s</b>' % gobject.markup_escape_text(mood)
|
markuptext = '<b>%s</b>' % gobject.markup_escape_text(mood)
|
||||||
if 'text' in self._pep_specific_data:
|
if 'text' in self._pep_specific_data:
|
||||||
text = self._pep_specific_data['text']
|
text = self._pep_specific_data['text']
|
||||||
markuptext += '(%s)' + gobject.markup_escape_text(text)
|
markuptext += ' (%s)' % gobject.markup_escape_text(text)
|
||||||
return markuptext
|
return markuptext
|
||||||
|
|
||||||
|
|
||||||
|
@ -310,28 +338,37 @@ class UserTunePEP(AbstractPEP):
|
||||||
if child.getName() in TUNE_DATA:
|
if child.getName() in TUNE_DATA:
|
||||||
tune_dict[name] = data
|
tune_dict[name] = data
|
||||||
|
|
||||||
retracted = items.getTag('retract') or not tune_dict
|
retracted = items.getTag('retract') or not ('artist' in tune_dict or
|
||||||
|
'title' in tune_dict)
|
||||||
return (tune_dict, retracted)
|
return (tune_dict, retracted)
|
||||||
|
|
||||||
|
|
||||||
def do(self, jid, name):
|
def do(self, jid, name):
|
||||||
tune_dict = {} if self._retracted else self._pep_specific_data
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
|
||||||
acc = common.gajim.connections[name]
|
|
||||||
acc.tune = tune_dict
|
|
||||||
|
|
||||||
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
|
||||||
for contact in common.gajim.contacts.get_contacts(name, user):
|
|
||||||
contact.tune = tune_dict
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
common.gajim.interface.roster.draw_account(name)
|
common.gajim.interface.roster.draw_account(name)
|
||||||
common.gajim.interface.roster.draw_tune(user, name)
|
common.gajim.interface.roster.draw_tune(jid, name)
|
||||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
|
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, name)
|
||||||
if ctrl:
|
if ctrl:
|
||||||
ctrl.update_tune()
|
ctrl.update_tune()
|
||||||
|
|
||||||
|
def asMarkupText(self):
|
||||||
|
assert not self._retracted
|
||||||
|
tune = self._pep_specific_data
|
||||||
|
|
||||||
|
artist = tune.get('artist', _('Unknown Artist'))
|
||||||
|
artist = gobject.markup_escape_text(artist)
|
||||||
|
|
||||||
|
title = tune.get('title', _('Unknown Title'))
|
||||||
|
title = gobject.markup_escape_text(title)
|
||||||
|
|
||||||
|
source = tune.get('source', _('Unknown Source'))
|
||||||
|
source = gobject.markup_escape_text(source)
|
||||||
|
|
||||||
|
tune_string = _('<b>"%(title)s"</b> by <i>%(artist)s</i>\n'
|
||||||
|
'from <i>%(source)s</i>') % {'title': title,
|
||||||
|
'artist': artist, 'source': source}
|
||||||
|
return tune_string
|
||||||
|
|
||||||
|
|
||||||
class UserActivityPEP(AbstractPEP):
|
class UserActivityPEP(AbstractPEP):
|
||||||
'''XEP-0108: User Activity'''
|
'''XEP-0108: User Activity'''
|
||||||
|
@ -361,20 +398,11 @@ class UserActivityPEP(AbstractPEP):
|
||||||
return (activity_dict, retracted)
|
return (activity_dict, retracted)
|
||||||
|
|
||||||
def do(self, jid, name):
|
def do(self, jid, name):
|
||||||
activity_dict = {} if self._retracted else self._pep_specific_data
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
|
||||||
acc = common.gajim.connections[name]
|
|
||||||
acc.activity = activity_dict
|
|
||||||
|
|
||||||
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
|
||||||
for contact in common.gajim.contacts.get_contacts(name, user):
|
|
||||||
contact.activity = activity_dict
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
common.gajim.interface.roster.draw_account(name)
|
common.gajim.interface.roster.draw_account(name)
|
||||||
common.gajim.interface.roster.draw_activity(user, name)
|
common.gajim.interface.roster.draw_activity(jid, name)
|
||||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
|
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, name)
|
||||||
if ctrl:
|
if ctrl:
|
||||||
ctrl.update_activity()
|
ctrl.update_activity()
|
||||||
|
|
||||||
|
@ -437,7 +465,7 @@ class ConnectionPEP:
|
||||||
for pep_class in SUPPORTED_PERSONAL_USER_EVENTS:
|
for pep_class in SUPPORTED_PERSONAL_USER_EVENTS:
|
||||||
pep = pep_class.get_tag_as_PEP(jid, self.name, event_tag)
|
pep = pep_class.get_tag_as_PEP(jid, self.name, event_tag)
|
||||||
if pep:
|
if pep:
|
||||||
self.dispatch('PEP_RECEIVED', (pep.type, pep))
|
self.dispatch('PEP_RECEIVED', (jid, pep.type))
|
||||||
|
|
||||||
items = event_tag.getTag('items')
|
items = event_tag.getTag('items')
|
||||||
if items is None: return
|
if items is None: return
|
||||||
|
|
|
@ -1281,15 +1281,10 @@ class RosterWindow:
|
||||||
iters = self._get_contact_iter(jid, account, model=self.model)
|
iters = self._get_contact_iter(jid, account, model=self.model)
|
||||||
if not iters or not gajim.config.get('show_mood_in_roster'):
|
if not iters or not gajim.config.get('show_mood_in_roster'):
|
||||||
return
|
return
|
||||||
jid = self.model[iters[0]][C_JID]
|
jid = self.model[iters[0]][C_JID].decode('utf-8')
|
||||||
jid = jid.decode('utf-8')
|
|
||||||
contact = gajim.contacts.get_contact(account, jid)
|
contact = gajim.contacts.get_contact(account, jid)
|
||||||
if 'mood' in contact.mood and contact.mood['mood'].strip() in MOODS:
|
if 'mood' in contact.pep:
|
||||||
pixbuf = gtkgui_helpers.load_mood_icon(
|
pixbuf = contact.pep['mood'].asPixbufIcon()
|
||||||
contact.mood['mood'].strip()).get_pixbuf()
|
|
||||||
elif 'mood' in contact.mood:
|
|
||||||
pixbuf = gtkgui_helpers.load_mood_icon(
|
|
||||||
'unknown').get_pixbuf()
|
|
||||||
else:
|
else:
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
for child_iter in iters:
|
for child_iter in iters:
|
||||||
|
|
|
@ -579,17 +579,9 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
Append Tune, Mood, Activity information of the specified contact
|
Append Tune, Mood, Activity information of the specified contact
|
||||||
to the given property list.
|
to the given property list.
|
||||||
'''
|
'''
|
||||||
if 'mood' in contact.mood:
|
if 'mood' in contact.pep:
|
||||||
mood = contact.mood['mood'].strip()
|
mood = contact.pep['mood'].asMarkupText()
|
||||||
mood = MOODS.get(mood, mood)
|
|
||||||
mood = gobject.markup_escape_text(mood)
|
|
||||||
mood_string = _('Mood:') + ' <b>%s</b>' % mood
|
mood_string = _('Mood:') + ' <b>%s</b>' % mood
|
||||||
if 'text' in contact.mood \
|
|
||||||
and contact.mood['text'] != '':
|
|
||||||
mood_text = contact.mood['text'].strip()
|
|
||||||
mood_text = \
|
|
||||||
gobject.markup_escape_text(mood_text)
|
|
||||||
mood_string += ' (%s)' % mood_text
|
|
||||||
properties.append((mood_string, None))
|
properties.append((mood_string, None))
|
||||||
|
|
||||||
if 'activity' in contact.activity:
|
if 'activity' in contact.activity:
|
||||||
|
@ -617,27 +609,9 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
activity_string += ' (%s)' % activity_text
|
activity_string += ' (%s)' % activity_text
|
||||||
properties.append((activity_string, None))
|
properties.append((activity_string, None))
|
||||||
|
|
||||||
if 'artist' in contact.tune \
|
if 'tune' in contact.pep:
|
||||||
or 'title' in contact.tune:
|
tune = contact.pep['tune'].asMarkupText()
|
||||||
if 'artist' in contact.tune:
|
tune_string = _('Tune:') + ' %s' % tune
|
||||||
artist = contact.tune['artist'].strip()
|
|
||||||
artist = gobject.markup_escape_text(artist)
|
|
||||||
else:
|
|
||||||
artist = _('Unknown Artist')
|
|
||||||
if 'title' in contact.tune:
|
|
||||||
title = contact.tune['title'].strip()
|
|
||||||
title = gobject.markup_escape_text(title)
|
|
||||||
else:
|
|
||||||
title = _('Unknown Title')
|
|
||||||
if 'source' in contact.tune:
|
|
||||||
source = contact.tune['source'].strip()
|
|
||||||
source = gobject.markup_escape_text(source)
|
|
||||||
else:
|
|
||||||
source = _('Unknown Source')
|
|
||||||
tune_string = _('Tune:') + ' ' + \
|
|
||||||
_('<b>"%(title)s"</b> by <i>%(artist)s</i>\n'
|
|
||||||
'from <i>%(source)s</i>') % {'title': title,
|
|
||||||
'artist': artist, 'source': source}
|
|
||||||
properties.append((tune_string, None))
|
properties.append((tune_string, None))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue