Skip to content

Commit

Permalink
self fix for incorrect and duplicated records
Browse files Browse the repository at this point in the history
remove duplicated schemas for currect path
remove incorrect schemas for current path
  • Loading branch information
dnk committed Feb 18, 2023
1 parent 338f486 commit ef7481b
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions libmate-panel-applet/mate-panel-applet-gsettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,56 @@ add_to_dict (GVariant *dict, const gchar *schema, const gchar *path)
{
GVariantIter iter;
GVariantBuilder builder;
gboolean already_contains;
gboolean is_schema_found;
gboolean is_incorrect_schema;
gint path_counter;

gchar *key;
gchar *value;

g_variant_builder_init (&builder, (const GVariantType *) "a{ss}");
g_variant_iter_init (&iter, dict);

already_contains = FALSE;
is_schema_found = FALSE;
is_incorrect_schema = FALSE;
path_counter = 0;

while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
if ( g_strcmp0 (key, schema) == 0 && g_strcmp0 (value, path) == 0) {
already_contains = TRUE;
gboolean path_is_found = FALSE;
if (g_strcmp0 (value, path) == 0) {
path_is_found = TRUE;
path_counter++;
if (g_strcmp0 (key, schema) == 0) {
is_schema_found = TRUE;
} else {
// skip incoorect schema for path
is_incorrect_schema = TRUE;
g_free (key);
g_free (value);
continue;
}
}

if (!already_contains) {
gboolean need_add_to_dict = !path_is_found || path_counter < 2;

if (need_add_to_dict) {
g_variant_builder_add (&builder, "{ss}", key, value);
}

g_free (key);
g_free (value);

if (already_contains) {
break;
}
}

if (!already_contains) {
if (!is_schema_found) {
g_variant_builder_add (&builder, "{ss}", schema, path);
}

if (!is_schema_found || is_incorrect_schema || (path_counter > 1)) {
return g_variant_ref_sink (g_variant_builder_end (&builder));
} else {
g_variant_builder_clear (&builder);
return g_variant_ref (dict);
// no changes
return NULL;
}
}

Expand All @@ -80,8 +98,10 @@ register_dconf_editor_relocatable_schema (const gchar *schema, const gchar *path

if (g_variant_is_of_type (relocatable_schemas, G_VARIANT_TYPE_DICTIONARY)) {
GVariant * new_relocatable_schemas = add_to_dict (relocatable_schemas, schema, path);
g_settings_set_value (dconf_editor_settings, "relocatable-schemas-user-paths", new_relocatable_schemas);
g_variant_unref (new_relocatable_schemas);
if (new_relocatable_schemas) {
g_settings_set_value (dconf_editor_settings, "relocatable-schemas-user-paths", new_relocatable_schemas);
g_variant_unref (new_relocatable_schemas);
}
}

g_variant_unref (relocatable_schemas);
Expand Down

0 comments on commit ef7481b

Please sign in to comment.