a bit more work
* added open screenshot folder button * removed history dialog * moved history dialog to main window * added filename to history * removed many actions from menu bar
This commit is contained in:
parent
2242f3f188
commit
8c0e961dc0
@ -8,11 +8,12 @@
|
|||||||
|
|
||||||
QNetworkAccessManager ioutils::networkManager;
|
QNetworkAccessManager ioutils::networkManager;
|
||||||
|
|
||||||
void addLogEntry(QNetworkReply *reply, QByteArray data) {
|
void addLogEntry(QNetworkReply *reply, QByteArray data, QString filename) {
|
||||||
requestlogging::RequestContext ctx;
|
requestlogging::RequestContext ctx;
|
||||||
|
|
||||||
ctx.reply = reply;
|
ctx.reply = reply;
|
||||||
ctx.response = data;
|
ctx.response = data;
|
||||||
|
ctx.filename = filename;
|
||||||
|
|
||||||
requestlogging::addEntry(ctx);
|
requestlogging::addEntry(ctx);
|
||||||
}
|
}
|
||||||
@ -30,6 +31,7 @@ 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) {
|
||||||
@ -37,10 +39,10 @@ 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] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data);
|
addLogEntry(reply, data, filename);
|
||||||
callback(QJsonDocument::fromJson(data), data, reply);
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
@ -49,6 +51,7 @@ 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) {
|
||||||
@ -56,10 +59,10 @@ 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] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data);
|
addLogEntry(reply, data, filename);
|
||||||
callback(data, reply);
|
callback(data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
@ -67,6 +70,7 @@ 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) {
|
||||||
@ -74,10 +78,10 @@ void ioutils::getJson(QUrl target,
|
|||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.get(req);
|
QNetworkReply *reply = networkManager.get(req);
|
||||||
addTask();
|
addTask();
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data);
|
addLogEntry(reply, data, filename);
|
||||||
callback(QJsonDocument::fromJson(data), data, reply);
|
callback(QJsonDocument::fromJson(data), data, reply);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
@ -86,6 +90,7 @@ 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) {
|
||||||
@ -93,26 +98,26 @@ 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] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data);
|
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, std::function<void(QByteArray, QNetworkReply *)> callback) {
|
void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, QString filename, 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] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data);
|
addLogEntry(reply, data, filename);
|
||||||
callback(data, reply);
|
callback(data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
@ -121,6 +126,7 @@ void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, std::
|
|||||||
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) {
|
||||||
@ -128,10 +134,10 @@ 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] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback, filename] {
|
||||||
removeTask();
|
removeTask();
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
addLogEntry(reply, data);
|
addLogEntry(reply, data, filename);
|
||||||
callback(data, reply);
|
callback(data, reply);
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
|
@ -11,20 +11,24 @@ namespace ioutils {
|
|||||||
extern QNetworkAccessManager networkManager;
|
extern QNetworkAccessManager networkManager;
|
||||||
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, std::function<void(QByteArray, QNetworkReply *)> callback);
|
void getData(QUrl target, QList<QPair<QString, QString>> headers, 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 postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, QString filename, 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);
|
||||||
} // namespace ioutils
|
} // namespace ioutils
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
#include "historydialog.hpp"
|
|
||||||
#include "requestlogging.hpp"
|
|
||||||
#include "ui_historydialog.h"
|
|
||||||
|
|
||||||
#include <monospacetextdialog.hpp>
|
|
||||||
|
|
||||||
using requestlogging::LoggedRequest;
|
|
||||||
|
|
||||||
HistoryDialog::HistoryDialog(QWidget *parent) : QDialog(parent), ui(new Ui::HistoryDialog) {
|
|
||||||
ui->setupUi(this);
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
ui->treeWidget->setColumnWidth(0, 50);
|
|
||||||
ui->treeWidget->setColumnWidth(1, 150);
|
|
||||||
ui->treeWidget->setColumnWidth(2, 50);
|
|
||||||
ui->treeWidget->setColumnWidth(3, 100);
|
|
||||||
|
|
||||||
QList<LoggedRequest> requests = requestlogging::getRequests();
|
|
||||||
for (LoggedRequest req : requests) {
|
|
||||||
ui->treeWidget->addTopLevelItem(
|
|
||||||
new QTreeWidgetItem({ req.getType(), req.getUrl(), QString::number(req.getResponseCode()), req.getTime() + " UTC" }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HistoryDialog::~HistoryDialog() {
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryDialog::on_treeWidget_doubleClicked(const QModelIndex &) {
|
|
||||||
QString file = ui->treeWidget->currentItem()->text(3);
|
|
||||||
file = settings::dir().absoluteFilePath("responses/" + file.left(file.length() - 4));
|
|
||||||
|
|
||||||
QFile dataFile(file);
|
|
||||||
if (!dataFile.open(QIODevice::ReadOnly)) return;
|
|
||||||
MonospaceTextDialog *dialog = new MonospaceTextDialog(file, dataFile.readAll());
|
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
dialog->show();
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#ifndef HISTORYDIALOG_H
|
|
||||||
#define HISTORYDIALOG_H
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
class HistoryDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
class HistoryDialog : public QDialog {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit HistoryDialog(QWidget *parent = 0);
|
|
||||||
~HistoryDialog();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void on_treeWidget_doubleClicked(const QModelIndex &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::HistoryDialog *ui;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // HISTORYDIALOG_H
|
|
@ -1,88 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>HistoryDialog</class>
|
|
||||||
<widget class="QDialog" name="HistoryDialog">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>400</width>
|
|
||||||
<height>300</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Request History</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Type</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>URL</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Status</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Time</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="standardButtons">
|
|
||||||
<set>QDialogButtonBox::Close</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections>
|
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>accepted()</signal>
|
|
||||||
<receiver>HistoryDialog</receiver>
|
|
||||||
<slot>accept()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>248</x>
|
|
||||||
<y>254</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>157</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>rejected()</signal>
|
|
||||||
<receiver>HistoryDialog</receiver>
|
|
||||||
<slot>reject()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>316</x>
|
|
||||||
<y>260</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>286</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
</connections>
|
|
||||||
</ui>
|
|
@ -4,6 +4,9 @@
|
|||||||
#include <io/ioutils.hpp>
|
#include <io/ioutils.hpp>
|
||||||
#include <utils.hpp>
|
#include <utils.hpp>
|
||||||
|
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
// $type $url $status $time
|
// $type $url $status $time
|
||||||
// $type = GET POST PATCH DELETE etc
|
// $type = GET POST PATCH DELETE etc
|
||||||
// $url = request target
|
// $url = request target
|
||||||
@ -37,6 +40,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.filename.replace(" ", "_") << " " // $filename
|
||||||
<< context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << " " // $status
|
<< context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << " " // $status
|
||||||
<< timeNow.replace(" ", "_") << endl
|
<< timeNow.replace(" ", "_") << endl
|
||||||
<< flush; // $time
|
<< flush; // $time
|
||||||
@ -57,9 +61,11 @@ QList<LoggedRequest> requestlogging::getRequests() {
|
|||||||
QTextStream stream(&line);
|
QTextStream stream(&line);
|
||||||
stream >> r.type;
|
stream >> r.type;
|
||||||
stream >> r.url;
|
stream >> r.url;
|
||||||
|
stream >> r.filename;
|
||||||
stream >> r.responseCode;
|
stream >> r.responseCode;
|
||||||
stream >> r.time;
|
stream >> r.time;
|
||||||
r.time = r.time.replace("_", " ");
|
r.time = r.time.replace("_", " ");
|
||||||
|
r.filename = r.filename.replace("_", " ");
|
||||||
ret.append(r);
|
ret.append(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QString>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
|
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ namespace requestlogging {
|
|||||||
struct RequestContext {
|
struct RequestContext {
|
||||||
QByteArray response;
|
QByteArray response;
|
||||||
QNetworkReply *reply;
|
QNetworkReply *reply;
|
||||||
|
QString filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoggedRequest {
|
class LoggedRequest {
|
||||||
@ -19,6 +21,9 @@ namespace requestlogging {
|
|||||||
QString getUrl() {
|
QString getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
QString getFilename() {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
QString getType() {
|
QString getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -34,6 +39,7 @@ namespace requestlogging {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString url;
|
QString url;
|
||||||
|
QString filename;
|
||||||
QString type;
|
QString type;
|
||||||
QString time;
|
QString time;
|
||||||
int responseCode;
|
int responseCode;
|
||||||
|
@ -10,14 +10,22 @@
|
|||||||
#include <formats.hpp>
|
#include <formats.hpp>
|
||||||
#include <hotkeying.hpp>
|
#include <hotkeying.hpp>
|
||||||
#include <logger.hpp>
|
#include <logger.hpp>
|
||||||
#include <logs/historydialog.hpp>
|
|
||||||
#include <platformbackend.hpp>
|
#include <platformbackend.hpp>
|
||||||
#include <recording/recordingformats.hpp>
|
#include <recording/recordingformats.hpp>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
#include <uploaders/uploadersingleton.hpp>
|
#include <uploaders/uploadersingleton.hpp>
|
||||||
|
#include <QBuffer>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <logs/requestlogging.hpp>
|
||||||
|
#include <monospacetextdialog.hpp>
|
||||||
|
|
||||||
MainWindow *MainWindow::instance;
|
MainWindow *MainWindow::instance;
|
||||||
|
|
||||||
|
using requestlogging::LoggedRequest;
|
||||||
|
|
||||||
void MainWindow::rec() {
|
void MainWindow::rec() {
|
||||||
if (controller->isRunning()) return;
|
if (controller->isRunning()) return;
|
||||||
auto f = static_cast<formats::Recording>(
|
auto f = static_cast<formats::Recording>(
|
||||||
@ -94,7 +102,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
connect(recoff, &QAction::triggered, controller, &RecordingController::end);
|
connect(recoff, &QAction::triggered, controller, &RecordingController::end);
|
||||||
connect(recabort, &QAction::triggered, controller, &RecordingController::abort);
|
connect(recabort, &QAction::triggered, controller, &RecordingController::abort);
|
||||||
connect(about, &QAction::triggered, this, &MainWindow::on_actionAbout_triggered);
|
connect(about, &QAction::triggered, this, &MainWindow::on_actionAbout_triggered);
|
||||||
connect(ui->settings, &QPushButton::clicked, this, &MainWindow::on_actionSettings_triggered);
|
|
||||||
|
connect(ui->settingsButton, &QPushButton::clicked, this, &MainWindow::on_actionSettings_triggered);
|
||||||
|
connect(ui->fullscreenButton, &QPushButton::clicked, this, [] { screenshotter::fullscreenDelayed(); });
|
||||||
|
connect(ui->areaButton, &QPushButton::clicked, this, [] { screenshotter::areaDelayed(); });
|
||||||
|
connect(ui->aboutButton, &QPushButton::clicked, this, &MainWindow::on_actionAbout_triggered);
|
||||||
|
connect(ui->screenshotFolderButton, &QPushButton::clicked, this, &MainWindow::openScreenshotFolder);
|
||||||
|
connect(ui->colorPickerButton, &QPushButton::clicked, this, [] { ColorPickerScene::showPicker(); });
|
||||||
|
|
||||||
tray->setContextMenu(menu);
|
tray->setContextMenu(menu);
|
||||||
|
|
||||||
@ -110,6 +124,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
for (auto err : errors) ui->logBox->addItem(QString("ERROR: ") + err.what());
|
for (auto err : errors) ui->logBox->addItem(QString("ERROR: ") + err.what());
|
||||||
setWindowTitle("KShare v" + QApplication::applicationVersion());
|
setWindowTitle("KShare v" + QApplication::applicationVersion());
|
||||||
val = true;
|
val = true;
|
||||||
|
|
||||||
|
QList<LoggedRequest> requests = requestlogging::getRequests();
|
||||||
|
for (LoggedRequest req : requests) {
|
||||||
|
ui->treeWidget->addTopLevelItem(
|
||||||
|
new QTreeWidgetItem({ QString::number(req.getResponseCode()), req.getFilename(), req.getUrl(), req.getTime() + " UTC" }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
@ -189,11 +209,43 @@ void MainWindow::on_actionAbort_triggered() {
|
|||||||
controller->abort();
|
controller->abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_history_clicked() {
|
void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &) {
|
||||||
HistoryDialog *dialog = new HistoryDialog;
|
QString file = ui->treeWidget->currentItem()->text(3);
|
||||||
|
file = settings::dir().absoluteFilePath("responses/" + file.left(file.length() - 4));
|
||||||
|
|
||||||
|
QFile dataFile(file);
|
||||||
|
if (!dataFile.open(QIODevice::ReadOnly)) return;
|
||||||
|
MonospaceTextDialog *dialog = new MonospaceTextDialog(file, dataFile.readAll());
|
||||||
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::openScreenshotFolder() {
|
||||||
|
QDir saveDir;
|
||||||
|
switch (settings::settings().value("saveLocation", 1).toInt()) {
|
||||||
|
case 0:
|
||||||
|
saveDir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||||
|
if (QStandardPaths::writableLocation(QStandardPaths::PicturesLocation).isEmpty()) {
|
||||||
|
qFatal("%s", tr("Cannot determine location for pictures").toLocal8Bit().constData());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (QStandardPaths::writableLocation(QStandardPaths::HomeLocation).isEmpty()) {
|
||||||
|
qFatal("%s", tr("Cannot determine location of your home directory").toLocal8Bit().constData());
|
||||||
|
}
|
||||||
|
saveDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Screenshots";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qFatal("%s", tr("Invalid config [saveLocation not int or is not in range]").toLocal8Bit().constData());
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
// Do not Save images
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(saveDir.absolutePath()));
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::setTrayIcon(QIcon icon) {
|
void MainWindow::setTrayIcon(QIcon icon) {
|
||||||
tray->setIcon(icon);
|
tray->setIcon(icon);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ private slots:
|
|||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
void on_actionActive_window_triggered();
|
void on_actionActive_window_triggered();
|
||||||
void on_actionAbort_triggered();
|
void on_actionAbort_triggered();
|
||||||
void on_history_clicked();
|
void openScreenshotFolder();
|
||||||
|
void on_treeWidget_doubleClicked(const QModelIndex &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static MainWindow *inst();
|
static MainWindow *inst();
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>513</width>
|
<width>760</width>
|
||||||
<height>328</height>
|
<height>363</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -25,30 +25,131 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="0" column="3" rowspan="3">
|
||||||
<widget class="QPushButton" name="settings">
|
<widget class="Line" name="line">
|
||||||
<property name="text">
|
<property name="orientation">
|
||||||
<string>Settings</string>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="2" rowspan="2">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<property name="title">
|
<item row="2" column="0">
|
||||||
<string>Log</string>
|
<widget class="QPushButton" name="clipboardButton">
|
||||||
</property>
|
<property name="text">
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<string>Copy Clipboard</string>
|
||||||
<item row="0" column="0">
|
</property>
|
||||||
<widget class="QListWidget" name="logBox"/>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
<item row="6" column="0">
|
||||||
</widget>
|
<widget class="QPushButton" name="settingsButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Settings</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="areaButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Area</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QPushButton" name="colorPickerButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open color picker</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0">
|
||||||
|
<widget class="QPushButton" name="aboutButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>About</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="fullscreenButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Fullscreen</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QPushButton" name="screenshotFolderButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open Screenshot Folder</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="0" column="4">
|
||||||
<widget class="QPushButton" name="history">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="text">
|
<property name="currentIndex">
|
||||||
<string>Open request history</string>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QWidget" name="tab_1">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Request History</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="uniformRowHeights">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="expandsOnDoubleClick">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Status</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Filename</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>URL</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Time</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Log</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QListWidget" name="logBox">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -59,7 +160,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>513</width>
|
<width>760</width>
|
||||||
<height>23</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -72,20 +173,6 @@
|
|||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionQuit"/>
|
<addaction name="actionQuit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuScreenshot">
|
|
||||||
<property name="title">
|
|
||||||
<string>Scree&nshot</string>
|
|
||||||
</property>
|
|
||||||
<addaction name="actionFullscreen"/>
|
|
||||||
<addaction name="actionArea"/>
|
|
||||||
<addaction name="actionActive_window"/>
|
|
||||||
</widget>
|
|
||||||
<widget class="QMenu" name="menuUtilities">
|
|
||||||
<property name="title">
|
|
||||||
<string>&Utilities</string>
|
|
||||||
</property>
|
|
||||||
<addaction name="actionColor_Picker"/>
|
|
||||||
</widget>
|
|
||||||
<widget class="QMenu" name="menuRecording">
|
<widget class="QMenu" name="menuRecording">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&Recording</string>
|
<string>&Recording</string>
|
||||||
@ -95,8 +182,6 @@
|
|||||||
<addaction name="actionAbort"/>
|
<addaction name="actionAbort"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuScreenshot"/>
|
|
||||||
<addaction name="menuUtilities"/>
|
|
||||||
<addaction name="menuRecording"/>
|
<addaction name="menuRecording"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionQuit">
|
<action name="actionQuit">
|
||||||
@ -156,6 +241,7 @@
|
|||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="icon.qrc"/>
|
<include location="icon.qrc"/>
|
||||||
|
<include location="sounds.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -67,7 +67,6 @@ SOURCES += main.cpp\
|
|||||||
uploaders/default/imgursettingsdialog.cpp \
|
uploaders/default/imgursettingsdialog.cpp \
|
||||||
filenamevalidator.cpp \
|
filenamevalidator.cpp \
|
||||||
logs/requestlogging.cpp \
|
logs/requestlogging.cpp \
|
||||||
logs/historydialog.cpp \
|
|
||||||
monospacetextdialog.cpp \
|
monospacetextdialog.cpp \
|
||||||
cropeditor/selectionrectangle.cpp \
|
cropeditor/selectionrectangle.cpp \
|
||||||
screenoverlay/screenoverlayview.cpp \
|
screenoverlay/screenoverlayview.cpp \
|
||||||
@ -119,7 +118,6 @@ HEADERS += mainwindow.hpp \
|
|||||||
uploaders/default/imgursettingsdialog.hpp \
|
uploaders/default/imgursettingsdialog.hpp \
|
||||||
filenamevalidator.hpp \
|
filenamevalidator.hpp \
|
||||||
logs/requestlogging.hpp \
|
logs/requestlogging.hpp \
|
||||||
logs/historydialog.hpp \
|
|
||||||
monospacetextdialog.hpp \
|
monospacetextdialog.hpp \
|
||||||
cropeditor/selectionrectangle.hpp \
|
cropeditor/selectionrectangle.hpp \
|
||||||
screenoverlay/screenoverlayview.hpp \
|
screenoverlay/screenoverlayview.hpp \
|
||||||
@ -185,7 +183,6 @@ FORMS += mainwindow.ui \
|
|||||||
aboutbox.ui \
|
aboutbox.ui \
|
||||||
hotkeyinputdialog.ui \
|
hotkeyinputdialog.ui \
|
||||||
uploaders/default/imgursettingsdialog.ui \
|
uploaders/default/imgursettingsdialog.ui \
|
||||||
logs/historydialog.ui \
|
|
||||||
monospacetextdialog.ui \
|
monospacetextdialog.ui \
|
||||||
screenoverlay/screenoverlaysettings.ui
|
screenoverlay/screenoverlaysettings.ui
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data, QString forma
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
void CustomUploader::doUpload(QByteArray imgData, QString format, QString filename) {
|
||||||
auto h = getHeaders(headers, format, this->rFormat);
|
auto h = getHeaders(headers, format, this->rFormat);
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
if (base64) imgData = imgData.toBase64(QByteArray::Base64UrlEncoding);
|
if (base64) imgData = imgData.toBase64(QByteArray::Base64UrlEncoding);
|
||||||
@ -337,7 +337,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::POST:
|
case HttpMethod::POST:
|
||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postMultipartData(target, h, multipart,
|
ioutils::postMultipartData(target, h, multipart, filename,
|
||||||
[&, buffersToDelete, arraysToDelete](QByteArray result, QNetworkReply *) {
|
[&, buffersToDelete, arraysToDelete](QByteArray result, QNetworkReply *) {
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
@ -347,7 +347,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
tr("Copied upload result to clipboard!"));
|
tr("Copied upload result to clipboard!"));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postMultipart(target, h, multipart,
|
ioutils::postMultipart(target, h, multipart, filename,
|
||||||
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
for (auto arr : arraysToDelete) delete arr;
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
@ -367,13 +367,13 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::POST:
|
case HttpMethod::POST:
|
||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
|
ioutils::postData(target, h, data, filename, [&](QByteArray result, QNetworkReply *) {
|
||||||
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, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
ioutils::postJson(target, h, data, filename, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
parseResult(result, data, returnPathspec, name());
|
parseResult(result, data, returnPathspec, name());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
CustomUploader(QString absFilePath);
|
CustomUploader(QString absFilePath);
|
||||||
QString name();
|
QString name();
|
||||||
QString description();
|
QString description();
|
||||||
void doUpload(QByteArray imgData, QString format);
|
void doUpload(QByteArray imgData, QString format, QString filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double limit = -1;
|
double limit = -1;
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <formats.hpp>
|
#include <formats.hpp>
|
||||||
#include <notifications.hpp>
|
#include <notifications.hpp>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
void ClipboardUploader::doUpload(QByteArray imgData, QString format) {
|
void ClipboardUploader::doUpload(QByteArray imgData, QString format, QString filename) {
|
||||||
auto f = formats::recordingFormatFromName(format);
|
auto f = formats::recordingFormatFromName(format);
|
||||||
if (f != formats::Recording::None) {
|
if (f != formats::Recording::None) {
|
||||||
auto data = new QMimeData();
|
auto data = new QMimeData();
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
return "Copies the image to clipboard";
|
return "Copies the image to clipboard";
|
||||||
}
|
}
|
||||||
|
|
||||||
void doUpload(QByteArray imgData, QString format);
|
void doUpload(QByteArray imgData, QString format, QString filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLIPBOARDUPLOADER_HPP
|
#endif // CLIPBOARDUPLOADER_HPP
|
||||||
|
@ -45,6 +45,7 @@ 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);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QString>
|
||||||
#include <formats.hpp>
|
#include <formats.hpp>
|
||||||
#include <io/ioutils.hpp>
|
#include <io/ioutils.hpp>
|
||||||
#include <notifications.hpp>
|
#include <notifications.hpp>
|
||||||
@ -25,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ private:
|
|||||||
QString mime;
|
QString mime;
|
||||||
}; // I feel terrible for making this. I am sorry, reader
|
}; // I feel terrible for making this. I am sorry, reader
|
||||||
|
|
||||||
void ImgurUploader::doUpload(QByteArray byteArray, QString format) {
|
void ImgurUploader::doUpload(QByteArray byteArray, QString format, QString filename) {
|
||||||
if (byteArray.size() > 1e+7) {
|
if (byteArray.size() > 1e+7) {
|
||||||
notifications::notify(tr("KShare imgur Uploader"), tr("Failed upload! Image too big"));
|
notifications::notify(tr("KShare imgur Uploader"), tr("Failed upload! Image too big"));
|
||||||
return;
|
return;
|
||||||
@ -70,20 +71,20 @@ void ImgurUploader::doUpload(QByteArray byteArray, QString format) {
|
|||||||
if (QDateTime::currentDateTimeUtc() > expireTime) {
|
if (QDateTime::currentDateTimeUtc() > expireTime) {
|
||||||
new SegfaultWorkaround(byteArray, this, mime);
|
new SegfaultWorkaround(byteArray, this, mime);
|
||||||
} else
|
} else
|
||||||
handleSend("Bearer " + settings::settings().value("imgur/access").toString(), mime, byteArray);
|
handleSend("Bearer " + settings::settings().value("imgur/access").toString(), mime, byteArray, filename);
|
||||||
} else
|
} else
|
||||||
handleSend(QStringLiteral("Client-ID 8a98f183fc895da"), mime, byteArray);
|
handleSend(QStringLiteral("Client-ID 8a98f183fc895da"), mime, byteArray, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImgurUploader::showSettings() {
|
void ImgurUploader::showSettings() {
|
||||||
(new ImgurSettingsDialog())->show();
|
(new ImgurSettingsDialog())->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray) {
|
void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray, QString filename) {
|
||||||
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, [byteArray, this, mime](QJsonDocument res, QByteArray, QNetworkReply *r) {
|
byteArray, filename, [byteArray, this, mime](QJsonDocument res, QByteArray, 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);
|
||||||
|
@ -15,11 +15,11 @@ public:
|
|||||||
QString description() override {
|
QString description() override {
|
||||||
return "imgur.com uploader";
|
return "imgur.com uploader";
|
||||||
}
|
}
|
||||||
void doUpload(QByteArray byteArray, QString) override;
|
void doUpload(QByteArray byteArray, QString, QString filename) override;
|
||||||
void showSettings() override;
|
void showSettings() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleSend(QString auth, QString mime, QByteArray byteArray);
|
void handleSend(QString auth, QString mime, QByteArray byteArray, QString filename);
|
||||||
void playSuccessSound();
|
void playSuccessSound();
|
||||||
void playErrorSound();
|
void playErrorSound();
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class Uploader {
|
class Uploader {
|
||||||
public:
|
public:
|
||||||
virtual void doUpload(QByteArray imgData, QString format) = 0;
|
virtual void doUpload(QByteArray imgData, QString format, QString filename) = 0;
|
||||||
virtual QString name() = 0;
|
virtual QString name() = 0;
|
||||||
virtual QString description() = 0;
|
virtual QString description() = 0;
|
||||||
virtual void showSettings() {
|
virtual void showSettings() {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <formats.hpp>
|
#include <formats.hpp>
|
||||||
@ -72,7 +73,8 @@ void UploaderSingleton::upload(QPixmap pixmap) {
|
|||||||
playSound();
|
playSound();
|
||||||
pixmap.save(file, format.toLocal8Bit().constData(), settings::settings().value("imageQuality", -1).toInt());
|
pixmap.save(file, format.toLocal8Bit().constData(), settings::settings().value("imageQuality", -1).toInt());
|
||||||
file->seek(0);
|
file->seek(0);
|
||||||
u->doUpload(file->readAll(), format);
|
QFileInfo fileInfo(file->fileName());
|
||||||
|
u->doUpload(file->readAll(), format, fileInfo.fileName());
|
||||||
} else
|
} else
|
||||||
notifications::notify(tr("KShare - Failed to save picture"), file->errorString(), QSystemTrayIcon::Warning);
|
notifications::notify(tr("KShare - Failed to save picture"), file->errorString(), QSystemTrayIcon::Warning);
|
||||||
delete file;
|
delete file;
|
||||||
@ -94,8 +96,9 @@ void UploaderSingleton::upload(QByteArray img, QString format) {
|
|||||||
file->write(img);
|
file->write(img);
|
||||||
file->close();
|
file->close();
|
||||||
}
|
}
|
||||||
|
QFileInfo fileInfo(file->fileName());
|
||||||
delete file;
|
delete file;
|
||||||
uploaders.value(uploader)->doUpload(img, format);
|
uploaders.value(uploader)->doUpload(img, format, fileInfo.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UploaderSingleton::upload(QFile &img, QString format) {
|
void UploaderSingleton::upload(QFile &img, QString format) {
|
||||||
@ -105,8 +108,9 @@ void UploaderSingleton::upload(QFile &img, QString format) {
|
|||||||
formatter::format(settings::settings().value("fileFormat", "Screenshot %(yyyy-MM-dd HH-mm-ss)date.%ext").toString(),
|
formatter::format(settings::settings().value("fileFormat", "Screenshot %(yyyy-MM-dd HH-mm-ss)date.%ext").toString(),
|
||||||
format.toLower())))) {
|
format.toLower())))) {
|
||||||
playSound();
|
playSound();
|
||||||
|
QFileInfo fileInfo(img.fileName());
|
||||||
if (img.open(QFile::ReadWrite))
|
if (img.open(QFile::ReadWrite))
|
||||||
uploaders.value(uploader)->doUpload(img.readAll(), format);
|
uploaders.value(uploader)->doUpload(img.readAll(), format, fileInfo.fileName());
|
||||||
else
|
else
|
||||||
notifications::notify(tr("KShare - Failed to save picture"), img.errorString(), QSystemTrayIcon::Warning);
|
notifications::notify(tr("KShare - Failed to save picture"), img.errorString(), QSystemTrayIcon::Warning);
|
||||||
} else
|
} else
|
||||||
|
Loading…
Reference in New Issue
Block a user