[bug fixes]
This commit is contained in:
@@ -32,6 +32,7 @@ public:
|
||||
|
||||
static bool testSetMode(QString& err_info);
|
||||
static void testGetMode();
|
||||
|
||||
//private:
|
||||
//explicit NetworkManager(QObject* parent = nullptr);
|
||||
//static NetworkManager* instance;
|
||||
|
||||
@@ -7,11 +7,19 @@
|
||||
|
||||
#include <QItemSelectionModel>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
|
||||
#include "guimessagedialog.h"
|
||||
|
||||
#include <QThread>
|
||||
networkCfgDialog::networkCfgDialog(QWidget* parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::networkCfgDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
msgDialog = new GUIMessageDialog(this);
|
||||
msgDialog->hide();
|
||||
|
||||
|
||||
setShadow(this);
|
||||
|
||||
ui->sw_dhcp->setChecked(true);
|
||||
@@ -184,55 +192,96 @@ void networkCfgDialog::loadData()
|
||||
ui->addr_ip->setText(default_addr.ip);
|
||||
ui->addr_mask->setText(default_addr.mask);
|
||||
ui->led_gw->setText(NetworkManager::getDefaultGateway());
|
||||
|
||||
model_addr->loadData(NetworkManager::getIpAddrList());
|
||||
model_route->loadData(NetworkManager::getIpRouteList());
|
||||
|
||||
}
|
||||
|
||||
bool networkCfgDialog::isModified()
|
||||
{
|
||||
if (ui->sw_dhcp->getChecked() != NetworkManager::isDHCP()) return true;
|
||||
|
||||
const IpAddr& default_addr = NetworkManager::getDefaultIpAddr();
|
||||
if (ui->addr_ip->text() != default_addr.ip) return true;
|
||||
if (ui->addr_mask->text() != default_addr.mask) return true;
|
||||
if (ui->led_gw->text() != NetworkManager::getDefaultGateway())return true;
|
||||
if (model_addr->getData() != NetworkManager::getIpAddrList())return true;
|
||||
if (model_route->getData() != NetworkManager::getIpRouteList()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void networkCfgDialog::afterThreadStart()
|
||||
{
|
||||
msgDialog->showMessage("Saving Network Configuration...");
|
||||
msgDialog->show();
|
||||
}
|
||||
void networkCfgDialog::beforeThreadExit()
|
||||
{
|
||||
|
||||
msgDialog->hide();
|
||||
ui->output->setPlainText(err);
|
||||
myThread->deleteLater();
|
||||
}
|
||||
|
||||
void networkCfgDialog::applyData()
|
||||
{
|
||||
|
||||
//compare with the old
|
||||
//if it is the same as the old, just exit
|
||||
if (!isModified())
|
||||
{
|
||||
accept();
|
||||
}
|
||||
ui->tabWidget->setCurrentIndex(2);
|
||||
|
||||
QString err;
|
||||
err.append("restart\t\t");
|
||||
|
||||
bool ret = NetworkManager::restart(err);
|
||||
//bool ret =true;
|
||||
//err.append(boolToStr(ret));
|
||||
|
||||
err.append("\n");
|
||||
if (ui->sw_dhcp->getChecked())
|
||||
{
|
||||
NetworkManager::setJsonDHCP(true);
|
||||
err.append("network setting\t");
|
||||
err.append(boolToStr(ret));
|
||||
}
|
||||
else
|
||||
{
|
||||
NetworkManager::setJsonDHCP(false);
|
||||
myThread = QThread::create([=]()
|
||||
{
|
||||
err.clear();
|
||||
err.append("restart\t\t");
|
||||
|
||||
bool ret = NetworkManager::restart(err);
|
||||
//bool ret =true;
|
||||
//err.append(boolToStr(ret));
|
||||
|
||||
err.append("\n");
|
||||
if (ui->sw_dhcp->getChecked())
|
||||
{
|
||||
NetworkManager::setJsonDHCP(true);
|
||||
err.append("network setting\t");
|
||||
err.append(boolToStr(ret));
|
||||
}
|
||||
else
|
||||
{
|
||||
NetworkManager::setJsonDHCP(false);
|
||||
|
||||
IpAddr de_ipa;
|
||||
de_ipa.ip = ui->addr_ip->text();
|
||||
de_ipa.mask = ui->addr_mask->text();
|
||||
err.append("setDefaultIpAddr\t");
|
||||
bool ret1 = NetworkManager::setDefaultIpAddr(de_ipa, err);
|
||||
err.append("setDefaultGateway\t");
|
||||
bool ret2 = NetworkManager::setDefaultGateway(ui->led_gw->text(), err);
|
||||
err.append("setIpAddrList\t");
|
||||
bool ret3 = NetworkManager::setIpAddrList(model_addr->getData(), err);
|
||||
err.append("setIpRouteList\t");
|
||||
bool ret4 = NetworkManager::setIpRouteList(model_route->getData(), err);
|
||||
err.append("\n").append("network setting\t");
|
||||
|
||||
bool retAll = ret & ret1 & ret2 & ret3 & ret4;
|
||||
err.append(boolToStr(retAll));
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
connect(myThread, SIGNAL(started()), this, SLOT(afterThreadStart()));
|
||||
connect(myThread, SIGNAL(finished()), this, SLOT(beforeThreadExit()));
|
||||
|
||||
myThread->start();
|
||||
|
||||
IpAddr de_ipa;
|
||||
de_ipa.ip = ui->addr_ip->text();
|
||||
de_ipa.mask = ui->addr_mask->text();
|
||||
err.append("setDefaultIpAddr\t");
|
||||
bool ret1 = NetworkManager::setDefaultIpAddr(de_ipa, err);
|
||||
err.append("setDefaultGateway\t");
|
||||
bool ret2 = NetworkManager::setDefaultGateway(ui->led_gw->text(), err);
|
||||
err.append("setIpAddrList\t");
|
||||
bool ret3 = NetworkManager::setIpAddrList(model_addr->getData(), err);
|
||||
err.append("setIpRouteList\t");
|
||||
bool ret4 = NetworkManager::setIpRouteList(model_route->getData(), err);
|
||||
err.append("\n").append("network setting\t");
|
||||
|
||||
bool retAll = ret & ret1 & ret2 & ret3 & ret4;
|
||||
err.append(boolToStr(retAll));
|
||||
}
|
||||
ui->output->setPlainText(err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace Ui {
|
||||
}
|
||||
|
||||
class NetCfgTableModel;
|
||||
class GUIMessageDialog;
|
||||
class QThread;
|
||||
|
||||
class networkCfgDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -21,14 +24,22 @@ public:
|
||||
void applyData();
|
||||
|
||||
|
||||
public slots:
|
||||
void afterThreadStart();
|
||||
void beforeThreadExit();
|
||||
|
||||
private:
|
||||
bool isModified();
|
||||
const char* boolToStr(bool b)
|
||||
{
|
||||
return b ? "sucess" : "failed";
|
||||
}
|
||||
NetCfgTableModel* model_addr = nullptr;
|
||||
NetCfgTableModel* model_route = nullptr;
|
||||
GUIMessageDialog* msgDialog = nullptr;
|
||||
Ui::networkCfgDialog* ui;
|
||||
QThread* myThread = nullptr;
|
||||
QString err;
|
||||
};
|
||||
|
||||
#endif // NetworkCfgDialog_H
|
||||
|
||||
@@ -20,69 +20,7 @@
|
||||
<string>Network Settings</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QWidget{
|
||||
background-color:#3c3c3c;
|
||||
color:#fcfcfc;
|
||||
margin:0;
|
||||
font-size:16px;
|
||||
border:0px;
|
||||
font-weight:normal;
|
||||
font-family:Microsoft YaHei
|
||||
}
|
||||
|
||||
QTabWidget::pane {
|
||||
border-top: 0px;
|
||||
}
|
||||
|
||||
QTabBar::tab {
|
||||
font-size:16px;
|
||||
height:30px;
|
||||
width:100px;
|
||||
background:#4d4d4d;
|
||||
border: 0px;
|
||||
border-top-left-radius: 10%;
|
||||
border-top-right-radius: 10%;
|
||||
border-bottom-left-radius:0%;
|
||||
border-bottom-right-radius:0%;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
QTabBar::tab:selected, QTabBar::tab:hover {
|
||||
border-bottom:5px solid #4a88c7;
|
||||
background: #505050;}
|
||||
|
||||
QPushButton{
|
||||
border-radius:5px;
|
||||
padding-left:10px;
|
||||
padding-right:10px;
|
||||
min-height:28px;
|
||||
max-height:28px;
|
||||
min-width:60px;
|
||||
max-width:60px;
|
||||
background:#4d4d4d;
|
||||
}
|
||||
|
||||
QLineEdit{
|
||||
color:#bcbcbc;
|
||||
min-height:26px;
|
||||
max-height:26px;
|
||||
border:0px;
|
||||
background-color: #232629;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
QTableView{
|
||||
background-color: #232629;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
QHeaderView::section:horizontal{
|
||||
border-bottom: 1px solid rgb(0,170,255);
|
||||
}
|
||||
QHeaderView::section:vertical{
|
||||
min-height:20px;
|
||||
max-height:20px;
|
||||
}</string>
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
@@ -190,13 +128,13 @@ max-height:20px;
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>26</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>26</height>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -336,13 +274,13 @@ max-height:20px;
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>190</width>
|
||||
<height>26</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>190</width>
|
||||
<height>26</height>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
||||
Reference in New Issue
Block a user