X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorehighlightrulemanager.cpp;h=40d056655f437daf0bf8da735b2d2396b7232fa4;hp=d7ccd8f8bccb8eda224dac974adc1edcfe6f1e69;hb=e14649614fbbf9b386505a5d782b88b1ac313c1f;hpb=68878dc8366f2f4a0afe132847aad9a51a80cdbf diff --git a/src/core/corehighlightrulemanager.cpp b/src/core/corehighlightrulemanager.cpp index d7ccd8f8..40d05665 100644 --- a/src/core/corehighlightrulemanager.cpp +++ b/src/core/corehighlightrulemanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -23,35 +23,28 @@ #include "core.h" #include "coresession.h" -INIT_SYNCABLE_OBJECT(CoreHighlightRuleManager) -CoreHighlightRuleManager::CoreHighlightRuleManager(CoreSession *parent) - : HighlightRuleManager(parent) -{ - CoreSession *session = qobject_cast(parent); - if (!session) { - qWarning() << "CoreHighlightRuleManager: unable to load HighlightRuleList. Parent is not a Coresession!"; - //loadDefaults(); - return; - } - - initSetHighlightRuleList(Core::getUserSetting(session->user(), "HighlightRuleList").toMap()); +constexpr auto settingsKey = "HighlightRuleList"; - // we store our settings whenever they change - connect(this, SIGNAL(updatedRemotely()), SLOT(save())); +CoreHighlightRuleManager::CoreHighlightRuleManager(CoreSession* session) + : HighlightRuleManager(session) + , _coreSession{session} +{ + // Load config from database if it exists + auto configMap = Core::getUserSetting(session->user(), settingsKey).toMap(); + if (!configMap.isEmpty()) + update(configMap); + // Otherwise, we just use the defaults initialized in the base class + + // We store our settings whenever they change + connect(this, &SyncableObject::updatedRemotely, this, &CoreHighlightRuleManager::save); } -void CoreHighlightRuleManager::save() const +void CoreHighlightRuleManager::save() { - CoreSession *session = qobject_cast(parent()); - if (!session) { - qWarning() << "CoreHighlightRuleManager: unable to save HighlightRuleList. Parent is not a Coresession!"; - return; - } - - Core::setUserSetting(session->user(), "HighlightRuleList", initHighlightRuleList()); + Core::setUserSetting(_coreSession->user(), settingsKey, toVariantMap()); } -bool CoreHighlightRuleManager::match(const RawMessage &msg, const QString ¤tNick, const QStringList &identityNicks) +bool CoreHighlightRuleManager::match(const RawMessage& msg, const QString& currentNick, const QStringList& identityNicks) { - return match(msg.text, msg.sender, msg.type, msg.flags, msg.target, currentNick, identityNicks); + return match(msg.networkId, msg.text, msg.sender, msg.type, msg.flags, msg.target, currentNick, identityNicks); }