Refactor system page in GUI Alpha.
This commit is contained in:
32
src/utilities/DiskInfoWorker.cpp
Normal file
32
src/utilities/DiskInfoWorker.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "DiskInfoWorker.h"
|
||||
#include "json/cmdhelper.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
DiskInfoWorker::DiskInfoWorker(QObject* aParent)
|
||||
: QObject (aParent)
|
||||
, mTimer(new QTimer(this))
|
||||
{
|
||||
connect(mTimer, &QTimer::timeout, this, &DiskInfoWorker::getDiskInfo);
|
||||
mTimer->start(30000);
|
||||
}
|
||||
|
||||
DiskInfoWorker::~DiskInfoWorker()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DiskInfoWorker::initDiskInfo()
|
||||
{
|
||||
double diskSize, diskUsed;
|
||||
bool flag = cmdHelper::Instance()->getDiskSize(diskSize);
|
||||
cmdHelper::Instance()->getDiskUsed(diskUsed);
|
||||
emit diskInfoInit(flag, diskSize, diskUsed);
|
||||
}
|
||||
|
||||
void DiskInfoWorker::getDiskInfo()
|
||||
{
|
||||
double diskUsed;
|
||||
bool flag = cmdHelper::Instance()->getDiskUsed(diskUsed);
|
||||
emit diskInfoBack(flag, diskUsed);
|
||||
}
|
||||
27
src/utilities/DiskInfoWorker.h
Normal file
27
src/utilities/DiskInfoWorker.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef DISKINFOWORKER_H
|
||||
#define DISKINFOWORKER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class DiskInfoWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiskInfoWorker(QObject* aParent = nullptr);
|
||||
~DiskInfoWorker();
|
||||
|
||||
public slots:
|
||||
void getDiskInfo();
|
||||
void initDiskInfo();
|
||||
|
||||
signals:
|
||||
void diskInfoBack(bool aDiskFlag, double aUsedDiskSize);
|
||||
void diskInfoInit(bool aDiskFlag, double aTotalDiskSize, double aUsedDiskSize);
|
||||
|
||||
private:
|
||||
QTimer* mTimer;
|
||||
};
|
||||
|
||||
#endif // DISKINFOWORKER_H
|
||||
15
src/utilities/InputFormatValidator.cpp
Normal file
15
src/utilities/InputFormatValidator.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "InputFormatValidator.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
bool InputFormatValidator::ValidateIpAddressFormat(const QString& aIpAddress)
|
||||
{
|
||||
QRegularExpression regex("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
|
||||
return regex.match(aIpAddress).hasMatch();
|
||||
}
|
||||
|
||||
bool InputFormatValidator::ValidatePortFormat(const QString& aPort)
|
||||
{
|
||||
QRegularExpression regex("^([1-9]\\d{0,4}|0)$");
|
||||
return regex.match(aPort).hasMatch();
|
||||
}
|
||||
16
src/utilities/InputFormatValidator.h
Normal file
16
src/utilities/InputFormatValidator.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef INPUTFORMATVALIDATOR_H
|
||||
#define INPUTFORMATVALIDATOR_H
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
class InputFormatValidator
|
||||
{
|
||||
public:
|
||||
InputFormatValidator() = delete;
|
||||
|
||||
static bool ValidateIpAddressFormat(const QString& aIpAddress);
|
||||
static bool ValidatePortFormat(const QString& aPort);
|
||||
};
|
||||
|
||||
#endif // INPUTFORMATVALIDATOR_H
|
||||
@@ -2,6 +2,22 @@
|
||||
|
||||
#include "event/EventCenter.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
QString changeLanguageToFileName(const QString& aLanguage)
|
||||
{
|
||||
if(aLanguage == "Chinese")
|
||||
{
|
||||
return "zh_CN";
|
||||
}
|
||||
else if(aLanguage == "English")
|
||||
{
|
||||
return "en_US";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
LanguageSwitcher* LanguageSwitcher::getInstance()
|
||||
{
|
||||
static LanguageSwitcher instance;
|
||||
@@ -29,7 +45,7 @@ QTranslator* LanguageSwitcher::getTranslator()
|
||||
|
||||
void LanguageSwitcher::setDefaultLanguage(const QString aLanguage)
|
||||
{
|
||||
QString language = QString(":/translations/" + aLanguage + ".qm");
|
||||
QString language = QString(":/translations/" + changeLanguageToFileName(aLanguage) + ".qm");
|
||||
if (mTranslator->load(language))
|
||||
{
|
||||
EventCenter::Default()->triggerEvent(ReloadLanguage, nullptr, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user