2023-07-31 12:21:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2023-09-27 10:56:10 +00:00
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
class QFileSystemWatcher;
|
2023-07-31 12:21:14 +00:00
|
|
|
|
|
|
|
struct PagesModelItem {
|
2023-09-27 10:56:10 +00:00
|
|
|
QString path;
|
|
|
|
QDateTime lastModified;
|
2023-07-31 12:21:14 +00:00
|
|
|
QString title;
|
|
|
|
QString category;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PagesModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PagesModel(const QString &path, QObject *parent = nullptr);
|
|
|
|
|
|
|
|
enum Roles {
|
|
|
|
TitleRole = Qt::UserRole + 1,
|
|
|
|
CategoryRole
|
|
|
|
};
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
|
2023-09-27 10:56:10 +00:00
|
|
|
void reload();
|
2023-07-31 12:21:14 +00:00
|
|
|
private:
|
2023-09-27 11:00:27 +00:00
|
|
|
QList<PagesModelItem> load() const;
|
2023-09-27 10:56:10 +00:00
|
|
|
|
|
|
|
static void readMetadata(PagesModelItem &item);
|
|
|
|
static void readMetadata(QList<PagesModelItem> &items);
|
|
|
|
|
|
|
|
QString m_path;
|
2023-07-31 12:21:14 +00:00
|
|
|
QList<PagesModelItem> m_items;
|
2023-09-27 10:56:10 +00:00
|
|
|
QFileSystemWatcher* fsWatcher;
|
2023-07-31 12:21:14 +00:00
|
|
|
};
|