From 1b41568d4c9aa67331041a09210faa1299345e29 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 29 Sep 2010 15:12:01 +0100 Subject: [PATCH] 1) Add validation to plugboard gui 2) allow plugboards to use metadata fields with no field metadata (e.g., language) --- src/calibre/ebooks/metadata/book/base.py | 2 +- src/calibre/gui2/preferences/plugboard.py | 21 ++++++- src/calibre/gui2/preferences/plugboard.ui | 76 ++++++++++++++++++----- 3 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 56df573cee..17aa2d5603 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -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: diff --git a/src/calibre/gui2/preferences/plugboard.py b/src/calibre/gui2/preferences/plugboard.py index 011131ae48..3742eb24d0 100644 --- a/src/calibre/gui2/preferences/plugboard.py +++ b/src/calibre/gui2/preferences/plugboard.py @@ -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'), + '

'+_('The template %s is invalid:')%s + \ + '
'+str(err), show=True) + return pb[s] = self.dest_fields[d] + else: + error_dialog(self, _('Invalid destination'), + '

'+_('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] diff --git a/src/calibre/gui2/preferences/plugboard.ui b/src/calibre/gui2/preferences/plugboard.ui index 79a07be1f7..4a3192aab5 100644 --- a/src/calibre/gui2/preferences/plugboard.ui +++ b/src/calibre/gui2/preferences/plugboard.ui @@ -17,7 +17,12 @@ - Here you can control what metadata calibre uses when saving or sending books: + 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. + + + Qt::PlainText true @@ -129,7 +134,7 @@ - + Qt::Vertical @@ -143,18 +148,61 @@ - - - Save - - - - - - - Delete - - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Save plugboard + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Delete plugboard + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + +