/***************************************************************************
- * Copyright (C) 2005-2016 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 *
#include "core.h"
#include "coresession.h"
-INIT_SYNCABLE_OBJECT(CoreHighlightRuleManager)
-CoreHighlightRuleManager::CoreHighlightRuleManager(CoreSession *parent)
- : HighlightRuleManager(parent)
-{
- CoreSession *session = qobject_cast<CoreSession*>(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<CoreSession *>(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);
}