mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A few changes to improve robustness. Also some cosmetic changes.
This commit is contained in:
parent
f12b0ff54b
commit
eb205aee6f
@ -31,9 +31,12 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
result = db.get_publishers_with_ids()
|
result = db.get_publishers_with_ids()
|
||||||
compare = (lambda x,y:cmp(x.lower(), y.lower()))
|
compare = (lambda x,y:cmp(x.lower(), y.lower()))
|
||||||
else: # should be a custom field
|
else: # should be a custom field
|
||||||
|
self.cc_label = None
|
||||||
|
if category in db.field_metadata:
|
||||||
self.cc_label = db.field_metadata[category]['label']
|
self.cc_label = db.field_metadata[category]['label']
|
||||||
print 'here', self.cc_label
|
|
||||||
result = self.db.get_custom_items_with_ids(label=self.cc_label)
|
result = self.db.get_custom_items_with_ids(label=self.cc_label)
|
||||||
|
else:
|
||||||
|
result = []
|
||||||
compare = (lambda x,y:cmp(x.lower(), y.lower()))
|
compare = (lambda x,y:cmp(x.lower(), y.lower()))
|
||||||
|
|
||||||
for k,v in result:
|
for k,v in result:
|
||||||
|
@ -135,8 +135,12 @@ class TagsView(QTreeView): # {{{
|
|||||||
if item.type == TagTreeItem.CATEGORY:
|
if item.type == TagTreeItem.CATEGORY:
|
||||||
category = unicode(item.name.toString())
|
category = unicode(item.name.toString())
|
||||||
key = item.category_key
|
key = item.category_key
|
||||||
|
# Verify that we are working with a field that we know something about
|
||||||
|
if key not in self.db.field_metadata:
|
||||||
|
return True
|
||||||
|
|
||||||
self.context_menu = QMenu(self)
|
self.context_menu = QMenu(self)
|
||||||
# If the user right-clicked on a tag/series/publisher, then offer
|
# If the user right-clicked on an editable item, then offer
|
||||||
# the possibility of renaming that item
|
# the possibility of renaming that item
|
||||||
if tag_name and \
|
if tag_name and \
|
||||||
(key in ['authors', 'tags', 'series', 'publisher', 'search'] or \
|
(key in ['authors', 'tags', 'series', 'publisher', 'search'] or \
|
||||||
@ -378,7 +382,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if category in data: # They should always be there, but ...
|
if category in data: # They should always be there, but ...
|
||||||
# make a map of sets of names per category for duplicate
|
# make a map of sets of names per category for duplicate
|
||||||
# checking when editing
|
# checking when editing
|
||||||
self.category_items[category] = [tag.name for tag in data[category]]
|
self.category_items[category] = set([tag.name for tag in data[category]])
|
||||||
self.row_map.append(category)
|
self.row_map.append(category)
|
||||||
self.categories.append(tb_categories[category]['name'])
|
self.categories.append(tb_categories[category]['name'])
|
||||||
|
|
||||||
@ -425,13 +429,16 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
error_dialog(self.tags_view, _('Item is blank'),
|
error_dialog(self.tags_view, _('Item is blank'),
|
||||||
_('An item cannot be set to nothing. Delete it instead.')).exec_()
|
_('An item cannot be set to nothing. Delete it instead.')).exec_()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
item = index.internalPointer()
|
item = index.internalPointer()
|
||||||
key = item.parent.category_key
|
key = item.parent.category_key
|
||||||
|
# make certain we know about the category
|
||||||
|
if key not in self.db.field_metadata:
|
||||||
|
return
|
||||||
if val in self.category_items[key]:
|
if val in self.category_items[key]:
|
||||||
error_dialog(self.tags_view, 'Duplicate item',
|
error_dialog(self.tags_view, 'Duplicate item',
|
||||||
_('The name %s is already used.')%val).exec_()
|
_('The name %s is already used.')%val).exec_()
|
||||||
return False
|
return False
|
||||||
|
oldval = item.tag.name
|
||||||
if key == 'search':
|
if key == 'search':
|
||||||
saved_searches.rename(unicode(item.data(role).toString()), val)
|
saved_searches.rename(unicode(item.data(role).toString()), val)
|
||||||
self.tags_view.search_item_renamed.emit()
|
self.tags_view.search_item_renamed.emit()
|
||||||
@ -449,7 +456,10 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
label=self.db.field_metadata[key]['label'])
|
label=self.db.field_metadata[key]['label'])
|
||||||
self.tags_view.tag_item_renamed.emit()
|
self.tags_view.tag_item_renamed.emit()
|
||||||
item.tag.name = val
|
item.tag.name = val
|
||||||
self.refresh()
|
self.dataChanged.emit(index, index)
|
||||||
|
# replace the old value in the duplicate detection map with the new one
|
||||||
|
self.category_items[key].discard(oldval)
|
||||||
|
self.category_items[key].add(val)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def headerData(self, *args):
|
def headerData(self, *args):
|
||||||
|
@ -986,6 +986,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
|
||||||
# Convenience methods for tags_list_editor
|
# Convenience methods for tags_list_editor
|
||||||
|
# Note: we generally do not need to refresh_ids because library_view will
|
||||||
|
# refresh everything.
|
||||||
def get_tags_with_ids(self):
|
def get_tags_with_ids(self):
|
||||||
result = self.conn.get('SELECT id,name FROM tags')
|
result = self.conn.get('SELECT id,name FROM tags')
|
||||||
if not result:
|
if not result:
|
||||||
@ -1017,11 +1019,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
def delete_series_using_id(self, id):
|
def delete_series_using_id(self, id):
|
||||||
if id:
|
if id:
|
||||||
books = self.conn.get('SELECT book from books_series_link WHERE series=?', (id,))
|
books = self.conn.get('SELECT book from books_series_link WHERE series=?', (id,))
|
||||||
for (book_id,) in books:
|
|
||||||
self.conn.execute('UPDATE books SET series_index=1.0 WHERE id=?', (book_id,))
|
|
||||||
self.conn.execute('DELETE FROM books_series_link WHERE series=?', (id,))
|
self.conn.execute('DELETE FROM books_series_link WHERE series=?', (id,))
|
||||||
self.conn.execute('DELETE FROM series WHERE id=?', (id,))
|
self.conn.execute('DELETE FROM series WHERE id=?', (id,))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
for (book_id,) in books:
|
||||||
|
self.conn.execute('UPDATE books SET series_index=1.0 WHERE id=?', (book_id,))
|
||||||
|
|
||||||
def get_publishers_with_ids(self):
|
def get_publishers_with_ids(self):
|
||||||
result = self.conn.get('SELECT id,name FROM publishers')
|
result = self.conn.get('SELECT id,name FROM publishers')
|
||||||
@ -1040,6 +1042,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.conn.execute('DELETE FROM publishers WHERE id=?', (id,))
|
self.conn.execute('DELETE FROM publishers WHERE id=?', (id,))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
|
# There is no editor for author, so we do not need get_authors_with_ids or
|
||||||
|
# delete_author_using_id.
|
||||||
def rename_author(self, id, new_name):
|
def rename_author(self, id, new_name):
|
||||||
if id:
|
if id:
|
||||||
# Make sure that any commas in new_name are changed to '|'!
|
# Make sure that any commas in new_name are changed to '|'!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user