Initial User Tune support

This commit is contained in:
Piotr Gaczkowski 2007-04-01 09:02:04 +00:00
parent 6917ab7ff5
commit 19c5c70f80
4 changed files with 85 additions and 6 deletions

View file

@ -29,6 +29,7 @@ class Contact:
# FIXME
self.mood = dict()
self.activity = dict()
self.tune = dict()
self.sub = sub
self.ask = ask
self.resource = resource

View file

@ -18,7 +18,33 @@ def user_mood(items, name, jid):
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 @@ def user_send_activity(account, activity, subactivity = '', message = ''):
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')

View file

@ -2984,14 +2984,25 @@ class RosterWindow:
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 @@ class RosterWindow:
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):

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
## tooltips.py
##
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
@ -497,6 +498,23 @@ class RosterTooltip(NotificationAreaTooltip):
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: