[glib] add get_permission API to GSettingsBackend



commit 61f3f45cb95f022d99689e0fee9b0cb97c5112a3
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Jun 4 23:07:40 2010 +0200

    add get_permission API to GSettingsBackend
    
    implement it in the various in-tree backends
    
    also, lots of whitespace changes to realign the vtable members

 gio/gdelayedsettingsbackend.c  |   11 ++++++
 gio/gkeyfilesettingsbackend.c  |    9 +++++
 gio/gmemorysettingsbackend.c   |    9 +++++
 gio/gnullsettingsbackend.c     |   11 ++++++-
 gio/gsettingsbackend.c         |   25 ++++++++++++++
 gio/gsettingsbackend.h         |   69 +++++++++++++++++++++-------------------
 gio/gsettingsbackendinternal.h |    3 ++
 7 files changed, 103 insertions(+), 34 deletions(-)
---
diff --git a/gio/gdelayedsettingsbackend.c b/gio/gdelayedsettingsbackend.c
index 33c9b3c..890c614 100644
--- a/gio/gdelayedsettingsbackend.c
+++ b/gio/gdelayedsettingsbackend.c
@@ -202,6 +202,16 @@ g_delayed_settings_backend_unsubscribe (GSettingsBackend *backend,
   g_settings_backend_unsubscribe (delayed->priv->backend, name);
 }
 
+static GPermission *
+g_delayed_settings_backend_get_permission (GSettingsBackend *backend,
+                                           const gchar      *path)
+{
+  GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
+
+  return g_settings_backend_get_permission (delayed->priv->backend, path);
+}
+
+
 /* method calls */
 gboolean
 g_delayed_settings_backend_get_has_unapplied (GDelayedSettingsBackend *delayed)
@@ -419,6 +429,7 @@ g_delayed_settings_backend_class_init (GDelayedSettingsBackendClass *class)
   backend_class->get_writable = g_delayed_settings_backend_get_writable;
   backend_class->subscribe = g_delayed_settings_backend_subscribe;
   backend_class->unsubscribe = g_delayed_settings_backend_unsubscribe;
+  backend_class->get_permission = g_delayed_settings_backend_get_permission;
 
   object_class->finalize = g_delayed_settings_backend_finalize;
 }
diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c
index 4bb9225..b3d0dcd 100644
--- a/gio/gkeyfilesettingsbackend.c
+++ b/gio/gkeyfilesettingsbackend.c
@@ -34,6 +34,7 @@
 #include "gfile.h"
 #include "gfileinfo.h"
 #include "gfilemonitor.h"
+#include "gsimplepermission.h"
 
 #include "gioalias.h"
 
@@ -244,6 +245,13 @@ g_keyfile_settings_backend_get_writable (GSettingsBackend *backend,
   return kf_backend->priv->writable;
 }
 
+static GPermission *
+g_keyfile_settings_backend_get_permission (GSettingsBackend *backend,
+                                           const gchar      *path)
+{
+  return g_simple_permission_new (TRUE);
+}
+
 static void
 g_keyfile_settings_backend_keyfile_reload (GKeyfileSettingsBackend *kf_backend)
 {
@@ -499,6 +507,7 @@ g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
   backend_class->reset = g_keyfile_settings_backend_reset;
   backend_class->reset_path = g_keyfile_settings_backend_reset_path;
   backend_class->get_writable = g_keyfile_settings_backend_get_writable;
+  backend_class->get_permission = g_keyfile_settings_backend_get_permission;
   /* No need to implement subscribed/unsubscribe: the only point would be to
    * stop monitoring the file when there's no GSettings anymore, which is no
    * big win. */
diff --git a/gio/gmemorysettingsbackend.c b/gio/gmemorysettingsbackend.c
index bb04f39..4a74abe 100644
--- a/gio/gmemorysettingsbackend.c
+++ b/gio/gmemorysettingsbackend.c
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include "gmemorysettingsbackend.h"
+#include "gsimplepermission.h"
 #include "gsettingsbackend.h"
 #include "giomodule.h"
 
@@ -118,6 +119,13 @@ g_memory_settings_backend_get_writable (GSettingsBackend *backend,
   return TRUE;
 }
 
+static GPermission *
+g_memory_settings_backend_get_permission (GSettingsBackend *backend,
+                                          const gchar      *path)
+{
+  return g_simple_permission_new (TRUE);
+}
+
 static void
 g_memory_settings_backend_finalize (GObject *object)
 {
@@ -146,5 +154,6 @@ g_memory_settings_backend_class_init (GMemorySettingsBackendClass *class)
   backend_class->write = g_memory_settings_backend_write;
   backend_class->write_keys = g_memory_settings_backend_write_keys;
   backend_class->get_writable = g_memory_settings_backend_get_writable;
+  backend_class->get_permission = g_memory_settings_backend_get_permission;
   object_class->finalize = g_memory_settings_backend_finalize;
 }
diff --git a/gio/gnullsettingsbackend.c b/gio/gnullsettingsbackend.c
index 5fb98e9..df0f676 100644
--- a/gio/gnullsettingsbackend.c
+++ b/gio/gnullsettingsbackend.c
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include "gnullsettingsbackend.h"
+#include "gsimplepermission.h"
 
 #include "gioalias.h"
 
@@ -81,11 +82,18 @@ g_null_settings_backend_reset_path (GSettingsBackend *backend,
 
 static gboolean
 g_null_settings_backend_get_writable (GSettingsBackend *backend,
-                                        const gchar      *name)
+                                      const gchar      *name)
 {
   return FALSE;
 }
 
+static GPermission *
+g_null_settings_backend_get_permission (GSettingsBackend *backend,
+                                        const gchar      *path)
+{
+  return g_simple_permission_new (FALSE);
+}
+
 static void
 g_null_settings_backend_init (GNullSettingsBackend *memory)
 {
@@ -102,6 +110,7 @@ g_null_settings_backend_class_init (GNullSettingsBackendClass *class)
   backend_class->reset = g_null_settings_backend_reset;
   backend_class->reset_path = g_null_settings_backend_reset_path;
   backend_class->get_writable = g_null_settings_backend_get_writable;
+  backend_class->get_permission = g_null_settings_backend_get_permission;
 }
 
 GSettingsBackend *
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c
index 1bd7a11..dca68bf 100644
--- a/gio/gsettingsbackend.c
+++ b/gio/gsettingsbackend.c
@@ -25,6 +25,7 @@
 
 #include "gsettingsbackendinternal.h"
 #include "gnullsettingsbackend.h"
+#include "gsimplepermission.h"
 #include "giomodule-priv.h"
 #include "gio-marshal.h"
 
@@ -1156,6 +1157,30 @@ g_settings_backend_supports_context (const gchar *context)
   return FALSE;
 }
 
+/*< private >
+ * g_settings_backend_get_permission:
+ * @backend: a #GSettingsBackend
+ * @path: a path
+ * @returns: a non-%NULL #GPermission
+ *
+ * Gets the permission object associated with writing to keys below
+ * @path on @backend.
+ *
+ * If this is not implemented in the backend, then a %TRUE
+ * #GSimplePermission is returned.
+ */
+GPermission *
+g_settings_backend_get_permission (GSettingsBackend *backend,
+                                   const gchar      *path)
+{
+  GSettingsBackendClass *class = G_SETTINGS_BACKEND_GET_CLASS (backend);
+
+  if (class->get_permission)
+    return class->get_permission (backend, path);
+
+  return g_simple_permission_new (TRUE);
+}
+
 /**
  * g_settings_backend_setup:
  * @context: a context string (not %NULL or "")
diff --git a/gio/gsettingsbackend.h b/gio/gsettingsbackend.h
index 23b9371..7fdd4e4 100644
--- a/gio/gsettingsbackend.h
+++ b/gio/gsettingsbackend.h
@@ -67,39 +67,42 @@ struct _GSettingsBackendClass
 {
   GObjectClass parent_class;
 
-  gboolean    (*supports_context) (const gchar         *context);
-
-  GVariant *  (*read)             (GSettingsBackend    *backend,
-                                   const gchar         *key,
-                                   const GVariantType  *expected_type,
-                                   gboolean             default_value);
-  gchar **    (*list)             (GSettingsBackend    *backend,
-                                   const gchar         *path,
-                                   gchar              **resets,
-                                   gsize                n_resets,
-                                   gsize               *length);
-  gboolean    (*write)            (GSettingsBackend    *backend,
-                                   const gchar         *key,
-                                   GVariant            *value,
-                                   gpointer             origin_tag);
-  gboolean    (*write_keys)       (GSettingsBackend    *backend,
-                                   GTree               *tree,
-                                   gpointer             origin_tag);
-  void        (*reset)            (GSettingsBackend    *backend,
-                                   const gchar         *key,
-                                   gpointer             origin_tag);
-  void        (*reset_path)       (GSettingsBackend    *backend,
-                                   const gchar         *path,
-                                   gpointer             origin_tag);
-  gboolean    (*get_writable)     (GSettingsBackend    *backend,
-                                   const gchar         *key);
-  void        (*subscribe)        (GSettingsBackend    *backend,
-                                   const gchar         *name);
-  void        (*unsubscribe)      (GSettingsBackend    *backend,
-                                   const gchar         *name);
-  void        (*sync)             (GSettingsBackend    *backend);
-
-  gpointer padding[8];
+  gboolean      (*supports_context) (const gchar         *context);
+
+  GVariant *    (*read)             (GSettingsBackend    *backend,
+                                     const gchar         *key,
+                                     const GVariantType  *expected_type,
+                                     gboolean             default_value);
+  gchar **      (*list)             (GSettingsBackend    *backend,
+                                     const gchar         *path,
+                                     gchar              **resets,
+                                     gsize                n_resets,
+                                     gsize               *length);
+  gboolean      (*write)            (GSettingsBackend    *backend,
+                                     const gchar         *key,
+                                     GVariant            *value,
+                                     gpointer             origin_tag);
+  gboolean      (*write_keys)       (GSettingsBackend    *backend,
+                                     GTree               *tree,
+                                     gpointer             origin_tag);
+  void          (*reset)            (GSettingsBackend    *backend,
+                                     const gchar         *key,
+                                     gpointer             origin_tag);
+  void          (*reset_path)       (GSettingsBackend    *backend,
+                                     const gchar         *path,
+                                     gpointer             origin_tag);
+  gboolean      (*get_writable)     (GSettingsBackend    *backend,
+                                     const gchar         *key);
+  void          (*subscribe)        (GSettingsBackend    *backend,
+                                     const gchar         *name);
+  void          (*unsubscribe)      (GSettingsBackend    *backend,
+                                     const gchar         *name);
+  void          (*sync)             (GSettingsBackend    *backend);
+
+  GPermission * (*get_permission)   (GSettingsBackend    *backend,
+                                     const gchar         *path);
+
+  gpointer padding[7];
 };
 
 struct _GSettingsBackend
diff --git a/gio/gsettingsbackendinternal.h b/gio/gsettingsbackendinternal.h
index 923dbf2..007bfd1 100644
--- a/gio/gsettingsbackendinternal.h
+++ b/gio/gsettingsbackendinternal.h
@@ -99,6 +99,9 @@ G_GNUC_INTERNAL
 void                            g_settings_backend_subscribe            (GSettingsBackend                     *backend,
                                                                          const char                           *name);
 G_GNUC_INTERNAL
+GPermission *                   g_settings_backend_get_permission       (GSettingsBackend                     *backend,
+                                                                         const gchar                          *path);
+G_GNUC_INTERNAL
 GMainContext *                  g_settings_backend_get_active_context   (void);
 
 #endif  /* __G_SETTINGS_BACKEND_INTERNAL_H__ */



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