HGGitLab

Commit de7bd5d0 authored by luoliangyi's avatar luoliangyi

将扫描目录和缓存目录标准化

parent e33eb8c7
#include "dialog_aquireinto.h"
#include "ui_dialog_aquireinto.h"
#include "dialog_savequality.h"
#include "global.h"
#include <QFileDialog>
#include <QDateTime>
#include <QRegExpValidator>
#include <QStandardPaths>
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
QDialog(parent),
......@@ -17,7 +20,11 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
QRegExp rx("[^\\\\/:*?\"<>|]+$");
ui->lineEdit_fileName->setValidator(new QRegExpValidator(rx, this));
QString filePath = APP_AQUIREINTO_PATH;
HGChar aquireIntoPath[512];
HGBase_GetDocumentsPath(aquireIntoPath, 512);
strcat(aquireIntoPath, "Huago/ScannerApp/AquireInto/");
QString filePath = getStdFileName(StdStringToUtf8(aquireIntoPath).c_str());
ui->lineEdit_directory->setText(filePath);
ui->cbtn_subFolder->setChecked(false);
ui->cbtn_subFolderByBlank->setChecked(false);
......@@ -102,7 +109,11 @@ void Dialog_AquireInto::on_btn_directory_clicked()
{
QString save_dir = QFileDialog::getExistingDirectory(this, tr("Browse directory"), "");
if (!save_dir.isEmpty())
ui->lineEdit_directory->setText(save_dir);
{
if (save_dir[save_dir.size() - 1] != '/')
save_dir += "/";
ui->lineEdit_directory->setText(getStdFileName(save_dir));
}
}
void Dialog_AquireInto::on_btn_option_clicked()
......
#include "dialog_clrcache.h"
#include "ui_dialog_clrcache.h"
#include "global.h"
#include <QMessageBox>
#include <QDir>
#include <QFileInfo>
#include <QKeyEvent>
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
Dialog_ClrCache::Dialog_ClrCache(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_ClrCache)
{
ui->setupUi(this);
ui->lineEdit->setText(APP_CACHE_PATH);
setInformation(APP_CACHE_PATH);
m_cachePath = getCachePath();
ui->lineEdit->setText(m_cachePath);
setInformation(m_cachePath);
}
Dialog_ClrCache::~Dialog_ClrCache()
......@@ -21,9 +22,18 @@ Dialog_ClrCache::~Dialog_ClrCache()
delete ui;
}
QString Dialog_ClrCache::getCachePath()
{
HGChar cachePath[512];
HGBase_GetDocumentsPath(cachePath, 512);
strcat(cachePath, "Huago/ScannerApp/Cache/");
QString filePath = getStdFileName(StdStringToUtf8(cachePath).c_str());
return filePath;
}
void Dialog_ClrCache::on_btn_clr_clicked()
{
QFileInfo file(APP_CACHE_PATH);
QFileInfo file(m_cachePath);
if (!file.exists())
{
......@@ -42,7 +52,7 @@ void Dialog_ClrCache::on_btn_clr_clicked()
return;
}
bool ret = clrCache(APP_CACHE_PATH);
bool ret = clrCache(m_cachePath);
if (ret)
{
emit clearCache();
......@@ -53,7 +63,7 @@ void Dialog_ClrCache::on_btn_clr_clicked()
QMessageBox::warning(this, tr("Warning"), tr("Cache clear failed or incompletely clear."));
}
setInformation(APP_CACHE_PATH);
setInformation(m_cachePath);
}
void Dialog_ClrCache::on_btn_close_clicked()
......@@ -65,7 +75,7 @@ bool Dialog_ClrCache::clrCache(const QString &path)
{
QDir dir = QDir(path);
bool isSuccessful = dir.removeRecursively();
dir.mkpath(APP_CACHE_PATH);
dir.mkpath(m_cachePath);
return isSuccessful;
}
......
......@@ -17,6 +17,8 @@ public:
explicit Dialog_ClrCache(QWidget *parent = nullptr);
~Dialog_ClrCache();
static QString getCachePath();
signals:
void clearCache();
......@@ -32,6 +34,7 @@ private:
private:
Ui::Dialog_ClrCache *ui;
QString m_cachePath;
};
#endif // DIALOG_CLRCACHE_H
#ifndef GLOBAL_H
#define GLOBAL_H
#include <QStandardPaths>
static const QString APP_AQUIREINTO_PATH = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Huago/ScannerApp/AquireInto";
static const QString APP_CACHE_PATH = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Huago/ScannerApp/Cache";
#endif // GLOBAL_H
#include "mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDockWidget>
#include <QFileDialog>
......@@ -28,7 +28,6 @@
#include "dialog_clrcache.h"
#include "dialog_moveto.h"
#include "hg_settingdialog.h"
#include "global.h"
#include "base/HGInfo.h"
#include "imgfmt/HGPdf.h"
#include "imgfmt/HGImgFmt.h"
......@@ -36,60 +35,6 @@
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
static std::string Utf8ToAnsi(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_UTF8, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pAnsi = new CHAR[len];
::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pAnsi;
delete[] pAnsi;
return ret;
}
#endif
static std::string Utf8ToStdString(const char* utf8)
{
#if defined(HG_CMP_MSC)
return Utf8ToAnsi(utf8);
#else
return utf8;
#endif
}
static std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
static void TrimString(std::string& str)
{
int s = (int)str.find_first_not_of(" ");
int e = (int)str.find_last_not_of(" ");
str = str.substr(s, e - s + 1);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
......@@ -101,6 +46,7 @@ MainWindow::MainWindow(QWidget *parent)
, m_multiIndex(-1)
, m_relation(false)
, m_modify(false)
, m_singleScan(false)
, m_scanType(0)
, m_scanInsertPos(-1)
, m_scanFileName("")
......@@ -695,7 +641,7 @@ void MainWindow::on_clearCache()
{
QString fileName;
m_thumb->getItemFileName(i, fileName);
if (0 == fileName.indexOf(getStdFileName(APP_CACHE_PATH)))
if (0 == fileName.indexOf(Dialog_ClrCache::getCachePath()))
{
removeItems.push_back(i);
}
......@@ -881,9 +827,9 @@ void MainWindow::on_new_image(void *img)
if (nullptr == m_scanImgFmtWriter)
{
assert(m_scanFileName.isEmpty());
HGBase_CreateDir(getStdString(getStdFileName(m_aquireIntoSaveParam.m_savePath)).c_str());
HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str());
QString scanFileName = QString(tr("%1/%2%3.%4")).arg(m_aquireIntoSaveParam.m_savePath)
QString scanFileName = QString(tr("%1%2%3.%4")).arg(m_aquireIntoSaveParam.m_savePath)
.arg(m_aquireIntoSaveParam.m_fileNamePrefix)
.arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
.arg(m_aquireIntoSaveParam.m_fileNameExt);
......@@ -900,14 +846,14 @@ void MainWindow::on_new_image(void *img)
{
assert(m_scanFileName.isEmpty());
assert(nullptr == m_scanImgFmtWriter);
HGBase_CreateDir(getStdString(getStdFileName(m_aquireIntoSaveParam.m_savePath)).c_str());
HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str());
QString scanFileName = QString(tr("%1/%2%3.%4")).arg(m_aquireIntoSaveParam.m_savePath)
QString scanFileName = QString(tr("%1%2%3.%4")).arg(m_aquireIntoSaveParam.m_savePath)
.arg(m_aquireIntoSaveParam.m_fileNamePrefix)
.arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
.arg(m_aquireIntoSaveParam.m_fileNameExt);
HGImgFmt_SaveImage(image, 0, nullptr, 0, getStdString(scanFileName).c_str());
HGImgFmt_SaveImage(image, 0, nullptr, 0, getStdString(getStdFileName(scanFileName)).c_str());
m_thumb->addItem(scanFileName);
++m_aquireIntoSaveParam.m_fileNameStartIndex;
}
......@@ -925,8 +871,6 @@ void MainWindow::on_scan_working(QString workingInfo)
void MainWindow::on_scan_finish(QString finishInfo, int err)
{
m_isScanning = false;
if (nullptr != m_scanImgFmtWriter)
{
HGImgFmt_CloseImageWriter(m_scanImgFmtWriter);
......@@ -935,6 +879,7 @@ void MainWindow::on_scan_finish(QString finishInfo, int err)
m_scanFileName.clear();
}
m_isScanning = false;
m_thumb->setAcceptDrops(true);
m_dialogLog->updateStatus(nullptr != m_saneDeviceHandle && 0 != m_scanType, m_isScanning);
updateActionStatus();
......@@ -956,7 +901,11 @@ void MainWindow::on_continueScan()
return;
}
SANE_Status ret = sane_start(m_saneDeviceHandle);
SANE_Status ret;
if (m_singleScan)
ret = sane_io_control(m_saneDeviceHandle, IO_CTRL_CODE_TEST_SINGLE, nullptr, nullptr);
else
ret = sane_start(m_saneDeviceHandle);
if (ret != SANE_STATUS_GOOD)
{
m_wndStatusBar->setDeviceStatusInfo(tr("start failed"), true);
......@@ -1041,12 +990,12 @@ void MainWindow::on_act_last_triggered()
QString MainWindow::getCacheFileName()
{
QString filePath = APP_CACHE_PATH;
HGBase_CreateDir(getStdString(getStdFileName(filePath)).c_str());
QString cachePath = Dialog_ClrCache::getCachePath();
HGBase_CreateDir(getStdString(cachePath).c_str());
char uuid[256] = {0};
HGBase_GetUuid(uuid, 256);
QString fileName = getStdFileName(filePath + "/" + uuid + ".jpg");
QString fileName = getStdFileName(cachePath + uuid + ".jpg");
return fileName;
}
......@@ -1235,10 +1184,10 @@ bool MainWindow::startSpaceCheck(QWidget* parent)
{
QString savePath;
if (1 == m_scanType)
savePath = APP_CACHE_PATH;
savePath = Dialog_ClrCache::getCachePath();
else if (2 == m_scanType)
savePath = m_aquireIntoSaveParam.m_savePath;
if (0 == savePath.indexOf(storage.rootPath()))
if (0 == savePath.indexOf(getStdFileName(storage.rootPath())))
{
space = storage.bytesAvailable() / 1024 / 1024;
break;
......@@ -1783,7 +1732,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
}
}
QDir dir = QDir(APP_CACHE_PATH);
QDir dir = QDir(Dialog_ClrCache::getCachePath());
dir.removeRecursively();
QMainWindow::closeEvent(e);
}
......@@ -2196,6 +2145,7 @@ void MainWindow::on_act_acquire_triggered()
return;
}
m_singleScan = false;
m_scanType = 1;
m_scanInsertPos = -1;
......@@ -2239,6 +2189,7 @@ void MainWindow::on_act_acquireSingle_triggered()
return;
}
m_singleScan = true;
m_scanType = 1;
m_scanInsertPos = -1;
......@@ -2285,15 +2236,15 @@ void MainWindow::on_act_acquireInto_triggered()
Dialog_AquireInto dlg(this);
if (dlg.exec())
{
m_singleScan = false;
m_scanType = 2;
m_aquireIntoSaveParam = dlg.getSaveParam();
if (m_aquireIntoSaveParam.m_isUseSubfolderByTime)
{
QDate date = QDate::currentDate();
QString str = date.toString("yyyy-MM-dd");
m_aquireIntoSaveParam.m_savePath += "/";
m_aquireIntoSaveParam.m_savePath += str;
QString newSavePath = m_aquireIntoSaveParam.m_savePath + date.toString("yyyy-MM-dd") + "/";
m_aquireIntoSaveParam.m_savePath = getStdFileName(newSavePath);
}
if (!startSpaceCheck(this))
......@@ -2331,6 +2282,7 @@ void MainWindow::on_act_insertFromScanner_triggered()
Dialog_InsertIndex dlg(this);
if (dlg.exec())
{
m_singleScan = false;
m_scanType = 1;
m_scanInsertPos = -1;
......
......@@ -221,6 +221,7 @@ private:
int m_multiIndex;
bool m_relation; // m_view上的图像是否关联到m_thumb
bool m_modify; // m_view上面的图像是否改变
bool m_singleScan; // 是否单张扫描
int m_scanType; // 1-扫描到缓存目录,2-扫描到本地目录
int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后
QString m_scanFileName;
......
......@@ -59,7 +59,6 @@ SOURCES += \
../../../app/scanner/dialog_passwordchange.cpp \
../../../app/scanner/dialog_saveas.cpp \
../../../app/scanner/dialog_savequality.cpp \
../../../app/scanner/global.cpp \
../../../app/scanner/hg_settingdialog.cpp \
../../../app/scanner/main.cpp \
../../../app/scanner/mainwindow.cpp \
......@@ -92,7 +91,6 @@ HEADERS += \
../../../app/scanner/dialog_passwordchange.h \
../../../app/scanner/dialog_saveas.h \
../../../app/scanner/dialog_savequality.h \
../../../app/scanner/global.h \
../../../app/scanner/hg_settingdialog.h \
../../../app/scanner/mainwindow.h \
../../../app/scanner/widget_imgproc_base.h \
......
#include "HGUIGlobal.h"
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
QString getStdFileName(const QString &fileName)
......@@ -16,3 +18,57 @@ std::string getStdString(const QString &str)
return str.toStdString();
#endif
}
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
static std::string Utf8ToAnsi(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_UTF8, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pAnsi = new CHAR[len];
::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pAnsi;
delete[] pAnsi;
return ret;
}
#endif
std::string Utf8ToStdString(const char* utf8)
{
#if defined(HG_CMP_MSC)
return Utf8ToAnsi(utf8);
#else
return utf8;
#endif
}
std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
void TrimString(std::string& str)
{
int s = (int)str.find_first_not_of(" ");
int e = (int)str.find_last_not_of(" ");
str = str.substr(s, e - s + 1);
}
......@@ -7,4 +7,10 @@ QString getStdFileName(const QString &fileName);
std::string getStdString(const QString &str);
std::string Utf8ToStdString(const char* utf8);
std::string StdStringToUtf8(const char* str);
void TrimString(std::string& str);
#endif /* __HGUIGLOBAL_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment