Commit 5c323047 authored by steve-e's avatar steve-e

Merge PEP refactorings back to the default branch.

parents 1c28dbfa 8b3a82ff
......@@ -1279,14 +1279,12 @@ class ChatControl(ChatControlBase):
self.video_state = self.JINGLE_STATE_NOT_AVAILABLE
self.update_toolbar()
self._mood_image = self.xml.get_widget('mood_image')
self._activity_image = self.xml.get_widget('activity_image')
self._tune_image = self.xml.get_widget('tune_image')
self.update_mood()
self.update_activity()
self.update_tune()
self._pep_images = {}
self._pep_images['mood'] = self.xml.get_widget('mood_image')
self._pep_images['activity'] = self.xml.get_widget('activity_image')
self._pep_images['tune'] = self.xml.get_widget('tune_image')
self.update_all_pep_types()
# keep timeout id and window obj for possible big avatar
# it is on enter-notify and leave-notify so no need to be
......@@ -1430,118 +1428,24 @@ class ChatControl(ChatControlBase):
self._convert_to_gc_button.set_sensitive(True)
else:
self._convert_to_gc_button.set_sensitive(False)
def update_all_pep_types(self):
for pep_type in self._pep_images:
self.update_pep(pep_type)
def update_mood(self):
mood = None
text = None
def update_pep(self, pep_type):
if isinstance(self.contact, GC_Contact):
return
if 'mood' in self.contact.mood:
mood = self.contact.mood['mood'].strip()
if 'text' in self.contact.mood:
text = self.contact.mood['text'].strip()
if mood is not None:
if mood in MOODS:
self._mood_image.set_from_pixbuf(gtkgui_helpers.load_mood_icon(
mood).get_pixbuf())
# Translate standard moods
mood = MOODS[mood]
else:
self._mood_image.set_from_pixbuf(gtkgui_helpers.load_mood_icon(
'unknown').get_pixbuf())
mood = gobject.markup_escape_text(mood)
tooltip = '<b>%s</b>' % mood
if text:
text = gobject.markup_escape_text(text)
tooltip += '\n' + text
self._mood_image.set_tooltip_markup(tooltip)
self._mood_image.show()
else:
self._mood_image.hide()
def update_activity(self):
activity = None
subactivity = None
text = None
if isinstance(self.contact, GC_Contact):
if pep_type not in self._pep_images:
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)
self._activity_image.show()
else:
self._activity_image.hide()
def update_tune(self):
artist = None
title = None
source = None
if isinstance(self.contact, GC_Contact):
return
if 'artist' in self.contact.tune:
artist = self.contact.tune['artist'].strip()
artist = gobject.markup_escape_text(artist)
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()
pep = self.contact.pep
img = self._pep_images[pep_type]
if pep_type in pep:
img.set_from_pixbuf(pep[pep_type].asPixbufIcon())
img.set_tooltip_markup(pep[pep_type].asMarkupText())
img.show()
else:
self._tune_image.hide()
img.hide()
def _update_jingle(self, jingle_type):
if jingle_type not in ('audio', 'video'):
......
......@@ -168,9 +168,7 @@ class Connection(ConnectionHandlers):
self.pubsub_supported = False
self.pubsub_publish_options_supported = False
self.pep_supported = False
self.mood = {}
self.tune = {}
self.activity = {}
self.pep = {}
# Do we continue connection when we get roster (send presence,get vcard..)
self.continue_connect_info = None
# Do we auto accept insecure connection
......
......@@ -46,11 +46,10 @@ import common.xmpp
from common import helpers
from common import gajim
from common import atom
from common import pep
from common import exceptions
from common.commands import ConnectionCommands
from common.pubsub import ConnectionPubSub
from common.pep import ConnectionPEP
from common.caps import ConnectionCaps
if gajim.HAVE_FARSIGHT:
from common.jingle import ConnectionJingle
......@@ -1453,7 +1452,7 @@ sent a message to.'''
return sess
class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionPEP, ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
def __init__(self):
ConnectionVcard.__init__(self)
ConnectionBytestream.__init__(self)
......@@ -1874,15 +1873,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
def _messageCB(self, con, msg):
'''Called when we receive a message'''
log.debug('MessageCB')
mtype = msg.getType()
# check if the message is pubsub#event
if msg.getTag('event') is not None:
if mtype == 'groupchat':
return
if msg.getTag('error') is None:
self._pubsubEventCB(con, msg)
return
# check if the message is a roster item exchange (XEP-0144)
if msg.getTag('x', namespace=common.xmpp.NS_ROSTERX):
......@@ -2148,42 +2139,6 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
self.dispatch('GC_INVITATION',(frm, jid_from, reason, password,
is_continued))
def _pubsubEventCB(self, con, msg):
''' Called when we receive <message/> with pubsub event. '''
# 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 = msg.getTag('event')
# XEP-0107: User Mood
items = event.getTag('items', {'node': common.xmpp.NS_MOOD})
if items: pep.user_mood(items, self.name, jid)
# XEP-0118: User Tune
items = event.getTag('items', {'node': common.xmpp.NS_TUNE})
if items: pep.user_tune(items, self.name, jid)
# XEP-0080: User Geolocation
items = event.getTag('items', {'node': common.xmpp.NS_GEOLOC})
if items: pep.user_geoloc(items, self.name, jid)
# XEP-0108: User Activity
items = event.getTag('items', {'node': common.xmpp.NS_ACTIVITY})
if items: pep.user_activity(items, self.name, jid)
# XEP-0172: User Nickname
items = event.getTag('items', {'node': common.xmpp.NS_NICK})
if items: pep.user_nickname(items, self.name, jid)
items = event.getTag('items')
if items is None: return
for item in items.getTags('item'):
entry = item.getTag('entry')
if entry is not None:
# 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
raise common.xmpp.NodeProcessed
def _presenceCB(self, con, prs):
'''Called when we receive a presence'''
ptype = prs.getType()
......@@ -2751,6 +2706,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
con.RegisterHandler('message', self._messageCB)
con.RegisterHandler('presence', self._presenceCB)
con.RegisterHandler('presence', self._capsPresenceCB)
con.RegisterHandler('message', self._pubsubEventCB,
ns=common.xmpp.NS_PUBSUB_EVENT)
con.RegisterHandler('iq', self._vCardCB, 'result',
common.xmpp.NS_VCARD)
con.RegisterHandler('iq', self._rosterSetCB, 'set',
......
......@@ -94,7 +94,7 @@ class Contact(CommonContact):
def __init__(self, jid, account, name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=0, keyID='', client_caps=None,
our_chatstate=None, chatstate=None, last_status_time=None, msg_id = None,
composing_xep=None, mood={}, tune={}, activity={}):
composing_xep=None):
CommonContact.__init__(self, jid, account, resource, show, status, name,
our_chatstate, composing_xep, chatstate, client_caps=client_caps)
......@@ -110,9 +110,7 @@ class Contact(CommonContact):
self.msg_id = msg_id
self.last_status_time = last_status_time
self.mood = mood.copy()
self.tune = tune.copy()
self.activity = activity.copy()
self.pep = {}
def get_full_jid(self):
if self.resource:
......@@ -229,23 +227,25 @@ class Contacts:
def create_contact(self, jid, account, name='', groups=[], show='', status='',
sub='', ask='', resource='', priority=0, keyID='', client_caps=None,
our_chatstate=None, chatstate=None, last_status_time=None,
composing_xep=None, mood={}, tune={}, activity={}):
composing_xep=None):
account = self._accounts.get(account, account) # Use Account object if available
return Contact(jid=jid, account=account, name=name, groups=groups,
show=show, status=status, sub=sub, ask=ask, resource=resource, priority=priority,
keyID=keyID, client_caps=client_caps, our_chatstate=our_chatstate,
chatstate=chatstate, last_status_time=last_status_time,
composing_xep=composing_xep, mood=mood, tune=tune, activity=activity)
composing_xep=composing_xep)
def create_self_contact(self, jid, account, resource, show, status, priority, keyID=''):
def create_self_contact(self, jid, account, resource, show, status, priority,
name='', keyID=''):
conn = common.gajim.connections[account]
nick = common.gajim.nicks[account]
nick = name or common.gajim.nicks[account]
account = self._accounts.get(account, account) # Use Account object if available
return self.create_contact(jid=jid, account=account,
self_contact = self.create_contact(jid=jid, account=account,
name=nick, groups=['self_contact'], show=show, status=status,
sub='both', ask='none', priority=priority, keyID=keyID,
resource=resource, mood=conn.mood, tune=conn.tune,
activity=conn.activity)
resource=resource)
self_contact.pep = conn.pep
return self_contact
def create_not_in_roster_contact(self, jid, account, resource='', name='', keyID=''):
account = self._accounts.get(account, account) # Use Account object if available
......
......@@ -569,8 +569,6 @@ def datetime_tuple(timestamp):
# import gajim only when needed (after decode_string is defined) see #4764
import gajim
import pep
def convert_bytes(string):
suffix = ''
......@@ -777,53 +775,6 @@ def get_global_status():
status = gajim.connections[account].status
return status
def get_pep_dict(account):
pep_dict = {}
con = gajim.connections[account]
# activity
if 'activity' in con.activity and con.activity['activity'] in pep.ACTIVITIES:
activity = con.activity['activity']
if 'subactivity' in con.activity and con.activity['subactivity'] in \
pep.ACTIVITIES[activity]:
subactivity = con.activity['subactivity']
else:
subactivity = 'other'
else:
activity = ''
subactivity = ''
if 'text' in con.activity:
text = con.activity['text']
else:
text = ''
pep_dict['activity'] = activity
pep_dict['subactivity'] = subactivity
pep_dict['activity_text'] = text
# mood
if 'mood' in con.mood and con.mood['mood'] in pep.MOODS:
mood = con.mood['mood']
else:
mood = ''
if 'text' in con.mood:
text = con.mood['text']
else:
text = ''
pep_dict['mood'] = mood
pep_dict['mood_text'] = text
return pep_dict
def get_global_pep():
maxi = 0
pep_dict = {'activity': '', 'mood': ''}
for account in gajim.connections:
if not gajim.config.get_per('accounts', account,
'sync_with_global_status'):
continue
connected = gajim.connections[account].connected
if connected > maxi:
maxi = connected
pep_dict = get_pep_dict(account)
return pep_dict
def statuses_unified():
'''testing if all statuses are the same.'''
......
This diff is collapsed.
......@@ -247,25 +247,23 @@ class XMPPDispatcher(PlugIn):
'''
Register user callback as stanzas handler of declared type.
Callback must take (if chained, see later) arguments:
Callback arguments:
dispatcher instance (for replying), incoming return of previous handlers.
The callback must raise xmpp.NodeProcessed just before return if it wants
other callbacks to be called with the same stanza as argument _and_, more
importantly library from returning stanza to sender with error set.
to prevent other callbacks to be called with the same stanza as argument
_and_, more importantly library from returning stanza to sender with error set.
:param name: name of stanza. F.e. "iq".
:param handler: user callback.
:param typ: value of stanza's "type" attribute. If not specified any
value will match
:param ns: namespace of child that stanza must contain.
:param chained: chain together output of several handlers.
:param makefirst: insert handler in the beginning of handlers list instea
:param makefirst: insert handler in the beginning of handlers list instead
of adding it to the end. Note that more common handlers i.e. w/o "typ"
and " will be called first nevertheless.
:param system: call handler even if NodeProcessed Exception were raised
already.
'''
# FIXME: What does chain mean and where is it handled?
if not xmlns:
xmlns=self._owner.defaultNamespace
log.debug('Registering handler %s for "%s" type->%s ns->%s(%s)' %
......
......@@ -88,6 +88,7 @@ NS_PRIVACY ='jabber:iq:privacy'
NS_PRIVATE ='jabber:iq:private'
NS_PROFILE ='http://jabber.org/protocol/profile' # XEP-0154
NS_PUBSUB ='http://jabber.org/protocol/pubsub' # XEP-0060
NS_PUBSUB_EVENT = 'http://jabber.org/protocol/pubsub#event'
NS_PUBSUB_PUBLISH_OPTIONS = NS_PUBSUB + '#publish-options' # XEP-0060
NS_PUBSUB_OWNER ='http://jabber.org/protocol/pubsub#owner' # JEP-0060
NS_REGISTER ='jabber:iq:register'
......
......@@ -88,9 +88,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.no_log_for = False
self.pep_supported = False
self.mood = {}
self.tune = {}
self.activity = {}
self.pep = {}
# Do we continue connection when we get roster (send presence,get vcard...)
self.continue_connect_info = None
if gajim.HAVE_GPG:
......
......@@ -1989,6 +1989,27 @@ class Interface:
_('PEP node %(node)s was not removed: %(message)s') % {
'node': data[1], 'message': data[2]})
def handle_event_pep_received(self, account, data):
# ('PEP_RECEIVED', account, (jid, pep_type))
jid = data[0]
pep_type = data[1]
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, account)
if jid == common.gajim.get_jid_from_account(account):
self.roster.draw_account(account)
if pep_type == 'nickname':
self.roster.draw_contact(jid, account)
if ctrl:
ctrl.update_ui()
win = ctrl.parent_win
win.redraw_tab(ctrl)
win.show_title()
else:
self.roster.draw_pep(jid, account, pep_type)
if ctrl:
ctrl.update_pep(pep_type)
def register_handler(self, event, handler):
if event not in self.handlers:
self.handlers[event] = []
......@@ -2088,6 +2109,7 @@ class Interface:
'JINGLE_CONNECTED': [self.handle_event_jingle_connected],
'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected],
'JINGLE_ERROR': [self.handle_event_jingle_error],
'PEP_RECEIVED': [self.handle_event_pep_received]
}
def dispatch(self, event, account, data):
......@@ -2774,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):
......
......@@ -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
......
This diff is collapsed.
......@@ -579,65 +579,19 @@ class RosterTooltip(NotificationAreaTooltip):
Append Tune, Mood, Activity information of the specified contact
to the given property list.
'''
if 'mood' in contact.mood:
mood = contact.mood['mood'].strip()
mood = MOODS.get(mood, mood)
mood = gobject.markup_escape_text(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
if 'mood' in contact.pep:
mood = contact.pep['mood'].asMarkupText()
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 'artist' in contact.tune \
or 'title' in contact.tune:
if 'artist' in contact.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}
if 'tune' in contact.pep:
tune = contact.pep['tune'].asMarkupText()
tune_string = _('Tune:') + ' %s' % tune
properties.append((tune_string, None))
......
......@@ -14,9 +14,7 @@ class MockConnection(Mock, ConnectionHandlersBase):
self.name = account
self.connected = 2
self.mood = {}
self.activity = {}
self.tune = {}
self.pep = {}
self.blocked_contacts = {}
self.blocked_groups = {}
self.sessions = {}
......
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