From d94dbc138e08bd7fc97e925503171f54ff0836a0 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Tue, 10 Nov 2009 00:50:01 +0000 Subject: [PATCH] Add GError to prefs_get functions This allows users to check the reason for a return value. E.g. G_KEY_FILE_ERROR_NOT_FOUND --- src/gis-prefs.c | 8 +++++--- src/gis-prefs.h | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gis-prefs.c b/src/gis-prefs.c index d7d7d6d..afb427c 100644 --- a/src/gis-prefs.c +++ b/src/gis-prefs.c @@ -65,19 +65,21 @@ GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults) #define make_pref_type(name, c_type, g_type) \ c_type gis_prefs_get_##name##_v(GisPrefs *self, \ - const gchar *group, const gchar *key) \ + const gchar *group, const gchar *key, GError **_error) \ { \ GError *error = NULL; \ c_type value = g_key_file_get_##name(self->key_file, group, key, &error); \ if (error && error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) \ g_warning("GisPrefs: get_value_##name - error getting key %s: %s\n", \ key, error->message); \ + if (error && _error) \ + *_error = error; \ return value; \ } \ -c_type gis_prefs_get_##name(GisPrefs *self, const gchar *key) \ +c_type gis_prefs_get_##name(GisPrefs *self, const gchar *key, GError **error) \ { \ gchar **keys = g_strsplit(key, "/", 2); \ - c_type value = gis_prefs_get_##name##_v(self, keys[0], keys[1]); \ + c_type value = gis_prefs_get_##name##_v(self, keys[0], keys[1], error); \ g_strfreev(keys); \ return value; \ } \ diff --git a/src/gis-prefs.h b/src/gis-prefs.h index bbd720b..8a56cee 100644 --- a/src/gis-prefs.h +++ b/src/gis-prefs.h @@ -50,15 +50,15 @@ GType gis_prefs_get_type(void); /* Methods */ GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults); -gchar *gis_prefs_get_string (GisPrefs *prefs, const gchar *key); -gboolean gis_prefs_get_boolean (GisPrefs *prefs, const gchar *key); -gint gis_prefs_get_integer (GisPrefs *prefs, const gchar *key); -gdouble gis_prefs_get_double (GisPrefs *prefs, const gchar *key); +gchar *gis_prefs_get_string (GisPrefs *prefs, const gchar *key, GError **error); +gboolean gis_prefs_get_boolean (GisPrefs *prefs, const gchar *key, GError **error); +gint gis_prefs_get_integer (GisPrefs *prefs, const gchar *key, GError **error); +gdouble gis_prefs_get_double (GisPrefs *prefs, const gchar *key, GError **error); -gchar *gis_prefs_get_string_v (GisPrefs *prefs, const gchar *group, const gchar *key); -gboolean gis_prefs_get_boolean_v(GisPrefs *prefs, const gchar *group, const gchar *key); -gint gis_prefs_get_integer_v(GisPrefs *prefs, const gchar *group, const gchar *key); -gdouble gis_prefs_get_double_v (GisPrefs *prefs, const gchar *group, const gchar *key); +gchar *gis_prefs_get_string_v (GisPrefs *prefs, const gchar *group, const gchar *key, GError **error); +gboolean gis_prefs_get_boolean_v(GisPrefs *prefs, const gchar *group, const gchar *key, GError **error); +gint gis_prefs_get_integer_v(GisPrefs *prefs, const gchar *group, const gchar *key, GError **error); +gdouble gis_prefs_get_double_v (GisPrefs *prefs, const gchar *group, const gchar *key, GError **error); void gis_prefs_set_string (GisPrefs *prefs, const gchar *key, const gchar *string); void gis_prefs_set_boolean (GisPrefs *prefs, const gchar *key, gboolean value); -- 2.43.2