X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fcorehighlightrulemanager.cpp;h=eed5655be55a08ede04950e6bae005a2a276e125;hb=f12d6496251729f7d21f4fbcb0814dec7fba4b75;hp=6299e82d3bd8100cfc6e9916f8a053d73e0efc02;hpb=71d3d0d705a853fa8fea3729e13dbddf52363417;p=quassel.git diff --git a/src/core/corehighlightrulemanager.cpp b/src/core/corehighlightrulemanager.cpp index 6299e82d..eed5655b 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,30 @@ #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); }