FaceAccess/Linguist/setUi/settingUiSysMng.cpp
2024-07-11 11:27:12 +08:00

309 lines
12 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <QDebug>
#include "settingUiSysMng.h"
#include "UiConfig.h"
int settingUiSysMng::m_pageIndex = 0;
settingUiSysMng::settingUiSysMng(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("设备语言"), "xxxxx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("数据加密"), "", myListWidget::enPropertySwitch),
SetOpn(tr("自动重启"), "", myListWidget::enPropertySwitch),
SetOpn(tr("自动重启时间"), "xx:xx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("自动重启间隔(天)"), "xx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("手动重启"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("服务器"), "xxxxxxxxxxxx:xxxx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("数据清空"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("恢复出厂设置"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyRedWord))
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiSysMng()";
}
settingUiSysMng::~settingUiSysMng()
{
qDebug() << "~settingUiSysMng()";
}
void settingUiSysMng::setBackstageUiinterface(BackstageInterfaceForUi *interface)
{
m_backstageIf = interface;
reset();
}
void settingUiSysMng::reset()
{
if(nullptr == m_backstageIf){
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
const int iBufSize = 64;
char buf[iBufSize] = {'\0'};
switch(i)
{
case SYS_MNG_LANGUAGE:
{
int lang = static_cast<int>(m_backstageIf->getLanguage());
if(lang >= 0 && lang < Language.size()){
str = Language[lang];
}
}
break;
case SYS_MNG_AUTO_REBOOT:
{
bool switch_option = false;
if(SYS_MNG_AUTO_REBOOT == i){
switch_option = m_backstageIf->getAutoRebootSw();
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case SYS_MNG_AUTO_REBOOT_TIME:
if(0 == m_backstageIf->getAutoRebootTime(buf, iBufSize)){
str = QString(buf);
}
break;
case SYS_MNG_AUTO_REBOOT_INTERVAL:
str = QString::number(m_backstageIf->getAutoRebootInterval());
break;
case SYS_MNG_SERVER_ADDR:
if(0 == m_backstageIf->getServerAddr(buf, iBufSize)){
str = QString(buf);
}
break;
case SYS_MNG_DATA_ENCRYPT:qDebug() << "SYS_MNG_DATA_ENCRYPT";
{
bool switch_option = m_backstageIf->getDataEncryptSw();
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
default:
break;
}
wdt->updateLabel(str);
}
controlListWidgetItemShow(m_backstageIf->getAutoRebootSw(), SYS_MNG_AUTO_REBOOT_TIME);
controlListWidgetItemShow(m_backstageIf->getAutoRebootSw(), SYS_MNG_AUTO_REBOOT_INTERVAL);
controlListWidgetItemShow(!UiConfig::GetInstance()->isFuncNotSupport(FuncDataEncrypt), SYS_MNG_DATA_ENCRYPT);
}
void settingUiSysMng::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
switch(row){
case SYS_MNG_LANGUAGE:
{
int choosed = 0;
const QVector<QString>& opts = Language;
if(SYS_MNG_LANGUAGE == row){
#ifndef DEBUG_MODE
choosed = static_cast<int>(m_backstageIf->getLanguage());
#endif
}
RadioBtnChooseDialog dlg(opts, parent()->parent(), choosed, &LanguageSup, "");
if(QDialog::Accepted == dlg.exec())
{
int newChoosed = dlg.getChoosedIndex();
qDebug() << "newChoosed:" << newChoosed;
if(newChoosed != choosed){
QuestionDialog queDlg(tr("您需要重新启动设备以设置并切换语言"), parent()->parent(), tr("重新启动"));
if(QDialog::Accepted == queDlg.exec()){
#ifndef DEBUG_MODE
m_backstageIf->setLanguage(newChoosed);
PureColorPage* black = new PureColorPage(0);
black->show();
QTimer::singleShot(1000, this, SLOT(slotSysReboot()));
//m_backstageIf->devReboot();
#endif
wdt->updateLabel(opts[newChoosed]);
}
}
}
}
break;
case SYS_MNG_DATA_ENCRYPT:
{
bool setting_value = !(m_backstageIf->getDataEncryptSw());
QuestionDialog queDlg(setting_value ? tr("您确定要开启数据加密吗?若确定设备将重启!") : tr("您确定要关闭数据加密吗?若确定设备将重启!"), parent()->parent());
if(QDialog::Accepted == queDlg.exec()){
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
m_backstageIf->setDataEncryptSw(setting_value);
QTimer::singleShot(1000, this, SLOT(slotSysReboot()));
}
}
break;
case SYS_MNG_AUTO_REBOOT:
{
bool setting_value = false;
#ifndef DEBUG_MODE
if(SYS_MNG_AUTO_REBOOT == row){
setting_value = static_cast<bool>(m_backstageIf->getAutoRebootSw());
}
#endif
setting_value = static_cast<bool>(!setting_value);
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
#ifndef DEBUG_MODE
if(SYS_MNG_AUTO_REBOOT == row){
m_backstageIf->setAutoRebootSw(setting_value);
controlListWidgetItemShow(setting_value, SYS_MNG_AUTO_REBOOT_TIME);
controlListWidgetItemShow(setting_value, SYS_MNG_AUTO_REBOOT_INTERVAL);
}
#endif
}
break;
case SYS_MNG_AUTO_REBOOT_TIME:
{
const int iBufSize = 64;
char buf[iBufSize] = {'\0'};
if(0 == m_backstageIf->getAutoRebootTime(buf, iBufSize)){
QDateTime dateTime(QDateTime::currentDateTime());
dateTime.setTime(QTime().fromString(QString(buf), "hh:mm"));
DateTimeDialog timeDlg(dateTime, parent()->parent(), false);
if(timeDlg.exec() == QDialog::Accepted){
m_backstageIf->setAutoRebootTime(timeDlg.getValueSet().toString("hh:mm").toStdString().c_str());
wdt->updateLabel(timeDlg.getValueSet().toString("hh:mm"));
}
}
}
break;
case SYS_MNG_AUTO_REBOOT_INTERVAL:
{
int currentValue = 10;
int min = 0;
int max = 100;
QString tip("this is a line of prompt text");
#ifndef DEBUG_MODE
if(SYS_MNG_AUTO_REBOOT_INTERVAL == row){
currentValue = m_backstageIf->getAutoRebootInterval();
min = 1;
max = 100;
tip.clear();
}
#endif
SliderDialog dlg(currentValue, min, max, tip, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString str("valueSet");
int valueSet = dlg.getValueSet();
#ifndef DEBUG_MODE
if(SYS_MNG_AUTO_REBOOT_INTERVAL == row){
m_backstageIf->setAutoRebootInterval(valueSet);
str = QString::number(valueSet);
}
#endif
wdt->updateLabel(str);
}
}
break;
case SYS_MNG_SERVER_ADDR:
{
bool settingFailed = true;
do{
QStringList strs;
if(SYS_MNG_SERVER_ADDR == row){
strs << tr("服务器地址:") << tr("端口:");
}
LineEditInputDialog dlg(strs, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString str;
do{
if(SYS_MNG_SERVER_ADDR == row){
if("" != dlg.getRow(0) && "" != dlg.getRow(1)){
bool isDigi = false;
int valueSet = dlg.getRow(1).toInt(&isDigi);
if( (!isDigi) || (valueSet < 0 || valueSet > 65535)){
break;
}
if(m_backstageIf){
str = dlg.getRow(0) + ":" + dlg.getRow(1);
m_backstageIf->setServerAddr(const_cast<char*>(str.toStdString().c_str()));
wdt->updateLabel(str);
settingFailed = false;
}
}
}
}while(0);
}
else {
settingFailed = false;
}
if(settingFailed)
{
InfoDialog(tr("设置有误,请重新输入!"), parent()->parent()).exec();
}
}while(settingFailed);
}
break;
case SYS_MNG_MAN_REBOOT:
case SYS_MNG_CLEAR_DATA:
case SYS_MNG_RESTORE:
{
QString que;
QString btnText;
if(SYS_MNG_MAN_REBOOT == row){
que = tr("您确定重新启动FaceTick吗");
btnText = tr("重新启动");
}
else if(SYS_MNG_CLEAR_DATA == row){
que = tr("您确定清空数据吗?");
btnText = tr("清空数据");
}
else if(SYS_MNG_RESTORE == row){
que = tr("您确定恢复出厂设置吗?");
btnText = tr("恢复");
}
QuestionDialog dlg(que, parent()->parent(), btnText);
if(QDialog::Accepted == dlg.exec()){
#ifndef DEBUG_MODE
if(SYS_MNG_MAN_REBOOT == row){
PureColorPage* black = new PureColorPage(0);
black->show();
QTimer::singleShot(1000, this, SLOT(slotSysReboot()));
//m_backstageIf->devReboot();
}
else if(SYS_MNG_CLEAR_DATA == row){
m_backstageIf->cleanData();
}
else if(SYS_MNG_RESTORE == row){
m_backstageIf->recoveryFactorySetting();
//create a black page before sys reboot
PureColorPage* black = new PureColorPage(0);
black->show();
QTimer::singleShot(1000, this, SLOT(slotSysReboot()));
}
#endif
}
}
break;
default:
break;
}
}
void settingUiSysMng::slotSysReboot()
{
m_backstageIf->devReboot();
}