Make activity launching asynchronous

The ActivityFactory create() method now returns a handler GObject,
which callers may attach signals to to receive success and error
signals from the result of the activity launch request.
This commit is contained in:
Dan Williams
2007-01-07 00:04:30 -05:00
parent 8cea4c5fc6
commit fb716ae046
5 changed files with 119 additions and 69 deletions
+25 -15
View File
@@ -40,22 +40,32 @@ class ClipboardIcon(MenuIcon):
else:
return None
def _icon_activated_cb(self, icon):
if self._percent == 100:
cb_service = clipboardservice.get_instance()
(name, percent, icon, preview, format_types) = \
cb_service.get_object(self._object_id)
def _activity_create_success_cb(self, handler, activity):
activity.start(util.unique_id())
activity.execute("open_document", [self._object_id])
if format_types:
logging.debug("_icon_activated_cb: " + self._object_id)
activity_id = self._get_activity_for_mime_type(format_types[0])
if activity_id:
activity = ActivityFactory.create(activity_id)
activity.start(util.unique_id())
activity.execute("open_document", [self._object_id])
def _activity_create_error_cb(self, handler, err):
pass
def _icon_activated_cb(self, icon):
if self._percent < 100:
return
cb_service = clipboardservice.get_instance()
(name, percent, icon, preview, format_types) = \
cb_service.get_object(self._object_id)
if not format_types:
return
logging.debug("_icon_activated_cb: " + self._object_id)
activity_type = self._get_activity_for_mime_type(format_types[0])
if not activity_type:
return
# Launch the activity to handle this item
handler = ActivityFactory.create(activity_type)
handler.connect('success', self._activity_create_success_cb)
handler.connect('error', self._activity_create_error_cb)
def _popup_action_cb(self, popup, action):
self.popdown()