2001-04-28 23:11:29 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
|
|
|
|
* Copyright (C) 1997 Josh MacDonald
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-01-26 02:34:33 +08:00
|
|
|
#include "gui-types.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-07-06 00:21:36 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
2002-04-17 07:03:23 +08:00
|
|
|
#include "core/gimpimage-new.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
#include "core/gimpimagefile.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-12-19 08:13:16 +08:00
|
|
|
#include "plug-in/plug-in-proc.h"
|
2001-12-01 08:14:14 +08:00
|
|
|
|
2001-10-25 21:30:01 +08:00
|
|
|
#include "file/file-open.h"
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
#include "widgets/gimpmenufactory.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
#include "widgets/gimppreview.h"
|
2002-12-20 00:33:29 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2001-11-28 03:27:55 +08:00
|
|
|
|
2003-05-04 07:02:26 +08:00
|
|
|
#include "dialogs.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
#include "file-dialog-utils.h"
|
|
|
|
#include "file-open-dialog.h"
|
2001-07-05 03:31:35 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
/* local function prototypes */
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
static GtkWidget * file_open_dialog_create (Gimp *gimp,
|
|
|
|
GimpMenuFactory *menu_factory);
|
2002-04-18 09:18:24 +08:00
|
|
|
static void file_open_selchanged_callback (GtkTreeSelection *sel,
|
|
|
|
GtkWidget *open_dialog);
|
|
|
|
static void file_open_imagefile_info_changed (GimpImagefile *imagefile,
|
|
|
|
GtkLabel *label);
|
2002-04-18 22:14:50 +08:00
|
|
|
static gboolean file_open_thumbnail_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GtkWidget *open_dialog);
|
|
|
|
static void file_open_thumbnail_clicked (GtkWidget *widget,
|
2003-03-20 23:49:48 +08:00
|
|
|
GdkModifierType state,
|
2002-05-03 20:45:22 +08:00
|
|
|
GtkWidget *open_dialog);
|
2002-04-18 09:18:24 +08:00
|
|
|
static void file_open_ok_callback (GtkWidget *widget,
|
|
|
|
GtkWidget *open_dialog);
|
|
|
|
static void file_open_dialog_open_image (GtkWidget *open_dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *entered_filename,
|
|
|
|
PlugInProcDef *load_proc);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
2002-04-19 02:55:31 +08:00
|
|
|
static GtkWidget *fileload = NULL;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-19 02:55:31 +08:00
|
|
|
static GtkWidget *open_options_frame = NULL;
|
|
|
|
static GtkWidget *open_options_title = NULL;
|
|
|
|
static GimpImagefile *open_options_imagefile = NULL;
|
|
|
|
static GtkWidget *open_options_preview = NULL;
|
|
|
|
static GtkWidget *open_options_label = NULL;
|
|
|
|
static GtkProgressBar *open_options_progress = NULL;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-30 01:20:26 +08:00
|
|
|
static PlugInProcDef *load_file_proc = NULL;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2003-01-11 01:55:53 +08:00
|
|
|
file_open_dialog_set_type (PlugInProcDef *proc)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2003-06-16 22:38:00 +08:00
|
|
|
/* Don't call file_dialog_update_name() here, see bug #112273. */
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
load_file_proc = proc;
|
2001-07-10 01:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-01-11 01:55:53 +08:00
|
|
|
file_open_dialog_show (Gimp *gimp,
|
|
|
|
GimpImage *gimage,
|
|
|
|
const gchar *uri,
|
|
|
|
GimpMenuFactory *menu_factory)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2002-11-02 00:20:13 +08:00
|
|
|
gchar *filename = NULL;
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
2002-11-02 00:20:13 +08:00
|
|
|
g_return_if_fail (gimage == NULL || GIMP_IS_IMAGE (gimage));
|
2003-01-11 01:55:53 +08:00
|
|
|
g_return_if_fail (GIMP_IS_MENU_FACTORY (menu_factory));
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
if (! fileload)
|
2003-01-11 01:55:53 +08:00
|
|
|
fileload = file_open_dialog_create (gimp, menu_factory);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
|
2002-11-02 00:20:13 +08:00
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
if (GTK_WIDGET_VISIBLE (fileload))
|
2002-11-02 00:20:13 +08:00
|
|
|
{
|
|
|
|
gtk_window_present (GTK_WINDOW (fileload));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimage)
|
|
|
|
{
|
|
|
|
filename = gimp_image_get_filename (gimage);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
gchar *dirname;
|
|
|
|
|
|
|
|
dirname = g_path_get_dirname (filename);
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
filename = g_build_filename (dirname, ".", NULL);
|
|
|
|
g_free (dirname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (uri)
|
|
|
|
{
|
|
|
|
filename = g_filename_from_uri (uri, NULL, NULL);
|
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2001-10-24 19:23:50 +08:00
|
|
|
gtk_window_set_title (GTK_WINDOW (fileload), _("Open Image"));
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-11-02 00:20:13 +08:00
|
|
|
gtk_file_selection_set_filename (GTK_FILE_SELECTION (fileload),
|
|
|
|
filename ?
|
|
|
|
filename :
|
|
|
|
"." G_DIR_SEPARATOR_S);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
file_dialog_show (fileload);
|
|
|
|
}
|
|
|
|
|
2001-06-21 17:25:06 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
static GtkWidget *
|
2003-01-11 01:55:53 +08:00
|
|
|
file_open_dialog_create (Gimp *gimp,
|
|
|
|
GimpMenuFactory *menu_factory)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2002-04-18 09:18:24 +08:00
|
|
|
GtkWidget *open_dialog;
|
|
|
|
GtkFileSelection *fs;
|
2002-02-11 03:51:20 +08:00
|
|
|
GtkTreeSelection *tree_sel;
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
open_dialog = file_dialog_new (gimp,
|
2003-05-04 07:02:26 +08:00
|
|
|
global_dialog_factory,
|
|
|
|
"gimp-file-open-dialog",
|
2003-01-11 01:55:53 +08:00
|
|
|
menu_factory, "<Load>",
|
2002-04-18 09:18:24 +08:00
|
|
|
_("Open Image"), "open_image",
|
|
|
|
"open/dialogs/file_open.html",
|
|
|
|
G_CALLBACK (file_open_ok_callback));
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
fs = GTK_FILE_SELECTION (open_dialog);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gtk_file_selection_set_select_multiple (fs, TRUE);
|
|
|
|
tree_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (fs->file_list));
|
2002-02-11 03:51:20 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
/* The preview frame */
|
2002-04-30 03:41:45 +08:00
|
|
|
if (gimp->config->thumbnail_size > 0)
|
2002-04-19 02:55:31 +08:00
|
|
|
{
|
2002-04-30 03:41:45 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *vbox2;
|
|
|
|
GtkWidget *ebox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *progress;
|
|
|
|
GtkStyle *style;
|
2002-12-20 00:33:29 +08:00
|
|
|
gchar *str;
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
|
|
/* Catch file-list clicks so we can update the preview thumbnail */
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (tree_sel, "changed",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (file_open_selchanged_callback),
|
|
|
|
open_dialog);
|
|
|
|
|
|
|
|
open_options_frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (open_options_frame),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
|
|
|
|
ebox = gtk_event_box_new ();
|
|
|
|
|
|
|
|
gtk_widget_ensure_style (ebox);
|
|
|
|
style = gtk_widget_get_style (ebox);
|
|
|
|
gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL,
|
|
|
|
&style->base[GTK_STATE_NORMAL]);
|
|
|
|
gtk_widget_modify_bg (ebox, GTK_STATE_INSENSITIVE,
|
|
|
|
&style->base[GTK_STATE_NORMAL]);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (open_options_frame), ebox);
|
|
|
|
gtk_widget_show (ebox);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (ebox, "button_press_event",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (file_open_thumbnail_button_press),
|
|
|
|
open_dialog);
|
|
|
|
|
2002-12-20 00:33:29 +08:00
|
|
|
str = g_strdup_printf (_("Click to update preview\n"
|
|
|
|
"%s Click to force update even "
|
|
|
|
"if preview is up-to-date"),
|
|
|
|
gimp_get_mod_name_control ());
|
|
|
|
|
|
|
|
gimp_help_set_help_data (ebox, str, NULL);
|
|
|
|
|
|
|
|
g_free (str);
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (ebox), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
button = gtk_button_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Preview"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (button, "button_press_event",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (button, "button_release_event",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (button, "enter_notify_event",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (button, "leave_notify_event",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
vbox2 = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), vbox2);
|
|
|
|
gtk_widget_show (vbox2);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (TRUE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
open_options_imagefile = gimp_imagefile_new (gimp, NULL);
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
|
|
open_options_preview =
|
|
|
|
gimp_preview_new (GIMP_VIEWABLE (open_options_imagefile),
|
|
|
|
gimp->config->thumbnail_size, 0, FALSE);
|
|
|
|
|
|
|
|
gtk_widget_ensure_style (open_options_preview);
|
|
|
|
style = gtk_widget_get_style (open_options_preview);
|
|
|
|
gtk_widget_modify_bg (open_options_preview, GTK_STATE_NORMAL,
|
|
|
|
&style->base[GTK_STATE_NORMAL]);
|
|
|
|
gtk_widget_modify_bg (open_options_preview, GTK_STATE_INSENSITIVE,
|
|
|
|
&style->base[GTK_STATE_NORMAL]);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox),
|
|
|
|
open_options_preview, TRUE, FALSE, 10);
|
|
|
|
gtk_widget_show (open_options_preview);
|
|
|
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), open_options_preview);
|
2002-05-03 20:45:22 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (open_options_preview, "clicked",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (file_open_thumbnail_clicked),
|
|
|
|
open_dialog);
|
|
|
|
|
|
|
|
open_options_title = gtk_label_new (_("No Selection"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2),
|
|
|
|
open_options_title, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (open_options_title);
|
|
|
|
|
|
|
|
label = gtk_label_new (" \n \n ");
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.0);
|
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
/* eek */
|
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
|
|
|
|
gtk_widget_size_request (label, &requisition);
|
|
|
|
gtk_widget_set_size_request (label, -1, requisition.height);
|
|
|
|
}
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (open_options_imagefile, "info_changed",
|
2002-04-30 03:41:45 +08:00
|
|
|
G_CALLBACK (file_open_imagefile_info_changed),
|
|
|
|
label);
|
|
|
|
|
|
|
|
open_options_label = label;
|
|
|
|
|
|
|
|
/* pack the containing open_options hbox into the open-dialog */
|
|
|
|
for (hbox = fs->dir_list; ! GTK_IS_HBOX (hbox); hbox = hbox->parent);
|
|
|
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), open_options_frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (open_options_frame);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (open_options_frame), FALSE);
|
|
|
|
|
|
|
|
/* The progress bar */
|
|
|
|
|
|
|
|
progress = gtk_progress_bar_new ();
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox2), progress, FALSE, FALSE, 0);
|
|
|
|
/* don't gtk_widget_show (progress); */
|
|
|
|
|
|
|
|
open_options_progress = GTK_PROGRESS_BAR (progress);
|
|
|
|
|
|
|
|
/* eek */
|
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
|
|
|
|
gtk_progress_bar_set_text (open_options_progress, "foo");
|
|
|
|
gtk_widget_size_request (progress, &requisition);
|
|
|
|
gtk_widget_set_size_request (open_options_title, requisition.width, -1);
|
|
|
|
}
|
2002-04-19 02:55:31 +08:00
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
return open_dialog;
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-17 04:25:27 +08:00
|
|
|
file_open_imagefile_info_changed (GimpImagefile *imagefile,
|
2002-04-18 09:18:24 +08:00
|
|
|
GtkLabel *label)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2003-04-09 00:01:01 +08:00
|
|
|
gtk_label_set_text (label, gimp_imagefile_get_desc_string (imagefile));
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
|
|
|
|
2002-01-31 16:50:14 +08:00
|
|
|
static void
|
|
|
|
selchanged_foreach (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *selected = data;
|
|
|
|
|
|
|
|
*selected = TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
2002-01-30 16:31:00 +08:00
|
|
|
file_open_selchanged_callback (GtkTreeSelection *sel,
|
2002-04-18 09:18:24 +08:00
|
|
|
GtkWidget *open_dialog)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2002-04-18 09:18:24 +08:00
|
|
|
GtkFileSelection *fs;
|
2001-10-29 19:47:11 +08:00
|
|
|
Gimp *gimp;
|
|
|
|
const gchar *fullfname;
|
2002-01-31 16:50:14 +08:00
|
|
|
gboolean selected = FALSE;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-01-31 16:50:14 +08:00
|
|
|
gtk_tree_selection_selected_foreach (sel,
|
|
|
|
selchanged_foreach,
|
|
|
|
&selected);
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
|
|
fs = GTK_FILE_SELECTION (open_dialog);
|
|
|
|
|
|
|
|
gimp = GIMP (g_object_get_data (G_OBJECT (open_dialog), "gimp"));
|
|
|
|
|
2002-01-31 16:50:14 +08:00
|
|
|
if (selected)
|
2002-01-30 16:31:00 +08:00
|
|
|
{
|
2002-04-17 04:25:27 +08:00
|
|
|
gchar *uri;
|
2002-04-17 21:48:22 +08:00
|
|
|
gchar *basename;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
fullfname = gtk_file_selection_get_filename (fs);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-30 03:41:45 +08:00
|
|
|
uri = file_utils_filename_to_uri (gimp->load_procs, fullfname, NULL);
|
2002-04-17 21:48:22 +08:00
|
|
|
basename = file_utils_uri_to_utf8_basename (uri);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), uri);
|
2002-04-17 21:48:22 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (open_options_title), basename);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
|
|
g_free (uri);
|
2002-04-17 21:48:22 +08:00
|
|
|
g_free (basename);
|
2002-04-17 04:25:27 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), NULL);
|
2002-04-17 21:48:22 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (open_options_title), _("No Selection"));
|
2002-01-30 16:31:00 +08:00
|
|
|
}
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (open_options_frame), selected);
|
2002-04-30 03:41:45 +08:00
|
|
|
gimp_imagefile_update (open_options_imagefile, gimp->config->thumbnail_size);
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
static void
|
2003-01-25 01:38:24 +08:00
|
|
|
file_open_create_thumbnail (Gimp *gimp,
|
|
|
|
const gchar *filename,
|
2002-05-03 20:45:22 +08:00
|
|
|
GimpThumbnailSize size,
|
|
|
|
gboolean always_create)
|
2002-04-18 09:18:24 +08:00
|
|
|
{
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
|
|
|
{
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
gchar *basename;
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
uri = g_filename_to_uri (filename, NULL, NULL);
|
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
imagefile = gimp_imagefile_new (gimp, uri);
|
2002-05-03 20:45:22 +08:00
|
|
|
|
|
|
|
if (always_create)
|
|
|
|
{
|
|
|
|
gimp_imagefile_create_thumbnail (imagefile, size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_imagefile_update (imagefile, size);
|
|
|
|
gimp_viewable_get_preview (GIMP_VIEWABLE (imagefile), size, size);
|
|
|
|
|
|
|
|
if (imagefile->state < GIMP_IMAGEFILE_STATE_THUMBNAIL_FAILED)
|
|
|
|
gimp_imagefile_create_thumbnail (imagefile, size);
|
|
|
|
}
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (imagefile);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
|
|
|
basename = file_utils_uri_to_utf8_basename (uri);
|
|
|
|
gtk_label_set_text (GTK_LABEL (open_options_title), basename);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), uri);
|
2002-04-30 03:41:45 +08:00
|
|
|
gimp_imagefile_update (open_options_imagefile, size);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
2002-05-03 20:45:22 +08:00
|
|
|
file_open_create_thumbnails (GtkWidget *open_dialog,
|
|
|
|
gboolean always_create)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2002-02-17 08:46:56 +08:00
|
|
|
GtkFileSelection *fs;
|
2002-04-17 04:25:27 +08:00
|
|
|
Gimp *gimp;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
fs = GTK_FILE_SELECTION (open_dialog);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp"));
|
|
|
|
|
2003-03-12 05:04:09 +08:00
|
|
|
if (gimp->config->thumbnail_size != GIMP_THUMBNAIL_SIZE_NONE &&
|
|
|
|
gimp->config->layer_previews)
|
2001-11-09 09:04:46 +08:00
|
|
|
{
|
2002-04-18 09:18:24 +08:00
|
|
|
gchar **selections;
|
2002-04-19 02:55:31 +08:00
|
|
|
gint n_selections;
|
2002-04-18 09:18:24 +08:00
|
|
|
gint i;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gimp_set_busy (gimp);
|
|
|
|
gtk_widget_set_sensitive (open_dialog, FALSE);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
selections = gtk_file_selection_get_selections (fs);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-19 02:55:31 +08:00
|
|
|
n_selections = 0;
|
|
|
|
for (i = 0; selections[i] != NULL; i++)
|
|
|
|
n_selections++;
|
|
|
|
|
|
|
|
if (n_selections > 1)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_set_text (open_options_progress, NULL);
|
|
|
|
gtk_progress_bar_set_fraction (open_options_progress, 0.0);
|
|
|
|
|
|
|
|
gtk_widget_hide (open_options_label);
|
|
|
|
gtk_widget_show (GTK_WIDGET (open_options_progress));
|
|
|
|
}
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
for (i = 1; selections[i] != NULL; i++)
|
2002-04-19 02:55:31 +08:00
|
|
|
{
|
|
|
|
if (n_selections > 1)
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("Thumbnail %d of %d"),
|
|
|
|
i, n_selections);
|
|
|
|
gtk_progress_bar_set_text (open_options_progress, str);
|
|
|
|
g_free (str);
|
2002-05-03 20:45:22 +08:00
|
|
|
|
|
|
|
while (g_main_context_pending (NULL))
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
2002-04-19 02:55:31 +08:00
|
|
|
}
|
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
file_open_create_thumbnail (gimp,
|
|
|
|
selections[i],
|
2002-05-03 20:45:22 +08:00
|
|
|
gimp->config->thumbnail_size,
|
|
|
|
always_create);
|
2002-04-19 02:55:31 +08:00
|
|
|
|
|
|
|
if (n_selections > 1)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_set_fraction (open_options_progress,
|
|
|
|
(gdouble) i /
|
|
|
|
(gdouble) n_selections);
|
2002-05-03 20:45:22 +08:00
|
|
|
|
|
|
|
while (g_main_context_pending (NULL))
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
2002-04-19 02:55:31 +08:00
|
|
|
}
|
|
|
|
}
|
2001-11-09 09:04:46 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
if (selections[0])
|
2002-04-19 02:55:31 +08:00
|
|
|
{
|
|
|
|
if (n_selections > 1)
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("Thumbnail %d of %d"),
|
|
|
|
n_selections, n_selections);
|
|
|
|
gtk_progress_bar_set_text (open_options_progress, str);
|
|
|
|
g_free (str);
|
2002-05-03 20:45:22 +08:00
|
|
|
|
|
|
|
while (g_main_context_pending (NULL))
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
|
|
|
}
|
2002-04-19 02:55:31 +08:00
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
file_open_create_thumbnail (gimp,
|
|
|
|
selections[0],
|
2002-05-03 20:45:22 +08:00
|
|
|
gimp->config->thumbnail_size,
|
|
|
|
always_create);
|
2002-04-19 02:55:31 +08:00
|
|
|
|
|
|
|
if (n_selections > 1)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_set_fraction (open_options_progress, 1.0);
|
2002-05-03 20:45:22 +08:00
|
|
|
|
|
|
|
while (g_main_context_pending (NULL))
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
2002-04-19 02:55:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_selections > 1)
|
|
|
|
{
|
|
|
|
gtk_widget_hide (GTK_WIDGET (open_options_progress));
|
|
|
|
gtk_widget_show (open_options_label);
|
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
g_strfreev (selections);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (open_dialog, TRUE);
|
|
|
|
gimp_unset_busy (gimp);
|
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
static gboolean
|
|
|
|
file_open_thumbnail_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GtkWidget *open_dialog)
|
|
|
|
{
|
|
|
|
gboolean always_create;
|
|
|
|
|
|
|
|
always_create = (bevent->state & GDK_CONTROL_MASK) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
file_open_create_thumbnails (open_dialog, always_create);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-20 23:49:48 +08:00
|
|
|
file_open_thumbnail_clicked (GtkWidget *widget,
|
|
|
|
GdkModifierType state,
|
|
|
|
GtkWidget *open_dialog)
|
2002-05-03 20:45:22 +08:00
|
|
|
{
|
|
|
|
gboolean always_create;
|
|
|
|
|
|
|
|
always_create = (state & GDK_CONTROL_MASK) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
file_open_create_thumbnails (open_dialog, always_create);
|
|
|
|
}
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
|
|
|
file_open_ok_callback (GtkWidget *widget,
|
2002-04-18 09:18:24 +08:00
|
|
|
GtkWidget *open_dialog)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2002-04-18 09:18:24 +08:00
|
|
|
GtkFileSelection *fs;
|
|
|
|
Gimp *gimp;
|
|
|
|
gchar **selections;
|
|
|
|
gchar *uri;
|
|
|
|
const gchar *entered_filename;
|
|
|
|
gint i;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
fs = GTK_FILE_SELECTION (open_dialog);
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gimp = GIMP (g_object_get_data (G_OBJECT (open_dialog), "gimp"));
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-02-17 08:46:56 +08:00
|
|
|
selections = gtk_file_selection_get_selections (fs);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-02-17 08:46:56 +08:00
|
|
|
if (selections == NULL)
|
2001-04-28 23:11:29 +08:00
|
|
|
return;
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
entered_filename = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
|
|
|
|
|
2002-04-19 22:09:53 +08:00
|
|
|
if (g_file_test (selections[0], G_FILE_TEST_IS_DIR))
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2002-04-19 22:09:53 +08:00
|
|
|
if (selections[0][strlen (selections[0]) - 1] != G_DIR_SEPARATOR)
|
2001-10-24 23:56:33 +08:00
|
|
|
{
|
2002-04-19 22:09:53 +08:00
|
|
|
gchar *s = g_strconcat (selections[0], G_DIR_SEPARATOR_S, NULL);
|
|
|
|
gtk_file_selection_set_filename (fs, s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_file_selection_set_filename (fs, selections[0]);
|
2002-04-18 09:18:24 +08:00
|
|
|
}
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2002-04-19 22:09:53 +08:00
|
|
|
g_strfreev (selections);
|
|
|
|
|
|
|
|
return;
|
2002-04-14 22:38:55 +08:00
|
|
|
}
|
2002-04-19 22:09:53 +08:00
|
|
|
|
|
|
|
if (strstr (entered_filename, "://"))
|
2002-04-14 22:38:55 +08:00
|
|
|
{
|
2002-04-19 22:09:53 +08:00
|
|
|
/* try with the entered filename if it looks like an URI */
|
2002-04-18 09:18:24 +08:00
|
|
|
|
|
|
|
uri = g_strdup (entered_filename);
|
2002-04-14 22:38:55 +08:00
|
|
|
}
|
2002-04-19 22:09:53 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
uri = g_filename_to_uri (selections[0], NULL, NULL);
|
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gtk_widget_set_sensitive (open_dialog, FALSE);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
file_open_dialog_open_image (open_dialog,
|
|
|
|
gimp,
|
|
|
|
uri,
|
|
|
|
entered_filename,
|
|
|
|
load_file_proc);
|
2002-04-14 22:38:55 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
g_free (uri);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
/*
|
2002-01-30 16:31:00 +08:00
|
|
|
* Now deal with multiple selections from the filesel list
|
2001-04-28 23:11:29 +08:00
|
|
|
*/
|
|
|
|
|
2002-02-17 08:46:56 +08:00
|
|
|
for (i = 1; selections[i] != NULL; i++)
|
2001-11-09 09:04:46 +08:00
|
|
|
{
|
2002-04-17 04:25:27 +08:00
|
|
|
if (g_file_test (selections[i], G_FILE_TEST_IS_REGULAR))
|
2002-04-14 22:38:55 +08:00
|
|
|
{
|
2002-04-17 04:25:27 +08:00
|
|
|
uri = g_filename_to_uri (selections[i], NULL, NULL);
|
2002-04-14 22:38:55 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
file_open_dialog_open_image (open_dialog,
|
|
|
|
gimp,
|
|
|
|
uri,
|
|
|
|
uri,
|
|
|
|
load_file_proc);
|
2002-04-14 22:38:55 +08:00
|
|
|
|
|
|
|
g_free (uri);
|
2002-02-17 08:46:56 +08:00
|
|
|
}
|
2001-11-09 09:04:46 +08:00
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2002-02-17 08:46:56 +08:00
|
|
|
g_strfreev (selections);
|
2001-11-09 09:04:46 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gtk_widget_set_sensitive (open_dialog, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_open_dialog_open_image (GtkWidget *open_dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *entered_filename,
|
|
|
|
PlugInProcDef *load_proc)
|
|
|
|
{
|
2003-03-05 19:25:59 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2003-03-05 19:25:59 +08:00
|
|
|
gimage = file_open_with_proc_and_display (gimp,
|
|
|
|
uri,
|
|
|
|
entered_filename,
|
|
|
|
load_proc,
|
|
|
|
&status,
|
|
|
|
&error);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2003-03-05 19:25:59 +08:00
|
|
|
if (gimage)
|
|
|
|
{
|
|
|
|
file_dialog_hide (open_dialog);
|
|
|
|
}
|
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = file_utils_uri_to_utf8_filename (uri);
|
|
|
|
|
|
|
|
g_message (_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|