ledok
This commit is contained in:
parent
2cfa0cc514
commit
9b767de1d0
|
@ -274,7 +274,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
|
|||
json.insert("packageName", strApkName);
|
||||
auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||||
connect(reply, &QNetworkReply::finished, this, [reply, item, strApkName] {
|
||||
QString err = errStrWithData(reply);
|
||||
QString err = checkReplyForJson(reply, "error");
|
||||
if(! err.isEmpty()) {
|
||||
item->setResult(tr("Uninstall error")+": "+err, Qt::red);
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "globaldefine.h"
|
||||
#include "devicepanel.h"
|
||||
#include "deviceitem.h"
|
||||
#include "gutil/qnetwork.h"
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QCoreApplication>
|
||||
|
@ -24,25 +25,8 @@ DeviceItem *findItem(QString id) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
QString replyErr(QNetworkReply *reply) {
|
||||
reply->deleteLater();
|
||||
auto error = reply->error();
|
||||
if(error != QNetworkReply::NoError) {
|
||||
auto errStr = reply->errorString();
|
||||
if(error!=QNetworkReply::InternalServerError || ! errStr.endsWith("replied: Unknown")) {
|
||||
if(error==QNetworkReply::OperationCanceledError) {
|
||||
error = QNetworkReply::TimeoutError;
|
||||
errStr = QCoreApplication::translate("Def","Connection Timeout");
|
||||
}
|
||||
return QString(QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(error))+" ("+QString::number(error)+") "+errStr;
|
||||
}
|
||||
}
|
||||
auto status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if(status != 200) return QString::number(status)+" "+reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
|
||||
return "";
|
||||
}
|
||||
QString checkReply(QNetworkReply *reply, QJsonDocument *outJson) {
|
||||
auto err = replyErr(reply);
|
||||
auto err = errStr(reply);
|
||||
if(! err.isEmpty()) {
|
||||
auto data = reply->readAll();
|
||||
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
|
||||
|
@ -57,7 +41,7 @@ QString checkReply(QNetworkReply *reply, QJsonDocument *outJson) {
|
|||
return "";
|
||||
}
|
||||
QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *outJson, QByteArray *outData) {
|
||||
auto err = replyErr(reply);
|
||||
auto err = errStr(reply);
|
||||
auto data = reply->readAll();
|
||||
if(outData) *outData = data;
|
||||
if(! err.isEmpty()) {
|
||||
|
@ -71,6 +55,22 @@ QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *outJson, QByteArr
|
|||
if(outJson) outJson->swap(json);
|
||||
return "";
|
||||
}
|
||||
QString checkReplyForJson(QNetworkReply *reply, QString errField) {
|
||||
auto err = errStr(reply);
|
||||
auto data = reply->readAll();
|
||||
if(! err.isEmpty()) {
|
||||
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
|
||||
return err;
|
||||
}
|
||||
QJsonParseError jsonErr;
|
||||
QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr);
|
||||
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
|
||||
if(! json["success"].toBool()) {
|
||||
auto errStr = json[errField].toString();
|
||||
return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+(errStr.isEmpty() ? data : errStr);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
quint64 dirFileSize(const QString &path) {
|
||||
QDir dir(path);
|
||||
|
|
|
@ -83,9 +83,9 @@ inline int verCompare(const QString& a, const QString& b) {
|
|||
return aparts.count() > bparts.count() ? aparts[cnt].toInt() : bparts[cnt].toInt();
|
||||
}
|
||||
|
||||
QString replyErr(QNetworkReply *);
|
||||
QString checkReply(QNetworkReply *, QJsonDocument * = 0);
|
||||
QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0);
|
||||
QString checkReplyForJson(QNetworkReply *, QString errField);
|
||||
|
||||
#define Def_CtrlReqPre \
|
||||
waitingDlg->show();\
|
||||
|
|
|
@ -18,8 +18,9 @@ public:
|
|||
explicit NetReq(QNetworkAccessManager *access) : mAccess(access) {};
|
||||
#else
|
||||
NetReq() {init();};
|
||||
explicit NetReq(QNetworkAccessManager *access) : mAccess(access) {init();};
|
||||
explicit NetReq(const QString &url) : QNetworkRequest{url} {init();};
|
||||
explicit NetReq(const QUrl &url) : QNetworkRequest{url} {init();};
|
||||
explicit NetReq(QNetworkAccessManager *access) : mAccess(access) {init();};
|
||||
inline void init() {
|
||||
setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user