diff options
author | robotbrain <robotbrainify@gmail.com> | 2014-02-23 16:14:24 -0500 |
---|---|---|
committer | robotbrain <robotbrainify@gmail.com> | 2014-02-23 16:14:24 -0500 |
commit | 4a77524b059c12165e20b38de6c0d4ed08e56419 (patch) | |
tree | 72212e305886d4cf37a387bb816b3397a0e56e31 /logic/lists/ScreenshotList.cpp | |
parent | 5cf599673db88b39100ffca78e10bbe5e10200d7 (diff) | |
download | MultiMC-4a77524b059c12165e20b38de6c0d4ed08e56419.tar MultiMC-4a77524b059c12165e20b38de6c0d4ed08e56419.tar.gz MultiMC-4a77524b059c12165e20b38de6c0d4ed08e56419.tar.lz MultiMC-4a77524b059c12165e20b38de6c0d4ed08e56419.tar.xz MultiMC-4a77524b059c12165e20b38de6c0d4ed08e56419.zip |
Initial stuff. It doesnt work.
Diffstat (limited to 'logic/lists/ScreenshotList.cpp')
-rw-r--r-- | logic/lists/ScreenshotList.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp new file mode 100644 index 00000000..ff37a092 --- /dev/null +++ b/logic/lists/ScreenshotList.cpp @@ -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(); +} |