2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:39:27 +02:00
|
|
|
## src/common/pep.py
|
|
|
|
##
|
|
|
|
## Copyright (C) 2007 Piotr Gaczkowski <doomhammerng AT gmail.com>
|
|
|
|
## Copyright (C) 2007-2008 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jean-Marie Traissard <jim AT lapin.org>
|
2009-04-12 20:13:37 +02:00
|
|
|
## Jonathan Schleifer <js-common.gajim AT webkeks.org>
|
2008-08-15 05:39:27 +02:00
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
##
|
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 3 only.
|
|
|
|
##
|
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
import common.gajim
|
|
|
|
from common import xmpp
|
2007-03-26 00:27:43 +02:00
|
|
|
|
2008-07-29 21:02:57 +02:00
|
|
|
MOODS = {
|
2008-10-30 20:01:26 +01:00
|
|
|
'afraid': _('Afraid'),
|
|
|
|
'amazed': _('Amazed'),
|
|
|
|
'amorous': _('Amorous'),
|
|
|
|
'angry': _('Angry'),
|
|
|
|
'annoyed': _('Annoyed'),
|
|
|
|
'anxious': _('Anxious'),
|
|
|
|
'aroused': _('Aroused'),
|
|
|
|
'ashamed': _('Ashamed'),
|
|
|
|
'bored': _('Bored'),
|
|
|
|
'brave': _('Brave'),
|
|
|
|
'calm': _('Calm'),
|
|
|
|
'cautious': _('Cautious'),
|
|
|
|
'cold': _('Cold'),
|
|
|
|
'confident': _('Confident'),
|
|
|
|
'confused': _('Confused'),
|
|
|
|
'contemplative': _('Contemplative'),
|
|
|
|
'contented': _('Contented'),
|
|
|
|
'cranky': _('Cranky'),
|
|
|
|
'crazy': _('Crazy'),
|
|
|
|
'creative': _('Creative'),
|
|
|
|
'curious': _('Curious'),
|
|
|
|
'dejected': _('Dejected'),
|
|
|
|
'depressed': _('Depressed'),
|
|
|
|
'disappointed': _('Disappointed'),
|
|
|
|
'disgusted': _('Disgusted'),
|
|
|
|
'dismayed': _('Dismayed'),
|
|
|
|
'distracted': _('Distracted'),
|
|
|
|
'embarrassed': _('Embarrassed'),
|
|
|
|
'envious': _('Envious'),
|
|
|
|
'excited': _('Excited'),
|
|
|
|
'flirtatious': _('Flirtatious'),
|
|
|
|
'frustrated': _('Frustrated'),
|
|
|
|
'grateful': _('Grateful'),
|
|
|
|
'grieving': _('Grieving'),
|
|
|
|
'grumpy': _('Grumpy'),
|
|
|
|
'guilty': _('Guilty'),
|
|
|
|
'happy': _('Happy'),
|
|
|
|
'hopeful': _('Hopeful'),
|
|
|
|
'hot': _('Hot'),
|
|
|
|
'humbled': _('Humbled'),
|
|
|
|
'humiliated': _('Humiliated'),
|
|
|
|
'hungry': _('Hungry'),
|
|
|
|
'hurt': _('Hurt'),
|
|
|
|
'impressed': _('Impressed'),
|
2008-10-30 22:49:49 +01:00
|
|
|
'in_awe': _('In Awe'),
|
|
|
|
'in_love': _('In Love'),
|
2008-10-30 20:01:26 +01:00
|
|
|
'indignant': _('Indignant'),
|
|
|
|
'interested': _('Interested'),
|
|
|
|
'intoxicated': _('Intoxicated'),
|
|
|
|
'invincible': _('Invincible'),
|
|
|
|
'jealous': _('Jealous'),
|
|
|
|
'lonely': _('Lonely'),
|
|
|
|
'lost': _('Lost'),
|
|
|
|
'lucky': _('Lucky'),
|
|
|
|
'mean': _('Mean'),
|
|
|
|
'moody': _('Moody'),
|
|
|
|
'nervous': _('Nervous'),
|
|
|
|
'neutral': _('Neutral'),
|
|
|
|
'offended': _('Offended'),
|
|
|
|
'outraged': _('Outraged'),
|
|
|
|
'playful': _('Playful'),
|
|
|
|
'proud': _('Proud'),
|
|
|
|
'relaxed': _('Relaxed'),
|
|
|
|
'relieved': _('Relieved'),
|
|
|
|
'remorseful': _('Remorseful'),
|
|
|
|
'restless': _('Restless'),
|
|
|
|
'sad': _('Sad'),
|
|
|
|
'sarcastic': _('Sarcastic'),
|
|
|
|
'satisfied': _('Satisfied'),
|
|
|
|
'serious': _('Serious'),
|
|
|
|
'shocked': _('Shocked'),
|
|
|
|
'shy': _('Shy'),
|
|
|
|
'sick': _('Sick'),
|
|
|
|
'sleepy': _('Sleepy'),
|
|
|
|
'spontaneous': _('Spontaneous'),
|
|
|
|
'stressed': _('Stressed'),
|
|
|
|
'strong': _('Strong'),
|
|
|
|
'surprised': _('Surprised'),
|
|
|
|
'thankful': _('Thankful'),
|
|
|
|
'thirsty': _('Thirsty'),
|
|
|
|
'tired': _('Tired'),
|
|
|
|
'undefined': _('Undefined'),
|
|
|
|
'weak': _('Weak'),
|
|
|
|
'worried': _('Worried')}
|
2008-07-22 23:08:52 +02:00
|
|
|
|
2008-07-28 22:57:56 +02:00
|
|
|
ACTIVITIES = {
|
2008-07-29 21:42:31 +02:00
|
|
|
'doing_chores': {'category': _('Doing Chores'),
|
|
|
|
'buying_groceries': _('Buying Groceries'),
|
|
|
|
'cleaning': _('Cleaning'),
|
|
|
|
'cooking': _('Cooking'),
|
|
|
|
'doing_maintenance': _('Doing Maintenance'),
|
|
|
|
'doing_the_dishes': _('Doing the Dishes'),
|
|
|
|
'doing_the_laundry': _('Doing the Laundry'),
|
|
|
|
'gardening': _('Gardening'),
|
|
|
|
'running_an_errand': _('Running an Errand'),
|
|
|
|
'walking_the_dog': _('Walking the Dog')},
|
|
|
|
'drinking': {'category': _('Drinking'),
|
|
|
|
'having_a_beer': _('Having a Beer'),
|
|
|
|
'having_coffee': _('Having Coffee'),
|
|
|
|
'having_tea': _('Having Tea')},
|
|
|
|
'eating': {'category': _('Eating'),
|
|
|
|
'having_a_snack': _('Having a Snack'),
|
|
|
|
'having_breakfast': _('Having Breakfast'),
|
|
|
|
'having_dinner': _('Having Dinner'),
|
|
|
|
'having_lunch': _('Having Lunch')},
|
|
|
|
'exercising': {'category': _('Exercising'),
|
|
|
|
'cycling': _('Cycling'),
|
2008-11-08 23:26:05 +01:00
|
|
|
'dancing': _('Dancing'),
|
2008-07-29 21:42:31 +02:00
|
|
|
'hiking': _('Hiking'),
|
|
|
|
'jogging': _('Jogging'),
|
|
|
|
'playing_sports': _('Playing Sports'),
|
|
|
|
'running': _('Running'),
|
|
|
|
'skiing': _('Skiing'),
|
|
|
|
'swimming': _('Swimming'),
|
|
|
|
'working_out': _('Working out')},
|
|
|
|
'grooming': {'category': _('Grooming'),
|
|
|
|
'at_the_spa': _('At the Spa'),
|
|
|
|
'brushing_teeth': _('Brushing Teeth'),
|
|
|
|
'getting_a_haircut': _('Getting a Haircut'),
|
|
|
|
'shaving': _('Shaving'),
|
|
|
|
'taking_a_bath': _('Taking a Bath'),
|
|
|
|
'taking_a_shower': _('Taking a Shower')},
|
|
|
|
'having_appointment': {'category': _('Having an Appointment')},
|
|
|
|
'inactive': {'category': _('Inactive'),
|
|
|
|
'day_off': _('Day Off'),
|
2008-08-09 18:40:48 +02:00
|
|
|
'hanging_out': _('Hanging out'),
|
2008-11-08 23:26:05 +01:00
|
|
|
'hiding': _('Hiding'),
|
2008-07-29 21:42:31 +02:00
|
|
|
'on_vacation': _('On Vacation'),
|
2008-11-08 23:26:05 +01:00
|
|
|
'praying': _('Praying'),
|
2008-07-29 21:42:31 +02:00
|
|
|
'scheduled_holiday': _('Scheduled Holiday'),
|
2008-11-08 23:26:05 +01:00
|
|
|
'sleeping': _('Sleeping'),
|
|
|
|
'thinking': _('Thinking')},
|
2008-07-29 21:42:31 +02:00
|
|
|
'relaxing': {'category': _('Relaxing'),
|
2008-11-08 23:26:05 +01:00
|
|
|
'fishing': _('Fishing'),
|
2008-07-29 21:42:31 +02:00
|
|
|
'gaming': _('Gaming'),
|
|
|
|
'going_out': _('Going out'),
|
|
|
|
'partying': _('Partying'),
|
|
|
|
'reading': _('Reading'),
|
|
|
|
'rehearsing': _('Rehearsing'),
|
|
|
|
'shopping': _('Shopping'),
|
2008-11-08 23:26:05 +01:00
|
|
|
'smoking': _('Smoking'),
|
2008-07-29 21:42:31 +02:00
|
|
|
'socializing': _('Socializing'),
|
|
|
|
'sunbathing': _('Sunbathing'),
|
|
|
|
'watching_tv': _('Watching TV'),
|
|
|
|
'watching_a_movie': _('Watching a Movie')},
|
|
|
|
'talking': {'category': _('Talking'),
|
|
|
|
'in_real_life': _('In Real Life'),
|
|
|
|
'on_the_phone': _('On the Phone'),
|
|
|
|
'on_video_phone': _('On Video Phone')},
|
|
|
|
'traveling': {'category': _('Traveling'),
|
|
|
|
'commuting': _('Commuting'),
|
|
|
|
'cycling': _('Cycling'),
|
|
|
|
'driving': _('Driving'),
|
|
|
|
'in_a_car': _('In a Car'),
|
|
|
|
'on_a_bus': _('On a Bus'),
|
|
|
|
'on_a_plane': _('On a Plane'),
|
|
|
|
'on_a_train': _('On a Train'),
|
|
|
|
'on_a_trip': _('On a Trip'),
|
|
|
|
'walking': _('Walking')},
|
|
|
|
'working': {'category': _('Working'),
|
|
|
|
'coding': _('Coding'),
|
|
|
|
'in_a_meeting': _('In a Meeting'),
|
|
|
|
'studying': _('Studying'),
|
|
|
|
'writing': _('Writing')}}
|
2008-07-28 22:57:56 +02:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
TUNE_DATA = ['artist', 'title', 'source', 'track', 'length']
|
|
|
|
|
2009-11-14 19:56:15 +01:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.c.pep')
|
|
|
|
|
2009-11-15 00:15:31 +01:00
|
|
|
import helpers
|
|
|
|
import atom
|
2009-11-15 00:12:15 +01:00
|
|
|
import gtkgui_helpers
|
|
|
|
import gobject
|
2009-11-15 16:52:19 +01:00
|
|
|
import gajim
|
|
|
|
import gtk
|
2009-11-14 19:56:15 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2009-11-15 10:55:31 +01:00
|
|
|
def translate_mood(mood):
|
|
|
|
if mood in MOODS:
|
|
|
|
return MOODS[mood]
|
|
|
|
else:
|
|
|
|
return mood
|
|
|
|
|
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
class AbstractPEP(object):
|
|
|
|
|
|
|
|
type = ''
|
|
|
|
namespace = ''
|
2009-11-14 22:47:21 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
@classmethod
|
|
|
|
def get_tag_as_PEP(cls, jid, account, event_tag):
|
|
|
|
items = event_tag.getTag('items', {'node': cls.namespace})
|
|
|
|
if items:
|
|
|
|
log.debug("Received PEP 'user %s' from %s" % (cls.type, jid))
|
|
|
|
return cls(jid, account, items)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2009-11-14 22:47:21 +01:00
|
|
|
def __init__(self, jid, account, items):
|
|
|
|
self._pep_specific_data, self._retracted = self._extract_info(items)
|
2009-11-15 10:55:31 +01:00
|
|
|
|
|
|
|
self._update_contacts(jid, account)
|
|
|
|
if jid == common.gajim.get_jid_from_account(account):
|
|
|
|
self._update_account(account)
|
2009-11-14 22:47:21 +01:00
|
|
|
|
|
|
|
def _extract_info(self, items):
|
|
|
|
'''To be implemented by subclasses'''
|
|
|
|
raise NotImplementedError
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2009-11-15 23:52:43 +01:00
|
|
|
def _update_contacts(self, jid, account):
|
|
|
|
for contact in common.gajim.contacts.get_contacts(account, jid):
|
2009-11-15 10:55:31 +01:00
|
|
|
if self._retracted:
|
|
|
|
if self.type in contact.pep:
|
|
|
|
del contact.pep[self.type]
|
|
|
|
else:
|
|
|
|
contact.pep[self.type] = self
|
|
|
|
|
2009-11-15 23:52:43 +01:00
|
|
|
def _update_account(self, account):
|
|
|
|
acc = common.gajim.connections[account]
|
2009-11-15 10:55:31 +01:00
|
|
|
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
|
|
|
|
|
2009-11-15 00:12:15 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
class UserMoodPEP(AbstractPEP):
|
|
|
|
'''XEP-0107: User Mood'''
|
|
|
|
|
|
|
|
type = 'mood'
|
|
|
|
namespace = common.xmpp.NS_MOOD
|
2009-11-14 20:54:42 +01:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
mood_dict = {}
|
2009-11-14 20:54:42 +01:00
|
|
|
|
|
|
|
for item in items.getTags('item'):
|
2009-11-14 22:31:27 +01:00
|
|
|
mood_tag = item.getTag('mood')
|
|
|
|
if mood_tag:
|
|
|
|
for child in mood_tag.getChildren():
|
2009-11-14 23:07:22 +01:00
|
|
|
name = child.getName().strip()
|
|
|
|
if name == 'text':
|
2009-11-14 22:31:27 +01:00
|
|
|
mood_dict['text'] = child.getData()
|
2009-11-15 00:12:15 +01:00
|
|
|
else:
|
2009-11-14 23:07:22 +01:00
|
|
|
mood_dict['mood'] = name
|
2009-11-14 22:31:27 +01:00
|
|
|
|
2009-11-15 00:12:15 +01:00
|
|
|
retracted = items.getTag('retract') or not 'mood' in mood_dict
|
2009-11-14 22:31:27 +01:00
|
|
|
return (mood_dict, retracted)
|
2009-11-15 00:12:15 +01:00
|
|
|
|
|
|
|
def asPixbufIcon(self):
|
2009-11-15 10:55:31 +01:00
|
|
|
assert not self._retracted
|
|
|
|
received_mood = self._pep_specific_data['mood']
|
|
|
|
mood = received_mood if received_mood in MOODS else 'unknown'
|
|
|
|
pixbuf = gtkgui_helpers.load_mood_icon(mood).get_pixbuf()
|
|
|
|
return pixbuf
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2009-11-15 00:12:15 +01:00
|
|
|
def asMarkupText(self):
|
2009-11-15 10:55:31 +01:00
|
|
|
assert not self._retracted
|
|
|
|
untranslated_mood = self._pep_specific_data['mood']
|
|
|
|
mood = translate_mood(untranslated_mood)
|
|
|
|
markuptext = '<b>%s</b>' % gobject.markup_escape_text(mood)
|
|
|
|
if 'text' in self._pep_specific_data:
|
|
|
|
text = self._pep_specific_data['text']
|
|
|
|
markuptext += ' (%s)' % gobject.markup_escape_text(text)
|
|
|
|
return markuptext
|
2009-11-15 00:12:15 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
|
|
|
|
class UserTunePEP(AbstractPEP):
|
|
|
|
'''XEP-0118: User Tune'''
|
|
|
|
|
|
|
|
type = 'tune'
|
|
|
|
namespace = common.xmpp.NS_TUNE
|
2009-11-14 22:47:21 +01:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
tune_dict = {}
|
|
|
|
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
tune_tag = item.getTag('tune')
|
|
|
|
if tune_tag:
|
|
|
|
for child in tune_tag.getChildren():
|
2009-11-14 23:07:22 +01:00
|
|
|
name = child.getName().strip()
|
|
|
|
data = child.getData().strip()
|
2009-11-14 22:31:27 +01:00
|
|
|
if child.getName() in TUNE_DATA:
|
2009-11-14 23:07:22 +01:00
|
|
|
tune_dict[name] = data
|
2009-11-14 22:31:27 +01:00
|
|
|
|
2009-11-15 10:55:31 +01:00
|
|
|
retracted = items.getTag('retract') or not ('artist' in tune_dict or
|
|
|
|
'title' in tune_dict)
|
2009-11-14 22:31:27 +01:00
|
|
|
return (tune_dict, retracted)
|
2009-11-15 16:52:19 +01:00
|
|
|
|
|
|
|
def asPixbufIcon(self):
|
|
|
|
import os
|
|
|
|
path = os.path.join(gajim.DATA_DIR, 'emoticons', 'static', 'music.png')
|
|
|
|
return gtk.gdk.pixbuf_new_from_file(path)
|
2009-11-15 11:11:51 +01:00
|
|
|
|
2009-11-15 10:55:31 +01:00
|
|
|
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
|
2009-11-14 22:31:27 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
|
|
|
|
class UserActivityPEP(AbstractPEP):
|
|
|
|
'''XEP-0108: User Activity'''
|
|
|
|
|
|
|
|
type = 'activity'
|
|
|
|
namespace = common.xmpp.NS_ACTIVITY
|
2009-11-14 22:47:21 +01:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
activity_dict = {}
|
|
|
|
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
activity_tag = item.getTag('activity')
|
|
|
|
if activity_tag:
|
2009-11-14 22:47:21 +01:00
|
|
|
for child in activity_tag.getChildren():
|
2009-11-14 23:07:22 +01:00
|
|
|
name = child.getName().strip()
|
|
|
|
data = child.getData().strip()
|
|
|
|
if name == 'text':
|
|
|
|
activity_dict['text'] = data
|
2009-11-15 16:52:19 +01:00
|
|
|
else:
|
2009-11-14 23:07:22 +01:00
|
|
|
activity_dict['activity'] = name
|
2009-11-14 22:31:27 +01:00
|
|
|
for subactivity in child.getChildren():
|
2009-11-14 23:07:22 +01:00
|
|
|
subactivity_name = subactivity.getName().strip()
|
2009-11-15 16:52:19 +01:00
|
|
|
activity_dict['subactivity'] = subactivity_name
|
2009-11-14 22:31:27 +01:00
|
|
|
|
2009-11-15 16:52:19 +01:00
|
|
|
retracted = items.getTag('retract') or not 'activity' in activity_dict
|
2009-11-14 22:31:27 +01:00
|
|
|
return (activity_dict, retracted)
|
2009-11-15 16:52:19 +01:00
|
|
|
|
|
|
|
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()
|
2009-11-14 22:31:27 +01:00
|
|
|
|
2009-11-15 16:52:19 +01:00
|
|
|
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
|
|
|
|
|
2009-11-15 11:11:51 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
class UserNicknamePEP(AbstractPEP):
|
|
|
|
'''XEP-0172: User Nickname'''
|
|
|
|
|
2009-11-15 11:11:51 +01:00
|
|
|
type = 'nickname'
|
2009-11-14 20:48:33 +01:00
|
|
|
namespace = common.xmpp.NS_NICK
|
2009-11-14 22:47:21 +01:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
nick = ''
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
child = item.getTag('nick')
|
|
|
|
if child:
|
|
|
|
nick = child.getData()
|
|
|
|
break
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
retracted = items.getTag('retract') or not nick
|
|
|
|
return (nick, retracted)
|
2009-11-15 11:11:51 +01:00
|
|
|
|
|
|
|
def _update_contacts(self, jid, account):
|
|
|
|
# TODO: use dict instead
|
2009-11-14 22:47:21 +01:00
|
|
|
nick = '' if self._retracted else self._pep_specific_data
|
2009-11-15 11:11:51 +01:00
|
|
|
for contact in common.gajim.contacts.get_contacts(account, jid):
|
2009-11-14 22:31:27 +01:00
|
|
|
contact.contact_name = nick
|
2009-11-15 11:11:51 +01:00
|
|
|
|
|
|
|
def _update_account(self, account):
|
|
|
|
# TODO: use dict instead
|
|
|
|
if self._retracted:
|
|
|
|
common.gajim.nicks[account] = common.gajim.config.get_per('accounts',
|
2009-11-15 16:52:19 +01:00
|
|
|
account, 'name')
|
2009-11-15 11:11:51 +01:00
|
|
|
else:
|
|
|
|
common.gajim.nicks[account] = self._pep_specific_data
|
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
|
|
|
|
SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP, UserNicknamePEP]
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2009-11-14 19:56:15 +01:00
|
|
|
class ConnectionPEP:
|
|
|
|
|
|
|
|
def _pubsubEventCB(self, xmpp_dispatcher, msg):
|
|
|
|
''' Called when we receive <message /> with pubsub event. '''
|
|
|
|
if msg.getTag('error'):
|
2009-11-14 20:48:33 +01:00
|
|
|
log.warning('PubsubEventCB received error stanza')
|
2009-11-14 19:56:15 +01:00
|
|
|
return
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2009-11-14 19:56:15 +01:00
|
|
|
# TODO: Logging? (actually services where logging would be useful, should
|
|
|
|
# TODO: allow to access archives remotely...)
|
|
|
|
jid = helpers.get_full_jid_from_iq(msg)
|
2009-11-14 20:48:33 +01:00
|
|
|
event_tag = msg.getTag('event')
|
2009-11-14 19:56:15 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
for pep_class in SUPPORTED_PERSONAL_USER_EVENTS:
|
|
|
|
pep = pep_class.get_tag_as_PEP(jid, self.name, event_tag)
|
|
|
|
if pep:
|
2009-11-15 10:55:31 +01:00
|
|
|
self.dispatch('PEP_RECEIVED', (jid, pep.type))
|
2009-11-14 20:48:33 +01:00
|
|
|
|
|
|
|
items = event_tag.getTag('items')
|
2009-11-15 22:59:43 +01:00
|
|
|
if items is None:
|
|
|
|
return
|
2009-11-14 19:56:15 +01:00
|
|
|
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
entry = item.getTag('entry')
|
2009-11-15 22:59:43 +01:00
|
|
|
if entry:
|
2009-11-14 19:56:15 +01:00
|
|
|
# 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
|
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
|
2008-11-28 08:25:31 +01:00
|
|
|
def user_send_mood(account, mood, message=''):
|
2009-04-12 20:13:37 +02:00
|
|
|
if not common.gajim.connections[account].pep_supported:
|
2007-08-10 01:05:43 +02:00
|
|
|
return
|
2007-03-31 00:52:11 +02:00
|
|
|
item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD})
|
2009-11-15 22:59:43 +01:00
|
|
|
if mood:
|
2008-10-30 20:01:26 +01:00
|
|
|
item.addChild(mood)
|
2009-11-15 22:59:43 +01:00
|
|
|
if message:
|
2007-03-31 00:52:11 +02:00
|
|
|
i = item.addChild('text')
|
|
|
|
i.addData(message)
|
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item,
|
|
|
|
'0')
|
2007-03-31 11:09:16 +02:00
|
|
|
|
2008-11-28 08:25:31 +01:00
|
|
|
def user_send_activity(account, activity, subactivity='', message=''):
|
2009-04-12 20:13:37 +02:00
|
|
|
if not common.gajim.connections[account].pep_supported:
|
2007-08-10 01:05:43 +02:00
|
|
|
return
|
2007-03-31 11:09:16 +02:00
|
|
|
item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY})
|
2009-11-15 22:59:43 +01:00
|
|
|
if activity:
|
2007-08-10 01:05:43 +02:00
|
|
|
i = item.addChild(activity)
|
2009-11-15 22:59:43 +01:00
|
|
|
if subactivity:
|
2007-03-31 11:09:16 +02:00
|
|
|
i.addChild(subactivity)
|
2009-11-15 22:59:43 +01:00
|
|
|
if message:
|
2007-03-31 11:09:16 +02:00
|
|
|
i = item.addChild('text')
|
|
|
|
i.addData(message)
|
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item,
|
|
|
|
'0')
|
2007-04-01 11:02:04 +02:00
|
|
|
|
2008-11-28 08:25:31 +01:00
|
|
|
def user_send_tune(account, artist='', title='', source='', track=0, length=0,
|
|
|
|
items=None):
|
2009-04-12 20:13:37 +02:00
|
|
|
if not (common.gajim.config.get_per('accounts', account, 'publish_tune') and\
|
|
|
|
common.gajim.connections[account].pep_supported):
|
2007-08-10 01:05:43 +02:00
|
|
|
return
|
2007-04-01 11:02:04 +02:00
|
|
|
item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE})
|
2009-11-15 22:59:43 +01:00
|
|
|
if artist:
|
2007-04-01 11:02:04 +02:00
|
|
|
i = item.addChild('artist')
|
|
|
|
i.addData(artist)
|
2009-11-15 22:59:43 +01:00
|
|
|
if title:
|
2007-04-01 11:02:04 +02:00
|
|
|
i = item.addChild('title')
|
|
|
|
i.addData(title)
|
2009-11-15 22:59:43 +01:00
|
|
|
if source:
|
2007-04-01 11:02:04 +02:00
|
|
|
i = item.addChild('source')
|
|
|
|
i.addData(source)
|
2009-11-15 22:59:43 +01:00
|
|
|
if track:
|
2007-04-01 11:02:04 +02:00
|
|
|
i = item.addChild('track')
|
|
|
|
i.addData(track)
|
2009-11-15 22:59:43 +01:00
|
|
|
if length:
|
2007-04-01 11:02:04 +02:00
|
|
|
i = item.addChild('length')
|
|
|
|
i.addData(length)
|
2009-11-15 22:59:43 +01:00
|
|
|
if items:
|
2007-04-01 11:02:04 +02:00
|
|
|
item.addChild(payload=items)
|
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item,
|
|
|
|
'0')
|
2008-05-05 09:48:13 +02:00
|
|
|
|
2008-05-05 23:55:59 +02:00
|
|
|
def user_send_nickname(account, nick):
|
2009-04-12 20:13:37 +02:00
|
|
|
if not common.gajim.connections[account].pep_supported:
|
2008-05-05 23:55:59 +02:00
|
|
|
return
|
|
|
|
item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK})
|
|
|
|
item.addData(nick)
|
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item,
|
|
|
|
'0')
|
2008-05-05 23:55:59 +02:00
|
|
|
|
2008-05-05 09:48:13 +02:00
|
|
|
def user_retract_mood(account):
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0')
|
2008-05-05 09:48:13 +02:00
|
|
|
|
|
|
|
def user_retract_activity(account):
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_retract('', xmpp.NS_ACTIVITY, '0')
|
2008-05-05 09:48:13 +02:00
|
|
|
|
|
|
|
def user_retract_tune(account):
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0')
|
2008-05-05 23:55:59 +02:00
|
|
|
|
|
|
|
def user_retract_nickname(account):
|
2009-04-12 20:13:37 +02:00
|
|
|
common.gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0')
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-28 13:43:10 +02:00
|
|
|
def delete_pep(jid, name):
|
2009-04-12 20:13:37 +02:00
|
|
|
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
2008-08-28 13:43:10 +02:00
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
if jid == common.gajim.get_jid_from_account(name):
|
|
|
|
acc = common.gajim.connections[name]
|
2009-11-15 23:52:43 +01:00
|
|
|
acc.pep = {}
|
2008-08-28 13:43:10 +02:00
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
for contact in common.gajim.contacts.get_contacts(name, user):
|
2009-11-15 23:52:43 +01:00
|
|
|
contact.pep = {}
|
2008-08-28 13:43:10 +02:00
|
|
|
|
2009-04-12 20:13:37 +02:00
|
|
|
if jid == common.gajim.get_jid_from_account(name):
|
|
|
|
common.gajim.interface.roster.draw_account(name)
|
2008-08-28 13:43:10 +02:00
|
|
|
|
2009-11-15 23:23:56 +01:00
|
|
|
common.gajim.interface.roster.draw_all_pep_types(jid, name)
|
2009-04-12 20:13:37 +02:00
|
|
|
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
|
2008-08-28 13:43:10 +02:00
|
|
|
if ctrl:
|
2009-11-15 22:54:20 +01:00
|
|
|
ctrl.update_all_pep_types()
|
|
|
|
|
2008-08-28 13:43:10 +02:00
|
|
|
|
2008-08-05 00:44:48 +02:00
|
|
|
# vim: se ts=3:
|