[glibmm/wip/dboles/SettingsSchemaSource-Issue#19] SettingsSchemaSource: Wrap new_from_directory()



commit 43f45746a0e477363929f497d171600cbd6b92cf
Author: Daniel Boles <dboles src gmail com>
Date:   Fri Nov 15 17:42:55 2019 +0000

    SettingsSchemaSource: Wrap new_from_directory()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783216
    https://gitlab.gnome.org/GNOME/glibmm/issues/19

 gio/src/settingsschemasource.ccg | 19 ++++++++++++++++++
 gio/src/settingsschemasource.hg  | 43 +++++++++++++++++++++++++++++++++-------
 2 files changed, 55 insertions(+), 7 deletions(-)
---
diff --git a/gio/src/settingsschemasource.ccg b/gio/src/settingsschemasource.ccg
index d1ae281d..699e9e8a 100644
--- a/gio/src/settingsschemasource.ccg
+++ b/gio/src/settingsschemasource.ccg
@@ -16,11 +16,30 @@
 
 #include <gio/gio.h>
 
+#include <glibmm/error.h>
 #include <glibmm/vectorutils.h>
 
 namespace Gio
 {
 
+Glib::RefPtr<SettingsSchemaSource>
+SettingsSchemaSource::create(const Glib::ustring& directory, bool trusted,
+                             const Glib::RefPtr<SettingsSchemaSource>& parent)
+{
+  auto parent_gobject = parent ? parent->gobj() : nullptr;
+  GError* gerror = nullptr;
+
+  auto gobject = g_settings_schema_source_new_from_directory(directory.c_str(),
+                                                             parent_gobject,
+                                                             trusted,
+                                                             &gerror);
+
+  if (gerror)
+    throw Glib::Error{gerror};
+
+  return Glib::wrap(gobject);
+}
+
 std::vector<Glib::ustring>
 SettingsSchemaSource::list_schemas(bool relocatable, bool recursive) const
 {
diff --git a/gio/src/settingsschemasource.hg b/gio/src/settingsschemasource.hg
index 69170794..ad0f2e24 100644
--- a/gio/src/settingsschemasource.hg
+++ b/gio/src/settingsschemasource.hg
@@ -47,13 +47,42 @@ protected:
 public:
   _WRAP_METHOD(static Glib::RefPtr<SettingsSchemaSource> get_default(), 
g_settings_schema_source_get_default, refreturn)
 
-/* TODO:
-GLIB_AVAILABLE_IN_2_32
-GSettingsSchemaSource * g_settings_schema_source_new_from_directory     (const gchar            *directory,
-                                                                         GSettingsSchemaSource  *parent,
-                                                                         gboolean                trusted,
-                                                                         GError                **error);
-*/
+  /** Attempts to create a new schema source corresponding to the contents of
+   * the given @a directory.
+   *
+   * This function is not required for normal uses of Gio::Settings but may be
+   * useful to authors of plugin management systems.
+   *
+   * @newin{2,64}
+   *
+   * @param directory: The filename of a directory. This directory should
+   * contain a file called <tt>gschemas.compiled</tt> as produced by the
+   * <tt>glib-compile-schemas</tt> tool.
+   *
+   * @param parent: Another Gio::SettingsSchemaSource, or an empty Glib::RefPtr.
+   * If non-empty, there are two effects: First, if lookup() is called with the
+   * <tt>recursive</tt> flag set to <tt>true</tt> and the schema cannot be found
+   * in the source, the lookup will recurse to the @a parent. Second, any
+   * references to other schemas specified in this source (i.e. <tt>child</tt>
+   * or <tt>extends</tt> references) may be resolved from the @a parent. For
+   * this second reason, except in very unusual situations, the @a parent
+   * should probably be the default schema source, as returned by get_default().
+   *
+   * @param trusted: Whether the @a directory is trusted. If <tt>true</tt>, the
+   * <tt>gschemas.compiled</tt> file therein is trusted not to be corrupted.
+   * This assumption has a performance advantage but can result in crashes or
+   * inconsistent behaviour in the case of a corrupted file. Generally, you
+   * should set @a trusted to <tt>true</tt> for files installed by the system
+   * and to <tt>false</tt> for files in the home directory.
+   *
+   * @return the newly created Gio::SettingsSchemaSource.
+   *
+   * @throw Glib::Error if the schema source could not be created, e.g. if the
+   * <tt>gschemas.compiled</tt> file was empty or (diagnosably) corrupted.
+   */
+  static Glib::RefPtr<SettingsSchemaSource> create(
+    const Glib::ustring& directory, bool trusted,
+    const Glib::RefPtr<SettingsSchemaSource>& parent = get_default());
 
   //Note this doesn't need refreturn because the C function returns a reference.
   //- it is documented as transfer:full


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