2014-07-12 15:58:23 +00:00
|
|
|
#include "GuiUtil.h"
|
|
|
|
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
#include "dialogs/ProgressDialog.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "net/PasteUpload.h"
|
2014-07-12 15:58:23 +00:00
|
|
|
#include "dialogs/CustomMessageBox.h"
|
|
|
|
|
|
|
|
void GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget)
|
|
|
|
{
|
|
|
|
ProgressDialog dialog(parentWidget);
|
2015-01-11 02:08:41 +00:00
|
|
|
std::unique_ptr<PasteUpload> paste(new PasteUpload(parentWidget, text));
|
|
|
|
|
|
|
|
if (!paste->validateText())
|
|
|
|
{
|
|
|
|
CustomMessageBox::selectable(
|
|
|
|
parentWidget, QObject::tr("Upload failed"),
|
|
|
|
QObject::tr("The log file is too big. You'll have to upload it manually."),
|
|
|
|
QMessageBox::Warning)->exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.exec(paste.get());
|
2014-07-12 15:58:23 +00:00
|
|
|
if (!paste->successful())
|
|
|
|
{
|
2015-01-11 02:08:41 +00:00
|
|
|
CustomMessageBox::selectable(parentWidget, QObject::tr("Upload failed"),
|
|
|
|
paste->failReason(), QMessageBox::Critical)->exec();
|
2014-07-12 15:58:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString link = paste->pasteLink();
|
|
|
|
setClipboardText(link);
|
|
|
|
QDesktopServices::openUrl(link);
|
|
|
|
CustomMessageBox::selectable(
|
|
|
|
parentWidget, QObject::tr("Upload finished"),
|
2015-01-11 02:08:41 +00:00
|
|
|
QObject::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),
|
2014-07-12 15:58:23 +00:00
|
|
|
QMessageBox::Information)->exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiUtil::setClipboardText(const QString &text)
|
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(text);
|
|
|
|
}
|