lib: settings: make settings name optional

The "name" field needs to be optional, to be backward compatible with
old settings spec format.  If it's omitted, make it NULL.
This commit is contained in:
Pauli Virtanen 2025-07-24 12:00:21 +03:00
parent 9e47393643
commit 36f809fb50
5 changed files with 20 additions and 21 deletions

View file

@ -90,13 +90,15 @@ wp_settings_spec_new (WpSpaJson * spec_json)
/* Parse mandatory fields */
if (!wp_spa_json_object_get (spec_json,
"name", "s", &name,
"description", "s", &desc,
"type", "s", &type_str,
"default", "J", &def_value,
NULL))
return NULL;
/* Parse optional fields */
wp_spa_json_object_get (spec_json, "name", "s", &name, NULL);
/* Parse type and check if values are correct */
if (g_str_equal (type_str, "bool")) {
type = WP_SETTINGS_SPEC_TYPE_BOOL;
@ -153,7 +155,8 @@ wp_settings_spec_new (WpSpaJson * spec_json)
* \brief Gets the human-readable name of a settings spec
* \ingroup wpsettings
* \param self the settings spec object
* \returns the human-readable name of the settings spec
* \returns (nullable): the human-readable name of the settings spec,
* or NULL if none
*/
const gchar *
wp_settings_spec_get_name (WpSettingsSpec * self)

View file

@ -1453,7 +1453,8 @@ print_setting (WpSettings *s, const gchar *key)
printf ("- Id: %s\n", key);
/* print spec */
printf (" Name: %s\n", dgettext (GETTEXT_PACKAGE, name));
if (name)
printf (" Name: %s\n", dgettext (GETTEXT_PACKAGE, name));
printf (" Desc: %s\n", dgettext (GETTEXT_PACKAGE, desc));
printf (" Type: %s\n", settings_spec_type_to_string (val_type));
printf (" Default: %s", wp_spa_json_get_data (def));

View file

@ -11,13 +11,11 @@ context.modules = [
wireplumber.settings.schema = {
## Bluetooth
bluetooth.use-persistent-storage = {
name = "Persistent storage"
description = "Whether to use persistent BT storage or not"
type = "bool"
default = true
}
bluetooth.autoswitch-to-headset-profile = {
name = "Auto-switch to headset profile"
description = "Whether to autoswitch to BT headset profile or not"
type = "bool"
default = true
@ -25,19 +23,16 @@ wireplumber.settings.schema = {
## Device
device.restore-profile = {
name = "Restore profile"
description = "Whether to restore device profile or not"
type = "bool"
default = true
}
device.restore-routes = {
name = "Restore routes"
description = "Whether to restore device routes or not"
type = "bool"
default = true
}
device.routes.default-sink-volume = {
name = "Default sink volume"
description = "The default volume for sink devices"
type = "float"
default = 0.064
@ -45,7 +40,6 @@ wireplumber.settings.schema = {
max = 1.0
}
device.routes.default-source-volume = {
name = "Default source volume"
description = "The default volume for source devices"
type = "float"
default = 1.0
@ -55,13 +49,11 @@ wireplumber.settings.schema = {
## Linking
linking.allow-moving-streams = {
name = "Allow moving streams"
description = "Whether to allow metadata to move streams at runtime or not"
type = "bool"
default = true
}
linking.follow-default-target = {
name = "Follow default target"
description = "Whether to allow streams follow the default device or not"
type = "bool"
default = true
@ -69,7 +61,6 @@ wireplumber.settings.schema = {
## Monitor
monitor.camera-discovery-timeout = {
name = "Discovery timeout"
description = "The camera discovery timeout in milliseconds"
type = "int"
default = 1000
@ -79,37 +70,31 @@ wireplumber.settings.schema = {
## Node
node.features.audio.no-dsp = {
name = "No DSP"
description = "Whether to never convert audio to F32 format or not"
type = "bool"
default = false
}
node.features.audio.monitor-ports = {
name = "Monitor ports"
description = "Whether to enable monitor ports on audio nodes or not"
type = "bool"
default = true
}
node.features.audio.control-port = {
name = "Control ports"
description = "Whether to enable control ports on audio nodes or not"
type = "bool"
default = false
}
node.stream.restore-props = {
name = "Restore properties"
description = "Whether to restore properties on stream nodes or not"
type = "bool"
default = true
}
node.stream.restore-target = {
name = "Restore target"
description = "Whether to restore target on stream nodes or not"
type = "bool"
default = true
}
node.stream.default-playback-volume = {
name = "Default playback volume"
description = "The default volume for playback nodes"
type = "float"
default = 1.0
@ -117,7 +102,6 @@ wireplumber.settings.schema = {
max = 1.0
}
node.stream.default-capture-volume = {
name = "Default capture volume"
description = "The default volume for capture nodes"
type = "float"
default = 1.0
@ -125,13 +109,11 @@ wireplumber.settings.schema = {
max = 1.0
}
node.filter.forward-format = {
name = "Forward format"
description = "Whether to forward format on filter nodes or not"
type = "bool"
default = false
}
node.restore-default-targets = {
name = "Restore default target"
description = "Whether to restore default targets or not"
type = "bool"
default = true

View file

@ -877,6 +877,13 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
g_assert_cmpstr (wp_spa_json_get_data (j), ==, "{}");
g_clear_pointer (&j, wp_spa_json_unref);
}
/* Name omitted */
{
spec = wp_settings_get_spec (s, "test-setting-no-name");
name = wp_settings_spec_get_name (spec);
g_assert_null (name);
}
}
static void

View file

@ -56,6 +56,12 @@ wireplumber.settings.schema = {
type = "object"
default = {}
}
test-setting-no-name = {
# optional name field omitted
description = "test-setting-no-name description"
type = "bool"
default = false
}
}
wireplumber.settings = {