Add an ImagePlus uploader
This commit is contained in:
parent
6ab5452fb6
commit
88985690c8
@ -64,7 +64,8 @@ SOURCES += main.cpp\
|
|||||||
cropeditor/drawing/ellipseitem.cpp \
|
cropeditor/drawing/ellipseitem.cpp \
|
||||||
hotkeyinputdialog.cpp \
|
hotkeyinputdialog.cpp \
|
||||||
cropeditor/drawing/arrowitem.cpp \
|
cropeditor/drawing/arrowitem.cpp \
|
||||||
uploaders/default/imgursettingsdialog.cpp
|
uploaders/default/imgursettingsdialog.cpp \
|
||||||
|
uploaders/default/imgplusuploader.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -107,7 +108,8 @@ HEADERS += mainwindow.hpp \
|
|||||||
cropeditor/drawing/ellipseitem.hpp \
|
cropeditor/drawing/ellipseitem.hpp \
|
||||||
hotkeyinputdialog.hpp \
|
hotkeyinputdialog.hpp \
|
||||||
cropeditor/drawing/arrowitem.hpp \
|
cropeditor/drawing/arrowitem.hpp \
|
||||||
uploaders/default/imgursettingsdialog.hpp
|
uploaders/default/imgursettingsdialog.hpp \
|
||||||
|
uploaders/default/imgplusuploader.hpp
|
||||||
|
|
||||||
LIBS += -lavcodec -lavformat -lavutil -lswscale -lavutil
|
LIBS += -lavcodec -lavformat -lavutil -lswscale -lavutil
|
||||||
|
|
||||||
|
52
uploaders/default/imgplusuploader.cpp
Normal file
52
uploaders/default/imgplusuploader.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include "imgplusuploader.hpp"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QBuffer>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QHttpMultiPart>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <formats.hpp>
|
||||||
|
#include <io/ioutils.hpp>
|
||||||
|
#include <settings.hpp>
|
||||||
|
|
||||||
|
void ImgplusUploader::doUpload(QByteArray byteArray, QString format) {
|
||||||
|
QString mime;
|
||||||
|
if (formats::normalFormatFromName(format) != formats::Normal::None)
|
||||||
|
mime = formats::normalFormatMIME(formats::normalFormatFromName(format));
|
||||||
|
else
|
||||||
|
mime = formats::recordingFormatMIME(formats::recordingFormatFromName(format));
|
||||||
|
QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||||
|
QHttpPart imagePart;
|
||||||
|
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"file\"; filename=\"image." + format + "\"");
|
||||||
|
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, mime);
|
||||||
|
QByteArray *data = new QByteArray;
|
||||||
|
data->swap(byteArray);
|
||||||
|
QBuffer *buff = new QBuffer(data);
|
||||||
|
buff->open(QIODevice::ReadOnly);
|
||||||
|
imagePart.setBodyDevice(buff);
|
||||||
|
multipart->append(imagePart);
|
||||||
|
|
||||||
|
QHttpPart keyPart;
|
||||||
|
keyPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"api_key\"");
|
||||||
|
keyPart.setBody(settings::settings().value("imgplus/apikey").toString().toUtf8());
|
||||||
|
multipart->append(keyPart);
|
||||||
|
|
||||||
|
ioutils::postMultipartData(QUrl("http://imgpl.us/api/upload"),
|
||||||
|
{ QPair<QString, QString>("Accept", "application/json") }, multipart,
|
||||||
|
[](QByteArray link, QNetworkReply *) {
|
||||||
|
QApplication::clipboard()->setText(QString::fromUtf8(link));
|
||||||
|
if (!link.startsWith("http"))
|
||||||
|
qCritical() << "Failed to upload! Copied the response to clipboard";
|
||||||
|
else
|
||||||
|
notifications::notify("KShare imgur Uploader ", "Uploaded to ImagePlus!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImgplusUploader::showSettings() {
|
||||||
|
QString text = QInputDialog::getText(0, "imgplus API key", "Enter the imgpl.us API key (Found in Settings)",
|
||||||
|
QLineEdit::Normal, settings::settings().value("imgplus/apikey").toString());
|
||||||
|
if (!text.isNull()) settings::settings().setValue("imgplus/apikey", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImgplusUploader::validate() {
|
||||||
|
return settings::settings().value("imgplus/apikey").userType() == QMetaType::QString;
|
||||||
|
}
|
19
uploaders/default/imgplusuploader.hpp
Normal file
19
uploaders/default/imgplusuploader.hpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef IMGPLUSUPLOADER_HPP
|
||||||
|
#define IMGPLUSUPLOADER_HPP
|
||||||
|
|
||||||
|
#include <uploaders/uploader.hpp>
|
||||||
|
|
||||||
|
class ImgplusUploader : public Uploader {
|
||||||
|
public:
|
||||||
|
QString name() override {
|
||||||
|
return "ImagePlus";
|
||||||
|
}
|
||||||
|
QString description() override {
|
||||||
|
return "imgpl.us uploader";
|
||||||
|
}
|
||||||
|
void doUpload(QByteArray byteArray, QString format) override;
|
||||||
|
void showSettings() override;
|
||||||
|
bool validate() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IMGPLUSUPLOADER_HPP
|
@ -11,6 +11,7 @@
|
|||||||
#include <formatter.hpp>
|
#include <formatter.hpp>
|
||||||
#include <notifications.hpp>
|
#include <notifications.hpp>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
|
#include <uploaders/default/imgplusuploader.hpp>
|
||||||
|
|
||||||
UploaderSingleton::UploaderSingleton()
|
UploaderSingleton::UploaderSingleton()
|
||||||
: QObject(), saveDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) {
|
: QObject(), saveDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) {
|
||||||
@ -37,6 +38,7 @@ UploaderSingleton::UploaderSingleton()
|
|||||||
|
|
||||||
// UPLOADERS
|
// UPLOADERS
|
||||||
registerUploader(new ImgurUploader);
|
registerUploader(new ImgurUploader);
|
||||||
|
registerUploader(new ImgplusUploader);
|
||||||
registerUploader(new ClipboardUploader);
|
registerUploader(new ClipboardUploader);
|
||||||
// ---------
|
// ---------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user