r23219 - gnucash/trunk/src/app-utils - GSettings: add functions to get/set most common data types
Geert Janssens
gjanssens at code.gnucash.org
Mon Oct 7 10:05:02 EDT 2013
Author: gjanssens
Date: 2013-10-07 10:05:02 -0400 (Mon, 07 Oct 2013)
New Revision: 23219
Trac: http://svn.gnucash.org/trac/changeset/23219
Modified:
gnucash/trunk/src/app-utils/gnc-gsettings.c
gnucash/trunk/src/app-utils/gnc-gsettings.h
Log:
GSettings: add functions to get/set most common data types
These are
- integers
- floating point numbers
- strings
- enums
- arbitary combinations of values in a GVariant (this will
be used to replace the current GConf list getters/setters)
Modified: gnucash/trunk/src/app-utils/gnc-gsettings.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-gsettings.c 2013-10-07 14:04:50 UTC (rev 23218)
+++ gnucash/trunk/src/app-utils/gnc-gsettings.c 2013-10-07 14:05:02 UTC (rev 23219)
@@ -220,3 +220,230 @@
{
gnc_gsettings_remove_cb_by_func (schema, NULL, func, user_data);
}
+
+
+/************************************************************/
+/* Getters/Setters */
+/************************************************************/
+
+gboolean
+gnc_gsettings_get_bool (const gchar *schema,
+ const gchar *key)
+{
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ return g_settings_get_boolean (schema_ptr, key);
+ else
+ {
+ PERR ("Invalid key %s for schema %s", key, schema);
+ return FALSE;
+ }
+}
+
+gboolean
+gnc_gsettings_set_bool (const gchar *schema,
+ const gchar *key,
+ gboolean value)
+{
+ gboolean result = FALSE;
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ {
+ result = g_settings_set_boolean (schema_ptr, key, value);
+ if (!result)
+ PERR ("Unable to set value for key %s in schema %s", key, schema);
+ }
+ else
+ PERR ("Invalid key %s for schema %s", key, schema);
+
+ return result;
+}
+
+gint
+gnc_gsettings_get_int (const gchar *schema,
+ const gchar *key)
+{
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), 0);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ return g_settings_get_int (schema_ptr, key);
+ else
+ {
+ PERR ("Invalid key %s for schema %s", key, schema);
+ return 0;
+ }
+}
+
+gboolean
+gnc_gsettings_set_int (const gchar *schema,
+ const gchar *key,
+ gint value)
+{
+ gboolean result = FALSE;
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ {
+ result = g_settings_set_int (schema_ptr, key, value);
+ if (!result)
+ PERR ("Unable to set value for key %s in schema %s", key, schema);
+ }
+ else
+ PERR ("Invalid key %s for schema %s", key, schema);
+
+ return result;
+}
+
+gdouble
+gnc_gsettings_get_float (const gchar *schema,
+ const gchar *key)
+{
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), 0);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ return g_settings_get_double (schema_ptr, key);
+ else
+ {
+ PERR ("Invalid key %s for schema %s", key, schema);
+ return 0;
+ }
+}
+
+gboolean
+gnc_gsettings_set_float (const gchar *schema,
+ const gchar *key,
+ gdouble value)
+{
+ gboolean result = FALSE;
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ {
+ result = g_settings_set_double (schema_ptr, key, value);
+ if (!result)
+ PERR ("Unable to set value for key %s in schema %s", key, schema);
+ }
+ else
+ PERR ("Invalid key %s for schema %s", key, schema);
+
+ return result;
+}
+
+gchar *
+gnc_gsettings_get_string (const gchar *schema,
+ const gchar *key)
+{
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), NULL);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ return g_settings_get_string (schema_ptr, key);
+ else
+ {
+ PERR ("Invalid key %s for schema %s", key, schema);
+ return NULL;
+ }
+}
+
+gboolean
+gnc_gsettings_set_string (const gchar *schema,
+ const gchar *key,
+ const gchar *value)
+{
+ gboolean result = FALSE;
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ {
+ result = g_settings_set_string (schema_ptr, key, value);
+ if (!result)
+ PERR ("Unable to set value for key %s in schema %s", key, schema);
+ }
+ else
+ PERR ("Invalid key %s for schema %s", key, schema);
+
+ return result;
+}
+
+gint
+gnc_gsettings_get_enum (const gchar *schema,
+ const gchar *key)
+{
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), 0);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ return g_settings_get_enum (schema_ptr, key);
+ else
+ {
+ PERR ("Invalid key %s for schema %s", key, schema);
+ return 0;
+ }
+}
+
+gboolean
+gnc_gsettings_set_enum (const gchar *schema,
+ const gchar *key,
+ gint value)
+{
+ gboolean result = FALSE;
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ {
+ result = g_settings_set_enum (schema_ptr, key, value);
+ if (!result)
+ PERR ("Unable to set value for key %s in schema %s", key, schema);
+ }
+ else
+ PERR ("Invalid key %s for schema %s", key, schema);
+
+ return result;
+}
+
+GVariant *
+gnc_gsettings_get_value (const gchar *schema,
+ const gchar *key)
+{
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), NULL);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ return g_settings_get_value (schema_ptr, key);
+ else
+ {
+ PERR ("Invalid key %s for schema %s", key, schema);
+ return NULL;
+ }
+}
+
+gboolean
+gnc_gsettings_set_value (const gchar *schema,
+ const gchar *key,
+ GVariant *value)
+{
+ gboolean result = FALSE;
+ GSettings *schema_ptr = gnc_gsettings_get_schema_ptr (schema);
+ g_return_val_if_fail (G_IS_SETTINGS (schema_ptr), FALSE);
+
+ if (gnc_gsettings_is_valid_key (schema_ptr, key))
+ {
+ result = g_settings_set_value (schema_ptr, key, value);
+ if (!result)
+ PERR ("Unable to set value for key %s in schema %s", key, schema);
+ }
+ else
+ PERR ("Invalid key %s for schema %s", key, schema);
+
+ return result;
+}
Modified: gnucash/trunk/src/app-utils/gnc-gsettings.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-gsettings.h 2013-10-07 14:04:50 UTC (rev 23218)
+++ gnucash/trunk/src/app-utils/gnc-gsettings.h 2013-10-07 14:05:02 UTC (rev 23219)
@@ -220,9 +220,336 @@
GCallback func,
gpointer user_data);
+
+/** @name GSettings Get Functions
+ @{
+*/
+
+/** 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @return 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.
+ */
+gboolean gnc_gsettings_get_bool (const gchar *schema,
+ /*@ null @*/ 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @return 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.
+ */
+gint gnc_gsettings_get_int (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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @return 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.
+ */
+gdouble gnc_gsettings_get_float (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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @return 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.
+ */
+gchar *gnc_gsettings_get_string (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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @return 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.
+ */
+gint gnc_gsettings_get_enum (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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @return 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.
+ */
+GVariant *gnc_gsettings_get_value (const gchar *schema,
+ const gchar *key);
+
/** @} */
+/** @name GSettings Set/Unset Functions
+ @{
+*/
+
+/** 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @param value The boolean value to be stored.
+ *
+ * @return This function returns true if the value was set successfully
+ * on the key or false if not.
+ */
+gboolean gnc_gsettings_set_bool (const gchar *schema,
+ const gchar *key,
+ gboolean 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @param value The integer number to be stored.
+ *
+ * @return This function returns true if the value was set successfully
+ * on the key or false if not.
+ */
+gboolean gnc_gsettings_set_int (const gchar *schema,
+ const gchar *key,
+ gint 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @param value The floating point number to be stored.
+ *
+ * @return This function returns true if the value was set successfully
+ * on the key or false if not.
+ */
+gboolean gnc_gsettings_set_float (const gchar *schema,
+ const gchar *key,
+ gdouble 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @param value The 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).
+ *
+ * @return This function returns true if the value was set successfully
+ * on the key or false if not.
+ */
+gboolean gnc_gsettings_set_string (const gchar *schema,
+ const gchar *key,
+ const gchar *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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @param value The enum number to be stored.
+ *
+ * @return This function returns true if the value was set successfully
+ * on the key or false if not.
+ */
+gboolean gnc_gsettings_set_enum (const gchar *schema,
+ const gchar *key,
+ gint 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.
+ *
+ * @param schema This 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.
+ *
+ * @param key This string is the name of the particular key within
+ * the named schema of gsettings.
+ *
+ * @param value The combination of values encapsulated in a GVariant
+ * to be stored.
+ *
+ * @return This function returns true if the value was set successfully
+ * on the key or false if not.
+ */
+gboolean gnc_gsettings_set_value (const gchar *schema,
+ const gchar *key,
+ GVariant *value);
+
+/** @} */
+
+
#endif /* GNC_GSETTINGS_H */
/** @} */
/** @} */
More information about the gnucash-changes
mailing list