2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-04-28 23:11:29 +08:00
|
|
|
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
|
|
|
|
* Copyright (C) 1997 Josh MacDonald
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-04-28 23:11:29 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-04-28 23:11:29 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-04-28 23:11:29 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-04-28 23:11:29 +08:00
|
|
|
#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
|
|
|
|
2007-05-12 02:50:35 +08:00
|
|
|
#include "file/file-procedure.h"
|
2001-10-25 21:30:01 +08:00
|
|
|
#include "file/file-save.h"
|
|
|
|
#include "file/file-utils.h"
|
2009-05-01 15:03:13 +08:00
|
|
|
#include "file/gimp-file.h"
|
2001-10-25 21:30:01 +08:00
|
|
|
|
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
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
#include "file-save-dialog.h"
|
|
|
|
|
2007-11-19 01:55:52 +08:00
|
|
|
#include "gimp-log.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 */
|
|
|
|
|
2009-04-26 00:11:21 +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 void file_save_dialog_unknown_ext_msg (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp);
|
|
|
|
static gboolean file_save_dialog_use_extension (GtkWidget *save_dialog,
|
|
|
|
const gchar *uri);
|
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
|
|
|
{
|
2008-05-08 19:30:54 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GimpFileDialogState *state;
|
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
|
|
|
|
2008-05-08 19:30:54 +08:00
|
|
|
state = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-dialog-state");
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
gimp_file_dialog_set_state (GIMP_FILE_DIALOG (dialog), state);
|
|
|
|
|
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;
|
2008-05-17 22:07:25 +08:00
|
|
|
gulong handler_id;
|
2008-05-08 19:30:54 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (gimp), "gimp-file-save-dialog-state",
|
|
|
|
gimp_file_dialog_get_state (dialog),
|
|
|
|
(GDestroyNotify) gimp_file_dialog_state_destroy);
|
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)
|
2008-05-08 19:30:54 +08:00
|
|
|
gtk_widget_destroy (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);
|
2008-05-17 22:07:25 +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
|
|
|
{
|
2009-05-02 21:58:32 +08:00
|
|
|
if (file_save_dialog_save_image (GIMP_PROGRESS (save_dialog),
|
|
|
|
gimp,
|
2006-03-29 01:08:36 +08:00
|
|
|
dialog->image,
|
2005-02-14 02:05:43 +08:00
|
|
|
uri,
|
|
|
|
save_proc,
|
2009-05-02 21:58:32 +08:00
|
|
|
GIMP_RUN_INTERACTIVE,
|
|
|
|
dialog->save_a_copy,
|
|
|
|
FALSE))
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
2009-05-03 15:29:04 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (dialog->image->gimp),
|
|
|
|
GIMP_FILE_SAVE_LAST_URI_KEY,
|
|
|
|
g_strdup (uri), (GDestroyNotify) g_free);
|
|
|
|
|
2006-05-19 04:04:29 +08:00
|
|
|
if (dialog)
|
2007-01-21 03:38:09 +08:00
|
|
|
{
|
2008-05-08 19:30:54 +08:00
|
|
|
GtkWindow *parent;
|
2007-01-21 03:38:09 +08:00
|
|
|
|
2008-05-08 19:30:54 +08:00
|
|
|
parent = gtk_window_get_transient_for (GTK_WINDOW (dialog));
|
2007-01-21 03:38:09 +08:00
|
|
|
|
2008-05-08 19:30:54 +08:00
|
|
|
if (dialog->close_after_saving)
|
|
|
|
{
|
2007-01-21 03:38:09 +08:00
|
|
|
if (GIMP_IS_DISPLAY_SHELL (parent))
|
|
|
|
{
|
|
|
|
GimpDisplay *display;
|
|
|
|
|
|
|
|
display = GIMP_DISPLAY_SHELL (parent)->display;
|
|
|
|
|
|
|
|
if (! display->image->dirty)
|
2008-04-06 04:32:24 +08:00
|
|
|
gimp_display_close (display);
|
2007-01-21 03:38:09 +08:00
|
|
|
}
|
|
|
|
}
|
2008-05-17 22:07:25 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (save_dialog);
|
2007-01-21 03:38:09 +08:00
|
|
|
}
|
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
|
|
|
}
|
2008-05-17 22:07:25 +08:00
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2007-12-26 00:10:22 +08:00
|
|
|
basename = file_utils_uri_display_basename (uri);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
save_proc = dialog->file_proc;
|
2007-05-12 02:50:35 +08:00
|
|
|
uri_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
|
|
|
|
uri, NULL);
|
|
|
|
basename_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
|
|
|
|
basename, NULL);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2007-12-26 00:10:22 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "URI = %s", uri);
|
|
|
|
GIMP_LOG (SAVE_DIALOG, "basename = %s", basename);
|
|
|
|
GIMP_LOG (SAVE_DIALOG, "selected save_proc: %s",
|
|
|
|
save_proc && save_proc->menu_label ?
|
|
|
|
save_proc->menu_label : "NULL");
|
|
|
|
GIMP_LOG (SAVE_DIALOG, "URI save_proc: %s",
|
|
|
|
uri_proc ? uri_proc->menu_label : "NULL");
|
|
|
|
GIMP_LOG (SAVE_DIALOG, "basename save_proc: %s",
|
|
|
|
basename_proc && basename_proc->menu_label ?
|
|
|
|
basename_proc->menu_label : "NULL");
|
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)
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "basename has no valid extension");
|
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
if (! strchr (basename, '.'))
|
|
|
|
{
|
|
|
|
const gchar *ext = NULL;
|
|
|
|
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "basename has no '.', trying to add extension");
|
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
|
|
|
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "appending .%s to basename", ext);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
uri = ext_uri;
|
|
|
|
basename = ext_basename;
|
|
|
|
|
2007-05-12 02:50:35 +08:00
|
|
|
uri_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
|
2006-09-10 19:55:43 +08:00
|
|
|
uri, NULL);
|
2007-05-12 02:50:35 +08:00
|
|
|
basename_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
|
|
|
|
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
|
|
|
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"set basename to %s, rerunning response and bailing out",
|
|
|
|
basename);
|
2006-09-10 19:55:43 +08:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"save_proc has no extensions, continuing without");
|
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)
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"unable to figure save_proc, bailing out");
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2009-04-26 00:11:21 +08:00
|
|
|
file_save_dialog_unknown_ext_msg (dialog, gimp);
|
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
g_free (uri);
|
|
|
|
g_free (basename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (save_proc && ! save_proc->extensions_list)
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"basename has '.', but save_proc has no extensions, "
|
|
|
|
"accepting random extension");
|
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
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "no save_proc was selected from the list");
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (! basename_proc)
|
2004-03-10 18:21:03 +08:00
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"basename has no useful extension, bailing out");
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2009-04-26 00:11:21 +08:00
|
|
|
file_save_dialog_unknown_ext_msg (dialog, gimp);
|
|
|
|
|
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
|
|
|
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "use URI's proc '%s' so indirect saving works",
|
|
|
|
uri_proc->menu_label ? uri_proc->menu_label : "<unnamed>");
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
/* use the URI's proc if no save proc was selected */
|
|
|
|
save_proc = uri_proc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "save_proc '%s' was selected from the list",
|
|
|
|
save_proc->menu_label ? save_proc->menu_label : "<unnamed>");
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (save_proc != basename_proc)
|
2004-12-29 22:17:43 +08:00
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG, "however the basename's proc is '%s'",
|
|
|
|
basename_proc ? basename_proc->menu_label : "NULL");
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
if (uri_proc != basename_proc)
|
2004-12-29 22:17:43 +08:00
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"that's impossible for remote URIs, bailing out");
|
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
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"ask the user if she really wants that filename");
|
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)
|
|
|
|
{
|
2007-11-19 01:55:52 +08:00
|
|
|
GIMP_LOG (SAVE_DIALOG,
|
|
|
|
"use URI's proc '%s' so indirect saving works",
|
|
|
|
uri_proc->menu_label ? uri_proc->menu_label : "<unnamed>");
|
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;
|
|
|
|
}
|
|
|
|
|
2009-04-26 00:11:21 +08:00
|
|
|
static void
|
|
|
|
file_save_dialog_unknown_ext_msg (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
gimp_message (gimp, G_OBJECT (dialog), GIMP_MESSAGE_WARNING,
|
|
|
|
_("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
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-02 21:58:32 +08:00
|
|
|
gboolean
|
|
|
|
file_save_dialog_save_image (GimpProgress *progress,
|
|
|
|
Gimp *gimp,
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpImage *image,
|
|
|
|
const gchar *uri,
|
|
|
|
GimpPlugInProcedure *save_proc,
|
2009-05-02 21:58:32 +08:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
gboolean save_a_copy,
|
|
|
|
gboolean verbose_cancel)
|
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;
|
2007-02-06 04:07:42 +08:00
|
|
|
gboolean success = FALSE;
|
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", FALSE);
|
|
|
|
}
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2009-05-03 14:34:39 +08:00
|
|
|
status = file_save (gimp, image, progress, uri,
|
|
|
|
save_proc, run_mode, save_a_copy, &error);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2006-12-15 20:03:47 +08:00
|
|
|
switch (status)
|
2002-04-18 09:18:24 +08:00
|
|
|
{
|
2006-12-15 20:03:47 +08:00
|
|
|
case GIMP_PDB_SUCCESS:
|
2007-02-06 04:07:42 +08:00
|
|
|
success = TRUE;
|
|
|
|
break;
|
2007-01-21 03:38:09 +08:00
|
|
|
|
2006-12-15 20:03:47 +08:00
|
|
|
case GIMP_PDB_CANCEL:
|
2009-05-02 21:58:32 +08:00
|
|
|
if (verbose_cancel)
|
|
|
|
gimp_message_literal (gimp,
|
|
|
|
G_OBJECT (progress), GIMP_MESSAGE_INFO,
|
|
|
|
_("Saving canceled"));
|
2006-12-15 20:03:47 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
gchar *filename = file_utils_uri_display_name (uri);
|
|
|
|
|
2009-05-02 21:58:32 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
|
2006-12-15 20:03:47 +08:00
|
|
|
_("Saving '%s' failed:\n\n%s"), filename, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
break;
|
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
|
|
|
}
|