X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fcorehighlightrulemanager.cpp;h=b9c81beaf2b2292a01758ac2ee258feb975ef1cf;hb=cdc6091a2e02b84a48937cda287a0769ceb8726a;hp=6299e82d3bd8100cfc6e9916f8a053d73e0efc02;hpb=71d3d0d705a853fa8fea3729e13dbddf52363417;p=quassel.git diff --git a/src/core/corehighlightrulemanager.cpp b/src/core/corehighlightrulemanager.cpp index 6299e82d..b9c81bea 100644 --- a/src/core/corehighlightrulemanager.cpp +++ b/src/core/corehighlightrulemanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -23,35 +23,31 @@ #include "core.h" #include "coresession.h" +constexpr auto settingsKey = "HighlightRuleList"; + INIT_SYNCABLE_OBJECT(CoreHighlightRuleManager) -CoreHighlightRuleManager::CoreHighlightRuleManager(CoreSession *parent) - : HighlightRuleManager(parent) +CoreHighlightRuleManager::CoreHighlightRuleManager(CoreSession *session) + : HighlightRuleManager(session) + , _coreSession{session} { - 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()); + // 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 + // We store our settings whenever they change connect(this, SIGNAL(updatedRemotely()), SLOT(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 ¤tNick, + 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); }