From cb5cfe724208beb7d506868fc4e50d9f13e28a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 25 Feb 2014 00:51:24 +0100 Subject: Reorganize all the screenshot files --- logic/screenshots/ScreenshotList.cpp | 112 +++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 logic/screenshots/ScreenshotList.cpp (limited to 'logic/screenshots/ScreenshotList.cpp') diff --git a/logic/screenshots/ScreenshotList.cpp b/logic/screenshots/ScreenshotList.cpp new file mode 100644 index 00000000..def1bdf7 --- /dev/null +++ b/logic/screenshots/ScreenshotList.cpp @@ -0,0 +1,112 @@ +#include "ScreenshotList.h" +#include "gui/dialogs/ScreenshotDialog.h" + +#include +#include +#include +#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.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>::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(); +} -- cgit v1.2.3 From 9d4e840a6e1a7169a2863fa1ff1812f8fe19e615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 25 Feb 2014 01:21:46 +0100 Subject: Screenshots: Optimize image loading and memory use, fix list and button layout. --- logic/screenshots/ScreenshotList.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'logic/screenshots/ScreenshotList.cpp') diff --git a/logic/screenshots/ScreenshotList.cpp b/logic/screenshots/ScreenshotList.cpp index def1bdf7..8a64dc36 100644 --- a/logic/screenshots/ScreenshotList.cpp +++ b/logic/screenshots/ScreenshotList.cpp @@ -25,7 +25,7 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const switch (role) { case Qt::DecorationRole: - return QIcon(m_screenshots.at(index.row())->file); + 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: @@ -80,6 +80,7 @@ void ScreenshotLoadTask::executeTask() m_list->loadShots(m_results); emitSucceeded(); } + void ScreenshotList::deleteSelected(ScreenshotDialog *dialog) { auto screens = dialog->selected(); -- cgit v1.2.3