Make notification work from outside the shell process
This commit is contained in:
parent
64812c7d67
commit
d7a8c5430e
@ -21,6 +21,7 @@ from model import bundleregistry
|
|||||||
|
|
||||||
_DBUS_SERVICE = "org.laptop.Shell"
|
_DBUS_SERVICE = "org.laptop.Shell"
|
||||||
_DBUS_ACTIVITY_REGISTRY_IFACE = "org.laptop.Shell.ActivityRegistry"
|
_DBUS_ACTIVITY_REGISTRY_IFACE = "org.laptop.Shell.ActivityRegistry"
|
||||||
|
_DBUS_SHELL_IFACE = "org.laptop.Shell"
|
||||||
_DBUS_OWNER_IFACE = "org.laptop.Shell.Owner"
|
_DBUS_OWNER_IFACE = "org.laptop.Shell.Owner"
|
||||||
_DBUS_PATH = "/org/laptop/Shell"
|
_DBUS_PATH = "/org/laptop/Shell"
|
||||||
|
|
||||||
@ -59,6 +60,17 @@ class ShellService(dbus.service.Object):
|
|||||||
bus_name = dbus.service.BusName(_DBUS_SERVICE, bus=bus)
|
bus_name = dbus.service.BusName(_DBUS_SERVICE, bus=bus)
|
||||||
dbus.service.Object.__init__(self, bus_name, _DBUS_PATH)
|
dbus.service.Object.__init__(self, bus_name, _DBUS_PATH)
|
||||||
|
|
||||||
|
|
||||||
|
@dbus.service.method(_DBUS_SHELL_IFACE,
|
||||||
|
in_signature="ss", out_signature="")
|
||||||
|
def NotifyLaunch(self, bundle_id, activity_id):
|
||||||
|
self._shell.notify_launch(bundle_id, activity_id)
|
||||||
|
|
||||||
|
@dbus.service.method(_DBUS_SHELL_IFACE,
|
||||||
|
in_signature="s", out_signature="")
|
||||||
|
def NotifyLaunchFailure(self, activity_id):
|
||||||
|
self._shell.notify_launch_failure(activity_id)
|
||||||
|
|
||||||
@dbus.service.method(_DBUS_ACTIVITY_REGISTRY_IFACE,
|
@dbus.service.method(_DBUS_ACTIVITY_REGISTRY_IFACE,
|
||||||
in_signature="s", out_signature="b")
|
in_signature="s", out_signature="b")
|
||||||
def AddBundle(self, bundle_path):
|
def AddBundle(self, bundle_path):
|
||||||
|
@ -68,12 +68,15 @@ class Shell(gobject.GObject):
|
|||||||
home_model.connect('active-activity-changed',
|
home_model.connect('active-activity-changed',
|
||||||
self._active_activity_changed_cb)
|
self._active_activity_changed_cb)
|
||||||
|
|
||||||
self.start_activity('org.laptop.JournalActivity')
|
|
||||||
|
|
||||||
# Unfreeze the display when it's stable
|
# Unfreeze the display when it's stable
|
||||||
hw_manager = hardwaremanager.get_manager()
|
hw_manager = hardwaremanager.get_manager()
|
||||||
hw_manager.set_dcon_freeze(0)
|
hw_manager.set_dcon_freeze(0)
|
||||||
|
|
||||||
|
gobject.idle_add(self._start_journal_idle)
|
||||||
|
|
||||||
|
def _start_journal_idle(self):
|
||||||
|
self.start_activity('org.laptop.JournalActivity')
|
||||||
|
|
||||||
def _activity_started_cb(self, home_model, home_activity):
|
def _activity_started_cb(self, home_model, home_activity):
|
||||||
activity_host = ActivityHost(home_activity)
|
activity_host = ActivityHost(home_activity)
|
||||||
self._hosts[activity_host.get_xid()] = activity_host
|
self._hosts[activity_host.get_xid()] = activity_host
|
||||||
@ -114,10 +117,6 @@ class Shell(gobject.GObject):
|
|||||||
def get_popup_context(self):
|
def get_popup_context(self):
|
||||||
return self._popup_context
|
return self._popup_context
|
||||||
|
|
||||||
def _join_error_cb(self, handler, err, home_model):
|
|
||||||
logging.debug("Failed to join activity %s: %s" % (handler.get_activity_id(), err))
|
|
||||||
home_model.notify_activity_launch_failed(handler.get_activity_id())
|
|
||||||
|
|
||||||
def join_activity(self, bundle_id, activity_id):
|
def join_activity(self, bundle_id, activity_id):
|
||||||
activity = self.get_activity(activity_id)
|
activity = self.get_activity(activity_id)
|
||||||
if activity:
|
if activity:
|
||||||
@ -133,40 +132,28 @@ class Shell(gobject.GObject):
|
|||||||
logging.error("Couldn't find activity for type %s" % bundle_id)
|
logging.error("Couldn't find activity for type %s" % bundle_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
home_model = self._model.get_home()
|
|
||||||
home_model.notify_activity_launch(activity_id, bundle_id)
|
|
||||||
|
|
||||||
handle = ActivityHandle(activity_id)
|
handle = ActivityHandle(activity_id)
|
||||||
handle.pservice_id = activity_id
|
handle.pservice_id = activity_id
|
||||||
|
|
||||||
handler = activityfactory.create(bundle_id, handle)
|
activityfactory.create(bundle_id, handle)
|
||||||
handler.connect('error', self._join_error_cb, home_model)
|
|
||||||
|
|
||||||
def _start_error_cb(self, handler, err, home_model):
|
def notify_launch(self, bundle_id, activity_id):
|
||||||
home_model.notify_activity_launch_failed(handler.get_activity_id())
|
# Zoom to Home for launch feedback
|
||||||
|
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||||
|
|
||||||
|
home_model = self._model.get_home()
|
||||||
|
home_model.notify_activity_launch(activity_id, bundle_id)
|
||||||
|
|
||||||
|
def notify_launch_failure(self, activity_id):
|
||||||
|
home_model.notify_activity_launch_failed(activity_id)
|
||||||
|
|
||||||
def start_activity(self, activity_type):
|
def start_activity(self, activity_type):
|
||||||
if activity_type in self._activities_starting:
|
if activity_type in self._activities_starting:
|
||||||
logging.debug("This activity is still launching.")
|
logging.debug("This activity is still launching.")
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.debug('Trying to start activity of type %s' % activity_type)
|
|
||||||
|
|
||||||
self._activities_starting.add(activity_type)
|
self._activities_starting.add(activity_type)
|
||||||
try:
|
activityfactory.create(activity_type)
|
||||||
handler = activityfactory.create(activity_type)
|
|
||||||
|
|
||||||
home_model = self._model.get_home()
|
|
||||||
home_model.notify_activity_launch(handler.get_activity_id(),
|
|
||||||
activity_type)
|
|
||||||
|
|
||||||
handler.connect('error', self._start_error_cb, home_model)
|
|
||||||
except Exception, err:
|
|
||||||
logging.debug("Couldn't start activity of type %s: %s" % (activity_type, err))
|
|
||||||
self._activities_starting.remove(activity_type)
|
|
||||||
|
|
||||||
# Zoom to Home for launch feedback
|
|
||||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
|
||||||
|
|
||||||
def set_zoom_level(self, level):
|
def set_zoom_level(self, level):
|
||||||
if self._zoom_level == level:
|
if self._zoom_level == level:
|
||||||
|
@ -26,6 +26,10 @@ from sugar.presence import presenceservice
|
|||||||
from sugar.activity.activityhandle import ActivityHandle
|
from sugar.activity.activityhandle import ActivityHandle
|
||||||
from sugar import util
|
from sugar import util
|
||||||
|
|
||||||
|
_SHELL_SERVICE = "org.laptop.Shell"
|
||||||
|
_SHELL_PATH = "/org/laptop/Shell"
|
||||||
|
_SHELL_IFACE = "org.laptop.Shell"
|
||||||
|
|
||||||
_ACTIVITY_FACTORY_INTERFACE = "org.laptop.ActivityFactory"
|
_ACTIVITY_FACTORY_INTERFACE = "org.laptop.ActivityFactory"
|
||||||
|
|
||||||
def create_activity_id():
|
def create_activity_id():
|
||||||
@ -59,13 +63,6 @@ class ActivityCreationHandler(gobject.GObject):
|
|||||||
activity startup using callbacks to the service's
|
activity startup using callbacks to the service's
|
||||||
create call.
|
create call.
|
||||||
"""
|
"""
|
||||||
__gsignals__ = {
|
|
||||||
'success': (gobject.SIGNAL_RUN_FIRST,
|
|
||||||
gobject.TYPE_NONE, ([])),
|
|
||||||
'error': (gobject.SIGNAL_RUN_FIRST,
|
|
||||||
gobject.TYPE_NONE,
|
|
||||||
([gobject.TYPE_PYOBJECT]))
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, service_name, activity_handle):
|
def __init__(self, service_name, activity_handle):
|
||||||
"""Initialise the handler
|
"""Initialise the handler
|
||||||
@ -99,34 +96,42 @@ class ActivityCreationHandler(gobject.GObject):
|
|||||||
factory = dbus.Interface(proxy_obj, _ACTIVITY_FACTORY_INTERFACE)
|
factory = dbus.Interface(proxy_obj, _ACTIVITY_FACTORY_INTERFACE)
|
||||||
|
|
||||||
factory.create(self._activity_handle.get_dict(),
|
factory.create(self._activity_handle.get_dict(),
|
||||||
reply_handler=self._reply_handler,
|
reply_handler=self._no_reply_handler,
|
||||||
error_handler=self._error_handler)
|
error_handler=self._create_error_handler)
|
||||||
|
|
||||||
|
bus = dbus.SessionBus()
|
||||||
|
bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH)
|
||||||
|
self._shell = dbus.Interface(bus_object, _SHELL_IFACE)
|
||||||
|
|
||||||
|
self._shell.NotifyLaunch(
|
||||||
|
service_name, self.get_activity_id(),
|
||||||
|
reply_handler=self._no_reply_handler,
|
||||||
|
error_handler=self._notify_launch_error_handler)
|
||||||
|
|
||||||
def get_activity_id(self):
|
def get_activity_id(self):
|
||||||
"""Retrieve the unique identity for this activity"""
|
"""Retrieve the unique identity for this activity"""
|
||||||
return self._activity_handle.activity_id
|
return self._activity_handle.activity_id
|
||||||
|
|
||||||
def _reply_handler(self, xid):
|
def _no_reply_handler(self, *args):
|
||||||
"""Reply from service regarding what window was created
|
pass
|
||||||
|
|
||||||
xid -- X windows ID for the window that was just created
|
def _notify_launch_failure_error_handler(self, err):
|
||||||
|
logging.debug('Notify launch failure failed %s' % err)
|
||||||
emits the "success" message (on ourselves)
|
|
||||||
"""
|
def _notify_launch_error_handler(self, err):
|
||||||
|
logging.debug('Notify launch failed %s' % err)
|
||||||
|
|
||||||
|
def _create_reply_handler(self, xid):
|
||||||
logging.debug("Activity created %s (%s)." %
|
logging.debug("Activity created %s (%s)." %
|
||||||
(self._activity_handle.activity_id, self._service_name))
|
(self._activity_handle.activity_id, self._service_name))
|
||||||
self.emit('success')
|
|
||||||
|
|
||||||
def _error_handler(self, err):
|
def _create_error_handler(self, err):
|
||||||
"""Reply from service with an error message (exception)
|
|
||||||
|
|
||||||
err -- exception object describing the error
|
|
||||||
|
|
||||||
emits the "error" message (on ourselves)
|
|
||||||
"""
|
|
||||||
logging.debug("Couldn't create activity %s (%s): %s" %
|
logging.debug("Couldn't create activity %s (%s): %s" %
|
||||||
(self._activity_handle.activity_id, self._service_name, err))
|
(self._activity_handle.activity_id, self._service_name, err))
|
||||||
self.emit('error', err)
|
self._shell.NotifyLaunchFailure(
|
||||||
|
service_name, self.get_activity_id(),
|
||||||
|
reply_handler=self._no_reply_handler,
|
||||||
|
error_handler=self._notify_launch_failure_error_handler)
|
||||||
|
|
||||||
def create(service_name, activity_handle=None):
|
def create(service_name, activity_handle=None):
|
||||||
"""Create a new activity from its name."""
|
"""Create a new activity from its name."""
|
||||||
|
Loading…
Reference in New Issue
Block a user