Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2013-06-13 18:51:28 (GMT)
committer Manuel QuiƱones <manuq@laptop.org>2013-06-28 00:54:42 (GMT)
commit9b1a12229202860fb291c50b4181e3897c4fc47d (patch)
treef4c870129fe99be62b3d3328e739f50e2c73cc16 /browser.py
parent110e6f4f9d3f08336cfadfd4dc9f3858227d7a65 (diff)
Add a option to set the home page
This feature was requested by AU. A menu in the home button is added, with options to set the home page, reset the home page, and go to the Library. The items in the menu are shown or hidden as needed. The configuration is stored using GConf Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'browser.py')
-rw-r--r--browser.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/browser.py b/browser.py
index dd23999..b03b0e3 100644
--- a/browser.py
+++ b/browser.py
@@ -27,6 +27,7 @@ from gi.repository import Gdk
from gi.repository import Pango
from gi.repository import WebKit
from gi.repository import Soup
+from gi.repository import GConf
from sugar3 import env
from sugar3.activity import activity
@@ -42,7 +43,7 @@ from pdfviewer import PDFTabPage
ZOOM_ORIGINAL = 1.0
_ZOOM_AMOUNT = 0.1
-_LIBRARY_PATH = '/usr/share/library-common/index.html'
+LIBRARY_PATH = '/usr/share/library-common/index.html'
_WEB_SCHEMES = ['http', 'https', 'ftp', 'file', 'javascript', 'data',
'about', 'gopher', 'mailto']
@@ -62,6 +63,8 @@ _NON_SEARCH_REGEX = re.compile('''
DEFAULT_ERROR_PAGE = os.path.join(activity.get_bundle_path(),
'data/error_page.tmpl')
+HOME_PAGE_GCONF_KEY = '/desktop/sugar/browser/home_page'
+
class CommandListener(object):
def __init__(self, window):
@@ -342,17 +345,31 @@ class TabbedView(BrowserNotebook):
else:
first_label.show_close_button()
- def load_homepage(self):
+ def load_homepage(self, ignore_gconf=False):
browser = self.current_browser
-
- if os.path.isfile(_LIBRARY_PATH):
- browser.load_uri('file://' + _LIBRARY_PATH)
+ uri_homepage = None
+ if not ignore_gconf:
+ client = GConf.Client.get_default()
+ uri_homepage = client.get_string(HOME_PAGE_GCONF_KEY)
+ if uri_homepage is not None:
+ browser.load_uri(uri_homepage)
+ elif os.path.isfile(LIBRARY_PATH):
+ browser.load_uri('file://' + LIBRARY_PATH)
else:
default_page = os.path.join(activity.get_bundle_path(),
"data/index.html")
browser.load_uri('file://' + default_page)
browser.grab_focus()
+ def set_homepage(self):
+ uri = self.current_browser.get_uri()
+ client = GConf.Client.get_default()
+ client.set_string(HOME_PAGE_GCONF_KEY, uri)
+
+ def reset_homepage(self):
+ client = GConf.Client.get_default()
+ client.unset(HOME_PAGE_GCONF_KEY)
+
def _get_current_browser(self):
if self.get_n_pages():
return self.get_nth_page(self.get_current_page()).browser