File indexing completed on 2024-12-01 07:41:09
0001 /* 0002 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "systemmessagesmodel.h" 0008 #include "ruqola_debug.h" 0009 #include <KLocalizedString> 0010 0011 SystemMessagesModel::SystemMessagesModel(QObject *parent) 0012 : QStandardItemModel(parent) 0013 { 0014 fillModel(); 0015 } 0016 0017 SystemMessagesModel::~SystemMessagesModel() = default; 0018 0019 void SystemMessagesModel::createItem(const QString &displayStr, const QString &systemStr) 0020 { 0021 auto item = new QStandardItem(displayStr); 0022 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 0023 item->setData(systemStr, SystemMessages); 0024 item->setData(Qt::Unchecked, Qt::CheckStateRole); 0025 item->setToolTip(displayStr); 0026 appendRow(item); 0027 } 0028 0029 void SystemMessagesModel::fillModel() 0030 { 0031 auto item = new QStandardItem(i18n("System Messages")); 0032 item->setSelectable(false); 0033 appendRow(item); 0034 createItem(i18n("Hide \"User Added\" messages"), QStringLiteral("au")); 0035 createItem(i18n("Hide \"Welcome\" messages"), QStringLiteral("wm")); 0036 createItem(i18n("Hide \"User Joined Conversation\" messages"), QStringLiteral("ut")); 0037 createItem(i18n("Hide \"User Leave\" messages"), QStringLiteral("ul")); 0038 createItem(i18n("Hide \"User Left Team\" messages"), QStringLiteral("ult")); 0039 createItem(i18n("Hide \"User Join\" messages"), QStringLiteral("uj")); 0040 createItem(i18n("Hide \"Role No Longer Defined\" messages"), QStringLiteral("subscription-role-removed")); 0041 createItem(i18n("Hide \"Was Set Role\" messages"), QStringLiteral("subscription-role-added")); 0042 createItem(i18n("Hide \"User Removed\" messages"), QStringLiteral("ru")); 0043 createItem(i18n("Hide \"Room Unarchived\" messages"), QStringLiteral("room-unarchived")); 0044 createItem(i18n("Hide \"Room encryption disabled\" messages"), QStringLiteral("room_disabled_encryption")); 0045 createItem(i18n("Hide \"Room encryption enabled\" messages"), QStringLiteral("enabled_encryption")); 0046 createItem(i18n("Hide \"Room type changed\" messages"), QStringLiteral("room_changed_privacy")); 0047 createItem(i18n("Hide \"Room avatar changed\" messages"), QStringLiteral("room_changed_avatar")); 0048 createItem(i18n("Hide \"User Muted / Unmuted\" messages"), QStringLiteral("mute_unmute")); 0049 createItem(i18n("Hide \"Room Name Changed\" messages"), QStringLiteral("r")); 0050 createItem(i18n("Hide \"Message Removed\" messages"), QStringLiteral("rm")); 0051 createItem(i18n("Hide \"Room Archived\" messages"), QStringLiteral("room-archived")); 0052 createItem(i18n("Hide \"Encryption Enabled\" messages"), QStringLiteral("room_e2e_enabled")); 0053 createItem(i18n("Hide \"Encryption Disabled\" messages"), QStringLiteral("room_e2e_disabled")); 0054 createItem(i18n("Hide \"Room added writing permission\" messages"), QStringLiteral("room-removed-read-only")); 0055 createItem(i18n("Hide \"Room set read-only\" messages"), QStringLiteral("room-set-read-only")); 0056 createItem(i18n("Hide \"Room disallowed reacting\" messages"), QStringLiteral("room-disallowed-reacting")); 0057 createItem(i18n("Hide \"Room allowed reacting\" messages"), QStringLiteral("room-allowed-reacting")); 0058 createItem(i18n("Hide \"User Added Room to Team\" messages"), QStringLiteral("user-added-room-to-team")); 0059 createItem(i18n("Hide \"User converted team to channel\" messages"), QStringLiteral("user-converted-to-channel")); 0060 createItem(i18n("Hide \"User converted channel to a Team\" messages"), QStringLiteral("user-converted-to-team")); 0061 createItem(i18n("Hide \"User deleted room from Team\" messages"), QStringLiteral("user-deleted-room-from-team")); 0062 createItem(i18n("Hide \"User removed room from Team\" messages"), QStringLiteral("user-removed-room-from-team")); 0063 0064 createItem(i18n("Hide \"Removed user from Team\" messages"), QStringLiteral("removed-user-from-team")); 0065 createItem(i18n("Hide \"Added user to Team\" messages"), QStringLiteral("added-user-to-team")); 0066 createItem(i18n("Hide \"Room topic changed\" messages"), QStringLiteral("room_changed_topic")); 0067 0068 createItem(i18n("Joined this Team"), QStringLiteral("ujt")); 0069 } 0070 0071 void SystemMessagesModel::setMessagesSystem(const QStringList &lst) 0072 { 0073 const int rowCountNb = rowCount(); 0074 // First one is not a message type 0075 QStringList copyList = lst; 0076 for (int i = 1; i < rowCountNb; i++) { 0077 QStandardItem *itemModel = item(i); 0078 if (itemModel) { 0079 for (const QString &s : lst) { 0080 if (itemModel->data(SystemMessages).toString() == s) { 0081 itemModel->setCheckState(Qt::Checked); 0082 copyList.removeAll(s); 0083 break; 0084 } 0085 } 0086 } 0087 } 0088 if (!copyList.isEmpty()) { 0089 qCWarning(RUQOLA_LOG) << "System message is not implemented here " << copyList; 0090 } 0091 } 0092 0093 QStringList SystemMessagesModel::systemMessagesSelected() const 0094 { 0095 QStringList lst; 0096 const int rowCountNb = rowCount(); 0097 // First one is not a message type 0098 for (int i = 1; i < rowCountNb; i++) { 0099 QStandardItem *itemModel = item(i); 0100 if (itemModel) { 0101 if (itemModel->isCheckable() && itemModel->checkState() == Qt::Checked) { 0102 lst.append(itemModel->data(SystemMessages).toString()); 0103 } 0104 } 0105 } 0106 return lst; 0107 } 0108 0109 #include "moc_systemmessagesmodel.cpp"