From d934e6483190d7d173051380c62bc040911b42cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 7 Jul 2014 00:02:04 +0200 Subject: [PATCH] Tweak the response to successful uploads (screenshots, log pastes) The url will now be shown as link, put into the clipboard AND opened in a browser. At the same time. To avoid losing the URL. --- gui/pages/LogPage.cpp | 15 +++++++++++++++ gui/pages/ScreenshotsPage.cpp | 10 ++++++++-- logic/net/PasteUpload.cpp | 5 ++--- logic/net/PasteUpload.h | 11 ++++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/gui/pages/LogPage.cpp b/gui/pages/LogPage.cpp index dd088862..a9e32cc2 100644 --- a/gui/pages/LogPage.cpp +++ b/gui/pages/LogPage.cpp @@ -6,6 +6,8 @@ #include "ui_LogPage.h" #include "logic/net/PasteUpload.h" #include +#include +#include QString LogPage::displayName() { @@ -56,6 +58,19 @@ void LogPage::on_btnPaste_clicked() CustomMessageBox::selectable(this, "Upload failed", paste->failReason(), QMessageBox::Critical)->exec(); } + else + { + QString link = paste->pasteLink(); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(link); + QDesktopServices::openUrl(link); + CustomMessageBox::selectable( + this, tr("Upload finished"), + tr("The link to the uploaded log has been opened in the default browser and placed in your clipboard.") + .arg(link), + QMessageBox::Information)->exec(); + } + delete paste; } void LogPage::writeColor(QString text, const char *color, const char * background) diff --git a/gui/pages/ScreenshotsPage.cpp b/gui/pages/ScreenshotsPage.cpp index 466b3c19..ff4f0099 100644 --- a/gui/pages/ScreenshotsPage.cpp +++ b/gui/pages/ScreenshotsPage.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include @@ -333,11 +335,15 @@ void ScreenshotsPage::on_uploadBtn_clicked() } else { + auto link = QString("https://imgur.com/a/%1").arg(imgurAlbum->id()); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(link); + QDesktopServices::openUrl(link); CustomMessageBox::selectable( this, tr("Upload finished"), - tr("Visit album
Delete hash: %2 (save " + tr("The link to the uploaded album has been opened in the default browser and placed in your clipboard.
Delete hash: %2 (save " "this if you want to be able to edit/delete the album)") - .arg(imgurAlbum->id(), imgurAlbum->deleteHash()), + .arg(link, imgurAlbum->deleteHash()), QMessageBox::Information)->exec(); } } diff --git a/logic/net/PasteUpload.cpp b/logic/net/PasteUpload.cpp index ec0b2c60..ccd7dc48 100644 --- a/logic/net/PasteUpload.cpp +++ b/logic/net/PasteUpload.cpp @@ -77,9 +77,8 @@ bool PasteUpload::parseResult(QJsonDocument doc) QLOG_ERROR() << "paste.ee reported error:" << QString(object.value("error").toString()); return false; } - // FIXME: not the place for GUI things. - QString pasteUrl = object.value("paste").toObject().value("link").toString(); - QDesktopServices::openUrl(pasteUrl); + m_pasteLink = object.value("paste").toObject().value("link").toString(); + m_pasteID = object.value("paste").toObject().value("id").toString(); return true; } diff --git a/logic/net/PasteUpload.h b/logic/net/PasteUpload.h index 55cfabf4..0ddc8cef 100644 --- a/logic/net/PasteUpload.h +++ b/logic/net/PasteUpload.h @@ -10,7 +10,14 @@ class PasteUpload : public Task public: PasteUpload(QWidget *window, QString text); virtual ~PasteUpload(){}; - + QString pasteLink() + { + return m_pasteLink; + } + QString pasteID() + { + return m_pasteID; + } protected: virtual void executeTask(); @@ -19,6 +26,8 @@ private: QString m_text; QString m_error; QWidget *m_window; + QString m_pasteID; + QString m_pasteLink; std::shared_ptr m_reply; public slots: