2006-08-25 20:12:52 +02:00
|
|
|
import os
|
2006-09-28 19:35:12 +02:00
|
|
|
import logging
|
2006-08-25 20:12:52 +02:00
|
|
|
|
2006-06-01 00:01:24 +02:00
|
|
|
import gtk
|
2006-09-21 01:27:47 +02:00
|
|
|
import gtkmozembed
|
2006-09-27 14:45:55 +02:00
|
|
|
import gobject
|
2006-06-01 00:01:24 +02:00
|
|
|
|
2006-06-21 22:05:52 +02:00
|
|
|
from sugar.activity.Activity import Activity
|
2006-06-15 23:05:44 +02:00
|
|
|
from sugar.presence.PresenceService import PresenceService
|
2006-06-16 19:21:28 +02:00
|
|
|
from sugar.p2p.model.LocalModel import LocalModel
|
2006-06-16 20:20:09 +02:00
|
|
|
from sugar.p2p.model.RemoteModel import RemoteModel
|
2006-09-26 21:58:54 +02:00
|
|
|
import gecko
|
2006-06-01 00:01:24 +02:00
|
|
|
|
2006-06-21 20:23:18 +02:00
|
|
|
from NotificationBar import NotificationBar
|
|
|
|
from NavigationToolbar import NavigationToolbar
|
2006-08-25 20:12:52 +02:00
|
|
|
from sugar import env
|
2006-06-21 20:23:18 +02:00
|
|
|
|
2006-09-27 15:30:56 +02:00
|
|
|
class PopupCreator(gobject.GObject):
|
|
|
|
__gsignals__ = {
|
|
|
|
'popup-created': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([])),
|
|
|
|
}
|
|
|
|
|
2006-09-27 17:27:08 +02:00
|
|
|
def __init__(self, parent_window):
|
2006-09-27 15:30:56 +02:00
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
2006-09-28 19:35:12 +02:00
|
|
|
logging.debug('Creating the popup widget')
|
|
|
|
|
2006-09-27 15:30:56 +02:00
|
|
|
self._sized_popup = False
|
2006-09-27 17:27:08 +02:00
|
|
|
self._parent_window = parent_window
|
2006-09-27 15:30:56 +02:00
|
|
|
|
|
|
|
self._dialog = gtk.Window()
|
|
|
|
self._dialog.set_resizable(True)
|
|
|
|
|
|
|
|
self._dialog.realize()
|
|
|
|
self._dialog.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
|
|
|
|
|
|
|
self._embed = Browser()
|
|
|
|
self._size_to_sid = self._embed.connect('size_to', self._size_to_cb)
|
|
|
|
self._vis_sid = self._embed.connect('visibility', self._visibility_cb)
|
|
|
|
|
|
|
|
self._dialog.add(self._embed)
|
|
|
|
|
|
|
|
def _size_to_cb(self, embed, width, height):
|
2006-09-28 19:35:12 +02:00
|
|
|
logging.debug('Resize the popup to %d %d' % (width, height))
|
2006-09-27 15:30:56 +02:00
|
|
|
self._sized_popup = True
|
|
|
|
self._dialog.resize(width, height)
|
|
|
|
|
|
|
|
def _visibility_cb(self, embed, visible):
|
|
|
|
if visible:
|
|
|
|
if self._sized_popup:
|
2006-09-28 19:35:12 +02:00
|
|
|
logging.debug('Show the popup')
|
2006-09-27 15:30:56 +02:00
|
|
|
self._embed.show()
|
2006-09-27 17:27:08 +02:00
|
|
|
self._dialog.set_transient_for(self._parent_window)
|
2006-09-27 15:30:56 +02:00
|
|
|
self._dialog.show()
|
|
|
|
else:
|
2006-09-28 19:35:12 +02:00
|
|
|
logging.debug('Open a new activity for the popup')
|
2006-09-27 15:30:56 +02:00
|
|
|
self._dialog.remove(self._embed)
|
|
|
|
|
|
|
|
activity = BrowserActivity(self._embed)
|
|
|
|
activity.set_type('com.redhat.Sugar.BrowserActivity')
|
|
|
|
|
|
|
|
self._embed.disconnect(self._size_to_sid)
|
|
|
|
self._embed.disconnect(self._vis_sid)
|
|
|
|
|
|
|
|
self.emit('popup-created')
|
|
|
|
|
|
|
|
def get_embed(self):
|
|
|
|
return self._embed
|
|
|
|
|
2006-09-27 14:45:55 +02:00
|
|
|
class Browser(gecko.Browser):
|
|
|
|
__gtype_name__ = "SugarBrowser"
|
|
|
|
def __init__(self):
|
|
|
|
gecko.Browser.__init__(self)
|
2006-09-27 15:30:56 +02:00
|
|
|
self._popup_creators = []
|
2006-09-27 14:45:55 +02:00
|
|
|
|
|
|
|
def do_create_window(self):
|
2006-09-27 17:27:08 +02:00
|
|
|
popup_creator = PopupCreator(self.get_toplevel())
|
2006-09-27 15:30:56 +02:00
|
|
|
popup_creator.connect('popup-created', self._popup_created_cb)
|
|
|
|
|
|
|
|
self._popup_creators.append(popup_creator)
|
|
|
|
|
|
|
|
return popup_creator.get_embed()
|
|
|
|
|
|
|
|
def _popup_created_cb(self, creator):
|
|
|
|
self._popup_creators.remove(creator)
|
2006-09-27 14:45:55 +02:00
|
|
|
|
2006-06-21 22:05:52 +02:00
|
|
|
class BrowserActivity(Activity):
|
2006-09-27 15:30:56 +02:00
|
|
|
def __init__(self, embed=None):
|
2006-08-09 01:08:19 +02:00
|
|
|
Activity.__init__(self)
|
2006-07-06 15:59:48 +02:00
|
|
|
|
2006-09-27 15:30:56 +02:00
|
|
|
self._embed = embed
|
2006-06-15 23:05:44 +02:00
|
|
|
self._share_service = None
|
2006-06-17 06:33:08 +02:00
|
|
|
self._model_service = None
|
|
|
|
self._notif_service = None
|
2006-06-15 23:05:44 +02:00
|
|
|
self._model = None
|
2006-07-09 17:37:54 +02:00
|
|
|
|
|
|
|
self.set_title("Web Page")
|
2006-09-12 13:21:18 +02:00
|
|
|
self.connect('destroy', self._destroy_cb)
|
2006-07-09 17:37:54 +02:00
|
|
|
|
|
|
|
vbox = gtk.VBox()
|
|
|
|
|
2006-09-21 16:09:23 +02:00
|
|
|
nav_toolbar = NavigationToolbar()
|
|
|
|
vbox.pack_start(nav_toolbar, False)
|
|
|
|
nav_toolbar.show()
|
|
|
|
|
2006-07-09 17:37:54 +02:00
|
|
|
self._notif_bar = NotificationBar()
|
|
|
|
vbox.pack_start(self._notif_bar, False)
|
|
|
|
self._notif_bar.connect('action', self.__notif_bar_action_cb)
|
|
|
|
|
2006-09-27 15:30:56 +02:00
|
|
|
if not self._embed:
|
|
|
|
self._embed = Browser()
|
2006-08-09 21:09:24 +02:00
|
|
|
self._embed.connect("title", self.__title_cb)
|
|
|
|
vbox.pack_start(self._embed)
|
|
|
|
self._embed.show()
|
|
|
|
|
2006-09-21 16:09:23 +02:00
|
|
|
nav_toolbar.set_embed(self._embed)
|
2006-09-27 15:41:13 +02:00
|
|
|
self._embed.load_url('http://www.google.com')
|
2006-08-09 21:09:24 +02:00
|
|
|
|
2006-07-09 17:37:54 +02:00
|
|
|
self.add(vbox)
|
|
|
|
vbox.show()
|
|
|
|
|
2006-08-09 01:08:19 +02:00
|
|
|
def join(self, activity_ps):
|
|
|
|
Activity.join(self, activity_ps)
|
|
|
|
|
|
|
|
activity_ps.connect('service-appeared', self._service_appeared_cb)
|
2006-07-26 18:00:28 +02:00
|
|
|
|
2006-09-02 10:54:34 +02:00
|
|
|
services = activity_ps.get_services_of_type(self._default_type)
|
2006-08-09 01:08:19 +02:00
|
|
|
if len(services) > 0:
|
|
|
|
self._notif_service = services[0]
|
2006-07-26 18:00:28 +02:00
|
|
|
|
2006-08-09 01:08:19 +02:00
|
|
|
services = activity_ps.get_services_of_type(LocalModel.SERVICE_TYPE)
|
|
|
|
if len(services) > 0:
|
|
|
|
self._model_service = services[0]
|
2006-07-26 18:00:28 +02:00
|
|
|
|
|
|
|
if self._notif_service and self._model_service:
|
|
|
|
self._listen_to_model()
|
2006-06-16 07:43:42 +02:00
|
|
|
|
2006-07-26 02:04:15 +02:00
|
|
|
def _service_appeared_cb(self, pservice, service):
|
2006-07-15 12:31:06 +02:00
|
|
|
if service.get_type() == self._default_type:
|
2006-06-17 06:33:08 +02:00
|
|
|
self._notif_service = service
|
|
|
|
elif service.get_type() == LocalModel.SERVICE_TYPE:
|
2006-08-09 01:08:19 +02:00
|
|
|
self._model_service = service
|
2006-06-17 06:33:08 +02:00
|
|
|
|
2006-06-23 19:13:28 +02:00
|
|
|
if not self._model and self._notif_service and self._model_service:
|
2006-07-26 18:00:28 +02:00
|
|
|
self._listen_to_model()
|
|
|
|
|
|
|
|
def _listen_to_model(self):
|
|
|
|
self._model = RemoteModel(self._model_service, self._notif_service)
|
|
|
|
self._model.add_listener(self.__shared_location_changed_cb)
|
|
|
|
self._go_to_shared_location()
|
2006-06-17 06:33:08 +02:00
|
|
|
|
2006-06-01 00:01:24 +02:00
|
|
|
def _update_shared_location(self):
|
2006-09-21 01:27:47 +02:00
|
|
|
address = self._embed.get_location()
|
2006-06-01 00:01:24 +02:00
|
|
|
self._model.set_value('address', address)
|
2006-08-09 21:09:24 +02:00
|
|
|
title = self._embed.get_title()
|
2006-06-01 00:01:24 +02:00
|
|
|
self._model.set_value('title', title)
|
|
|
|
|
|
|
|
def __notif_bar_action_cb(self, bar, action_id):
|
|
|
|
if action_id == 'set_shared_location':
|
|
|
|
self._update_shared_location()
|
|
|
|
elif action_id == 'goto_shared_location':
|
2006-07-26 18:00:28 +02:00
|
|
|
self._go_to_shared_location()
|
|
|
|
|
|
|
|
def _go_to_shared_location(self):
|
|
|
|
address = self._model.get_value("address")
|
2006-09-21 01:27:47 +02:00
|
|
|
self._embed.load_url(address)
|
2006-07-26 18:00:28 +02:00
|
|
|
self._notif_bar.hide()
|
2006-06-01 00:01:24 +02:00
|
|
|
|
|
|
|
def get_embed(self):
|
2006-08-09 21:09:24 +02:00
|
|
|
return self._embed
|
2006-06-01 00:01:24 +02:00
|
|
|
|
2006-07-26 00:17:05 +02:00
|
|
|
def share(self):
|
2006-08-07 16:42:36 +02:00
|
|
|
Activity.share(self)
|
2006-06-15 23:05:44 +02:00
|
|
|
|
2006-08-07 16:42:36 +02:00
|
|
|
self._model = LocalModel(self, self._pservice, self._service)
|
2006-07-24 17:57:21 +02:00
|
|
|
self._model.set_value('owner', self._pservice.get_owner().get_name())
|
2006-06-16 19:06:11 +02:00
|
|
|
self._update_shared_location()
|
2006-06-16 20:20:09 +02:00
|
|
|
|
2006-08-09 01:08:19 +02:00
|
|
|
self._notif_bar.set_text('Share this page with the group.')
|
|
|
|
self._notif_bar.set_action('set_shared_location', 'Share')
|
|
|
|
self._notif_bar.set_icon('stock_shared-by-me')
|
|
|
|
self._notif_bar.show()
|
2006-06-16 19:06:11 +02:00
|
|
|
|
2006-06-01 00:01:24 +02:00
|
|
|
def __title_cb(self, embed):
|
2006-07-10 13:42:34 +02:00
|
|
|
self.set_title(embed.get_title())
|
2006-06-01 00:01:24 +02:00
|
|
|
|
|
|
|
def __shared_location_changed_cb(self, model, key):
|
|
|
|
self._notify_shared_location_change()
|
|
|
|
|
|
|
|
def _notify_shared_location_change(self):
|
|
|
|
owner = self._model.get_value('owner')
|
|
|
|
title = self._model.get_value('title')
|
|
|
|
|
|
|
|
text = '<b>' + owner + '</b> is reading <i>' + title + '</i>'
|
|
|
|
self._notif_bar.set_text(text)
|
|
|
|
self._notif_bar.set_action('goto_shared_location', 'Go There')
|
|
|
|
self._notif_bar.set_icon('stock_right')
|
|
|
|
self._notif_bar.show()
|
2006-09-12 13:21:18 +02:00
|
|
|
|
|
|
|
def _destroy_cb(self, window):
|
|
|
|
if self._model:
|
|
|
|
self._model.shutdown()
|
2006-09-26 22:12:18 +02:00
|
|
|
|
|
|
|
def start():
|
|
|
|
gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko')
|
|
|
|
gtkmozembed.push_startup()
|
|
|
|
gecko.startup()
|