2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-03-30 13:31:41 +00:00
|
|
|
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
|
|
|
|
* Copyright (C) 1997 Josh MacDonald
|
|
|
|
*
|
2004-09-22 15:12:24 +00:00
|
|
|
* file-save.c
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-03-30 13:31:41 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-03-30 13:31:41 +00: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-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-03-30 13:31:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
#include <errno.h>
|
2001-03-30 13:31:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-09-25 23:22:05 +00:00
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
2005-09-25 23:22:05 +00:00
|
|
|
|
2001-03-30 13:31:41 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2005-09-25 23:22:05 +00:00
|
|
|
#include <glib/gstdio.h>
|
2001-08-17 14:27:31 +00:00
|
|
|
|
2002-02-17 15:55:54 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#define W_OK 2
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "core/core-types.h"
|
2001-04-17 21:43:29 +00:00
|
|
|
|
2002-11-18 20:50:31 +00:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2001-07-11 12:39:49 +00:00
|
|
|
#include "core/gimp.h"
|
2004-04-14 23:37:34 +00:00
|
|
|
#include "core/gimpcontext.h"
|
2002-05-15 11:05:32 +00:00
|
|
|
#include "core/gimpdocumentlist.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
2002-04-19 17:15:39 +00:00
|
|
|
#include "core/gimpimagefile.h"
|
2006-04-03 20:54:55 +00:00
|
|
|
#include "core/gimpparamspecs.h"
|
2004-08-10 18:47:21 +00:00
|
|
|
#include "core/gimpprogress.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2006-04-26 09:13:47 +00:00
|
|
|
#include "pdb/gimppdb.h"
|
2006-08-05 21:21:01 +00:00
|
|
|
|
|
|
|
#include "plug-in/gimppluginprocedure.h"
|
2001-12-01 00:14:14 +00:00
|
|
|
|
2001-03-30 13:31:41 +00:00
|
|
|
#include "file-save.h"
|
|
|
|
#include "file-utils.h"
|
2009-05-01 09:03:13 +02:00
|
|
|
#include "gimp-file.h"
|
2001-10-25 13:30:01 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-03-30 13:31:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-05-21 13:58:46 +00:00
|
|
|
GimpPDBStatusType
|
2009-05-03 08:34:39 +02:00
|
|
|
file_save (Gimp *gimp,
|
|
|
|
GimpImage *image,
|
2006-04-05 08:38:33 +00:00
|
|
|
GimpProgress *progress,
|
|
|
|
const gchar *uri,
|
|
|
|
GimpPlugInProcedure *file_proc,
|
|
|
|
GimpRunMode run_mode,
|
2009-05-06 15:03:30 +02:00
|
|
|
gboolean change_saved_state,
|
2006-04-05 08:38:33 +00:00
|
|
|
GError **error)
|
2001-03-30 13:31:41 +00:00
|
|
|
{
|
2006-04-26 09:13:47 +00:00
|
|
|
GimpDrawable *drawable;
|
2006-04-04 10:30:58 +00:00
|
|
|
GValueArray *return_vals;
|
2001-10-29 11:47:11 +00:00
|
|
|
GimpPDBStatusType status;
|
2006-03-27 11:40:00 +00:00
|
|
|
gchar *filename;
|
2006-04-26 09:13:47 +00:00
|
|
|
gint32 image_ID;
|
|
|
|
gint32 drawable_ID;
|
2001-10-29 11:47:11 +00:00
|
|
|
|
2009-05-03 08:34:39 +02:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR);
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR);
|
2004-08-10 18:47:21 +00:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress),
|
|
|
|
GIMP_PDB_CALLING_ERROR);
|
2003-03-04 10:32:35 +00:00
|
|
|
g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
|
2006-04-05 08:38:33 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc),
|
|
|
|
GIMP_PDB_CALLING_ERROR);
|
2003-03-05 11:25:59 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL,
|
|
|
|
GIMP_PDB_CALLING_ERROR);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2007-07-19 14:59:51 +00:00
|
|
|
drawable = gimp_image_get_active_drawable (image);
|
2006-04-26 09:13:47 +00:00
|
|
|
|
|
|
|
if (! drawable)
|
2001-05-21 13:58:46 +00:00
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2005-02-13 18:05:43 +00:00
|
|
|
filename = file_utils_filename_from_uri (uri);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
/* check if we are saving to a file */
|
2002-04-16 20:25:27 +00:00
|
|
|
if (g_file_test (filename, G_FILE_TEST_EXISTS))
|
2001-03-30 13:31:41 +00:00
|
|
|
{
|
2002-04-16 20:25:27 +00:00
|
|
|
if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
2002-04-14 14:38:55 +00:00
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Not a regular file"));
|
2005-02-10 14:32:14 +00:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
goto out;
|
2002-04-14 14:38:55 +00:00
|
|
|
}
|
|
|
|
|
2005-09-25 23:22:05 +00:00
|
|
|
if (g_access (filename, W_OK) != 0)
|
2002-04-14 14:38:55 +00:00
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_ACCES,
|
|
|
|
g_strerror (errno));
|
2005-02-10 14:32:14 +00:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
goto out;
|
2002-04-14 14:38:55 +00:00
|
|
|
}
|
2001-03-30 13:31:41 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-27 11:40:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
filename = g_strdup (uri);
|
|
|
|
}
|
2001-03-30 13:31:41 +00:00
|
|
|
|
|
|
|
/* ref the image, so it can't get deleted during save */
|
2006-03-28 17:08:36 +00:00
|
|
|
g_object_ref (image);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2006-04-26 09:13:47 +00:00
|
|
|
image_ID = gimp_image_get_ID (image);
|
|
|
|
drawable_ID = gimp_item_get_ID (GIMP_ITEM (drawable));
|
|
|
|
|
|
|
|
return_vals =
|
|
|
|
gimp_pdb_execute_procedure_by_name (image->gimp->pdb,
|
2009-05-03 08:34:39 +02:00
|
|
|
gimp_get_user_context (gimp),
|
|
|
|
progress, error,
|
2006-04-26 09:13:47 +00:00
|
|
|
GIMP_OBJECT (file_proc)->name,
|
|
|
|
GIMP_TYPE_INT32, run_mode,
|
|
|
|
GIMP_TYPE_IMAGE_ID, image_ID,
|
|
|
|
GIMP_TYPE_DRAWABLE_ID, drawable_ID,
|
|
|
|
G_TYPE_STRING, filename,
|
|
|
|
G_TYPE_STRING, uri,
|
|
|
|
G_TYPE_NONE);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2006-04-04 10:30:58 +00:00
|
|
|
status = g_value_get_enum (&return_vals->values[0]);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2006-04-04 10:30:58 +00:00
|
|
|
g_value_array_free (return_vals);
|
2006-03-27 11:40:00 +00:00
|
|
|
|
2001-05-21 13:58:46 +00:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2001-03-30 13:31:41 +00:00
|
|
|
{
|
2002-05-15 11:05:32 +00:00
|
|
|
GimpDocumentList *documents;
|
|
|
|
GimpImagefile *imagefile;
|
2002-04-19 17:15:39 +00:00
|
|
|
|
2009-05-06 15:03:30 +02:00
|
|
|
if (change_saved_state)
|
2003-04-09 09:52:01 +00:00
|
|
|
{
|
2006-04-12 12:49:29 +00:00
|
|
|
gimp_image_set_uri (image, uri);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_set_save_proc (image, file_proc);
|
2007-09-20 21:23:05 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_clean_all (image);
|
2006-04-12 12:49:29 +00:00
|
|
|
}
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2006-12-11 20:57:44 +00:00
|
|
|
gimp_image_saved (image, uri);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
documents = GIMP_DOCUMENT_LIST (image->gimp->documents);
|
2004-11-16 13:37:36 +00:00
|
|
|
imagefile = gimp_document_list_add_uri (documents,
|
2005-02-13 18:05:43 +00:00
|
|
|
uri,
|
2005-02-10 14:32:14 +00:00
|
|
|
file_proc->mime_type);
|
2004-11-16 13:37:36 +00:00
|
|
|
|
2006-11-06 08:12:37 +00:00
|
|
|
/* only save a thumbnail if we are saving as XCF, see bug #25272 */
|
|
|
|
if (GIMP_PROCEDURE (file_proc)->proc_type == GIMP_INTERNAL)
|
|
|
|
gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, image);
|
2001-03-30 13:31:41 +00:00
|
|
|
}
|
2003-03-05 11:25:59 +00:00
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2007-12-02 18:05:54 +00:00
|
|
|
if (error && *error == NULL)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("%s plug-in could not save image"),
|
|
|
|
gimp_plug_in_procedure_get_label (file_proc));
|
|
|
|
}
|
2003-03-05 11:25:59 +00:00
|
|
|
}
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2008-08-20 06:30:59 +00:00
|
|
|
gimp_image_flush (image);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_object_unref (image);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2005-02-10 14:32:14 +00:00
|
|
|
out:
|
|
|
|
g_free (filename);
|
|
|
|
|
2001-03-30 13:31:41 +00:00
|
|
|
return status;
|
|
|
|
}
|