File indexing completed on 2024-05-12 05:04:09

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QtQml>
0007 
0008 /// Fetches a user's lists
0009 class ListsModel : public QAbstractListModel
0010 {
0011     Q_OBJECT
0012     QML_ELEMENT
0013 
0014     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
0015 
0016 public:
0017     /// Custom roles for this model
0018     enum CustomRoles {
0019         IdRole = Qt::UserRole, ///< ID of the list
0020         TitleRole ///< Title of the list
0021     };
0022 
0023     explicit ListsModel(QObject *parent = nullptr);
0024 
0025     bool loading() const;
0026     void setLoading(bool loading);
0027 
0028     QVariant data(const QModelIndex &index, int role) const override;
0029     int rowCount(const QModelIndex &parent) const override;
0030     QHash<int, QByteArray> roleNames() const override;
0031 
0032     void fillTimeline();
0033 
0034 Q_SIGNALS:
0035     void loadingChanged();
0036 
0037 private:
0038     struct List {
0039         QString id, title;
0040     };
0041 
0042     QList<List> m_lists;
0043     bool m_loading = false;
0044     List fromSourceData(const QJsonObject &object) const;
0045 };