a-la-karte/src/screenshotmodel.h

60 lines
1.4 KiB
C
Raw Normal View History

#pragma once
#include <QAbstractListModel>
#include <QDateTime>
#include <QFutureWatcher>
#include <QQmlEngine>
#include <QUrl>
#include <QVector>
class ScreenshotModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QString directoryPath READ directoryPath WRITE setDirectoryPath NOTIFY directoryPathChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum Roles {
UrlRole = Qt::UserRole + 1,
FileNameRole,
CreatedRole,
SizeRole,
};
explicit ScreenshotModel(QObject *parent = nullptr);
~ScreenshotModel() override;
QString directoryPath() const;
void setDirectoryPath(const QString &path);
int count() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void refresh();
Q_SIGNALS:
void directoryPathChanged();
void countChanged();
private:
struct ScreenshotEntry {
QString filePath;
QString fileName;
QDateTime created;
qint64 size = 0;
};
void setEntries(QVector<ScreenshotEntry> entries);
QString m_directoryPath;
QVector<ScreenshotEntry> m_entries;
QFutureWatcher<QVector<ScreenshotEntry>> m_watcher;
int m_refreshToken = 0;
};