File indexing completed on 2024-05-12 05:04:10
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 class Identity; 0009 0010 class SocialGraphModel : public QAbstractListModel 0011 { 0012 Q_OBJECT 0013 QML_ELEMENT 0014 0015 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0016 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0017 Q_PROPERTY(QString displayName READ displayName NOTIFY nameChanged) 0018 Q_PROPERTY(QString placeholderText READ placeholderText NOTIFY nameChanged) 0019 Q_PROPERTY(bool isFollowRequest READ isFollowRequest CONSTANT) 0020 Q_PROPERTY(bool isFollowing READ isFollowing CONSTANT) 0021 Q_PROPERTY(bool isFollower READ isFollower CONSTANT) 0022 0023 /// The account id of the account we want to display 0024 Q_PROPERTY(QString accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged) 0025 Q_PROPERTY(QString statusId READ statusId WRITE setStatusId NOTIFY statusIdChanged) 0026 Q_PROPERTY(int count READ count WRITE setCount) 0027 0028 public: 0029 enum CustomRoles { 0030 IdentityRole = Qt::UserRole + 1, 0031 }; 0032 0033 explicit SocialGraphModel(QObject *parent = nullptr); 0034 0035 QVariant data(const QModelIndex &index, int role) const override; 0036 int rowCount(const QModelIndex &parent) const override; 0037 QHash<int, QByteArray> roleNames() const override; 0038 0039 bool loading() const; 0040 void setLoading(bool loading); 0041 0042 QString name() const; 0043 void setName(const QString &name); 0044 QString displayName() const; 0045 QString placeholderText() const; 0046 QString accountId() const; 0047 void setAccountId(const QString &accountId); 0048 bool isFollowRequest() const; 0049 bool isFollowing() const; 0050 bool isFollower() const; 0051 QString statusId() const; 0052 void setStatusId(const QString &statusId); 0053 int count() const; 0054 void setCount(int count); 0055 0056 public Q_SLOTS: 0057 void actionAllow(const QModelIndex &index); 0058 void actionDeny(const QModelIndex &index); 0059 0060 Q_SIGNALS: 0061 void loadingChanged(); 0062 void nameChanged(); 0063 void accountIdChanged(); 0064 void statusIdChanged(); 0065 0066 protected: 0067 void fetchMore(const QModelIndex &parent) override; 0068 bool canFetchMore(const QModelIndex &parent) const override; 0069 0070 private: 0071 void fillTimeline(); 0072 0073 QList<std::shared_ptr<Identity>> m_accounts; 0074 bool m_loading = false; 0075 QUrl m_next; 0076 0077 QString m_followListName; 0078 QString m_accountId; 0079 QString m_statusId; 0080 int m_count = 0; 0081 };