mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-03-18 15:37:52 -04:00
Merge branch 'improve-disabling-plugins' of https://github.com/un-pogaz/calibre
This commit is contained in:
commit
9d99cca285
@ -661,7 +661,6 @@ class InterfaceActionBase(Plugin): # {{{
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
author = 'Kovid Goyal'
|
||||
type = _('User interface action')
|
||||
can_be_disabled = False
|
||||
|
||||
actual_plugin = None
|
||||
|
||||
@ -696,7 +695,6 @@ class PreferencesPlugin(Plugin): # {{{
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
author = 'Kovid Goyal'
|
||||
type = _('Preferences')
|
||||
can_be_disabled = False
|
||||
|
||||
#: Import path to module that contains a class named ConfigWidget
|
||||
#: which implements the ConfigWidgetInterface. Used by
|
||||
|
||||
@ -133,7 +133,6 @@ class InputFormatPlugin(Plugin):
|
||||
'''
|
||||
|
||||
type = _('Conversion input')
|
||||
can_be_disabled = False
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
commit_name = None # unique name under which options for this plugin are saved
|
||||
ui_data = None
|
||||
@ -281,7 +280,6 @@ class OutputFormatPlugin(Plugin):
|
||||
'''
|
||||
|
||||
type = _('Conversion output')
|
||||
can_be_disabled = False
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
commit_name = None # unique name under which options for this plugin are saved
|
||||
ui_data = None
|
||||
|
||||
@ -16,6 +16,7 @@ from calibre.customize import (
|
||||
CatalogPlugin,
|
||||
EditBookToolPlugin,
|
||||
FileTypePlugin,
|
||||
InterfaceActionBase,
|
||||
InvalidPlugin,
|
||||
LibraryClosedPlugin,
|
||||
MetadataReaderPlugin,
|
||||
@ -105,7 +106,7 @@ def disable_plugin(plugin_or_name):
|
||||
plugin = find_plugin(x)
|
||||
if plugin is None:
|
||||
raise ValueError(f'No plugin named: {x} found')
|
||||
if not plugin.can_be_disabled:
|
||||
if not can_be_disabled(plugin):
|
||||
raise ValueError(f'Plugin {x} cannot be disabled')
|
||||
disable_plugin_by_name(x)
|
||||
|
||||
@ -121,6 +122,26 @@ def enable_plugin(plugin_or_name):
|
||||
config['enabled_plugins'] = ep
|
||||
|
||||
|
||||
def is_internal_plugin(plugin_or_name):
|
||||
x = getattr(plugin_or_name, 'name', plugin_or_name)
|
||||
plugin = find_plugin(x)
|
||||
return (plugin.installation_type is PluginInstallationType.BUILTIN
|
||||
and isinstance(plugin, (
|
||||
InterfaceActionBase,
|
||||
PreferencesPlugin,
|
||||
InputFormatPlugin,
|
||||
OutputFormatPlugin,
|
||||
InputProfile,
|
||||
OutputProfile,
|
||||
)))
|
||||
|
||||
|
||||
def can_be_disabled(plugin_or_name):
|
||||
x = getattr(plugin_or_name, 'name', plugin_or_name)
|
||||
plugin = find_plugin(x)
|
||||
return not is_internal_plugin(x) and plugin.can_be_disabled
|
||||
|
||||
|
||||
def restore_plugin_state_to_default(plugin_or_name):
|
||||
x = getattr(plugin_or_name, 'name', plugin_or_name)
|
||||
dp = config['disabled_plugins']
|
||||
|
||||
@ -40,6 +40,7 @@ from calibre.customize.ui import (
|
||||
BLACKLISTED_PLUGINS,
|
||||
NameConflict,
|
||||
add_plugin,
|
||||
can_be_disabled,
|
||||
disable_plugin,
|
||||
enable_plugin,
|
||||
has_external_plugins,
|
||||
@ -953,7 +954,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
|
||||
def _toggle_enabled_clicked(self):
|
||||
display_plugin = self._selected_display_plugin()
|
||||
plugin = display_plugin.plugin
|
||||
if not plugin.can_be_disabled:
|
||||
if not can_be_disabled(plugin):
|
||||
return error_dialog(self, _('Plugin cannot be disabled'),
|
||||
_('The plugin: %s cannot be disabled')%plugin.name, show=True)
|
||||
if is_disabled(plugin):
|
||||
|
||||
@ -13,7 +13,17 @@ from qt.core import QAbstractItemModel, QAbstractItemView, QBrush, QDialog, QIco
|
||||
|
||||
from calibre.constants import iswindows
|
||||
from calibre.customize import PluginInstallationType
|
||||
from calibre.customize.ui import NameConflict, add_plugin, disable_plugin, enable_plugin, initialized_plugins, is_disabled, plugin_customization, remove_plugin
|
||||
from calibre.customize.ui import (
|
||||
NameConflict,
|
||||
add_plugin,
|
||||
can_be_disabled,
|
||||
disable_plugin,
|
||||
enable_plugin,
|
||||
initialized_plugins,
|
||||
is_disabled,
|
||||
plugin_customization,
|
||||
remove_plugin,
|
||||
)
|
||||
from calibre.gui2 import choose_files, error_dialog, gprefs, info_dialog, question_dialog
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||
@ -349,7 +359,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
|
||||
plugin = self._plugin_model.index_to_plugin(index)
|
||||
if op == 'toggle':
|
||||
if not plugin.can_be_disabled:
|
||||
if not can_be_disabled(plugin):
|
||||
info_dialog(self, _('Plugin cannot be disabled'),
|
||||
_('Disabling the plugin %s is not allowed')%plugin.name, show=True, show_copy_button=False)
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user