1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
3
* Copyright (C) 1997 Josh MacDonald
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#ifdef HAVE_SYS_PARAM_H
29
#include <sys/param.h>
35
#include <glib-object.h>
40
#define access(f,p) _access(f,p)
43
#include "core/core-types.h"
45
#include "config/gimpcoreconfig.h"
47
#include "core/gimp.h"
48
#include "core/gimpcontext.h"
49
#include "core/gimpdocumentlist.h"
50
#include "core/gimpdrawable.h"
51
#include "core/gimpimage.h"
52
#include "core/gimpimagefile.h"
53
#include "core/gimpprogress.h"
55
#include "pdb/procedural_db.h"
57
#include "plug-in/plug-in.h"
58
#include "plug-in/plug-in-proc-def.h"
60
#include "file-save.h"
61
#include "file-utils.h"
62
#include "gimprecentlist.h"
64
#include "gimp-intl.h"
67
/* public functions */
70
file_save (GimpImage *gimage,
72
GimpProgress *progress,
77
PlugInProcDef *file_proc;
79
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_PDB_CALLING_ERROR);
80
g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_PDB_CALLING_ERROR);
81
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress),
82
GIMP_PDB_CALLING_ERROR);
83
g_return_val_if_fail (error == NULL || *error == NULL,
84
GIMP_PDB_CALLING_ERROR);
86
uri = gimp_object_get_name (GIMP_OBJECT (gimage));
88
g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
90
file_proc = gimp_image_get_save_proc (gimage);
92
return file_save_as (gimage, context, progress,
93
uri, uri, file_proc, run_mode, FALSE, error);
97
file_save_as (GimpImage *gimage,
99
GimpProgress *progress,
101
const gchar *raw_filename,
102
PlugInProcDef *file_proc,
103
GimpRunMode run_mode,
104
gboolean save_a_copy,
107
const ProcRecord *proc;
109
Argument *return_vals;
110
GimpPDBStatusType status;
114
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_PDB_CALLING_ERROR);
115
g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_PDB_CALLING_ERROR);
116
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress),
117
GIMP_PDB_CALLING_ERROR);
118
g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
119
g_return_val_if_fail (raw_filename != NULL, GIMP_PDB_CALLING_ERROR);
120
g_return_val_if_fail (error == NULL || *error == NULL,
121
GIMP_PDB_CALLING_ERROR);
123
if (gimp_image_active_drawable (gimage) == NULL)
124
return GIMP_PDB_EXECUTION_ERROR;
127
file_proc = file_utils_find_proc (gimage->gimp->save_procs, raw_filename);
131
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
132
_("Unknown file type"));
133
return GIMP_PDB_CALLING_ERROR;
136
filename = g_filename_from_uri (uri, NULL, NULL);
140
/* check if we are saving to a file */
141
if (g_file_test (filename, G_FILE_TEST_EXISTS))
143
if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
145
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
146
_("Not a regular file"));
148
return GIMP_PDB_EXECUTION_ERROR;
151
if (access (filename, W_OK) != 0)
153
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES,
156
return GIMP_PDB_EXECUTION_ERROR;
161
/* ref the image, so it can't get deleted during save */
162
g_object_ref (gimage);
164
proc = plug_in_proc_def_get_proc (file_proc);
166
args = g_new0 (Argument, proc->num_args);
168
for (i = 0; i < proc->num_args; i++)
169
args[i].arg_type = proc->args[i].arg_type;
171
args[0].value.pdb_int = run_mode;
172
args[1].value.pdb_int = gimp_image_get_ID (gimage);
173
args[2].value.pdb_int = gimp_item_get_ID (GIMP_ITEM (gimp_image_active_drawable (gimage)));
174
args[3].value.pdb_pointer = (gpointer) (filename ? filename : uri);
175
args[4].value.pdb_pointer = (gpointer) raw_filename;
177
return_vals = procedural_db_execute (gimage->gimp, context, progress,
183
status = return_vals[0].value.pdb_int;
185
if (status == GIMP_PDB_SUCCESS)
187
GimpDocumentList *documents;
188
GimpImagefile *imagefile;
192
/* remember the "save-a-copy" filename for the next invocation */
193
g_object_set_data_full (G_OBJECT (gimage),
194
"gimp-image-save-a-copy", g_strdup (uri),
195
(GDestroyNotify) g_free);
199
/* reset the "save-a-copy" filename when the image URI changes */
200
if (uri && strcmp (uri, gimp_image_get_uri (gimage)))
201
g_object_set_data (G_OBJECT (gimage),
202
"gimp-image-save-a-copy", NULL);
204
gimp_image_set_uri (gimage, uri);
205
gimp_image_set_save_proc (gimage, file_proc);
206
gimp_image_clean_all (gimage);
209
documents = GIMP_DOCUMENT_LIST (gimage->gimp->documents);
210
imagefile = gimp_document_list_add_uri (documents,
211
uri, file_proc->mime_type);
213
gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, gimage);
215
gimp_recent_list_add_uri (uri, file_proc->mime_type);
217
else if (status != GIMP_PDB_CANCEL)
219
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
220
_("Plug-In could not save image"));
223
g_free (return_vals);
226
g_object_unref (gimage);