In edit metadata single:

1) Correct implementation of author case change
2) Add a cancel button to the 'save' dialogs
3) Select the first author in Manage Authors
This commit is contained in:
Charles Haley 2011-05-06 06:04:16 +01:00
parent 4ee65e6b27
commit 399d94bd3f
4 changed files with 50 additions and 18 deletions

View File

@ -19,7 +19,7 @@ class tableItem(QTableWidgetItem):
class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
def __init__(self, parent, db, id_to_select): def __init__(self, parent, db, id_to_select, select_sort):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
Ui_EditAuthorsDialog.__init__(self) Ui_EditAuthorsDialog.__init__(self)
self.setupUi(self) self.setupUi(self)
@ -48,7 +48,10 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
self.table.setItem(row, 0, aut) self.table.setItem(row, 0, aut)
self.table.setItem(row, 1, sort) self.table.setItem(row, 1, sort)
if id == id_to_select: if id == id_to_select:
select_item = sort if select_sort:
select_item = sort
else:
select_item = aut
self.table.resizeColumnsToContents() self.table.resizeColumnsToContents()
# set up the cellChanged signal only after the table is filled # set up the cellChanged signal only after the table is filled

View File

@ -8,8 +8,9 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import textwrap, re, os import textwrap, re, os
from functools import partial
from PyQt4.Qt import (Qt, QDateEdit, QDate, pyqtSignal, from PyQt4.Qt import (Qt, QDateEdit, QDate, pyqtSignal, QMessageBox,
QIcon, QToolButton, QWidget, QLabel, QGridLayout, QIcon, QToolButton, QWidget, QLabel, QGridLayout,
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, QDoubleSpinBox, QListWidgetItem, QSize, QPixmap,
QPushButton, QSpinBox, QLineEdit, QSizePolicy) QPushButton, QSpinBox, QLineEdit, QSizePolicy)
@ -31,6 +32,16 @@ from calibre.utils.date import utcfromtimestamp
from calibre.gui2.comments_editor import Editor from calibre.gui2.comments_editor import Editor
from calibre.library.comments import comments_to_html from calibre.library.comments import comments_to_html
from calibre.gui2.dialogs.tag_editor import TagEditor from calibre.gui2.dialogs.tag_editor import TagEditor
from calibre.utils.icu import strcmp
def save_dialog(parent, title, msg, det_msg=''):
d = QMessageBox(parent)
d.setWindowTitle(title)
d.setText(msg)
d.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
return d.exec_()
''' '''
The interface common to all widgets used to set basic metadata The interface common to all widgets used to set basic metadata
@ -168,16 +179,22 @@ class AuthorsEdit(MultiCompleteComboBox):
def manage_authors(self): def manage_authors(self):
if self.original_val != self.current_val: if self.original_val != self.current_val:
if (question_dialog(self, _('Authors changed'), d = save_dialog(self, _('Authors changed'),
_('You have changed the authors for this book. You must save ' _('You have changed the authors for this book. You must save '
'these changes before you can use Manage authors. Do you ' 'these changes before you can use Manage authors. Do you '
'want to save these changes?'), show_copy_button=False)): 'want to save these changes?'))
if d == QMessageBox.Cancel:
return
if d == QMessageBox.Yes:
self.commit(self.db, self.id_) self.commit(self.db, self.id_)
self.db.commit() self.db.commit()
self.original_val = self.current_val self.original_val = self.current_val
else: else:
self.current_val = self.original_val self.current_val = self.original_val
self.dialog.parent().do_author_sort_edit(self, self.id_) first_author = self.current_val[0] if len(self.current_val) else None
self.dialog.parent().do_author_sort_edit(self,
self.db.get_author_id(first_author),
select_sort=False)
self.initialize(self.db, self.id_) self.initialize(self.db, self.id_)
self.dialog.author_sort.initialize(self.db, self.id_) self.dialog.author_sort.initialize(self.db, self.id_)
@ -256,13 +273,13 @@ class AuthorSortEdit(EnLineEdit):
'No action is required if this is what you want.')) 'No action is required if this is what you want.'))
self.tooltips = (ok_tooltip, bad_tooltip) self.tooltips = (ok_tooltip, bad_tooltip)
self.authors_edit.editTextChanged.connect(self.update_state) self.authors_edit.editTextChanged.connect(partial(self.update_state, True))
self.textChanged.connect(self.update_state) self.textChanged.connect(partial(self.update_state, False))
autogen_button.clicked.connect(self.auto_generate) autogen_button.clicked.connect(self.auto_generate)
copy_a_to_as_action.triggered.connect(self.auto_generate) copy_a_to_as_action.triggered.connect(self.auto_generate)
copy_as_to_a_action.triggered.connect(self.copy_to_authors) copy_as_to_a_action.triggered.connect(self.copy_to_authors)
self.update_state() self.update_state(False)
@dynamic_property @dynamic_property
def current_val(self): def current_val(self):
@ -278,12 +295,16 @@ class AuthorSortEdit(EnLineEdit):
return property(fget=fget, fset=fset) return property(fget=fget, fset=fset)
def update_state(self, *args): def update_state(self, modify_aus, *args):
au = unicode(self.authors_edit.text()) au = unicode(self.authors_edit.text())
# Handle case change if the authors box changed
if modify_aus and strcmp(au, self.current_val) == 0:
self.current_val = au
au = re.sub(r'\s+et al\.$', '', au) au = re.sub(r'\s+et al\.$', '', au)
au = self.db.author_sort_from_authors(string_to_authors(au)) au = self.db.author_sort_from_authors(string_to_authors(au))
normal = au == self.current_val normal = strcmp(au, self.current_val) == 0
if normal: if normal:
col = 'rgb(0, 255, 0, 20%)' col = 'rgb(0, 255, 0, 20%)'
else: else:
@ -316,12 +337,11 @@ class AuthorSortEdit(EnLineEdit):
self.current_val = self.db.author_sort_from_authors(authors) self.current_val = self.db.author_sort_from_authors(authors)
def initialize(self, db, id_): def initialize(self, db, id_):
self.current_val = self.original_val = db.author_sort(id_, index_is_id=True) self.current_val = db.author_sort(id_, index_is_id=True)
def commit(self, db, id_): def commit(self, db, id_):
aus = self.current_val aus = self.current_val
if aus != self.original_val: db.set_author_sort(id_, aus, notify=False, commit=False)
db.set_author_sort(id_, aus, notify=False, commit=False)
return True return True
# }}} # }}}
@ -919,10 +939,13 @@ class TagsEdit(MultiCompleteLineEdit): # {{{
def edit(self, db, id_): def edit(self, db, id_):
if self.changed: if self.changed:
if question_dialog(self, _('Tags changed'), d = save_dialog(self, _('Tags changed'),
_('You have changed the tags. In order to use the tags' _('You have changed the tags. In order to use the tags'
' editor, you must either discard or apply these ' ' editor, you must either discard or apply these '
'changes. Apply changes?'), show_copy_button=False): 'changes. Apply changes?'))
if d == QMessageBox.Cancel:
return
if d == QMessageBox.Yes:
self.commit(db, id_) self.commit(db, id_)
db.commit() db.commit()
self.original_val = self.current_val self.original_val = self.current_val

View File

@ -2048,12 +2048,12 @@ class TagBrowserMixin(object): # {{{
self.library_view.select_rows(ids) self.library_view.select_rows(ids)
# refreshing the tags view happens at the emit()/call() site # refreshing the tags view happens at the emit()/call() site
def do_author_sort_edit(self, parent, id): def do_author_sort_edit(self, parent, id, select_sort=True):
''' '''
Open the manage authors dialog Open the manage authors dialog
''' '''
db = self.library_view.model().db db = self.library_view.model().db
editor = EditAuthorsDialog(parent, db, id) editor = EditAuthorsDialog(parent, db, id, select_sort)
d = editor.exec_() d = editor.exec_()
if d: if d:
for (id, old_author, new_author, new_sort) in editor.result: for (id, old_author, new_author, new_sort) in editor.result:

View File

@ -2285,6 +2285,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
return [] return []
return result return result
def get_author_id(self, author):
author = author.replace(',', '|')
result = self.conn.get('SELECT id FROM authors WHERE name=?',
(author,), all=False)
return result
def set_sort_field_for_author(self, old_id, new_sort, commit=True, notify=False): def set_sort_field_for_author(self, old_id, new_sort, commit=True, notify=False):
self.conn.execute('UPDATE authors SET sort=? WHERE id=?', \ self.conn.execute('UPDATE authors SET sort=? WHERE id=?', \
(new_sort.strip(), old_id)) (new_sort.strip(), old_id))