From 9cac2a8abd25b1fcacffffa2972d43781732f0d8 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 3 Nov 2023 17:39:10 +0100 Subject: [PATCH] Delete KeywordNotificationRuleModel It's unused --- src/models/keywordnotificationrulemodel.cpp | 112 -------------------- src/models/keywordnotificationrulemodel.h | 66 ------------ 2 files changed, 178 deletions(-) delete mode 100644 src/models/keywordnotificationrulemodel.cpp delete mode 100644 src/models/keywordnotificationrulemodel.h diff --git a/src/models/keywordnotificationrulemodel.cpp b/src/models/keywordnotificationrulemodel.cpp deleted file mode 100644 index e8d9d6d67..000000000 --- a/src/models/keywordnotificationrulemodel.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// SPDX-FileCopyrightText: 2022 James Graham -// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - -#include "keywordnotificationrulemodel.h" -#include "controller.h" -#include "notificationsmanager.h" - -#include -#include -#include -#include -#include -#include - -KeywordNotificationRuleModel::KeywordNotificationRuleModel(QObject *parent) - : QAbstractListModel(parent) -{ - if (Controller::instance().activeConnection()) { - controllerConnectionChanged(); - } - connect(&Controller::instance(), &Controller::activeConnectionChanged, this, &KeywordNotificationRuleModel::controllerConnectionChanged); -} - -void KeywordNotificationRuleModel::controllerConnectionChanged() -{ - connect(Controller::instance().activeConnection(), &Quotient::Connection::accountDataChanged, this, &KeywordNotificationRuleModel::updateNotificationRules); - updateNotificationRules("m.push_rules"); -} - -void KeywordNotificationRuleModel::updateNotificationRules(const QString &type) -{ - if (type != "m.push_rules") { - return; - } - - const QJsonObject ruleDataJson = Controller::instance().activeConnection()->accountDataJson("m.push_rules"); - const Quotient::PushRuleset ruleData = Quotient::fromJson(ruleDataJson["global"].toObject()); - const QList contentRules = ruleData.content; - - beginResetModel(); - m_notificationRules.clear(); - for (const auto &i : contentRules) { - if (!m_notificationRules.contains(i.ruleId) && i.ruleId[0] != '.') { - m_notificationRules.append(i.ruleId); - } - } - endResetModel(); -} - -QVariant KeywordNotificationRuleModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return {}; - } - - if (index.row() >= m_notificationRules.count()) { - qDebug() << "KeywordNotificationRuleModel, something's wrong: index.row() >= m_notificationRules.count()"; - return {}; - } - - if (role == NameRole) { - return m_notificationRules.at(index.row()); - } - - return {}; -} - -int KeywordNotificationRuleModel::rowCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent) - - return m_notificationRules.count(); -} - -void KeywordNotificationRuleModel::addKeyword(const QString &keyword) -{ - if (m_notificationRules.count() == 0) { - NotificationsManager::instance().initializeKeywordNotificationAction(); - } - - const QList actions = NotificationsManager::instance().getKeywordNotificationActions(); - - auto job = Controller::instance() - .activeConnection() - ->callApi("global", "content", keyword, actions, "", "", QList(), keyword); - connect(job, &Quotient::BaseJob::success, this, [this, keyword]() { - beginInsertRows(QModelIndex(), m_notificationRules.count(), m_notificationRules.count()); - m_notificationRules.append(keyword); - endInsertRows(); - }); -} - -void KeywordNotificationRuleModel::removeKeywordAtIndex(int index) -{ - auto job = Controller::instance().activeConnection()->callApi("global", "content", m_notificationRules[index]); - connect(job, &Quotient::BaseJob::success, this, [this, index]() { - beginRemoveRows(QModelIndex(), index, index); - m_notificationRules.removeAt(index); - endRemoveRows(); - - if (m_notificationRules.count() == 0) { - NotificationsManager::instance().deactivateKeywordNotificationAction(); - } - }); -} - -QHash KeywordNotificationRuleModel::roleNames() const -{ - return {{NameRole, QByteArrayLiteral("name")}}; -} - -#include "moc_keywordnotificationrulemodel.cpp" diff --git a/src/models/keywordnotificationrulemodel.h b/src/models/keywordnotificationrulemodel.h deleted file mode 100644 index 54a1a3360..000000000 --- a/src/models/keywordnotificationrulemodel.h +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-FileCopyrightText: 2022 James Graham -// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - -#pragma once - -#include - -#include - -/** - * @class KeywordNotificationRuleModel - * - * This class defines the model for managing notification push rule keywords. - */ -class KeywordNotificationRuleModel : public QAbstractListModel -{ - Q_OBJECT - -public: - /** - * @brief Defines the model roles. - */ - enum EventRoles { - NameRole = Qt::DisplayRole, /**< The push rule keyword. */ - }; - - KeywordNotificationRuleModel(QObject *parent = nullptr); - - /** - * @brief Get the given role value at the given index. - * - * @sa QAbstractItemModel::data - */ - [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - - /** - * @brief Number of rows in the model. - * - * @sa QAbstractItemModel::rowCount - */ - [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - /** - * @brief Returns a mapping from Role enum values to role names. - * - * @sa EventRoles, QAbstractItemModel::roleNames() - */ - [[nodiscard]] QHash roleNames() const override; - - /** - * @brief Add a new keyword to the model. - */ - Q_INVOKABLE void addKeyword(const QString &keyword); - - /** - * @brief Remove a keyword from the model. - */ - Q_INVOKABLE void removeKeywordAtIndex(int index); - -private Q_SLOTS: - void controllerConnectionChanged(); - void updateNotificationRules(const QString &type); - -private: - QList m_notificationRules; -};