diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-02-25 00:51:24 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-02-25 00:51:24 +0100 |
commit | cb5cfe724208beb7d506868fc4e50d9f13e28a53 (patch) | |
tree | 527bfd30ef74d5edef055ae6b4258dd2526162d8 /logic/lists | |
parent | b1cddb4600db2aa54c9d274466b393fc1e03eba9 (diff) | |
download | MultiMC-cb5cfe724208beb7d506868fc4e50d9f13e28a53.tar MultiMC-cb5cfe724208beb7d506868fc4e50d9f13e28a53.tar.gz MultiMC-cb5cfe724208beb7d506868fc4e50d9f13e28a53.tar.lz MultiMC-cb5cfe724208beb7d506868fc4e50d9f13e28a53.tar.xz MultiMC-cb5cfe724208beb7d506868fc4e50d9f13e28a53.zip |
Reorganize all the screenshot files
Diffstat (limited to 'logic/lists')
-rw-r--r-- | logic/lists/ScreenshotList.cpp | 112 | ||||
-rw-r--r-- | logic/lists/ScreenshotList.h | 77 |
2 files changed, 0 insertions, 189 deletions
diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp deleted file mode 100644 index eda57a03..00000000 --- a/logic/lists/ScreenshotList.cpp +++ /dev/null @@ -1,112 +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(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.row() >= m_screenshots.size() || index.row() < 0) - return QVariant(); - - switch (role) - { - case Qt::DecorationRole: - return QIcon(m_screenshots.at(index.row())->file); - 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 = QList<ScreenShot *>(); - 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(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++) - { - std::shared_ptr<ScreenShot> = *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(); -} diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h deleted file mode 100644 index 8e512ace..00000000 --- a/logic/lists/ScreenshotList.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#include <QAbstractListModel> -#include "logic/BaseInstance.h" -#include "logic/tasks/Task.h" - -class ScreenShot -{ -public: - QDateTime timestamp; - QString file; - QString url; - QString imgurId; -}; - -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; - } - - void deleteSelected(class ScreenshotDialog *dialog); - -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; -}; |