Actually join the activity, check for duplicates in the model.

master
Marco Pesenti Gritti 18 years ago
parent c6d59fd7b4
commit 7ab6da7278

@ -30,20 +30,31 @@ class ActivitiesModel(gobject.GObject):
def __init__(self, registry):
gobject.GObject.__init__(self)
self._activities = []
self._activities = {}
self._registry = registry
self._pservice = PresenceService()
self._pservice.connect("service-appeared", self.__service_appeared_cb)
for service in self._pservice.get_services():
self.__check_service(service)
def has_activity(self, activity_id):
return self._activities.has_key(activity_id)
def add_activity(self, service):
activity_info = ActivityInfo(service)
self._activities.append(activity_info)
self._activities[activity_info.get_id()] = (activity_info)
self.emit('activity-added', activity_info)
def __iter__(self):
return self._activities.__iter__()
activities = self._activities.values()
return activities.__iter__()
def __service_appeared_cb(self, pservice, service):
self.__check_service(service)
def __check_service(self, service):
if self._registry.get_activity(service.get_type()) != None:
self.add_activity(service)
if not self.has_activity(service.get_activity_id()):
self.add_activity(service)

@ -1,4 +1,5 @@
import sys
import logging
import dbus
import dbus.service
@ -116,7 +117,7 @@ class ActivityDbusService(dbus.service.Object):
@dbus.service.method(ACTIVITY_SERVICE_NAME)
def get_shared(self):
"""Get the activity identifier"""
"""Returns True if the activity is shared on the mesh."""
return self._activity.get_shared()
class Activity(gtk.Window):
@ -165,10 +166,23 @@ class Activity(gtk.Window):
return self._activity_id
def join(self, activity_ps):
"""Join an activity shared on the network"""
"""Join an activity shared on the network."""
self._shared = True
self._activity_id = activity_ps.get_id()
# Publish the default service, it's a copy of
# one of those we found on the network.
services = activity_ps.get_services_of_type(self._default_type)
if len(services) > 0:
service = services[0]
addr = service.get_address()
port = service.get_port()
properties = { 'title' : service.get_published_value('title') }
self._service = self._pservice.share_activity(self,
self._default_type, properties, addr, port)
else:
logging.error('Cannot join the activity')
def share(self):
"""Share the activity on the network."""
properties = { 'title' : self.get_title() }

Loading…
Cancel
Save