Put exec back, I forgot it was used by the camera.
Helper method to create an activity with an uri.
This commit is contained in:
parent
0b6b6cd6ac
commit
1b5ac988d7
@ -93,6 +93,10 @@ class Activity(gtk.Window):
|
||||
self._service = self._pservice.share_activity(self, default_type)
|
||||
self._shared = True
|
||||
|
||||
def execute(self, command, args):
|
||||
"""Execute the given command with args"""
|
||||
return False
|
||||
|
||||
def _destroy_cb(self, window):
|
||||
if self._bus:
|
||||
del self._bus
|
||||
|
@ -30,6 +30,28 @@ _ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
|
||||
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
|
||||
_ACTIVITY_INTERFACE = "org.laptop.Activity"
|
||||
|
||||
def _find_activity_id():
|
||||
pservice = PresenceService.get_instance()
|
||||
|
||||
# create a new unique activity ID
|
||||
i = 0
|
||||
act_id = None
|
||||
while i < 10:
|
||||
act_id = util.unique_id()
|
||||
i += 1
|
||||
|
||||
# check through network activities
|
||||
found = False
|
||||
activities = pservice.get_activities()
|
||||
for act in activities:
|
||||
if act_id == act.get_id():
|
||||
found = True
|
||||
break
|
||||
if found:
|
||||
raise RuntimeError("Cannot generate unique activity id.")
|
||||
|
||||
return act_id
|
||||
|
||||
class ActivityCreationHandler(gobject.GObject):
|
||||
|
||||
__gsignals__ = {
|
||||
@ -42,15 +64,7 @@ class ActivityCreationHandler(gobject.GObject):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self._service_name = service_name
|
||||
|
||||
if activity_handle:
|
||||
self._activity_handle = activity_handle
|
||||
else:
|
||||
activity_id = self._find_unique_activity_id()
|
||||
if activity_id:
|
||||
self._activity_handle = ActivityHandle(activity_id)
|
||||
else:
|
||||
raise RuntimeError("Cannot generate activity id.")
|
||||
self._activity_handle = activity_handle
|
||||
|
||||
registry = bundleregistry.get_registry()
|
||||
bundle = registry.get_bundle(service_name)
|
||||
@ -66,29 +80,6 @@ class ActivityCreationHandler(gobject.GObject):
|
||||
def get_activity_id(self):
|
||||
return self._activity_handle.activity_id
|
||||
|
||||
def _find_unique_activity_id(self):
|
||||
pservice = PresenceService.get_instance()
|
||||
|
||||
# create a new unique activity ID
|
||||
i = 0
|
||||
act_id = None
|
||||
while i < 10:
|
||||
act_id = util.unique_id()
|
||||
i += 1
|
||||
|
||||
# check through network activities
|
||||
found = False
|
||||
activities = pservice.get_activities()
|
||||
for act in activities:
|
||||
if act_id == act.get_id():
|
||||
found = True
|
||||
break
|
||||
if found:
|
||||
act_id = None
|
||||
continue
|
||||
|
||||
return act_id
|
||||
|
||||
def _reply_handler(self, xid):
|
||||
logging.debug("Activity created %s (%s)." %
|
||||
(self._activity_handle.activity_id, self._service_name))
|
||||
@ -100,4 +91,12 @@ class ActivityCreationHandler(gobject.GObject):
|
||||
|
||||
def create(service_name, activity_handle=None):
|
||||
"""Create a new activity from its name."""
|
||||
if not activity_handle:
|
||||
activity_handle = ActivityHandle(_find_activity_id())
|
||||
return ActivityCreationHandler(service_name, activity_handle)
|
||||
|
||||
def create_with_uri(service_name, uri):
|
||||
"""Create a new activity and pass the uri as handle."""
|
||||
activity_handle = ActivityHandle(_find_activity_id())
|
||||
activity_handle.uri = uri
|
||||
return ActivityCreationHandler(service_name, handle)
|
||||
|
@ -60,3 +60,9 @@ class ActivityService(dbus.service.Object):
|
||||
def get_shared(self):
|
||||
"""Returns True if the activity is shared on the mesh."""
|
||||
return self._activity.get_shared()
|
||||
|
||||
@dbus.service.method(_ACTIVITY_INTERFACE,
|
||||
in_signature="sas", out_signature="b")
|
||||
def execute(self, command, args):
|
||||
return self._activity.execute(command, args)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user