// maybe that works
This commit is contained in:
parent
9e2c588c9e
commit
45b1c6f2dc
@ -8,14 +8,17 @@ namespace ioutils {
|
|||||||
QNetworkAccessManager networkManager;
|
QNetworkAccessManager networkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback) {
|
void ioutils::getJson(QUrl target,
|
||||||
|
QList<QPair<QString, QString>> headers,
|
||||||
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.get(req);
|
QNetworkReply *reply = networkManager.get(req);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
callback(QJsonDocument::fromJson(reply->readAll()), reply);
|
QByteArray data = reply->readAll();
|
||||||
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -23,14 +26,15 @@ void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::
|
|||||||
void ioutils::postJson(QUrl target,
|
void ioutils::postJson(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QByteArray body,
|
QByteArray body,
|
||||||
std::function<void(QJsonDocument, QNetworkReply *)> callback) {
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.post(req, body);
|
QNetworkReply *reply = networkManager.post(req, body);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
callback(QJsonDocument::fromJson(reply->readAll()), reply);
|
QByteArray data = reply->readAll();
|
||||||
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,11 @@
|
|||||||
|
|
||||||
namespace ioutils {
|
namespace ioutils {
|
||||||
extern QNetworkAccessManager networkManager;
|
extern QNetworkAccessManager networkManager;
|
||||||
void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback);
|
void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
||||||
void postJson(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QJsonDocument, QNetworkReply *)> callback);
|
void postJson(QUrl target,
|
||||||
|
QList<QPair<QString, QString>> headers,
|
||||||
|
QByteArray body,
|
||||||
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
||||||
void getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback);
|
void getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback);
|
||||||
void postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QByteArray, QNetworkReply *)> callback);
|
void postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QByteArray, QNetworkReply *)> callback);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,9 @@ void MainWindow::quit() {
|
|||||||
void MainWindow::toggleVisible() {
|
void MainWindow::toggleVisible() {
|
||||||
this->setVisible(!this->isVisible());
|
this->setVisible(!this->isVisible());
|
||||||
if (this->isVisible()) {
|
if (this->isVisible()) {
|
||||||
this->raise();
|
this->raise(); // that didn't work
|
||||||
|
this->setWindowState(Qt::WindowActive); // maybe that works
|
||||||
|
this->activateWindow(); // maybe that works
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +284,9 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
|
|||||||
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postJson(target, h, data,
|
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray, QNetworkReply *) {
|
||||||
[&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); });
|
parseResult(result, returnPathspec, name());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ void ImgurUploader::doUpload(QPixmap *pixmap) {
|
|||||||
QList<QPair<QString, QString>>()
|
QList<QPair<QString, QString>>()
|
||||||
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
|
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
|
||||||
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
|
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
|
||||||
byteArray, [](QJsonDocument res, QNetworkReply *) {
|
byteArray, [](QJsonDocument res, QByteArray, QNetworkReply *) {
|
||||||
QString result = res.object()["data"].toObject()["link"].toString();
|
QString result = res.object()["data"].toObject()["link"].toString();
|
||||||
screenshotutil::toClipboard(result);
|
screenshotutil::toClipboard(result);
|
||||||
notifications::notify("KShare imgur Uploader ",
|
notifications::notify("KShare imgur Uploader ",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user