[Sugar-devel] [PATCH] Patch that let users set current page as homepage
Ariel Calzada
ariel at activitycentral.com
Mon Jan 23 19:41:25 EST 2012
---
This patch has been requested by teachers. They want to set school homepage as the browse's homepage
browser.py | 21 +++++++++++++++++++--
webactivity.py | 14 ++++++++++++--
webtoolbar.py | 12 ------------
3 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/browser.py b/browser.py
index e1d8990..24553f5 100644
--- a/browser.py
+++ b/browser.py
@@ -277,11 +277,28 @@ class TabbedView(BrowserNotebook):
if os.path.isfile(_LIBRARY_PATH):
browser.load_uri('file://' + _LIBRARY_PATH)
+ elif os.path.isfile(activity.get_bundle_path() + "/homepage.conf"):
+ f = open(activity.get_bundle_path() + "/homepage.conf","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")
+ default_page = os.path.join(activity.get_bundle_path(),"data/index.html")
browser.load_uri(default_page)
+ def change_homepage(self):
+ browser = self.current_browser
+ ui_uri = browser.get_url_from_nsiuri(browser.progress.location)
+ f = open ( activity.get_bundle_path() + "/homepage.conf","w")
+ f.write(ui_uri)
+ f.close()
+
def _get_current_browser(self):
return self.get_nth_page(self.get_current_page())
diff --git a/webactivity.py b/webactivity.py
index eefb169..0a65cb0 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -174,6 +174,8 @@ from browser import TabbedView
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
@@ -237,11 +239,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)
-
if NEW_TOOLBARS:
logging.debug('Using new toolbars')
@@ -257,6 +258,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)
else:
@@ -508,6 +515,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 = gtk.gdk.keyval_name(event.keyval)
browser = self._tabbed_view.props.current_browser
diff --git a/webtoolbar.py b/webtoolbar.py
index a4623be..bae4636 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -228,9 +228,6 @@ class PrimaryToolbar(ToolbarBase):
'add-link': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([])),
- 'go-home': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ([])),
}
def __init__(self, tabbed_view, act):
@@ -249,12 +246,6 @@ class PrimaryToolbar(ToolbarBase):
else:
toolbar = self
- 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')
@@ -406,9 +397,6 @@ class PrimaryToolbar(ToolbarBase):
browser.load_uri(entry.props.text)
browser.grab_focus()
- def _go_home_cb(self, button):
- self.emit('go-home')
-
def _go_back_cb(self, button):
browser = self._tabbed_view.props.current_browser
browser.web_navigation.goBack()
--
1.7.5.4
More information about the Sugar-devel
mailing list