Initial stuff. It doesnt work.
This commit is contained in:
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;
|
||||
};
|
Reference in New Issue
Block a user