mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) Add validation to plugboard gui
2) allow plugboards to use metadata fields with no field metadata (e.g., language)
This commit is contained in:
parent
5aadbb2dcd
commit
1b41568d4c
@ -308,7 +308,7 @@ class Metadata(object):
|
||||
val = composite_formatter.safe_format\
|
||||
(src, other, 'PLUGBOARD TEMPLATE ERROR', other)
|
||||
dfm = self.metadata_for_field(attrs[src])
|
||||
if dfm['is_multiple']:
|
||||
if dfm and dfm['is_multiple']:
|
||||
self.set(attrs[src],
|
||||
[f.strip() for f in val.split(',') if f.strip()])
|
||||
else:
|
||||
|
@ -13,6 +13,7 @@ from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
||||
from calibre.customize.ui import metadata_writers, device_plugins
|
||||
from calibre.library.save_to_disk import plugboard_any_format_value, \
|
||||
plugboard_any_device_value, plugboard_save_to_disk_value
|
||||
from calibre.utils.formatter import validation_formatter
|
||||
|
||||
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
|
||||
@ -62,12 +63,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.source_fields.append(f)
|
||||
self.source_fields.sort(cmp=field_cmp)
|
||||
|
||||
self.dest_fields = ['', 'authors', 'author_sort', 'publisher',
|
||||
'tags', 'title']
|
||||
self.dest_fields = ['',
|
||||
'authors', 'author_sort', 'language', 'publisher',
|
||||
'tags', 'title', 'title_sort']
|
||||
|
||||
self.source_widgets = []
|
||||
self.dest_widgets = []
|
||||
for i in range(0, 10):
|
||||
for i in range(0, len(self.dest_fields)-1):
|
||||
w = QtGui.QLineEdit(self)
|
||||
self.source_widgets.append(w)
|
||||
self.fields_layout.addWidget(w, 5+i, 0, 1, 1)
|
||||
@ -220,7 +222,20 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
if s:
|
||||
d = self.dest_widgets[i].currentIndex()
|
||||
if d != 0:
|
||||
try:
|
||||
validation_formatter.validate(s)
|
||||
except Exception, err:
|
||||
error_dialog(self, _('Invalid template'),
|
||||
'<p>'+_('The template %s is invalid:')%s + \
|
||||
'<br>'+str(err), show=True)
|
||||
return
|
||||
pb[s] = self.dest_fields[d]
|
||||
else:
|
||||
error_dialog(self, _('Invalid destination'),
|
||||
'<p>'+_('The destination field cannot be blank'),
|
||||
show=True)
|
||||
return
|
||||
|
||||
if len(pb) == 0:
|
||||
if self.current_format in self.current_plugboards:
|
||||
fpb = self.current_plugboards[self.current_format]
|
||||
|
@ -17,7 +17,12 @@
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Here you can control what metadata calibre uses when saving or sending books:</string>
|
||||
<string>Here you can change the metadata calibre uses when saving or sending books. One possibility is to alter the title to contain series informaton. Another would be to change the author sort.
|
||||
|
||||
Use this dialog to define for a format (or all formats) and a device (or all devices) the template to be used to find the value to assign to a destination field. Often the templates will contain simple references to composite columns, but this is not necessary. You can put arbitrary templates in the source box.</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
@ -129,7 +134,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="20" column="0">
|
||||
<item row="21" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -143,18 +148,61 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="19" column="0">
|
||||
<widget class="QPushButton" name="ok_button">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="19" column="1">
|
||||
<widget class="QPushButton" name="del_button">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ok_button">
|
||||
<property name="text">
|
||||
<string>Save plugboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="del_button">
|
||||
<property name="text">
|
||||
<string>Delete plugboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user