HGGitLab

Commit 543dac9d authored by yangjiaxuan's avatar yangjiaxuan

增加清除缓存功能,并翻译

parent d3577653
......@@ -78,7 +78,8 @@ SOURCES += \
widget_statusbar.cpp \
hg_settingdialog.cpp \
dialog_logmanager.cpp \
global.cpp
global.cpp \
dialog_clrcache.cpp
HEADERS += \
../../../ui/HGUIGlobal.h \
......@@ -104,7 +105,8 @@ HEADERS += \
widget_statusbar.h \
hg_settingdialog.h \
dialog_logmanager.h \
global.h
global.h \
dialog_clrcache.h
FORMS += \
dialog_admin.ui \
......@@ -125,7 +127,8 @@ FORMS += \
mainwindow.ui \
widget_imgproc_base.ui \
widget_statusbar.ui \
dialog_logmanager.ui
dialog_logmanager.ui \
dialog_clrcache.ui
TRANSLATIONS += \
Scanner_zh_CN.ts
......
This diff is collapsed.
#include "dialog_aquireinto.h"
#include "ui_dialog_aquireinto.h"
#include "dialog_savequality.h"
#include "global.h"
#include <QFileDialog>
#include <QDateTime>
#include <QRegExpValidator>
......@@ -16,7 +17,7 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
QRegExp rx("[^\\\\/:*?\"<>|]+$");
ui->lineEdit_fileName->setValidator(new QRegExpValidator(rx, this));
QString filePath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Huago/ScannerApp/AquireInto";
QString filePath = APP_AQUIREINTO_PATH;
ui->lineEdit_directory->setText(filePath);
ui->cbtn_subFolder->setChecked(false);
ui->cbtn_subFolderByBlank->setChecked(false);
......
#include "dialog_clrcache.h"
#include "ui_dialog_clrcache.h"
#include "global.h"
#include <QMessageBox>
#include <QDir>
#include <QFileInfo>
#include <QKeyEvent>
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);
}
Dialog_ClrCache::~Dialog_ClrCache()
{
delete ui;
}
void Dialog_ClrCache::closeEvent(QCloseEvent *event)
{
(void)event;
if(m_isClear)
accept();
else
reject();
}
void Dialog_ClrCache::keyPressEvent(QKeyEvent* event)
{
switch (event->key())
{
case Qt::Key_Escape:
break;
default:
QDialog::keyPressEvent(event);
}
}
void Dialog_ClrCache::on_btn_clr_clicked()
{
QFileInfo file(APP_CACHE_PATH);
if(file.exists())
{
int ret = QMessageBox::question(this, tr("Question"), tr("Main window contains temporary files, clear cache would remove all of them.\n"
"Continue to clear?"));
if(ret != QMessageBox::Yes)
return;
}
else
{
QMessageBox::information(this, tr("Information"), tr("No cached file is available"));
}
if(file.exists() && clrCache(APP_CACHE_PATH))
{
QMessageBox::information(this, tr("Information"), tr("Cache clear successfully."));
Global::writeSyslog(user_level_messages, Informational, "User try to clear cache and succeed.");
}
else if(file.exists() && !clrCache(APP_CACHE_PATH))
{
QMessageBox::warning(this, tr("Warning"), tr("Cache clear failed or incompletely clear."));
Global::writeSyslog(user_level_messages, Informational, "User try to clear cache, but failed or incompletely clear.");
}
setInformation(APP_CACHE_PATH);
}
void Dialog_ClrCache::on_btn_close_clicked()
{
close();
}
bool Dialog_ClrCache::clrCache(const QString &path)
{
m_isClear = true;
QDir dir = QDir(path);
bool isSuccessful = dir.removeRecursively();
dir.mkpath(APP_CACHE_PATH);
return isSuccessful;
}
qint64 Dialog_ClrCache::getDirSize(const QString &path)
{
QDir dir(path);
qint64 size = 0;
foreach(QFileInfo info, dir.entryInfoList(QDir::Files))
size += info.size();
foreach(QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
size += getDirSize(path + QDir::separator() + subDir);
return size;
}
int Dialog_ClrCache::getFileNum(const QString &path)
{
QDir dir(path);
int num = 0;
foreach(QFileInfo info, dir.entryInfoList(QDir::Files))
num++;
foreach(QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
num += getFileNum(path + QDir::separator() + subDir);
return num;
}
void Dialog_ClrCache::setInformation(const QString &path)
{
//生成缓存占用空间大小信息
qint64 size = getDirSize(path);
double s = size;
int unit = 0;
while(true)
{
if(s > 1024.0)
{
s /= 1024.0;
unit += 1;
}
else
break;
}
QString sstring = QString::number(s, 'f', 2);
ui->lab_size->setText(sstring);
QString unitstring = unit == 3 ? "GB" : (unit == 2 ? "MB" : (unit == 1 ? "KB" : "B"));
ui->lab_unit->setText(unitstring);
QString Bstring = QString::number(size);
int commaNum = Bstring.size() / 3;
if(Bstring.size() % 3 == 0)
commaNum -= 1;
int offset = 0;
for(int i = 0; i < commaNum; i++)
{
Bstring.insert(Bstring.size() - 3 - offset * 4, ",");
offset += 1;
}
ui->lab_sizeByB->setText("(" + Bstring + " Byte)");
//生成文件个数信息
ui->lab_num->setNum(getFileNum(path));
}
#ifndef DIALOG_CLRCACHE_H
#define DIALOG_CLRCACHE_H
#include <QDialog>
namespace Ui {
class Dialog_ClrCache;
}
class Dialog_ClrCache : public QDialog
{
Q_OBJECT
public:
explicit Dialog_ClrCache(QWidget *parent = nullptr);
~Dialog_ClrCache();
protected:
void closeEvent(QCloseEvent *event);
void keyPressEvent(QKeyEvent* event);
private slots:
void on_btn_clr_clicked();
void on_btn_close_clicked();
private:
bool clrCache(const QString &path);
qint64 getDirSize(const QString &path);
int getFileNum(const QString &path);
void setInformation(const QString &path);
private:
Ui::Dialog_ClrCache *ui;
bool m_containTempFile, m_isClear;
};
#endif // DIALOG_CLRCACHE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_ClrCache</class>
<widget class="QDialog" name="Dialog_ClrCache">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>490</width>
<height>159</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>159</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>159</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Cache path:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Cache occupied space:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lab_size">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lab_unit">
<property name="text">
<string>B</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lab_sizeByB">
<property name="text">
<string>(0 Byte)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Number of files:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lab_num">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_clr">
<property name="text">
<string>Clear Cache</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_close">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -3,8 +3,9 @@
#include <QStandardPaths>
static const QString APP_FILE_PATH = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Huago/ScannerApp/Cache";
static const QString LOG_PATH = APP_FILE_PATH + "/log";
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";
static const QString LOG_PATH = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Huago/ScannerApp/Cache/Log";
enum LogFacility {
kernel_messages,
......
......@@ -24,6 +24,7 @@
#include "dialog_insertindex.h"
#include "dialog_aquireinto.h"
#include "dialog_logmanager.h"
#include "dialog_clrcache.h"
#if !defined(HG_CMP_MSC) || !defined(APP_USE_TWAIN)
#include "hg_settingdialog.h"
#endif
......@@ -1721,6 +1722,10 @@ void MainWindow::on_act_clrCache_triggered()
{
return;
}
Dialog_ClrCache d(this);
d.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
d.exec();
}
void MainWindow::on_act_consume_triggered()
......
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