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>
|
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
#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"
|
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"
|
2015-09-01 02:57:37 +08:00
|
|
|
#include "widgets/gimpexportdialog.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"
|
2015-09-01 02:57:37 +08:00
|
|
|
#include "widgets/gimpsavedialog.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
|
|
|
|
|
|
|
|
2013-08-24 02:35:24 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CHECK_URI_FAIL,
|
|
|
|
CHECK_URI_OK,
|
|
|
|
CHECK_URI_SWITCH_DIALOGS
|
|
|
|
} CheckUriResult;
|
|
|
|
|
|
|
|
|
2002-04-18 09:18:24 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2009-05-11 05:58:27 +08:00
|
|
|
static GtkFileChooserConfirmation
|
2015-09-10 03:04:18 +08:00
|
|
|
file_save_dialog_confirm_overwrite (GtkWidget *dialog,
|
2009-05-16 18:41:24 +08:00
|
|
|
Gimp *gimp);
|
2015-09-10 03:04:18 +08:00
|
|
|
static void file_save_dialog_response (GtkWidget *dialog,
|
2009-05-16 18:41:24 +08:00
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp);
|
2014-07-07 06:46:25 +08:00
|
|
|
static CheckUriResult file_save_dialog_check_file (GtkWidget *save_dialog,
|
2009-05-16 18:41:24 +08:00
|
|
|
Gimp *gimp,
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile **ret_file,
|
2009-05-16 18:41:24 +08:00
|
|
|
gchar **ret_basename,
|
|
|
|
GimpPlugInProcedure **ret_save_proc);
|
|
|
|
static gboolean file_save_dialog_no_overwrite_confirmation (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp);
|
|
|
|
static GSList * file_save_dialog_get_procs (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp);
|
2013-08-24 02:35:24 +08:00
|
|
|
static gboolean file_save_dialog_switch_dialogs (GimpFileDialog *file_dialog,
|
2009-05-16 18:41:24 +08:00
|
|
|
Gimp *gimp,
|
|
|
|
const gchar *basename);
|
|
|
|
static gboolean file_save_dialog_use_extension (GtkWidget *save_dialog,
|
2014-07-08 07:07:07 +08:00
|
|
|
GFile *file);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2004-09-14 00:37:01 +08:00
|
|
|
GtkWidget *
|
2009-04-25 16:51:07 +08:00
|
|
|
file_save_dialog_new (Gimp *gimp,
|
|
|
|
gboolean export)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
GtkWidget *dialog;
|
2015-09-01 19:49:59 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2003-11-18 02:29:59 +08:00
|
|
|
|
2009-04-25 16:51:07 +08:00
|
|
|
if (! export)
|
|
|
|
{
|
2015-09-01 02:57:37 +08:00
|
|
|
dialog = gimp_save_dialog_new (gimp);
|
2009-04-25 16:51:07 +08:00
|
|
|
|
2015-09-01 19:49:59 +08:00
|
|
|
gimp_file_dialog_load_state (GIMP_FILE_DIALOG (dialog),
|
|
|
|
"gimp-file-save-dialog-state");
|
2009-04-25 16:51:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-01 02:57:37 +08:00
|
|
|
dialog = gimp_export_dialog_new (gimp);
|
2004-09-14 00:37:01 +08:00
|
|
|
|
2015-09-01 19:49:59 +08:00
|
|
|
gimp_file_dialog_load_state (GIMP_FILE_DIALOG (dialog),
|
|
|
|
"gimp-file-export-dialog-state");
|
2009-04-25 16:51:07 +08:00
|
|
|
}
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2009-05-11 05:58:27 +08:00
|
|
|
g_signal_connect (dialog, "confirm-overwrite",
|
|
|
|
G_CALLBACK (file_save_dialog_confirm_overwrite),
|
|
|
|
gimp);
|
|
|
|
|
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 */
|
|
|
|
|
2009-05-11 05:58:27 +08:00
|
|
|
static GtkFileChooserConfirmation
|
2015-09-10 03:04:18 +08:00
|
|
|
file_save_dialog_confirm_overwrite (GtkWidget *dialog,
|
2009-05-11 05:58:27 +08:00
|
|
|
Gimp *gimp)
|
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
|
2009-05-11 05:58:27 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (file_save_dialog_no_overwrite_confirmation (file_dialog, gimp))
|
2009-05-11 05:58:27 +08:00
|
|
|
/* The URI will not be accepted whatever happens, so don't
|
|
|
|
* bother asking the user about overwriting files
|
|
|
|
*/
|
|
|
|
return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
|
|
|
|
else
|
|
|
|
return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
|
|
|
|
}
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
2015-09-10 03:04:18 +08:00
|
|
|
file_save_dialog_response (GtkWidget *dialog,
|
2004-02-28 00:28:55 +08:00
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file;
|
2006-04-05 16:38:33 +08:00
|
|
|
gchar *basename;
|
|
|
|
GimpPlugInProcedure *save_proc;
|
2008-05-08 19:30:54 +08:00
|
|
|
|
2015-09-01 02:57:37 +08:00
|
|
|
if (GIMP_IS_SAVE_DIALOG (dialog))
|
2009-04-25 16:51:07 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_file_dialog_save_state (file_dialog, "gimp-file-save-dialog-state");
|
2009-04-25 16:51:07 +08:00
|
|
|
}
|
2015-09-01 02:57:37 +08:00
|
|
|
else /* GIMP_IS_EXPORT_DIALOG (dialog) */
|
2009-04-25 16:51:07 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_file_dialog_save_state (file_dialog, "gimp-file-export-dialog-state");
|
2009-04-25 16:51:07 +08:00
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
if (! file_dialog->busy)
|
|
|
|
gtk_widget_destroy (dialog);
|
2004-08-11 05:20:38 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
g_object_ref (file_dialog);
|
|
|
|
g_object_ref (file_dialog->image);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
switch (file_save_dialog_check_file (dialog, gimp,
|
2014-07-07 06:46:25 +08:00
|
|
|
&file, &basename, &save_proc))
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
2013-08-24 02:35:24 +08:00
|
|
|
case CHECK_URI_FAIL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHECK_URI_OK:
|
2015-12-09 03:10:45 +08:00
|
|
|
{
|
|
|
|
gboolean xcf_compat = FALSE;
|
|
|
|
|
|
|
|
gimp_file_dialog_set_sensitive (file_dialog, FALSE);
|
|
|
|
|
|
|
|
if (GIMP_IS_SAVE_DIALOG (dialog))
|
|
|
|
{
|
|
|
|
GimpSaveDialog* save_dialog = GIMP_SAVE_DIALOG (dialog);
|
|
|
|
|
|
|
|
xcf_compat = save_dialog->compat &&
|
|
|
|
gtk_widget_get_sensitive (save_dialog->compat_toggle);
|
|
|
|
}
|
|
|
|
if (file_save_dialog_save_image (GIMP_PROGRESS (dialog),
|
|
|
|
gimp,
|
|
|
|
file_dialog->image,
|
|
|
|
file,
|
|
|
|
save_proc,
|
|
|
|
GIMP_RUN_INTERACTIVE,
|
|
|
|
GIMP_IS_SAVE_DIALOG (dialog) &&
|
|
|
|
! GIMP_SAVE_DIALOG (dialog)->save_a_copy,
|
|
|
|
FALSE,
|
|
|
|
GIMP_IS_EXPORT_DIALOG (dialog),
|
|
|
|
xcf_compat,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
/* Save was successful, now store the URI in a couple of
|
|
|
|
* places that depend on it being the user that made a
|
|
|
|
* save. Lower-level URI management is handled in
|
|
|
|
* file_save()
|
|
|
|
*/
|
|
|
|
if (GIMP_IS_SAVE_DIALOG (dialog))
|
|
|
|
{
|
|
|
|
if (GIMP_SAVE_DIALOG (dialog)->save_a_copy)
|
|
|
|
gimp_image_set_save_a_copy_file (file_dialog->image, file);
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (file_dialog->image->gimp),
|
|
|
|
GIMP_FILE_SAVE_LAST_FILE_KEY,
|
|
|
|
g_object_ref (file),
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_set_data_full (G_OBJECT (file_dialog->image->gimp),
|
|
|
|
GIMP_FILE_EXPORT_LAST_FILE_KEY,
|
|
|
|
g_object_ref (file),
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure the menus are updated with the keys we've just set */
|
|
|
|
gimp_image_flush (file_dialog->image);
|
|
|
|
|
|
|
|
/* Handle close-after-saving */
|
|
|
|
if (GIMP_IS_SAVE_DIALOG (dialog) &&
|
|
|
|
GIMP_SAVE_DIALOG (dialog)->close_after_saving &&
|
|
|
|
GIMP_SAVE_DIALOG (dialog)->display_to_close)
|
|
|
|
{
|
|
|
|
GimpDisplay *display = GIMP_DISPLAY (GIMP_SAVE_DIALOG (dialog)->display_to_close);
|
|
|
|
|
|
|
|
if (! gimp_image_is_dirty (gimp_display_get_image (display)))
|
|
|
|
{
|
|
|
|
gimp_display_close (display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
gimp_file_dialog_set_sensitive (file_dialog, TRUE);
|
|
|
|
}
|
2013-08-24 02:35:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHECK_URI_SWITCH_DIALOGS:
|
2015-09-10 03:04:18 +08:00
|
|
|
file_dialog->busy = TRUE; /* prevent destruction */
|
2013-08-24 02:35:24 +08:00
|
|
|
gtk_dialog_response (GTK_DIALOG (dialog), FILE_SAVE_RESPONSE_OTHER_DIALOG);
|
2015-09-10 03:04:18 +08:00
|
|
|
file_dialog->busy = FALSE;
|
2013-08-24 02:35:24 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
2013-08-24 02:35:24 +08:00
|
|
|
break;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
2008-05-17 22:07:25 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
g_object_unref (file_dialog->image);
|
|
|
|
g_object_unref (file_dialog);
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
|
2013-08-24 02:35:24 +08:00
|
|
|
/* IMPORTANT: When changing this function, keep
|
|
|
|
* file_save_dialog_no_overwrite_confirmation() up to date. It is
|
|
|
|
* difficult to move logic to a common place due to how the dialog is
|
|
|
|
* implemented in GTK+ in combination with how we use it.
|
2009-05-11 05:58:27 +08:00
|
|
|
*/
|
2013-08-24 02:35:24 +08:00
|
|
|
static CheckUriResult
|
2015-09-10 03:04:18 +08:00
|
|
|
file_save_dialog_check_file (GtkWidget *dialog,
|
2014-07-07 06:46:25 +08:00
|
|
|
Gimp *gimp,
|
|
|
|
GFile **ret_file,
|
|
|
|
gchar **ret_basename,
|
|
|
|
GimpPlugInProcedure **ret_save_proc)
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file;
|
2014-07-08 07:07:07 +08:00
|
|
|
gchar *uri;
|
2006-04-05 16:38:33 +08:00
|
|
|
gchar *basename;
|
2014-07-08 08:26:51 +08:00
|
|
|
GFile *basename_file;
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpPlugInProcedure *save_proc;
|
|
|
|
GimpPlugInProcedure *uri_proc;
|
|
|
|
GimpPlugInProcedure *basename_proc;
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2014-07-08 07:07:07 +08:00
|
|
|
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (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
|
|
|
|
2014-07-08 07:07:07 +08:00
|
|
|
if (! file)
|
2013-08-24 02:35:24 +08:00
|
|
|
return CHECK_URI_FAIL;
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2014-07-08 08:26:51 +08:00
|
|
|
basename_file = g_file_new_for_uri (basename);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
save_proc = file_dialog->file_proc;
|
|
|
|
uri_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
|
|
|
|
gimp),
|
2014-07-07 06:46:25 +08:00
|
|
|
file, NULL);
|
2015-09-10 03:04:18 +08:00
|
|
|
basename_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
|
|
|
|
gimp),
|
2014-07-08 08:26:51 +08:00
|
|
|
basename_file, NULL);
|
|
|
|
|
|
|
|
g_object_unref (basename_file);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2014-07-08 07:07:07 +08:00
|
|
|
uri = g_file_get_uri (file);
|
|
|
|
|
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
|
|
|
|
2014-07-08 07:07:07 +08:00
|
|
|
g_free (uri);
|
|
|
|
|
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
|
|
|
|
2015-09-01 02:57:37 +08:00
|
|
|
if (! save_proc && GIMP_IS_SAVE_DIALOG (dialog))
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
|
|
|
ext = "xcf";
|
|
|
|
}
|
2012-06-13 04:33:47 +08:00
|
|
|
else if (save_proc && save_proc->extensions_list)
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
|
|
|
ext = save_proc->extensions_list->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext)
|
|
|
|
{
|
2011-10-06 11:31:51 +08:00
|
|
|
gchar *ext_basename;
|
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
|
|
|
|
2011-10-06 11:31:51 +08:00
|
|
|
ext_basename = g_strconcat (basename, ".", ext, NULL);
|
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
g_free (basename);
|
|
|
|
basename = ext_basename;
|
|
|
|
|
2005-02-14 18:41:55 +08:00
|
|
|
utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
|
2015-09-10 03:04:18 +08:00
|
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
|
2005-02-14 18:41:55 +08:00
|
|
|
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
|
|
|
|
*/
|
2015-09-10 03:04:18 +08:00
|
|
|
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2006-09-10 19:55:43 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
goto fail;
|
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
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (file_save_dialog_switch_dialogs (file_dialog, gimp, basename))
|
2013-08-24 02:35:24 +08:00
|
|
|
{
|
2014-07-07 06:46:25 +08:00
|
|
|
goto switch_dialogs;
|
2013-08-24 02:35:24 +08:00
|
|
|
}
|
2009-04-26 00:11:21 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
goto fail;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (file_save_dialog_switch_dialogs (file_dialog, gimp, basename))
|
2013-08-24 02:35:24 +08:00
|
|
|
{
|
2014-07-07 06:46:25 +08:00
|
|
|
goto switch_dialogs;
|
2013-08-24 02:35:24 +08:00
|
|
|
}
|
2009-04-26 00:11:21 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
goto fail;
|
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 */
|
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (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."));
|
2013-08-24 02:35:24 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
goto fail;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
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 */
|
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (! file_save_dialog_use_extension (dialog, file))
|
2005-02-14 02:05:43 +08:00
|
|
|
{
|
2014-07-07 06:46:25 +08:00
|
|
|
goto fail;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
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);
|
2013-08-24 02:35:24 +08:00
|
|
|
|
|
|
|
return CHECK_URI_FAIL;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
*ret_file = file;
|
2005-02-14 18:41:55 +08:00
|
|
|
*ret_basename = basename;
|
2005-02-14 02:05:43 +08:00
|
|
|
*ret_save_proc = save_proc;
|
|
|
|
|
2013-08-24 02:35:24 +08:00
|
|
|
return CHECK_URI_OK;
|
2014-07-07 06:46:25 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
return CHECK_URI_FAIL;
|
|
|
|
|
|
|
|
switch_dialogs:
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
return CHECK_URI_SWITCH_DIALOGS;
|
2005-02-14 02:05:43 +08:00
|
|
|
}
|
|
|
|
|
2009-05-11 05:58:27 +08:00
|
|
|
/*
|
|
|
|
* IMPORTANT: Keep this up to date with file_save_dialog_check_uri().
|
|
|
|
*/
|
|
|
|
static gboolean
|
2015-09-10 03:04:18 +08:00
|
|
|
file_save_dialog_no_overwrite_confirmation (GimpFileDialog *file_dialog,
|
2009-05-16 18:41:24 +08:00
|
|
|
Gimp *gimp)
|
2009-05-11 05:58:27 +08:00
|
|
|
{
|
2014-07-08 07:07:07 +08:00
|
|
|
GFile *file;
|
|
|
|
gchar *basename;
|
2014-07-08 08:26:51 +08:00
|
|
|
GFile *basename_file;
|
2014-07-08 07:07:07 +08:00
|
|
|
GimpPlugInProcedure *basename_proc;
|
|
|
|
GimpPlugInProcedure *save_proc;
|
|
|
|
gboolean uri_will_change;
|
|
|
|
gboolean unknown_ext;
|
2009-05-11 05:58:27 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_dialog));
|
2009-05-11 05:58:27 +08:00
|
|
|
|
2014-07-08 07:07:07 +08:00
|
|
|
if (! file)
|
2009-05-11 05:58:27 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2014-07-08 07:07:07 +08:00
|
|
|
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2014-07-08 08:26:51 +08:00
|
|
|
basename_file = g_file_new_for_uri (basename);
|
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
save_proc = file_dialog->file_proc;
|
|
|
|
basename_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
|
|
|
|
gimp),
|
2014-07-08 08:26:51 +08:00
|
|
|
basename_file, NULL);
|
|
|
|
|
|
|
|
g_object_unref (basename_file);
|
2009-05-11 05:58:27 +08:00
|
|
|
|
2009-05-16 18:41:24 +08:00
|
|
|
uri_will_change = (! basename_proc &&
|
|
|
|
! strchr (basename, '.') &&
|
|
|
|
(! save_proc || save_proc->extensions_list));
|
|
|
|
|
|
|
|
unknown_ext = (! save_proc &&
|
|
|
|
! basename_proc);
|
2009-05-11 05:58:27 +08:00
|
|
|
|
|
|
|
g_free (basename);
|
2014-07-08 07:07:07 +08:00
|
|
|
g_object_unref (file);
|
2009-05-11 05:58:27 +08:00
|
|
|
|
2009-05-16 18:41:24 +08:00
|
|
|
return uri_will_change || unknown_ext;
|
2009-05-11 05:58:27 +08:00
|
|
|
}
|
|
|
|
|
2009-04-25 16:51:07 +08:00
|
|
|
static GSList *
|
2015-09-10 03:04:18 +08:00
|
|
|
file_save_dialog_get_procs (GimpFileDialog *file_dialog,
|
2009-04-25 16:51:07 +08:00
|
|
|
Gimp *gimp)
|
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
return (GIMP_IS_SAVE_DIALOG (file_dialog) ?
|
2009-04-25 16:51:07 +08:00
|
|
|
gimp->plug_in_manager->save_procs :
|
|
|
|
gimp->plug_in_manager->export_procs);
|
|
|
|
}
|
|
|
|
|
2013-08-24 02:35:24 +08:00
|
|
|
static gboolean
|
|
|
|
file_save_other_dialog_activated (GtkWidget *label,
|
|
|
|
const gchar *uri,
|
|
|
|
GtkDialog *dialog)
|
|
|
|
{
|
|
|
|
gtk_dialog_response (dialog, FILE_SAVE_RESPONSE_OTHER_DIALOG);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
file_save_dialog_switch_dialogs (GimpFileDialog *file_dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
const gchar *basename)
|
2009-04-26 00:11:21 +08:00
|
|
|
{
|
2009-04-26 03:46:25 +08:00
|
|
|
GimpPlugInProcedure *proc_in_other_group;
|
2014-07-08 08:26:51 +08:00
|
|
|
GFile *file;
|
2013-08-24 02:35:24 +08:00
|
|
|
gboolean switch_dialogs = FALSE;
|
2009-04-26 03:46:25 +08:00
|
|
|
|
2014-07-08 08:26:51 +08:00
|
|
|
file = g_file_new_for_uri (basename);
|
|
|
|
|
2009-04-26 03:46:25 +08:00
|
|
|
proc_in_other_group =
|
2015-09-01 02:57:37 +08:00
|
|
|
file_procedure_find (GIMP_IS_EXPORT_DIALOG (file_dialog) ?
|
2013-08-24 02:35:24 +08:00
|
|
|
gimp->plug_in_manager->save_procs :
|
|
|
|
gimp->plug_in_manager->export_procs,
|
2014-07-08 08:26:51 +08:00
|
|
|
file, NULL);
|
|
|
|
|
|
|
|
g_object_unref (file);
|
2009-04-26 03:46:25 +08:00
|
|
|
|
2013-08-24 02:35:24 +08:00
|
|
|
if (proc_in_other_group)
|
2009-04-26 03:46:25 +08:00
|
|
|
{
|
2013-08-24 02:35:24 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
const gchar *primary;
|
|
|
|
const gchar *message;
|
|
|
|
const gchar *link;
|
|
|
|
|
2015-09-01 02:57:37 +08:00
|
|
|
if (GIMP_IS_EXPORT_DIALOG (file_dialog))
|
2013-08-24 02:35:24 +08:00
|
|
|
{
|
|
|
|
primary = _("The given filename cannot be used for exporting");
|
|
|
|
message = _("You can use this dialog to export to various file formats. "
|
2009-04-26 03:46:25 +08:00
|
|
|
"If you want to save the image to the GIMP XCF format, use "
|
2013-08-24 02:35:24 +08:00
|
|
|
"File→Save instead.");
|
|
|
|
link = _("Take me to the Save dialog");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
primary = _("The given filename cannot be used for saving");
|
|
|
|
message = _("You can use this dialog to save to the GIMP XCF "
|
|
|
|
"format. Use File→Export to export to other file formats.");
|
|
|
|
link = _("Take me to the Export dialog");
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog = gimp_message_dialog_new (_("Extension Mismatch"),
|
|
|
|
GIMP_STOCK_WARNING,
|
|
|
|
GTK_WIDGET (file_dialog),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gimp_standard_help_func, NULL,
|
|
|
|
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
"%s", primary);
|
|
|
|
|
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
"%s", message);
|
|
|
|
|
2015-09-01 02:57:37 +08:00
|
|
|
if (GIMP_IS_EXPORT_DIALOG (file_dialog) ||
|
|
|
|
(! GIMP_SAVE_DIALOG (file_dialog)->save_a_copy &&
|
|
|
|
! GIMP_SAVE_DIALOG (file_dialog)->close_after_saving))
|
2013-08-24 02:35:24 +08:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gchar *markup;
|
|
|
|
|
|
|
|
markup = g_strdup_printf ("<a href=\"other-dialog\">%s</a>", link);
|
|
|
|
label = gtk_label_new (markup);
|
|
|
|
g_free (markup);
|
|
|
|
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GIMP_MESSAGE_DIALOG (dialog)->box), label,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
g_signal_connect (label, "activate-link",
|
|
|
|
G_CALLBACK (file_save_other_dialog_activated),
|
|
|
|
dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (file_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, FALSE);
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (file_dialog),
|
|
|
|
GTK_RESPONSE_OK, FALSE);
|
|
|
|
|
|
|
|
g_object_ref (dialog);
|
|
|
|
|
|
|
|
if (gimp_dialog_run (GIMP_DIALOG (dialog)) == FILE_SAVE_RESPONSE_OTHER_DIALOG)
|
|
|
|
{
|
|
|
|
switch_dialogs = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
g_object_unref (dialog);
|
|
|
|
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (file_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, TRUE);
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (file_dialog),
|
|
|
|
GTK_RESPONSE_OK, TRUE);
|
2009-04-26 03:46:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-24 02:35:24 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (file_dialog), GIMP_MESSAGE_WARNING,
|
2009-04-26 03:46:25 +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."));
|
|
|
|
}
|
2013-08-24 02:35:24 +08:00
|
|
|
|
|
|
|
return switch_dialogs;
|
2009-04-26 00:11:21 +08:00
|
|
|
}
|
|
|
|
|
2005-02-14 02:05:43 +08:00
|
|
|
static gboolean
|
2014-07-08 07:07:07 +08:00
|
|
|
file_save_dialog_use_extension (GtkWidget *save_dialog,
|
|
|
|
GFile *file)
|
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);
|
2013-08-24 02:35:24 +08:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
|
|
|
|
GTK_RESPONSE_OK, FALSE);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
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);
|
2013-08-24 02:35:24 +08:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
|
|
|
|
GTK_RESPONSE_OK, TRUE);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
|
|
|
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,
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file,
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpPlugInProcedure *save_proc,
|
2009-05-02 21:58:32 +08:00
|
|
|
GimpRunMode run_mode,
|
2009-05-06 23:09:31 +08:00
|
|
|
gboolean change_saved_state,
|
2012-05-19 00:48:51 +08:00
|
|
|
gboolean export_backward,
|
|
|
|
gboolean export_forward,
|
2014-10-04 08:26:36 +08:00
|
|
|
gboolean xcf_compat,
|
2009-05-02 21:58:32 +08:00
|
|
|
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
|
|
|
|
2015-09-01 21:17:44 +08:00
|
|
|
gimp_image_set_xcf_compat_mode (image, xcf_compat);
|
2014-10-04 08:26:36 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
status = file_save (gimp, image, progress, file,
|
2012-05-19 00:48:51 +08:00
|
|
|
save_proc, run_mode,
|
|
|
|
change_saved_state, export_backward, export_forward,
|
|
|
|
&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:
|
|
|
|
{
|
2009-05-02 21:58:32 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
|
2014-07-07 06:46:25 +08:00
|
|
|
_("Saving '%s' failed:\n\n%s"),
|
|
|
|
gimp_file_get_utf8_name (file), error->message);
|
2006-12-15 20:03:47 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|