Refactor file backend settings to no longer depend on gconf

This affects many other components as well, including the
python bindings

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22942 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2013-05-03 12:03:38 +00:00
parent 5a26e65e6c
commit eb409ecd35
26 changed files with 178 additions and 112 deletions

View File

@ -29,6 +29,7 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/core-utils \
-I${top_srcdir}/src/engine \
-I${top_srcdir}/src/libqof/qof \
-I${top_srcdir}/src/backend/xml \
${GUILE_INCS} \
${PYTHON_CPPFLAGS} \
${GLIB_CFLAGS} \
@ -54,6 +55,7 @@ libgncmod_app_utils_la_SOURCES = \
gnc-gconf-utils.c \
gnc-gettext-util.c \
gnc-helpers.c \
gnc-prefs.c \
gnc-sx-instance-model.c \
gncmod-app-utils.c \
gnc-ui-balances.c \
@ -80,6 +82,7 @@ gncinclude_HEADERS = \
gnc-gettext-util.h \
gnc-help-utils.h \
gnc-helpers.h \
gnc-prefs.h \
gnc-sx-instance-model.h \
gnc-ui-balances.h \
gnc-ui-util.h \

View File

@ -8,6 +8,7 @@
#include <gnc-exp-parser.h>
#include <gnc-ui-util.h>
#include <gnc-gettext-util.h>
#include <gnc-prefs.h>
#include <gnc-helpers.h>
#include <gnc-accounting-period.h>
#include <gnc-session.h>
@ -41,6 +42,8 @@ SWIG_init (void);
typedef void (*GNCOptionChangeCallback) (gpointer user_data);
typedef int GNCOptionDBHandle;
void gnc_prefs_init();
QofBook * gnc_get_current_book (void);
const gchar * gnc_get_current_book_tax_name (void);
const gchar * gnc_get_current_book_tax_type (void);

View File

@ -28,13 +28,18 @@
#include <string.h>
#include "gnc-core-prefs.h"
#include "gnc-gconf-utils.h"
#include "gnc-backend-xml.h"
#define CLIENT_TAG "%s-%s-client"
#define NOTIFY_TAG "%s-%s-notify_id"
static QofLogModule log_module = G_LOG_DOMAIN;
static GConfClient *our_client = NULL;
static guint gconf_general_cb_id = 0;
/************************************************************/
/* Enum Utilities */
/************************************************************/
@ -987,3 +992,68 @@ gnc_gconf_schemas_found (void)
NULL);
return TRUE;
}
/***************************************************************
* Initialization *
***************************************************************/
static void
file_retain_changed_cb(GConfEntry *entry, gpointer user_data)
{
gint days = (int)gnc_gconf_get_float(GCONF_GENERAL, KEY_RETAIN_DAYS, NULL);
gnc_core_prefs_set_file_retention_days (days);
}
static void
file_retain_type_changed_cb(GConfEntry *entry, gpointer user_data)
{
XMLFileRetentionType type;
gchar *choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_RETAIN_TYPE, NULL);
if (!choice)
choice = g_strdup("days");
if (g_strcmp0 (choice, "never") == 0)
type = XML_RETAIN_NONE;
else if (g_strcmp0 (choice, "forever") == 0)
type = XML_RETAIN_ALL;
else
{
if (g_strcmp0 (choice, "days") != 0)
PERR("bad value '%s'", choice ? choice : "(null)");
type = XML_RETAIN_DAYS;
}
gnc_core_prefs_set_file_retention_policy (type);
g_free (choice);
}
static void
file_compression_changed_cb(GConfEntry *entry, gpointer user_data)
{
gboolean file_compression = gnc_gconf_get_bool(GCONF_GENERAL, KEY_FILE_COMPRESSION, NULL);
gnc_core_prefs_set_file_save_compressed (file_compression);
}
void gnc_gconf_prefs_init (void)
{
/* Add hooks to update core preferences whenever the associated gconf key changes */
gnc_gconf_general_register_cb(KEY_RETAIN_DAYS, file_retain_changed_cb, NULL);
gnc_gconf_general_register_cb(KEY_RETAIN_TYPE, file_retain_type_changed_cb, NULL);
gnc_gconf_general_register_cb(KEY_FILE_COMPRESSION, file_compression_changed_cb, NULL);
/* Call the hooks once manually to initialize the core preferences */
file_retain_changed_cb (NULL, NULL);
file_retain_type_changed_cb (NULL, NULL);
file_compression_changed_cb (NULL, NULL);
/* Backwards compatibility code. Pre 2.3.15, 0 retain_days meant
* "keep forever". From 2.3.15 on this is controlled via a multiple
* choice ("retain_type"). So if we find a 0 retain_days value with
* a "days" retain_type, we should interpret it as if we got a
* "forever" retain_type.
*/
if ( (gnc_core_prefs_get_file_retention_policy () == XML_RETAIN_DAYS) &&
(gnc_core_prefs_get_file_retention_days () == 0 ) )
{
gnc_gconf_set_string (GCONF_GENERAL, KEY_RETAIN_TYPE, "forever", NULL);
}
}

View File

@ -71,6 +71,11 @@
#define KEY_DATE_BACKMONTHS "date_backmonths"
#define KEY_SHOW_LEAF_ACCOUNT_NAMES "show_leaf_account_names"
/* Keys used for core preferences */
#define KEY_FILE_COMPRESSION "file_compression"
#define KEY_RETAIN_TYPE "retain_type"
#define KEY_RETAIN_DAYS "retain_days"
typedef void (*GncGconfGeneralCb) (GConfEntry *entry, gpointer user_data);
typedef void (*GncGconfGeneralAnyCb) (gpointer user_data);
@ -79,6 +84,11 @@ typedef void (*GncGconfGeneralAnyCb) (gpointer user_data);
@{
*/
/** This function is called early in the load process
* to preload a number of preferences from gconf
*/
void gnc_gconf_prefs_init (void);
/** This function takes an enum value and returns its nickname.
*
* @param type The value defining the enum class. For example,
@ -171,7 +181,7 @@ void gnc_gconf_suggest_sync (void);
/** Register a callback for when a specific key in the general section
* of Gnucash's gconf data is changed. Any time the key's value
* changes, the routine will be invoked and will be passed both the
* changes gconf entry and the user data passed to this function.
* changed gconf entry and the user data passed to this function.
*
* @param key This value contains the name of the key within the
* "general" section to watch.

30
src/app-utils/gnc-prefs.c Normal file
View File

@ -0,0 +1,30 @@
/********************************************************************\
* gnc-prefs.h -- utility functions for preferences management *
* Copyright (C) 2013 Geert Janssens <geert@kobaltwit.be> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "gnc-gconf-utils.h"
#include "gnc-prefs.h"
void gnc_prefs_init (void)
{
gnc_gconf_prefs_init ();
}

29
src/app-utils/gnc-prefs.h Normal file
View File

@ -0,0 +1,29 @@
/********************************************************************\
* gnc-prefs.h -- utility functions for preferences management *
* Copyright (C) 2013 Geert Janssens <geert@kobaltwit.be> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef GNC_PREFS_H_
#define GNC_PREFS_H_
void gnc_prefs_init (void);
#endif /* GNC_PREFS_H_ */

View File

@ -43,7 +43,7 @@
#include "qof.h"
#include "guile-mappings.h"
#include "core-utils/gnc-gconf-utils.h"
#include "gnc-gconf-utils.h"
#include "gnc-module/gnc-module.h"
#include "engine/Account.h"
#include "engine/Transaction.h"

View File

@ -14,6 +14,7 @@
#include "gnc-component-manager.h"
#include "gnc-hooks.h"
#include "gnc-prefs.h"
#include "gnc-exp-parser.h"
GNC_MODULE_API_DECL(libgncmod_app_utils)
@ -75,6 +76,7 @@ libgncmod_app_utils_gnc_module_init(int refcount)
if (refcount == 0)
{
gnc_component_manager_init ();
gnc_prefs_init ();
gnc_hook_add_dangler(HOOK_STARTUP, (GFunc)gnc_exp_parser_init, NULL);
gnc_hook_add_dangler(HOOK_SHUTDOWN, (GFunc)app_utils_shutdown, NULL);
}

View File

@ -46,7 +46,6 @@
#include "SX-book.h"
#include "Recurrence.h"
#include "gnc-gconf-utils.h"
#include "gnc-uri-utils.h"
#include "gnc-filepath-utils.h"
#include "gnc-locale-utils.h"

View File

@ -41,12 +41,6 @@ gnc_module_init(int refcount)
engine = gnc_module_load( "gnucash/engine", 0 );
if ( !engine ) return FALSE;
/* Need to initialize g-type engine for gconf */
if (refcount == 0)
{
g_type_init();
}
return TRUE;
}

View File

@ -1,5 +1,5 @@
/*
* utest-gnc-prefs-gconf.c
* utest-backend-dbi-basic.c
*
* Created on: 2011-04-23
* Author: phil

View File

@ -24,7 +24,7 @@
*/
/*
* utest-gnc-prefs-gconf.c
* utest-backend-dbi-business.c
*
* Created on: 2011-04-23
* Author: phil

View File

@ -46,8 +46,6 @@
#include "gncTaxTable.h"
#include "gncInvoice.h"
#include "gnc-gconf-utils.h"
#include "gnc-backend-sql.h"
#include "gnc-account-sql.h"

View File

@ -75,7 +75,7 @@ typedef int ssize_t;
#include "io-gncxml.h"
#include "io-gncxml-v2.h"
#include "gnc-backend-xml.h"
#include "gnc-gconf-utils.h"
#include "gnc-core-prefs.h"
#include "gnc-address-xml-v2.h"
#include "gnc-bill-term-xml-v2.h"
@ -93,10 +93,6 @@ typedef int ssize_t;
# include "strptime.h"
#endif
#define KEY_FILE_COMPRESSION "file_compression"
#define KEY_RETAIN_TYPE "retain_type"
#define KEY_RETAIN_DAYS "retain_days"
static QofLogModule log_module = GNC_MOD_BACKEND;
static gboolean save_may_clobber_data (QofBackend *bend);
@ -724,7 +720,7 @@ gnc_xml_be_write_to_file(FileBackend *fbe,
}
}
if (gnc_book_write_to_xml_file_v2(book, tmp_name, fbe->file_compression))
if (gnc_book_write_to_xml_file_v2(book, tmp_name, gnc_core_prefs_get_file_save_compressed()))
{
/* Record the file's permissions before g_unlinking it */
rc = g_stat(datafile, &statbuf);
@ -949,13 +945,13 @@ gnc_xml_be_remove_old_files(FileBackend *be)
/* The file is a backup or log file. Check the user's retention preference
* to determine if we should keep it or not
*/
if (be->file_retention_type == XML_RETAIN_NONE)
if (gnc_core_prefs_get_file_retention_policy() == XML_RETAIN_NONE)
{
PINFO ("remove stale file: %s - reason: preference XML_RETAIN_NONE", name);
g_unlink(name);
}
else if ((be->file_retention_type == XML_RETAIN_DAYS) &&
(be->file_retention_days > 0))
else if ((gnc_core_prefs_get_file_retention_policy() == XML_RETAIN_DAYS) &&
(gnc_core_prefs_get_file_retention_days() > 0))
{
int days;
@ -967,8 +963,8 @@ gnc_xml_be_remove_old_files(FileBackend *be)
}
days = (int)(difftime(now, statbuf.st_mtime) / 86400);
PINFO ("file retention = %d days", be->file_retention_days);
if (days >= be->file_retention_days)
PINFO ("file retention = %d days", gnc_core_prefs_get_file_retention_days());
if (days >= gnc_core_prefs_get_file_retention_days())
{
PINFO ("remove stale file: %s - reason: more than %d days old", name, days);
g_unlink(name);
@ -1226,46 +1222,6 @@ libgncmod_backend_file_LTX_gnc_backend_new(void)
}
#endif
static void
retain_changed_cb(GConfEntry *entry, gpointer user_data)
{
FileBackend *be = (FileBackend*)user_data;
g_return_if_fail(be != NULL);
be->file_retention_days = (int)gnc_gconf_get_float(GCONF_GENERAL, KEY_RETAIN_DAYS, NULL);
}
static void
retain_type_changed_cb(GConfEntry *entry, gpointer user_data)
{
FileBackend *be = (FileBackend*)user_data;
gchar *choice = NULL;
g_return_if_fail(be != NULL);
choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_RETAIN_TYPE, NULL);
if (!choice)
choice = g_strdup("days");
if (g_strcmp0 (choice, "never") == 0)
be->file_retention_type = XML_RETAIN_NONE;
else if (g_strcmp0 (choice, "forever") == 0)
be->file_retention_type = XML_RETAIN_ALL;
else
{
if (g_strcmp0 (choice, "days") != 0)
PERR("bad value '%s'", choice ? choice : "(null)");
be->file_retention_type = XML_RETAIN_DAYS;
}
g_free (choice);
}
static void
compression_changed_cb(GConfEntry *entry, gpointer user_data)
{
FileBackend *be = (FileBackend*)user_data;
g_return_if_fail(be != NULL);
be->file_compression = gnc_gconf_get_bool(GCONF_GENERAL, KEY_FILE_COMPRESSION, NULL);
}
static QofBackend*
gnc_backend_new(void)
{
@ -1310,27 +1266,6 @@ gnc_backend_new(void)
gnc_be->book = NULL;
gnc_be->file_retention_days = (int)gnc_gconf_get_float(GCONF_GENERAL, KEY_RETAIN_DAYS, NULL);
gnc_be->file_compression = gnc_gconf_get_bool(GCONF_GENERAL, KEY_FILE_COMPRESSION, NULL);
retain_type_changed_cb(NULL, (gpointer)be); /* Get retain_type from gconf */
if ( (gnc_be->file_retention_type == XML_RETAIN_DAYS) &&
(gnc_be->file_retention_days == 0 ) )
{
/* Backwards compatibility code. Pre 2.3.15, 0 retain_days meant
* "keep forever". From 2.3.15 on this is controlled via a multiple
* choice ("retain_type"). So if we find a 0 retain_days value with
* a "days" retain_type, we should interpret it as if we got a
* "forever" retain_type.
*/
gnc_be->file_retention_type = XML_RETAIN_ALL;
gnc_gconf_set_string (GCONF_GENERAL, KEY_RETAIN_TYPE, "forever", NULL);
}
gnc_gconf_general_register_cb(KEY_RETAIN_DAYS, retain_changed_cb, be);
gnc_gconf_general_register_cb(KEY_RETAIN_TYPE, retain_type_changed_cb, be);
gnc_gconf_general_register_cb(KEY_FILE_COMPRESSION, compression_changed_cb, be);
return be;
}

View File

@ -64,10 +64,6 @@ struct FileBackend_struct
int lockfd;
QofBook *book; /* The primary, main open book */
XMLFileRetentionType file_retention_type;
int file_retention_days;
gboolean file_compression;
};
typedef struct FileBackend_struct FileBackend;

View File

@ -29,7 +29,6 @@
#include <stdlib.h>
#include <string.h>
#include "gnc-gconf-utils.h"
#include "gnc-xml-helper.h"
#include "sixtp.h"

View File

@ -44,8 +44,6 @@
#include "sixtp-dom-parsers.h"
#include "gnc-gconf-utils.h"
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.backend.file.sx"

View File

@ -43,10 +43,6 @@ libgncmod_backend_file_gnc_module_init(int refcount)
engine = gnc_module_load("gnucash/engine", 0);
if (!engine) return FALSE;
/* Need to initialize g-type engine for gconf */
if (refcount == 0)
g_type_init();
return TRUE;
}

View File

@ -31,7 +31,6 @@
#include "gnc-xml.h"
#include "gnc-xml.h"
#include "io-utils.h"
#include "gnc-gconf-utils.h"
/*
<!-- Local variables: -->

View File

@ -49,7 +49,7 @@
#include "gnome-utils/gnc-icons.h" /* for GNC_STOCK_INVOICE_NEW */
#include "gnc-core-prefs.h" /* for GCONF_PATH */
#include "core-utils/gnc-gconf-utils.h"
#include "gnc-gconf-utils.h"
#include "gnome-utils/gnc-main-window.h"
#include "gnc-plugin-page-register.h"

View File

@ -39,7 +39,7 @@
#include "table-allgui.h"
#include "pricecell.h"
#include "dialog-tax-table.h"
#include "core-utils/gnc-gconf-utils.h"
#include "gnc-gconf-utils.h"
#include "register/register-core/checkboxcell.h"
#include "gncEntryLedgerP.h"

View File

@ -25,7 +25,7 @@ void
#endif
%import "base-typemaps.i"
gboolean gnc_core_prefs_is_debugging_enabled(void);
%include <gnc-core-prefs.h>
%newobject gnc_path_get_bindir;
gchar * gnc_path_get_bindir(void);
@ -56,8 +56,6 @@ gchar * gnc_locale_from_utf8(const gchar *);
%newobject gnc_locale_to_utf8;
gchar * gnc_locale_to_utf8(const gchar *);
gboolean gnc_core_prefs_is_extra_enabled();
const char * gnc_locale_default_iso_currency_code (void);
#if defined(SWIGGUILE)

View File

@ -25,14 +25,18 @@
#include "config.h"
#include "gnc-core-prefs.h"
#include "gnc-version.h"
#include "libqof/qof/qof.h"
static gchar *namespace_regexp = NULL;
static gboolean is_debugging = FALSE;
static gboolean extras_enabled = FALSE;
static gboolean use_compression = FALSE;
static gint file_retention_policy = 0;
static gint file_retention_days = 0;
static const gchar *gconf_path;
static gboolean use_compression = TRUE; // This is also the default in GConf
static gint file_retention_policy = 1; // 1 = "days", the default in GConf
static gint file_retention_days = 30; // This is also the default in GConf
static const gchar *gconf_path = "/apps/gnucash"; // A sensible default
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = G_LOG_DOMAIN;
const gchar *
gnc_core_prefs_get_namespace_regexp(void)

View File

@ -46,7 +46,7 @@
#include "gnc-engine.h"
#include "gnc-ui-util.h"
#include "gnc-glib-utils.h"
#include "core-utils/gnc-gconf-utils.h"
#include "gnc-gconf-utils.h"
#include "gnome-utils/gnc-ui.h"
#include "gnome-utils/dialog-account.h"
#include "dialog-utils.h"

View File

@ -24,7 +24,7 @@ _gnucash_core_c_la_CPPFLAGS = \
-I${top_srcdir}/src/app-utils \
-I${top_srcdir}/src/gnc-module \
-I${top_srcdir}/src/gnome \
-I${top_srcdir}/src/core-utils \
-I${top_srcdir}/src/core-utils \
-I${top_srcdir}/src/gnc-module
# Suppress all warnings for now, but we really only need to -Wno-implicit
@ -36,7 +36,8 @@ _gnucash_core_c_la_LIBADD = \
${GLIB_LIBS} \
${top_builddir}/src/libqof/qof/libgnc-qof.la \
${top_builddir}/src/gnc-module/libgnc-module.la \
${top_builddir}/src/engine/libgncmod-engine.la
${top_builddir}/src/engine/libgncmod-engine.la \
${top_builddir}/src/app-utils/libgncmod-app-utils.la
if BUILDING_FROM_SCM
_gnucash_core_c_includes= \
${top_builddir}/config.h \
@ -66,13 +67,14 @@ _gnucash_core_c_includes= \
${top_srcdir}/src/engine/gncEntry.h \
${top_srcdir}/src/engine/gncTaxTable.h \
${top_srcdir}/src/engine/gncIDSearch.h \
${top_srcdir}/src/engine/gnc-pricedb.h
${top_srcdir}/src/engine/gnc-pricedb.h \
${top_srcdir}/src/app-utils/gnc-prefs.h
gnucash_core.c: $(SWIG_FILES) ${top_srcdir}/src/base-typemaps.i ${top_srcdir}/src/engine/engine-common.i $(_gnucash_core_c_includes)
swig -python -Wall -Werror \
-I$(top_srcdir)/src -I$(top_srcdir)/src/engine \
-I${top_srcdir}/src/libqof/qof \
-I$(top_srcdir)/src/app-utils -I${top_srcdir}/src/libqof/qof \
-o $@ $<
gnucash_core_c.py: gnucash_core.c $(SWIG_FILES)

View File

@ -77,6 +77,7 @@
#include "gncTaxTable.h"
#include "gncIDSearch.h"
#include "engine/gnc-pricedb.h"
#include "app-utils/gnc-prefs.h"
%}
%include <timespec.i>
@ -204,7 +205,6 @@
// Commodity prices includes and stuff
%include <gnc-pricedb.h>
%init %{
qof_log_init();
qof_init();
@ -212,5 +212,6 @@ qof_query_init();
gnc_module_system_init();
char * no_args[1] = { NULL };
gnc_engine_init(0, no_args);
gnc_prefs_init();
%}