File indexing completed on 2024-05-19 12:39:13
0001 // SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.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 <Quotient/csapi/definitions/push_rule.h> 0007 0008 #include <QAbstractListModel> 0009 0010 /** 0011 * @class KeywordNotificationRuleModel 0012 * 0013 * This class defines the model for managing notification push rule keywords. 0014 */ 0015 class KeywordNotificationRuleModel : public QAbstractListModel 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 /** 0021 * @brief Defines the model roles. 0022 */ 0023 enum EventRoles { 0024 NameRole = Qt::DisplayRole, /**< The push rule keyword. */ 0025 }; 0026 0027 KeywordNotificationRuleModel(QObject *parent = nullptr); 0028 0029 /** 0030 * @brief Get the given role value at the given index. 0031 * 0032 * @sa QAbstractItemModel::data 0033 */ 0034 [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0035 0036 /** 0037 * @brief Number of rows in the model. 0038 * 0039 * @sa QAbstractItemModel::rowCount 0040 */ 0041 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0042 0043 /** 0044 * @brief Returns a mapping from Role enum values to role names. 0045 * 0046 * @sa EventRoles, QAbstractItemModel::roleNames() 0047 */ 0048 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0049 0050 /** 0051 * @brief Add a new keyword to the model. 0052 */ 0053 Q_INVOKABLE void addKeyword(const QString &keyword); 0054 0055 /** 0056 * @brief Remove a keyword from the model. 0057 */ 0058 Q_INVOKABLE void removeKeywordAtIndex(int index); 0059 0060 private Q_SLOTS: 0061 void controllerConnectionChanged(); 0062 void updateNotificationRules(const QString &type); 0063 0064 private: 0065 QList<QString> m_notificationRules; 0066 };