Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: e0da08e9f58a5fada761659e211125813e534485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright (C) 2007, One Laptop Per Child
#
# 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 os
import sys
import server

OLD_TOOLBAR = False
try:
    from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
except ImportError:
    OLD_TOOLBAR = True

#from sugar.activity import registry
#activity_info = registry.get_registry().get_activity('org.laptop.WebActivity')

#sys.path.append(activity_info.path)
sys.path.append("/home/olpc/Activities/Browse.activity")
import webactivity

from searchtoolbar import SearchToolbar

# Default settings.
WIKIDB = 'es_PE/es_PE.xml.bz2'
HOME_PAGE = '/static/'

# Activity class, extends WebActivity.
class WikipediaActivity(webactivity.WebActivity):
    def __init__(self, handle):
        
        print "Starting server...\n"
        
        os.chdir(os.environ['SUGAR_BUNDLE_PATH'])

        self.HTTP_PORT = '8000'
        server.load_db(WIKIDB)
        server.run_server({ 'path': WIKIDB,
                            'port': int(self.HTTP_PORT) })

        handle.uri = 'http://localhost:%s%s' % (self.HTTP_PORT, HOME_PAGE)

        webactivity.WebActivity.__init__(self, handle)

        # Use xpcom to set a RAM cache limit.  (Trac #7081.)
        from xpcom import components
        from xpcom.components import interfaces
        cls = components.classes['@mozilla.org/preferences-service;1']
        pref_service = cls.getService(interfaces.nsIPrefService)
        branch = pref_service.getBranch("browser.cache.memory.")
        branch.setIntPref("capacity", "5000")

        # Use xpcom to turn off "offline mode" detection, which disables
        # access to localhost for no good reason.  (Trac #6250.)
        ios_class = components.classes["@mozilla.org/network/io-service;1"]
        io_service = ios_class.getService(interfaces.nsIIOService2)
        io_service.manageOfflineStatus = False

        self.searchtoolbar = SearchToolbar(self)
        # WTB: Hacked to use hardcoded Spanish localization for WikiBrowse release.
        if OLD_TOOLBAR:
            self.toolbox.add_toolbar('Buscar', self.searchtoolbar)
        else:
            search_toolbar_button = ToolbarButton()
            search_toolbar_button.set_page(self.searchtoolbar)
            search_toolbar_button.props.icon_name = 'search'
            search_toolbar_button.props.label = _('Search')
            self.get_toolbar_box().toolbar.insert(search_toolbar_button, 1)
            search_toolbar_button.show()

        self.searchtoolbar.show()

    def _get_browser(self):
        if hasattr(self, '_browser') and callable(self._browser):
            # Browse < 109
            return self._browser
        else:
            return self._tabbed_view.props.current_browser

    def _load_homepage(self):
        home_uri = 'http://localhost:%s%s' % (self.HTTP_PORT, HOME_PAGE)
        browser = self._get_browser()
        browser.load_uri(home_uri)