diff --git a/src/calibre/gui2/dialogs/sort_field_dialog.py b/src/calibre/gui2/dialogs/edit_authors_dialog.py
similarity index 88%
rename from src/calibre/gui2/dialogs/sort_field_dialog.py
rename to src/calibre/gui2/dialogs/edit_authors_dialog.py
index a73d0d8cf4..8d13f98f7a 100644
--- a/src/calibre/gui2/dialogs/sort_field_dialog.py
+++ b/src/calibre/gui2/dialogs/edit_authors_dialog.py
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
from PyQt4.Qt import Qt, QDialog, QTableWidgetItem, QAbstractItemView
from calibre.ebooks.metadata import author_to_author_sort
-from calibre.gui2.dialogs.sort_field_dialog_ui import Ui_SortFieldDialog
+from calibre.gui2.dialogs.edit_authors_dialog_ui import Ui_EditAuthorsDialog
class tableItem(QTableWidgetItem):
def __ge__(self, other):
@@ -15,11 +15,11 @@ class tableItem(QTableWidgetItem):
def __lt__(self, other):
return unicode(self.text()).lower() < unicode(other.text()).lower()
-class SortFieldDialog(QDialog, Ui_SortFieldDialog):
+class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
def __init__(self, parent, db, id_to_select):
QDialog.__init__(self, parent)
- Ui_SortFieldDialog.__init__(self)
+ Ui_EditAuthorsDialog.__init__(self)
self.setupUi(self)
self.buttonBox.accepted.connect(self.accepted)
@@ -42,22 +42,21 @@ class SortFieldDialog(QDialog, Ui_SortFieldDialog):
self.table.setItem(row, 0, aut)
self.table.setItem(row, 1, sort)
if id == id_to_select:
- select_item = aut
+ select_item = sort
if select_item is not None:
self.table.setCurrentItem(select_item)
+ self.table.editItem(select_item)
self.table.resizeColumnsToContents()
self.table.setSortingEnabled(True)
self.table.sortByColumn(1, Qt.AscendingOrder)
def accepted(self):
- print 'accepted!'
self.result = []
for row in range(0,self.table.rowCount()):
id = self.table.item(row, 0).data(Qt.UserRole).toInt()[0]
aut = unicode(self.table.item(row, 0).text())
sort = unicode(self.table.item(row, 1).text())
- print id, aut, sort
orig_aut,orig_sort = self.authors[id]
if orig_aut != aut or orig_sort != sort:
self.result.append((id, orig_aut, aut, sort))
@@ -68,3 +67,4 @@ class SortFieldDialog(QDialog, Ui_SortFieldDialog):
c = self.table.item(row, 1)
if c is not None:
c.setText(author_to_author_sort(aut))
+ self.table.setCurrentItem(c)
diff --git a/src/calibre/gui2/dialogs/edit_authors_dialog.ui b/src/calibre/gui2/dialogs/edit_authors_dialog.ui
new file mode 100644
index 0000000000..4ac133700f
--- /dev/null
+++ b/src/calibre/gui2/dialogs/edit_authors_dialog.ui
@@ -0,0 +1,89 @@
+
+
+ EditAuthorsDialog
+
+
+
+ 0
+ 0
+ 410
+ 239
+
+
+
+
+ 0
+ 0
+
+
+
+ Manage authors
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ 0
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+ true
+
+
+
+
+ buttonBox
+ table
+ buttonBox
+
+
+
+
+ buttonBox
+ accepted()
+ EditAuthorsDialog
+ accept()
+
+
+ 229
+ 211
+
+
+ 157
+ 234
+
+
+
+
+ buttonBox
+ rejected()
+ EditAuthorsDialog
+ reject()
+
+
+ 297
+ 217
+
+
+ 286
+ 234
+
+
+
+
+
diff --git a/src/calibre/gui2/dialogs/sort_field_dialog.ui b/src/calibre/gui2/dialogs/sort_field_dialog.ui
deleted file mode 100644
index bc6ffae4fc..0000000000
--- a/src/calibre/gui2/dialogs/sort_field_dialog.ui
+++ /dev/null
@@ -1,87 +0,0 @@
-
-
- SortFieldDialog
-
-
-
- 0
- 0
- 518
- 262
-
-
-
-
- 0
- 0
-
-
-
- Edit sort field
-
-
-
-
- 10
- 10
- 501
- 231
-
-
-
- -
-
-
- 0
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
-
-
-
-
-
-
- buttonBox
- accepted()
- SortFieldDialog
- accept()
-
-
- 229
- 211
-
-
- 157
- 234
-
-
-
-
- buttonBox
- rejected()
- SortFieldDialog
- reject()
-
-
- 297
- 217
-
-
- 286
- 234
-
-
-
-
-
diff --git a/src/calibre/gui2/dialogs/tag_list_editor.ui b/src/calibre/gui2/dialogs/tag_list_editor.ui
index 4f57af745b..39076aa1f6 100644
--- a/src/calibre/gui2/dialogs/tag_list_editor.ui
+++ b/src/calibre/gui2/dialogs/tag_list_editor.ui
@@ -121,6 +121,9 @@
QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+ true
+
diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py
index 27d73a0af8..83463128bd 100644
--- a/src/calibre/gui2/tag_view.py
+++ b/src/calibre/gui2/tag_view.py
@@ -23,7 +23,7 @@ from calibre.utils.search_query_parser import saved_searches
from calibre.gui2 import error_dialog
from calibre.gui2.dialogs.tag_categories import TagCategories
from calibre.gui2.dialogs.tag_list_editor import TagListEditor
-from calibre.gui2.dialogs.sort_field_dialog import SortFieldDialog
+from calibre.gui2.dialogs.edit_authors_dialog import EditAuthorsDialog
class TagDelegate(QItemDelegate):
@@ -91,7 +91,7 @@ class TagsView(QTreeView): # {{{
user_category_edit = pyqtSignal(object)
tag_list_edit = pyqtSignal(object, object)
saved_search_edit = pyqtSignal(object)
- author_sort_edit = pyqtSignal(object, object, object)
+ author_sort_edit = pyqtSignal(object, object)
tag_item_renamed = pyqtSignal()
search_item_renamed = pyqtSignal()
@@ -176,7 +176,7 @@ class TagsView(QTreeView): # {{{
self.saved_search_edit.emit(category)
return
if action == 'edit_author_sort':
- self.author_sort_edit.emit(self, category, index)
+ self.author_sort_edit.emit(self, index)
return
if action == 'hide':
self.hidden_categories.add(category)
@@ -199,7 +199,6 @@ class TagsView(QTreeView): # {{{
tag_item = item
tag_name = item.tag.name
tag_id = item.tag.id
- tag_sort = item.tag.sort
item = item.parent
if item.type == TagTreeItem.CATEGORY:
category = unicode(item.name.toString())
@@ -215,13 +214,13 @@ class TagsView(QTreeView): # {{{
(key in ['authors', 'tags', 'series', 'publisher', 'search'] or \
self.db.field_metadata[key]['is_custom'] and \
self.db.field_metadata[key]['datatype'] != 'rating'):
- self.context_menu.addAction(_('Rename') + " '" + tag_name + "'",
+ self.context_menu.addAction(_('Rename \'%s\'')%tag_name,
partial(self.context_menu_handler, action='edit_item',
category=tag_item, index=index))
if key == 'authors':
- self.context_menu.addAction(_('Edit sort for') + " '" + tag_name + "'",
- partial(self.context_menu_handler, action='edit_author_sort',
- category=tag_sort, index=tag_id))
+ self.context_menu.addAction(_('Edit sort for \'%s\'')%tag_name,
+ partial(self.context_menu_handler,
+ action='edit_author_sort', index=tag_id))
self.context_menu.addSeparator()
# Hide/Show/Restore categories
self.context_menu.addAction(_('Hide category %s') % category,
@@ -238,9 +237,12 @@ class TagsView(QTreeView): # {{{
self.context_menu.addSeparator()
if key in ['tags', 'publisher', 'series'] or \
self.db.field_metadata[key]['is_custom']:
- self.context_menu.addAction(_('Manage ') + category,
+ self.context_menu.addAction(_('Manage %s')%category,
partial(self.context_menu_handler, action='open_editor',
category=tag_name, key=key))
+ elif key == 'authors':
+ self.context_menu.addAction(_('Manage %s')%category,
+ partial(self.context_menu_handler, action='edit_author_sort'))
elif key == 'search':
self.context_menu.addAction(_('Manage Saved Searches'),
partial(self.context_menu_handler, action='manage_searches',
@@ -725,16 +727,17 @@ class TagBrowserMixin(object): # {{{
self.saved_search.clear_to_help()
self.search.clear_to_help()
- def do_author_sort_edit(self, parent, text, id):
- editor = SortFieldDialog(parent, self.library_view.model().db, id)
+ def do_author_sort_edit(self, parent, id):
+ db = self.library_view.model().db
+ editor = EditAuthorsDialog(parent, db, id)
d = editor.exec_()
if d:
- print editor.result
for (id, old_author, new_author, new_sort) in editor.result:
if old_author != new_author:
- self.library_view.model().db.rename_author(id, new_author)
- self.library_view.model().db.set_sort_field_for_author \
- (id, unicode(new_sort))
+ # The id might change if the new author already exists
+ id = db.rename_author(id, new_author)
+ db.set_sort_field_for_author(id, unicode(new_sort))
+ self.library_view.model().refresh()
self.tags_view.recount()
# }}}
diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py
index 794474f821..e2302c1c77 100644
--- a/src/calibre/library/database2.py
+++ b/src/calibre/library/database2.py
@@ -1160,6 +1160,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.conn.execute('UPDATE authors SET sort=? WHERE id=?', \
(new_sort, old_id))
self.conn.commit()
+ # Now change all the author_sort fields in books by this author
+ bks = self.conn.get('SELECT book from books_authors_link WHERE author=?', (old_id,))
+ for (book_id,) in bks:
+ ss = self.author_sort_from_book(book_id, index_is_id=True)
+ self.set_author_sort(book_id, ss)
def rename_author(self, old_id, new_name):
# Make sure that any commas in new_name are changed to '|'!
@@ -1186,7 +1191,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.conn.execute('UPDATE authors SET name=? WHERE id=?',
(new_name, old_id))
self.conn.commit()
- return
+ return new_id
# Author exists. To fix this, we must replace all the authors
# instead of replacing the one. Reason: db integrity checks can stop
# the rename process, which would leave everything half-done. We
@@ -1233,6 +1238,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.set_author_sort(book_id, ss)
# the caller will do a general refresh, so we don't need to
# do one here
+ return new_id
# end convenience methods