mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Show progress dialog to give user feedback that something is happening when applying bulk metadata edit
This commit is contained in:
parent
8b40b9f22c
commit
8d9a4164b4
@ -174,8 +174,14 @@ class EditMetadataAction(InterfaceAction):
|
||||
_('No books selected'))
|
||||
d.exec_()
|
||||
return
|
||||
if MetadataBulkDialog(self.gui, rows,
|
||||
self.gui.library_view.model().db).changed:
|
||||
# Prevent the TagView from updating due to signals from the database
|
||||
self.gui.tags_view.blockSignals(True)
|
||||
try:
|
||||
changed = MetadataBulkDialog(self.gui, rows,
|
||||
self.gui.library_view.model().db).changed
|
||||
finally:
|
||||
self.gui.tags_view.blockSignals(False)
|
||||
if changed:
|
||||
self.gui.library_view.model().resort(reset=False)
|
||||
self.gui.library_view.model().research()
|
||||
self.gui.tags_view.recount()
|
||||
|
@ -11,7 +11,7 @@ from functools import partial
|
||||
from PyQt4.Qt import QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateEdit, \
|
||||
QDate, QGroupBox, QVBoxLayout, QPlainTextEdit, QSizePolicy, \
|
||||
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, SIGNAL, \
|
||||
QPushButton
|
||||
QPushButton, QCoreApplication
|
||||
|
||||
from calibre.utils.date import qt_to_dt, now
|
||||
from calibre.gui2.widgets import TagsLineEdit, EnComboBox
|
||||
@ -406,6 +406,7 @@ class BulkBase(Base):
|
||||
def commit(self, book_ids, notify=False):
|
||||
if self.process_each_book():
|
||||
for book_id in book_ids:
|
||||
QCoreApplication.processEvents()
|
||||
val = self.db.get_custom(book_id, num=self.col_id, index_is_id=True)
|
||||
new_val = self.getter(val)
|
||||
if set(val) != new_val:
|
||||
@ -415,6 +416,7 @@ class BulkBase(Base):
|
||||
val = self.normalize_ui_val(val)
|
||||
if val != self.initial_val:
|
||||
for book_id in book_ids:
|
||||
QCoreApplication.processEvents()
|
||||
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
|
||||
|
||||
class BulkBool(BulkBase, Bool):
|
||||
@ -433,6 +435,7 @@ class BulkDateTime(BulkBase, DateTime):
|
||||
pass
|
||||
|
||||
class BulkSeries(BulkBase):
|
||||
|
||||
def setup_ui(self, parent):
|
||||
values = self.all_values = list(self.db.all_custom(num=self.col_id))
|
||||
values.sort(cmp = lambda x,y: cmp(x.lower(), y.lower()))
|
||||
@ -458,6 +461,7 @@ class BulkSeries(BulkBase):
|
||||
update_indices = self.idx_widget.checkState()
|
||||
if val != '':
|
||||
for book_id in book_ids:
|
||||
QCoreApplication.processEvents()
|
||||
if update_indices:
|
||||
if tweaks['series_index_auto_increment'] == 'next':
|
||||
s_index = self.db.get_next_cc_series_num_for\
|
||||
|
@ -3,8 +3,8 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
'''Dialog to edit metadata in bulk'''
|
||||
|
||||
from PyQt4.QtCore import SIGNAL, QObject
|
||||
from PyQt4.QtGui import QDialog, QGridLayout
|
||||
from PyQt4.Qt import SIGNAL, QObject, QDialog, QGridLayout, \
|
||||
QProgressDialog, QCoreApplication, QString
|
||||
|
||||
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
|
||||
from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||
@ -25,7 +25,6 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
len(rows))
|
||||
self.write_series = False
|
||||
self.changed = False
|
||||
QObject.connect(self.button_box, SIGNAL("accepted()"), self.sync)
|
||||
|
||||
all_tags = self.db.all_tags()
|
||||
self.tags.update_tags_cache(all_tags)
|
||||
@ -103,56 +102,102 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
self.tags.update_tags_cache(self.db.all_tags())
|
||||
self.remove_tags.update_tags_cache(self.db.all_tags())
|
||||
|
||||
def sync(self):
|
||||
remove = unicode(self.remove_tags.text()).strip().split(',')
|
||||
add = unicode(self.tags.text()).strip().split(',')
|
||||
self.db.bulk_modify_tags(self.ids, add=add, remove=remove)
|
||||
def accept(self):
|
||||
if len(self.ids) < 1:
|
||||
return QDialog.accept(self)
|
||||
|
||||
pd = QProgressDialog(
|
||||
_('Applying changes to %d books. This may take a while.')%len(self.ids),
|
||||
QString(), 0, 0, self)
|
||||
pd.setModal(True)
|
||||
pd.show()
|
||||
pd.setValue(0)
|
||||
def upd():
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
for id in self.ids:
|
||||
try:
|
||||
remove = unicode(self.remove_tags.text()).strip().split(',')
|
||||
add = unicode(self.tags.text()).strip().split(',')
|
||||
au = unicode(self.authors.text())
|
||||
if au:
|
||||
au = string_to_authors(au)
|
||||
self.db.set_authors(id, au, notify=False)
|
||||
if self.auto_author_sort.isChecked():
|
||||
x = self.db.author_sort_from_book(id, index_is_id=True)
|
||||
if x:
|
||||
self.db.set_author_sort(id, x, notify=False)
|
||||
aus = unicode(self.author_sort.text())
|
||||
if aus and self.author_sort.isEnabled():
|
||||
self.db.set_author_sort(id, aus, notify=False)
|
||||
if self.rating.value() != -1:
|
||||
self.db.set_rating(id, 2*self.rating.value(), notify=False)
|
||||
do_aus = self.author_sort.isEnabled()
|
||||
rating = self.rating.value()
|
||||
pub = unicode(self.publisher.text())
|
||||
if pub:
|
||||
self.db.set_publisher(id, pub, notify=False)
|
||||
if self.write_series:
|
||||
series = unicode(self.series.currentText()).strip()
|
||||
next = self.db.get_next_series_num_for(series)
|
||||
self.db.set_series(id, series, notify=False)
|
||||
num = next if self.autonumber_series.isChecked() and series else 1.0
|
||||
self.db.set_series_index(id, num, notify=False)
|
||||
do_series = self.write_series
|
||||
series = unicode(self.series.currentText()).strip()
|
||||
do_autonumber = self.autonumber_series.isChecked()
|
||||
do_remove_format = self.remove_format.currentIndex() > -1
|
||||
remove_format = unicode(self.remove_format.currentText())
|
||||
do_swap_ta = self.swap_title_and_author.isChecked()
|
||||
do_remove_conv = self.remove_conversion_settings.isChecked()
|
||||
do_auto_author = self.auto_author_sort.isChecked()
|
||||
|
||||
if self.remove_format.currentIndex() > -1:
|
||||
self.db.remove_format(id, unicode(self.remove_format.currentText()), index_is_id=True, notify=False)
|
||||
upd()
|
||||
self.changed = bool(self.ids)
|
||||
for id in self.ids:
|
||||
upd()
|
||||
if do_swap_ta:
|
||||
title = self.db.title(id, index_is_id=True)
|
||||
aum = self.db.authors(id, index_is_id=True)
|
||||
if aum:
|
||||
aum = [a.strip().replace('|', ',') for a in aum.split(',')]
|
||||
new_title = authors_to_string(aum)
|
||||
self.db.set_title(id, new_title, notify=False)
|
||||
if title:
|
||||
new_authors = string_to_authors(title)
|
||||
self.db.set_authors(id, new_authors, notify=False)
|
||||
upd()
|
||||
|
||||
if self.swap_title_and_author.isChecked():
|
||||
title = self.db.title(id, index_is_id=True)
|
||||
aum = self.db.authors(id, index_is_id=True)
|
||||
if aum:
|
||||
aum = [a.strip().replace('|', ',') for a in aum.split(',')]
|
||||
new_title = authors_to_string(aum)
|
||||
self.db.set_title(id, new_title, notify=False)
|
||||
if title:
|
||||
new_authors = string_to_authors(title)
|
||||
self.db.set_authors(id, new_authors, notify=False)
|
||||
if au:
|
||||
self.db.set_authors(id, string_to_authors(au), notify=False)
|
||||
upd()
|
||||
|
||||
if self.remove_conversion_settings.isChecked():
|
||||
self.db.delete_conversion_options(id, 'PIPE')
|
||||
if do_auto_author:
|
||||
x = self.db.author_sort_from_book(id, index_is_id=True)
|
||||
if x:
|
||||
self.db.set_author_sort(id, x, notify=False)
|
||||
upd()
|
||||
|
||||
self.changed = True
|
||||
for w in getattr(self, 'custom_column_widgets', []):
|
||||
w.commit(self.ids)
|
||||
if aus and do_aus:
|
||||
self.db.set_author_sort(id, aus, notify=False)
|
||||
upd()
|
||||
|
||||
if rating != -1:
|
||||
self.db.set_rating(id, 2*rating, notify=False)
|
||||
upd()
|
||||
|
||||
if pub:
|
||||
self.db.set_publisher(id, pub, notify=False)
|
||||
upd()
|
||||
|
||||
if do_series:
|
||||
next = self.db.get_next_series_num_for(series)
|
||||
self.db.set_series(id, series, notify=False)
|
||||
num = next if do_autonumber and series else 1.0
|
||||
self.db.set_series_index(id, num, notify=False)
|
||||
upd()
|
||||
|
||||
if do_remove_format:
|
||||
self.db.remove_format(id, remove_format, index_is_id=True, notify=False)
|
||||
upd()
|
||||
|
||||
|
||||
if do_remove_conv:
|
||||
self.db.delete_conversion_options(id, 'PIPE')
|
||||
upd()
|
||||
|
||||
upd()
|
||||
for w in getattr(self, 'custom_column_widgets', []):
|
||||
w.commit(self.ids)
|
||||
self.db.bulk_modify_tags(self.ids, add=add, remove=remove,
|
||||
notify=False)
|
||||
upd()
|
||||
|
||||
|
||||
finally:
|
||||
pd.cancel()
|
||||
|
||||
return QDialog.accept(self)
|
||||
|
||||
|
||||
def series_changed(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user