]> Pileus Git - grits/blobdiff - src/gis-prefs.c
Fix misc bugs and bump version to 0.3
[grits] / src / gis-prefs.c
index abae1a2a1c6f97d5d83d2fabc33a5e1e62022fc4..d7d7d6d7e96a4dbe11e5aea7f1f83ab370292e8d 100644 (file)
@@ -1,62 +1,62 @@
 /*
  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
- * 
+ *
  * 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 <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
+
 #include <glib.h>
 #include "gis-marshal.h"
 #include "gis-prefs.h"
 
-
 enum {
        SIG_PREF_CHANGED,
        NUM_SIGNALS,
 };
 static guint signals[NUM_SIGNALS];
 
-
 /***********
  * Methods *
  ***********/
-GisPrefs *gis_prefs_new(const gchar *prog)
+GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults)
 {
-       g_debug("GisPrefs: new - %s", prog);
+       g_debug("GisPrefs: new - %s, %s", config, defaults);
        GisPrefs *self = g_object_new(GIS_TYPE_PREFS, NULL);
-       self->key_path = g_build_filename(g_get_user_config_dir(),
-                       prog, "config.ini", NULL);
+       if (config)
+               self->key_path = g_strdup(config);
+       else
+               self->key_path = g_build_filename(g_get_user_config_dir(),
+                               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) {
-               g_debug("GisPrefs: new - Trying %s defaults", prog);
+       if (error && defaults) {
+               g_debug("GisPrefs: new - Trying %s defaults", defaults);
                g_clear_error(&error);
-               gchar *tmp = g_build_filename(DATADIR, prog, "defaults.ini", NULL);
-               g_key_file_load_from_file(self->key_file, tmp,
+               g_key_file_load_from_file(self->key_file, defaults,
                                G_KEY_FILE_KEEP_COMMENTS, &error);
-               g_free(tmp);
        }
        if (error) {
                g_debug("GisPrefs: new - Trying GIS defaults");
                g_clear_error(&error);
-               gchar *tmp = g_build_filename(DATADIR, "gis", "defaults.ini", NULL);
+               gchar *tmp = g_build_filename(PKGDATADIR, "defaults.ini", NULL);
                g_key_file_load_from_file(self->key_file, tmp,
                                G_KEY_FILE_KEEP_COMMENTS, &error);
                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);
        }
@@ -116,7 +116,7 @@ static void gis_prefs_init(GisPrefs *self)
 static GObject *gis_prefs_constructor(GType gtype, guint n_properties,
                GObjectConstructParam *properties)
 {
-       g_debug("gis_prefs: constructor");
+       g_debug("GisPrefs: constructor");
        GObjectClass *parent_class = G_OBJECT_CLASS(gis_prefs_parent_class);
        return  parent_class->constructor(gtype, n_properties, properties);
 }