~ubuntu-branches/debian/stretch/gtg/stretch

« back to all changes in this revision

Viewing changes to GTG/core/plugins/manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-12-12 16:04:44 UTC
  • mfrom: (1.1.2 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091212160444-gcmi5g9rfnh8zxl0
Tags: 0.2-1
* New upstream release.
  - xdg module is no longer required at build time (Closes: #560566).
* Remove unneeded build-dependencies.
* Add python-dbus to Depends.
* Bump dependency on python-gtk2 to be at least 2.14 (Closes: #559498).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# -----------------------------------------------------------------------------
 
3
# Gettings Things Gnome! - a personal organizer for the GNOME desktop
 
4
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
 
5
#
 
6
# This program is free software: you can redistribute it and/or modify it under
 
7
# the terms of the GNU General Public License as published by the Free Software
 
8
# Foundation, either version 3 of the License, or (at your option) any later
 
9
# version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
14
# details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along with
 
17
# this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
# -----------------------------------------------------------------------------
 
19
 
 
20
from GTG.core.plugins          import GnomeConfig
 
21
# not being used
 
22
#from GTG.core.plugins.engine import PluginEngine
 
23
#from GTG.core.plugins.engine import PluginAPI
 
24
 
 
25
import sys
 
26
 
 
27
try:
 
28
    import pygtk
 
29
    pygtk.require("2.0")
 
30
except:
 
31
    sys.exit(1)
 
32
try:
 
33
    import gtk
 
34
except:
 
35
    sys.exit(1)
 
36
 
 
37
class PluginManager:
 
38
    
 
39
    def __init__(self, parent, plugins, pengine, plugin_apis):
 
40
        self.plugins = plugins
 
41
        self.pengine = pengine
 
42
        self.plugin_apis = plugin_apis
 
43
        self.builder = gtk.Builder() 
 
44
        self.builder.add_from_file(GnomeConfig.GLADE_FILE)
 
45
        
 
46
        self.dialog = self.builder.get_object("PluginManagerDialog")
 
47
        
 
48
        # stuff to populate
 
49
        self.close_btn = self.builder.get_object("close_btn")
 
50
        self.config_btn = self.builder.get_object("config_btn")
 
51
        self.lblPluginName = self.builder.get_object("lblPluginName")
 
52
        self.lblPluginVersion = self.builder.get_object("lblPluginVersion")
 
53
        self.lblPluginAuthors = self.builder.get_object("lblPluginAuthors")
 
54
        self.txtPluginDescription = self.builder.get_object("txtPluginDescription")
 
55
        
 
56
        self.vbox_frame = self.builder.get_object("vbox_frame")
 
57
        self.box_error = self.builder.get_object("box_error")
 
58
        self.box_error.hide()
 
59
        self.lblErrorTitle = self.builder.get_object("lblErrorTitle")
 
60
        self.lblPluginMM = self.builder.get_object("lblPluginMM")
 
61
        #self.btnClose = self.builder.get_object("close_btn")
 
62
        #self.btnClose.connect('clicked', self.close, None)
 
63
        
 
64
#        # recheck the plugins with errors
 
65
#        self.pengine.recheckPluginsErrors(self.plugins, self.plugin_apis)
 
66
        
 
67
        # liststore
 
68
        self.PluginList = gtk.ListStore('gboolean', str, str, 'gboolean', 'gboolean')
 
69
        
 
70
#        for plgin in self.plugins:
 
71
#            if not plgin['error']:
 
72
#                self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], True, False])
 
73
#            else:
 
74
#                self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], False, True])
 
75
        # end - liststore
 
76
        
 
77
        # treeview
 
78
        self.pluginTree = self.builder.get_object("pluginTree")
 
79
        
 
80
        self.rendererToggle = gtk.CellRendererToggle()
 
81
        self.rendererToggle.set_property('activatable', True)
 
82
        self.rendererToggle.connect('toggled', self.colToggledClicked, self.PluginList)
 
83
        
 
84
        self.colToggle = gtk.TreeViewColumn("Enabled", self.rendererToggle)
 
85
        self.colToggle.add_attribute(self.rendererToggle, "active", 0)
 
86
        self.colToggle.add_attribute(self.rendererToggle, "activatable", 3)
 
87
        
 
88
        self.rendererName = gtk.CellRendererText()
 
89
        self.rendererName.set_property('foreground', 'gray')
 
90
        self.colName = gtk.TreeViewColumn("Name", self.rendererName, text=1, foreground_set=4)
 
91
        
 
92
        self.rendererVersion = gtk.CellRendererText()
 
93
        self.rendererVersion.set_property('foreground', 'gray')
 
94
        self.colVersion = gtk.TreeViewColumn("Version", self.rendererVersion, text=2, foreground_set=4)
 
95
        
 
96
        self.pluginTree.append_column(self.colToggle)
 
97
        self.pluginTree.append_column(self.colName)
 
98
        self.pluginTree.append_column(self.colVersion)
 
99
        
 
100
        self.pluginTree.set_model(self.PluginList)
 
101
        self.pluginTree.set_search_column(2)
 
102
        # end - treeview
 
103
        
 
104
        # properties
 
105
        
 
106
        self.dialog.set_transient_for(parent)
 
107
        self.config_btn.set_sensitive(False)
 
108
        
 
109
        # connect signals 
 
110
        self.dialog.connect("delete_event", self.close)
 
111
        self.close_btn.connect("clicked", self.close)
 
112
        self.pluginTree.connect("cursor-changed", self.pluginExtraInfo, self.plugins)
 
113
        self.config_btn.connect("clicked", self.plugin_configure_dialog)
 
114
        self.present()
 
115
        self.dialog.show_all()
 
116
        
 
117
        
 
118
    def present(self):
 
119
        # recheck the plugins with errors
 
120
        #doing this reset all plugin state to False
 
121
        self.pengine.recheckPluginsErrors(self.plugins, self.plugin_apis,checkall=True)
 
122
        self.PluginList.clear()
 
123
        
 
124
        for plgin in self.plugins:
 
125
            if not plgin['error']:
 
126
                self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], True, False])
 
127
            else:
 
128
                self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], False, True])
 
129
        
 
130
        self.dialog.present()
 
131
 
 
132
    def close(self, widget, response=None):
 
133
        # get the plugins that are going to be initialized and the ones
 
134
        # that are going do be desabled
 
135
        self.pengine.recheckPlugins(self.plugins, self.plugin_apis)
 
136
        self.dialog.hide()
 
137
        return True
 
138
    
 
139
    #def delete(self, widget, response=None):
 
140
    #    self.dialog.destroy()
 
141
    #    return True
 
142
 
 
143
    def colToggledClicked(self, cell, path, model):
 
144
        model[path][0] = not model[path][0]
 
145
        if path:
 
146
            iter = model.get_iter(path)
 
147
            for plgin in self.plugins:
 
148
                if model[path][1] == plgin['name'] and model[path][2] == plgin['version']:
 
149
                    plgin['state'] = not plgin['state']
 
150
                    #we instantly apply the plugin activation/deactivation
 
151
                    #to respect HIG
 
152
                    if plgin['state'] :
 
153
                        self.pengine.activatePlugins([plgin], self.plugin_apis)
 
154
                    else :
 
155
                        self.pengine.deactivatePlugins([plgin], self.plugin_apis)
 
156
                    
 
157
 
 
158
    def pluginExtraInfo(self, treeview, plugins):
 
159
        path = treeview.get_cursor()[0]
 
160
        if path:
 
161
            model = treeview.get_model()
 
162
            iter = treeview.get_model().get_iter(path)
 
163
            
 
164
            for plgin in plugins:
 
165
                if (model.get_value(iter,1) == plgin['name']) and (model.get_value(iter,2) == plgin['version']):
 
166
                    self.lblPluginName.set_label("<b>" + plgin['name'] + "</b>")
 
167
                    self.lblPluginVersion.set_label(plgin['version'])
 
168
                    self.lblPluginAuthors.set_label(plgin['authors'])
 
169
                    self.txtPluginDescription.get_buffer().set_text(\
 
170
                                plgin['description'].replace("\n", " ").replace(r'\n', "\n"))
 
171
                    
 
172
                    if plgin['error']:
 
173
                        # set the title label
 
174
                        cantload = "<small><b>%s</b>. \n" %GnomeConfig.CANNOTLOAD
 
175
                        if plgin['missing_modules'] and not plgin['missing_dbus']:
 
176
                            self.lblErrorTitle.set_markup(
 
177
                                    cantload+
 
178
                                    "%s</small>" %GnomeConfig.MODULEMISSING)
 
179
                                    
 
180
                        elif plgin['missing_dbus'] and not plgin['missing_modules']:
 
181
                            self.lblErrorTitle.set_markup(
 
182
                                    cantload+
 
183
                                    "%s</small>" %GnomeConfig.DBUSMISSING)
 
184
                        elif plgin['missing_modules'] and plgin['missing_dbus']:
 
185
                            self.lblErrorTitle.set_markup(
 
186
                                    cantload+
 
187
                                    "%s</small>" %GnomeConfig.MODULANDDBUS)
 
188
                        else:
 
189
                            self.lblErrorTitle.set_markup(
 
190
                                    cantload+
 
191
                                    "%s</small>" %GnomeConfig.UNKNOWN)
 
192
                            self.box_error.show_all()
 
193
                            
 
194
                        #set the missing/info
 
195
                        if plgin['missing_modules'] and not plgin['missing_dbus']:
 
196
                            missing = ""
 
197
                            for element in plgin['missing_modules']:
 
198
                                missing = missing + ", " + element
 
199
                            
 
200
                            self.lblPluginMM.set_markup("<small><b>" + missing[2:] + "</b></small>")
 
201
                            self.lblPluginMM.set_line_wrap(True)
 
202
                            self.box_error.show_all()
 
203
                        elif plgin['missing_dbus'] and not plgin['missing_modules']:
 
204
                            missing_dbus = ""
 
205
                            for element in plgin['missing_dbus']:
 
206
                                missing_dbus = missing_dbus + "; " + str(element)
 
207
                            
 
208
                            self.lblPluginMM.set_markup("<small><b>" + missing_dbus[2:] + "</b></small>")
 
209
                            self.box_error.show_all()
 
210
                        elif plgin['missing_modules'] and plgin['missing_dbus']:
 
211
                            missing = ""
 
212
                            for element in plgin['missing_modules']:
 
213
                                missing = missing + ", " + element
 
214
                            
 
215
                            missing_dbus = ""
 
216
                            for element in plgin['missing_dbus']:
 
217
                                missing_dbus = missing_dbus + "; " + str(element)
 
218
                                
 
219
                            self.lblPluginMM.set_markup("<small><b>" + missing[2:] + "</b>\n\n" + "<b>" + missing_dbus[2:] + "</b></small>")
 
220
                    else:
 
221
                        self.box_error.hide()
 
222
                        
 
223
                    try:
 
224
                        if plgin['state']:
 
225
                            if not plgin['instance']:
 
226
                                plgin['instance'] = plgin['class']()
 
227
                                
 
228
                            if plgin['instance'].is_configurable():
 
229
                                self.config_btn.set_sensitive(True)
 
230
                                self.current_plugin = plgin
 
231
                        else:
 
232
                            self.config_btn.set_sensitive(False)
 
233
                    except Exception, e:
 
234
                        self.config_btn.set_sensitive(False)
 
235
                        
 
236
    def plugin_configure_dialog(self, widget, data=None):
 
237
        self.current_plugin['instance'].configure_dialog(self.plugin_api)
 
238