GnuCash  4.12-527-g05ffd3d4eb
Files | Functions
GSettings Utilities

The API in this file is designed to make it easy to use the GSettings system from within Gnucash. More...

Files

file  gnc-gsettings.h
 GSettings helper routines.
 

Functions

gchar * gnc_gsettings_normalize_schema_name (const gchar *name)
 Convert a partial schema name into a complete gsettings schema name. More...
 
const gchar * gnc_gsettings_get_prefix (void)
 Get the default gsettings schema prefix. More...
 
void gnc_gsettings_block_all (void)
 Block all prefs callbacks, used while preference dialog is loaded.
 
void gnc_gsettings_unblock_all (void)
 UnBlock all prefs callbacks, used while preference dialog is loaded.
 
void gnc_gsettings_load_backend (void)
 Configure gsettings as the backend for the gnucash preferences api.
 
void gnc_gsettings_version_upgrade (void)
 Check whether we need to adjust the user settings to a newer version. More...
 

Listening for changes

gulong gnc_gsettings_register_cb (const char *schema, const gchar *key, gpointer func, gpointer user_data)
 Register a callback for when a specific key in the settings schema is changed. More...
 
void gnc_gsettings_remove_cb_by_func (const gchar *schema, const gchar *key, gpointer func, gpointer user_data)
 Remove a function that was registered for a callback when a specific key in the settings schema changed. More...
 
void gnc_gsettings_remove_cb_by_id (const gchar *schema, guint id)
 Remove a function that was registered for a callback when a specific key in the settings schema changed. More...
 
guint gnc_gsettings_register_any_cb (const gchar *schema, gpointer func, gpointer user_data)
 Register a callback for when any key in the settings schema is changed. More...
 
void gnc_gsettings_remove_any_cb_by_func (const gchar *schema, gpointer func, gpointer user_data)
 Remove a function that was registered for a callback when any key in the given settings schema changed. More...
 
void gnc_gsettings_bind (const gchar *schema, const gchar *key, gpointer object, const gchar *property)
 Bind a setting to a g_object property. More...
 

GSettings Get Functions

gboolean gnc_gsettings_get_bool (const gchar *schema, const gchar *key)
 Get a boolean value from GSettings. More...
 
gint gnc_gsettings_get_int (const gchar *schema, const gchar *key)
 Get an integer value from GSettings. More...
 
gdouble gnc_gsettings_get_float (const gchar *schema, const gchar *key)
 Get an float value from GSettings. More...
 
gchar * gnc_gsettings_get_string (const gchar *schema, const gchar *key)
 Get a string value from GSettings. More...
 
gint gnc_gsettings_get_enum (const gchar *schema, const gchar *key)
 Get an enum value from GSettings. More...
 
GVariant * gnc_gsettings_get_value (const gchar *schema, const gchar *key)
 Get an arbitrary combination of values from GSettings. More...
 

GSettings Set/Unset Functions

gboolean gnc_gsettings_set_bool (const gchar *schema, const gchar *key, gboolean value)
 Store a boolean value into GSettings. More...
 
gboolean gnc_gsettings_set_int (const gchar *schema, const gchar *key, gint value)
 Store an integer value into GSettings. More...
 
gboolean gnc_gsettings_set_float (const gchar *schema, const gchar *key, gdouble value)
 Store a float value into GSettings. More...
 
gboolean gnc_gsettings_set_string (const gchar *schema, const gchar *key, const gchar *value)
 Store a string into GSettings. More...
 
gboolean gnc_gsettings_set_enum (const gchar *schema, const gchar *key, gint value)
 Store an enum value into GSettings. More...
 
gboolean gnc_gsettings_set_value (const gchar *schema, const gchar *key, GVariant *value)
 Store an arbitrary combination of values into GSettings. More...
 
void gnc_gsettings_reset (const gchar *schema, const gchar *key)
 Reset a key to its default value in GSettings. More...
 
void gnc_gsettings_reset_schema (const gchar *schema)
 Reset all keys in a schema to their default values in GSettings. More...
 

Detailed Description

The API in this file is designed to make it easy to use the GSettings system from within Gnucash.

GSettings is a shared key/value storage system.

The main benefits of these routines are that they

  1. maintain a list of GSettings objects (one per schema),
  2. convert gnucash internal schema names into full gsettings schema id's, and
  3. optionally take care of error checking on return values.

Note that this api should not be called directly. Instead use the gnc_gsettings_load_backend function to configure gsettings as backend for the gnucash preferences api and then use the gnc_prefs_* functions instead to work with preferences.

Function Documentation

◆ gnc_gsettings_bind()

void gnc_gsettings_bind ( const gchar *  schema,
const gchar *  key,
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
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
objectThe object to be bound.
propertyThe property of the object to bind to.

Definition at line 307 of file gnc-gsettings.cpp.

311 {
312  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
313  g_return_if_fail (G_IS_SETTINGS (settings_ptr));
314 
315  if (gnc_gsettings_is_valid_key (settings_ptr, key))
316  g_settings_bind (settings_ptr, key, object, property, G_SETTINGS_BIND_DEFAULT);
317  else
318  {
319  PERR ("Invalid key %s for schema %s", key, schema);
320  }
321 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_get_bool()

gboolean gnc_gsettings_get_bool ( const gchar *  schema,
const gchar *  key 
)

Get a boolean value from GSettings.

Retrieve a TRUE/FALSE value from GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
Returns
This function returns the TRUE or FALSE value stored at the requested key in the gsettings database. If the key has never been set, this function passes on the default value returned by GSettings as specified in the schema for this key.

Definition at line 328 of file gnc-gsettings.cpp.

330 {
331  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
332  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
333 
334  if (gnc_gsettings_is_valid_key (settings_ptr, key))
335  return g_settings_get_boolean (settings_ptr, key);
336  else
337  {
338  PERR ("Invalid key %s for schema %s", key, schema);
339  return FALSE;
340  }
341 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_get_enum()

gint gnc_gsettings_get_enum ( const gchar *  schema,
const gchar *  key 
)

Get an enum value from GSettings.

Retrieve an enum value from GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
Returns
This function returns the enum value stored at the requested key in the gsettings database. If the key has never been set, this function passes on the default value returned by GSettings as specified in the schema for this key. If there is an error in processing, this function passed on the value of zero as returned by GSettings.

Definition at line 480 of file gnc-gsettings.cpp.

482 {
483  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
484  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), 0);
485 
486  if (gnc_gsettings_is_valid_key (settings_ptr, key))
487  return g_settings_get_enum (settings_ptr, key);
488  else
489  {
490  PERR ("Invalid key %s for schema %s", key, schema);
491  return 0;
492  }
493 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_get_float()

gdouble gnc_gsettings_get_float ( const gchar *  schema,
const gchar *  key 
)

Get an float value from GSettings.

Retrieve an float value from GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
Returns
This function returns the float value stored at the requested key in the gsettings database. If the key has never been set, this function passes on the default value returned by GSettings as specified in the schema for this key. If there is an error in processing, this function passed on the value of zero as returned by GSettings.

Definition at line 404 of file gnc-gsettings.cpp.

406 {
407  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
408  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), 0);
409 
410  if (gnc_gsettings_is_valid_key (settings_ptr, key))
411  return g_settings_get_double (settings_ptr, key);
412  else
413  {
414  PERR ("Invalid key %s for schema %s", key, schema);
415  return 0;
416  }
417 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_get_int()

gint gnc_gsettings_get_int ( const gchar *  schema,
const gchar *  key 
)

Get an integer value from GSettings.

Retrieve an integer value from GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
Returns
This function returns the integer value stored at the requested key in the gsettings database. If the key has never been set, this function passes on the default value returned by GSettings as specified in the schema for this key. If there is an error in processing, this function passed on the value of zero as returned by GSettings.

Definition at line 367 of file gnc-gsettings.cpp.

369 {
370  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
371  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), 0);
372 
373  if (gnc_gsettings_is_valid_key (settings_ptr, key))
374  return g_settings_get_int (settings_ptr, key);
375  else
376  {
377  PERR ("Invalid key %s for schema %s", key, schema);
378  return 0;
379  }
380 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_get_prefix()

const gchar* gnc_gsettings_get_prefix ( void  )

Get the default gsettings schema prefix.

If none was set explicitly, this defaults to "org.gnucash.GnuCash"

Definition at line 144 of file gnc-gsettings.cpp.

145 {
146  return GSET_SCHEMA_PREFIX;
147 }

◆ gnc_gsettings_get_string()

gchar* gnc_gsettings_get_string ( const gchar *  schema,
const gchar *  key 
)

Get a string value from GSettings.

Retrieve an string value from GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
Returns
This function returns the string value stored at the requested key in the gsettings database. If the key has never been set, this function passes on the default value returned by GSettings as specified in the schema for this key. If there is an error in processing, this function passed on the NULL value as returned by GSettings. It is the callers responsibility to free any string returned by this function.

Definition at line 441 of file gnc-gsettings.cpp.

443 {
444  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
445  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), NULL);
446 
447  if (gnc_gsettings_is_valid_key (settings_ptr, key))
448  return g_settings_get_string (settings_ptr, key);
449  else
450  {
451  PERR ("Invalid key %s for schema %s", key, schema);
452  return NULL;
453  }
454 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_get_value()

GVariant* gnc_gsettings_get_value ( const gchar *  schema,
const gchar *  key 
)

Get an arbitrary combination of values from GSettings.

Retrieve an arbitrary combination of values from GSettings. This combination of values can be anything that can be encapsulated in a GVariant structure. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
Returns
This function returns the a GVariant encapsulating the combination of values stored at the requested key in the gsettings database. If the key has never been set, this function passes on the default value returned by GSettings as specified in the schema for this key. If there is an error in processing, this function passed on the NULL value as returned by GSettings. It is the callers responsibility to free any GVariant data returned by this function.

Definition at line 517 of file gnc-gsettings.cpp.

519 {
520  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
521  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), NULL);
522 
523  if (gnc_gsettings_is_valid_key (settings_ptr, key))
524  return g_settings_get_value (settings_ptr, key);
525  else
526  {
527  PERR ("Invalid key %s for schema %s", key, schema);
528  return NULL;
529  }
530 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_normalize_schema_name()

gchar* gnc_gsettings_normalize_schema_name ( const gchar *  name)

Convert a partial schema name into a complete gsettings schema name.

This function takes a partial gsettings schema name and converts it into a fully qualified gsettings schema name. It does this by prepending the standard prefix for all gnucash schemas. If the schema is already fully qualified (i.e. begins with the default schema prefix, this routine will not change it.

Parameters
nameA partial schema name. The default prefix is prepended to this name to produce a fully qualified schema name.
Returns
This function returns a string pointer to the fully qualified schema name. It is the caller's responsibility to free this string.

Definition at line 150 of file gnc-gsettings.cpp.

151 {
152  if (!name)
153  {
154  /* Need to return a newly allocated string */
155  return g_strdup(GSET_SCHEMA_PREFIX);
156  }
157  if (g_str_has_prefix (name, GSET_SCHEMA_PREFIX) ||
158  (g_str_has_prefix (name, GSET_SCHEMA_OLD_PREFIX)))
159  {
160  /* Need to return a newly allocated string */
161  return g_strdup(name);
162  }
163 
164  return g_strjoin(".", GSET_SCHEMA_PREFIX, name, NULL);
165 }

◆ gnc_gsettings_register_any_cb()

guint gnc_gsettings_register_any_cb ( const gchar *  schema,
gpointer  func,
gpointer  user_data 
)

Register a callback for when any key in the settings schema is changed.

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

Parameters
schemaThis value contains the name of the schema that is being watched.
funcThis is a pointer to the function to call when a key changes.
user_dataThis pointer will be passed to the callback function.

Definition at line 290 of file gnc-gsettings.cpp.

293 {
294  return gnc_gsettings_register_cb (schema, NULL, func, user_data);
295 }
gulong gnc_gsettings_register_cb(const char *schema, const gchar *key, gpointer func, gpointer user_data)
Register a callback for when a specific key in the settings schema is changed.

◆ gnc_gsettings_register_cb()

gulong gnc_gsettings_register_cb ( const char *  schema,
const gchar *  key,
gpointer  func,
gpointer  user_data 
)

Register a callback for when a specific key in the settings schema is changed.

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

Parameters
schemaThis value contains the schema name of the key to watch.
keyThis value contains the name of the key to watch.
funcThis is a pointer to the function to call when the key changes.
user_dataThis pointer will be passed to the callback function.
Returns
This function returns the handler id for the registered callback.

◆ gnc_gsettings_remove_any_cb_by_func()

void gnc_gsettings_remove_any_cb_by_func ( const gchar *  schema,
gpointer  func,
gpointer  user_data 
)

Remove a function that was registered for a callback when any key in the given settings schema 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 key, nothing will happen.

Parameters
schemaThis value contains the name of the schema 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 299 of file gnc-gsettings.cpp.

302 {
303  gnc_gsettings_remove_cb_by_func (schema, NULL, func, user_data);
304 }
void gnc_gsettings_remove_cb_by_func(const gchar *schema, const gchar *key, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when a specific key in the settings schema chang...

◆ gnc_gsettings_remove_cb_by_func()

void gnc_gsettings_remove_cb_by_func ( const gchar *  schema,
const gchar *  key,
gpointer  func,
gpointer  user_data 
)

Remove a function that was registered for a callback when a specific key in the settings schema 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 key, nothing will happen.

Parameters
schemaThis value contains the schema name of the key that is being watched.
keyThis value contains the name of the key 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 216 of file gnc-gsettings.cpp.

220 {
221  gint matched = 0;
222  GQuark quark = 0;
223  gulong handler_id = 0;
224 
225  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
226  g_return_if_fail (G_IS_SETTINGS (settings_ptr));
227  g_return_if_fail (func);
228 
229  ENTER ();
230 
231  if ((key) && (gnc_gsettings_is_valid_key(settings_ptr, key)))
232  quark = g_quark_from_string (key);
233 
234  handler_id = g_signal_handler_find (
235  settings_ptr,
236  static_cast<GSignalMatchType> (G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA),
237  g_signal_lookup ("changed", G_TYPE_SETTINGS), /* signal_id */
238  quark, /* signal_detail */
239  NULL, /* closure */
240  func, /* callback function */
241  user_data);
242 
243  while (handler_id)
244  {
245  matched ++;
246  gnc_gsettings_remove_cb_by_id (schema, handler_id);
247 
248  handler_id = g_signal_handler_find (
249  settings_ptr,
250  static_cast<GSignalMatchType> (G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA),
251  g_signal_lookup ("changed", G_TYPE_SETTINGS), /* signal_id */
252  quark, /* signal_detail */
253  NULL, /* closure */
254  func, /* callback function */
255  user_data);
256  }
257 
258  LEAVE ("Schema: %s, key: %s, hashtable size: %d - removed %d handlers for 'changed' signal",
259  schema, key, g_hash_table_size (registered_handlers_hash), matched);
260 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
void gnc_gsettings_remove_cb_by_id(const gchar *schema, guint handlerid)
Remove a function that was registered for a callback when a specific key in the settings schema chang...

◆ gnc_gsettings_remove_cb_by_id()

void gnc_gsettings_remove_cb_by_id ( const gchar *  schema,
guint  id 
)

Remove a function that was registered for a callback when a specific key in the settings schema 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
schemaThis value contains the schema name of the key that is being watched.
idThe handler id of the callback to be removed.

Definition at line 264 of file gnc-gsettings.cpp.

266 {
267  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
268  g_return_if_fail (G_IS_SETTINGS (settings_ptr));
269 
270  ENTER ();
271 
272  g_signal_handler_disconnect (settings_ptr, handlerid);
273 
274  // remove the handlerid from the registerered_handlers_hash
275  g_hash_table_remove (registered_handlers_hash, GINT_TO_POINTER(handlerid));
276 
277  // destroy hash table if size is 0
278  if (g_hash_table_size (registered_handlers_hash) == 0)
279  {
280  g_hash_table_destroy (registered_handlers_hash);
281  PINFO ("All registered preference callbacks removed");
282  }
283 
284  LEAVE ("Schema: %s, handlerid: %d, hashtable size: %d - removed for handler",
285  schema, handlerid, g_hash_table_size (registered_handlers_hash));
286 }
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_gsettings_reset()

void gnc_gsettings_reset ( const gchar *  schema,
const gchar *  key 
)

Reset a key to its default value in GSettings.

Reset a key to its default value in GSettings. Internally this is done by removing the value from the database. The next attempt to read this value will return the default as specified in the GSettings schema for this key. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.

Definition at line 554 of file gnc-gsettings.cpp.

556 {
557  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
558  g_return_if_fail (G_IS_SETTINGS (settings_ptr));
559 
560  if (gnc_gsettings_is_valid_key (settings_ptr, key))
561  g_settings_reset (settings_ptr, key);
562  else
563  PERR ("Invalid key %s for schema %s", key, schema);
564 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_reset_schema()

void gnc_gsettings_reset_schema ( const gchar *  schema)

Reset all keys in a schema to their default values in GSettings.

Reset a keys in schema to their default values in GSettings. Internally this is done by removing the values from the database. The next attempt to read a keys will return its default as specified in the GSettings schema for this key. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.

Definition at line 567 of file gnc-gsettings.cpp.

568 {
569  gchar **keys;
570  gint counter = 0;
571  GSettingsSchema *schema;
572  GSettings *settings = gnc_gsettings_get_settings_ptr (schema_str);
573 
574  if (!settings)
575  return;
576 
577  g_object_get (settings, "settings-schema", &schema, NULL);
578  if (!schema)
579  return;
580 
581  keys = g_settings_schema_list_keys (schema);
582  if (!keys)
583  return;
584 
585  while (keys[counter])
586  {
587  gnc_gsettings_reset (schema_str, keys[counter]);
588  counter++;
589  }
590 
591  g_strfreev (keys);
592 }
void gnc_gsettings_reset(const gchar *schema, const gchar *key)
Reset a key to its default value in GSettings.

◆ gnc_gsettings_set_bool()

gboolean gnc_gsettings_set_bool ( const gchar *  schema,
const gchar *  key,
gboolean  value 
)

Store a boolean value into GSettings.

Store a boolean value into GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
valueThe boolean value to be stored.
Returns
This function returns true if the value was set successfully on the key or false if not.

Definition at line 344 of file gnc-gsettings.cpp.

347 {
348  gboolean result = FALSE;
349  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
350  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
351 
352  ENTER("schema: %s, key: %s", schema, key);
353  if (gnc_gsettings_is_valid_key (settings_ptr, key))
354  {
355  result = g_settings_set_boolean (settings_ptr, key, value);
356  if (!result)
357  PERR ("Unable to set value for key %s in schema %s", key, schema);
358  }
359  else
360  PERR ("Invalid key %s for schema %s", key, schema);
361 
362  LEAVE("result %i", result);
363  return result;
364 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_gsettings_set_enum()

gboolean gnc_gsettings_set_enum ( const gchar *  schema,
const gchar *  key,
gint  value 
)

Store an enum value into GSettings.

Store an enum into GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
valueThe enum number to be stored.
Returns
This function returns true if the value was set successfully on the key or false if not.

Definition at line 496 of file gnc-gsettings.cpp.

499 {
500  gboolean result = FALSE;
501  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
502  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
503 
504  if (gnc_gsettings_is_valid_key (settings_ptr, key))
505  {
506  result = g_settings_set_enum (settings_ptr, key, value);
507  if (!result)
508  PERR ("Unable to set value for key %s in schema %s", key, schema);
509  }
510  else
511  PERR ("Invalid key %s for schema %s", key, schema);
512 
513  return result;
514 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_set_float()

gboolean gnc_gsettings_set_float ( const gchar *  schema,
const gchar *  key,
gdouble  value 
)

Store a float value into GSettings.

Store a float into GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
valueThe floating point number to be stored.
Returns
This function returns true if the value was set successfully on the key or false if not.

Definition at line 420 of file gnc-gsettings.cpp.

423 {
424  gboolean result = FALSE;
425  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
426  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
427 
428  if (gnc_gsettings_is_valid_key (settings_ptr, key))
429  {
430  result = g_settings_set_double (settings_ptr, key, value);
431  if (!result)
432  PERR ("Unable to set value for key %s in schema %s", key, schema);
433  }
434  else
435  PERR ("Invalid key %s for schema %s", key, schema);
436 
437  return result;
438 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_set_int()

gboolean gnc_gsettings_set_int ( const gchar *  schema,
const gchar *  key,
gint  value 
)

Store an integer value into GSettings.

Store an integer into GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
valueThe integer number to be stored.
Returns
This function returns true if the value was set successfully on the key or false if not.

Definition at line 383 of file gnc-gsettings.cpp.

386 {
387  gboolean result = FALSE;
388  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
389  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
390 
391  if (gnc_gsettings_is_valid_key (settings_ptr, key))
392  {
393  result = g_settings_set_int (settings_ptr, key, value);
394  if (!result)
395  PERR ("Unable to set value for key %s in schema %s", key, schema);
396  }
397  else
398  PERR ("Invalid key %s for schema %s", key, schema);
399 
400  return result;
401 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_set_string()

gboolean gnc_gsettings_set_string ( const gchar *  schema,
const gchar *  key,
const gchar *  value 
)

Store a string into GSettings.

Store a single string into GSettings. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
valueThe string to be stored. GSettings 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 key or false if not.

Definition at line 457 of file gnc-gsettings.cpp.

460 {
461  gboolean result = FALSE;
462  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
463  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
464 
465  ENTER("schema: %s, key: %s", schema, key);
466  if (gnc_gsettings_is_valid_key (settings_ptr, key))
467  {
468  result = g_settings_set_string (settings_ptr, key, value);
469  if (!result)
470  PERR ("Unable to set value for key %s in schema %s", key, schema);
471  }
472  else
473  PERR ("Invalid key %s for schema %s", key, schema);
474 
475  LEAVE("result %i", result);
476  return result;
477 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_gsettings_set_value()

gboolean gnc_gsettings_set_value ( const gchar *  schema,
const gchar *  key,
GVariant *  value 
)

Store an arbitrary combination of values into GSettings.

Store an arbitrary combination of values into GSettings. This combination of values can be anything that can be encapsulated in a GVariant structure. The schema name provided as argument is combined with the default gnucash schema prefix to produce a fully qualified schema name.

Parameters
schemaThis string provides a grouping of keys within the GnuCash schema of the gsettings database. It can be a simple string as in "history" for settings that are common to many areas of gnucash, or it can be a partial path name as in "dialogs.business.invoice" for setting that only apply to one specific area of the program.
keyThis string is the name of the particular key within the named schema of gsettings.
valueThe combination of values encapsulated in a GVariant to be stored.
Returns
This function returns true if the value was set successfully on the key or false if not.

Definition at line 533 of file gnc-gsettings.cpp.

536 {
537  gboolean result = FALSE;
538  GSettings *settings_ptr = gnc_gsettings_get_settings_ptr (schema);
539  g_return_val_if_fail (G_IS_SETTINGS (settings_ptr), FALSE);
540 
541  if (gnc_gsettings_is_valid_key (settings_ptr, key))
542  {
543  result = g_settings_set_value (settings_ptr, key, value);
544  if (!result)
545  PERR ("Unable to set value for key %s in schema %s", key, schema);
546  }
547  else
548  PERR ("Invalid key %s for schema %s", key, schema);
549 
550  return result;
551 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_gsettings_version_upgrade()

void gnc_gsettings_version_upgrade ( void  )

Check whether we need to adjust the user settings to a newer version.

New version of GnuCash may come with changes in the settings schema. This function will take the necessary steps to convert old settings to new (when possible).

Definition at line 790 of file gnc-gsettings.cpp.

791 {
792  /* This routine will conditionally execute conversion rules from
793  * prefs_transformations.xml to adapt the user's existing preferences to
794  * the current preferences schema. The rules in this file are versioned and
795  * only rules still relevant to the user's existing preferences and for
796  * this version of GnuCash will be executed.
797  *
798  * Starting with GnuCash 4.7 the code expects all preferences to be stored
799  * under prefix org.gnucash instead of org.gnucash.GnuCash, including our
800  * GNC_PREF_VERSION setting.
801  * As the logic to determine whether or not settings conversions are needed
802  * depends on this preference, we have to test for its value in two
803  * locations:
804  * - if GNC_PREF_VERSION is not set under old nor new prefix
805  * => GnuCash has never run before so no conversion run necessary
806  * - if GNC_PREF_VERSION is set under old prefix and not new prefix
807  * => user's preferences weren't moved yet from old to new prefix. Use old
808  * prefix GNC_PREF_VERSION to determine which conversions may be needed
809  * - if GNC_PREF_VERSION is set under both prefixes
810  * => ignore old prefix and use new prefix GNC_PREF_VERSION to determine
811  * which conversions may be needed.
812  * Sometime in the future (GnuCash 6.0) the old prefix will be fully removed
813  * and the test will be simplified to only check in the new prefix.
814  */
815  ENTER("Start of settings transform routine.");
816 
817  auto ogG_maj_min = gnc_gsettings_get_user_value (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
818  auto og_maj_min = gnc_gsettings_get_user_value (GSET_SCHEMA_OLD_PREFIX "." GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
819 
820  if (!ogG_maj_min && !og_maj_min)
821  {
822  LEAVE("");
823  return;
824  }
825 
826  auto old_maj_min = 0;
827  if (!ogG_maj_min)
828  old_maj_min = gnc_gsettings_get_int (GSET_SCHEMA_OLD_PREFIX "." GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
829  else
830  {
831  g_variant_unref (ogG_maj_min);
832  old_maj_min = gnc_gsettings_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
833  }
834  if (og_maj_min)
835  g_variant_unref (og_maj_min);
836 
837  PINFO ("Previous setting compatibility level: %i", old_maj_min);
838 
839  transform_settings (old_maj_min);
840 
841  /* Only write current version if it's more recent than what was set */
842  auto cur_maj_min = PROJECT_VERSION_MAJOR * 1000 + PROJECT_VERSION_MINOR;
843  if (cur_maj_min > old_maj_min)
844  gnc_gsettings_set_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION, cur_maj_min);
845 
846  LEAVE("");
847 }
gboolean gnc_gsettings_set_int(const gchar *schema, const gchar *key, gint value)
Store an integer value into GSettings.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
gint gnc_gsettings_get_int(const gchar *schema, const gchar *key)
Get an integer value from GSettings.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282