Commit 2b53cd5d authored by Martyn Russell's avatar Martyn Russell

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 :)
parent dc4fbfe9
......@@ -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
......
......@@ -35,4 +35,5 @@ EXTRA_DIST = \
$(common) \
$(tp) \
$(tn) \
$(tmrss)
$(tmrss) \
gsettings.xsl
<?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>
......@@ -6,3 +6,4 @@ tracker-sparql-scanner.c
tracker-turtle-reader.c
*.xml
*.valid
*.cfg.5
......@@ -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,14 +88,30 @@ 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
BUILT_SOURCES = \
libtracker_data_la_vala.stamp
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)
/*
* 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
......
......@@ -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)
/*
* 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
......
......@@ -2,3 +2,4 @@ tracker-miner-fs
*.service
*.xml
*.valid
*.cfg.5
......@@ -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)
/*
* 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");
}
......
......@@ -5,3 +5,4 @@ tracker-extract-priority-dbus.h
*.service
*.xml
*.valid
*.cfg.5
......@@ -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)
/*
* 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;