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:
Charles Haley 2010-09-29 15:12:01 +01:00
parent 5aadbb2dcd
commit 1b41568d4c
3 changed files with 81 additions and 18 deletions

View File

@ -308,7 +308,7 @@ class Metadata(object):
val = composite_formatter.safe_format\ val = composite_formatter.safe_format\
(src, other, 'PLUGBOARD TEMPLATE ERROR', other) (src, other, 'PLUGBOARD TEMPLATE ERROR', other)
dfm = self.metadata_for_field(attrs[src]) dfm = self.metadata_for_field(attrs[src])
if dfm['is_multiple']: if dfm and dfm['is_multiple']:
self.set(attrs[src], self.set(attrs[src],
[f.strip() for f in val.split(',') if f.strip()]) [f.strip() for f in val.split(',') if f.strip()])
else: else:

View File

@ -13,6 +13,7 @@ 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
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
from calibre.utils.formatter import validation_formatter
class ConfigWidget(ConfigWidgetBase, Ui_Form): class ConfigWidget(ConfigWidgetBase, Ui_Form):
@ -62,12 +63,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.source_fields.append(f) self.source_fields.append(f)
self.source_fields.sort(cmp=field_cmp) self.source_fields.sort(cmp=field_cmp)
self.dest_fields = ['', 'authors', 'author_sort', 'publisher', self.dest_fields = ['',
'tags', 'title'] 'authors', 'author_sort', 'language', 'publisher',
'tags', 'title', 'title_sort']
self.source_widgets = [] self.source_widgets = []
self.dest_widgets = [] self.dest_widgets = []
for i in range(0, 10): for i in range(0, len(self.dest_fields)-1):
w = QtGui.QLineEdit(self) w = QtGui.QLineEdit(self)
self.source_widgets.append(w) self.source_widgets.append(w)
self.fields_layout.addWidget(w, 5+i, 0, 1, 1) self.fields_layout.addWidget(w, 5+i, 0, 1, 1)
@ -220,7 +222,20 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
if s: if s:
d = self.dest_widgets[i].currentIndex() d = self.dest_widgets[i].currentIndex()
if d != 0: 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] 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 len(pb) == 0:
if self.current_format in self.current_plugboards: if self.current_format in self.current_plugboards:
fpb = self.current_plugboards[self.current_format] fpb = self.current_plugboards[self.current_format]

View File

@ -17,7 +17,12 @@
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <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>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -129,7 +134,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="20" column="0"> <item row="21" column="0">
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -143,19 +148,62 @@
</spacer> </spacer>
</item> </item>
<item row="19" column="0"> <item row="19" column="0">
<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"> <widget class="QPushButton" name="ok_button">
<property name="text"> <property name="text">
<string>Save</string> <string>Save plugboard</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="19" column="1"> <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"> <widget class="QPushButton" name="del_button">
<property name="text"> <property name="text">
<string>Delete</string> <string>Delete plugboard</string>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
</layout> </layout>