[tracker/libtracker-common-cleanup: 5/5] all: Migrate to GKeyfileSettingsBackend and generate man pages from schemas



commit 37109980abea4303b97c9cd13ea0ec1e2e6f2e00
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Oct 9 19:11:45 2014 +0100

    all: Migrate to GKeyfileSettingsBackend and generate man pages from schemas
    
    Now we've removed the internal key file object, we've had to put in place
    another method for supporting the existing TRACKER_USE_CONFIG_FILES
    environment variable. Thanks to the GKeyfileSettingsBackend provided by
    GLib, we can fallback to old school INI type config files for embedded
    solutions or cases where we don't want dconf as a backend. This works rather
    well.
    
    IT should be noted, the INI files are *NOT* written out in full if they do not
    exist, only options which are saved or different to the default settings are.
    This is how it should be too.
    
    Now we build man pages based on GSettings schemas using xsltproc with the
    template in docs/manpages/gsettings.xsl. This is a useful aid when trying to
    understand what config files can have in them. One thing it does highlight, is
    the config documentation could be better :)

 configure.ac                            |   27 +++++++++
 docs/manpages/Makefile.am               |    3 +-
 docs/manpages/gsettings.xsl             |   54 +++++++++++++++++++
 src/libtracker-data/Makefile.am         |   22 +++++++-
 src/libtracker-data/tracker-db-config.c |   61 ++++++++++++++++++---
 src/libtracker-fts/Makefile.am          |   25 ++++++++-
 src/libtracker-fts/tracker-fts-config.c |   64 ++++++++++++++++++++---
 src/miners/fs/Makefile.am               |   22 +++++++-
 src/miners/fs/tracker-config.c          |   32 ++++++++---
 src/tracker-extract/Makefile.am         |   22 +++++++-
 src/tracker-extract/tracker-config.c    |   88 +++++++++++++++++--------------
 src/tracker-extract/tracker-config.h    |    4 +-
 src/tracker-store/Makefile.am           |   30 ++++++++--
 src/tracker-store/tracker-config.c      |   79 +++++++++++++++++++++++++--
 src/tracker-writeback/Makefile.am       |   22 +++++++-
 src/tracker-writeback/tracker-config.c  |   62 +++++++++++++++++++---
 16 files changed, 521 insertions(+), 96 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4842875..c80454e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1771,6 +1771,32 @@ fi
 
 AM_CONDITIONAL(HAVE_LIBXML2, test "x$have_libxml2" = "xyes")
 
+##################################################################
+# Check for xsltproc, used to generate cfg man pages (5)
+##################################################################
+
+AC_ARG_ENABLE([cfg-man-pages],
+              AS_HELP_STRING([--enable-cfg-man-pages],
+                             [enable man pages for config (.cfg) files [[default=yes]]]),
+              [enable_cfg_man_pages=$enableval],
+              [enable_cfg_man_pages=yes])
+
+if test "x$enable_cfg_man_pages" != "xno" ; then
+   # Check for graphviz if we are building gtk_doc
+   AC_PATH_PROG(XSLTPROC, xsltproc)
+   AC_SUBST(XSLTPROC)
+else
+   have_xsltproc="no  (disabled)"
+fi
+
+if test "x$enable_cfg_man_pages" = "xyes"; then
+   if test -z "$XSLTPROC"; then
+      AC_MSG_ERROR([Couldn't find xsltproc, try installing libxslt.])
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_XSLTPROC, test -n "$XSLTPROC")
+
 ####################################################################
 # Check for tracker-extract: gstreamer/mplayer/etc
 ####################################################################
@@ -2719,6 +2745,7 @@ Build Configuration:
        Win32:                                  $native_win32
 
        Enable gtk doc (for documentation):     $enable_gtk_doc
+       Enable man pages for GSettings:         $enable_cfg_man_pages
 
        Enable functional tests:                $enable_functional_tests
        Enable unit tests:                      $have_unit_tests
diff --git a/docs/manpages/Makefile.am b/docs/manpages/Makefile.am
index 8cbb71d..a3d76b0 100644
--- a/docs/manpages/Makefile.am
+++ b/docs/manpages/Makefile.am
@@ -35,4 +35,5 @@ EXTRA_DIST = \
        $(common) \
        $(tp) \
        $(tn) \
-       $(tmrss)
+       $(tmrss) \
+       gsettings.xsl
diff --git a/docs/manpages/gsettings.xsl b/docs/manpages/gsettings.xsl
new file mode 100644
index 0000000..e975edd
--- /dev/null
+++ b/docs/manpages/gsettings.xsl
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+
+<xsl:output method="xml" omit-xml-declaration="yes" disable-output-escaping="yes"/>
+
+<xsl:template match="/">
+.TH <xsl:value-of select="$config-file"/> 5 "<xsl:value-of select="$current-date"/>" <xsl:value-of 
select="$version"/> "Tracker Manual"
+
+.SH NAME
+<xsl:value-of select="$config-file"/>
+
+.SH SYNOPSIS
+$HOME/.config/tracker/<xsl:value-of select="$config-file"/>
+
+.SH DESCRIPTION
+Tracker's configuration is built on top of GSettings, part of GLib. This means that there is a proper schema 
for configurations and they can be viewed (normally) using the \fBdconf-editor\fR tool.
+
+Tracker also allows switching from the GSettings database, used by most (cross) desktop applications, to a 
key/value formatted files (like Microsoft's INI format). To do this, the environment variable 
\fBTRACKER_USE_CONFIG_FILES\fR must be defined before running the application using that configuration.
+
+So where is this configuration? Well, normally they're stored in \fI$HOME/.config/tracker/\fR, however, 
default values are not stored to config files, only \fBdifferent\fR values are. This man page describes what 
keys and values can be used.
+
+See EXAMPLES for a general overview.
+
+.SH OPTIONS
+<xsl:for-each select="schemalist/schema/key">
+.TP
+\fB<xsl:value-of select="@name"/>\fR=<xsl:value-of select="translate(default, '(\[ | \])', '')" 
disable-output-escaping="yes"/>
+.nf
+
+<xsl:value-of select="description"  disable-output-escaping="yes"/>
+
+<xsl:for-each select="range">
+Values range from <xsl:value-of select="@min"/> to <xsl:value-of select="@max"/>.
+</xsl:for-each>
+.fi
+
+</xsl:for-each>
+
+.SH EXAMPLES
+The top level group is "General". The default configuration (if saved to <xsl:value-of 
select="$config-file"/>), would look like:
+
+.nf
+    [General]
+    <xsl:for-each select="schemalist/schema/key">
+      <xsl:value-of select="@name"/>=<xsl:value-of select="translate(default, '(\[ | \])', '')" 
disable-output-escaping="yes"/>;
+    </xsl:for-each>
+.fi
+
+.SH SEE ALSO
+.BR <xsl:value-of select="translate($config-file, '.', '\n')"/>
+
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/src/libtracker-data/Makefile.am b/src/libtracker-data/Makefile.am
index bf26e65..a87d990 100644
--- a/src/libtracker-data/Makefile.am
+++ b/src/libtracker-data/Makefile.am
@@ -16,6 +16,8 @@ AM_CPPFLAGS =                                          \
        -DSHAREDIR=\""$(datadir)"\"                    \
        $(LIBTRACKER_DATA_CFLAGS)
 
+all: $(libtracker_data_LTLIBRARIES) $(man_MANS)
+
 libtracker_datadir = $(libdir)/tracker-$(TRACKER_API_VERSION)
 libtracker_data_LTLIBRARIES = libtracker-data.la
 
@@ -86,11 +88,27 @@ gsettings_SCHEMAS = org.freedesktop.Tracker.DB.gschema.xml
 
 @GSETTINGS_RULES@
 
+if HAVE_XSLTPROC
+DATE=`date +'%B %Y'`
+man_MANS = tracker-db.cfg.5
+else
+man_MANS =
+endif
+
+%.cfg.5: $(gsettings_SCHEMAS)
+       $(AM_V_GEN)$(XSLTPROC) \
+         --stringparam version "${VERSION}" \
+         --stringparam current-date "${DATE}" \
+         --stringparam config-file "$(@:.cfg.5=.cfg)" \
+         $(top_srcdir)/docs/manpages/gsettings.xsl $^ > $@
+
 # Dist / Clean rules for all data
 CLEANFILES = \
        libtracker_data_la_vala.stamp \
-       $(gsettings_SCHEMAS)
+       $(gsettings_SCHEMAS) \
+       $(man_MANS)
 
 EXTRA_DIST = \
        libtracker-data.vapi \
-       $(gsettings_SCHEMAS:.xml=.xml.in)
+       $(gsettings_SCHEMAS:.xml=.xml.in) \
+       $(man_MANS)
diff --git a/src/libtracker-data/tracker-db-config.c b/src/libtracker-data/tracker-db-config.c
index eb3c65d..2b95f15 100644
--- a/src/libtracker-data/tracker-db-config.c
+++ b/src/libtracker-data/tracker-db-config.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,10 +26,15 @@
 #include <glib.h>
 #include <gio/gio.h>
 
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
+#include <libtracker-common/tracker-common.h>
+
 #include "tracker-db-config.h"
 
-/* GKeyFile defines */
-#define GROUP_JOURNAL     "Journal"
+#define CONFIG_SCHEMA "org.freedesktop.Tracker.DB"
+#define CONFIG_PATH   "/org/freedesktop/tracker/db/"
 
 /* Default values */
 #define DEFAULT_JOURNAL_CHUNK_SIZE           50
@@ -139,22 +145,61 @@ config_finalize (GObject *object)
        (G_OBJECT_CLASS (tracker_db_config_parent_class)->finalize) (object);
 }
 
-
 static void
 config_constructed (GObject *object)
 {
+       GSettings *settings;
+
        (G_OBJECT_CLASS (tracker_db_config_parent_class)->constructed) (object);
 
-       g_settings_delay (G_SETTINGS (object));
+       settings = G_SETTINGS (object);
+
+       if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               g_settings_delay (settings);
+       }
+
+       g_settings_bind (settings, "journal-chunk-size", object, "journal-chunk-size", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "journal-rotate-destination", object, "journal-rotate-destination", 
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_GET_NO_CHANGES);
 }
 
 TrackerDBConfig *
 tracker_db_config_new (void)
 {
-       return g_object_new (TRACKER_TYPE_DB_CONFIG,
-                            "schema-id", "org.freedesktop.Tracker.DB",
-                            "path", "/org/freedesktop/tracker/db/",
-                            NULL);
+       TrackerDBConfig *config = NULL;
+
+       /* FIXME: should we unset GSETTINGS_BACKEND env var? */
+
+       if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               GSettingsBackend *backend;
+               gchar *filename;
+               gboolean need_to_save;
+
+               filename = g_build_filename (g_get_user_config_dir (), "tracker", "tracker-db.cfg", NULL);
+
+               need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
+
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
+               g_info ("Using config file '%s'", filename);
+               g_free (filename);
+
+               config = g_object_new (TRACKER_TYPE_DB_CONFIG,
+                                      "backend", backend,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+               g_object_unref (backend);
+
+               if (need_to_save) {
+                       g_info ("  Config file does not exist, using default values...");
+               }
+       } else {
+               config = g_object_new (TRACKER_TYPE_DB_CONFIG,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+       }
+
+       return config;
 }
 
 gboolean
diff --git a/src/libtracker-fts/Makefile.am b/src/libtracker-fts/Makefile.am
index 322365e..e583c39 100644
--- a/src/libtracker-fts/Makefile.am
+++ b/src/libtracker-fts/Makefile.am
@@ -4,6 +4,8 @@ AM_CPPFLAGS =                                          \
        -DNDEBUG                                       \
        $(LIBTRACKER_FTS_CFLAGS)
 
+all: $(noinst_LTLIBRARIES) $(man_MANS)
+
 noinst_LTLIBRARIES = libtracker-fts.la
 
 fts4_sources =                                         \
@@ -65,6 +67,25 @@ gsettings_SCHEMAS = org.freedesktop.Tracker.FTS.gschema.xml
 
 @GSETTINGS_RULES@
 
+if HAVE_XSLTPROC
+DATE=`date +'%B %Y'`
+man_MANS = tracker-fts.cfg.5
+else
+man_MANS =
+endif
+
+%.cfg.5: $(gsettings_SCHEMAS)
+       $(AM_V_GEN)$(XSLTPROC) \
+         --stringparam version "${VERSION}" \
+         --stringparam current-date "${DATE}" \
+         --stringparam config-file "$(@:.cfg.5=.cfg)" \
+         $(top_srcdir)/docs/manpages/gsettings.xsl $^ > $@
+
 # Dist / Clean rules for all data
-CLEANFILES = $(gsettings_SCHEMAS)
-EXTRA_DIST += $(gsettings_SCHEMAS:.xml=.xml.in)
+CLEANFILES = \
+       $(gsettings_SCHEMAS) \
+       $(man_MANS)
+
+EXTRA_DIST += \
+       $(gsettings_SCHEMAS:.xml=.xml.in) \
+       $(man_MANS)
diff --git a/src/libtracker-fts/tracker-fts-config.c b/src/libtracker-fts/tracker-fts-config.c
index 34ebc61..64abf25 100644
--- a/src/libtracker-fts/tracker-fts-config.c
+++ b/src/libtracker-fts/tracker-fts-config.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,10 +26,15 @@
 #include <glib.h>
 #include <gio/gio.h>
 
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
+#include <libtracker-common/tracker-common.h>
+
 #include "tracker-fts-config.h"
 
-/* GKeyFile defines */
-#define GROUP_INDEXING             "Indexing"
+#define CONFIG_SCHEMA "org.freedesktop.Tracker.FTS"
+#define CONFIG_PATH   "/org/freedesktop/tracker/fts/"
 
 /* Default values */
 #define DEFAULT_MAX_WORD_LENGTH      30     /* 0->200 */
@@ -217,18 +223,62 @@ config_finalize (GObject *object)
 static void
 config_constructed (GObject *object)
 {
+       GSettings *settings;
+
        (G_OBJECT_CLASS (tracker_fts_config_parent_class)->constructed) (object);
 
-        g_settings_delay (G_SETTINGS (object));
+       settings = G_SETTINGS (object);
+
+       if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               g_settings_delay (settings);
+       }
+
+       g_settings_bind (settings, "max-word-length", object, "max-word-length", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "enable-stemmer", object, "enable-stemmer", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "enable-unaccent", object, "enable-unaccent", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "ignore-numbers", object, "ignore-numbers", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "ignore-stop-words", object, "ignore-stop-words", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "max-words-to-index", object, "max-words-to-index", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
 }
 
 TrackerFTSConfig *
 tracker_fts_config_new (void)
 {
-       return g_object_new (TRACKER_TYPE_FTS_CONFIG,
-                             "schema-id", "org.freedesktop.Tracker.FTS",
-                             "path", "/org/freedesktop/tracker/fts/",
-                            NULL);
+       TrackerFTSConfig *config = NULL;
+
+       /* FIXME: should we unset GSETTINGS_BACKEND env var? */
+
+       if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               GSettingsBackend *backend;
+               gchar *filename;
+               gboolean need_to_save;
+
+               filename = g_build_filename (g_get_user_config_dir (), "tracker", "tracker-fts.cfg", NULL);
+
+               need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
+
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
+               g_info ("Using config file '%s'", filename);
+               g_free (filename);
+
+               config = g_object_new (TRACKER_TYPE_FTS_CONFIG,
+                                      "backend", backend,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+               g_object_unref (backend);
+
+               if (need_to_save) {
+                       g_info ("  Config file does not exist, using default values...");
+               }
+       } else {
+               config = g_object_new (TRACKER_TYPE_FTS_CONFIG,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+       }
+
+       return config;
 }
 
 gboolean
diff --git a/src/miners/fs/Makefile.am b/src/miners/fs/Makefile.am
index ef3a303..3d00786 100644
--- a/src/miners/fs/Makefile.am
+++ b/src/miners/fs/Makefile.am
@@ -7,6 +7,8 @@ AM_CPPFLAGS =                                          \
        -DLIBEXEC_PATH=\""$(libexecdir)"\"             \
        $(TRACKER_MINER_FS_CFLAGS)
 
+all: $(libexec_PROGRAMS) $(man_MANS)
+
 libexec_PROGRAMS = tracker-miner-fs
 
 # Prefer UPower for the power data if it's available, else fall back to HAL
@@ -97,17 +99,33 @@ gsettings_SCHEMAS = org.freedesktop.Tracker.Miner.Files.gschema.xml
 
 @GSETTINGS_RULES@
 
+if HAVE_XSLTPROC
+DATE=`date +'%B %Y'`
+man_MANS = $(libexec_PROGRAMS).cfg.5
+else
+man_MANS =
+endif
+
+%.cfg.5: $(gsettings_SCHEMAS)
+       $(AM_V_GEN)$(XSLTPROC) \
+         --stringparam version "${VERSION}" \
+         --stringparam current-date "${DATE}" \
+         --stringparam config-file "$(@:.cfg.5=.cfg)" \
+         $(top_srcdir)/docs/manpages/gsettings.xsl $^ > $@
+
 # Dist / Clean rules for all data
 CLEANFILES = \
        $(autostart_DATA) \
        $(autostart_DATA:.desktop=.desktop.in) \
        $(service_DATA) \
        $(service_DATA:.service=.service.in) \
-       $(gsettings_SCHEMAS)
+       $(gsettings_SCHEMAS) \
+       $(man_MANS)
 
 EXTRA_DIST = \
        $(autostart_DATA:.desktop=.desktop.in.in) \
        $(config_DATA) \
        $(service_DATA:.service=.service.in.in) \
-       $(gsettings_SCHEMAS:.xml=.xml.in)
+       $(gsettings_SCHEMAS:.xml=.xml.in) \
+       $(man_MANS)
 
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index 3ffa922..733caa6 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -693,10 +694,27 @@ config_constructed (GObject *object)
                g_settings_delay (settings);
        }
 
-       /* Set up bindings */
-       g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET_NO_CHANGES);
+       /* Set up bindings:
+        *
+        * What's interesting here is that 'verbosity' and
+        * 'initial-sleep' are command line arguments that can be
+        * overridden, so we don't update the config when we set them
+        * from main() because it's a session configuration only, not
+        * a permanent one. To do this we use the flag
+        * G_SETTINGS_BIND_GET_NO_CHANGES.
+        *
+        * For the other settings, we don't bind the
+        * G_SETTINGS_BIND_SET because we don't want to save anything,
+        * ever, we only want to know about updates to the settings as
+        * they're changed externally. The only time this may be
+        * different is where we use the environment variable
+        * TRACKER_USE_CONFIG_FILES and we want to write a config
+        * file for convenience. But this is only necessary if the
+        * config is different to the default.
+        */
+       g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
        g_settings_bind (settings, "sched-idle", object, "sched-idle", G_SETTINGS_BIND_GET);
-       g_settings_bind (settings, "initial-sleep", object, "initial-sleep", G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "initial-sleep", object, "initial-sleep", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
        g_settings_bind (settings, "throttle", object, "throttle", G_SETTINGS_BIND_GET);
        g_settings_bind (settings, "low-disk-space-limit", object, "low-disk-space-limit", 
G_SETTINGS_BIND_GET);
        g_settings_bind (settings, "crawling-interval", object, "crawling-interval", G_SETTINGS_BIND_GET);
@@ -736,11 +754,10 @@ tracker_config_new (void)
 
                need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
 
-               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, NULL);
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
                g_info ("Using config file '%s'", filename);
                g_free (filename);
 
-               /* settings = g_settings_new_with_backend (CONFIG_SCHEME, backend); */
                config = g_object_new (TRACKER_TYPE_CONFIG,
                                       "backend", backend,
                                       "schema-id", CONFIG_SCHEMA,
@@ -749,8 +766,7 @@ tracker_config_new (void)
                g_object_unref (backend);
 
                if (need_to_save) {
-                       g_info ("  Config file did not exist, creating...");
-                       g_settings_apply (G_SETTINGS (config));
+                       g_info ("  Config file does not exist, using default values...");
                }
        } else {
                config = g_object_new (TRACKER_TYPE_CONFIG,
@@ -932,7 +948,6 @@ tracker_config_set_verbosity (TrackerConfig *config,
 {
        g_return_if_fail (TRACKER_IS_CONFIG (config));
 
-       /* g_object_set (G_OBJECT (config), "verbosity", value, NULL); */
        g_settings_set_enum (G_SETTINGS (config), "verbosity", value);
        g_object_notify (G_OBJECT (config), "verbosity");
 }
@@ -943,7 +958,6 @@ tracker_config_set_initial_sleep (TrackerConfig *config,
 {
        g_return_if_fail (TRACKER_IS_CONFIG (config));
 
-       /* g_object_set (G_OBJECT (config), "initial-sleep", value, NULL); */
        g_settings_set_int (G_SETTINGS (config), "initial-sleep", value);
        g_object_notify (G_OBJECT (config), "initial-sleep");
 }
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index 6a0b58f..ced5ef0 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -529,6 +529,8 @@ libextract_dummy_la_LIBADD = \
 #
 # Binaries
 #
+all: $(libexec_PROGRAMS) $(man_MANS)
+
 libexec_PROGRAMS = tracker-extract
 
 tracker_extract_SOURCES = \
@@ -632,16 +634,32 @@ gsettings_SCHEMAS = org.freedesktop.Tracker.Extract.gschema.xml
 
 @GSETTINGS_RULES@
 
+if HAVE_XSLTPROC
+DATE=`date +'%B %Y'`
+man_MANS = $(libexec_PROGRAMS).cfg.5
+else
+man_MANS =
+endif
+
+%.cfg.5: $(gsettings_SCHEMAS)
+       $(AM_V_GEN)$(XSLTPROC) \
+         --stringparam version "${VERSION}" \
+         --stringparam current-date "${DATE}" \
+         --stringparam config-file "$(@:.cfg.5=.cfg)" \
+         $(top_srcdir)/docs/manpages/gsettings.xsl $^ > $@
+
 # Dist / Clean rules for all data
 CLEANFILES += \
        $(autostart_DATA) \
        $(autostart_DATA:.desktop=.desktop.in) \
        $(service_DATA) \
        $(service_DATA:.service=.service.in) \
-       $(gsettings_SCHEMAS)
+       $(gsettings_SCHEMAS) \
+       $(man_MANS)
 
 EXTRA_DIST += \
        $(autostart_DATA:.desktop=.desktop.in.in) \
        $(config_DATA) \
        $(service_DATA:.service=.service.in.in) \
-       $(gsettings_SCHEMAS:.xml=.xml.in)
+       $(gsettings_SCHEMAS:.xml=.xml.in) \
+       $(man_MANS)
diff --git a/src/tracker-extract/tracker-config.c b/src/tracker-extract/tracker-config.c
index 04b0e28..cc30633 100644
--- a/src/tracker-extract/tracker-config.c
+++ b/src/tracker-extract/tracker-config.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -26,13 +27,9 @@
 
 #include "tracker-config.h"
 
-#define CONFIG_SCHEME "org.freedesktop.Tracker.Extract"
+#define CONFIG_SCHEMA "org.freedesktop.Tracker.Extract"
 #define CONFIG_PATH   "/org/freedesktop/tracker/extract/"
 
-typedef struct {
-       GSettings *settings;
-} TrackerConfigPrivate;
-
 static void     config_set_property         (GObject       *object,
                                              guint          param_id,
                                              const GValue  *value,
@@ -46,7 +43,6 @@ static void     config_constructed          (GObject       *object);
 
 enum {
        PROP_0,
-       PROP_SETTINGS,
        PROP_VERBOSITY,
        PROP_SCHED_IDLE,
        PROP_MAX_BYTES,
@@ -54,7 +50,7 @@ enum {
        PROP_WAIT_FOR_MINER_FS,
 };
 
-G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_OBJECT);
+G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_SETTINGS);
 
 static void
 tracker_config_class_init (TrackerConfigClass *klass)
@@ -66,14 +62,6 @@ tracker_config_class_init (TrackerConfigClass *klass)
        object_class->finalize     = config_finalize;
        object_class->constructed  = config_constructed;
 
-       g_object_class_install_property (object_class,
-                                        PROP_SETTINGS,
-                                        g_param_spec_object ("settings",
-                                                             "GSettings",
-                                                             "GSettings GObject used",
-                                                             G_TYPE_SETTINGS,
-                                                             G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
-
        /* General */
        g_object_class_install_property (object_class,
                                         PROP_VERBOSITY,
@@ -118,14 +106,11 @@ tracker_config_class_init (TrackerConfigClass *klass)
                                                               "%TRUE to wait for tracker-miner-fs is done 
before extracting. %FAlSE otherwise",
                                                               FALSE,
                                                               G_PARAM_READWRITE));
-
-       g_type_class_add_private (object_class, sizeof (TrackerConfigPrivate));
 }
 
 static void
 tracker_config_init (TrackerConfig *object)
 {
-       object->priv = G_TYPE_INSTANCE_GET_PRIVATE (object, TRACKER_TYPE_CONFIG, TrackerConfigPrivate);
 }
 
 static void
@@ -137,14 +122,6 @@ config_set_property (GObject      *object,
        TrackerConfig *config = TRACKER_CONFIG (object);
 
        switch (param_id) {
-       case PROP_SETTINGS: {
-               TrackerConfigPrivate *priv;
-
-               priv = config->priv;
-               priv->settings = g_value_get_object (value);
-               break;
-       }
-
        /* General */
        /* NOTE: We handle these because we have to be able
         * to save these based on command line overrides.
@@ -219,22 +196,35 @@ config_finalize (GObject *object)
 static void
 config_constructed (GObject *object)
 {
-       TrackerConfigPrivate *priv;
        GSettings *settings;
 
        (G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
 
-       priv = TRACKER_CONFIG (object)->priv;
-       settings = priv->settings;
+       settings = G_SETTINGS (object);
 
-       if (!settings) {
-               priv->settings = settings = g_settings_new_with_path (CONFIG_SCHEME, CONFIG_PATH);
+       if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               g_settings_delay (settings);
        }
 
-       g_settings_delay (settings);
-
-       /* Set up bindings */
-       g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET_NO_CHANGES);
+       /* Set up bindings:
+        *
+        * What's interesting here is that 'verbosity' and
+        * 'initial-sleep' are command line arguments that can be
+        * overridden, so we don't update the config when we set them
+        * from main() because it's a session configuration only, not
+        * a permanent one. To do this we use the flag
+        * G_SETTINGS_BIND_GET_NO_CHANGES.
+        *
+        * For the other settings, we don't bind the
+        * G_SETTINGS_BIND_SET because we don't want to save anything,
+        * ever, we only want to know about updates to the settings as
+        * they're changed externally. The only time this may be
+        * different is where we use the environment variable
+        * TRACKER_USE_CONFIG_FILES and we want to write a config
+        * file for convenience. But this is only necessary if the
+        * config is different to the default.
+        */
+       g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
        g_settings_bind (settings, "sched-idle", object, "sched-idle", G_SETTINGS_BIND_GET);
        g_settings_bind (settings, "max-bytes", object, "max-bytes", G_SETTINGS_BIND_GET);
        g_settings_bind (settings, "max-media-art-width", object, "max-media-art-width", G_SETTINGS_BIND_GET);
@@ -244,25 +234,43 @@ config_constructed (GObject *object)
 TrackerConfig *
 tracker_config_new (void)
 {
-       GSettings *settings = NULL;
+       TrackerConfig *config = NULL;
+
+       /* FIXME: should we unset GSETTINGS_BACKEND env var? */
 
        if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
-               /* FIXME: should we unset GSETTINGS_BACKEND env var? */
                GSettingsBackend *backend;
                gchar *filename, *basename;
+               gboolean need_to_save;
 
                basename = g_strdup_printf ("%s.cfg", g_get_prgname ());
                filename = g_build_filename (g_get_user_config_dir (), "tracker", basename, NULL);
                g_free (basename);
 
-               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, NULL);
+               need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
+
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
+               g_info ("Using config file '%s'", filename);
                g_free (filename);
 
-               settings = g_settings_new_with_backend (CONFIG_SCHEME, backend);
+               config = g_object_new (TRACKER_TYPE_CONFIG,
+                                      "backend", backend,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
                g_object_unref (backend);
+
+               if (need_to_save) {
+                       g_info ("  Config file does not exist, using default values...");
+               }
+       } else {
+               config = g_object_new (TRACKER_TYPE_CONFIG,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
        }
 
-       return g_object_new (TRACKER_TYPE_CONFIG, "settings", settings, NULL);
+       return config;
 }
 
 gint
diff --git a/src/tracker-extract/tracker-config.h b/src/tracker-extract/tracker-config.h
index c350310..daf1574 100644
--- a/src/tracker-extract/tracker-config.h
+++ b/src/tracker-extract/tracker-config.h
@@ -35,12 +35,12 @@ typedef struct TrackerConfig      TrackerConfig;
 typedef struct TrackerConfigClass TrackerConfigClass;
 
 struct TrackerConfig {
-       GObject parent;
+       GSettings parent;
        gpointer priv;
 };
 
 struct TrackerConfigClass {
-       GObjectClass parent_class;
+       GSettingsClass parent_class;
 };
 
 GType          tracker_config_get_type                (void) G_GNUC_CONST;
diff --git a/src/tracker-store/Makefile.am b/src/tracker-store/Makefile.am
index 1097e54..4c201de 100644
--- a/src/tracker-store/Makefile.am
+++ b/src/tracker-store/Makefile.am
@@ -13,6 +13,8 @@ AM_CPPFLAGS =                                          \
 #
 # Daemon sources
 #
+all: $(libexec_PROGRAMS) $(man_MANS)
+
 libexec_PROGRAMS = tracker-store
 
 tracker_store_SOURCES =                                \
@@ -95,25 +97,41 @@ autostart_DATA = tracker-store.desktop
 gsettings_ENUM_NAMESPACE = org.freedesktop.Tracker
 gsettings_ENUM_FILES = $(top_srcdir)/src/libtracker-common/tracker-enums.h
 
-gsettings_SCHEMAS = \
-       org.freedesktop.Tracker.gschema.xml \
-       org.freedesktop.Tracker.Store.gschema.xml
+gsettings_SCHEMAS = $(schemalist) $(config)
+
+config = org.freedesktop.Tracker.Store.gschema.xml
+schemalist = org.freedesktop.Tracker.gschema.xml
 
 @INTLTOOL_XML_NOMERGE_RULE@
 
 @GSETTINGS_RULES@
 
+if HAVE_XSLTPROC
+DATE=`date +'%B %Y'`
+man_MANS = $(libexec_PROGRAMS).cfg.5
+else
+man_MANS =
+endif
+
+%.cfg.5: $(config)
+       $(AM_V_GEN)$(XSLTPROC) \
+         --stringparam version "${VERSION}" \
+         --stringparam current-date "${DATE}" \
+         --stringparam config-file "$(@:.cfg.5=.cfg)" \
+         $(top_srcdir)/docs/manpages/gsettings.xsl $^ > $@
+
 # Dist / Clean rules for all data
 CLEANFILES = \
        $(autostart_DATA) \
        $(autostart_DATA:.desktop=.desktop.in) \
        $(service_DATA) \
-       $(gsettings_SCHEMAS)
+       $(gsettings_SCHEMAS) \
+       $(man_MANS)
 
 EXTRA_DIST += \
        $(autostart_DATA:.desktop=.desktop.in.in) \
        $(service_DATA:.service=.service.in) \
        $(config_DATA) \
-       $(gsettings_SCHEMAS:.xml=.xml.in)
-
+       $(gsettings_SCHEMAS:.xml=.xml.in) \
+       $(man_MANS)
 
diff --git a/src/tracker-store/tracker-config.c b/src/tracker-store/tracker-config.c
index 384c378..1c3f9c3 100644
--- a/src/tracker-store/tracker-config.c
+++ b/src/tracker-store/tracker-config.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -25,10 +26,16 @@
 #include <glib.h>
 #include <gio/gio.h>
 
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
 #include <libtracker-common/tracker-common.h>
 
 #include "tracker-config.h"
 
+#define CONFIG_SCHEMA "org.freedesktop.Tracker.Store"
+#define CONFIG_PATH   "/org/freedesktop/tracker/store/"
+
 #define GRAPHUPDATED_DELAY_DEFAULT     1000
 
 static void config_set_property         (GObject       *object,
@@ -142,18 +149,78 @@ config_finalize (GObject *object)
 static void
 config_constructed (GObject *object)
 {
+       GSettings *settings;
+
        (G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
 
-       g_settings_delay (G_SETTINGS (object));
+       settings = G_SETTINGS (object);
+
+       if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               g_settings_delay (settings);
+       }
+
+       /* Set up bindings:
+        *
+        * What's interesting here is that 'verbosity' and
+        * 'initial-sleep' are command line arguments that can be
+        * overridden, so we don't update the config when we set them
+        * from main() because it's a session configuration only, not
+        * a permanent one. To do this we use the flag
+        * G_SETTINGS_BIND_GET_NO_CHANGES.
+        *
+        * For the other settings, we don't bind the
+        * G_SETTINGS_BIND_SET because we don't want to save anything,
+        * ever, we only want to know about updates to the settings as
+        * they're changed externally. The only time this may be
+        * different is where we use the environment variable
+        * TRACKER_USE_CONFIG_FILES and we want to write a config
+        * file for convenience. But this is only necessary if the
+        * config is different to the default.
+        */
+       g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "graphupdated-delay", object, "graphupdated-delay", G_SETTINGS_BIND_GET);
 }
 
 TrackerConfig *
 tracker_config_new (void)
 {
-       return g_object_new (TRACKER_TYPE_CONFIG,
-                            "schema-id", "org.freedesktop.Tracker.Store",
-                            "path", "/org/freedesktop/tracker/store/",
-                            NULL);
+       TrackerConfig *config = NULL;
+
+       /* FIXME: should we unset GSETTINGS_BACKEND env var? */
+
+       if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               GSettingsBackend *backend;
+               gchar *filename, *basename;
+               gboolean need_to_save;
+
+               basename = g_strdup_printf ("%s.cfg", g_get_prgname ());
+               filename = g_build_filename (g_get_user_config_dir (), "tracker", basename, NULL);
+               g_free (basename);
+
+               need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
+
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
+               g_info ("Using config file '%s'", filename);
+               g_free (filename);
+
+               config = g_object_new (TRACKER_TYPE_CONFIG,
+                                      "backend", backend,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+               g_object_unref (backend);
+
+               if (need_to_save) {
+                       g_info ("  Config file does not exist, using default values...");
+               }
+       } else {
+               config = g_object_new (TRACKER_TYPE_CONFIG,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+       }
+
+       return config;
 }
 
 gint
@@ -185,7 +252,7 @@ tracker_config_get_graphupdated_delay (TrackerConfig *config)
 
 void
 tracker_config_set_graphupdated_delay (TrackerConfig *config,
-                                           gint           value)
+                                       gint           value)
 {
        g_return_if_fail (TRACKER_IS_CONFIG (config));
 
diff --git a/src/tracker-writeback/Makefile.am b/src/tracker-writeback/Makefile.am
index 89959b8..55fb8a1 100644
--- a/src/tracker-writeback/Makefile.am
+++ b/src/tracker-writeback/Makefile.am
@@ -42,6 +42,8 @@ endif
 #
 # Binaries
 #
+all: $(libexec_PROGRAMS) $(man_MANS)
+
 libexec_PROGRAMS = tracker-writeback
 
 tracker_writeback_SOURCES = \
@@ -83,12 +85,28 @@ gsettings_SCHEMAS = org.freedesktop.Tracker.Writeback.gschema.xml
 
 @GSETTINGS_RULES@
 
+if HAVE_XSLTPROC
+DATE=`date +'%B %Y'`
+man_MANS = $(libexec_PROGRAMS).cfg.5
+else
+man_MANS =
+endif
+
+%.cfg.5: $(gsettings_SCHEMAS)
+       $(AM_V_GEN)$(XSLTPROC) \
+         --stringparam version "${VERSION}" \
+         --stringparam current-date "${DATE}" \
+         --stringparam config-file "$(@:.cfg.5=.cfg)" \
+         $(top_srcdir)/docs/manpages/gsettings.xsl $^ > $@
+
 # Dist / Clean rules for all data
 CLEANFILES = \
        $(service_DATA) \
-       $(gsettings_SCHEMAS)
+       $(gsettings_SCHEMAS) \
+       $(man_MANS)
 
 EXTRA_DIST = \
        $(service_DATA:.service=.service.in) \
        $(config_DATA) \
-       $(gsettings_SCHEMAS:.xml=.xml.in)
+       $(gsettings_SCHEMAS:.xml=.xml.in) \
+       $(man_MANS)
diff --git a/src/tracker-writeback/tracker-config.c b/src/tracker-writeback/tracker-config.c
index 59e7940..dce8798 100644
--- a/src/tracker-writeback/tracker-config.c
+++ b/src/tracker-writeback/tracker-config.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -25,10 +26,16 @@
 #include <glib.h>
 #include <gio/gio.h>
 
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
 #include <libtracker-common/tracker-common.h>
 
 #include "tracker-config.h"
 
+#define CONFIG_SCHEMA "org.freedesktop.Tracker.Writeback"
+#define CONFIG_PATH   "/org/freedesktop/tracker/writeback/"
+
 static void     config_set_property         (GObject           *object,
                                              guint              param_id,
                                              const GValue      *value,
@@ -45,7 +52,7 @@ enum {
        PROP_VERBOSITY,
 };
 
-G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_OBJECT);
+G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_SETTINGS);
 
 static void
 tracker_config_class_init (TrackerConfigClass *klass)
@@ -76,7 +83,7 @@ static void
 config_set_property (GObject      *object,
                      guint         param_id,
                      const GValue *value,
-                     GParamSpec           *pspec)
+                     GParamSpec   *pspec)
 {
        switch (param_id) {
        case PROP_VERBOSITY:
@@ -114,18 +121,59 @@ config_finalize (GObject *object)
 static void
 config_constructed (GObject *object)
 {
+       GSettings *settings;
+
        (G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
 
-       g_settings_delay (G_SETTINGS (object));
+       settings = G_SETTINGS (object);
+
+       if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               g_settings_delay (settings);
+       }
+
+       g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
 }
 
 TrackerConfig *
 tracker_config_new (void)
 {
-       return g_object_new (TRACKER_TYPE_CONFIG,
-                            "schema-id", "org.freedesktop.Tracker.Writeback",
-                            "path", "/org/freedesktop/tracker/writeback/",
-                            NULL);
+       TrackerConfig *config = NULL;
+
+       /* FIXME: should we unset GSETTINGS_BACKEND env var? */
+
+       if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               GSettingsBackend *backend;
+               gchar *filename, *basename;
+               gboolean need_to_save;
+
+               basename = g_strdup_printf ("%s.cfg", g_get_prgname ());
+               filename = g_build_filename (g_get_user_config_dir (), "tracker", basename, NULL);
+               g_free (basename);
+
+               need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
+
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
+               g_info ("Using config file '%s'", filename);
+               g_free (filename);
+
+               config = g_object_new (TRACKER_TYPE_CONFIG,
+                                      "backend", backend,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+               g_object_unref (backend);
+
+               if (need_to_save) {
+                       g_info ("  Config file does not exist, using default values...");
+               }
+       } else {
+               config = g_object_new (TRACKER_TYPE_CONFIG,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+       }
+
+       return config;
 }
 
 gint



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