From 4a77524b059c12165e20b38de6c0d4ed08e56419 Mon Sep 17 00:00:00 2001 From: robotbrain Date: Sun, 23 Feb 2014 16:14:24 -0500 Subject: Initial stuff. It doesnt work. --- gui/MainWindow.cpp | 71 +++++++++++++++++++++++++++++- gui/MainWindow.h | 14 ++++-- gui/MainWindow.ui | 13 +++++- gui/dialogs/ScreenshotDialog.cpp | 28 ++++++++++++ gui/dialogs/ScreenshotDialog.h | 29 +++++++++++++ gui/dialogs/ScreenshotDialog.ui | 93 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+), 8 deletions(-) create mode 100644 gui/dialogs/ScreenshotDialog.cpp create mode 100644 gui/dialogs/ScreenshotDialog.h create mode 100644 gui/dialogs/ScreenshotDialog.ui (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 29f7c8e8..5a22f678 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -43,7 +43,6 @@ #include "gui/Platform.h" - #include "gui/widgets/LabeledToolButton.h" #include "gui/dialogs/SettingsDialog.h" @@ -61,6 +60,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" @@ -80,6 +80,8 @@ #include "logic/status/StatusChecker.h" #include "logic/net/URLConstants.h" +#include "logic/net/NetJob.h" +#include "logic/net/ScreenshotUploader.h" #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" @@ -143,7 +145,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); @@ -1499,3 +1500,69 @@ 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() == QDialog::Accepted) + { + QList screenshots = dialog.selected(); + if (screenshots.size() == 0) + return; + NetJob *job = new NetJob("Screenshot Upload"); + for (ScreenShot *shot : screenshots) + job->addNetAction(ScreenShotUpload::make(shot)); + ProgressDialog prog2(this); + prog2.exec(job); + connect(job, &NetJob::failed, [this] + { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), + tr("Unknown error"), QMessageBox::Warning)->exec(); + }); + connect(job, &NetJob::succeeded, [this, screenshots] + { screenshotsUploaded(screenshots); }); + } +} + +void MainWindow::screenshotsUploaded(QList screenshots) +{ + NetJob *job2 = new NetJob("Screenshot Data"); + for (ScreenShot *shot : screenshots) + { + job2->addNetAction(ScreenShotGet::make(shot)); + } + ProgressDialog prog3(this); + prog3.exec(job2); + connect(job2, &NetJob::failed, [this] + { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), + tr("Unknown error"), QMessageBox::Warning)->exec(); + }); + connect(job2, &NetJob::succeeded, [this, screenshots] + { screenShotsGotten(screenshots); }); +} + +void MainWindow::screenShotsGotten(QList screenshots) +{ + + QStringList urls; + for (ScreenShot *shot : screenshots) + { + urls << QString("url + "\">Image %s") + .arg(QString::number(shot->imgurIndex)); + } + CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), + QMessageBox::Information)->exec(); +} diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 4d9e165d..b57afcf5 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -138,7 +138,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(); public slots: @@ -167,11 +169,15 @@ slots: void updateStatusFailedUI(); void reloadStatus(); - + + void screenshotsUploaded(QList screenshots); + + void screenShotsGotten(QList screenshots); + /*! * 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); @@ -188,7 +194,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 8cf26d18..67625ac8 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -112,6 +112,8 @@ + + @@ -528,12 +530,19 @@ Launch the selected instance. + + + Upload Screenshots + + + <html><head/><body><p>View and upload screenshots for this instance</p></body></html> + + - - + diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp new file mode 100644 index 00000000..662c9e84 --- /dev/null +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -0,0 +1,28 @@ +#include "ScreenshotDialog.h" +#include "ui_ScreenshotDialog.h" +#include "QModelIndex" + +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; +} + +QList ScreenshotDialog::selected() +{ + QList list; + QList first = m_list->screenshots(); + for (QModelIndex index : ui->listView->selectionModel()->selectedIndexes()) + { + list.append(first.at(index.row())); + } + return list; +} diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h new file mode 100644 index 00000000..d3f629e7 --- /dev/null +++ b/gui/dialogs/ScreenshotDialog.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "logic/lists/ScreenshotList.h" + +class BaseInstance; + +namespace Ui +{ +class ScreenshotDialog; +} + +class ScreenshotDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0); + ~ScreenshotDialog(); + + QList selected(); + +private +slots: + +private: + Ui::ScreenshotDialog *ui; + ScreenshotList *m_list; +}; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui new file mode 100644 index 00000000..c912dffe --- /dev/null +++ b/gui/dialogs/ScreenshotDialog.ui @@ -0,0 +1,93 @@ + + + ScreenshotDialog + + + + 0 + 0 + 470 + 300 + + + + Dialog + + + + + 10 + 260 + 441 + 31 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 439 + 241 + + + + QAbstractItemView::MultiSelection + + + + 480 + 360 + + + + QListView::LeftToRight + + + true + + + QListView::ListMode + + + + + + + buttonBox + accepted() + ScreenshotDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ScreenshotDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- cgit v1.2.3