File indexing completed on 2024-05-12 05:04:10
0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #pragma once 0005 0006 #include "abstractaccount.h" 0007 0008 class AdminAccountInfo; 0009 0010 class AccountsToolModel : public QAbstractListModel 0011 { 0012 Q_OBJECT 0013 QML_ELEMENT 0014 0015 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0016 /// This property holds the "Location" value of account tool. 0017 Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged) 0018 /// This property holds the "moderation Status" value of account tool. 0019 Q_PROPERTY(QString moderationStatus READ moderationStatus WRITE setModerationStatus NOTIFY moderationStatusChanged) 0020 /// This property holds the "Role" value of account tool. 0021 Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged) 0022 /// This property holds the "username" value of account tool. 0023 Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged) 0024 /// This property holds the "displayName" value of account tool. 0025 Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) 0026 /// This property holds the "email" value of account tool. 0027 Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged) 0028 /// This property holds the "ip" value of account tool. 0029 Q_PROPERTY(QString ip READ ip WRITE setIp NOTIFY ipChanged) 0030 /// This property holds the position value of the current account which is logged in 0031 Q_PROPERTY(int selectedAccountPosition READ selectedAccountPosition CONSTANT) 0032 0033 public: 0034 enum CustomRoles { 0035 IdentityRole = Qt::UserRole + 1, 0036 }; 0037 0038 enum AdminAccountAction { 0039 ApproveAccount, 0040 RejectAccount, 0041 ActionAgainstAccount, 0042 EnableDisabledAccount, 0043 UnsilenceAccount, 0044 UnsuspendAccount, 0045 UnmarkSensitiveAccount, 0046 }; 0047 0048 explicit AccountsToolModel(QObject *parent = nullptr); 0049 0050 QVariant data(const QModelIndex &index, int role) const override; 0051 int rowCount(const QModelIndex &parent) const override; 0052 QHash<int, QByteArray> roleNames() const override; 0053 0054 bool loading() const; 0055 void setLoading(bool loading); 0056 0057 QUrlQuery buildQuery() const; 0058 0059 // location 0060 QString location() const; 0061 void setLocation(const QString &location); 0062 0063 // moderation status 0064 QString moderationStatus() const; 0065 void setModerationStatus(const QString &moderationStatus); 0066 0067 // role 0068 QString role() const; 0069 void setRole(const QString &role); 0070 0071 // UserName 0072 QString username() const; 0073 void setUsername(const QString &username); 0074 0075 // displayName 0076 QString displayName() const; 0077 void setDisplayName(const QString &displayName); 0078 0079 // email 0080 QString email() const; 0081 void setEmail(const QString &email); 0082 0083 // ip 0084 QString ip() const; 0085 void setIp(const QString &role); 0086 0087 int selectedAccountPosition() const; 0088 0089 // clearing and reloading the model 0090 void clear(); 0091 // delete account data 0092 Q_INVOKABLE void deleteAccountData(int row); 0093 0094 Q_INVOKABLE void approveAccount(int row); 0095 Q_INVOKABLE void rejectAccount(int row); 0096 Q_INVOKABLE void enableAccount(int row); 0097 Q_INVOKABLE void unsilenceAccount(int row); 0098 Q_INVOKABLE void unsuspendAccount(int row); 0099 Q_INVOKABLE void unsensitiveAccount(int row); 0100 Q_INVOKABLE void actionAgainstAccount(int row, const QString &type, const bool &emailWarning, const QString ¬e); 0101 0102 Q_SIGNALS: 0103 void loadingChanged(); 0104 void locationChanged(); 0105 void moderationStatusChanged(); 0106 void roleChanged(); 0107 void usernameChanged(); 0108 void displayNameChanged(); 0109 void emailChanged(); 0110 void ipChanged(); 0111 0112 protected: 0113 void fetchSelectedAccountPosition(); 0114 void fetchMore(const QModelIndex &parent) override; 0115 bool canFetchMore(const QModelIndex &parent) const override; 0116 void executeAdminAction(int row, AdminAccountAction accountAction, const QJsonObject &extraArguments = {}); 0117 0118 private: 0119 void fillTimeline(); 0120 0121 QList<std::shared_ptr<AdminAccountInfo>> m_accounts; 0122 bool m_loading = false; 0123 bool m_pagination = true; 0124 0125 QString m_username; 0126 QString m_displayName; 0127 QString m_email; 0128 QString m_ip; 0129 QString m_location; 0130 QString m_moderationStatus; 0131 QString m_role; 0132 QUrl m_next; 0133 int m_selectedAccountPosition = 0; 0134 };