mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Speed up setting metadata for tag browser drag & drop. Add series columns.
This commit is contained in:
parent
249ca16c4c
commit
ddcde43f2c
@ -16,10 +16,12 @@ from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, \
|
|||||||
QPushButton, QWidget, QItemDelegate
|
QPushButton, QWidget, QItemDelegate
|
||||||
|
|
||||||
from calibre.ebooks.metadata import title_sort
|
from calibre.ebooks.metadata import title_sort
|
||||||
|
from calibre.ebooks.metadata.book import ALL_METADATA_FIELDS
|
||||||
from calibre.gui2 import config, NONE
|
from calibre.gui2 import config, NONE
|
||||||
from calibre.library.field_metadata import TagsIcons
|
from calibre.library.field_metadata import TagsIcons
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.dialogs.tag_categories import TagCategories
|
from calibre.gui2.dialogs.tag_categories import TagCategories
|
||||||
from calibre.gui2.dialogs.tag_list_editor import TagListEditor
|
from calibre.gui2.dialogs.tag_list_editor import TagListEditor
|
||||||
from calibre.gui2.dialogs.edit_authors_dialog import EditAuthorsDialog
|
from calibre.gui2.dialogs.edit_authors_dialog import EditAuthorsDialog
|
||||||
@ -126,7 +128,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
if item.category_key in \
|
if item.category_key in \
|
||||||
('tags', 'series', 'authors', 'rating', 'publisher') or\
|
('tags', 'series', 'authors', 'rating', 'publisher') or\
|
||||||
(fm['is_custom'] and \
|
(fm['is_custom'] and \
|
||||||
(fm['datatype'] == 'text' or fm['datatype'] == 'rating')):
|
fm['datatype'] in ['text', 'rating', 'series']):
|
||||||
allowed = True
|
allowed = True
|
||||||
if allowed:
|
if allowed:
|
||||||
event.acceptProposedAction()
|
event.acceptProposedAction()
|
||||||
@ -144,7 +146,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
if item.category_key in \
|
if item.category_key in \
|
||||||
('tags', 'series', 'authors', 'rating', 'publisher') or\
|
('tags', 'series', 'authors', 'rating', 'publisher') or\
|
||||||
(fm['is_custom'] and \
|
(fm['is_custom'] and \
|
||||||
(fm['datatype'] == 'text' or fm['datatype'] == 'rating')):
|
fm['datatype'] in ['text', 'rating', 'series']):
|
||||||
child = m.data(idx, Qt.UserRole)
|
child = m.data(idx, Qt.UserRole)
|
||||||
md = event.mimeData()
|
md = event.mimeData()
|
||||||
mime = 'application/calibre+from_library'
|
mime = 'application/calibre+from_library'
|
||||||
@ -155,6 +157,17 @@ class TagsView(QTreeView): # {{{
|
|||||||
def handle_drop(self, parent, child, ids):
|
def handle_drop(self, parent, child, ids):
|
||||||
# print 'Dropped ids:', ids, parent.category_key, child.tag.name
|
# print 'Dropped ids:', ids, parent.category_key, child.tag.name
|
||||||
key = parent.category_key
|
key = parent.category_key
|
||||||
|
if (key == 'authors' and len(ids) >= 5):
|
||||||
|
if not confirm('<p>'+_('Changing the authors for several books can '
|
||||||
|
'take a while. Are you sure?')
|
||||||
|
+'</p>', 'tag_browser_drop_authors', self):
|
||||||
|
return
|
||||||
|
elif len(ids) > 15:
|
||||||
|
if not confirm('<p>'+_('Changing the metadata for that many books '
|
||||||
|
'can take a while. Are you sure?')
|
||||||
|
+'</p>', 'tag_browser_many_changes', self):
|
||||||
|
return
|
||||||
|
|
||||||
fm = self.db.metadata_for_field(key)
|
fm = self.db.metadata_for_field(key)
|
||||||
is_multiple = fm['is_multiple']
|
is_multiple = fm['is_multiple']
|
||||||
val = child.tag.name
|
val = child.tag.name
|
||||||
@ -174,6 +187,8 @@ class TagsView(QTreeView): # {{{
|
|||||||
set_authors=True
|
set_authors=True
|
||||||
elif fm['datatype'] == 'rating':
|
elif fm['datatype'] == 'rating':
|
||||||
mi.set(key, len(val) * 2)
|
mi.set(key, len(val) * 2)
|
||||||
|
elif fm['is_custom'] and fm['datatype'] == 'series':
|
||||||
|
mi.set(key, val, extra=1.0)
|
||||||
elif is_multiple:
|
elif is_multiple:
|
||||||
new_val = mi.get(key, [])
|
new_val = mi.get(key, [])
|
||||||
if val in new_val:
|
if val in new_val:
|
||||||
@ -185,7 +200,8 @@ class TagsView(QTreeView): # {{{
|
|||||||
else:
|
else:
|
||||||
mi.set(key, val)
|
mi.set(key, val)
|
||||||
self.db.set_metadata(id, mi, set_title=False,
|
self.db.set_metadata(id, mi, set_title=False,
|
||||||
set_authors=set_authors)
|
set_authors=set_authors, commit=False)
|
||||||
|
self.db.commit()
|
||||||
self.drag_drop_finished.emit(ids)
|
self.drag_drop_finished.emit(ids)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1248,7 +1248,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
|
||||||
def set_metadata(self, id, mi, ignore_errors=False,
|
def set_metadata(self, id, mi, ignore_errors=False,
|
||||||
set_title=True, set_authors=True):
|
set_title=True, set_authors=True, commit=True):
|
||||||
'''
|
'''
|
||||||
Set metadata for the book `id` from the `Metadata` object `mi`
|
Set metadata for the book `id` from the `Metadata` object `mi`
|
||||||
'''
|
'''
|
||||||
@ -1306,7 +1306,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
val=mi.get(key),
|
val=mi.get(key),
|
||||||
extra=mi.get_extra(key),
|
extra=mi.get_extra(key),
|
||||||
label=user_mi[key]['label'], commit=False)
|
label=user_mi[key]['label'], commit=False)
|
||||||
self.conn.commit()
|
if commit:
|
||||||
|
self.conn.commit()
|
||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
|
||||||
def authors_sort_strings(self, id, index_is_id=False):
|
def authors_sort_strings(self, id, index_is_id=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user