Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: 924ff86a6796f202b819dc802db64368ac7c72f1 (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
# 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

#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.
        self.toolbox.add_toolbar('Buscar', self.searchtoolbar)
        self.searchtoolbar.show()

    def _load_homepage(self):
        home_url = 'http://localhost:%s%s' % (self.HTTP_PORT, HOME_PAGE)
        self._browser.load_uri(home_url)