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"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.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
|
|
|
|
2001-07-06 00:21:36 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "core/gimpprogress.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"
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
|
|
|
#include "widgets/gimpfiledialog.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.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-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
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
static GtkWidget * file_open_dialog_create (Gimp *gimp);
|
|
|
|
static void file_open_dialog_response (GtkWidget *open_dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp);
|
|
|
|
static gboolean file_open_dialog_open_image (GtkWidget *open_dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *entered_filename,
|
|
|
|
PlugInProcDef *load_proc);
|
2004-02-26 21:48:42 +08:00
|
|
|
|
|
|
|
|
2004-02-28 00:28:55 +08:00
|
|
|
/* private variables */
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
static GtkWidget *fileload = NULL;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
void
|
2004-07-17 05:24:39 +08:00
|
|
|
file_open_dialog_show (Gimp *gimp,
|
|
|
|
GimpImage *gimage,
|
|
|
|
const gchar *uri,
|
|
|
|
GtkWidget *parent)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
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));
|
2004-02-28 00:28:55 +08:00
|
|
|
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
if (! fileload)
|
2004-07-17 05:24:39 +08:00
|
|
|
fileload = file_open_dialog_create (gimp);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-03-01 21:40:46 +08:00
|
|
|
gimp_file_dialog_set_uri (GIMP_FILE_DIALOG (fileload), gimage, uri);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-03-01 21:40:46 +08:00
|
|
|
if (parent)
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (fileload),
|
|
|
|
gtk_widget_get_screen (parent));
|
2002-11-02 00:20:13 +08:00
|
|
|
|
2004-03-01 21:40:46 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (fileload));
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
|
|
|
|
2001-06-21 17:25:06 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
static GtkWidget *
|
2004-07-17 05:24:39 +08:00
|
|
|
file_open_dialog_create (Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2004-02-27 23:43:58 +08:00
|
|
|
GtkWidget *dialog;
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
dialog = gimp_file_dialog_new (gimp,
|
2004-04-16 00:28:26 +08:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
2004-02-27 23:43:58 +08:00
|
|
|
_("Open Image"), "gimp-file-open",
|
|
|
|
GTK_STOCK_OPEN,
|
|
|
|
GIMP_HELP_FILE_OPEN);
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
|
|
|
gimp_dialog_factory_add_foreign (global_dialog_factory,
|
2004-07-17 05:24:39 +08:00
|
|
|
"gimp-file-open-dialog", dialog);
|
2003-11-18 02:29:59 +08:00
|
|
|
|
2004-02-27 23:43:58 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (file_open_dialog_response),
|
2003-11-18 02:29:59 +08:00
|
|
|
gimp);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-02-27 23:43:58 +08:00
|
|
|
return dialog;
|
2002-05-03 20:45:22 +08:00
|
|
|
}
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
2004-02-27 23:43:58 +08:00
|
|
|
file_open_dialog_response (GtkWidget *open_dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2004-04-16 00:28:26 +08:00
|
|
|
GSList *uris;
|
|
|
|
GSList *list;
|
2004-08-11 02:47:21 +08:00
|
|
|
gboolean success = FALSE;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-03-01 21:40:46 +08:00
|
|
|
gtk_widget_hide (open_dialog);
|
2003-11-18 02:29:59 +08:00
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (open_dialog));
|
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
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
for (list = uris; list; list = g_slist_next (list))
|
2004-02-28 00:28:55 +08:00
|
|
|
{
|
2004-04-16 00:28:26 +08:00
|
|
|
gchar *filename = g_filename_from_uri (list->data, NULL, NULL);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
|
|
|
{
|
|
|
|
if (file_open_dialog_open_image (open_dialog,
|
2004-02-28 00:28:55 +08:00
|
|
|
gimp,
|
2004-04-16 00:28:26 +08:00
|
|
|
list->data,
|
|
|
|
list->data,
|
2004-02-28 00:28:55 +08:00
|
|
|
GIMP_FILE_DIALOG (open_dialog)->file_proc))
|
|
|
|
{
|
2004-08-11 02:47:21 +08:00
|
|
|
success = TRUE;
|
|
|
|
|
|
|
|
gdk_window_raise (open_dialog->window);
|
2004-02-28 00:28:55 +08:00
|
|
|
}
|
2004-04-16 00:28:26 +08:00
|
|
|
}
|
2002-04-14 22:38:55 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
g_free (filename);
|
2001-11-09 09:04:46 +08:00
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (success)
|
|
|
|
gtk_widget_hide (open_dialog);
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
gtk_widget_set_sensitive (open_dialog, TRUE);
|
2004-04-16 00:28:26 +08:00
|
|
|
|
|
|
|
g_slist_foreach (uris, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (uris);
|
2002-04-18 09:18:24 +08:00
|
|
|
}
|
|
|
|
|
2004-02-28 00:28:55 +08:00
|
|
|
static gboolean
|
2002-04-18 09:18:24 +08:00
|
|
|
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,
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_get_user_context (gimp),
|
2004-08-11 02:47:21 +08:00
|
|
|
GIMP_PROGRESS (open_dialog),
|
2003-03-05 19:25:59 +08:00
|
|
|
uri,
|
2003-11-08 01:29:02 +08:00
|
|
|
entered_filename,
|
2003-03-05 19:25:59 +08:00
|
|
|
load_proc,
|
|
|
|
&status,
|
|
|
|
&error);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2003-03-05 19:25:59 +08:00
|
|
|
if (gimage)
|
|
|
|
{
|
2004-02-28 00:28:55 +08:00
|
|
|
return TRUE;
|
2003-03-05 19:25:59 +08:00
|
|
|
}
|
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2004-02-28 00:28:55 +08:00
|
|
|
gchar *filename = file_utils_uri_to_utf8_filename (uri);
|
2003-03-05 19:25:59 +08:00
|
|
|
|
|
|
|
g_message (_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2004-02-28 00:28:55 +08:00
|
|
|
|
|
|
|
return FALSE;
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|