sugar-toolkit-gtk3/activities/web/webactivity.py

140 lines
4.1 KiB
Python
Raw Normal View History

2006-10-15 01:12:48 +02:00
# Copyright (C) 2006, Red Hat, Inc.
#
# 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
from gettext import gettext as _
import gtk
import gtkmozembed
import logging
import dbus
2006-10-17 14:51:20 +02:00
import _sugar
from sugar.activity import ActivityFactory
2006-10-13 10:22:01 +02:00
from sugar.activity.Activity import Activity
from sugar import env
2006-10-13 18:05:48 +02:00
from sugar.graphics import style
import web.stylesheet
2006-10-13 10:22:01 +02:00
from webbrowser import WebBrowser
from toolbar import Toolbar
from linksmodel import LinksModel
from linksview import LinksView
from linkscontroller import LinksController
2006-10-13 10:22:01 +02:00
_HOMEPAGE = 'http://www.google.com'
class WebActivity(Activity):
2006-10-24 15:46:10 +02:00
def __init__(self, browser=None):
2006-10-13 10:22:01 +02:00
Activity.__init__(self)
logging.debug('Starting the web activity')
self.set_title(_('Web Activity'))
vbox = gtk.VBox()
2006-10-24 15:46:10 +02:00
if browser:
self._browser = browser
else:
self._browser = WebBrowser()
self._browser.connect('notify::title', self._title_changed_cb)
2006-10-13 18:05:48 +02:00
self._links_model = LinksModel()
2006-10-13 19:04:04 +02:00
links_view = LinksView(self._links_model, self._browser)
self._toolbar = Toolbar(self._browser)
vbox.pack_start(self._toolbar, False)
self._toolbar.show()
hbox = gtk.HBox()
hbox.pack_start(links_view, False)
hbox.pack_start(self._browser)
2006-10-13 10:22:01 +02:00
self._browser.show()
vbox.pack_start(hbox)
hbox.show()
self.add(vbox)
vbox.show()
2006-10-13 10:22:01 +02:00
self._browser.load_url(_HOMEPAGE)
2006-10-13 18:05:48 +02:00
def _setup_links_controller(self):
links_controller = LinksController(self._service, self._links_model)
self._toolbar.set_links_controller(links_controller)
def join(self, activity_ps):
Activity.join(self, activity_ps)
2006-10-13 18:05:48 +02:00
self._setup_links_controller()
url = self._service.get_published_value('URL')
if url:
self._browser.load_url(url)
def share(self):
Activity.share(self)
2006-10-13 18:05:48 +02:00
self._setup_links_controller()
url = self._browser.get_location()
if url:
self._service.set_published_value('URL', url)
def _title_changed_cb(self, embed, pspec):
self.set_title(embed.props.title)
def start():
gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko')
2006-10-17 14:51:20 +02:00
gtkmozembed.push_startup()
if not _sugar.startup_browser():
raise "Error when initializising the web activity."
2006-10-17 14:51:20 +02:00
2006-10-13 18:05:48 +02:00
style.load_stylesheet(web.stylesheet)
chandler = _sugar.get_browser_chandler()
chandler.connect('download-started', download_started_cb)
chandler.connect('download-completed', download_completed_cb)
chandler.connect('download-cancelled', download_started_cb)
chandler.connect('download-progress', download_progress_cb)
2006-10-17 14:51:20 +02:00
def stop():
gtkmozembed.pop_startup()
def download_started_cb(chandler, url, mimeType, tmpFileName):
bus = dbus.SessionBus()
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
iface.add_object(mimeType, tmpFileName)
def download_completed_cb(chandler, tmpFileName):
bus = dbus.SessionBus()
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
iface.update_object_state(tmpFileName, 100)
def download_cancelled_cb(chandler, tmpFileName):
bus = dbus.SessionBus()
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
iface.delete_object(tmpFileName, 100)
def download_progress_cb(chandler, tmpFileName, progress):
bus = dbus.SessionBus()
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
iface.update_object_state(tmpFileName, progress)