2006-09-16 15:36:39 +02:00
|
|
|
from sugar.canvas.Menu import Menu
|
2006-09-14 13:03:11 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-09-16 11:00:46 +02:00
|
|
|
from sugar.presence import PresenceService
|
2006-09-13 16:26:54 +02:00
|
|
|
|
2006-09-16 15:43:07 +02:00
|
|
|
class BuddyMenu(Menu):
|
2006-09-15 02:54:25 +02:00
|
|
|
ACTION_MAKE_FRIEND = 0
|
2006-09-15 03:33:09 +02:00
|
|
|
ACTION_INVITE = 1
|
2006-09-15 15:28:18 +02:00
|
|
|
ACTION_REMOVE_FRIEND = 2
|
2006-09-15 02:54:25 +02:00
|
|
|
|
2006-09-15 15:28:18 +02:00
|
|
|
def __init__(self, shell, buddy):
|
2006-09-21 15:00:59 +02:00
|
|
|
Menu.__init__(self, shell.get_grid(), buddy.get_name())
|
2006-09-13 16:26:54 +02:00
|
|
|
|
2006-09-15 15:28:18 +02:00
|
|
|
self._buddy = buddy
|
2006-09-16 10:46:10 +02:00
|
|
|
self._shell = shell
|
|
|
|
|
|
|
|
owner = shell.get_model().get_owner()
|
|
|
|
if buddy.get_name() != owner.get_name():
|
2006-09-16 15:36:39 +02:00
|
|
|
self._add_actions()
|
2006-09-16 10:46:10 +02:00
|
|
|
|
2006-09-16 15:36:39 +02:00
|
|
|
def _add_actions(self):
|
2006-09-16 11:00:46 +02:00
|
|
|
shell_model = self._shell.get_model()
|
|
|
|
pservice = PresenceService.get_instance()
|
|
|
|
|
|
|
|
friends = shell_model.get_friends()
|
2006-09-16 10:46:10 +02:00
|
|
|
if friends.has_buddy(self._buddy):
|
2006-09-15 15:28:18 +02:00
|
|
|
icon = IconItem(icon_name='stock-remove-friend')
|
2006-09-16 15:43:07 +02:00
|
|
|
self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND)
|
2006-09-15 15:28:18 +02:00
|
|
|
else:
|
|
|
|
icon = IconItem(icon_name='stock-make-friend')
|
2006-09-16 15:43:07 +02:00
|
|
|
self.add_action(icon, BuddyMenu.ACTION_MAKE_FRIEND)
|
2006-09-14 13:03:11 +02:00
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-chat')
|
2006-09-16 15:36:39 +02:00
|
|
|
self.add_action(icon, -1)
|
2006-09-14 13:03:11 +02:00
|
|
|
|
2006-09-21 15:02:46 +02:00
|
|
|
activity_id = shell_model.get_current_activity()
|
|
|
|
if activity_id != None:
|
|
|
|
activity_ps = pservice.get_activity(activity_id)
|
2006-09-16 11:00:46 +02:00
|
|
|
|
|
|
|
# FIXME check that the buddy is not in the activity already
|
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-invite')
|
2006-09-16 15:43:07 +02:00
|
|
|
self.add_action(icon, BuddyMenu.ACTION_INVITE)
|