| 1113 | } |
| 1114 | |
| 1115 | void MainWindowViewer::extractPages() |
| 1116 | { |
| 1117 | const QString outputDir = QFileDialog::getExistingDirectory(this, tr("Extract page(s)"), pageExportDirectory(settings, EXTRACT_PAGE_DIRECTORY)); |
| 1118 | if (outputDir.isEmpty()) |
| 1119 | return; |
| 1120 | |
| 1121 | settings->setValue(EXTRACT_PAGE_DIRECTORY, outputDir); |
| 1122 | |
| 1123 | const QString baseName = comicBaseName(currentComicPath); |
| 1124 | const QList<int> pages = viewer->currentVisiblePages(); |
| 1125 | QList<PageExtraction> pageExtractions; |
| 1126 | QStringList existingPaths; |
| 1127 | |
| 1128 | for (const int page : pages) { |
| 1129 | const QByteArray rawPage = viewer->rawPage(page); |
| 1130 | if (rawPage.isEmpty()) |
| 1131 | continue; |
| 1132 | |
| 1133 | const QString path = QDir(outputDir).filePath(QString("%1-%2.%3").arg(baseName).arg(page + 1).arg(imageExtension(rawPage))); |
| 1134 | pageExtractions.append({ rawPage, path }); |
| 1135 | if (QFileInfo::exists(path)) |
| 1136 | existingPaths << path; |
| 1137 | } |
| 1138 | |
| 1139 | if (pageExtractions.isEmpty()) { |
| 1140 | QMessageBox::warning(this, tr("Extract page(s)"), tr("The current page could not be extracted.")); |
| 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | if (!existingPaths.isEmpty()) { |
| 1145 | const auto answer = QMessageBox::question(this, tr("Overwrite files?"), tr("Some files already exist. Do you want to overwrite them?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
| 1146 | if (answer != QMessageBox::Yes) |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | QStringList failedPaths; |
| 1151 | for (const auto &pageExtraction : pageExtractions) { |
| 1152 | QFile file(pageExtraction.outputPath); |
| 1153 | if (!file.open(QIODevice::WriteOnly) || file.write(pageExtraction.rawPage) != pageExtraction.rawPage.size()) |
| 1154 | failedPaths << pageExtraction.outputPath; |
| 1155 | } |
| 1156 | |
| 1157 | if (!failedPaths.isEmpty()) |
| 1158 | QMessageBox::warning(this, tr("Extract page(s)"), tr("Some pages could not be extracted.")); |
| 1159 | } |
| 1160 | |
| 1161 | void MainWindowViewer::enableActions() |
| 1162 | { |
nothing calls this directly
no test coverage detected