~ubuntu-branches/ubuntu/karmic/sugar-web-activity/karmic

« back to all changes in this revision

Viewing changes to Web.activity/sessionhistory.py

  • Committer: Bazaar Package Importer
  • Author(s): Jani Monoses
  • Date: 2008-01-31 15:17:08 UTC
  • Revision ID: james.westby@ubuntu.com-20080131151708-4tegqfae3vdhiylk
Tags: upstream-85
ImportĀ upstreamĀ versionĀ 85

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
import logging
 
18
 
 
19
import gobject
 
20
import xpcom
 
21
from xpcom.components import interfaces
 
22
 
 
23
class HistoryListener(gobject.GObject):
 
24
    _com_interfaces_ = interfaces.nsISHistoryListener
 
25
 
 
26
    __gsignals__ = {
 
27
        'session-history-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
 
28
                                    ([int])),
 
29
        'session-link-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
 
30
                                    ([str]))
 
31
    }
 
32
 
 
33
    def __init__(self, browser):
 
34
        gobject.GObject.__init__(self)
 
35
 
 
36
        self._wrapped_self = xpcom.server.WrapObject(self, interfaces.nsISHistoryListener)
 
37
        weak_ref = xpcom.client.WeakReference(self._wrapped_self)
 
38
 
 
39
        self._session_history = browser.web_navigation.sessionHistory
 
40
        self._session_history.addSHistoryListener(self._wrapped_self)
 
41
 
 
42
    def OnHistoryGoBack(self, back_uri):
 
43
        logging.debug("OnHistoryGoBack: %s" % back_uri.spec)
 
44
        self.emit('session-link-changed', back_uri.spec)
 
45
        self.emit('session-history-changed', self._session_history.index - 1)
 
46
        return True
 
47
 
 
48
    def OnHistoryGoForward(self, forward_uri):
 
49
        logging.debug("OnHistoryGoForward: %s" % forward_uri.spec)
 
50
        self.emit('session-link-changed', forward_uri.spec)
 
51
        self.emit('session-history-changed', self._session_history.index + 1)
 
52
        return True
 
53
 
 
54
    def OnHistoryGotoIndex(self, index, goto_uri):
 
55
        logging.debug("OnHistoryGotoIndex: %i %s" % (index, goto_uri.spec))
 
56
        self.emit('session-link-changed', goto_uri.spec)
 
57
        self.emit('session-history-changed', index)
 
58
        return True
 
59
 
 
60
    def OnHistoryNewEntry(self, new_uri):
 
61
        logging.debug("OnHistoryNewEntry: %s" % new_uri.spec)
 
62
        self.emit('session-link-changed', new_uri.spec)
 
63
        self.emit('session-history-changed', self._session_history.index + 1)
 
64
 
 
65
    def OnHistoryPurge(self, num_entries):
 
66
        logging.debug("OnHistoryPurge: %i" % num_entries)
 
67
        #self.emit('session-history-changed')
 
68
        return True
 
69
 
 
70
    def OnHistoryReload(self, reload_uri, reload_flags):
 
71
        self.emit('session-link-changed', reload_uri.spec)
 
72
        logging.debug("OnHistoryReload: %s" % reload_uri.spec)
 
73
        return True
 
74
 
 
75
_session_history_listener = None
 
76
 
 
77
def init(browser):
 
78
    global _session_history_listener
 
79
    _session_history_listener = HistoryListener(browser)
 
80
 
 
81
def get_instance():
 
82
    global _session_history_listener
 
83
    return _session_history_listener