2018-09-05 02:59:34 +02:00
|
|
|
# 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/>.
|
2008-06-07 19:28:34 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
GUI classes related to plug-in management.
|
|
|
|
|
|
|
|
:author: Mateusz Biliński <mateusz@bilinski.it>
|
2008-07-18 09:05:07 +02:00
|
|
|
:since: 6th June 2008
|
2008-06-07 19:28:34 +02:00
|
|
|
:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
|
|
|
|
:license: GPL
|
|
|
|
'''
|
|
|
|
|
|
|
|
__all__ = ['PluginsWindow']
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GdkPixbuf
|
2018-07-16 23:22:33 +02:00
|
|
|
from gi.repository import Gdk
|
2012-12-23 16:23:43 +01:00
|
|
|
import os
|
2008-06-07 19:28:34 +02:00
|
|
|
|
2017-03-04 21:22:46 +01:00
|
|
|
from enum import IntEnum, unique
|
2017-02-07 21:18:41 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
2018-07-16 23:22:33 +02:00
|
|
|
from gajim.gtk import WarningDialog
|
|
|
|
from gajim.gtk import YesNoDialog
|
2018-08-19 17:44:17 +02:00
|
|
|
from gajim.gtk.filechoosers import ArchiveChooserDialog
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2018-04-25 20:49:37 +02:00
|
|
|
from gajim.common import configpaths
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.plugins.helpers import log_calls
|
|
|
|
from gajim.plugins.helpers import GajimPluginActivateException
|
|
|
|
from gajim.plugins.plugins_i18n import _
|
|
|
|
from gajim.common.exceptions import PluginsystemError
|
2008-06-07 19:28:34 +02:00
|
|
|
|
2018-07-16 23:22:33 +02:00
|
|
|
|
2017-03-04 21:22:46 +01:00
|
|
|
@unique
|
2017-02-07 21:18:41 +01:00
|
|
|
class Column(IntEnum):
|
|
|
|
PLUGIN = 0
|
|
|
|
NAME = 1
|
|
|
|
ACTIVE = 2
|
|
|
|
ACTIVATABLE = 3
|
|
|
|
ICON = 4
|
2012-08-16 14:56:02 +02:00
|
|
|
|
|
|
|
|
2018-09-16 11:56:56 +02:00
|
|
|
class PluginsWindow:
|
2010-04-08 01:20:17 +02:00
|
|
|
'''Class for Plugins window'''
|
|
|
|
|
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def __init__(self):
|
|
|
|
'''Initialize Plugins window'''
|
2017-07-10 01:11:33 +02:00
|
|
|
builder = gtkgui_helpers.get_gtk_builder('plugins_window.ui')
|
|
|
|
self.window = builder.get_object('plugins_window')
|
2017-08-13 13:18:56 +02:00
|
|
|
self.window.set_transient_for(app.interface.roster.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2010-09-14 19:31:35 +02:00
|
|
|
widgets_to_extract = ('plugins_notebook', 'plugin_name_label',
|
|
|
|
'plugin_version_label', 'plugin_authors_label',
|
2013-08-16 14:53:17 +02:00
|
|
|
'plugin_homepage_linkbutton', 'uninstall_plugin_button',
|
2017-07-10 01:11:33 +02:00
|
|
|
'configure_plugin_button', 'installed_plugins_treeview',
|
2018-07-16 22:38:08 +02:00
|
|
|
'available_text', 'available_text_label')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
for widget_name in widgets_to_extract:
|
2017-07-10 01:11:33 +02:00
|
|
|
setattr(self, widget_name, builder.get_object(widget_name))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2018-07-16 22:38:08 +02:00
|
|
|
self.plugin_description_textview = builder.get_object('description')
|
2013-07-30 21:00:27 +02:00
|
|
|
self.installed_plugins_model = Gtk.ListStore(object, str, bool, bool,
|
2012-12-23 16:23:43 +01:00
|
|
|
GdkPixbuf.Pixbuf)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.installed_plugins_treeview.set_model(self.installed_plugins_model)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
renderer = Gtk.CellRendererText()
|
2017-02-07 21:18:41 +01:00
|
|
|
col = Gtk.TreeViewColumn(_('Plugin'))#, renderer, text=Column.NAME)
|
2012-12-23 16:23:43 +01:00
|
|
|
cell = Gtk.CellRendererPixbuf()
|
2012-12-31 17:13:35 +01:00
|
|
|
col.pack_start(cell, False)
|
2017-02-07 21:18:41 +01:00
|
|
|
col.add_attribute(cell, 'pixbuf', Column.ICON)
|
2012-12-31 17:13:35 +01:00
|
|
|
col.pack_start(renderer, True)
|
2017-02-07 21:18:41 +01:00
|
|
|
col.add_attribute(renderer, 'text', Column.NAME)
|
2013-01-27 22:32:17 +01:00
|
|
|
col.set_property('expand', True)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.installed_plugins_treeview.append_column(col)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
renderer = Gtk.CellRendererToggle()
|
2010-04-08 01:20:17 +02:00
|
|
|
renderer.connect('toggled', self.installed_plugins_toggled_cb)
|
2017-02-07 21:18:41 +01:00
|
|
|
col = Gtk.TreeViewColumn(_('Active'), renderer, active=Column.ACTIVE,
|
|
|
|
activatable=Column.ACTIVATABLE)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.installed_plugins_treeview.append_column(col)
|
|
|
|
|
2014-11-14 09:35:39 +01:00
|
|
|
self.def_icon = gtkgui_helpers.get_icon_pixmap('preferences-desktop')
|
2012-08-16 15:58:00 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
# connect signal for selection change
|
|
|
|
selection = self.installed_plugins_treeview.get_selection()
|
|
|
|
selection.connect('changed',
|
2010-09-14 19:31:35 +02:00
|
|
|
self.installed_plugins_treeview_selection_changed)
|
2012-12-23 16:23:43 +01:00
|
|
|
selection.set_mode(Gtk.SelectionMode.SINGLE)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2014-02-15 21:08:54 +01:00
|
|
|
self._clear_installed_plugin_info()
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
self.fill_installed_plugins_model()
|
2012-12-31 17:13:35 +01:00
|
|
|
root_iter = self.installed_plugins_model.get_iter_first()
|
|
|
|
if root_iter:
|
2017-07-10 01:11:33 +02:00
|
|
|
selection.select_iter(root_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2017-07-10 01:11:33 +02:00
|
|
|
builder.connect_signals(self)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
self.plugins_notebook.set_current_page(0)
|
|
|
|
|
2017-02-25 19:21:21 +01:00
|
|
|
# Adding GUI extension point for Plugins that want to hook the Plugin Window
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.gui_extension_point('plugin_window', self)
|
2017-02-13 11:35:17 +01:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
self.window.show_all()
|
|
|
|
|
2017-02-06 23:21:04 +01:00
|
|
|
def on_key_press_event(self, widget, event):
|
|
|
|
if event.keyval == Gdk.KEY_Escape:
|
|
|
|
self.window.destroy()
|
2012-08-16 15:58:00 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def installed_plugins_treeview_selection_changed(self, treeview_selection):
|
2018-09-18 13:54:25 +02:00
|
|
|
model, iter_ = treeview_selection.get_selected()
|
|
|
|
if iter_:
|
|
|
|
plugin = model.get_value(iter_, Column.PLUGIN)
|
2010-04-08 01:20:17 +02:00
|
|
|
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)
|
2010-09-18 23:00:43 +02:00
|
|
|
self.plugin_authors_label.set_text(plugin.authors)
|
2018-07-16 22:38:08 +02:00
|
|
|
markup = '<a href="%s">%s</a>' % (plugin.homepage, plugin.homepage)
|
|
|
|
self.plugin_homepage_linkbutton.set_markup(markup)
|
|
|
|
|
2012-04-30 21:04:37 +02:00
|
|
|
if plugin.available_text:
|
2018-07-16 22:38:08 +02:00
|
|
|
text = _('Warning: %s') % plugin.available_text
|
|
|
|
self.available_text_label.set_text(text)
|
|
|
|
self.available_text.show()
|
|
|
|
# Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=710888
|
|
|
|
self.available_text.queue_resize()
|
|
|
|
else:
|
|
|
|
self.available_text.hide()
|
|
|
|
|
|
|
|
self.plugin_description_textview.set_text(plugin.description)
|
|
|
|
|
2018-04-25 20:49:37 +02:00
|
|
|
self.uninstall_plugin_button.set_property(
|
|
|
|
'sensitive', configpaths.get('PLUGINS_USER') in plugin.__path__)
|
2013-05-04 16:27:32 +02:00
|
|
|
self.configure_plugin_button.set_property(
|
2017-02-08 13:07:12 +01:00
|
|
|
'sensitive', plugin.config_dialog is not None)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def _clear_installed_plugin_info(self):
|
|
|
|
self.plugin_name_label.set_text('')
|
|
|
|
self.plugin_version_label.set_text('')
|
|
|
|
self.plugin_authors_label.set_text('')
|
2018-07-16 22:38:08 +02:00
|
|
|
self.plugin_homepage_linkbutton.set_markup('')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2018-07-16 22:38:08 +02:00
|
|
|
self.plugin_description_textview.set_text('')
|
2010-04-08 01:20:17 +02:00
|
|
|
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):
|
2017-08-13 13:18:56 +02:00
|
|
|
pm = app.plugin_manager
|
2010-04-08 01:20:17 +02:00
|
|
|
self.installed_plugins_model.clear()
|
2012-12-23 16:23:43 +01:00
|
|
|
self.installed_plugins_model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
for plugin in pm.plugins:
|
2012-08-16 15:58:00 +02:00
|
|
|
icon = self.get_plugin_icon(plugin)
|
2010-09-14 19:31:35 +02:00
|
|
|
self.installed_plugins_model.append([plugin, plugin.name,
|
2012-08-16 15:58:00 +02:00
|
|
|
plugin.active and plugin.activatable, plugin.activatable, icon])
|
|
|
|
|
|
|
|
def get_plugin_icon(self, plugin):
|
|
|
|
icon_file = os.path.join(plugin.__path__, os.path.split(
|
|
|
|
plugin.__path__)[1]) + '.png'
|
|
|
|
icon = self.def_icon
|
|
|
|
if os.path.isfile(icon_file):
|
2012-12-23 16:23:43 +01:00
|
|
|
icon = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_file, 16, 16)
|
2012-08-16 15:58:00 +02:00
|
|
|
return icon
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def installed_plugins_toggled_cb(self, cell, path):
|
2017-02-07 21:18:41 +01:00
|
|
|
is_active = self.installed_plugins_model[path][Column.ACTIVE]
|
|
|
|
plugin = self.installed_plugins_model[path][Column.PLUGIN]
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
if is_active:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.deactivate_plugin(plugin)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-11-01 21:22:43 +01:00
|
|
|
try:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.activate_plugin(plugin)
|
2013-01-01 23:18:36 +01:00
|
|
|
except GajimPluginActivateException as e:
|
2012-07-15 22:44:02 +02:00
|
|
|
WarningDialog(_('Plugin failed'), str(e),
|
|
|
|
transient_for=self.window)
|
2010-11-01 21:22:43 +01:00
|
|
|
return
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2017-02-07 21:18:41 +01:00
|
|
|
self.installed_plugins_model[path][Column.ACTIVE] = not is_active
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def on_plugins_window_destroy(self, widget):
|
|
|
|
'''Close window'''
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.remove_gui_extension_point('plugin_window', self)
|
|
|
|
del app.interface.instances['plugins']
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def on_configure_plugin_button_clicked(self, widget):
|
|
|
|
selection = self.installed_plugins_treeview.get_selection()
|
2018-09-18 13:54:25 +02:00
|
|
|
model, iter_ = selection.get_selected()
|
|
|
|
if iter_:
|
|
|
|
plugin = model.get_value(iter_, Column.PLUGIN)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2017-09-29 02:38:41 +02:00
|
|
|
if isinstance(plugin.config_dialog, GajimPluginConfigDialog):
|
|
|
|
plugin.config_dialog.run(self.window)
|
|
|
|
else:
|
|
|
|
plugin.config_dialog(self.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
# No plugin selected. this should never be reached. As configure
|
|
|
|
# plugin button should only be clickable when plugin is selected.
|
|
|
|
# XXX: maybe throw exception here?
|
|
|
|
pass
|
|
|
|
|
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def on_uninstall_plugin_button_clicked(self, widget):
|
2010-09-14 19:31:35 +02:00
|
|
|
selection = self.installed_plugins_treeview.get_selection()
|
2018-09-18 13:54:25 +02:00
|
|
|
model, iter_ = selection.get_selected()
|
|
|
|
if iter_:
|
|
|
|
plugin = model.get_value(iter_, Column.PLUGIN)
|
2010-09-14 19:31:35 +02:00
|
|
|
try:
|
2018-04-25 21:55:54 +02:00
|
|
|
app.plugin_manager.uninstall_plugin(plugin)
|
2013-01-01 23:18:36 +01:00
|
|
|
except PluginsystemError as e:
|
2010-09-20 07:08:47 +02:00
|
|
|
WarningDialog(_('Unable to properly remove the plugin'),
|
2010-09-21 21:44:04 +02:00
|
|
|
str(e), self.window)
|
2010-09-14 19:31:35 +02:00
|
|
|
return
|
2018-09-18 13:54:25 +02:00
|
|
|
model.remove(iter_)
|
2010-09-14 19:31:35 +02:00
|
|
|
|
|
|
|
@log_calls('PluginsWindow')
|
|
|
|
def on_install_plugin_button_clicked(self, widget):
|
2010-09-20 07:08:47 +02:00
|
|
|
def show_warn_dialog():
|
|
|
|
text = _('Archive is malformed')
|
|
|
|
dialog = WarningDialog(text, '', transient_for=self.window)
|
|
|
|
dialog.set_modal(False)
|
|
|
|
dialog.popup()
|
|
|
|
|
2010-09-14 19:31:35 +02:00
|
|
|
def _on_plugin_exists(zip_filename):
|
|
|
|
def on_yes(is_checked):
|
2017-08-13 13:18:56 +02:00
|
|
|
plugin = app.plugin_manager.install_from_zip(zip_filename,
|
2010-09-14 19:31:35 +02:00
|
|
|
True)
|
2010-09-20 07:08:47 +02:00
|
|
|
if not plugin:
|
|
|
|
show_warn_dialog()
|
|
|
|
return
|
2010-09-14 19:31:35 +02:00
|
|
|
model = self.installed_plugins_model
|
|
|
|
|
2018-09-17 21:11:45 +02:00
|
|
|
for _index, row in enumerate(model):
|
2017-02-07 21:18:41 +01:00
|
|
|
if plugin == row[Column.PLUGIN]:
|
2017-06-25 20:42:15 +02:00
|
|
|
model.remove(row.iter)
|
2010-09-14 19:31:35 +02:00
|
|
|
break
|
|
|
|
|
2012-04-30 00:43:18 +02:00
|
|
|
iter_ = model.append([plugin, plugin.name, False,
|
2012-08-16 15:58:00 +02:00
|
|
|
plugin.activatable, self.get_plugin_icon(plugin)])
|
2010-09-14 19:31:35 +02:00
|
|
|
sel = self.installed_plugins_treeview.get_selection()
|
|
|
|
sel.select_iter(iter_)
|
|
|
|
|
2010-09-20 07:08:47 +02:00
|
|
|
YesNoDialog(_('Plugin already exists'), sectext=_('Overwrite?'),
|
2013-09-24 15:03:30 +02:00
|
|
|
on_response_yes=on_yes, transient_for=self.window)
|
2010-09-14 19:31:35 +02:00
|
|
|
|
|
|
|
def _try_install(zip_filename):
|
|
|
|
try:
|
2017-08-13 13:18:56 +02:00
|
|
|
plugin = app.plugin_manager.install_from_zip(zip_filename)
|
2013-01-01 23:18:36 +01:00
|
|
|
except PluginsystemError as er_type:
|
2010-09-14 19:31:35 +02:00
|
|
|
error_text = str(er_type)
|
|
|
|
if error_text == _('Plugin already exists'):
|
|
|
|
_on_plugin_exists(zip_filename)
|
|
|
|
return
|
|
|
|
|
2010-09-21 21:44:04 +02:00
|
|
|
WarningDialog(error_text, '"%s"' % zip_filename, self.window)
|
2010-09-20 07:08:47 +02:00
|
|
|
return
|
|
|
|
if not plugin:
|
|
|
|
show_warn_dialog()
|
2010-09-14 19:31:35 +02:00
|
|
|
return
|
|
|
|
model = self.installed_plugins_model
|
2012-04-30 00:43:18 +02:00
|
|
|
iter_ = model.append([plugin, plugin.name, False,
|
2017-06-25 20:42:15 +02:00
|
|
|
plugin.activatable, self.get_plugin_icon(plugin)])
|
2010-09-14 19:31:35 +02:00
|
|
|
sel = self.installed_plugins_treeview.get_selection()
|
|
|
|
sel.select_iter(iter_)
|
|
|
|
|
2018-05-04 00:36:10 +02:00
|
|
|
ArchiveChooserDialog(_try_install, transient_for=self.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
class GajimPluginConfigDialog(Gtk.Dialog):
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
@log_calls('GajimPluginConfigDialog')
|
|
|
|
def __init__(self, plugin, **kwargs):
|
2014-11-14 09:35:39 +01:00
|
|
|
Gtk.Dialog.__init__(self, title='%s %s'%(plugin.name,
|
|
|
|
_('Configuration')), **kwargs)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.plugin = plugin
|
2013-05-19 18:40:20 +02:00
|
|
|
button = self.add_button('gtk-close', Gtk.ResponseType.CLOSE)
|
|
|
|
button.connect('clicked', self.on_close_button_clicked)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
self.get_child().set_spacing(3)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
self.init()
|
|
|
|
|
2013-12-06 09:25:34 +01:00
|
|
|
def on_close_dialog(self, widget, data):
|
|
|
|
self.hide()
|
|
|
|
return True
|
|
|
|
|
2013-05-19 18:40:20 +02:00
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.hide()
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
@log_calls('GajimPluginConfigDialog')
|
|
|
|
def run(self, parent=None):
|
|
|
|
self.set_transient_for(parent)
|
|
|
|
self.on_run()
|
|
|
|
self.show_all()
|
2013-12-06 09:25:34 +01:00
|
|
|
self.connect('delete-event', self.on_close_dialog)
|
2018-09-18 12:06:01 +02:00
|
|
|
result = super(GajimPluginConfigDialog, self)
|
2010-04-08 01:20:17 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_run(self):
|
|
|
|
pass
|