Move more stuff to settings

This commit is contained in:
James Graham
2025-04-12 20:14:59 +01:00
parent 32ee590cef
commit 3a4bc18d45
22 changed files with 50 additions and 45 deletions

View File

@@ -17,8 +17,6 @@ add_library(neochat STATIC
models/roomlistmodel.h models/roomlistmodel.h
models/sortfilterspacelistmodel.cpp models/sortfilterspacelistmodel.cpp
models/sortfilterspacelistmodel.h models/sortfilterspacelistmodel.h
models/accountemoticonmodel.cpp
models/accountemoticonmodel.h
roommanager.cpp roommanager.cpp
roommanager.h roommanager.h
models/userlistmodel.cpp models/userlistmodel.cpp
@@ -35,10 +33,6 @@ add_library(neochat STATIC
models/spacetreeitem.h models/spacetreeitem.h
models/userdirectorylistmodel.cpp models/userdirectorylistmodel.cpp
models/userdirectorylistmodel.h models/userdirectorylistmodel.h
models/pushrulemodel.cpp
models/pushrulemodel.h
models/emoticonfiltermodel.cpp
models/emoticonfiltermodel.h
notificationsmanager.cpp notificationsmanager.cpp
notificationsmanager.h notificationsmanager.h
models/sortfilterroomlistmodel.cpp models/sortfilterroomlistmodel.cpp
@@ -47,9 +41,6 @@ add_library(neochat STATIC
models/roomtreemodel.h models/roomtreemodel.h
chatdocumenthandler.cpp chatdocumenthandler.cpp
chatdocumenthandler.h chatdocumenthandler.h
models/devicesmodel.cpp
models/devicesmodel.h
models/devicesproxymodel.cpp
login.cpp login.cpp
login.h login.h
models/webshortcutmodel.cpp models/webshortcutmodel.cpp
@@ -72,10 +63,6 @@ add_library(neochat STATIC
models/statefiltermodel.h models/statefiltermodel.h
logger.cpp logger.cpp
logger.h logger.h
models/stickermodel.cpp
models/stickermodel.h
models/imagepacksmodel.cpp
models/imagepacksmodel.h
models/livelocationsmodel.cpp models/livelocationsmodel.cpp
models/livelocationsmodel.h models/livelocationsmodel.h
models/locationsmodel.cpp models/locationsmodel.cpp
@@ -111,8 +98,6 @@ add_library(neochat STATIC
threepidaddhelper.h threepidaddhelper.h
identityserverhelper.cpp identityserverhelper.cpp
identityserverhelper.h identityserverhelper.h
models/permissionsmodel.cpp
models/permissionsmodel.h
threepidbindhelper.cpp threepidbindhelper.cpp
threepidbindhelper.h threepidbindhelper.h
enums/roomsortparameter.cpp enums/roomsortparameter.cpp

View File

@@ -21,6 +21,7 @@
#include "models/actionsmodel.h" #include "models/actionsmodel.h"
#include "models/messagemodel.h" #include "models/messagemodel.h"
#include "models/pushrulemodel.h"
#include "neochatconfig.h" #include "neochatconfig.h"
#include "neochatconnection.h" #include "neochatconnection.h"
#include "neochatroom.h" #include "neochatroom.h"
@@ -65,6 +66,11 @@ Controller::Controller(QObject *parent)
Q_EMIT globalUrlPreviewDefaultChanged(); Q_EMIT globalUrlPreviewDefaultChanged();
}); });
NeoChatConnection::setKeywordPushRuleDefault(static_cast<PushRuleAction::Action>(NeoChatConfig::keywordPushRuleDefault()));
connect(NeoChatConfig::self(), &NeoChatConfig::KeywordPushRuleDefaultChanged, this, [] {
NeoChatConnection::setKeywordPushRuleDefault(static_cast<PushRuleAction::Action>(NeoChatConfig::keywordPushRuleDefault()));
});
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit()); ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
connect(NeoChatConfig::self(), &NeoChatConfig::AllowQuickEditChanged, this, []() { connect(NeoChatConfig::self(), &NeoChatConfig::AllowQuickEditChanged, this, []() {
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit()); ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());

View File

@@ -29,6 +29,8 @@ target_sources(LibNeoChat PRIVATE
models/actionsmodel.cpp models/actionsmodel.cpp
models/customemojimodel.cpp models/customemojimodel.cpp
models/emojimodel.cpp models/emojimodel.cpp
models/imagepacksmodel.cpp
models/stickermodel.cpp
) )
ecm_add_qml_module(LibNeoChat GENERATE_PLUGIN_SOURCE ecm_add_qml_module(LibNeoChat GENERATE_PLUGIN_SOURCE

View File

@@ -35,6 +35,7 @@ using namespace Quotient;
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
bool NeoChatConnection::m_globalUrlPreviewDefault = true; bool NeoChatConnection::m_globalUrlPreviewDefault = true;
PushRuleAction::Action NeoChatConnection::m_defaultAction = PushRuleAction::Unknown;
NeoChatConnection::NeoChatConnection(QObject *parent) NeoChatConnection::NeoChatConnection(QObject *parent)
: Connection(parent) : Connection(parent)
@@ -178,6 +179,16 @@ void NeoChatConnection::setGlobalUrlPreviewDefault(bool useByDefault)
NeoChatConnection::m_globalUrlPreviewDefault = useByDefault; NeoChatConnection::m_globalUrlPreviewDefault = useByDefault;
} }
PushRuleAction::Action NeoChatConnection::keywordPushRuleDefault() const
{
return m_defaultAction;
}
void NeoChatConnection::setKeywordPushRuleDefault(PushRuleAction::Action defaultAction)
{
NeoChatConnection::m_defaultAction = defaultAction;
}
void NeoChatConnection::logout(bool serverSideLogout) void NeoChatConnection::logout(bool serverSideLogout)
{ {
SettingsGroup(u"Accounts"_s).remove(userId()); SettingsGroup(u"Accounts"_s).remove(userId());

View File

@@ -13,6 +13,7 @@
#include <Quotient/keyimport.h> #include <Quotient/keyimport.h>
#include "enums/messagetype.h" #include "enums/messagetype.h"
#include "enums/pushrule.h"
#include "linkpreviewer.h" #include "linkpreviewer.h"
class NeoChatConnection : public Quotient::Connection class NeoChatConnection : public Quotient::Connection
@@ -181,6 +182,16 @@ public:
*/ */
static void setGlobalUrlPreviewDefault(bool useByDefault); static void setGlobalUrlPreviewDefault(bool useByDefault);
/**
* @brief The current default PushRuleAction for keyword rules.
*/
PushRuleAction::Action keywordPushRuleDefault() const;
/**
* @brief Set the current default PushRuleAction for keyword rules.
*/
static void setKeywordPushRuleDefault(PushRuleAction::Action defaultAction);
bool directChatInvites() const; bool directChatInvites() const;
// note: this is intentionally a copied QString because // note: this is intentionally a copied QString because
@@ -223,6 +234,7 @@ Q_SIGNALS:
private: private:
static bool m_globalUrlPreviewDefault; static bool m_globalUrlPreviewDefault;
static PushRuleAction::Action m_defaultAction;
bool m_isOnline = true; bool m_isOnline = true;
void setIsOnline(bool isOnline); void setIsOnline(bool isOnline);

View File

@@ -46,8 +46,18 @@ ecm_add_qml_module(Settings GENERATE_PLUGIN_SOURCE
RoomProfile.qml RoomProfile.qml
SOURCES SOURCES
colorschemer.cpp colorschemer.cpp
models/accountemoticonmodel.cpp
models/devicesmodel.cpp
models/devicesproxymodel.cpp
models/emoticonfiltermodel.cpp
models/permissionsmodel.cpp
models/pushrulemodel.cpp
) )
target_include_directories(Settings PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_link_libraries(Settings PRIVATE target_link_libraries(Settings PRIVATE
KF6::ColorScheme KF6::ColorScheme
QuotientQt6
LibNeoChat
) )

View File

@@ -136,7 +136,8 @@ void DevicesModel::logout(const QString &deviceId, const QString &password)
void DevicesModel::setName(const QString &deviceId, const QString &name) void DevicesModel::setName(const QString &deviceId, const QString &name)
{ {
int index; int index;
for (index = 0; m_devices[index].deviceId != deviceId; index++); for (index = 0; m_devices[index].deviceId != deviceId; index++)
;
auto job = m_connection->callApi<UpdateDeviceJob>(m_devices[index].deviceId, name); auto job = m_connection->callApi<UpdateDeviceJob>(m_devices[index].deviceId, name);
QString oldName = m_devices[index].displayName; QString oldName = m_devices[index].displayName;

View File

@@ -4,7 +4,7 @@
#include "emoticonfiltermodel.h" #include "emoticonfiltermodel.h"
#include "accountemoticonmodel.h" #include "accountemoticonmodel.h"
#include "stickermodel.h" #include "models/stickermodel.h"
EmoticonFilterModel::EmoticonFilterModel(QObject *parent) EmoticonFilterModel::EmoticonFilterModel(QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)

View File

@@ -10,7 +10,7 @@
#include <Quotient/csapi/pushrules.h> #include <Quotient/csapi/pushrules.h>
#include <Quotient/jobs/basejob.h> #include <Quotient/jobs/basejob.h>
#include "neochatconfig.h" #include "enums/pushrule.h"
#include <KLazyLocalizedString> #include <KLazyLocalizedString>
@@ -65,7 +65,6 @@ static const QStringList noHighlight = {
PushRuleModel::PushRuleModel(QObject *parent) PushRuleModel::PushRuleModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
m_defaultKeywordAction = static_cast<PushRuleAction::Action>(NeoChatConfig::self()->keywordPushRuleDefault());
} }
void PushRuleModel::updateNotificationRules(const QString &type) void PushRuleModel::updateNotificationRules(const QString &type)
@@ -172,21 +171,6 @@ PushRuleSection::Section PushRuleModel::getSection(Quotient::PushRule rule)
} }
} }
PushRuleAction::Action PushRuleModel::defaultState() const
{
return m_defaultKeywordAction;
}
void PushRuleModel::setDefaultState(PushRuleAction::Action defaultState)
{
if (defaultState == m_defaultKeywordAction) {
return;
}
m_defaultKeywordAction = defaultState;
NeoChatConfig::setKeywordPushRuleDefault(m_defaultKeywordAction);
Q_EMIT defaultStateChanged();
}
bool PushRuleModel::globalNotificationsEnabled() const bool PushRuleModel::globalNotificationsEnabled() const
{ {
auto masterIndex = getRuleIndex(u".m.rule.master"_s); auto masterIndex = getRuleIndex(u".m.rule.master"_s);
@@ -292,8 +276,12 @@ void PushRuleModel::setPushRuleAction(const QString &id, PushRuleAction::Action
void PushRuleModel::addKeyword(const QString &keyword, const QString &roomId) void PushRuleModel::addKeyword(const QString &keyword, const QString &roomId)
{ {
if (!m_connection) {
return;
}
PushRuleKind::Kind kind = PushRuleKind::Content; PushRuleKind::Kind kind = PushRuleKind::Content;
const QList<QVariant> actions = actionToVariant(m_defaultKeywordAction); const QList<QVariant> actions = actionToVariant(m_connection->keywordPushRuleDefault());
QList<Quotient::PushCondition> pushConditions; QList<Quotient::PushCondition> pushConditions;
if (!roomId.isEmpty()) { if (!roomId.isEmpty()) {
kind = PushRuleKind::Override; kind = PushRuleKind::Override;

View File

@@ -23,11 +23,6 @@ class PushRuleModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
QML_ELEMENT QML_ELEMENT
/**
* @brief The default state for any newly created keyword rule.
*/
Q_PROPERTY(PushRuleAction::Action defaultState READ defaultState WRITE setDefaultState NOTIFY defaultStateChanged)
/** /**
* @brief The global notification state. * @brief The global notification state.
* *
@@ -72,9 +67,6 @@ public:
explicit PushRuleModel(QObject *parent = nullptr); explicit PushRuleModel(QObject *parent = nullptr);
[[nodiscard]] PushRuleAction::Action defaultState() const;
void setDefaultState(PushRuleAction::Action defaultState);
[[nodiscard]] bool globalNotificationsEnabled() const; [[nodiscard]] bool globalNotificationsEnabled() const;
void setGlobalNotificationsEnabled(bool enabled); void setGlobalNotificationsEnabled(bool enabled);
@@ -117,7 +109,6 @@ public:
NeoChatConnection *connection() const; NeoChatConnection *connection() const;
Q_SIGNALS: Q_SIGNALS:
void defaultStateChanged();
void globalNotificationsEnabledChanged(); void globalNotificationsEnabledChanged();
void globalNotificationsSetChanged(); void globalNotificationsSetChanged();
void connectionChanged(); void connectionChanged();
@@ -126,7 +117,6 @@ private Q_SLOTS:
void updateNotificationRules(const QString &type); void updateNotificationRules(const QString &type);
private: private:
PushRuleAction::Action m_defaultKeywordAction;
QList<Rule> m_rules; QList<Rule> m_rules;
QPointer<NeoChatConnection> m_connection; QPointer<NeoChatConnection> m_connection;