基本完成网络设置模块,还有一些细节需要完善。

This commit is contained in:
xueyan hu
2021-12-17 18:02:39 +08:00
parent faa69197f3
commit b6475e7ed4
21 changed files with 1979 additions and 421 deletions

View File

@@ -7,14 +7,13 @@
#include <QLabel>
#include <QLineEdit>
#include <QEvent>
#include <QToolButton>
#include "json/jsonobject.h"
#include "SelectDialog.h"
#include "components/imageswitch.h"
#include "components/ipaddress.h"
#include <QProcess>
#include "network/networkcfgdialog.h"
systemSettingForm::systemSettingForm(QWidget* parent) : QWidget(parent)
{
@@ -390,8 +389,6 @@ systemSettingForm::systemSettingForm(QWidget* parent) : QWidget(parent)
lbl_list->setFixedWidth(100);
lbl_verify->setFixedWidth(100);
lbl_Local->setFixedHeight(50);
const QString style = "QLineEdit{min-height:36px;max-height:36px;border:0px}";
this->setStyleSheet(style);
//data init
@@ -400,12 +397,15 @@ systemSettingForm::systemSettingForm(QWidget* parent) : QWidget(parent)
loadServersInfo();
//connection
connect(swt_verify, &ImageSwitch::clicked, [=]() {
if(swt_verify->getChecked())
{
autoDHCP();
}
});
connect(swt_verify, &ImageSwitch::clicked, [=]() {
if (swt_verify->getChecked())
{
//autoDHCP();
networkCfgDialog dia(this);
dia.setWindowModality(Qt::WindowModal);
dia.exec();
}
});
connect(btnCancel, &QToolButton::clicked, [=]() {
loadServersInfo();
@@ -474,36 +474,16 @@ void systemSettingForm::loadServersInfo()
wl_Name->setText(h.name);
wl_Port->setText(h.port);
localhost lhost = JsonObject::Instance()->getLocalHost();
local_IP->setIP(lhost.ip);
local_Mask->setIP(lhost.mask);
local_Gate->setIP(lhost.gateway);
//localhost lhost = JsonObject::Instance()->getLocalHost();
//local_IP->setIP(lhost.ip);
//local_Mask->setIP(lhost.mask);
//local_Gate->setIP(lhost.gateway);
qIfConfig(lhost);
//qIfConfig(lhost);
}
void systemSettingForm::qIfConfig(const localhost &lhost)
{
QProcess *myProcess = new QProcess;
//QString cmd = QString("echo %1 | sudo -S ifconfig eth0 %2 up").;
QString cmd = QString("echo %1 | sudo -S ifconfig eth0 %2 netmask %3 up; sudo -S route del default dev eth0; \
sudo -S route add default gw %4").arg("klxts4047").arg(lhost.ip).arg(lhost.mask).arg(lhost.gateway);
QStringList args;
args<<"-c"<<cmd;
myProcess->start("/bin/sh",args);
}
void systemSettingForm::autoDHCP()
{
QProcess *myProcess = new QProcess;
//QString cmd = QString("echo %1 | sudo -S cp cfgs/ifcfg-eth0 /etc/sysconfig/network/ifcfg-eth0; sudo -S rcnetwork restart eth0").arg("klxts4047");
//we propose that the default config is DHCP
QString cmd = QString("echo %1 | sudo -S rcnetwork restart eth0").arg("klxts4047");
QStringList args;
args<<"-c"<<cmd;
myProcess->start("/bin/sh",args);
}
void systemSettingForm::saveServersInfo()
{
@@ -535,12 +515,12 @@ void systemSettingForm::saveServersInfo()
JsonObject::Instance()->setServer(JsonObject::DAQ, h);
localhost lhost;
lhost.ip = local_IP->getIP();
lhost.mask = local_Mask->getIP();
lhost.gateway = local_Gate->getIP();
JsonObject::Instance()->setLocalHost(lhost);
//localhost lhost;
//lhost.ip = local_IP->getIP();
//lhost.mask = local_Mask->getIP();
//lhost.gateway = local_Gate->getIP();
//JsonObject::Instance()->setLocalHost(lhost);
qIfConfig(lhost);
//qIfConfig(lhost);
}