summaryrefslogtreecommitdiff
path: root/trunk/dimbola/prefs.py
blob: 54daae994100d394fb36f356793fbdfd7857215d (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
75
76
77
78
79
80
81
# Copyright (C) 2009  Lars Wirzenius <liw@liw.fi>
# 
# 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 3 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, see <http://www.gnu.org/licenses/>.


import gobject
import gtk

import dimbola


class Preferences(gobject.GObject):

    def init(self, mwc):
        self.dialog = mwc.widgets['preferences_dialog']

        model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
                              gobject.TYPE_PYOBJECT)
        plugins = [(p.name, p) for p in mwc.pm.plugins]
        plugins.sort()
        for name, plugin in plugins:
            model.append((True, name, plugin))
        
        treeview = mwc.widgets['plugins_treeview']

        toggle_cr = gtk.CellRendererToggle()
        toggle_cr.connect('toggled', self.toggled, treeview)
        toggle_col = gtk.TreeViewColumn()
        toggle_col.pack_start(toggle_cr)
        toggle_col.add_attribute(toggle_cr, 'active', 0)
        
        text_cr = gtk.CellRendererText()
        name_col = gtk.TreeViewColumn()
        name_col.pack_start(text_cr)
        name_col.add_attribute(text_cr, 'text', 1)
        
        treeview.append_column(toggle_col)
        treeview.append_column(name_col)
        treeview.set_model(model)
        self.model = model
    
    def toggled(self, cr, path, treeview):
        model = treeview.get_model()
        it = model.get_iter(path)
        enabled = model.get_value(it, 0)
        plugin = model.get_value(it, 2)
        model.set_value(it, 0, not enabled)
        if enabled:
            plugin.disable()
        else:
            plugin.enable()
    
    def on_preferences_menuitem_activate(self, *args):
        self.dialog.show()

    def on_preferences_close_button_clicked(self, *args):
        self.dialog.hide()
        
    def on_preferences_dialog_delete_event(self, *args):
        self.dialog.hide()
        return True
        
    def plugin_is_enabled(self, plugin):
        it = self.model.get_iter_first()
        while it:
            if self.model.get_value(it, 2) == plugin:
                return self.model.get_value(it, 0)
            it = self.model.iter_next(it)
        return False