2006-07-15 12:31:06 +02:00
|
|
|
import xml.sax.saxutils
|
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
import gobject
|
|
|
|
|
2006-07-14 16:40:45 +02:00
|
|
|
from sugar.presence.PresenceService import PresenceService
|
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
class ActivityInfo:
|
|
|
|
def __init__(self, service):
|
|
|
|
self._service = service
|
|
|
|
|
|
|
|
def get_id(self):
|
2006-07-15 12:31:06 +02:00
|
|
|
activity_id = self._service.get_one_property('activity_id')
|
|
|
|
|
|
|
|
def get_type(self):
|
|
|
|
return self._service.get_type()
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
def get_title(self):
|
2006-07-15 12:31:06 +02:00
|
|
|
escaped_title = self._service.get_one_property('Title')
|
2006-07-14 15:47:42 +02:00
|
|
|
title = xml.sax.saxutils.unescape(escaped_title)
|
2006-07-15 12:31:06 +02:00
|
|
|
return title
|
|
|
|
|
|
|
|
def get_service(self):
|
|
|
|
return self._service
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
class ActivitiesModel(gobject.GObject):
|
|
|
|
__gsignals__ = {
|
|
|
|
'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT])),
|
2006-07-14 16:40:45 +02:00
|
|
|
'activity-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT]))
|
2006-07-14 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
2006-07-14 16:40:45 +02:00
|
|
|
gobject.GObject.__init__(self)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
self._activities = []
|
|
|
|
|
2006-07-20 10:12:42 +02:00
|
|
|
self._pservice = PresenceService()
|
|
|
|
self._pservice.connect("ActivityAppeared", self._on_activity_announced_cb)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
def add_activity(self, service):
|
|
|
|
activity_info = ActivityInfo(service)
|
|
|
|
self._activities.append(activity_info)
|
|
|
|
self.emit('activity-added', activity_info)
|
|
|
|
|
|
|
|
def __iter__(self):
|
2006-07-14 16:40:45 +02:00
|
|
|
return self._activities.__iter__()
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
def _on_activity_announced_cb(self, pservice, service, buddy):
|
2006-07-15 12:31:06 +02:00
|
|
|
# FIXME We should not hard code activity types here
|
|
|
|
if service.get_type() == "_web_olpc._udp":
|
|
|
|
self.add_activity(service)
|