diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index bde5cae128..9dbc3dee5e 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -417,6 +417,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.multiple_separator.setFixedWidth(30) self.multiple_separator.setText(' ::: ') self.multiple_separator.textChanged.connect(self.s_r_separator_changed) + self.results_count.valueChanged[int].connect(self.s_r_display_bounds_changed) + self.starting_from.valueChanged[int].connect(self.s_r_display_bounds_changed) def s_r_get_field(self, mi, field): if field: @@ -439,6 +441,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): val = [] return val + def s_r_display_bounds_changed(self, i): + self.s_r_search_field_changed(self.search_field.currentIndex()) + def s_r_template_changed(self): self.s_r_search_field_changed(self.search_field.currentIndex()) @@ -454,6 +459,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): mi = self.db.get_metadata(self.ids[i], index_is_id=True) src = unicode(self.search_field.currentText()) t = self.s_r_get_field(mi, src) + if len(t) > 1: + t = t[self.starting_from.value()-1: + self.starting_from.value()-1 + self.results_count.value()] w.setText(unicode(self.multiple_separator.text()).join(t)) if self.search_mode.currentIndex() == 0: @@ -466,12 +474,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): txt = unicode(txt) if not txt: txt = unicode(self.search_field.currentText()) - self.comma_separated.setEnabled(True) if txt and txt in self.writable_fields: self.destination_field_fm = self.db.metadata_for_field(txt) - if self.destination_field_fm['is_multiple']: - self.comma_separated.setEnabled(False) - self.comma_separated.setChecked(True) self.s_r_paint_results(None) def s_r_search_mode_changed(self, val): @@ -542,6 +546,22 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): dest = src dest_mode = self.replace_mode.currentIndex() + if self.destination_field_fm['is_multiple']: + if self.comma_separated.isChecked(): + if dest == 'authors': + splitter = ' & ' + else: + splitter = ',' + + res = [] + for v in val: + for x in v.split(splitter): + if x.strip(): + res.append(x.strip()) + val = res + else: + val = [v.replace(',', '') for v in val] + if dest_mode != 0: dest_val = mi.get(dest, '') if dest_val is None: @@ -602,8 +622,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): try: result = self.s_r_do_regexp(mi) t = self.s_r_do_destination(mi, result) - if len(result) > 1 and self.destination_field_fm is not None and \ - self.destination_field_fm['is_multiple']: + if len(t) > 1 and self.destination_field_fm['is_multiple']: + t = t[self.starting_from.value()-1: + self.starting_from.value()-1 + self.results_count.value()] t = unicode(self.multiple_separator.text()).join(t) else: t = self.s_r_replace_mode_separator().join(t) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index d945909f96..41858b099b 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -658,11 +658,12 @@ If blank, the source field is used if the field is modifiable - Specifies whether a comma should be put between values when copying from a -multiple-valued field to a single-valued field + Specifies whether result items should be split into multiple values or +left as single values. This option has the most effect when the source field is +not multiple and the destination field is multiple - &Use comma + Split &result true @@ -684,28 +685,8 @@ multiple-valued field to a single-valued field - - - - Test text - - - test_text - - - - + - - - - Test result - - - test_result - - - @@ -719,10 +700,62 @@ multiple-valued field to a single-valued field + + + + For multiple-valued fields, sho&w + + + results_count + + + + + + + true + + + 1 + + + 999 + + + 999 + + + + + + + values starting a&t + + + starting_from + + + + + + + true + + + 1 + + + 999 + + + 1 + + + - Multi&ple separator: + with values separated b&y multiple_separator @@ -756,6 +789,20 @@ multiple-valued field to a single-valued field + + + + Test text + + + + + + + Test result + + + @@ -857,6 +904,8 @@ multiple-valued field to a single-valued field destination_field replace_mode comma_separated + results_count + starting_from multiple_separator test_text test_result