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



commit 682767f53ddeab10328baae57b678bbb67e9d539
Author: Daniel Boles <danielboles equiomgroup co uk>
Date:   Fri Nov 15 10:44:30 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 | 18 +++++++++++++++++
 gio/src/settingsschemasource.hg  | 43 +++++++++++++++++++++++++++++++++-------
 2 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/gio/src/settingsschemasource.ccg b/gio/src/settingsschemasource.ccg
index 243deceb..aef4b32a 100644
--- a/gio/src/settingsschemasource.ccg
+++ b/gio/src/settingsschemasource.ccg
@@ -21,6 +21,24 @@
 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..30237b33 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</t> 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::FileError with code Glib::FileError::Code::INVALID_ARGUMENT 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]