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"
|
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs-types.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2001-10-29 19:47:11 +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-05-09 10:32:03 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
#include "plug-in/gimppluginmanager.h"
|
2006-08-06 05:21:01 +08:00
|
|
|
#include "plug-in/gimppluginprocedure.h"
|
2006-04-29 06:26:51 +08:00
|
|
|
|
2001-10-25 21:30:01 +08:00
|
|
|
#include "file/file-save.h"
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2005-10-29 09:43:14 +08:00
|
|
|
#include "widgets/gimpactiongroup.h"
|
2004-02-27 22:20:19 +08:00
|
|
|
#include "widgets/gimpfiledialog.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2004-10-13 19:57:07 +08:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
2004-10-13 22:35:28 +08:00
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2001-11-28 03:27:55 +08:00
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
#include "file-save-dialog.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2006-04-05 16:38:33 +08:00
|
|
|
static void file_save_dialog_response (GtkWidget *save_dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp);
|
|
|
|
static gboolean file_save_dialog_check_uri (GtkWidget *save_dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
gchar **ret_uri,
|
|
|
|
gchar **ret_basename,
|
|
|
|
GimpPlugInProcedure **ret_save_proc);
|
|
|
|
static gboolean file_save_dialog_use_extension (GtkWidget *save_dialog,
|
|
|
|
const gchar *uri);
|
|
|
|
static gboolean file_save_dialog_save_image (GtkWidget *save_dialog,
|
|
|
|
GimpImage *image,
|
|
|
|
const gchar *uri,
|
|
|
|
GimpPlugInProcedure *save_proc,
|
|
|
|
gboolean save_a_copy);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2004-09-14 00:37:01 +08:00
|
|
|
GtkWidget *
|
|
|
|
file_save_dialog_new (Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2005-01-14 01:41:48 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
const gchar *uri;
|
2003-11-18 02:29:59 +08:00
|
|
|
|
2004-09-14 00:37:01 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
dialog = gimp_file_dialog_new (gimp,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
_("Save Image"), "gimp-file-save",
|
|
|
|
GTK_STOCK_SAVE,
|
|
|
|
GIMP_HELP_FILE_SAVE);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2005-01-14 01:41:48 +08:00
|
|
|
uri = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-last-uri");
|
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri);
|
2005-01-14 01:41:48 +08:00
|
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "");
|
|
|
|
}
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
2004-02-28 00:28:55 +08:00
|
|
|
G_CALLBACK (file_save_dialog_response),
|
2003-11-18 02:29:59 +08:00
|
|
|
gimp);
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
return dialog;
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
|
|
|
|
2004-09-14 00:37:01 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
2004-02-28 00:28:55 +08:00
|
|
|
file_save_dialog_response (GtkWidget *save_dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
|
|
|
|
gchar *uri;
|
|
|
|
gchar *basename;
|
|
|
|
GimpPlugInProcedure *save_proc;
|
2006-05-19 05:23:52 +08:00
|
|
|
gulong handler_id;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-08-11 05:20:38 +08:00
|
|
|
if (! dialog->busy)
|
2004-09-14 00:37:01 +08:00
|
|
|
gtk_widget_hide (save_dialog);
|
2004-08-11 05:20:38 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
gimp_file_dialog_set_sensitive (dialog, FALSE);
|
2006-05-19 05:23:52 +08:00
|
|
|
handler_id = g_signal_connect (dialog, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
&dialog);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2005-02-14 18:41:55 +08:00
|
|
|
if (file_save_dialog_check_uri (save_dialog, gimp,
|
|
|
|
&uri, &basename, &save_proc))
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
|
|
|
if (file_save_dialog_save_image (save_dialog,
|
2006-03-29 01:08:36 +08:00
|
|
|
dialog->image,
|
2005-02-14 02:05:43 +08:00
|
|
|
uri,
|
|
|
|
save_proc,
|
|
|
|
dialog->save_a_copy))
|
|
|
|
{
|
2006-05-19 04:04:29 +08:00
|
|
|
if (dialog)
|
|
|
|
gtk_widget_hide (save_dialog);
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
2005-02-14 18:41:55 +08:00
|
|
|
g_free (basename);
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
|
2006-05-19 04:04:29 +08:00
|
|
|
/* dialog may have been destroyed while save plugin was running */
|
|
|
|
if (dialog)
|
2006-05-19 05:23:52 +08:00
|
|
|
{
|
|
|
|
gimp_file_dialog_set_sensitive (dialog, TRUE);
|
|
|
|
g_signal_handler_disconnect (dialog, handler_id);
|
|
|
|
}
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2006-04-05 16:38:33 +08:00
|
|
|
file_save_dialog_check_uri (GtkWidget *save_dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
gchar **ret_uri,
|
|
|
|
gchar **ret_basename,
|
|
|
|
GimpPlugInProcedure **ret_save_proc)
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
|
|
|
|
gchar *uri;
|
|
|
|
gchar *basename;
|
|
|
|
GimpPlugInProcedure *save_proc;
|
|
|
|
GimpPlugInProcedure *uri_proc;
|
|
|
|
GimpPlugInProcedure *basename_proc;
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2004-08-11 05:20:38 +08:00
|
|
|
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (save_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
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
if (! (uri && strlen (uri)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
basename = g_path_get_basename (uri);
|
|
|
|
|
|
|
|
save_proc = dialog->file_proc;
|
2006-04-29 06:26:51 +08:00
|
|
|
uri_proc = file_utils_find_proc (gimp->plug_in_manager->save_procs,
|
2006-08-11 05:22:05 +08:00
|
|
|
uri, NULL);
|
2006-04-29 06:26:51 +08:00
|
|
|
basename_proc = file_utils_find_proc (gimp->plug_in_manager->save_procs,
|
2006-08-11 05:22:05 +08:00
|
|
|
basename, NULL);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 18:41:55 +08:00
|
|
|
g_print ("\n\n%s: URI = %s\n",
|
|
|
|
G_STRFUNC, uri);
|
|
|
|
g_print ("%s: basename = %s\n",
|
|
|
|
G_STRFUNC, basename);
|
|
|
|
g_print ("%s: selected save_proc: %s\n",
|
2006-08-08 15:51:35 +08:00
|
|
|
G_STRFUNC, save_proc && save_proc->menu_label ?
|
|
|
|
save_proc->menu_label : "NULL");
|
2005-02-14 18:41:55 +08:00
|
|
|
g_print ("%s: URI save_proc: %s\n",
|
|
|
|
G_STRFUNC, uri_proc ? uri_proc->menu_label : "NULL");
|
|
|
|
g_print ("%s: basename save_proc: %s\n\n",
|
2006-08-08 15:51:35 +08:00
|
|
|
G_STRFUNC, basename_proc && basename_proc->menu_label ?
|
|
|
|
basename_proc->menu_label : "NULL");
|
|
|
|
#endif
|
2005-02-14 18:41:55 +08:00
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
/* first check if the user entered an extension at all */
|
|
|
|
if (! basename_proc)
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: basename has no valid extension\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
if (! strchr (basename, '.'))
|
|
|
|
{
|
|
|
|
const gchar *ext = NULL;
|
|
|
|
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: basename has no '.', trying to add extension\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (! save_proc)
|
|
|
|
{
|
|
|
|
ext = "xcf";
|
|
|
|
}
|
|
|
|
else if (save_proc->extensions_list)
|
|
|
|
{
|
|
|
|
ext = save_proc->extensions_list->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext)
|
|
|
|
{
|
|
|
|
gchar *ext_uri = g_strconcat (uri, ".", ext, NULL);
|
|
|
|
gchar *ext_basename = g_strconcat (basename, ".", ext, NULL);
|
2005-02-14 18:41:55 +08:00
|
|
|
gchar *utf8;
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 18:41:55 +08:00
|
|
|
g_print ("%s: appending .%s to basename\n",
|
2005-02-14 02:05:43 +08:00
|
|
|
G_STRFUNC, ext);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
uri = ext_uri;
|
|
|
|
basename = ext_basename;
|
|
|
|
|
2006-09-10 19:55:43 +08:00
|
|
|
uri_proc = file_utils_find_proc (gimp->plug_in_manager->save_procs,
|
|
|
|
uri, NULL);
|
2006-04-29 06:26:51 +08:00
|
|
|
basename_proc = file_utils_find_proc (gimp->plug_in_manager->save_procs,
|
2006-08-11 05:22:05 +08:00
|
|
|
basename, NULL);
|
2005-02-14 18:41:55 +08:00
|
|
|
|
|
|
|
utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
|
|
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog),
|
|
|
|
utf8);
|
|
|
|
g_free (utf8);
|
2006-09-10 19:55:43 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_SPEW
|
|
|
|
g_print ("%s: set basename to %s, rerunning response and "
|
|
|
|
"bailing out\n", G_STRFUNC, basename);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* call the response callback again, so the
|
|
|
|
* overwrite-confirm logic can check the changed uri
|
|
|
|
*/
|
|
|
|
gtk_dialog_response (GTK_DIALOG (save_dialog), GTK_RESPONSE_OK);
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
return FALSE;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: save_proc has no extensions, continuing without\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
/* there may be file formats with no extension at all, use
|
|
|
|
* the selected proc in this case.
|
|
|
|
*/
|
|
|
|
basename_proc = save_proc;
|
|
|
|
|
|
|
|
if (! uri_proc)
|
|
|
|
uri_proc = basename_proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! basename_proc)
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: unable to figure save_proc, bailing out\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (save_dialog), GIMP_MESSAGE_WARNING,
|
2006-08-09 05:06:36 +08:00
|
|
|
_("The given filename does not have any known "
|
|
|
|
"file extension. Please enter a known file "
|
|
|
|
"extension or select a file format from the "
|
|
|
|
"file format list."));
|
2005-02-14 02:05:43 +08:00
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (save_proc && ! save_proc->extensions_list)
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: basename has '.', but save_proc has no extensions, "
|
|
|
|
"accepting random extension\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
/* accept any random extension if the file format has
|
|
|
|
* no extensions at all
|
|
|
|
*/
|
|
|
|
basename_proc = save_proc;
|
|
|
|
|
|
|
|
if (! uri_proc)
|
|
|
|
uri_proc = basename_proc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then check if the selected format matches the entered extension */
|
|
|
|
if (! save_proc)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: no save_proc was selected from the list\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (! basename_proc)
|
2004-03-10 18:21:03 +08:00
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: basename had no useful extension, bailing out\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (save_dialog), GIMP_MESSAGE_WARNING,
|
2006-08-10 21:12:17 +08:00
|
|
|
_("The given filename does not have any known "
|
|
|
|
"file extension. Please enter a known file "
|
|
|
|
"extension or select a file format from the "
|
|
|
|
"file format list."));
|
2005-02-14 02:05:43 +08:00
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
return FALSE;
|
2004-12-29 22:17:43 +08:00
|
|
|
}
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: use URI's proc '%s' so indirect saving works\n",
|
2005-09-26 03:30:55 +08:00
|
|
|
G_STRFUNC, uri_proc->menu_label ? uri_proc->menu_label : "?");
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
/* use the URI's proc if no save proc was selected */
|
|
|
|
save_proc = uri_proc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: save_proc '%s' was selected from the list\n",
|
|
|
|
G_STRFUNC, save_proc->menu_label);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (save_proc != basename_proc)
|
2004-12-29 22:17:43 +08:00
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: however the basename's proc is '%s'\n",
|
|
|
|
G_STRFUNC,
|
|
|
|
basename_proc ? basename_proc->menu_label : "NULL");
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (uri_proc != basename_proc)
|
2004-12-29 22:17:43 +08:00
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: that's impossible for remote URIs, bailing out\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
/* remote URI */
|
|
|
|
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (save_dialog), GIMP_MESSAGE_WARNING,
|
2006-08-10 21:12:17 +08:00
|
|
|
_("Saving remote files needs to determine the "
|
|
|
|
"file format from the file extension. "
|
|
|
|
"Please enter a file extension that matches "
|
|
|
|
"the selected file format or enter no file "
|
|
|
|
"extension at all."));
|
2005-02-14 02:05:43 +08:00
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: ask the user if she really wants that filename\n",
|
|
|
|
G_STRFUNC);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
/* local URI */
|
|
|
|
|
|
|
|
if (! file_save_dialog_use_extension (save_dialog, uri))
|
|
|
|
{
|
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-29 22:17:43 +08:00
|
|
|
}
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
else if (save_proc != uri_proc)
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
#ifdef DEBUG_SPEW
|
2005-02-14 02:05:43 +08:00
|
|
|
g_print ("%s: use URI's proc '%s' so indirect saving works\n",
|
|
|
|
G_STRFUNC, uri_proc->menu_label);
|
2006-08-08 15:51:35 +08:00
|
|
|
#endif
|
2004-12-29 22:17:43 +08:00
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
/* need to use the URI's proc for saving because e.g.
|
|
|
|
* the GIF plug-in can't save a GIF to sftp://
|
|
|
|
*/
|
|
|
|
save_proc = uri_proc;
|
2004-03-10 18:21:03 +08:00
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
2005-02-13 06:41:39 +08:00
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
if (! save_proc)
|
|
|
|
{
|
2006-08-08 15:51:35 +08:00
|
|
|
g_warning ("%s: EEEEEEK", G_STRFUNC);
|
2005-02-14 02:05:43 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
*ret_uri = uri;
|
2005-02-14 18:41:55 +08:00
|
|
|
*ret_basename = basename;
|
2005-02-14 02:05:43 +08:00
|
|
|
*ret_save_proc = save_proc;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
file_save_dialog_use_extension (GtkWidget *save_dialog,
|
|
|
|
const gchar *uri)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2005-02-14 02:05:43 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
gboolean use_name = FALSE;
|
|
|
|
|
|
|
|
dialog = gimp_message_dialog_new (_("Extension Mismatch"),
|
|
|
|
GIMP_STOCK_QUESTION,
|
|
|
|
save_dialog, GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gimp_standard_help_func, NULL,
|
|
|
|
|
2006-03-04 10:23:26 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("The given file extension does "
|
|
|
|
"not match the chosen file type."));
|
|
|
|
|
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
2006-03-04 10:23:26 +08:00
|
|
|
_("Do you want to save the image using this "
|
|
|
|
"name anyway?"));
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, FALSE);
|
|
|
|
|
|
|
|
g_object_ref (dialog);
|
|
|
|
|
|
|
|
use_name = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
g_object_unref (dialog);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, TRUE);
|
|
|
|
|
|
|
|
return use_name;
|
|
|
|
}
|
|
|
|
|
2004-03-10 18:21:03 +08:00
|
|
|
static gboolean
|
2006-04-05 16:38:33 +08:00
|
|
|
file_save_dialog_save_image (GtkWidget *save_dialog,
|
|
|
|
GimpImage *image,
|
|
|
|
const gchar *uri,
|
|
|
|
GimpPlugInProcedure *save_proc,
|
|
|
|
gboolean save_a_copy)
|
2002-04-18 09:18:24 +08:00
|
|
|
{
|
2003-03-05 19:25:59 +08:00
|
|
|
GimpPDBStatusType status;
|
2005-10-29 09:43:14 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
GList *list;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
for (list = gimp_action_groups_from_name ("file");
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gimp_action_group_set_action_sensitive (list->data, "file-quit", FALSE);
|
|
|
|
}
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_ref (image);
|
2005-01-14 01:41:48 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
status = file_save (image, gimp_get_user_context (image->gimp),
|
2005-02-14 02:05:43 +08:00
|
|
|
GIMP_PROGRESS (save_dialog),
|
|
|
|
uri, save_proc,
|
|
|
|
GIMP_RUN_INTERACTIVE, save_a_copy, &error);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2005-01-14 01:41:48 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (image->gimp), "gimp-file-save-last-uri",
|
2005-01-14 01:41:48 +08:00
|
|
|
g_strdup (uri), (GDestroyNotify) g_free);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_unref (image);
|
2005-01-14 01:41:48 +08:00
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS &&
|
|
|
|
status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2005-10-02 06:43:22 +08:00
|
|
|
gchar *filename = file_utils_uri_display_name (uri);
|
2003-03-05 19:25:59 +08:00
|
|
|
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (image->gimp, G_OBJECT (save_dialog), GIMP_MESSAGE_ERROR,
|
2006-08-09 05:06:36 +08:00
|
|
|
_("Saving '%s' failed:\n\n%s"), filename, error->message);
|
2003-03-05 19:25:59 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
2004-03-10 18:21:03 +08:00
|
|
|
|
2005-10-29 09:43:14 +08:00
|
|
|
success = FALSE;
|
2002-04-18 09:18:24 +08:00
|
|
|
}
|
2004-03-10 18:21:03 +08:00
|
|
|
|
2005-10-29 09:43:14 +08:00
|
|
|
for (list = gimp_action_groups_from_name ("file");
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gimp_action_group_set_action_sensitive (list->data, "file-quit", TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
2002-04-18 09:18:24 +08:00
|
|
|
}
|