GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Macros | Functions

The only function in this file is meant to initialize the preferences system early in the load process. More...

Files

file  gnc-prefs-utils.h
 Preferences initialization function.
 
file  gnc-prefs.h
 Generic api to store and retrieve preferences.
 

Macros

#define GNC_PREFS_GROUP_GENERAL   "general"
 
#define GNC_PREFS_GROUP_GENERAL_REGISTER   "general.register"
 
#define GNC_PREFS_GROUP_GENERAL_REPORT   "general.report"
 
#define GNC_PREFS_GROUP_WARNINGS   "general.warnings"
 
#define GNC_PREFS_GROUP_WARNINGS_TEMP   "warnings.temporary"
 
#define GNC_PREFS_GROUP_WARNINGS_PERM   "warnings.permanent"
 
#define GNC_PREFS_GROUP_ACCT_SUMMARY   "window.pages.account-tree.summary"
 
#define GNC_PREF_VERSION   "prefs-version"
 
#define GNC_PREF_SAVE_GEOMETRY   "save-window-geometry"
 
#define GNC_PREF_LAST_PATH   "last-path"
 
#define GNC_PREF_USE_NEW   "use-new-window"
 
#define GNC_PREF_ACCOUNTING_LABELS   "use-accounting-labels"
 
#define GNC_PREF_ACCOUNT_SEPARATOR   "account-separator"
 
#define GNC_PREF_NEGATIVE_IN_RED   "negative-in-red"
 
#define GNC_PREF_NUM_SOURCE   "num-source"
 
#define GNC_PREF_DATE_FORMAT   "date-format"
 
#define GNC_PREF_DATE_COMPL_THISYEAR   "date-completion-thisyear"
 
#define GNC_PREF_DATE_COMPL_SLIDING   "date-completion-sliding"
 
#define GNC_PREF_DATE_BACKMONTHS   "date-backmonths"
 
#define GNC_PREF_SHOW_LEAF_ACCT_NAMES   "show-leaf-account-names"
 
#define GNC_PREF_ENTER_MOVES_TO_END   "enter-moves-to-end"
 
#define GNC_PREF_DRAW_HOR_LINES   "draw-horizontal-lines"
 
#define GNC_PREF_DRAW_VERT_LINES   "draw-vertical-lines"
 
#define GNC_PREF_ALT_COLOR_BY_TRANS   "alternate-color-by-transaction"
 
#define GNC_PREF_USE_THEME_COLORS   "use-theme-colors"
 
#define GNC_PREF_USE_GNUCASH_COLOR_THEME   "use-gnucash-color-theme"
 
#define GNC_PREF_TAB_TRANS_MEMORISED   "tab-to-transfer-on-memorised"
 
#define GNC_PREF_FUTURE_AFTER_BLANK   "future-after-blank-transaction"
 
#define GNC_PREF_JUMP_MULT_SPLITS   "jump-multiple-splits"
 
#define GNC_PREF_START_CHOICE_ABS   "start-choice-absolute"
 
#define GNC_PREF_START_CHOICE_REL   "start-choice-relative"
 
#define GNC_PREF_START_DATE   "start-date"
 
#define GNC_PREF_START_PERIOD   "start-period"
 
#define GNC_PREF_END_CHOICE_ABS   "end-choice-absolute"
 
#define GNC_PREF_END_CHOICE_REL   "end-choice-relative"
 
#define GNC_PREF_END_DATE   "end-date"
 
#define GNC_PREF_END_PERIOD   "end-period"
 
#define GNC_PREF_CURRENCY_OTHER   "currency-other"
 
#define GNC_PREF_CURRENCY_CHOICE_LOCALE   "currency-choice-locale"
 
#define GNC_PREF_CURRENCY_CHOICE_OTHER   "currency-choice-other"
 

Functions

void gnc_prefs_init (void)
 This function is called early in the load process to preload a number of preferences from the settings backend.
 
void gnc_prefs_remove_registered (void)
 This function is called to remove the registered preference call backs setup in this file.
 
gboolean gnc_prefs_is_set_up (void)
 Test if preferences backend is set up.
 
void gnc_prefs_block_all (void)
 Block all preference callbacks.
 
void gnc_prefs_unblock_all (void)
 Unblock all preferences callbacks.
 

Early bird functions, needed before any backend has been set up

const gchar * gnc_prefs_get_namespace_regexp (void)
 
void gnc_prefs_set_namespace_regexp (const gchar *str)
 
gboolean gnc_prefs_is_debugging_enabled (void)
 
void gnc_prefs_set_debugging (gboolean d)
 
gboolean gnc_prefs_is_extra_enabled (void)
 
void gnc_prefs_set_extra (gboolean enabled)
 
gboolean gnc_prefs_get_file_save_compressed (void)
 
void gnc_prefs_set_file_save_compressed (gboolean compressed)
 
gint gnc_prefs_get_file_retention_policy (void)
 
void gnc_prefs_set_file_retention_policy (gint policy)
 
gint gnc_prefs_get_file_retention_days (void)
 
void gnc_prefs_set_file_retention_days (gint days)
 
guint gnc_prefs_get_long_version (void)
 

Listening for changes

gulong gnc_prefs_register_cb (const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
 Register a callback that gets triggered when the given preference changes.
 
void gnc_prefs_remove_cb_by_func (const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
 Remove a function that was registered for a callback when the given preference changed.
 
void gnc_prefs_remove_cb_by_id (const gchar *group, guint id)
 Remove a function that was registered for a callback when a specific preference in the settings group changed.
 
guint gnc_prefs_register_group_cb (const gchar *group, gpointer func, gpointer user_data)
 Register a callback for when any preference in the settings group is changed.
 
void gnc_prefs_remove_group_cb_by_func (const gchar *group, gpointer func, gpointer user_data)
 Remove a function that was registered for a callback when any preference in the given settings group changed.
 
void gnc_prefs_bind (const gchar *group, const gchar *pref_name, const gchar *pref_value, gpointer object, const gchar *property)
 Bind a setting to a g_object property.
 

Preference Getters

gboolean gnc_prefs_get_bool (const gchar *group, const gchar *pref_name)
 Get a boolean value from the preferences backend.
 
gint gnc_prefs_get_int (const gchar *group, const gchar *pref_name)
 Get an integer value from the preferences backend.
 
gint64 gnc_prefs_get_int64 (const gchar *group, const gchar *pref_name)
 Get an 64 bit integer value from the preferences backend.
 
gdouble gnc_prefs_get_float (const gchar *group, const gchar *pref_name)
 Get an float value from the preferences backend.
 
gchar * gnc_prefs_get_string (const gchar *group, const gchar *pref_name)
 Get a string value from the preferences backend.
 
gint gnc_prefs_get_enum (const gchar *group, const gchar *pref_name)
 Get an enum value from the preferences backend.
 
void gnc_prefs_get_coords (const gchar *group, const gchar *pref_name, gdouble *x, gdouble *y)
 Get a pair of coordinates from the preferences backend.
 
GVariant * gnc_prefs_get_value (const gchar *group, const gchar *pref_name)
 Get an arbitrary combination of values from the preferences backend.
 

Preference Setters and Unset Functions

gboolean gnc_prefs_set_bool (const gchar *group, const gchar *pref_name, gboolean value)
 Store a boolean value into the preferences backend.
 
gboolean gnc_prefs_set_int (const gchar *group, const gchar *pref_name, gint value)
 Store an integer value into the preferences backend.
 
gboolean gnc_prefs_set_int64 (const gchar *group, const gchar *pref_name, gint64 value)
 Store a 64 bit integer value into the preferences backend.
 
gboolean gnc_prefs_set_float (const gchar *group, const gchar *pref_name, gdouble value)
 Store a float value into the preferences backend.
 
gboolean gnc_prefs_set_string (const gchar *group, const gchar *pref_name, const gchar *value)
 Store a string into the preferences backend.
 
gboolean gnc_prefs_set_enum (const gchar *group, const gchar *pref_name, gint value)
 Store an enum value into the preferences backend.
 
gboolean gnc_prefs_set_coords (const gchar *group, const gchar *pref_name, gdouble x, gdouble y)
 Store coordinates into the preferences backend.
 
gboolean gnc_prefs_set_value (const gchar *group, const gchar *pref_name, GVariant *value)
 Store an arbitrary combination of values into the preferences backend.
 
void gnc_prefs_reset (const gchar *group, const gchar *pref_name)
 Reset a preference to its default value in the preferences backend.
 
void gnc_prefs_reset_group (const gchar *group)
 Reset all preferences in a group to their default values in the preferences backend.
 
gulong gnc_prefs_get_reg_auto_raise_lists_id (void)
 Get and Set registered preference id for register auto_raise_lists.
 
void gnc_prefs_set_reg_auto_raise_lists_id (gulong id)
 
gulong gnc_prefs_get_reg_negative_color_pref_id (void)
 Get and Set registered preference id for register negative_color_pref.
 
void gnc_prefs_set_reg_negative_color_pref_id (gulong id)
 

Detailed Description

The only function in this file is meant to initialize the preferences system early in the load process.

The API in this file is used to read and store preferences used by gnucash.

This is done in a way to hide the actual preferences backend from the rest of the engine.

This api is a generic one. To actually store and load preferences, a preferences backend should be configured. Currently only one backend is defined: the preferences backend.

Note that preferences are organized in groups. Most functions will require both a group and a preference name to find the exact preference to work with.

Macro Definition Documentation

◆ GNC_PREF_ACCOUNT_SEPARATOR

#define GNC_PREF_ACCOUNT_SEPARATOR   "account-separator"

Definition at line 65 of file gnc-prefs.h.

◆ GNC_PREF_ACCOUNTING_LABELS

#define GNC_PREF_ACCOUNTING_LABELS   "use-accounting-labels"

Definition at line 64 of file gnc-prefs.h.

◆ GNC_PREF_ALT_COLOR_BY_TRANS

#define GNC_PREF_ALT_COLOR_BY_TRANS   "alternate-color-by-transaction"

Definition at line 77 of file gnc-prefs.h.

◆ GNC_PREF_CURRENCY_CHOICE_LOCALE

#define GNC_PREF_CURRENCY_CHOICE_LOCALE   "currency-choice-locale"

Definition at line 94 of file gnc-prefs.h.

◆ GNC_PREF_CURRENCY_CHOICE_OTHER

#define GNC_PREF_CURRENCY_CHOICE_OTHER   "currency-choice-other"

Definition at line 95 of file gnc-prefs.h.

◆ GNC_PREF_CURRENCY_OTHER

#define GNC_PREF_CURRENCY_OTHER   "currency-other"

Definition at line 93 of file gnc-prefs.h.

◆ GNC_PREF_DATE_BACKMONTHS

#define GNC_PREF_DATE_BACKMONTHS   "date-backmonths"

Definition at line 71 of file gnc-prefs.h.

◆ GNC_PREF_DATE_COMPL_SLIDING

#define GNC_PREF_DATE_COMPL_SLIDING   "date-completion-sliding"

Definition at line 70 of file gnc-prefs.h.

◆ GNC_PREF_DATE_COMPL_THISYEAR

#define GNC_PREF_DATE_COMPL_THISYEAR   "date-completion-thisyear"

Definition at line 69 of file gnc-prefs.h.

◆ GNC_PREF_DATE_FORMAT

#define GNC_PREF_DATE_FORMAT   "date-format"

Definition at line 68 of file gnc-prefs.h.

◆ GNC_PREF_DRAW_HOR_LINES

#define GNC_PREF_DRAW_HOR_LINES   "draw-horizontal-lines"

Definition at line 75 of file gnc-prefs.h.

◆ GNC_PREF_DRAW_VERT_LINES

#define GNC_PREF_DRAW_VERT_LINES   "draw-vertical-lines"

Definition at line 76 of file gnc-prefs.h.

◆ GNC_PREF_END_CHOICE_ABS

#define GNC_PREF_END_CHOICE_ABS   "end-choice-absolute"

Definition at line 88 of file gnc-prefs.h.

◆ GNC_PREF_END_CHOICE_REL

#define GNC_PREF_END_CHOICE_REL   "end-choice-relative"

Definition at line 89 of file gnc-prefs.h.

◆ GNC_PREF_END_DATE

#define GNC_PREF_END_DATE   "end-date"

Definition at line 90 of file gnc-prefs.h.

◆ GNC_PREF_END_PERIOD

#define GNC_PREF_END_PERIOD   "end-period"

Definition at line 91 of file gnc-prefs.h.

◆ GNC_PREF_ENTER_MOVES_TO_END

#define GNC_PREF_ENTER_MOVES_TO_END   "enter-moves-to-end"

Definition at line 73 of file gnc-prefs.h.

◆ GNC_PREF_FUTURE_AFTER_BLANK

#define GNC_PREF_FUTURE_AFTER_BLANK   "future-after-blank-transaction"

Definition at line 81 of file gnc-prefs.h.

◆ GNC_PREF_JUMP_MULT_SPLITS

#define GNC_PREF_JUMP_MULT_SPLITS   "jump-multiple-splits"

Definition at line 82 of file gnc-prefs.h.

◆ GNC_PREF_LAST_PATH

#define GNC_PREF_LAST_PATH   "last-path"

Definition at line 62 of file gnc-prefs.h.

◆ GNC_PREF_NEGATIVE_IN_RED

#define GNC_PREF_NEGATIVE_IN_RED   "negative-in-red"

Definition at line 66 of file gnc-prefs.h.

◆ GNC_PREF_NUM_SOURCE

#define GNC_PREF_NUM_SOURCE   "num-source"

Definition at line 67 of file gnc-prefs.h.

◆ GNC_PREF_SAVE_GEOMETRY

#define GNC_PREF_SAVE_GEOMETRY   "save-window-geometry"

Definition at line 61 of file gnc-prefs.h.

◆ GNC_PREF_SHOW_LEAF_ACCT_NAMES

#define GNC_PREF_SHOW_LEAF_ACCT_NAMES   "show-leaf-account-names"

Definition at line 72 of file gnc-prefs.h.

◆ GNC_PREF_START_CHOICE_ABS

#define GNC_PREF_START_CHOICE_ABS   "start-choice-absolute"

Definition at line 84 of file gnc-prefs.h.

◆ GNC_PREF_START_CHOICE_REL

#define GNC_PREF_START_CHOICE_REL   "start-choice-relative"

Definition at line 85 of file gnc-prefs.h.

◆ GNC_PREF_START_DATE

#define GNC_PREF_START_DATE   "start-date"

Definition at line 86 of file gnc-prefs.h.

◆ GNC_PREF_START_PERIOD

#define GNC_PREF_START_PERIOD   "start-period"

Definition at line 87 of file gnc-prefs.h.

◆ GNC_PREF_TAB_TRANS_MEMORISED

#define GNC_PREF_TAB_TRANS_MEMORISED   "tab-to-transfer-on-memorised"

Definition at line 80 of file gnc-prefs.h.

◆ GNC_PREF_USE_GNUCASH_COLOR_THEME

#define GNC_PREF_USE_GNUCASH_COLOR_THEME   "use-gnucash-color-theme"

Definition at line 79 of file gnc-prefs.h.

◆ GNC_PREF_USE_NEW

#define GNC_PREF_USE_NEW   "use-new-window"

Definition at line 63 of file gnc-prefs.h.

◆ GNC_PREF_USE_THEME_COLORS

#define GNC_PREF_USE_THEME_COLORS   "use-theme-colors"

Definition at line 78 of file gnc-prefs.h.

◆ GNC_PREF_VERSION

#define GNC_PREF_VERSION   "prefs-version"

Definition at line 60 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_ACCT_SUMMARY

#define GNC_PREFS_GROUP_ACCT_SUMMARY   "window.pages.account-tree.summary"

Definition at line 57 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_GENERAL

#define GNC_PREFS_GROUP_GENERAL   "general"

Definition at line 51 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_GENERAL_REGISTER

#define GNC_PREFS_GROUP_GENERAL_REGISTER   "general.register"

Definition at line 52 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_GENERAL_REPORT

#define GNC_PREFS_GROUP_GENERAL_REPORT   "general.report"

Definition at line 53 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_WARNINGS

#define GNC_PREFS_GROUP_WARNINGS   "general.warnings"

Definition at line 54 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_WARNINGS_PERM

#define GNC_PREFS_GROUP_WARNINGS_PERM   "warnings.permanent"

Definition at line 56 of file gnc-prefs.h.

◆ GNC_PREFS_GROUP_WARNINGS_TEMP

#define GNC_PREFS_GROUP_WARNINGS_TEMP   "warnings.temporary"

Definition at line 55 of file gnc-prefs.h.

Function Documentation

◆ gnc_prefs_bind()

void gnc_prefs_bind ( const gchar *  group,
const gchar *  pref_name,
const gchar *  pref_value,
gpointer  object,
const gchar *  property 
)

Bind a setting to a g_object property.

When this succeeds a change of the setting will automatically update the bound object property and vice versa.

Parameters
groupThis string contains the group name of the preference to bind to.
pref_nameThis string is the name of the particular preference to bind to.
pref_valueThis string is the enum value of the preference to bind to.
objectThe object to be bound.
propertyThe property of the object to bind to.

Definition at line 180 of file gnc-prefs.cpp.

185{
186 if (prefsbackend && prefsbackend->bind)
187 (prefsbackend->bind) (group, pref_name, pref_value, object, property);
188}

◆ gnc_prefs_block_all()

void gnc_prefs_block_all ( void  )

Block all preference callbacks.

Definition at line 379 of file gnc-prefs.cpp.

380{
381 if (prefsbackend && prefsbackend->block_all)
382 (prefsbackend->block_all) ();
383}

◆ gnc_prefs_get_bool()

gboolean gnc_prefs_get_bool ( const gchar *  group,
const gchar *  pref_name 
)

Get a boolean value from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the TRUE or FALSE value stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend.

Definition at line 16 of file gmock-gnc-prefs.cpp.

17{
18 EXPECT_NE(prefsbackend, nullptr);
19 return prefsbackend ? prefsbackend->get_bool(group, pref_name) : FALSE;
20}

◆ gnc_prefs_get_coords()

void gnc_prefs_get_coords ( const gchar *  group,
const gchar *  pref_name,
gdouble *  x,
gdouble *  y 
)

Get a pair of coordinates from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
xThe x coordinate to retrieve.
yThe y coordinate to retrieve.

If there is an error in processing, both coordinates will be set to zero.

Definition at line 58 of file gmock-gnc-prefs.cpp.

59{
60 EXPECT_NE(prefsbackend, nullptr);
61
62 *x = 0.0;
63 *y = 0.0;
64
65 if (prefsbackend != nullptr)
66 prefsbackend->get_coords(group, pref_name, x, y);
67}

◆ gnc_prefs_get_enum()

gint gnc_prefs_get_enum ( const gchar *  group,
const gchar *  pref_name 
)

Get an enum value from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the enum value stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend. If there is an error in processing, zero will be returned.

Definition at line 51 of file gmock-gnc-prefs.cpp.

52{
53 EXPECT_NE(prefsbackend, nullptr);
54 return prefsbackend ? prefsbackend->get_enum(group, pref_name) : 0;
55}

◆ gnc_prefs_get_file_retention_days()

gint gnc_prefs_get_file_retention_days ( void  )

Definition at line 110 of file gnc-prefs.cpp.

111{
112 return file_retention_days;
113}

◆ gnc_prefs_get_file_retention_policy()

gint gnc_prefs_get_file_retention_policy ( void  )

Definition at line 98 of file gnc-prefs.cpp.

99{
100 return file_retention_policy;
101}

◆ gnc_prefs_get_file_save_compressed()

gboolean gnc_prefs_get_file_save_compressed ( void  )

Definition at line 86 of file gnc-prefs.cpp.

87{
88 return use_compression;
89}

◆ gnc_prefs_get_float()

gdouble gnc_prefs_get_float ( const gchar *  group,
const gchar *  pref_name 
)

Get an float value from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the float value stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend. If there is an error in processing, zero will be returned.

Definition at line 37 of file gmock-gnc-prefs.cpp.

38{
39 EXPECT_NE(prefsbackend, nullptr);
40 return prefsbackend ? prefsbackend->get_float(group, pref_name) : 0.0;
41}

◆ gnc_prefs_get_int()

gint gnc_prefs_get_int ( const gchar *  group,
const gchar *  pref_name 
)

Get an integer value from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the integer value stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend. If there is an error in processing, zero will be returned.

Definition at line 23 of file gmock-gnc-prefs.cpp.

24{
25 EXPECT_NE(prefsbackend, nullptr);
26 return prefsbackend ? prefsbackend->get_int(group, pref_name) : 0;
27}

◆ gnc_prefs_get_int64()

gint64 gnc_prefs_get_int64 ( const gchar *  group,
const gchar *  pref_name 
)

Get an 64 bit integer value from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the 64 bit integer value stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend. If there is an error in processing, zero will be returned.

Definition at line 30 of file gmock-gnc-prefs.cpp.

31{
32 EXPECT_NE(prefsbackend, nullptr);
33 return prefsbackend ? prefsbackend->get_int64(group, pref_name) : 0;
34}

◆ gnc_prefs_get_long_version()

guint gnc_prefs_get_long_version ( void  )

Definition at line 122 of file gnc-prefs.cpp.

123{
124 return PROJECT_VERSION_MAJOR * 1000000 + PROJECT_VERSION_MINOR;
125}

◆ gnc_prefs_get_namespace_regexp()

const gchar * gnc_prefs_get_namespace_regexp ( void  )

Definition at line 49 of file gnc-prefs.cpp.

50{
51 return namespace_regexp.c_str();
52}

◆ gnc_prefs_get_reg_auto_raise_lists_id()

gulong gnc_prefs_get_reg_auto_raise_lists_id ( void  )

Get and Set registered preference id for register auto_raise_lists.

Definition at line 391 of file gnc-prefs.cpp.

392{
393 return reg_auto_raise_lists_id;
394}

◆ gnc_prefs_get_reg_negative_color_pref_id()

gulong gnc_prefs_get_reg_negative_color_pref_id ( void  )

Get and Set registered preference id for register negative_color_pref.

Definition at line 401 of file gnc-prefs.cpp.

402{
403 return reg_negative_color_pref_id;
404}

◆ gnc_prefs_get_string()

gchar * gnc_prefs_get_string ( const gchar *  group,
const gchar *  pref_name 
)

Get a string value from the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the string value stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend If there is an error in processing, NULL will be returned.

Definition at line 44 of file gmock-gnc-prefs.cpp.

45{
46 EXPECT_NE(prefsbackend, nullptr);
47 return prefsbackend ? prefsbackend->get_string(group, pref_name) : NULL;
48}

◆ gnc_prefs_get_value()

GVariant * gnc_prefs_get_value ( const gchar *  group,
const gchar *  pref_name 
)

Get an arbitrary combination of values from the preferences backend.

This combination of values can be anything that can be encapsulated in a GVariant structure.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
Returns
This function returns the a GVariant encapsulating the combination of values stored at the requested preference in the preferences backend. If the preference has never been set, this function passes on the default value returned by the preferences backend. If there is an error in processing, NULL will be returned. It is the callers responsibility to free any GVariant data returned by this function.

Definition at line 267 of file gnc-prefs.cpp.

269{
270 if (prefsbackend && prefsbackend->get_value)
271 return (prefsbackend->get_value) (group,pref_name);
272 else
273 return NULL;
274}

◆ gnc_prefs_init()

void gnc_prefs_init ( void  )

This function is called early in the load process to preload a number of preferences from the settings backend.

Definition at line 82 of file gnc-prefs-utils.c.

83{
85
86 /* Initialize the core preferences by reading their values from the loaded backend.
87 * Note: if no backend was loaded, these functions will return sane default values.
88 */
89 file_retain_changed_cb (NULL, NULL, NULL);
90 file_retain_type_changed_cb (NULL, NULL, NULL);
91 file_compression_changed_cb (NULL, NULL, NULL);
92
93 /* Check for invalid retain_type (days)/retain_days (0) combo.
94 * This can happen either because a user changed the preferences
95 * manually outside of GnuCash, or because the user upgraded from
96 * gnucash version 2.3.15 or older. Back then, 0 retain_days meant
97 * "keep forever". From 2.3.15 on this is controlled via a multiple
98 * choice ("retain_type").
99 * So if we find a 0 retain_days value with a "days" retain_type,
100 * we will silently and conservatively interpret is as meaning
101 * retain forever ("forever" retain_type).
102 */
103 if ( (gnc_prefs_get_file_retention_policy () == XML_RETAIN_DAYS) &&
104 (gnc_prefs_get_file_retention_days () == 0 ) )
105 {
106 gnc_prefs_set_file_retention_policy (XML_RETAIN_ALL);
107 gnc_prefs_set_file_retention_days (30);
108 gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_FOREVER, TRUE);
109 gnc_prefs_set_float (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_DAYS, 30);
110 PWARN("retain 0 days policy was set, but this is probably not what the user wanted,\n"
111 "assuming conservative policy 'forever'");
112 }
113
114 /* Add hooks to update core preferences whenever the associated preference changes */
115 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_DAYS,
116 file_retain_changed_cb, NULL);
117 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_NEVER,
118 file_retain_type_changed_cb, NULL);
119 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_DAYS,
120 file_retain_type_changed_cb, NULL);
121 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_FOREVER,
122 file_retain_type_changed_cb, NULL);
123 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_FILE_COMPRESSION,
124 file_compression_changed_cb, NULL);
125
126}
void gnc_gsettings_load_backend(void)
Configure gsettings as the backend for the gnucash preferences api.
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
gboolean gnc_prefs_set_float(const gchar *group, const gchar *pref_name, gdouble value)
Store a float value into the preferences backend.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
gboolean gnc_prefs_set_bool(const gchar *group, const gchar *pref_name, gboolean value)
Store a boolean value into the preferences backend.

◆ gnc_prefs_is_debugging_enabled()

gboolean gnc_prefs_is_debugging_enabled ( void  )

Definition at line 62 of file gnc-prefs.cpp.

63{
64 return is_debugging;
65}

◆ gnc_prefs_is_extra_enabled()

gboolean gnc_prefs_is_extra_enabled ( void  )

Definition at line 74 of file gnc-prefs.cpp.

75{
76 return extras_enabled;
77}

◆ gnc_prefs_is_set_up()

gboolean gnc_prefs_is_set_up ( void  )

Test if preferences backend is set up.

Definition at line 374 of file gnc-prefs.cpp.

375{
376 return (prefsbackend !=NULL);
377}

◆ gnc_prefs_register_cb()

gulong gnc_prefs_register_cb ( const char *  group,
const gchar *  pref_name,
gpointer  func,
gpointer  user_data 
)

Register a callback that gets triggered when the given preference changes.

Any time the preference's value changes, the routine will be invoked and will be passed both the changed preference and the user data passed to this function.

Parameters
groupThis string contains the group name of the preference to watch.
preferenceThis string contains the name of the preference to watch.
funcThis is a pointer to the function to call when the preference changes.
user_dataThis pointer will be passed to the callback function.
Returns
This function returns the handler id for the registered callback.

Definition at line 127 of file gnc-prefs.cpp.

131{
132 if (prefsbackend && prefsbackend->register_cb)
133 return (prefsbackend->register_cb) (group, pref_name, func, user_data);
134 else
135 {
136 g_warning ("no preferences backend loaded, or the backend doesn't define register_cb, returning 0");
137 return 0;
138 }
139}

◆ gnc_prefs_register_group_cb()

guint gnc_prefs_register_group_cb ( const gchar *  group,
gpointer  func,
gpointer  user_data 
)

Register a callback for when any preference in the settings group is changed.

Any time the value of a preference in this group changes, the routine will be invoked and will be passed the specified user data.

Parameters
groupThis string contains the name of the group that is being watched.
funcThis is a pointer to the function to call when a preference changes.
user_dataThis pointer will be passed to the callback function.

Definition at line 160 of file gnc-prefs.cpp.

163{
164 if (prefsbackend && prefsbackend->register_group_cb)
165 return (prefsbackend->register_group_cb) (group, func, user_data);
166 else
167 return 0;
168}

◆ gnc_prefs_remove_cb_by_func()

void gnc_prefs_remove_cb_by_func ( const gchar *  group,
const gchar *  pref_name,
gpointer  func,
gpointer  user_data 
)

Remove a function that was registered for a callback when the given preference changed.

Both the func and user_data arguments are used to match up the callback to remove. If no matching func and user_data are found to be registered for the given preference, nothing will happen.

Parameters
groupThis string contains the group name of the preference that is being watched.
preferenceThis string contains the name of the preference being watched.
funcThis is a pointer to the function that was registered earlier.
user_dataThis pointer was passed to the callback function when it was registered.

Definition at line 142 of file gnc-prefs.cpp.

146{
147 if (prefsbackend && prefsbackend->remove_cb_by_func)
148 (prefsbackend->remove_cb_by_func) (group, pref_name, func, user_data);
149}

◆ gnc_prefs_remove_cb_by_id()

void gnc_prefs_remove_cb_by_id ( const gchar *  group,
guint  id 
)

Remove a function that was registered for a callback when a specific preference in the settings group changed.

The handler id that was generated when the callback was registered is use to find the callback to remove. If no handler id is found nothing will happen.

Parameters
groupThis string contains the group name of the preference that is being watched.
idThe handler id of the callback to be removed.

Definition at line 152 of file gnc-prefs.cpp.

154{
155 if (prefsbackend && prefsbackend->remove_cb_by_id)
156 (prefsbackend->remove_cb_by_id) (group, id);
157}

◆ gnc_prefs_remove_group_cb_by_func()

void gnc_prefs_remove_group_cb_by_func ( const gchar *  group,
gpointer  func,
gpointer  user_data 
)

Remove a function that was registered for a callback when any preference in the given settings group changed.

Both the func and user_data arguments are used to match up the callback to remove. If no matching func and user_data are found to be registered for the given preference, nothing will happen.

Parameters
groupThis string contains the name of the group that is being watched.
funcThis is a pointer to the function that was registered earlier.
user_dataThis pointer was passed to the callback function when it was registered.
Note
there is no gnc_settings_remove_any_cb_by_id. Use gnc_settings_remove_cb_by_id instead if you want to remove a callback set with gnc_settings_register_any_cb by its handler id.

Definition at line 171 of file gnc-prefs.cpp.

174{
175 if (prefsbackend && prefsbackend->remove_group_cb_by_func)
176 (prefsbackend->remove_group_cb_by_func) (group, func, user_data);
177}

◆ gnc_prefs_remove_registered()

void gnc_prefs_remove_registered ( void  )

This function is called to remove the registered preference call backs setup in this file.

Definition at line 129 of file gnc-prefs-utils.c.

130{
131 // remove the registered pref call backs above
132 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_DAYS,
133 file_retain_changed_cb, NULL);
134 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_NEVER,
135 file_retain_type_changed_cb, NULL);
136 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_DAYS,
137 file_retain_type_changed_cb, NULL);
138 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_RETAIN_TYPE_FOREVER,
139 file_retain_type_changed_cb, NULL);
140 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_FILE_COMPRESSION,
141 file_compression_changed_cb, NULL);
143}
void gnc_gsettings_shutdown(void)
Free the GSettings resources.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.

◆ gnc_prefs_reset()

void gnc_prefs_reset ( const gchar *  group,
const gchar *  pref_name 
)

Reset a preference to its default value in the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.

Definition at line 361 of file gnc-prefs.cpp.

363{
364 if (prefsbackend && prefsbackend->reset)
365 (prefsbackend->reset) (group, pref_name);
366}

◆ gnc_prefs_reset_group()

void gnc_prefs_reset_group ( const gchar *  group)

Reset all preferences in a group to their default values in the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs

Definition at line 368 of file gnc-prefs.cpp.

369{
370 if (prefsbackend && prefsbackend->reset_group)
371 (prefsbackend->reset_group) (group);
372}

◆ gnc_prefs_set_bool()

gboolean gnc_prefs_set_bool ( const gchar *  group,
const gchar *  pref_name,
gboolean  value 
)

Store a boolean value into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe boolean value to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 277 of file gnc-prefs.cpp.

280{
281 if (prefsbackend && prefsbackend->set_bool)
282 return (prefsbackend->set_bool) (group, pref_name, value);
283 else
284 return FALSE;
285}

◆ gnc_prefs_set_coords()

gboolean gnc_prefs_set_coords ( const gchar *  group,
const gchar *  pref_name,
gdouble  x,
gdouble  y 
)

Store coordinates into the preferences backend.

Coordinates consist of a pair of floating point values (x and y).

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
xThe x coordinate to be stored.
yThe y coordinate to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 341 of file gnc-prefs.cpp.

344{
345 GVariant *var = g_variant_new ("(dd)",x, y);
346 return gnc_prefs_set_value (group, pref_name, var);
347}
gboolean gnc_prefs_set_value(const gchar *group, const gchar *pref_name, GVariant *value)
Store an arbitrary combination of values into the preferences backend.

◆ gnc_prefs_set_debugging()

void gnc_prefs_set_debugging ( gboolean  d)

Definition at line 68 of file gnc-prefs.cpp.

69{
70 is_debugging = d;
71}

◆ gnc_prefs_set_enum()

gboolean gnc_prefs_set_enum ( const gchar *  group,
const gchar *  pref_name,
gint  value 
)

Store an enum value into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe enum number to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 330 of file gnc-prefs.cpp.

333{
334 if (prefsbackend && prefsbackend->set_enum)
335 return (prefsbackend->set_enum) (group, pref_name, value);
336 else
337 return FALSE;
338}

◆ gnc_prefs_set_extra()

void gnc_prefs_set_extra ( gboolean  enabled)

Definition at line 80 of file gnc-prefs.cpp.

81{
82 extras_enabled = enabled;
83}

◆ gnc_prefs_set_file_retention_days()

void gnc_prefs_set_file_retention_days ( gint  days)

Definition at line 116 of file gnc-prefs.cpp.

117{
118 file_retention_days = days;
119}

◆ gnc_prefs_set_file_retention_policy()

void gnc_prefs_set_file_retention_policy ( gint  policy)

Definition at line 104 of file gnc-prefs.cpp.

105{
106 file_retention_policy = policy;
107}

◆ gnc_prefs_set_file_save_compressed()

void gnc_prefs_set_file_save_compressed ( gboolean  compressed)

Definition at line 92 of file gnc-prefs.cpp.

93{
94 use_compression = compressed;
95}

◆ gnc_prefs_set_float()

gboolean gnc_prefs_set_float ( const gchar *  group,
const gchar *  pref_name,
gdouble  value 
)

Store a float value into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe floating point number to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 308 of file gnc-prefs.cpp.

311{
312 if (prefsbackend && prefsbackend->set_float)
313 return (prefsbackend->set_float) (group, pref_name, value);
314 else
315 return FALSE;
316}

◆ gnc_prefs_set_int()

gboolean gnc_prefs_set_int ( const gchar *  group,
const gchar *  pref_name,
gint  value 
)

Store an integer value into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe integer number to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 288 of file gnc-prefs.cpp.

291{
292 if (prefsbackend && prefsbackend->set_int)
293 return (prefsbackend->set_int) (group, pref_name, value);
294 else
295 return FALSE;
296}

◆ gnc_prefs_set_int64()

gboolean gnc_prefs_set_int64 ( const gchar *  group,
const gchar *  pref_name,
gint64  value 
)

Store a 64 bit integer value into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe 64 bit integer number to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 299 of file gnc-prefs.cpp.

302{
303 GVariant *var = g_variant_new ("x",value);
304 return gnc_prefs_set_value (group, pref_name, var);
305}

◆ gnc_prefs_set_namespace_regexp()

void gnc_prefs_set_namespace_regexp ( const gchar *  str)

Definition at line 55 of file gnc-prefs.cpp.

56{
57 if (str)
58 namespace_regexp = str;
59}

◆ gnc_prefs_set_reg_auto_raise_lists_id()

void gnc_prefs_set_reg_auto_raise_lists_id ( gulong  id)

Definition at line 396 of file gnc-prefs.cpp.

397{
398 reg_auto_raise_lists_id = id;
399}

◆ gnc_prefs_set_reg_negative_color_pref_id()

void gnc_prefs_set_reg_negative_color_pref_id ( gulong  id)

Definition at line 406 of file gnc-prefs.cpp.

407{
408 reg_negative_color_pref_id = id;
409}

◆ gnc_prefs_set_string()

gboolean gnc_prefs_set_string ( const gchar *  group,
const gchar *  pref_name,
const gchar *  value 
)

Store a string into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe string to be stored. the preferences backend will make a copy of this string, so it is the callers responsibility to free the space used by this string (if necessary).
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 319 of file gnc-prefs.cpp.

322{
323 if (prefsbackend && prefsbackend->set_string)
324 return (prefsbackend->set_string) (group, pref_name, value);
325 else
326 return FALSE;
327}

◆ gnc_prefs_set_value()

gboolean gnc_prefs_set_value ( const gchar *  group,
const gchar *  pref_name,
GVariant *  value 
)

Store an arbitrary combination of values into the preferences backend.

Parameters
groupThis string specifies the group to which the preference belongs
preferenceThis string is the name of the particular preference within the named group of the preferences backend.
valueThe combination of values encapsulated in a GVariant to be stored.
Returns
This function returns true if the value was set successfully on the preference or false if not.

Definition at line 350 of file gnc-prefs.cpp.

353{
354 if (prefsbackend && prefsbackend->set_value)
355 return (prefsbackend->set_value) (group, pref_name, value);
356 else
357 return FALSE;
358}

◆ gnc_prefs_unblock_all()

void gnc_prefs_unblock_all ( void  )

Unblock all preferences callbacks.

Definition at line 385 of file gnc-prefs.cpp.

386{
387 if (prefsbackend && prefsbackend->unblock_all)
388 (prefsbackend->unblock_all) ();
389}