2001-03-30 21:31:41 +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"
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
#include <errno.h>
|
2001-03-30 21:31:41 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-10-29 19:47:11 +08:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
2001-03-30 21:31:41 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
2002-02-17 23:55:54 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#define W_OK 2
|
|
|
|
#define access(f,p) _access(f,p)
|
|
|
|
#endif
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/core-types.h"
|
2002-03-29 11:50:29 +08:00
|
|
|
#include "libgimptool/gimptooltypes.h"
|
2001-04-18 05:43:29 +08:00
|
|
|
|
2001-07-11 20:39:49 +08:00
|
|
|
#include "core/gimp.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimpcoreconfig.h"
|
2001-08-11 22:39:19 +08:00
|
|
|
#include "core/gimpdocuments.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-12-01 08:14:14 +08:00
|
|
|
#include "pdb/procedural_db.h"
|
|
|
|
|
|
|
|
#include "plug-in/plug-in.h"
|
2001-12-19 08:13:16 +08:00
|
|
|
#include "plug-in/plug-in-proc.h"
|
2001-12-01 08:14:14 +08:00
|
|
|
|
2001-03-30 21:31:41 +08:00
|
|
|
#include "file-save.h"
|
|
|
|
#include "file-utils.h"
|
2001-10-25 21:30:01 +08:00
|
|
|
|
2001-03-30 21:31:41 +08:00
|
|
|
#include "undo.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
GimpPDBStatusType
|
2001-10-29 19:47:11 +08:00
|
|
|
file_save (GimpImage *gimage,
|
|
|
|
const gchar *filename,
|
|
|
|
const gchar *raw_filename,
|
|
|
|
PlugInProcDef *file_proc,
|
2001-12-19 08:13:16 +08:00
|
|
|
GimpRunMode run_mode,
|
2001-10-29 19:47:11 +08:00
|
|
|
gboolean set_filename)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
ProcRecord *proc;
|
|
|
|
Argument *args;
|
|
|
|
Argument *return_vals;
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
gint i;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_PDB_CALLING_ERROR);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
if (gimp_image_active_drawable (gimage) == NULL)
|
2001-05-21 21:58:46 +08:00
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
/* set the image's save_proc if we got passed one, otherwise
|
|
|
|
* try to find a matching file_proc
|
|
|
|
*/
|
|
|
|
if (file_proc)
|
|
|
|
{
|
|
|
|
gimp_image_set_save_proc (gimage, file_proc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_proc = gimp_image_get_save_proc (gimage);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
if (! file_proc)
|
|
|
|
file_proc = file_proc_find (gimage->gimp->save_procs, raw_filename);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
if (! file_proc)
|
|
|
|
{
|
|
|
|
g_message (_("Save failed.\n"
|
|
|
|
"%s: Unknown file type."),
|
|
|
|
filename);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
|
|
|
|
}
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we are saving to a file */
|
|
|
|
if (stat (filename, &statbuf) == 0)
|
|
|
|
{
|
|
|
|
if (! (statbuf.st_mode & S_IFREG))
|
|
|
|
{
|
|
|
|
g_message (_("Save failed.\n"
|
|
|
|
"%s is not a regular file."),
|
|
|
|
filename);
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
if (access (filename, W_OK) != 0)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
g_message (_("Save failed.\n"
|
2001-10-29 19:47:11 +08:00
|
|
|
"%s: %s."),
|
|
|
|
filename,
|
|
|
|
g_strerror (errno));
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ref the image, so it can't get deleted during save */
|
2001-07-25 09:03:43 +08:00
|
|
|
g_object_ref (G_OBJECT (gimage));
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-12-19 08:13:16 +08:00
|
|
|
proc = plug_in_proc_def_get_proc (file_proc);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
args = g_new0 (Argument, proc->num_args);
|
|
|
|
|
|
|
|
for (i = 0; i < proc->num_args; i++)
|
|
|
|
args[i].arg_type = proc->args[i].arg_type;
|
|
|
|
|
|
|
|
args[0].value.pdb_int = run_mode;
|
2001-04-13 22:50:43 +08:00
|
|
|
args[1].value.pdb_int = gimp_image_get_ID (gimage);
|
2002-02-26 01:58:50 +08:00
|
|
|
args[2].value.pdb_int = gimp_item_get_ID (GIMP_ITEM (gimp_image_active_drawable (gimage)));
|
2001-07-29 22:09:50 +08:00
|
|
|
args[3].value.pdb_pointer = (gpointer) filename;
|
|
|
|
args[4].value.pdb_pointer = (gpointer) raw_filename;
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
return_vals = procedural_db_execute (gimage->gimp, proc->name, args);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
status = return_vals[0].value.pdb_int;
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
/* set this image to clean */
|
|
|
|
gimp_image_clean_all (gimage);
|
|
|
|
|
2001-08-11 15:47:35 +08:00
|
|
|
gimp_documents_add (gimage->gimp, filename);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
/* use the same plug-in for this image next time */
|
|
|
|
/* DISABLED - gets stuck on first saved format... needs
|
|
|
|
attention --Adam */
|
|
|
|
/* gimage_set_save_proc(gimage, file_proc); */
|
|
|
|
|
|
|
|
/* Write a thumbnail for the saved image, where appropriate */
|
2001-12-17 02:31:30 +08:00
|
|
|
if (gimage->gimp->config->write_thumbnails)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
2001-12-17 02:31:30 +08:00
|
|
|
TempBuf *tempbuf;
|
|
|
|
|
|
|
|
tempbuf = make_thumb_tempbuf (gimage);
|
|
|
|
file_save_thumbnail (gimage, filename, tempbuf);
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (set_filename)
|
|
|
|
{
|
|
|
|
/* set the image title */
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (gimage), filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (return_vals);
|
|
|
|
g_free (args);
|
|
|
|
|
2001-07-25 09:03:43 +08:00
|
|
|
g_object_unref (G_OBJECT (gimage));
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|