Refactor system page in GUI Alpha.

This commit is contained in:
sunwen
2024-04-25 14:37:38 +08:00
parent f9eb807fa3
commit 982b54b727
420 changed files with 23907 additions and 872 deletions

View 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);
}

View 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

View 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();
}

View 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

View File

@@ -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);