2006-07-20 11:34:06 +02:00
|
|
|
import gtk
|
|
|
|
import dbus
|
|
|
|
|
2006-09-04 21:34:54 +02:00
|
|
|
import conf
|
2006-07-20 11:34:06 +02:00
|
|
|
from sugar.activity import Activity
|
2006-08-26 14:17:55 +02:00
|
|
|
from sugar.presence import PresenceService
|
|
|
|
from sugar.canvas.IconColor import IconColor
|
2006-09-04 14:30:44 +02:00
|
|
|
from sugar.p2p import Stream
|
|
|
|
from sugar.p2p import network
|
2006-09-28 21:52:56 +02:00
|
|
|
from sugar.chat import ActivityChat
|
|
|
|
|
|
|
|
class ActivityChatWindow(gtk.Window):
|
|
|
|
def __init__(self, gdk_window, chat_widget):
|
|
|
|
gtk.Window.__init__(self)
|
|
|
|
|
|
|
|
self.realize()
|
|
|
|
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
|
|
|
self.window.set_accept_focus(True)
|
|
|
|
self.window.set_transient_for(gdk_window)
|
2006-09-28 22:20:48 +02:00
|
|
|
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
|
2006-09-28 23:00:03 +02:00
|
|
|
self.set_default_size(600, 450)
|
2006-09-28 21:52:56 +02:00
|
|
|
|
|
|
|
self.add(chat_widget)
|
2006-07-20 11:34:06 +02:00
|
|
|
|
|
|
|
class ActivityHost:
|
2006-08-09 18:29:33 +02:00
|
|
|
def __init__(self, shell, window):
|
2006-07-26 12:57:54 +02:00
|
|
|
self._shell = shell
|
2006-09-28 21:52:56 +02:00
|
|
|
|
2006-08-12 00:29:32 +02:00
|
|
|
self._window = window
|
|
|
|
self._xid = window.get_xid()
|
2006-09-04 17:00:45 +02:00
|
|
|
self._pservice = PresenceService.get_instance()
|
2006-08-09 18:29:33 +02:00
|
|
|
|
2006-07-20 11:34:06 +02:00
|
|
|
bus = dbus.SessionBus()
|
2006-08-12 00:29:32 +02:00
|
|
|
proxy_obj = bus.get_object(Activity.get_service_name(self._xid),
|
|
|
|
Activity.get_object_path(self._xid))
|
2006-07-20 11:34:06 +02:00
|
|
|
|
2006-08-09 12:57:42 +02:00
|
|
|
self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
|
2006-07-20 11:34:06 +02:00
|
|
|
self._id = self._activity.get_id()
|
2006-09-02 10:54:34 +02:00
|
|
|
self._type = self._activity.get_type()
|
2006-08-12 00:29:32 +02:00
|
|
|
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
|
2006-07-20 11:34:06 +02:00
|
|
|
|
2006-08-22 14:01:53 +02:00
|
|
|
registry = conf.get_activity_registry()
|
2006-09-02 10:54:34 +02:00
|
|
|
info = registry.get_activity(self._type)
|
2006-08-17 14:23:52 +02:00
|
|
|
self._icon_name = info.get_icon()
|
|
|
|
|
2006-09-28 21:52:56 +02:00
|
|
|
self._chat_widget = ActivityChat.ActivityChat(self)
|
|
|
|
self._chat_window = ActivityChatWindow(self._gdk_window, self._chat_widget)
|
|
|
|
|
2006-09-28 22:13:48 +02:00
|
|
|
self._frame_was_visible = False
|
|
|
|
self._shell.connect('activity-changed', self._activity_changed_cb)
|
|
|
|
self._shell.connect('activity-closed', self._activity_closed_cb)
|
|
|
|
|
2006-07-20 11:34:06 +02:00
|
|
|
def get_id(self):
|
|
|
|
return self._id
|
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
def get_title(self):
|
|
|
|
return self._window.get_name()
|
|
|
|
|
2006-09-15 12:40:22 +02:00
|
|
|
def get_xid(self):
|
|
|
|
return self._xid
|
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
def get_icon_name(self):
|
|
|
|
return self._icon_name
|
|
|
|
|
2006-08-26 14:17:55 +02:00
|
|
|
def get_icon_color(self):
|
2006-09-04 17:00:45 +02:00
|
|
|
activity = self._pservice.get_activity(self._id)
|
2006-08-26 14:17:55 +02:00
|
|
|
if activity != None:
|
|
|
|
return IconColor(activity.get_color())
|
|
|
|
else:
|
|
|
|
return conf.get_profile().get_color()
|
|
|
|
|
2006-07-26 00:17:05 +02:00
|
|
|
def share(self):
|
|
|
|
self._activity.share()
|
2006-07-20 11:34:06 +02:00
|
|
|
|
2006-09-04 14:30:44 +02:00
|
|
|
def invite(self, buddy):
|
2006-09-04 17:00:45 +02:00
|
|
|
if not self.get_shared():
|
|
|
|
self.share()
|
|
|
|
|
|
|
|
issuer = self._pservice.get_owner().get_name()
|
2006-09-04 14:30:44 +02:00
|
|
|
service = buddy.get_service_of_type("_presence_olpc._tcp")
|
|
|
|
stream = Stream.Stream.new_from_service(service, start_reader=False)
|
|
|
|
writer = stream.new_writer(service)
|
2006-09-04 17:00:45 +02:00
|
|
|
writer.custom_request("invite", None, None, issuer,
|
|
|
|
self._type, self._id)
|
2006-09-04 14:30:44 +02:00
|
|
|
|
2006-07-20 11:34:06 +02:00
|
|
|
def get_shared(self):
|
|
|
|
return self._activity.get_shared()
|
|
|
|
|
2006-09-02 10:54:34 +02:00
|
|
|
def get_type(self):
|
|
|
|
return self._type
|
2006-07-20 12:13:47 +02:00
|
|
|
|
2006-08-12 00:29:32 +02:00
|
|
|
def present(self):
|
|
|
|
self._window.activate(gtk.get_current_event_time())
|
|
|
|
|
2006-09-18 11:56:53 +02:00
|
|
|
def close(self):
|
|
|
|
self._window.close(gtk.get_current_event_time())
|
|
|
|
|
2006-07-20 11:34:06 +02:00
|
|
|
def show_dialog(self, dialog):
|
|
|
|
dialog.show()
|
2006-08-12 00:29:32 +02:00
|
|
|
dialog.window.set_transient_for(self._gdk_window)
|
2006-09-28 21:52:56 +02:00
|
|
|
|
2006-09-28 22:12:07 +02:00
|
|
|
def chat_show(self, frame_was_visible):
|
2006-09-28 21:52:56 +02:00
|
|
|
self._chat_window.show_all()
|
2006-09-28 22:12:07 +02:00
|
|
|
self._frame_was_visible = frame_was_visible
|
2006-09-28 21:52:56 +02:00
|
|
|
|
|
|
|
def chat_hide(self):
|
|
|
|
self._chat_window.hide()
|
2006-09-28 22:12:07 +02:00
|
|
|
wasvis = self._frame_was_visible
|
|
|
|
self._frame_was_visible = False
|
|
|
|
return wasvis
|
2006-09-28 21:52:56 +02:00
|
|
|
|
|
|
|
def is_chat_visible(self):
|
|
|
|
return self._chat_window.get_property('visible')
|
|
|
|
|
|
|
|
def _activity_changed_cb(self, shell, activity):
|
|
|
|
if activity != self:
|
|
|
|
self.chat_hide()
|
2006-09-28 22:12:07 +02:00
|
|
|
self._frame_was_visible = False
|
2006-09-28 21:52:56 +02:00
|
|
|
|
|
|
|
def _activity_closed_cb(self, shell, activity):
|
|
|
|
if activity == self:
|
|
|
|
self.chat_hide()
|
2006-09-28 22:12:07 +02:00
|
|
|
self._frame_was_visible = False
|
2006-09-28 21:52:56 +02:00
|
|
|
|