summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-03-12 16:12:47 +0100
committermathieui <mathieui@mathieui.net>2013-03-12 16:12:47 +0100
commitd797b1fd65ba73c48e1933cc8042db0cc548094a (patch)
treed53c18b406f18c236ccee7b72ab71d57d2d5b35c
parentcec1151ecb577a270b9e1f0ae5eaa238d3269ae8 (diff)
downloadpoezio-d797b1fd65ba73c48e1933cc8042db0cc548094a.tar.gz
poezio-d797b1fd65ba73c48e1933cc8042db0cc548094a.tar.bz2
poezio-d797b1fd65ba73c48e1933cc8042db0cc548094a.tar.xz
poezio-d797b1fd65ba73c48e1933cc8042db0cc548094a.zip
Implement user gaming (xep-0196)
- configuration options - theming options - /gaming
-rw-r--r--data/default_config.cfg9
-rw-r--r--doc/en/configure.txt18
-rw-r--r--src/common.py19
-rw-r--r--src/connection.py3
-rw-r--r--src/contact.py1
-rw-r--r--src/core.py65
-rw-r--r--src/tabs.py2
-rw-r--r--src/theming.py3
-rw-r--r--src/windows.py12
9 files changed, 126 insertions, 6 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index 19f435bc..a3e3a49b 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -349,6 +349,15 @@ display_tune_notifications = false
# option will be ignored.
enable_user_tune = true
+# Display user gaming notifications as information messages or not
+display_gaming_notifications = false
+
+# Receive the gaming notifications or not (in order to display informations
+# in the roster).
+# If this is set to false, then the display_gaming_notifications
+# option will be ignored.
+enable_user_gaming = true
+
# Display user mood notifications as information messages or not
display_mood_notifications = false
diff --git a/doc/en/configure.txt b/doc/en/configure.txt
index a11b7e66..0b94a7a8 100644
--- a/doc/en/configure.txt
+++ b/doc/en/configure.txt
@@ -113,6 +113,11 @@ section of this documentation.
the nick you will use when joining a room with no associated nick
If this is empty, the $USER environnement variable will be used
+*display_gaming_notifications*:: false
+
+ If set to true, notifications about the games your are playing
+ will be displayed in the info buffer as 'Gaming' messages.
+
*display_tune_notifications*:: false
If set to true, notifications about the music your contacts listen to
@@ -135,7 +140,12 @@ section of this documentation.
*enable_user_activity*:: true
- Set this to false if you don’t want to receive the mood of your contacts
+ Set this to false if you don’t want to receive the activity of your contacts
+ anymore.
+
+*enable_user_gaming*:: true
+
+ Set this to false if you don’t want to receive the gaming activity of your contacts
anymore.
*enable_user_mood*:: true
@@ -572,6 +582,12 @@ bar = false
If set to true, notifications about the current activity of your contacts
will be displayed in the info buffer as 'Activity' messages.
+*display_gaming_notifications*:: false
+
+ If set to true, notifications about the game your are playing
+ will be displayed in the info buffer as 'Gaming' messages.
+
+
*display_mood_notifications*:: false
If set to true, notifications about the mood of your contacts
diff --git a/src/common.py b/src/common.py
index 5b62732c..16fcfba5 100644
--- a/src/common.py
+++ b/src/common.py
@@ -315,6 +315,25 @@ def format_tune_string(infos):
elems.append('[' + mins + ':' + secs + ']')
return ' '.join(elems)
+def format_gaming_string(infos):
+ """
+ Construct a string from a dict containing the "user gaming"
+ informations.
+ (for now, only use address and name)
+
+ :param dict infos: The informations
+ :returns: The formatted string
+ :rtype: :py:class:`str`
+ """
+ name = infos.get('name')
+ if not name:
+ return ''
+
+ server_address = infos.get('server_address')
+ if server_address:
+ return '%s on %s' % (name, server_address)
+ return name
+
def safeJID(*args, **kwargs):
"""
Construct a :py:class:`sleekxmpp.JID` object from a string.
diff --git a/src/connection.py b/src/connection.py
index 8565a616..b72c8d1f 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -84,6 +84,9 @@ class Connection(sleekxmpp.ClientXMPP):
if config.get('enable_user_activity', 'true') != 'false':
self.register_plugin('xep_0108')
+ if config.get('enable_user_gaming', 'true') != 'false':
+ self.register_plugin('xep_0196')
+
if config.get('send_poezio_info', 'true') == 'true':
info = {'name':'poezio',
'version': options.version}
diff --git a/src/contact.py b/src/contact.py
index 8e6595db..5074a0dc 100644
--- a/src/contact.py
+++ b/src/contact.py
@@ -68,6 +68,7 @@ class Contact(object):
self._name = ''
self.error = None
self.tune = {}
+ self.gaming = {}
self.mood = ''
self.activity = ''
diff --git a/src/core.py b/src/core.py
index 0b041f2d..ff982ae7 100644
--- a/src/core.py
+++ b/src/core.py
@@ -265,9 +265,11 @@ class Core(object):
if config.get('enable_user_nick', 'true') != 'false':
self.xmpp.add_event_handler("user_nick_publish", self.on_nick_received)
if config.get('enable_user_mood', 'true') != 'false':
- self.xmpp.add_event_handler("user_mood_publish", self.on_mood)
+ self.xmpp.add_event_handler("user_mood_publish", self.on_mood_event)
if config.get('enable_user_activity', 'true') != 'false':
- self.xmpp.add_event_handler("user_activity_publish", self.on_activity)
+ self.xmpp.add_event_handler("user_activity_publish", self.on_activity_event)
+ if config.get('enable_user_gaming', 'true') != 'false':
+ self.xmpp.add_event_handler("user_gaming_publish", self.on_gaming_event)
self.xmpp.register_handler(self.all_stanzas)
self.initial_joins = []
@@ -2215,6 +2217,20 @@ class Core(object):
return self.information('%s is not a correct value for an activity' % specific, 'Error')
self.xmpp.plugin['xep_0108'].publish_activity(general, specific, text, block=False)
+ def command_gaming(self, arg):
+ """
+ /gaming [<game name> [server address]]
+ """
+ args = common.shell_split(arg)
+ if not args:
+ return self.xmpp.plugin['xep_1096'].stop(block=False)
+ name = args[0]
+ if len(args) > 1:
+ address = args[1]
+ else:
+ address = None
+ return self.xmpp.plugin['xep_0196'].publish_gaming(name=name, server_address=address, block=False)
+
def completion_activity(self, the_input):
"""Completion for /activity"""
txt = the_input.get_text()
@@ -2303,6 +2319,8 @@ class Core(object):
self.xmpp.plugin['xep_0107'].stop(block=False)
if config.get('enable_user_activity', 'true') != 'false':
self.xmpp.plugin['xep_0108'].stop(block=False)
+ if config.get('enable_user_gaming', 'true') != 'false':
+ self.xmpp.plugin['xep_0196'].stop(block=False)
self.plugin_manager.disable_plugins()
self.disconnect(msg)
self.running = False
@@ -2571,13 +2589,20 @@ class Core(object):
' Nothing means "stop broadcasting an activity".'),
shortdesc=_('Send your activity.'),
completion=self.completion_activity)
- if config.get('eanble_user_activity', 'true') != 'false':
+ if config.get('enable_user_activity', 'true') != 'false':
self.register_command('mood', self.command_mood,
usage='[<mood> [text]]',
desc=_('Send your current mood to your contacts (use the completion).'
' Nothing means "stop broadcasting a mood".'),
shortdesc=_('Send your mood.'),
completion=self.completion_mood)
+ if config.get('enable_user_gaming', 'true') != 'false':
+ self.register_command('gaming', self.command_gaming,
+ usage='[<game name> [server address]]',
+ desc=_('Send your current gaming activity to your contacts.'
+ ' Nothing means "stop broadcasting a mood".'),
+ shortdesc=_('Send your gaming activity.'),
+ completion=None)
####################### XMPP Event Handlers ##################################
@@ -2720,7 +2745,37 @@ class Core(object):
else:
contact.name= ''
- def on_mood(self, message):
+ def on_gaming_event(self, message):
+ """
+ Called when a pep notification for user gaming
+ is received
+ """
+ contact = roster[message['from'].bare]
+ if not contact:
+ return
+ item = message['pubsub_event']['items']['item']
+ if item.find('{urn:xmpp:gaming:0}gaming') is not None:
+ item = item['gaming']
+ # only name and server_address are used for now
+ contact.gaming = {
+ 'character_name': item['character_name'],
+ 'character_profile': item['character_profile'],
+ 'name': item['name'],
+ 'level': item['level'],
+ 'uri': item['uri'],
+ 'server_name': item['server_name'],
+ 'server_address': item['server_address'],
+ }
+ else:
+ contact.gaming = {}
+
+ if config.get_by_tabname('display_gaming_notifications', 'false', contact.bare_jid) == 'true':
+ if contact.gaming:
+ self.information('%s is playing %s' % (contact.bare_jid, common.format_gaming_string(contact.gaming)), 'Gaming')
+ else:
+ self.information(contact.bare_jid + ' stopped playing.', 'Gaming')
+
+ def on_mood_event(self, message):
"""
Called when a pep notification for an user mood
is received.
@@ -2747,7 +2802,7 @@ class Core(object):
else:
self.information(contact.bare_jid + ' stopped having his/her mood.', 'Mood')
- def on_activity(self, message):
+ def on_activity_event(self, message):
"""
Called when a pep notification for an user activity
is received.
diff --git a/src/tabs.py b/src/tabs.py
index ed2a5998..6cd3be86 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -2855,6 +2855,8 @@ class RosterInfoTab(Tab):
acc.append('Mood: %s' % cont.mood)
if cont.activity:
acc.append('Activity: %s' % cont.activity)
+ if cont.gaming:
+ acc.append('Game: %s' % (common.format_gaming_string(cont.gaming)))
msg = '\n'.join(acc)
elif isinstance(selected_row, Resource):
res = selected_row
diff --git a/src/theming.py b/src/theming.py
index 26b66377..f7a0b431 100644
--- a/src/theming.py
+++ b/src/theming.py
@@ -204,7 +204,9 @@ class Theme(object):
CHAR_ROSTER_ASKED = '?'
CHAR_ROSTER_ACTIVITY = '☃'
CHAR_ROSTER_MOOD = '☺'
+ CHAR_ROSTER_GAMING = '♠'
+ COLOR_ROSTER_GAMING = (6, -1)
COLOR_ROSTER_MOOD = (2, -1)
COLOR_ROSTER_ACTIVITY = (3, -1)
COLOR_ROSTER_TUNE = (6, -1)
@@ -225,6 +227,7 @@ class Theme(object):
'help': (10, -1),
'headline': (11, -1, 'b'),
'tune': (6, -1),
+ 'gaming': (6, -1),
'mood': (2, -1),
'activity': (3, -1),
'default': (7, -1),
diff --git a/src/windows.py b/src/windows.py
index c4927a6d..0916cadb 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -1942,6 +1942,8 @@ class RosterWin(Win):
added += len(get_theme().CHAR_ROSTER_MOOD)
if contact.activity:
added += len(get_theme().CHAR_ROSTER_ACTIVITY)
+ if contact.gaming:
+ added += len(get_theme().CHAR_ROSTER_GAMING)
if config.getl('show_roster_jids', 'true') == 'false' and contact.name:
display_name = '%s' % contact.name
@@ -1966,6 +1968,8 @@ class RosterWin(Win):
self.addstr(get_theme().CHAR_ROSTER_ACTIVITY, to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY))
if contact.mood:
self.addstr(get_theme().CHAR_ROSTER_MOOD, to_curses_attr(get_theme().COLOR_ROSTER_MOOD))
+ if contact.gaming:
+ self.addstr(get_theme().CHAR_ROSTER_GAMING, to_curses_attr(get_theme().COLOR_ROSTER_GAMING))
self.finish_line()
def draw_resource_line(self, y, resource, colored):
@@ -2033,14 +2037,22 @@ class ContactInfoWin(Win):
if contact.tune:
self.addstr(i, 0, 'Current Tune: %s' % common.format_tune_string(contact.tune), to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
+ self.finish_line()
i += 1
if contact.mood:
self.addstr(i, 0, 'Mood: %s' % contact.mood, to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
+ self.finish_line()
i += 1
if contact.activity:
self.addstr(i, 0, 'Activity: %s' % contact.activity, to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
+ self.finish_line()
+ i += 1
+
+ if contact.gaming:
+ self.addstr(i, 0, 'Game: %s on %s' % (contact.gaming['name'], contact.gamin['server_address']), to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
+ self.finish_line()
i += 1
def draw_group_info(self, group):