diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index ab971065..3632200f 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -67,7 +67,6 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) , m_scanCurIndex(-1) , m_scanFileName("") , m_scanImgFmtWriter(nullptr) - , m_fileNameStartIndex(-1) , m_isScanning(false) , auto_save_changes_(false) , save_from_changed_(false) @@ -86,6 +85,8 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) { ui->setupUi(this); + m_aquireIntoSaveParam.m_fileNameStartIndex = -1; + m_versionDll = new VersionDll; HGBase_RegisterCrashFunc(CrashFunc, this); @@ -637,9 +638,8 @@ void MainWindow::on_AcquireInto2() m_scanInsertPos = -1; m_scanCurIndex = -1; - Dialog_AquireInto dlg(m_fileNameStartIndex, this); + Dialog_AquireInto dlg(-1, this); m_aquireIntoSaveParam = dlg.getSaveParam(); - m_fileNameStartIndex = m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoInBlank = true; m_aquireIntoBatchStartIndex = 0; m_aquireIntoPageIndex = 0; @@ -693,7 +693,7 @@ void MainWindow::on_reloadAcquireIntoCfg() void MainWindow::on_m_acquireIntoCfg_changed(QString schemeName) { QString selectedCfgName = m_cbtn_acquireIntoCfg->currentText(); - Dialog_AquireInto dlg(m_fileNameStartIndex, this); + Dialog_AquireInto dlg(-1, this); dlg.setConfig(selectedCfgName); } @@ -1080,21 +1080,30 @@ void MainWindow::on_newImage(void *image) HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str()); QString scanFileName; - while (1) + if (-1 == m_scanInsertPos) { - scanFileName = m_aquireIntoSaveParam.m_savePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") - .arg(m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) - .arg(m_aquireIntoSaveParam.m_fileNameExt); - QFileInfo fileInfo(scanFileName); - if (fileInfo.isFile()) + while (1) { - ++m_fileNameStartIndex; - } - else - { - break; + scanFileName = m_aquireIntoSaveParam.m_savePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") + .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) + .arg(m_aquireIntoSaveParam.m_fileNameExt); + QFileInfo fileInfo(scanFileName); + if (fileInfo.isFile()) + { + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + else + { + break; + } } } + else + { + HGChar uuid[256]; + HGBase_GetUuid(uuid, 256); + scanFileName = m_aquireIntoSaveParam.m_savePath + QString(uuid) + "." + m_aquireIntoSaveParam.m_fileNameExt; + } HGUInt fmtType = 0; if (m_aquireIntoSaveParam.m_isOcr) @@ -1146,7 +1155,8 @@ void MainWindow::on_newImage(void *image) m_scanImgFmtWriter = nullptr; emit post_new_image(m_scanFileName); m_scanFileName.clear(); - ++m_fileNameStartIndex; + if (-1 == m_scanInsertPos) + ++m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoMultiPageCount = 0; } } @@ -1197,21 +1207,30 @@ void MainWindow::on_newImage(void *image) HGBase_CreateDir(getStdString(savePath).c_str()); - while (1) + if (-1 == m_scanInsertPos) { - m_scanFileName = savePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") - .arg(m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) - .arg(m_aquireIntoSaveParam.m_fileNameExt); - QFileInfo fileInfo(m_scanFileName); - if (fileInfo.isFile()) + while (1) { - ++m_fileNameStartIndex; - } - else - { - break; + m_scanFileName = savePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") + .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) + .arg(m_aquireIntoSaveParam.m_fileNameExt); + QFileInfo fileInfo(m_scanFileName); + if (fileInfo.isFile()) + { + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + else + { + break; + } } } + else + { + HGChar uuid[256]; + HGBase_GetUuid(uuid, 256); + m_scanFileName = m_aquireIntoSaveParam.m_savePath + QString(uuid) + "." + m_aquireIntoSaveParam.m_fileNameExt; + } HGImgFmtSaveInfo saveInfo; saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality; @@ -1247,7 +1266,8 @@ void MainWindow::on_newImage(void *image) if (HGBASE_ERR_OK == HGImgFmt_SaveImage((HGImage)image, fmtType, &saveInfo, getStdString(m_scanFileName).c_str())) { emit post_new_image(m_scanFileName); - ++m_fileNameStartIndex; + if (-1 == m_scanInsertPos) + ++m_aquireIntoSaveParam.m_fileNameStartIndex; } m_scanFileName.clear(); @@ -1286,7 +1306,8 @@ void MainWindow::on_scanFinishEvent() m_scanImgFmtWriter = nullptr; emit post_new_image(m_scanFileName); m_scanFileName.clear(); - ++m_fileNameStartIndex; + if (-1 == m_scanInsertPos) + ++m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoMultiPageCount = 0; } @@ -1327,6 +1348,8 @@ void MainWindow::on_scanFinishEvent() assert(ScanType_InsertScanInto == m_scanType); assert(-1 != m_scanInsertPos); + std::list backupFileNames; + int count = 0; m_thumb->getItemCount(&count); for (int i = m_scanInsertPos; i < count; ++i) @@ -1339,8 +1362,25 @@ void MainWindow::on_scanFinishEvent() { if (*iter == fileName) { + HGChar filePath[256]; + HGBase_GetFilePath(fileName.toLocal8Bit().toStdString().c_str(), filePath, 256); + HGChar fileSuffix[256]; + HGBase_GetFileSuffix(fileName.toLocal8Bit().toStdString().c_str(), fileSuffix, 256); + HGChar uuid[256]; + HGBase_GetUuid(uuid, 256); + + QString strFilePath = QString::fromLocal8Bit(filePath); + QString strFileSuffix = QString::fromLocal8Bit(fileSuffix); + QString strUuid = QString::fromLocal8Bit(uuid); + QString newFileName = strFilePath + strUuid + "." + strFileSuffix; + + QFile file(fileName); + file.rename(newFileName); + m_thumb->updateItem(fileName, newFileName, false); + m_curBatchFileList.erase(iter); - m_curBatchTmpFileList.push_back(fileName); + backupFileNames.push_back(fileName); + m_curBatchTmpFileList.push_back(newFileName); break; } } @@ -1349,27 +1389,20 @@ void MainWindow::on_scanFinishEvent() std::list::iterator iter; for (iter = m_curBatchTmpFileList.begin(); iter != m_curBatchTmpFileList.end(); ++iter) { - HGChar filePath[256]; - HGBase_GetFilePath((*iter).toLocal8Bit().toStdString().c_str(), filePath, 256); - HGChar fileSuffix[256]; - HGBase_GetFileSuffix((*iter).toLocal8Bit().toStdString().c_str(), fileSuffix, 256); - HGChar uuid[256]; - HGBase_GetUuid(uuid, 256); + if (!backupFileNames.empty()) + { + QString &newFileName = backupFileNames.front(); - QString strFilePath = QString::fromLocal8Bit(filePath); - QString strFileSuffix = QString::fromLocal8Bit(fileSuffix); - QString strUuid = QString::fromLocal8Bit(uuid); - QString newFileName = strFilePath + strUuid + "." + strFileSuffix; + QFile file(*iter); + file.rename(newFileName); + m_thumb->updateItem(*iter, newFileName, false); + m_curBatchFileList.push_back(newFileName); + ++m_aquireIntoSaveParam.m_fileNameStartIndex; - QFile file(*iter); - file.rename(newFileName); - m_thumb->updateItem(*iter, newFileName, false); - *iter = newFileName; - } + backupFileNames.erase(backupFileNames.begin()); + continue; + } - int fileNameStartIndex = 1;//m_aquireIntoSaveParam.m_fileNameStartIndex; - for (iter = m_curBatchTmpFileList.begin(); iter != m_curBatchTmpFileList.end(); ++iter) - { HGChar filePath[256]; HGBase_GetFilePath((*iter).toLocal8Bit().toStdString().c_str(), filePath, 256); HGChar fileSuffix[256]; @@ -1382,12 +1415,12 @@ void MainWindow::on_scanFinishEvent() while (1) { newFileName = strFilePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") - .arg(fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) + .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) .arg(strFileSuffix); QFileInfo fileInfo(newFileName); if (fileInfo.isFile()) { - ++fileNameStartIndex; + ++m_aquireIntoSaveParam.m_fileNameStartIndex; } else { @@ -1399,7 +1432,7 @@ void MainWindow::on_scanFinishEvent() file.rename(newFileName); m_thumb->updateItem(*iter, newFileName, false); m_curBatchFileList.push_back(newFileName); - ++fileNameStartIndex; + ++m_aquireIntoSaveParam.m_fileNameStartIndex; } m_curBatchTmpFileList.clear(); @@ -3338,7 +3371,7 @@ void MainWindow::on_act_acquireInto_triggered() return; } - Dialog_AquireInto dlg(m_fileNameStartIndex, this); + Dialog_AquireInto dlg(m_aquireIntoSaveParam.m_fileNameStartIndex, this); connect(&dlg, SIGNAL(reloadAcquireIntoCfg()), this, SLOT(on_reloadAcquireIntoCfg())); if (dlg.exec()) { @@ -3347,7 +3380,6 @@ void MainWindow::on_act_acquireInto_triggered() m_scanCurIndex = -1; m_aquireIntoSaveParam = dlg.getSaveParam(); - m_fileNameStartIndex = m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoInBlank = true; m_aquireIntoBatchStartIndex = 0; m_aquireIntoPageIndex = 0; @@ -3411,9 +3443,8 @@ void MainWindow::on_act_insertFromScanner_triggered() break; } - Dialog_AquireInto dlg2(m_fileNameStartIndex, this); + Dialog_AquireInto dlg2(-1, this); m_aquireIntoSaveParam = dlg2.getSaveParam(); - m_fileNameStartIndex = m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoInBlank = true; m_aquireIntoBatchStartIndex = 0; m_aquireIntoPageIndex = 0; diff --git a/app/scanner2/mainwindow.h b/app/scanner2/mainwindow.h index d35c68fa..96259996 100644 --- a/app/scanner2/mainwindow.h +++ b/app/scanner2/mainwindow.h @@ -317,7 +317,6 @@ private: QString m_scanFileName; HGImgFmtWriter m_scanImgFmtWriter; AquireIntoSaveParam m_aquireIntoSaveParam; - int m_fileNameStartIndex; bool m_aquireIntoInBlank; int m_aquireIntoBatchStartIndex; int m_aquireIntoPageIndex;