qt/LedOK/device/ctrlnetworkpanel.cpp

1174 lines
50 KiB
C++
Raw Normal View History

2023-04-18 14:14:46 +08:00
#include "ctrlnetworkpanel.h"
2023-10-23 15:08:45 +08:00
#include "gutil/qwaitingdlg.h"
2024-08-07 18:18:37 +08:00
#include "main.h"
2023-04-18 14:14:46 +08:00
#include "tools.h"
2023-05-15 16:06:10 +08:00
#include "devicepanel.h"
2023-04-18 14:14:46 +08:00
#include "gutil/qgui.h"
2023-04-23 17:01:35 +08:00
#include "gutil/qnetwork.h"
2023-04-18 14:14:46 +08:00
#include <QJsonArray>
#include <QMessageBox>
#include <QStackedLayout>
#include <QGridLayout>
2023-08-01 11:42:41 +08:00
CtrlNetworkPanel::CtrlNetworkPanel() {
2023-04-18 14:14:46 +08:00
auto vBox = new VBox(this);
lbLanCfg = new QLabel;
2023-04-27 15:06:24 +08:00
auto ftTitle = lbLanCfg->font();
ftTitle.setPixelSize(16);
lbLanCfg->setFont(ftTitle);
2023-04-18 14:14:46 +08:00
lbLanCfg->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbLanCfg);
auto hBox = new HBox(vBox);
hBox->addStretch();
2025-05-06 18:28:05 +08:00
fdDhcp = new QRadioButton("DHCP");
2023-04-18 14:14:46 +08:00
fdDhcp->setChecked(true);
hBox->addWidget(fdDhcp, 0, Qt::AlignTop);
hBox->addSpacing(30);
auto vBoxSpecifyIp = new VBox(hBox);
vBoxSpecifyIp->setContentsMargins(0, 0, 0, 0);
fdSpecifyIp = new QRadioButton;
vBoxSpecifyIp->addWidget(fdSpecifyIp, 0, Qt::AlignCenter);
auto grp = new QButtonGroup(this);
grp->addButton(fdDhcp);
grp->addButton(fdSpecifyIp);
gBoxSpecifyIp = new QGroupBox;
gBoxSpecifyIp->setMaximumWidth(340);
gBoxSpecifyIp->setVisible(false);
connect(fdSpecifyIp, &QRadioButton::toggled, gBoxSpecifyIp, &QWidget::setVisible);
{
auto vvv = new VBox(gBoxSpecifyIp);
auto hhh = new HBox(vvv);
2023-04-19 14:42:06 +08:00
hhh->addWidget(labelIpAddress = new QLabel);
2023-04-18 14:14:46 +08:00
2023-04-19 14:42:06 +08:00
fdIP = new QLineEdit;
2023-05-05 17:22:54 +08:00
auto ft = fdIP->font();
ft.setFamilies({"Monaco", "Consolas", "Mono-space"});
fdIP->setFont(ft);
fdIP->setInputMask("000.000.000.000");
2023-04-23 14:30:16 +08:00
fdIP->setAlignment(Qt::AlignCenter);
2023-04-18 14:14:46 +08:00
fdIP->setFixedWidth(160);
hhh->addWidget(fdIP);
hhh = new HBox(vvv);
2023-04-19 14:42:06 +08:00
hhh->addWidget(labelMaskAddress = new QLabel);
2023-04-18 14:14:46 +08:00
2023-04-19 14:42:06 +08:00
fdMask = new QLineEdit;
2023-05-05 17:22:54 +08:00
fdMask->setFont(ft);
fdMask->setInputMask("000.000.000.000");
2023-04-23 14:30:16 +08:00
fdMask->setAlignment(Qt::AlignCenter);
2023-04-18 14:14:46 +08:00
fdMask->setFixedWidth(160);
hhh->addWidget(fdMask);
hhh = new HBox(vvv);
2023-04-19 14:42:06 +08:00
hhh->addWidget(labelGateway = new QLabel);
2023-04-18 14:14:46 +08:00
2023-04-19 14:42:06 +08:00
fdGateWay = new QLineEdit;
2023-05-05 17:22:54 +08:00
fdGateWay->setFont(ft);
fdGateWay->setInputMask("000.000.000.000");
2023-04-23 14:30:16 +08:00
fdGateWay->setAlignment(Qt::AlignCenter);
2023-04-18 14:14:46 +08:00
fdGateWay->setFixedWidth(160);
hhh->addWidget(fdGateWay);
hhh = new HBox(vvv);
2023-04-19 14:42:06 +08:00
hhh->addWidget(labelDnsAddress = new QLabel);
2023-04-18 14:14:46 +08:00
2023-04-19 14:42:06 +08:00
fdDns = new QLineEdit;
2023-05-05 17:22:54 +08:00
fdDns->setFont(ft);
fdDns->setInputMask("000.000.000.000");
2023-04-23 14:30:16 +08:00
fdDns->setAlignment(Qt::AlignCenter);
2023-04-18 14:14:46 +08:00
fdDns->setFixedWidth(160);
hhh->addWidget(fdDns);
}
vBoxSpecifyIp->addWidget(gBoxSpecifyIp);
hBox->addStretch();
hBox = new HBox(vBox);
hBox->addStretch();
btnLanSet = new QPushButton;
btnLanSet->setMinimumSize(QSize(60, 30));
btnLanSet->setProperty("ssType", "progManageTool");
connect(btnLanSet, &QPushButton::clicked, this, [this] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
2023-04-23 14:30:16 +08:00
QString ip = fdIP->text();
QString mask = fdMask->text();
QString gateWay = fdGateWay->text();
QString dns = fdDns->text();
2023-04-18 14:14:46 +08:00
if(fdDhcp->isChecked()) {
2023-04-23 14:30:16 +08:00
if(ip=="...") ip = "0.255.255.255";
if(mask=="...") mask = "0.255.255.255";
if(gateWay=="...") gateWay = "0.255.255.255";
if(dns=="...") dns = "0.255.255.255";
2023-04-18 14:14:46 +08:00
} else {
2023-04-23 14:30:16 +08:00
if(ip=="...") {
2023-05-11 11:47:00 +08:00
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
2023-04-18 14:14:46 +08:00
fdIP->setFocus();
return;
}
2023-04-23 14:30:16 +08:00
if(mask=="...") {
2023-05-11 11:47:00 +08:00
QMessageBox::warning(this, tr("Attention"), tr("Please input Mask address!"));
2023-04-18 14:14:46 +08:00
fdMask->setFocus();
return;
}
2023-04-23 14:30:16 +08:00
if(gateWay=="...") {
2023-05-11 11:47:00 +08:00
QMessageBox::warning(this, tr("Attention"), tr("Please input Gateway address!"));
2023-04-18 14:14:46 +08:00
fdGateWay->setFocus();
return;
}
2023-04-23 14:30:16 +08:00
if(dns=="...") {
2023-05-11 11:47:00 +08:00
QMessageBox::warning(this, tr("Attention"), tr("Please input DNS address!"));
2023-04-18 14:14:46 +08:00
fdDns->setFocus();
return;
}
}
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "SetEthernet");
json.insert("_type", "SetEthernet");
json.insert("dhcp", fdDhcp->isChecked());
json.insert("ip", ip);
json.insert("netMask", mask);
json.insert("gateWay", gateWay);
json.insert("dns", dns);
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("SetEthernet"));
Def_CtrlReqPre
2023-05-11 11:47:00 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2023-04-18 14:14:46 +08:00
Def_CtrlSetReqAfter
});
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
2023-04-18 14:14:46 +08:00
Def_CtrlSetMulti(tr("SetEthernet"))
}
}
});
hBox->addWidget(btnLanSet);
hBox->addSpacing(50);
btnLanGet = new QPushButton;
btnLanGet->setMinimumSize(QSize(60, 30));
btnLanGet->setProperty("ssType", "progManageTool");
connect(btnLanGet, &QPushButton::clicked, this, [this] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet");
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("GetEthernet"));
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
if(json["dhcp"].toBool()) {
fdDhcp->setChecked(true);
gBoxSpecifyIp->setVisible(false);
} else {
fdSpecifyIp->setChecked(true);
gBoxSpecifyIp->setVisible(true);
}
fdIP->setText(json["ipAddr"].toString());
fdMask->setText(json["netMask"].toString());
fdGateWay->setText(json["gateWay"].toString());
fdDns->setText(json["dnsAddr"].toString());
});
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
2023-05-15 16:06:10 +08:00
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card.id;
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(err.isEmpty()) err = json["dhcp"].toBool() ? tr("DHCP IP") : tr("STATIC IP");
gFdResInfo->append(cardId+" "+tr("GetEthernet")+" "+err);
gFdResInfo->append(" IP: "+json["ipAddr"].toString());
gFdResInfo->append(" Mask: "+json["netMask"].toString());
gFdResInfo->append(" GateWay: "+json["gateWay"].toString());
gFdResInfo->append(" Dns: "+json["dnsAddr"].toString());
});
}
}
});
hBox->addWidget(btnLanGet);
hBox->addStretch();
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line);
2025-05-06 18:28:05 +08:00
lbWifiCfg = new QLabel;
lbWifiCfg->setFont(ftTitle);
lbWifiCfg->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbWifiCfg);
2023-04-18 14:14:46 +08:00
hBox = new HBox(vBox);
hBox->addStretch();
{
2025-05-06 18:28:05 +08:00
auto vvv = new VBox(hBox);
auto hBox = new HBox(vvv);
hBox->addStretch();
hBox->addWidget(fdIsWifi = new QCheckBox);
hBox->addStretch();
2023-04-18 14:14:46 +08:00
hBox = new HBox(vvv);
lbWifiName = new QLabel;
lbWifiName->setMinimumWidth(80);
2024-05-23 17:13:51 +08:00
lbWifiName->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
2023-04-18 14:14:46 +08:00
hBox->addWidget(lbWifiName);
2025-05-06 18:28:05 +08:00
edWifiName = new QComboBox;
edWifiName->setEditable(true);
edWifiName->setMinimumWidth(180);
edWifiName->setSizeAdjustPolicy(QComboBox::AdjustToContents);
hBox->addWidget(edWifiName);
2023-04-18 14:14:46 +08:00
btnScan = new QPushButton;
btnScan->setMinimumWidth(60);
btnScan->setProperty("ssType", "progManageTool");
connect(btnScan, &QPushButton::clicked, this, [this] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
QJsonObject json;
json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList");
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("GetWifiList")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
auto wifis = json["wifiList"].toArray();
2025-05-06 18:28:05 +08:00
auto cur = edWifiName->currentText();
edWifiName->clear();
for(auto &wifi : wifis) edWifiName->addItem(QIcon(":/res/signal-"+QString::number((wifi["signal"].toInt()+19)/20)+".png"), wifi["ssid"].toString());
if(! cur.isEmpty()) edWifiName->setCurrentText(cur);
2023-04-18 14:14:46 +08:00
});
}
});
hBox->addWidget(btnScan);
hBox->addStretch();
hBox = new HBox(vvv);
2025-05-06 18:28:05 +08:00
lbWifiPswd = new QLabel;
lbWifiPswd->setMinimumWidth(80);
lbWifiPswd->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
hBox->addWidget(lbWifiPswd);
2023-04-18 14:14:46 +08:00
2025-05-06 18:28:05 +08:00
edWifiPswd = new QLineEdit;
edWifiPswd->setFixedWidth(180);
edWifiPswd->setEchoMode(QLineEdit::PasswordEchoOnEdit);
hBox->addWidget(edWifiPswd);
2023-04-18 14:14:46 +08:00
hBox->addStretch();
2025-05-06 18:28:05 +08:00
hBox = new HBox(vvv);
hBox->addStretch();
btnWiFiSet = new QPushButton;
btnWiFiSet->setMinimumSize(QSize(60, 30));
btnWiFiSet->setProperty("ssType", "progManageTool");
connect(btnWiFiSet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
auto isWifi = fdIsWifi->isChecked();
JObj json;
json.insert("_id", "SetSwitchWiFi");
json.insert("_type", "SetSwitchWiFi");
json.insert("enable", true);
JObj jsonG;
jsonG.insert("_id", "ControllerWifiSwitch");
jsonG.insert("_type", "ControllerWifiSwitch");
jsonG.insert("isWifi", true);
jsonG.insert("isOpen", isWifi);
JObj json2;
json2.insert("_id", "ConfigurationWiFi");
json2.insert("_type", "ConfigurationWiFi");
json2.insert("ssid", edWifiName->currentText());
json2.insert("password", edWifiPswd->text());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ConfigurationWiFi")+" ...");
waitingDlg->show();
auto card = gSelCards[0];
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
if(isWifi) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(isG ? jsonG : json);
ConnReply(reply, waitingDlg) [=] {
auto err = errStrWithJson(reply);
if(! err.isEmpty()) {
waitingDlg->close();
QMessageBox::critical(this, translate("","Error"), err);
return;
}
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json2);
ConnReply(reply, waitingDlg) [=] {
Def_CtrlSetReqAfter
});
});
} else if(isG) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(jsonG);
ConnReply(reply, waitingDlg) [=] {
Def_CtrlSetReqAfter
});
}
else waitingDlg->success();
} else {
for(auto &card : gSelCards) {
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
if(isWifi) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(isG ? jsonG : json);
connect(reply, &QNetworkReply::finished, gFdResInfo, [=] {
auto err = errStrWithJson(reply);
if(! err.isEmpty()) {
gFdResInfo->append(card.id+" "+tr("ConfigurationWiFi")+" "+err);
return;
}
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json2);
connect(reply, &QNetworkReply::finished, gFdResInfo, [=] {
auto err = errStrWithJson(reply);
gFdResInfo->append(card.id+" "+tr("ConfigurationWiFi")+" "+(err.isEmpty()?translate("","Success"):err));
});
});
} else if(isG) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(jsonG);
connect(reply, &QNetworkReply::finished, gFdResInfo, [=] {
auto err = errStrWithJson(reply);
gFdResInfo->append(card.id+" "+tr("ConfigurationWiFi")+" "+(err.isEmpty()?translate("","Success"):err));
});
}
else gFdResInfo->append(card.id+" "+tr("ConfigurationWiFi")+" "+translate("","Success"));
}
}
});
hBox->addWidget(btnWiFiSet);
hBox->addStretch();
2023-04-18 14:14:46 +08:00
vvv->addStretch();
2025-05-06 18:28:05 +08:00
}
{
auto vvv = new VBox(hBox);
auto hBox = new HBox(vvv);
hBox->addStretch();
hBox->addWidget(fdIsAP = new QCheckBox);
hBox->addStretch();
2023-04-18 14:14:46 +08:00
hBox = new HBox(vvv);
lbHotspotName = new QLabel;
lbHotspotName->setMinimumWidth(80);
2024-05-23 17:13:51 +08:00
lbHotspotName->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
2023-04-18 14:14:46 +08:00
hBox->addWidget(lbHotspotName);
2025-05-06 18:28:05 +08:00
edHotspotName = new QLineEdit;
edHotspotName->setFixedWidth(180);
hBox->addWidget(edHotspotName);
2023-04-18 14:14:46 +08:00
hBox->addStretch();
hBox = new HBox(vvv);
2025-05-06 18:28:05 +08:00
lbHotspotPswd = new QLabel;
lbHotspotPswd->setMinimumWidth(80);
lbHotspotPswd->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
hBox->addWidget(lbHotspotPswd);
2023-04-18 14:14:46 +08:00
2025-05-06 18:28:05 +08:00
edHotspotPswd = new QLineEdit;
edHotspotPswd->setEchoMode(QLineEdit::PasswordEchoOnEdit);
edHotspotPswd->setFixedWidth(180);
hBox->addWidget(edHotspotPswd);
2023-04-18 14:14:46 +08:00
hBox->addStretch();
2024-05-23 17:13:51 +08:00
hBox = new HBox(vvv);
auto lll = new QLabel;
lll->setMinimumWidth(80);
hBox->addWidget(lll);
2025-05-06 18:28:05 +08:00
auto edIs2_4G = new QRadioButton("2.4G");
edIs2_4G->setChecked(true);
hBox->addWidget(edIs2_4G);
2024-05-23 17:13:51 +08:00
2025-05-06 18:28:05 +08:00
edIs5G = new QRadioButton("5G");
hBox->addWidget(edIs5G);
2024-05-23 17:13:51 +08:00
hBox->addStretch();
2025-05-06 18:28:05 +08:00
hBox = new HBox(vvv);
hBox->addStretch();
2023-04-18 14:14:46 +08:00
2025-05-06 18:28:05 +08:00
btnHotspotSet = new QPushButton;
btnHotspotSet->setMinimumSize(60, 30);
btnHotspotSet->setProperty("ssType", "progManageTool");
connect(btnHotspotSet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
auto isAp = fdIsAP->isChecked();
JObj jsonG;
jsonG.insert("_id", "ControllerWifiSwitch");
jsonG.insert("_type", "ControllerWifiSwitch");
jsonG.insert("isWifi", false);
jsonG.insert("isOpen", isAp);
JObj json;
json.insert("_id", "ConfigurationHotSpot");
json.insert("_type", "ConfigurationHotSpot");
json.insert("apName", edHotspotName->text());
json.insert("apBand", edIs5G->isChecked() ? 1 : 0);
json.insert("password", edHotspotPswd->text());
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2025-05-06 18:28:05 +08:00
auto waitingDlg = new WaitingDlg(this, tr("Config Hotspot")+" ...");
waitingDlg->show();
auto card = gSelCards[0];
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
if(isG) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(jsonG);
connect(waitingDlg, &WaitingDlg::rejected, reply, &QNetworkReply::deleteLater);
connect(reply, &QNetworkReply::finished, waitingDlg, [=] {
auto err = errStrWithJson(reply);
2023-04-25 16:30:58 +08:00
if(! err.isEmpty()) {
2025-05-06 18:28:05 +08:00
waitingDlg->close();
QMessageBox::critical(this, translate("","Error"), err);
2023-04-25 16:30:58 +08:00
return;
}
2025-05-06 18:28:05 +08:00
if(isAp) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
ConnReply(reply, waitingDlg) [=] {
Def_CtrlSetReqAfter
});
} else waitingDlg->success();
2023-04-23 17:01:35 +08:00
});
2025-05-06 18:28:05 +08:00
} else if(isAp) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
ConnReply(reply, waitingDlg) [=] {
Def_CtrlSetReqAfter
});
} else waitingDlg->success();
2023-04-25 16:30:58 +08:00
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
if(isG) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(jsonG);
connect(reply, &QNetworkReply::finished, gFdResInfo, [=] {
auto err = errStrWithJson(reply);
if(! err.isEmpty()) {
gFdResInfo->append(card.id+" "+tr("Config Hotspot")+" "+err);
return;
}
if(isAp) {
Def_CtrlSetMulti(tr("Config Hotspot"));
} else gFdResInfo->append(card.id+" "+tr("Config Hotspot")+" "+translate("","Success"));
});
} else if(isAp) {
Def_CtrlSetMulti(tr("Config Hotspot"));
} else gFdResInfo->append(card.id+" "+tr("Config Hotspot")+" "+translate("","Success"));
2023-04-25 16:30:58 +08:00
}
2023-04-18 14:14:46 +08:00
}
2025-05-06 18:28:05 +08:00
});
hBox->addWidget(btnHotspotSet);
hBox->addStretch();
vvv->addStretch();
}
hBox->addStretch();
fdIsWifi->setChecked(true);
hBox = new HBox(vBox);
hBox->addStretch();
2023-04-18 14:14:46 +08:00
btnWiFiGet = new QPushButton;
2025-05-06 18:28:05 +08:00
btnWiFiGet->setMinimumSize(60, 30);
2023-04-18 14:14:46 +08:00
btnWiFiGet->setProperty("ssType", "progManageTool");
connect(btnWiFiGet, &QPushButton::clicked, this, [this] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "IsPortableHotSpot");
json.insert("_type", "IsPortableHotSpot");
2025-05-06 18:28:05 +08:00
JObj jsonG;
jsonG.insert("_id", "GetWifiSwitchState");
jsonG.insert("_type", "GetWifiSwitchState");
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2025-05-06 18:28:05 +08:00
auto waitingDlg = new WaitingDlg(this, tr("Get AP or WiFi")+" ...");
waitingDlg->show();
auto card = gSelCards[0];
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
auto reply = NetReq("http://"+card.ip+":2016/settings").post(isG ? jsonG : json);
connect(waitingDlg, &WaitingDlg::rejected, reply, &QNetworkReply::deleteLater);
connect(reply, &QNetworkReply::finished, this, [=] {
2023-04-18 14:14:46 +08:00
Def_CtrlSingleGetReply
waitingDlg->success();
2025-05-06 18:28:05 +08:00
if(isG) {
fdIsWifi->setChecked(json["wifiEnable"].toBool());
fdIsAP->setChecked(json["apEnable"].toBool());
edWifiName->setCurrentText(json["wifiName"].toString());
edHotspotName->setText(json["hotSpotName"].toString());
edIs5G->setChecked(json["apBand"].toBool());
} else {
edWifiName->setCurrentText(json["wifi"].toString());
auto hotSpots = json["hotSpots"].toString();
edHotspotName->setText(hotSpots);
fdIsWifi->setChecked(hotSpots.isEmpty());
fdIsAP->setChecked(! hotSpots.isEmpty());
}
2023-04-18 14:14:46 +08:00
});
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
2023-05-15 16:06:10 +08:00
auto cardId = card.id;
2025-05-06 18:28:05 +08:00
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(err.isEmpty()) {
2025-05-06 18:28:05 +08:00
err = translate("","Success");
if(isG) {
err = err+"\nWifi: "+(json["wifiEnable"].toBool()?"On":"Off")+" "+json["wifiName"].toString();
err = err+"\nAP: "+(json["apEnable"].toBool()?"On":"Off")+" "+json["hotSpotName"].toString()
+(json["apBand"].toBool() ? " 5G" : " 2.4G");
} else {
auto wifi = json["wifi"].toString();
if(! wifi.isEmpty()) err += " "+tr("WifiName")+":"+wifi;
auto hotSpots = json["hotSpots"].toString();
if(! hotSpots.isEmpty()) err += " "+tr("ApName")+":"+hotSpots;
}
2023-04-18 14:14:46 +08:00
}
2025-05-06 18:28:05 +08:00
gFdResInfo->append(cardId+" "+tr("Get AP or WiFi")+" "+err);
2023-04-18 14:14:46 +08:00
});
}
}
});
hBox->addWidget(btnWiFiGet);
hBox->addStretch();
line_3 = new QFrame;
line_3->setFrameShape(QFrame::HLine);
line_3->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line_3);
lbCellularConfig = new QLabel;
2023-04-27 15:06:24 +08:00
lbCellularConfig->setFont(ftTitle);
2023-04-18 14:14:46 +08:00
vBox->addWidget(lbCellularConfig, 0, Qt::AlignHCenter);
hBox = new HBox(vBox);
fdEnableCellular = new QCheckBox;
fdEnableCellular->setChecked(true);
connect(fdEnableCellular, &QCheckBox::toggled, this, [=](bool checked) {
groupApn->setEnabled(checked);
fdMcc->setEnabled(checked);
fdCarrierName->setEnabled(checked);
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
QJsonObject json;
json.insert("_id", "SetSwitchSimData");
json.insert("_type", "SetSwitchSimData");
json.insert("enable", checked);
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("SetSwitchSimData")+" ...");
Def_CtrlReqPre
2023-05-11 11:47:00 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2023-04-18 14:14:46 +08:00
Def_CtrlSetReqAfter
});
} else {
2025-05-23 18:35:00 +08:00
for(auto &card : gSelCards) {
2023-04-18 14:14:46 +08:00
Def_CtrlSetMulti(tr("SetSwitchSimData"))
}
}
});
hBox->addWidget(fdEnableCellular);
btnSIMStatusGet = new QPushButton;
btnSIMStatusGet->setMinimumHeight(30);
btnSIMStatusGet->setProperty("ssType", "progManageTool");
connect(btnSIMStatusGet, &QPushButton::clicked, this, [this] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
QJsonObject json;
json.insert("_id", "GetSIMStatus");
json.insert("_type", "GetSIMStatus");
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("GetSIMStatus")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->close();
2025-05-06 18:28:05 +08:00
QString str4GStatus = tr("Status")+":";
2023-04-18 14:14:46 +08:00
auto state = json["state"].toInt();
if(state<2) str4GStatus += tr("未知");
else if(state==2) str4GStatus += tr("锁定状态需要用户的PIN码解锁");
else if(state==3) str4GStatus += tr("锁定状态需要用户的PUK码解锁");
else if(state==4) str4GStatus += tr("锁定状态需要网络的PIN码解锁");
else if(state==5) str4GStatus += tr("就绪");
auto imsi = json["imsi"].toString();
if(imsi.isEmpty()) str4GStatus += "\n"+tr("no checked sim card");
else {
str4GStatus += "\nIMSI: "+imsi+"\n";
fdMcc->setCurrentText(imsi.left(3));
str4GStatus += tr("国家码:") + json["countryCode"].toString() + "(" + imsi.left(3) + ")\n";
str4GStatus += tr("号码:") + json["phoneNumber"].toString() + "\n";
str4GStatus += tr("用户:") + json["user"].toString() + "\n";
str4GStatus += tr("信号:");
switch(json["serviceState"].toInt()) {
case 0: str4GStatus+=tr("信号正常")+"\r\n"; break;
case 1: str4GStatus+=tr("不在服务区")+"\r\n"; break;
case 2: str4GStatus+=tr("仅限紧急呼叫")+"\r\n"; break;
case 3: str4GStatus+=tr("射频已经关闭")+"\r\n"; break;
}
str4GStatus += tr("网络:");
switch(json["networkType"].toInt()) {
case 0: str4GStatus+=tr("网络类型未知")+"\r\n"; break;
case 1: str4GStatus+=tr("GPRS网络")+"\r\n"; break;
case 2: str4GStatus+=tr("EDGE网络")+"\r\n"; break;
case 3: str4GStatus+=tr("UMTS网络")+"\r\n"; break;
case 4: str4GStatus+=tr("CDMA网络,IS95A 或 IS95B.")+"\r\n"; break;
case 5: str4GStatus+=tr("EVDO网络, revision 0.")+"\r\n"; break;
case 6: str4GStatus+=tr("EVDO网络, revision A.")+"\r\n"; break;
case 7: str4GStatus+=tr("1xRTT网络")+"\r\n"; break;
case 8: str4GStatus+=tr("HSDPA网络")+"\r\n"; break;
case 9: str4GStatus+=tr("HSUPA网络")+"\r\n"; break;
case 10: str4GStatus+=tr("HSPA网络")+"\r\n"; break;
}
str4GStatus += tr("漫游:") + (json["roaming"].toBool() ? tr("Yes") : tr("No")) + "\n";
str4GStatus += tr("数据连接状态:");
switch(json["dataState"].toInt()) {
case 0: str4GStatus+=tr("断开")+"\r\n"; break;
case 1: str4GStatus+=tr("正在连接")+"\r\n"; break;
case 2: str4GStatus+=tr("已连接")+"\r\n"; break;
case 3: str4GStatus+=tr("暂停")+"\r\n"; break;
}
str4GStatus += tr("数据活动休眠状态:");
switch(json["dataActivity"].toInt()) {
case 0: str4GStatus+=tr("活动,但无数据发送和接收")+"\r\n"; break;
case 1: str4GStatus+=tr("活动,正在接收数据")+"\r\n"; break;
case 2: str4GStatus+=tr("活动,正在发送数据")+"\r\n"; break;
case 3: str4GStatus+=tr("活动,正在接收和发送数据")+"\r\n"; break;
case 4: str4GStatus+=tr("休眠状态")+"\r\n"; break;
}
str4GStatus += tr("信号强度:") + QString::number(json["signalStrength"].toInt())+"\n";
}
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), str4GStatus);
2023-04-18 14:14:46 +08:00
});
}
});
hBox->addWidget(btnSIMStatusGet);
hBox->addStretch();
groupApn = new QGroupBox;
vBox->addWidget(groupApn);
auto vvv = new VBox(groupApn);
lbCheckStatusTip = new QLabel(groupApn);
lbCheckStatusTip->setWordWrap(true);
vvv->addWidget(lbCheckStatusTip);
hBox = new HBox(vvv);
label_2 = new QLabel(groupApn);
hBox->addWidget(label_2);
fdMcc = new QComboBox;
fdMcc->setMinimumWidth(80);
fdMcc->setEditable(true);
connect(fdMcc, (void(QComboBox::*)(int))&QComboBox::currentIndexChanged, this, [=](int index) {
if(index < 1) return;
fdCarrierName->clear();
fdCarrierName->addItem("");
auto apnInfos = fdMcc->itemData(index).toJsonArray();
2025-05-06 18:28:05 +08:00
for(QJsonValue apnInfo : apnInfos) fdCarrierName->addItem(apnInfo["carrier"].toString(), apnInfo);
2023-04-18 14:14:46 +08:00
});
hBox->addWidget(fdMcc);
hBox->addWidget(new QLabel("->"));
label_3 = new QLabel(groupApn);
hBox->addWidget(label_3);
fdCarrierName = new QComboBox;
fdCarrierName->setMinimumSize(QSize(200, 0));
fdCarrierName->setEditable(true);
connect(fdCarrierName, (void(QComboBox::*)(int))&QComboBox::currentIndexChanged, this, [=](int index) {
if(index < 1) return;
auto json = fdCarrierName->itemData(index).toJsonObject();
fdCus_Name->setText(json["carrier"].toString());
fdCus_apn->setText(json["apn"].toString());
fdCus_User->setText(json["user"].toString());
fdCus_pwd->setText(json["password"].toString());
fdCus_type->setText(json["type"].toString());
fdCus_server->setText(json["server"].toString());
fdCus_proxy->setText(json["proxy"].toString());
fdCus_port->setText(json["port"].toString());
fdCus_mmsc->setText(json["mmsc"].toString());
fdCus_mmsProxy->setText(json["mmsproxy"].toString());
fdCus_mmsPort->setText(json["mmsport"].toString());
});
hBox->addWidget(fdCarrierName);
hBox->addStretch();
hBox = new HBox(vvv);
hBox->addStretch();
auto grid = new QGridLayout();
hBox->addLayout(grid);
auto label = new QLabel("APN");
label->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(label, 0, 0);
grid->addWidget(lbCus_Name = new QLabel, 1, 0);
lbCus_Name->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_User = new QLabel, 2, 0);
lbCus_User->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_pwd = new QLabel, 3, 0);
lbCus_pwd->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_type = new QLabel, 4, 0);
lbCus_type->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_server = new QLabel, 5, 0);
lbCus_server->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_port = new QLabel, 0, 2);
lbCus_port->setMinimumWidth(80);
lbCus_port->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_proxy = new QLabel, 1, 2);
lbCus_proxy->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(label = new QLabel("mmsc"), 2, 2);
label->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_mmsPort = new QLabel, 3, 2);
lbCus_mmsPort->setAlignment((Qt::Alignment)AlignRight);
grid->addWidget(lbCus_mmsProxy = new QLabel, 4, 2);
lbCus_mmsProxy->setAlignment((Qt::Alignment)AlignRight);
fdCus_apn = new QLineEdit;
fdCus_Name = new QLineEdit;
fdCus_User = new QLineEdit;
fdCus_pwd = new QLineEdit;
fdCus_type = new QLineEdit;
fdCus_server = new QLineEdit;
fdCus_port = new QLineEdit;
fdCus_proxy = new QLineEdit;
fdCus_mmsc = new QLineEdit;
fdCus_mmsPort = new QLineEdit;
fdCus_mmsProxy = new QLineEdit;
fdCus_apn->setMinimumWidth(260);
fdCus_port->setMinimumWidth(260);
grid->addWidget(fdCus_apn, 0, 1);
grid->addWidget(fdCus_Name, 1, 1);
grid->addWidget(fdCus_User, 2, 1);
grid->addWidget(fdCus_pwd, 3, 1);
grid->addWidget(fdCus_type, 4, 1);
grid->addWidget(fdCus_server, 5, 1);
grid->addWidget(fdCus_port, 0, 3);
grid->addWidget(fdCus_proxy, 1, 3);
grid->addWidget(fdCus_mmsc, 2, 3);
grid->addWidget(fdCus_mmsPort, 3, 3);
grid->addWidget(fdCus_mmsProxy, 4, 3);
auto hhhh = new HBox;
btnAPNCusSet = new QPushButton;
btnAPNCusSet->setMinimumSize(QSize(60, 30));
btnAPNCusSet->setProperty("ssType", "progManageTool");
connect(btnAPNCusSet, &QPushButton::clicked, this, [=] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
QJsonObject json;
json.insert("_id", "SetAPN");
json.insert("_type", "SetAPN");
json.insert("carrier", fdCus_Name->text());
json.insert("apn", fdCus_apn->text());
json.insert("user", fdCus_User->text());
json.insert("password", fdCus_pwd->text());
json.insert("type", fdCus_type->text());
json.insert("server", fdCus_server->text());
json.insert("proxy", fdCus_proxy->text());
json.insert("port", fdCus_port->text());
json.insert("mmsc", fdCus_mmsc->text());
json.insert("mmsproxy", fdCus_mmsProxy->text());
json.insert("mmsport", fdCus_mmsPort->text());
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("SetAPN")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
2025-05-23 18:35:00 +08:00
for(auto &card : gSelCards) {
2023-04-18 14:14:46 +08:00
Def_CtrlSetMulti(tr("SetAPN"))
}
}
});
hhhh->addWidget(btnAPNCusSet);
hhhh->addStretch();
btnAPNCusGet = new QPushButton;
btnAPNCusGet->setMinimumSize(QSize(60, 30));
btnAPNCusGet->setProperty("ssType", "progManageTool");
connect(btnAPNCusGet, &QPushButton::clicked, this, [=] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetCurrentAPN");
json.insert("_type", "GetCurrentAPN");
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("GetCurrentAPN")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSingleGetReply
waitingDlg->success();
fdCus_Name->setText(json["carrier"].toString());
fdCus_apn->setText(json["apn"].toString());
fdCus_User->setText(json["user"].toString());
fdCus_pwd->setText(json["password"].toString());
fdCus_type->setText(json["type"].toString());
fdCus_server->setText(json["server"].toString());
fdCus_proxy->setText(json["proxy"].toString());
fdCus_port->setText(json["port"].toString());
fdCus_mmsc->setText(json["mmsc"].toString());
fdCus_mmsProxy->setText(json["mmsproxy"].toString());
fdCus_mmsPort->setText(json["mmsport"].toString());
});
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
2023-05-15 16:06:10 +08:00
auto cardId = card.id;
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(err.isEmpty()) {
err = json["apn"].toString();
auto user = json["user"].toString();
if(! user.isEmpty()) err += ", User:"+user+", Password:"+json["password"].toString();
}
gFdResInfo->append(cardId+" "+tr("GetCurrentAPN")+" "+err);
});
}
}
});
hhhh->addWidget(btnAPNCusGet);
grid->addLayout(hhhh, 5, 3);
hBox->addStretch();
vBox->addSpacing(20);
hBox = new HBox(vBox);
hBox->setContentsMargins(-1, 0, 10, -1);
label_10 = new QLabel;
hBox->addWidget(label_10);
fdFightModel = new SwitchControl;
fdFightModel->setMinimumSize(QSize(80, 35));
fdFightModel->setSliderColor(QColor(0, 0, 0),QColor(0, 160, 230));
fdFightModel->setBgColor(QColor(200,200,200),QColor(0,200,0));
fdFightModel->setTextColor(QColor(100,100,100),QColor(0, 160, 230));
fdFightModel->setText(tr("OFF"), tr("ON"));
connect(fdFightModel, &SwitchControl::checkedChanged, this, [=](bool checked) {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "ContrFlightMode");
json.insert("_type", "ContrFlightMode");
json.insert("state", checked);
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("ContrFlightMode")+" ...");
Def_CtrlReqPre
2023-05-11 11:47:00 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2023-04-18 14:14:46 +08:00
Def_CtrlSetReqAfter
});
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
2023-04-18 14:14:46 +08:00
Def_CtrlSetMulti(tr("ContrFlightMode"))
}
}
});
hBox->addWidget(fdFightModel);
btnFlightModelGet = new QPushButton;
btnFlightModelGet->setMinimumSize(QSize(0, 30));
btnFlightModelGet->setProperty("ssType", "progManageTool");
connect(btnFlightModelGet, &QPushButton::clicked, this, [this] {
2023-05-15 16:06:10 +08:00
if(gSelCards.isEmpty()) {
2025-05-06 18:28:05 +08:00
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
2023-04-18 14:14:46 +08:00
return;
}
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState");
2023-05-15 16:06:10 +08:00
if(gSelCards.count() == 1) {
2023-04-18 14:14:46 +08:00
auto waitingDlg = new WaitingDlg(this, tr("GetFlightModeState")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
fdFightModel->setCheckedStatus(json["result"].toBool());
fdFightModel->update();
});
} else {
2025-05-06 18:28:05 +08:00
for(auto &card : gSelCards) {
2023-05-15 16:06:10 +08:00
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card.id;
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(err.isEmpty()) err = json["result"].toBool() ? "true" : "false";
gFdResInfo->append(cardId+" "+tr("GetFlightModeState")+" "+err);
});
}
}
});
hBox->addWidget(btnFlightModelGet);
hBox->addStretch();
vBox->addStretch();
connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(isVisible()) init();
});
transUi();
}
void CtrlNetworkPanel::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
init();
}
void CtrlNetworkPanel::init() {
2023-05-15 16:06:10 +08:00
bool isSingle = gSelCards.count()==1;
2023-04-18 14:14:46 +08:00
btnScan->setEnabled(isSingle);
if(! isSingle) return;
2023-05-15 16:06:10 +08:00
auto card = gSelCards[0];
2023-04-18 14:14:46 +08:00
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet");
2023-05-15 16:06:10 +08:00
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [this, reply] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
if(json["dhcp"].toBool()) {
fdDhcp->setChecked(true);
gBoxSpecifyIp->setVisible(false);
} else {
fdSpecifyIp->setChecked(true);
gBoxSpecifyIp->setVisible(true);
}
fdIP->setText(json["ipAddr"].toString());
fdGateWay->setText(json["gateWay"].toString());
fdMask->setText(json["netMask"].toString());
fdDns->setText(json["dnsAddr"].toString());
});
2025-05-06 18:28:05 +08:00
json = JObj();
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList");
2025-05-06 18:28:05 +08:00
reply = NetReq("http://"+card.ip+":2016/settings").post(json);
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
auto wifis = json["wifiList"].toArray();
2025-05-06 18:28:05 +08:00
edWifiName->clear();
for(JValue &wifi : wifis) edWifiName->addItem(QIcon(":/res/signal-"+QString::number((wifi["signal"].toInt()+19)/20)+".png"), wifi["ssid"].toString());
2023-04-18 14:14:46 +08:00
{
2025-05-06 18:28:05 +08:00
JObj json;
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
if(isG) {
json.insert("_id", "GetWifiSwitchState");
json.insert("_type", "GetWifiSwitchState");
} else {
json.insert("_id", "IsPortableHotSpot");
json.insert("_type", "IsPortableHotSpot");
}
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
2025-05-06 18:28:05 +08:00
if(isG) {
fdIsWifi->setChecked(json["wifiEnable"].toBool());
fdIsAP->setChecked(json["apEnable"].toBool());
edWifiName->setCurrentText(json["wifiName"].toString());
edHotspotName->setText(json["hotSpotName"].toString());
edIs5G->setChecked(json["apBand"].toBool());
} else {
edWifiName->setCurrentText(json["wifi"].toString());
auto hotspots = json["hotSpots"].toString();
edHotspotName->setText(hotspots);
fdIsWifi->setChecked(hotspots.isEmpty());
fdIsAP->setChecked(! hotspots.isEmpty());
}
2023-04-18 14:14:46 +08:00
});
}
});
2025-05-06 18:28:05 +08:00
json = JObj();
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetSwitchSimData");
json.insert("_type", "GetSwitchSimData");
2023-05-15 16:06:10 +08:00
reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
2025-05-06 18:28:05 +08:00
auto enable = json["enable"].toBool();
fdEnableCellular->setChecked(enable);
fdMcc->setEnabled(enable);
fdCarrierName->setEnabled(enable);
2023-04-18 14:14:46 +08:00
});
2025-05-06 18:28:05 +08:00
json = JObj();
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetAPNList");
json.insert("_type", "GetAPNList");
2023-05-15 16:06:10 +08:00
reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
2025-05-06 18:28:05 +08:00
auto err = checkReplyForJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
fdMcc->clear();
fdMcc->addItem("");
auto apns = json["apns"].toArray();
2025-05-06 18:28:05 +08:00
for(QJsonValue apn : apns) {
auto mcc = apn["mcc"].toString();
2023-04-18 14:14:46 +08:00
for(int i=0; i<fdMcc->count(); i++) if(mcc==fdMcc->itemText(i)) {
auto var = fdMcc->itemData(i);
fdMcc->setItemData(i, QVariant());
((QJsonArray *)var.data())->append(apn);
fdMcc->setItemData(i, var);
goto end;
}
fdMcc->addItem(mcc, QJsonArray{apn});
end:;
}
});
2023-05-15 16:06:10 +08:00
getCurrentAPN(card.ip);
2023-04-18 14:14:46 +08:00
2025-05-06 18:28:05 +08:00
json = JObj();
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState");
2025-05-06 18:28:05 +08:00
reply = NetReq("http://"+card.ip+":2016/settings").post(json);
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
fdFightModel->setCheckedStatus(json["result"].toBool());
fdFightModel->update();
});
}
void CtrlNetworkPanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void CtrlNetworkPanel::transUi() {
lbLanCfg->setText(tr("Wire Enther(RJ45) Configuration"));
fdSpecifyIp->setText(tr("Specify IP"));
lbHotspotName->setText(tr("AP name"));
labelGateway->setText(tr("Gateway"));
lbWifiName->setText(tr("WiFi name"));
labelIpAddress->setText(tr("IP Address"));
2025-05-06 18:28:05 +08:00
lbHotspotPswd->setText(tr("Password"));
2023-04-18 14:14:46 +08:00
labelDnsAddress->setText(tr("DNS Address"));
labelMaskAddress->setText(tr("Subnet mask"));
2025-05-06 18:28:05 +08:00
lbWifiPswd->setText(tr("Password"));
2023-04-18 14:14:46 +08:00
btnScan->setText(tr("Scan"));
2025-05-06 18:28:05 +08:00
btnWiFiSet->setText(translate("","Set"));
btnHotspotSet->setText(translate("","Set"));
btnLanSet->setText(translate("","Set"));
btnWiFiGet->setText(translate("","Readback"));
btnLanGet->setText(translate("","Readback"));
fdIsWifi->setText(tr("Enable WiFi"));
fdIsAP->setText(tr("Enable AP"));
lbWifiCfg->setText(tr("WiFi Config"));
edHotspotPswd->setPlaceholderText(translate("","Input Password"));
edWifiPswd->setPlaceholderText(translate("","Input Password"));
edHotspotName->setPlaceholderText(tr("Input ap name"));
2023-04-18 14:14:46 +08:00
lbCellularConfig->setText(tr("Cellular Config"));
lbCheckStatusTip->setText(tr("Through the check status button"));
fdEnableCellular->setText(tr("Enable Cellular Data"));
groupApn->setTitle(tr("Set APN Info"));
label_2->setText(tr("Country ID(mcc):"));
label_3->setText(tr("Carrier Name"));
fdCus_apn->setPlaceholderText(tr("APN(Required)"));
2025-05-06 18:28:05 +08:00
btnFlightModelGet->setText(translate("","Readback"));
2023-04-18 14:14:46 +08:00
btnSIMStatusGet->setText(tr("Get cellular network status information"));
label_10->setText(tr("Flight Mode"));
lbCus_Name->setText(tr("Carrier Name"));
lbCus_User->setText(tr("User"));
lbCus_pwd->setText(tr("Password"));
lbCus_type->setText(tr("Type"));
lbCus_server->setText(tr("Server"));
lbCus_port->setText(tr("Port"));
lbCus_proxy->setText(tr("Proxy"));
lbCus_mmsPort->setText(tr("MMS Port"));
lbCus_mmsProxy->setText(tr("MMS Proxy"));
2025-05-06 18:28:05 +08:00
btnAPNCusSet->setText(translate("","Set"));
btnAPNCusGet->setText(translate("","Readback"));
2023-04-18 14:14:46 +08:00
}
void CtrlNetworkPanel::getCurrentAPN(QString &ip) {
2025-05-06 18:28:05 +08:00
JObj json;
2023-04-18 14:14:46 +08:00
json.insert("_id", "GetCurrentAPN");
json.insert("_type", "GetCurrentAPN");
2023-04-23 17:01:35 +08:00
auto reply = NetReq("http://"+ip+":2016/settings").timeout(120000).post(json);
2023-04-18 14:14:46 +08:00
connect(reply, &QNetworkReply::finished, this, [=] {
2025-05-06 18:28:05 +08:00
JValue json;
auto err = errStrWithJson(reply, &json);
2023-04-18 14:14:46 +08:00
if(! err.isEmpty()) return;
fdCus_Name->setText(json["carrier"].toString());
fdCus_apn->setText(json["apn"].toString());
fdCus_User->setText(json["user"].toString());
fdCus_pwd->setText(json["password"].toString());
fdCus_type->setText(json["type"].toString());
fdCus_server->setText(json["server"].toString());
fdCus_proxy->setText(json["proxy"].toString());
fdCus_port->setText(json["port"].toString());
fdCus_mmsc->setText(json["mmsc"].toString());
fdCus_mmsProxy->setText(json["mmsproxy"].toString());
fdCus_mmsPort->setText(json["mmsport"].toString());
});
}