1
# -.- coding: utf-8 -.-
3
# blacklist_manager.py GNOME Activity Journal Plugin
5
# Copyright © 2010 Randal Barlow
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
__plugin_name__ = _("Blacklist Manager")
26
__description__ = _("Add and remove items from the zeitgeist blacklist")
28
from zeitgeist.datamodel import Event
30
from src.supporting_widgets import StockIconButton
31
from src.common import get_icon_for_name
34
class BlacklistManager(object):
36
obj = dbus.SessionBus().get_object("org.gnome.zeitgeist.Engine", "/org/gnome/zeitgeist/blacklist")
37
self.iface = dbus.Interface(obj, "org.gnome.zeitgeist.Blacklist")
39
def get_templates(self):
40
return map(Event.new_for_struct, self.iface.GetBlacklist())
42
def append_template(self, new_template):
43
templates = self.get_templates()
44
templates.append(new_template)
45
self.iface.SetBlacklist(templates)
47
def remove_template(self, new_template):
48
templates = self.get_templates()
49
for template in templates:
50
if template.matches_template(new_template):
51
templates.remove(template)
52
return self.iface.SetBlacklist(templates)
55
def delete_events_matching_blacklist(self):
56
raise NotImplementedError("This function is not available yet")
57
templates = self.get_templates()
60
class BlacklistView(gtk.TreeView):
61
empty_row_text = _("[Insert Path]")
63
super(BlacklistView, self).__init__()
64
self.manager = BlacklistManager()
65
delcolumn = gtk.TreeViewColumn("")
66
pixbuf_render = gtk.CellRendererPixbuf()
67
delcolumn.pack_start(pixbuf_render, False)
68
stock_pb = get_icon_for_name("remove", 8)
69
delcolumn.set_cell_data_func(pixbuf_render, lambda *x: pixbuf_render.set_property("pixbuf", stock_pb), "pixbuf")
70
self.append_column(delcolumn)
71
bcolumn = gtk.TreeViewColumn("Blacklisted subject URIs")
72
text_render = gtk.CellRendererText()
73
text_render.set_property("editable", True)
74
text_render.set_property("ellipsize", pango.ELLIPSIZE_MIDDLE)
75
text_render.connect("edited", self._edited)
76
bcolumn.pack_start(text_render, True)
77
bcolumn.add_attribute(text_render, "markup", 0)
78
self.append_column(bcolumn)
80
self.connect("row-activated", self._on_row_activated)
83
def _on_row_activated(self, this, path, column):
84
if isinstance(column.get_cell_renderers()[0], gtk.CellRendererPixbuf):
85
model = self.get_model()
86
template = model[path][1]
87
self.manager.remove_template(template)
90
def _edited(self, renderer, path, new_text):
91
if not new_text or new_text == self.empty_row_text:
93
model = self.get_model()
94
template = model[path][1]
95
if template and new_text == template.subjects[0].uri:
98
template = Event.new_for_values(subject_uri=new_text)
99
model[path][1] = template
101
template.subjects[0].uri = new_text
103
self.manager.remove_template(template)
106
self.manager.append_template(template)
107
model[path][0] = new_text
110
store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
111
for template in self.manager.get_templates():
112
store.append([template.subjects[0].uri, template])
113
self.set_model(store)
117
def activate(client, store, window):
119
This function is called to activate the plugin.
121
:param client: the zeitgeist client used by journal
122
:param store: the date based store which is used by journal to handle event and content object request
123
:param window: the activity journal primary window
125
window.preferences_dialog.notebook.page = page = gtk.VBox()
126
treescroll = gtk.ScrolledWindow()
127
page.set_border_width(10)
128
treescroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
129
treescroll.set_shadow_type(gtk.SHADOW_IN)
130
tree = BlacklistView()
133
new_template_button = StockIconButton(gtk.STOCK_NEW)
134
new_template_button.set_alignment(1, 0.5)
135
# apply_black_list = StockIconButton(gtk.STOCK_APPLY, label="Apply to existing")
136
page.pack_start(bbox, False, False, 2)
138
bbox.pack_start(new_template_button, False, False)
139
# bbox.pack_end(apply_black_list, False, False)
140
new_template_button.connect("clicked", lambda w: tree.get_model().append([tree.empty_row_text, None]))
141
window.preferences_dialog.notebook.append_page(page, tab_label=gtk.Label(_("Blacklist")))
142
window.preferences_dialog.notebook.show_all()
146
def deactivate(client, store, window):
148
This function is called to deactivate the plugin.
150
:param client: the zeitgeist client used by journal
151
:param store: the date based store which is used by journal to handle event and content object request
152
:param window: the activity journal primary window
154
window.preferences_dialog.notebook.page.destroy()
155
del window.preferences_dialog.notebook.page