HM-SPMS/product/src/tools/workBench/SystemSetForm.cpp
2025-03-13 15:21:23 +08:00

247 lines
6.6 KiB
C++

#include "SystemSetForm.h"
#include "ui_SystemSetForm.h"
#include "DataMng.h"
#include "DogCheck.h"
#include "SetupFunc.h"
#include "pub_utility_api/FileUtil.h"
#include "pub_utility_api/I18N.h"
#include "../include/sys/sys_login_api/CLoginDlg.h"
#include "ModifyButtonForm.h"
#include <QDesktopServices>
#include <QUrl>
#include <QFileInfo>
#include <QDir>
#include <QProcess>
#include <QButtonGroup>
using namespace workBench;
SystemSetForm::SystemSetForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::SystemSetForm),
m_groupBtn(Q_NULLPTR)
{
ui->setupUi(this);
m_language = iot_public::getCurLanguage().c_str();
initView();
initConn();
ui->tabWidget->setCurrentIndex(1);
ui->mainPathValue->installEventFilter(this);
ui->backPathValue->installEventFilter(this);
}
SystemSetForm::~SystemSetForm()
{
delete ui;
}
void SystemSetForm::setAuthorityLabelText(int model)
{
switch (model) {
case 0:
ui->lbl_active_state->setText(tr("未检测"));
break;
case 1:
ui->lbl_active_state->setText(tr("未激活"));
break;
case 2:
ui->lbl_active_state->setText(tr("已激活"));
break;
default:
ui->lbl_active_state->setText(tr("未检测"));
break;
}
}
void SystemSetForm::linkActive(const QString &link)
{
LOGDEBUG("SystemSetForm:%s",link.toStdString().c_str());
QDesktopServices::openUrl(QUrl("file:///"+link,QUrl::TolerantMode));
}
void SystemSetForm::slotActiveBtnClicked()
{
DogCheck dogCheck(this);
dogCheck.exec();
}
void SystemSetForm::slotCheckBoxSelfStart(int state)
{
QString text = "";
QString strErr;
if( Qt::Checked == state && !m_isSys)
{
if(iot_sys::regSysService(strErr))
{
text+=tr("设置系统开机自启动成功...");
}
else
{
text+=tr("设置系统开机自启动失败...错误:%1").arg(strErr);
}
emit sigLogText(text);
}else if( Qt::Unchecked == state && m_isSys)
{
if(iot_sys::unregSysService(strErr))
{
text+=tr("注销系统开机自启动成功...");
}
else
{
text+=tr("注销系统开机自启动失败......错误:%1").arg(strErr);
}
emit sigLogText(text);
}
}
void SystemSetForm::slotBtnModifyClicked()
{
ModifyButtonForm form(m_language , this);
if( QDialog::Accepted == form.exec())
{
emit signalUpdataPage1(EN_SYS_STARTUP_PAGE1);
}
}
void SystemSetForm::slotBtnChangeClicked()
{
//自启动
slotCheckBoxSelfStart(ui->checkBox_selfStart->checkState());
//语言
int id = m_groupBtn->checkedId();
QString logStr,language = "";
switch (id) {
case 0:
language = "zh";
break;
case 1:
language = "en";
break;
case 2:
language = "fr";
break;
default:
return;
}
if( DataMng::instance()->modifyLanguageXml(language) )
{
logStr += tr("切换成功!请重启该软件");
}else
{
logStr += tr("切换失败..请稍后再试");
}
emit sigLogText(logStr);
}
bool SystemSetForm::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
QEvent::Type type = event->type();
switch (type) {
case QEvent::MouseButtonDblClick: {
if ( ui->mainPathValue == static_cast<QWidget*>(watched) )
{
showInFolder(ui->mainPathValue->text());
}else if( ui->backPathValue == static_cast<QWidget*>(watched) )
{
showInFolder(ui->backPathValue->text());
}
}
break;
default:
return false;
}
return true;
}
void SystemSetForm::initView()
{
QMap<QString,QString> versionMap = DataMng::instance()->getVersionInfo();
ui->label->setProperty("type" , "titleComm" );
ui->label_title->setProperty("type" , "titleComm" );
ui->label_title2->setProperty("type" , "titleComm" );
ui->versionValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_VERSION),tr("无版本信息")));
ui->mainValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_ISMAIN),"0") == "1" ? tr("已安装"):tr("未安装"));
ui->dbValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_ISDB),"0") == "1" ? tr("已安装"):tr("未安装"));
ui->webValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_ISWEB),"0") == "1" ? tr("已安装"):tr("未安装"));
const std::string strFileName = "hmi_explorer.bat";
QString strPath = QString::fromStdString( iot_public::CFileUtil::getPathOfBinDir(CN_DIR_PLATFORM));
QDir pathFile(strPath);
pathFile.cdUp();
pathFile.cdUp();
ui->mainPathValue->setText(pathFile.absolutePath());
if( pathFile.cd("backup"))
{
ui->backPathValue->setText(pathFile.absolutePath());
}else
{
ui->backPathValue->setText(tr("暂无"));
}
if(versionMap.value(QString::fromStdString(SOFTWARE_ISDB),"0") == "0")
{
ui->dbPathValue->setText(tr("无数据库路径"));
}else
{
//#ifdef OS_WINDOWS
// ui->dbPathValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_DBPATH)));
//#endif
//#ifdef OS_LINUX
ui->dbPathKey->setVisible(false);
ui->dbPathValue->setVisible(false);
adjustSize();
//ui->db_layout->setVisible(false);
//#endif
}
QString strSysErr;
m_isSys = false;
m_isSys = iot_sys::isSysService(strSysErr);
ui->checkBox_selfStart->setChecked(m_isSys);
m_groupBtn = new QButtonGroup(this);
m_groupBtn->addButton(ui->checkBox_chinese , 0);
m_groupBtn->addButton(ui->checkBox_english , 1);
m_groupBtn->addButton(ui->checkBox_fr , 2);
if( m_language == "zh"){
ui->checkBox_chinese->setChecked(true);
}else if( m_language == "en"){
ui->checkBox_english->setChecked(true);
}else if( m_language == "fr"){
ui->checkBox_fr->setChecked(true);
}
}
void SystemSetForm::initConn()
{
connect(ui->btn_active , &QToolButton::clicked , this , &SystemSetForm::slotActiveBtnClicked);
connect(ui->btn_modeify , &QToolButton::clicked , this , &SystemSetForm::slotBtnModifyClicked);
connect(ui->btn_change , &QToolButton::clicked , this , &SystemSetForm::slotBtnChangeClicked);
}
void SystemSetForm::showInFolder(const QString &path)
{
//initView();
QFileInfo info(path);
#if defined(Q_OS_WIN)
QStringList args;
if (!info.isDir())
args << "/select,";
args << QDir::toNativeSeparators(path);
if (QProcess::startDetached("explorer", args))
return;
#endif
QDesktopServices::openUrl(QUrl::fromLocalFile(info.isDir()? path : info.path()));
}