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.
This commit is contained in:
Petr Mrázek 2014-07-07 00:02:04 +02:00
parent 15775bd30a
commit d934e64831
4 changed files with 35 additions and 6 deletions

View File

@ -6,6 +6,8 @@
#include "ui_LogPage.h" #include "ui_LogPage.h"
#include "logic/net/PasteUpload.h" #include "logic/net/PasteUpload.h"
#include <QScrollBar> #include <QScrollBar>
#include <QtGui/QClipboard>
#include <QtGui/QDesktopServices>
QString LogPage::displayName() QString LogPage::displayName()
{ {
@ -56,6 +58,19 @@ void LogPage::on_btnPaste_clicked()
CustomMessageBox::selectable(this, "Upload failed", paste->failReason(), CustomMessageBox::selectable(this, "Upload failed", paste->failReason(),
QMessageBox::Critical)->exec(); 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 <a href=\"%1\">link to the uploaded log</a> 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) void LogPage::writeColor(QString text, const char *color, const char * background)

View File

@ -11,6 +11,8 @@
#include <QLineEdit> #include <QLineEdit>
#include <QtGui/qevent.h> #include <QtGui/qevent.h>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QClipboard>
#include <QtGui/QDesktopServices>
#include <pathutils.h> #include <pathutils.h>
@ -333,11 +335,15 @@ void ScreenshotsPage::on_uploadBtn_clicked()
} }
else else
{ {
auto link = QString("https://imgur.com/a/%1").arg(imgurAlbum->id());
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(link);
QDesktopServices::openUrl(link);
CustomMessageBox::selectable( CustomMessageBox::selectable(
this, tr("Upload finished"), this, tr("Upload finished"),
tr("<a href=\"https://imgur.com/a/%1\">Visit album</a><br/>Delete hash: %2 (save " tr("The <a href=\"%1\">link to the uploaded album</a> has been opened in the default browser and placed in your clipboard.<br/>Delete hash: %2 (save "
"this if you want to be able to edit/delete the album)") "this if you want to be able to edit/delete the album)")
.arg(imgurAlbum->id(), imgurAlbum->deleteHash()), .arg(link, imgurAlbum->deleteHash()),
QMessageBox::Information)->exec(); QMessageBox::Information)->exec();
} }
} }

View File

@ -77,9 +77,8 @@ bool PasteUpload::parseResult(QJsonDocument doc)
QLOG_ERROR() << "paste.ee reported error:" << QString(object.value("error").toString()); QLOG_ERROR() << "paste.ee reported error:" << QString(object.value("error").toString());
return false; return false;
} }
// FIXME: not the place for GUI things. m_pasteLink = object.value("paste").toObject().value("link").toString();
QString pasteUrl = object.value("paste").toObject().value("link").toString(); m_pasteID = object.value("paste").toObject().value("id").toString();
QDesktopServices::openUrl(pasteUrl);
return true; return true;
} }

View File

@ -10,7 +10,14 @@ class PasteUpload : public Task
public: public:
PasteUpload(QWidget *window, QString text); PasteUpload(QWidget *window, QString text);
virtual ~PasteUpload(){}; virtual ~PasteUpload(){};
QString pasteLink()
{
return m_pasteLink;
}
QString pasteID()
{
return m_pasteID;
}
protected: protected:
virtual void executeTask(); virtual void executeTask();
@ -19,6 +26,8 @@ private:
QString m_text; QString m_text;
QString m_error; QString m_error;
QWidget *m_window; QWidget *m_window;
QString m_pasteID;
QString m_pasteLink;
std::shared_ptr<QNetworkReply> m_reply; std::shared_ptr<QNetworkReply> m_reply;
public public
slots: slots: