1
# -.- coding: utf-8 -.-
5
# Copyright © 2011 Collabora Ltd.
6
# By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
7
# By Seif Lotfy <seif@lotfy.com>
8
# Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU Lesser General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
from itertools import imap
25
from zeitgeist.client import ZeitgeistClient
26
from zeitgeist.datamodel import Event, Subject
28
class ZeitgeistInterface:
30
INCOGNITO = Event.new_for_values()
31
INCOGNITO_TEMPLATE_ID = "block-all"
34
self._client = ZeitgeistClient()
35
if self._client.get_version() < [0, 7, 99]:
36
raise SystemExit, _("Zeitgeist version 0.8 or later required.")
38
self._blacklist = self._client._iface.get_extension('Blacklist',
43
def all_templates(self):
47
self._blacklist.connect('TemplateAdded', self._template_added)
48
self._blacklist.connect('TemplateRemoved', self._template_removed)
49
# And fetch the current templates
50
for blacklist_id, template in self._blacklist.GetTemplates().iteritems():
51
self._all[blacklist_id] = Event(template)
54
def _template_added(self, blacklist_id, template):
55
if blacklist_id not in self._all:
56
self._all[blacklist_id] = template
58
def _template_removed(self, blacklist_id, template):
59
if blacklist_id in self._all:
60
del self._all[blacklist_id]
62
def add_blacklist_template(self, blacklist_id, template):
64
Add a new blacklist template.
66
self._blacklist.AddTemplate(blacklist_id, template)
67
self._all[blacklist_id] = template
69
def remove_blacklist_template(self, blacklist_id):
71
Remove the blacklist template for the provided template id.
73
self._blacklist.RemoveTemplate(blacklist_id)
74
del self._all[blacklist_id]
76
def get_incognito(self):
78
The blacklist template for incognito is matched against all the
81
return any(imap(self.INCOGNITO.matches_template, self.all_templates.itervalues()))
83
def set_incognito(self, enabled):
85
self.add_blacklist_template(self.INCOGNITO_TEMPLATE_ID, self.INCOGNITO)
87
self.remove_blacklist_template(self.INCOGNITO_TEMPLATE_ID)
89
def remove_history(self, timerange, callback):
91
def get_ids_callback(ids):
93
def remove_callback(timerange):
95
self._client.delete_events(ids, remove_callback)
96
self._client.find_event_ids_for_templates([], get_ids_callback, timerange, 2, 0)