Improve the activity api

This commit is contained in:
Marco Pesenti Gritti 2006-08-09 01:08:19 +02:00
parent f1821704e7
commit c6d59fd7b4
4 changed files with 44 additions and 42 deletions

View File

@ -9,18 +9,10 @@ from sugar.p2p.model.RemoteModel import RemoteModel
from NotificationBar import NotificationBar
from NavigationToolbar import NavigationToolbar
_SERVICE_URI_TAG = "URI"
_SERVICE_TITLE_TAG = "Title"
class BrowserActivity(Activity):
SOLO = 1
FOLLOWING = 2
LEADING = 3
def __init__(self):
Activity.__init__(self)
def __init__(self, service):
Activity.__init__(self, service)
self._mode = BrowserActivity.SOLO
self._share_service = None
self._model_service = None
self._notif_service = None
@ -46,16 +38,19 @@ class BrowserActivity(Activity):
self.add(vbox)
vbox.show()
if service:
service.connect('service-appeared', self._service_appeared_cb)
def join(self, activity_ps):
Activity.join(self, activity_ps)
services = service.get_services_of_type('_web_olpc._udp')
if len(services) > 0:
self._notif_service = services[0]
activity_ps.connect('service-appeared', self._service_appeared_cb)
services = service.get_services_of_type(LocalModel.SERVICE_TYPE)
if len(services) > 0:
self._model_service = services[0]
default_type = self.get_default_type()
services = activity_ps.get_services_of_type(default_type)
if len(services) > 0:
self._notif_service = services[0]
services = activity_ps.get_services_of_type(LocalModel.SERVICE_TYPE)
if len(services) > 0:
self._model_service = services[0]
if self._notif_service and self._model_service:
self._listen_to_model()
@ -64,8 +59,7 @@ class BrowserActivity(Activity):
if service.get_type() == self._default_type:
self._notif_service = service
elif service.get_type() == LocalModel.SERVICE_TYPE:
if self._mode != BrowserActivity.LEADING:
self._model_service = service
self._model_service = service
if not self._model and self._notif_service and self._model_service:
self._listen_to_model()
@ -92,14 +86,6 @@ class BrowserActivity(Activity):
self.embed.load_address(address)
self._notif_bar.hide()
def set_mode(self, mode):
self._mode = mode
if mode == BrowserActivity.LEADING:
self._notif_bar.set_text('Share this page with the group.')
self._notif_bar.set_action('set_shared_location', 'Share')
self._notif_bar.set_icon('stock_shared-by-me')
self._notif_bar.show()
def get_embed(self):
return self.embed
@ -110,7 +96,10 @@ class BrowserActivity(Activity):
self._model.set_value('owner', self._pservice.get_owner().get_name())
self._update_shared_location()
self.set_mode(BrowserActivity.LEADING)
self._notif_bar.set_text('Share this page with the group.')
self._notif_bar.set_action('set_shared_location', 'Share')
self._notif_bar.set_icon('stock_shared-by-me')
self._notif_bar.show()
def __title_cb(self, embed):
self.set_title(embed.get_title())

View File

@ -1,5 +1,3 @@
import xml.sax.saxutils
import gobject
from sugar.presence.PresenceService import PresenceService

View File

@ -5,6 +5,7 @@ import wnck
from sugar.activity import Activity
from ActivitiesModel import ActivitiesModel
from sugar.presence.PresenceService import PresenceService
class NewActivityButton(gtk.MenuToolButton):
def __init__(self, home):
@ -72,7 +73,15 @@ class ActivitiesGrid(gtk.VBox):
def __button_clicked_cb(self, button, info):
activity = self._shell.get_registry().get_activity(info.get_type())
Activity.create(activity.get_id(), info.get_service())
activity_id = info.get_service().get_activity_id()
pservice = PresenceService()
activity_ps = pservice.get_activity(activity_id)
if activity_ps:
Activity.create(activity.get_id(), activity_ps)
else:
print 'Cannot start activity.'
class TasksGrid(gtk.VBox):
def __init__(self, home):

View File

@ -52,12 +52,16 @@ class ActivityFactory(dbus.service.Object):
def create_with_service(self, service_path):
pservice = PresenceService()
service = pservice.get(service_path)
activity = self._class(service)
activity = self._class()
activity.set_default_type(self._default_type)
activity.join(service)
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
def create(self):
activity = self._class(None)
activity = self._class()
activity.set_default_type(self._default_type)
def create(activity_name, service = None):
"""Create a new activity from his name."""
@ -121,13 +125,8 @@ class Activity(gtk.Window):
def __init__(self, service = None):
gtk.Window.__init__(self)
if service:
self._activity_id = service.get_activity_id()
self._shared = True
else:
self._activity_id = sugar.util.unique_id()
self._shared = False
self._shared = False
self._activity_id = None
self._default_type = None
self._pservice = PresenceService()
@ -161,10 +160,17 @@ class Activity(gtk.Window):
def get_id(self):
"""Get the unique activity identifier."""
if self._activity_id == None:
self._activity_id = sugar.util.unique_id()
return self._activity_id
def join(self, activity_ps):
"""Join an activity shared on the network"""
self._shared = True
self._activity_id = activity_ps.get_id()
def share(self):
"""Called to request the activity to share itself on the network."""
"""Share the activity on the network."""
properties = { 'title' : self.get_title() }
self._service = self._pservice.share_activity(self,
self._default_type,