Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/ActivityHost.py
blob: 456406bce8e24c7dbc2f1aa5b46524f793219508 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gtk
import dbus

import conf
from sugar.activity import Activity
from sugar.presence import PresenceService
from sugar.canvas.IconColor import IconColor
from sugar.p2p import Stream
from sugar.p2p import network

class ActivityHost:
	def __init__(self, shell, window):
		self._shell = shell
		self._window = window
		self._xid = window.get_xid()
		self._pservice = PresenceService.get_instance()

		bus = dbus.SessionBus()
		proxy_obj = bus.get_object(Activity.get_service_name(self._xid),
								   Activity.get_object_path(self._xid))

		self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
		self._id = self._activity.get_id()
		self._type = self._activity.get_type()
		self._gdk_window = gtk.gdk.window_foreign_new(self._xid)

		registry = conf.get_activity_registry()
		info = registry.get_activity(self._type)
		self._icon_name = info.get_icon()

	def get_id(self):
		return self._id

	def get_xid(self):
		return self._xid

	def get_icon_name(self):
		return self._icon_name

	def get_icon_color(self):
		activity = self._pservice.get_activity(self._id)
		if activity != None:
			return IconColor(activity.get_color())
		else:
			return conf.get_profile().get_color()

	def share(self):
		self._activity.share()

	def invite(self, buddy):
		if not self.get_shared():
			self.share()

		issuer = self._pservice.get_owner().get_name()
		service = buddy.get_service_of_type("_presence_olpc._tcp")
		stream = Stream.Stream.new_from_service(service, start_reader=False)
		writer = stream.new_writer(service)
		writer.custom_request("invite", None, None, issuer,
							  self._type, self._id)

	def get_shared(self):
		return self._activity.get_shared()

	def get_type(self):
		return self._type

	def present(self):
		self._window.activate(gtk.get_current_event_time())

	def show_dialog(self, dialog):
		dialog.show()
		dialog.window.set_transient_for(self._gdk_window)