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
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
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
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
# -----------------------------------------------------------------------------
20
from GTG.core.plugins import GnomeConfig
22
#from GTG.core.plugins.engine import PluginEngine
23
#from GTG.core.plugins.engine import PluginAPI
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)
46
self.dialog = self.builder.get_object("PluginManagerDialog")
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")
56
self.vbox_frame = self.builder.get_object("vbox_frame")
57
self.box_error = self.builder.get_object("box_error")
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)
64
# # recheck the plugins with errors
65
# self.pengine.recheckPluginsErrors(self.plugins, self.plugin_apis)
68
self.PluginList = gtk.ListStore('gboolean', str, str, 'gboolean', 'gboolean')
70
# for plgin in self.plugins:
71
# if not plgin['error']:
72
# self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], True, False])
74
# self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], False, True])
78
self.pluginTree = self.builder.get_object("pluginTree")
80
self.rendererToggle = gtk.CellRendererToggle()
81
self.rendererToggle.set_property('activatable', True)
82
self.rendererToggle.connect('toggled', self.colToggledClicked, self.PluginList)
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)
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)
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)
96
self.pluginTree.append_column(self.colToggle)
97
self.pluginTree.append_column(self.colName)
98
self.pluginTree.append_column(self.colVersion)
100
self.pluginTree.set_model(self.PluginList)
101
self.pluginTree.set_search_column(2)
106
self.dialog.set_transient_for(parent)
107
self.config_btn.set_sensitive(False)
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)
115
self.dialog.show_all()
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()
124
for plgin in self.plugins:
125
if not plgin['error']:
126
self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], True, False])
128
self.PluginList.append([plgin['state'], plgin['name'], plgin['version'], False, True])
130
self.dialog.present()
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)
139
#def delete(self, widget, response=None):
140
# self.dialog.destroy()
143
def colToggledClicked(self, cell, path, model):
144
model[path][0] = not model[path][0]
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
153
self.pengine.activatePlugins([plgin], self.plugin_apis)
155
self.pengine.deactivatePlugins([plgin], self.plugin_apis)
158
def pluginExtraInfo(self, treeview, plugins):
159
path = treeview.get_cursor()[0]
161
model = treeview.get_model()
162
iter = treeview.get_model().get_iter(path)
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"))
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(
178
"%s</small>" %GnomeConfig.MODULEMISSING)
180
elif plgin['missing_dbus'] and not plgin['missing_modules']:
181
self.lblErrorTitle.set_markup(
183
"%s</small>" %GnomeConfig.DBUSMISSING)
184
elif plgin['missing_modules'] and plgin['missing_dbus']:
185
self.lblErrorTitle.set_markup(
187
"%s</small>" %GnomeConfig.MODULANDDBUS)
189
self.lblErrorTitle.set_markup(
191
"%s</small>" %GnomeConfig.UNKNOWN)
192
self.box_error.show_all()
194
#set the missing/info
195
if plgin['missing_modules'] and not plgin['missing_dbus']:
197
for element in plgin['missing_modules']:
198
missing = missing + ", " + element
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']:
205
for element in plgin['missing_dbus']:
206
missing_dbus = missing_dbus + "; " + str(element)
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']:
212
for element in plgin['missing_modules']:
213
missing = missing + ", " + element
216
for element in plgin['missing_dbus']:
217
missing_dbus = missing_dbus + "; " + str(element)
219
self.lblPluginMM.set_markup("<small><b>" + missing[2:] + "</b>\n\n" + "<b>" + missing_dbus[2:] + "</b></small>")
221
self.box_error.hide()
225
if not plgin['instance']:
226
plgin['instance'] = plgin['class']()
228
if plgin['instance'].is_configurable():
229
self.config_btn.set_sensitive(True)
230
self.current_plugin = plgin
232
self.config_btn.set_sensitive(False)
234
self.config_btn.set_sensitive(False)
236
def plugin_configure_dialog(self, widget, data=None):
237
self.current_plugin['instance'].configure_dialog(self.plugin_api)