diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index 1c315bf3..c1fe4f4d 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -50,6 +50,7 @@ #include #include "lang/app_language.h" #include "huagao/brand.h" +#include #define PASSWORD_KEY 4 @@ -749,6 +750,11 @@ void MainWindow::on_itemSelectingChanged() updateActionStatus(); } +static bool Greater(const QString &str1, const QString &str2) +{ + return str1 < str2; +} + void MainWindow::on_currItemChanged(int index) { HGImage img = nullptr; @@ -871,6 +877,143 @@ void MainWindow::on_currItemChanged(int index) m_wndStatusBar->setPageInfo(count, m_currIndex); updateStatusBarPixelInfo(); updateActionStatus(); + + if (!m_isScanning && !m_curBatchFileList.empty()) + { + std::vector fileNames; + + int count = 0; + m_thumb->getItemCount(&count); + for (int i = 0; i < count; ++i) + { + QString fileName; + m_thumb->getItemFileName(i, fileName); + + std::list::iterator iter; + for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter) + { + if (*iter == fileName) + { + HGChar name[256]; + HGBase_GetFileName(fileName.toLocal8Bit().toStdString().c_str(), name, 256); + HGChar filePrefix[256]; + HGBase_GetFilePrefix(name, filePrefix, 256); + fileNames.push_back(filePrefix); + break; + } + } + } + + std::vector backupFileNames = fileNames; + std::sort(fileNames.begin(), fileNames.end(), Greater); + if (backupFileNames != fileNames) + { + std::list batchTmpFileList; + for (int i = 0; i < count; ++i) + { + QString fileName; + m_thumb->getItemFileName(i, fileName); + + std::list::iterator iter; + for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter) + { + if (*iter == fileName) + { + HGChar filePath[256]; + HGBase_GetFilePath(fileName.toLocal8Bit().toStdString().c_str(), filePath, 256); + HGChar name[256]; + HGBase_GetFileName(fileName.toLocal8Bit().toStdString().c_str(), name, 256); + HGChar filePrefix[256]; + HGBase_GetFilePrefix(name, filePrefix, 256); + HGChar fileSuffix[256]; + HGBase_GetFileSuffix(name, 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); + batchTmpFileList.push_back(newFileName); + break; + } + } + } + + std::list::iterator iter; + for (iter = batchTmpFileList.begin(); iter != batchTmpFileList.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); + + QString strFilePath = QString::fromLocal8Bit(filePath); + QString strFileSuffix = QString::fromLocal8Bit(fileSuffix); + + QString newFileName; + while (!fileNames.empty()) + { + QString fileName = strFilePath + fileNames.front() + "." + strFileSuffix; + QFileInfo fileInfo(fileName); + if (fileInfo.isFile()) + { + fileNames.erase(fileNames.begin()); + } + else + { + newFileName = fileName; + break; + } + } + + if (!newFileName.isEmpty()) + { + QFile file(*iter); + file.rename(newFileName); + m_thumb->updateItem(*iter, newFileName, false); + m_curBatchFileList.push_back(newFileName); + fileNames.erase(fileNames.begin()); + } + else + { + while (1) + { + QString fileName = strFilePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") + .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) + .arg(strFileSuffix); + QFileInfo fileInfo(fileName); + if (fileInfo.isFile()) + { + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + else + { + newFileName = fileName; + break; + } + } + + if (!newFileName.isEmpty()) + { + QFile file(*iter); + file.rename(newFileName); + m_thumb->updateItem(*iter, newFileName, false); + m_curBatchFileList.push_back(newFileName); + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + } + } + + batchTmpFileList.clear(); + } + } } void MainWindow::on_itemDoubleClicked(int index) @@ -1050,7 +1193,7 @@ void MainWindow::on_post_new_image(QString fileName) HGBase_LeaveLock(m_lockPreviewImage); updateStatusBarPixelInfo(); - if ((ScanType_ScanInto == m_scanType)) + if (ScanType_ScanInto == m_scanType) { m_curBatchFileList.push_back(stdFileName); }