Browse Source

// maybe that works

tags/v5.0.0
ArsenArsen 5 years ago
parent
commit
45b1c6f2dc
  1. 12
      io/ioutils.cpp
  2. 7
      io/ioutils.hpp
  3. 4
      mainwindow.cpp
  4. 5
      uploaders/customuploader.cpp
  5. 2
      uploaders/default/imguruploader.cpp

12
io/ioutils.cpp

@ -8,14 +8,17 @@ namespace ioutils {
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);
for (auto header : headers) {
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
}
QNetworkReply *reply = networkManager.get(req);
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();
});
}
@ -23,14 +26,15 @@ void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::
void ioutils::postJson(QUrl target,
QList<QPair<QString, QString>> headers,
QByteArray body,
std::function<void(QJsonDocument, QNetworkReply *)> callback) {
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
QNetworkRequest req(target);
for (auto header : headers) {
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
}
QNetworkReply *reply = networkManager.post(req, body);
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;
});
}

7
io/ioutils.hpp

@ -9,8 +9,11 @@
namespace ioutils {
extern QNetworkAccessManager networkManager;
void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback);
void postJson(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, 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, 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);
}

4
mainwindow.cpp

@ -114,7 +114,9 @@ void MainWindow::quit() {
void MainWindow::toggleVisible() {
this->setVisible(!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
}
}

5
uploaders/customuploader.cpp

@ -284,8 +284,9 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
});
} else {
ioutils::postJson(target, h, data,
[&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); });
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray, QNetworkReply *) {
parseResult(result, returnPathspec, name());
});
}
break;
}

2
uploaders/default/imguruploader.cpp

@ -15,7 +15,7 @@ void ImgurUploader::doUpload(QPixmap *pixmap) {
QList<QPair<QString, QString>>()
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
byteArray, [](QJsonDocument res, QNetworkReply *) {
byteArray, [](QJsonDocument res, QByteArray, QNetworkReply *) {
QString result = res.object()["data"].toObject()["link"].toString();
screenshotutil::toClipboard(result);
notifications::notify("KShare imgur Uploader ",

Loading…
Cancel
Save