mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improve search/replace handling of is_multiple fields
This commit is contained in:
parent
1fa911c8c9
commit
c0c4df77ca
@ -417,6 +417,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
self.multiple_separator.setFixedWidth(30)
|
self.multiple_separator.setFixedWidth(30)
|
||||||
self.multiple_separator.setText(' ::: ')
|
self.multiple_separator.setText(' ::: ')
|
||||||
self.multiple_separator.textChanged.connect(self.s_r_separator_changed)
|
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):
|
def s_r_get_field(self, mi, field):
|
||||||
if field:
|
if field:
|
||||||
@ -439,6 +441,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
val = []
|
val = []
|
||||||
return 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):
|
def s_r_template_changed(self):
|
||||||
self.s_r_search_field_changed(self.search_field.currentIndex())
|
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)
|
mi = self.db.get_metadata(self.ids[i], index_is_id=True)
|
||||||
src = unicode(self.search_field.currentText())
|
src = unicode(self.search_field.currentText())
|
||||||
t = self.s_r_get_field(mi, src)
|
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))
|
w.setText(unicode(self.multiple_separator.text()).join(t))
|
||||||
|
|
||||||
if self.search_mode.currentIndex() == 0:
|
if self.search_mode.currentIndex() == 0:
|
||||||
@ -466,12 +474,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
txt = unicode(txt)
|
txt = unicode(txt)
|
||||||
if not txt:
|
if not txt:
|
||||||
txt = unicode(self.search_field.currentText())
|
txt = unicode(self.search_field.currentText())
|
||||||
self.comma_separated.setEnabled(True)
|
|
||||||
if txt and txt in self.writable_fields:
|
if txt and txt in self.writable_fields:
|
||||||
self.destination_field_fm = self.db.metadata_for_field(txt)
|
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)
|
self.s_r_paint_results(None)
|
||||||
|
|
||||||
def s_r_search_mode_changed(self, val):
|
def s_r_search_mode_changed(self, val):
|
||||||
@ -542,6 +546,22 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
dest = src
|
dest = src
|
||||||
dest_mode = self.replace_mode.currentIndex()
|
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:
|
if dest_mode != 0:
|
||||||
dest_val = mi.get(dest, '')
|
dest_val = mi.get(dest, '')
|
||||||
if dest_val is None:
|
if dest_val is None:
|
||||||
@ -602,8 +622,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
try:
|
try:
|
||||||
result = self.s_r_do_regexp(mi)
|
result = self.s_r_do_regexp(mi)
|
||||||
t = self.s_r_do_destination(mi, result)
|
t = self.s_r_do_destination(mi, result)
|
||||||
if len(result) > 1 and self.destination_field_fm is not None and \
|
if len(t) > 1 and self.destination_field_fm['is_multiple']:
|
||||||
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)
|
t = unicode(self.multiple_separator.text()).join(t)
|
||||||
else:
|
else:
|
||||||
t = self.s_r_replace_mode_separator().join(t)
|
t = self.s_r_replace_mode_separator().join(t)
|
||||||
|
@ -658,11 +658,12 @@ If blank, the source field is used if the field is modifiable</string>
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="comma_separated">
|
<widget class="QCheckBox" name="comma_separated">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Specifies whether a comma should be put between values when copying from a
|
<string>Specifies whether result items should be split into multiple values or
|
||||||
multiple-valued field to a single-valued field</string>
|
left as single values. This option has the most effect when the source field is
|
||||||
|
not multiple and the destination field is multiple</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Use comma</string>
|
<string>Split &result</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@ -684,28 +685,8 @@ multiple-valued field to a single-valued field</string>
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="1">
|
<item row="8" column="1" colspan="2">
|
||||||
<widget class="QLabel" name="xlabel_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Test text</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>test_text</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="2">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_21">
|
<layout class="QHBoxLayout" name="horizontalLayout_21">
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_51">
|
|
||||||
<property name="text">
|
|
||||||
<string>Test result</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>test_result</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="HSpacer_347">
|
<spacer name="HSpacer_347">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -719,10 +700,62 @@ multiple-valued field to a single-valued field</string>
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="xlabel_412">
|
||||||
|
<property name="text">
|
||||||
|
<string>For multiple-valued fields, sho&w</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>results_count</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="results_count">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>999</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>999</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="xlabel_412">
|
||||||
|
<property name="text">
|
||||||
|
<string>values starting a&t</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>starting_from</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="starting_from">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>999</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="xlabel_41">
|
<widget class="QLabel" name="xlabel_41">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Multi&ple separator:</string>
|
<string>with values separated b&y</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
<property name="buddy">
|
||||||
<cstring>multiple_separator</cstring>
|
<cstring>multiple_separator</cstring>
|
||||||
@ -756,6 +789,20 @@ multiple-valued field to a single-valued field</string>
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="testgrid">
|
<layout class="QGridLayout" name="testgrid">
|
||||||
|
<item row="7" column="1">
|
||||||
|
<widget class="QLabel" name="xlabel_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Test text</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="2">
|
||||||
|
<widget class="QLabel" name="xlabel_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Test result</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="8" column="0">
|
||||||
<widget class="QLabel" name="label_31">
|
<widget class="QLabel" name="label_31">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -857,6 +904,8 @@ multiple-valued field to a single-valued field</string>
|
|||||||
<tabstop>destination_field</tabstop>
|
<tabstop>destination_field</tabstop>
|
||||||
<tabstop>replace_mode</tabstop>
|
<tabstop>replace_mode</tabstop>
|
||||||
<tabstop>comma_separated</tabstop>
|
<tabstop>comma_separated</tabstop>
|
||||||
|
<tabstop>results_count</tabstop>
|
||||||
|
<tabstop>starting_from</tabstop>
|
||||||
<tabstop>multiple_separator</tabstop>
|
<tabstop>multiple_separator</tabstop>
|
||||||
<tabstop>test_text</tabstop>
|
<tabstop>test_text</tabstop>
|
||||||
<tabstop>test_result</tabstop>
|
<tabstop>test_result</tabstop>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user