~manishsinha/gnome-activity-journal/fixes-831436-gaj-notloading-oneiric

« back to all changes in this revision

Viewing changes to src/plugins/blacklist_manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Siegfried-Angel Gevatter Pujals, Siegfried-Angel Gevatter Pujals, Manish Sinha
  • Date: 2011-07-16 19:12:03 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110716191203-jpvrhnlpsi12hav7
Tags: 0.8.0-1
[ Siegfried-Angel Gevatter Pujals ]
* New upstream releases (Closes: #621011) (LP: #643795, #722227, #734412,
  #743054, #743125, #650917).
* debian/postinst:
   - Restart zeitgeist-daemon after installation, to ensure that
     the extension gets loaded (LP: #638217).
* debian/control:
   - Bump Zeitgeist dependency to 0.8.0.
   - Remove Tracker from Suggests, support for it has been disabled
     for now.
   - Bump Standards-Version to 3.9.2.
* debian/rules:
   - Remove build/ directory on clean.
* debian/copyright:
   - Update copyright years and add Stefano Candori and Collabora.

[ Manish Sinha ]
* debian/control:
   - Add Recommends on gstreamer0.10-plugins-base (LP: #705545).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -.- coding: utf-8 -.-
2
 
#
3
 
# blacklist_manager.py GNOME Activity Journal Plugin
4
 
#
5
 
# Copyright © 2010 Randal Barlow
6
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
 
20
 
import dbus
21
 
import gobject
22
 
import gtk
23
 
import pango
24
 
 
25
 
__plugin_name__ = _("Blacklist Manager")
26
 
__description__ = _("Add and remove items from the zeitgeist blacklist")
27
 
 
28
 
from zeitgeist.datamodel import Event
29
 
 
30
 
from src.supporting_widgets import StockIconButton
31
 
from src.common import get_icon_for_name
32
 
 
33
 
 
34
 
class BlacklistManager(object):
35
 
    def __init__(self):
36
 
        obj = dbus.SessionBus().get_object("org.gnome.zeitgeist.Engine", "/org/gnome/zeitgeist/blacklist")
37
 
        self.iface = dbus.Interface(obj, "org.gnome.zeitgeist.Blacklist")
38
 
 
39
 
    def get_templates(self):
40
 
        return map(Event.new_for_struct, self.iface.GetBlacklist())
41
 
 
42
 
    def append_template(self, new_template):
43
 
        templates = self.get_templates()
44
 
        templates.append(new_template)
45
 
        self.iface.SetBlacklist(templates)
46
 
 
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)
53
 
        raise ValueError()
54
 
 
55
 
    def delete_events_matching_blacklist(self):
56
 
        raise NotImplementedError("This function is not available yet")
57
 
        templates = self.get_templates()
58
 
 
59
 
 
60
 
class BlacklistView(gtk.TreeView):
61
 
    empty_row_text = _("[Insert Path]")
62
 
    def __init__(self):
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)
79
 
 
80
 
        self.connect("row-activated", self._on_row_activated)
81
 
        self.load_list()
82
 
 
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)
88
 
            del model[path]
89
 
 
90
 
    def _edited(self, renderer, path, new_text):
91
 
        if not new_text or new_text == self.empty_row_text:
92
 
            return
93
 
        model = self.get_model()
94
 
        template = model[path][1]
95
 
        if template and new_text == template.subjects[0].uri:
96
 
            return
97
 
        if not template:
98
 
            template = Event.new_for_values(subject_uri=new_text)
99
 
            model[path][1] = template
100
 
        else:
101
 
            template.subjects[0].uri = new_text
102
 
        try:
103
 
            self.manager.remove_template(template)
104
 
        except ValueError:
105
 
            pass
106
 
        self.manager.append_template(template)
107
 
        model[path][0] = new_text
108
 
 
109
 
    def load_list(self):
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)
114
 
 
115
 
 
116
 
 
117
 
def activate(client, store, window):
118
 
    """
119
 
    This function is called to activate the plugin.
120
 
 
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
124
 
    """
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()
131
 
    treescroll.add(tree)
132
 
    bbox = gtk.HBox()
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)
137
 
    page.add(treescroll)
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()
143
 
    pass
144
 
 
145
 
 
146
 
def deactivate(client, store, window):
147
 
    """
148
 
    This function is called to deactivate the plugin.
149
 
 
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
153
 
    """
154
 
    window.preferences_dialog.notebook.page.destroy()
155
 
    del window.preferences_dialog.notebook.page
156
 
    pass