2001-04-28 15:11:29 +00: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 15:15:23 +00:00
|
|
|
#include "dialogs-types.h"
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpimage.h"
|
2004-08-10 18:47:21 +00:00
|
|
|
#include "core/gimpprogress.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2001-10-25 13:30:01 +00:00
|
|
|
#include "file/file-save.h"
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2004-02-27 14:20:19 +00:00
|
|
|
#include "widgets/gimpfiledialog.h"
|
2003-08-21 15:54:47 +00:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2004-10-13 11:57:07 +00:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
2004-10-13 14:35:28 +00:00
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2001-11-27 19:27:55 +00:00
|
|
|
|
2001-04-28 15:11:29 +00:00
|
|
|
#include "file-save-dialog.h"
|
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-04-28 15:11:29 +00:00
|
|
|
|
|
|
|
|
2002-04-18 01:18:24 +00:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2004-09-13 16:37:01 +00:00
|
|
|
static void file_save_dialog_response (GtkWidget *save_dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp);
|
|
|
|
static void file_save_overwrite (GtkWidget *save_dialog,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *raw_filename);
|
2004-10-13 11:57:07 +00:00
|
|
|
static void file_save_overwrite_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
2004-09-13 16:37:01 +00:00
|
|
|
gpointer data);
|
|
|
|
static gboolean file_save_dialog_save_image (GtkWidget *save_dialog,
|
|
|
|
GimpImage *gimage,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *raw_filename,
|
|
|
|
PlugInProcDef *save_proc,
|
2004-11-16 13:37:36 +00:00
|
|
|
gboolean save_a_copy);
|
2001-04-28 15:11:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2004-09-13 16:37:01 +00:00
|
|
|
GtkWidget *
|
|
|
|
file_save_dialog_new (Gimp *gimp)
|
2001-04-28 15:11:29 +00:00
|
|
|
{
|
2005-01-13 17:41:48 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
const gchar *uri;
|
2003-11-17 18:29:59 +00:00
|
|
|
|
2004-09-13 16:37:01 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
2004-07-16 21:24:39 +00: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 14:20:19 +00:00
|
|
|
|
2005-02-08 20:40:33 +00:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2005-01-13 17:41:48 +00:00
|
|
|
uri = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-last-uri");
|
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
gchar *folder_uri = g_path_get_dirname (uri);
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning: FIXME: should use set_uri() but idle stuff in the file chooser seems to override set_current_name() when called immediately after set_uri()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (folder_uri)
|
|
|
|
{
|
|
|
|
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
|
|
|
|
folder_uri);
|
|
|
|
g_free (folder_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "");
|
|
|
|
}
|
|
|
|
|
2004-07-16 21:24:39 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2004-02-27 16:28:55 +00:00
|
|
|
G_CALLBACK (file_save_dialog_response),
|
2003-11-17 18:29:59 +00:00
|
|
|
gimp);
|
|
|
|
|
2004-07-16 21:24:39 +00:00
|
|
|
return dialog;
|
2001-04-28 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:37:01 +00:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-04-28 15:11:29 +00:00
|
|
|
static void
|
2004-02-27 16:28:55 +00:00
|
|
|
file_save_dialog_response (GtkWidget *save_dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp)
|
2001-04-28 15:11:29 +00:00
|
|
|
{
|
2004-08-10 21:20:38 +00:00
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
|
2004-04-15 16:28:26 +00:00
|
|
|
gchar *uri;
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2003-11-17 18:29:59 +00:00
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-08-10 21:20:38 +00:00
|
|
|
if (! dialog->busy)
|
2004-09-13 16:37:01 +00:00
|
|
|
gtk_widget_hide (save_dialog);
|
2004-08-10 21:20:38 +00:00
|
|
|
|
2003-11-17 18:29:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-10 21:20:38 +00: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-24 21:27:11 +00:00
|
|
|
|
2004-12-29 14:17:43 +00:00
|
|
|
if (uri && strlen (uri))
|
2001-04-28 15:11:29 +00:00
|
|
|
{
|
2005-02-07 17:56:18 +00:00
|
|
|
gchar *filename = file_utils_filename_from_uri (uri);
|
|
|
|
|
2004-12-29 14:17:43 +00:00
|
|
|
g_return_if_fail (filename != NULL);
|
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_EXISTS))
|
2004-03-10 10:21:03 +00:00
|
|
|
{
|
2004-12-29 14:17:43 +00:00
|
|
|
file_save_overwrite (save_dialog, uri, uri);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_file_dialog_set_sensitive (dialog, FALSE);
|
|
|
|
|
|
|
|
if (file_save_dialog_save_image (save_dialog,
|
|
|
|
dialog->gimage,
|
|
|
|
uri,
|
|
|
|
uri,
|
|
|
|
dialog->file_proc,
|
|
|
|
dialog->save_a_copy))
|
|
|
|
{
|
|
|
|
gtk_widget_hide (save_dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_file_dialog_set_sensitive (dialog, TRUE);
|
2004-03-10 10:21:03 +00:00
|
|
|
}
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2004-12-29 14:17:43 +00:00
|
|
|
g_free (filename);
|
|
|
|
g_free (uri);
|
2001-04-28 15:11:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-18 01:18:24 +00:00
|
|
|
typedef struct _OverwriteData OverwriteData;
|
|
|
|
|
|
|
|
struct _OverwriteData
|
|
|
|
{
|
|
|
|
GtkWidget *save_dialog;
|
|
|
|
gchar *uri;
|
|
|
|
gchar *raw_filename;
|
|
|
|
};
|
|
|
|
|
2001-04-28 15:11:29 +00:00
|
|
|
static void
|
2002-04-18 01:18:24 +00:00
|
|
|
file_save_overwrite (GtkWidget *save_dialog,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *raw_filename)
|
2001-04-28 15:11:29 +00:00
|
|
|
{
|
2004-10-13 11:57:07 +00:00
|
|
|
OverwriteData *overwrite_data = g_new0 (OverwriteData, 1);
|
|
|
|
GtkWidget *dialog;
|
2003-03-04 10:32:35 +00:00
|
|
|
gchar *filename;
|
2001-10-29 11:47:11 +00:00
|
|
|
|
2002-04-18 01:18:24 +00:00
|
|
|
overwrite_data->save_dialog = save_dialog;
|
2002-04-14 14:38:55 +00:00
|
|
|
overwrite_data->uri = g_strdup (uri);
|
|
|
|
overwrite_data->raw_filename = g_strdup (raw_filename);
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2004-10-13 14:35:28 +00:00
|
|
|
dialog =
|
|
|
|
gimp_message_dialog_new (_("File exists"), GIMP_STOCK_WARNING,
|
|
|
|
save_dialog, 0,
|
|
|
|
gimp_standard_help_func, NULL,
|
2004-10-13 11:57:07 +00:00
|
|
|
|
2004-10-13 14:35:28 +00:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Replace"), GTK_RESPONSE_OK,
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2004-10-13 14:35:28 +00:00
|
|
|
NULL);
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2005-02-08 20:40:33 +00:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-10-13 11:57:07 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (file_save_overwrite_response),
|
|
|
|
overwrite_data);
|
|
|
|
|
|
|
|
filename = file_utils_uri_to_utf8_filename (uri);
|
2004-10-13 14:35:28 +00:00
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
2004-10-13 11:57:07 +00:00
|
|
|
_("A file named '%s' already exists."),
|
|
|
|
filename);
|
|
|
|
g_free (filename);
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2004-10-13 14:35:28 +00:00
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
2004-10-13 11:57:07 +00:00
|
|
|
_("Do you want to replace it with the image "
|
|
|
|
"you are saving?"));
|
2003-03-16 17:51:52 +00:00
|
|
|
|
2004-08-10 21:20:38 +00:00
|
|
|
gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (save_dialog), FALSE);
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, FALSE);
|
2003-03-20 14:34:16 +00:00
|
|
|
|
2004-10-13 11:57:07 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-04-28 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-10-13 11:57:07 +00:00
|
|
|
file_save_overwrite_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
2002-04-18 01:18:24 +00:00
|
|
|
gpointer data)
|
2001-04-28 15:11:29 +00:00
|
|
|
{
|
2004-08-10 21:20:38 +00:00
|
|
|
OverwriteData *overwrite_data = data;
|
2004-10-13 11:57:07 +00:00
|
|
|
GimpFileDialog *save_dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
|
2004-08-10 21:20:38 +00:00
|
|
|
|
2004-10-13 11:57:07 +00:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
|
2004-08-10 21:20:38 +00:00
|
|
|
GTK_RESPONSE_CANCEL, TRUE);
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2004-10-13 11:57:07 +00:00
|
|
|
gtk_widget_destroy (dialog);
|
2004-06-22 00:12:52 +00:00
|
|
|
|
2004-10-13 11:57:07 +00:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-03-10 10:21:03 +00:00
|
|
|
if (file_save_dialog_save_image (overwrite_data->save_dialog,
|
2004-10-13 11:57:07 +00:00
|
|
|
save_dialog->gimage,
|
2004-03-10 10:21:03 +00:00
|
|
|
overwrite_data->uri,
|
|
|
|
overwrite_data->raw_filename,
|
2004-10-13 11:57:07 +00:00
|
|
|
save_dialog->file_proc,
|
2004-11-16 13:37:36 +00:00
|
|
|
save_dialog->save_a_copy))
|
2004-03-10 10:21:03 +00:00
|
|
|
{
|
2004-09-13 16:37:01 +00:00
|
|
|
gtk_widget_hide (overwrite_data->save_dialog);
|
2004-03-10 10:21:03 +00:00
|
|
|
}
|
2001-04-28 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
2004-10-13 11:57:07 +00:00
|
|
|
gimp_file_dialog_set_sensitive (save_dialog, TRUE);
|
2001-04-28 15:11:29 +00:00
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
g_free (overwrite_data->uri);
|
2001-04-28 15:11:29 +00:00
|
|
|
g_free (overwrite_data->raw_filename);
|
|
|
|
g_free (overwrite_data);
|
|
|
|
}
|
2002-04-18 01:18:24 +00:00
|
|
|
|
2004-03-10 10:21:03 +00:00
|
|
|
static gboolean
|
2002-04-18 01:18:24 +00:00
|
|
|
file_save_dialog_save_image (GtkWidget *save_dialog,
|
|
|
|
GimpImage *gimage,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *raw_filename,
|
|
|
|
PlugInProcDef *save_proc,
|
2004-11-16 13:37:36 +00:00
|
|
|
gboolean save_a_copy)
|
2002-04-18 01:18:24 +00:00
|
|
|
{
|
2003-03-05 11:25:59 +00:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
2002-04-18 01:18:24 +00:00
|
|
|
|
2005-01-13 17:41:48 +00:00
|
|
|
g_object_ref (gimage);
|
|
|
|
|
2003-03-04 10:32:35 +00:00
|
|
|
status = file_save_as (gimage,
|
2004-04-14 23:37:34 +00:00
|
|
|
gimp_get_user_context (gimage->gimp),
|
2004-08-10 18:47:21 +00:00
|
|
|
GIMP_PROGRESS (save_dialog),
|
2003-03-04 10:32:35 +00:00
|
|
|
uri,
|
|
|
|
raw_filename,
|
|
|
|
save_proc,
|
|
|
|
GIMP_RUN_INTERACTIVE,
|
2004-11-16 13:37:36 +00:00
|
|
|
save_a_copy,
|
2003-03-05 11:25:59 +00:00
|
|
|
&error);
|
2002-04-18 01:18:24 +00:00
|
|
|
|
2005-01-13 17:41:48 +00:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
g_object_set_data_full (G_OBJECT (gimage->gimp), "gimp-file-save-last-uri",
|
|
|
|
g_strdup (uri), (GDestroyNotify) g_free);
|
|
|
|
|
|
|
|
g_object_unref (gimage);
|
|
|
|
|
2002-04-18 01:18:24 +00:00
|
|
|
if (status != GIMP_PDB_SUCCESS &&
|
|
|
|
status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2004-02-27 16:28:55 +00:00
|
|
|
gchar *filename = file_utils_uri_to_utf8_filename (uri);
|
2003-03-05 11:25:59 +00:00
|
|
|
|
|
|
|
g_message (_("Saving '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
2004-03-10 10:21:03 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2002-04-18 01:18:24 +00:00
|
|
|
}
|
2004-03-10 10:21:03 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2002-04-18 01:18:24 +00:00
|
|
|
}
|