Fix export to CBZ
This commit is contained in:
parent
7448e9828b
commit
a8f269aefa
@ -173,15 +173,20 @@ class FileSelectionList(QtWidgets.QWidget):
|
||||
self.listCleared.emit()
|
||||
|
||||
def add_path_list(self, pathlist: list[str]) -> None:
|
||||
if not pathlist:
|
||||
return
|
||||
filelist = utils.get_recursive_filelist(pathlist)
|
||||
# we now have a list of files to add
|
||||
|
||||
# Prog dialog on Linux flakes out for small range, so scale up
|
||||
progdialog = QtWidgets.QProgressDialog("", "Cancel", 0, len(filelist), parent=self)
|
||||
progdialog.setWindowTitle("Adding Files")
|
||||
progdialog.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
|
||||
progdialog.setMinimumDuration(300)
|
||||
center_window_on_parent(progdialog)
|
||||
progdialog = None
|
||||
if len(filelist) < 3:
|
||||
# Prog dialog on Linux flakes out for small range, so scale up
|
||||
progdialog = QtWidgets.QProgressDialog("", "Cancel", 0, len(filelist), parent=self)
|
||||
progdialog.setWindowTitle("Adding Files")
|
||||
progdialog.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
|
||||
progdialog.setMinimumDuration(300)
|
||||
progdialog.show()
|
||||
center_window_on_parent(progdialog)
|
||||
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
first_added = None
|
||||
@ -189,10 +194,11 @@ class FileSelectionList(QtWidgets.QWidget):
|
||||
self.twList.setSortingEnabled(False)
|
||||
for idx, f in enumerate(filelist):
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
if progdialog.wasCanceled():
|
||||
break
|
||||
progdialog.setValue(idx + 1)
|
||||
progdialog.setLabelText(f)
|
||||
if progdialog is not None:
|
||||
if progdialog.wasCanceled():
|
||||
break
|
||||
progdialog.setValue(idx + 1)
|
||||
progdialog.setLabelText(f)
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
row = self.add_path_item(f)
|
||||
if row is not None:
|
||||
@ -201,7 +207,8 @@ class FileSelectionList(QtWidgets.QWidget):
|
||||
if first_added is None and row != -1:
|
||||
first_added = row
|
||||
|
||||
progdialog.hide()
|
||||
if progdialog is not None:
|
||||
progdialog.hide()
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
|
||||
if first_added is not None:
|
||||
|
@ -491,14 +491,14 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
def repackage_archive(self) -> None:
|
||||
ca_list = self.fileSelectionList.get_selected_archive_list()
|
||||
non_zip_count = 0
|
||||
zip_list = []
|
||||
to_zip = []
|
||||
largest_page_size = 0
|
||||
for ca in ca_list:
|
||||
largest_page_size = max(largest_page_size, len(ca.get_page_name_list()))
|
||||
if not ca.is_zip():
|
||||
non_zip_count += 1
|
||||
else:
|
||||
zip_list.append(ca)
|
||||
to_zip.append(ca)
|
||||
|
||||
if non_zip_count == 0:
|
||||
if not to_zip:
|
||||
QtWidgets.QMessageBox.information(
|
||||
self, self.tr("Export as Zip Archive"), self.tr("Only ZIP archives are selected!")
|
||||
)
|
||||
@ -511,11 +511,11 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
):
|
||||
return
|
||||
|
||||
if non_zip_count != 0:
|
||||
if to_zip:
|
||||
EW = ExportWindow(
|
||||
self,
|
||||
(
|
||||
f"You have selected {non_zip_count} archive(s) to export to Zip format. "
|
||||
f"You have selected {len(to_zip)} archive(s) to export to Zip format. "
|
||||
""" New archives will be created in the same folder as the original.
|
||||
|
||||
Please choose config below, and select OK.
|
||||
@ -527,11 +527,13 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
if not EW.exec():
|
||||
return
|
||||
|
||||
prog_dialog = QtWidgets.QProgressDialog("", "Cancel", 0, non_zip_count, self)
|
||||
prog_dialog.setWindowTitle("Exporting as ZIP")
|
||||
prog_dialog.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
|
||||
prog_dialog.setMinimumDuration(300)
|
||||
center_window_on_parent(prog_dialog)
|
||||
prog_dialog = None
|
||||
if len(to_zip) > 3 or largest_page_size > 24:
|
||||
prog_dialog = QtWidgets.QProgressDialog("", "Cancel", 0, non_zip_count, self)
|
||||
prog_dialog.setWindowTitle("Exporting as ZIP")
|
||||
prog_dialog.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
|
||||
prog_dialog.setMinimumDuration(300)
|
||||
center_window_on_parent(prog_dialog)
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
|
||||
new_archives_to_add = []
|
||||
@ -539,13 +541,16 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
skipped_list = []
|
||||
failed_list = []
|
||||
success_count = 0
|
||||
logger.debug("Exporting %d comics to zip", len(to_zip))
|
||||
|
||||
for prog_idx, ca in enumerate(zip_list, 1):
|
||||
for prog_idx, ca in enumerate(to_zip, 1):
|
||||
logger.debug("Exporting comic %d: %s", prog_idx, ca.path)
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
if prog_dialog.wasCanceled():
|
||||
break
|
||||
prog_dialog.setValue(prog_idx)
|
||||
prog_dialog.setLabelText(str(ca.path))
|
||||
if prog_dialog is not None:
|
||||
if prog_dialog.wasCanceled():
|
||||
break
|
||||
prog_dialog.setValue(prog_idx)
|
||||
prog_dialog.setLabelText(str(ca.path))
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
|
||||
export_name = ca.path.with_suffix(".cbz")
|
||||
@ -559,6 +564,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
export_name = utils.unique_file(export_name)
|
||||
|
||||
if export:
|
||||
logger.debug("Exporting %s to %s", ca.path, export_name)
|
||||
if ca.export_as_zip(export_name):
|
||||
success_count += 1
|
||||
if EW.addToList:
|
||||
@ -573,9 +579,9 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
if export_name.exists():
|
||||
export_name.unlink(missing_ok=True)
|
||||
|
||||
prog_dialog.hide()
|
||||
if prog_dialog is not None:
|
||||
prog_dialog.hide()
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
self.fileSelectionList.add_path_list(new_archives_to_add)
|
||||
self.fileSelectionList.remove_archive_list(archives_to_remove)
|
||||
|
||||
summary = f"Successfully created {success_count} Zip archive(s)."
|
||||
@ -597,6 +603,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
dlg.set_text(summary)
|
||||
dlg.setWindowTitle("Archive Export to Zip Summary")
|
||||
dlg.exec()
|
||||
self.fileSelectionList.add_path_list(new_archives_to_add)
|
||||
|
||||
def about_app(self) -> None:
|
||||
website = "https://github.com/comictagger/comictagger"
|
||||
|
Loading…
Reference in New Issue
Block a user