File indexing completed on 2024-09-29 07:26:44
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 "federationinfo.h" 0007 0008 #include <QtQml> 0009 0010 class FederationToolModel : public QAbstractListModel 0011 { 0012 Q_OBJECT 0013 QML_ELEMENT 0014 0015 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0016 Q_PROPERTY(FederationAction federationAction READ federationAction WRITE setFederationAction NOTIFY federationActionChanged) 0017 0018 public: 0019 enum CustomRoles { 0020 IdRole, 0021 DomainRole, 0022 CreatedAtRole, 0023 SeverityRole, 0024 RejectMediaRole, 0025 RejectReportsRole, 0026 PrivateCommentRole, 0027 PublicCommentRole, 0028 ObfuscateRole 0029 }; 0030 0031 enum FederationAction { 0032 AllowedDomains, 0033 BlockedDomains, 0034 }; 0035 0036 Q_ENUM(FederationAction) 0037 0038 explicit FederationToolModel(QObject *parent = nullptr); 0039 0040 void clear(); 0041 0042 QVariant data(const QModelIndex &index, int role) const override; 0043 int rowCount(const QModelIndex &parent) const override; 0044 QHash<int, QByteArray> roleNames() const override; 0045 0046 bool loading() const; 0047 void setLoading(bool loading); 0048 FederationToolModel::FederationAction federationAction() const; 0049 void setFederationAction(const FederationToolModel::FederationAction &federationAction); 0050 void filltimeline(FederationAction action = FederationAction::BlockedDomains); 0051 0052 Q_INVOKABLE void removeDomainBlock(int row); 0053 Q_INVOKABLE void removeAllowedDomain(int row); 0054 Q_INVOKABLE void updateDomainBlock(int row, 0055 const QString &severity, 0056 const QString &publicComment, 0057 const QString &privateComment, 0058 const bool &rejectMedia, 0059 const bool &rejectReports, 0060 const bool &obfuscateReport); 0061 Q_INVOKABLE void newDomainBlock(const QString &domain, 0062 const QString &severity, 0063 const QString &publicComment, 0064 const QString &privateComment, 0065 const bool &rejectMedia, 0066 const bool &rejectReports, 0067 const bool &obfuscateReport); 0068 Q_INVOKABLE void newDomainAllow(const QString &domain); 0069 0070 Q_SIGNALS: 0071 void loadingChanged(); 0072 void federationActionChanged(); 0073 0074 private: 0075 QList<FederationInfo> m_federations; 0076 bool m_loading = false; 0077 FederationToolModel::FederationAction m_federationAction = FederationAction::BlockedDomains; 0078 QUrl m_next; 0079 };