From 479523abf9d23c6418090a63c1600607e38c91f6 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Thu, 29 Aug 2024 16:58:14 +0300 Subject: [PATCH] lib: settings: find the first loaded instance of WpSettings when metadata_name is NULL This allows changing the metadata name in the configuration file and get all the Lua scripts looking at this new settings metadata without requiring any other code changes. It can be useful in multi-instance setups where we'd like the instances to be isolated and load their own settings instead of relying on each other for that. --- lib/wp/settings.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/wp/settings.c b/lib/wp/settings.c index 393647e8..8b5fda08 100644 --- a/lib/wp/settings.c +++ b/lib/wp/settings.c @@ -683,8 +683,11 @@ find_settings_func (gpointer g_object, gpointer metadata_name) if (!WP_IS_SETTINGS (g_object)) return FALSE; - return g_str_equal (((WpSettings *) g_object)->metadata_name, - (gchar *) metadata_name); + if (metadata_name) + return g_str_equal (((WpSettings *) g_object)->metadata_name, + (gchar *) metadata_name); + else + return TRUE; } /*! @@ -693,7 +696,8 @@ find_settings_func (gpointer g_object, gpointer metadata_name) * \ingroup wpsettings * \param core the WpCore * \param metadata_name (nullable): the name of the metadata object that the - * settings object is associated with; NULL means the default "sm-settings" + * settings object is associated with; NULL returns the first settings object + * that is found * \returns (transfer full) (nullable): the WpSettings object, or NULL if not * found */ @@ -703,7 +707,7 @@ wp_settings_find (WpCore * core, const gchar * metadata_name) g_return_val_if_fail (WP_IS_CORE (core), NULL); GObject *s = wp_core_find_object (core, (GEqualFunc) find_settings_func, - metadata_name ? metadata_name : "sm-settings"); + metadata_name); return s ? WP_SETTINGS (s) : NULL; }