2014-02-23 21:14:24 +00:00
|
|
|
#include "ScreenshotList.h"
|
|
|
|
#include "QDir"
|
2014-02-24 00:45:59 +00:00
|
|
|
#include "QIcon"
|
2014-02-23 21:14:24 +00:00
|
|
|
|
|
|
|
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:
|
2014-02-24 00:45:59 +00:00
|
|
|
return QIcon(m_screenshots.at(index.row())->file);
|
2014-02-23 21:14:24 +00:00
|
|
|
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
|
|
|
|
{
|
2014-02-24 00:45:59 +00:00
|
|
|
return Qt::ItemIsSelectable;
|
2014-02-23 21:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-02-24 00:45:59 +00:00
|
|
|
shot->file = dir.absoluteFilePath(file);
|
2014-02-23 21:14:24 +00:00
|
|
|
m_results.append(shot);
|
|
|
|
}
|
|
|
|
m_list->loadShots(m_results);
|
|
|
|
emitSucceeded();
|
|
|
|
}
|