Author: doomhammer
Date: 2007-04-01 11:02:04 +0200 (Sun, 01 Apr 2007)
New Revision: 8061
Modified:
branches/pep/src/common/contacts.py
branches/pep/src/common/pep.py
branches/pep/src/roster_window.py
branches/pep/src/tooltips.py
Log:
Initial User Tune support
Modified: branches/pep/src/common/contacts.py
===================================================================
--- branches/pep/src/common/contacts.py 2007-03-31 13:40:23 UTC (rev 8060)
+++ branches/pep/src/common/contacts.py 2007-04-01 09:02:04 UTC (rev 8061)
@@ -29,6 +29,7 @@
# FIXME
self.mood = dict()
self.activity = dict()
+ self.tune = dict()
self.sub = sub
self.ask = ask
self.resource = resource
Modified: branches/pep/src/common/pep.py
===================================================================
--- branches/pep/src/common/pep.py 2007-03-31 13:40:23 UTC (rev 8060)
+++ branches/pep/src/common/pep.py 2007-04-01 09:02:04 UTC (rev 8061)
@@ -18,7 +18,33 @@
contact.mood['text'] = ch.getData()
def user_tune(items, name, jid):
- pass
+ (user, resource) = gajim.get_room_and_nick_from_fjid(jid)
+ contacts = gajim.contacts.get_contact(name, user, resource=resource)
+ for item in items.getTags('item'):
+ child = item.getTag('tune')
+ if child is not None:
+ for contact in contacts:
+ if contact.tune.has_key('artist'):
+ del contact.tune['artist']
+ if contact.tune.has_key('title'):
+ del contact.tune['title']
+ if contact.tune.has_key('source'):
+ del contact.tune['source']
+ if contact.tune.has_key('track'):
+ del contact.tune['track']
+ if contact.tune.has_key('length'):
+ del contact.tune['length']
+ for ch in child.getChildren():
+ if ch.getName() == 'artist':
+ contact.tune['artist'] = ch.getData()
+ elif ch.getName() == 'title':
+ contact.tune['title'] = ch.getData()
+ elif ch.getName() == 'source':
+ contact.tune['source'] = ch.getData()
+ elif ch.getName() == 'track':
+ contact.tune['track'] = ch.getData()
+ elif ch.getName() == 'length':
+ contact.tune['length'] = ch.getData()
def user_geoloc(items, name, jid):
pass
@@ -63,3 +89,25 @@
i.addData(message)
gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item, '0')
+
+def user_send_tune(account, artist = '', title = '', source = '', track = 0,length = 0, items = None):
+ item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE})
+ if artist != '':
+ i = item.addChild('artist')
+ i.addData(artist)
+ if title != '':
+ i = item.addChild('title')
+ i.addData(title)
+ if source != '':
+ i = item.addChild('source')
+ i.addData(source)
+ if track != 0:
+ i = item.addChild('track')
+ i.addData(track)
+ if length != 0:
+ i = item.addChild('length')
+ i.addData(length)
+ if items is not None:
+ item.addChild(payload=items)
+
+ gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0')
Modified: branches/pep/src/roster_window.py
===================================================================
--- branches/pep/src/roster_window.py 2007-03-31 13:40:23 UTC (rev 8060)
+++ branches/pep/src/roster_window.py 2007-04-01 09:02:04 UTC (rev 8061)
@@ -2984,14 +2984,25 @@
self._music_track_changed(None, None)
def _music_track_changed(self, unused_listener, music_track_info):
+ from common import pep
accounts = gajim.connections.keys()
if music_track_info is None:
- status_message = ''
+ artist = ''
+ title = ''
+ source = ''
+ track = ''
+ length = ''
else:
if hasattr(music_track_info, 'paused') and \
music_track_info.paused == 0:
- status_message = ''
+ artist = ''
+ title = ''
+ source = ''
+ track = ''
+ length = ''
else:
+ artist = music_track_info.artist
+ title = music_track_info.title
status_message = '♪ ' + _('"%(title)s" by %(artist)s') % \
{'title': music_track_info.title,
'artist': music_track_info.artist } + ' ♪'
@@ -2999,10 +3010,11 @@
if not gajim.config.get_per('accounts', account,
'sync_with_global_status'):
continue
- if not gajim.connections[account].connected:
+ #FIXME: updates should arrive, when all accounts are
+ # connected and we know their abilities
+ if not gajim.connections[account].pep_supported:
continue
- current_show = gajim.SHOW_LIST[gajim.connections[account].connected]
- self.send_status(account, current_show, status_message)
+ pep.user_send_tune(account, artist, title, source = '')
def update_status_combobox(self):
Modified: branches/pep/src/tooltips.py
===================================================================
--- branches/pep/src/tooltips.py 2007-03-31 13:40:23 UTC (rev 8060)
+++ branches/pep/src/tooltips.py 2007-04-01 09:02:04 UTC (rev 8061)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
## tooltips.py
##
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov(a)gmail.com>
@@ -497,6 +498,23 @@
activity_string += ' (%s)' % activity_text
properties.append((activity_string, None))
+ if contact.tune.has_key('artist') or contact.tune.has_key('title'):
+ if contact.tune.has_key('artist'):
+ artist = contact.tune['artist'].strip()
+ else:
+ artist = _('Unknown Artist')
+ if contact.tune.has_key('title'):
+ title = contact.tune['title'].strip()
+ else:
+ title = _('Unknown Title')
+ if contact.tune.has_key('source'):
+ source = contact.tune['source'].strip()
+ else:
+ source = _('Unknown Source')
+ tune_string = '♪ ' + _('<b>"%(title)s"</b> by <i>%(artist)s</i>\nfrom <i>%(source)s</i>' %\
+ {'title': title, 'artist': artist, 'source': source}) + ' ♪'
+ properties.append((tune_string, None))
+
if contact.status:
status = contact.status.strip()
if status: