changeset 212:c7021159079d

differentiate among normal image, raw image and metadata removed raw extension lists on various places and fixed most of the Exiv2 warnings todo: configuration and a special icons for unreadable raw or metadata
author nadvornik
date Sun, 30 Mar 2008 11:47:14 +0000
parents d43153435be4
children 28f2274c9bd0
files src/exif-common.c src/exiv2.cc src/filelist.c src/filelist.h src/preferences.c src/typedefs.h
diffstat 6 files changed, 107 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/src/exif-common.c	Sun Mar 30 07:14:37 2008 +0000
+++ b/src/exif-common.c	Sun Mar 30 11:47:14 2008 +0000
@@ -336,14 +336,12 @@
 
 	work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
 
-	if (strcasecmp(fd->extension, ".cr2") == 0 || // FIXME: list of formats that can have xmp sidecar, make it configurable
-	    strcasecmp(fd->extension, ".nef") == 0)
+	if (filter_file_class(fd->extension, FORMAT_CLASS_RAWIMAGE))
 		{
 		while(work)
 			{
 			FileData *sfd = work->data;
 			work = work->next;
-			printf("sfd %s\n", sfd->path);
 			if (strcasecmp(sfd->extension, ".xmp") == 0)
 				{
 				sidecar_path = sfd->path;
--- a/src/exiv2.cc	Sun Mar 30 07:14:37 2008 +0000
+++ b/src/exiv2.cc	Sun Mar 30 11:47:14 2008 +0000
@@ -42,6 +42,7 @@
 #include <glib.h> 
 #include "gqview.h"
 #include "exif.h"
+#include "filelist.h"
 
 }
 
@@ -106,7 +107,7 @@
 
 ExifData *exif_read(gchar *path, gchar *sidecar_path, gint parse_color_profile)
 {
-	printf("exif %s %s\n", path, sidecar_path ? sidecar_path : "-");
+	if (debug) printf("exif read %s,  sidecar: %s\n", path, sidecar_path ? sidecar_path : "-");
 	try {
 		return new ExifData(path, sidecar_path, parse_color_profile);
 	}
@@ -683,8 +684,6 @@
 }
 
 
-const static char *raw_ext_list[] = { ".cr2", ".nef", ".pef", ".arw", NULL };
-
 extern "C" gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
 				    unsigned char *header_data, const guint header_len,
 				    guint *image_offset, guint *exif_offset)
@@ -693,28 +692,8 @@
 	unsigned long offset;
 
 	/* given image pathname, first do simple (and fast) file extension test */
-/*	if (path)
-		{
-		const gchar *ext;
-		gint match = FALSE;
-		gint i;
+	if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return 0;
 
-		ext = strrchr(path, '.');
-		if (!ext) return FALSE;
-		
-		for (i = 0; raw_ext_list[i]; i++) 
-			{
-			if (strcasecmp(raw_ext_list[i], ext) == 0)
-				{
-				match = TRUE;
-				break;
-				}
-			}
-
-		if (!match) return FALSE;
-
-		}
-*/
 	try {
 		RawFile rf(fd);
 		if (debug) printf("%s: offset ", path);
--- a/src/filelist.c	Sun Mar 30 07:14:37 2008 +0000
+++ b/src/filelist.c	Sun Mar 30 11:47:14 2008 +0000
@@ -29,6 +29,9 @@
 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;
@@ -37,7 +40,7 @@
 }
 
 static FilterEntry *filter_entry_new(const gchar *key, const gchar *description,
-				     const gchar *extensions, gint enabled)
+				     const gchar *extensions, FileFormatClass file_class, gint enabled)
 {
 	FilterEntry *fe;
 
@@ -46,6 +49,7 @@
 	fe->description = g_strdup(description);
 	fe->extensions = g_strdup(extensions);
 	fe->enabled = enabled;
+	fe->file_class = file_class;
 	
 	return fe;
 }
@@ -91,12 +95,12 @@
 	return FALSE;
 }
 
-void filter_add(const gchar *key, const gchar *description, const gchar *extensions, gint enabled)
+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, 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, gint enabled)
+void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
 {
 	gchar *key;
 	gint n;
@@ -111,11 +115,11 @@
 		n++;
 		}
 
-	filter_add(key, description, extensions, enabled);
+	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, gint enabled)
+static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled)
 {
 	GList *work;
 
@@ -126,10 +130,15 @@
 		{
 		FilterEntry *fe = work->data;
 		work = work->next;
-		if (fe->key && strcmp(fe->key, key) == 0) return;
+		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, enabled);
+	filter_add(key, description, extensions, file_class, enabled);
 }
 
 void filter_reset(void)
@@ -188,7 +197,7 @@
 
 		if (debug) printf("loader reported [%s] [%s] [%s]\n", name, desc, filter->str);
 
-		filter_add_if_missing(name, desc, filter->str, TRUE);
+		filter_add_if_missing(name, desc, filter->str, FORMAT_CLASS_IMAGE, TRUE);
 
 		g_free(name);
 		g_free(desc);
@@ -198,39 +207,39 @@
 	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", FALSE);
-	filter_add_if_missing("png", "Portable Network Graphic", ".png", FALSE);
-	filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FALSE);
-	filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FALSE);
-	filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FALSE);
-	filter_add_if_missing("xbm", "X bitmap", ".xbm", FALSE);
-	filter_add_if_missing("xpm", "X pixmap", ".xpm", FALSE);
-	filter_add_if_missing("bmp", "Bitmap", ".bmp", FALSE);
-	filter_add_if_missing("ico", "Icon file", ".ico;.cur", FALSE);
-	filter_add_if_missing("ras", "Raster", ".ras", FALSE);
-	filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FALSE);
+	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", TRUE);
+	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", TRUE);
-	filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", TRUE);
-	filter_add_if_missing("kdc", "Kodak raw format", ".kdc;.dcr", TRUE);
-	filter_add_if_missing("raf", "Fujifilm raw format", ".raf", TRUE);
-	filter_add_if_missing("mef", "Mamiya raw format", ".mef;.mos", TRUE);
-	filter_add_if_missing("mrw", "Minolta raw format", ".mrw", TRUE);
-	filter_add_if_missing("nef", "Nikon raw format", ".nef", TRUE);
-	filter_add_if_missing("orf", "Olympus raw format", ".orf", TRUE);
-	filter_add_if_missing("pef", "Pentax raw format", ".pef;.ptx", TRUE);
-	filter_add_if_missing("dng", "Adobe Digital Negative raw format", ".dng", TRUE);
-	filter_add_if_missing("x3f", "Sigma raw format", ".x3f", TRUE);
-	filter_add_if_missing("raw", "Panasonic raw format", ".raw", TRUE);
-	filter_add_if_missing("r3d", "Red raw format", ".r3d", TRUE);
-	filter_add_if_missing("3fr", "Hasselblad raw format", ".3fr", TRUE);
-	filter_add_if_missing("erf", "Epson raw format", ".erf", TRUE);
+	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 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)
@@ -262,10 +271,17 @@
 void filter_rebuild(void)
 {
 	GList *work;
+	gint i;
 
-	path_list_free(extension_list);
+	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)
 		{
@@ -280,6 +296,16 @@
 
 			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);
+				}
 			}
 		}
 }
@@ -305,6 +331,32 @@
 	return FALSE;
 }
 
+gint filter_file_class(const gchar *name, FileFormatClass file_class)
+{
+	GList *work;
+
+	if (file_class < 0 || file_class >= FILE_FORMAT_CLASSES)
+		{
+		printf("WARNING: invalid file class %d\n", file_class);
+		return FALSE;
+		}
+
+	work = file_class_extension_list[file_class];
+	while (work)
+		{
+		gchar *filter = work->data;
+		gint lf = strlen(filter);
+		gint ln = strlen(name);
+		if (ln >= lf)
+			{
+			if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE;
+			}
+		work = work->next;
+		}
+
+	return FALSE;
+}
+
 void filter_write_list(FILE *f)
 {
 	GList *work;
@@ -376,7 +428,7 @@
 		enabled = FALSE;
 		}
 
-	if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, enabled);
+	if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, FORMAT_CLASS_UNKNOWN, enabled);
 
 	g_free(key);
 	g_free(ext);
--- a/src/filelist.h	Sun Mar 30 07:14:37 2008 +0000
+++ b/src/filelist.h	Sun Mar 30 11:47:14 2008 +0000
@@ -19,6 +19,7 @@
 	gchar *key;
 	gchar *description;
 	gchar *extensions;
+	FileFormatClass file_class;
 	gint enabled;
 };
 
@@ -26,14 +27,15 @@
 GList *filter_get_list(void);
 void filter_remove_entry(FilterEntry *fe);
 
-void filter_add(const gchar *key, const gchar *description, const gchar *extensions, gint enabled);
-void filter_add_unique(const gchar *description, const gchar *extensions, gint enabled);
+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(FILE *f);
 void filter_parse(const gchar *text);
--- a/src/preferences.c	Sun Mar 30 07:14:37 2008 +0000
+++ b/src/preferences.c	Sun Mar 30 11:47:14 2008 +0000
@@ -659,7 +659,7 @@
 
 static void filter_add_cb(GtkWidget *widget, gpointer data)
 {
-	filter_add_unique("description", ".new", TRUE);
+	filter_add_unique("description", ".new", FORMAT_CLASS_IMAGE, TRUE);
 	filter_store_populate();
 
 	/* FIXME: implement the scroll to/select row stuff for tree view */
--- a/src/typedefs.h	Sun Mar 30 07:14:37 2008 +0000
+++ b/src/typedefs.h	Sun Mar 30 11:47:14 2008 +0000
@@ -88,6 +88,14 @@
 	STM_MODE_TOGGLE
 } SelectionToMarkMode;
 
+typedef enum {
+	FORMAT_CLASS_UNKNOWN,
+	FORMAT_CLASS_IMAGE,
+	FORMAT_CLASS_RAWIMAGE,
+	FORMAT_CLASS_META,
+	FILE_FORMAT_CLASSES
+} FileFormatClass;
+
 
 #define MAX_SPLIT_IMAGES 4