From 3ede4103a308e2f4b771c4848529268831c6d215 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 26 Apr 2007 22:56:33 +0000 Subject: Remove the not working links stuff. More API fixes. --- diff --git a/addressentry.py b/addressentry.py deleted file mode 100644 index ce9f81a..0000000 --- a/addressentry.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2007, One Laptop Per Child -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. -import gobject - -import sugar.browser -from sugar.graphics.entry import Entry - -class AddressEntry(Entry): - __gtype_name__ = 'WebAddressEntry' - - __gproperties__ = { - 'title' : (str, None, None, None, gobject.PARAM_READWRITE), - 'address' : (str, None, None, None, gobject.PARAM_READWRITE), - 'progress' : (float, None, None, 0.0, 1.0, 0.0, gobject.PARAM_READWRITE) - } - - def __init__(self, **kwargs): - Entry.__init__(self, **kwargs) - - def create_entry(self): - self._address_entry = sugar.browser.AddressEntry() - return self._address_entry diff --git a/linkscontroller.py b/linkscontroller.py deleted file mode 100755 index 1004fc6..0000000 --- a/linkscontroller.py +++ /dev/null @@ -1,60 +0,0 @@ -# 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 sugar.p2p.Stream import Stream -from sugar.presence import PresenceService - -class _Marshaller(object): - def __init__(self, title, address): - pservice = PresenceService.get_instance() - name = pservice.get_owner().get_name() - self._message = name + '\n' + title + '\n' + address - - def get_message(self): - return self._message - -class _Demarshaller(object): - def __init__(self, message): - self._pservice = PresenceService.get_instance() - self._split_msg = message.split('\n') - - def get_buddy(self): - return self._pservice.get_buddy_by_name(self._split_msg[0]) - - def get_title(self): - return self._split_msg[1] - - def get_address(self): - return self._split_msg[2] - -class LinksController(object): - def __init__(self, service, model): - self._model = model - - self._stream = Stream.new_from_service(service) - self._stream.set_data_listener(self._recv_message) - self._stream_writer = self._stream.new_writer() - - def post_link(self, title, address): - marshaller = _Marshaller(title, address) - self._stream_writer.write(marshaller.get_message()) - - def _recv_message(self, address, msg): - demarshaller = _Demarshaller(msg) - buddy = demarshaller.get_buddy() - if buddy: - self._model.add_link(buddy, demarshaller.get_title(), - demarshaller.get_address()) diff --git a/linksmodel.py b/linksmodel.py deleted file mode 100755 index bca05e4..0000000 --- a/linksmodel.py +++ /dev/null @@ -1,51 +0,0 @@ -# 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 - -import gobject - -class Link(object): - def __init__(self, buddy, title, url): - self.buddy = buddy - self.title = title - self.url = url - -class LinksModel(gobject.GObject): - __gsignals__ = { - 'link-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'link-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - } - - def __init__(self): - gobject.GObject.__init__(self) - self._links = {} - - def add_link(self, buddy, title, url): - link = Link(buddy, title, url) - self._links[(buddy.get_name(), url)] = link - - self.emit('link-added', link) - - def remove_link(self, buddy, url): - key = (buddy.get_name(), url) - if self._links.haskey(key): - link = self._links[key] - del self._links[key] - self.emit('link-removed', link) - - def __iter__(self): - return self._links.values().__iter__() diff --git a/linksview.py b/linksview.py deleted file mode 100755 index 1ad5584..0000000 --- a/linksview.py +++ /dev/null @@ -1,77 +0,0 @@ -# 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 -import os - -import hippo - -from sugar.activity import activity -from sugar.graphics.toolbar import Toolbar -from sugar.graphics.menu import Menu -from sugar.graphics.canvasicon import CanvasIcon -from sugar.graphics.popupcontext import PopupContext -from sugar.graphics.xocolor import XoColor - -class LinkIcon(CanvasIcon): - def __init__(self, link): - color = XoColor(link.buddy.get_color()) - - path = os.path.join(activity.get_bundle_path(), 'activity') - icon_name = os.path.join(path, 'activity-web.svg') - CanvasIcon.__init__(self, xo_color=color, icon_name=icon_name) - - self._link = link - - def get_popup(self): - menu = Menu(self._link.title) - return menu - -class LinksView(Toolbar): - def __init__(self, model, browser, **kwargs): - Toolbar.__init__(self, orientation=hippo.ORIENTATION_VERTICAL) - - self._icons = {} - self._browser = browser - - for link in model: - self._add_link(link) - - model.connect('link_added', self._link_added_cb) - model.connect('link_removed', self._link_removed_cb) - - def _add_link(self, link): - icon = LinkIcon(link) - icon.connect('activated', self._link_activated_cb, link) - self.append(icon) - - self._icons[link] = icon - - def _remove_link(self, link): - icon = self._icons[link] - self.remove(icon) - - del self._icons[link] - - def _link_added_cb(self, model, link): - self._add_link(link) - - def _link_removed_cb(self, model, link): - self._remove_link(link) - - def _link_activated_cb(self, link_item, link): - self._browser.load_url(link.url) - - def get_link_count(self): - return len(self._icons) diff --git a/webactivity.py b/webactivity.py index 866cee9..774b93d 100755 --- a/webactivity.py +++ b/webactivity.py @@ -14,11 +14,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -import hippo import logging -import dbus from gettext import gettext as _ +import gtk +import dbus + import sugar.browser from sugar.activity import activity from sugar.clipboard import clipboardservice @@ -26,9 +27,6 @@ from sugar import env from webview import WebView from webtoolbar import WebToolbar -from linksmodel import LinksModel -from linksview import LinksView -#from linkscontroller import LinksController _HOMEPAGE = 'file:///home/olpc/Library/index.html' @@ -47,26 +45,15 @@ class WebActivity(activity.Activity): self._browser.connect('notify::title', self._title_changed_cb) self._toolbar = WebToolbar(self._browser) - self.toolbox.add_toolbar(self._toolbar) + self.toolbox.add_toolbar(_('Browse'), self._toolbar) self._toolbar.show() self._hbox = gtk.HBox() - self._links_model = LinksModel() - self._links_view = LinksView(self._links_model, self._browser) - self._hbox.pack_start(self._links_view, False) - - self._links_model.connect('link_added', self._link_added_cb) - self._links_model.connect('link_removed', self._link_removed_cb) - self.set_canvas(self._hbox) self._hbox.show() - self._service = handle.get_presence_service() - if self._service: - self._setup_links_controller() - url = self._service.get_published_value('URL') - elif handle.uri: + if handle.uri: url = handle.uri else: url = _HOMEPAGE @@ -74,27 +61,6 @@ class WebActivity(activity.Activity): if url: self._browser.load_url(url) - def _link_added_cb(self, model, link): - if self._links_view.get_link_count() > 0: - self._hbox.set_child_visible(self._links_view, True) - - def _link_removed_cb(self, model, link): - if self._links_view.get_link_count() == 0: - self._hbox.set_child_visible(self._links_view, False) - - def _setup_links_controller(self): - links_controller = LinksController(self._service, self._links_model) - self._toolbar.set_links_controller(links_controller) - - def share(self): - activity.Activity.share(self) - - 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) diff --git a/webtoolbar.py b/webtoolbar.py index 02af101..fcb8b27 100755 --- a/webtoolbar.py +++ b/webtoolbar.py @@ -22,7 +22,7 @@ import gtk from sugar.graphics.toolbutton import ToolButton from sugar.graphics.filechooser import FileChooserDialog -from addressentry import AddressEntry +from sugar.browser import AddressEntry class WebToolbar(gtk.Toolbar): def __init__(self, embed): @@ -43,8 +43,13 @@ class WebToolbar(gtk.Toolbar): self.insert(self._stop_and_reload, -1) self._entry = AddressEntry() - self._entry.connect('activated', self._entry_activate_cb) - self.append(self._entry, hippo.PACK_EXPAND) + self._entry.connect('activate', self._entry_activate_cb) + + entry_item = gtk.ToolItem() + entry_item.add(self._entry) + self._entry.show() + + self.insert(entry_item, -1) self._open = ToolButton('stock-open') self._open.connect('clicked', self._open_cb) @@ -52,7 +57,7 @@ class WebToolbar(gtk.Toolbar): self._save = ToolButton('stock-save') self._save.connect('clicked', self._save_cb) - self.append(self._save) + self.insert(self._save, -1) self._embed = embed embed.connect("notify::progress", self._progress_changed_cb) @@ -65,17 +70,11 @@ class WebToolbar(gtk.Toolbar): self._update_stop_and_reload_icon() - def set_links_controller(self, links_controller): - self._links_controller = links_controller - #self._post.props.active = True - def _update_stop_and_reload_icon(self): if self._embed.props.loading: - self._stop_and_reload.props.icon_name = 'theme:stock-close' - self._stop_and_reload.props.tooltip = _('Stop') + self._stop_and_reload.set_icon_name('stock-close') else: - self._stop_and_reload.props.icon_name = 'theme:stock-continue' - self._stop_and_reload.props.tooltip = _('Reload') + self._stop_and_reload.set_icon_name('stock-continue') def _progress_changed_cb(self, embed, spec): self._entry.props.progress = embed.props.progress @@ -111,11 +110,6 @@ class WebToolbar(gtk.Toolbar): else: self._embed.reload(0) - def _post_cb(self, button): - title = self._embed.get_title() - address = self._embed.get_location() - self._links_controller.post_link(title, address) - def _save_cb(self, button): filename = self._embed.props.document_metadata.filename if not filename: -- cgit v0.9.1