2014-02-24 02:44:24 +05:30
|
|
|
#include "ScreenshotList.h"
|
2014-02-25 04:10:05 +05:30
|
|
|
#include "gui/dialogs/ScreenshotDialog.h"
|
2014-02-24 15:04:51 +05:30
|
|
|
|
2014-02-24 14:04:21 +05:30
|
|
|
#include <QDir>
|
|
|
|
#include <QIcon>
|
2014-02-25 04:10:05 +05:30
|
|
|
#include <QList>
|
|
|
|
#include "gui/dialogs/ProgressDialog.h"
|
|
|
|
#include "gui/dialogs/CustomMessageBox.h"
|
2014-02-24 02:44:24 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2014-02-25 04:10:05 +05:30
|
|
|
if (index.row() >= m_screenshots.size() || index.row() < 0)
|
2014-02-24 02:44:24 +05:30
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case Qt::DecorationRole:
|
2014-02-24 06:15:59 +05:30
|
|
|
return QIcon(m_screenshots.at(index.row())->file);
|
2014-02-24 02:44:24 +05:30
|
|
|
case Qt::DisplayRole:
|
2014-02-24 15:04:51 +05:30
|
|
|
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
|
2014-02-24 02:44:24 +05:30
|
|
|
case Qt::ToolTipRole:
|
2014-02-24 15:04:51 +05:30
|
|
|
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
|
2014-02-24 02:44:24 +05:30
|
|
|
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 14:04:21 +05:30
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
2014-02-24 02:44:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2014-02-24 15:04:51 +05:30
|
|
|
shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png");
|
2014-02-24 06:15:59 +05:30
|
|
|
shot->file = dir.absoluteFilePath(file);
|
2014-02-24 02:44:24 +05:30
|
|
|
m_results.append(shot);
|
|
|
|
}
|
|
|
|
m_list->loadShots(m_results);
|
|
|
|
emitSucceeded();
|
|
|
|
}
|
2014-02-25 04:10:05 +05:30
|
|
|
void ScreenshotList::deleteSelected(ScreenshotDialog *dialog)
|
|
|
|
{
|
|
|
|
auto screens = dialog->selected();
|
|
|
|
if (screens.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
beginResetModel();
|
|
|
|
QList<ScreenShot *>::const_iterator it;
|
|
|
|
for (it = screens.cbegin(); it != screens.cend(); it++)
|
|
|
|
{
|
|
|
|
ScreenShot *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();
|
|
|
|
}
|