[glibmm/glibmm-2-66] Gio::SettingsSchemaSource: Wrap new_from_directory() and list_schemas()



commit 344fab9c87f612b3ba02280fb34115916b8c01a7
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Thu Jan 14 15:03:34 2021 +0100

    Gio::SettingsSchemaSource: Wrap new_from_directory() and list_schemas()
    
    Similar to commits by Daniel Boles in the master branch.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=783216,
    issue #19 and MR !20

 gio/src/gio_docs_override.xml    |  2 ++
 gio/src/settingsschemasource.ccg | 15 +++++++++++++++
 gio/src/settingsschemasource.hg  | 36 +++++++++++++++++++++++++++---------
 tools/m4/convert_gio.m4          |  2 +-
 4 files changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/gio/src/gio_docs_override.xml b/gio/src/gio_docs_override.xml
index 9d757d39..0b95da1a 100644
--- a/gio/src/gio_docs_override.xml
+++ b/gio/src/gio_docs_override.xml
@@ -1,4 +1,6 @@
 <root>
+<!-- Some GFileError enumerators have different names in glibmm. -->
+<substitute_enumerator_name from="G_FILE_ERROR_INVAL" to="Glib::FileError::INVALID_ARGUMENT" />
 <!-- These are preprocessor defines. Don't substitute. -->
 <substitute_enumerator_name from="G_MAXSSIZE" to="G_MAXSSIZE" />
 <substitute_enumerator_name from="G_MAXINT" to="G_MAXINT" />
diff --git a/gio/src/settingsschemasource.ccg b/gio/src/settingsschemasource.ccg
index 1c733264..120efb93 100644
--- a/gio/src/settingsschemasource.ccg
+++ b/gio/src/settingsschemasource.ccg
@@ -15,8 +15,23 @@
  */
 
 #include <gio/gio.h>
+#include <glibmm/vectorutils.h>
 
 namespace Gio
 {
 
+std::vector<Glib::ustring>
+SettingsSchemaSource::list_schemas(bool relocatable, bool recursive) const
+{
+  auto gobject = const_cast<GSettingsSchemaSource*>(gobj());
+  gchar** schemas{};
+
+  if (relocatable)
+    g_settings_schema_source_list_schemas(gobject, recursive, nullptr, &schemas);
+  else
+    g_settings_schema_source_list_schemas(gobject, recursive, &schemas, nullptr);
+
+  return Glib::ArrayHandler<Glib::ustring>::array_to_vector(schemas, Glib::OWNERSHIP_DEEP);
+}
+
 } // namespace Gio
diff --git a/gio/src/settingsschemasource.hg b/gio/src/settingsschemasource.hg
index 536fe5bb..a83c1712 100644
--- a/gio/src/settingsschemasource.hg
+++ b/gio/src/settingsschemasource.hg
@@ -17,6 +17,8 @@
 _CONFIGINCLUDE(giommconfig.h)
 
 #include <giomm/settingsschema.h>
+#include <glibmm/ustring.h>
+#include <vector>
 
 _DEFS(giomm,gio)
 _PINCLUDE(glibmm/private/object_p.h)
@@ -42,23 +44,39 @@ protected:
   _IGNORE(g_settings_schema_source_ref, g_settings_schema_source_unref)
 
 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);
-*/
+  _WRAP_METHOD(static Glib::RefPtr<SettingsSchemaSource> create(
+    const std::string& directory, bool trusted{.},
+    const Glib::RefPtr<SettingsSchemaSource>& parent{.} = get_default()),
+    g_settings_schema_source_new_from_directory, errthrow, newin "2,66")
 
   //Note this doesn't need refreturn because the C function returns a reference.
   //- it is documented as transfer:full
   _WRAP_METHOD(Glib::RefPtr<SettingsSchema> lookup(const Glib::ustring& schema_id, bool recursive), 
g_settings_schema_source_lookup)
   _WRAP_METHOD(Glib::RefPtr<const SettingsSchema> lookup(const Glib::ustring& schema_id, bool recursive) 
const, g_settings_schema_source_lookup)
 
-  //TODO:_WRAP_METHOD(void list_schemas(bool recursive,  gchar*** non_relocatable, gchar*** relocatable), 
g_settings_schema_source_list_schemas)
+  _IGNORE(g_settings_schema_source_list_schemas)
+  /** Lists the schemas in a given source.
+   *
+   * Do not call this function from normal programs. It is designed for use by
+   * database editors, commandline tools, etc.
+   *
+   * @newin{2,66}
+   *
+   * @param relocatable Whether you want the list of relocatable schemas
+   * (<tt>true</tt>) or the list of non-relocatable schemas (<tt>false</tt>)
+   * for this source. Non-relocatable schemas are those for which you can call
+   * Gio::Settings::create() without specifying a path. Relocatable schemas are
+   * those for which you must pass a path to Gio::Settings::create().
+   *
+   * @param recursive If <tt>true</tt>, the list will include parent sources.
+   * If <tt>false</tt>, it will only include the schemas from one source (i.e.
+   * one directory). You probably want to recurse.
+   *
+   * @return A vector of the names of the schemas matching the given parameters.
+   */
+  std::vector<Glib::ustring> list_schemas(bool relocatable, bool recursive) const;
 };
 
 } // namespace Gio
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index 601f1c1d..896423db 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -282,7 +282,7 @@ _CONVERSION(`GSettingsSchema*',`Glib::RefPtr<SettingsSchema>',`Glib::wrap($3)')
 _CONVERSION(`GSettingsSchema*',`Glib::RefPtr<const SettingsSchema>',`Glib::wrap($3)')
 
 _CONVERSION(`GSettingsSchemaSource*',`Glib::RefPtr<SettingsSchemaSource>',`Glib::wrap($3)')
-
+_CONVERSION(`const Glib::RefPtr<SettingsSchemaSource>&',`GSettingsSchemaSource*',__CONVERT_REFPTR_TO_P)
 
 #Socket
 _CONVERSION(`const Glib::RefPtr<Socket>&',`GSocket*',__CONVERT_CONST_REFPTR_TO_P)


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