2006-10-03 16:31:32 +02:00
|
|
|
import hippo
|
|
|
|
import gobject
|
2006-09-25 05:15:53 +02:00
|
|
|
|
|
|
|
import BuddyIcon
|
2006-10-03 16:31:32 +02:00
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
2006-09-25 05:15:53 +02:00
|
|
|
from sugar.presence import PresenceService
|
|
|
|
import conf
|
|
|
|
|
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
class BuddyActivityView(hippo.CanvasBox):
|
2006-09-25 05:15:53 +02:00
|
|
|
def __init__(self, shell, menu_shell, buddy, **kwargs):
|
2006-10-03 16:31:32 +02:00
|
|
|
hippo.CanvasBox.__init__(self, **kwargs)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
|
|
|
self._pservice = PresenceService.get_instance()
|
|
|
|
self._activity_registry = conf.get_activity_registry()
|
|
|
|
|
|
|
|
self._buddy = buddy
|
|
|
|
self._buddy_icon = BuddyIcon.BuddyIcon(shell, menu_shell, buddy)
|
2006-10-03 16:31:32 +02:00
|
|
|
self.append(self._buddy_icon)
|
2006-09-25 11:42:13 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
self._activity_icon = CanvasIcon(size=48)
|
2006-09-25 05:15:53 +02:00
|
|
|
self._activity_icon_visible = False
|
2006-09-25 11:42:13 +02:00
|
|
|
|
2006-09-26 19:40:52 +02:00
|
|
|
if self._buddy.is_present():
|
2006-10-03 16:31:32 +02:00
|
|
|
self._buddy_appeared_cb(buddy)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
self._buddy.connect('current-activity-changed', self._buddy_activity_changed_cb)
|
|
|
|
self._buddy.connect('appeared', self._buddy_appeared_cb)
|
|
|
|
self._buddy.connect('disappeared', self._buddy_disappeared_cb)
|
|
|
|
self._buddy.connect('color-changed', self._buddy_color_changed_cb)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
|
|
|
def _get_new_icon_name(self, activity):
|
|
|
|
# FIXME: do something better here; we probably need to use "flagship"
|
|
|
|
# services like mDNS where activities default services are marked
|
|
|
|
# somehow.
|
|
|
|
for serv in activity.get_services():
|
|
|
|
act = self._activity_registry.get_activity_from_type(serv.get_type())
|
|
|
|
if act:
|
|
|
|
return act.get_icon()
|
|
|
|
return None
|
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
def _remove_activity_icon(self):
|
2006-09-26 19:40:52 +02:00
|
|
|
if self._activity_icon_visible:
|
2006-10-03 16:31:32 +02:00
|
|
|
self.remove(self._activity_icon)
|
2006-09-25 05:15:53 +02:00
|
|
|
self._activity_icon_visible = False
|
2006-09-26 19:40:52 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
def _buddy_activity_changed_cb(self, buddy, activity=None):
|
2006-09-26 19:40:52 +02:00
|
|
|
if not activity:
|
2006-10-03 16:31:32 +02:00
|
|
|
self._remove_activity_icon()
|
2006-09-25 05:15:53 +02:00
|
|
|
return
|
|
|
|
|
2006-09-26 19:40:52 +02:00
|
|
|
# FIXME: use some sort of "unknown activity" icon rather
|
|
|
|
# than hiding the icon?
|
2006-09-25 05:15:53 +02:00
|
|
|
name = self._get_new_icon_name(activity)
|
|
|
|
if name:
|
|
|
|
self._activity_icon.props.icon_name = name
|
2006-09-26 19:40:52 +02:00
|
|
|
self._activity_icon.props.color = buddy.get_color()
|
|
|
|
if not self._activity_icon_visible:
|
2006-10-03 16:31:32 +02:00
|
|
|
self.append(self._activity_icon)
|
2006-09-26 19:40:52 +02:00
|
|
|
self._activity_icon_visible = True
|
|
|
|
else:
|
2006-10-03 16:31:32 +02:00
|
|
|
self._remove_activity_icon()
|
2006-09-26 19:40:52 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
def _buddy_appeared_cb(self, buddy):
|
2006-09-26 19:40:52 +02:00
|
|
|
activity = self._buddy.get_current_activity()
|
2006-10-03 16:31:32 +02:00
|
|
|
self._buddy_activity_changed_cb(buddy, activity)
|
2006-09-26 19:40:52 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
def _buddy_disappeared_cb(self, buddy):
|
|
|
|
self._buddy_activity_changed_cb(buddy, None)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
def _buddy_color_changed_cb(self, buddy, color):
|
2006-09-25 05:15:53 +02:00
|
|
|
self._activity_icon.props.color = buddy.get_color()
|