Complete move to external bundle registry.
This commit is contained in:
+13
-13
@@ -18,29 +18,29 @@ import gobject
|
||||
|
||||
from sugar.graphics.xocolor import XoColor
|
||||
from sugar.presence import presenceservice
|
||||
from sugar import activity
|
||||
|
||||
from model import bundleregistry
|
||||
from model.BuddyModel import BuddyModel
|
||||
from model.accesspointmodel import AccessPointModel
|
||||
from hardware import hardwaremanager
|
||||
from hardware import nmclient
|
||||
|
||||
class ActivityModel:
|
||||
def __init__(self, activity, bundle):
|
||||
def __init__(self, activity, activity_info):
|
||||
self._activity = activity
|
||||
self._bundle = bundle
|
||||
self._activity_info = activity_info
|
||||
|
||||
def get_id(self):
|
||||
return self._activity.props.id
|
||||
|
||||
def get_icon_name(self):
|
||||
return self._bundle.get_icon()
|
||||
return self._activity_info.icon
|
||||
|
||||
def get_color(self):
|
||||
return XoColor(self._activity.props.color)
|
||||
|
||||
def get_service_name(self):
|
||||
return self._bundle.get_service_name()
|
||||
return self._activity_info.service_name
|
||||
|
||||
def get_title(self):
|
||||
return self._activity.props.name
|
||||
@@ -75,7 +75,6 @@ class MeshModel(gobject.GObject):
|
||||
self._buddies = {}
|
||||
self._access_points = {}
|
||||
self._mesh = None
|
||||
self._bundle_registry = bundleregistry.get_registry()
|
||||
|
||||
self._pservice = presenceservice.get_instance()
|
||||
self._pservice.connect("activity-appeared",
|
||||
@@ -196,13 +195,14 @@ class MeshModel(gobject.GObject):
|
||||
def _activity_appeared_cb(self, pservice, activity):
|
||||
self._check_activity(activity)
|
||||
|
||||
def _check_activity(self, activity):
|
||||
bundle = self._bundle_registry.get_bundle(activity.props.type)
|
||||
if not bundle:
|
||||
def _check_activity(self, presence_activity):
|
||||
registry = activity.get_registry()
|
||||
activity_info = registry.get_activity(presence_activity.props.type)
|
||||
if not activity_info:
|
||||
return
|
||||
if self.has_activity(activity.props.id):
|
||||
if self.has_activity(presence_activity.props.id):
|
||||
return
|
||||
self.add_activity(bundle, activity)
|
||||
self.add_activity(activity_info, presence_activity)
|
||||
|
||||
def has_activity(self, activity_id):
|
||||
return self._activities.has_key(activity_id)
|
||||
@@ -213,8 +213,8 @@ class MeshModel(gobject.GObject):
|
||||
else:
|
||||
return None
|
||||
|
||||
def add_activity(self, bundle, activity):
|
||||
model = ActivityModel(activity, bundle)
|
||||
def add_activity(self, activity_info, activity):
|
||||
model = ActivityModel(activity, activity_info)
|
||||
self._activities[model.get_id()] = model
|
||||
self.emit('activity-added', model)
|
||||
|
||||
|
||||
@@ -44,10 +44,10 @@ class HomeActivity(gobject.GObject):
|
||||
gobject.PARAM_READWRITE),
|
||||
}
|
||||
|
||||
def __init__(self, bundle, activity_id):
|
||||
def __init__(self, activity_info, activity_id):
|
||||
"""Initialise the HomeActivity
|
||||
|
||||
bundle -- sugar.activity.bundle.Bundle instance,
|
||||
activity_info -- sugar.activity.registry.ActivityInfo instance,
|
||||
provides the information required to actually
|
||||
create the new instance. This is, in effect,
|
||||
the "type" of activity being created.
|
||||
@@ -61,7 +61,7 @@ class HomeActivity(gobject.GObject):
|
||||
self._pid = None
|
||||
self._service = None
|
||||
self._activity_id = activity_id
|
||||
self._bundle = bundle
|
||||
self._activity_info = activity_info
|
||||
self._launch_time = time.time()
|
||||
self._launching = False
|
||||
|
||||
@@ -99,9 +99,9 @@ class HomeActivity(gobject.GObject):
|
||||
return self._window.get_name()
|
||||
|
||||
def get_icon_name(self):
|
||||
"""Retrieve the bundle's icon (file) name"""
|
||||
if self._bundle:
|
||||
return self._bundle.get_icon()
|
||||
"""Retrieve the activity's icon (file) name"""
|
||||
if self._activity_info:
|
||||
return self._activity_info.icon
|
||||
else:
|
||||
return 'theme:stock-missing'
|
||||
|
||||
@@ -156,9 +156,9 @@ class HomeActivity(gobject.GObject):
|
||||
return self._window
|
||||
|
||||
def get_type(self):
|
||||
"""Retrieve bundle's "service_name" for future reference"""
|
||||
if self._bundle:
|
||||
return self._bundle.get_service_name()
|
||||
"""Retrieve activity_info's "service_name" for future reference"""
|
||||
if self._activity_info:
|
||||
return self._activity_info.service_name
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
+49
-48
@@ -21,9 +21,9 @@ import wnck
|
||||
import dbus
|
||||
|
||||
from sugar import wm
|
||||
from sugar import activity
|
||||
|
||||
from model.homeactivity import HomeActivity
|
||||
from model import bundleregistry
|
||||
|
||||
class HomeModel(gobject.GObject):
|
||||
"""Model of the "Home" view (activity management)
|
||||
@@ -61,7 +61,6 @@ class HomeModel(gobject.GObject):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self._activities = []
|
||||
self._bundle_registry = bundleregistry.get_registry()
|
||||
self._active_activity = None
|
||||
self._pending_activity = None
|
||||
|
||||
@@ -83,11 +82,11 @@ class HomeModel(gobject.GObject):
|
||||
"""
|
||||
return self._pending_activity
|
||||
|
||||
def _set_pending_activity(self, activity):
|
||||
if self._pending_activity == activity:
|
||||
def _set_pending_activity(self, home_activity):
|
||||
if self._pending_activity == home_activity:
|
||||
return
|
||||
|
||||
self._pending_activity = activity
|
||||
self._pending_activity = home_activity
|
||||
self.emit('pending-activity-changed', self._pending_activity)
|
||||
|
||||
def get_active_activity(self):
|
||||
@@ -101,8 +100,8 @@ class HomeModel(gobject.GObject):
|
||||
"""
|
||||
return self._active_activity
|
||||
|
||||
def _set_active_activity(self, activity):
|
||||
if self._active_activity == activity:
|
||||
def _set_active_activity(self, home_activity):
|
||||
if self._active_activity == home_activity:
|
||||
return
|
||||
|
||||
if self._active_activity:
|
||||
@@ -111,14 +110,14 @@ class HomeModel(gobject.GObject):
|
||||
service.set_active(False,
|
||||
reply_handler=self._set_active_success,
|
||||
error_handler=self._set_active_error)
|
||||
if activity:
|
||||
service = activity.get_service()
|
||||
if home_activity:
|
||||
service = home_activity.get_service()
|
||||
if service:
|
||||
service.set_active(True,
|
||||
reply_handler=self._set_active_success,
|
||||
error_handler=self._set_active_error)
|
||||
|
||||
self._active_activity = activity
|
||||
self._active_activity = home_activity
|
||||
self.emit('active-activity-changed', self._active_activity)
|
||||
|
||||
def __iter__(self):
|
||||
@@ -135,45 +134,46 @@ class HomeModel(gobject.GObject):
|
||||
|
||||
def _window_opened_cb(self, screen, window):
|
||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||
activity = None
|
||||
home_activity = None
|
||||
|
||||
activity_id = wm.get_activity_id(window)
|
||||
|
||||
bundle_id = wm.get_bundle_id(window)
|
||||
if bundle_id:
|
||||
bundle = self._bundle_registry.get_bundle(bundle_id)
|
||||
service_name = wm.get_bundle_id(window)
|
||||
if service_name:
|
||||
registry = activity.get_registry()
|
||||
activity_info = registry.get_activity(service_name)
|
||||
else:
|
||||
bundle = None
|
||||
activity_info = None
|
||||
|
||||
if activity_id:
|
||||
activity = self._get_activity_by_id(activity_id)
|
||||
home_activity = self._get_activity_by_id(activity_id)
|
||||
|
||||
if not activity:
|
||||
activity = HomeActivity(bundle, activity_id)
|
||||
self._add_activity(activity)
|
||||
if not home_activity:
|
||||
home_activity = HomeActivity(activity_info, activity_id)
|
||||
self._add_activity(home_activity)
|
||||
|
||||
activity.set_window(window)
|
||||
home_activity.set_window(window)
|
||||
|
||||
activity.props.launching = False
|
||||
self.emit('activity-started', activity)
|
||||
home_activity.props.launching = False
|
||||
self.emit('activity-started', home_activity)
|
||||
|
||||
if self._pending_activity is None:
|
||||
self._set_pending_activity(activity)
|
||||
self._set_pending_activity(home_activity)
|
||||
|
||||
def _window_closed_cb(self, screen, window):
|
||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||
self._remove_activity_by_xid(window.get_xid())
|
||||
|
||||
def _get_activity_by_xid(self, xid):
|
||||
for activity in self._activities:
|
||||
if activity.get_xid() == xid:
|
||||
return activity
|
||||
for home_activity in self._activities:
|
||||
if home_activity.get_xid() == xid:
|
||||
return home_activity
|
||||
return None
|
||||
|
||||
def _get_activity_by_id(self, activity_id):
|
||||
for activity in self._activities:
|
||||
if activity.get_activity_id() == activity_id:
|
||||
return activity
|
||||
for home_activity in self._activities:
|
||||
if home_activity.get_activity_id() == activity_id:
|
||||
return home_activity
|
||||
return None
|
||||
|
||||
def _set_active_success(self):
|
||||
@@ -194,12 +194,12 @@ class HomeModel(gobject.GObject):
|
||||
self._set_pending_activity(act)
|
||||
self._set_active_activity(act)
|
||||
|
||||
def _add_activity(self, activity):
|
||||
self._activities.append(activity)
|
||||
self.emit('activity-added', activity)
|
||||
def _add_activity(self, home_activity):
|
||||
self._activities.append(home_activity)
|
||||
self.emit('activity-added', home_activity)
|
||||
|
||||
def _remove_activity(self, activity):
|
||||
if activity == self._active_activity:
|
||||
def _remove_activity(self, home_activity):
|
||||
if home_activity == self._active_activity:
|
||||
self._set_active_activity(None)
|
||||
# Figure out the new _pending_activity.
|
||||
windows = wnck.screen_get_default().get_windows_stacked()
|
||||
@@ -213,28 +213,29 @@ class HomeModel(gobject.GObject):
|
||||
logging.error('No activities are running')
|
||||
self._set_pending_activity(None)
|
||||
|
||||
self.emit('activity-removed', activity)
|
||||
self._activities.remove(activity)
|
||||
self.emit('activity-removed', home_activity)
|
||||
self._activities.remove(home_activity)
|
||||
|
||||
def _remove_activity_by_xid(self, xid):
|
||||
activity = self._get_activity_by_xid(xid)
|
||||
if activity:
|
||||
self._remove_activity(activity)
|
||||
home_activity = self._get_activity_by_xid(xid)
|
||||
if home_activity:
|
||||
self._remove_activity(home_activity)
|
||||
else:
|
||||
logging.error('Model for window %d does not exist.' % xid)
|
||||
|
||||
def notify_activity_launch(self, activity_id, service_name):
|
||||
bundle = self._bundle_registry.get_bundle(service_name)
|
||||
if not bundle:
|
||||
registry = activity.get_registry()
|
||||
activity_info = registry.get_activity(service_name)
|
||||
if not activity_info:
|
||||
raise ValueError("Activity service name '%s' was not found in the bundle registry." % service_name)
|
||||
activity = HomeActivity(bundle, activity_id)
|
||||
activity.props.launching = True
|
||||
self._add_activity(activity)
|
||||
home_activity = HomeActivity(activity_info, activity_id)
|
||||
home_activity.props.launching = True
|
||||
self._add_activity(home_activity)
|
||||
|
||||
def notify_activity_launch_failed(self, activity_id):
|
||||
activity = self._get_activity_by_id(activity_id)
|
||||
if activity:
|
||||
logging.debug("Activity %s (%s) launch failed" % (activity_id, activity.get_type()))
|
||||
self._remove_activity(activity)
|
||||
home_activity = self._get_activity_by_id(activity_id)
|
||||
if home_activity:
|
||||
logging.debug("Activity %s (%s) launch failed" % (activity_id, home_activity.get_type()))
|
||||
self._remove_activity(home_activity)
|
||||
else:
|
||||
logging.error('Model for activity id %s does not exist.' % activity_id)
|
||||
|
||||
Reference in New Issue
Block a user