summaryrefslogtreecommitdiffstats
path: root/application/GuiUtil.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-02-09 01:51:14 +0100
committerPetr Mrázek <peterix@gmail.com>2015-04-12 20:57:18 +0200
commitdb877ba121ff87a4e029daf8555d85dfef45993a (patch)
tree7673f83c404b3883f0a4fcf6b492f0c4125c293c /application/GuiUtil.cpp
parent4730f54df7edf4775dfddf45f77c60edd86c32d9 (diff)
downloadMultiMC-db877ba121ff87a4e029daf8555d85dfef45993a.tar
MultiMC-db877ba121ff87a4e029daf8555d85dfef45993a.tar.gz
MultiMC-db877ba121ff87a4e029daf8555d85dfef45993a.tar.lz
MultiMC-db877ba121ff87a4e029daf8555d85dfef45993a.tar.xz
MultiMC-db877ba121ff87a4e029daf8555d85dfef45993a.zip
NOISSUE move everything.
Diffstat (limited to 'application/GuiUtil.cpp')
-rw-r--r--application/GuiUtil.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/application/GuiUtil.cpp b/application/GuiUtil.cpp
new file mode 100644
index 00000000..fb42b9bc
--- /dev/null
+++ b/application/GuiUtil.cpp
@@ -0,0 +1,48 @@
+#include "GuiUtil.h"
+
+#include <QClipboard>
+#include <QDesktopServices>
+#include <QApplication>
+
+#include "dialogs/ProgressDialog.h"
+#include "net/PasteUpload.h"
+#include "dialogs/CustomMessageBox.h"
+
+void GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget)
+{
+ ProgressDialog dialog(parentWidget);
+ 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());
+ if (!paste->successful())
+ {
+ CustomMessageBox::selectable(parentWidget, QObject::tr("Upload failed"),
+ paste->failReason(), QMessageBox::Critical)->exec();
+ }
+ else
+ {
+ const QString link = paste->pasteLink();
+ setClipboardText(link);
+ QDesktopServices::openUrl(link);
+ CustomMessageBox::selectable(
+ parentWidget, QObject::tr("Upload finished"),
+ 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),
+ QMessageBox::Information)->exec();
+ }
+}
+
+void GuiUtil::setClipboardText(const QString &text)
+{
+ QApplication::clipboard()->setText(text);
+}