GnuCash  5.6-150-g038405b370+
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

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_shutdown (void)
 Free the GSettings resources.
 
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, const gchar *value, 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,
const gchar *  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
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.
valueThis string is the enum value of the particular setting.
objectThe object to be bound.
propertyThe property of the object to bind to.

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

314 {
315  auto gs_obj = gnc_gsettings_get_settings_obj (schema);
316  g_return_if_fail (G_IS_SETTINGS (gs_obj));
317 
318  if (gnc_gsettings_is_valid_key (gs_obj, key))
319  {
320  if (value)
321  {
322  g_settings_bind_with_mapping (gs_obj, key, object, property,
323  G_SETTINGS_BIND_DEFAULT,
324  gnc_gsettings_enum_bool_mapping_get,
325  gnc_gsettings_enum_bool_mapping_set,
326  g_strdup (value), g_free);
327  }
328  else
329  {
330  g_settings_bind (gs_obj, key, object, property, G_SETTINGS_BIND_DEFAULT);
331  }
332  }
333  else
334  {
335  PERR ("Invalid key %s for schema %s", key, schema);
336  }
337 }
#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 395 of file gnc-gsettings.cpp.

396 {
397  return gnc_gsettings_get (schema, key, g_settings_get_boolean,
398  static_cast<gboolean>(false));
399 }

◆ 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 421 of file gnc-gsettings.cpp.

422 {
423  return gnc_gsettings_get (schema, key, g_settings_get_enum, 0);
424 }

◆ 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 408 of file gnc-gsettings.cpp.

409 {
410  return gnc_gsettings_get (schema, key, g_settings_get_double, 0.0);
411 }

◆ 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 402 of file gnc-gsettings.cpp.

403 {
404  return gnc_gsettings_get (schema, key, g_settings_get_int, 0);
405 }

◆ 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 147 of file gnc-gsettings.cpp.

148 {
149  return GSET_SCHEMA_PREFIX;
150 }

◆ 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 414 of file gnc-gsettings.cpp.

415 {
416  return gnc_gsettings_get (schema, key, g_settings_get_string,
417  static_cast<gchar *> (nullptr));
418 }

◆ 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 427 of file gnc-gsettings.cpp.

428 {
429  return gnc_gsettings_get (schema, key, g_settings_get_value,
430  static_cast<GVariant *> (nullptr));
431 }

◆ 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 265 of file gnc-gsettings.cpp.

268 {
269  return gnc_gsettings_register_cb (schema, nullptr, func, user_data);
270 }
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 274 of file gnc-gsettings.cpp.

277 {
278  gnc_gsettings_remove_cb_by_func (schema, nullptr, func, user_data);
279 }
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 203 of file gnc-gsettings.cpp.

205 {
206  ENTER ();
207  g_return_if_fail (func);
208 
209  auto gs_obj = schema_to_gsettings (schema, false);
210 
211  if (!G_IS_SETTINGS (gs_obj))
212  {
213  LEAVE ("No valid GSettings object retrieved from hash table");
214  return;
215  }
216 
217  auto match_type = static_cast<GSignalMatchType> (G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA);
218  auto changed_signal = g_signal_lookup ("changed", G_TYPE_SETTINGS); /* signal_id */
219  auto quark = g_quark_from_string (key); /* signal_detail */
220 
221  auto matched = 0;
222  guint handler_id = 0;
223  do
224  {
225  handler_id = g_signal_handler_find (gs_obj, match_type,
226  changed_signal, quark, nullptr,
227  func, user_data);
228  if (handler_id)
229  {
230  matched ++;
231  gnc_gsettings_remove_cb_by_id_internal (gs_obj, handler_id);
232 
233  // Previous function will invalidate object if there is only one handler
234  if (!G_IS_SETTINGS (gs_obj))
235  handler_id = 0;
236  }
237  } while (handler_id);
238 
239  LEAVE ("Schema: %s, key: %s - removed %d handlers for 'changed' signal",
240  schema, key, matched);
241 }
#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_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 245 of file gnc-gsettings.cpp.

246 {
247  ENTER ();
248 
249  auto gs_obj = schema_to_gsettings (schema, false);
250 
251  if (!G_IS_SETTINGS (gs_obj))
252  {
253  LEAVE ("No valid GSettings object retrieved from hash table");
254  return;
255  }
256 
257  gnc_gsettings_remove_cb_by_id_internal (gs_obj, handlerid);
258 
259  LEAVE ("Schema: %p, handlerid: %d - removed for handler",
260  gs_obj, handlerid);
261 }
#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 499 of file gnc-gsettings.cpp.

501 {
502  auto gs_obj = gnc_gsettings_get_settings_obj (schema);
503  g_return_if_fail (G_IS_SETTINGS (gs_obj));
504 
505  if (gnc_gsettings_is_valid_key (gs_obj, key))
506  g_settings_reset (gs_obj, key);
507  else
508  PERR ("Invalid key %s for schema %s", key, schema);
509 
510  g_object_unref (gs_obj);
511 }
#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 514 of file gnc-gsettings.cpp.

515 {
516  auto gs_obj = gnc_gsettings_get_settings_obj (schema_str);
517 
518  if (!gs_obj)
519  return;
520 
521  GSettingsSchema *schema;
522  g_object_get (gs_obj, "settings-schema", &schema, nullptr);
523  if (!schema)
524  {
525  g_object_unref (gs_obj);
526  return;
527  }
528 
529  auto keys = g_settings_schema_list_keys (schema);
530  if (keys)
531  {
532  auto fkeys = keys;
533  for (auto key = *fkeys; key; key = *++fkeys)
534  gnc_gsettings_reset (schema_str, key);
535  }
536 
537  g_object_unref (gs_obj);
538  g_settings_schema_unref (schema);
539  g_strfreev (keys);
540 }
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 463 of file gnc-gsettings.cpp.

464 {
465  return gnc_gsettings_set (schema, key, value, g_settings_set_boolean);
466 }

◆ 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 487 of file gnc-gsettings.cpp.

488 {
489  return gnc_gsettings_set (schema, key, value, g_settings_set_enum);
490 }

◆ 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 475 of file gnc-gsettings.cpp.

476 {
477  return gnc_gsettings_set (schema, key, value, g_settings_set_double);
478 }

◆ 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 469 of file gnc-gsettings.cpp.

470 {
471  return gnc_gsettings_set (schema, key, value, g_settings_set_int);
472 }

◆ 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 481 of file gnc-gsettings.cpp.

482 {
483  return gnc_gsettings_set (schema, key, value, g_settings_set_string);
484 }

◆ 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 493 of file gnc-gsettings.cpp.

494 {
495  return gnc_gsettings_set (schema, key, value, g_settings_set_value);
496 }

◆ 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 766 of file gnc-gsettings.cpp.

767 {
768  /* This routine will conditionally execute conversion rules from
769  * prefs_transformations.xml to adapt the user's existing preferences to
770  * the current preferences schema. The rules in this file are versioned and
771  * only rules still relevant to the user's existing preferences and for
772  * this version of GnuCash will be executed.
773  *
774  * Starting with GnuCash 4.7 the code expects all preferences to be stored
775  * under prefix org.gnucash.GnuCash instead of org.gnucash, including our
776  * GNC_PREF_VERSION setting.
777  * As the logic to determine whether or not settings conversions are needed
778  * depends on this preference, we have to test for its value in two
779  * locations:
780  * - if GNC_PREF_VERSION is not set under old nor new prefix
781  * => GnuCash has never run before so no conversion run necessary
782  * - if GNC_PREF_VERSION is set under old prefix and not new prefix
783  * => user's preferences weren't moved yet from old to new prefix. Use old
784  * prefix GNC_PREF_VERSION to determine which conversions may be needed
785  * - if GNC_PREF_VERSION is set under both prefixes
786  * => ignore old prefix and use new prefix GNC_PREF_VERSION to determine
787  * which conversions may be needed.
788  * Sometime in the future (GnuCash 6.0) the old prefix will be fully removed
789  * and the test will be simplified to only check in the new prefix.
790  */
791  ENTER("Start of settings transform routine.");
792 
793  auto ogG_maj_min = gnc_gsettings_get_user_value (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
794  auto og_maj_min = gnc_gsettings_get_user_value (GSET_SCHEMA_OLD_PREFIX "." GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
795 
796  auto cur_maj_min = PROJECT_VERSION_MAJOR * 1000 + PROJECT_VERSION_MINOR;
797 
798  if (!ogG_maj_min && !og_maj_min) // new install
799  {
800  gnc_gsettings_set_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION, cur_maj_min);
801  LEAVE ("Setting Previous compatibility level to current version: %i", cur_maj_min);
802  return;
803  }
804 
805  auto old_maj_min = 0;
806  if (!ogG_maj_min) // old preference location
807  old_maj_min = gnc_gsettings_get_int (GSET_SCHEMA_OLD_PREFIX "." GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
808  else // new preference location
809  {
810  g_variant_unref (ogG_maj_min);
811  old_maj_min = gnc_gsettings_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
812  }
813  if (og_maj_min)
814  g_variant_unref (og_maj_min);
815 
816  PINFO ("Previous setting compatibility level: %i, Current version: %i", old_maj_min, cur_maj_min);
817 
818  transform_settings (old_maj_min, cur_maj_min);
819 
820  /* Only write current version if it's more recent than what was set */
821  if (cur_maj_min > old_maj_min)
822  gnc_gsettings_set_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION, cur_maj_min);
823 
824  LEAVE("");
825 }
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