split filelist.c to filefilter.c and filedata.c
authorVladimir Nadvornik <nadvornik@suse.cz>
Mon, 5 May 2008 19:11:12 +0000 (19:11 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Mon, 5 May 2008 19:11:12 +0000 (19:11 +0000)
42 files changed:
src/Makefile.am
src/bar_exif.c
src/bar_info.c
src/bar_sort.c
src/cache-loader.c
src/cache_maint.c
src/collect-io.c
src/collect-table.c
src/collect.c
src/dupe.c
src/editors.c
src/exif-common.c
src/exiv2.cc
src/filedata.c [moved from src/filelist.c with 63% similarity]
src/filedata.h [moved from src/filelist.h with 61% similarity]
src/filefilter.c [new file with mode: 0644]
src/filefilter.h [new file with mode: 0644]
src/image-load.c
src/image-overlay.c
src/image.c
src/img-view.c
src/info.c
src/layout.c
src/layout_image.c
src/layout_util.c
src/main.c
src/menu.c
src/pan-types.h
src/preferences.c
src/print.c
src/rcfile.c
src/search.c
src/slideshow.c
src/thumb.c
src/ui_bookmark.c
src/ui_utildlg.c
src/utilops.c
src/view_dir.c
src/view_dir_list.c
src/view_dir_tree.c
src/view_file_icon.c
src/view_file_list.h

index 652287e..174edd3 100644 (file)
@@ -104,8 +104,10 @@ geeqie_SOURCES = \
        exif-int.h      \
        exif-common.c   \
        exiv2.cc        \
-       filelist.c      \
-       filelist.h      \
+       filedata.c      \
+       filedata.h      \
+       filefilter.c    \
+       filefilter.h    \
        format_canon.c  \
        format_canon.h  \
        format_fuji.c   \
index 100d91a..86c3157 100644 (file)
@@ -17,7 +17,7 @@
 #include "exif.h"
 #include "ui_bookmark.h"
 #include "ui_misc.h"
-#include "filelist.h"
+#include "filedata.h"
 
 #include <math.h>
 
index f08a999..9e42d8c 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "cache.h"
 #include "debug.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "info.h"
 #include "secure_save.h"
 #include "utilops.h"
index d4a37ea..9376735 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "collect.h"
 #include "collect-io.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "utilops.h"
index 770955b..b01ad21 100644 (file)
@@ -14,7 +14,7 @@
 #include "cache-loader.h"
 #include "cache.h"
 
-#include "filelist.h"
+#include "filedata.h"
 #include "exif.h"
 #include "md5-util.h"
 #include "ui_fileops.h"
index dff3e41..f6bcb6d 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "cache.h"
 #include "debug.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "thumb.h"
 #include "thumb_standard.h"
 #include "ui_fileops.h"
index c61be6a..89f764f 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "collect.h"
 #include "debug.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout_util.h"
 #include "rcfile.h"
 #include "secure_save.h"
index 2f37c1e..cc4c11f 100644 (file)
@@ -21,7 +21,7 @@
 #include "dnd.h"
 #include "dupe.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "img-view.h"
 #include "info.h"
 #include "layout.h"
index f1f2ad6..35db6fb 100644 (file)
@@ -19,7 +19,7 @@
 #include "collect-table.h"
 #include "debug.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "img-view.h"
 #include "info.h"
 #include "layout.h"
index aa00784..b71dcff 100644 (file)
@@ -20,7 +20,7 @@
 #include "debug.h"
 #include "dnd.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "image-load.h"
 #include "img-view.h"
 #include "info.h"
index 3b120d2..5a90598 100644 (file)
@@ -19,7 +19,8 @@
 #include "ui_spinner.h"
 #include "ui_utildlg.h"
 
-#include "filelist.h"
+#include "filedata.h"
+#include "filefilter.h"
 
 #include <errno.h>
 
index 5e3ce3c..8697467 100644 (file)
@@ -36,7 +36,8 @@
 #include "exif.h"
 
 #include "debug.h"
-#include "filelist.h"
+#include "filedata.h"
+#include "filefilter.h"
 #include "format_raw.h"
 #include "ui_fileops.h"
 
index 8d4d3a5..f5ddc61 100644 (file)
@@ -55,7 +55,7 @@ extern "C" {
 #include "exif.h"
 
 #include "debug.h"
-#include "filelist.h"
+#include "filefilter.h"
 #include "ui_fileops.h"
 }
 
similarity index 63%
rename from src/filelist.c
rename to src/filedata.c
index f4e3988..9938b07 100644 (file)
@@ -12,8 +12,9 @@
 
 
 #include "main.h"
-#include "filelist.h"
+#include "filedata.h"
 
+#include "filefilter.h"
 #include "cache.h"
 #include "debug.h"
 #include "rcfile.h"
 #include "ui_fileops.h"
 
 
-/*
- *-----------------------------------------------------------------------------
- * file filtering
- *-----------------------------------------------------------------------------
- */
-
-static GList *filter_list = NULL;
-static GList *extension_list = NULL;
-static GList *sidecar_ext_list = NULL;
-
-static GList *file_class_extension_list[FILE_FORMAT_CLASSES];
-
 static gint sidecar_file_priority(const gchar *path);
 
 
-gint ishidden(const gchar *name)
-{
-       if (name[0] != '.') return FALSE;
-       if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE;
-       return TRUE;
-}
-
-static FilterEntry *filter_entry_new(const gchar *key, const gchar *description,
-                                    const gchar *extensions, FileFormatClass file_class, gint enabled)
-{
-       FilterEntry *fe;
-
-       fe = g_new0(FilterEntry, 1);
-       fe->key = g_strdup(key);
-       fe->description = g_strdup(description);
-       fe->extensions = g_strdup(extensions);
-       fe->enabled = enabled;
-       fe->file_class = file_class;
-
-       return fe;
-}
-
-static void filter_entry_free(FilterEntry *fe)
-{
-       if (!fe) return;
-
-       g_free(fe->key);
-       g_free(fe->description);
-       g_free(fe->extensions);
-       g_free(fe);
-}
-
-GList *filter_get_list(void)
-{
-       return filter_list;
-}
-
-void filter_remove_entry(FilterEntry *fe)
-{
-       if (!g_list_find(filter_list, fe)) return;
-
-       filter_list = g_list_remove(filter_list, fe);
-       filter_entry_free(fe);
-}
-
-static gint filter_key_exists(const gchar *key)
-{
-       GList *work;
-
-       if (!key) return FALSE;
-
-       work = filter_list;
-       while (work)
-               {
-               FilterEntry *fe = work->data;
-               work = work->next;
-
-               if (strcmp(fe->key, key) == 0) return TRUE;
-               }
-
-       return FALSE;
-}
-
-void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
-{
-       filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, file_class, enabled));
-}
-
-void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
-{
-       gchar *key;
-       gint n;
-
-       key = g_strdup("user0");
-       n = 1;
-       while (filter_key_exists(key))
-               {
-               g_free(key);
-               if (n > 999) return;
-               key = g_strdup_printf("user%d", n);
-               n++;
-               }
-
-       filter_add(key, description, extensions, file_class, enabled);
-       g_free(key);
-}
-
-static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
-{
-       GList *work;
-
-       if (!key) return;
-
-       work = filter_list;
-       while (work)
-               {
-               FilterEntry *fe = work->data;
-               work = work->next;
-               if (fe->key && strcmp(fe->key, key) == 0)
-                       {
-                       if (fe->file_class == FORMAT_CLASS_UNKNOWN)
-                               fe->file_class = file_class;    /* for compatibility */
-                       return;
-                       }
-               }
-
-       filter_add(key, description, extensions, file_class, enabled);
-}
-
-void filter_reset(void)
-{
-       GList *work;
-
-       work = filter_list;
-       while (work)
-               {
-               FilterEntry *fe = work->data;
-               work = work->next;
-               filter_entry_free(fe);
-               }
-
-       g_list_free(filter_list);
-       filter_list = NULL;
-}
-
-void filter_add_defaults(void)
-{
-       GSList *list, *work;
-
-       list = gdk_pixbuf_get_formats();
-       work = list;
-       while (work)
-               {
-               GdkPixbufFormat *format;
-               gchar *name;
-               gchar *desc;
-               gchar **extensions;
-               GString *filter = NULL;
-               gint i;
-
-               format = work->data;
-               work = work->next;
-
-               name = gdk_pixbuf_format_get_name(format);
-               desc = gdk_pixbuf_format_get_description(format);
-               extensions = gdk_pixbuf_format_get_extensions(format);
-
-               i = 0;
-               while (extensions[i])
-                       {
-                       if (!filter)
-                               {
-                               filter = g_string_new(".");
-                               filter = g_string_append(filter, extensions[i]);
-                               }
-                       else
-                               {
-                               filter = g_string_append(filter, ";.");
-                               filter = g_string_append(filter, extensions[i]);
-                               }
-                       i++;
-                       }
-
-               DEBUG_1("loader reported [%s] [%s] [%s]", name, desc, filter->str);
-
-               filter_add_if_missing(name, desc, filter->str, FORMAT_CLASS_IMAGE, TRUE);
-
-               g_free(name);
-               g_free(desc);
-               g_strfreev(extensions);
-               g_string_free(filter, TRUE);
-               }
-       g_slist_free(list);
-
-       /* add defaults even if gdk-pixbuf does not have them, but disabled */
-       filter_add_if_missing("jpeg", "JPEG group", ".jpg;.jpeg;.jpe", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("png", "Portable Network Graphic", ".png", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("xbm", "X bitmap", ".xbm", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("xpm", "X pixmap", ".xpm", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("bmp", "Bitmap", ".bmp", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("ico", "Icon file", ".ico;.cur", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("ras", "Raster", ".ras", FORMAT_CLASS_IMAGE, FALSE);
-       filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FORMAT_CLASS_IMAGE, FALSE);
-
-       /* non-image files that might be desirable to show */
-       filter_add_if_missing("xmp", "XMP sidecar", ".xmp", FORMAT_CLASS_META, TRUE);
-
-       /* These are the raw camera formats with embedded jpeg/exif.
-        * (see format_raw.c and/or exiv2.cc)
-        */
-       filter_add_if_missing("arw", "Sony raw format", ".arw;.srf;.sr2", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("kdc", "Kodak raw format", ".kdc;.dcr", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("raf", "Fujifilm raw format", ".raf", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("mef", "Mamiya raw format", ".mef;.mos", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("mrw", "Minolta raw format", ".mrw", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("nef", "Nikon raw format", ".nef", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("orf", "Olympus raw format", ".orf", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("pef", "Pentax or Samsung raw format", ".pef;.ptx", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("dng", "Adobe Digital Negative raw format", ".dng", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("x3f", "Sigma raw format", ".x3f", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("raw", "Panasonic raw format", ".raw", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("r3d", "Red raw format", ".r3d", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("3fr", "Hasselblad raw format", ".3fr", FORMAT_CLASS_RAWIMAGE, TRUE);
-       filter_add_if_missing("erf", "Epson raw format", ".erf", FORMAT_CLASS_RAWIMAGE, TRUE);
-}
-
-GList *filter_to_list(const gchar *extensions)
-{
-       GList *list = NULL;
-       const gchar *p;
-
-       if (!extensions) return NULL;
-
-       p = extensions;
-       while (*p != '\0')
-               {
-               const gchar *b;
-               gint l = 0;
-
-               b = p;
-               while (*p != '\0' && *p != ';')
-                       {
-                       p++;
-                       l++;
-                       }
-               list = g_list_append(list, g_strndup(b, l));
-               if (*p == ';') p++;
-               }
-
-       return list;
-}
-
-void filter_rebuild(void)
-{
-       GList *work;
-       gint i;
-
-       string_list_free(extension_list);
-       extension_list = NULL;
-
-       for (i = 0; i < FILE_FORMAT_CLASSES; i++)
-               {
-               string_list_free(file_class_extension_list[i]);
-               file_class_extension_list[i] = NULL;
-               }
-
-       work = filter_list;
-       while (work)
-               {
-               FilterEntry *fe;
-
-               fe = work->data;
-               work = work->next;
-
-               if (fe->enabled)
-                       {
-                       GList *ext;
-
-                       ext = filter_to_list(fe->extensions);
-                       if (ext) extension_list = g_list_concat(extension_list, ext);
-
-                       if (fe->file_class >= 0 && fe->file_class < FILE_FORMAT_CLASSES)
-                               {
-                               ext = filter_to_list(fe->extensions);
-                               if (ext) file_class_extension_list[fe->file_class] = g_list_concat(file_class_extension_list[fe->file_class], ext);
-                               }
-                       else
-                               {
-                               printf("WARNING: invalid file class %d\n", fe->file_class);
-                               }
-                       }
-               }
-}
-
-gint filter_name_exists(const gchar *name)
-{
-       GList *work;
-       gint ln;
-
-       if (!extension_list || options->file_filter.disable) return TRUE;
-
-       ln = strlen(name);
-       work = extension_list;
-       while (work)
-               {
-               gchar *filter = work->data;
-               gint lf = strlen(filter);
-
-               if (ln >= lf)
-                       {
-                       if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE;
-                       }
-               work = work->next;
-               }
-
-       return FALSE;
-}
-
-gint filter_file_class(const gchar *name, FileFormatClass file_class)
-{
-       GList *work;
-       gint ln;
-
-       if (file_class < 0 || file_class >= FILE_FORMAT_CLASSES)
-               {
-               printf("WARNING: invalid file class %d\n", file_class);
-               return FALSE;
-               }
-
-       ln = strlen(name);
-       work = file_class_extension_list[file_class];
-       while (work)
-               {
-               gchar *filter = work->data;
-               gint lf = strlen(filter);
-
-               if (ln >= lf)
-                       {
-                       if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE;
-                       }
-               work = work->next;
-               }
-
-       return FALSE;
-}
-
-void filter_write_list(SecureSaveInfo *ssi)
-{
-       GList *work;
-
-       work = filter_list;
-       while (work)
-               {
-               FilterEntry *fe = work->data;
-               work = work->next;
-
-               gchar *extensions = escquote_value(fe->extensions);
-               gchar *description = escquote_value(fe->description);
-
-               secure_fprintf(ssi, "file_filter.ext: \"%s%s\" %s %s %d\n",
-                              (fe->enabled) ? "" : "#",
-                              fe->key, extensions, description, fe->file_class);
-               g_free(extensions);
-               g_free(description);
-               }
-}
-
-void filter_parse(const gchar *text)
-{
-       const gchar *p;
-       gchar *key;
-       gchar *ext;
-       gchar *desc;
-       gint enabled = TRUE;
-       gint file_class;
-
-       if (!text || text[0] != '"') return;
-
-       key = quoted_value(text, &p);
-       if (!key) return;
-
-       ext = quoted_value(p, &p);
-       desc = quoted_value(p, &p);
-
-       file_class = strtol(p, NULL, 10);
-
-       if (file_class < 0 || file_class >= FILE_FORMAT_CLASSES) file_class = FORMAT_CLASS_UNKNOWN;
-
-       if (key && key[0] == '#')
-               {
-               gchar *tmp;
-               tmp = g_strdup(key + 1);
-               g_free(key);
-               key = tmp;
-
-               enabled = FALSE;
-               }
-
-       if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, file_class, enabled);
-
-       g_free(key);
-       g_free(ext);
-       g_free(desc);
-}
-
-/*
- *-----------------------------------------------------------------------------
- * sidecar extension list
- *-----------------------------------------------------------------------------
- */
-
-static GList *sidecar_ext_get_list(void)
-{
-       return sidecar_ext_list;
-}
-
-void sidecar_ext_parse(const gchar *text, gint quoted)
-{
-       GList *work;
-       gchar *value;
-
-       work = sidecar_ext_list;
-       while (work)
-               {
-               gchar *ext = work->data;
-               work = work->next;
-               g_free(ext);
-               }
-       g_list_free(sidecar_ext_list);
-       sidecar_ext_list = NULL;
-
-       if (quoted)
-               value = quoted_value(text, NULL);
-       else
-               value = g_strdup(text);
-
-       if (value == NULL) return;
-
-       sidecar_ext_list = filter_to_list(value);
-
-       g_free(value);
-}
-
-void sidecar_ext_write(SecureSaveInfo *ssi)
-{
-       secure_fprintf(ssi, "sidecar.ext: \"%s\"\n", sidecar_ext_to_string());
-}
-
-char *sidecar_ext_to_string()
-{
-       GList *work;
-       GString *str = g_string_new("");
-
-       work = sidecar_ext_list;
-       while (work)
-               {
-               gchar *ext = work->data;
-               work = work->next;
-               g_string_append(str, ext);
-               if (work) g_string_append(str, ";");
-               }
-       return g_string_free(str, FALSE);
-}
-
-void sidecar_ext_add_defaults()
-{
-       sidecar_ext_parse(".jpg;.cr2;.nef;.crw;.xmp", FALSE);
-}
-
 /*
  *-----------------------------------------------------------------------------
  * text conversion utils
similarity index 61%
rename from src/filelist.h
rename to src/filedata.h
index eb713fa..ebabd50 100644 (file)
  */
 
 
-#ifndef FILELIST_H
-#define FILELIST_H
-
-
-typedef struct _FilterEntry FilterEntry;
-struct _FilterEntry {
-       gchar *key;
-       gchar *description;
-       gchar *extensions;
-       FileFormatClass file_class;
-       gint enabled;
-};
-
-/* you can change, but not add or remove entries from the returned list */
-GList *filter_get_list(void);
-void filter_remove_entry(FilterEntry *fe);
-
-void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled);
-void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled);
-void filter_add_defaults(void);
-void filter_reset(void);
-void filter_rebuild(void);
-GList *filter_to_list(const gchar *extensions);
-
-gint filter_name_exists(const gchar *name);
-gint filter_file_class(const gchar *name, FileFormatClass file_class);
-
-void filter_write_list(SecureSaveInfo *ssi);
-void filter_parse(const gchar *text);
-
-void sidecar_ext_parse(const gchar *text, gint quoted);
-void sidecar_ext_write(SecureSaveInfo *ssi);
-char *sidecar_ext_to_string();
-void sidecar_ext_add_defaults();
-
-gint ishidden(const gchar *name);
-
+#ifndef FILEDATA_H
+#define FILEDATA_H
 
 gchar *text_from_size(gint64 size);
 gchar *text_from_size_abrev(gint64 size);
diff --git a/src/filefilter.c b/src/filefilter.c
new file mode 100644 (file)
index 0000000..aaff8c9
--- /dev/null
@@ -0,0 +1,489 @@
+/*
+ * Geeqie
+ * (C) 2006 John Ellis
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * Author: John Ellis
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+
+#include "main.h"
+#include "filefilter.h"
+
+#include "cache.h"
+#include "debug.h"
+#include "rcfile.h"
+#include "secure_save.h"
+#include "thumb_standard.h"
+#include "ui_fileops.h"
+
+
+/*
+ *-----------------------------------------------------------------------------
+ * file filtering
+ *-----------------------------------------------------------------------------
+ */
+
+static GList *filter_list = NULL;
+static GList *extension_list = NULL;
+static GList *sidecar_ext_list = NULL;
+
+static GList *file_class_extension_list[FILE_FORMAT_CLASSES];
+
+
+gint ishidden(const gchar *name)
+{
+       if (name[0] != '.') return FALSE;
+       if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE;
+       return TRUE;
+}
+
+static FilterEntry *filter_entry_new(const gchar *key, const gchar *description,
+                                    const gchar *extensions, FileFormatClass file_class, gint enabled)
+{
+       FilterEntry *fe;
+
+       fe = g_new0(FilterEntry, 1);
+       fe->key = g_strdup(key);
+       fe->description = g_strdup(description);
+       fe->extensions = g_strdup(extensions);
+       fe->enabled = enabled;
+       fe->file_class = file_class;
+
+       return fe;
+}
+
+static void filter_entry_free(FilterEntry *fe)
+{
+       if (!fe) return;
+
+       g_free(fe->key);
+       g_free(fe->description);
+       g_free(fe->extensions);
+       g_free(fe);
+}
+
+GList *filter_get_list(void)
+{
+       return filter_list;
+}
+
+void filter_remove_entry(FilterEntry *fe)
+{
+       if (!g_list_find(filter_list, fe)) return;
+
+       filter_list = g_list_remove(filter_list, fe);
+       filter_entry_free(fe);
+}
+
+static gint filter_key_exists(const gchar *key)
+{
+       GList *work;
+
+       if (!key) return FALSE;
+
+       work = filter_list;
+       while (work)
+               {
+               FilterEntry *fe = work->data;
+               work = work->next;
+
+               if (strcmp(fe->key, key) == 0) return TRUE;
+               }
+
+       return FALSE;
+}
+
+void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
+{
+       filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, file_class, enabled));
+}
+
+void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
+{
+       gchar *key;
+       gint n;
+
+       key = g_strdup("user0");
+       n = 1;
+       while (filter_key_exists(key))
+               {
+               g_free(key);
+               if (n > 999) return;
+               key = g_strdup_printf("user%d", n);
+               n++;
+               }
+
+       filter_add(key, description, extensions, file_class, enabled);
+       g_free(key);
+}
+
+static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
+{
+       GList *work;
+
+       if (!key) return;
+
+       work = filter_list;
+       while (work)
+               {
+               FilterEntry *fe = work->data;
+               work = work->next;
+               if (fe->key && strcmp(fe->key, key) == 0)
+                       {
+                       if (fe->file_class == FORMAT_CLASS_UNKNOWN)
+                               fe->file_class = file_class;    /* for compatibility */
+                       return;
+                       }
+               }
+
+       filter_add(key, description, extensions, file_class, enabled);
+}
+
+void filter_reset(void)
+{
+       GList *work;
+
+       work = filter_list;
+       while (work)
+               {
+               FilterEntry *fe = work->data;
+               work = work->next;
+               filter_entry_free(fe);
+               }
+
+       g_list_free(filter_list);
+       filter_list = NULL;
+}
+
+void filter_add_defaults(void)
+{
+       GSList *list, *work;
+
+       list = gdk_pixbuf_get_formats();
+       work = list;
+       while (work)
+               {
+               GdkPixbufFormat *format;
+               gchar *name;
+               gchar *desc;
+               gchar **extensions;
+               GString *filter = NULL;
+               gint i;
+
+               format = work->data;
+               work = work->next;
+
+               name = gdk_pixbuf_format_get_name(format);
+               desc = gdk_pixbuf_format_get_description(format);
+               extensions = gdk_pixbuf_format_get_extensions(format);
+
+               i = 0;
+               while (extensions[i])
+                       {
+                       if (!filter)
+                               {
+                               filter = g_string_new(".");
+                               filter = g_string_append(filter, extensions[i]);
+                               }
+                       else
+                               {
+                               filter = g_string_append(filter, ";.");
+                               filter = g_string_append(filter, extensions[i]);
+                               }
+                       i++;
+                       }
+
+               DEBUG_1("loader reported [%s] [%s] [%s]", name, desc, filter->str);
+
+               filter_add_if_missing(name, desc, filter->str, FORMAT_CLASS_IMAGE, TRUE);
+
+               g_free(name);
+               g_free(desc);
+               g_strfreev(extensions);
+               g_string_free(filter, TRUE);
+               }
+       g_slist_free(list);
+
+       /* add defaults even if gdk-pixbuf does not have them, but disabled */
+       filter_add_if_missing("jpeg", "JPEG group", ".jpg;.jpeg;.jpe", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("png", "Portable Network Graphic", ".png", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("xbm", "X bitmap", ".xbm", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("xpm", "X pixmap", ".xpm", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("bmp", "Bitmap", ".bmp", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("ico", "Icon file", ".ico;.cur", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("ras", "Raster", ".ras", FORMAT_CLASS_IMAGE, FALSE);
+       filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FORMAT_CLASS_IMAGE, FALSE);
+
+       /* non-image files that might be desirable to show */
+       filter_add_if_missing("xmp", "XMP sidecar", ".xmp", FORMAT_CLASS_META, TRUE);
+
+       /* These are the raw camera formats with embedded jpeg/exif.
+        * (see format_raw.c and/or exiv2.cc)
+        */
+       filter_add_if_missing("arw", "Sony raw format", ".arw;.srf;.sr2", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("kdc", "Kodak raw format", ".kdc;.dcr", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("raf", "Fujifilm raw format", ".raf", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("mef", "Mamiya raw format", ".mef;.mos", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("mrw", "Minolta raw format", ".mrw", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("nef", "Nikon raw format", ".nef", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("orf", "Olympus raw format", ".orf", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("pef", "Pentax or Samsung raw format", ".pef;.ptx", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("dng", "Adobe Digital Negative raw format", ".dng", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("x3f", "Sigma raw format", ".x3f", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("raw", "Panasonic raw format", ".raw", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("r3d", "Red raw format", ".r3d", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("3fr", "Hasselblad raw format", ".3fr", FORMAT_CLASS_RAWIMAGE, TRUE);
+       filter_add_if_missing("erf", "Epson raw format", ".erf", FORMAT_CLASS_RAWIMAGE, TRUE);
+}
+
+GList *filter_to_list(const gchar *extensions)
+{
+       GList *list = NULL;
+       const gchar *p;
+
+       if (!extensions) return NULL;
+
+       p = extensions;
+       while (*p != '\0')
+               {
+               const gchar *b;
+               gint l = 0;
+
+               b = p;
+               while (*p != '\0' && *p != ';')
+                       {
+                       p++;
+                       l++;
+                       }
+               list = g_list_append(list, g_strndup(b, l));
+               if (*p == ';') p++;
+               }
+
+       return list;
+}
+
+void filter_rebuild(void)
+{
+       GList *work;
+       gint i;
+
+       string_list_free(extension_list);
+       extension_list = NULL;
+
+       for (i = 0; i < FILE_FORMAT_CLASSES; i++)
+               {
+               string_list_free(file_class_extension_list[i]);
+               file_class_extension_list[i] = NULL;
+               }
+
+       work = filter_list;
+       while (work)
+               {
+               FilterEntry *fe;
+
+               fe = work->data;
+               work = work->next;
+
+               if (fe->enabled)
+                       {
+                       GList *ext;
+
+                       ext = filter_to_list(fe->extensions);
+                       if (ext) extension_list = g_list_concat(extension_list, ext);
+
+                       if (fe->file_class >= 0 && fe->file_class < FILE_FORMAT_CLASSES)
+                               {
+                               ext = filter_to_list(fe->extensions);
+                               if (ext) file_class_extension_list[fe->file_class] = g_list_concat(file_class_extension_list[fe->file_class], ext);
+                               }
+                       else
+                               {
+                               printf("WARNING: invalid file class %d\n", fe->file_class);
+                               }
+                       }
+               }
+}
+
+gint filter_name_exists(const gchar *name)
+{
+       GList *work;
+       gint ln;
+
+       if (!extension_list || options->file_filter.disable) return TRUE;
+
+       ln = strlen(name);
+       work = extension_list;
+       while (work)
+               {
+               gchar *filter = work->data;
+               gint lf = strlen(filter);
+
+               if (ln >= lf)
+                       {
+                       if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE;
+                       }
+               work = work->next;
+               }
+
+       return FALSE;
+}
+
+gint filter_file_class(const gchar *name, FileFormatClass file_class)
+{
+       GList *work;
+       gint ln;
+
+       if (file_class < 0 || file_class >= FILE_FORMAT_CLASSES)
+               {
+               printf("WARNING: invalid file class %d\n", file_class);
+               return FALSE;
+               }
+
+       ln = strlen(name);
+       work = file_class_extension_list[file_class];
+       while (work)
+               {
+               gchar *filter = work->data;
+               gint lf = strlen(filter);
+
+               if (ln >= lf)
+                       {
+                       if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE;
+                       }
+               work = work->next;
+               }
+
+       return FALSE;
+}
+
+void filter_write_list(SecureSaveInfo *ssi)
+{
+       GList *work;
+
+       work = filter_list;
+       while (work)
+               {
+               FilterEntry *fe = work->data;
+               work = work->next;
+
+               gchar *extensions = escquote_value(fe->extensions);
+               gchar *description = escquote_value(fe->description);
+
+               secure_fprintf(ssi, "file_filter.ext: \"%s%s\" %s %s %d\n",
+                              (fe->enabled) ? "" : "#",
+                              fe->key, extensions, description, fe->file_class);
+               g_free(extensions);
+               g_free(description);
+               }
+}
+
+void filter_parse(const gchar *text)
+{
+       const gchar *p;
+       gchar *key;
+       gchar *ext;
+       gchar *desc;
+       gint enabled = TRUE;
+       gint file_class;
+
+       if (!text || text[0] != '"') return;
+
+       key = quoted_value(text, &p);
+       if (!key) return;
+
+       ext = quoted_value(p, &p);
+       desc = quoted_value(p, &p);
+
+       file_class = strtol(p, NULL, 10);
+
+       if (file_class < 0 || file_class >= FILE_FORMAT_CLASSES) file_class = FORMAT_CLASS_UNKNOWN;
+
+       if (key && key[0] == '#')
+               {
+               gchar *tmp;
+               tmp = g_strdup(key + 1);
+               g_free(key);
+               key = tmp;
+
+               enabled = FALSE;
+               }
+
+       if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, file_class, enabled);
+
+       g_free(key);
+       g_free(ext);
+       g_free(desc);
+}
+
+/*
+ *-----------------------------------------------------------------------------
+ * sidecar extension list
+ *-----------------------------------------------------------------------------
+ */
+
+GList *sidecar_ext_get_list(void)
+{
+       return sidecar_ext_list;
+}
+
+void sidecar_ext_parse(const gchar *text, gint quoted)
+{
+       GList *work;
+       gchar *value;
+
+       work = sidecar_ext_list;
+       while (work)
+               {
+               gchar *ext = work->data;
+               work = work->next;
+               g_free(ext);
+               }
+       g_list_free(sidecar_ext_list);
+       sidecar_ext_list = NULL;
+
+       if (quoted)
+               value = quoted_value(text, NULL);
+       else
+               value = g_strdup(text);
+
+       if (value == NULL) return;
+
+       sidecar_ext_list = filter_to_list(value);
+
+       g_free(value);
+}
+
+void sidecar_ext_write(SecureSaveInfo *ssi)
+{
+       secure_fprintf(ssi, "sidecar.ext: \"%s\"\n", sidecar_ext_to_string());
+}
+
+char *sidecar_ext_to_string()
+{
+       GList *work;
+       GString *str = g_string_new("");
+
+       work = sidecar_ext_list;
+       while (work)
+               {
+               gchar *ext = work->data;
+               work = work->next;
+               g_string_append(str, ext);
+               if (work) g_string_append(str, ";");
+               }
+       return g_string_free(str, FALSE);
+}
+
+void sidecar_ext_add_defaults()
+{
+       sidecar_ext_parse(".jpg;.cr2;.nef;.crw;.xmp", FALSE);
+}
diff --git a/src/filefilter.h b/src/filefilter.h
new file mode 100644 (file)
index 0000000..7e3d4b3
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Geeqie
+ * (C) 2004 John Ellis
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * Author: John Ellis
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+
+#ifndef FILEFILTER_H
+#define FILEFILTER_H
+
+
+typedef struct _FilterEntry FilterEntry;
+struct _FilterEntry {
+       gchar *key;
+       gchar *description;
+       gchar *extensions;
+       FileFormatClass file_class;
+       gint enabled;
+};
+
+/* you can change, but not add or remove entries from the returned list */
+GList *filter_get_list(void);
+void filter_remove_entry(FilterEntry *fe);
+
+void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled);
+void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled);
+void filter_add_defaults(void);
+void filter_reset(void);
+void filter_rebuild(void);
+GList *filter_to_list(const gchar *extensions);
+
+gint filter_name_exists(const gchar *name);
+gint filter_file_class(const gchar *name, FileFormatClass file_class);
+
+void filter_write_list(SecureSaveInfo *ssi);
+void filter_parse(const gchar *text);
+
+void sidecar_ext_parse(const gchar *text, gint quoted);
+void sidecar_ext_write(SecureSaveInfo *ssi);
+char *sidecar_ext_to_string();
+void sidecar_ext_add_defaults();
+GList *sidecar_ext_get_list(void);
+
+gint ishidden(const gchar *name);
+
+#endif
index 87b3a64..848b4c3 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "debug.h"
 #include "exif.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "ui_fileops.h"
 
 #include <fcntl.h>
index 5df1031..9af2d1b 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "collect.h"
 #include "exif.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "image.h"
 #include "img-view.h"
 #include "layout.h"
index a080ac3..65e4737 100644 (file)
@@ -28,7 +28,7 @@
 #include "pixbuf_util.h"
 #include "ui_fileops.h"
 
-#include "filelist.h"
+#include "filedata.h"
 
 #include <math.h>
 
index 956cfc6..405f7c4 100644 (file)
@@ -18,7 +18,7 @@
 #include "collect-io.h"
 #include "dnd.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "fullscreen.h"
 #include "image.h"
 #include "image-overlay.h"
index 24b16e3..ab50de4 100644 (file)
@@ -17,7 +17,7 @@
 #include "bar_info.h"
 #include "bar_exif.h"
 #include "dnd.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "image.h"
 #include "image-load.h"
 #include "pixbuf-renderer.h"
index 6a37cb2..a04b361 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "color-man.h"
 #include "debug.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "histogram.h"
 #include "image.h"
 #include "image-overlay.h"
index 3662fca..5c125e3 100644 (file)
@@ -17,7 +17,7 @@
 #include "dnd.h"
 #include "debug.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "fullscreen.h"
 #include "image.h"
 #include "image-overlay.h"
index 6bac013..ad787cd 100644 (file)
@@ -23,7 +23,7 @@
 #include "compat.h"
 #include "dupe.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "image-overlay.h"
 #include "img-view.h"
 #include "info.h"
index 9c047f7..cc554b5 100644 (file)
@@ -19,7 +19,8 @@
 #include "debug.h"
 #include "dnd.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
+#include "filefilter.h"
 #include "fullscreen.h"
 #include "image-overlay.h"
 #include "img-view.h"
index 55f0bcf..c7dafe8 100644 (file)
@@ -18,7 +18,7 @@
 #include "collect.h"
 #include "collect-dlg.h"
 #include "dupe.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "img-view.h"
 #include "preferences.h"
 #include "slideshow.h"
index 39da369..74b95b1 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "cache.h"
 #include "cache-loader.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "image.h"
 #include "image-load.h"
 #include "pixbuf_util.h"
index 83c6714..a0cc763 100644 (file)
@@ -17,7 +17,8 @@
 #include "cache_maint.h"
 #include "debug.h"
 #include "editors.h"
-#include "filelist.h"
+#include "filedata.h"
+#include "filefilter.h"
 #include "fullscreen.h"
 #include "image.h"
 #include "image-overlay.h"
index cecc87e..39bb8e8 100644 (file)
@@ -15,7 +15,7 @@
 #include "print.h"
 
 #include "debug.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "image.h"
 #include "image-load.h"
 #include "pixbuf_util.h"
index b99d4e4..0a6f01b 100644 (file)
@@ -17,7 +17,7 @@
 #include "rcfile.h"
 
 #include "bar_exif.h"
-#include "filelist.h"
+#include "filefilter.h"
 #include "secure_save.h"
 #include "slideshow.h"
 #include "ui_fileops.h"
index 3766d10..9d2acbe 100644 (file)
@@ -24,7 +24,7 @@
 #include "info.h"
 #include "editors.h"
 #include "img-view.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout_image.h"
 #include "menu.h"
 #include "print.h"
index e36dd79..ffe803c 100644 (file)
@@ -15,7 +15,7 @@
 #include "collect.h"
 #include "image.h"
 #include "slideshow.h"
-#include "filelist.h"
+#include "filedata.h"
 
 #include "layout.h"
 #include "layout_image.h"
index 58e6ad2..795a1b9 100644 (file)
@@ -17,7 +17,7 @@
 #include "cache.h"
 #include "debug.h"
 #include "image-load.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "pixbuf_util.h"
 #include "thumb_standard.h"
 #include "ui_fileops.h"
index 80de82c..f8559e8 100644 (file)
@@ -24,7 +24,7 @@
 #include <gdk/gdkkeysyms.h> /* for key values */
 
 #include "main.h"
-#include "filelist.h"
+#include "filedata.h"
 
 #include "debug.h"
 #include "secure_save.h"
index e0a8f8b..cd140f4 100644 (file)
@@ -26,7 +26,7 @@
 #include "main.h"
 #include "ui_utildlg.h"
 
-#include "filelist.h"
+#include "filedata.h"
 #include "ui_fileops.h"
 #include "ui_misc.h"
 #include "ui_pathsel.h"
index 6c1a284..f3815f2 100644 (file)
@@ -20,7 +20,8 @@
 #include "collect.h"
 #include "debug.h"
 #include "dupe.h"
-#include "filelist.h"
+#include "filedata.h"
+#include "filefilter.h"
 #include "image.h"
 #include "img-view.h"
 #include "layout.h"
index 7755d4b..cf4896f 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "dnd.h"
 #include "dupe.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout_image.h"
 #include "layout_util.h"
 #include "ui_bookmark.h"
index 4055871..9d3cdcb 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "dnd.h"
 #include "dupe.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "layout_util.h"
index 6076d9f..d08db8f 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "dnd.h"
 #include "dupe.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "layout_util.h"
index 9ac7608..3bdc32d 100644 (file)
@@ -22,7 +22,7 @@
 #include "editors.h"
 #include "img-view.h"
 #include "info.h"
-#include "filelist.h"
+#include "filedata.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
index fe829a0..72bf440 100644 (file)
@@ -14,7 +14,7 @@
 #define VIEW_FILE_LIST_H
 
 
-#include "filelist.h"
+#include "filedata.h"
 
 gint vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data);
 gint vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data);