summaryrefslogtreecommitdiffstats
path: root/gui
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
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')
-rw-r--r--gui/ConsoleWindow.cpp3
-rw-r--r--gui/ConsoleWindow.h1
-rw-r--r--gui/ConsoleWindow.ui7
-rw-r--r--gui/MainWindow.cpp27
-rw-r--r--gui/MainWindow.h10
-rw-r--r--gui/MainWindow.ui10
-rw-r--r--gui/dialogs/CustomMessageBox.cpp1
-rw-r--r--gui/dialogs/ScreenshotDialog.cpp78
-rw-r--r--gui/dialogs/ScreenshotDialog.h40
-rw-r--r--gui/dialogs/ScreenshotDialog.ui110
10 files changed, 281 insertions, 6 deletions
diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp
index ccc037f2..d11e8aff 100644
--- a/gui/ConsoleWindow.cpp
+++ b/gui/ConsoleWindow.cpp
@@ -42,6 +42,8 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
connect(mcproc, SIGNAL(launch_failed(BaseInstance *)), this,
SLOT(onLaunchFailed(BaseInstance *)));
+ connect(ui->btnScreenshots, &QPushButton::clicked, this, &ConsoleWindow::uploadScreenshots);
+
restoreState(
QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray()));
restoreGeometry(
@@ -52,6 +54,7 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
auto icon = MMC->icons()->getIcon(iconKey);
setWindowIcon(icon);
m_trayIcon = new QSystemTrayIcon(icon, this);
+ // TODO add screenshot upload as a menu item in the tray icon
QString consoleTitle = tr("Console window for ") + name;
m_trayIcon->setToolTip(consoleTitle);
setWindowTitle(consoleTitle);
diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h
index 7fe90c52..e21da33c 100644
--- a/gui/ConsoleWindow.h
+++ b/gui/ConsoleWindow.h
@@ -51,6 +51,7 @@ private:
signals:
void isClosing();
+ void uploadScreenshots();
public
slots:
diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui
index c2307ecc..344cf74d 100644
--- a/gui/ConsoleWindow.ui
+++ b/gui/ConsoleWindow.ui
@@ -50,6 +50,13 @@
</widget>
</item>
<item>
+ <widget class="QPushButton" name="btnScreenshots">
+ <property name="text">
+ <string>Manage Screenshots</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 121c2a73..17d4630b 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -44,7 +44,6 @@
#include "gui/Platform.h"
-
#include "gui/widgets/LabeledToolButton.h"
#include "gui/dialogs/SettingsDialog.h"
@@ -62,6 +61,7 @@
#include "gui/dialogs/AccountSelectDialog.h"
#include "gui/dialogs/UpdateDialog.h"
#include "gui/dialogs/EditAccountDialog.h"
+#include "gui/dialogs/ScreenshotDialog.h"
#include "gui/ConsoleWindow.h"
@@ -81,6 +81,7 @@
#include "logic/status/StatusChecker.h"
#include "logic/net/URLConstants.h"
+#include "logic/net/NetJob.h"
#include "logic/BaseInstance.h"
#include "logic/InstanceFactory.h"
@@ -146,7 +147,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
{
view = new GroupView(ui->centralWidget);
-
view->setSelectionMode(QAbstractItemView::SingleSelection);
// view->setCategoryDrawer(drawer);
// view->setCollapsibleBlocks(true);
@@ -1284,6 +1284,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session,
console = new ConsoleWindow(proc);
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
+ connect(console, &ConsoleWindow::uploadScreenshots, this, &MainWindow::on_actionScreenshots_triggered);
proc->setLogin(session);
proc->arm();
@@ -1600,3 +1601,25 @@ void MainWindow::checkSetDefaultJava()
MMC->settings()->set("JavaPath", QString("java"));
}
}
+
+void MainWindow::on_actionScreenshots_triggered()
+{
+ if (!m_selectedInstance)
+ return;
+ ScreenshotList *list = new ScreenshotList(m_selectedInstance);
+ Task *task = list->load();
+ ProgressDialog prog(this);
+ prog.exec(task);
+ if (!task->successful())
+ {
+ CustomMessageBox::selectable(this, tr("Failed to load screenshots!"),
+ task->failReason(), QMessageBox::Warning)->exec();
+ return;
+ }
+ ScreenshotDialog dialog(list, this);
+ if (dialog.exec() == ScreenshotDialog::Accepted)
+ {
+ CustomMessageBox::selectable(this, tr("Done uploading!"), dialog.message(),
+ QMessageBox::Information)->exec();
+ }
+}
diff --git a/gui/MainWindow.h b/gui/MainWindow.h
index 7a29977d..3a2843f8 100644
--- a/gui/MainWindow.h
+++ b/gui/MainWindow.h
@@ -139,7 +139,9 @@ slots:
// called when an icon is changed in the icon model.
void iconUpdated(QString);
- void showInstanceContextMenu(const QPoint&);
+ void showInstanceContextMenu(const QPoint &);
+
+ void on_actionScreenshots_triggered();
void updateToolsMenu();
@@ -170,11 +172,11 @@ slots:
void updateStatusFailedUI();
void reloadStatus();
-
+
/*!
* Runs the DownloadUpdateTask and installs updates.
*/
- void downloadUpdates(QString repo, int versionId, bool installOnExit=false);
+ void downloadUpdates(QString repo, int versionId, bool installOnExit = false);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
@@ -191,7 +193,7 @@ private:
ConsoleWindow *console;
LabeledToolButton *renameButton;
QToolButton *changeIconButton;
- QToolButton* newsLabel;
+ QToolButton *newsLabel;
BaseInstance *m_selectedInstance;
QString m_currentInstIcon;
diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui
index 90c86075..2bd8ec22 100644
--- a/gui/MainWindow.ui
+++ b/gui/MainWindow.ui
@@ -112,6 +112,8 @@
<addaction name="actionEditInstNotes"/>
<addaction name="actionChangeInstGroup"/>
<addaction name="separator"/>
+ <addaction name="actionScreenshots"/>
+ <addaction name="separator"/>
<addaction name="actionInstanceSettings"/>
<addaction name="actionChangeInstMCVersion"/>
<addaction name="actionChangeInstLWJGLVersion"/>
@@ -528,6 +530,14 @@
<string>Launch the selected instance.</string>
</property>
</action>
+ <action name="actionScreenshots">
+ <property name="text">
+ <string>Manage Screenshots</string>
+ </property>
+ <property name="toolTip">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;View and upload screenshots for this instance&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
diff --git a/gui/dialogs/CustomMessageBox.cpp b/gui/dialogs/CustomMessageBox.cpp
index 1d2ab58a..4013db60 100644
--- a/gui/dialogs/CustomMessageBox.cpp
+++ b/gui/dialogs/CustomMessageBox.cpp
@@ -28,6 +28,7 @@ QMessageBox *selectable(QWidget *parent, const QString &title, const QString &te
messageBox->setDefaultButton(defaultButton);
messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
messageBox->setIcon(icon);
+ messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction);
return messageBox;
}
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);
+}
diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h
new file mode 100644
index 00000000..29dd6765
--- /dev/null
+++ b/gui/dialogs/ScreenshotDialog.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <QDialog>
+#include "logic/screenshots/ScreenshotList.h"
+
+class ImgurAlbumCreation;
+
+namespace Ui
+{
+class ScreenshotDialog;
+}
+
+class ScreenshotDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0);
+ ~ScreenshotDialog();
+
+ enum
+ {
+ NothingDone = 0x42
+ };
+
+ QString message() const;
+ QList<ScreenshotPtr> selected() const;
+
+private
+slots:
+ void on_uploadBtn_clicked();
+
+ void on_deleteBtn_clicked();
+
+private:
+ Ui::ScreenshotDialog *ui;
+ ScreenshotList *m_list;
+ QList<ScreenshotPtr> m_uploaded;
+ std::shared_ptr<ImgurAlbumCreation> m_imgurAlbum;
+};
diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui
new file mode 100644
index 00000000..eb3dafba
--- /dev/null
+++ b/gui/dialogs/ScreenshotDialog.ui
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ScreenshotDialog</class>
+ <widget class="QDialog" name="ScreenshotDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>470</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Screenshot Manager</string>
+ </property>
+ <property name="windowIcon">
+ <iconset resource="../../resources/multimc/multimc.qrc">
+ <normaloff>:/icons/multimc/scalable/apps/multimc.svg</normaloff>:/icons/multimc/scalable/apps/multimc.svg</iconset>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QListView" name="listView">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectItems</enum>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>120</width>
+ <height>90</height>
+ </size>
+ </property>
+ <property name="flow">
+ <enum>QListView::LeftToRight</enum>
+ </property>
+ <property name="isWrapping" stdset="0">
+ <bool>true</bool>
+ </property>
+ <property name="resizeMode">
+ <enum>QListView::Adjust</enum>
+ </property>
+ <property name="viewMode">
+ <enum>QListView::IconMode</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="uploadBtn">
+ <property name="text">
+ <string>Upload</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteBtn">
+ <property name="text">
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeBtn">
+ <property name="text">
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="../../resources/multimc/multimc.qrc"/>
+ </resources>
+ <connections>
+ <connection>
+ <sender>closeBtn</sender>
+ <signal>clicked()</signal>
+ <receiver>ScreenshotDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>315</x>
+ <y>272</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>271</x>
+ <y>258</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>