2006-08-29 11:48:20 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
import goocanvas
|
|
|
|
|
2006-09-04 21:34:54 +02:00
|
|
|
import conf
|
2006-08-29 11:48:20 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
|
|
|
from sugar.canvas.IconItem import IconColor
|
2006-08-30 10:54:28 +02:00
|
|
|
from sugar.presence import PresenceService
|
2006-09-15 13:23:21 +02:00
|
|
|
from view.home.IconLayout import IconLayout
|
2006-08-29 11:48:20 +02:00
|
|
|
|
|
|
|
class ActivityItem(IconItem):
|
2006-09-12 12:19:20 +02:00
|
|
|
def __init__(self, activity, service):
|
2006-08-30 10:54:28 +02:00
|
|
|
self._service = service
|
2006-09-12 12:19:20 +02:00
|
|
|
self._activity = activity
|
2006-08-30 10:54:28 +02:00
|
|
|
|
|
|
|
IconItem.__init__(self, icon_name=self.get_icon_name(),
|
2006-09-22 21:29:48 +02:00
|
|
|
color=self.get_color(), size=112)
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-08-30 10:54:28 +02:00
|
|
|
def get_id(self):
|
2006-09-12 12:19:20 +02:00
|
|
|
return self._activity.get_id()
|
2006-08-30 10:54:28 +02:00
|
|
|
|
|
|
|
def get_icon_name(self):
|
|
|
|
registry = conf.get_activity_registry()
|
2006-09-02 10:54:34 +02:00
|
|
|
info = registry.get_activity_from_type(self._service.get_type())
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-08-30 10:54:28 +02:00
|
|
|
return info.get_icon()
|
|
|
|
|
|
|
|
def get_color(self):
|
2006-09-12 12:19:20 +02:00
|
|
|
return IconColor(self._activity.get_color())
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-08-30 13:14:37 +02:00
|
|
|
def get_service(self):
|
|
|
|
return self._service
|
|
|
|
|
2006-08-29 11:48:20 +02:00
|
|
|
class MeshGroup(goocanvas.Group):
|
2006-09-15 15:28:18 +02:00
|
|
|
def __init__(self, shell):
|
2006-08-29 11:48:20 +02:00
|
|
|
goocanvas.Group.__init__(self)
|
2006-09-15 15:28:18 +02:00
|
|
|
|
|
|
|
self._shell = shell
|
|
|
|
|
2006-09-24 22:55:13 +02:00
|
|
|
self._icon_layout = IconLayout(shell.get_grid())
|
2006-08-30 10:54:28 +02:00
|
|
|
self._activities = {}
|
2006-08-29 16:07:23 +02:00
|
|
|
|
2006-09-12 12:19:20 +02:00
|
|
|
self._pservice = PresenceService.get_instance()
|
2006-09-22 21:49:59 +02:00
|
|
|
self._pservice.connect("service-appeared",
|
|
|
|
self._service_appeared_cb)
|
|
|
|
self._pservice.connect('activity-disappeared',
|
|
|
|
self._activity_disappeared_cb)
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-09-12 12:19:20 +02:00
|
|
|
for service in self._pservice.get_services():
|
|
|
|
self._check_service(service)
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-09-12 12:19:20 +02:00
|
|
|
def _service_appeared_cb(self, pservice, service):
|
|
|
|
self._check_service(service)
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-09-12 12:19:20 +02:00
|
|
|
def _check_service(self, service):
|
2006-08-30 10:54:28 +02:00
|
|
|
registry = conf.get_activity_registry()
|
2006-09-02 10:54:34 +02:00
|
|
|
if registry.get_activity_from_type(service.get_type()) != None:
|
2006-09-12 12:19:20 +02:00
|
|
|
activity_id = service.get_activity_id()
|
|
|
|
if not self.has_activity(activity_id):
|
|
|
|
activity = self._pservice.get_activity(activity_id)
|
|
|
|
if activity != None:
|
|
|
|
self.add_activity(activity, service)
|
2006-08-30 10:54:28 +02:00
|
|
|
|
|
|
|
def has_activity(self, activity_id):
|
|
|
|
return self._activities.has_key(activity_id)
|
|
|
|
|
2006-09-12 12:19:20 +02:00
|
|
|
def add_activity(self, activity, service):
|
|
|
|
item = ActivityItem(activity, service)
|
|
|
|
item.connect('clicked', self._activity_clicked_cb)
|
2006-08-29 16:07:23 +02:00
|
|
|
self._icon_layout.add_icon(item)
|
2006-08-29 11:48:20 +02:00
|
|
|
self.add_child(item)
|
|
|
|
|
2006-08-30 10:54:28 +02:00
|
|
|
self._activities[item.get_id()] = item
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-09-12 13:21:18 +02:00
|
|
|
def _activity_disappeared_cb(self, pservice, activity):
|
2006-09-12 12:19:20 +02:00
|
|
|
if self._activities.has_key(activity.get_id()):
|
|
|
|
self.remove_child(self._activities[activity.get_id()])
|
|
|
|
del self._activities[activity.get_id()]
|
|
|
|
|
|
|
|
def _activity_clicked_cb(self, item):
|
2006-09-04 17:00:45 +02:00
|
|
|
default_type = item.get_service().get_type()
|
|
|
|
registry = conf.get_activity_registry()
|
|
|
|
|
2006-09-08 01:54:52 +02:00
|
|
|
bundle_id = registry.get_activity_from_type(default_type).get_id()
|
2006-09-12 12:19:20 +02:00
|
|
|
activity_id = item.get_id()
|
2006-09-04 17:00:45 +02:00
|
|
|
|
|
|
|
self._shell.join_activity(bundle_id, activity_id)
|