基本完成网络设置模块,还有一些细节需要完善。
This commit is contained in:
@@ -19,19 +19,22 @@
|
||||
"institutionAddr": "杭州市滨江区",
|
||||
"lockscreen": "30"
|
||||
},
|
||||
"pacsservers": [{
|
||||
"pacsservers": [
|
||||
{
|
||||
"ae": "HELLO",
|
||||
"ip": "127.0.0.1",
|
||||
"isdefault": "1",
|
||||
"name": "test",
|
||||
"port": "104"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"ae": "KISS",
|
||||
"ip": "127.0.0.1",
|
||||
"isdefault": "0",
|
||||
"name": "nihao",
|
||||
"port": "106"
|
||||
}],
|
||||
}
|
||||
],
|
||||
"protocol": {
|
||||
"default": "LSTAND",
|
||||
"lists": "LSTAND;RSTAND;LONE;RONE"
|
||||
@@ -49,19 +52,22 @@
|
||||
"remember": "false",
|
||||
"usercode": ""
|
||||
},
|
||||
"wklistservers": [{
|
||||
"wklistservers":[
|
||||
{
|
||||
"ae": "OFFIS",
|
||||
"ip": "127.0.0.1",
|
||||
"isdefault": "1",
|
||||
"name": "wklist sever",
|
||||
"port": "104"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"ae": "ACME1",
|
||||
"ip": "127.0.0.1",
|
||||
"isdefault": "0",
|
||||
"name": "wklist1",
|
||||
"port": "104"
|
||||
}],
|
||||
}
|
||||
],
|
||||
"worklistfilter": {
|
||||
"default": "Today",
|
||||
"lists": "Today;Recent3Days;ThisWeek;ThisMonth"
|
||||
|
||||
@@ -91,7 +91,6 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
||||
table->hideColumn(0);
|
||||
table->hideColumn(7);
|
||||
|
||||
|
||||
table->show();
|
||||
|
||||
// table->setSortingEnabled(true);
|
||||
@@ -213,10 +212,12 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
edit_patient->setPatientInformation(&pat);
|
||||
LOG_USER_OPERATION(DeletePatient);
|
||||
} else{
|
||||
}
|
||||
else {
|
||||
currentRow = -1;
|
||||
}
|
||||
} else{
|
||||
}
|
||||
else {
|
||||
//TODO:error handle
|
||||
}
|
||||
|
||||
|
||||
285
src/device/networkmanager.cpp
Normal file
285
src/device/networkmanager.cpp
Normal file
@@ -0,0 +1,285 @@
|
||||
#include "networkmanager.h"
|
||||
#include "json/jsonobject.h"
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
|
||||
//NetworkManager* NetworkManager::instance = nullptr;
|
||||
|
||||
//NetworkManager::NetworkManager(QObject* parent) : QObject(parent)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
//NetworkManager* NetworkManager::Instance()
|
||||
//{
|
||||
// if (nullptr == instance)
|
||||
// {
|
||||
// instance = new NetworkManager();
|
||||
// }
|
||||
// return instance;
|
||||
//}
|
||||
|
||||
|
||||
//void NetworkManager::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);
|
||||
//}
|
||||
|
||||
|
||||
QString NetworkManager::interfaceName()
|
||||
{
|
||||
return JsonObject::Instance()->interfaceName();
|
||||
}
|
||||
bool NetworkManager::isDHCP()
|
||||
{
|
||||
return JsonObject::Instance()->isDHCP();
|
||||
}
|
||||
IpAddr NetworkManager::getDefaultIpAddr()
|
||||
{
|
||||
return JsonObject::Instance()->getDefaultIpAddr();
|
||||
}
|
||||
QList<QStringList> NetworkManager::getIpAddrList()
|
||||
{
|
||||
return JsonObject::Instance()->getIpAddrList();
|
||||
}
|
||||
QString NetworkManager::getDefaultGateway()
|
||||
{
|
||||
return JsonObject::Instance()->getDefaultGateway();
|
||||
}
|
||||
QList<QStringList> NetworkManager::getIpRouteList()
|
||||
{
|
||||
return JsonObject::Instance()->getIpRouteList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool NetworkManager::restart(QString& err_info)
|
||||
{
|
||||
|
||||
QProcess* myProcess = new QProcess;
|
||||
QString inface = JsonObject::Instance()->interfaceName();
|
||||
QString pwd = JsonObject::Instance()->passWord();
|
||||
QString cmd = QString("echo %1 | sudo -S rcnetwork restart %2").arg(pwd).arg(inface);
|
||||
QStringList args;
|
||||
args << "-c" << cmd;
|
||||
connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
|
||||
myProcess->start("/bin/sh", args);
|
||||
|
||||
if (!myProcess->waitForFinished()) {
|
||||
err_info.append("failed...\n");
|
||||
return false;
|
||||
}
|
||||
if (myProcess->exitCode() == 0) {
|
||||
err_info.append("suceess...\n");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkManager::setJsonDHCP(bool enable)
|
||||
{
|
||||
JsonObject::Instance()->autoDHCP(enable);
|
||||
return true;
|
||||
}
|
||||
bool NetworkManager::setDefaultIpAddr(const IpAddr& addr, QString& err_info)
|
||||
{
|
||||
|
||||
QString ipaddr = NewExp(addr.ip, addr.mask);
|
||||
QProcess* myProcess = new QProcess;
|
||||
QString inface = JsonObject::Instance()->interfaceName();
|
||||
QString pwd = JsonObject::Instance()->passWord();
|
||||
QString cmd = QString("echo %1 | sudo -S ip addr add %2 dev %3").arg(pwd).arg(ipaddr).arg(inface);
|
||||
QStringList args;
|
||||
args << "-c" << cmd;
|
||||
connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
|
||||
myProcess->start("/bin/sh", args);
|
||||
|
||||
if (!myProcess->waitForFinished()) {
|
||||
err_info.append("failed...\n");
|
||||
return false;
|
||||
}
|
||||
if (myProcess->exitCode() == 0) {
|
||||
JsonObject::Instance()->setDefaultIpAddr(addr);
|
||||
err_info.append("success...\n");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString NetworkManager::NewExp(QString ip, QString mask)
|
||||
{
|
||||
QStringList list = mask.split(".");
|
||||
int count = 0;
|
||||
for (QString str : list)
|
||||
{
|
||||
if (str == "255")
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
QString temp = "";
|
||||
temp.append(ip).append("/").append(QString::number(count * 8));
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool NetworkManager::setIpAddrList(const QList<QStringList>& list, QString& err_info)
|
||||
{
|
||||
|
||||
QProcess* myProcess = new QProcess;
|
||||
QString inface = JsonObject::Instance()->interfaceName();
|
||||
QString pwd = JsonObject::Instance()->passWord();
|
||||
QString cmd = QString("echo %1 | ").arg(pwd);
|
||||
for (QStringList addr : list)
|
||||
{
|
||||
QString ipaddr = NewExp(addr[0], addr[1]);
|
||||
cmd.append(QString("sudo -S ip addr add %1 dev %2;").arg(ipaddr).arg(inface));
|
||||
}
|
||||
QStringList args;
|
||||
args << "-c" << cmd;
|
||||
connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
|
||||
myProcess->start("/bin/sh", args);
|
||||
|
||||
if (!myProcess->waitForFinished()) {
|
||||
err_info.append("failed...\n");
|
||||
return false;
|
||||
}
|
||||
if (myProcess->exitCode() == 0) {
|
||||
JsonObject::Instance()->setIpAddrList(list);
|
||||
err_info.append("success...\n");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool NetworkManager::setDefaultGateway(const QString& gw, QString& err_info)
|
||||
{
|
||||
|
||||
QProcess* myProcess = new QProcess;
|
||||
QString pwd = JsonObject::Instance()->passWord();
|
||||
QString cmd = QString("echo %1 | sudo -S ip route replace default via %2").arg(pwd).arg(gw);
|
||||
QStringList args;
|
||||
args << "-c" << cmd;
|
||||
connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
|
||||
//qDebug()<<args;
|
||||
myProcess->start("/bin/sh", args);
|
||||
if (!myProcess->waitForFinished()) {
|
||||
err_info.append("failed...\n");
|
||||
return false;
|
||||
}
|
||||
if (myProcess->exitCode() == 0) {
|
||||
JsonObject::Instance()->setDefaultGateway(gw);
|
||||
err_info.append("success...\n");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool NetworkManager::setIpRouteList(const QList<QStringList>& list, QString& err_info)
|
||||
{
|
||||
QProcess* myProcess = new QProcess;
|
||||
QString inface = JsonObject::Instance()->interfaceName();
|
||||
QString pwd = JsonObject::Instance()->passWord();
|
||||
QString cmd = QString("echo %1 | ").arg(pwd);
|
||||
for (QStringList route : list)
|
||||
{
|
||||
QString ipaddr = NewExp(route[0], route[1]);
|
||||
cmd.append(QString("sudo -S ip route replace %1 via %2 dev %3;").arg(ipaddr).arg(route[2]).arg(inface));
|
||||
}
|
||||
QStringList args;
|
||||
args << "-c" << cmd;
|
||||
connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
|
||||
myProcess->start("/bin/sh", args);
|
||||
if (!myProcess->waitForFinished()) {
|
||||
err_info.append("failed...\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myProcess->exitCode() == 0) {
|
||||
JsonObject::Instance()->setIpRouteList(list);
|
||||
err_info.append("success...\n");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(cmd);
|
||||
err_info.append("\n");
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool NetworkManager::testSetMode(QString& err_info)
|
||||
{
|
||||
// autoDHCP(true);
|
||||
QString err1, err2, err3, err4;
|
||||
|
||||
qDebug() << "DefaultIpAddr";
|
||||
const IpAddr& t1 = getDefaultIpAddr();
|
||||
|
||||
bool ret1 = setDefaultIpAddr(t1, err1);
|
||||
err_info.append(err1);
|
||||
|
||||
qDebug() << "DefaultGateway";
|
||||
|
||||
const QString& t2 = getDefaultGateway();
|
||||
bool ret2 = setDefaultGateway(t2, err2);
|
||||
err_info.append(err2);
|
||||
|
||||
qDebug() << "IpAddrList";
|
||||
const QList<QStringList>& t3 = getIpAddrList();
|
||||
bool ret3 = setIpAddrList(t3, err3);
|
||||
err_info.append(err3);
|
||||
|
||||
qDebug() << "IpRouteList";
|
||||
const QList<QStringList>& t4 = getIpRouteList();
|
||||
bool ret4 = setIpRouteList(t4, err4);
|
||||
err_info.append(err4);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NetworkManager::testGetMode()
|
||||
{
|
||||
qDebug() << "interfaceName()" << " : " << interfaceName();
|
||||
qDebug() << "isDHCP()" << " : " << isDHCP();
|
||||
|
||||
IpAddr t1 = getDefaultIpAddr();
|
||||
qDebug() << "getDefaultIpAddr()" << " : " << t1.ip << " " << t1.mask;
|
||||
|
||||
qDebug() << "getDefaultGateway()" << " : " << getDefaultGateway();
|
||||
|
||||
qDebug() << "ggetIpAddrList()" << " : ";
|
||||
const QList<QStringList>& t2 = getIpAddrList();
|
||||
for (QStringList var : t2)
|
||||
{
|
||||
qDebug() << var[0] << " " << var[1];
|
||||
}
|
||||
qDebug() << "getDefaultIpAddr()" << " : " << t1.ip << " " << t1.mask;
|
||||
|
||||
qDebug() << "getIpRouteList()" << " : ";
|
||||
const QList<QStringList>& t3 = getIpRouteList();
|
||||
for (QStringList var : t3)
|
||||
{
|
||||
qDebug() << var[0] << " " << var[1] << " " << var[2];
|
||||
}
|
||||
|
||||
}
|
||||
52
src/device/networkmanager.h
Normal file
52
src/device/networkmanager.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef NETWORKMANAGER_H
|
||||
#define NETWORKMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "json/jsonobject.h"
|
||||
|
||||
class NetworkManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//static NetworkManager* Instance();
|
||||
//static void qIfConfig(const localhost& lhost);
|
||||
static QString interfaceName();
|
||||
static bool isDHCP();
|
||||
static IpAddr getDefaultIpAddr();
|
||||
static QList<QStringList> getIpAddrList();
|
||||
static QString getDefaultGateway();
|
||||
static QList<QStringList> getIpRouteList();
|
||||
|
||||
//static void setInterfaceName(const QString& name);
|
||||
static bool restart(QString& err_info);
|
||||
static bool setJsonDHCP(bool enable);
|
||||
|
||||
static bool setDefaultIpAddr(const IpAddr& addr, QString& err_info);
|
||||
static bool setIpAddrList(const QList<QStringList>& list, QString& err_info);
|
||||
static bool setDefaultGateway(const QString& gw, QString& err_info);
|
||||
static bool setIpRouteList(const QList<QStringList>& list, QString& err_info);
|
||||
static QString NewExp(QString ip, QString mask);
|
||||
|
||||
|
||||
static bool testSetMode(QString& err_info);
|
||||
static void testGetMode();
|
||||
//private:
|
||||
//explicit NetworkManager(QObject* parent = nullptr);
|
||||
//static NetworkManager* instance;
|
||||
|
||||
|
||||
//QString InterfaceName;
|
||||
//bool isDHCP;
|
||||
//IpAddress default_IpAddr;
|
||||
//QList<IpAddress> addresses;
|
||||
|
||||
//IpRoute default_IpRoute;
|
||||
//QList<IpRoute> routes;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // NETWORKMANAGER_H
|
||||
@@ -236,7 +236,11 @@ cJSON* cJSON_Parse(const char* value)
|
||||
ep = 0;
|
||||
if (!c) return 0; /* memory fail */
|
||||
|
||||
if (!parse_value(c, skip(value))) { cJSON_Delete(c); return 0; }
|
||||
if (!parse_value(c, skip(value)))
|
||||
{
|
||||
cJSON_Delete(c);
|
||||
return 0;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -481,12 +485,6 @@ void cJSON_ReplaceItemInArray(cJSON* array, int which, cJSON* newitem) {
|
||||
if (c == array->child) array->child = newitem; else newitem->prev->next = newitem; c->next = c->prev = 0; cJSON_Delete(c);
|
||||
}
|
||||
|
||||
cJSON* cJSON_FindItemInArray(cJSON* array, int which)
|
||||
{
|
||||
cJSON* c = array->child;
|
||||
while (c && which > 0) c = c->next, which--;
|
||||
return c;
|
||||
}
|
||||
|
||||
void cJSON_ReplaceItemInObject(cJSON* object, const char* string, cJSON* newitem)
|
||||
{
|
||||
@@ -500,14 +498,6 @@ void cJSON_ReplaceItemInObject(cJSON* object, const char* string, cJSON* newit
|
||||
}
|
||||
}
|
||||
|
||||
cJSON* cJSON_FindItemInObject(cJSON* object, const char* string)
|
||||
{
|
||||
int i = 0;
|
||||
cJSON* c = object->child;
|
||||
while (c && cJSON_strcasecmp(c->string, string))i++, c = c->next;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Create basic types: */
|
||||
cJSON* cJSON_CreateNull() { cJSON* item = cJSON_New_Item(); if (item)item->type = cJSON_NULL; return item; }
|
||||
cJSON* cJSON_CreateTrue() { cJSON* item = cJSON_New_Item(); if (item)item->type = cJSON_True; return item; }
|
||||
|
||||
@@ -114,10 +114,6 @@ extern void cJSON_Delete(cJSON *c);
|
||||
extern void cJSON_ReplaceItemInArray(cJSON* array, int which, cJSON* newitem);
|
||||
extern void cJSON_ReplaceItemInObject(cJSON* object, const char* string, cJSON* newitem);
|
||||
|
||||
/*created by huxy*/
|
||||
extern cJSON* cJSON_FindItemInObject(cJSON* object, const char* string);
|
||||
extern cJSON* cJSON_FindItemInArray(cJSON* array, int which);
|
||||
|
||||
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
|
||||
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
|
||||
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
|
||||
|
||||
@@ -13,18 +13,20 @@ const char* strProductFileName = "./cfgs/usct-product.json";
|
||||
JsonObject::JsonObject()
|
||||
{
|
||||
loadcfg();
|
||||
|
||||
}
|
||||
JsonObject::~JsonObject()
|
||||
{
|
||||
savecfg();
|
||||
|
||||
|
||||
}
|
||||
void JsonObject::setJsonString(const char* catergory, const char* stringName, const char* stringValue, bool save)
|
||||
{
|
||||
if (!loadcfg())
|
||||
return;
|
||||
|
||||
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, catergory);
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, catergory);
|
||||
if (!first) return;
|
||||
|
||||
cJSON* Item = cJSON_CreateString(stringValue);
|
||||
@@ -40,14 +42,60 @@ char* JsonObject::getJsonString(const char* catergory, const char* stringName)
|
||||
if (!loadcfg())
|
||||
return "";
|
||||
|
||||
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, catergory);
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, catergory);
|
||||
if (!first) return "";
|
||||
|
||||
cJSON* second = cJSON_FindItemInObject(first, stringName);
|
||||
cJSON* second = cJSON_GetObjectItem(first, stringName);
|
||||
return second->valuestring;
|
||||
|
||||
}
|
||||
char* JsonObject::getArrayNode(const char* catergory, const char* stringName, int index, const char* id)
|
||||
{
|
||||
if (!loadcfg())
|
||||
return "";
|
||||
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, catergory);
|
||||
if (!first) return "";
|
||||
|
||||
cJSON* second = cJSON_GetObjectItem(first, stringName);
|
||||
if (!second) return "";
|
||||
|
||||
cJSON* third = cJSON_GetArrayItem(second, index);
|
||||
|
||||
cJSON* fourth = cJSON_GetObjectItem(third, id);
|
||||
return fourth->valuestring;
|
||||
}
|
||||
|
||||
void JsonObject::setArrayNode(const char* catergory, const char* stringName, int index, const char* id, const char* stringValue)
|
||||
{
|
||||
if (!loadcfg())
|
||||
return;
|
||||
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, catergory);
|
||||
if (!first) return;
|
||||
|
||||
cJSON* second = cJSON_GetObjectItem(first, stringName);
|
||||
if (!second) return;
|
||||
|
||||
cJSON* third = cJSON_GetArrayItem(second, index);
|
||||
|
||||
cJSON* Item = cJSON_CreateString(stringValue);
|
||||
cJSON_ReplaceItemInObject(third, id, Item);
|
||||
}
|
||||
|
||||
|
||||
int JsonObject::getArraySize(const char* catergory, const char* stringName)
|
||||
{
|
||||
if (!loadcfg())
|
||||
return 0;
|
||||
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, catergory);
|
||||
if (!first) return 0;
|
||||
|
||||
cJSON* second = cJSON_GetObjectItem(first, stringName);
|
||||
|
||||
return cJSON_GetArraySize(second);
|
||||
}
|
||||
|
||||
|
||||
QStringList JsonObject::protocals()
|
||||
@@ -55,11 +103,13 @@ QStringList JsonObject::protocals()
|
||||
if (!loadcfg())
|
||||
return QStringList();
|
||||
|
||||
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, "protocol");
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, "protocol");
|
||||
if (!first) return QStringList();
|
||||
|
||||
cJSON* second = cJSON_FindItemInObject(first, "lists");
|
||||
cJSON* second = cJSON_GetObjectItem(first, "lists");
|
||||
std::string lans = second->valuestring;
|
||||
|
||||
|
||||
QString str = QString::fromLocal8Bit(QByteArray::fromRawData(lans.c_str(), lans.size()));
|
||||
return str.split(";");
|
||||
|
||||
@@ -90,10 +140,10 @@ QStringList JsonObject::worklistFilters()
|
||||
if (!loadcfg())
|
||||
return QStringList();
|
||||
|
||||
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, "worklistfilter");
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, "worklistfilter");
|
||||
if (!first) return QStringList();
|
||||
|
||||
cJSON* second = cJSON_FindItemInObject(first, "lists");
|
||||
cJSON* second = cJSON_GetObjectItem(first, "lists");
|
||||
std::string lans = second->valuestring;
|
||||
QString str = QString::fromLocal8Bit(QByteArray::fromRawData(lans.c_str(), lans.size()));
|
||||
return str.split(";");
|
||||
@@ -107,10 +157,10 @@ QStringList JsonObject::language()
|
||||
if (!loadcfg())
|
||||
return QStringList();
|
||||
|
||||
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, "general");
|
||||
cJSON* first = cJSON_GetObjectItem((cJSON*)json_root, "general");
|
||||
if (!first) return QStringList();
|
||||
|
||||
cJSON* second = cJSON_FindItemInObject(first, "language");
|
||||
cJSON* second = cJSON_GetObjectItem(first, "language");
|
||||
std::string lans = second->valuestring;
|
||||
QString str = QString::fromLocal8Bit(QByteArray::fromRawData(lans.c_str(), lans.size()));
|
||||
return str.split(";");
|
||||
@@ -181,29 +231,10 @@ bool JsonObject::loadcfg()
|
||||
std::string strJsonData = ss.str();
|
||||
json_root = cJSON_Parse(strJsonData.c_str());
|
||||
|
||||
//modify somthing
|
||||
//QJsonValueRef ref = m_JsonRootObject.find("general").value();
|
||||
//QJsonObject obj = ref.toObject();
|
||||
//obj["language"] = language;
|
||||
|
||||
//cJSON* parent = cJSON_FindItemInObject(json_root, "waitinglist");
|
||||
//if (parent)
|
||||
//{
|
||||
// //const char* newtime = QDateTime::currentDateTime().toString("yyyyMMdd").toStdString().c_str();
|
||||
// cJSON* Item = cJSON_CreateString(QDateTime::currentDateTime().toString("yyyy-MM-dd").toStdString().c_str());
|
||||
// cJSON_ReplaceItemInObject(parent, "waitinglistDefaultDate", Item);
|
||||
//}
|
||||
|
||||
//cJSON* parent = cJSON_FindItemInObject(json_root, "pacsservers");
|
||||
//if (parent)
|
||||
//{
|
||||
// cJSON* p2 = cJSON_FindItemInArray(parent, 1);
|
||||
// cJSON* Item = cJSON_CreateString("KISS");
|
||||
// //const char* newtime = QDateTime::currentDateTime().toString("yyyyMMdd").toStdString().c_str();
|
||||
// cJSON_ReplaceItemInObject(p2, "ae", Item);
|
||||
//}
|
||||
|
||||
inFile.close();
|
||||
if (!json_root)
|
||||
return false;
|
||||
|
||||
m_bLoaded = true;
|
||||
return true;
|
||||
}
|
||||
@@ -288,31 +319,107 @@ void JsonObject::setServer(ServerType type, const host& list)
|
||||
}
|
||||
|
||||
|
||||
localhost JsonObject::getLocalHost()
|
||||
QString JsonObject::interfaceName()
|
||||
{
|
||||
return QString(getJsonString("address", "device"));
|
||||
}
|
||||
|
||||
QString JsonObject::passWord()
|
||||
{
|
||||
return QString("klxts4047");
|
||||
}
|
||||
void JsonObject::setInterfaceName(const QString& name)
|
||||
{
|
||||
setJsonString("address", "device", name.toStdString().c_str());
|
||||
}
|
||||
|
||||
localhost lhost;
|
||||
//lhost.ip = IPConfig::getDeviceIP();
|
||||
lhost.ip = QString(getJsonString("localhost", "ip"));
|
||||
lhost.mask = QString(getJsonString("localhost", "mask"));
|
||||
lhost.gateway = QString(getJsonString("localhost", "gateway"));
|
||||
return lhost;
|
||||
bool JsonObject::isDHCP()
|
||||
{
|
||||
QVariant tempValue = QString(getJsonString("address", "dhcp"));
|
||||
return tempValue.toBool();
|
||||
}
|
||||
|
||||
|
||||
// localhost lhost;
|
||||
// lhost.ip = QString(getJsonString("localhost", "ip"));
|
||||
// lhost.mask = QString(getJsonString("localhost", "mask"));
|
||||
// lhost.gateway = QString(getJsonString("localhost", "gateway"));
|
||||
// return lhost;
|
||||
void JsonObject::autoDHCP(bool ena)
|
||||
{
|
||||
QString str = QVariant(ena).toString();
|
||||
setJsonString("address", "dhcp", str.toStdString().c_str());
|
||||
}
|
||||
|
||||
|
||||
void JsonObject::setLocalHost(const localhost& lh)
|
||||
IpAddr JsonObject::getDefaultIpAddr()
|
||||
{
|
||||
setJsonString("localhost", "ip", lh.ip.toStdString().c_str(), false);
|
||||
setJsonString("localhost", "mask", lh.mask.toStdString().c_str(), false);
|
||||
setJsonString("localhost", "gateway", lh.gateway.toStdString().c_str(), false);
|
||||
IpAddr obj;
|
||||
//lhost.ip = IPConfig::getDeviceIP();
|
||||
obj.ip = QString(getJsonString("address", "ip"));
|
||||
obj.mask = QString(getJsonString("address", "mask"));
|
||||
return obj;
|
||||
}
|
||||
|
||||
void JsonObject::setDefaultIpAddr(const IpAddr& addr)
|
||||
{
|
||||
setJsonString("address", "ip", addr.ip.toStdString().c_str());
|
||||
setJsonString("address", "mask", addr.mask.toStdString().c_str());
|
||||
}
|
||||
|
||||
QList<QStringList> JsonObject::getIpAddrList()
|
||||
{
|
||||
|
||||
QList<QStringList> obj;
|
||||
int size = getArraySize("address", "additional");
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
QStringList temp;
|
||||
char* ip_str = getArrayNode("address", "additional", i, "ip");
|
||||
char* mask_str = getArrayNode("address", "additional", i, "netmask");
|
||||
|
||||
temp << ip_str << mask_str;
|
||||
obj.push_back(temp);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
void JsonObject::setIpAddrList(const QList<QStringList>& list)
|
||||
{
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
setArrayNode("address", "additional", i, "ip", list.at(i)[0].toStdString().c_str());
|
||||
setArrayNode("address", "additional", i, "netmask", list.at(i)[1].toStdString().c_str());
|
||||
}
|
||||
savecfg();
|
||||
}
|
||||
|
||||
QString JsonObject::getDefaultGateway()
|
||||
{
|
||||
return QString(getJsonString("routing", "defaultgateway"));
|
||||
}
|
||||
|
||||
void JsonObject::setDefaultGateway(const QString& gw)
|
||||
{
|
||||
setJsonString("routing", "defaultgateway", gw.toStdString().c_str());
|
||||
}
|
||||
|
||||
QList<QStringList> JsonObject::getIpRouteList()
|
||||
{
|
||||
QList<QStringList> obj;
|
||||
int size = getArraySize("routing", "routingtable");
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
QStringList temp;
|
||||
char* des_str = getArrayNode("routing", "routingtable", i, "destination");
|
||||
char* gw_str = getArrayNode("routing", "routingtable", i, "gateway");
|
||||
char* nm_str = getArrayNode("routing", "routingtable", i, "netmask");
|
||||
|
||||
temp << des_str << nm_str << gw_str;
|
||||
obj.push_back(temp);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
void JsonObject::setIpRouteList(const QList<QStringList>& list)
|
||||
{
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
setArrayNode("routing", "routingtable", i, "destination", list.at(i)[0].toStdString().c_str());
|
||||
setArrayNode("routing", "routingtable", i, "netmask", list.at(i)[1].toStdString().c_str());
|
||||
setArrayNode("routing", "routingtable", i, "gateway", list.at(i)[2].toStdString().c_str());
|
||||
}
|
||||
savecfg();
|
||||
}
|
||||
|
||||
@@ -14,11 +14,18 @@ struct host {
|
||||
QString port;
|
||||
//QString isDefault;
|
||||
};
|
||||
struct localhost {
|
||||
|
||||
struct IpAddr {
|
||||
QString ip;
|
||||
QString mask;
|
||||
QString gateway;
|
||||
};
|
||||
struct IpRoute
|
||||
{
|
||||
QString des;
|
||||
QString gw;
|
||||
QString mask;
|
||||
};
|
||||
|
||||
|
||||
class JsonObject
|
||||
{
|
||||
@@ -61,13 +68,36 @@ public:
|
||||
host getServer(ServerType type);
|
||||
void setServer(ServerType type, const host& list);
|
||||
|
||||
localhost getLocalHost();
|
||||
void setLocalHost(const localhost& lh);
|
||||
//for network manager
|
||||
QString passWord();
|
||||
|
||||
QString interfaceName();
|
||||
void setInterfaceName(const QString& name);
|
||||
|
||||
bool isDHCP();
|
||||
void autoDHCP(bool);
|
||||
|
||||
IpAddr getDefaultIpAddr();
|
||||
void setDefaultIpAddr(const IpAddr& addr);
|
||||
|
||||
QList<QStringList> getIpAddrList();
|
||||
void setIpAddrList(const QList<QStringList>& list);
|
||||
|
||||
QString getDefaultGateway();
|
||||
void setDefaultGateway(const QString& gw);
|
||||
|
||||
QList<QStringList> getIpRouteList();
|
||||
void setIpRouteList(const QList<QStringList>& list);
|
||||
|
||||
private:
|
||||
void setJsonString(const char* catergory, const char* stringName, const char* stringValue, bool save = true);
|
||||
char* getJsonString(const char* catergory, const char* stringName);
|
||||
|
||||
char* getArrayNode(const char* catergory, const char* stringName, int index, const char* id);
|
||||
void setArrayNode(const char* catergory, const char* stringName, int index, const char* id, const char* stringValue);
|
||||
int getArraySize(const char* catergory, const char* stringName);
|
||||
|
||||
|
||||
bool loadcfg();
|
||||
bool savecfg();
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ int main(int argc, char* argv[])
|
||||
QFont font(fontName);
|
||||
QApplication::setFont(font);
|
||||
|
||||
//a.installEventFilter(obj);
|
||||
InputObject* obj = new InputObject();
|
||||
a.installEventFilter(obj);
|
||||
SQLHelper::Open();
|
||||
|
||||
43
src/network/getipdialog.cpp
Normal file
43
src/network/getipdialog.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/11.
|
||||
//
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include "getipdialog.h"
|
||||
GetIPDialog::GetIPDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
|
||||
setWindowModality(Qt::WindowModal);
|
||||
QFormLayout* form = new QFormLayout(formWidget);
|
||||
QString value1 = QString("IP Address");
|
||||
_ip = new QLineEdit(this);
|
||||
form->addRow(value1, _ip);
|
||||
QString value2 = QString("Netmask");
|
||||
_mask = new QLineEdit(this);
|
||||
form->addRow(value2, _mask);
|
||||
|
||||
|
||||
}
|
||||
|
||||
GetIPDialog::~GetIPDialog() {
|
||||
|
||||
}
|
||||
|
||||
QStringList GetIPDialog::getList()const
|
||||
{
|
||||
QStringList tmp;
|
||||
tmp << _ip->text() << _mask->text();
|
||||
return tmp;
|
||||
}
|
||||
void GetIPDialog::setList(const QStringList& list)
|
||||
{
|
||||
if (!list.empty()) {
|
||||
_ip->setText(list[0]);
|
||||
_mask->setText(list[1]);
|
||||
}
|
||||
}
|
||||
|
||||
bool GetIPDialog::updateReferenceData() {
|
||||
return true;
|
||||
}
|
||||
26
src/network/getipdialog.h
Normal file
26
src/network/getipdialog.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/11.
|
||||
//
|
||||
|
||||
#ifndef GUI_GETIPDIALOG_H
|
||||
#define GUI_GETIPDIALOG_H
|
||||
|
||||
#include "GUIFormBaseDialog.h"
|
||||
class QLineEdit;
|
||||
class QLabel;
|
||||
class GetIPDialog :public GUIFormBaseDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GetIPDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~GetIPDialog();
|
||||
QStringList getList()const;
|
||||
void setList(const QStringList& list);
|
||||
protected:
|
||||
bool updateReferenceData();
|
||||
private:
|
||||
QLineEdit* _ip = nullptr;
|
||||
QLineEdit* _mask = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //GUI_GetIPDialog_H
|
||||
46
src/network/getroutedialog.cpp
Normal file
46
src/network/getroutedialog.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/11.
|
||||
//
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include "getroutedialog.h"
|
||||
GetRouteDialog::GetRouteDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
|
||||
setWindowModality(Qt::WindowModal);
|
||||
QFormLayout* form = new QFormLayout(formWidget);
|
||||
QString value1 = QString("Destination");
|
||||
_des = new QLineEdit(this);
|
||||
form->addRow(value1, _des);
|
||||
QString value2 = QString("Netmask");
|
||||
_mask = new QLineEdit(this);
|
||||
form->addRow(value2, _mask);
|
||||
QString value3 = QString("Destination");
|
||||
_gw = new QLineEdit(this);
|
||||
form->addRow(value3, _gw);
|
||||
|
||||
}
|
||||
|
||||
GetRouteDialog::~GetRouteDialog() {
|
||||
|
||||
}
|
||||
|
||||
QStringList GetRouteDialog::getList()const
|
||||
{
|
||||
QStringList tmp;
|
||||
tmp << _des->text() << _mask->text() << _gw->text();
|
||||
return tmp;
|
||||
}
|
||||
void GetRouteDialog::setList(const QStringList& list)
|
||||
{
|
||||
if (!list.empty()) {
|
||||
_des->setText(list[0]);
|
||||
_mask->setText(list[1]);
|
||||
_gw->setText(list[2]);
|
||||
}
|
||||
}
|
||||
|
||||
bool GetRouteDialog::updateReferenceData() {
|
||||
return true;
|
||||
}
|
||||
27
src/network/getroutedialog.h
Normal file
27
src/network/getroutedialog.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/11.
|
||||
//
|
||||
|
||||
#ifndef GUI_GetRouteDialog_H
|
||||
#define GUI_GETROUTEDIALOG_H
|
||||
|
||||
#include "GUIFormBaseDialog.h"
|
||||
class QLineEdit;
|
||||
class QLabel;
|
||||
class GetRouteDialog :public GUIFormBaseDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GetRouteDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~GetRouteDialog();
|
||||
QStringList getList()const;
|
||||
void setList(const QStringList& list);
|
||||
protected:
|
||||
bool updateReferenceData();
|
||||
private:
|
||||
QLineEdit* _des = nullptr;
|
||||
QLineEdit* _mask = nullptr;
|
||||
QLineEdit* _gw = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //GUI_GetRouteDialog_H
|
||||
101
src/network/netcfgtablemodel.cpp
Normal file
101
src/network/netcfgtablemodel.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/23.
|
||||
//
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QTextStream>
|
||||
#include "network/netcfgtablemodel.h"
|
||||
#include <QDebug>
|
||||
|
||||
NetCfgTableModel::NetCfgTableModel(QObject* parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
/*!
|
||||
Sets the \a role data for the item at \a index to \a value.
|
||||
Returns \c{true} if successful; otherwise returns \c{false}.
|
||||
The dataChanged() signal should be emitted if the data was successfully
|
||||
set.
|
||||
The base class implementation returns \c{false}. This function and data() must
|
||||
be reimplemented for editable models.
|
||||
\sa Qt::ItemDataRole, data(), itemData()
|
||||
*/
|
||||
|
||||
//bool NetCfgTableModel::setData(const QModelIndex& index, const QVariant& value, int role){}
|
||||
|
||||
QList<QStringList> NetCfgTableModel::getData()
|
||||
{
|
||||
return mydata;
|
||||
}
|
||||
bool NetCfgTableModel::loadData(const QList<QStringList>& list)
|
||||
{
|
||||
this->mydata = list;
|
||||
|
||||
QModelIndex tl = this->index(0, 0);
|
||||
QModelIndex br = this->index(list.size() - 1, list.begin()->size() - 1);
|
||||
emit dataChanged(tl, br);
|
||||
return true;
|
||||
}
|
||||
bool NetCfgTableModel::addRow(const QStringList& value)
|
||||
{
|
||||
int index = rowCount(QModelIndex());
|
||||
QAbstractTableModel::beginInsertRows(QModelIndex(), index, index);
|
||||
mydata.insert(index, value);
|
||||
QAbstractTableModel::endInsertRows();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool NetCfgTableModel::insertRow(int index, const QStringList& value)
|
||||
{
|
||||
QAbstractTableModel::beginInsertRows(QModelIndex(), index, index);
|
||||
mydata.insert(index, value);
|
||||
QAbstractTableModel::endInsertRows();
|
||||
return true;
|
||||
}
|
||||
bool NetCfgTableModel::removeRow(int index)
|
||||
{
|
||||
QAbstractTableModel::beginRemoveRows(QModelIndex(), index, index);
|
||||
mydata.removeAt(index);
|
||||
QAbstractTableModel::endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList NetCfgTableModel::rowData(QModelIndex index)
|
||||
{
|
||||
if (!index.isValid()) return QStringList();
|
||||
if (index.row() < mydata.size())
|
||||
{
|
||||
return mydata[index.row()];
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QVariant NetCfgTableModel::data(const QModelIndex& index, int role) const {
|
||||
if (!index.isValid()) return QVariant();
|
||||
if (role == Qt::TextAlignmentRole) {
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||
{
|
||||
return mydata[index.row()][index.column()];
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int NetCfgTableModel::rowCount(const QModelIndex& parent) const {
|
||||
if (!mydata.isEmpty()) return mydata.count();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NetCfgTableModel::columnCount(const QModelIndex& parent) const {
|
||||
if (!mydata.isEmpty()) return mydata[0].count();
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant NetCfgTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
if (orientation == Qt::Horizontal)
|
||||
return headerStrings.at(section);
|
||||
return QVariant();
|
||||
}
|
||||
47
src/network/netcfgtablemodel.h
Normal file
47
src/network/netcfgtablemodel.h
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/23.
|
||||
//
|
||||
|
||||
#ifndef GUI_LOGFILETABLEMODEL_H
|
||||
#define GUI_LOGFILETABLEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
|
||||
class NetCfgTableModel : public QAbstractTableModel {
|
||||
public:
|
||||
NetCfgTableModel(QObject* parent = nullptr);
|
||||
~NetCfgTableModel() {}
|
||||
|
||||
//bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
|
||||
bool loadData(const QList<QStringList>& list);
|
||||
QList<QStringList> getData();
|
||||
|
||||
QStringList rowData(QModelIndex index);
|
||||
bool addRow(const QStringList& value);
|
||||
bool removeRow(int index);
|
||||
bool insertRow(int index, const QStringList& value);
|
||||
|
||||
|
||||
void setHeader(QStringList header) {
|
||||
headerStrings = header;
|
||||
}
|
||||
protected:
|
||||
|
||||
//数据展示用
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
//行数,重新实现
|
||||
int rowCount(const QModelIndex& parent) const;
|
||||
//列数,重新实现
|
||||
int columnCount(const QModelIndex& parent) const;
|
||||
//标头
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
private:
|
||||
QList<QStringList> mydata;
|
||||
QStringList headerStrings;
|
||||
};
|
||||
|
||||
|
||||
#endif //GUI_LOGFILETABLEMODEL_H
|
||||
239
src/network/networkcfgdialog.cpp
Normal file
239
src/network/networkcfgdialog.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
#include "networkcfgdialog.h"
|
||||
#include "ui_networkcfgdialog.h"
|
||||
#include "device/networkmanager.h"
|
||||
#include "network/netcfgtablemodel.h"
|
||||
#include "network/getipdialog.h"
|
||||
#include "network/getroutedialog.h"
|
||||
|
||||
#include <QItemSelectionModel>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
networkCfgDialog::networkCfgDialog(QWidget* parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::networkCfgDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setShadow(this);
|
||||
|
||||
ui->sw_dhcp->setChecked(true);
|
||||
ui->sw_dhcp->setButtonStyle(ImageSwitch::ButtonStyle_1);
|
||||
|
||||
|
||||
model_addr = new NetCfgTableModel(this);
|
||||
model_route = new NetCfgTableModel(this);
|
||||
|
||||
QStringList header_addr;
|
||||
header_addr << "IP Address" << "Netmask";
|
||||
model_addr->setHeader(header_addr);
|
||||
QStringList route_addr;
|
||||
route_addr << "Destination" << "Gateway" << "Netmask";
|
||||
model_route->setHeader(route_addr);
|
||||
|
||||
loadData();
|
||||
|
||||
ui->tbl_addr->setModel(model_addr);
|
||||
ui->tbl_route->setModel(model_route);
|
||||
|
||||
//ui->tbl_addr->setAlternatingRowColors(true);
|
||||
ui->tbl_addr->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->tbl_addr->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
ui->tbl_addr->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
//ui->tbl_addr->verticalHeader()->setDefaultSectionSize(38);
|
||||
ui->tbl_addr->horizontalHeader()->setStretchLastSection(true);
|
||||
ui->tbl_addr->setColumnWidth(0, 345);
|
||||
ui->tbl_addr->setColumnWidth(1, 345);
|
||||
ui->tbl_addr->horizontalHeader()->setFixedHeight(38);
|
||||
|
||||
//ui->tbl_route->setAlternatingRowColors(true);
|
||||
ui->tbl_route->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->tbl_route->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
ui->tbl_route->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->tbl_route->verticalHeader()->setDefaultSectionSize(38);
|
||||
ui->tbl_route->horizontalHeader()->setStretchLastSection(true);
|
||||
ui->tbl_route->setColumnWidth(0, 230);
|
||||
ui->tbl_route->setColumnWidth(1, 230);
|
||||
ui->tbl_route->setColumnWidth(2, 230);
|
||||
ui->tbl_route->horizontalHeader()->setFixedHeight(38);
|
||||
|
||||
connect(ui->btn_addr_add, &QPushButton::clicked, [=]()
|
||||
{
|
||||
GetIPDialog* dialog = new GetIPDialog(this);
|
||||
|
||||
if (dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
model_addr->addRow(dialog->getList());
|
||||
ui->tbl_addr->selectRow(0);
|
||||
}
|
||||
});
|
||||
connect(ui->btn_addr_edit, &QPushButton::clicked, [=]()
|
||||
{
|
||||
|
||||
QItemSelectionModel* select = ui->tbl_addr->selectionModel();
|
||||
if (select->hasSelection())
|
||||
{
|
||||
QModelIndexList index = select->selectedRows();
|
||||
if (!index.empty()) {
|
||||
const QStringList ipdata = model_addr->rowData(index.at(0));
|
||||
|
||||
GetIPDialog* dialog = new GetIPDialog(this);
|
||||
dialog->setList(ipdata);
|
||||
if (dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
model_addr->removeRow(index.at(0).row());
|
||||
model_addr->insertRow(index.at(0).row(), dialog->getList());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->btn_addr_del, &QPushButton::clicked, [=]()
|
||||
{
|
||||
QItemSelectionModel* select = ui->tbl_addr->selectionModel();
|
||||
if (select->hasSelection())
|
||||
{
|
||||
QModelIndexList index = select->selectedRows();
|
||||
if (!index.empty()) {
|
||||
model_addr->removeRow(index.at(0).row());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
connect(ui->btn_route_add, &QPushButton::clicked, [=]()
|
||||
{
|
||||
GetRouteDialog* dialog = new GetRouteDialog(this);
|
||||
|
||||
if (dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
model_route->addRow(dialog->getList());
|
||||
}
|
||||
});
|
||||
connect(ui->btn_route_edit, &QPushButton::clicked, [=]()
|
||||
{
|
||||
|
||||
QItemSelectionModel* select = ui->tbl_route->selectionModel();
|
||||
if (select->hasSelection())
|
||||
{
|
||||
QModelIndexList index = select->selectedRows();
|
||||
if (!index.empty()) {
|
||||
const QStringList ipdata = model_route->rowData(index.at(0));
|
||||
|
||||
GetRouteDialog* dialog = new GetRouteDialog(this);
|
||||
dialog->setList(ipdata);
|
||||
if (dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
model_route->removeRow(index.at(0).row());
|
||||
model_route->insertRow(index.at(0).row(), dialog->getList());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->btn_route_del, &QPushButton::clicked, [=]()
|
||||
{
|
||||
QItemSelectionModel* select = ui->tbl_route->selectionModel();
|
||||
if (select->hasSelection())
|
||||
{
|
||||
QModelIndexList index = select->selectedRows();
|
||||
if (!index.empty()) {
|
||||
model_route->removeRow(index.at(0).row());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(ui->btn_group->button(QDialogButtonBox::Apply), &QPushButton::clicked, [=]()
|
||||
{
|
||||
applyData();
|
||||
});
|
||||
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ
|
||||
void networkCfgDialog::setShadow(QDialog* dialog)
|
||||
{
|
||||
dialog->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
|
||||
dialog->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
//setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
|
||||
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(dialog);
|
||||
shadow->setOffset(0, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD>
|
||||
shadow->setColor(Qt::black); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>ɫ
|
||||
shadow->setBlurRadius(20); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӰԲ<D3B0><D4B2>
|
||||
dialog->setGraphicsEffect(shadow); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ
|
||||
//ui->frame->setObjectName("widgetShadow");
|
||||
//ui->frame->setStyleSheet("#widgetShadow{border-radius:5px;}");//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB8>
|
||||
}
|
||||
|
||||
networkCfgDialog::~networkCfgDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void networkCfgDialog::loadData()
|
||||
{
|
||||
|
||||
ui->led_inface->setText(NetworkManager::interfaceName());
|
||||
//ui->led_inface->setDisabled(true);
|
||||
ui->sw_dhcp->setChecked(NetworkManager::isDHCP());
|
||||
const IpAddr& default_addr = NetworkManager::getDefaultIpAddr();
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void networkCfgDialog::applyData()
|
||||
{
|
||||
|
||||
//compare with the old
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
34
src/network/networkcfgdialog.h
Normal file
34
src/network/networkcfgdialog.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef NETWORKCFGDIALOG_H
|
||||
#define NETWORKCFGDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class networkCfgDialog;
|
||||
}
|
||||
|
||||
class NetCfgTableModel;
|
||||
class networkCfgDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static void setShadow(QDialog* dialog);
|
||||
explicit networkCfgDialog(QWidget* parent = nullptr);
|
||||
~networkCfgDialog();
|
||||
|
||||
void loadData();
|
||||
void applyData();
|
||||
|
||||
|
||||
private:
|
||||
const char* boolToStr(bool b)
|
||||
{
|
||||
return b ? "sucess" : "failed";
|
||||
}
|
||||
NetCfgTableModel* model_addr = nullptr;
|
||||
NetCfgTableModel* model_route = nullptr;
|
||||
Ui::networkCfgDialog* ui;
|
||||
};
|
||||
|
||||
#endif // NetworkCfgDialog_H
|
||||
550
src/networkcfgdialog.ui
Normal file
550
src/networkcfgdialog.ui
Normal file
@@ -0,0 +1,550 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>networkCfgDialog</class>
|
||||
<widget class="QDialog" name="networkCfgDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>863</width>
|
||||
<height>678</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<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>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Address</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>IP Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLineEdit" name="addr_ip"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Dynamic Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Dev</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="ImageSwitch" name="sw_dhcp" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: #232629;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="led_inface">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>26</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>26</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Subnet Mask</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="addr_mask"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Additional Address</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="topMargin">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="SlideableTableView" name="tbl_addr"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_addr_add">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_addr_edit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_addr_del">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>321</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Routing</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_4" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="led_gw">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>190</width>
|
||||
<height>26</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>190</width>
|
||||
<height>26</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>373</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Default IPv4 Gateway</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Routing Table</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="SlideableTableView" name="tbl_route">
|
||||
<property name="gridStyle">
|
||||
<enum>Qt::DashLine</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_5" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_route_add">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_route_edit">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_route_del">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>321</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Result</string>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>20</y>
|
||||
<width>781</width>
|
||||
<height>541</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="output"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="btn_group">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ImageSwitch</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">components/imageswitch.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>SlideableTableView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header location="global">components/SlideableTableView.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>btn_group</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>networkCfgDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>btn_group</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>networkCfgDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -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
|
||||
@@ -403,7 +400,10 @@ systemSettingForm::systemSettingForm(QWidget* parent) : QWidget(parent)
|
||||
connect(swt_verify, &ImageSwitch::clicked, [=]() {
|
||||
if (swt_verify->getChecked())
|
||||
{
|
||||
autoDHCP();
|
||||
//autoDHCP();
|
||||
networkCfgDialog dia(this);
|
||||
dia.setWindowModality(Qt::WindowModal);
|
||||
dia.exec();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ private:
|
||||
|
||||
void loadServersInfo();
|
||||
void saveServersInfo();
|
||||
void qIfConfig(const localhost &lhost);
|
||||
void autoDHCP();
|
||||
|
||||
QLineEdit* pacs_Name;
|
||||
QLineEdit* recon_IP;
|
||||
QLineEdit* daq_AE;
|
||||
|
||||
Reference in New Issue
Block a user