Finish up porting to the new registry
This commit is contained in:
parent
2b97505577
commit
ba5d1b4804
@ -22,7 +22,7 @@ from sugar.presence import PresenceService
|
|||||||
from model.BuddyModel import BuddyModel
|
from model.BuddyModel import BuddyModel
|
||||||
|
|
||||||
class ActivityModel:
|
class ActivityModel:
|
||||||
def __init__(self, activity, service):
|
def __init__(self, activity, bundle, service):
|
||||||
self._service = service
|
self._service = service
|
||||||
self._activity = activity
|
self._activity = activity
|
||||||
|
|
||||||
@ -30,10 +30,7 @@ class ActivityModel:
|
|||||||
return self._activity.get_id()
|
return self._activity.get_id()
|
||||||
|
|
||||||
def get_icon_name(self):
|
def get_icon_name(self):
|
||||||
registry = conf.get_activity_registry()
|
return bundle.get_icon()
|
||||||
info = registry.get_activity_from_type(self._service.get_type())
|
|
||||||
|
|
||||||
return info.get_icon()
|
|
||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
return IconColor(self._activity.get_color())
|
return IconColor(self._activity.get_color())
|
||||||
@ -56,11 +53,12 @@ class MeshModel(gobject.GObject):
|
|||||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
|
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, bundle_registry):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self._activities = {}
|
self._activities = {}
|
||||||
self._buddies = {}
|
self._buddies = {}
|
||||||
|
self._bundle_registry = bundle_registry
|
||||||
|
|
||||||
self._pservice = PresenceService.get_instance()
|
self._pservice = PresenceService.get_instance()
|
||||||
self._pservice.connect("service-appeared",
|
self._pservice.connect("service-appeared",
|
||||||
@ -124,8 +122,7 @@ class MeshModel(gobject.GObject):
|
|||||||
self._check_service(service)
|
self._check_service(service)
|
||||||
|
|
||||||
def _check_service(self, service):
|
def _check_service(self, service):
|
||||||
registry = conf.get_activity_registry()
|
if self._bundle_registry.get_bundle(service.get_type()) != None:
|
||||||
if registry.get_activity_from_type(service.get_type()) != None:
|
|
||||||
activity_id = service.get_activity_id()
|
activity_id = service.get_activity_id()
|
||||||
if not self.has_activity(activity_id):
|
if not self.has_activity(activity_id):
|
||||||
activity = self._pservice.get_activity(activity_id)
|
activity = self._pservice.get_activity(activity_id)
|
||||||
@ -135,8 +132,15 @@ class MeshModel(gobject.GObject):
|
|||||||
def has_activity(self, activity_id):
|
def has_activity(self, activity_id):
|
||||||
return self._activities.has_key(activity_id)
|
return self._activities.has_key(activity_id)
|
||||||
|
|
||||||
|
def get_activity(self, activity_id):
|
||||||
|
if self.has_activity(activity_id):
|
||||||
|
return self._activities[activity_id]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def add_activity(self, activity, service):
|
def add_activity(self, activity, service):
|
||||||
model = ActivityModel(activity, service)
|
bundle = self._bundle_registry.get_bundle(service.get_type())
|
||||||
|
model = ActivityModel(activity, bundle, service)
|
||||||
self._activities[model.get_id()] = model
|
self._activities[model.get_id()] = model
|
||||||
self.emit('activity-added', model)
|
self.emit('activity-added', model)
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ class ShellModel:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._current_activity = None
|
self._current_activity = None
|
||||||
|
|
||||||
|
self._bundle_registry = BundleRegistry()
|
||||||
|
|
||||||
PresenceService.start()
|
PresenceService.start()
|
||||||
self._pservice = PresenceService.get_instance()
|
self._pservice = PresenceService.get_instance()
|
||||||
|
|
||||||
@ -34,9 +36,7 @@ class ShellModel:
|
|||||||
self._owner.announce()
|
self._owner.announce()
|
||||||
|
|
||||||
self._friends = Friends()
|
self._friends = Friends()
|
||||||
self._mesh = MeshModel()
|
self._mesh = MeshModel(self._bundle_registry)
|
||||||
|
|
||||||
self._bundle_registry = BundleRegistry()
|
|
||||||
|
|
||||||
path = os.path.expanduser('~/Activities')
|
path = os.path.expanduser('~/Activities')
|
||||||
self._bundle_registry.add_search_path(path)
|
self._bundle_registry.add_search_path(path)
|
||||||
|
@ -32,11 +32,11 @@ class ActivityItem(CanvasIcon):
|
|||||||
return self._activity.get_service_name()
|
return self._activity.get_service_name()
|
||||||
|
|
||||||
class InviteItem(CanvasIcon):
|
class InviteItem(CanvasIcon):
|
||||||
def __init__(self, invite):
|
def __init__(self, activity, invite):
|
||||||
CanvasIcon.__init__(self, icon_name=invite.get_icon())
|
CanvasIcon.__init__(self, icon_name=activity.get_icon())
|
||||||
|
|
||||||
style.apply_stylesheet(self, 'frame.ActivityIcon')
|
style.apply_stylesheet(self, 'frame.ActivityIcon')
|
||||||
self.props.color = invite.get_color()
|
self.props.color = activity.get_color()
|
||||||
|
|
||||||
self._invite = invite
|
self._invite = invite
|
||||||
|
|
||||||
@ -87,7 +87,10 @@ class ActivitiesBox(hippo.CanvasBox):
|
|||||||
self.append(item, 0)
|
self.append(item, 0)
|
||||||
|
|
||||||
def add_invite(self, invite):
|
def add_invite(self, invite):
|
||||||
item = InviteItem(invite)
|
mesh = self._shell_model.get_mesh()
|
||||||
|
activity = mesh.get_activity(invite.get_activity_id())
|
||||||
|
if activity:
|
||||||
|
item = InviteItem(activity, invite)
|
||||||
item.connect('activated', self._invite_clicked_cb)
|
item.connect('activated', self._invite_clicked_cb)
|
||||||
self.append(item, 0)
|
self.append(item, 0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user