From fed2665a90b46715b9cbbcb4dc9d2e18dce5fab3 Mon Sep 17 00:00:00 2001 From: gangphon Date: Sun, 23 Apr 2023 17:01:35 +0800 Subject: [PATCH] ledok --- LedOK/base/waitingdlg.h | 9 ++ LedOK/device/controlpowerwidget.cpp | 9 +- LedOK/device/controlvolumewidget.cpp | 4 +- LedOK/device/ctrladvancedpanel.cpp | 130 +++++--------------------- LedOK/device/ctrlbrightpanel.cpp | 16 ++-- LedOK/device/ctrlhdmipanel.cpp | 4 +- LedOK/device/ctrlnetworkpanel.cpp | 101 ++++++++++++-------- LedOK/device/ctrlpwdpanel.cpp | 6 +- LedOK/device/ctrlverifyclockpanel.cpp | 18 ++-- LedOK/device/wupgradeapkitem.cpp | 6 +- LedOK/devicepanel.cpp | 2 +- LedOK/globaldefine.cpp | 7 -- LedOK/globaldefine.h | 16 +--- LedOK/gutil/qgui.h | 16 ++++ LedOK/gutil/qnetwork.h | 35 ++++--- 15 files changed, 169 insertions(+), 210 deletions(-) diff --git a/LedOK/base/waitingdlg.h b/LedOK/base/waitingdlg.h index cccab19..32453d8 100644 --- a/LedOK/base/waitingdlg.h +++ b/LedOK/base/waitingdlg.h @@ -4,12 +4,21 @@ #include "basedlg.h" #include "base/customprogressindicator.h" #include +#include 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; diff --git a/LedOK/device/controlpowerwidget.cpp b/LedOK/device/controlpowerwidget.cpp index f2cf965..f1e30b0 100644 --- a/LedOK/device/controlpowerwidget.cpp +++ b/LedOK/device/controlpowerwidget.cpp @@ -87,13 +87,12 @@ ControlPowerWidget::ControlPowerWidget(QWidget *parent, QList *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); diff --git a/LedOK/device/controlvolumewidget.cpp b/LedOK/device/controlvolumewidget.cpp index 66a8baf..360bed8 100644 --- a/LedOK/device/controlvolumewidget.cpp +++ b/LedOK/device/controlvolumewidget.cpp @@ -87,7 +87,7 @@ ControlVolumeWidget::ControlVolumeWidget(QWidget *parent,QList *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); diff --git a/LedOK/device/ctrladvancedpanel.cpp b/LedOK/device/ctrladvancedpanel.cpp index 675437c..49c5d2d 100644 --- a/LedOK/device/ctrladvancedpanel.cpp +++ b/LedOK/device/ctrladvancedpanel.cpp @@ -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"); diff --git a/LedOK/device/ctrlbrightpanel.cpp b/LedOK/device/ctrlbrightpanel.cpp index e687f1c..cae39f7 100644 --- a/LedOK/device/ctrlbrightpanel.cpp +++ b/LedOK/device/ctrlbrightpanel.cpp @@ -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); diff --git a/LedOK/device/ctrlhdmipanel.cpp b/LedOK/device/ctrlhdmipanel.cpp index 1d05750..518420a 100644 --- a/LedOK/device/ctrlhdmipanel.cpp +++ b/LedOK/device/ctrlhdmipanel.cpp @@ -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); diff --git a/LedOK/device/ctrlnetworkpanel.cpp b/LedOK/device/ctrlnetworkpanel.cpp index ea21778..c60ade4 100644 --- a/LedOK/device/ctrlnetworkpanel.cpp +++ b/LedOK/device/ctrlnetworkpanel.cpp @@ -3,6 +3,7 @@ #include "globaldefine.h" #include "tools.h" #include "gutil/qgui.h" +#include "gutil/qnetwork.h" #include #include #include @@ -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()) { - 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")) - } - } + auto isWifi = fdIsWifi->isChecked(); + QJsonObject json; + 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()); - if(gSelCards->count() == 1) { - auto waitingDlg = new WaitingDlg(this, tr("ConfigurationHotSpot")+" ..."); - Def_CtrlReqPre - connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { + 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, tip+" ..."); + Def_CtrlReqPre + 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")) - } + }); + } else { + foreach(auto card, *gSelCards) { + 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); diff --git a/LedOK/device/ctrlpwdpanel.cpp b/LedOK/device/ctrlpwdpanel.cpp index 6ea7bff..0d70935 100644 --- a/LedOK/device/ctrlpwdpanel.cpp +++ b/LedOK/device/ctrlpwdpanel.cpp @@ -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); diff --git a/LedOK/device/ctrlverifyclockpanel.cpp b/LedOK/device/ctrlverifyclockpanel.cpp index 49f74b5..b11f15c 100644 --- a/LedOK/device/ctrlverifyclockpanel.cpp +++ b/LedOK/device/ctrlverifyclockpanel.cpp @@ -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); diff --git a/LedOK/device/wupgradeapkitem.cpp b/LedOK/device/wupgradeapkitem.cpp index 21141bd..c1f2a01 100644 --- a/LedOK/device/wupgradeapkitem.cpp +++ b/LedOK/device/wupgradeapkitem.cpp @@ -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); diff --git a/LedOK/devicepanel.cpp b/LedOK/devicepanel.cpp index b52934c..59e0a57 100644 --- a/LedOK/devicepanel.cpp +++ b/LedOK/devicepanel.cpp @@ -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) { diff --git a/LedOK/globaldefine.cpp b/LedOK/globaldefine.cpp index e1b35ce..70f4a48 100644 --- a/LedOK/globaldefine.cpp +++ b/LedOK/globaldefine.cpp @@ -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(); diff --git a/LedOK/globaldefine.h b/LedOK/globaldefine.h index 03cd520..05fea9c 100644 --- a/LedOK/globaldefine.h +++ b/LedOK/globaldefine.h @@ -1,5 +1,6 @@ #ifndef GLOBALDEFINE_H #define GLOBALDEFINE_H +#include "gutil/qnetwork.h" #include #include #include @@ -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));\ diff --git a/LedOK/gutil/qgui.h b/LedOK/gutil/qgui.h index 59b56da..4c1efe2 100644 --- a/LedOK/gutil/qgui.h +++ b/LedOK/gutil/qgui.h @@ -6,6 +6,16 @@ #include #include +#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); diff --git a/LedOK/gutil/qnetwork.h b/LedOK/gutil/qnetwork.h index 8b1fe86..0bc2b6d 100644 --- a/LedOK/gutil/qnetwork.h +++ b/LedOK/gutil/qnetwork.h @@ -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 {