Improve the activity api
This commit is contained in:
parent
f1821704e7
commit
c6d59fd7b4
@ -9,18 +9,10 @@ from sugar.p2p.model.RemoteModel import RemoteModel
|
|||||||
from NotificationBar import NotificationBar
|
from NotificationBar import NotificationBar
|
||||||
from NavigationToolbar import NavigationToolbar
|
from NavigationToolbar import NavigationToolbar
|
||||||
|
|
||||||
_SERVICE_URI_TAG = "URI"
|
|
||||||
_SERVICE_TITLE_TAG = "Title"
|
|
||||||
|
|
||||||
class BrowserActivity(Activity):
|
class BrowserActivity(Activity):
|
||||||
SOLO = 1
|
def __init__(self):
|
||||||
FOLLOWING = 2
|
Activity.__init__(self)
|
||||||
LEADING = 3
|
|
||||||
|
|
||||||
def __init__(self, service):
|
|
||||||
Activity.__init__(self, service)
|
|
||||||
|
|
||||||
self._mode = BrowserActivity.SOLO
|
|
||||||
self._share_service = None
|
self._share_service = None
|
||||||
self._model_service = None
|
self._model_service = None
|
||||||
self._notif_service = None
|
self._notif_service = None
|
||||||
@ -46,16 +38,19 @@ class BrowserActivity(Activity):
|
|||||||
self.add(vbox)
|
self.add(vbox)
|
||||||
vbox.show()
|
vbox.show()
|
||||||
|
|
||||||
if service:
|
def join(self, activity_ps):
|
||||||
service.connect('service-appeared', self._service_appeared_cb)
|
Activity.join(self, activity_ps)
|
||||||
|
|
||||||
services = service.get_services_of_type('_web_olpc._udp')
|
activity_ps.connect('service-appeared', self._service_appeared_cb)
|
||||||
if len(services) > 0:
|
|
||||||
self._notif_service = services[0]
|
|
||||||
|
|
||||||
services = service.get_services_of_type(LocalModel.SERVICE_TYPE)
|
default_type = self.get_default_type()
|
||||||
if len(services) > 0:
|
services = activity_ps.get_services_of_type(default_type)
|
||||||
self._model_service = services[0]
|
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:
|
if self._notif_service and self._model_service:
|
||||||
self._listen_to_model()
|
self._listen_to_model()
|
||||||
@ -64,8 +59,7 @@ class BrowserActivity(Activity):
|
|||||||
if service.get_type() == self._default_type:
|
if service.get_type() == self._default_type:
|
||||||
self._notif_service = service
|
self._notif_service = service
|
||||||
elif service.get_type() == LocalModel.SERVICE_TYPE:
|
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:
|
if not self._model and self._notif_service and self._model_service:
|
||||||
self._listen_to_model()
|
self._listen_to_model()
|
||||||
@ -92,14 +86,6 @@ class BrowserActivity(Activity):
|
|||||||
self.embed.load_address(address)
|
self.embed.load_address(address)
|
||||||
self._notif_bar.hide()
|
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):
|
def get_embed(self):
|
||||||
return self.embed
|
return self.embed
|
||||||
|
|
||||||
@ -110,7 +96,10 @@ class BrowserActivity(Activity):
|
|||||||
self._model.set_value('owner', self._pservice.get_owner().get_name())
|
self._model.set_value('owner', self._pservice.get_owner().get_name())
|
||||||
self._update_shared_location()
|
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):
|
def __title_cb(self, embed):
|
||||||
self.set_title(embed.get_title())
|
self.set_title(embed.get_title())
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import xml.sax.saxutils
|
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
from sugar.presence.PresenceService import PresenceService
|
from sugar.presence.PresenceService import PresenceService
|
||||||
|
@ -5,6 +5,7 @@ import wnck
|
|||||||
|
|
||||||
from sugar.activity import Activity
|
from sugar.activity import Activity
|
||||||
from ActivitiesModel import ActivitiesModel
|
from ActivitiesModel import ActivitiesModel
|
||||||
|
from sugar.presence.PresenceService import PresenceService
|
||||||
|
|
||||||
class NewActivityButton(gtk.MenuToolButton):
|
class NewActivityButton(gtk.MenuToolButton):
|
||||||
def __init__(self, home):
|
def __init__(self, home):
|
||||||
@ -72,7 +73,15 @@ class ActivitiesGrid(gtk.VBox):
|
|||||||
|
|
||||||
def __button_clicked_cb(self, button, info):
|
def __button_clicked_cb(self, button, info):
|
||||||
activity = self._shell.get_registry().get_activity(info.get_type())
|
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):
|
class TasksGrid(gtk.VBox):
|
||||||
def __init__(self, home):
|
def __init__(self, home):
|
||||||
|
@ -52,13 +52,17 @@ class ActivityFactory(dbus.service.Object):
|
|||||||
def create_with_service(self, service_path):
|
def create_with_service(self, service_path):
|
||||||
pservice = PresenceService()
|
pservice = PresenceService()
|
||||||
service = pservice.get(service_path)
|
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")
|
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
|
||||||
def create(self):
|
def create(self):
|
||||||
activity = self._class(None)
|
activity = self._class()
|
||||||
activity.set_default_type(self._default_type)
|
activity.set_default_type(self._default_type)
|
||||||
|
|
||||||
|
|
||||||
def create(activity_name, service = None):
|
def create(activity_name, service = None):
|
||||||
"""Create a new activity from his name."""
|
"""Create a new activity from his name."""
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
@ -121,13 +125,8 @@ class Activity(gtk.Window):
|
|||||||
def __init__(self, service = None):
|
def __init__(self, service = None):
|
||||||
gtk.Window.__init__(self)
|
gtk.Window.__init__(self)
|
||||||
|
|
||||||
if service:
|
self._shared = False
|
||||||
self._activity_id = service.get_activity_id()
|
self._activity_id = None
|
||||||
self._shared = True
|
|
||||||
else:
|
|
||||||
self._activity_id = sugar.util.unique_id()
|
|
||||||
self._shared = False
|
|
||||||
|
|
||||||
self._default_type = None
|
self._default_type = None
|
||||||
self._pservice = PresenceService()
|
self._pservice = PresenceService()
|
||||||
|
|
||||||
@ -161,10 +160,17 @@ class Activity(gtk.Window):
|
|||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
"""Get the unique activity identifier."""
|
"""Get the unique activity identifier."""
|
||||||
|
if self._activity_id == None:
|
||||||
|
self._activity_id = sugar.util.unique_id()
|
||||||
return self._activity_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):
|
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() }
|
properties = { 'title' : self.get_title() }
|
||||||
self._service = self._pservice.share_activity(self,
|
self._service = self._pservice.share_activity(self,
|
||||||
self._default_type,
|
self._default_type,
|
||||||
|
Loading…
Reference in New Issue
Block a user