diff --git a/src/calls-settings.c b/src/calls-settings.c index ca34fda..2816f64 100644 --- a/src/calls-settings.c +++ b/src/calls-settings.c @@ -50,6 +50,9 @@ struct _CallsSettings { GObject parent_instance; GSettings *settings; + + GStrv autoload_plugins; + GStrv preferred_audio_codecs; }; G_DEFINE_TYPE (CallsSettings, calls_settings, G_TYPE_OBJECT) @@ -126,10 +129,14 @@ calls_settings_constructed (GObject *object) G_OBJECT_CLASS (calls_settings_parent_class)->constructed (object); - g_settings_bind (self->settings, "auto-use-default-origins", - self, "auto-use-default-origins", G_SETTINGS_BIND_DEFAULT); + /** + * The country code is the only persistent setting which should be written + * from within Calls (by looking at the MCC of the network the modem is connected to) + */ g_settings_bind (self->settings, "country-code", self, "country-code", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (self->settings, "auto-use-default-origins", + self, "auto-use-default-origins", G_SETTINGS_BIND_DEFAULT); g_settings_bind (self->settings, "autoload-plugins", self, "autoload-plugins", G_SETTINGS_BIND_DEFAULT); g_settings_bind (self->settings, "preferred-audio-codecs", @@ -163,27 +170,27 @@ calls_settings_class_init (CallsSettingsClass *klass) "auto use default origins", "Automatically use default origins", TRUE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); props[PROP_COUNTRY_CODE] = g_param_spec_string ("country-code", "country code", "The country code (usually from the modem)", "", - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); props[PROP_AUTOLOAD_PLUGINS] = g_param_spec_boxed ("autoload-plugins", "autoload plugins", "The plugins to automatically load on startup", G_TYPE_STRV, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); props[PROP_PREFERRED_AUDIO_CODECS] = g_param_spec_boxed ("preferred-audio-codecs", "Preferred audio codecs", "The audio codecs to prefer for VoIP calls", G_TYPE_STRV, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } @@ -296,7 +303,7 @@ calls_settings_get_autoload_plugins (CallsSettings *self) /** * calls_settings_set_autoload_plugins: * @self: A #CallsSettings - * @plugins: (nullable) (array zero-terminated=1): The plugins to autoload + * @plugins: (array zero-terminated=1): The plugins to autoload * * Sets the plugins that should be loaded on startup. */ @@ -304,9 +311,22 @@ void calls_settings_set_autoload_plugins (CallsSettings *self, const char * const *plugins) { - g_return_if_fail (CALLS_IS_SETTINGS (self)); + gboolean initial = TRUE; - g_settings_set_strv (G_SETTINGS (self->settings), "autoload-plugins", plugins); + g_return_if_fail (CALLS_IS_SETTINGS (self)); + g_return_if_fail (plugins); + + if (self->autoload_plugins) { + initial = FALSE; + if (g_strv_equal (plugins, (const char * const *) self->autoload_plugins)) + return; + } + + g_free (self->autoload_plugins); + self->autoload_plugins = g_strdupv ((char **) plugins); + + if (!initial) + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_AUTOLOAD_PLUGINS]); } @@ -322,13 +342,13 @@ calls_settings_get_preferred_audio_codecs (CallsSettings *self) { g_return_val_if_fail (CALLS_IS_SETTINGS (self), NULL); - return g_settings_get_strv (self->settings, "preferred-audio-codecs"); + return g_strdupv (self->preferred_audio_codecs); } /** * calls_settings_set_preferred_audio_codecs: * @self: A #CallsSettings - * @codecs: (nullable) (array zero-terminated=1): The preferred codecs + * @codecs: (array zero-terminated=1): The preferred codecs * * Set the preferred audio codecs for VoIP calls. */ @@ -336,7 +356,21 @@ void calls_settings_set_preferred_audio_codecs (CallsSettings *self, const char * const *codecs) { - g_return_if_fail (CALLS_IS_SETTINGS (self)); + gboolean initial = TRUE; - g_settings_set_strv (self->settings, "preferred-audio-codecs", codecs); + g_return_if_fail (CALLS_IS_SETTINGS (self)); + g_return_if_fail (codecs); + + if (self->preferred_audio_codecs) { + initial = FALSE; + + if (g_strv_equal (codecs, (const char * const *) self->preferred_audio_codecs)) + return; + } + + g_free (self->preferred_audio_codecs); + self->preferred_audio_codecs = g_strdupv ((char **) codecs); + + if (!initial) + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_PREFERRED_AUDIO_CODECS]); }