[glib/wip/gsettings-work: 4/10] Make GSettingsSchemaKey public



commit 496e57691bca64578cb77c872d6d3a15f2c087b0
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Oct 26 18:57:24 2013 -0400

    Make GSettingsSchemaKey public
    
    Take this private API and make it public along with a boxed type and
    ref/unref functions.
    
    Future commits will add accessors with new functionality and some that
    allow us to deprecate functions on GSettings itself (such as
    g_settings_get_range).

 docs/reference/gio/gio-sections.txt |    7 ++++
 gio/gsettingsschema-internal.h      |    6 ++-
 gio/gsettingsschema.c               |   66 +++++++++++++++++++++++++++++++++++
 gio/gsettingsschema.h               |   13 +++++++
 4 files changed, 90 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 2c9813f..be7da51 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -2406,8 +2406,15 @@ g_settings_schema_unref
 g_settings_schema_get_id
 g_settings_schema_get_path
 
+<SUBSECTION>
+GSettingsSchemaKey
+g_settings_schema_get_key
+g_settings_schema_key_ref
+g_settings_schema_key_unref
+
 <SUBSECTION Private>
 g_settings_schema_get_type
+g_settings_schema_key_get_type
 g_settings_schema_source_get_type
 </SECTION>
 
diff --git a/gio/gsettingsschema-internal.h b/gio/gsettingsschema-internal.h
index 7b002c2..d701f5c 100644
--- a/gio/gsettingsschema-internal.h
+++ b/gio/gsettingsschema-internal.h
@@ -22,7 +22,7 @@
 
 #include "gsettingsschema.h"
 
-typedef struct
+struct _GSettingsSchemaKey
 {
   GSettingsSchema *schema;
   const gchar *name;
@@ -39,7 +39,9 @@ typedef struct
   const GVariantType *type;
   GVariant *minimum, *maximum;
   GVariant *default_value;
-} GSettingsSchemaKey;
+
+  gint ref_count;
+};
 
 const gchar *           g_settings_schema_get_gettext_domain            (GSettingsSchema  *schema);
 GVariantIter *          g_settings_schema_get_value                     (GSettingsSchema  *schema,
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index cac5f71..df531e5 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -1076,3 +1076,69 @@ g_settings_schema_key_from_flags (GSettingsSchemaKey *key,
 
   return g_variant_builder_end (&builder);
 }
+
+G_DEFINE_BOXED_TYPE (GSettingsSchemaKey, g_settings_schema_key, g_settings_schema_key_ref, 
g_settings_schema_key_unref)
+
+/**
+ * g_settings_schema_key_ref:
+ * @source: a #GSettingsSchemaKey
+ *
+ * Increase the reference count of @key, returning a new reference.
+ *
+ * Returns: a new reference to @key
+ *
+ * Since: 2.40
+ **/
+GSettingsSchemaKey *
+g_settings_schema_key_ref (GSettingsSchemaKey *key)
+{
+  g_atomic_int_inc (&key->ref_count);
+
+  return key;
+}
+
+/**
+ * g_settings_schema_key_unref:
+ * @schema: a #GSettingsSchemaKey
+ *
+ * Decrease the reference count of @key, possibly freeing it.
+ *
+ * Since: 2.40
+ **/
+void
+g_settings_schema_key_unref (GSettingsSchemaKey *key)
+{
+  if (g_atomic_int_dec_and_test (&key->ref_count))
+    {
+      g_settings_schema_key_clear (key);
+
+      g_slice_free (GSettingsSchemaKey, key);
+    }
+}
+
+/**
+ * g_settings_schema_get_key:
+ * @schema: a #GSettingsSchema
+ * @name: the name of a key
+ *
+ * Gets the key named @name from @schema.
+ *
+ * It is a programmer error to request a key that does not exist.  See
+ * g_settings_schema_list_keys().
+ *
+ * Returns: (transfer full): the #GSettingsSchemaKey for @name
+ *
+ * Since: 2.40
+ **/
+GSettingsSchemaKey *
+g_settings_schema_get_key (GSettingsSchema *schema,
+                           const gchar     *name)
+{
+  GSettingsSchemaKey *key;
+
+  key = g_slice_new (GSettingsSchemaKey);
+  g_settings_schema_key_init (key, schema, name);
+  key->ref_count = 1;
+
+  return key;
+}
diff --git a/gio/gsettingsschema.h b/gio/gsettingsschema.h
index 20bf99f..e84029e 100644
--- a/gio/gsettingsschema.h
+++ b/gio/gsettingsschema.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 
 typedef struct _GSettingsSchemaSource                       GSettingsSchemaSource;
 typedef struct _GSettingsSchema                             GSettingsSchema;
+typedef struct _GSettingsSchemaKey                          GSettingsSchemaKey;
 
 #define                 G_TYPE_SETTINGS_SCHEMA_SOURCE                   (g_settings_schema_source_get_type 
())
 GLIB_AVAILABLE_IN_2_32
@@ -63,6 +64,18 @@ GLIB_AVAILABLE_IN_2_32
 const gchar *           g_settings_schema_get_id                        (GSettingsSchema        *schema);
 GLIB_AVAILABLE_IN_2_32
 const gchar *           g_settings_schema_get_path                      (GSettingsSchema        *schema);
+GLIB_AVAILABLE_IN_2_40
+GSettingsSchemaKey *    g_settings_schema_get_key                       (GSettingsSchema        *schema,
+                                                                         const gchar            *key);
+
+#define                 G_TYPE_SETTINGS_SCHEMA_KEY                      (g_settings_schema_key_get_type ())
+GLIB_AVAILABLE_IN_2_40
+GType                   g_settings_schema_key_get_type                  (void) G_GNUC_CONST;
+
+GLIB_AVAILABLE_IN_2_40
+GSettingsSchemaKey *    g_settings_schema_key_ref                       (GSettingsSchemaKey     *key);
+GLIB_AVAILABLE_IN_2_40
+void                    g_settings_schema_key_unref                     (GSettingsSchemaKey     *key);
 
 G_END_DECLS
 


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