From b6475e7ed460123f87425d59269f9d7e52cd70de Mon Sep 17 00:00:00 2001 From: xueyan hu <576627988@qq.com> Date: Fri, 17 Dec 2021 18:02:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E8=AE=BE=E7=BD=AE=E6=A8=A1=E5=9D=97=EF=BC=8C=E8=BF=98?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E4=BA=9B=E7=BB=86=E8=8A=82=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cfgs/usct-product.json | 18 +- src/ChangePasswordFormDialog.cpp | 140 ++++---- src/SelectFormWidget.cpp | 407 +++++++++++------------ src/device/networkmanager.cpp | 285 ++++++++++++++++ src/device/networkmanager.h | 52 +++ src/json/cJSON.c | 20 +- src/json/cJSON.h | 50 ++- src/json/jsonobject.cpp | 203 +++++++++--- src/json/jsonobject.h | 38 ++- src/main.cpp | 7 +- src/network/getipdialog.cpp | 43 +++ src/network/getipdialog.h | 26 ++ src/network/getroutedialog.cpp | 46 +++ src/network/getroutedialog.h | 27 ++ src/network/netcfgtablemodel.cpp | 101 ++++++ src/network/netcfgtablemodel.h | 47 +++ src/network/networkcfgdialog.cpp | 239 ++++++++++++++ src/network/networkcfgdialog.h | 34 ++ src/networkcfgdialog.ui | 550 +++++++++++++++++++++++++++++++ src/systemsettingform.cpp | 62 ++-- src/systemsettingform.h | 5 +- 21 files changed, 1979 insertions(+), 421 deletions(-) create mode 100644 src/device/networkmanager.cpp create mode 100644 src/device/networkmanager.h create mode 100644 src/network/getipdialog.cpp create mode 100644 src/network/getipdialog.h create mode 100644 src/network/getroutedialog.cpp create mode 100644 src/network/getroutedialog.h create mode 100644 src/network/netcfgtablemodel.cpp create mode 100644 src/network/netcfgtablemodel.h create mode 100644 src/network/networkcfgdialog.cpp create mode 100644 src/network/networkcfgdialog.h create mode 100644 src/networkcfgdialog.ui diff --git a/cfgs/usct-product.json b/cfgs/usct-product.json index d61d001..d049bac 100644 --- a/cfgs/usct-product.json +++ b/cfgs/usct-product.json @@ -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" diff --git a/src/ChangePasswordFormDialog.cpp b/src/ChangePasswordFormDialog.cpp index 0c53274..3c3d137 100644 --- a/src/ChangePasswordFormDialog.cpp +++ b/src/ChangePasswordFormDialog.cpp @@ -9,52 +9,52 @@ #include #include "ChangePasswordFormDialog.h" -ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { - QVBoxLayout* layout = new QVBoxLayout(formWidget); - layout->setSpacing(10); - // add title - QLabel* lbl_title = new QLabel(this); - lbl_title->setAlignment(Qt::AlignCenter); - lbl_title->setText(tr("Change Password")); - lbl_title->setObjectName("title"); - layout->addWidget(lbl_title); +ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { + QVBoxLayout* layout = new QVBoxLayout(formWidget); + layout->setSpacing(10); + // add title + QLabel* lbl_title = new QLabel(this); + lbl_title->setAlignment(Qt::AlignCenter); + lbl_title->setText(tr("Change Password")); + lbl_title->setObjectName("title"); + layout->addWidget(lbl_title); - //add old password - QLabel* lbl_Old = new QLabel(this); - lbl_Old->setText(tr("Current Password")); - pwd = new QLineEdit(this); - pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(lbl_Old); - layout->addWidget(pwd); - QLabel* lbl_endline1 = new QLabel(this); - lbl_endline1->setObjectName("endline"); - layout->addWidget(lbl_endline1); + //add old password + QLabel* lbl_Old = new QLabel(this); + lbl_Old->setText(tr("Current Password")); + pwd = new QLineEdit(this); + pwd->setEchoMode(QLineEdit::Password); + layout->addWidget(lbl_Old); + layout->addWidget(pwd); + QLabel* lbl_endline1 = new QLabel(this); + lbl_endline1->setObjectName("endline"); + layout->addWidget(lbl_endline1); - //add new password - QLabel* lbl_New = new QLabel(this); - lbl_New->setText(tr("New Password")); - new_pwd = new QLineEdit(this); - new_pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(lbl_New); - layout->addWidget(new_pwd); - QLabel* lbl_endline2 = new QLabel(this); - lbl_endline2->setObjectName("endline"); - layout->addWidget(lbl_endline2); + //add new password + QLabel* lbl_New = new QLabel(this); + lbl_New->setText(tr("New Password")); + new_pwd = new QLineEdit(this); + new_pwd->setEchoMode(QLineEdit::Password); + layout->addWidget(lbl_New); + layout->addWidget(new_pwd); + QLabel* lbl_endline2 = new QLabel(this); + lbl_endline2->setObjectName("endline"); + layout->addWidget(lbl_endline2); - //add confirm password - QLabel* lbl_Confirm = new QLabel(this); - lbl_Confirm->setText(tr("Confirm Password")); - confirm_pwd = new QLineEdit(this); - confirm_pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(lbl_Confirm); - layout->addWidget(confirm_pwd); - QLabel* lbl_endline3 = new QLabel(this); - lbl_endline3->setObjectName("endline"); - layout->addWidget(lbl_endline3); + //add confirm password + QLabel* lbl_Confirm = new QLabel(this); + lbl_Confirm->setText(tr("Confirm Password")); + confirm_pwd = new QLineEdit(this); + confirm_pwd->setEchoMode(QLineEdit::Password); + layout->addWidget(lbl_Confirm); + layout->addWidget(confirm_pwd); + QLabel* lbl_endline3 = new QLabel(this); + lbl_endline3->setObjectName("endline"); + layout->addWidget(lbl_endline3); - lbl_error = new QLabel(this); - lbl_error->setObjectName("warn"); - layout->addWidget(lbl_error); + lbl_error = new QLabel(this); + lbl_error->setObjectName("warn"); + layout->addWidget(lbl_error); } ChangePasswordFormDialog::~ChangePasswordFormDialog() { @@ -62,32 +62,32 @@ ChangePasswordFormDialog::~ChangePasswordFormDialog() { } bool ChangePasswordFormDialog::updateReferenceData() { - if (pwd->text().isEmpty()) - { - lbl_error->setText(tr("Please enter your old password!")); - return false; - } - if (new_pwd->text().length()<6) { - lbl_error->setText(tr("New password should at least 6 characters!")); - return false; - } - QString encryptPwd = User::getEncryptedPassword(pwd->text()); - if (encryptPwd!=User::Current()->getPassword()) - { - lbl_error->setText(tr("Wrong password!")); - return false; - } - if (new_pwd->text() != confirm_pwd->text()) - { - lbl_error->setText(tr("Your new password does not match!")); - return false; - } - User::Current()->setPassword(User::getEncryptedPassword(new_pwd->text())); - if (!User::Current()->submitChange()) { - lbl_error->setText(tr("Database update error!")); - User::Current()->restorePassword(encryptPwd); - return false; - } - LOG_USER_OPERATION(ChangePassword); - return true; + if (pwd->text().isEmpty()) + { + lbl_error->setText(tr("Please enter your old password!")); + return false; + } + if (new_pwd->text().length() < 6) { + lbl_error->setText(tr("New password should at least 6 characters!")); + return false; + } + QString encryptPwd = User::getEncryptedPassword(pwd->text()); + if (encryptPwd != User::Current()->getPassword()) + { + lbl_error->setText(tr("Wrong password!")); + return false; + } + if (new_pwd->text() != confirm_pwd->text()) + { + lbl_error->setText(tr("Your new password does not match!")); + return false; + } + User::Current()->setPassword(User::getEncryptedPassword(new_pwd->text())); + if (!User::Current()->submitChange()) { + lbl_error->setText(tr("Database update error!")); + User::Current()->restorePassword(encryptPwd); + return false; + } + LOG_USER_OPERATION(ChangePassword); + return true; } diff --git a/src/SelectFormWidget.cpp b/src/SelectFormWidget.cpp index b163804..c191c45 100644 --- a/src/SelectFormWidget.cpp +++ b/src/SelectFormWidget.cpp @@ -26,226 +26,227 @@ int queryValue(QSqlTableModel* model, int colID, QVariant var) { - for (int i = 0; i < model->rowCount(); ++i) { - if (model->data(model->index(i,colID))==var) return i; - } - return -1; + for (int i = 0; i < model->rowCount(); ++i) { + if (model->data(model->index(i, colID)) == var) return i; + } + return -1; } -SelectFormWidget::SelectFormWidget(QWidget *parent) : - TabFormWidget(parent) +SelectFormWidget::SelectFormWidget(QWidget* parent) : + TabFormWidget(parent) { -// const char* style="QHeaderView::section{background-color:#595959;" -// " min-height:50px;max-height:50px;" -// "font-weight:Bold; font-size:16px; border:1px solid #323232;}" -// "QHeaderView::section:horizontal{border-bottom: 1px solid rgb(0,170,255);}" -// "QHeaderView::section:vertical{min-height:36px;max-height:36px;}" -// "QWidget#edit_patient{min-width:300px;max-width:300px;}" -// "QTableView{border:none}" -// "QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}" -// "QToolButton#sexBtn{min-width:120px;max-width:120px;font-size:20px;padding:2px;}" -// "QToolButton#sexBtn:disabled{color:silver}" -// "QWidget#sexpanelwidget{border:1px solid silver;}" -// "QWidget#sexpanelwidget:enabled{background-color: #515151;}" -// "QToolButton#sexBtn:checked{border:2px solid darkorange;padding:0px;}" -// ; -// -// this->setStyleSheet(this->styleSheet().append(style)); - //init command bar - QHBoxLayout* layout =new QHBoxLayout(); - ui->commandWidget->setLayout(layout); - ADD_TOOL_BTN(Account,":/icons/account.png"); - ADD_TOOL_BTN(Worklist,":/icons/setting.png"); - layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding)); - QWidget* spacerLine= new QWidget(this); - spacerLine->setFixedWidth(2); - spacerLine->setObjectName("verSpaceLine"); - layout->addWidget(spacerLine); - ADD_TOOL_BTN(Add,":/icons/add.png"); - ADD_TOOL_BTN(Edit,":/icons/details.png"); - ADD_TOOL_BTN(Delete,":/icons/close_circle.png"); - ADD_TOOL_BTN(Select,":/icons/selected.png"); + // const char* style="QHeaderView::section{background-color:#595959;" + // " min-height:50px;max-height:50px;" + // "font-weight:Bold; font-size:16px; border:1px solid #323232;}" + // "QHeaderView::section:horizontal{border-bottom: 1px solid rgb(0,170,255);}" + // "QHeaderView::section:vertical{min-height:36px;max-height:36px;}" + // "QWidget#edit_patient{min-width:300px;max-width:300px;}" + // "QTableView{border:none}" + // "QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}" + // "QToolButton#sexBtn{min-width:120px;max-width:120px;font-size:20px;padding:2px;}" + // "QToolButton#sexBtn:disabled{color:silver}" + // "QWidget#sexpanelwidget{border:1px solid silver;}" + // "QWidget#sexpanelwidget:enabled{background-color: #515151;}" + // "QToolButton#sexBtn:checked{border:2px solid darkorange;padding:0px;}" + // ; + // + // this->setStyleSheet(this->styleSheet().append(style)); + //init command bar + QHBoxLayout* layout = new QHBoxLayout(); + ui->commandWidget->setLayout(layout); + ADD_TOOL_BTN(Account, ":/icons/account.png"); + ADD_TOOL_BTN(Worklist, ":/icons/setting.png"); + layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding)); + QWidget* spacerLine = new QWidget(this); + spacerLine->setFixedWidth(2); + spacerLine->setObjectName("verSpaceLine"); + layout->addWidget(spacerLine); + ADD_TOOL_BTN(Add, ":/icons/add.png"); + ADD_TOOL_BTN(Edit, ":/icons/details.png"); + ADD_TOOL_BTN(Delete, ":/icons/close_circle.png"); + ADD_TOOL_BTN(Select, ":/icons/selected.png"); - //Init content widget - QHBoxLayout* contentLayout =new QHBoxLayout(); - this->ui->contentWidget->setLayout(contentLayout); - // TableView for patient - QTableView* table= new SlideableTableView(this); - table->setAlternatingRowColors(true); - table->setSelectionMode(QAbstractItemView::SingleSelection); - table->setEditTriggers(QAbstractItemView::NoEditTriggers); - table->setSelectionBehavior(QAbstractItemView::SelectRows); - table->verticalHeader()->setDefaultSectionSize(38); - table->horizontalHeader()->setStretchLastSection(true); - //data from SQLITE + //Init content widget + QHBoxLayout* contentLayout = new QHBoxLayout(); + this->ui->contentWidget->setLayout(contentLayout); + // TableView for patient + QTableView* table = new SlideableTableView(this); + table->setAlternatingRowColors(true); + table->setSelectionMode(QAbstractItemView::SingleSelection); + table->setEditTriggers(QAbstractItemView::NoEditTriggers); + table->setSelectionBehavior(QAbstractItemView::SelectRows); + table->verticalHeader()->setDefaultSectionSize(38); + table->horizontalHeader()->setStretchLastSection(true); + //data from SQLITE - auto model = SQLHelper::getTable("Patient"); - model->setFilter("Flag=0"); - model->sort(5,Qt::DescendingOrder); - model->select(); - model->setHeaderData(1,Qt::Horizontal,"ID"); - model->setHeaderData(2,Qt::Horizontal,"Name"); - model->setHeaderData(3,Qt::Horizontal,"Birth Date"); - model->setHeaderData(5,Qt::Horizontal,"Add Date"); - table->setModel((QAbstractItemModel*)model); - table->hideColumn(0); - table->hideColumn(7); + auto model = SQLHelper::getTable("Patient"); + model->setFilter("Flag=0"); + model->sort(5, Qt::DescendingOrder); + model->select(); + model->setHeaderData(1, Qt::Horizontal, "ID"); + model->setHeaderData(2, Qt::Horizontal, "Name"); + model->setHeaderData(3, Qt::Horizontal, "Birth Date"); + model->setHeaderData(5, Qt::Horizontal, "Add Date"); + table->setModel((QAbstractItemModel*)model); + table->hideColumn(0); + table->hideColumn(7); + table->show(); - table->show(); - -// table->setSortingEnabled(true); - table->setColumnWidth(1,250); - table->setColumnWidth(2,250); - table->setColumnWidth(3,120); - table->setColumnWidth(4,60); - table->setColumnWidth(5,250); -// table->sortByColumn(5); -// table->setSortingEnabled(true); - contentLayout->addWidget(table); - QWidget* spacerLine2= new QWidget(this); - spacerLine2->setFixedWidth(2); - spacerLine2->setObjectName("verSpaceLine"); - contentLayout->addWidget(spacerLine2); - //edit panel - EditPatientForm* edit_patient= new EditPatientForm(this); - edit_patient->setObjectName("edit_patient"); - contentLayout->addWidget(edit_patient); - //select default row 0 - if (model->rowCount()>0) - { - table->selectRow(0); - currentRow=0; - PatientInformation pat; - #define ADD_PATIENT_PROPERTY(val)\ + // table->setSortingEnabled(true); + table->setColumnWidth(1, 250); + table->setColumnWidth(2, 250); + table->setColumnWidth(3, 120); + table->setColumnWidth(4, 60); + table->setColumnWidth(5, 250); + // table->sortByColumn(5); + // table->setSortingEnabled(true); + contentLayout->addWidget(table); + QWidget* spacerLine2 = new QWidget(this); + spacerLine2->setFixedWidth(2); + spacerLine2->setObjectName("verSpaceLine"); + contentLayout->addWidget(spacerLine2); + //edit panel + EditPatientForm* edit_patient = new EditPatientForm(this); + edit_patient->setObjectName("edit_patient"); + contentLayout->addWidget(edit_patient); + //select default row 0 + if (model->rowCount() > 0) + { + table->selectRow(0); + currentRow = 0; + PatientInformation pat; +#define ADD_PATIENT_PROPERTY(val)\ pat. val = model->data(model->index(currentRow,PatientInformationEnum:: val)).toString(); - EDIT_PATIENT() - #undef ADD_PATIENT_PROPERTY - edit_patient->setPatientInformation(&pat); - } - //events---------------------------------------------------------------------- - //table current row selection changing event - connect(table,&QTableView::clicked,[=](const QModelIndex & modelIndex){ - if (currentRow!=modelIndex.row()) - { - currentRow=modelIndex.row(); - PatientInformation pat; - #define ADD_PATIENT_PROPERTY(val)\ + EDIT_PATIENT() +#undef ADD_PATIENT_PROPERTY + edit_patient->setPatientInformation(&pat); + } + //events---------------------------------------------------------------------- + //table current row selection changing event + connect(table, &QTableView::clicked, [=](const QModelIndex& modelIndex) { + if (currentRow != modelIndex.row()) + { + currentRow = modelIndex.row(); + PatientInformation pat; +#define ADD_PATIENT_PROPERTY(val)\ pat. val = model->data(model->index(modelIndex.row(),PatientInformationEnum:: val)).toString(); - EDIT_PATIENT() - #undef ADD_PATIENT_PROPERTY - edit_patient->setPatientInformation(&pat); - } - }); + EDIT_PATIENT() +#undef ADD_PATIENT_PROPERTY + edit_patient->setPatientInformation(&pat); + } + }); - connect(btnAdd, &QToolButton::clicked,[=](){ - edit_patient->clearPatientInformation(); - edit_patient->setEditEnable(true); - btnSelect->setEnabled(false); - }); - connect(btnEdit, &QToolButton::clicked,[=](){ - table->clicked(table->currentIndex()); - edit_patient->setEditEnable(true); - btnSelect->setEnabled(false); - }); - connect(edit_patient, &EditPatientForm::editCancel,[=](){ - btnSelect->setEnabled(true); - }); - connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf, bool& result){ - int selectedRow = currentRow; - bool isAdd = inf->PatientUID.isEmpty(); - if (isAdd) { - int ref_rowid = queryValue(model, 1, inf->ID); - if(ref_rowid>=0) - { - //非触屏时,如果被选中的行在选中区域外,以下代码可能会出错 - //但是触屏时一般没问题 - qDebug()<scrollTo(model->index(ref_rowid,3)); - table->selectRow(ref_rowid); - result = false; - return; - } - selectedRow = model->rowCount(); - inf->PatientUID = QUuid::createUuid().toString(); - inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); - model->insertRow(0); - selectedRow = 0; - } - qDebug()<PatientUID<AddDate; - #define ADD_PATIENT_PROPERTY(val)\ + connect(btnAdd, &QToolButton::clicked, [=]() { + edit_patient->clearPatientInformation(); + edit_patient->setEditEnable(true); + btnSelect->setEnabled(false); + }); + connect(btnEdit, &QToolButton::clicked, [=]() { + table->clicked(table->currentIndex()); + edit_patient->setEditEnable(true); + btnSelect->setEnabled(false); + }); + connect(edit_patient, &EditPatientForm::editCancel, [=]() { + btnSelect->setEnabled(true); + }); + connect(edit_patient, &EditPatientForm::editAccept, [=](PatientInformation* inf, bool& result) { + int selectedRow = currentRow; + bool isAdd = inf->PatientUID.isEmpty(); + if (isAdd) { + int ref_rowid = queryValue(model, 1, inf->ID); + if (ref_rowid >= 0) + { + //非触屏时,如果被选中的行在选中区域外,以下代码可能会出错 + //但是触屏时一般没问题 + qDebug() << ref_rowid; + table->scrollTo(model->index(ref_rowid, 3)); + table->selectRow(ref_rowid); + result = false; + return; + } + selectedRow = model->rowCount(); + inf->PatientUID = QUuid::createUuid().toString(); + inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); + model->insertRow(0); + selectedRow = 0; + } + qDebug() << inf->PatientUID << inf->AddDate; +#define ADD_PATIENT_PROPERTY(val)\ model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val); - EDIT_PATIENT() - #undef ADD_PATIENT_PROPERTY - if (model->submitAll()) - { - table->selectRow(selectedRow); - model->selectRow(selectedRow); - } - else{ - //TODO:add some error handle logic - } - if(isAdd){ - LOG_USER_OPERATION(AddPatient); - } - else - { - LOG_USER_OPERATION(ChangePatientInfo); - } - btnSelect->setEnabled(true); - }); + EDIT_PATIENT() +#undef ADD_PATIENT_PROPERTY + if (model->submitAll()) + { + table->selectRow(selectedRow); + model->selectRow(selectedRow); + } + else { + //TODO:add some error handle logic + } + if (isAdd) { + LOG_USER_OPERATION(AddPatient); + } + else + { + LOG_USER_OPERATION(ChangePatientInfo); + } + btnSelect->setEnabled(true); + }); - connect(btnDelete, &QToolButton::clicked,[=](){ - if (currentRow<0)return; - model->setData(model->index(currentRow,PatientInformationEnum::Flag),9); -// model->removeRow(currentRow); - if (model->submitAll()) - { - model->select(); - if (model->rowCount()>0) - { - table->selectRow(0); - model->selectRow(0); - PatientInformation pat; - #define ADD_PATIENT_PROPERTY(val)\ + connect(btnDelete, &QToolButton::clicked, [=]() { + if (currentRow < 0)return; + model->setData(model->index(currentRow, PatientInformationEnum::Flag), 9); + // model->removeRow(currentRow); + if (model->submitAll()) + { + model->select(); + if (model->rowCount() > 0) + { + table->selectRow(0); + model->selectRow(0); + PatientInformation pat; +#define ADD_PATIENT_PROPERTY(val)\ pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString(); - EDIT_PATIENT() - #undef ADD_PATIENT_PROPERTY - edit_patient->setPatientInformation(&pat); - LOG_USER_OPERATION(DeletePatient); - } else{ - currentRow=-1; - } - } else{ - //TODO:error handle - } + EDIT_PATIENT() +#undef ADD_PATIENT_PROPERTY + edit_patient->setPatientInformation(&pat); + LOG_USER_OPERATION(DeletePatient); + } + else { + currentRow = -1; + } + } + else { + //TODO:error handle + } - }); + }); - connect(btnSelect, &QToolButton::clicked,[=](){ - if (currentRow<0)return; - EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr,edit_patient->getPatientInformation()->Copy()); - LOG_USER_OPERATION(SelectPatient); - }); + connect(btnSelect, &QToolButton::clicked, [=]() { + if (currentRow < 0)return; + EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr, edit_patient->getPatientInformation()->Copy()); + LOG_USER_OPERATION(SelectPatient); + }); - connect(btnAccount, &QToolButton::clicked,[=](){ - AccountFormDialog dia(this); - dia.setWindowModality(Qt::WindowModal); - dia.exec(); - }); - connect(EventCenter::Default(),&EventCenter::ResponsePreview,[=](QObject* sender,QObject* data){ - btnSelect->setEnabled(false); - btnDelete->setEnabled(false); - btnEdit->setEnabled(false); - btnAdd->setEnabled(false); - }); - connect(EventCenter::Default(),&EventCenter::ResponseStop,[=](QObject* sender,QObject* data){ - btnSelect->setEnabled(true); - btnDelete->setEnabled(true); - btnEdit->setEnabled(true); - btnAdd->setEnabled(true); - }); + connect(btnAccount, &QToolButton::clicked, [=]() { + AccountFormDialog dia(this); + dia.setWindowModality(Qt::WindowModal); + dia.exec(); + }); + connect(EventCenter::Default(), &EventCenter::ResponsePreview, [=](QObject* sender, QObject* data) { + btnSelect->setEnabled(false); + btnDelete->setEnabled(false); + btnEdit->setEnabled(false); + btnAdd->setEnabled(false); + }); + connect(EventCenter::Default(), &EventCenter::ResponseStop, [=](QObject* sender, QObject* data) { + btnSelect->setEnabled(true); + btnDelete->setEnabled(true); + btnEdit->setEnabled(true); + btnAdd->setEnabled(true); + }); } diff --git a/src/device/networkmanager.cpp b/src/device/networkmanager.cpp new file mode 100644 index 0000000..42a8b44 --- /dev/null +++ b/src/device/networkmanager.cpp @@ -0,0 +1,285 @@ +#include "networkmanager.h" +#include "json/jsonobject.h" +#include +#include + +//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 NetworkManager::getIpAddrList() +{ + return JsonObject::Instance()->getIpAddrList(); +} +QString NetworkManager::getDefaultGateway() +{ + return JsonObject::Instance()->getDefaultGateway(); +} +QList 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& 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()<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& 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& t3 = getIpAddrList(); + bool ret3 = setIpAddrList(t3, err3); + err_info.append(err3); + + qDebug() << "IpRouteList"; + const QList& 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& t2 = getIpAddrList(); + for (QStringList var : t2) + { + qDebug() << var[0] << " " << var[1]; + } + qDebug() << "getDefaultIpAddr()" << " : " << t1.ip << " " << t1.mask; + + qDebug() << "getIpRouteList()" << " : "; + const QList& t3 = getIpRouteList(); + for (QStringList var : t3) + { + qDebug() << var[0] << " " << var[1] << " " << var[2]; + } + +} diff --git a/src/device/networkmanager.h b/src/device/networkmanager.h new file mode 100644 index 0000000..00fbfcc --- /dev/null +++ b/src/device/networkmanager.h @@ -0,0 +1,52 @@ +#ifndef NETWORKMANAGER_H +#define NETWORKMANAGER_H + +#include +#include + +#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 getIpAddrList(); + static QString getDefaultGateway(); + static QList 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& list, QString& err_info); + static bool setDefaultGateway(const QString& gw, QString& err_info); + static bool setIpRouteList(const QList& 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 addresses; + + //IpRoute default_IpRoute; + //QList routes; + + + +}; + +#endif // NETWORKMANAGER_H diff --git a/src/json/cJSON.c b/src/json/cJSON.c index a7bf8bd..2c6ad7d 100644 --- a/src/json/cJSON.c +++ b/src/json/cJSON.c @@ -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; } diff --git a/src/json/cJSON.h b/src/json/cJSON.h index 522f3b4..194bc01 100644 --- a/src/json/cJSON.h +++ b/src/json/cJSON.h @@ -40,36 +40,36 @@ extern "C" #define cJSON_IsReference 256 /* The cJSON structure: */ -typedef struct cJSON { - struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + typedef struct cJSON { + struct cJSON* next, * prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON* child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ - int type; /* The type of the item, as above. */ + int type; /* The type of the item, as above. */ - char *valuestring; /* The item's string, if type==cJSON_String */ - int valueint; /* The item's number, if type==cJSON_Number */ - double valuedouble; /* The item's number, if type==cJSON_Number */ + char* valuestring; /* The item's string, if type==cJSON_String */ + int valueint; /* The item's number, if type==cJSON_Number */ + double valuedouble; /* The item's number, if type==cJSON_Number */ - char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ -} cJSON; + char* string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + } cJSON; -typedef struct cJSON_Hooks { - void *(*malloc_fn)(size_t sz); - void (*free_fn)(void *ptr); -} cJSON_Hooks; + typedef struct cJSON_Hooks { + void* (*malloc_fn)(size_t sz); + void (*free_fn)(void* ptr); + } cJSON_Hooks; -/* Supply malloc, realloc and free functions to cJSON */ -extern void cJSON_InitHooks(cJSON_Hooks* hooks); + /* Supply malloc, realloc and free functions to cJSON */ + extern void cJSON_InitHooks(cJSON_Hooks* hooks); -/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ -extern cJSON *cJSON_Parse(const char *value); -/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ -extern char *cJSON_Print(cJSON *item); -/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ -extern char *cJSON_PrintUnformatted(cJSON *item); -/* Delete a cJSON entity and all subentities. */ -extern void cJSON_Delete(cJSON *c); + /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ + extern cJSON* cJSON_Parse(const char* value); + /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ + extern char* cJSON_Print(cJSON* item); + /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ + extern char* cJSON_PrintUnformatted(cJSON* item); + /* Delete a cJSON entity and all subentities. */ + extern void cJSON_Delete(cJSON* c); /* Returns the number of items in an array (or object). */ extern int cJSON_GetArraySize(cJSON* array); @@ -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()) diff --git a/src/json/jsonobject.cpp b/src/json/jsonobject.cpp index 277948b..75245f8 100644 --- a/src/json/jsonobject.cpp +++ b/src/json/jsonobject.cpp @@ -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 JsonObject::getIpAddrList() +{ + + QList 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& 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 JsonObject::getIpRouteList() +{ + QList 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& 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(); } diff --git a/src/json/jsonobject.h b/src/json/jsonobject.h index d04e1aa..26d8aca 100644 --- a/src/json/jsonobject.h +++ b/src/json/jsonobject.h @@ -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 getIpAddrList(); + void setIpAddrList(const QList& list); + + QString getDefaultGateway(); + void setDefaultGateway(const QString& gw); + + QList getIpRouteList(); + void setIpRouteList(const QList& 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(); diff --git a/src/main.cpp b/src/main.cpp index 378a71b..6238280 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,16 +54,15 @@ int main(int argc, char* argv[]) QFont font(fontName); QApplication::setFont(font); - //a.installEventFilter(obj); InputObject* obj = new InputObject(); a.installEventFilter(obj); SQLHelper::Open(); MainWindow w; UserOperationLog::Default()->init(); - //暂时为了调试关闭锁屏 - //Locker::Instance()->start(); - //QObject::connect(obj, SIGNAL(touchScreen()), Locker::Instance(), SLOT(refreshTimer())); + //暂时为了调试关闭锁屏 + //Locker::Instance()->start(); + //QObject::connect(obj, SIGNAL(touchScreen()), Locker::Instance(), SLOT(refreshTimer())); //multi-language suppport diff --git a/src/network/getipdialog.cpp b/src/network/getipdialog.cpp new file mode 100644 index 0000000..41f1523 --- /dev/null +++ b/src/network/getipdialog.cpp @@ -0,0 +1,43 @@ +// +// Created by Krad on 2021/11/11. +// + +#include +#include +#include +#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; +} diff --git a/src/network/getipdialog.h b/src/network/getipdialog.h new file mode 100644 index 0000000..f762be2 --- /dev/null +++ b/src/network/getipdialog.h @@ -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 diff --git a/src/network/getroutedialog.cpp b/src/network/getroutedialog.cpp new file mode 100644 index 0000000..b04faf3 --- /dev/null +++ b/src/network/getroutedialog.cpp @@ -0,0 +1,46 @@ +// +// Created by Krad on 2021/11/11. +// + +#include +#include +#include +#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; +} \ No newline at end of file diff --git a/src/network/getroutedialog.h b/src/network/getroutedialog.h new file mode 100644 index 0000000..1efd6d4 --- /dev/null +++ b/src/network/getroutedialog.h @@ -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 diff --git a/src/network/netcfgtablemodel.cpp b/src/network/netcfgtablemodel.cpp new file mode 100644 index 0000000..2c8a3aa --- /dev/null +++ b/src/network/netcfgtablemodel.cpp @@ -0,0 +1,101 @@ +// +// Created by Krad on 2021/11/23. +// + +#include +#include +#include "network/netcfgtablemodel.h" +#include + +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 NetCfgTableModel::getData() +{ + return mydata; +} +bool NetCfgTableModel::loadData(const QList& 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(); +} diff --git a/src/network/netcfgtablemodel.h b/src/network/netcfgtablemodel.h new file mode 100644 index 0000000..887ee69 --- /dev/null +++ b/src/network/netcfgtablemodel.h @@ -0,0 +1,47 @@ +// +// Created by Krad on 2021/11/23. +// + +#ifndef GUI_LOGFILETABLEMODEL_H +#define GUI_LOGFILETABLEMODEL_H + +#include +#include +#include + +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& list); + QList 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 mydata; + QStringList headerStrings; +}; + + +#endif //GUI_LOGFILETABLEMODEL_H diff --git a/src/network/networkcfgdialog.cpp b/src/network/networkcfgdialog.cpp new file mode 100644 index 0000000..0142312 --- /dev/null +++ b/src/network/networkcfgdialog.cpp @@ -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 +#include +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); +} + + +//Ӱ +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); //Ӱ + shadow->setColor(Qt::black); //Ӱɫ + shadow->setBlurRadius(20); //ӰԲ + dialog->setGraphicsEffect(shadow); //Ӱ + //ui->frame->setObjectName("widgetShadow"); + //ui->frame->setStyleSheet("#widgetShadow{border-radius:5px;}");//һʽӴҲ͸ +} + +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); +} + + + diff --git a/src/network/networkcfgdialog.h b/src/network/networkcfgdialog.h new file mode 100644 index 0000000..c3b799c --- /dev/null +++ b/src/network/networkcfgdialog.h @@ -0,0 +1,34 @@ +#ifndef NETWORKCFGDIALOG_H +#define NETWORKCFGDIALOG_H + +#include + +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 diff --git a/src/networkcfgdialog.ui b/src/networkcfgdialog.ui new file mode 100644 index 0000000..43112db --- /dev/null +++ b/src/networkcfgdialog.ui @@ -0,0 +1,550 @@ + + + networkCfgDialog + + + + 0 + 0 + 863 + 678 + + + + + 0 + 0 + + + + Network Settings + + + 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; +} + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 0 + + + + Address + + + + + + + + + IP Address + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Dynamic Address + + + + + + + Dev + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 87 + 28 + + + + + 87 + 28 + + + + background-color: #232629; + + + + + + + false + + + + 0 + 0 + + + + + 87 + 26 + + + + + 87 + 26 + + + + + + + + + + + Subnet Mask + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Additional Address + + + Qt::AlignCenter + + + + 30 + + + + + + + + + + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Edit + + + + + + + + 0 + 0 + + + + Delete + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 321 + 20 + + + + + + + + + + + + Routing + + + + 10 + + + 15 + + + + + + + + + 0 + 0 + + + + + 190 + 26 + + + + + 190 + 26 + + + + + + + + + + + Qt::Horizontal + + + + 373 + 20 + + + + + + + + Default IPv4 Gateway + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + + + Routing Table + + + Qt::AlignCenter + + + + 9 + + + 30 + + + 9 + + + + + Qt::DashLine + + + false + + + + + + + + + + + + + Add + + + + + + + Edit + + + + + + + Delete + + + + + + + Qt::Horizontal + + + + 321 + 20 + + + + + + + + + + + + Result + + + + + 30 + 20 + 781 + 541 + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel + + + + + + + + + + + ImageSwitch + QWidget +
components/imageswitch.h
+ 1 +
+ + SlideableTableView + QTableView +
components/SlideableTableView.h
+
+
+ + + + btn_group + accepted() + networkCfgDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + btn_group + rejected() + networkCfgDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/systemsettingform.cpp b/src/systemsettingform.cpp index 257f165..9bc8da0 100644 --- a/src/systemsettingform.cpp +++ b/src/systemsettingform.cpp @@ -7,14 +7,13 @@ #include #include #include - #include #include "json/jsonobject.h" #include "SelectDialog.h" #include "components/imageswitch.h" #include "components/ipaddress.h" -#include +#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"<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"<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); } diff --git a/src/systemsettingform.h b/src/systemsettingform.h index 2d8eadf..c033f04 100644 --- a/src/systemsettingform.h +++ b/src/systemsettingform.h @@ -25,9 +25,8 @@ private: SelectDialog* sd_filter = nullptr; void loadServersInfo(); - void saveServersInfo(); - void qIfConfig(const localhost &lhost); - void autoDHCP(); + void saveServersInfo(); + QLineEdit* pacs_Name; QLineEdit* recon_IP; QLineEdit* daq_AE;