' + textwrap.fill(base+'
'+
+ ok_tooltip = '
' + textwrap.fill(base+'
'+
_(' The green color indicates that the current '
'author sort matches the current author'))
- self.bad_aus_tooltip = '
'+textwrap.fill(base + '
'+
+ bad_tooltip = '
'+textwrap.fill(base + '
'+
_(' The red color indicates that the current '
- 'author sort does not match the current author'))
+ 'author sort does not match the current author. '
+ 'No action is required if this is what you want.'))
+ self.aus_tooltips = (ok_tooltip, bad_tooltip)
+ base = unicode(self.title_sort.toolTip())
+ ok_tooltip = '
' + textwrap.fill(base+'
'+
+ _(' The green color indicates that the current '
+ 'title sort matches the current title'))
+ bad_tooltip = '
'+textwrap.fill(base + '
'+
+ _(' The red color warns that the current '
+ 'title sort does not match the current title. '
+ 'No action is required if this is what you want.'))
+ self.ts_tooltips = (ok_tooltip, bad_tooltip)
self.row_delta = 0
if prev:
self.prev_button = QPushButton(QIcon(I('back.png')), _('Previous'),
@@ -506,7 +517,13 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
self.remove_unused_series)
QObject.connect(self.auto_author_sort, SIGNAL('clicked()'),
self.deduce_author_sort)
+ QObject.connect(self.auto_title_sort, SIGNAL('clicked()'),
+ self.deduce_title_sort)
self.trim_cover_button.clicked.connect(self.trim_cover)
+ self.connect(self.title_sort, SIGNAL('textChanged(const QString&)'),
+ self.title_sort_box_changed)
+ self.connect(self.title, SIGNAL('textChanged(const QString&)'),
+ self.title_box_changed)
self.connect(self.author_sort, SIGNAL('textChanged(const QString&)'),
self.author_sort_box_changed)
self.connect(self.authors, SIGNAL('editTextChanged(const QString&)'),
@@ -523,6 +540,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
self.title.setText(db.title(row))
+ self.title_sort.setText(db.title_sort(row))
isbn = db.isbn(self.id, index_is_id=True)
if not isbn:
isbn = ''
@@ -598,8 +616,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
w = self.central_widget.widget(1)
layout = w.layout()
self.custom_column_widgets, self.__cc_spacers = \
- populate_metadata_page(layout, self.db, self.id,
- parent=w, bulk=False, two_column=True)
+ populate_metadata_page(layout, self.db, self.id, parent=w, bulk=False,
+ two_column=tweaks['metadata_single_use_2_cols_for_custom_fields'])
self.__custom_col_layouts = [layout]
ans = self.custom_column_widgets
for i in range(len(ans)-1):
@@ -610,27 +628,40 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
for c in range(2, len(ans[i].widgets), 2):
w.setTabOrder(ans[i].widgets[c-1], ans[i].widgets[c+1])
+ def title_box_changed(self, txt):
+ ts = unicode(txt)
+ ts = title_sort(ts)
+ self.mark_box_as_ok(control = self.title_sort, tt=self.ts_tooltips,
+ normal=(unicode(self.title_sort.text()) == ts))
+
+ def title_sort_box_changed(self, txt):
+ ts = unicode(txt)
+ self.mark_box_as_ok(control = self.title_sort, tt=self.ts_tooltips,
+ normal=(title_sort(unicode(self.title.text())) == ts))
+
def authors_box_changed(self, txt):
aus = unicode(txt)
aus = re.sub(r'\s+et al\.$', '', aus)
aus = self.db.author_sort_from_authors(string_to_authors(aus))
- self.mark_author_sort(normal=(unicode(self.author_sort.text()) == aus))
+ self.mark_box_as_ok(control = self.author_sort, tt=self.aus_tooltips,
+ normal=(unicode(self.author_sort.text()) == aus))
def author_sort_box_changed(self, txt):
au = unicode(self.authors.text())
au = re.sub(r'\s+et al\.$', '', au)
au = self.db.author_sort_from_authors(string_to_authors(au))
- self.mark_author_sort(normal=(au == txt))
+ self.mark_box_as_ok(control = self.author_sort, tt=self.aus_tooltips,
+ normal=(au == txt))
- def mark_author_sort(self, normal=True):
+ def mark_box_as_ok(self, control, tt, normal=True):
if normal:
col = 'rgb(0, 255, 0, 20%)'
else:
col = 'rgb(255, 0, 0, 20%)'
- self.author_sort.setStyleSheet('QLineEdit { color: black; '
- 'background-color: %s; }'%col)
- tt = self.ok_aus_tooltip if normal else self.bad_aus_tooltip
- self.author_sort.setToolTip(tt)
+ control.setStyleSheet('QLineEdit { color: black; '
+ 'background-color: %s; }'%col)
+ tt = tt[0] if normal else tt[1]
+ control.setToolTip(tt)
def validate_isbn(self, isbn):
isbn = unicode(isbn).strip()
@@ -652,12 +683,16 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
authors = string_to_authors(au)
self.author_sort.setText(self.db.author_sort_from_authors(authors))
+ def deduce_title_sort(self):
+ ts = unicode(self.title.text())
+ self.title_sort.setText(title_sort(ts))
+
def swap_title_author(self):
title = self.title.text()
self.title.setText(self.authors.text())
self.authors.setText(title)
- self.author_sort.setText('')
-
+ self.deduce_author_sort()
+ self.deduce_title_sort()
def initialize_combos(self):
self.initalize_authors()
@@ -804,7 +839,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
series = unicode(self.series.text()).strip()
if series and series != self.original_series_name:
ns = 1
- if tweaks['series_index_auto_increment'] == 'next':
+ if tweaks['series_index_auto_increment'] != 'const':
ns = self.db.get_next_series_num_for(series)
self.series_index.setValue(ns)
self.original_series_name = series
@@ -838,6 +873,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
title = unicode(self.title.text()).strip()
if title != self.original_title:
self.db.set_title(self.id, title, notify=False)
+ # This must be after setting the title because of the DB update trigger
+ ts = unicode(self.title_sort.text()).strip()
+ if ts:
+ self.db.set_title_sort(self.id, ts, notify=False, commit=False)
au = unicode(self.authors.text()).strip()
if au and au != self.original_author:
self.db.set_authors(self.id, string_to_authors(au), notify=False)
diff --git a/src/calibre/gui2/dialogs/metadata_single.ui b/src/calibre/gui2/dialogs/metadata_single.ui
index 2bd85e30bb..770807b2d7 100644
--- a/src/calibre/gui2/dialogs/metadata_single.ui
+++ b/src/calibre/gui2/dialogs/metadata_single.ui
@@ -100,27 +100,27 @@