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'))
|
_('No books selected'))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
return
|
return
|
||||||
if MetadataBulkDialog(self.gui, rows,
|
# Prevent the TagView from updating due to signals from the database
|
||||||
self.gui.library_view.model().db).changed:
|
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().resort(reset=False)
|
||||||
self.gui.library_view.model().research()
|
self.gui.library_view.model().research()
|
||||||
self.gui.tags_view.recount()
|
self.gui.tags_view.recount()
|
||||||
|
@ -11,7 +11,7 @@ from functools import partial
|
|||||||
from PyQt4.Qt import QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateEdit, \
|
from PyQt4.Qt import QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateEdit, \
|
||||||
QDate, QGroupBox, QVBoxLayout, QPlainTextEdit, QSizePolicy, \
|
QDate, QGroupBox, QVBoxLayout, QPlainTextEdit, QSizePolicy, \
|
||||||
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, SIGNAL, \
|
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, SIGNAL, \
|
||||||
QPushButton
|
QPushButton, QCoreApplication
|
||||||
|
|
||||||
from calibre.utils.date import qt_to_dt, now
|
from calibre.utils.date import qt_to_dt, now
|
||||||
from calibre.gui2.widgets import TagsLineEdit, EnComboBox
|
from calibre.gui2.widgets import TagsLineEdit, EnComboBox
|
||||||
@ -406,6 +406,7 @@ class BulkBase(Base):
|
|||||||
def commit(self, book_ids, notify=False):
|
def commit(self, book_ids, notify=False):
|
||||||
if self.process_each_book():
|
if self.process_each_book():
|
||||||
for book_id in book_ids:
|
for book_id in book_ids:
|
||||||
|
QCoreApplication.processEvents()
|
||||||
val = self.db.get_custom(book_id, num=self.col_id, index_is_id=True)
|
val = self.db.get_custom(book_id, num=self.col_id, index_is_id=True)
|
||||||
new_val = self.getter(val)
|
new_val = self.getter(val)
|
||||||
if set(val) != new_val:
|
if set(val) != new_val:
|
||||||
@ -415,6 +416,7 @@ class BulkBase(Base):
|
|||||||
val = self.normalize_ui_val(val)
|
val = self.normalize_ui_val(val)
|
||||||
if val != self.initial_val:
|
if val != self.initial_val:
|
||||||
for book_id in book_ids:
|
for book_id in book_ids:
|
||||||
|
QCoreApplication.processEvents()
|
||||||
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
|
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
|
||||||
|
|
||||||
class BulkBool(BulkBase, Bool):
|
class BulkBool(BulkBase, Bool):
|
||||||
@ -433,6 +435,7 @@ class BulkDateTime(BulkBase, DateTime):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class BulkSeries(BulkBase):
|
class BulkSeries(BulkBase):
|
||||||
|
|
||||||
def setup_ui(self, parent):
|
def setup_ui(self, parent):
|
||||||
values = self.all_values = list(self.db.all_custom(num=self.col_id))
|
values = self.all_values = list(self.db.all_custom(num=self.col_id))
|
||||||
values.sort(cmp = lambda x,y: cmp(x.lower(), y.lower()))
|
values.sort(cmp = lambda x,y: cmp(x.lower(), y.lower()))
|
||||||
@ -458,6 +461,7 @@ class BulkSeries(BulkBase):
|
|||||||
update_indices = self.idx_widget.checkState()
|
update_indices = self.idx_widget.checkState()
|
||||||
if val != '':
|
if val != '':
|
||||||
for book_id in book_ids:
|
for book_id in book_ids:
|
||||||
|
QCoreApplication.processEvents()
|
||||||
if update_indices:
|
if update_indices:
|
||||||
if tweaks['series_index_auto_increment'] == 'next':
|
if tweaks['series_index_auto_increment'] == 'next':
|
||||||
s_index = self.db.get_next_cc_series_num_for\
|
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'''
|
'''Dialog to edit metadata in bulk'''
|
||||||
|
|
||||||
from PyQt4.QtCore import SIGNAL, QObject
|
from PyQt4.Qt import SIGNAL, QObject, QDialog, QGridLayout, \
|
||||||
from PyQt4.QtGui import QDialog, QGridLayout
|
QProgressDialog, QCoreApplication, QString
|
||||||
|
|
||||||
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
|
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
|
||||||
from calibre.gui2.dialogs.tag_editor import TagEditor
|
from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||||
@ -25,7 +25,6 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
len(rows))
|
len(rows))
|
||||||
self.write_series = False
|
self.write_series = False
|
||||||
self.changed = False
|
self.changed = False
|
||||||
QObject.connect(self.button_box, SIGNAL("accepted()"), self.sync)
|
|
||||||
|
|
||||||
all_tags = self.db.all_tags()
|
all_tags = self.db.all_tags()
|
||||||
self.tags.update_tags_cache(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.tags.update_tags_cache(self.db.all_tags())
|
||||||
self.remove_tags.update_tags_cache(self.db.all_tags())
|
self.remove_tags.update_tags_cache(self.db.all_tags())
|
||||||
|
|
||||||
def sync(self):
|
def accept(self):
|
||||||
remove = unicode(self.remove_tags.text()).strip().split(',')
|
if len(self.ids) < 1:
|
||||||
add = unicode(self.tags.text()).strip().split(',')
|
return QDialog.accept(self)
|
||||||
self.db.bulk_modify_tags(self.ids, add=add, remove=remove)
|
|
||||||
|
|
||||||
|
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())
|
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())
|
aus = unicode(self.author_sort.text())
|
||||||
if aus and self.author_sort.isEnabled():
|
do_aus = self.author_sort.isEnabled()
|
||||||
self.db.set_author_sort(id, aus, notify=False)
|
rating = self.rating.value()
|
||||||
if self.rating.value() != -1:
|
|
||||||
self.db.set_rating(id, 2*self.rating.value(), notify=False)
|
|
||||||
pub = unicode(self.publisher.text())
|
pub = unicode(self.publisher.text())
|
||||||
if pub:
|
do_series = self.write_series
|
||||||
self.db.set_publisher(id, pub, notify=False)
|
series = unicode(self.series.currentText()).strip()
|
||||||
if self.write_series:
|
do_autonumber = self.autonumber_series.isChecked()
|
||||||
series = unicode(self.series.currentText()).strip()
|
do_remove_format = self.remove_format.currentIndex() > -1
|
||||||
next = self.db.get_next_series_num_for(series)
|
remove_format = unicode(self.remove_format.currentText())
|
||||||
self.db.set_series(id, series, notify=False)
|
do_swap_ta = self.swap_title_and_author.isChecked()
|
||||||
num = next if self.autonumber_series.isChecked() and series else 1.0
|
do_remove_conv = self.remove_conversion_settings.isChecked()
|
||||||
self.db.set_series_index(id, num, notify=False)
|
do_auto_author = self.auto_author_sort.isChecked()
|
||||||
|
|
||||||
if self.remove_format.currentIndex() > -1:
|
upd()
|
||||||
self.db.remove_format(id, unicode(self.remove_format.currentText()), index_is_id=True, notify=False)
|
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():
|
if au:
|
||||||
title = self.db.title(id, index_is_id=True)
|
self.db.set_authors(id, string_to_authors(au), notify=False)
|
||||||
aum = self.db.authors(id, index_is_id=True)
|
upd()
|
||||||
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 self.remove_conversion_settings.isChecked():
|
if do_auto_author:
|
||||||
self.db.delete_conversion_options(id, 'PIPE')
|
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
|
if aus and do_aus:
|
||||||
for w in getattr(self, 'custom_column_widgets', []):
|
self.db.set_author_sort(id, aus, notify=False)
|
||||||
w.commit(self.ids)
|
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):
|
def series_changed(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user