X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorehighlightrulemanager.cpp;h=99a046f3109d6d764ad1c9a949547de5904f5017;hp=c35ca508b52e465c468250f60d90751409c7967c;hb=fcacaaf16551524c7ebb6114254d005274cc3d63;hpb=16f22647e6890d3eb8c3e94f7a0700e12fa29e44 diff --git a/src/core/corehighlightrulemanager.cpp b/src/core/corehighlightrulemanager.cpp index c35ca508..99a046f3 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" -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 ¤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); }