Refactor activity share/join in Activity.__init__() to be clearer and cover all cases
Remove the 'pservice_id' attribute of the ActivityHandle too, since it was completely pointless and should have been the same as the activity id anyway. Share/join is handled in the Activity.__init__() method and the shell doesn't really need to know about it at all.
This commit is contained in:
parent
d79db5d172
commit
739b9160b1
2
NEWS
2
NEWS
@ -1,3 +1,5 @@
|
|||||||
|
* Refactor activity share/join in Activity.__init__() to be clearer and cover
|
||||||
|
all cases (dcbw)
|
||||||
* #2971: Fix palette flash when the mouse pointer leave the palete and go
|
* #2971: Fix palette flash when the mouse pointer leave the palete and go
|
||||||
over the Invoker (marco)
|
over the Invoker (marco)
|
||||||
|
|
||||||
|
@ -131,8 +131,6 @@ class Shell(gobject.GObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
handle = ActivityHandle(activity_id)
|
handle = ActivityHandle(activity_id)
|
||||||
handle.pservice_id = activity_id
|
|
||||||
|
|
||||||
activityfactory.create(bundle_id, handle)
|
activityfactory.create(bundle_id, handle)
|
||||||
|
|
||||||
def notify_launch(self, bundle_id, activity_id):
|
def notify_launch(self, bundle_id, activity_id):
|
||||||
|
@ -44,9 +44,9 @@ from sugar import wm
|
|||||||
from sugar import profile
|
from sugar import profile
|
||||||
from sugar import _sugarext
|
from sugar import _sugarext
|
||||||
|
|
||||||
SHARE_PRIVATE = "private"
|
SCOPE_PRIVATE = "private"
|
||||||
SHARE_INVITE_ONLY = "invite" # shouldn't be shown in UI, it's implicit when you invite somebody
|
SCOPE_INVITE_ONLY = "invite" # shouldn't be shown in UI, it's implicit when you invite somebody
|
||||||
SHARE_NEIGHBORHOOD = "public"
|
SCOPE_NEIGHBORHOOD = "public"
|
||||||
|
|
||||||
class ActivityToolbar(gtk.Toolbar):
|
class ActivityToolbar(gtk.Toolbar):
|
||||||
def __init__(self, activity):
|
def __init__(self, activity):
|
||||||
@ -75,9 +75,9 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
|
|
||||||
self.share = ToolComboBox(label_text=_('Share with:'))
|
self.share = ToolComboBox(label_text=_('Share with:'))
|
||||||
self.share.combo.connect('changed', self._share_changed_cb)
|
self.share.combo.connect('changed', self._share_changed_cb)
|
||||||
self.share.combo.append_item(SHARE_PRIVATE, _('Private'),
|
self.share.combo.append_item(SCOPE_PRIVATE, _('Private'),
|
||||||
'zoom-home-mini')
|
'zoom-home-mini')
|
||||||
self.share.combo.append_item(SHARE_NEIGHBORHOOD, _('My Neighborhood'),
|
self.share.combo.append_item(SCOPE_NEIGHBORHOOD, _('My Neighborhood'),
|
||||||
'zoom-neighborhood-mini')
|
'zoom-neighborhood-mini')
|
||||||
self.insert(self.share, -1)
|
self.insert(self.share, -1)
|
||||||
self.share.show()
|
self.share.show()
|
||||||
@ -117,9 +117,9 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
model = self.share.combo.get_model()
|
model = self.share.combo.get_model()
|
||||||
it = self.share.combo.get_active_iter()
|
it = self.share.combo.get_active_iter()
|
||||||
(scope, ) = model.get(it, 0)
|
(scope, ) = model.get(it, 0)
|
||||||
if scope == SHARE_NEIGHBORHOOD:
|
if scope == SCOPE_NEIGHBORHOOD:
|
||||||
self._activity.share()
|
self._activity.share()
|
||||||
elif scope == SHARE_INVITE_ONLY:
|
elif scope == SCOPE_INVITE_ONLY:
|
||||||
self._activity.share(private=True)
|
self._activity.share(private=True)
|
||||||
|
|
||||||
def _keep_clicked_cb(self, button):
|
def _keep_clicked_cb(self, button):
|
||||||
@ -267,19 +267,11 @@ class Activity(Window, gtk.Container):
|
|||||||
self._closing = False
|
self._closing = False
|
||||||
self._max_participants = 0
|
self._max_participants = 0
|
||||||
|
|
||||||
shared_activity = handle.get_shared_activity()
|
|
||||||
if shared_activity:
|
|
||||||
# Join an existing instance of this activity on the network
|
|
||||||
self._shared_activity = shared_activity
|
|
||||||
self._join_id = self._shared_activity.connect("joined", self._internal_joined_cb)
|
|
||||||
if not self._shared_activity.props.joined:
|
|
||||||
self._shared_activity.join()
|
|
||||||
else:
|
|
||||||
self._internal_joined_cb(self._shared_activity, True, None)
|
|
||||||
|
|
||||||
self._bus = ActivityService(self)
|
self._bus = ActivityService(self)
|
||||||
self._owns_file = False
|
self._owns_file = False
|
||||||
|
|
||||||
|
share_scope = SCOPE_PRIVATE
|
||||||
|
|
||||||
if handle.object_id:
|
if handle.object_id:
|
||||||
self._jobject = datastore.get(handle.object_id)
|
self._jobject = datastore.get(handle.object_id)
|
||||||
# TODO: Don't create so many objects until we have versioning
|
# TODO: Don't create so many objects until we have versioning
|
||||||
@ -289,25 +281,11 @@ class Activity(Window, gtk.Container):
|
|||||||
del self._jobject.metadata['mtime']
|
del self._jobject.metadata['mtime']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
share_scope = self._jobject.metadata['share-scope']
|
||||||
title = self._jobject.metadata['title']
|
title = self._jobject.metadata['title']
|
||||||
self.set_title(title)
|
self.set_title(title)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
|
||||||
# Explicitly share the activity if it used to be shared,
|
|
||||||
# but there isn't an instance out there now
|
|
||||||
scope = self._jobject.metadata['share-scope']
|
|
||||||
if not shared_activity:
|
|
||||||
logging.debug("share scope %s" % scope)
|
|
||||||
if scope == SHARE_INVITE_ONLY:
|
|
||||||
self.share(private=True)
|
|
||||||
elif scope == SHARE_NEIGHBORHOOD:
|
|
||||||
self.share(private=False)
|
|
||||||
else:
|
|
||||||
logging.debug("Unknown share scope %r" % scope)
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
elif create_jobject:
|
elif create_jobject:
|
||||||
logging.debug('Creating a jobject.')
|
logging.debug('Creating a jobject.')
|
||||||
self._jobject = datastore.create()
|
self._jobject = datastore.create()
|
||||||
@ -318,7 +296,7 @@ class Activity(Window, gtk.Container):
|
|||||||
self._jobject.metadata['activity_id'] = self.get_id()
|
self._jobject.metadata['activity_id'] = self.get_id()
|
||||||
self._jobject.metadata['keep'] = '0'
|
self._jobject.metadata['keep'] = '0'
|
||||||
self._jobject.metadata['preview'] = ''
|
self._jobject.metadata['preview'] = ''
|
||||||
self._jobject.metadata['share-scope'] = SHARE_PRIVATE
|
self._jobject.metadata['share-scope'] = SCOPE_PRIVATE
|
||||||
|
|
||||||
if self._shared_activity is not None:
|
if self._shared_activity is not None:
|
||||||
icon_color = self._shared_activity.props.color
|
icon_color = self._shared_activity.props.color
|
||||||
@ -334,6 +312,29 @@ class Activity(Window, gtk.Container):
|
|||||||
else:
|
else:
|
||||||
self._jobject = None
|
self._jobject = None
|
||||||
|
|
||||||
|
# handle activity share/join
|
||||||
|
mesh_instance = self._pservice.get_activity(self._activity_id)
|
||||||
|
logging.debug("*** Act %s, mesh instance %r, scope %s" % (self._activity_id, mesh_instance, share_scope))
|
||||||
|
if mesh_instance:
|
||||||
|
# There's already an instance on the mesh, join it
|
||||||
|
logging.debug("*** Act %s joining existing mesh instance" % self._activity_id)
|
||||||
|
self._shared_activity = mesh_instance
|
||||||
|
self._join_id = self._shared_activity.connect("joined", self._internal_joined_cb)
|
||||||
|
if not self._shared_activity.props.joined:
|
||||||
|
self._shared_activity.join()
|
||||||
|
else:
|
||||||
|
self._internal_joined_cb(self._shared_activity, True, None)
|
||||||
|
elif share_scope != SCOPE_PRIVATE:
|
||||||
|
logging.debug("*** Act %s no existing mesh instance, but used to be shared, will share" % self._activity_id)
|
||||||
|
# no existing mesh instance, but activity used to be shared, so
|
||||||
|
# restart the share
|
||||||
|
if share_scope == SCOPE_INVITE_ONLY:
|
||||||
|
self.share(private=True)
|
||||||
|
elif share_scope == SCOPE_NEIGHBORHOOD:
|
||||||
|
self.share(private=False)
|
||||||
|
else:
|
||||||
|
logging.debug("Unknown share scope %r" % share_scope)
|
||||||
|
|
||||||
def do_set_property(self, pspec, value):
|
def do_set_property(self, pspec, value):
|
||||||
if pspec.name == 'active':
|
if pspec.name == 'active':
|
||||||
if self._active != value:
|
if self._active != value:
|
||||||
@ -499,6 +500,9 @@ class Activity(Window, gtk.Container):
|
|||||||
return
|
return
|
||||||
self.present()
|
self.present()
|
||||||
self.emit('joined')
|
self.emit('joined')
|
||||||
|
if self._jobject:
|
||||||
|
# FIXME: some way to distinguish between share scopes
|
||||||
|
self._jobject.metadata['share-scope'] = SCOPE_NEIGHBORHOOD
|
||||||
|
|
||||||
def get_shared(self):
|
def get_shared(self):
|
||||||
"""Returns TRUE if the activity is shared on the mesh."""
|
"""Returns TRUE if the activity is shared on the mesh."""
|
||||||
@ -519,8 +523,8 @@ class Activity(Window, gtk.Container):
|
|||||||
self._shared_activity = activity
|
self._shared_activity = activity
|
||||||
self.emit('shared')
|
self.emit('shared')
|
||||||
if self._jobject:
|
if self._jobject:
|
||||||
# FIXME: some wy to distinguish between share scopes
|
# FIXME: some way to distinguish between share scopes
|
||||||
self._jobject.metadata['share-scope'] = SHARE_NEIGHBORHOOD
|
self._jobject.metadata['share-scope'] = SCOPE_NEIGHBORHOOD
|
||||||
|
|
||||||
def share(self, private=False):
|
def share(self, private=False):
|
||||||
"""Request that the activity be shared on the network.
|
"""Request that the activity be shared on the network.
|
||||||
|
@ -20,15 +20,12 @@ from sugar.presence import presenceservice
|
|||||||
class ActivityHandle(object):
|
class ActivityHandle(object):
|
||||||
"""Data structure storing simple activity metadata"""
|
"""Data structure storing simple activity metadata"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self, activity_id=None, pservice_id=None,
|
self, activity_id=None, object_id=None, uri=None
|
||||||
object_id=None, uri=None
|
|
||||||
):
|
):
|
||||||
"""Initialise the handle from activity_id
|
"""Initialise the handle from activity_id
|
||||||
|
|
||||||
activity_id -- unique id for the activity to be
|
activity_id -- unique id for the activity to be
|
||||||
created
|
created
|
||||||
pservice_id -- identity of the sharing service
|
|
||||||
for this activity in the PresenceService
|
|
||||||
object_id -- identity of the journal object
|
object_id -- identity of the journal object
|
||||||
associated with the activity. It was used by
|
associated with the activity. It was used by
|
||||||
the journal prototype implementation, might
|
the journal prototype implementation, might
|
||||||
@ -48,28 +45,12 @@ class ActivityHandle(object):
|
|||||||
example or web pages)
|
example or web pages)
|
||||||
"""
|
"""
|
||||||
self.activity_id = activity_id
|
self.activity_id = activity_id
|
||||||
self.pservice_id = pservice_id
|
|
||||||
self.object_id = object_id
|
self.object_id = object_id
|
||||||
self.uri = uri
|
self.uri = uri
|
||||||
|
|
||||||
def get_shared_activity(self):
|
|
||||||
"""Retrieve the shared instance of this activity
|
|
||||||
|
|
||||||
Uses the PresenceService to find any existing dbus
|
|
||||||
service which provides sharing mechanisms for this
|
|
||||||
activity.
|
|
||||||
"""
|
|
||||||
if self.pservice_id:
|
|
||||||
pservice = presenceservice.get_instance()
|
|
||||||
return pservice.get_activity(self.pservice_id)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_dict(self):
|
def get_dict(self):
|
||||||
"""Retrieve our settings as a dictionary"""
|
"""Retrieve our settings as a dictionary"""
|
||||||
result = { 'activity_id' : self.activity_id }
|
result = { 'activity_id' : self.activity_id }
|
||||||
if self.pservice_id:
|
|
||||||
result['pservice_id'] = self.pservice_id
|
|
||||||
if self.object_id:
|
if self.object_id:
|
||||||
result['object_id'] = self.object_id
|
result['object_id'] = self.object_id
|
||||||
if self.uri:
|
if self.uri:
|
||||||
@ -81,7 +62,6 @@ def create_from_dict(handle_dict):
|
|||||||
"""Create a handle from a dictionary of parameters"""
|
"""Create a handle from a dictionary of parameters"""
|
||||||
result = ActivityHandle(
|
result = ActivityHandle(
|
||||||
handle_dict['activity_id'],
|
handle_dict['activity_id'],
|
||||||
pservice_id = handle_dict.get( 'pservice_id' ),
|
|
||||||
object_id = handle_dict.get('object_id'),
|
object_id = handle_dict.get('object_id'),
|
||||||
uri = handle_dict.get('uri'),
|
uri = handle_dict.get('uri'),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user