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-08-08 12:01:45 +02:00
|
|
|
from ActivityRegistry import ActivityRegistry
|
2006-07-14 16:40:45 +02:00
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
class ActivityInfo:
|
|
|
|
def __init__(self, service):
|
|
|
|
self._service = service
|
|
|
|
|
|
|
|
def get_id(self):
|
2006-08-08 12:01:45 +02:00
|
|
|
return self._service.get_activity_id()
|
2006-07-15 12:31:06 +02:00
|
|
|
|
|
|
|
def get_type(self):
|
2006-08-08 12:01:45 +02:00
|
|
|
return self._service.get_type()
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
def get_title(self):
|
2006-08-08 12:08:16 +02:00
|
|
|
return self._service.get_published_value('title')
|
2006-07-15 12:31:06 +02:00
|
|
|
|
|
|
|
def get_service(self):
|
|
|
|
return self._service
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-08-19 11:12:25 +02:00
|
|
|
class MeshModel(gobject.GObject):
|
2006-07-14 15:47:42 +02:00
|
|
|
__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
|
|
|
}
|
|
|
|
|
2006-08-08 12:01:45 +02:00
|
|
|
def __init__(self, registry):
|
2006-07-14 16:40:45 +02:00
|
|
|
gobject.GObject.__init__(self)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-08-09 01:50:35 +02:00
|
|
|
self._activities = {}
|
2006-08-08 12:01:45 +02:00
|
|
|
self._registry = registry
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-07-20 10:12:42 +02:00
|
|
|
self._pservice = PresenceService()
|
2006-08-08 12:01:45 +02:00
|
|
|
self._pservice.connect("service-appeared", self.__service_appeared_cb)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-08-09 01:50:35 +02:00
|
|
|
for service in self._pservice.get_services():
|
|
|
|
self.__check_service(service)
|
|
|
|
|
|
|
|
def has_activity(self, activity_id):
|
|
|
|
return self._activities.has_key(activity_id)
|
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
def add_activity(self, service):
|
|
|
|
activity_info = ActivityInfo(service)
|
2006-08-09 01:50:35 +02:00
|
|
|
self._activities[activity_info.get_id()] = (activity_info)
|
2006-07-14 15:47:42 +02:00
|
|
|
self.emit('activity-added', activity_info)
|
|
|
|
|
|
|
|
def __iter__(self):
|
2006-08-09 01:50:35 +02:00
|
|
|
activities = self._activities.values()
|
|
|
|
return activities.__iter__()
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-08-08 12:01:45 +02:00
|
|
|
def __service_appeared_cb(self, pservice, service):
|
2006-08-09 01:50:35 +02:00
|
|
|
self.__check_service(service)
|
|
|
|
|
|
|
|
def __check_service(self, service):
|
2006-08-08 12:01:45 +02:00
|
|
|
if self._registry.get_activity(service.get_type()) != None:
|
2006-08-09 01:50:35 +02:00
|
|
|
if not self.has_activity(service.get_activity_id()):
|
|
|
|
self.add_activity(service)
|