Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriel Calzada <ariel@acivitycentral.com>2012-12-24 09:25:30 (GMT)
committer Ariel Calzada <ariel@acivitycentral.com>2012-12-24 09:25:30 (GMT)
commitef80e912c62faebc53ee1fb8abb97eba96c29213 (patch)
tree22c083ebae94c48ca768a39c082db90e0efe9763
parent83cbf1b147a75dfc057639c671443f11b436671b (diff)
Added custom/go homepage feature
-rw-r--r--activity/activity.info2
-rw-r--r--browser.py25
-rw-r--r--data/homepage.conf1
-rw-r--r--hometoolbar.py45
-rw-r--r--icons/browse-change-homepage.svg11
-rw-r--r--icons/browse-go-homepage.svg11
-rw-r--r--webactivity.py13
-rw-r--r--webtoolbar.py14
8 files changed, 106 insertions, 16 deletions
diff --git a/activity/activity.info b/activity/activity.info
index 293c2ea..ff73a47 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,6 +1,6 @@
[Activity]
name = Browse
-activity_version = 149
+activity_version = 149.3
bundle_id = org.laptop.WebActivity
icon = activity-web
exec = sugar-activity webactivity.WebActivity -s
diff --git a/browser.py b/browser.py
index 7419d2d..80936fa 100644
--- a/browser.py
+++ b/browser.py
@@ -342,12 +342,37 @@ class TabbedView(BrowserNotebook):
if os.path.isfile(_LIBRARY_PATH):
browser.load_uri('file://' + _LIBRARY_PATH)
+
+ elif os.path.isfile(activity.get_bundle_path() + "/data/homepage.conf"):
+ confFile = os.path.join(activity.get_bundle_path(),"data/homepage.conf")
+ f = open(confFile,"r")
+ contents = f.read().strip()
+ f.close()
+
+ if contents != "":
+ default_page = contents
+ else:
+ default_page = os.path.join(activity.get_bundle_path(),"data/index.html")
+
+ browser.load_uri(default_page)
else:
default_page = os.path.join(activity.get_bundle_path(),
"data/index.html")
browser.load_uri('file://' + default_page)
+
browser.grab_focus()
+ def change_homepage(self):
+ """ Change data/homepage.conf with current URL
+ """
+ confFile = os.path.join(activity.get_bundle_path(),"data/homepage.conf")
+ index = self.get_current_page()
+ ui_uri = self.get_nth_page(index).browser.get_uri()
+
+ f = open ( confFile,"w")
+ f.write(ui_uri)
+ f.close()
+
def _get_current_browser(self):
if self.get_n_pages():
return self.get_nth_page(self.get_current_page()).browser
diff --git a/data/homepage.conf b/data/homepage.conf
new file mode 100644
index 0000000..f693ef6
--- /dev/null
+++ b/data/homepage.conf
@@ -0,0 +1 @@
+http://www.google.com.co/ \ No newline at end of file
diff --git a/hometoolbar.py b/hometoolbar.py
new file mode 100644
index 0000000..3d5e6a6
--- /dev/null
+++ b/hometoolbar.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2007, One Laptop Per Child
+# Copyright (C) 2012, Ariel Calzada
+#
+# 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 _
+from gi.repository import Gtk
+from sugar3.graphics.toolbutton import ToolButton
+
+class HomeToolbar(Gtk.Toolbar):
+ def __init__(self, activity):
+ Gtk.Toolbar.__init__(self)
+
+ self._activity = activity
+
+ self.gohome = ToolButton('browse-go-homepage')
+ self.gohome.set_tooltip(_('Go to home page'))
+ self.gohome.connect('clicked', self.__gohome_clicked_cb)
+ self.insert(self.gohome, -1)
+ self.gohome.show()
+
+ self.changehome = ToolButton('browse-change-homepage')
+ self.changehome.set_tooltip(_('Set current page as home page'))
+ self.changehome.connect('clicked', self.__changehome_clicked_cb)
+ self.insert(self.changehome, -1)
+ self.changehome.show()
+
+ def __changehome_clicked_cb(self, button):
+ self._activity._change_home_button_cb(button)
+
+ def __gohome_clicked_cb(self, button):
+ self._activity._go_home_button_cb(button)
+
diff --git a/icons/browse-change-homepage.svg b/icons/browse-change-homepage.svg
new file mode 100644
index 0000000..c79c6d9
--- /dev/null
+++ b/icons/browse-change-homepage.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY fill_color "#FF0000">
+ <!ENTITY stroke_color "#010101">
+]>
+<svg xmlns="http://www.w3.org/2000/svg" width="55" height="55">
+ <g id="go-home">
+ <path d="M 27.5 15.96256 L 8.48131 32.4005 L 8.55256 48.0374 L 17 48.0052 L 17 30.9243 L 26 30.9243 L 26 48.0052 L 47.59 48.0052 L 47.4221 32.2792 Z M 31.5 30.9243 l 8 0 l 0 8 l -8 0 Z" stroke="none" fill="&fill_color;" stroke-linecap="round" stroke-width="3.5" />
+ <path d="M 5.48131 27.4005 L 27.5 8.96256 L 38.8997 18.0775 L 38.8637 9.26122 L 42.8936 9.27163 L 42.8832 21.3246 L 50.4221 27.2792" stroke="&fill_color;" fill="none" stroke-linecap="round" stroke-width="4.5" />
+ </g>
+</svg>
diff --git a/icons/browse-go-homepage.svg b/icons/browse-go-homepage.svg
new file mode 100644
index 0000000..a4fd762
--- /dev/null
+++ b/icons/browse-go-homepage.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY fill_color "#00cb00">
+ <!ENTITY stroke_color "#010101">
+]>
+<svg xmlns="http://www.w3.org/2000/svg" width="55" height="55">
+ <g id="go-home">
+ <path d="M 27.5 15.96256 L 8.48131 32.4005 L 8.55256 48.0374 L 17 48.0052 L 17 30.9243 L 26 30.9243 L 26 48.0052 L 47.59 48.0052 L 47.4221 32.2792 Z M 31.5 30.9243 l 8 0 l 0 8 l -8 0 Z" stroke="none" fill="&fill_color;" stroke-linecap="round" stroke-width="3.5" />
+ <path d="M 5.48131 27.4005 L 27.5 8.96256 L 38.8997 18.0775 L 38.8637 9.26122 L 42.8936 9.27163 L 42.8832 21.3246 L 50.4221 27.2792" stroke="&fill_color;" fill="none" stroke-linecap="round" stroke-width="4.5" />
+ </g>
+</svg>
diff --git a/webactivity.py b/webactivity.py
index 3c0d337..0bbd9da 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -132,6 +132,7 @@ from browser import ZOOM_ORIGINAL
from webtoolbar import PrimaryToolbar
from edittoolbar import EditToolbar
from viewtoolbar import ViewToolbar
+from hometoolbar import HomeToolbar
import downloadmanager
# TODO: make the registration clearer SL #3087
@@ -182,11 +183,10 @@ class WebActivity(activity.Activity):
self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self)
self._edit_toolbar = EditToolbar(self)
self._view_toolbar = ViewToolbar(self)
+ self._home_toolbar = HomeToolbar(self)
self._primary_toolbar.connect('add-link', self._link_add_button_cb)
- self._primary_toolbar.connect('go-home', self._go_home_button_cb)
-
self._edit_toolbar_button = ToolbarButton(
page=self._edit_toolbar,
icon_name='toolbar-edit')
@@ -200,6 +200,12 @@ class WebActivity(activity.Activity):
self._primary_toolbar.toolbar.insert(
view_toolbar_button, 2)
+ home_toolbar_button = ToolbarButton(
+ page=self._home_toolbar,
+ icon_name='go-home')
+ self._primary_toolbar.toolbar.insert(
+ home_toolbar_button, 3)
+
self._primary_toolbar.show_all()
self.set_toolbar_box(self._primary_toolbar)
@@ -470,6 +476,9 @@ class WebActivity(activity.Activity):
def _go_home_button_cb(self, button):
self._tabbed_view.load_homepage()
+ def _change_home_button_cb(self, button):
+ self._tabbed_view.change_homepage()
+
def _key_press_cb(self, widget, event):
key_name = Gdk.keyval_name(event.keyval)
browser = self._tabbed_view.props.current_browser
diff --git a/webtoolbar.py b/webtoolbar.py
index dc0b3de..35a699a 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -252,9 +252,6 @@ class PrimaryToolbar(ToolbarBase):
'add-link': (GObject.SignalFlags.RUN_FIRST,
None,
([])),
- 'go-home': (GObject.SignalFlags.RUN_FIRST,
- None,
- ([])),
}
def __init__(self, tabbed_view, act):
@@ -270,12 +267,6 @@ class PrimaryToolbar(ToolbarBase):
activity_button = ActivityToolbarButton(self._activity)
toolbar.insert(activity_button, 0)
- self._go_home = ToolButton('go-home')
- self._go_home.set_tooltip(_('Home page'))
- self._go_home.connect('clicked', self._go_home_cb)
- toolbar.insert(self._go_home, -1)
- self._go_home.show()
-
self.entry = WebEntry()
self.entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY,
'browse-dialog-cancel')
@@ -451,7 +442,7 @@ class PrimaryToolbar(ToolbarBase):
is_webkit_browser = isinstance(self._browser, Browser)
self._link_add.props.sensitive = is_webkit_browser
- self._go_home.props.sensitive = is_webkit_browser
+ #self._go_home.props.sensitive = is_webkit_browser
if is_webkit_browser:
self._reload_session_history()
@@ -463,9 +454,6 @@ class PrimaryToolbar(ToolbarBase):
self.entry.props.address = effective_url
self._browser.grab_focus()
- def _go_home_cb(self, button):
- self.emit('go-home')
-
def _go_back_cb(self, button):
self._browser.go_back()