Commit 19761f08 authored by Yann Leboulanger's avatar Yann Leboulanger

[js & I] show pep info in account tooltip, fix a bug in create_contact()

parent 192669b6
......@@ -5,9 +5,7 @@ Tune use cases:
• on disconnection of an account set Tune to None
Tooltips use cases:
• Show PEP in contact tooltips
• Show PEP in GC tooltips
• Show PEP in account tooltips
Mood/Activity use cases
• on connection of an account set them to None
......
......@@ -142,6 +142,9 @@ class Connection(ConnectionHandlers):
self.blocked_contacts = []
self.blocked_groups = []
self.pep_supported = False
self.mood = {}
self.tune = {}
self.activity = {}
# Do we continue connection when we get roster (send presence,get vcard..)
self.continue_connect_info = None
# To know the groupchat jid associated with a sranza ID. Useful to
......
......@@ -27,17 +27,14 @@ class Contact:
'''Information concerning each contact'''
def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=0, keyID='', our_chatstate=None,
chatstate=None, last_status_time=None, msg_id = None, composing_xep = None):
chatstate=None, last_status_time=None, msg_id = None, composing_xep = None,
mood={}, tune={}, activity={}):
self.jid = jid
self.name = name
self.contact_name = '' # nick choosen by contact
self.groups = groups
self.show = show
self.status = status
# FIXME
self.mood = dict()
self.activity = dict()
self.tune = dict()
self.sub = sub
self.ask = ask
self.resource = resource
......@@ -67,6 +64,10 @@ class Contact:
self.chatstate = chatstate
self.last_status_time = last_status_time
self.mood = mood.copy()
self.tune = tune.copy()
self.activity = activity.copy()
def get_full_jid(self):
if self.resource:
return self.jid + '/' + self.resource
......@@ -166,10 +167,11 @@ class Contacts:
def create_contact(self, jid='', name='', groups=[], show='', status='',
sub='', ask='', resource='', priority=0, keyID='', our_chatstate=None,
chatstate=None, last_status_time=None, composing_xep=None):
chatstate=None, last_status_time=None, composing_xep=None,
mood={}, tune={}, activity={}):
return Contact(jid, name, groups, show, status, sub, ask, resource,
priority, keyID, our_chatstate, chatstate, last_status_time,
composing_xep)
None, composing_xep, mood, tune, activity)
def copy_contact(self, contact):
return self.create_contact(jid = contact.jid, name = contact.name,
......
from common import gajim, xmpp
def user_mood(items, name, jid):
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contact = gajim.contacts.get_contact(name, user, resource=resource)
if not contact:
return
has_child = False
mood = None
text = None
for item in items.getTags('item'):
child = item.getTag('mood')
if child is not None:
if contact.mood.has_key('mood'):
del contact.mood['mood']
if contact.mood.has_key('text'):
del contact.mood['text']
has_child = True
for ch in child.getChildren():
if ch.getName() != 'text':
contact.mood['mood'] = ch.getName()
mood = ch.getName()
else:
contact.mood['text'] = ch.getData()
text = ch.getData()
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
if has_child:
if acc.mood.has_key('mood'):
del acc.mood['mood']
if acc.mood.has_key('text'):
del acc.mood['text']
if mood != None:
acc.mood['mood'] = mood
if text != None:
acc.mood['text'] = text
def user_tune(items, name, jid):
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contact = gajim.contacts.get_contact(name, user, resource=resource)
if not contact:
return
if has_child:
if contact.mood.has_key('mood'):
del contact.mood['mood']
if contact.mood.has_key('text'):
del contact.mood['text']
if mood != None:
contact.mood['mood'] = mood
if text != None:
contact.mood['text'] = text
def user_tune(items, name, jid):
has_child = False
artist = None
title = None
source = None
track = None
length = None
for item in items.getTags('item'):
child = item.getTag('tune')
if child is not None:
if contact.tune.has_key('artist'):
del contact.tune['artist']
if contact.tune.has_key('title'):
del contact.tune['title']
if contact.tune.has_key('source'):
del contact.tune['source']
if contact.tune.has_key('track'):
del contact.tune['track']
if contact.tune.has_key('length'):
del contact.tune['length']
has_child = True
for ch in child.getChildren():
if ch.getName() == 'artist':
contact.tune['artist'] = ch.getData()
artist = ch.getData()
elif ch.getName() == 'title':
contact.tune['title'] = ch.getData()
title = ch.getData()
elif ch.getName() == 'source':
contact.tune['source'] = ch.getData()
source = ch.getData()
elif ch.getName() == 'track':
contact.tune['track'] = ch.getData()
track = ch.getData()
elif ch.getName() == 'length':
contact.tune['length'] = ch.getData()
length = ch.getData()
def user_geoloc(items, name, jid):
pass
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
if has_child:
if acc.tune.has_key('artist'):
del acc.tune['artist']
if acc.tune.has_key('title'):
del acc.tune['title']
if acc.tune.has_key('source'):
del acc.tune['source']
if acc.tune.has_key('track'):
del acc.tune['track']
if acc.tune.has_key('length'):
del acc.tune['length']
if artist != None:
acc.tune['artist'] = artist
if title != None:
acc.tune['title'] = title
if source != None:
acc.tune['source'] = source
if track != None:
acc.tune['track'] = track
if length != None:
acc.tune['length'] = length
def user_activity(items, name, jid):
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contact = gajim.contacts.get_contact(name, user, resource=resource)
if not contact:
return
if has_child:
if contact.tune.has_key('artist'):
del contact.tune['artist']
if contact.tune.has_key('title'):
del contact.tune['title']
if contact.tune.has_key('source'):
del contact.tune['source']
if contact.tune.has_key('track'):
del contact.tune['track']
if contact.tune.has_key('length'):
del contact.tune['length']
if artist != None:
contact.tune['artist'] = artist
if title != None:
contact.tune['title'] = title
if source != None:
contact.tune['source'] = source
if track != None:
contact.tune['track'] = track
if length != None:
contact.tune['length'] = length
def user_geoloc(items, name, jid):
pass
def user_activity(items, name, jid):
has_child = False
activity = None
subactivity = None
text = None
for item in items.getTags('item'):
child = item.getTag('activity')
if child is not None:
if contact.activity.has_key('activity'):
del contact.activity['activity']
if contact.activity.has_key('subactivity'):
del contact.activity['subactivity']
if contact.activity.has_key('text'):
del contact.activity['text']
has_child = True
for ch in child.getChildren():
if ch.getName() != 'text':
contact.activity['activity'] = ch.getName()
activity = ch.getName()
for chi in ch.getChildren():
contact.activity['subactivity'] = chi.getName()
subactivity = chi.getName()
else:
contact.activity['text'] = ch.getData()
text = ch.getData()
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
if has_child:
if acc.activity.has_key('activity'):
del acc.activity['activity']
if acc.activity.has_key('subactivity'):
del acc.activity['subactivity']
if acc.activity.has_key('text'):
del acc.activity['text']
if activity != None:
acc.activity['activity'] = activity
if subactivity != None:
acc.activity['subactivity'] = subactivity
if text != None:
acc.activity['text'] = text
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contact = gajim.contacts.get_contact(name, user, resource=resource)
if not contact:
return
if has_child:
if contact.activity.has_key('activity'):
del contact.activity['activity']
if contact.activity.has_key('subactivity'):
del contact.activity['subactivity']
if contact.activity.has_key('text'):
del contact.activity['text']
if activity != None:
contact.activity['activity'] = activity
if subactivity != None:
contact.activity['subactivity'] = subactivity
if text != None:
contact.activity['text'] = text
def user_send_mood(account, mood, message = ''):
if gajim.config.get('publish_mood') == False:
......
......@@ -86,6 +86,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.no_log_for = False
self.pep_supported = False
self.mood = {}
self.tune = {}
self.activity = {}
# Do we continue connection when we get roster (send presence,get vcard...)
self.continue_connect_info = None
if USE_GPG:
......
......@@ -1530,7 +1530,10 @@ class RosterWindow:
name = account_name, show = connection.get_status(), sub = '',
status = connection.status,
resource = connection.server_resource,
priority = connection.priority)
priority = connection.priority,
mood = connection.mood,
tune = connection.tune,
activity = connection.activity)
if gajim.connections[account].gpg:
contact.keyID = gajim.config.get_per('accounts', connection.name,
'keyid')
......
......@@ -500,14 +500,14 @@ class RosterTooltip(NotificationAreaTooltip):
# we append show below
if contact.mood.has_key('mood'):
mood_string = 'Mood: <b>%s</b>' % contact.mood['mood'].strip()
mood_string = _('Mood:') + ' <b>%s</b>' % contact.mood['mood'].strip()
if contact.mood.has_key('text') and contact.mood['text'] != '':
mood_string += ' (%s)' % contact.mood['text'].strip()
properties.append((mood_string, None))
if contact.activity.has_key('activity'):
activity = contact.activity['activity'].strip()
activity_string = 'Activity: <b>%s' % activity
activity_string = _('Activity:') + ' <b>%s' % activity
if contact.activity.has_key('subactivity'):
activity_sub = contact.activity['subactivity'].strip()
activity_string += ' (%s)</b>' % activity_sub
......@@ -531,8 +531,8 @@ class RosterTooltip(NotificationAreaTooltip):
source = contact.tune['source'].strip()
else:
source = _('Unknown Source')
tune_string = '♪ ' + _('<b>"%(title)s"</b> by <i>%(artist)s</i>\nfrom <i>%(source)s</i>' %\
{'title': title, 'artist': artist, 'source': source}) + ' ♪'
tune_string = _('Tune:') + ' ' + _('<b>"%(title)s"</b> by <i>%(artist)s</i>\nfrom <i>%(source)s</i>' %\
{'title': title, 'artist': artist, 'source': source})
properties.append((tune_string, None))
if contact.status:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment