2007-06-24 14:45:05 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2006-10-15 01:24:45 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
import hippo
|
|
|
|
import gobject
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
2007-07-31 16:46:06 +02:00
|
|
|
from sugar.graphics import style
|
2007-04-09 20:40:56 +02:00
|
|
|
from sugar.presence import presenceservice
|
2007-08-09 18:10:16 +02:00
|
|
|
from sugar import activity
|
2007-05-27 20:24:10 +02:00
|
|
|
|
|
|
|
from view.BuddyIcon import BuddyIcon
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-10-05 14:52:33 +02:00
|
|
|
class FriendView(hippo.CanvasBox):
|
2007-07-01 12:55:10 +02:00
|
|
|
def __init__(self, shell, buddy, **kwargs):
|
2006-12-04 20:12:24 +01:00
|
|
|
hippo.CanvasBox.__init__(self, **kwargs)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
self._pservice = presenceservice.get_instance()
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._buddy = buddy
|
2007-07-01 12:55:10 +02:00
|
|
|
self._buddy_icon = BuddyIcon(shell, buddy)
|
2007-07-31 17:15:36 +02:00
|
|
|
self._buddy_icon.props.size = style.LARGE_ICON_SIZE
|
2006-12-04 20:12:24 +01:00
|
|
|
self.append(self._buddy_icon)
|
2006-09-25 11:42:13 +02:00
|
|
|
|
2007-07-31 16:46:06 +02:00
|
|
|
self._activity_icon = CanvasIcon(size=style.LARGE_ICON_SIZE)
|
2006-12-04 20:12:24 +01:00
|
|
|
self._activity_icon_visible = False
|
2006-09-25 11:42:13 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
if self._buddy.is_present():
|
|
|
|
self._buddy_appeared_cb(buddy)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-12-04 20:12:24 +01: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
|
|
|
|
2007-08-09 18:10:16 +02:00
|
|
|
def _get_new_icon_name(self, home_activity):
|
|
|
|
registry = activity.get_registry()
|
|
|
|
bundle = registry.get_bundle(home_activity.get_type())
|
2007-04-09 22:05:32 +02:00
|
|
|
if bundle:
|
|
|
|
return bundle.get_icon()
|
2006-12-04 20:12:24 +01:00
|
|
|
return None
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _remove_activity_icon(self):
|
|
|
|
if self._activity_icon_visible:
|
|
|
|
self.remove(self._activity_icon)
|
|
|
|
self._activity_icon_visible = False
|
2006-09-26 19:40:52 +02:00
|
|
|
|
2007-08-09 18:10:16 +02:00
|
|
|
def _buddy_activity_changed_cb(self, buddy, home_activity=None):
|
|
|
|
if not home_activity:
|
2006-12-04 20:12:24 +01:00
|
|
|
self._remove_activity_icon()
|
|
|
|
return
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
# FIXME: use some sort of "unknown activity" icon rather
|
|
|
|
# than hiding the icon?
|
2007-08-09 18:10:16 +02:00
|
|
|
name = self._get_new_icon_name(home_activity)
|
2006-12-04 20:12:24 +01:00
|
|
|
if name:
|
|
|
|
self._activity_icon.props.icon_name = name
|
2007-02-23 17:08:37 +01:00
|
|
|
self._activity_icon.props.xo_color = buddy.get_color()
|
2006-12-04 20:12:24 +01:00
|
|
|
if not self._activity_icon_visible:
|
|
|
|
self.append(self._activity_icon, hippo.PACK_EXPAND)
|
|
|
|
self._activity_icon_visible = True
|
|
|
|
else:
|
|
|
|
self._remove_activity_icon()
|
2006-09-26 19:40:52 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _buddy_appeared_cb(self, buddy):
|
2007-08-09 18:10:16 +02:00
|
|
|
home_activity = self._buddy.get_current_activity()
|
|
|
|
self._buddy_activity_changed_cb(buddy, home_activity)
|
2006-09-26 19:40:52 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _buddy_disappeared_cb(self, buddy):
|
|
|
|
self._buddy_activity_changed_cb(buddy, None)
|
2006-09-25 05:15:53 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _buddy_color_changed_cb(self, buddy, color):
|
2007-02-23 17:08:37 +01:00
|
|
|
self._activity_icon.props.xo_color = buddy.get_color()
|