Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-09-15 10:40:46 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-09-15 10:40:46 (GMT)
commit14383f4fc7c6e182fc8a79e5f9d56c740b2bc7e7 (patch)
treeb9a4a0b0bb5ef879fbb3e1ae801206917ba961ed /shell
parent645aa93e50288547dda88c156795839178426df9 (diff)
Forgot to add the model
Diffstat (limited to 'shell')
-rw-r--r--shell/ShellModel.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/shell/ShellModel.py b/shell/ShellModel.py
new file mode 100644
index 0000000..c0c8bcc
--- /dev/null
+++ b/shell/ShellModel.py
@@ -0,0 +1,86 @@
+import gobject
+
+from Owner import ShellOwner
+from sugar.presence import PresenceService
+from sugar.activity import ActivityFactory
+from sugar.activity import Activity
+from Friends import Friends
+from Invites import Invites
+
+class ShellModel(gobject.GObject):
+ __gsignals__ = {
+ 'activity-opened': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
+ 'activity-changed': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
+ 'activity-closed': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
+ }
+
+ def __init__(self):
+ gobject.GObject.__init__(self)
+
+ self._hosts = {}
+ self._current_activity = None
+
+ PresenceService.start()
+ self._pservice = PresenceService.get_instance()
+
+ self._owner = ShellOwner()
+ self._owner.announce()
+ self._friends = Friends()
+ self._invites = Invites()
+
+ def get_friends(self):
+ return self._friends
+
+ def get_invites(self):
+ return self._invites
+
+ def get_owner(self):
+ return self._owner
+
+ def add_activity(self, activity_host):
+ self._hosts[activity_host.get_xid()] = activity_host
+ self.emit('activity-opened', activity_host)
+
+ def set_current_activity(self, activity_xid):
+ activity_host = self._hosts[activity_xid]
+ if self._current_activity == activity_host:
+ return
+
+ self._current_activity = activity_host
+ self.emit('activity-changed', activity_host)
+
+ def remove_activity(self, activity_xid):
+ if self._hosts.has_key(activity_xid):
+ host = self._hosts[activity_xid]
+ self.emit('activity-closed', host)
+ del self._hosts[activity_xid]
+
+ def get_activity(self, activity_id):
+ for host in self._hosts.values():
+ if host.get_id() == activity_id:
+ return host
+ return None
+
+ def get_current_activity(self):
+ return self._current_activity
+
+ def join_activity(self, bundle_id, activity_id):
+ activity = self.get_activity(activity_id)
+ if activity:
+ activity.present()
+ else:
+ activity_ps = self._pservice.get_activity(activity_id)
+
+ if activity_ps:
+ activity = ActivityFactory.create(bundle_id)
+ activity.join(activity_ps.object_path())
+ else:
+ logging.error('Cannot start activity.')
+
+ def start_activity(self, activity_type):
+ activity = ActivityFactory.create(activity_type)
+ activity.execute('test', [])
+ return activity