Slightly modify access_file() and use it to test profile files existence and read...
authorLaurent Monin <geeqie@norz.org>
Sun, 1 Mar 2009 15:41:51 +0000 (15:41 +0000)
committerLaurent Monin <geeqie@norz.org>
Sun, 1 Mar 2009 15:41:51 +0000 (15:41 +0000)
src/image.c
src/layout.c
src/ui_fileops.c

index 4becafa..447d325 100644 (file)
@@ -204,13 +204,12 @@ static gint image_post_process_color(ImageWindow *imd, gint start_row, ExifData
        if (imd->color_profile_input >= COLOR_PROFILE_FILE &&
            imd->color_profile_input <  COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS)
                {
-               gint n;
-
-               n = imd->color_profile_input - COLOR_PROFILE_FILE;
-               if (!options->color_profile.input_file[n] || !options->color_profile.input_file[n][0]) return FALSE;
+               const gchar *file = options->color_profile.input_file[imd->color_profile_input - COLOR_PROFILE_FILE];
+       
+               if (!access_file(file, R_OK)) return FALSE;
 
                input_type = COLOR_PROFILE_FILE;
-               input_file = options->color_profile.input_file[n];
+               input_file = file;
                }
        else if (imd->color_profile_input >= COLOR_PROFILE_SRGB &&
                 imd->color_profile_input <  COLOR_PROFILE_FILE)
@@ -224,8 +223,7 @@ static gint image_post_process_color(ImageWindow *imd, gint start_row, ExifData
                }
 
        if (imd->color_profile_screen == 1 &&
-           options->color_profile.screen_file &&
-           options->color_profile.screen_file[0])
+           access_file(options->color_profile.screen_file, R_OK))
                {
                screen_type = COLOR_PROFILE_FILE;
                screen_file = options->color_profile.screen_file;
index 23cb060..7c8cbde 100644 (file)
@@ -482,7 +482,7 @@ static void layout_color_button_press_cb(GtkWidget *widget, gpointer data)
                                           G_CALLBACK(layout_color_menu_input_cb), lw);
                g_free(buf);
                g_object_set_data(G_OBJECT(item), COLOR_MENU_KEY, GINT_TO_POINTER(i + COLOR_PROFILE_FILE));
-               gtk_widget_set_sensitive(item, active && !from_image && file && file[0] && access_file(file, R_OK));
+               gtk_widget_set_sensitive(item, active && !from_image && access_file(file, R_OK));
                }
 
        menu_item_add_divider(menu);
@@ -498,7 +498,7 @@ static void layout_color_button_press_cb(GtkWidget *widget, gpointer data)
                                   _("_Screen profile"), (screen == 1),
                                   G_CALLBACK(layout_color_menu_screen_cb), lw);
        g_object_set_data(G_OBJECT(item), COLOR_MENU_KEY, GINT_TO_POINTER(1));
-       gtk_widget_set_sensitive(item, active && options->color_profile.screen_file && options->color_profile.screen_file[0]);
+       gtk_widget_set_sensitive(item, active && access_file(options->color_profile.screen_file, R_OK));
 
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME);
 #endif /* HAVE_LCMS */
index f4c1b40..9815198 100644 (file)
@@ -424,7 +424,7 @@ gint access_file(const gchar *s, gint mode)
        gchar *sl;
        gint ret;
 
-       if (!s) return FALSE;
+       if (!s || !s[0]) return FALSE;
 
        sl = path_from_utf8(s);
        ret = (access(sl, mode) == 0);