mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Preferences->Metadata plugboards: Show plugboards for disabled devices and formats whose metadata writer plugins have been disabled. Fixes #1360766 [display plugboards with disabled plugin](https://bugs.launchpad.net/calibre/+bug/1360766)
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
92418618e1
@ -30,7 +30,7 @@ class ShowTemplateTesterAction(InterfaceAction):
|
|||||||
rows = view.selectionModel().selectedRows()
|
rows = view.selectionModel().selectedRows()
|
||||||
if not rows:
|
if not rows:
|
||||||
return error_dialog(self.gui, _('No books selected'),
|
return error_dialog(self.gui, _('No books selected'),
|
||||||
_('A book must be selected'), show=True)
|
_('One book must be selected'), show=True)
|
||||||
if len(rows) > 1:
|
if len(rows) > 1:
|
||||||
return error_dialog(self.gui, _('Selected multiple books'),
|
return error_dialog(self.gui, _('Selected multiple books'),
|
||||||
_('Only one book can be selected'), show=True)
|
_('Only one book can be selected'), show=True)
|
||||||
@ -38,8 +38,8 @@ class ShowTemplateTesterAction(InterfaceAction):
|
|||||||
index = rows[0]
|
index = rows[0]
|
||||||
if index.isValid():
|
if index.isValid():
|
||||||
db = view.model().db
|
db = view.model().db
|
||||||
t = TemplateDialog(self.gui, _('Enter a template to test'),
|
t = TemplateDialog(self.gui,
|
||||||
mi=db.get_metadata(index.row(), index_is_id=False,
|
_('Enter a template to test using data from the selected book'),
|
||||||
get_cover=False))
|
mi=db.get_metadata(index.row(), index_is_id=False, get_cover=False))
|
||||||
t.setWindowTitle(_('Template tester'))
|
t.setWindowTitle(_('Template tester'))
|
||||||
t.exec_()
|
t.exec_()
|
@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from PyQt5.Qt import Qt, QComboBox, QListWidgetItem
|
from PyQt5.Qt import Qt, QComboBox, QListWidgetItem
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ from calibre.gui2.device import device_name_for_plugboards
|
|||||||
from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor
|
from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
||||||
from calibre.customize.ui import metadata_writers, device_plugins
|
from calibre.customize.ui import metadata_writers, device_plugins, disabled_device_plugins
|
||||||
from calibre.library.save_to_disk import plugboard_any_format_value, \
|
from calibre.library.save_to_disk import plugboard_any_format_value, \
|
||||||
plugboard_any_device_value, plugboard_save_to_disk_value, \
|
plugboard_any_device_value, plugboard_save_to_disk_value, \
|
||||||
find_plugboard
|
find_plugboard
|
||||||
@ -56,6 +57,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.device_label.setText(_('Device currently connected: None'))
|
self.device_label.setText(_('Device currently connected: None'))
|
||||||
|
|
||||||
self.devices = ['', 'APPLE', 'FOLDER_DEVICE']
|
self.devices = ['', 'APPLE', 'FOLDER_DEVICE']
|
||||||
|
self.disabled_devices = []
|
||||||
self.device_to_formats_map = {}
|
self.device_to_formats_map = {}
|
||||||
for device in device_plugins():
|
for device in device_plugins():
|
||||||
n = device_name_for_plugboards(device)
|
n = device_name_for_plugboards(device)
|
||||||
@ -64,6 +66,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.device_to_formats_map[n].add('device_db')
|
self.device_to_formats_map[n].add('device_db')
|
||||||
if n not in self.devices:
|
if n not in self.devices:
|
||||||
self.devices.append(n)
|
self.devices.append(n)
|
||||||
|
|
||||||
|
for device in disabled_device_plugins():
|
||||||
|
n = device_name_for_plugboards(device)
|
||||||
|
if n not in self.disabled_devices:
|
||||||
|
self.disabled_devices.append(n)
|
||||||
|
|
||||||
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
||||||
self.devices.insert(1, plugboard_save_to_disk_value)
|
self.devices.insert(1, plugboard_save_to_disk_value)
|
||||||
self.devices.insert(1, plugboard_content_server_value)
|
self.devices.insert(1, plugboard_content_server_value)
|
||||||
@ -76,11 +84,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.new_device.addItems(self.devices)
|
self.new_device.addItems(self.devices)
|
||||||
|
|
||||||
self.formats = ['']
|
self.formats = ['']
|
||||||
|
self.format_to_writers_map = defaultdict(list)
|
||||||
for w in metadata_writers():
|
for w in metadata_writers():
|
||||||
if not is_disabled(w):
|
for f in w.file_types:
|
||||||
for f in w.file_types:
|
if f not in self.formats:
|
||||||
if not f in self.formats:
|
self.formats.append(f)
|
||||||
self.formats.append(f)
|
self.format_to_writers_map[f].append(w)
|
||||||
self.formats.append('device_db')
|
self.formats.append('device_db')
|
||||||
self.formats.sort()
|
self.formats.sort()
|
||||||
self.formats.insert(1, plugboard_any_format_value)
|
self.formats.insert(1, plugboard_any_format_value)
|
||||||
@ -173,12 +182,26 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
print 'edit_format_changed: none editable format!'
|
print 'edit_format_changed: none editable format!'
|
||||||
return
|
return
|
||||||
self.current_format = txt
|
self.current_format = txt
|
||||||
|
self.check_if_writer_disabled(txt)
|
||||||
devices = ['']
|
devices = ['']
|
||||||
for d in fpb:
|
for d in fpb:
|
||||||
devices.append(d)
|
devices.append(d)
|
||||||
self.edit_device.clear()
|
self.edit_device.clear()
|
||||||
self.edit_device.addItems(devices)
|
self.edit_device.addItems(devices)
|
||||||
|
|
||||||
|
def check_if_writer_disabled(self, format_name):
|
||||||
|
if format_name in ['device_db', plugboard_any_format_value]:
|
||||||
|
return
|
||||||
|
show_message = True
|
||||||
|
for writer in self.format_to_writers_map[format_name]:
|
||||||
|
if not is_disabled(writer):
|
||||||
|
show_message = False
|
||||||
|
if show_message:
|
||||||
|
warning_dialog(self, '',
|
||||||
|
_('That format has no metadata writers enabled. A plugboard '
|
||||||
|
'will probably have no effect.'),
|
||||||
|
show=True)
|
||||||
|
|
||||||
def new_device_changed(self, txt):
|
def new_device_changed(self, txt):
|
||||||
self.current_device = None
|
self.current_device = None
|
||||||
if txt == '':
|
if txt == '':
|
||||||
@ -250,8 +273,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
if self.current_format not in allowable_formats:
|
if self.current_format not in allowable_formats:
|
||||||
error_dialog(self, '',
|
error_dialog(self, '',
|
||||||
_('The {0} device does not support the {1} format.').
|
_('The {0} device does not support the {1} format.').
|
||||||
format(self.current_device, self.current_format),
|
format(self.current_device, self.current_format), show=True)
|
||||||
show=True)
|
|
||||||
self.new_device.setCurrentIndex(0)
|
self.new_device.setCurrentIndex(0)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -260,8 +282,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
warning_dialog(self, '',
|
warning_dialog(self, '',
|
||||||
_('The {0} device supports only the {1} format(s).').
|
_('The {0} device supports only the {1} format(s).').
|
||||||
format(plugboard_content_server_value,
|
format(plugboard_content_server_value,
|
||||||
', '.join(plugboard_content_server_formats)),
|
', '.join(plugboard_content_server_formats)), show=True)
|
||||||
show=True)
|
|
||||||
|
|
||||||
self.set_fields()
|
self.set_fields()
|
||||||
|
|
||||||
@ -272,6 +293,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
if txt:
|
if txt:
|
||||||
self.clear_fields(edit_boxes=True)
|
self.clear_fields(edit_boxes=True)
|
||||||
self.current_format = unicode(txt)
|
self.current_format = unicode(txt)
|
||||||
|
self.check_if_writer_disabled(self.current_format)
|
||||||
else:
|
else:
|
||||||
self.clear_fields(edit_boxes=False)
|
self.clear_fields(edit_boxes=False)
|
||||||
|
|
||||||
@ -320,10 +342,15 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.changed_signal.emit()
|
self.changed_signal.emit()
|
||||||
self.refill_all_boxes()
|
self.refill_all_boxes()
|
||||||
|
|
||||||
def existing_pb_clicked(self, Qitem):
|
def existing_pb_clicked(self, qitem):
|
||||||
item = Qitem.data(Qt.UserRole)
|
item = qitem.data(Qt.UserRole)
|
||||||
self.edit_format.setCurrentIndex(self.edit_format.findText(item[0]))
|
if (qitem.flags() & Qt.ItemIsEnabled):
|
||||||
self.edit_device.setCurrentIndex(self.edit_device.findText(item[1]))
|
self.edit_format.setCurrentIndex(self.edit_format.findText(item[0]))
|
||||||
|
self.edit_device.setCurrentIndex(self.edit_device.findText(item[1]))
|
||||||
|
else:
|
||||||
|
warning_dialog(self, '',
|
||||||
|
_('The {0} device plugin is disabled.').format(item[1]),
|
||||||
|
show=True)
|
||||||
|
|
||||||
def refill_all_boxes(self):
|
def refill_all_boxes(self):
|
||||||
if self.refilling:
|
if self.refilling:
|
||||||
@ -344,7 +371,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
for f in self.formats:
|
for f in self.formats:
|
||||||
if f not in self.current_plugboards:
|
if f not in self.current_plugboards:
|
||||||
continue
|
continue
|
||||||
for d in self.devices:
|
for d in sorted(self.devices + self.disabled_devices, key=lambda x:x.lower()):
|
||||||
if d not in self.current_plugboards[f]:
|
if d not in self.current_plugboards[f]:
|
||||||
continue
|
continue
|
||||||
ops = []
|
ops = []
|
||||||
@ -353,6 +380,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
txt = '%s:%s = %s\n'%(f, d, ', '.join(ops))
|
txt = '%s:%s = %s\n'%(f, d, ', '.join(ops))
|
||||||
item = QListWidgetItem(txt)
|
item = QListWidgetItem(txt)
|
||||||
item.setData(Qt.UserRole, (f, d))
|
item.setData(Qt.UserRole, (f, d))
|
||||||
|
if d in self.disabled_devices:
|
||||||
|
item.setFlags(item.flags() & ~Qt.ItemIsEnabled)
|
||||||
self.existing_plugboards.addItem(item)
|
self.existing_plugboards.addItem(item)
|
||||||
self.refilling = False
|
self.refilling = False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user