2007-06-24 14:45:05 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2006-10-15 01:24:45 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-07-20 11:34:06 +02:00
|
|
|
import gtk
|
|
|
|
import dbus
|
2007-08-31 12:43:10 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from sugar.presence import presenceservice
|
2006-07-20 11:34:06 +02:00
|
|
|
|
2006-09-29 19:35:48 +02:00
|
|
|
import OverlayWindow
|
2006-09-28 21:52:56 +02:00
|
|
|
|
|
|
|
class ActivityChatWindow(gtk.Window):
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self, gdk_window, chat_widget):
|
|
|
|
gtk.Window.__init__(self)
|
2006-09-28 21:52:56 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self.realize()
|
|
|
|
self.set_decorated(False)
|
|
|
|
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
|
|
|
self.window.set_accept_focus(True)
|
|
|
|
self.window.set_transient_for(gdk_window)
|
|
|
|
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
|
|
|
|
self.set_default_size(600, 450)
|
2006-09-28 21:52:56 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self.add(chat_widget)
|
2006-07-20 11:34:06 +02:00
|
|
|
|
|
|
|
class ActivityHost:
|
2006-12-24 14:35:02 +01:00
|
|
|
def __init__(self, model):
|
|
|
|
self._model = model
|
|
|
|
self._window = model.get_window()
|
|
|
|
self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid())
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
self._overlay_window = OverlayWindow.OverlayWindow(self._gdk_window)
|
|
|
|
win = self._overlay_window.window
|
|
|
|
except RuntimeError:
|
|
|
|
self._overlay_window = None
|
|
|
|
win = self._gdk_window
|
|
|
|
|
2007-03-28 11:40:22 +02:00
|
|
|
#self._chat_widget = ActivityChat.ActivityChat(self)
|
2007-03-28 12:17:34 +02:00
|
|
|
self._chat_widget = gtk.HBox()
|
|
|
|
self._chat_window = ActivityChatWindow(win, self._chat_widget)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
self._frame_was_visible = False
|
|
|
|
|
|
|
|
def get_id(self):
|
2007-04-08 19:20:59 +02:00
|
|
|
return self._model.get_activity_id()
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def get_xid(self):
|
2006-12-24 14:35:02 +01:00
|
|
|
return self._window.get_xid()
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2006-12-24 14:35:02 +01:00
|
|
|
def get_model(self):
|
|
|
|
return self._model
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-09-11 17:53:27 +02:00
|
|
|
def invite(self, buddy_model):
|
|
|
|
service = self._model.get_service()
|
|
|
|
if service:
|
|
|
|
buddy = buddy_model.get_buddy()
|
|
|
|
service.Invite(buddy.props.key)
|
|
|
|
else:
|
|
|
|
logging.error('Invite failed, activity service not ')
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-10-23 15:19:17 +02:00
|
|
|
def toggle_fullscreen(self):
|
|
|
|
fullscreen = not self._window.is_fullscreen()
|
|
|
|
self._window.set_fullscreen(fullscreen)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def present(self):
|
2007-08-06 15:23:45 +02:00
|
|
|
# wnck.Window.activate() expects a timestamp, but we don't
|
|
|
|
# always have one, and libwnck will complain if we pass "0",
|
|
|
|
# and matchbox doesn't look at the timestamp anyway. So we
|
|
|
|
# just always pass "1".
|
|
|
|
self._window.activate(1)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def close(self):
|
2007-08-06 15:23:45 +02:00
|
|
|
# The "1" is a fake timestamp as with present()
|
|
|
|
self._window.close(1)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def show_dialog(self, dialog):
|
|
|
|
dialog.show()
|
|
|
|
dialog.window.set_transient_for(self._gdk_window)
|
|
|
|
|
|
|
|
def chat_show(self, frame_was_visible):
|
|
|
|
if self._overlay_window:
|
2007-01-31 17:31:52 +01:00
|
|
|
self._overlay_window.appear()
|
2006-12-04 20:12:24 +01:00
|
|
|
self._chat_window.show_all()
|
|
|
|
self._frame_was_visible = frame_was_visible
|
|
|
|
|
|
|
|
def chat_hide(self):
|
|
|
|
self._chat_window.hide()
|
|
|
|
if self._overlay_window:
|
2007-01-31 17:31:52 +01:00
|
|
|
self._overlay_window.disappear()
|
2006-12-04 20:12:24 +01:00
|
|
|
wasvis = self._frame_was_visible
|
|
|
|
self._frame_was_visible = False
|
|
|
|
return wasvis
|
|
|
|
|
|
|
|
def is_chat_visible(self):
|
|
|
|
return self._chat_window.get_property('visible')
|
|
|
|
|
|
|
|
def set_active(self, active):
|
|
|
|
if not active:
|
|
|
|
self.chat_hide()
|
|
|
|
self._frame_was_visible = False
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
self._chat_window.destroy()
|
|
|
|
self._frame_was_visible = False
|