This commit is contained in:
gangphon 2023-04-23 17:01:35 +08:00
parent 7f44fd1ca5
commit fed2665a90
15 changed files with 169 additions and 210 deletions

View File

@ -4,12 +4,21 @@
#include "basedlg.h"
#include "base/customprogressindicator.h"
#include <QLabel>
#include <QNetworkReply>
class WaitingDlg : public BaseDlg {
Q_OBJECT
public:
explicit WaitingDlg(QWidget *parent = nullptr, QString text = 0, QString sucText = 0);
inline void connAbort(QNetworkReply *reply) {
connect(this, &WaitingDlg::rejected, reply, [reply] {
reply->blockSignals(true);
reply->abort();
reply->blockSignals(false);
reply->deleteLater();
});
}
QPushButton *btnAbort;
QLabel *fdText;
QString sucText;

View File

@ -87,13 +87,12 @@ ControlPowerWidget::ControlPowerWidget(QWidget *parent, QList<LedCard *> *list)
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) err = json["on"].toBool() ? tr("On") : tr("Off");
gFdResInfo->append(cardId+" "+tr("IsScreenOn")+" "+err);
gFdResInfo->append(card->m_strCardId+" "+tr("IsScreenOn")+" "+err);
});
}
}
@ -129,7 +128,7 @@ void ControlPowerWidget::init() {
QJsonObject json;
json.insert("_id", "IsScreenOn");
json.insert("_type", "IsScreenOn");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -87,7 +87,7 @@ ControlVolumeWidget::ControlVolumeWidget(QWidget *parent,QList<LedCard *> *list)
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -129,7 +129,7 @@ void ControlVolumeWidget::init() {
QJsonObject json;
json.insert("_id", "GetVolume");
json.insert("_type", "GetVolume");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -387,7 +387,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -532,13 +532,8 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
auto waitingDlg = new WaitingDlg(this, tr("Getting Log")+" ...");
waitingDlg->show();
auto card = gSelCards->at(0);
auto reply = Tools::netManager().get(netReq("http://"+card->m_strCardIp+":2016/download?file=logs"));
connect(waitingDlg, &WaitingDlg::rejected, reply, [reply] {
reply->blockSignals(true);
reply->abort();
reply->blockSignals(false);
reply->deleteLater();
});
auto reply = NetReq("http://"+card->m_strCardIp+":2016/download?file=logs").timeout(120000).get();
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] {
waitingDlg->close();
QString err = checkReply(reply);
@ -546,7 +541,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
QMessageBox::critical(gMainWin, tr("Error"), err);
return;
}
QString logFile = QApplication::applicationDirPath()+"/log_"+card->m_strCardId+".txt";
QString logFile = QApplication::applicationDirPath()+"/card-log.txt";
QFile file(logFile);
if(! file.open(QIODevice::WriteOnly)) {
QMessageBox::critical(gMainWin, tr("Error"), "Open for Write Fail");
@ -613,7 +608,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -681,7 +676,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -757,12 +752,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
waitingDlg->show();
NetReq req("http://"+gSelCards->at(0)->m_strCardIp+":2016/upload?type=update_display");
auto reply = req.timeout(120000).type("multipart/form-data; boundary="+Boundary).post(data);
connect(waitingDlg, &WaitingDlg::rejected, reply, [reply] {
reply->blockSignals(true);
reply->abort();
reply->blockSignals(false);
reply->deleteLater();
});
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] {
QString err = checkReply(reply);
if(! err.isEmpty()) {
@ -836,7 +826,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
@ -916,7 +906,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
@ -1049,13 +1039,8 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("InvokeTaxiAppFunction"));
waitingDlg->show();
auto reply = Tools::netManager().post(reqForJson("http://"+gSelCards->at(0)->m_strCardIp+":3000"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
connect(waitingDlg, &WaitingDlg::rejected, reply, [reply] {
reply->blockSignals(true);
reply->abort();
reply->blockSignals(false);
reply->deleteLater();
});
auto reply = NetReq("http://"+gSelCards->at(0)->m_strCardIp+":3000").timeout(120000).post(json);
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] {
QString err = checkReply(reply);
if(! err.isEmpty()) {
@ -1080,7 +1065,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":3000"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":3000").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QString err = checkReply(reply);
@ -1165,7 +1150,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -1240,7 +1225,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -1309,7 +1294,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -1418,12 +1403,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
waitingDlg->show();
NetReq req("http://"+gSelCards->at(0)->m_strCardIp+":2016/upload?type=mcu_update");
auto reply = req.timeout(120000).type("multipart/form-data; boundary="+Boundary).post(data);
connect(waitingDlg, &WaitingDlg::rejected, reply, [reply] {
reply->blockSignals(true);
reply->abort();
reply->blockSignals(false);
reply->deleteLater();
});
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] {
QString err = checkReply(reply);
if(! err.isEmpty()) {
@ -1467,7 +1447,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -1779,7 +1759,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -1925,7 +1905,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId, fdTraficProtocol] {
QJsonDocument json;
@ -2013,7 +1993,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
@ -2081,7 +2061,7 @@ void CtrlAdvancedPanel::init() {
QJsonObject json;
json.insert("_id", "GetAllScreenSizeM80");
json.insert("_type", "GetAllScreenSizeM80");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -2103,7 +2083,7 @@ void CtrlAdvancedPanel::init() {
QJsonObject json;
json.insert("_id", "GetScreenSize");
json.insert("_type", "GetScreenSize");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -2115,7 +2095,7 @@ void CtrlAdvancedPanel::init() {
json = QJsonObject();
json.insert("_id", "GetCardAlias");
json.insert("_type", "GetCardAlias");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -2126,7 +2106,7 @@ void CtrlAdvancedPanel::init() {
json = QJsonObject();
json.insert("_id", "GetOnlineAddr");
json.insert("_type", "GetOnlineAddr");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -2138,7 +2118,7 @@ void CtrlAdvancedPanel::init() {
json = QJsonObject();
json.insert("_id", "GetRealtimeServer");
json.insert("_type", "GetRealtimeServer");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -2245,66 +2225,6 @@ void CtrlAdvancedPanel::transUi() {
btnTraficGet->setText(tr("Get"));
}
//void CtrlAdvancedPanel::onUpload(QString file) {
// if(file.length() < 3) return;
// QFile qFile(file);
// if(! qFile.exists()) return;
// bool isApk = ! file.endsWith(".rpd", Qt::CaseInsensitive);
// auto BOUNDARY = QUuid::createUuid().toByteArray();
// QByteArray data;
// data.append("--").append(BOUNDARY).append("\r\n");
// data.append("Content-Disposition: form-data;name=\"username\"\r\n\r\n");
// data.append("10005\r\n");
// //上传文件的头部
// data.append("--").append(BOUNDARY).append("\r\n");
// QFileInfo fileinfo(file);
// auto name = fileinfo.fileName().toUtf8();
// data.append("Content-Disposition: form-data;name=\"").append(name).append("\";filename=\"").append(name).append("\"\r\n\r\n");
// //上传文件内容
// if(! qFile.open(QIODevice::ReadOnly)) return;
// data.append(qFile.readAll());
// qFile.close();
// data.append("\r\n");
// data.append("--").append(BOUNDARY).append("\r\n");
// auto waitingDlg = new WaitingDlg(this, tr("Uploading")+" ...");
// waitingDlg->show();
// auto request = netReq("http://"+gSelCards->at(0)->m_strCardIp+":2016/upload?type="+(isApk ? "software":"hardware"), "multipart/form-data;boundary="+BOUNDARY, 0);
// auto reply = Tools::netManager().post(request, data);
// connect(waitingDlg, &WaitingDlg::rejected, reply, [reply] {
// reply->blockSignals(true);
// reply->abort();
// reply->blockSignals(false);
// reply->deleteLater();
// });
// connect(reply, &QNetworkReply::uploadProgress, this, [=](qint64 bytesSent, qint64 bytesTotal) {
// if(bytesTotal<=0) return;
// waitingDlg->fdText->setText(tr("Uploading")+" "+QString::number(bytesSent*100/bytesTotal)+"%");
// });
// connect(reply, &QNetworkReply::finished, this, [=] {
// QString err = checkReply(reply);
// if(! err.isEmpty()) {
// waitingDlg->close();
// QMessageBox::critical(gMainWin, tr("Error"), err);
// return;
// }
// waitingDlg->fdText->setText(tr("Installing")+" ...");
// QJsonObject json;
// if(isApk) {
// json.insert("_id", "UpgradeSoftware");
// json.insert("_type", "UpgradeSoftware");
// json.insert("fileName", QFileInfo(file).fileName());
// json.insert("isCustom", true);
// } else {
// json.insert("_id", "SynchronousHardwareVersion");
// json.insert("_type", "SynchronousHardwareVersion");
// }
// auto reply = Tools::netManager().post(reqForJson("http://"+gSelCards->at(0)->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
// connect(reply, &QNetworkReply::finished, this, [=] {
// Def_CtrlSetReqAfter
// });
// });
//}
void messageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
auto cur = QDateTime::currentDateTime();
QFile file("D:/LedOK-advanced-"+cur.toString("yy-MM-dd")+".log");

View File

@ -128,7 +128,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -218,7 +218,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
auto brightLevel = card->BrightnessLevel;
connect(reply, &QNetworkReply::finished, this, [reply, cardId, brightLevel] {
@ -420,7 +420,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -525,7 +525,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -809,7 +809,7 @@ void CtrlBrightPanel::init() {
QJsonObject json;
json.insert("_id", "GetAutoBrightnessTask");
json.insert("_type", "GetAutoBrightnessTask");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -823,7 +823,7 @@ void CtrlBrightPanel::init() {
json = QJsonObject();
json.insert("_id", "GetBrightnessSensitivity");
json.insert("_type", "GetBrightnessSensitivity");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -838,7 +838,7 @@ void CtrlBrightPanel::init() {
json = QJsonObject();
json.insert("_id", "GetMinBrightness");
json.insert("_type", "GetMinBrightness");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -851,7 +851,7 @@ void CtrlBrightPanel::init() {
json = QJsonObject();
json.insert("_id", "GetBrightness");
json.insert("_type", "GetBrightness");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -112,7 +112,7 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -322,7 +322,7 @@ void CtrlHdmiPanel::init() {
QJsonObject json;
json.insert("_id", "IsSync");
json.insert("_type", "IsSync");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -3,6 +3,7 @@
#include "globaldefine.h"
#include "tools.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include <QJsonArray>
#include <QMessageBox>
#include <QStackedLayout>
@ -184,7 +185,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -324,39 +325,57 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController"));
return;
}
if(fdIsWifi->isChecked()) {
auto isWifi = fdIsWifi->isChecked();
QJsonObject json;
json.insert("_id", "ConfigurationWiFi");
json.insert("_type", "ConfigurationWiFi");
json.insert("ssid", fdWifiName->currentText());
json.insert("password", fdWifiPassword->text());
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ConfigurationWiFi")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, *gSelCards) {
Def_CtrlSetMulti(tr("ConfigurationWiFi"))
}
}
json.insert("_id", "SetSwitchWiFi");
json.insert("_type", "SetSwitchWiFi");
json.insert("enable", isWifi);
QString tip;
QJsonObject json2;
if(isWifi) {
tip = tr("ConfigurationWiFi");
json2.insert("_id", "ConfigurationWiFi");
json2.insert("_type", "ConfigurationWiFi");
json2.insert("ssid", fdWifiName->currentText());
json2.insert("password", fdWifiPassword->text());
} else if(fdIsHotspot->isChecked()) {
QJsonObject json;
json.insert("_id", "ConfigurationHotSpot");
json.insert("_type", "ConfigurationHotSpot");
json.insert("apName", fdHotspotName->text());
json.insert("password", fdHotspotPassword->text());
tip = tr("ConfigurationHotSpot");
json2.insert("_id", "ConfigurationHotSpot");
json2.insert("_type", "ConfigurationHotSpot");
json2.insert("apName", fdHotspotName->text());
json2.insert("password", fdHotspotPassword->text());
}
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ConfigurationHotSpot")+" ...");
auto waitingDlg = new WaitingDlg(this, tip+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] {
connect(reply, &QNetworkReply::finished, card, [=] {
QString err = checkReplyForJson(reply);
if(! err.isEmpty()) {
waitingDlg->close();
QMessageBox::critical(gMainWin, tr("Error"), err);
return;
}
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json2);
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, card, [reply, waitingDlg] {
Def_CtrlSetReqAfter
});
});
} else {
foreach(auto card, *gSelCards) {
Def_CtrlSetMulti(tr("ConfigurationHotSpot"))
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QString err = checkReplyForJson(reply);
if(! err.isEmpty()) {
gFdResInfo->append(card->m_strCardId+" "+tip+" "+err);
return;
}
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json2);
connect(reply, &QNetworkReply::finished, card, [=] {
QString err = checkReplyForJson(reply);
gFdResInfo->append(card->m_strCardId+" "+tip+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));
});
});
}
}
});
@ -388,7 +407,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -709,7 +728,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -790,7 +809,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -826,7 +845,7 @@ void CtrlNetworkPanel::init() {
QJsonObject json;
json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -848,7 +867,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject();
json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -860,7 +879,7 @@ void CtrlNetworkPanel::init() {
QJsonObject json;
json.insert("_id", "IsPortableHotSpot");
json.insert("_type", "IsPortableHotSpot");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -878,7 +897,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject();
json.insert("_id", "GetSwitchSimData");
json.insert("_type", "GetSwitchSimData");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -892,7 +911,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject();
json.insert("_id", "GetAPNList");
json.insert("_type", "GetAPNList");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -919,7 +938,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject();
json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -985,7 +1004,7 @@ void CtrlNetworkPanel::getCurrentAPN(QString &ip) {
QJsonObject json;
json.insert("_id", "GetCurrentAPN");
json.insert("_type", "GetCurrentAPN");
auto reply = Tools::netManager().post(reqForJson("http://"+ip+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -106,7 +106,7 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -173,7 +173,7 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -216,7 +216,7 @@ void CtrlPwdPanel::init() {
QJsonObject json;
json.insert("_id", "HasControllerPassword");
json.insert("_type", "HasControllerPassword");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -179,7 +179,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -257,7 +257,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -415,7 +415,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -501,7 +501,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card, isMaster] {
QString err = checkReplyForJson(reply);
gFdResInfo->append(card->m_strCardId+" "+(isMaster ? tr("MasterSwitch ") : tr("SlaveSwitch "))+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));
@ -533,7 +533,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -614,7 +614,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
});
} else {
foreach(auto card, *gSelCards) {
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
@ -680,7 +680,7 @@ void CtrlVerifyClockPanel::init() {
QJsonObject json;
json.insert("_id", "GetingSyncMethod");
json.insert("_type", "GetingSyncMethod");
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -691,7 +691,7 @@ void CtrlVerifyClockPanel::init() {
json = QJsonObject();
json.insert("_id", "GetTimezone");
json.insert("_type", "GetTimezone");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -702,7 +702,7 @@ void CtrlVerifyClockPanel::init() {
json = QJsonObject();
json.insert("_id", "GetLanguage");
json.insert("_type", "GetLanguage");
reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -39,7 +39,7 @@ void wUpgradeApkItem::OnCheckFpgaVersions() {
QJsonObject json;
json.insert("_id", "CheckHardwareVersions");
json.insert("_type", "CheckHardwareVersions");
auto reply = Tools::netManager().post(reqForJson("http://"+mCard->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, this] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -59,7 +59,7 @@ void wUpgradeApkItem::OnCheckSoftVersions() {
QJsonObject json;
json.insert("_id", "CheckSoftVersions");
json.insert("_type", "CheckSoftVersions");
auto reply = Tools::netManager().post(reqForJson("http://"+mCard->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, this] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
@ -88,7 +88,7 @@ void wUpgradeApkItem::onVerifyLockPassword() {
json.insert("_id", "VerifyPassword");
json.insert("_type", "VerifyPassword");
json.insert("pwd", pwd);
auto reply = Tools::netManager().post(reqForJson("http://"+mCard->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, this] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);

View File

@ -380,7 +380,7 @@ void DevicePanel::addLedCard(LedCard *card) {
json.insert("_id", "SyncTime");
json.insert("_type", "SyncTime");
json.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch());
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
}
void DevicePanel::clearUdpHeartbeat(LedCard *p) {

View File

@ -11,13 +11,6 @@ bool gTextAntialiasing = false;
bool gShowLoraScreen = false;
bool gWidthSplit = false;
QNetworkRequest netReq(const QString &url, const QByteArray &contentType, int timeout) {
QNetworkRequest request{url};
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
if(timeout) request.setTransferTimeout(timeout);
if(! contentType.isEmpty()) request.setRawHeader("Content-Type", contentType);
return request;
}
QString replyErr(QNetworkReply *reply) {
reply->deleteLater();
auto error = reply->error();

View File

@ -1,5 +1,6 @@
#ifndef GLOBALDEFINE_H
#define GLOBALDEFINE_H
#include "gutil/qnetwork.h"
#include <QString>
#include <QJsonValue>
#include <QJsonObject>
@ -171,10 +172,6 @@ enum _ENUM_CONTRL_WIDGET {
Setting_End,
};
QNetworkRequest netReq(const QString &url, const QByteArray & = QByteArray(), int = QNetworkRequest::DefaultTransferTimeoutConstant);
inline QNetworkRequest reqForJson(const QString &url, int timeout = QNetworkRequest::DefaultTransferTimeoutConstant) {
return netReq(url, "application/json", timeout);
}
QString replyErr(QNetworkReply *);
QString checkReply(QNetworkReply *, QJsonDocument * = 0);
QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0);
@ -182,13 +179,8 @@ QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0
#define Def_CtrlReqPre \
waitingDlg->show();\
auto card = gSelCards->at(0);\
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));\
connect(waitingDlg, &WaitingDlg::rejected, reply, [reply] {\
reply->blockSignals(true);\
reply->abort();\
reply->blockSignals(false);\
reply->deleteLater();\
});
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);\
waitingDlg->connAbort(reply);
#define Def_CtrlSetReqAfter \
QString err = checkReplyForJson(reply);\
@ -209,7 +201,7 @@ QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0
}
#define Def_CtrlSetMulti(tip) \
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));\
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);\
connect(reply, &QNetworkReply::finished, card, [=] {\
QString err = checkReplyForJson(reply);\
gFdResInfo->append(card->m_strCardId+" "+tip+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));\

View File

@ -6,6 +6,16 @@
#include <QTableWidget>
#include <QHeaderView>
#define MainMust \
#if(QT_VERSION_MAJOR > 5) \
QImageReader::setAllocationLimit(0);\
#else\
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);\
#endif
extern const int AlignRight;
inline int setCurrentData(QComboBox *combo, const QVariant &data) {
@ -259,6 +269,12 @@ public:
obj->setFont(font);
return *this;
}
inline Wrp& font(int size){
auto font = obj->font();
font.setPixelSize(size);
obj->setFont(font);
return *this;
}
inline Wrp& width(int w){
obj->setFixedWidth(w);

View File

@ -12,10 +12,16 @@ QNetworkAccessManager &netAccess();
class NetReq : public QNetworkRequest {
public:
NetReq();
explicit NetReq(const QString &url) : QNetworkRequest{url}{};
explicit NetReq(const QUrl &url) : QNetworkRequest{url}{};
NetReq(const QNetworkRequest &other) : QNetworkRequest{other}{};
NetReq() {init();};
explicit NetReq(const QString &url) : QNetworkRequest{url} {init();};
explicit NetReq(const QUrl &url) : QNetworkRequest{url} {init();};
NetReq(const QNetworkRequest &other) : QNetworkRequest{other} {init();};
inline void init() {
#if(QT_VERSION_MAJOR < 6)
setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
#endif
}
inline NetReq &type(const QByteArray &value) {
setRawHeader("Content-Type", value);
@ -29,10 +35,6 @@ public:
setTransferTimeout(timeout);
return *this;
}
inline NetReq &v5() {
setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
return *this;
}
inline QNetworkReply *get() {
return netAccess().get(*this);
@ -40,13 +42,15 @@ public:
inline QNetworkReply *post(const QByteArray &data) {
return netAccess().post(*this, data);
}
inline QNetworkReply *post(const QJsonObject &json) {
inline QNetworkReply *post(const QJsonDocument &json) {
setRawHeader("Content-Type", "application/json");
return netAccess().post(*this, QJsonDocument{json}.toJson(QJsonDocument::Compact));
return netAccess().post(*this, json.toJson(QJsonDocument::Compact));
}
inline QNetworkReply *post(const QJsonObject &json) {
return post(QJsonDocument{json});
}
inline QNetworkReply *post(const QJsonArray &json) {
setRawHeader("Content-Type", "application/json");
return netAccess().post(*this, QJsonDocument{json}.toJson(QJsonDocument::Compact));
return post(QJsonDocument{json});
}
inline QNetworkReply *post(QHttpMultiPart *multiPart) {
return netAccess().post(*this, multiPart);
@ -56,6 +60,13 @@ public:
QString errStr(QNetworkReply *);
QString errStrWithData(QNetworkReply *, QJsonDocument * = 0);
inline void abortSilence(QNetworkReply *reply) {
reply->blockSignals(true);
reply->abort();
reply->blockSignals(false);
reply->deleteLater();
}
const char* socketErrKey(int value);
class TcpSocket : public QTcpSocket {