2006-10-15 01:24:45 +02:00
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# 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
|
2007-02-21 17:55:44 +01:00
|
|
|
from gettext import gettext as _
|
2006-10-15 01:24:45 +02:00
|
|
|
|
2006-10-03 18:52:11 +02:00
|
|
|
import gtk
|
|
|
|
import gobject
|
2006-10-05 18:53:34 +02:00
|
|
|
import hippo
|
2006-09-25 21:20:28 +02:00
|
|
|
|
2007-02-21 17:55:44 +01:00
|
|
|
from sugar.graphics.menu import Menu, MenuItem
|
2006-10-03 18:52:11 +02:00
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
2007-02-21 17:55:44 +01:00
|
|
|
from sugar.graphics import units
|
2007-04-09 20:40:56 +02:00
|
|
|
from sugar.presence import presenceservice
|
2006-10-03 18:52:11 +02:00
|
|
|
|
2006-09-16 15:43:07 +02:00
|
|
|
class BuddyMenu(Menu):
|
2006-12-04 20:12:24 +01:00
|
|
|
ACTION_MAKE_FRIEND = 0
|
|
|
|
ACTION_INVITE = 1
|
|
|
|
ACTION_REMOVE_FRIEND = 2
|
|
|
|
|
|
|
|
def __init__(self, shell, buddy):
|
|
|
|
self._buddy = buddy
|
|
|
|
self._shell = shell
|
|
|
|
|
2007-04-10 21:55:55 +02:00
|
|
|
Menu.__init__(self, buddy.get_nick())
|
2007-02-24 14:58:38 +01:00
|
|
|
self.props.border = 0
|
|
|
|
self.props.padding = units.points_to_pixels(5)
|
2006-12-04 20:12:24 +01:00
|
|
|
pixbuf = self._get_buddy_icon_pixbuf()
|
|
|
|
if pixbuf:
|
2007-02-21 17:55:44 +01:00
|
|
|
scaled_pixbuf = pixbuf.scale_simple(units.grid_to_pixels(1),
|
|
|
|
units.grid_to_pixels(1),
|
2006-12-04 20:12:24 +01:00
|
|
|
gtk.gdk.INTERP_BILINEAR)
|
|
|
|
del pixbuf
|
2007-04-10 22:45:36 +02:00
|
|
|
image = hippo.cairo_surface_from_gdk_pixbuf(scaled_pixbuf)
|
|
|
|
icon_item = hippo.CanvasImage(image=image)
|
2007-02-21 17:55:44 +01:00
|
|
|
self.add_separator()
|
|
|
|
self.append(icon_item)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
|
|
|
|
|
|
|
|
owner = shell.get_model().get_owner()
|
2007-04-10 21:55:55 +02:00
|
|
|
if buddy.get_nick() != owner.get_nick():
|
2007-02-21 17:55:44 +01:00
|
|
|
self._add_items()
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def _get_buddy_icon_pixbuf(self):
|
|
|
|
buddy_object = self._buddy.get_buddy()
|
|
|
|
if not buddy_object:
|
|
|
|
return None
|
|
|
|
|
2007-04-10 20:56:34 +02:00
|
|
|
icon_data = buddy_object.props.icon
|
2007-04-11 04:24:31 +02:00
|
|
|
if not icon_data:
|
|
|
|
return None
|
2006-12-04 20:12:24 +01:00
|
|
|
pbl = gtk.gdk.PixbufLoader()
|
2007-04-11 04:24:31 +02:00
|
|
|
pbl.write(icon_data)
|
|
|
|
pixbuf = None
|
2006-12-04 20:12:24 +01:00
|
|
|
try:
|
|
|
|
pbl.close()
|
|
|
|
pixbuf = pbl.get_pixbuf()
|
|
|
|
except gobject.GError:
|
|
|
|
pass
|
|
|
|
del pbl
|
|
|
|
return pixbuf
|
|
|
|
|
2007-02-21 17:55:44 +01:00
|
|
|
def _add_items(self):
|
2006-12-04 20:12:24 +01:00
|
|
|
shell_model = self._shell.get_model()
|
2007-04-09 20:40:56 +02:00
|
|
|
pservice = presenceservice.get_instance()
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
friends = shell_model.get_friends()
|
|
|
|
if friends.has_buddy(self._buddy):
|
2007-02-21 17:55:44 +01:00
|
|
|
self.add_item(MenuItem(BuddyMenu.ACTION_REMOVE_FRIEND,
|
|
|
|
_('Remove friend'),
|
|
|
|
'theme:stock-remove'))
|
2006-12-04 20:12:24 +01:00
|
|
|
else:
|
2007-02-21 17:55:44 +01:00
|
|
|
self.add_item(MenuItem(BuddyMenu.ACTION_MAKE_FRIEND,
|
|
|
|
_('Make friend'),
|
|
|
|
'theme:stock-add'))
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-01-10 15:30:21 +01:00
|
|
|
activity = shell_model.get_home().get_current_activity()
|
|
|
|
if activity != None:
|
2007-04-15 22:51:01 +02:00
|
|
|
activity_ps = pservice.get_activity(activity.get_activity_id())
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
# FIXME check that the buddy is not in the activity already
|
|
|
|
|
2007-02-21 17:55:44 +01:00
|
|
|
self.add_item(MenuItem(BuddyMenu.ACTION_INVITE,
|
|
|
|
_('Invite'),
|
|
|
|
'theme:stock-invite'))
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def __buddy_icon_changed_cb(self, buddy):
|
|
|
|
pass
|