show warning dialog when trying to enable a plugin that raise an exception when activate is called.
This commit is contained in:
parent
ea0f12b2f5
commit
5fa8dab30f
3 changed files with 29 additions and 18 deletions
|
@ -33,6 +33,7 @@ import gtkgui_helpers
|
||||||
from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog
|
from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from plugins.helpers import log_calls, log
|
from plugins.helpers import log_calls, log
|
||||||
|
from plugins.helpers import GajimPluginActivateException
|
||||||
from common.exceptions import PluginsystemError
|
from common.exceptions import PluginsystemError
|
||||||
|
|
||||||
class PluginsWindow(object):
|
class PluginsWindow(object):
|
||||||
|
@ -153,7 +154,11 @@ class PluginsWindow(object):
|
||||||
if is_active:
|
if is_active:
|
||||||
gajim.plugin_manager.deactivate_plugin(plugin)
|
gajim.plugin_manager.deactivate_plugin(plugin)
|
||||||
else:
|
else:
|
||||||
gajim.plugin_manager.activate_plugin(plugin)
|
try:
|
||||||
|
gajim.plugin_manager.activate_plugin(plugin)
|
||||||
|
except GajimPluginActivateException, e:
|
||||||
|
WarningDialog(_('Plugin failed'), str(e))
|
||||||
|
return
|
||||||
|
|
||||||
self.installed_plugins_model[path][2] = not is_active
|
self.installed_plugins_model[path][2] = not is_active
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,12 @@ log.propagate = False
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
|
class GajimPluginActivateException(Exception):
|
||||||
|
'''
|
||||||
|
Raised when activation failed
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
class log_calls(object):
|
class log_calls(object):
|
||||||
'''
|
'''
|
||||||
Decorator class for functions to easily log when they are entered and left.
|
Decorator class for functions to easily log when they are entered and left.
|
||||||
|
|
|
@ -38,7 +38,8 @@ from common import nec
|
||||||
from common.exceptions import PluginsystemError
|
from common.exceptions import PluginsystemError
|
||||||
|
|
||||||
from plugins.helpers import log, log_calls, Singleton
|
from plugins.helpers import log, log_calls, Singleton
|
||||||
from plugins.plugin import GajimPlugin
|
from plugins.helpers import GajimPluginActivateException
|
||||||
|
from plugins.plugin import GajimPlugin, GajimPluginException
|
||||||
|
|
||||||
class PluginManager(object):
|
class PluginManager(object):
|
||||||
'''
|
'''
|
||||||
|
@ -279,13 +280,7 @@ class PluginManager(object):
|
||||||
'''
|
'''
|
||||||
:param plugin: plugin to be activated
|
:param plugin: plugin to be activated
|
||||||
:type plugin: class object of `GajimPlugin` subclass
|
:type plugin: class object of `GajimPlugin` subclass
|
||||||
|
|
||||||
:todo: success checks should be implemented using exceptions. Such
|
|
||||||
control should also be implemented in deactivation. Exceptions
|
|
||||||
should be shown to user inside popup dialog, so the reason
|
|
||||||
for not activating plugin is known.
|
|
||||||
'''
|
'''
|
||||||
success = False
|
|
||||||
if not plugin.active:
|
if not plugin.active:
|
||||||
|
|
||||||
self._add_gui_extension_points_handlers_from_plugin(plugin)
|
self._add_gui_extension_points_handlers_from_plugin(plugin)
|
||||||
|
@ -293,15 +288,14 @@ class PluginManager(object):
|
||||||
self._register_events_handlers_in_ged(plugin)
|
self._register_events_handlers_in_ged(plugin)
|
||||||
self._register_network_events_in_nec(plugin)
|
self._register_network_events_in_nec(plugin)
|
||||||
|
|
||||||
success = True
|
self.active_plugins.append(plugin)
|
||||||
|
try:
|
||||||
if success:
|
|
||||||
self.active_plugins.append(plugin)
|
|
||||||
plugin.activate()
|
plugin.activate()
|
||||||
self._set_plugin_active_in_global_config(plugin)
|
except GajimPluginException, e:
|
||||||
plugin.active = True
|
self.deactivate_plugin(plugin)
|
||||||
|
raise GajimPluginActivateException(str(e))
|
||||||
return success
|
self._set_plugin_active_in_global_config(plugin)
|
||||||
|
plugin.active = True
|
||||||
|
|
||||||
def deactivate_plugin(self, plugin):
|
def deactivate_plugin(self, plugin):
|
||||||
# remove GUI extension points handlers (provided by plug-in) from
|
# remove GUI extension points handlers (provided by plug-in) from
|
||||||
|
@ -362,12 +356,18 @@ class PluginManager(object):
|
||||||
Activated plugins are appended to `active_plugins` list.
|
Activated plugins are appended to `active_plugins` list.
|
||||||
'''
|
'''
|
||||||
for plugin in self.plugins:
|
for plugin in self.plugins:
|
||||||
self.activate_plugin(plugin)
|
try:
|
||||||
|
self.activate_plugin(plugin)
|
||||||
|
except GajimPluginActivateException:
|
||||||
|
pass
|
||||||
|
|
||||||
def _activate_all_plugins_from_global_config(self):
|
def _activate_all_plugins_from_global_config(self):
|
||||||
for plugin in self.plugins:
|
for plugin in self.plugins:
|
||||||
if self._plugin_is_active_in_global_config(plugin):
|
if self._plugin_is_active_in_global_config(plugin):
|
||||||
self.activate_plugin(plugin)
|
try:
|
||||||
|
self.activate_plugin(plugin)
|
||||||
|
except GajimPluginActivateException:
|
||||||
|
pass
|
||||||
|
|
||||||
def _plugin_is_active_in_global_config(self, plugin):
|
def _plugin_is_active_in_global_config(self, plugin):
|
||||||
return gajim.config.get_per('plugins', plugin.short_name, 'active')
|
return gajim.config.get_per('plugins', plugin.short_name, 'active')
|
||||||
|
|
Loading…
Add table
Reference in a new issue