Initial stuff. It doesnt work.

This commit is contained in:
robotbrain
2014-02-23 16:14:24 -05:00
parent 5cf599673d
commit 4a77524b05
12 changed files with 744 additions and 151 deletions

View File

@ -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<ScreenShot *> 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<ScreenShot *> 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<ScreenShot *> screenshots)
{
QStringList urls;
for (ScreenShot *shot : screenshots)
{
urls << QString("<a href=\"" + shot->url + "\">Image %s</a>")
.arg(QString::number(shot->imgurIndex));
}
CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"),
QMessageBox::Information)->exec();
}

View File

@ -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<class ScreenShot*> screenshots);
void screenShotsGotten(QList<class ScreenShot*> 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;

View File

@ -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,12 +530,19 @@
<string>Launch the selected instance.</string>
</property>
</action>
<action name="actionScreenshots">
<property name="text">
<string>Upload 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>
<include location="../resources/instances/instances.qrc"/>
<include location="../resources/multimc/multimc.qrc"/>
<include location="../resources/backgrounds/backgrounds.qrc"/>
<include location="../resources/instances/instances.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -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<ScreenShot*> ScreenshotDialog::selected()
{
QList<ScreenShot*> list;
QList<ScreenShot*> first = m_list->screenshots();
for (QModelIndex index : ui->listView->selectionModel()->selectedIndexes())
{
list.append(first.at(index.row()));
}
return list;
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <QDialog>
#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<ScreenShot *> selected();
private
slots:
private:
Ui::ScreenshotDialog *ui;
ScreenshotList *m_list;
};

View File

@ -0,0 +1,93 @@
<?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>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>10</x>
<y>260</y>
<width>441</width>
<height>31</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QListView" name="listView">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>439</width>
<height>241</height>
</rect>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="iconSize">
<size>
<width>480</width>
<height>360</height>
</size>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="viewMode">
<enum>QListView::ListMode</enum>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ScreenshotDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ScreenshotDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>