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"
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#ifndef S_IWUSR
|
|
|
|
#define S_IWUSR _S_IWRITE
|
|
|
|
#endif
|
|
|
|
#ifndef S_IRUSR
|
|
|
|
#define S_IRUSR _S_IREAD
|
|
|
|
#endif
|
|
|
|
#ifndef S_IWGRP
|
|
|
|
#define S_IWGRP (_S_IWRITE>>3)
|
|
|
|
#define S_IWOTH (_S_IWRITE>>6)
|
|
|
|
#endif
|
|
|
|
#ifndef S_IRGRP
|
|
|
|
#define S_IRGRP (_S_IREAD>>3)
|
|
|
|
#define S_IROTH (_S_IREAD>>6)
|
|
|
|
#endif
|
|
|
|
#define uid_t gint
|
|
|
|
#define gid_t gint
|
|
|
|
#define geteuid() 0
|
|
|
|
#define getegid() 0
|
|
|
|
#endif
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/core-types.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-05-10 06:34:59 +08:00
|
|
|
#include "docindex.h"
|
|
|
|
#include "gui/menus.h"
|
|
|
|
|
2001-03-30 21:31:41 +08:00
|
|
|
#include "file-save.h"
|
|
|
|
#include "file-utils.h"
|
|
|
|
#include "plug_in.h"
|
|
|
|
#include "undo.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
GSList *save_procs = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
GimpPDBStatusType
|
2001-03-30 21:31:41 +08:00
|
|
|
file_save (GimpImage *gimage,
|
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-25 05:27:11 +08:00
|
|
|
const gchar *filename,
|
|
|
|
const gchar *raw_filename,
|
2001-03-30 21:31:41 +08:00
|
|
|
RunModeType run_mode,
|
|
|
|
gboolean set_filename)
|
|
|
|
{
|
|
|
|
PlugInProcDef *file_proc;
|
|
|
|
ProcRecord *proc;
|
|
|
|
Argument *args;
|
|
|
|
Argument *return_vals;
|
|
|
|
gint status;
|
|
|
|
gint i;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
file_proc = gimp_image_get_save_proc (gimage);
|
|
|
|
|
|
|
|
if (!file_proc)
|
|
|
|
file_proc = file_proc_find (save_procs, raw_filename);
|
|
|
|
|
|
|
|
if (!file_proc)
|
|
|
|
{
|
|
|
|
g_message (_("Save failed.\n"
|
|
|
|
"%s: Unknown file type."),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we are saving to a file */
|
|
|
|
if (stat (filename, &statbuf) == 0)
|
|
|
|
{
|
|
|
|
uid_t euid;
|
|
|
|
gid_t egid;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
euid = geteuid ();
|
|
|
|
egid = getegid ();
|
|
|
|
|
|
|
|
if (! ((statbuf.st_mode & S_IWUSR) ||
|
|
|
|
|
|
|
|
((statbuf.st_mode & S_IWGRP) &&
|
|
|
|
(statbuf.st_uid != euid)) ||
|
|
|
|
|
|
|
|
((statbuf.st_mode & S_IWOTH) &&
|
|
|
|
(statbuf.st_uid != euid) &&
|
|
|
|
(statbuf.st_gid != egid))))
|
|
|
|
{
|
|
|
|
g_message (_("Save failed.\n"
|
|
|
|
"%s: Permission denied."),
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
proc = &file_proc->db_info;
|
|
|
|
|
|
|
|
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);
|
2001-03-30 21:31:41 +08:00
|
|
|
args[2].value.pdb_int = gimp_drawable_get_ID (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
|
|
|
document_index_add (filename);
|
|
|
|
menus_last_opened_add (filename);
|
|
|
|
|
|
|
|
/* 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-07-11 20:39:49 +08:00
|
|
|
switch (gimage->gimp->config->thumbnail_mode)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
TempBuf *tempbuf;
|
|
|
|
|
|
|
|
tempbuf = make_thumb_tempbuf (gimage);
|
|
|
|
file_save_thumbnail (gimage, filename, tempbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set "gimage"s save handler to "save_proc", then save the image.
|
|
|
|
* Hide the dialog if all went well, otherwise make the user knows an
|
|
|
|
* error happened and leave the dialog up. Make sure it's sensitive.
|
|
|
|
*/
|
2001-04-28 23:11:29 +08:00
|
|
|
gboolean
|
2001-03-30 21:31:41 +08:00
|
|
|
file_save_with_proc (GimpImage *gimage,
|
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-25 05:27:11 +08:00
|
|
|
const gchar *full_filename,
|
|
|
|
const gchar *raw_filename,
|
2001-03-30 21:31:41 +08:00
|
|
|
PlugInProcDef *save_proc,
|
|
|
|
gboolean set_filename)
|
|
|
|
{
|
2001-05-21 21:58:46 +08:00
|
|
|
gint status = GIMP_PDB_EXECUTION_ERROR;
|
2001-04-28 23:11:29 +08:00
|
|
|
gboolean success = FALSE;
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
if (gimage != NULL)
|
|
|
|
{
|
|
|
|
gimp_image_set_save_proc (gimage, save_proc);
|
|
|
|
status = file_save (gimage,
|
|
|
|
full_filename,
|
|
|
|
raw_filename,
|
|
|
|
RUN_INTERACTIVE,
|
|
|
|
set_filename);
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2001-04-28 23:11:29 +08:00
|
|
|
success = TRUE;
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If there was an error but file_save() didn't print an error
|
2001-04-28 23:11:29 +08:00
|
|
|
* message, then we'd better.
|
|
|
|
*/
|
2001-05-21 21:58:46 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS && status != GIMP_PDB_CANCEL)
|
2001-03-30 21:31:41 +08:00
|
|
|
g_message (_("Save failed.\n%s"), full_filename);
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
return success;
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|