GnuCash c935c2f+
Loading...
Searching...
No Matches
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.
 
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.
 

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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

GSettings Get Functions

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

GSettings Set/Unset Functions

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

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

318{
319 auto gs_obj = gnc_gsettings_get_settings_obj (schema);
320 g_return_if_fail (G_IS_SETTINGS (gs_obj));
321
322 if (gnc_gsettings_is_valid_key (gs_obj, key))
323 {
324 if (value)
325 {
326 g_settings_bind_with_mapping (gs_obj, key, object, property,
327 G_SETTINGS_BIND_DEFAULT,
328 gnc_gsettings_enum_bool_mapping_get,
329 gnc_gsettings_enum_bool_mapping_set,
330 g_strdup (value), g_free);
331 }
332 else
333 {
334 g_settings_bind (gs_obj, key, object, property, G_SETTINGS_BIND_DEFAULT);
335 }
336 }
337 else
338 {
339 PERR ("Invalid key %s for schema %s", key, schema);
340 }
341}
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ gnc_gsettings_block_all()

void gnc_gsettings_block_all ( void  )

Block all prefs callbacks, used while preference dialog is loaded.

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

361{
362 ENTER ();
363 for (const auto& it : schema_hash)
364 gs_obj_block_handlers (nullptr, it.second.get(), nullptr);
365 LEAVE();
366}
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272

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

400{
401 return gnc_gsettings_get (schema, key, g_settings_get_boolean,
402 static_cast<gboolean>(false));
403}

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

426{
427 return gnc_gsettings_get (schema, key, g_settings_get_enum, 0);
428}

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

413{
414 return gnc_gsettings_get (schema, key, g_settings_get_double, 0.0);
415}

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

407{
408 return gnc_gsettings_get (schema, key, g_settings_get_int, 0);
409}

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

152{
153 return GSET_SCHEMA_PREFIX;
154}

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

419{
420 return gnc_gsettings_get (schema, key, g_settings_get_string,
421 static_cast<gchar *> (nullptr));
422}

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

432{
433 return gnc_gsettings_get (schema, key, g_settings_get_value,
434 static_cast<GVariant *> (nullptr));
435}

◆ gnc_gsettings_load_backend()

void gnc_gsettings_load_backend ( void  )

Configure gsettings as the backend for the gnucash preferences api.

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

564{
565 ENTER("");
566
567 /* The gsettings backend only works in an installed environment.
568 * When called from the source environment (for testing purposes)
569 * simply return.
570 */
571 if (g_strcmp0 (g_getenv ("GNC_UNINSTALLED"), "1") == 0)
572 return;
573
574 g_free (prefsbackend);
575 prefsbackend = g_new0 (PrefsBackend, 1);
576
577 prefsbackend->register_cb = gnc_gsettings_register_cb;
578 prefsbackend->remove_cb_by_func = gnc_gsettings_remove_cb_by_func;
579 prefsbackend->remove_cb_by_id = gnc_gsettings_remove_cb_by_id;
580 prefsbackend->register_group_cb = gnc_gsettings_register_any_cb;
581 prefsbackend->remove_group_cb_by_func = gnc_gsettings_remove_any_cb_by_func;
582 prefsbackend->bind = gnc_gsettings_bind;
583 prefsbackend->get_bool = gnc_gsettings_get_bool;
584 prefsbackend->get_int = gnc_gsettings_get_int;
585 prefsbackend->get_float = gnc_gsettings_get_float;
586 prefsbackend->get_string = gnc_gsettings_get_string;
587 prefsbackend->get_enum = gnc_gsettings_get_enum;
588 prefsbackend->get_value = gnc_gsettings_get_value;
589 prefsbackend->set_bool = gnc_gsettings_set_bool;
590 prefsbackend->set_int = gnc_gsettings_set_int;
591 prefsbackend->set_float = gnc_gsettings_set_float;
592 prefsbackend->set_string = gnc_gsettings_set_string;
593 prefsbackend->set_enum = gnc_gsettings_set_enum;
594 prefsbackend->set_value = gnc_gsettings_set_value;
595 prefsbackend->reset = gnc_gsettings_reset;
596 prefsbackend->reset_group = gnc_gsettings_reset_schema;
597 prefsbackend->block_all = gnc_gsettings_block_all;
598 prefsbackend->unblock_all = gnc_gsettings_unblock_all;
599
600 if (qof_log_check (log_module, QOF_LOG_DEBUG))
601 gnc_settings_dump_schema_paths ();
602
603 /* Run any data model changes for the backend before it's used
604 * by anyone */
606
607 LEAVE("Prefsbackend bind = %p", prefsbackend->bind);
608}
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.
void gnc_gsettings_reset(const gchar *schema, const gchar *key)
Reset a key to its default value in GSettings.
gchar * gnc_gsettings_get_string(const gchar *schema, const gchar *key)
Get a string value from GSettings.
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...
gboolean gnc_gsettings_set_enum(const gchar *schema, const gchar *key, gint value)
Store an enum value into GSettings.
gboolean gnc_gsettings_get_bool(const gchar *schema, const gchar *key)
Get a boolean value from GSettings.
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 change...
gint gnc_gsettings_get_enum(const gchar *schema, const gchar *key)
Get an enum value from GSettings.
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...
gboolean gnc_gsettings_set_bool(const gchar *schema, const gchar *key, gboolean value)
Store a boolean value into GSettings.
gboolean gnc_gsettings_set_value(const gchar *schema, const gchar *key, GVariant *value)
Store an arbitrary combination of values into GSettings.
gint gnc_gsettings_get_int(const gchar *schema, const gchar *key)
Get an integer value from GSettings.
void gnc_gsettings_reset_schema(const gchar *schema_str)
Reset all keys in a schema to their default values in GSettings.
void gnc_gsettings_unblock_all(void)
UnBlock all prefs callbacks, used while preference dialog is loaded.
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.
GVariant * gnc_gsettings_get_value(const gchar *schema, const gchar *key)
Get an arbitrary combination of values from GSettings.
void gnc_gsettings_version_upgrade(void)
Check whether we need to adjust the user settings to a newer version.
gdouble gnc_gsettings_get_float(const gchar *schema, const gchar *key)
Get an float value from GSettings.
gboolean gnc_gsettings_set_float(const gchar *schema, const gchar *key, gdouble value)
Store a float value into GSettings.
gboolean gnc_gsettings_set_int(const gchar *schema, const gchar *key, gint value)
Store an integer value into GSettings.
gboolean gnc_gsettings_set_string(const gchar *schema, const gchar *key, const gchar *value)
Store a string into GSettings.
void gnc_gsettings_block_all(void)
Block all prefs callbacks, used while preference dialog is loaded.
gboolean qof_log_check(QofLogModule domain, QofLogLevel level)
Check to see if the given log_module is configured to log at the given log_level.
Definition qoflog.cpp:330

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

272{
273 return gnc_gsettings_register_cb (schema, nullptr, func, user_data);
274}

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

281{
282 gnc_gsettings_remove_cb_by_func (schema, nullptr, func, user_data);
283}

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

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

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

250{
251 ENTER ();
252
253 auto gs_obj = schema_to_gsettings (schema, false);
254
255 if (!G_IS_SETTINGS (gs_obj))
256 {
257 LEAVE ("No valid GSettings object retrieved from hash table");
258 return;
259 }
260
261 gnc_gsettings_remove_cb_by_id_internal (gs_obj, handlerid);
262
263 LEAVE ("Schema: %p, handlerid: %d - removed for handler",
264 gs_obj, handlerid);
265}

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

505{
506 auto gs_obj = gnc_gsettings_get_settings_obj (schema);
507 g_return_if_fail (G_IS_SETTINGS (gs_obj));
508
509 if (gnc_gsettings_is_valid_key (gs_obj, key))
510 g_settings_reset (gs_obj, key);
511 else
512 PERR ("Invalid key %s for schema %s", key, schema);
513
514 g_object_unref (gs_obj);
515}

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

519{
520 auto gs_obj = gnc_gsettings_get_settings_obj (schema_str);
521
522 if (!gs_obj)
523 return;
524
525 GSettingsSchema *schema;
526 g_object_get (gs_obj, "settings-schema", &schema, nullptr);
527 if (!schema)
528 {
529 g_object_unref (gs_obj);
530 return;
531 }
532
533 auto keys = g_settings_schema_list_keys (schema);
534 if (keys)
535 {
536 auto fkeys = keys;
537 for (auto key = *fkeys; key; key = *++fkeys)
538 gnc_gsettings_reset (schema_str, key);
539 }
540
541 g_object_unref (gs_obj);
542 g_settings_schema_unref (schema);
543 g_strfreev (keys);
544}

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

468{
469 return gnc_gsettings_set (schema, key, value, g_settings_set_boolean);
470}

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

492{
493 return gnc_gsettings_set (schema, key, value, g_settings_set_enum);
494}

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

480{
481 return gnc_gsettings_set (schema, key, value, g_settings_set_double);
482}

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

474{
475 return gnc_gsettings_set (schema, key, value, g_settings_set_int);
476}

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

486{
487 return gnc_gsettings_set (schema, key, value, g_settings_set_string);
488}

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

498{
499 return gnc_gsettings_set (schema, key, value, g_settings_set_value);
500}

◆ gnc_gsettings_shutdown()

void gnc_gsettings_shutdown ( void  )

Free the GSettings resources.

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

612{
613 schema_hash.clear();
614 g_free (prefsbackend);
615}

◆ gnc_gsettings_unblock_all()

void gnc_gsettings_unblock_all ( void  )

UnBlock all prefs callbacks, used while preference dialog is loaded.

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

370{
371 ENTER ();
372 for (const auto& it : schema_hash)
373 gs_obj_unblock_handlers (nullptr, it.second.get(), nullptr);
374 LEAVE();
375}

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

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