summaryrefslogtreecommitdiffstats
path: root/gui/dialogs/ScreenshotDialog.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-02-25 01:52:58 +0100
committerPetr Mrázek <peterix@gmail.com>2014-02-25 01:52:58 +0100
commitacff15562431d5d9e9f091ed7cf912f5fe34a61a (patch)
treee78502e7eda84696632be9b6539d386b829053b2 /gui/dialogs/ScreenshotDialog.cpp
parent49dc9695f5204bb80a91214c411bcb1b868ee0db (diff)
parent9d4e840a6e1a7169a2863fa1ff1812f8fe19e615 (diff)
downloadMultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar.gz
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar.lz
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar.xz
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.zip
Merge branch 'feature_screenshots' into integration_json_and_tools
Conflicts: logic/net/URLConstants.h Resolve issues with multiple definitions of URL constants by moving them to their own object file.
Diffstat (limited to 'gui/dialogs/ScreenshotDialog.cpp')
-rw-r--r--gui/dialogs/ScreenshotDialog.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp
new file mode 100644
index 00000000..a88c8dfd
--- /dev/null
+++ b/gui/dialogs/ScreenshotDialog.cpp
@@ -0,0 +1,78 @@
+#include "ScreenshotDialog.h"
+#include "ui_ScreenshotDialog.h"
+
+#include <QModelIndex>
+#include <QMutableListIterator>
+
+#include "ProgressDialog.h"
+#include "CustomMessageBox.h"
+#include "logic/net/NetJob.h"
+#include "logic/screenshots/ImgurUpload.h"
+#include "logic/screenshots/ImgurAlbumCreation.h"
+#include "logic/tasks/SequentialTask.h"
+
+ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent)
+ : QDialog(parent), ui(new Ui::ScreenshotDialog), m_list(list)
+{
+ ui->setupUi(this);
+ ui->listView->setModel(m_list);
+}
+
+ScreenshotDialog::~ScreenshotDialog()
+{
+ delete ui;
+}
+
+QString ScreenshotDialog::message() const
+{
+ return tr("<a href=\"https://imgur.com/a/%1\">Visit album</a><br/>Delete hash: %2 (save "
+ "this if you want to be able to edit/delete the album)")
+ .arg(m_imgurAlbum->id(), m_imgurAlbum->deleteHash());
+}
+
+QList<ScreenshotPtr> ScreenshotDialog::selected() const
+{
+ QList<ScreenshotPtr> list;
+ QList<ScreenshotPtr> first = m_list->screenshots();
+ for (QModelIndex index : ui->listView->selectionModel()->selectedRows())
+ {
+ list.append(first.at(index.row()));
+ }
+ return list;
+}
+
+void ScreenshotDialog::on_uploadBtn_clicked()
+{
+ m_uploaded = selected();
+ if (m_uploaded.isEmpty())
+ {
+ done(NothingDone);
+ return;
+ }
+ SequentialTask *task = new SequentialTask(this);
+ NetJob *job = new NetJob("Screenshot Upload");
+ for (auto shot : m_uploaded)
+ {
+ job->addNetAction(ImgurUpload::make(shot));
+ }
+ NetJob *albumTask = new NetJob("Imgur Album Creation");
+ albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded));
+ task->addTask(NetJobPtr(job));
+ task->addTask(NetJobPtr(albumTask));
+ ProgressDialog prog(this);
+ if (prog.exec(task) == QDialog::Accepted)
+ {
+ accept();
+ }
+ else
+ {
+ CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
+ tr("Unknown error"), QMessageBox::Warning)->exec();
+ reject();
+ }
+}
+
+void ScreenshotDialog::on_deleteBtn_clicked()
+{
+ m_list->deleteSelected(this);
+}