X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fgis-prefs.c;h=9659a6e8b143d4e7c5eb24cd2eb08963dcff10a9;hb=7b2073d0ef64ae7bdd6e2ddd31cfd0961bdf749a;hp=4a1ee0d885bf977858df7ef77a46cc21053ea014;hpb=d836e9913e3fa991c935a8e7d5064f9adb51e191;p=grits diff --git a/src/gis-prefs.c b/src/gis-prefs.c index 4a1ee0d..9659a6e 100644 --- a/src/gis-prefs.c +++ b/src/gis-prefs.c @@ -1,32 +1,32 @@ /* * Copyright (C) 2009 Andy Spencer - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include + #include #include "gis-marshal.h" #include "gis-prefs.h" - enum { SIG_PREF_CHANGED, NUM_SIGNALS, }; static guint signals[NUM_SIGNALS]; - /*********** * Methods * ***********/ @@ -38,12 +38,12 @@ GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults) self->key_path = g_strdup(config); else self->key_path = g_build_filename(g_get_user_config_dir(), - "gis", "config.ini", NULL); + PACKAGE, "config.ini", NULL); GError *error = NULL; g_key_file_load_from_file(self->key_file, self->key_path, G_KEY_FILE_KEEP_COMMENTS, &error); if (error && defaults) { - g_debug("GisPrefs: new - Trying %s defaults", defaults); + g_debug("GisPrefs: new - Trying defaults"); g_clear_error(&error); g_key_file_load_from_file(self->key_file, defaults, G_KEY_FILE_KEEP_COMMENTS, &error); @@ -57,7 +57,6 @@ GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults) g_free(tmp); } if (error) { - g_clear_error(&error); g_warning("GisPrefs: new - Unable to load key file `%s': %s", self->key_path, error->message); } @@ -66,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; \ } \ @@ -114,13 +115,6 @@ static void gis_prefs_init(GisPrefs *self) g_debug("GisPrefs: init"); self->key_file = g_key_file_new(); } -static GObject *gis_prefs_constructor(GType gtype, guint n_properties, - GObjectConstructParam *properties) -{ - g_debug("GisPrefs: constructor"); - GObjectClass *parent_class = G_OBJECT_CLASS(gis_prefs_parent_class); - return parent_class->constructor(gtype, n_properties, properties); -} static void gis_prefs_dispose(GObject *_self) { g_debug("GisPrefs: dispose"); @@ -139,18 +133,11 @@ static void gis_prefs_dispose(GObject *_self) } G_OBJECT_CLASS(gis_prefs_parent_class)->dispose(_self); } -static void gis_prefs_finalize(GObject *_self) -{ - g_debug("GisPrefs: finalize"); - G_OBJECT_CLASS(gis_prefs_parent_class)->finalize(_self); -} static void gis_prefs_class_init(GisPrefsClass *klass) { g_debug("GisPrefs: class_init"); GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->constructor = gis_prefs_constructor; gobject_class->dispose = gis_prefs_dispose; - gobject_class->finalize = gis_prefs_finalize; signals[SIG_PREF_CHANGED] = g_signal_new( "pref-changed", G_TYPE_FROM_CLASS(gobject_class),