Philipp Hörist pushed to branch master at gajim / gajim
Commits: 14f088c2 by Philipp Hörist at 2018-07-05T19:37:51+02:00 Refactor UserMood into own module
- - - - - bbf3a544 by Philipp Hörist at 2018-07-05T19:38:03+02:00 Refactor UserLocation into own module
- - - - - 31d62358 by Philipp Hörist at 2018-07-05T19:38:41+02:00 Fix retracting UserTune/UserActivity
- - - - - b04f9af4 by Philipp Hörist at 2018-07-05T19:54:32+02:00 Fix copy/paste typo
- - - - - fe3c1b4f by Philipp Hörist at 2018-07-05T20:20:22+02:00 Refactor UserNickname into own module
- - - - -
19 changed files:
- gajim/chat_control.py - gajim/common/connection.py - gajim/common/connection_handlers.py - gajim/common/const.py - gajim/common/location_listener.py - gajim/common/modules/pep.py - gajim/common/modules/user_activity.py - + gajim/common/modules/user_location.py - + gajim/common/modules/user_mood.py - + gajim/common/modules/user_nickname.py - gajim/common/modules/user_tune.py - gajim/common/pep.py - gajim/common/zeroconf/connection_handlers_zeroconf.py - gajim/dialogs.py - gajim/gtkgui_helpers.py - gajim/gui_interface.py - gajim/profile_window.py - gajim/roster_window.py - gajim/tooltips.py
Changes:
===================================== gajim/chat_control.py ===================================== --- a/gajim/chat_control.py +++ b/gajim/chat_control.py @@ -122,7 +122,7 @@ class ChatControl(ChatControlBase): self._pep_images['mood'] = self.xml.get_object('mood_image') self._pep_images['activity'] = self.xml.get_object('activity_image') self._pep_images['tune'] = self.xml.get_object('tune_image') - self._pep_images['location'] = self.xml.get_object('location_image') + self._pep_images['geoloc'] = self.xml.get_object('location_image') self.update_all_pep_types()
self.show_avatar() @@ -422,7 +422,7 @@ class ChatControl(ChatControlBase): if obj.jid != self.contact.jid: return
- if obj.pep_type == 'nickname': + if obj.pep_type == 'nick': self.update_ui() self.parent_win.redraw_tab(self) self.parent_win.show_title() @@ -584,8 +584,8 @@ class ChatControl(ChatControlBase): return True
def on_location_eventbox_button_release_event(self, widget, event): - if 'location' in self.contact.pep: - location = self.contact.pep['location']._pep_specific_data + if 'geoloc' in self.contact.pep: + location = self.contact.pep['geoloc']._pep_specific_data if ('lat' in location) and ('lon' in location): uri = 'https://www.openstreetmap.org/?' + \ 'mlat=%(lat)s&mlon=%(lon)s&zoom=16' % {'lat': location['lat'],
===================================== gajim/common/connection.py ===================================== --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -80,6 +80,9 @@ from gajim.common.modules.pep import PEP from gajim.common.modules.user_avatar import UserAvatar from gajim.common.modules.user_activity import UserActivity from gajim.common.modules.user_tune import UserTune +from gajim.common.modules.user_mood import UserMood +from gajim.common.modules.user_location import UserLocation +from gajim.common.modules.user_nickname import UserNickname from gajim.common.connection_handlers import * from gajim.common.contacts import GC_Contact from gajim.gtkgui_helpers import get_action @@ -632,7 +635,7 @@ class Connection(CommonConnection, ConnectionHandlers): self.password = passwords.get_password(name)
self.music_track_info = 0 - self.location_info = {} + self.register_supported = False self.pubsub_publish_options_supported = False # Do we auto accept insecure connection @@ -676,6 +679,9 @@ class Connection(CommonConnection, ConnectionHandlers): self.register_module('UserAvatar', UserAvatar, self) self.register_module('UserActivity', UserActivity, self) self.register_module('UserTune', UserTune, self) + self.register_module('UserMood', UserMood, self) + self.register_module('UserLocation', UserLocation, self) + self.register_module('UserNickname', UserNickname, self)
app.ged.register_event_handler('privacy-list-received', ged.CORE, self._nec_privacy_list_received) @@ -761,7 +767,6 @@ class Connection(CommonConnection, ConnectionHandlers): # We are doing disconnect at so many places, better use one function in all def disconnect(self, on_purpose=False): app.interface.music_track_changed(None, None, self.name) - self.reset_awaiting_pep() self.get_module('PEP').reset_stored_publish() self.on_purpose = on_purpose self.connected = 0
===================================== gajim/common/connection_handlers.py ===================================== --- a/gajim/common/connection_handlers.py +++ b/gajim/common/connection_handlers.py @@ -42,7 +42,6 @@ from gi.repository import GLib import nbxmpp from gajim.common import caps_cache as capscache
-from gajim.common.pep import LOCATION_DATA from gajim.common import helpers from gajim.common import app from gajim.common import dataforms @@ -282,98 +281,6 @@ class ConnectionDisco: app.nec.push_incoming_event(AgentInfoReceivedEvent(None, conn=self, stanza=iq_obj))
- -class ConnectionPEP(object): - - def __init__(self, account, dispatcher, pubsub_connection): - self._account = account - self._dispatcher = dispatcher - self._pubsub_connection = pubsub_connection - self.reset_awaiting_pep() - - def pep_change_account_name(self, new_name): - self._account = new_name - - def reset_awaiting_pep(self): - self.to_be_sent_mood = None - self.to_be_sent_nick = None - self.to_be_sent_location = None - - def send_awaiting_pep(self): - """ - Send pep info that were waiting for connection - """ - if self.to_be_sent_mood: - self.send_mood(*self.to_be_sent_mood) - if self.to_be_sent_nick: - self.send_nick(self.to_be_sent_nick) - if self.to_be_sent_location: - self.send_location(self.to_be_sent_location) - self.reset_awaiting_pep() - - def send_mood(self, mood, message=None): - if self.connected == 1: - # We are connecting, keep mood in mem and send it when we'll be - # connected - self.to_be_sent_mood = (mood, message) - return - if not self.pep_supported: - return - item = nbxmpp.Node('mood', {'xmlns': nbxmpp.NS_MOOD}) - if mood: - item.addChild(mood) - if message: - i = item.addChild('text') - i.addData(message) - self.get_module('PubSub').send_pb_publish('', nbxmpp.NS_MOOD, item, '0') - - def retract_mood(self): - if not self.pep_supported: - return - self.send_mood(None) - # not all client support new XEP, so we still retract - self.get_module('PubSub').send_pb_retract('', nbxmpp.NS_MOOD, '0') - - def send_nickname(self, nick): - if self.connected == 1: - # We are connecting, keep nick in mem and send it when we'll be - # connected - self.to_be_sent_nick = nick - return - if not self.pep_supported: - return - item = nbxmpp.Node('nick', {'xmlns': nbxmpp.NS_NICK}) - item.addData(nick) - self.get_module('PubSub').send_pb_publish('', nbxmpp.NS_NICK, item, '0') - - def retract_nickname(self): - if not self.pep_supported: - return - - self.get_module('PubSub').send_pb_retract('', nbxmpp.NS_NICK, '0') - - def send_location(self, info): - if self.connected == 1: - # We are connecting, keep location in mem and send it when we'll be - # connected - self.to_be_sent_location = info - return - if not self.pep_supported: - return - item = nbxmpp.Node('geoloc', {'xmlns': nbxmpp.NS_LOCATION}) - for field in LOCATION_DATA: - if info.get(field, None): - i = item.addChild(field) - i.addData(info[field]) - self.get_module('PubSub').send_pb_publish('', nbxmpp.NS_LOCATION, item, '0') - - def retract_location(self): - if not self.pep_supported: - return - self.send_location({}) - # not all client support new XEP, so we still retract - self.get_module('PubSub').send_pb_retract('', nbxmpp.NS_LOCATION, '0') - # basic connection handlers used here and in zeroconf class ConnectionHandlersBase: def __init__(self): @@ -841,7 +748,7 @@ class ConnectionHandlersBase:
class ConnectionHandlers(ConnectionArchive313, ConnectionSocks5Bytestream, ConnectionDisco, -ConnectionCommands, ConnectionPEP, ConnectionCaps, +ConnectionCommands, ConnectionCaps, ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream, ConnectionHTTPUpload): def __init__(self): @@ -849,8 +756,6 @@ ConnectionHTTPUpload): ConnectionSocks5Bytestream.__init__(self) ConnectionIBBytestream.__init__(self) ConnectionCommands.__init__(self) - ConnectionPEP.__init__(self, account=self.name, dispatcher=self, - pubsub_connection=self) ConnectionHTTPUpload.__init__(self)
# Handle presences BEFORE caps @@ -1446,7 +1351,6 @@ ConnectionHTTPUpload):
# Inform GUI we just signed in app.nec.push_incoming_event(SignedInEvent(None, conn=self)) - self.send_awaiting_pep() self.get_module('PEP').send_stored_publish() self.continue_connect_info = None
===================================== gajim/common/const.py ===================================== --- a/gajim/common/const.py +++ b/gajim/common/const.py @@ -4,6 +4,7 @@ from collections import namedtuple Option = namedtuple('Option', 'kind label type value name callback data desc enabledif props') Option.__new__.__defaults__ = (None,) * len(Option._fields)
+ @unique class OptionKind(IntEnum): ENTRY = 0 @@ -20,6 +21,7 @@ class OptionKind(IntEnum): CHANGEPASSWORD = 11 GPG = 12
+ @unique class OptionType(IntEnum): ACCOUNT_CONFIG = 0 @@ -28,6 +30,7 @@ class OptionType(IntEnum): ACTION = 3 DIALOG = 4
+ class AvatarSize(IntEnum): TAB = 16 ROSTER = 32 @@ -37,22 +40,26 @@ class AvatarSize(IntEnum): VCARD = 200 PUBLISH = 200
+ class ArchiveState(IntEnum): NEVER = 0 ALL = 1
+ @unique class PathLocation(IntEnum): CONFIG = 0 CACHE = 1 DATA = 2
+ @unique class PathType(IntEnum): FILE = 0 FOLDER = 1 FOLDER_OPTIONAL = 2
+ @unique class KindConstant(IntEnum): STATUS = 0 @@ -67,6 +74,7 @@ class KindConstant(IntEnum): def __str__(self): return str(self.value)
+ @unique class ShowConstant(IntEnum): ONLINE = 0 @@ -76,6 +84,7 @@ class ShowConstant(IntEnum): DND = 4 OFFLINE = 5
+ @unique class TypeConstant(IntEnum): AIM = 0 @@ -94,6 +103,7 @@ class TypeConstant(IntEnum): MRIM = 13 NO_TRANSPORT = 14
+ @unique class SubscriptionConstant(IntEnum): NONE = 0 @@ -101,11 +111,13 @@ class SubscriptionConstant(IntEnum): FROM = 2 BOTH = 3
+ @unique class JIDConstant(IntEnum): NORMAL_TYPE = 0 ROOM_TYPE = 1
+ @unique class IdleState(IntEnum): UNKNOWN = 0 @@ -113,26 +125,33 @@ class IdleState(IntEnum): AWAY = 2 AWAKE = 3
+ @unique class RequestAvatar(IntEnum): SELF = 0 ROOM = 1 USER = 2
+ @unique class BookmarkStorageType(IntEnum): PRIVATE = 0 PUBSUB = 1
+ @unique class PEPHandlerType(IntEnum): NOTIFY = 0 RETRACT = 1
+ @unique class PEPEventType(IntEnum): ACTIVITY = 0 TUNE = 1 + MOOD = 2 + LOCATION = 3 + NICKNAME = 4
ACTIVITIES = { @@ -226,6 +245,118 @@ ACTIVITIES = { 'studying': _('Studying'), 'writing': _('Writing')}}
+MOODS = { + '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'), + 'in_awe': _('In Awe'), + 'in_love': _('In Love'), + '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') +} + +LOCATION_DATA = { + 'accuracy': _('accuracy'), + 'alt': _('alt'), + 'area': _('area'), + 'bearing': _('bearing'), + 'building': _('building'), + 'country': _('country'), + 'countrycode': _('countrycode'), + 'datum': _('datum'), + 'description': _('description'), + 'error': _('error'), + 'floor': _('floor'), + 'lat': _('lat'), + 'locality': _('locality'), + 'lon': _('lon'), + 'postalcode': _('postalcode'), + 'region': _('region'), + 'room': _('room'), + 'speed': _('speed'), + 'street': _('street'), + 'text': _('text'), + 'timestamp': _('timestamp'), + 'uri': _('URI') +} +
SSLError = { 2: _("Unable to get issuer certificate"), @@ -260,7 +391,7 @@ SSLError = { 31: _("Authority and issuer serial number mismatch"), 32: _("Key usage does not include certificate signing"), 50: _("Application verification failure"), - } +}
THANKS = u"""\
===================================== gajim/common/location_listener.py ===================================== --- a/gajim/common/location_listener.py +++ b/gajim/common/location_listener.py @@ -97,7 +97,7 @@ class LocationListener: del new_data['timestamp'] if last_data == new_data: continue - app.connections[acct].send_location(self._data) + app.connections[acct].get_module('UserLocation').send(self._data) self.location_info = self._data.copy()
def _timestamp_to_utc(self, timestamp):
===================================== gajim/common/modules/pep.py ===================================== --- a/gajim/common/modules/pep.py +++ b/gajim/common/modules/pep.py @@ -195,6 +195,10 @@ class AbstractPEPData:
type_ = PEPEventType
+ def asMarkupText(self): + '''SHOULD be implemented by subclasses''' + return '' + def __eq__(self, other): return other == self.type_
===================================== gajim/common/modules/user_activity.py ===================================== --- a/gajim/common/modules/user_activity.py +++ b/gajim/common/modules/user_activity.py @@ -87,8 +87,10 @@ class UserActivity(AbstractPEPModule): return activity_dict or None
def _build_node(self, data): - activity, subactivity, message = data item = nbxmpp.Node('activity', {'xmlns': self.namespace}) + if data is None: + return + activity, subactivity, message = data if activity: i = item.addChild(activity) if subactivity:
===================================== gajim/common/modules/user_location.py ===================================== --- /dev/null +++ b/gajim/common/modules/user_location.py @@ -0,0 +1,85 @@ +# 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/. + +# XEP-0080: User Location + +import logging + +import nbxmpp +from gi.repository import GLib + +from gajim.common.const import PEPEventType, LOCATION_DATA +from gajim.common.exceptions import StanzaMalformed +from gajim.common.modules.pep import AbstractPEPModule, AbstractPEPData + +log = logging.getLogger('gajim.c.m.user_location') + + +class UserLocationData(AbstractPEPData): + + type_ = PEPEventType.LOCATION + + def __init__(self, location): + self._pep_specific_data = location + + def asMarkupText(self): + location = self._pep_specific_data + location_string = '' + + for entry in location.keys(): + text = location[entry] + text = GLib.markup_escape_text(text) + # Translate standard location tag + tag = LOCATION_DATA.get(entry, entry) + location_string += '\n<b>%(tag)s</b>: %(text)s' % { + 'tag': tag.capitalize(), 'text': text} + + return location_string.strip() + + +class UserLocation(AbstractPEPModule): + + name = 'geoloc' + namespace = nbxmpp.NS_LOCATION + pep_class = UserLocationData + store_publish = True + _log = log + + def __init__(self, con): + AbstractPEPModule.__init__(self, con, con.name) + + self.handlers = [] + + def _extract_info(self, item): + location_dict = {} + location_tag = item.getTag('geoloc', namespace=nbxmpp.NS_LOCATION) + if location_tag is None: + raise StanzaMalformed('No geoloc node') + + for child in location_tag.getChildren(): + name = child.getName().strip() + data = child.getData().strip() + if child.getName() in LOCATION_DATA: + location_dict[name] = data + + return location_dict or None + + def _build_node(self, data): + item = nbxmpp.Node('geoloc', {'xmlns': nbxmpp.NS_LOCATION}) + if data is None: + return item + for field in LOCATION_DATA: + if data.get(field, False): + item.addChild(field, payload=data[field]) + return item
===================================== gajim/common/modules/user_mood.py ===================================== --- /dev/null +++ b/gajim/common/modules/user_mood.py @@ -0,0 +1,88 @@ +# 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/. + +# XEP-0107: User Mood + +import logging + +import nbxmpp +from gi.repository import GLib + +from gajim.common.const import PEPEventType, MOODS +from gajim.common.exceptions import StanzaMalformed +from gajim.common.modules.pep import AbstractPEPModule, AbstractPEPData + +log = logging.getLogger('gajim.c.m.user_mood') + + +class UserMoodData(AbstractPEPData): + + type_ = PEPEventType.MOOD + + def __init__(self, mood): + self._pep_specific_data = mood + + def asMarkupText(self): + mood = self._translate_mood(self._pep_specific_data['mood']) + markuptext = '<b>%s</b>' % GLib.markup_escape_text(mood) + if 'text' in self._pep_specific_data: + text = self._pep_specific_data['text'] + markuptext += ' (%s)' % GLib.markup_escape_text(text) + return markuptext + + def _translate_mood(self, mood): + if mood in MOODS: + return MOODS[mood] + else: + return mood + + +class UserMood(AbstractPEPModule): + + name = 'mood' + namespace = nbxmpp.NS_MOOD + pep_class = UserMoodData + store_publish = True + _log = log + + def __init__(self, con): + AbstractPEPModule.__init__(self, con, con.name) + + self.handlers = [] + + def _extract_info(self, item): + mood_dict = {} + mood_tag = item.getTag('mood', namespace=nbxmpp.NS_MOOD) + if mood_tag is None: + raise StanzaMalformed('No mood node') + + for child in mood_tag.getChildren(): + name = child.getName().strip() + if name == 'text': + mood_dict['text'] = child.getData() + else: + mood_dict['mood'] = name + + return mood_dict or None + + def _build_node(self, data): + item = nbxmpp.Node('mood', {'xmlns': nbxmpp.NS_MOOD}) + if data is None: + return + mood, text = data + if mood: + item.addChild(mood) + if text: + item.addChild('text', payload=text) + return item
===================================== gajim/common/modules/user_nickname.py ===================================== --- /dev/null +++ b/gajim/common/modules/user_nickname.py @@ -0,0 +1,78 @@ +# 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/. + +# XEP-0172: User Nickname + +import logging + +import nbxmpp + +from gajim.common import app +from gajim.common.const import PEPEventType +from gajim.common.exceptions import StanzaMalformed +from gajim.common.modules.pep import AbstractPEPModule, AbstractPEPData + +log = logging.getLogger('gajim.c.m.user_nickname') + + +class UserNicknameData(AbstractPEPData): + + type_ = PEPEventType.NICKNAME + + def __init__(self, nickname): + self._pep_specific_data = nickname + + def get_nick(self): + return self._pep_specific_data or '' + + +class UserNickname(AbstractPEPModule): + + name = 'nick' + namespace = nbxmpp.NS_NICK + pep_class = UserNicknameData + store_publish = True + _log = log + + def __init__(self, con): + AbstractPEPModule.__init__(self, con, con.name) + + self.handlers = [] + + def _extract_info(self, item): + nick = '' + child = item.getTag('nick', namespace=nbxmpp.NS_NICK) + if child is None: + raise StanzaMalformed('No nick node') + nick = child.getData() + + return nick or None + + def _build_node(self, data): + item = nbxmpp.Node('nick', {'xmlns': nbxmpp.NS_NICK}) + if data is None: + return + item.addData(data) + return item + + def _update_contacts(self, jid, user_pep): + for contact in app.contacts.get_contacts(self._account, str(jid)): + contact.contact_name = user_pep.get_nick() + + if jid == self._con.get_own_jid().getStripped(): + if user_pep: + app.nicks[self._account] = user_pep.get_nick() + else: + app.nicks[self._account] = app.config.get_per( + 'accounts', self._account, 'name')
===================================== gajim/common/modules/user_tune.py ===================================== --- a/gajim/common/modules/user_tune.py +++ b/gajim/common/modules/user_tune.py @@ -81,8 +81,10 @@ class UserTune(AbstractPEPModule): return tune_dict or None
def _build_node(self, data): - artist, title, source, track, length = data item = nbxmpp.Node('tune', {'xmlns': nbxmpp.NS_TUNE}) + if data is None: + return item + artist, title, source, track, length = data if artist: item.addChild('artist', payload=artist) if title:
===================================== gajim/common/pep.py ===================================== --- a/gajim/common/pep.py +++ b/gajim/common/pep.py @@ -23,122 +23,9 @@ ## along with Gajim. If not, see http://www.gnu.org/licenses/. ##
-MOODS = { - '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'), - 'in_awe': _('In Awe'), - 'in_love': _('In Love'), - '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')} - -LOCATION_DATA = { - 'accuracy': _('accuracy'), - 'alt': _('alt'), - 'area': _('area'), - 'bearing': _('bearing'), - 'building': _('building'), - 'country': _('country'), - 'countrycode': _('countrycode'), - 'datum': _('datum'), - 'description': _('description'), - 'error': _('error'), - 'floor': _('floor'), - 'lat': _('lat'), - 'locality': _('locality'), - 'lon': _('lon'), - 'postalcode': _('postalcode'), - 'region': _('region'), - 'room': _('room'), - 'speed': _('speed'), - 'street': _('street'), - 'text': _('text'), - 'timestamp': _('timestamp'), - 'uri': _('URI')} - -from gi.repository import GLib - import logging log = logging.getLogger('gajim.c.pep')
-import nbxmpp from gajim.common import app
@@ -193,116 +80,6 @@ class AbstractPEP(object): pass
-class UserMoodPEP(AbstractPEP): - '''XEP-0107: User Mood''' - - type_ = 'mood' - namespace = nbxmpp.NS_MOOD - - def _extract_info(self, items): - mood_dict = {} - - for item in items.getTags('item'): - mood_tag = item.getTag('mood') - if mood_tag: - for child in mood_tag.getChildren(): - name = child.getName().strip() - if name == 'text': - mood_dict['text'] = child.getData() - else: - mood_dict['mood'] = name - - retracted = items.getTag('retract') or not 'mood' in mood_dict - return (mood_dict, retracted) - - def asMarkupText(self): - assert not self._retracted - untranslated_mood = self._pep_specific_data['mood'] - mood = self._translate_mood(untranslated_mood) - markuptext = '<b>%s</b>' % GLib.markup_escape_text(mood) - if 'text' in self._pep_specific_data: - text = self._pep_specific_data['text'] - markuptext += ' (%s)' % GLib.markup_escape_text(text) - return markuptext - - def _translate_mood(self, mood): - if mood in MOODS: - return MOODS[mood] - else: - return mood - - -class UserNicknamePEP(AbstractPEP): - '''XEP-0172: User Nickname''' - - type_ = 'nickname' - namespace = nbxmpp.NS_NICK - - def _extract_info(self, items): - nick = '' - for item in items.getTags('item'): - child = item.getTag('nick') - if child: - nick = child.getData() - break - - retracted = items.getTag('retract') or not nick - return (nick, retracted) - - def _update_contacts(self, jid, account): - nick = '' if self._retracted else self._pep_specific_data - for contact in app.contacts.get_contacts(account, jid): - contact.contact_name = nick - - def _update_account(self, account): - if self._retracted: - app.nicks[account] = app.config.get_per('accounts', account, 'name') - else: - app.nicks[account] = self._pep_specific_data - - -class UserLocationPEP(AbstractPEP): - '''XEP-0080: User Location''' - - type_ = 'location' - namespace = nbxmpp.NS_LOCATION - - def _extract_info(self, items): - location_dict = {} - - for item in items.getTags('item'): - location_tag = item.getTag('geoloc') - if location_tag: - for child in location_tag.getChildren(): - name = child.getName().strip() - data = child.getData().strip() - if child.getName() in LOCATION_DATA: - location_dict[name] = data - - retracted = items.getTag('retract') or not location_dict - return (location_dict, retracted) - - def _update_account(self, account): - AbstractPEP._update_account(self, account) - con = app.connections[account].location_info = \ - self._pep_specific_data - - def asMarkupText(self): - assert not self._retracted - location = self._pep_specific_data - location_string = '' - - for entry in location.keys(): - text = location[entry] - text = GLib.markup_escape_text(text) - # Translate standard location tag - tag = LOCATION_DATA.get(entry, entry) - location_string += '\n<b>%(tag)s</b>: %(text)s' % \ - {'tag': tag.capitalize(), 'text': text} - - return location_string.strip() - - class AvatarNotificationPEP(AbstractPEP): '''XEP-0084: Avatars'''
@@ -347,5 +124,4 @@ class AvatarNotificationPEP(AbstractPEP):
SUPPORTED_PERSONAL_USER_EVENTS = [ - UserMoodPEP, - UserNicknamePEP, UserLocationPEP, AvatarNotificationPEP] + AvatarNotificationPEP]
===================================== gajim/common/zeroconf/connection_handlers_zeroconf.py ===================================== --- a/gajim/common/zeroconf/connection_handlers_zeroconf.py +++ b/gajim/common/zeroconf/connection_handlers_zeroconf.py @@ -50,7 +50,7 @@ class ConnectionVcard:
class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionSocks5BytestreamZeroconf, ConnectionCommands, -connection_handlers.ConnectionPEP, connection_handlers.ConnectionHandlersBase, +connection_handlers.ConnectionHandlersBase, connection_handlers.ConnectionJingle): def __init__(self): ConnectionVcard.__init__(self)
===================================== gajim/dialogs.py ===================================== --- a/gajim/dialogs.py +++ b/gajim/dialogs.py @@ -52,6 +52,7 @@ from gajim.common import ged from gajim.common import const from gajim.options_dialog import OptionsDialog from gajim.common.const import Option, OptionKind, OptionType, ACTIVITIES +from gajim.common.const import MOODS
from gajim.common import app from gajim.common import helpers @@ -505,7 +506,7 @@ class ChangeMoodDialog:
# Order them first self.MOODS = [] - for mood in pep.MOODS: + for mood in MOODS: self.MOODS.append(mood) self.MOODS.sort()
@@ -515,7 +516,7 @@ class ChangeMoodDialog: self.mood_buttons[mood].set_mode(False) self.mood_buttons[mood].add(gtkgui_helpers.load_mood_icon(mood)) self.mood_buttons[mood].set_relief(Gtk.ReliefStyle.NONE) - self.mood_buttons[mood].set_tooltip_text(pep.MOODS[mood]) + self.mood_buttons[mood].set_tooltip_text(MOODS[mood]) self.mood_buttons[mood].connect('clicked', self.on_mood_button_clicked, mood) table.attach(self.mood_buttons[mood], x, y, 1, 1) @@ -526,9 +527,9 @@ class ChangeMoodDialog: x = 0 y += 1
- if self.mood in pep.MOODS: + if self.mood in MOODS: self.mood_buttons[self.mood].set_active(True) - self.label.set_text(pep.MOODS[self.mood]) + self.label.set_text(MOODS[self.mood]) self.entry.set_sensitive(True) if self.text: self.entry.set_text(self.text) @@ -543,7 +544,7 @@ class ChangeMoodDialog:
def on_mood_button_clicked(self, widget, data): if data: - self.label.set_text(pep.MOODS[data]) + self.label.set_text(MOODS[data]) self.entry.set_sensitive(True) else: self.label.set_text(_('None')) @@ -705,7 +706,7 @@ class ChangeStatusMessageDialog(TimeoutDialog): """ img = self.xml.get_object('mood_image') label = self.xml.get_object('mood_button_label') - if 'mood' in self.pep_dict and self.pep_dict['mood'] in pep.MOODS: + if 'mood' in self.pep_dict and self.pep_dict['mood'] in MOODS: img.set_from_pixbuf(gtkgui_helpers.load_mood_icon( self.pep_dict['mood']).get_pixbuf()) if self.pep_dict['mood_text']:
===================================== gajim/gtkgui_helpers.py ===================================== --- a/gajim/gtkgui_helpers.py +++ b/gajim/gtkgui_helpers.py @@ -28,7 +28,6 @@ ##
import xml.sax.saxutils -import gi from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GdkPixbuf @@ -50,9 +49,8 @@ log = logging.getLogger('gajim.gtkgui_helpers')
from gajim.common import i18n from gajim.common import app -from gajim.common import pep from gajim.common import configpaths -from gajim.common.const import PEPEventType, ACTIVITIES +from gajim.common.const import PEPEventType, ACTIVITIES, MOODS from gajim.filechoosers import AvatarSaveDialog
gtk_icon_theme = Gtk.IconTheme.get_default() @@ -623,10 +621,9 @@ def load_activity_icon(category, activity = None): return icon_list[activity]
def get_pep_as_pixbuf(pep_class): - if isinstance(pep_class, pep.UserMoodPEP): - assert not pep_class._retracted + if pep_class == PEPEventType.MOOD: received_mood = pep_class._pep_specific_data['mood'] - mood = received_mood if received_mood in pep.MOODS else 'unknown' + mood = received_mood if received_mood in MOODS else 'unknown' pixbuf = load_mood_icon(mood).get_pixbuf() return pixbuf elif pep_class == PEPEventType.TUNE: @@ -652,7 +649,7 @@ def get_pep_as_pixbuf(pep_class): return load_activity_icon(activity).get_pixbuf() else: return load_activity_icon('unknown').get_pixbuf() - elif isinstance(pep_class, pep.UserLocationPEP): + elif pep_class == PEPEventType.LOCATION: icon = get_icon_pixmap('applications-internet', quiet=True) if not icon: icon = get_icon_pixmap('gajim-earth')
===================================== gajim/gui_interface.py ===================================== --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -97,9 +97,9 @@ from gajim.common.connection_handlers_events import ( HTTPUploadProgressEvent) from gajim.common.connection import Connection from gajim.common.file_props import FilesProp -from gajim.common import pep from gajim import emoticons -from gajim.common.const import AvatarSize, SSLError, PEPEventType, ACTIVITIES +from gajim.common.const import AvatarSize, SSLError, PEPEventType +from gajim.common.const import ACTIVITIES, MOODS
from gajim import roster_window from gajim import profile_window @@ -2474,9 +2474,9 @@ class Interface:
@staticmethod def get_pep_icon(pep_obj): - if isinstance(pep_obj, pep.UserMoodPEP): + if pep_obj == PEPEventType.MOOD: received_mood = pep_obj._pep_specific_data['mood'] - mood = received_mood if received_mood in pep.MOODS else 'unknown' + mood = received_mood if received_mood in MOODS else 'unknown' return gtkgui_helpers.load_mood_icon(mood).get_pixbuf() elif pep_obj == PEPEventType.TUNE: path = os.path.join( @@ -2500,7 +2500,7 @@ class Interface: get_pixbuf() else: return gtkgui_helpers.load_activity_icon('unknown').get_pixbuf() - elif isinstance(pep_obj, pep.UserLocationPEP): + elif pep_obj == PEPEventType.LOCATION: icon = gtkgui_helpers.get_icon_pixmap('applications-internet', quiet=True) return icon
===================================== gajim/profile_window.py ===================================== --- a/gajim/profile_window.py +++ b/gajim/profile_window.py @@ -329,9 +329,9 @@ class ProfileWindow(Gtk.ApplicationWindow): nick = '' if 'NICKNAME' in vcard_: nick = vcard_['NICKNAME'] - app.connections[self.account].send_nickname(nick) + app.connections[self.account].get_module('UserNickname').send(nick) if nick == '': - app.connections[self.account].retract_nickname() + app.connections[self.account].get_module('UserNickname').retract() nick = app.config.get_per('accounts', self.account, 'name') app.nicks[self.account] = nick app.connections[self.account].get_module('VCardTemp').send_vcard(
===================================== gajim/roster_window.py ===================================== --- a/gajim/roster_window.py +++ b/gajim/roster_window.py @@ -1090,10 +1090,10 @@ class RosterWindow: else: self.model[child_iter][Column.TUNE_PIXBUF] = empty_pixbuf
- if app.config.get('show_location_in_roster') and 'location' in \ + if app.config.get('show_location_in_roster') and 'geoloc' in \ pep_dict: self.model[child_iter][Column.LOCATION_PIXBUF] = \ - gtkgui_helpers.get_pep_as_pixbuf(pep_dict['location']) + gtkgui_helpers.get_pep_as_pixbuf(pep_dict['geoloc']) else: self.model[child_iter][Column.LOCATION_PIXBUF] = empty_pixbuf
@@ -1354,7 +1354,7 @@ class RosterWindow: return app.config.get('show_activity_in_roster') elif pep_type == 'tune': return app.config.get('show_tunes_in_roster') - elif pep_type == 'location': + elif pep_type == 'geoloc': return app.config.get('show_location_in_roster') else: return False @@ -2107,9 +2107,9 @@ class RosterWindow: if 'mood' in pep_dict: mood = pep_dict['mood'] mood_text = pep_dict.get('mood_text', None) - connection.send_mood(mood, mood_text) + connection.get_module('UserMood').send((mood, mood_text)) else: - connection.retract_mood() + connection.get_module('UserMood').retract()
def delete_pep(self, jid, account): if jid == app.get_jid_from_account(account): @@ -2651,7 +2651,7 @@ class RosterWindow: if obj.jid == app.get_jid_from_account(obj.conn.name): self.draw_account(obj.conn.name)
- if obj.pep_type == 'nickname': + if obj.pep_type == 'nick': self.draw_contact(obj.jid, obj.conn.name) else: self.draw_pep(obj.jid, obj.conn.name, obj.pep_type) @@ -3610,7 +3610,7 @@ class RosterWindow: if active: location_listener.enable() else: - app.connections[account].retract_location() + app.connections[account].get_module('UserLocation').retract()
helpers.update_optional_features(account)
@@ -5728,7 +5728,7 @@ class RosterWindow: self.renderers_propertys ={} self._pep_type_to_model_column = {'mood': Column.MOOD_PIXBUF, 'activity': Column.ACTIVITY_PIXBUF, 'tune': Column.TUNE_PIXBUF, - 'location': Column.LOCATION_PIXBUF} + 'geoloc': Column.LOCATION_PIXBUF}
renderer_text = Gtk.CellRendererText() self.renderers_propertys[renderer_text] = ('ellipsize', @@ -5761,7 +5761,7 @@ class RosterWindow: 'pixbuf', Column.TUNE_PIXBUF, self._fill_pep_pixbuf_renderer, Column.TUNE_PIXBUF),
- ('location', Gtk.CellRendererPixbuf(), False, + ('geoloc', Gtk.CellRendererPixbuf(), False, 'pixbuf', Column.LOCATION_PIXBUF, self._fill_pep_pixbuf_renderer, Column.LOCATION_PIXBUF))
===================================== gajim/tooltips.py ===================================== --- a/gajim/tooltips.py +++ b/gajim/tooltips.py @@ -577,8 +577,8 @@ class RosterTooltip(Gtk.Window, StatusTable): self.tune.show() self.tune_label.show()
- if 'location' in contact.pep: - location = contact.pep['location'].asMarkupText() + if 'geoloc' in contact.pep: + location = contact.pep['geoloc'].asMarkupText() self.location.set_markup(location) self.location.show() self.location_label.show()
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/1712743fd5372b18c011163d0b8fa76688...