Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/view/BuddyMenu.py
blob: 3658f87da8ca73ac83f309da5f18ed05c1fbf09b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from sugar.canvas.Menu import Menu
from sugar.canvas.IconItem import IconItem
from sugar.presence import PresenceService

class BuddyMenu(Menu):
	ACTION_MAKE_FRIEND = 0
	ACTION_INVITE = 1
	ACTION_REMOVE_FRIEND = 2

	def __init__(self, shell, buddy):
		Menu.__init__(self, shell.get_grid(), buddy.get_name())

		self._buddy = buddy
		self._shell = shell

		owner = shell.get_model().get_owner()
		if buddy.get_name() != owner.get_name():
			self._add_actions()

	def _add_actions(self):
		shell_model = self._shell.get_model()
		pservice = PresenceService.get_instance()

		friends = shell_model.get_friends()
		if friends.has_buddy(self._buddy):
			icon = IconItem(icon_name='stock-remove-friend')
			self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND) 
		else:
			icon = IconItem(icon_name='stock-make-friend')
			self.add_action(icon, BuddyMenu.ACTION_MAKE_FRIEND)

		icon = IconItem(icon_name='stock-chat')
		self.add_action(icon, -1)

		activity_id = shell_model.get_current_activity()
		if activity_id != None:
			activity_ps = pservice.get_activity(activity_id)

			# FIXME check that the buddy is not in the activity already

			icon = IconItem(icon_name='stock-invite')
			self.add_action(icon, BuddyMenu.ACTION_INVITE)