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:
Marco Pesenti Gritti 2007-02-22 01:23:58 +01:00
parent 0b6b6cd6ac
commit 1b5ac988d7
3 changed files with 41 additions and 32 deletions

View File

@ -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

View File

@ -30,43 +30,7 @@ _ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
_ACTIVITY_INTERFACE = "org.laptop.Activity"
class ActivityCreationHandler(gobject.GObject):
__gsignals__ = {
'error': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
}
def __init__(self, service_name, activity_handle):
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.")
registry = bundleregistry.get_registry()
bundle = registry.get_bundle(service_name)
bus = dbus.SessionBus()
proxy_obj = bus.get_object(service_name, bundle.get_object_path())
factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory")
factory.create(self._activity_handle.get_dict(),
reply_handler=self._reply_handler,
error_handler=self._error_handler)
def get_activity_id(self):
return self._activity_handle.activity_id
def _find_unique_activity_id(self):
def _find_activity_id():
pservice = PresenceService.get_instance()
# create a new unique activity ID
@ -84,11 +48,38 @@ class ActivityCreationHandler(gobject.GObject):
found = True
break
if found:
act_id = None
continue
raise RuntimeError("Cannot generate unique activity id.")
return act_id
class ActivityCreationHandler(gobject.GObject):
__gsignals__ = {
'error': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
}
def __init__(self, service_name, activity_handle):
gobject.GObject.__init__(self)
self._service_name = service_name
self._activity_handle = activity_handle
registry = bundleregistry.get_registry()
bundle = registry.get_bundle(service_name)
bus = dbus.SessionBus()
proxy_obj = bus.get_object(service_name, bundle.get_object_path())
factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory")
factory.create(self._activity_handle.get_dict(),
reply_handler=self._reply_handler,
error_handler=self._error_handler)
def get_activity_id(self):
return self._activity_handle.activity_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)

View File

@ -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)