1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-06-28 14:49:30 +00:00

settings: Break settings binding cycle

This breaks the settings binding cycle for the "autoload-plugins" and
"preferred-audio-codecs" settings which went something like this:

g_settings_bind () is used with
G_SETTINGS_BIND_DEFAULT (G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET).
It grabs the value of our setting and sets it for the bound property.
This emits the notify signal causing the same value to be set for the
setting.

In effect this caused the setting to be marked as non-default because
Calls had changed the setting without user action. This caused updated
defaults not to apply for existing installations.
This commit is contained in:
Evangelos Ribeiro Tzaras 2022-04-12 09:25:55 +02:00
parent 94fa13af4c
commit 46f46cf3ec

View file

@ -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]);
}