sidecar files grouping was made case-insensitive
authorVladimir Nadvornik <nadvornik@suse.cz>
Fri, 2 Jan 2009 09:26:23 +0000 (09:26 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Fri, 2 Jan 2009 09:26:23 +0000 (09:26 +0000)
added possibility to use macros %raw, %image, %meta in extensions lists

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

index d0f37ce..2a648fd 100644 (file)
@@ -56,14 +56,14 @@ struct _EditorData {
 
 
 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 */
index 3618509..bce4073 100644 (file)
@@ -395,7 +395,7 @@ static void file_data_check_sidecars(FileData *fd)
 
                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 @@ static void file_data_check_sidecars(FileData *fd)
                        {
                        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 @@ static gint sidecar_file_priority(const gchar *path)
                gchar *ext = work->data;
                
                work = work->next;
-               if (strcmp(extension, ext) == 0) return i;
+               if (strcasecmp(extension, ext) == 0) return i;
                i++;
        }
        return 0;
index 54a4d46..6a3ee72 100644 (file)
@@ -260,6 +260,8 @@ GList *filter_to_list(const gchar *extensions)
        while (*p != '\0')
                {
                const gchar *b;
+               const gchar *ext;
+               gint file_class = -1;
                guint l = 0;
 
                b = p;
@@ -268,7 +270,23 @@ GList *filter_to_list(const gchar *extensions)
                        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 @@ void filter_rebuild(void)
                                }
                        }
                }
+
+       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 @@ void sidecar_ext_parse(const gchar *text, gboolean quoted)
        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: */
index d6f2cb3..361937a 100644 (file)
@@ -42,9 +42,7 @@ void filter_write_list(SecureSaveInfo *ssi);
 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);
index 3602988..432e7ad 100644 (file)
@@ -203,7 +203,7 @@ void setup_default_options(ConfOptions *options)
                }
 
        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());
 
index 62af984..ff3ef0c 100644 (file)
@@ -101,6 +101,10 @@ struct _ConfOptions
                gboolean disable;
        } file_filter;
 
+       struct {
+               gchar *ext;
+       } sidecar;
+       
        /* collections */
        struct {
                gboolean rectangular_selection;
index d0ff5a6..6a6f783 100644 (file)
@@ -277,7 +277,8 @@ static void config_window_apply(void)
        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 @@ static void config_tab_filtering(GtkWidget *notebook)
        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);
 
index cfc1ce5..f191db5 100644 (file)
@@ -463,8 +463,7 @@ gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
 
        WRITE_SUBTITLE("Sidecars Options");
 
-       sidecar_ext_write(ssi);
-
+       WRITE_CHAR(sidecar.ext);
 
        WRITE_SUBTITLE("Color Profiles");
 
@@ -842,11 +841,7 @@ gboolean load_options_from(const gchar *utf8_path, ConfOptions *options)
                        continue;
                        }
 
-               if (g_ascii_strcasecmp(option, "sidecar.ext") == 0)
-                       {
-                       sidecar_ext_parse(value_all, TRUE);
-                       continue;
-                       }
+               READ_CHAR(sidecar.ext);
 
                /* Color Profiles */
 
index 7324c34..e9c1ac8 100644 (file)
@@ -311,6 +311,51 @@ gint lstat_utf8(const gchar *s, struct stat *st)
        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;
index 3ddbc99..55e26db 100644 (file)
@@ -44,6 +44,9 @@ const gchar *get_trash_dir(void);
 
 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);