Try to load a system-wide rc file if any, before per-user rc file.
authorLaurent Monin <geeqie@norz.org>
Fri, 23 May 2008 00:20:56 +0000 (00:20 +0000)
committerLaurent Monin <geeqie@norz.org>
Fri, 23 May 2008 00:20:56 +0000 (00:20 +0000)
For now, system-wide rc file path is set to /etc/geeqie/geeqierc
(defined by GQ_SYSTEM_WIDE_DIR in main.h).
filter_parse() was modified to replace entries having the same key,
needed since it may be called more than once.

Please test heavily.

src/filefilter.c
src/main.h
src/rcfile.c

index 7974c61..66fe73b 100644 (file)
@@ -79,11 +79,11 @@ void filter_remove_entry(FilterEntry *fe)
        filter_entry_free(fe);
 }
 
-static gint filter_key_exists(const gchar *key)
+static FilterEntry *filter_get_by_key(const gchar *key)
 {
        GList *work;
 
-       if (!key) return FALSE;
+       if (!key) return NULL;
 
        work = filter_list;
        while (work)
@@ -91,10 +91,15 @@ static gint filter_key_exists(const gchar *key)
                FilterEntry *fe = work->data;
                work = work->next;
 
-               if (strcmp(fe->key, key) == 0) return TRUE;
+               if (strcmp(fe->key, key) == 0) return fe;
                }
 
-       return FALSE;
+       return NULL;
+}
+
+static gint filter_key_exists(const gchar *key)
+{
+       return (filter_get_by_key(key) == NULL ? FALSE : TRUE);
 }
 
 void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
@@ -419,7 +424,13 @@ void filter_parse(const gchar *text)
                enabled = FALSE;
                }
 
-       if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, file_class, enabled);
+       if (key && strlen(key) > 0 && ext)
+               {
+               FilterEntry *fe = filter_get_by_key(key);
+
+               if (fe != NULL) filter_remove_entry(fe);
+               filter_add(key, desc, ext, file_class, enabled);
+               }
 
        g_free(key);
        g_free(ext);
index 96aa2e6..0800302 100644 (file)
@@ -76,6 +76,8 @@
 #define GQ_RC_DIR_COLLECTIONS GQ_RC_DIR G_DIR_SEPARATOR_S "collections"
 #define GQ_RC_DIR_TRASH       GQ_RC_DIR G_DIR_SEPARATOR_S "trash"
 
+#define GQ_SYSTEM_WIDE_DIR    "/etc/" GQ_APPNAME_LC
+
 #define RC_FILE_NAME GQ_APPNAME_LC "rc"
 
 #define ZOOM_RESET_ORIGINAL 0
index 73734ea..202ee0d 100644 (file)
@@ -924,9 +924,19 @@ static gboolean load_options_from(const gchar *utf8_path, ConfOptions *options)
 
 void load_options(ConfOptions *options)
 {
+       gboolean success;
        gchar *rc_path;
 
+       if (isdir(GQ_SYSTEM_WIDE_DIR))
+               {
+               rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
+               success = load_options_from(rc_path, options);
+               DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
+               g_free(rc_path);
+               }
+       
        rc_path = g_build_filename(homedir(), GQ_RC_DIR, RC_FILE_NAME, NULL);
-       load_options_from(rc_path, options);
+       success = load_options_from(rc_path, options);
+       DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
        g_free(rc_path);
 }