diff --git a/src/calibre/gui2/dialogs/choose_plugin_toolbars.py b/src/calibre/gui2/dialogs/choose_plugin_toolbars.py
new file mode 100644
index 0000000000..5639286519
--- /dev/null
+++ b/src/calibre/gui2/dialogs/choose_plugin_toolbars.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
+
+from __future__ import (unicode_literals, division, absolute_import,
+ print_function)
+
+__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
+__docformat__ = 'restructuredtext en'
+__license__ = 'GPL v3'
+
+
+from PyQt4.Qt import QDialog, QVBoxLayout, QLabel, QDialogButtonBox, \
+ QListWidget, QAbstractItemView
+from PyQt4 import QtGui
+
+class ChoosePluginToolbarsDialog(QDialog):
+
+ def __init__(self, parent, plugin, locations):
+ QDialog.__init__(self, parent)
+ self.locations = locations
+
+ self.setWindowTitle(
+ _('Add "%s" to toolbars or menus')%plugin.name)
+
+ self._layout = QVBoxLayout(self)
+ self.setLayout(self._layout)
+
+ self._header_label = QLabel(
+ _('Select the toolbars and/or menus to add "%s" to:') %
+ plugin.name)
+ self._layout.addWidget(self._header_label)
+
+ self._locations_list = QListWidget(self)
+ self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection)
+ sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
+ QtGui.QSizePolicy.Minimum)
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ self._locations_list.setSizePolicy(sizePolicy)
+ for key, text in locations:
+ self._locations_list.addItem(text)
+ self._layout.addWidget(self._locations_list)
+
+ self._footer_label = QLabel(
+ _('You can also customise the plugin locations '
+ 'using Preferences -> Customise the toolbar'))
+ self._layout.addWidget(self._footer_label)
+
+ button_box = QDialogButtonBox(QDialogButtonBox.Ok |
+ QDialogButtonBox.Cancel)
+ button_box.accepted.connect(self.accept)
+ button_box.rejected.connect(self.reject)
+ self._layout.addWidget(button_box)
+ self.resize(self.sizeHint())
+
+ def selected_locations(self):
+ selected = []
+ for row in self._locations_list.selectionModel().selectedRows():
+ selected.append(self.locations[row.row()])
+ return selected
+
diff --git a/src/calibre/gui2/preferences/plugins.py b/src/calibre/gui2/preferences/plugins.py
index acf42fee16..740119831e 100644
--- a/src/calibre/gui2/preferences/plugins.py
+++ b/src/calibre/gui2/preferences/plugins.py
@@ -16,9 +16,10 @@ from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin
disable_plugin, plugin_customization, add_plugin, \
remove_plugin
from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \
- question_dialog
+ question_dialog, gprefs
from calibre.utils.search_query_parser import SearchQueryParser
from calibre.utils.icu import lower
+from calibre.utils.ordered_dict import OrderedDict
class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{
@@ -281,6 +282,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self._plugin_model.populate()
self._plugin_model.reset()
self.changed_signal.emit()
+ self.check_for_add_to_toolbars(plugin)
info_dialog(self, _('Success'),
_('Plugin {0} successfully installed under '
' {1} plugins. You may have to restart calibre '
@@ -342,6 +344,37 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
plugin.name + _(' cannot be removed. It is a '
'builtin plugin. Try disabling it instead.')).exec_()
+ def check_for_add_to_toolbars(self, plugin):
+ from calibre.gui2.preferences.toolbar import ConfigWidget
+ from calibre.customize import InterfaceActionBase
+
+ if not isinstance(plugin, InterfaceActionBase):
+ return
+
+ all_locations = OrderedDict(ConfigWidget.LOCATIONS)
+ plugin_action = plugin.load_actual_plugin(self.gui)
+ installed_actions = OrderedDict([
+ (key, list(gprefs.get('action-layout-'+key, [])))
+ for key in all_locations])
+
+ # If already installed in a GUI container, do nothing
+ for action_names in installed_actions.itervalues():
+ if plugin_action.name in action_names:
+ return
+
+ allowed_locations = [(key, text) for key, text in
+ all_locations.iteritems() if key
+ not in plugin_action.dont_add_to]
+ if not allowed_locations:
+ return # This plugin doesn't want to live in the GUI
+
+ from calibre.gui2.dialogs.choose_plugin_toolbars import ChoosePluginToolbarsDialog
+ d = ChoosePluginToolbarsDialog(self, plugin_action, allowed_locations)
+ if d.exec_() == d.Accepted:
+ for key, text in d.selected_locations():
+ installed_actions = list(gprefs['action-layout-'+key])
+ installed_actions.append(plugin_action.name)
+ gprefs['action-layout-'+key] = tuple(installed_actions)
if __name__ == '__main__':
from PyQt4.Qt import QApplication