[gnome-terminal] settings: Remove direct dconf dependency



commit e895306524f99c7d6fc1cc2ba58a7f572f8fd7fd
Author: Christian Persch <chpe src gnome org>
Date:   Fri Aug 26 22:10:31 2022 +0200

    settings: Remove direct dconf dependency
    
    Instead, use GSettingsBackend::write-tree which will have the same
    effect as using dconf directly, when using the dconf backend, and
    also works elsewhere, e.g. for the memory and keyfile settings backend,
    and potentially also everywhere else.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/7822

 meson.build                               |   2 -
 src/meson.build                           |   4 -
 src/org.gnome.Terminal.SettingsBridge.xml |  13 ---
 src/terminal-dconf.cc                     | 124 -----------------------
 src/terminal-dconf.hh                     |  41 --------
 src/terminal-prefs.cc                     |   1 -
 src/terminal-settings-bridge-backend.cc   |  56 -----------
 src/terminal-settings-bridge-backend.hh   |  11 ---
 src/terminal-settings-bridge-impl.cc      |  41 --------
 src/terminal-settings-list.cc             | 159 +++++++++---------------------
 src/terminal-settings-utils.cc            | 142 ++++++++++++++++++++++----
 src/terminal-settings-utils.hh            |  16 +++
 12 files changed, 187 insertions(+), 423 deletions(-)
---
diff --git a/meson.build b/meson.build
index a25a04f7..b8b1e4f3 100644
--- a/meson.build
+++ b/meson.build
@@ -55,7 +55,6 @@ gtk_req_version              = '3.22.27'
 gtk_min_req_version          = '3.18'
 gtk_max_allowed_version      = '3.24'
 
-dconf_req_version            = '0.14.0'
 libnautilus_ext_req_version  = '43'
 pcre2_req_version            = '10.00'
 schemas_req_version          = '0.1.0'
@@ -329,7 +328,6 @@ add_project_arguments(global_cxxflags, language: 'cpp')
 
 vte_dep       = dependency(vte_req,        version: '>=' + vte_req_version)
 
-dconf_dep     = dependency('dconf',        version: '>=' + dconf_req_version)
 gio_dep       = dependency('gio-2.0',      version: '>=' + glib_req_version)
 gio_unix_dep  = dependency('gio-unix-2.0', version: '>=' + glib_req_version)
 glib_dep      = dependency('glib-2.0',     version: '>=' + glib_req_version)
diff --git a/src/meson.build b/src/meson.build
index 6676fbb2..df24c102 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -104,8 +104,6 @@ misc_sources = files(
 )
 
 profiles_sources = files(
-  'terminal-dconf.cc',
-  'terminal-dconf.hh',
   'terminal-profiles-list.cc',
   'terminal-profiles-list.hh',
   'terminal-schemas.hh',
@@ -250,7 +248,6 @@ server_cxxflags = common_cxxflags + [
 ]
 
 server_deps = [
-  dconf_dep,
   gio_dep,
   gio_unix_dep,
   glib_dep,
@@ -367,7 +364,6 @@ client_cxxflags = common_cxxflags + [
 ]
 
 client_deps = [
-  dconf_dep,
   gio_dep,
   gio_unix_dep,
   glib_dep,
diff --git a/src/org.gnome.Terminal.SettingsBridge.xml b/src/org.gnome.Terminal.SettingsBridge.xml
index f07551e2..4dac6d78 100644
--- a/src/org.gnome.Terminal.SettingsBridge.xml
+++ b/src/org.gnome.Terminal.SettingsBridge.xml
@@ -21,19 +21,6 @@
   <interface name="org.gnome.Terminal.SettingsBridge">
     <annotation name="org.gtk.GDBus.C.Name" value="SettingsBridge" />
 
-    <method name="clone_schema">
-      <arg type="s" name="schema_id" direction="in" />
-      <arg type="s" name="path_from" direction="in" />
-      <arg type="s" name="path_to" direction="in" />
-      <arg type="a(sv)" name="extra_prefs" direction="in">
-        <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true" />
-      </arg>
-    </method>
-
-    <method name="erase_path">
-      <arg type="s" name="path" direction="in" />
-    </method>
-
     <method name="get_permission">
       <arg type="s" name="path" direction="in" />
       <arg type="v" name="permission" direction="out" />
diff --git a/src/terminal-prefs.cc b/src/terminal-prefs.cc
index 300b2868..1163f739 100644
--- a/src/terminal-prefs.cc
+++ b/src/terminal-prefs.cc
@@ -21,7 +21,6 @@
 #include <string.h>
 
 #include <uuid.h>
-#include <dconf.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
diff --git a/src/terminal-settings-bridge-backend.cc b/src/terminal-settings-bridge-backend.cc
index 66805bbd..2a6f2a13 100644
--- a/src/terminal-settings-bridge-backend.cc
+++ b/src/terminal-settings-bridge-backend.cc
@@ -577,59 +577,3 @@ terminal_settings_bridge_backend_new(TerminalSettingsBridge* bridge)
                   "settings-bridge", bridge,
                   nullptr));
 }
-
-void
-terminal_settings_bridge_backend_clone_schema(TerminalSettingsBridgeBackend* backend,
-                                              GSettingsSchemaSource*schema_source,
-                                              char const* schema_id,
-                                              char const* path,
-                                              char const* new_path,
-                                              char const* first_key,
-                                              ...)
-{
-  auto const impl = IMPL(backend);
-
-  auto builder = GVariantBuilder{};
-  g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sv)"));
-
-  va_list args;
-  va_start(args, first_key);
-  while (first_key != nullptr) {
-    auto const type = va_arg(args, char const*);
-    auto const value = g_variant_new_va(type, nullptr, &args);
-    gs_free auto wkey = g_strconcat(new_path, first_key, nullptr);
-
-    g_variant_builder_add(&builder, "(sv)", wkey, value);
-    first_key = va_arg(args, char const*);
-  }
-  va_end(args);
-
-  auto const r =
-    terminal_settings_bridge_call_clone_schema_sync(impl->bridge,
-                                                    schema_id,
-                                                    path,
-                                                    new_path,
-                                                    g_variant_builder_end(&builder),
-                                                    impl->cancellable,
-                                                    nullptr);
-
-  _terminal_debug_print(TERMINAL_DEBUG_BRIDGE,
-                        "Bridge backend ::clone_schema schema %s from-path %s to-path %s success %d\n",
-                        schema_id, path, new_path, r);
-}
-
-void
-terminal_settings_bridge_backend_erase_path(TerminalSettingsBridgeBackend* backend,
-                                            char const* path)
-{
-  auto const impl = IMPL(backend);
-  auto const r =
-    terminal_settings_bridge_call_erase_path_sync(impl->bridge,
-                                                  path,
-                                                  impl->cancellable,
-                                                  nullptr);
-
-  _terminal_debug_print(TERMINAL_DEBUG_BRIDGE,
-                        "Bridge backend ::erase_path path %s success %d\n",
-                        path, r);
-}
diff --git a/src/terminal-settings-bridge-backend.hh b/src/terminal-settings-bridge-backend.hh
index 8a6bff15..2b7c1887 100644
--- a/src/terminal-settings-bridge-backend.hh
+++ b/src/terminal-settings-bridge-backend.hh
@@ -35,15 +35,4 @@ GType terminal_settings_bridge_backend_get_type(void);
 
 GSettingsBackend* terminal_settings_bridge_backend_new(TerminalSettingsBridge* bridge);
 
-void terminal_settings_bridge_backend_clone_schema(TerminalSettingsBridgeBackend* backend,
-                                                   GSettingsSchemaSource*schema_source,
-                                                   char const* schema_id,
-                                                   char const* path,
-                                                   char const* new_path,
-                                                   char const* first_key,
-                                                   ...);
-
-void terminal_settings_bridge_backend_erase_path(TerminalSettingsBridgeBackend* backend,
-                                                 char const* path);
-
 G_END_DECLS
diff --git a/src/terminal-settings-bridge-impl.cc b/src/terminal-settings-bridge-impl.cc
index 14ab3682..ec387fd1 100644
--- a/src/terminal-settings-bridge-impl.cc
+++ b/src/terminal-settings-bridge-impl.cc
@@ -23,7 +23,6 @@
 #include "terminal-settings-bridge-impl.hh"
 
 #include "terminal-app.hh"
-#include "terminal-dconf.hh"
 #include "terminal-debug.hh"
 #include "terminal-libgsystem.hh"
 #include "terminal-settings-utils.hh"
@@ -141,44 +140,6 @@ success(GDBusMethodInvocation* invocation,
 
 /* TerminalSettingsBridge interface implementation */
 
-static gboolean
-terminal_settings_bridge_impl_clone_schema(TerminalSettingsBridge* object,
-                                           GDBusMethodInvocation* invocation,
-                                           char const* schema_id,
-                                           char const* path_from,
-                                           char const* path_to,
-                                           GVariant* asv)
-{
-  _terminal_debug_print(TERMINAL_DEBUG_BRIDGE,
-                        "Bridge impl ::clone_schema schema %s from-path %s to-path %s\n",
-                        schema_id, path_from, path_to);
-
-  auto const impl = IMPL(object);
-  if (terminal_dconf_backend_is_dconf(impl->backend)) {
-    auto const schema_source = terminal_app_get_schema_source(terminal_app_get());
-    terminal_dconf_clone_schemav(schema_source, schema_id, path_from, path_to, asv);
-  }
-
-  return nothing(invocation);
-}
-
-static gboolean
-terminal_settings_bridge_impl_erase_path(TerminalSettingsBridge* object,
-                                         GDBusMethodInvocation* invocation,
-                                         char const* path)
-{
-  _terminal_debug_print(TERMINAL_DEBUG_BRIDGE,
-                        "Bridge impl ::erase_path path %s\n",
-                        path);
-
-  auto const impl = IMPL(object);
-  if (terminal_dconf_backend_is_dconf(impl->backend)) {
-    terminal_dconf_erase_path(path);
-  }
-
-  return nothing(invocation);
-}
-
 static gboolean
 terminal_settings_bridge_impl_get_permission(TerminalSettingsBridge* object,
                                              GDBusMethodInvocation* invocation,
@@ -360,8 +321,6 @@ terminal_settings_bridge_impl_write_tree(TerminalSettingsBridge* object,
 static void
 terminal_settings_bridge_impl_iface_init(TerminalSettingsBridgeIface* iface) noexcept
 {
-  iface->handle_clone_schema = terminal_settings_bridge_impl_clone_schema;
-  iface->handle_erase_path = terminal_settings_bridge_impl_erase_path;
   iface->handle_get_permission = terminal_settings_bridge_impl_get_permission;
   iface->handle_get_writable = terminal_settings_bridge_impl_get_writable;
   iface->handle_read = terminal_settings_bridge_impl_read;
diff --git a/src/terminal-settings-list.cc b/src/terminal-settings-list.cc
index 12d74a4a..40b9a985 100644
--- a/src/terminal-settings-list.cc
+++ b/src/terminal-settings-list.cc
@@ -30,13 +30,8 @@
 #include "terminal-settings-utils.hh"
 #include "terminal-schemas.hh"
 #include "terminal-debug.hh"
-#include "terminal-dconf.hh"
 #include "terminal-libgsystem.hh"
 
-#ifdef TERMINAL_PREFERENCES
-#include "terminal-settings-bridge-backend.hh"
-#endif
-
 struct _TerminalSettingsList {
   GSettings parent;
 
@@ -131,6 +126,8 @@ strv_find (char **strv,
   return -1;
 }
 
+#if defined(TERMINAL_SERVER) || defined(TERMINAL_PREFERENCES)
+
 static char **
 strv_dupv_insert (char **strv,
                   const char *str)
@@ -178,6 +175,8 @@ strv_dupv_remove (char **strv,
   return nstrv;
 }
 
+#endif /* TERMINAL_SERVER || TERMINAL_PREFERENCES */
+
 gboolean
 terminal_settings_list_valid_uuid (const char *str)
 {
@@ -189,6 +188,8 @@ terminal_settings_list_valid_uuid (const char *str)
   return uuid_parse ((char *) str, u) == 0;
 }
 
+#if defined(TERMINAL_SERVER) || defined(TERMINAL_PREFERENCES)
+
 static char *
 new_list_entry (void)
 {
@@ -201,6 +202,8 @@ new_list_entry (void)
   return g_strdup (name);
 }
 
+#endif /* TERMINAL_SERVER || TERMINAL_PREFERENCES */
+
 static gboolean
 validate_list (TerminalSettingsList *list,
                char **entries)
@@ -272,114 +275,48 @@ terminal_settings_list_ref_child_internal (TerminalSettingsList *list,
   return (GSettings*)g_object_ref(child);
 }
 
-static char *
-new_child (TerminalSettingsList *list,
-           const char *name)
-{
-  char *new_uuid = new_list_entry ();
-
-  if (name != nullptr) {
-    gs_free char *new_path = path_new (list, new_uuid);
-    gs_unref_object GSettings *child =
-      terminal_g_settings_new_with_path(list->settings_backend,
-                                        list->schema_source,
-                                        list->child_schema_id,
-                                        new_path);
-    g_settings_set_string (child, TERMINAL_PROFILE_VISIBLE_NAME_KEY, name);
-  }
-
-  return new_uuid;
-}
+#if defined(TERMINAL_SERVER) || defined(TERMINAL_PREFERENCES)
 
 static char *
-clone_child_dconf (TerminalSettingsList *list,
-                   const char *uuid,
-                   const char *name)
-{
-  char* const new_uuid = new_list_entry();
-
-  _terminal_debug_print (TERMINAL_DEBUG_SETTINGS_LIST,
-                         "%s UUID %s NEW UUID %s \n", G_STRFUNC, uuid ? uuid : "(null)", new_uuid);
-
-  gs_free auto path = path_new(list, uuid);
-  gs_free auto new_path = path_new(list, new_uuid);
-
-  if (name)
-    terminal_dconf_clone_schema(list->schema_source,
-                                list->child_schema_id,
-                                path,
-                                new_path,
-                                TERMINAL_PROFILE_VISIBLE_NAME_KEY, "s", name,
-                                nullptr);
-  else
-    terminal_dconf_clone_schema(list->schema_source,
-                                list->child_schema_id,
-                                path,
-                                new_path,
-                                nullptr);
-
-  return new_uuid;
-}
-
-#ifdef TERMINAL_PREFERENCES
-
-static char *
-clone_child_bridge (TerminalSettingsList *list,
-                    const char *uuid,
-                    const char *name)
+terminal_settings_list_add_child_internal (TerminalSettingsList *list,
+                                           const char *uuid,
+                                           const char *name)
 {
-  char* const new_uuid = new_list_entry();
 
+  auto const new_uuid = new_list_entry();
   _terminal_debug_print (TERMINAL_DEBUG_SETTINGS_LIST,
-                         "%s UUID %s NEW UUID %s \n", G_STRFUNC, uuid ? uuid : "(null)", new_uuid);
+                         "%s NEW UUID %s\n", G_STRFUNC, new_uuid);
 
   gs_free auto path = path_new(list, uuid);
   gs_free auto new_path = path_new(list, new_uuid);
 
-  if (name)
-    terminal_settings_bridge_backend_clone_schema(TERMINAL_SETTINGS_BRIDGE_BACKEND(list->settings_backend),
-                                                  list->schema_source,
-                                                  list->child_schema_id,
-                                                  path,
-                                                  new_path,
-                                                  TERMINAL_PROFILE_VISIBLE_NAME_KEY, "s", name,
-                                                  nullptr);
-  else
-    terminal_settings_bridge_backend_clone_schema(TERMINAL_SETTINGS_BRIDGE_BACKEND(list->settings_backend),
-                                                  list->schema_source,
-                                                  list->child_schema_id,
-                                                  path,
-                                                  new_path,
-                                                  nullptr);
-
-  return new_uuid;
-}
-
-#endif /* TERMINAL_PREFERENCES */
-
-static char *
-terminal_settings_list_add_child_internal (TerminalSettingsList *list,
-                                           const char *uuid,
-                                           const char *name)
-{
-  char *new_uuid;
-  gs_strfreev char **new_uuids;
+  auto tree = terminal_g_settings_backend_create_tree();
+  terminal_g_settings_backend_clone_schema(list->settings_backend,
+                                           list->schema_source,
+                                           list->child_schema_id,
+                                           path,
+                                           new_path,
+                                           tree);
+  if (name) {
+    g_tree_insert(tree,
+                  g_strconcat(new_path, TERMINAL_PROFILE_VISIBLE_NAME_KEY, nullptr), // transfer
+                  g_variant_take_ref(g_variant_new_string(name))); // transfer
+  }
 
-  if (uuid && terminal_dconf_backend_is_dconf (list->settings_backend))
-    new_uuid = clone_child_dconf (list, uuid, name);
-#ifdef TERMINAL_PREFERENCES
-  else if (uuid && TERMINAL_IS_SETTINGS_BRIDGE_BACKEND (list->settings_backend))
-    new_uuid = clone_child_bridge (list, uuid, name);
+#ifdef ENABLE_DEBUG
+  _TERMINAL_DEBUG_IF(TERMINAL_DEBUG_SETTINGS_LIST) {
+    g_printerr("Cloning schema %s from %s -> %s\n", list->child_schema_id, path, new_path);
+    terminal_g_settings_backend_print_tree(tree);
+  }
 #endif
-  else
-    new_uuid = new_child (list, name);
 
-  _terminal_debug_print (TERMINAL_DEBUG_SETTINGS_LIST,
-                         "%s NEW UUID %s\n", G_STRFUNC, new_uuid);
+  auto const tag = &list;
+  (void)terminal_g_settings_backend_write_tree(list->settings_backend, tree, tag);
+  g_tree_unref(tree);
 
-  new_uuids = strv_dupv_insert (list->uuids, new_uuid);
-  g_settings_set_strv (&list->parent, TERMINAL_SETTINGS_LIST_LIST_KEY,
-                       (const char * const *) new_uuids);
+  gs_strfreev auto new_uuids = strv_dupv_insert(list->uuids, new_uuid);
+  g_settings_set_strv(&list->parent, TERMINAL_SETTINGS_LIST_LIST_KEY,
+                      (char const* const*)new_uuids);
 
   return new_uuid;
 }
@@ -406,19 +343,15 @@ terminal_settings_list_remove_child_internal (TerminalSettingsList *list,
     g_settings_set_string (&list->parent, TERMINAL_SETTINGS_LIST_DEFAULT_KEY, "");
 
   /* Now we unset all keys under the child */
-  if (terminal_dconf_backend_is_dconf (list->settings_backend)) {
-    gs_free auto path = path_new(list, uuid);
-    terminal_dconf_erase_path(path);
-  }
-#ifdef TERMINAL_PREFERENCES
-  else if (TERMINAL_IS_SETTINGS_BRIDGE_BACKEND (list->settings_backend)) {
-    gs_free auto path = path_new(list, uuid);
-    terminal_settings_bridge_backend_erase_path(TERMINAL_SETTINGS_BRIDGE_BACKEND (list->settings_backend),
-                                                path);
-  }
-#endif
+  gs_free auto path = path_new(list, uuid);
+  terminal_g_settings_backend_erase_path(list->settings_backend,
+                                         list->schema_source,
+                                         list->child_schema_id,
+                                         path);
 }
 
+#endif /* TERMINAL_SERVER || TERMINAL_PREFERENCES */
+
 static void
 terminal_settings_list_update_list (TerminalSettingsList *list)
 {
@@ -841,6 +774,8 @@ terminal_settings_list_ref_default_child (TerminalSettingsList *list)
   return terminal_settings_list_ref_child_internal (list, uuid);
 }
 
+#if defined(TERMINAL_SERVER) || defined(TERMINAL_PREFERENCES)
+
 /**
  * terminal_settings_list_add_child:
  * @list: a #TerminalSettingsList
@@ -898,6 +833,8 @@ terminal_settings_list_remove_child (TerminalSettingsList *list,
   terminal_settings_list_remove_child_internal (list, uuid);
 }
 
+#endif /* TERMINAL_SERVER || TERMINAL_PREFERENCES */
+
 /**
  * terminal_settings_list_dup_uuid_from_child:
  * @list: a #TerminalSettingsList
diff --git a/src/terminal-settings-utils.cc b/src/terminal-settings-utils.cc
index 0b52ef8a..f64d9cc6 100644
--- a/src/terminal-settings-utils.cc
+++ b/src/terminal-settings-utils.cc
@@ -121,6 +121,102 @@ terminal_g_settings_new(GSettingsBackend* backend,
 
 #if defined(TERMINAL_SERVER) || defined(TERMINAL_PREFERENCES)
 
+void
+terminal_g_settings_backend_clone_schema(GSettingsBackend* backend,
+                                         GSettingsSchemaSource* schema_source,
+                                         char const* schema_id,
+                                         char const* path,
+                                         char const* new_path,
+                                         GTree* tree)
+{
+  gs_unref_settings_schema auto schema =
+    g_settings_schema_source_lookup(schema_source, schema_id, true);
+  if (schema == nullptr) [[unlikely]] // This shouldn't really happen ever
+    return;
+
+  gs_strfreev auto keys = g_settings_schema_list_keys(schema);
+
+  for (auto i = 0; keys[i]; ++i) {
+    gs_unref_settings_schema_key auto schema_key =
+      g_settings_schema_get_key(schema, keys[i]);
+
+    gs_free auto rkey = g_strconcat(path, keys[i], nullptr);
+    auto const value =
+      terminal_g_settings_backend_read(backend,
+                                       rkey,
+                                       g_settings_schema_key_get_value_type(schema_key),
+                                       false);
+
+    if (value) {
+      g_tree_insert(tree,
+                    g_strconcat(new_path, keys[i], nullptr), // transfer
+                    value); // transfer
+    }
+  }
+}
+
+gboolean
+terminal_g_settings_backend_erase_path(GSettingsBackend* backend,
+                                       GSettingsSchemaSource* schema_source,
+                                       char const* schema_id,
+                                       char const* path)
+
+{
+  // We want to erase all keys below @path, not just keys we wrote ourself
+  // or that are (currently) in a known schema.  DConf supports this kind of
+  // 'directory reset' by writing a NULL value for the non-key @path (i.e.
+  // which ends in a slash). However, neither g_settings_backend_reset() nor
+  // g_settings_backend_write() accept a non-key path, and the latter
+  // doesn't accept NULL values anyway. g_settings_backend_write_tree()
+  // does allow NULL values, and the DConf backend works fine with this and
+  // performs the directory reset, however it also (as is a documented
+  // requirement) calls g_settings_backend_changed_tree() which chokes on
+  // such a tree containing a non-key path.
+  //
+  // We could:
+  // 1. Just do nothing, i.e. leave the deleted settings lying around.
+  // 2. Fix glib. However, getting any improvements to gsettings into glib
+  //    seems almost impossible at this point.
+  // 3. Interpose a fixed g_settings_backend_changed_tree() that works
+  //    with these non-key paths. This will work with out-of-tree
+  //    settings backends like DConf. However, this will *not* work with
+  //    the settings backends inside libgio, like the memory and keyfile
+  //    backends, due to -Bsymbolic_functions.
+  // 4. At least reset those keys we know might exists, i.e. those in
+  //    the schema.
+  //
+  // Since I don't like 1, 2 is impossible, and 3 is too hacky, let's at least
+  // do 4.
+
+#if 0
+  // This is how this function would ideally work if glib was fixed (option 2 above)
+  auto tree = terminal_g_settings_backend_create_tree();
+  g_tree_insert(tree, g_strdup(path), nullptr);
+  auto const tag = &backend;
+  auto const r = terminal_g_settings_backend_write_tree(backend, tree, tag);
+  g_tree_unref(tree);
+#endif
+
+  gs_unref_settings_schema auto schema =
+    g_settings_schema_source_lookup(schema_source, schema_id, true);
+  if (schema == nullptr) [[unlikely]] // This shouldn't really happen ever
+    return false;
+
+  auto tree = terminal_g_settings_backend_create_tree();
+  gs_strfreev auto keys = g_settings_schema_list_keys(schema);
+
+  for (auto i = 0; keys[i]; ++i) {
+    g_tree_insert(tree,
+                  g_strconcat(path, keys[i], nullptr), // transfer
+                  nullptr); // reset key
+  }
+
+  auto const tag = &backend;
+  auto const r = terminal_g_settings_backend_write_tree(backend, tree, tag);
+  g_tree_unref(tree);
+  return r;
+}
+
 #define TERMINAL_SCHEMA_VERIFIER_ERROR (g_quark_from_static_string("TerminalSchemaVerifier"))
 
 typedef enum {
@@ -497,6 +593,8 @@ terminal_g_settings_schema_source_get_default(void)
   return g_settings_schema_source_ref(default_source);
 }
 
+#endif /* TERMINAL_SERVER || TERMINAL_PREFERENCES */
+
 // BEGIN copied from glib/gio/gsettingsbackend.c
 
 /*
@@ -553,25 +651,31 @@ terminal_g_settings_backend_create_tree(void)
                          variant_unref0);
 }
 
-/*
- * SPDX-License-Identifier: LGPL-2.1-or-later
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
- * Authors: Ryan Lortie <desrt desrt ca>
- *          Matthias Clasen <mclasen redhat com>
- */
+#ifdef ENABLE_DEBUG
+
+static gboolean
+print_tree(void* key,
+           void* value,
+           void* closure)
+{
+  g_printerr("  %s => %s\n",
+             reinterpret_cast<char const*>(key),
+             value ? g_variant_print(reinterpret_cast<GVariant*>(value), true): "(null)");
+
+  return false; // continue
+}
+
+void
+terminal_g_settings_backend_print_tree(GTree* tree)
+{
+  g_printerr("Settings tree: [\n");
+  g_tree_foreach(tree, print_tree, nullptr);
+  g_printerr("]\n");
+}
+
+#endif /* ENABLE_DEBUG */
+
+#if defined(TERMINAL_SERVER) || defined(TERMINAL_PREFERENCES)
 
 /*
  * g_settings_backend_read:
diff --git a/src/terminal-settings-utils.hh b/src/terminal-settings-utils.hh
index 90ca6256..9079485e 100644
--- a/src/terminal-settings-utils.hh
+++ b/src/terminal-settings-utils.hh
@@ -29,6 +29,22 @@ GSettings* terminal_g_settings_new_with_path (GSettingsBackend* backend,
                                               char const* schema_id,
                                               char const* path);
 
+void terminal_g_settings_backend_clone_schema(GSettingsBackend* backend,
+                                              GSettingsSchemaSource*schema_source,
+                                              char const* schema_id,
+                                              char const* path,
+                                              char const* new_path,
+                                              GTree* tree);
+
+gboolean terminal_g_settings_backend_erase_path(GSettingsBackend* backend,
+                                                GSettingsSchemaSource* schema_source,
+                                                char const* schema_id,
+                                                char const* path);
+
+GTree* terminal_g_settings_backend_create_tree(void);
+
+void terminal_g_settings_backend_print_tree(GTree* tree);
+
 GSettingsSchemaSource* terminal_g_settings_schema_source_get_default(void);
 
 GTree* terminal_g_settings_backend_create_tree(void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]