Newer
Older
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*-
## This file is part of Gajim.
##
## Gajim 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; version 3 only.
##
## Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.
##
'''
GUI classes related to plug-in management.
:author: Mateusz Biliński <mateusz@bilinski.it>
:since: 06/06/2008
:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
:license: GPL
'''
__all__ = ['PluginsWindow']
import pango
import gtk, gobject
import gtkgui_helpers
from common import gajim
from plugins.helpers import log_calls, log
class PluginsWindow(object):
'''Class for Plugins window'''
@log_calls('PluginsWindow')
def __init__(self):
'''Initialize Plugins window'''
self.xml = gtkgui_helpers.get_glade('plugins_window.glade')
self.window = self.xml.get_widget('plugins_window')
self.window.set_transient_for(gajim.interface.roster.window)
widgets_to_extract = ('plugins_notebook',
'plugin_name_label',
'plugin_version_label',
'plugin_authors_label',
'plugin_homepage_linkbutton',
'plugin_description_textview',
'uninstall_plugin_button',
'configure_plugin_button',
'installed_plugins_treeview')
for widget_name in widgets_to_extract:
setattr(self, widget_name, self.xml.get_widget(widget_name))
attr_list = pango.AttrList()
attr_list.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
self.plugin_name_label.set_attributes(attr_list)
self.installed_plugins_model = gtk.ListStore(gobject.TYPE_PYOBJECT,
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN)
self.installed_plugins_treeview.set_model(self.installed_plugins_model)
renderer = gtk.CellRendererText()
col = gtk.TreeViewColumn(_('Plugin'), renderer, text=1)
self.installed_plugins_treeview.append_column(col)
renderer = gtk.CellRendererToggle()
renderer.set_property('activatable', True)
renderer.connect('toggled', self.installed_plugins_toggled_cb)
col = gtk.TreeViewColumn(_('Active'), renderer, active=2)
self.installed_plugins_treeview.append_column(col)
# connect signal for selection change
selection = self.installed_plugins_treeview.get_selection()
selection.connect('changed',
self.installed_plugins_treeview_selection_changed)
selection.set_mode(gtk.SELECTION_SINGLE)
self._clear_installed_plugin_info()
self.fill_installed_plugins_model()
self.xml.signal_autoconnect(self)
self.plugins_notebook.set_current_page(0)
self.window.show_all()
gtkgui_helpers.possibly_move_window_in_current_desktop(self.window)
@log_calls('PluginsWindow')
def installed_plugins_treeview_selection_changed(self, treeview_selection):
model, iter = treeview_selection.get_selected()
if iter:
plugin = model.get_value(iter, 0)
plugin_name = model.get_value(iter, 1)
is_active = model.get_value(iter, 2)
self._display_installed_plugin_info(plugin)
else:
self._clear_installed_plugin_info()
def _display_installed_plugin_info(self, plugin):
self.plugin_name_label.set_text(plugin.name)
self.plugin_version_label.set_text(plugin.version)
self.plugin_authors_label.set_text(", ".join(plugin.authors))
self.plugin_homepage_linkbutton.set_uri(plugin.homepage)
self.plugin_homepage_linkbutton.set_label(plugin.homepage)
self.plugin_homepage_linkbutton.set_property('sensitive', True)
desc_textbuffer = self.plugin_description_textview.get_buffer()
desc_textbuffer.set_text(plugin.description)
self.plugin_description_textview.set_property('sensitive', True)
self.uninstall_plugin_button.set_property('sensitive', True)

Mateusz Biliński
committed
if plugin.config_dialog is None:
self.configure_plugin_button.set_property('sensitive', False)
else:
self.configure_plugin_button.set_property('sensitive', True)
def _clear_installed_plugin_info(self):
self.plugin_name_label.set_text('')
self.plugin_version_label.set_text('')
self.plugin_authors_label.set_text('')
self.plugin_homepage_linkbutton.set_uri('')
self.plugin_homepage_linkbutton.set_label('')
self.plugin_homepage_linkbutton.set_property('sensitive', False)
desc_textbuffer = self.plugin_description_textview.get_buffer()
desc_textbuffer.set_text('')
self.plugin_description_textview.set_property('sensitive', False)
self.uninstall_plugin_button.set_property('sensitive', False)
self.configure_plugin_button.set_property('sensitive', False)
@log_calls('PluginsWindow')
def fill_installed_plugins_model(self):
pm = gajim.plugin_manager
self.installed_plugins_model.clear()
self.installed_plugins_model.set_sort_column_id(0, gtk.SORT_ASCENDING)

Mateusz Biliński
committed
for plugin in pm.plugins:
self.installed_plugins_model.append([plugin,
plugin.name,
plugin.active])
@log_calls('PluginsWindow')
def installed_plugins_toggled_cb(self, cell, path):
is_active = self.installed_plugins_model[path][2]

Mateusz Biliński
committed
plugin = self.installed_plugins_model[path][0]
if is_active:

Mateusz Biliński
committed
gajim.plugin_manager.deactivate_plugin(plugin)
else:

Mateusz Biliński
committed
gajim.plugin_manager.activate_plugin(plugin)
self.installed_plugins_model[path][2] = not is_active
@log_calls('PluginsWindow')
def on_plugins_window_destroy(self, widget):
'''Close window'''
del gajim.interface.instances['plugins']
@log_calls('PluginsWindow')
def on_close_button_clicked(self, widget):

Mateusz Biliński
committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
self.window.destroy()
@log_calls('PluginsWindow')
def on_configure_plugin_button_clicked(self, widget):
log.debug('widget: %s'%(widget))
selection = self.installed_plugins_treeview.get_selection()
model, iter = selection.get_selected()
if iter:
plugin = model.get_value(iter, 0)
plugin_name = model.get_value(iter, 1)
is_active = model.get_value(iter, 2)
result = plugin.config_dialog.run(self.window)
else:
# No plugin selected. this should never be reached. As configure
# plugin button should only my clickable when plugin is selected.
# XXX: maybe throw exception here?
pass
@log_calls('PluginsWindow')
def on_uninstall_plugin_button_clicked(self, widget):
pass
class GajimPluginConfigDialog(gtk.Dialog):
@log_calls('GajimPluginConfigDialog')
def __init__(self, plugin, **kwargs):
gtk.Dialog.__init__(self, '%s %s'%(plugin.name, _('Configuration')), **kwargs)

Mateusz Biliński
committed
self.plugin = plugin
self.add_button('gtk-close', gtk.RESPONSE_CLOSE)

Mateusz Biliński
committed
#label = gtk.Label(_('<b>%s Configuration</b>') % (plugin.name))
#label.set_markup(label.get_label())
#self.child.pack_start(label, False, False)

Mateusz Biliński
committed
@log_calls('GajimPluginConfigDialog')
def run(self, parent=None):
self.reparent(parent)
self.show_all()
result = super(GajimPluginConfigDialog, self).run()
self.hide()
return result