Turn screenshot management into a page.
This commit is contained in:
@ -34,6 +34,7 @@
|
||||
#include <gui/pages/TexturePackPage.h>
|
||||
#include <gui/pages/InstanceSettingsPage.h>
|
||||
#include <gui/pages/NotesPage.h>
|
||||
#include <gui/pages/ScreenshotsPage.h>
|
||||
|
||||
LegacyInstance::LegacyInstance(const QString &rootDir, SettingsObject *settings,
|
||||
QObject *parent)
|
||||
@ -57,6 +58,7 @@ QList<BasePage *> LegacyInstance::getPages()
|
||||
"Core-mods"));
|
||||
values.append(new TexturePackPage(this));
|
||||
values.append(new NotesPage(this));
|
||||
values.append(new ScreenshotsPage(this));
|
||||
values.append(new InstanceSettingsPage(&settings()));
|
||||
return values;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <gui/pages/TexturePackPage.h>
|
||||
#include <gui/pages/InstanceSettingsPage.h>
|
||||
#include <gui/pages/NotesPage.h>
|
||||
#include <gui/pages/ScreenshotsPage.h>
|
||||
|
||||
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
|
||||
QObject *parent)
|
||||
@ -69,6 +70,7 @@ QList<BasePage *> OneSixInstance::getPages()
|
||||
values.append(new ResourcePackPage(this));
|
||||
values.append(new TexturePackPage(this));
|
||||
values.append(new NotesPage(this));
|
||||
values.append(new ScreenshotsPage(this));
|
||||
values.append(new InstanceSettingsPage(&settings()));
|
||||
return values;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include "logic/screenshots//ScreenshotList.h"
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logger/QsLog.h"
|
||||
@ -28,7 +27,7 @@ void ImgurAlbumCreation::start()
|
||||
QStringList ids;
|
||||
for (auto shot : m_screenshots)
|
||||
{
|
||||
ids.append(shot->imgurId);
|
||||
ids.append(shot->m_imgurId);
|
||||
}
|
||||
|
||||
const QByteArray data = "ids=" + ids.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden";
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
|
||||
#include "logic/screenshots/ScreenshotList.h"
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logger/QsLog.h"
|
||||
@ -27,7 +26,7 @@ void ImgurUpload::start()
|
||||
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
|
||||
QFile f(m_shot->file);
|
||||
QFile f(m_shot->m_file.absoluteFilePath());
|
||||
if (!f.open(QFile::ReadOnly))
|
||||
{
|
||||
emit failed(m_index_within_job);
|
||||
@ -46,7 +45,7 @@ void ImgurUpload::start()
|
||||
multipart->append(typePart);
|
||||
QHttpPart namePart;
|
||||
namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\"");
|
||||
namePart.setBody(m_shot->timestamp.toString(Qt::ISODate).toUtf8());
|
||||
namePart.setBody(m_shot->m_file.baseName().toUtf8());
|
||||
multipart->append(namePart);
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
@ -84,8 +83,8 @@ void ImgurUpload::downloadFinished()
|
||||
emit failed(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
m_shot->imgurId = object.value("data").toObject().value("id").toString();
|
||||
m_shot->url = object.value("data").toObject().value("link").toString();
|
||||
m_shot->m_imgurId = object.value("data").toObject().value("id").toString();
|
||||
m_shot->m_url = object.value("data").toObject().value("link").toString();
|
||||
m_status = Job_Finished;
|
||||
emit succeeded(m_index_within_job);
|
||||
return;
|
||||
|
@ -1,14 +0,0 @@
|
||||
#include "Screenshot.h"
|
||||
#include <QImage>
|
||||
#include <QIcon>
|
||||
QIcon ScreenShot::getImage()
|
||||
{
|
||||
if(!imageloaded)
|
||||
{
|
||||
QImage image(file);
|
||||
QImage thumbnail = image.scaledToWidth(256, Qt::SmoothTransformation);
|
||||
m_image = QIcon(QPixmap::fromImage(thumbnail));
|
||||
imageloaded = true;
|
||||
}
|
||||
return m_image;
|
||||
}
|
@ -2,18 +2,18 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QFileInfo>
|
||||
#include <memory>
|
||||
#include <QIcon>
|
||||
|
||||
struct ScreenShot
|
||||
{
|
||||
QIcon getImage();
|
||||
QIcon m_image;
|
||||
bool imageloaded = false;
|
||||
QDateTime timestamp;
|
||||
QString file;
|
||||
QString url;
|
||||
QString imgurId;
|
||||
ScreenShot(QFileInfo file)
|
||||
{
|
||||
m_file = file;
|
||||
}
|
||||
QFileInfo m_file;
|
||||
QString m_url;
|
||||
QString m_imgurId;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ScreenShot> ScreenshotPtr;
|
||||
|
@ -1,113 +0,0 @@
|
||||
#include "ScreenshotList.h"
|
||||
#include "gui/dialogs/ScreenshotDialog.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <QList>
|
||||
#include "gui/dialogs/ProgressDialog.h"
|
||||
#include "gui/dialogs/CustomMessageBox.h"
|
||||
|
||||
ScreenshotList::ScreenshotList(InstancePtr 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.row() >= m_screenshots.size() || index.row() < 0)
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DecorationRole:
|
||||
return m_screenshots.at(index.row())->getImage();
|
||||
case Qt::DisplayRole:
|
||||
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
|
||||
case Qt::ToolTipRole:
|
||||
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
|
||||
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::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
}
|
||||
|
||||
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.clear();
|
||||
for (auto file : dir.entryList())
|
||||
{
|
||||
ScreenShot *shot = new ScreenShot();
|
||||
shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png");
|
||||
shot->file = dir.absoluteFilePath(file);
|
||||
m_results.append(ScreenshotPtr(shot));
|
||||
}
|
||||
m_list->loadShots(m_results);
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void ScreenshotList::deleteSelected(ScreenshotDialog *dialog)
|
||||
{
|
||||
auto screens = dialog->selected();
|
||||
if (screens.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
beginResetModel();
|
||||
QList<std::shared_ptr<ScreenShot>>::const_iterator it;
|
||||
for (it = screens.cbegin(); it != screens.cend(); it++)
|
||||
{
|
||||
auto shot = *it;
|
||||
if (!QFile(shot->file).remove())
|
||||
{
|
||||
CustomMessageBox::selectable(dialog, tr("Error!"),
|
||||
tr("Failed to delete screenshots!"),
|
||||
QMessageBox::Warning)->exec();
|
||||
break;
|
||||
}
|
||||
}
|
||||
ProgressDialog refresh(dialog);
|
||||
Task *t = load();
|
||||
if (refresh.exec(t) != QDialog::Accepted)
|
||||
{
|
||||
CustomMessageBox::selectable(dialog, tr("Error!"),
|
||||
tr("Unable to refresh list: %1").arg(t->failReason()),
|
||||
QMessageBox::Warning)->exec();
|
||||
}
|
||||
endResetModel();
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "logic/tasks/Task.h"
|
||||
|
||||
#include "Screenshot.h"
|
||||
|
||||
class ScreenshotList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScreenshotList(InstancePtr 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<ScreenshotPtr> shots)
|
||||
{
|
||||
m_screenshots = shots;
|
||||
}
|
||||
|
||||
QList<ScreenshotPtr> screenshots() const
|
||||
{
|
||||
return m_screenshots;
|
||||
}
|
||||
|
||||
InstancePtr instance() const
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
void deleteSelected(class ScreenshotDialog *dialog);
|
||||
|
||||
signals:
|
||||
|
||||
public
|
||||
slots:
|
||||
|
||||
private:
|
||||
QList<ScreenshotPtr> m_screenshots;
|
||||
InstancePtr m_instance;
|
||||
};
|
||||
|
||||
class ScreenshotLoadTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScreenshotLoadTask(ScreenshotList *list);
|
||||
~ScreenshotLoadTask();
|
||||
|
||||
QList<ScreenshotPtr> screenShots() const
|
||||
{
|
||||
return m_results;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void executeTask();
|
||||
|
||||
private:
|
||||
ScreenshotList *m_list;
|
||||
QList<ScreenshotPtr> m_results;
|
||||
};
|
Reference in New Issue
Block a user