Initial stuff. It doesnt work.
This commit is contained in:
parent
5cf599673d
commit
4a77524b05
@ -308,6 +308,8 @@ gui/dialogs/AccountSelectDialog.h
|
|||||||
gui/dialogs/AccountSelectDialog.cpp
|
gui/dialogs/AccountSelectDialog.cpp
|
||||||
gui/dialogs/UpdateDialog.h
|
gui/dialogs/UpdateDialog.h
|
||||||
gui/dialogs/UpdateDialog.cpp
|
gui/dialogs/UpdateDialog.cpp
|
||||||
|
gui/dialogs/ScreenshotDialog.h
|
||||||
|
gui/dialogs/ScreenshotDialog.cpp
|
||||||
|
|
||||||
# GUI - widgets
|
# GUI - widgets
|
||||||
gui/widgets/Common.h
|
gui/widgets/Common.h
|
||||||
@ -370,6 +372,8 @@ logic/net/HttpMetaCache.cpp
|
|||||||
logic/net/PasteUpload.h
|
logic/net/PasteUpload.h
|
||||||
logic/net/PasteUpload.cpp
|
logic/net/PasteUpload.cpp
|
||||||
logic/net/URLConstants.h
|
logic/net/URLConstants.h
|
||||||
|
logic/net/ScreenshotUploader.h
|
||||||
|
logic/net/ScreenshotUploader.cpp
|
||||||
|
|
||||||
# Yggdrasil login stuff
|
# Yggdrasil login stuff
|
||||||
logic/auth/AuthSession.h
|
logic/auth/AuthSession.h
|
||||||
@ -460,6 +464,8 @@ logic/lists/ForgeVersionList.h
|
|||||||
logic/lists/ForgeVersionList.cpp
|
logic/lists/ForgeVersionList.cpp
|
||||||
logic/lists/JavaVersionList.h
|
logic/lists/JavaVersionList.h
|
||||||
logic/lists/JavaVersionList.cpp
|
logic/lists/JavaVersionList.cpp
|
||||||
|
logic/lists/ScreenshotList.h
|
||||||
|
logic/lists/ScreenshotList.cpp
|
||||||
|
|
||||||
# Icons
|
# Icons
|
||||||
logic/icons/MMCIcon.h
|
logic/icons/MMCIcon.h
|
||||||
@ -525,6 +531,7 @@ gui/dialogs/AccountListDialog.ui
|
|||||||
gui/dialogs/AccountSelectDialog.ui
|
gui/dialogs/AccountSelectDialog.ui
|
||||||
gui/dialogs/EditAccountDialog.ui
|
gui/dialogs/EditAccountDialog.ui
|
||||||
gui/dialogs/UpdateDialog.ui
|
gui/dialogs/UpdateDialog.ui
|
||||||
|
gui/dialogs/ScreenshotDialog.ui
|
||||||
|
|
||||||
# Widgets/other
|
# Widgets/other
|
||||||
gui/widgets/MCModInfoFrame.ui
|
gui/widgets/MCModInfoFrame.ui
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
|
|
||||||
#include "gui/Platform.h"
|
#include "gui/Platform.h"
|
||||||
|
|
||||||
|
|
||||||
#include "gui/widgets/LabeledToolButton.h"
|
#include "gui/widgets/LabeledToolButton.h"
|
||||||
|
|
||||||
#include "gui/dialogs/SettingsDialog.h"
|
#include "gui/dialogs/SettingsDialog.h"
|
||||||
@ -61,6 +60,7 @@
|
|||||||
#include "gui/dialogs/AccountSelectDialog.h"
|
#include "gui/dialogs/AccountSelectDialog.h"
|
||||||
#include "gui/dialogs/UpdateDialog.h"
|
#include "gui/dialogs/UpdateDialog.h"
|
||||||
#include "gui/dialogs/EditAccountDialog.h"
|
#include "gui/dialogs/EditAccountDialog.h"
|
||||||
|
#include "gui/dialogs/ScreenshotDialog.h"
|
||||||
|
|
||||||
#include "gui/ConsoleWindow.h"
|
#include "gui/ConsoleWindow.h"
|
||||||
|
|
||||||
@ -80,6 +80,8 @@
|
|||||||
#include "logic/status/StatusChecker.h"
|
#include "logic/status/StatusChecker.h"
|
||||||
|
|
||||||
#include "logic/net/URLConstants.h"
|
#include "logic/net/URLConstants.h"
|
||||||
|
#include "logic/net/NetJob.h"
|
||||||
|
#include "logic/net/ScreenshotUploader.h"
|
||||||
|
|
||||||
#include "logic/BaseInstance.h"
|
#include "logic/BaseInstance.h"
|
||||||
#include "logic/InstanceFactory.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 = new GroupView(ui->centralWidget);
|
||||||
|
|
||||||
|
|
||||||
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
// view->setCategoryDrawer(drawer);
|
// view->setCategoryDrawer(drawer);
|
||||||
// view->setCollapsibleBlocks(true);
|
// view->setCollapsibleBlocks(true);
|
||||||
@ -1499,3 +1500,69 @@ void MainWindow::checkSetDefaultJava()
|
|||||||
MMC->settings()->set("JavaPath", QString("java"));
|
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();
|
||||||
|
}
|
||||||
|
@ -138,7 +138,9 @@ slots:
|
|||||||
// called when an icon is changed in the icon model.
|
// called when an icon is changed in the icon model.
|
||||||
void iconUpdated(QString);
|
void iconUpdated(QString);
|
||||||
|
|
||||||
void showInstanceContextMenu(const QPoint&);
|
void showInstanceContextMenu(const QPoint &);
|
||||||
|
|
||||||
|
void on_actionScreenshots_triggered();
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
@ -168,10 +170,14 @@ slots:
|
|||||||
|
|
||||||
void reloadStatus();
|
void reloadStatus();
|
||||||
|
|
||||||
|
void screenshotsUploaded(QList<class ScreenShot*> screenshots);
|
||||||
|
|
||||||
|
void screenShotsGotten(QList<class ScreenShot*> screenshots);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Runs the DownloadUpdateTask and installs updates.
|
* 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:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *ev);
|
bool eventFilter(QObject *obj, QEvent *ev);
|
||||||
@ -188,7 +194,7 @@ private:
|
|||||||
ConsoleWindow *console;
|
ConsoleWindow *console;
|
||||||
LabeledToolButton *renameButton;
|
LabeledToolButton *renameButton;
|
||||||
QToolButton *changeIconButton;
|
QToolButton *changeIconButton;
|
||||||
QToolButton* newsLabel;
|
QToolButton *newsLabel;
|
||||||
|
|
||||||
BaseInstance *m_selectedInstance;
|
BaseInstance *m_selectedInstance;
|
||||||
QString m_currentInstIcon;
|
QString m_currentInstIcon;
|
||||||
|
@ -112,6 +112,8 @@
|
|||||||
<addaction name="actionEditInstNotes"/>
|
<addaction name="actionEditInstNotes"/>
|
||||||
<addaction name="actionChangeInstGroup"/>
|
<addaction name="actionChangeInstGroup"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionScreenshots"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionInstanceSettings"/>
|
<addaction name="actionInstanceSettings"/>
|
||||||
<addaction name="actionChangeInstMCVersion"/>
|
<addaction name="actionChangeInstMCVersion"/>
|
||||||
<addaction name="actionChangeInstLWJGLVersion"/>
|
<addaction name="actionChangeInstLWJGLVersion"/>
|
||||||
@ -528,12 +530,19 @@
|
|||||||
<string>Launch the selected instance.</string>
|
<string>Launch the selected instance.</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionScreenshots">
|
||||||
|
<property name="text">
|
||||||
|
<string>Upload Screenshots</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>View and upload screenshots for this instance</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../resources/instances/instances.qrc"/>
|
|
||||||
<include location="../resources/multimc/multimc.qrc"/>
|
<include location="../resources/multimc/multimc.qrc"/>
|
||||||
<include location="../resources/backgrounds/backgrounds.qrc"/>
|
<include location="../resources/instances/instances.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
28
gui/dialogs/ScreenshotDialog.cpp
Normal file
28
gui/dialogs/ScreenshotDialog.cpp
Normal 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;
|
||||||
|
}
|
29
gui/dialogs/ScreenshotDialog.h
Normal file
29
gui/dialogs/ScreenshotDialog.h
Normal 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;
|
||||||
|
};
|
93
gui/dialogs/ScreenshotDialog.ui
Normal file
93
gui/dialogs/ScreenshotDialog.ui
Normal 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>
|
81
logic/lists/ScreenshotList.cpp
Normal file
81
logic/lists/ScreenshotList.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#include "ScreenshotList.h"
|
||||||
|
#include "QDir"
|
||||||
|
#include "QPixmap"
|
||||||
|
|
||||||
|
ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent)
|
||||||
|
: QAbstractListModel(parent), m_instance(instance)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenshotList::rowCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return m_screenshots.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ScreenshotList::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
switch (role)
|
||||||
|
{
|
||||||
|
case Qt::DecorationRole:
|
||||||
|
{
|
||||||
|
QPixmap map;
|
||||||
|
map.loadFromData(m_screenshots.at(index.row())->file);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return m_screenshots.at(index.row())->timestamp;
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
return m_screenshots.at(index.row())->timestamp;
|
||||||
|
case Qt::TextAlignmentRole:
|
||||||
|
return (int)(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return Qt::NoItemFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
Task *ScreenshotList::load()
|
||||||
|
{
|
||||||
|
return new ScreenshotLoadTask(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenshotLoadTask::ScreenshotLoadTask(ScreenshotList *list) : m_list(list)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenshotLoadTask::~ScreenshotLoadTask()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshotLoadTask::executeTask()
|
||||||
|
{
|
||||||
|
auto dir = QDir(m_list->instance()->minecraftRoot());
|
||||||
|
if (!dir.cd("screenshots"))
|
||||||
|
{
|
||||||
|
emitFailed("Selected instance does not have any screenshots!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dir.setNameFilters(QStringList() << "*.png");
|
||||||
|
this->m_results = QList<ScreenShot *>();
|
||||||
|
for (auto file : dir.entryList())
|
||||||
|
{
|
||||||
|
ScreenShot *shot = new ScreenShot();
|
||||||
|
shot->timestamp = file.left(file.length() - 4);
|
||||||
|
shot->file = QFile(file).readAll();
|
||||||
|
m_results.append(shot);
|
||||||
|
}
|
||||||
|
m_list->loadShots(m_results);
|
||||||
|
emitSucceeded();
|
||||||
|
}
|
75
logic/lists/ScreenshotList.h
Normal file
75
logic/lists/ScreenshotList.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include "logic/BaseInstance.h"
|
||||||
|
#include "logic/tasks/Task.h"
|
||||||
|
|
||||||
|
class ScreenShot
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString timestamp;
|
||||||
|
QByteArray file;
|
||||||
|
int imgurIndex;
|
||||||
|
QString url;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ScreenshotList : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ScreenshotList(BaseInstance *instance, QObject *parent = 0);
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent) const;
|
||||||
|
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
Task *load();
|
||||||
|
|
||||||
|
void loadShots(QList<ScreenShot *> shots)
|
||||||
|
{
|
||||||
|
m_screenshots = shots;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ScreenShot *> screenshots() const
|
||||||
|
{
|
||||||
|
return m_screenshots;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseInstance *instance() const
|
||||||
|
{
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public
|
||||||
|
slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<ScreenShot *> m_screenshots;
|
||||||
|
BaseInstance *m_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ScreenshotLoadTask : public Task
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScreenshotLoadTask(ScreenshotList *list);
|
||||||
|
~ScreenshotLoadTask();
|
||||||
|
|
||||||
|
QList<ScreenShot *> screenShots() const
|
||||||
|
{
|
||||||
|
return m_results;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void executeTask();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScreenshotList *m_list;
|
||||||
|
QList<ScreenShot *> m_results;
|
||||||
|
};
|
144
logic/net/ScreenshotUploader.cpp
Normal file
144
logic/net/ScreenshotUploader.cpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
#include "ScreenshotUploader.h"
|
||||||
|
#include "logic/lists/ScreenshotList.h"
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include "URLConstants.h"
|
||||||
|
#include "MultiMC.h"
|
||||||
|
|
||||||
|
ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : m_shot(shot)
|
||||||
|
{
|
||||||
|
m_status = Job_NotStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenShotUpload::start()
|
||||||
|
{
|
||||||
|
m_status = Job_InProgress;
|
||||||
|
QNetworkRequest request(URLConstants::IMGUR_UPLOAD_URL);
|
||||||
|
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||||
|
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
||||||
|
|
||||||
|
QJsonObject object;
|
||||||
|
object.insert("image", QJsonValue::fromVariant(m_shot->file.toBase64()));
|
||||||
|
object.insert("type", QJsonValue::fromVariant("base64"));
|
||||||
|
object.insert("name", QJsonValue::fromVariant(m_shot->timestamp));
|
||||||
|
QJsonDocument doc;
|
||||||
|
doc.setObject(object);
|
||||||
|
|
||||||
|
auto worker = MMC->qnam();
|
||||||
|
QNetworkReply *rep = worker->post(request, doc.toJson());
|
||||||
|
|
||||||
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||||
|
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
|
||||||
|
SLOT(downloadProgress(qint64, qint64)));
|
||||||
|
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||||
|
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||||
|
SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||||
|
connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
|
||||||
|
}
|
||||||
|
void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error)
|
||||||
|
{
|
||||||
|
m_status = Job_Failed;
|
||||||
|
}
|
||||||
|
void ScreenShotUpload::downloadFinished()
|
||||||
|
{
|
||||||
|
if (m_status != Job_Failed)
|
||||||
|
{
|
||||||
|
QByteArray data = m_reply->readAll();
|
||||||
|
m_reply.reset();
|
||||||
|
QJsonParseError jsonError;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
|
||||||
|
if (jsonError.error != QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
emit failed(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto object = doc.object();
|
||||||
|
if (!object.value("success").toBool())
|
||||||
|
{
|
||||||
|
emit failed(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_shot->imgurIndex = object.value("data").toVariant().toInt();
|
||||||
|
m_status = Job_Finished;
|
||||||
|
emit succeeded(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_reply.reset();
|
||||||
|
emit failed(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ScreenShotUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||||
|
{
|
||||||
|
m_total_progress = bytesTotal;
|
||||||
|
m_progress = bytesReceived;
|
||||||
|
emit progress(m_index_within_job, bytesReceived, bytesTotal);
|
||||||
|
}
|
||||||
|
void ScreenShotUpload::downloadReadyRead()
|
||||||
|
{
|
||||||
|
// noop
|
||||||
|
}
|
||||||
|
ScreenShotGet::ScreenShotGet(ScreenShot *shot) : m_shot(shot)
|
||||||
|
{
|
||||||
|
m_status = Job_NotStarted;
|
||||||
|
}
|
||||||
|
void ScreenShotGet::start()
|
||||||
|
{
|
||||||
|
m_status = Job_InProgress;
|
||||||
|
QNetworkRequest request(URLConstants::IMGUR_GET_BASE + m_shot->imgurIndex + ".json");
|
||||||
|
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||||
|
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
||||||
|
|
||||||
|
auto worker = MMC->qnam();
|
||||||
|
QNetworkReply *rep = worker->get(request);
|
||||||
|
|
||||||
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||||
|
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
|
||||||
|
SLOT(downloadProgress(qint64, qint64)));
|
||||||
|
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||||
|
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||||
|
SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||||
|
connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
|
||||||
|
}
|
||||||
|
void ScreenShotGet::downloadError(QNetworkReply::NetworkError error)
|
||||||
|
{
|
||||||
|
m_status = Job_Failed;
|
||||||
|
}
|
||||||
|
void ScreenShotGet::downloadFinished()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void ScreenShotGet::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||||
|
{
|
||||||
|
m_total_progress = bytesTotal;
|
||||||
|
m_progress = bytesReceived;
|
||||||
|
emit progress(m_index_within_job, bytesReceived, bytesTotal);
|
||||||
|
}
|
||||||
|
void ScreenShotGet::downloadReadyRead()
|
||||||
|
{
|
||||||
|
if (m_status != Job_Failed)
|
||||||
|
{
|
||||||
|
QByteArray data = m_reply->readAll();
|
||||||
|
m_reply.reset();
|
||||||
|
QJsonParseError jsonError;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
|
||||||
|
if (jsonError.error != QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
emit failed(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto object = doc.object();
|
||||||
|
m_shot->url = object.value("link").toString();
|
||||||
|
m_status = Job_Finished;
|
||||||
|
emit succeeded(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_reply.reset();
|
||||||
|
emit failed(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
52
logic/net/ScreenshotUploader.h
Normal file
52
logic/net/ScreenshotUploader.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "NetAction.h"
|
||||||
|
|
||||||
|
class ScreenShot;
|
||||||
|
typedef std::shared_ptr<class ScreenShotUpload> ScreenShotUploadPtr;
|
||||||
|
typedef std::shared_ptr<class ScreenShotGet> ScreenShotGetPtr;
|
||||||
|
class ScreenShotUpload : public NetAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ScreenShotUpload(ScreenShot *shot);
|
||||||
|
static ScreenShotUploadPtr make(ScreenShot *shot)
|
||||||
|
{
|
||||||
|
return ScreenShotUploadPtr(new ScreenShotUpload(shot));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected
|
||||||
|
slots:
|
||||||
|
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||||
|
virtual void downloadError(QNetworkReply::NetworkError error);
|
||||||
|
virtual void downloadFinished();
|
||||||
|
virtual void downloadReadyRead();
|
||||||
|
|
||||||
|
public
|
||||||
|
slots:
|
||||||
|
virtual void start();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScreenShot *m_shot;
|
||||||
|
};
|
||||||
|
class ScreenShotGet : public NetAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ScreenShotGet(ScreenShot *shot);
|
||||||
|
static ScreenShotGetPtr make(ScreenShot *shot)
|
||||||
|
{
|
||||||
|
return ScreenShotGetPtr(new ScreenShotGet(shot));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected
|
||||||
|
slots:
|
||||||
|
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||||
|
virtual void downloadError(QNetworkReply::NetworkError error);
|
||||||
|
virtual void downloadFinished();
|
||||||
|
virtual void downloadReadyRead();
|
||||||
|
|
||||||
|
public
|
||||||
|
slots:
|
||||||
|
virtual void start();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScreenShot *m_shot;
|
||||||
|
};
|
@ -33,4 +33,6 @@ const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/j
|
|||||||
const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
|
const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
|
||||||
const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
|
const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
|
||||||
const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
|
const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
|
||||||
|
const QString IMGUR_UPLOAD_URL("https://api.imgur.com/3/image.json");
|
||||||
|
const QString IMGUR_GET_BASE("https://api.imgur.com/3/image/");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user