Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate
1
# Copyright (C) 2007, One Laptop Per Child
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16
17
from gettext import gettext as _
18
19
import os
20
import sys
21
import server
22
23
OLD_TOOLBAR = False
24
try:
25
    from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
26
except ImportError:
27
    OLD_TOOLBAR = True
28
29
#from sugar.activity import registry
30
#activity_info = registry.get_registry().get_activity('org.laptop.WebActivity')
31
32
#sys.path.append(activity_info.path)
33
sys.path.append("/home/olpc/Activities/Browse.activity")
34
import webactivity
35
36
from searchtoolbar import SearchToolbar
37
38
# Default settings.
39
WIKIDB = 'es_PE/es_PE.xml.bz2'
40
HOME_PAGE = '/static/'
41
42
# Activity class, extends WebActivity.
43
class WikipediaActivity(webactivity.WebActivity):
44
    def __init__(self, handle):
45
        
46
        print "Starting server...\n"
47
        
48
        os.chdir(os.environ['SUGAR_BUNDLE_PATH'])
49
50
        self.HTTP_PORT = '8000'
51
        server.load_db(WIKIDB)
52
        server.run_server({ 'path': WIKIDB,
53
                            'port': int(self.HTTP_PORT) })
54
55
        handle.uri = 'http://localhost:%s%s' % (self.HTTP_PORT, HOME_PAGE)
56
57
        webactivity.WebActivity.__init__(self, handle)
58
59
        # Use xpcom to set a RAM cache limit.  (Trac #7081.)
60
        from xpcom import components
61
        from xpcom.components import interfaces
62
        cls = components.classes['@mozilla.org/preferences-service;1']
63
        pref_service = cls.getService(interfaces.nsIPrefService)
64
        branch = pref_service.getBranch("browser.cache.memory.")
65
        branch.setIntPref("capacity", "5000")
66
67
        # Use xpcom to turn off "offline mode" detection, which disables
68
        # access to localhost for no good reason.  (Trac #6250.)
69
        ios_class = components.classes["@mozilla.org/network/io-service;1"]
70
        io_service = ios_class.getService(interfaces.nsIIOService2)
71
        io_service.manageOfflineStatus = False
72
73
        self.searchtoolbar = SearchToolbar(self)
74
        # WTB: Hacked to use hardcoded Spanish localization for WikiBrowse release.
75
        if OLD_TOOLBAR:
76
            self.toolbox.add_toolbar('Buscar', self.searchtoolbar)
77
        else:
78
            search_toolbar_button = ToolbarButton()
79
            search_toolbar_button.set_page(self.searchtoolbar)
80
            search_toolbar_button.props.icon_name = 'search'
81
            search_toolbar_button.props.label = _('Search')
82
            self.get_toolbar_box().toolbar.insert(search_toolbar_button, 1)
83
            search_toolbar_button.show()
84
85
        self.searchtoolbar.show()
86
87
    def _get_browser(self):
88
        if hasattr(self, '_browser') and callable(self._browser):
89
            # Browse < 109
90
            return self._browser
91
        else:
92
            return self._tabbed_view.props.current_browser
93
94
    def _load_homepage(self):
95
        home_uri = 'http://localhost:%s%s' % (self.HTTP_PORT, HOME_PAGE)
96
        browser = self._get_browser()
97
        browser.load_uri(home_uri)