Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/ActivityContainer.py
blob: 85c954a906804cbc5156abb4dc0166abb9b77af3 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import dbus
import gobject
import gtk
from gettext import gettext as _

from sugar.chat.ChatWindow import ChatWindow
from sugar.chat.MeshChat import MeshChat
from ActivityHost import ActivityHost
from PresenceWindow import PresenceWindow
from WindowManager import WindowManager
from StartPage import StartPage
from Owner import ShellOwner

class ActivityContainerSignalHelper(gobject.GObject):
	"""A gobject whose sole purpose is to distribute signals for
	an ActivityContainer object."""

	__gsignals__ = {
		'local-activity-started': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
		'local-activity-ended': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
						([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT]))
	}

	def __init__(self, parent):
		gobject.GObject.__init__(self)
		self._parent = parent

	def activity_started(self, activity_id):
		self.emit('local-activity-started', self._parent, activity_id)

	def activity_ended(self, activity_id):
		self.emit('local-activity-ended', self._parent, activity_id)

class ActivityContainer(dbus.service.Object):

	def __init__(self, service, bus):
		self.activities = []

		self.bus = bus
		self.service = service

		self._signal_helper = ActivityContainerSignalHelper(self)

		dbus.service.Object.__init__(self, self.service, "/com/redhat/Sugar/Shell/ActivityContainer")
		bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")

		self.window = gtk.Window()
		self.window.connect("key-press-event", self.__key_press_event_cb)
		self.window.set_title("OLPC Sugar")

		self._fullscreen = False

		self.notebook = gtk.Notebook()
		self.notebook.set_scrollable(True)

		tab_label = gtk.Label(_("Everyone"))
		self._start_page = StartPage(self._signal_helper)
		self.notebook.append_page(self._start_page, tab_label)
		self._start_page.show()

		self.notebook.show()
		self.notebook.connect("switch-page", self.notebook_tab_changed)
		self.window.add(self.notebook)
		
		self.window.connect("destroy", lambda w: gtk.main_quit())
		
		self.current_activity = None

		# Create our owner service
		self._owner = ShellOwner()

		self._presence_window = PresenceWindow(self)
		self._presence_window.set_transient_for(self.window)

		wm = WindowManager(self._presence_window)
		wm.set_type(WindowManager.TYPE_POPUP)
		wm.set_animation(WindowManager.ANIMATION_SLIDE_IN)
		wm.set_geometry(0.02, 0.1, 0.25, 0.9)
		wm.set_key(gtk.keysyms.F1)
		
		self._chat_window = ChatWindow()
		self._chat_window.set_transient_for(self.window)

		self._chat_wm = WindowManager(self._chat_window)
		self._chat_wm.set_animation(WindowManager.ANIMATION_SLIDE_IN)
		self._chat_wm.set_type(WindowManager.TYPE_POPUP)
		self._chat_wm.set_geometry(0.28, 0.1, 0.5, 0.9)
		self._chat_wm.set_key(gtk.keysyms.F1)
				
		self._mesh_chat = MeshChat()

	def show(self):
		self.window.show()

	def set_current_activity(self, activity):
		self.current_activity = activity
		self._presence_window.set_activity(activity)

		if activity:
			host_chat = activity.get_chat()
			self._chat_window.set_chat(host_chat)
		else:
			self._chat_window.set_chat(self._mesh_chat)

	def notebook_tab_changed(self, notebook, page, page_number):
		new_activity = notebook.get_nth_page(page_number).get_data("sugar-activity")

		if self.current_activity != None:
			self.current_activity.lost_focus()
		
		self.set_current_activity(new_activity)

		if self.current_activity != None:
			self.current_activity.got_focus()

	def name_owner_changed(self, service_name, old_service_name, new_service_name):
		#print "in name_owner_changed: svc=%s oldsvc=%s newsvc=%s"%(service_name, old_service_name, new_service_name)
		for owner, activity in self.activities[:]:
			if owner == old_service_name:
				activity_id = activity.get_host_activity_id()
				self._signal_helper.activity_ended(activity_id)
				self.activities.remove((owner, activity))
		#self.__print_activities()


	@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
			 in_signature="ss", \
			 out_signature="s", \
			 sender_keyword="sender")
	def add_activity(self, activity_name, default_type, sender):
		#print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender)
		activity = ActivityHost(self, activity_name, default_type)
		self.activities.append((sender, activity))

		activity_id = activity.get_host_activity_id()
		self._signal_helper.activity_started(activity_id)

		self.current_activity = activity
		return activity_id

	@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
			 in_signature="sss", \
			 sender_keyword="sender")
	def add_activity_with_id(self, activity_name, default_type, activity_id, sender):
		activity = ActivityHost(self, activity_name, default_type, activity_id)
		self.activities.append((sender, activity))
		activity_id = activity.get_host_activity_id()
		self._signal_helper.activity_started(activity_id)
		self.current_activity = activity
		
	def __print_activities(self):
		print "__print_activities: %d activities registered" % len(self.activities)
		i = 0
		for owner, activity in self.activities:
			print "  %d: owner=%s activity_object_name=%s" % (i, owner, activity.dbus_object_name)
			i += 1
	
	def __key_press_event_cb(self, window, event):
		if event.keyval == gtk.keysyms.F11:
			if self._fullscreen:
				window.unfullscreen()
				self._fullscreen = False
			else:
				window.fullscreen()
				self._fullscreen = True