Skip to content

Commit

Permalink
tell dconf-edit about relocatable schemas (#1355)
Browse files Browse the repository at this point in the history
* tell dconf-edit about relocatable schemas

* self fix for incorrect and duplicated records

remove duplicated schemas for currect path
remove incorrect schemas for current path

* remove clock applet hack

* expose mate_panel_applet_settings_new to introspection

add "transfer full" annotation to make this method available throught
introspection
  • Loading branch information
dnk authored May 17, 2023
1 parent 1a16bc1 commit 277418c
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 10 deletions.
10 changes: 0 additions & 10 deletions applets/clock/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2411,18 +2411,8 @@ show_week_changed (GSettings *settings,
static void
setup_gsettings (ClockData *cd)
{
gint format;
gchar *custom_format;

cd->settings = mate_panel_applet_settings_new (MATE_PANEL_APPLET (cd->applet), CLOCK_SCHEMA);

/* hack to allow users to set custom format in dconf-editor */
format = g_settings_get_enum (cd->settings, KEY_FORMAT);
custom_format = g_settings_get_string (cd->settings, KEY_CUSTOM_FORMAT);
g_settings_set_enum (cd->settings, KEY_FORMAT, format);
g_settings_set_string (cd->settings, KEY_CUSTOM_FORMAT, custom_format);
g_free (custom_format);

g_signal_connect (cd->settings, "changed::" KEY_FORMAT, G_CALLBACK (format_changed), cd);
g_signal_connect (cd->settings, "changed::" KEY_SHOW_SECONDS, G_CALLBACK (show_seconds_changed), cd);
g_signal_connect (cd->settings, "changed::" KEY_SHOW_DATE, G_CALLBACK (show_date_changed), cd);
Expand Down
82 changes: 82 additions & 0 deletions libmate-panel-applet/mate-panel-applet-gsettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,87 @@
#include "mate-panel-applet.h"
#include "mate-panel-applet-gsettings.h"

static GVariant *
add_to_dict (GVariant *dict, const gchar *schema, const gchar *path)
{
GVariantIter iter;
GVariantBuilder builder;
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);

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

while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
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;
}
}

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 (!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);
// no changes
return NULL;
}
}

static void
register_dconf_editor_relocatable_schema (const gchar *schema, const gchar *path)
{
GSettings *dconf_editor_settings;
dconf_editor_settings = g_settings_new ("ca.desrt.dconf-editor.Settings");

if (dconf_editor_settings && g_settings_is_writable (dconf_editor_settings, "relocatable-schemas-user-paths")) {
GVariant *relocatable_schemas = g_settings_get_value (dconf_editor_settings, "relocatable-schemas-user-paths");

if (g_variant_is_of_type (relocatable_schemas, G_VARIANT_TYPE_DICTIONARY)) {
GVariant * new_relocatable_schemas = add_to_dict (relocatable_schemas, schema, path);
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);
}

g_object_unref (dconf_editor_settings);
}

GSettings *
mate_panel_applet_settings_new (MatePanelApplet *applet, gchar *schema)
{
Expand All @@ -41,6 +122,7 @@ mate_panel_applet_settings_new (MatePanelApplet *applet, gchar *schema)

if (path) {
settings = g_settings_new_with_path (schema, path);
register_dconf_editor_relocatable_schema (schema, path);
g_free (path);
}

Expand Down
8 changes: 8 additions & 0 deletions libmate-panel-applet/mate-panel-applet-gsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@

G_BEGIN_DECLS

/**
* mate_panel_applet_settings_new:
* @applet A #MatePanelApplet
* @schema applet's schema id
*
* Returns: (transfer full): a #GSettings. free when you used it
*/
GSettings* mate_panel_applet_settings_new (MatePanelApplet *applet, gchar *schema);

GList* mate_panel_applet_settings_get_glist (GSettings *settings, gchar *key);
void mate_panel_applet_settings_set_glist (GSettings *settings, gchar *key, GList *list);
GSList* mate_panel_applet_settings_get_gslist (GSettings *settings, gchar *key);
Expand Down
47 changes: 47 additions & 0 deletions mate-panel/panel-profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,52 @@ key_from_type (PanelGSettingsKeyType type) {
return NULL;
}

static GVariant *
remove_from_dict (GVariant *dict, const gchar *path)
{
GVariantIter iter;
GVariantBuilder builder;

gchar *key;
gchar *value;

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

while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
if ( g_strcmp0 (value, path) != 0) {
g_variant_builder_add (&builder, "{ss}", key, value);
}

g_free (key);
g_free (value);
}

return g_variant_ref_sink (g_variant_builder_end (&builder));
}

static void
unregister_dconf_editor_relocatable_schema (const gchar *path)
{
GSettings *dconf_editor_settings;
dconf_editor_settings = g_settings_new ("ca.desrt.dconf-editor.Settings");

if (dconf_editor_settings && g_settings_is_writable (dconf_editor_settings, "relocatable-schemas-user-paths")) {
GVariant *relocatable_schemas = g_settings_get_value (dconf_editor_settings, "relocatable-schemas-user-paths");

if (g_variant_is_of_type (relocatable_schemas, G_VARIANT_TYPE_DICTIONARY)) {
GVariant * new_relocatable_schemas = remove_from_dict (relocatable_schemas, path);
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);
}

g_object_unref (dconf_editor_settings);
}


void
panel_profile_add_to_list (PanelGSettingsKeyType type,
const char *id)
Expand Down Expand Up @@ -1345,6 +1391,7 @@ panel_profile_delete_dir (PanelGSettingsKeyType type,
gchar *subdir;
subdir = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/prefs/", id);
mate_dconf_recursive_reset (subdir, NULL);
unregister_dconf_editor_relocatable_schema (subdir);
g_free (subdir);
}

Expand Down

0 comments on commit 277418c

Please sign in to comment.