Create asPixbufIcon and asMarkupText functions on the UserActivity class.
This commit is contained in:
parent
6c0fb26e58
commit
30191888ba
|
@ -1443,46 +1443,12 @@ class ChatControl(ChatControlBase):
|
|||
self._mood_image.hide()
|
||||
|
||||
def update_activity(self):
|
||||
activity = None
|
||||
subactivity = None
|
||||
text = None
|
||||
|
||||
if isinstance(self.contact, GC_Contact):
|
||||
return
|
||||
|
||||
if 'activity' in self.contact.activity:
|
||||
activity = self.contact.activity['activity'].strip()
|
||||
if 'subactivity' in self.contact.activity:
|
||||
subactivity = self.contact.activity['subactivity'].strip()
|
||||
if 'text' in self.contact.activity:
|
||||
text = self.contact.activity['text'].strip()
|
||||
|
||||
if activity is not None:
|
||||
if activity in ACTIVITIES:
|
||||
# Translate standard activities
|
||||
if subactivity in ACTIVITIES[activity]:
|
||||
self._activity_image.set_from_pixbuf(
|
||||
gtkgui_helpers.load_activity_icon(activity, subactivity). \
|
||||
get_pixbuf())
|
||||
subactivity = ACTIVITIES[activity][subactivity]
|
||||
else:
|
||||
self._activity_image.set_from_pixbuf(
|
||||
gtkgui_helpers.load_activity_icon(activity).get_pixbuf())
|
||||
activity = ACTIVITIES[activity]['category']
|
||||
else:
|
||||
self._activity_image.set_from_pixbuf(
|
||||
gtkgui_helpers.load_activity_icon('unknown').get_pixbuf())
|
||||
|
||||
# Translate standard subactivities
|
||||
|
||||
tooltip = '<b>' + gobject.markup_escape_text(activity)
|
||||
if subactivity:
|
||||
tooltip += ': ' + gobject.markup_escape_text(subactivity)
|
||||
tooltip += '</b>'
|
||||
if text:
|
||||
tooltip += '\n' + gobject.markup_escape_text(text)
|
||||
self._activity_image.set_tooltip_markup(tooltip)
|
||||
|
||||
pep = self.contact.pep
|
||||
if 'activity' in pep:
|
||||
self._activity_image.set_from_pixbuf(pep['activity'].asPixbufIcon())
|
||||
self._activity_image.set_tooltip_markup(pep['activity'].asMarkupText())
|
||||
self._activity_image.show()
|
||||
else:
|
||||
self._activity_image.hide()
|
||||
|
@ -1490,7 +1456,6 @@ class ChatControl(ChatControlBase):
|
|||
def update_tune(self):
|
||||
if isinstance(self.contact, GC_Contact):
|
||||
return
|
||||
|
||||
pep = self.contact.pep
|
||||
if 'tune' in pep:
|
||||
self._tune_image.set_tooltip_markup(pep['tune'].asMarkupText())
|
||||
|
|
|
@ -201,6 +201,8 @@ import helpers
|
|||
import atom
|
||||
import gtkgui_helpers
|
||||
import gobject
|
||||
import gajim
|
||||
import gtk
|
||||
|
||||
|
||||
def translate_mood(mood):
|
||||
|
@ -329,6 +331,11 @@ class UserTunePEP(AbstractPEP):
|
|||
retracted = items.getTag('retract') or not ('artist' in tune_dict or
|
||||
'title' in tune_dict)
|
||||
return (tune_dict, retracted)
|
||||
|
||||
def asPixbufIcon(self):
|
||||
import os
|
||||
path = os.path.join(gajim.DATA_DIR, 'emoticons', 'static', 'music.png')
|
||||
return gtk.gdk.pixbuf_new_from_file(path)
|
||||
|
||||
def asMarkupText(self):
|
||||
assert not self._retracted
|
||||
|
@ -366,16 +373,54 @@ class UserActivityPEP(AbstractPEP):
|
|||
data = child.getData().strip()
|
||||
if name == 'text':
|
||||
activity_dict['text'] = data
|
||||
elif name in ACTIVITIES:
|
||||
else:
|
||||
activity_dict['activity'] = name
|
||||
for subactivity in child.getChildren():
|
||||
subactivity_name = subactivity.getName().strip()
|
||||
if subactivity_name in ACTIVITIES[name]:
|
||||
activity_dict['subactivity'] = subactivity_name
|
||||
activity_dict['subactivity'] = subactivity_name
|
||||
|
||||
retracted = items.getTag('retract') or not activity_dict
|
||||
retracted = items.getTag('retract') or not 'activity' in activity_dict
|
||||
return (activity_dict, retracted)
|
||||
|
||||
def asPixbufIcon(self):
|
||||
assert not self._retracted
|
||||
pep = self._pep_specific_data
|
||||
activity = pep['activity']
|
||||
|
||||
has_known_activity = activity in ACTIVITIES
|
||||
has_known_subactivity = (has_known_activity and ('subactivity' in pep)
|
||||
and (pep['subactivity'] in ACTIVITIES[activity]))
|
||||
|
||||
if has_known_activity:
|
||||
if has_known_subactivity:
|
||||
subactivity = pep['subactivity']
|
||||
return gtkgui_helpers.load_activity_icon(activity, subactivity).get_pixbuf()
|
||||
else:
|
||||
return gtkgui_helpers.load_activity_icon(activity).get_pixbuf()
|
||||
else:
|
||||
return gtkgui_helpers.load_activity_icon('unknown').get_pixbuf()
|
||||
|
||||
def asMarkupText(self):
|
||||
assert not self._retracted
|
||||
pep = self._pep_specific_data
|
||||
activity = pep['activity']
|
||||
subactivity = pep['subactivity'] if 'subactivity' in pep else None
|
||||
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']
|
||||
|
||||
markuptext = '<b>' + gobject.markup_escape_text(activity)
|
||||
if subactivity:
|
||||
markuptext += ': ' + gobject.markup_escape_text(subactivity)
|
||||
markuptext += '</b>'
|
||||
if text:
|
||||
markuptext += ' (%s)' + gobject.markup_escape_text(text)
|
||||
return markuptext
|
||||
|
||||
|
||||
class UserNicknamePEP(AbstractPEP):
|
||||
'''XEP-0172: User Nickname'''
|
||||
|
@ -404,7 +449,7 @@ class UserNicknamePEP(AbstractPEP):
|
|||
# TODO: use dict instead
|
||||
if self._retracted:
|
||||
common.gajim.nicks[account] = common.gajim.config.get_per('accounts',
|
||||
account, 'name')
|
||||
account, 'name')
|
||||
else:
|
||||
common.gajim.nicks[account] = self._pep_specific_data
|
||||
|
||||
|
|
|
@ -1299,20 +1299,8 @@ class RosterWindow:
|
|||
jid = self.model[iters[0]][C_JID]
|
||||
jid = jid.decode('utf-8')
|
||||
contact = gajim.contacts.get_contact(account, jid)
|
||||
if 'activity' in contact.activity \
|
||||
and contact.activity['activity'].strip() in ACTIVITIES:
|
||||
if 'subactivity' in contact.activity \
|
||||
and contact.activity['subactivity'].strip() in \
|
||||
ACTIVITIES[contact.activity['activity'].strip()]:
|
||||
pixbuf = gtkgui_helpers.load_activity_icon(
|
||||
contact.activity['activity'].strip(),
|
||||
contact.activity['subactivity'].strip()).get_pixbuf()
|
||||
else:
|
||||
pixbuf = gtkgui_helpers.load_activity_icon(
|
||||
contact.activity['activity'].strip()).get_pixbuf()
|
||||
elif 'activity' in contact.activity:
|
||||
pixbuf = gtkgui_helpers.load_activity_icon(
|
||||
'unknown').get_pixbuf()
|
||||
if 'activity' in contact.pep:
|
||||
pixbuf = contact.pep['activity'].asPixbufIcon()
|
||||
else:
|
||||
pixbuf = None
|
||||
for child_iter in iters:
|
||||
|
@ -1327,9 +1315,8 @@ class RosterWindow:
|
|||
jid = self.model[iters[0]][C_JID]
|
||||
jid = jid.decode('utf-8')
|
||||
contact = gajim.contacts.get_contact(account, jid)
|
||||
if 'artist' in contact.tune or 'title' in contact.tune:
|
||||
path = os.path.join(gajim.DATA_DIR, 'emoticons', 'static', 'music.png')
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
|
||||
if 'tune' in contact.pep:
|
||||
pixbuf = contact.pep['tune'].asPixbufIcon()
|
||||
else:
|
||||
pixbuf = None
|
||||
for child_iter in iters:
|
||||
|
|
|
@ -581,32 +581,12 @@ class RosterTooltip(NotificationAreaTooltip):
|
|||
'''
|
||||
if 'mood' in contact.pep:
|
||||
mood = contact.pep['mood'].asMarkupText()
|
||||
mood_string = _('Mood:') + ' <b>%s</b>' % mood
|
||||
mood_string = _('Mood:') + ' %s' % mood
|
||||
properties.append((mood_string, None))
|
||||
|
||||
if 'activity' in contact.activity:
|
||||
activity = act_plain = \
|
||||
contact.activity['activity'].strip()
|
||||
activity = gobject.markup_escape_text(activity)
|
||||
if act_plain in ACTIVITIES:
|
||||
activity = ACTIVITIES[activity]['category']
|
||||
activity_string = _('Activity:') + ' <b>%s' % activity
|
||||
if 'subactivity' in contact.activity:
|
||||
activity_sub = \
|
||||
contact.activity['subactivity'].strip()
|
||||
if act_plain in ACTIVITIES and activity_sub in \
|
||||
ACTIVITIES[act_plain]:
|
||||
activity_sub = ACTIVITIES[act_plain][activity_sub]
|
||||
activity_sub = \
|
||||
gobject.markup_escape_text(activity_sub)
|
||||
activity_string += ': %s</b>' % activity_sub
|
||||
else:
|
||||
activity_string += '</b>'
|
||||
if 'text' in contact.activity:
|
||||
activity_text = contact.activity['text'].strip()
|
||||
activity_text = gobject.markup_escape_text(
|
||||
activity_text)
|
||||
activity_string += ' (%s)' % activity_text
|
||||
if 'activity' in contact.pep:
|
||||
activity = contact.pep['activity'].asMarkupText()
|
||||
activity_string = _('Activity:') + ' %s' % activity
|
||||
properties.append((activity_string, None))
|
||||
|
||||
if 'tune' in contact.pep:
|
||||
|
|
Loading…
Reference in New Issue