From: Shane Synan Date: Mon, 16 Jul 2018 21:47:37 +0000 (-0500) Subject: core: Fix highlight nick config save/load X-Git-Tag: 0.13-rc1~9 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=b3b83bb123fb3087eba7147539ec0e7a34c6258b core: Fix highlight nick config save/load Modernize CoreHighlightRuleManager to use the conventions of DccConfig, saving/loading via SyncableObject serialization handling for load/save. This simplifies the code and fixes highlight nick configuration (highlightNick, nicksCaseSensitive) not being persisted after core restart. Add some documentation, too. Fixes regression from 17c39210b1bce04795046657642de66292518fe6. --- diff --git a/src/core/corehighlightrulemanager.cpp b/src/core/corehighlightrulemanager.cpp index d7ccd8f8..eed5655b 100644 --- a/src/core/corehighlightrulemanager.cpp +++ b/src/core/corehighlightrulemanager.cpp @@ -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); } diff --git a/src/core/corehighlightrulemanager.h b/src/core/corehighlightrulemanager.h index 85a26ff5..4cf3427d 100644 --- a/src/core/corehighlightrulemanager.h +++ b/src/core/corehighlightrulemanager.h @@ -25,6 +25,11 @@ class CoreSession; struct RawMessage; +/** + * Core-side specialization for HighlightRuleManager. + * + * Adds the ability to load/save the settings from/to the database. + */ class CoreHighlightRuleManager : public HighlightRuleManager { Q_OBJECT @@ -33,7 +38,12 @@ class CoreHighlightRuleManager : public HighlightRuleManager using HighlightRuleManager::match; public: - explicit CoreHighlightRuleManager(CoreSession *parent); + /** + * Constructor. + * + * @param[in] session Pointer to the parent CoreSession (takes ownership) + */ + explicit CoreHighlightRuleManager(CoreSession *session); virtual const QMetaObject *syncMetaObject() const override { return &HighlightRuleManager::staticMetaObject; } @@ -50,5 +60,11 @@ public slots: } private slots: - void save() const; + /** + * Saves the config to the database. + */ + void save(); + +private: + CoreSession *_coreSession {nullptr}; ///< Pointer to the parent CoreSession };