GnuCash  5.6-133-gc519490283+
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, 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 282 of file gnc-gsettings.cpp.

286 {
287  auto gs_obj = gnc_gsettings_get_settings_obj (schema);
288  g_return_if_fail (G_IS_SETTINGS (gs_obj));
289 
290  if (gnc_gsettings_is_valid_key (gs_obj, key))
291  g_settings_bind (gs_obj, key, object, property, G_SETTINGS_BIND_DEFAULT);
292  else
293  PERR ("Invalid key %s for schema %s", key, schema);
294 }
#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 352 of file gnc-gsettings.cpp.

353 {
354  return gnc_gsettings_get (schema, key, g_settings_get_boolean,
355  static_cast<gboolean>(false));
356 }

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

379 {
380  return gnc_gsettings_get (schema, key, g_settings_get_enum, 0);
381 }

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

366 {
367  return gnc_gsettings_get (schema, key, g_settings_get_double, 0.0);
368 }

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

360 {
361  return gnc_gsettings_get (schema, key, g_settings_get_int, 0);
362 }

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

372 {
373  return gnc_gsettings_get (schema, key, g_settings_get_string,
374  static_cast<gchar *> (nullptr));
375 }

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

385 {
386  return gnc_gsettings_get (schema, key, g_settings_get_value,
387  static_cast<GVariant *> (nullptr));
388 }

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

458 {
459  auto gs_obj = gnc_gsettings_get_settings_obj (schema);
460  g_return_if_fail (G_IS_SETTINGS (gs_obj));
461 
462  if (gnc_gsettings_is_valid_key (gs_obj, key))
463  g_settings_reset (gs_obj, key);
464  else
465  PERR ("Invalid key %s for schema %s", key, schema);
466 
467  g_object_unref (gs_obj);
468 }
#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 471 of file gnc-gsettings.cpp.

472 {
473  auto gs_obj = gnc_gsettings_get_settings_obj (schema_str);
474 
475  if (!gs_obj)
476  return;
477 
478  GSettingsSchema *schema;
479  g_object_get (gs_obj, "settings-schema", &schema, nullptr);
480  if (!schema)
481  {
482  g_object_unref (gs_obj);
483  return;
484  }
485 
486  auto keys = g_settings_schema_list_keys (schema);
487  if (keys)
488  {
489  auto fkeys = keys;
490  for (auto key = *fkeys; key; key = *++fkeys)
491  gnc_gsettings_reset (schema_str, key);
492  }
493 
494  g_object_unref (gs_obj);
495  g_settings_schema_unref (schema);
496  g_strfreev (keys);
497 }
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 420 of file gnc-gsettings.cpp.

421 {
422  return gnc_gsettings_set (schema, key, value, g_settings_set_boolean);
423 }

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

445 {
446  return gnc_gsettings_set (schema, key, value, g_settings_set_enum);
447 }

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

433 {
434  return gnc_gsettings_set (schema, key, value, g_settings_set_double);
435 }

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

427 {
428  return gnc_gsettings_set (schema, key, value, g_settings_set_int);
429 }

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

439 {
440  return gnc_gsettings_set (schema, key, value, g_settings_set_string);
441 }

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

451 {
452  return gnc_gsettings_set (schema, key, value, g_settings_set_value);
453 }

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

724 {
725  /* This routine will conditionally execute conversion rules from
726  * prefs_transformations.xml to adapt the user's existing preferences to
727  * the current preferences schema. The rules in this file are versioned and
728  * only rules still relevant to the user's existing preferences and for
729  * this version of GnuCash will be executed.
730  *
731  * Starting with GnuCash 4.7 the code expects all preferences to be stored
732  * under prefix org.gnucash.GnuCash instead of org.gnucash, including our
733  * GNC_PREF_VERSION setting.
734  * As the logic to determine whether or not settings conversions are needed
735  * depends on this preference, we have to test for its value in two
736  * locations:
737  * - if GNC_PREF_VERSION is not set under old nor new prefix
738  * => GnuCash has never run before so no conversion run necessary
739  * - if GNC_PREF_VERSION is set under old prefix and not new prefix
740  * => user's preferences weren't moved yet from old to new prefix. Use old
741  * prefix GNC_PREF_VERSION to determine which conversions may be needed
742  * - if GNC_PREF_VERSION is set under both prefixes
743  * => ignore old prefix and use new prefix GNC_PREF_VERSION to determine
744  * which conversions may be needed.
745  * Sometime in the future (GnuCash 6.0) the old prefix will be fully removed
746  * and the test will be simplified to only check in the new prefix.
747  */
748  ENTER("Start of settings transform routine.");
749 
750  auto ogG_maj_min = gnc_gsettings_get_user_value (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
751  auto og_maj_min = gnc_gsettings_get_user_value (GSET_SCHEMA_OLD_PREFIX "." GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
752 
753  auto cur_maj_min = PROJECT_VERSION_MAJOR * 1000 + PROJECT_VERSION_MINOR;
754 
755  if (!ogG_maj_min && !og_maj_min) // new install
756  {
757  gnc_gsettings_set_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION, cur_maj_min);
758  LEAVE ("Setting Previous compatibility level to current version: %i", cur_maj_min);
759  return;
760  }
761 
762  auto old_maj_min = 0;
763  if (!ogG_maj_min) // old preference location
764  old_maj_min = gnc_gsettings_get_int (GSET_SCHEMA_OLD_PREFIX "." GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
765  else // new preference location
766  {
767  g_variant_unref (ogG_maj_min);
768  old_maj_min = gnc_gsettings_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION);
769  }
770  if (og_maj_min)
771  g_variant_unref (og_maj_min);
772 
773  PINFO ("Previous setting compatibility level: %i, Current version: %i", old_maj_min, cur_maj_min);
774 
775  transform_settings (old_maj_min, cur_maj_min);
776 
777  /* Only write current version if it's more recent than what was set */
778  if (cur_maj_min > old_maj_min)
779  gnc_gsettings_set_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION, cur_maj_min);
780 
781  LEAVE("");
782 }
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