[PATCH] default source



Hi,

Well, this just tries to implement Havoc Pennington suggestion on the
"possible way to list the configured databases" thread. (Sorry to not
reply to that mail but I was not subscribed to the list).

I think it would help a lot to have such gconftool feature / macro in
gconf.

ISSUES:
- I added a -DGCONF_ETCDIR in gconf/gconf/Makefile.am because I need to
get the $sysconfdir/gconf path. If there is a better way to get it, I'd
be happy to change this.
- I'm using gconf_load_source_path to parse the
$sysconfdir/gconf/schema-install-source file, it print out a "Adding
..." line, so the gconftool output is not very clear in this case and we
need an additional tail command in gconf.m4 to parse it correctly.
Suggestions are welcome :)

I'm not very good with sh/m4 macros, but I tried to do my best :)

Thank you !

Marco




? gconfpatch
? defaultsource
Index: gconf.m4.in
===================================================================
RCS file: /cvs/gnome/gconf/Attic/gconf.m4.in,v
retrieving revision 1.1
diff -u -r1.1 gconf.m4.in
--- gconf.m4.in	2000/07/19 03:40:23	1.1
+++ gconf.m4.in	2001/07/31 16:57:33
@@ -64,3 +64,21 @@
   AC_SUBST(GCONF_LIBS)
   rm -f conf.gconftest
 ])
+
+dnl AM_PATH_GCONF
+dnl Define INSTALL_GCONF_CONFIG_SOURCE
+dnl
+AC_DEFUN(AM_GCONF_SOURCE,
+[
+if test "x$GCONF_SCHEMA_INSTALL_SOURCE" = "x"; then
+  INSTALL_GCONF_CONFIG_SOURCE=`gconftool --get-default-source | tail -n1`
+else
+  INSTALL_GCONF_CONFIG_SOURCE=$GCONF_SCHEMA_INSTALL_SOURCE
+fi
+
+AC_ARG_ENABLE(gconf-source, 
+[  --enable-gconf-source=sourceaddress      Where to install schema files.],INSTALL_GCONF_CONFIG_SOURCE=$enable_gconf_source,)
+
+  AC_SUBST(INSTALL_GCONF_CONFIG_SOURCE)
+  AC_MSG_RESULT("Using config source $INSTALL_GCONF_CONFIG_SOURCE for schema installation")
+])
Index: gconf/Makefile.am
===================================================================
RCS file: /cvs/gnome/gconf/gconf/Makefile.am,v
retrieving revision 1.52.2.4
diff -u -r1.52.2.4 Makefile.am
--- gconf/Makefile.am	2001/04/17 23:16:49	1.52.2.4
+++ gconf/Makefile.am	2001/07/31 16:57:33
@@ -11,6 +11,7 @@
 	-DGCONF_LOCALE_DIR=\""$(gconflocaledir)"\"  \
         -DGCONF_SRCDIR=\""$(absolute_top_srcdir)"\" \
 	-DGCONF_CONFDIR=\""$(sysconfdir)/gconf/$(MAJOR_VERSION)"\" \
+	-DGCONF_ETCDIR=\""$(sysconfdir)/gconf"\" \
 	-DGCONF_BUILDDIR=\""$(top_builddir)"\" 			\
 	-DGCONF_BACKEND_DIR=\""$(pkglibdir)/$(MAJOR_VERSION)"\" \
 	-DVERSION=\""$(VERSION)"\" \
Index: gconf/gconftool.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconftool.c,v
retrieving revision 1.51.2.7
diff -u -r1.51.2.7 gconftool.c
--- gconf/gconftool.c	2001/07/28 06:17:39	1.51.2.7
+++ gconf/gconftool.c	2001/07/31 16:57:35
@@ -56,6 +56,7 @@
 static int long_docs_mode = FALSE;
 static int schema_name_mode = FALSE;
 static int associate_schema_mode = FALSE;
+static int default_source_mode = FALSE;
 
 struct poptOption options[] = {
   { 
@@ -321,6 +322,15 @@
     NULL
   },
   {
+    "get-default-source",
+    '\0',
+    POPT_ARG_NONE,
+    &default_source_mode,
+    0,
+    N_("Get the name of the default source"),
+    NULL
+  },
+  {
     NULL,
     '\0',
     0,
@@ -350,6 +360,7 @@
 static int do_long_docs (GConfEngine *conf, const gchar **args);
 static int do_get_schema_name (GConfEngine *conf, const gchar **args);
 static int do_associate_schema (GConfEngine *conf, const gchar **args);
+static int do_get_default_source (GConfEngine *conf, const gchar **args);
 
 int 
 main (int argc, char** argv)
@@ -717,6 +728,16 @@
           return 1;
         }
     }
+
+  if (default_source_mode)
+    {
+      const gchar** args = poptGetArgs(ctx);
+      if (do_get_default_source(conf, args)  == 1)
+        {
+          gconf_engine_unref(conf);
+          return 1;
+        }
+    }
   
   if (all_entries_mode)
     {
@@ -2494,5 +2515,33 @@
       ++args;
     }
 
+  return 0;
+}
+
+static int
+do_get_default_source(GConfEngine* conf, const gchar** args)
+{
+  gchar *source;
+  gchar* conffile;
+  gchar** addresses;
+
+  /* Try with $sysconfdir/gconf/schema-install-source */
+  conffile = g_strconcat(GCONF_ETCDIR, "/schema-install-source", NULL);
+  addresses = gconf_load_source_path(conffile, NULL);
+  g_free(conffile);
+
+  if (addresses)
+    {
+	  printf ("%s\n", addresses[0]);
+	  g_free (addresses);
+    }
+  else
+    {
+      /* Use default database */
+      source = g_strconcat("xml::", GCONF_ETCDIR, "/gconf.xml.defaults", NULL);
+      printf ("%s\n", source);
+      g_free (source);
+    }
+  
   return 0;
 }


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