Allow installing new metadata sources from the configure metadata download window

This commit is contained in:
Kovid Goyal 2025-08-21 12:01:30 +05:30
parent faa13c1899
commit 81d16882bf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 42 additions and 6 deletions

View File

@ -538,6 +538,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
initial_extra_size = QSize(350, 100)
forum_label_text = _('Plugin homepage')
warn_about_neededing_restart = True
@property
def gui(self):
@ -546,6 +547,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
def __init__(self, parent, initial_filter=FILTER_UPDATE_AVAILABLE, initial_category: Category | None = None):
SizePersistedDialog.__init__(self, parent, 'Plugin Updater plugin:plugin updater dialog')
self.number_installed = 0
self.forum_link = None
self.zip_url = None
self.model = None
@ -855,7 +857,11 @@ class PluginUpdaterDialog(SizePersistedDialog):
widget.gui = self.gui
widget.check_for_add_to_toolbars(plugin, previously_installed=plugin.name in installed_plugins)
self.gui.status_bar.showMessage(_('Plugin installed: %s') % display_plugin.name)
do_restart = notify_on_successful_install(self.gui, plugin)
if self.warn_about_neededing_restart:
do_restart = notify_on_successful_install(self.gui, plugin)
else:
info_dialog(self, _('Plugin installed'), _('The plugin {} was successfully installed.').format(display_plugin.name), show=True)
self.number_installed += 1
display_plugin.plugin = plugin
# We cannot read the 'actual' version information as the plugin will not be loaded yet
display_plugin.installed_version = display_plugin.available_version

View File

@ -322,7 +322,11 @@ class MetadataSingleDialogBase(QDialog):
self.fetch_metadata_button = b = CenteredToolButton(QIcon.ic('download-metadata.png'), _('&Download metadata'), self)
b.setPopupMode(QToolButton.ToolButtonPopupMode.DelayedPopup)
b.setToolTip(_('Download metadata for this book [%s]') % self.download_shortcut.key().toString(QKeySequence.SequenceFormat.NativeText))
b.setToolTip(_(
'Download metadata for this book [{}]\n\nMetadata includes title, authors, series, covers, etc.\n'
'For improved results, you can install more metadata sources,\n'
'by clicking the configure button to the right.').format(
self.download_shortcut.key().toString(QKeySequence.SequenceFormat.NativeText)))
self.fetch_metadata_button.clicked.connect(self.fetch_metadata)
self.fetch_metadata_menu = m = QMenu(self.fetch_metadata_button)
m.addAction(QIcon.ic('edit-undo.png'), _('Undo last metadata download'), self.undo_fetch_metadata)

View File

@ -5,8 +5,6 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from operator import attrgetter
from qt.core import (
QAbstractListModel,
QAbstractTableModel,
@ -29,6 +27,7 @@ from calibre.ebooks.metadata.sources.prefs import msprefs
from calibre.gui2 import error_dialog, question_dialog
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
from calibre.gui2.preferences.metadata_sources_ui import Ui_Form
from calibre.utils.icu import primary_sort_key
from calibre.utils.localization import ngettext
from polyglot.builtins import iteritems
@ -43,10 +42,16 @@ class SourcesModel(QAbstractTableModel): # {{{
self.enabled_overrides = {}
self.cover_overrides = {}
def reload_plugins(self):
self.beginResetModel()
self.plugins = list(all_metadata_plugins())
self.plugins.sort(key=lambda p: primary_sort_key(p.name))
self.endResetModel()
def initialize(self):
self.beginResetModel()
self.plugins = list(all_metadata_plugins())
self.plugins.sort(key=attrgetter('name'))
self.plugins.sort(key=lambda p: primary_sort_key(p.name))
self.enabled_overrides = {}
self.cover_overrides = {}
self.endResetModel()
@ -352,6 +357,16 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
l = self.page.layout()
l.setStretch(0, 1)
l.setStretch(1, 1)
self.add_new_source_button.clicked.connect(self.add_new_source)
def add_new_source(self):
from calibre.gui2.dialogs.plugin_updater import FILTER_NOT_INSTALLED, Category, PluginUpdaterDialog
d = PluginUpdaterDialog(self, initial_filter=FILTER_NOT_INSTALLED, initial_category=Category.MetadataSource)
d.warn_about_neededing_restart = False
d.exec()
if d.number_installed:
self.sources_model.reload_plugins()
self.fields_model.initialize()
def context_menu(self, pos):
m = QMenu(self)

View File

@ -77,6 +77,17 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="add_new_source_button">
<property name="text">
<string>&amp;Add new source</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/plus.png</normaloff>:/images/plus.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -164,7 +175,7 @@
<x>0</x>
<y>0</y>
<width>350</width>
<height>441</height>
<height>455</height>
</rect>
</property>
<property name="sizePolicy">