mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Enhancement #1360766: show plugboards for disabled devices and allow entering plugboards when no metadata writer is enabled.
This commit is contained in:
parent
fdbaf04456
commit
c73d87a71d
@ -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 not f 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 == '':
|
||||||
@ -272,6 +295,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 +344,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 +373,8 @@ 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,
|
||||||
|
cmp=lambda x, y: cmp(x.lower(), y.lower())):
|
||||||
if d not in self.current_plugboards[f]:
|
if d not in self.current_plugboards[f]:
|
||||||
continue
|
continue
|
||||||
ops = []
|
ops = []
|
||||||
@ -353,6 +383,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