* added result url to history
* added context menu to history * added example config that work with Gurkengewuerz/php_filehoster and is ShareX compatible * added filename as parameter to custom uploader
This commit is contained in:
parent
828c9542ad
commit
3c9a87583a
15
examples/php_filehost.uploader
Normal file
15
examples/php_filehost.uploader
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "Gurkengewuerz Share",
|
||||||
|
"target": "https://share.example.com/index.php?token=XXXXXXXXXXXXXXXXX",
|
||||||
|
"format": "multipart-form-data",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"__Content-Type": "/%contenttype/",
|
||||||
|
"filename": "/%filename/",
|
||||||
|
"name": "file",
|
||||||
|
"body": "/%imagedata/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"return": "|"
|
||||||
|
}
|
||||||
|
|
@ -8,11 +8,12 @@
|
|||||||
|
|
||||||
QNetworkAccessManager ioutils::networkManager;
|
QNetworkAccessManager ioutils::networkManager;
|
||||||
|
|
||||||
void addLogEntry(QNetworkReply *reply, QByteArray data, QString filename) {
|
void ioutils::addLogEntry(QNetworkReply* reply, QByteArray data, QString result, QString filename) {
|
||||||
requestlogging::RequestContext ctx;
|
requestlogging::RequestContext ctx;
|
||||||
|
|
||||||
ctx.reply = reply;
|
ctx.reply = reply;
|
||||||
ctx.response = data;
|
ctx.response = data;
|
||||||
|
ctx.result = result;
|
||||||
ctx.filename = filename;
|
ctx.filename = filename;
|
||||||
|
|
||||||
requestlogging::addEntry(ctx);
|
requestlogging::addEntry(ctx);
|
||||||
@ -31,7 +32,6 @@ void removeTask() {
|
|||||||
void ioutils::postMultipart(QUrl target,
|
void ioutils::postMultipart(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QHttpMultiPart *body,
|
QHttpMultiPart *body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
@ -39,10 +39,9 @@ void ioutils::postMultipart(QUrl target,
|
|||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.post(req, body);
|
QNetworkReply *reply = networkManager.post(req, body);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data, filename);
|
|
||||||
callback(QJsonDocument::fromJson(data), data, reply);
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
@ -51,7 +50,6 @@ void ioutils::postMultipart(QUrl target,
|
|||||||
void ioutils::postMultipartData(QUrl target,
|
void ioutils::postMultipartData(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QHttpMultiPart *body,
|
QHttpMultiPart *body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QByteArray, QNetworkReply *)> callback) {
|
std::function<void(QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
@ -59,10 +57,9 @@ void ioutils::postMultipartData(QUrl target,
|
|||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.post(req, body);
|
QNetworkReply *reply = networkManager.post(req, body);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data, filename);
|
|
||||||
callback(data, reply);
|
callback(data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
@ -70,7 +67,6 @@ void ioutils::postMultipartData(QUrl target,
|
|||||||
|
|
||||||
void ioutils::getJson(QUrl target,
|
void ioutils::getJson(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QString filename,
|
|
||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
@ -78,10 +74,9 @@ void ioutils::getJson(QUrl target,
|
|||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.get(req);
|
QNetworkReply *reply = networkManager.get(req);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data, filename);
|
|
||||||
callback(QJsonDocument::fromJson(data), data, reply);
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
@ -90,7 +85,6 @@ void ioutils::getJson(QUrl target,
|
|||||||
void ioutils::postJson(QUrl target,
|
void ioutils::postJson(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QByteArray body,
|
QByteArray body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
@ -98,26 +92,24 @@ void ioutils::postJson(QUrl target,
|
|||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.post(req, body);
|
QNetworkReply *reply = networkManager.post(req, body);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data, filename);
|
|
||||||
callback(QJsonDocument::fromJson(data), data, reply);
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, QString filename, std::function<void(QByteArray, QNetworkReply *)> callback) {
|
void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(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);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data, filename);
|
|
||||||
callback(data, reply);
|
callback(data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
@ -126,7 +118,6 @@ void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, QStri
|
|||||||
void ioutils::postData(QUrl target,
|
void ioutils::postData(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QByteArray body,
|
QByteArray body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QByteArray, QNetworkReply *)> callback) {
|
std::function<void(QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
@ -134,10 +125,9 @@ void ioutils::postData(QUrl target,
|
|||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.post(req, body);
|
QNetworkReply *reply = networkManager.post(req, body);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data, filename);
|
|
||||||
callback(data, reply);
|
callback(data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
|
@ -9,26 +9,23 @@
|
|||||||
|
|
||||||
namespace ioutils {
|
namespace ioutils {
|
||||||
extern QNetworkAccessManager networkManager;
|
extern QNetworkAccessManager networkManager;
|
||||||
|
void addLogEntry(QNetworkReply* reply, QByteArray data, QString result, QString filename);
|
||||||
void getJson(QUrl target,
|
void getJson(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QString filename,
|
|
||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
||||||
void postJson(QUrl target,
|
void postJson(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QByteArray body,
|
QByteArray body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
||||||
void getData(QUrl target, QList<QPair<QString, QString>> headers, QString filename, 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, QString filename, std::function<void(QByteArray, QNetworkReply *)> callback);
|
void postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QByteArray, QNetworkReply *)> callback);
|
||||||
void postMultipart(QUrl target,
|
void postMultipart(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QHttpMultiPart *body,
|
QHttpMultiPart *body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
|
||||||
void postMultipartData(QUrl target,
|
void postMultipartData(QUrl target,
|
||||||
QList<QPair<QString, QString>> headers,
|
QList<QPair<QString, QString>> headers,
|
||||||
QHttpMultiPart *body,
|
QHttpMultiPart *body,
|
||||||
QString filename,
|
|
||||||
std::function<void(QByteArray, QNetworkReply *)> callback);
|
std::function<void(QByteArray, QNetworkReply *)> callback);
|
||||||
QString methodString(QNetworkAccessManager::Operation operation);
|
QString methodString(QNetworkAccessManager::Operation operation);
|
||||||
QString httpString(int responseCode);
|
QString httpString(int responseCode);
|
||||||
|
@ -39,6 +39,7 @@ void requestlogging::addEntry(RequestContext context) {
|
|||||||
|
|
||||||
QTextStream(&requestFile) << ioutils::methodString(context.reply->operation()) << " " // $type
|
QTextStream(&requestFile) << ioutils::methodString(context.reply->operation()) << " " // $type
|
||||||
<< context.reply->url().toString().replace(" ", "%20") << " " // $url
|
<< context.reply->url().toString().replace(" ", "%20") << " " // $url
|
||||||
|
<< context.result.replace(" ", "%20") << " " // $result
|
||||||
<< context.filename.replace(" ", "_") << " " // $filename
|
<< context.filename.replace(" ", "_") << " " // $filename
|
||||||
<< context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << " " // $status
|
<< context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << " " // $status
|
||||||
<< timeNow.replace(" ", "_") << endl
|
<< timeNow.replace(" ", "_") << endl
|
||||||
@ -48,6 +49,7 @@ void requestlogging::addEntry(RequestContext context) {
|
|||||||
MainWindow::inst()->addResponse(
|
MainWindow::inst()->addResponse(
|
||||||
context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),
|
context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),
|
||||||
context.filename,
|
context.filename,
|
||||||
|
context.result,
|
||||||
context.reply->url().toString(),
|
context.reply->url().toString(),
|
||||||
timeNow.replace("_", " "));
|
timeNow.replace("_", " "));
|
||||||
}
|
}
|
||||||
@ -66,6 +68,7 @@ QList<LoggedRequest> requestlogging::getRequests() {
|
|||||||
QTextStream stream(&line);
|
QTextStream stream(&line);
|
||||||
stream >> r.type;
|
stream >> r.type;
|
||||||
stream >> r.url;
|
stream >> r.url;
|
||||||
|
stream >> r.result;
|
||||||
stream >> r.filename;
|
stream >> r.filename;
|
||||||
stream >> r.responseCode;
|
stream >> r.responseCode;
|
||||||
stream >> r.time;
|
stream >> r.time;
|
||||||
|
@ -12,6 +12,7 @@ namespace requestlogging {
|
|||||||
QByteArray response;
|
QByteArray response;
|
||||||
QNetworkReply *reply;
|
QNetworkReply *reply;
|
||||||
QString filename;
|
QString filename;
|
||||||
|
QString result;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoggedRequest {
|
class LoggedRequest {
|
||||||
@ -27,6 +28,9 @@ namespace requestlogging {
|
|||||||
QString getType() {
|
QString getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
QString getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
QString getTime() {
|
QString getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
@ -40,6 +44,7 @@ namespace requestlogging {
|
|||||||
private:
|
private:
|
||||||
QString url;
|
QString url;
|
||||||
QString filename;
|
QString filename;
|
||||||
|
QString result;
|
||||||
QString type;
|
QString type;
|
||||||
QString time;
|
QString time;
|
||||||
int responseCode;
|
int responseCode;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "settingsdialog.hpp"
|
#include "settingsdialog.hpp"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <colorpicker/colorpickerscene.hpp>
|
#include <colorpicker/colorpickerscene.hpp>
|
||||||
@ -113,6 +115,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
connect(ui->clipboardButton, &QPushButton::clicked, this, &MainWindow::openScreenshotFolder);
|
connect(ui->clipboardButton, &QPushButton::clicked, this, &MainWindow::openScreenshotFolder);
|
||||||
connect(ui->colorPickerButton, &QPushButton::clicked, this, [] { ColorPickerScene::showPicker(); });
|
connect(ui->colorPickerButton, &QPushButton::clicked, this, [] { ColorPickerScene::showPicker(); });
|
||||||
|
|
||||||
|
ui->treeWidget->addAction(ui->actionOpenURL);
|
||||||
|
ui->treeWidget->addAction(ui->actionOpenLocalFile);
|
||||||
|
ui->treeWidget->addAction(ui->actionOpenRequest);
|
||||||
|
ui->treeWidget->addAction(ui->actionCopyLinktoClipboard);
|
||||||
|
|
||||||
ui->aboutButton->setFocus();
|
ui->aboutButton->setFocus();
|
||||||
|
|
||||||
tray->setContextMenu(menu);
|
tray->setContextMenu(menu);
|
||||||
@ -132,7 +139,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
|
|
||||||
QList<LoggedRequest> requests = requestlogging::getRequests();
|
QList<LoggedRequest> requests = requestlogging::getRequests();
|
||||||
for (LoggedRequest req : requests) {
|
for (LoggedRequest req : requests) {
|
||||||
addResponse(req.getResponseCode(), req.getFilename(), req.getUrl(), req.getTime());
|
addResponse(req.getResponseCode(), req.getFilename(), req.getResult(), req.getUrl(), req.getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,14 +180,6 @@ void MainWindow::on_actionQuit_triggered() {
|
|||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionFullscreen_triggered() {
|
|
||||||
screenshotter::fullscreenDelayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionArea_triggered() {
|
|
||||||
screenshotter::areaDelayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionStart_triggered() {
|
void MainWindow::on_actionStart_triggered() {
|
||||||
rec();
|
rec();
|
||||||
}
|
}
|
||||||
@ -189,10 +188,6 @@ void MainWindow::on_actionStop_triggered() {
|
|||||||
controller->end();
|
controller->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionColor_Picker_triggered() {
|
|
||||||
ColorPickerScene::showPicker();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionSettings_triggered() {
|
void MainWindow::on_actionSettings_triggered() {
|
||||||
SettingsDialog *dialog = new SettingsDialog(this);
|
SettingsDialog *dialog = new SettingsDialog(this);
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
@ -205,16 +200,12 @@ void MainWindow::on_actionAbout_triggered() {
|
|||||||
box->show();
|
box->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionActive_window_triggered() {
|
|
||||||
screenshotter::activeDelayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionAbort_triggered() {
|
void MainWindow::on_actionAbort_triggered() {
|
||||||
controller->abort();
|
controller->abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &) {
|
void MainWindow::on_actionOpenRequest_triggered() {
|
||||||
QString file = ui->treeWidget->currentItem()->text(3);
|
QString file = ui->treeWidget->currentItem()->text(4);
|
||||||
file = settings::dir().absoluteFilePath("responses/" + file.left(file.length() - 4));
|
file = settings::dir().absoluteFilePath("responses/" + file.left(file.length() - 4));
|
||||||
|
|
||||||
QFile dataFile(file);
|
QFile dataFile(file);
|
||||||
@ -228,6 +219,25 @@ void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &) {
|
|||||||
dialog->show();
|
dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionOpenURL_triggered() {
|
||||||
|
QDesktopServices::openUrl(QUrl(ui->treeWidget->currentItem()->text(2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionOpenLocalFile_triggered() {
|
||||||
|
QString file = ui->treeWidget->currentItem()->text(1);
|
||||||
|
file = settings::dir().absoluteFilePath("responses/" + file.left(file.length() - 4));
|
||||||
|
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionCopyLinktoClipboard_triggered() {
|
||||||
|
QApplication::clipboard()->setText(ui->treeWidget->currentItem()->text(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &) {
|
||||||
|
on_actionOpenURL_triggered();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::openScreenshotFolder() {
|
void MainWindow::openScreenshotFolder() {
|
||||||
QDir saveDir;
|
QDir saveDir;
|
||||||
switch (settings::settings().value("saveLocation", 1).toInt()) {
|
switch (settings::settings().value("saveLocation", 1).toInt()) {
|
||||||
@ -258,9 +268,9 @@ void MainWindow::setTrayIcon(QIcon icon) {
|
|||||||
tray->setIcon(icon);
|
tray->setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addResponse(int httpCode, QString filename, QString url, QString time) {
|
void MainWindow::addResponse(int httpCode, QString filename, QString result, QString url, QString time) {
|
||||||
QString httpStatus = ioutils::httpString(httpCode);
|
QString httpStatus = ioutils::httpString(httpCode);
|
||||||
QTreeWidgetItem* tw = new QTreeWidgetItem({ QString::number(httpCode) + " " + httpStatus, filename, url, time + " UTC" });
|
QTreeWidgetItem* tw = new QTreeWidgetItem({ QString::number(httpCode) + " " + httpStatus, filename, result, url, time + " UTC" });
|
||||||
|
|
||||||
if(httpCode >= 200 && httpCode < 300) {
|
if(httpCode >= 200 && httpCode < 300) {
|
||||||
tw->setIcon(0, *(new QIcon(":/icons/checked.png")));
|
tw->setIcon(0, *(new QIcon(":/icons/checked.png")));
|
||||||
|
@ -21,15 +21,15 @@ private slots:
|
|||||||
void toggleVisible();
|
void toggleVisible();
|
||||||
|
|
||||||
void on_actionQuit_triggered();
|
void on_actionQuit_triggered();
|
||||||
void on_actionFullscreen_triggered();
|
|
||||||
void on_actionArea_triggered();
|
|
||||||
void on_actionStart_triggered();
|
void on_actionStart_triggered();
|
||||||
void on_actionStop_triggered();
|
void on_actionStop_triggered();
|
||||||
void on_actionSettings_triggered();
|
void on_actionSettings_triggered();
|
||||||
void on_actionColor_Picker_triggered();
|
|
||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
void on_actionActive_window_triggered();
|
|
||||||
void on_actionAbort_triggered();
|
void on_actionAbort_triggered();
|
||||||
|
void on_actionOpenRequest_triggered();
|
||||||
|
void on_actionOpenURL_triggered();
|
||||||
|
void on_actionOpenLocalFile_triggered();
|
||||||
|
void on_actionCopyLinktoClipboard_triggered();
|
||||||
void openScreenshotFolder();
|
void openScreenshotFolder();
|
||||||
void on_treeWidget_doubleClicked(const QModelIndex &);
|
void on_treeWidget_doubleClicked(const QModelIndex &);
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
bool valid();
|
bool valid();
|
||||||
void setTrayIcon(QIcon icon);
|
void setTrayIcon(QIcon icon);
|
||||||
void addResponse(int httpCode, QString filename, QString url, QString time);
|
void addResponse(int httpCode, QString filename, QString result, QString url, QString time);
|
||||||
RecordingController *controller = new RecordingController;
|
RecordingController *controller = new RecordingController;
|
||||||
|
|
||||||
QSystemTrayIcon *tray;
|
QSystemTrayIcon *tray;
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>819</width>
|
<width>931</width>
|
||||||
<height>388</height>
|
<height>386</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@ -129,6 +129,9 @@
|
|||||||
<layout class="QGridLayout" name="gridLayout_5">
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
|
</property>
|
||||||
<property name="indentation">
|
<property name="indentation">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
@ -156,6 +159,11 @@
|
|||||||
<string>URL</string>
|
<string>URL</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Request</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Time</string>
|
<string>Time</string>
|
||||||
@ -195,7 +203,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>819</width>
|
<width>931</width>
|
||||||
<height>29</height>
|
<height>29</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -227,21 +235,6 @@
|
|||||||
<string notr="true">Ctrl+Q</string>
|
<string notr="true">Ctrl+Q</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionFullscreen">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Fullscreen</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionArea">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Area</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionColor_Picker">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Color Picker</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionStart">
|
<action name="actionStart">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Start</string>
|
<string>&Start</string>
|
||||||
@ -262,16 +255,31 @@
|
|||||||
<string>&About</string>
|
<string>&About</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionActive_window">
|
|
||||||
<property name="text">
|
|
||||||
<string>Active &window</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionAbort">
|
<action name="actionAbort">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Abort</string>
|
<string>&Abort</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionOpenURL">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open URL</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionOpenLocalFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open Local File</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionOpenRequest">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open Request</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionCopyLinktoClipboard">
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy Link to Clipboard</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -210,7 +210,7 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomUploader::parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name) {
|
void CustomUploader::parseResult(QNetworkReply *r, QJsonDocument result, QByteArray data, QString returnPathspec, QString name, QString filename) {
|
||||||
if (result.isObject()) {
|
if (result.isObject()) {
|
||||||
QString url
|
QString url
|
||||||
= formatter::format(urlPrepend, "") + parsePathspec(result, returnPathspec) + formatter::format(urlAppend, "");
|
= formatter::format(urlPrepend, "") + parsePathspec(result, returnPathspec) + formatter::format(urlAppend, "");
|
||||||
@ -218,19 +218,22 @@ void CustomUploader::parseResult(QJsonDocument result, QByteArray data, QString
|
|||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
QApplication::clipboard()->setText(url);
|
QApplication::clipboard()->setText(url);
|
||||||
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Copied upload link to clipboard!"));
|
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Copied upload link to clipboard!"));
|
||||||
|
ioutils::addLogEntry(r, data, url, filename);
|
||||||
} else {
|
} else {
|
||||||
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Upload done, but result empty!"));
|
notifications::notify(tr("KShare Custom Uploader ") + name, tr("Upload done, but result empty!"));
|
||||||
QApplication::clipboard()->setText(data);
|
QApplication::clipboard()->setText(data);
|
||||||
|
ioutils::addLogEntry(r, data, "", filename);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
playErrorSound();
|
playErrorSound();
|
||||||
notifications::notify(tr("KShare Custom Uploader ") + name,
|
notifications::notify(tr("KShare Custom Uploader ") + name,
|
||||||
tr("Upload done, but result is not JSON Object! Result in clipboard."));
|
tr("Upload done, but result is not JSON Object! Result in clipboard."));
|
||||||
QApplication::clipboard()->setText(data);
|
QApplication::clipboard()->setText(data);
|
||||||
|
ioutils::addLogEntry(r, data, "", filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray substituteArgs(QByteArray arr, QString format, QByteArray imgData = QByteArray()) {
|
QByteArray substituteArgs(QByteArray arr, QString format, QString filename, QByteArray imgData = QByteArray()) {
|
||||||
QString mime = normalFormatMIME(normalFormatFromName(format));
|
QString mime = normalFormatMIME(normalFormatFromName(format));
|
||||||
if (mime.isEmpty()) mime = recordingFormatMIME(recordingFormatFromName(format));
|
if (mime.isEmpty()) mime = recordingFormatMIME(recordingFormatFromName(format));
|
||||||
if (arr.startsWith("/") && arr.endsWith("/")) {
|
if (arr.startsWith("/") && arr.endsWith("/")) {
|
||||||
@ -240,6 +243,9 @@ QByteArray substituteArgs(QByteArray arr, QString format, QByteArray imgData = Q
|
|||||||
{ { "format", format.toLower() }, { "FORMAT", format }, { "contenttype", mime } })
|
{ { "format", format.toLower() }, { "FORMAT", format }, { "contenttype", mime } })
|
||||||
.toUtf8();
|
.toUtf8();
|
||||||
|
|
||||||
|
QByteArray fA = filename.toLocal8Bit();
|
||||||
|
arr.replace("%filename", fA.data());
|
||||||
|
|
||||||
if (imgData.isNull()) return arr;
|
if (imgData.isNull()) return arr;
|
||||||
return arr.replace("%imagedata", imgData);
|
return arr.replace("%imagedata", imgData);
|
||||||
} else
|
} else
|
||||||
@ -247,17 +253,17 @@ QByteArray substituteArgs(QByteArray arr, QString format, QByteArray imgData = Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data, QString format) {
|
QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data, QString format, QString filename) {
|
||||||
QJsonObject o;
|
QJsonObject o;
|
||||||
for (QString s : body.keys()) {
|
for (QString s : body.keys()) {
|
||||||
QJsonValue v = body[s];
|
QJsonValue v = body[s];
|
||||||
if (v.isObject()) {
|
if (v.isObject()) {
|
||||||
QJsonObject vo = v.toObject();
|
QJsonObject vo = v.toObject();
|
||||||
o.insert(s, recurseAndReplace(vo, data, format));
|
o.insert(s, recurseAndReplace(vo, data, format, filename));
|
||||||
} else if (v.isString()) {
|
} else if (v.isString()) {
|
||||||
QString str = v.toString();
|
QString str = v.toString();
|
||||||
if (str.startsWith("/") && str.endsWith("/")) {
|
if (str.startsWith("/") && str.endsWith("/")) {
|
||||||
o.insert(s, QString::fromUtf8(substituteArgs(str.toUtf8(), format, data)));
|
o.insert(s, QString::fromUtf8(substituteArgs(str.toUtf8(), format, filename, data)));
|
||||||
} else
|
} else
|
||||||
o.insert(s, v);
|
o.insert(s, v);
|
||||||
} else
|
} else
|
||||||
@ -277,10 +283,10 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
} break;
|
} break;
|
||||||
case RequestFormat::JSON: {
|
case RequestFormat::JSON: {
|
||||||
if (body.isString()) {
|
if (body.isString()) {
|
||||||
data = substituteArgs(body.toString().toUtf8(), format, imgData);
|
data = substituteArgs(body.toString().toUtf8(), format, filename, imgData);
|
||||||
} else {
|
} else {
|
||||||
QJsonObject vo = body.toObject();
|
QJsonObject vo = body.toObject();
|
||||||
data = QJsonDocument::fromVariant(recurseAndReplace(vo, imgData, format).toVariantMap()).toJson();
|
data = QJsonDocument::fromVariant(recurseAndReplace(vo, imgData, format, filename).toVariantMap()).toJson();
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case RequestFormat::X_WWW_FORM_URLENCODED: {
|
case RequestFormat::X_WWW_FORM_URLENCODED: {
|
||||||
@ -288,7 +294,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
for (QString key : body.keys()) {
|
for (QString key : body.keys()) {
|
||||||
QJsonValue val = body[key];
|
QJsonValue val = body[key];
|
||||||
if (val.isString()) {
|
if (val.isString()) {
|
||||||
data.append(QUrl::toPercentEncoding(key)).append('=').append(substituteArgs(val.toString().toUtf8(), format, imgData));
|
data.append(QUrl::toPercentEncoding(key)).append('=').append(substituteArgs(val.toString().toUtf8(), format, filename, imgData));
|
||||||
} else {
|
} else {
|
||||||
if (!data.isEmpty()) data.append('&');
|
if (!data.isEmpty()) data.append('&');
|
||||||
data.append(QUrl::toPercentEncoding(key))
|
data.append(QUrl::toPercentEncoding(key))
|
||||||
@ -307,7 +313,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
QHttpPart part;
|
QHttpPart part;
|
||||||
QJsonValue bd = valo["body"];
|
QJsonValue bd = valo["body"];
|
||||||
if (bd.isString()) {
|
if (bd.isString()) {
|
||||||
QByteArray body = substituteArgs(bd.toString().toUtf8(), format, imgData);
|
QByteArray body = substituteArgs(bd.toString().toUtf8(), format, filename, imgData);
|
||||||
QByteArray *bodyHeap = new QByteArray;
|
QByteArray *bodyHeap = new QByteArray;
|
||||||
body.swap(*bodyHeap);
|
body.swap(*bodyHeap);
|
||||||
QBuffer *buffer = new QBuffer(bodyHeap);
|
QBuffer *buffer = new QBuffer(bodyHeap);
|
||||||
@ -317,7 +323,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
arraysToDelete.append(bodyHeap);
|
arraysToDelete.append(bodyHeap);
|
||||||
} else {
|
} else {
|
||||||
auto bdo = bd.toObject();
|
auto bdo = bd.toObject();
|
||||||
QJsonObject result = recurseAndReplace(bdo, imgData, format);
|
QJsonObject result = recurseAndReplace(bdo, imgData, format, filename);
|
||||||
part.setBody(QJsonDocument::fromVariant(result.toVariantMap()).toJson());
|
part.setBody(QJsonDocument::fromVariant(result.toVariantMap()).toJson());
|
||||||
}
|
}
|
||||||
QByteArray cdh("form-data");
|
QByteArray cdh("form-data");
|
||||||
@ -325,11 +331,11 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
if (headerVal.startsWith("__")) {
|
if (headerVal.startsWith("__")) {
|
||||||
headerVal = headerVal.mid(2);
|
headerVal = headerVal.mid(2);
|
||||||
QByteArray str = valo["__" + headerVal].toString().toUtf8();
|
QByteArray str = valo["__" + headerVal].toString().toUtf8();
|
||||||
if (str.startsWith("/") && str.endsWith("/")) str = substituteArgs(str, format);
|
if (str.startsWith("/") && str.endsWith("/")) str = substituteArgs(str, format, filename);
|
||||||
part.setRawHeader(headerVal.toLatin1(), str);
|
part.setRawHeader(headerVal.toLatin1(), str);
|
||||||
} else if (headerVal != "body")
|
} else if (headerVal != "body")
|
||||||
cdh += "; " + headerVal + "=\""
|
cdh += "; " + headerVal + "=\""
|
||||||
+ substituteArgs(valo[headerVal].toString().toUtf8(), format).replace("\"", "\\\"") + "\"";
|
+ substituteArgs(valo[headerVal].toString().toUtf8(), format, filename).replace("\"", "\\\"") + "\"";
|
||||||
}
|
}
|
||||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh);
|
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh);
|
||||||
multipart->append(part);
|
multipart->append(part);
|
||||||
@ -337,8 +343,9 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::POST:
|
case HttpMethod::POST:
|
||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postMultipartData(target, h, multipart, filename,
|
ioutils::postMultipartData(target, h, multipart,
|
||||||
[&, buffersToDelete, arraysToDelete](QByteArray result, QNetworkReply *) {
|
[&, buffersToDelete, arraysToDelete, filename](QByteArray result, QNetworkReply *r) {
|
||||||
|
ioutils::addLogEntry(r, result, QString::fromUtf8(result), filename);
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
for (auto arr : arraysToDelete) delete arr;
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
@ -347,11 +354,11 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
tr("Copied upload result to clipboard!"));
|
tr("Copied upload result to clipboard!"));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postMultipart(target, h, multipart, filename,
|
ioutils::postMultipart(target, h, multipart,
|
||||||
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
[&, buffersToDelete, arraysToDelete, filename](QJsonDocument result, QByteArray data, QNetworkReply *r) {
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
for (auto arr : arraysToDelete) delete arr;
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
parseResult(result, data, returnPathspec, name());
|
parseResult(r, result, data, returnPathspec, name(), filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -367,14 +374,15 @@ void CustomUploader::doUpload(QByteArray imgData, QString format, QString filena
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::POST:
|
case HttpMethod::POST:
|
||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postData(target, h, data, filename, [&](QByteArray result, QNetworkReply *) {
|
ioutils::postData(target, h, data, [&, filename](QByteArray result, QNetworkReply *r) {
|
||||||
|
ioutils::addLogEntry(r, result, QString::fromUtf8(result), filename);
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||||
playSuccessSound();
|
playSuccessSound();
|
||||||
notifications::notify(tr("KShare Custom Uploader ") + name(), tr("Copied upload result to clipboard!"));
|
notifications::notify(tr("KShare Custom Uploader ") + name(), tr("Copied upload result to clipboard!"));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postJson(target, h, data, filename, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
ioutils::postJson(target, h, data, [&, filename](QJsonDocument result, QByteArray data, QNetworkReply *r) {
|
||||||
parseResult(result, data, returnPathspec, name());
|
parseResult(r, result, data, returnPathspec, name(), filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
enum class HttpMethod { POST };
|
enum class HttpMethod { POST };
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ private:
|
|||||||
bool base64 = false;
|
bool base64 = false;
|
||||||
QString returnPathspec;
|
QString returnPathspec;
|
||||||
QString urlPrepend, urlAppend;
|
QString urlPrepend, urlAppend;
|
||||||
void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name);
|
void parseResult(QNetworkReply *r, QJsonDocument result, QByteArray data, QString returnPathspec, QString name, QString filename);
|
||||||
void playSuccessSound();
|
void playSuccessSound();
|
||||||
void playErrorSound();
|
void playErrorSound();
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,6 @@ void ImgurSettingsDialog::on_authorize_clicked() {
|
|||||||
ioutils::postJson(QUrl("https://api.imgur.com/oauth2/token"),
|
ioutils::postJson(QUrl("https://api.imgur.com/oauth2/token"),
|
||||||
QList<QPair<QString, QString>>({ QPair<QString, QString>("Content-Type", "applicaton/json") }),
|
QList<QPair<QString, QString>>({ QPair<QString, QString>("Content-Type", "applicaton/json") }),
|
||||||
QJsonDocument::fromVariant(object.toVariantMap()).toJson(),
|
QJsonDocument::fromVariant(object.toVariantMap()).toJson(),
|
||||||
"",
|
|
||||||
[&](QJsonDocument response, QByteArray, QNetworkReply *r) {
|
[&](QJsonDocument response, QByteArray, QNetworkReply *r) {
|
||||||
if (r->error() != QNetworkReply::NoError || !response.isObject()) {
|
if (r->error() != QNetworkReply::NoError || !response.isObject()) {
|
||||||
ui->buttonBox->setEnabled(true);
|
ui->buttonBox->setEnabled(true);
|
||||||
|
@ -26,15 +26,15 @@ struct SegfaultWorkaround { // I'm a scrub for doing this
|
|||||||
ioutils::postJson(
|
ioutils::postJson(
|
||||||
QUrl("https://api.imgur.com/oauth2/token"),
|
QUrl("https://api.imgur.com/oauth2/token"),
|
||||||
QList<QPair<QString, QString>>({ QPair<QString, QString>("Content-Type", "applicaton/json") }),
|
QList<QPair<QString, QString>>({ QPair<QString, QString>("Content-Type", "applicaton/json") }),
|
||||||
QJsonDocument::fromVariant(object.toVariantMap()).toJson(), "", [&](QJsonDocument response, QByteArray, QNetworkReply *r) {
|
QJsonDocument::fromVariant(object.toVariantMap()).toJson(), [&](QJsonDocument response, QByteArray, QNetworkReply *r) {
|
||||||
qDebug() << response;
|
qDebug() << response;
|
||||||
if (r->error() != QNetworkReply::NoError || !response.isObject()) {
|
if (r->error() != QNetworkReply::NoError || !response.isObject()) {
|
||||||
dis->handleSend(QStringLiteral("Client-ID 8a98f183fc895da"), mime, byteArray, "");
|
dis->handleSend(QStringLiteral("Client-ID 8a98f183fc895da"), mime, byteArray);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonObject res = response.object();
|
QJsonObject res = response.object();
|
||||||
if (res.value("success").toBool()) {
|
if (res.value("success").toBool()) {
|
||||||
dis->handleSend(QStringLiteral("Client-ID 8a98f183fc895da"), mime, byteArray, "");
|
dis->handleSend(QStringLiteral("Client-ID 8a98f183fc895da"), mime, byteArray);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ struct SegfaultWorkaround { // I'm a scrub for doing this
|
|||||||
settings::settings().setValue("imgur/refresh", res["refresh_token"].toString());
|
settings::settings().setValue("imgur/refresh", res["refresh_token"].toString());
|
||||||
settings::settings().setValue("imgur/access", token);
|
settings::settings().setValue("imgur/access", token);
|
||||||
|
|
||||||
dis->handleSend(token.prepend("Bearer "), mime, byteArray, "");
|
dis->handleSend(token.prepend("Bearer "), mime, byteArray);
|
||||||
QScopedPointer<SegfaultWorkaround>(this);
|
QScopedPointer<SegfaultWorkaround>(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -84,13 +84,14 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray,
|
|||||||
ioutils::postJson(QUrl("https://api.imgur.com/3/image"),
|
ioutils::postJson(QUrl("https://api.imgur.com/3/image"),
|
||||||
QList<QPair<QString, QString>>() << QPair<QString, QString>("Content-Type", mime.toUtf8())
|
QList<QPair<QString, QString>>() << QPair<QString, QString>("Content-Type", mime.toUtf8())
|
||||||
<< QPair<QString, QString>("Authorization", auth),
|
<< QPair<QString, QString>("Authorization", auth),
|
||||||
byteArray, filename, [byteArray, this, mime](QJsonDocument res, QByteArray, QNetworkReply *r) {
|
byteArray, [byteArray, this, mime, filename](QJsonDocument res, QByteArray data, QNetworkReply *r) {
|
||||||
QString result = res.object()["data"].toObject()["link"].toString();
|
QString result = res.object()["data"].toObject()["link"].toString();
|
||||||
if (r->error() == QNetworkReply::ContentAccessDenied) {
|
if (r->error() == QNetworkReply::ContentAccessDenied) {
|
||||||
new SegfaultWorkaround(byteArray, this, mime);
|
new SegfaultWorkaround(byteArray, this, mime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
|
ioutils::addLogEntry(r, data, result, filename);
|
||||||
utils::toClipboard(result);
|
utils::toClipboard(result);
|
||||||
notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!"));
|
notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!"));
|
||||||
playSuccessSound();
|
playSuccessSound();
|
||||||
@ -104,6 +105,10 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray) {
|
||||||
|
handleSend(auth, mime, byteArray);
|
||||||
|
}
|
||||||
|
|
||||||
void ImgurUploader::playSuccessSound() {
|
void ImgurUploader::playSuccessSound() {
|
||||||
QMediaPlayer* mediaPlayer = new QMediaPlayer(MainWindow::inst());
|
QMediaPlayer* mediaPlayer = new QMediaPlayer(MainWindow::inst());
|
||||||
mediaPlayer->setMedia(QUrl("qrc:/successsound.wav"));
|
mediaPlayer->setMedia(QUrl("qrc:/successsound.wav"));
|
||||||
|
@ -20,6 +20,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void handleSend(QString auth, QString mime, QByteArray byteArray, QString filename);
|
void handleSend(QString auth, QString mime, QByteArray byteArray, QString filename);
|
||||||
|
void handleSend(QString auth, QString mime, QByteArray byteArray);
|
||||||
void playSuccessSound();
|
void playSuccessSound();
|
||||||
void playErrorSound();
|
void playErrorSound();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user