[dconf] writer: add list class virtual method



commit 9ebbf9ba1854932b61c4c49b0a4d24132532d492
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Jan 7 22:20:55 2013 -0500

    writer: add list class virtual method
    
    This populates a set with the names of databases available for a given
    writer class.

 service/dconf-writer.c |   33 +++++++++++++++++++++++++++++++++
 service/dconf-writer.h |    6 ++++++
 2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/service/dconf-writer.c b/service/dconf-writer.c
index 46aaf2d..fb3589a 100644
--- a/service/dconf-writer.c
+++ b/service/dconf-writer.c
@@ -58,6 +58,25 @@ static void dconf_writer_iface_init (DConfDBusWriterIface *iface);
 G_DEFINE_TYPE_WITH_CODE (DConfWriter, dconf_writer, DCONF_DBUS_TYPE_WRITER_SKELETON,
                          G_IMPLEMENT_INTERFACE (DCONF_DBUS_TYPE_WRITER, dconf_writer_iface_init))
 
+static void
+dconf_writer_real_list (GHashTable *set)
+{
+  const gchar *name;
+  gchar *dirname;
+  GDir *dir;
+
+  dirname = g_build_filename (g_get_user_config_dir (), "dconf", NULL);
+  dir = g_dir_open (dirname, 0, NULL);
+
+  if (!dir)
+    return;
+
+  while (name = g_dir_read_name (dir))
+    g_hash_table_add (set, g_strdup (name));
+
+  g_dir_close (dir);
+}
+
 static gchar *
 dconf_writer_get_tag (DConfWriter *writer)
 {
@@ -309,6 +328,7 @@ dconf_writer_class_init (DConfWriterClass *class)
   class->change = dconf_writer_real_change;
   class->commit = dconf_writer_real_commit;
   class->end = dconf_writer_real_end;
+  class->list = dconf_writer_real_list;
 
   g_object_class_install_property (object_class, 1,
                                    g_param_spec_string ("name", "name", "name", NULL,
@@ -324,6 +344,19 @@ dconf_writer_get_name (DConfWriter *writer)
   return writer->priv->name;
 }
 
+void
+dconf_writer_list (GType       type,
+                   GHashTable *set)
+{
+  DConfWriterClass *class;
+
+  g_return_if_fail (g_type_is_a (type, DCONF_TYPE_WRITER));
+
+  class = g_type_class_ref (type);
+  class->list (set);
+  g_type_class_unref (class);
+}
+
 GDBusInterfaceSkeleton *
 dconf_writer_new (GType        type,
                   const gchar *name)
diff --git a/service/dconf-writer.h b/service/dconf-writer.h
index 7783c94..8a2d7e4 100644
--- a/service/dconf-writer.h
+++ b/service/dconf-writer.h
@@ -47,6 +47,9 @@ struct _DConfWriterClass
 {
   DConfDBusWriterSkeletonClass parent_instance;
 
+  /* static methods */
+  void     (* list)   (GHashTable      *set);
+
   /* instance methods */
   gboolean (* begin)  (DConfWriter     *writer,
                        GError         **error);
@@ -64,6 +67,9 @@ struct _DConfWriter
   DConfWriterPrivate *priv;
 };
 
+
+void                    dconf_writer_list                               (GType        type,
+                                                                         GHashTable  *set);
 GDBusInterfaceSkeleton *dconf_writer_new                                (GType        type,
                                                                          const gchar *name);
 



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