From 77a73b84f2b6789ea16e0c2897e2f6c6c3c7314e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 21 Jan 2012 09:58:51 +0530 Subject: [PATCH] Add a checkbox to preferences->plugins to show only user installed plugins --- src/calibre/gui2/preferences/plugins.py | 20 +++++++++++++++++--- src/calibre/gui2/preferences/plugins.ui | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/preferences/plugins.py b/src/calibre/gui2/preferences/plugins.py index 70a8a82311..2d89b187bf 100644 --- a/src/calibre/gui2/preferences/plugins.py +++ b/src/calibre/gui2/preferences/plugins.py @@ -24,18 +24,27 @@ from calibre.constants import iswindows class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{ - def __init__(self, *args): - QAbstractItemModel.__init__(self, *args) + def __init__(self, show_only_user_plugins=False): + QAbstractItemModel.__init__(self) SearchQueryParser.__init__(self, ['all']) + self.show_only_user_plugins = show_only_user_plugins self.icon = QVariant(QIcon(I('plugins.png'))) p = QIcon(self.icon).pixmap(32, 32, QIcon.Disabled, QIcon.On) self.disabled_icon = QVariant(QIcon(p)) self._p = p self.populate() + def toggle_shown_plugins(self, show_only_user_plugins): + self.show_only_user_plugins = show_only_user_plugins + self.populate() + self.reset() + def populate(self): self._data = {} for plugin in initialized_plugins(): + if (getattr(plugin, 'plugin_path', None) is None + and self.show_only_user_plugins): + continue if plugin.type not in self._data: self._data[plugin.type] = [plugin] else: @@ -64,6 +73,7 @@ class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{ if p < 0: if query in lower(self.categories[c]): ans.add((c, p)) + continue else: try: plugin = self._data[self.categories[c]][p] @@ -209,7 +219,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def genesis(self, gui): self.gui = gui - self._plugin_model = PluginModel() + self._plugin_model = PluginModel(self.user_installed_plugins.isChecked()) self.plugin_view.setModel(self._plugin_model) self.plugin_view.setStyleSheet( "QTreeView::item { padding-bottom: 10px;}") @@ -226,6 +236,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.next_button.clicked.connect(self.find_next) self.previous_button.clicked.connect(self.find_previous) self.changed_signal.connect(self.reload_store_plugins) + self.user_installed_plugins.stateChanged.connect(self.show_user_installed_plugins) + + def show_user_installed_plugins(self, state): + self._plugin_model.toggle_shown_plugins(self.user_installed_plugins.isChecked()) def find(self, query): idx = self._plugin_model.find(query) diff --git a/src/calibre/gui2/preferences/plugins.ui b/src/calibre/gui2/preferences/plugins.ui index b4dfd4426e..6f284c4426 100644 --- a/src/calibre/gui2/preferences/plugins.ui +++ b/src/calibre/gui2/preferences/plugins.ui @@ -65,6 +65,16 @@ + + + + Show only those plugins that have been installed by you + + + Show only &user installed plugins + + +