diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index dbd7a9cb..60e486ad 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -536,9 +536,9 @@ void GeneralConf::initAntialiasingPinZoom() void GeneralConf::initUploadWithoutConfirmation() { m_uploadWithoutConfirmation = - new QCheckBox(tr("Upload to Imgur without confirmation"), this); + new QCheckBox(tr("Upload image without confirmation"), this); m_uploadWithoutConfirmation->setToolTip( - tr("Upload to Imgur without confirmation")); + tr("Upload image without confirmation")); m_scrollAreaLayout->addWidget(m_uploadWithoutConfirmation); connect(m_uploadWithoutConfirmation, &QCheckBox::clicked, [](bool checked) { ConfigHandler().setUploadWithoutConfirmation(checked); diff --git a/src/core/capturerequest.cpp b/src/core/capturerequest.cpp index a639c63e..7a7250f6 100644 --- a/src/core/capturerequest.cpp +++ b/src/core/capturerequest.cpp @@ -4,10 +4,10 @@ #include "capturerequest.h" #include "confighandler.h" #include "controller.h" -#include "imguruploader.h" +#include "imgupload/imguploadermanager.h" #include "pinwidget.h" #include "src/utils/screenshotsaver.h" -#include "src/widgets/imguruploaddialog.h" +#include "src/widgets/imguploaddialog.h" #include "systemnotification.h" #include #include @@ -166,18 +166,19 @@ void CaptureRequest::exportCapture(const QPixmap& capture) if (m_tasks & UPLOAD) { if (!ConfigHandler().uploadWithoutConfirmation()) { - ImgurUploadDialog* dialog = new ImgurUploadDialog(); + ImgUploadDialog* dialog = new ImgUploadDialog(); if (dialog->exec() == QDialog::Rejected) { return; } } - ImgurUploader* widget = new ImgurUploader(capture); + + ImgUploaderBase* widget = ImgUploaderManager().uploader(capture); widget->show(); widget->activateWindow(); // NOTE: lambda can't capture 'this' because it might be destroyed later ExportTask tasks = m_tasks; QObject::connect( - widget, &ImgurUploader::uploadOk, [widget, tasks](const QUrl& url) { + widget, &ImgUploaderBase::uploadOk, [widget, tasks](const QUrl& url) { if (ConfigHandler().copyAndCloseAfterUpload()) { if (!(tasks & COPY)) { SystemNotification().sendMessage( diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 0524076c..95a13ccd 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -8,10 +8,14 @@ target_sources(flameshot PRIVATE sizeincrease/sizeincreasetool.h sizeincrease/si target_sources(flameshot PRIVATE sizedecrease/sizedecreasetool.h sizedecrease/sizedecreasetool.cpp) target_sources( flameshot - PRIVATE imgur/imguruploader.h - imgur/imguruploadertool.h - imgur/imguruploader.cpp - imgur/imguruploadertool.cpp + PRIVATE imgupload/storages/imgur/imguruploader.h + imgupload/storages/imgur/imguruploader.cpp + imgupload/storages/imguploaderbase.h + imgupload/storages/imguploaderbase.cpp + imgupload/imguploadertool.h + imgupload/imguploadertool.cpp + imgupload/imguploadermanager.h + imgupload/imguploadermanager.cpp ) target_sources( flameshot diff --git a/src/tools/imgupload/imguploadermanager.cpp b/src/tools/imgupload/imguploadermanager.cpp new file mode 100644 index 00000000..37df80c0 --- /dev/null +++ b/src/tools/imgupload/imguploadermanager.cpp @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: Yurii Puchkov & Contributors +// + +#include "imguploadermanager.h" +#include +#include + +// TODO - remove this hard-code and create plugin manager in the future, you may +// include other storage headers here +#include "storages/imgur/imguruploader.h" + +ImgUploaderManager::ImgUploaderManager(QObject* parent) + : QObject(parent) + , m_imgUploaderBase(nullptr) +{ + // TODO - implement ImgUploader for other Storages and selection among them + m_imgUploaderPlugin = IMG_UPLOADER_STORAGE_DEFAULT; + init(); +} + +void ImgUploaderManager::init() +{ + // TODO - implement ImgUploader for other Storages and selection among them, + // example: + // if (uploaderPlugin().compare("s3") == 0) { + // m_qstrUrl = ImgS3Settings().value("S3", "S3_URL").toString(); + //} else { + // m_qstrUrl = "https://imgur.com/"; + // m_imgUploaderPlugin = "imgur"; + //} + m_urlString = "https://imgur.com/"; + m_imgUploaderPlugin = "imgur"; +} + +ImgUploaderBase* ImgUploaderManager::uploader(const QPixmap& capture, + QWidget* parent) +{ + // TODO - implement ImgUploader for other Storages and selection among them, + // example: + // if (uploaderPlugin().compare("s3") == 0) { + // m_imgUploaderBase = + // (ImgUploaderBase*)(new ImgS3Uploader(capture, parent)); + //} else { + // m_imgUploaderBase = + // (ImgUploaderBase*)(new ImgurUploader(capture, parent)); + //} + m_imgUploaderBase = (ImgUploaderBase*)(new ImgurUploader(capture, parent)); + if (m_imgUploaderBase && !capture.isNull()) { + m_imgUploaderBase->upload(); + } + return m_imgUploaderBase; +} + +ImgUploaderBase* ImgUploaderManager::uploader(const QString& imgUploaderPlugin) +{ + m_imgUploaderPlugin = imgUploaderPlugin; + init(); + return uploader(QPixmap()); +} + +const QString& ImgUploaderManager::uploaderPlugin() +{ + return m_imgUploaderPlugin; +} + +const QString& ImgUploaderManager::url() +{ + return m_urlString; +} diff --git a/src/tools/imgupload/imguploadermanager.h b/src/tools/imgupload/imguploadermanager.h new file mode 100644 index 00000000..9b6f214c --- /dev/null +++ b/src/tools/imgupload/imguploadermanager.h @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: Yurii Puchkov & Contributors +// + +#ifndef FLAMESHOT_IMGUPLOADERMANAGER_H +#define FLAMESHOT_IMGUPLOADERMANAGER_H + +#include "src/tools/imgupload/storages/imguploaderbase.h" +#include + +#define IMG_UPLOADER_STORAGE_DEFAULT "imgur" + +class QPixmap; +class QWidget; + +class ImgUploaderManager : public QObject +{ + Q_OBJECT +public: + explicit ImgUploaderManager(QObject* parent = nullptr); + + ImgUploaderBase* uploader(const QPixmap& capture, + QWidget* parent = nullptr); + ImgUploaderBase* uploader(const QString& imgUploaderPlugin); + + const QString& url(); + const QString& uploaderPlugin(); + +private: + void init(); + +private: + ImgUploaderBase* m_imgUploaderBase; + QString m_urlString; + QString m_imgUploaderPlugin; +}; + +#endif // FLAMESHOT_IMGUPLOADERMANAGER_H diff --git a/src/tools/imgupload/imguploadertool.cpp b/src/tools/imgupload/imguploadertool.cpp new file mode 100644 index 00000000..5623dc1b --- /dev/null +++ b/src/tools/imgupload/imguploadertool.cpp @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors + +#include "imguploadertool.h" + +ImgUploaderTool::ImgUploaderTool(QObject* parent) + : AbstractActionTool(parent) +{} + +bool ImgUploaderTool::closeOnButtonPressed() const +{ + return true; +} + +QIcon ImgUploaderTool::icon(const QColor& background, bool inEditor) const +{ + Q_UNUSED(inEditor); + return QIcon(iconPath(background) + "cloud-upload.svg"); +} + +QString ImgUploaderTool::name() const +{ + return tr("Image Uploader"); +} + +CaptureTool::Type ImgUploaderTool::type() const +{ + return CaptureTool::TYPE_IMAGEUPLOADER; +} + +QString ImgUploaderTool::description() const +{ + return tr("Upload the selection"); +} + +CaptureTool* ImgUploaderTool::copy(QObject* parent) +{ + return new ImgUploaderTool(parent); +} + +void ImgUploaderTool::pressed(CaptureContext& context) +{ + emit requestAction(REQ_CAPTURE_DONE_OK); + context.request()->addTask(CaptureRequest::UPLOAD); + emit requestAction(REQ_CLOSE_GUI); +} diff --git a/src/tools/imgur/imguruploadertool.h b/src/tools/imgupload/imguploadertool.h similarity index 84% rename from src/tools/imgur/imguruploadertool.h rename to src/tools/imgupload/imguploadertool.h index 372e8007..72b0b00e 100644 --- a/src/tools/imgur/imguruploadertool.h +++ b/src/tools/imgupload/imguploadertool.h @@ -5,11 +5,11 @@ #include "src/tools/abstractactiontool.h" -class ImgurUploaderTool : public AbstractActionTool +class ImgUploaderTool : public AbstractActionTool { Q_OBJECT public: - explicit ImgurUploaderTool(QObject* parent = nullptr); + explicit ImgUploaderTool(QObject* parent = nullptr); bool closeOnButtonPressed() const override; diff --git a/src/tools/imgur/imguruploader.cpp b/src/tools/imgupload/storages/imguploaderbase.cpp similarity index 51% rename from src/tools/imgur/imguruploader.cpp rename to src/tools/imgupload/storages/imguploaderbase.cpp index 9a222254..f9367dd2 100644 --- a/src/tools/imgur/imguruploader.cpp +++ b/src/tools/imgupload/storages/imguploaderbase.cpp @@ -1,30 +1,24 @@ // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors -#include "imguruploader.h" +#include "imguploaderbase.h" #include "src/utils/confighandler.h" -#include "src/utils/filenamehandler.h" #include "src/utils/globalvalues.h" #include "src/utils/history.h" -#include "src/utils/systemnotification.h" #include "src/widgets/imagelabel.h" #include "src/widgets/loadspinner.h" #include "src/widgets/notificationwidget.h" #include -#include #include #include #include #include #include -#include #include #include #include #include #include -#include -#include #include #include #include @@ -33,11 +27,11 @@ #include #include -ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent) +ImgUploaderBase::ImgUploaderBase(const QPixmap& capture, QWidget* parent) : QWidget(parent) , m_pixmap(capture) { - setWindowTitle(tr("Upload to Imgur")); + setWindowTitle(tr("Upload image")); setWindowIcon(QIcon(GlobalValues::iconPath())); #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) @@ -60,52 +54,45 @@ ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent) m_vLayout->addWidget(m_spinner, 0, Qt::AlignHCenter); m_vLayout->addWidget(m_infoLabel); - m_NetworkAM = new QNetworkAccessManager(this); - connect(m_NetworkAM, - &QNetworkAccessManager::finished, - this, - &ImgurUploader::handleReply); - setAttribute(Qt::WA_DeleteOnClose); - - upload(); - // QTimer::singleShot(2000, this, &ImgurUploader::showPostUploadDialog); // - // testing } -void ImgurUploader::handleReply(QNetworkReply* reply) +LoadSpinner* ImgUploaderBase::spinner() { - m_spinner->deleteLater(); - if (reply->error() == QNetworkReply::NoError) { - QJsonDocument response = QJsonDocument::fromJson(reply->readAll()); - QJsonObject json = response.object(); - QJsonObject data = json[QStringLiteral("data")].toObject(); - m_imageURL.setUrl(data[QStringLiteral("link")].toString()); - - auto deleteToken = data[QStringLiteral("deletehash")].toString(); - m_deleteImageURL.setUrl( - QStringLiteral("https://imgur.com/delete/%1").arg(deleteToken)); - - // save history - QString imageName = m_imageURL.toString(); - int lastSlash = imageName.lastIndexOf("/"); - if (lastSlash >= 0) { - imageName = imageName.mid(lastSlash + 1); - } - - // save image to history - History history; - imageName = history.packFileName("imgur", deleteToken, imageName); - history.save(m_pixmap, imageName); - - emit uploadOk(m_imageURL); - } else { - m_infoLabel->setText(reply->errorString()); - } - new QShortcut(Qt::Key_Escape, this, SLOT(close())); + return m_spinner; } -void ImgurUploader::startDrag() +const QUrl& ImgUploaderBase::imageURL() +{ + return m_imageURL; +} + +void ImgUploaderBase::setImageURL(const QUrl& imageURL) +{ + m_imageURL = imageURL; +} + +const QPixmap& ImgUploaderBase::pixmap() +{ + return m_pixmap; +} + +void ImgUploaderBase::setPixmap(const QPixmap& pixmap) +{ + m_pixmap = pixmap; +} + +NotificationWidget* ImgUploaderBase::notification() +{ + return m_notification; +} + +void ImgUploaderBase::setInfoLabelText(const QString& text) +{ + m_infoLabel->setText(text); +} + +void ImgUploaderBase::startDrag() { QMimeData* mimeData = new QMimeData; mimeData->setUrls(QList{ m_imageURL }); @@ -118,30 +105,7 @@ void ImgurUploader::startDrag() dragHandler->exec(); } -void ImgurUploader::upload() -{ - QByteArray byteArray; - QBuffer buffer(&byteArray); - m_pixmap.save(&buffer, "PNG"); - - QUrlQuery urlQuery; - urlQuery.addQueryItem(QStringLiteral("title"), QStringLiteral("")); - QString description = FileNameHandler().parsedPattern(); - urlQuery.addQueryItem(QStringLiteral("description"), description); - - QUrl url(QStringLiteral("https://api.imgur.com/3/image")); - url.setQuery(urlQuery); - QNetworkRequest request(url); - request.setHeader(QNetworkRequest::ContentTypeHeader, - "application/application/x-www-form-urlencoded"); - request.setRawHeader( - "Authorization", - QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8()); - - m_NetworkAM->post(request, byteArray); -} - -void ImgurUploader::showPostUploadDialog() +void ImgUploaderBase::showPostUploadDialog() { m_infoLabel->deleteLater(); @@ -151,8 +115,10 @@ void ImgurUploader::showPostUploadDialog() ImageLabel* imageLabel = new ImageLabel(); imageLabel->setScreenshot(m_pixmap); imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - connect( - imageLabel, &ImageLabel::dragInitiated, this, &ImgurUploader::startDrag); + connect(imageLabel, + &ImageLabel::dragInitiated, + this, + &ImgUploaderBase::startDrag); m_vLayout->addWidget(imageLabel); m_hLayout = new QHBoxLayout(); @@ -168,20 +134,20 @@ void ImgurUploader::showPostUploadDialog() m_hLayout->addWidget(m_toClipboardButton); connect( - m_copyUrlButton, &QPushButton::clicked, this, &ImgurUploader::copyURL); + m_copyUrlButton, &QPushButton::clicked, this, &ImgUploaderBase::copyURL); connect( - m_openUrlButton, &QPushButton::clicked, this, &ImgurUploader::openURL); + m_openUrlButton, &QPushButton::clicked, this, &ImgUploaderBase::openURL); connect(m_openDeleteUrlButton, &QPushButton::clicked, this, - &ImgurUploader::openDeleteURL); + &ImgUploaderBase::deleteCurrentImage); connect(m_toClipboardButton, &QPushButton::clicked, this, - &ImgurUploader::copyImage); + &ImgUploaderBase::copyImage); } -void ImgurUploader::openURL() +void ImgUploaderBase::openURL() { bool successful = QDesktopServices::openUrl(m_imageURL); if (!successful) { @@ -189,22 +155,22 @@ void ImgurUploader::openURL() } } -void ImgurUploader::copyURL() +void ImgUploaderBase::copyURL() { QApplication::clipboard()->setText(m_imageURL.toString()); m_notification->showMessage(tr("URL copied to clipboard.")); } -void ImgurUploader::openDeleteURL() -{ - bool successful = QDesktopServices::openUrl(m_deleteImageURL); - if (!successful) { - m_notification->showMessage(tr("Unable to open the URL.")); - } -} - -void ImgurUploader::copyImage() +void ImgUploaderBase::copyImage() { QApplication::clipboard()->setPixmap(m_pixmap); m_notification->showMessage(tr("Screenshot copied to clipboard.")); } + +void ImgUploaderBase::deleteCurrentImage() +{ + History history; + HISTORY_FILE_NAME unpackFileName = + history.unpackFileName(m_currentImageName); + deleteImage(unpackFileName.file, unpackFileName.token); +} \ No newline at end of file diff --git a/src/tools/imgur/imguruploader.h b/src/tools/imgupload/storages/imguploaderbase.h similarity index 61% rename from src/tools/imgur/imguruploader.h rename to src/tools/imgupload/storages/imguploaderbase.h index 6c41b917..09316b8a 100644 --- a/src/tools/imgur/imguruploader.h +++ b/src/tools/imgupload/storages/imguploaderbase.h @@ -16,30 +16,41 @@ class QPushButton; class QUrl; class NotificationWidget; -class ImgurUploader : public QWidget +class ImgUploaderBase : public QWidget { Q_OBJECT public: - explicit ImgurUploader(const QPixmap& capture, QWidget* parent = nullptr); + explicit ImgUploaderBase(const QPixmap& capture, QWidget* parent = nullptr); + + LoadSpinner* spinner(); + + const QUrl& imageURL(); + void setImageURL(const QUrl&); + const QPixmap& pixmap(); + void setPixmap(const QPixmap&); + void setInfoLabelText(const QString&); + + NotificationWidget* notification(); + virtual void deleteImage(const QString& fileName, + const QString& deleteToken) = 0; + virtual void upload() = 0; signals: void uploadOk(const QUrl& url); + void deleteOk(); public slots: void showPostUploadDialog(); private slots: - void handleReply(QNetworkReply* reply); void startDrag(); - void openURL(); void copyURL(); - void openDeleteURL(); void copyImage(); + void deleteCurrentImage(); private: QPixmap m_pixmap; - QNetworkAccessManager* m_NetworkAM; QVBoxLayout* m_vLayout; QHBoxLayout* m_hLayout; @@ -52,8 +63,8 @@ private: QPushButton* m_copyUrlButton; QPushButton* m_toClipboardButton; QUrl m_imageURL; - QUrl m_deleteImageURL; NotificationWidget* m_notification; - void upload(); +public: + QString m_currentImageName; }; diff --git a/src/tools/imgupload/storages/imgur/imguruploader.cpp b/src/tools/imgupload/storages/imgur/imguruploader.cpp new file mode 100644 index 00000000..bb14b15f --- /dev/null +++ b/src/tools/imgupload/storages/imgur/imguruploader.cpp @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors + +#include "imguruploader.h" +#include "src/utils/confighandler.h" +#include "src/utils/filenamehandler.h" +#include "src/utils/history.h" +#include "src/widgets/loadspinner.h" +#include "src/widgets/notificationwidget.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent) + : ImgUploaderBase(capture, parent) +{ + m_NetworkAM = new QNetworkAccessManager(this); + connect(m_NetworkAM, + &QNetworkAccessManager::finished, + this, + &ImgurUploader::handleReply); +} + +void ImgurUploader::handleReply(QNetworkReply* reply) +{ + spinner()->deleteLater(); + m_currentImageName.clear(); + if (reply->error() == QNetworkReply::NoError) { + QJsonDocument response = QJsonDocument::fromJson(reply->readAll()); + QJsonObject json = response.object(); + QJsonObject data = json[QStringLiteral("data")].toObject(); + setImageURL(data[QStringLiteral("link")].toString()); + + auto deleteToken = data[QStringLiteral("deletehash")].toString(); + + // save history + m_currentImageName = imageURL().toString(); + int lastSlash = m_currentImageName.lastIndexOf("/"); + if (lastSlash >= 0) { + m_currentImageName = m_currentImageName.mid(lastSlash + 1); + } + + // save image to history + History history; + m_currentImageName = + history.packFileName("imgur", deleteToken, m_currentImageName); + history.save(pixmap(), m_currentImageName); + + emit uploadOk(imageURL()); + } else { + setInfoLabelText(reply->errorString()); + } + new QShortcut(Qt::Key_Escape, this, SLOT(close())); +} + +void ImgurUploader::upload() +{ + QByteArray byteArray; + QBuffer buffer(&byteArray); + pixmap().save(&buffer, "PNG"); + + QUrlQuery urlQuery; + urlQuery.addQueryItem(QStringLiteral("title"), QStringLiteral("")); + QString description = FileNameHandler().parsedPattern(); + urlQuery.addQueryItem(QStringLiteral("description"), description); + + QUrl url(QStringLiteral("https://api.imgur.com/3/image")); + url.setQuery(urlQuery); + QNetworkRequest request(url); + request.setHeader(QNetworkRequest::ContentTypeHeader, + "application/application/x-www-form-urlencoded"); + request.setRawHeader( + "Authorization", + QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8()); + + m_NetworkAM->post(request, byteArray); +} + +void ImgurUploader::deleteImage(const QString& fileName, + const QString& deleteToken) +{ + Q_UNUSED(fileName) + bool successful = QDesktopServices::openUrl( + QUrl(QStringLiteral("https://imgur.com/delete/%1").arg(deleteToken))); + if (!successful) { + notification()->showMessage(tr("Unable to open the URL.")); + } + + emit deleteOk(); +} diff --git a/src/tools/imgupload/storages/imgur/imguruploader.h b/src/tools/imgupload/storages/imgur/imguruploader.h new file mode 100644 index 00000000..69f9f1ef --- /dev/null +++ b/src/tools/imgupload/storages/imgur/imguruploader.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors + +#pragma once + +#include "src/tools/imgupload/storages/imguploaderbase.h" +#include +#include + +class QNetworkReply; +class QNetworkAccessManager; +class QUrl; + +class ImgurUploader : public ImgUploaderBase +{ + Q_OBJECT +public: + explicit ImgurUploader(const QPixmap& capture, QWidget* parent = nullptr); + void deleteImage(const QString& fileName, const QString& deleteToken); + +private slots: + void handleReply(QNetworkReply* reply); + +private: + void upload(); + +private: + QNetworkAccessManager* m_NetworkAM; +}; diff --git a/src/tools/imgur/imguruploadertool.cpp b/src/tools/imgur/imguruploadertool.cpp deleted file mode 100644 index 47929497..00000000 --- a/src/tools/imgur/imguruploadertool.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors - -#include "imguruploadertool.h" -#include "imguruploader.h" -#include - -ImgurUploaderTool::ImgurUploaderTool(QObject* parent) - : AbstractActionTool(parent) -{} - -bool ImgurUploaderTool::closeOnButtonPressed() const -{ - return true; -} - -QIcon ImgurUploaderTool::icon(const QColor& background, bool inEditor) const -{ - Q_UNUSED(inEditor); - return QIcon(iconPath(background) + "cloud-upload.svg"); -} - -QString ImgurUploaderTool::name() const -{ - return tr("Image Uploader"); -} - -CaptureTool::Type ImgurUploaderTool::type() const -{ - return CaptureTool::TYPE_IMAGEUPLOADER; -} - -QString ImgurUploaderTool::description() const -{ - return tr("Upload the selection to Imgur"); -} - -CaptureTool* ImgurUploaderTool::copy(QObject* parent) -{ - return new ImgurUploaderTool(parent); -} - -void ImgurUploaderTool::pressed(CaptureContext& context) -{ - emit requestAction(REQ_CAPTURE_DONE_OK); - context.request()->addTask(CaptureRequest::UPLOAD); - emit requestAction(REQ_CLOSE_GUI); -} diff --git a/src/tools/toolfactory.cpp b/src/tools/toolfactory.cpp index c442aca2..edeb2bc0 100644 --- a/src/tools/toolfactory.cpp +++ b/src/tools/toolfactory.cpp @@ -8,7 +8,7 @@ #include "circlecount/circlecounttool.h" #include "copy/copytool.h" #include "exit/exittool.h" -#include "imgur/imguruploadertool.h" +#include "imgupload/imguploadertool.h" #include "invert/inverttool.h" #include "launcher/applaunchertool.h" #include "line/linetool.h" @@ -24,7 +24,6 @@ #include "sizedecrease/sizedecreasetool.h" #include "sizeincrease/sizeincreasetool.h" #include "sizeindicator/sizeindicatortool.h" -#include "src/utils/confighandler.h" #include "text/texttool.h" #include "undo/undotool.h" @@ -52,7 +51,7 @@ CaptureTool* ToolFactory::CreateTool(CaptureTool::Type t, QObject* parent) if_TYPE_return_TOOL(TYPE_COPY, CopyTool); if_TYPE_return_TOOL(TYPE_SAVE, SaveTool); if_TYPE_return_TOOL(TYPE_EXIT, ExitTool); - if_TYPE_return_TOOL(TYPE_IMAGEUPLOADER, ImgurUploaderTool); + if_TYPE_return_TOOL(TYPE_IMAGEUPLOADER, ImgUploaderTool); #if !defined(Q_OS_MACOS) if_TYPE_return_TOOL(TYPE_OPEN_APP, AppLauncher); #endif diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 62a5f930..e649d340 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -13,7 +13,7 @@ target_sources( orientablepushbutton.h historywidget.h updatenotificationwidget.h - imguruploaddialog.h + imguploaddialog.h capture/capturetoolobjects.h ) @@ -28,6 +28,6 @@ target_sources( orientablepushbutton.cpp historywidget.cpp updatenotificationwidget.cpp - imguruploaddialog.cpp + imguploaddialog.cpp capture/capturetoolobjects.cpp ) diff --git a/src/widgets/historywidget.cpp b/src/widgets/historywidget.cpp index 5240582d..84c05477 100644 --- a/src/widgets/historywidget.cpp +++ b/src/widgets/historywidget.cpp @@ -1,4 +1,5 @@ #include "historywidget.h" +#include "src/tools/imgupload/imguploadermanager.h" #include "src/utils/confighandler.h" #include "src/utils/globalvalues.h" #include "src/utils/history.h" @@ -18,6 +19,7 @@ #include #include #include + HistoryWidget::HistoryWidget(QWidget* parent) : QDialog(parent) { @@ -101,7 +103,7 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName) History history; HISTORY_FILE_NAME unpackFileName = history.unpackFileName(fileName); - QString url = "https://imgur.com/" + unpackFileName.file; + QString url = ImgUploaderManager(this).url() + unpackFileName.file; // load pixmap QPixmap pixmap; @@ -170,9 +172,11 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName) QMessageBox::Yes | QMessageBox::No)) { return; } - QDesktopServices::openUrl( - QUrl(QStringLiteral("https://imgur.com/delete/%1") - .arg(unpackFileName.token))); + + ImgUploaderBase* imgUploaderBase = + ImgUploaderManager(this).uploader(unpackFileName.type); + imgUploaderBase->deleteImage(unpackFileName.file, unpackFileName.token); + removeCacheFile(fullFileName); removeLayoutItem(phbl); }); diff --git a/src/widgets/imguruploaddialog.cpp b/src/widgets/imguploaddialog.cpp similarity index 75% rename from src/widgets/imguruploaddialog.cpp rename to src/widgets/imguploaddialog.cpp index 1d76e228..6fc46ca4 100644 --- a/src/widgets/imguruploaddialog.cpp +++ b/src/widgets/imguploaddialog.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors -#include "imguruploaddialog.h" +#include "imguploaddialog.h" #include "src/utils/confighandler.h" #include "src/utils/globalvalues.h" #include @@ -9,7 +9,7 @@ #include #include -ImgurUploadDialog::ImgurUploadDialog(QDialog* parent) +ImgUploadDialog::ImgUploadDialog(QDialog* parent) : QDialog(parent) { setAttribute(Qt::WA_DeleteOnClose); @@ -19,8 +19,7 @@ ImgurUploadDialog::ImgurUploadDialog(QDialog* parent) layout = new QVBoxLayout(this); - m_uploadLabel = - new QLabel(tr("Do you want to upload this capture to Imgur?"), this); + m_uploadLabel = new QLabel(tr("Do you want to upload this capture?"), this); layout->addWidget(m_uploadLabel); @@ -33,9 +32,8 @@ ImgurUploadDialog::ImgurUploadDialog(QDialog* parent) layout->addWidget(buttonBox); m_uploadWithoutConfirmation = - new QCheckBox(tr("Upload to Imgur without confirmation"), this); - m_uploadWithoutConfirmation->setToolTip( - tr("Upload to Imgur without confirmation")); + new QCheckBox(tr("Upload without confirmation"), this); + m_uploadWithoutConfirmation->setToolTip(tr("Upload without confirmation")); connect(m_uploadWithoutConfirmation, &QCheckBox::clicked, [](bool checked) { ConfigHandler().setUploadWithoutConfirmation(checked); }); diff --git a/src/widgets/imguruploaddialog.h b/src/widgets/imguploaddialog.h similarity index 79% rename from src/widgets/imguruploaddialog.h rename to src/widgets/imguploaddialog.h index 61490c84..d2ed4444 100644 --- a/src/widgets/imguruploaddialog.h +++ b/src/widgets/imguploaddialog.h @@ -10,11 +10,11 @@ class QLabel; class QDialogButtonBox; class QVBoxLayout; -class ImgurUploadDialog : public QDialog +class ImgUploadDialog : public QDialog { Q_OBJECT public: - explicit ImgurUploadDialog(QDialog* parent = nullptr); + explicit ImgUploadDialog(QDialog* parent = nullptr); private: QCheckBox* m_uploadWithoutConfirmation;