2008-11-04 Sven Neumann <sven@sven> * configure.in: bumped minimum required version of GLib to 2.18.0. * INSTALL: document the updated dependency. * app/core/gimp.[ch]: introduced gimp_message_literal(), a variant of gimp_message() that takes a literal string. * app/errors.[ch]: removed format arguments from gimp_fatal_error() and gimp_terminate() and let them take a literal string instead. * app/tools/gimptool.[ch]: introduced gimp_tool_message_literal(), a variant of gimp_tool_message() that takes a literal string. * app/actions/documents-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/error-console-commands.c * app/actions/file-commands.c * app/actions/gradients-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/plug-in-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/config/gimprc.c * app/core/gimp-modules.c * app/core/gimp-parasites.c * app/core/gimp-templates.c * app/core/gimp-units.c * app/core/gimpchannel.c * app/core/gimpcontainer-filter.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpimage-convert.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimpselection.c * app/dialogs/convert-dialog.c * app/dialogs/dialogs.c * app/dialogs/palette-import-dialog.c * app/dialogs/preferences-dialog.c * app/dialogs/quit-dialog.c * app/dialogs/stroke-dialog.c * app/display/gimpdisplayshell-dnd.c * app/file/file-open.c * app/file/file-procedure.c * app/file/file-save.c * app/file/file-utils.c * app/gegl/gimpcurvesconfig.c * app/gegl/gimplevelsconfig.c * app/gui/gui-message.c * app/gui/gui.c * app/gui/session.c * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c * app/paint/gimpsourcecore.c * app/pdb/gimppdb-utils.c * app/pdb/gimpprocedure.c * app/plug-in/gimpplugin-message.c * app/plug-in/gimpplugin.c * app/plug-in/gimppluginmanager-restore.c * app/plug-in/gimppluginprocedure.c * app/text/gimptextlayer.c * app/tools/gimp-tools.c * app/tools/gimpaligntool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcurvestool.c * app/tools/gimpdesaturatetool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpforegroundselecttool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpgegltool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool-settings.c * app/tools/gimpiscissorstool.c * app/tools/gimplevelstool.c * app/tools/gimpmeasuretool.c * app/tools/gimppainttool.c * app/tools/gimpposterizetool.c * app/tools/gimpselectiontool.c * app/tools/gimpsourcetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpactionview.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimpcontrollers.c * app/widgets/gimpdataeditor.c * app/widgets/gimpdevices.c * app/widgets/gimpdnd-xds.c * app/widgets/gimperrordialog.c * app/widgets/gimphelp.c * app/widgets/gimpitemtreeview.c * app/widgets/gimppdbdialog.c * app/widgets/gimpsettingsbox.c * app/widgets/gimpvectorstreeview.c * app/widgets/gimpwidgets-utils.c * app/xcf/xcf-load.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/floating_sel.pdb * tools/pdbgen/pdb/image.pdb: use the _literal variants for g_set_error(), gimp_message() and gimp_tool_message(). * app/pdb/convert-cmds.c * app/pdb/edit-cmds.c * app/pdb/floating-sel-cmds.c * app/pdb/image-cmds.c: regenerated. svn path=/trunk/; revision=27548
205 lines
6.2 KiB
C
205 lines
6.2 KiB
C
/* GIMP - The GNU Image Manipulation Program
|
|
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
|
|
* Copyright (C) 1997 Josh MacDonald
|
|
*
|
|
* file-save.c
|
|
*
|
|
* 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 <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
#include <sys/param.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include <gegl.h>
|
|
#include <glib/gstdio.h>
|
|
|
|
#ifdef G_OS_WIN32
|
|
#include <io.h>
|
|
#define W_OK 2
|
|
#endif
|
|
|
|
#include "core/core-types.h"
|
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
#include "core/gimp.h"
|
|
#include "core/gimpcontext.h"
|
|
#include "core/gimpdocumentlist.h"
|
|
#include "core/gimpdrawable.h"
|
|
#include "core/gimpimage.h"
|
|
#include "core/gimpimagefile.h"
|
|
#include "core/gimpparamspecs.h"
|
|
#include "core/gimpprogress.h"
|
|
|
|
#include "pdb/gimppdb.h"
|
|
|
|
#include "plug-in/gimppluginprocedure.h"
|
|
|
|
#include "file-save.h"
|
|
#include "file-utils.h"
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
/* public functions */
|
|
|
|
GimpPDBStatusType
|
|
file_save (GimpImage *image,
|
|
GimpContext *context,
|
|
GimpProgress *progress,
|
|
const gchar *uri,
|
|
GimpPlugInProcedure *file_proc,
|
|
GimpRunMode run_mode,
|
|
gboolean save_a_copy,
|
|
GError **error)
|
|
{
|
|
GimpDrawable *drawable;
|
|
GValueArray *return_vals;
|
|
GimpPDBStatusType status;
|
|
gchar *filename;
|
|
gint32 image_ID;
|
|
gint32 drawable_ID;
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR);
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_PDB_CALLING_ERROR);
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress),
|
|
GIMP_PDB_CALLING_ERROR);
|
|
g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc),
|
|
GIMP_PDB_CALLING_ERROR);
|
|
g_return_val_if_fail (error == NULL || *error == NULL,
|
|
GIMP_PDB_CALLING_ERROR);
|
|
|
|
drawable = gimp_image_get_active_drawable (image);
|
|
|
|
if (! drawable)
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
filename = file_utils_filename_from_uri (uri);
|
|
|
|
if (filename)
|
|
{
|
|
/* check if we are saving to a file */
|
|
if (g_file_test (filename, G_FILE_TEST_EXISTS))
|
|
{
|
|
if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
|
{
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
_("Not a regular file"));
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
goto out;
|
|
}
|
|
|
|
if (g_access (filename, W_OK) != 0)
|
|
{
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_ACCES,
|
|
g_strerror (errno));
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
goto out;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
filename = g_strdup (uri);
|
|
}
|
|
|
|
/* ref the image, so it can't get deleted during save */
|
|
g_object_ref (image);
|
|
|
|
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,
|
|
context, progress, error,
|
|
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);
|
|
|
|
status = g_value_get_enum (&return_vals->values[0]);
|
|
|
|
g_value_array_free (return_vals);
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
{
|
|
GimpDocumentList *documents;
|
|
GimpImagefile *imagefile;
|
|
|
|
if (save_a_copy)
|
|
{
|
|
/* remember the "save-a-copy" filename for the next invocation */
|
|
g_object_set_data_full (G_OBJECT (image), "gimp-image-save-a-copy",
|
|
g_strdup (uri),
|
|
(GDestroyNotify) g_free);
|
|
}
|
|
else
|
|
{
|
|
/* reset the "save-a-copy" filename when the image URI changes */
|
|
if (strcmp (uri, gimp_image_get_uri (image)))
|
|
g_object_set_data (G_OBJECT (image),
|
|
"gimp-image-save-a-copy", NULL);
|
|
|
|
gimp_image_set_uri (image, uri);
|
|
gimp_image_set_save_proc (image, file_proc);
|
|
|
|
gimp_image_clean_all (image);
|
|
}
|
|
|
|
gimp_image_saved (image, uri);
|
|
|
|
documents = GIMP_DOCUMENT_LIST (image->gimp->documents);
|
|
imagefile = gimp_document_list_add_uri (documents,
|
|
uri,
|
|
file_proc->mime_type);
|
|
|
|
/* 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);
|
|
}
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
{
|
|
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));
|
|
}
|
|
}
|
|
|
|
gimp_image_flush (image);
|
|
|
|
g_object_unref (image);
|
|
|
|
out:
|
|
g_free (filename);
|
|
|
|
return status;
|
|
}
|