qt/LedOK/device/ctrlnetworkpanel.cpp
2025-05-23 18:35:00 +08:00

1174 lines
50 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "ctrlnetworkpanel.h"
#include "gutil/qwaitingdlg.h"
#include "main.h"
#include "tools.h"
#include "devicepanel.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include <QJsonArray>
#include <QMessageBox>
#include <QStackedLayout>
#include <QGridLayout>
CtrlNetworkPanel::CtrlNetworkPanel() {
auto vBox = new VBox(this);
lbLanCfg = new QLabel;
auto ftTitle = lbLanCfg->font();
ftTitle.setPixelSize(16);
lbLanCfg->setFont(ftTitle);
lbLanCfg->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbLanCfg);
auto hBox = new HBox(vBox);
hBox->addStretch();
fdDhcp = new QRadioButton("DHCP");
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);
hhh->addWidget(labelIpAddress = new QLabel);
fdIP = new QLineEdit;
auto ft = fdIP->font();
ft.setFamilies({"Monaco", "Consolas", "Mono-space"});
fdIP->setFont(ft);
fdIP->setInputMask("000.000.000.000");
fdIP->setAlignment(Qt::AlignCenter);
fdIP->setFixedWidth(160);
hhh->addWidget(fdIP);
hhh = new HBox(vvv);
hhh->addWidget(labelMaskAddress = new QLabel);
fdMask = new QLineEdit;
fdMask->setFont(ft);
fdMask->setInputMask("000.000.000.000");
fdMask->setAlignment(Qt::AlignCenter);
fdMask->setFixedWidth(160);
hhh->addWidget(fdMask);
hhh = new HBox(vvv);
hhh->addWidget(labelGateway = new QLabel);
fdGateWay = new QLineEdit;
fdGateWay->setFont(ft);
fdGateWay->setInputMask("000.000.000.000");
fdGateWay->setAlignment(Qt::AlignCenter);
fdGateWay->setFixedWidth(160);
hhh->addWidget(fdGateWay);
hhh = new HBox(vvv);
hhh->addWidget(labelDnsAddress = new QLabel);
fdDns = new QLineEdit;
fdDns->setFont(ft);
fdDns->setInputMask("000.000.000.000");
fdDns->setAlignment(Qt::AlignCenter);
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] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
QString ip = fdIP->text();
QString mask = fdMask->text();
QString gateWay = fdGateWay->text();
QString dns = fdDns->text();
if(fdDhcp->isChecked()) {
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";
} else {
if(ip=="...") {
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
fdIP->setFocus();
return;
}
if(mask=="...") {
QMessageBox::warning(this, tr("Attention"), tr("Please input Mask address!"));
fdMask->setFocus();
return;
}
if(gateWay=="...") {
QMessageBox::warning(this, tr("Attention"), tr("Please input Gateway address!"));
fdGateWay->setFocus();
return;
}
if(dns=="...") {
QMessageBox::warning(this, tr("Attention"), tr("Please input DNS address!"));
fdDns->setFocus();
return;
}
}
JObj json;
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);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetEthernet"));
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
for(auto &card : gSelCards) {
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] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
JObj json;
json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet");
if(gSelCards.count() == 1) {
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 {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
JValue json;
auto err = errStrWithJson(reply, &json);
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);
lbWifiCfg = new QLabel;
lbWifiCfg->setFont(ftTitle);
lbWifiCfg->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbWifiCfg);
hBox = new HBox(vBox);
hBox->addStretch();
{
auto vvv = new VBox(hBox);
auto hBox = new HBox(vvv);
hBox->addStretch();
hBox->addWidget(fdIsWifi = new QCheckBox);
hBox->addStretch();
hBox = new HBox(vvv);
lbWifiName = new QLabel;
lbWifiName->setMinimumWidth(80);
lbWifiName->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
hBox->addWidget(lbWifiName);
edWifiName = new QComboBox;
edWifiName->setEditable(true);
edWifiName->setMinimumWidth(180);
edWifiName->setSizeAdjustPolicy(QComboBox::AdjustToContents);
hBox->addWidget(edWifiName);
btnScan = new QPushButton;
btnScan->setMinimumWidth(60);
btnScan->setProperty("ssType", "progManageTool");
connect(btnScan, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
QJsonObject json;
json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList");
if(gSelCards.count() == 1) {
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();
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);
});
}
});
hBox->addWidget(btnScan);
hBox->addStretch();
hBox = new HBox(vvv);
lbWifiPswd = new QLabel;
lbWifiPswd->setMinimumWidth(80);
lbWifiPswd->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
hBox->addWidget(lbWifiPswd);
edWifiPswd = new QLineEdit;
edWifiPswd->setFixedWidth(180);
edWifiPswd->setEchoMode(QLineEdit::PasswordEchoOnEdit);
hBox->addWidget(edWifiPswd);
hBox->addStretch();
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();
vvv->addStretch();
}
{
auto vvv = new VBox(hBox);
auto hBox = new HBox(vvv);
hBox->addStretch();
hBox->addWidget(fdIsAP = new QCheckBox);
hBox->addStretch();
hBox = new HBox(vvv);
lbHotspotName = new QLabel;
lbHotspotName->setMinimumWidth(80);
lbHotspotName->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
hBox->addWidget(lbHotspotName);
edHotspotName = new QLineEdit;
edHotspotName->setFixedWidth(180);
hBox->addWidget(edHotspotName);
hBox->addStretch();
hBox = new HBox(vvv);
lbHotspotPswd = new QLabel;
lbHotspotPswd->setMinimumWidth(80);
lbHotspotPswd->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
hBox->addWidget(lbHotspotPswd);
edHotspotPswd = new QLineEdit;
edHotspotPswd->setEchoMode(QLineEdit::PasswordEchoOnEdit);
edHotspotPswd->setFixedWidth(180);
hBox->addWidget(edHotspotPswd);
hBox->addStretch();
hBox = new HBox(vvv);
auto lll = new QLabel;
lll->setMinimumWidth(80);
hBox->addWidget(lll);
auto edIs2_4G = new QRadioButton("2.4G");
edIs2_4G->setChecked(true);
hBox->addWidget(edIs2_4G);
edIs5G = new QRadioButton("5G");
hBox->addWidget(edIs5G);
hBox->addStretch();
hBox = new HBox(vvv);
hBox->addStretch();
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());
if(gSelCards.count() == 1) {
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);
if(! err.isEmpty()) {
waitingDlg->close();
QMessageBox::critical(this, translate("","Error"), err);
return;
}
if(isAp) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
ConnReply(reply, waitingDlg) [=] {
Def_CtrlSetReqAfter
});
} else waitingDlg->success();
});
} else if(isAp) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
ConnReply(reply, waitingDlg) [=] {
Def_CtrlSetReqAfter
});
} else waitingDlg->success();
} else {
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"));
}
}
});
hBox->addWidget(btnHotspotSet);
hBox->addStretch();
vvv->addStretch();
}
hBox->addStretch();
fdIsWifi->setChecked(true);
hBox = new HBox(vBox);
hBox->addStretch();
btnWiFiGet = new QPushButton;
btnWiFiGet->setMinimumSize(60, 30);
btnWiFiGet->setProperty("ssType", "progManageTool");
connect(btnWiFiGet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
JObj json;
json.insert("_id", "IsPortableHotSpot");
json.insert("_type", "IsPortableHotSpot");
JObj jsonG;
jsonG.insert("_id", "GetWifiSwitchState");
jsonG.insert("_type", "GetWifiSwitchState");
if(gSelCards.count() == 1) {
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, [=] {
Def_CtrlSingleGetReply
waitingDlg->success();
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());
}
});
} else {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
auto cardId = card.id;
auto isG = card.id.startsWith("g", Qt::CaseInsensitive);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
if(err.isEmpty()) {
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;
}
}
gFdResInfo->append(cardId+" "+tr("Get AP or WiFi")+" "+err);
});
}
}
});
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;
lbCellularConfig->setFont(ftTitle);
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);
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
QJsonObject json;
json.insert("_id", "SetSwitchSimData");
json.insert("_type", "SetSwitchSimData");
json.insert("enable", checked);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetSwitchSimData")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetSwitchSimData"))
}
}
});
hBox->addWidget(fdEnableCellular);
btnSIMStatusGet = new QPushButton;
btnSIMStatusGet->setMinimumHeight(30);
btnSIMStatusGet->setProperty("ssType", "progManageTool");
connect(btnSIMStatusGet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
QJsonObject json;
json.insert("_id", "GetSIMStatus");
json.insert("_type", "GetSIMStatus");
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetSIMStatus")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->close();
QString str4GStatus = tr("Status")+":";
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";
}
QMessageBox::information(this, translate("","Tip"), str4GStatus);
});
}
});
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();
for(QJsonValue apnInfo : apnInfos) fdCarrierName->addItem(apnInfo["carrier"].toString(), apnInfo);
});
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, [=] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
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());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetAPN")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
for(auto &card : gSelCards) {
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, [=] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
JObj json;
json.insert("_id", "GetCurrentAPN");
json.insert("_type", "GetCurrentAPN");
if(gSelCards.count() == 1) {
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 {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").post(json);
auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
JValue json;
auto err = errStrWithJson(reply, &json);
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) {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
JObj json;
json.insert("_id", "ContrFlightMode");
json.insert("_type", "ContrFlightMode");
json.insert("state", checked);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ContrFlightMode")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
for(auto &card : gSelCards) {
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] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, translate("","Tip"), translate("","Please select screen first"));
return;
}
JObj json;
json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState");
if(gSelCards.count() == 1) {
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 {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
JValue json;
auto err = errStrWithJson(reply, &json);
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() {
bool isSingle = gSelCards.count()==1;
btnScan->setEnabled(isSingle);
if(! isSingle) return;
auto card = gSelCards[0];
JObj json;
json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet");
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
JValue json;
auto err = errStrWithJson(reply, &json);
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());
});
json = JObj();
json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList");
reply = NetReq("http://"+card.ip+":2016/settings").post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
if(! err.isEmpty()) return;
auto wifis = json["wifiList"].toArray();
edWifiName->clear();
for(JValue &wifi : wifis) edWifiName->addItem(QIcon(":/res/signal-"+QString::number((wifi["signal"].toInt()+19)/20)+".png"), wifi["ssid"].toString());
{
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);
if(! err.isEmpty()) return;
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());
}
});
}
});
json = JObj();
json.insert("_id", "GetSwitchSimData");
json.insert("_type", "GetSwitchSimData");
reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
if(! err.isEmpty()) return;
auto enable = json["enable"].toBool();
fdEnableCellular->setChecked(enable);
fdMcc->setEnabled(enable);
fdCarrierName->setEnabled(enable);
});
json = JObj();
json.insert("_id", "GetAPNList");
json.insert("_type", "GetAPNList");
reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
auto err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
fdMcc->clear();
fdMcc->addItem("");
auto apns = json["apns"].toArray();
for(QJsonValue apn : apns) {
auto mcc = apn["mcc"].toString();
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:;
}
});
getCurrentAPN(card.ip);
json = JObj();
json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState");
reply = NetReq("http://"+card.ip+":2016/settings").post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
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"));
lbHotspotPswd->setText(tr("Password"));
labelDnsAddress->setText(tr("DNS Address"));
labelMaskAddress->setText(tr("Subnet mask"));
lbWifiPswd->setText(tr("Password"));
btnScan->setText(tr("Scan"));
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"));
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)"));
btnFlightModelGet->setText(translate("","Readback"));
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"));
btnAPNCusSet->setText(translate("","Set"));
btnAPNCusGet->setText(translate("","Readback"));
}
void CtrlNetworkPanel::getCurrentAPN(QString &ip) {
JObj json;
json.insert("_id", "GetCurrentAPN");
json.insert("_type", "GetCurrentAPN");
auto reply = NetReq("http://"+ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
auto err = errStrWithJson(reply, &json);
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());
});
}