changeset 1229:878718372aca

sidecar files grouping was made case-insensitive added possibility to use macros %raw, %image, %meta in extensions lists
author nadvornik
date Fri, 02 Jan 2009 09:26:23 +0000
parents 4d5587c4bf56
children d13233ab7def
files src/editors.c src/filedata.c src/filefilter.c src/filefilter.h src/options.c src/options.h src/preferences.c src/rcfile.c src/ui_fileops.c src/ui_fileops.h
diffstat 10 files changed, 85 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/src/editors.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/editors.c	Fri Jan 02 09:26:23 2009 +0000
@@ -56,14 +56,14 @@
 
 
 static Editor editor_slot_defaults[GQ_EDITOR_SLOTS] = {
-	{ N_("The Gimp"), "gimp-remote %{.cr2;.crw;.nef;.raw;*}f" },
+	{ N_("The Gimp"), "gimp-remote %{%raw;*}f" },
 	{ N_("XV"), "xv %f" },
 	{ N_("Xpaint"), "xpaint %f" },
-	{ N_("UFraw"), "ufraw %{.cr2;.crw;.nef;.raw}p" },
-	{ N_("Add XMP sidecar"), "%vFILE=%{.cr2;.crw;.nef;.raw}p;XMP=`echo \"$FILE\"|sed -e 's|\\.[^.]*$|.xmp|'`; exiftool -tagsfromfile \"$FILE\" \"$XMP\"" },
+	{ N_("UFraw"), "ufraw %{%raw}p" },
 	{ N_("Symlink"), "ln -s %p %d"},
 	{ NULL, NULL },
 	{ NULL, NULL },
+	{ NULL, NULL },
 	{ N_("Rotate jpeg clockwise"), "%vif jpegtran -rotate 90 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi" },
 	{ N_("Rotate jpeg counterclockwise"), "%vif jpegtran -rotate 270 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi" },
 	/* special slots */
--- a/src/filedata.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/filedata.c	Fri Jan 02 09:26:23 2009 +0000
@@ -395,7 +395,7 @@
 
 		work = work->next;
 
-		if (strcmp(ext, fd->extension) == 0)
+		if (strcasecmp(ext, fd->extension) == 0)
 			{
 			new_fd = fd; /* processing the original file */
 			}
@@ -403,9 +403,8 @@
 			{
 			struct stat nst;
 			g_string_truncate(fname, base_len);
-			g_string_append(fname, ext);
 
-			if (!stat_utf8(fname->str, &nst))
+			if (!stat_utf8_case_insensitive_ext(fname, ext, &nst))
 				continue;
 
 			new_fd = file_data_new(fname->str, &nst, FALSE);
@@ -730,7 +729,7 @@
 		gchar *ext = work->data;
 		
 		work = work->next;
-		if (strcmp(extension, ext) == 0) return i;
+		if (strcasecmp(extension, ext) == 0) return i;
 		i++;
 	}
 	return 0;
--- a/src/filefilter.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/filefilter.c	Fri Jan 02 09:26:23 2009 +0000
@@ -260,6 +260,8 @@
 	while (*p != '\0')
 		{
 		const gchar *b;
+		const gchar *ext;
+		gint file_class = -1;
 		guint l = 0;
 
 		b = p;
@@ -268,7 +270,23 @@
 			p++;
 			l++;
 			}
-		list = g_list_append(list, g_strndup(b, l));
+		
+		ext = g_strndup(b, l);
+		
+		if (strcasecmp(ext, "%image") == 0) file_class = FORMAT_CLASS_IMAGE;
+		else if (strcasecmp(ext, "%raw") == 0) file_class = FORMAT_CLASS_RAWIMAGE;
+		else if (strcasecmp(ext, "%meta") == 0) file_class = FORMAT_CLASS_META;
+		
+		if (file_class == -1) 
+			{
+			list = g_list_append(list, ext);
+			}
+		else
+			{
+			list = g_list_concat(list, string_list_copy(file_class_extension_list[file_class]));
+			g_free(ext);
+			}
+			
 		if (*p == ';') p++;
 		}
 
@@ -315,6 +333,8 @@
 				}
 			}
 		}
+
+	sidecar_ext_parse(options->sidecar.ext, FALSE); /* this must be updated after changed file extensions */
 }
 
 gint filter_name_exists(const gchar *name)
@@ -480,30 +500,5 @@
 	if (quoted) g_free(value);
 }
 
-void sidecar_ext_write(SecureSaveInfo *ssi)
-{
-	secure_fprintf(ssi, "sidecar.ext: \"%s\"\n", sidecar_ext_to_string());
-}
-
-gchar *sidecar_ext_to_string(void)
-{
-	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(void)
-{
-	sidecar_ext_parse(".jpg;.cr2;.nef;.crw;.pef;.dng;.arw;.xmp", FALSE);
-}
 
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/filefilter.h	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/filefilter.h	Fri Jan 02 09:26:23 2009 +0000
@@ -42,9 +42,7 @@
 void filter_parse(const gchar *text);
 
 void sidecar_ext_parse(const gchar *text, gboolean quoted);
-void sidecar_ext_write(SecureSaveInfo *ssi);
 gchar *sidecar_ext_to_string(void);
-void sidecar_ext_add_defaults(void);
 GList *sidecar_ext_get_list(void);
 
 gint ishidden(const gchar *name);
--- a/src/options.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/options.c	Fri Jan 02 09:26:23 2009 +0000
@@ -203,7 +203,7 @@
 		}
 
 	set_default_image_overlay_template_string(&options->image_overlay.common.template_string);
-	sidecar_ext_add_defaults();
+	options->sidecar.ext = g_strdup(".jpg;%raw;.xmp");
 	options->layout.order = g_strdup("123");
 	options->properties.tabs_order = g_strdup(info_tab_default_order());
 
--- a/src/options.h	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/options.h	Fri Jan 02 09:26:23 2009 +0000
@@ -101,6 +101,10 @@
 		gboolean disable;
 	} file_filter;
 
+	struct {
+		gchar *ext;
+	} sidecar;
+	
 	/* collections */
 	struct {
 		gboolean rectangular_selection;
--- a/src/preferences.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/preferences.c	Fri Jan 02 09:26:23 2009 +0000
@@ -277,7 +277,8 @@
 	options->file_sort.case_sensitive = c_options->file_sort.case_sensitive;
 	options->file_filter.disable = c_options->file_filter.disable;
 
-	sidecar_ext_parse(gtk_entry_get_text(GTK_ENTRY(sidecar_ext_entry)), FALSE);
+	config_entry_to_option(sidecar_ext_entry, &options->sidecar.ext, NULL);
+	sidecar_ext_parse(options->sidecar.ext, FALSE);
 
 	options->slideshow.random = c_options->slideshow.random;
 	options->slideshow.repeat = c_options->slideshow.repeat;
@@ -1221,7 +1222,7 @@
 	group = pref_group_new(vbox, FALSE, _("Grouping sidecar extensions"), GTK_ORIENTATION_VERTICAL);
 
 	sidecar_ext_entry = gtk_entry_new();
-	gtk_entry_set_text(GTK_ENTRY(sidecar_ext_entry), sidecar_ext_to_string());
+	gtk_entry_set_text(GTK_ENTRY(sidecar_ext_entry), options->sidecar.ext);
 	gtk_box_pack_start(GTK_BOX(group), sidecar_ext_entry, FALSE, FALSE, 0);
 	gtk_widget_show(sidecar_ext_entry);
 
--- a/src/rcfile.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/rcfile.c	Fri Jan 02 09:26:23 2009 +0000
@@ -463,8 +463,7 @@
 
 	WRITE_SUBTITLE("Sidecars Options");
 
-	sidecar_ext_write(ssi);
-
+	WRITE_CHAR(sidecar.ext);
 
 	WRITE_SUBTITLE("Color Profiles");
 
@@ -842,11 +841,7 @@
 			continue;
 			}
 
-		if (g_ascii_strcasecmp(option, "sidecar.ext") == 0)
-			{
-			sidecar_ext_parse(value_all, TRUE);
-			continue;
-			}
+		READ_CHAR(sidecar.ext);
 
 		/* Color Profiles */
 
--- a/src/ui_fileops.c	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/ui_fileops.c	Fri Jan 02 09:26:23 2009 +0000
@@ -311,6 +311,51 @@
 	return ret;
 }
 
+/* extension must contain only ASCII characters */
+gint stat_utf8_case_insensitive_ext(GString *base, const gchar *ext, struct stat *st)
+{
+	gchar *sl;
+	gchar *extl;
+	gint ret = 0;
+	gint ext_len;
+	gint base_len = strlen(base->str);
+
+	g_string_append(base, ext);
+	sl = path_from_utf8(base->str);
+	
+	extl = strrchr(sl, '.');
+	if (extl)
+		{
+		gint i, j;
+		extl++; /* the first char after . */
+		ext_len = strlen(extl);
+	
+		for (i = 0; i < (1 << ext_len); i++)
+			{
+			for (j = 0; j < ext_len; j++)
+				{
+				if (i & (1 << j)) 
+					extl[j] = g_ascii_toupper(extl[j]);
+				else
+					extl[j] = g_ascii_tolower(extl[j]);
+				}
+			ret = (stat(sl, st) == 0);
+			if (ret) break;
+			}
+		
+		if (ret)
+			{
+			/* append the found extension to base */
+			base = g_string_truncate(base, base_len);
+			extl--;
+			g_string_append(base, extl);
+			}
+		}
+	g_free(sl);
+
+	return ret;
+}
+
 gint isname(const gchar *s)
 {
 	struct stat st;
--- a/src/ui_fileops.h	Sat Dec 27 22:53:07 2008 +0000
+++ b/src/ui_fileops.h	Fri Jan 02 09:26:23 2009 +0000
@@ -44,6 +44,9 @@
 
 gint stat_utf8(const gchar *s, struct stat *st);
 gint lstat_utf8(const gchar *s, struct stat *st);
+gint stat_utf8_case_insensitive_ext(GString *base, const gchar *ext, struct stat *st);
+
+
 gint isname(const gchar *s);
 gint isfile(const gchar *s);
 gint isdir(const gchar *s);