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 R_OK 4
|
|
|
|
#define access(f,p) _access(f,p)
|
|
|
|
#endif
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/core-types.h"
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-11-11 03:35:21 +08:00
|
|
|
#include "core/gimpdocuments.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
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-open.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-04-28 23:11:29 +08:00
|
|
|
GimpImage *
|
2001-10-29 19:47:11 +08:00
|
|
|
file_open_image (Gimp *gimp,
|
|
|
|
const gchar *filename,
|
|
|
|
const gchar *raw_filename,
|
|
|
|
const gchar *open_mode,
|
|
|
|
PlugInProcDef *file_proc,
|
2001-12-19 08:13:16 +08:00
|
|
|
GimpRunMode run_mode,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpPDBStatusType *status)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
ProcRecord *proc;
|
|
|
|
Argument *args;
|
|
|
|
Argument *return_vals;
|
|
|
|
gint gimage_id;
|
|
|
|
gint i;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (status != NULL, NULL);
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
*status = GIMP_PDB_CANCEL; /* inhibits error messages by caller */
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
if (! file_proc)
|
2001-10-29 19:47:11 +08:00
|
|
|
file_proc = file_proc_find (gimp->load_procs, filename);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
if (! file_proc)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
/* no errors when making thumbnails */
|
2001-12-19 08:13:16 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2001-03-30 21:31:41 +08:00
|
|
|
g_message (_("%s failed.\n"
|
|
|
|
"%s: Unknown file type."),
|
|
|
|
open_mode, filename);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we are opening a file */
|
|
|
|
if (stat (filename, &statbuf) == 0)
|
|
|
|
{
|
|
|
|
if (! (statbuf.st_mode & S_IFREG))
|
|
|
|
{
|
|
|
|
/* no errors when making thumbnails */
|
2001-12-19 08:13:16 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2001-03-30 21:31:41 +08:00
|
|
|
g_message (_("%s failed.\n"
|
|
|
|
"%s is not a regular file."),
|
|
|
|
open_mode, filename);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
if (access (filename, R_OK) != 0)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
/* no errors when making thumbnails */
|
2001-12-19 08:13:16 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2001-03-30 21:31:41 +08:00
|
|
|
g_message (_("%s failed.\n"
|
2001-10-29 19:47:11 +08:00
|
|
|
"%s: %s."),
|
|
|
|
open_mode, filename, g_strerror (errno));
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
args[1].value.pdb_pointer = (gchar *) filename;
|
|
|
|
args[2].value.pdb_pointer = (gchar *) raw_filename;
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
return_vals = procedural_db_execute (gimp, proc->name, args);
|
2001-03-30 21:31:41 +08:00
|
|
|
|
|
|
|
*status = return_vals[0].value.pdb_int;
|
|
|
|
gimage_id = return_vals[1].value.pdb_int;
|
|
|
|
|
|
|
|
procedural_db_destroy_args (return_vals, proc->num_values);
|
|
|
|
g_free (args);
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
if (*status == GIMP_PDB_SUCCESS && gimage_id != -1)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
2001-07-11 20:39:49 +08:00
|
|
|
return gimp_image_get_by_ID (gimp, gimage_id);
|
2001-03-30 21:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-11-11 03:35:21 +08:00
|
|
|
GimpPDBStatusType
|
|
|
|
file_open_with_display (Gimp *gimp,
|
|
|
|
const gchar *filename)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR);
|
|
|
|
|
|
|
|
return file_open_with_proc_and_display (gimp, filename, filename, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpPDBStatusType
|
|
|
|
file_open_with_proc_and_display (Gimp *gimp,
|
|
|
|
const gchar *filename,
|
|
|
|
const gchar *raw_filename,
|
|
|
|
PlugInProcDef *file_proc)
|
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
gchar *absolute;
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR);
|
|
|
|
|
|
|
|
if ((gimage = file_open_image (gimp,
|
|
|
|
filename,
|
|
|
|
raw_filename,
|
|
|
|
_("Open"),
|
|
|
|
file_proc,
|
2001-12-19 08:13:16 +08:00
|
|
|
GIMP_RUN_INTERACTIVE,
|
2001-11-11 03:35:21 +08:00
|
|
|
&status)) != NULL)
|
|
|
|
{
|
|
|
|
/* enable & clear all undo steps */
|
|
|
|
gimp_image_undo_enable (gimage);
|
|
|
|
|
|
|
|
/* set the image to clean */
|
|
|
|
gimp_image_clean_all (gimage);
|
|
|
|
|
|
|
|
gimp_create_display (gimage->gimp, gimage, 0x0101);
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (gimage));
|
|
|
|
|
|
|
|
absolute = file_open_absolute_filename (gimp, filename);
|
|
|
|
|
|
|
|
gimp_documents_add (gimp, filename);
|
|
|
|
|
|
|
|
g_free (absolute);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
gchar *
|
2001-10-29 19:47:11 +08:00
|
|
|
file_open_absolute_filename (Gimp *gimp,
|
|
|
|
const gchar *name)
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
PlugInProcDef *proc;
|
|
|
|
GSList *procs;
|
|
|
|
GSList *prefixes;
|
|
|
|
gchar *absolute;
|
|
|
|
gchar *current;
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2001-03-30 21:31:41 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
/* check for prefixes like http or ftp */
|
2001-10-29 19:47:11 +08:00
|
|
|
for (procs = gimp->load_procs; procs; procs = g_slist_next (procs))
|
2001-03-30 21:31:41 +08:00
|
|
|
{
|
|
|
|
proc = (PlugInProcDef *)procs->data;
|
|
|
|
|
|
|
|
for (prefixes = proc->prefixes_list;
|
|
|
|
prefixes;
|
|
|
|
prefixes = g_slist_next (prefixes))
|
|
|
|
{
|
|
|
|
if (strncmp (name, prefixes->data, strlen (prefixes->data)) == 0)
|
|
|
|
return g_strdup (name);
|
|
|
|
}
|
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2001-03-30 21:31:41 +08:00
|
|
|
if (g_path_is_absolute (name))
|
|
|
|
return g_strdup (name);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2001-03-30 21:31:41 +08:00
|
|
|
current = g_get_current_dir ();
|
2001-10-24 23:56:33 +08:00
|
|
|
absolute = g_build_filename (current, name, NULL);
|
2001-03-30 21:31:41 +08:00
|
|
|
g_free (current);
|
|
|
|
|
|
|
|
return absolute;
|
|
|
|
}
|