Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugin/launcher.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/launcher.py')
-rw-r--r--plugin/launcher.py113
1 files changed, 49 insertions, 64 deletions
diff --git a/plugin/launcher.py b/plugin/launcher.py
index d55117e..ec403ed 100644
--- a/plugin/launcher.py
+++ b/plugin/launcher.py
@@ -14,14 +14,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
-from gettext import gettext as _
import gtk
import wnck
import gconf
-import gobject
-
-from sugar_network import launch
from sugar import wm
from sugar.graphics.xocolor import XoColor
@@ -30,7 +26,8 @@ from sugar.activity.activityfactory import create_activity_id
from jarabe.view.launcher import LaunchWindow
from jarabe.journal import model
from jarabe.model import shell
-from jarabe.plugins.sn import get_client, get_registry, add_alert, get_browser
+from jarabe.plugins.sn import get_client, get_registry, get_browser
+from jarabe.plugins.sn.bundleregistry import stub_icon
_logger = logging.getLogger('plugins.sn.launcher')
@@ -42,7 +39,7 @@ class Launcher(object):
self._launches = {}
self._screen = wnck.screen_get_default()
self._screen.connect('window-opened', self.__window_opened_cb)
- get_client().connect_to_signal('Event', self.__Event_cb)
+ get_client().connect('event', self.__Event_cb)
def launch(self, bundle, activity_id=None, object_id=None, uri=None,
color=None, invited=None, args=None):
@@ -53,62 +50,53 @@ class Launcher(object):
activity.get_window().activate(gtk.get_current_event_time())
return
- def found_jobject(props):
+ def found_jobjects(jobjects, total):
+ if not jobjects:
+ props = {}
+ else:
+ props = jobjects[0]
self._launch(bundle,
props.get('activity_id') or activity_id,
props.get('object_id') or object_id,
+ props.get('icon-color') or color,
uri,
- XoColor(props['icon-color']) if 'icon-color' in props
- else color,
args)
- def not_found_jobject(error):
+ def not_found_jobjects(error):
_logger.exception('Failed to launch %r: %s',
bundle.get_bundle_id(), error)
- # pylint: disable-msg=W0212
if activity_id and not object_id:
_logger.debug('Look for jobject for %r activity_id', activity_id)
+ # pylint: disable-msg=W0212
model._get_datastore().find({'activity_id': activity_id}, ['uid'],
- reply_handler=lambda jobjects, total:
- found_jobject(jobjects[0] if total else {}),
- error_handler=not_found_jobject, byte_arrays=True)
- elif object_id and not activity_id:
- _logger.debug('Look for %r jobject', object_id)
- model._get_datastore().get_properties(object_id,
- reply_handler=found_jobject,
- error_handler=not_found_jobject, byte_arrays=True)
+ reply_handler=found_jobjects,
+ error_handler=not_found_jobjects,
+ byte_arrays=True)
else:
- self._launch(bundle, activity_id, object_id, uri, color, args)
+ self._launch(bundle, activity_id, object_id, color, uri, args)
- def _launch(self, bundle, activity_id, object_id, uri, color, extra_args):
+ def _launch(self, bundle, activity_id, object_id, color, uri, extra_args):
if not activity_id:
activity_id = create_activity_id()
- if color is None:
- gc = gconf.client_get_default()
- color = XoColor(gc.get_string('/desktop/sugar/user/color'))
-
- args = ['-b', bundle.get_bundle_id()]
- if activity_id:
- args.extend(['-a', activity_id])
- if object_id:
- args.extend(['-o', object_id])
- if uri:
- args.extend(['-u', uri])
- if extra_args:
- args.extend(extra_args)
_logger.info('Starting %r: activity_id=%r object_id=%r uri=%r',
bundle.get_bundle_id(), activity_id, object_id, uri)
- pipe = launch(bundle.mountpoint, bundle.get_bundle_id(), 'activity',
- args)
- gobject.io_add_watch(pipe.fileno(), gobject.IO_IN | gobject.IO_HUP,
- self.__progress_cb, pipe, activity_id)
+ self._start_launcher(bundle.get_bundle_id(), bundle.get_icon(),
+ activity_id, color)
+ get_client().get(['context', bundle.get_bundle_id()], cmd='launch',
+ mountpoint=bundle.mountpoint, args=extra_args,
+ activity_id=activity_id, object_id=object_id, uri=uri,
+ color=None if color is None else color.to_string())
- window = LaunchWindow(activity_id, bundle.get_icon(), color)
+ def _start_launcher(self, bundle_id, icon, activity_id, color):
+ if color is None:
+ gc = gconf.client_get_default()
+ color = XoColor(gc.get_string('/desktop/sugar/user/color'))
+ window = LaunchWindow(activity_id, icon, color)
window.connect('realize', self.__window_realize_cb,
- bundle.get_bundle_id(), activity_id)
+ bundle_id, activity_id)
window.show()
self._launches[activity_id] = window
@@ -141,28 +129,25 @@ class Launcher(object):
gtk.gdk.PROP_MODE_REPLACE, 'launcher')
wm.set_bundle_id(widget.window, str(bundle_id))
- def __Event_cb(self, event):
- if event.get('event') != 'launch':
+ def __Event_cb(self, event, data):
+ if event != 'launch':
return
- bundle = get_registry().get_bundle(
- event['context'], event['mountpoint'])
- if bundle is None:
- add_alert('error', msg=_('Cannot find %s activity to launch') %
- event['context'])
- else:
- self.launch(bundle, object_id=event['object_id'], uri=event['uri'],
- args=event['args'])
-
- def __progress_cb(self, source, cb_condition, pipe, activity_id):
- event = pipe.read()
- if event is None:
- return False
- _logger.debug('Execution progress for %r: %r', activity_id, event)
- try:
- if event['state'] == 'failure':
- _logger.warning('Activity %r failed', activity_id)
- self._stop_launcher(activity_id)
- self._failure_report(event)
- except Exception:
- _logger.exception('Failed to process event')
- return True
+
+ if data['state'] == 'fork':
+ if data['activity_id'] not in self._launches:
+ bundle = get_registry().get_bundle(
+ data['context'], data.get('mountpoint') or '/')
+ if bundle is None:
+ icon = stub_icon()
+ else:
+ icon = bundle.get_icon()
+ color = data.get('color')
+ if color:
+ color = XoColor(color)
+ self._start_launcher(data['context'], icon,
+ data['activity_id'], color)
+
+ elif event['state'] == 'failure':
+ _logger.warning('Activity %r failed', data['activity_id'])
+ self._stop_launcher(data['activity_id'])
+ self._failure_report(event)