app, plug-ins: remove file-uri completely
and enable the new file-remote code in app unconditionally.
This commit is contained in:
@ -148,7 +148,7 @@ file_open_image (Gimp *gimp,
|
||||
{
|
||||
path = g_file_get_path (file);
|
||||
|
||||
if (! path && g_getenv ("GIMP_HANDLE_REMOTE_FILES"))
|
||||
if (! path)
|
||||
{
|
||||
GError *my_error = NULL;
|
||||
|
||||
|
@ -254,7 +254,6 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc,
|
||||
const gchar *name = gimp_object_get_name (file_proc);
|
||||
gboolean is_xcf_save = FALSE;
|
||||
gboolean is_filter = FALSE;
|
||||
gboolean is_uri = FALSE;
|
||||
|
||||
is_xcf_save = (strcmp (name, "gimp-xcf-save") == 0);
|
||||
|
||||
@ -262,17 +261,15 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc,
|
||||
strcmp (name, "file-bz2-save") == 0 ||
|
||||
strcmp (name, "file-xz-save") == 0);
|
||||
|
||||
is_uri = (strcmp (name, "file-uri-save") == 0);
|
||||
|
||||
switch (group)
|
||||
{
|
||||
case FILE_PROCEDURE_GROUP_SAVE:
|
||||
/* Only .xcf shall pass */
|
||||
return is_xcf_save || is_filter || is_uri;
|
||||
return is_xcf_save || is_filter;
|
||||
|
||||
case FILE_PROCEDURE_GROUP_EXPORT:
|
||||
/* Anything but .xcf shall pass */
|
||||
return ! is_xcf_save || is_uri;
|
||||
return ! is_xcf_save;
|
||||
|
||||
case FILE_PROCEDURE_GROUP_OPEN:
|
||||
/* No filter applied for Open */
|
||||
|
@ -129,7 +129,7 @@ file_save (Gimp *gimp,
|
||||
{
|
||||
path = g_file_get_path (file);
|
||||
|
||||
if (! path && g_getenv ("GIMP_HANDLE_REMOTE_FILES"))
|
||||
if (! path)
|
||||
{
|
||||
GError *my_error = NULL;
|
||||
|
||||
|
@ -310,7 +310,6 @@ gimp_file_dialog_new (Gimp *gimp,
|
||||
GSList *file_procs_all_images = NULL;
|
||||
const gchar *automatic = NULL;
|
||||
const gchar *automatic_help_id = NULL;
|
||||
gboolean local_only = FALSE;
|
||||
GtkFileChooserAction gtk_action = 0;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
@ -327,10 +326,6 @@ gimp_file_dialog_new (Gimp *gimp,
|
||||
file_procs_all_images = NULL;
|
||||
automatic = _("Automatically Detected");
|
||||
automatic_help_id = GIMP_HELP_FILE_OPEN_BY_EXTENSION;
|
||||
|
||||
local_only = (gimp_pdb_lookup_procedure (gimp->pdb,
|
||||
"file-uri-load") == NULL &&
|
||||
! g_getenv ("GIMP_HANDLE_REMOTE_FILES"));
|
||||
break;
|
||||
|
||||
case GIMP_FILE_CHOOSER_ACTION_SAVE:
|
||||
@ -344,10 +339,6 @@ gimp_file_dialog_new (Gimp *gimp,
|
||||
gimp->plug_in_manager->save_procs);
|
||||
automatic = _("By Extension");
|
||||
automatic_help_id = GIMP_HELP_FILE_SAVE_BY_EXTENSION;
|
||||
|
||||
local_only = (gimp_pdb_lookup_procedure (gimp->pdb,
|
||||
"file-uri-save") == NULL &&
|
||||
! g_getenv ("GIMP_HANDLE_REMOTE_FILES"));
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -359,7 +350,7 @@ gimp_file_dialog_new (Gimp *gimp,
|
||||
"title", title,
|
||||
"role", role,
|
||||
"action", gtk_action,
|
||||
"local-only", local_only,
|
||||
"local-only", FALSE,
|
||||
"do-overwrite-confirmation", TRUE,
|
||||
NULL);
|
||||
|
||||
|
@ -2201,7 +2201,6 @@ plug-ins/file-ico/Makefile
|
||||
plug-ins/file-jpeg/Makefile
|
||||
plug-ins/file-psd/Makefile
|
||||
plug-ins/file-sgi/Makefile
|
||||
plug-ins/file-uri/Makefile
|
||||
plug-ins/flame/Makefile
|
||||
plug-ins/fractal-explorer/Makefile
|
||||
plug-ins/fractal-explorer/examples/Makefile
|
||||
|
@ -42,7 +42,6 @@ SUBDIRS = \
|
||||
file-jpeg \
|
||||
file-psd \
|
||||
file-sgi \
|
||||
file-uri \
|
||||
flame \
|
||||
fractal-explorer \
|
||||
gfig \
|
||||
|
7
plug-ins/file-uri/.gitignore
vendored
7
plug-ins/file-uri/.gitignore
vendored
@ -1,7 +0,0 @@
|
||||
/Makefile.in
|
||||
/Makefile
|
||||
/.deps
|
||||
/_libs
|
||||
/.libs
|
||||
/file-uri
|
||||
/file-uri.exe
|
@ -1,48 +0,0 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
libgimpui = $(top_builddir)/libgimp/libgimpui-$(GIMP_API_VERSION).la
|
||||
libgimpconfig = $(top_builddir)/libgimpconfig/libgimpconfig-$(GIMP_API_VERSION).la
|
||||
libgimpwidgets = $(top_builddir)/libgimpwidgets/libgimpwidgets-$(GIMP_API_VERSION).la
|
||||
libgimp = $(top_builddir)/libgimp/libgimp-$(GIMP_API_VERSION).la
|
||||
libgimpcolor = $(top_builddir)/libgimpcolor/libgimpcolor-$(GIMP_API_VERSION).la
|
||||
libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la
|
||||
libgimpmath = $(top_builddir)/libgimpmath/libgimpmath-$(GIMP_API_VERSION).la
|
||||
|
||||
if OS_WIN32
|
||||
mwindows = -mwindows
|
||||
endif
|
||||
|
||||
if HAVE_WINDRES
|
||||
include $(top_srcdir)/build/windows/gimprc-plug-ins.rule
|
||||
file_uri_RC = file-uri.rc.o
|
||||
endif
|
||||
|
||||
AM_LDFLAGS = $(mwindows)
|
||||
|
||||
libexecdir = $(gimpplugindir)/plug-ins
|
||||
|
||||
libexec_PROGRAMS = file-uri
|
||||
|
||||
file_uri_SOURCES = \
|
||||
uri.c \
|
||||
uri-backend.h \
|
||||
uri-backend-gvfs.c
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir) \
|
||||
$(GTK_CFLAGS) \
|
||||
$(GEGL_CFLAGS) \
|
||||
-I$(includedir)
|
||||
|
||||
LDADD = \
|
||||
$(libgimpui) \
|
||||
$(libgimpwidgets) \
|
||||
$(libgimpconfig) \
|
||||
$(libgimpmath) \
|
||||
$(libgimp) \
|
||||
$(libgimpcolor) \
|
||||
$(libgimpbase) \
|
||||
$(GTK_LIBS) \
|
||||
$(RT_LIBS) \
|
||||
$(INTLLIBS) \
|
||||
$(file_uri_RC)
|
@ -1,313 +0,0 @@
|
||||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* URI plug-in, GIO/GVfs backend
|
||||
* Copyright (C) 2008 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <libgimp/gimp.h>
|
||||
#include <libgimp/gimpui.h>
|
||||
|
||||
#include "uri-backend.h"
|
||||
|
||||
#include "libgimp/stdplugins-intl.h"
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DOWNLOAD,
|
||||
UPLOAD
|
||||
} Mode;
|
||||
|
||||
|
||||
static gchar * get_protocols (void);
|
||||
static gboolean copy_file (GFile *src_file,
|
||||
GFile *dest_file,
|
||||
Mode mode,
|
||||
GimpRunMode run_mode,
|
||||
GError **error);
|
||||
static gboolean mount_enclosing_volume (GFile *file,
|
||||
GError **error);
|
||||
|
||||
static gchar *supported_protocols = NULL;
|
||||
|
||||
|
||||
gboolean
|
||||
uri_backend_init (const gchar *plugin_name,
|
||||
gboolean run,
|
||||
GimpRunMode run_mode,
|
||||
GError **error)
|
||||
{
|
||||
if (run_mode == GIMP_RUN_INTERACTIVE)
|
||||
{
|
||||
gimp_ui_init (plugin_name, FALSE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
uri_backend_shutdown (void)
|
||||
{
|
||||
}
|
||||
|
||||
const gchar *
|
||||
uri_backend_get_load_help (void)
|
||||
{
|
||||
return "Loads a file using the GIO Virtual File System";
|
||||
}
|
||||
|
||||
const gchar *
|
||||
uri_backend_get_save_help (void)
|
||||
{
|
||||
return "Saves a file using the GIO Virtual File System";
|
||||
}
|
||||
|
||||
const gchar *
|
||||
uri_backend_get_load_protocols (void)
|
||||
{
|
||||
if (! supported_protocols)
|
||||
supported_protocols = get_protocols ();
|
||||
|
||||
return supported_protocols;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
uri_backend_get_save_protocols (void)
|
||||
{
|
||||
if (! supported_protocols)
|
||||
supported_protocols = get_protocols ();
|
||||
|
||||
return supported_protocols;
|
||||
}
|
||||
|
||||
gboolean
|
||||
uri_backend_load_image (GFile *file,
|
||||
GFile *local_file,
|
||||
GimpRunMode run_mode,
|
||||
GError **error)
|
||||
{
|
||||
return copy_file (file, local_file, DOWNLOAD, run_mode, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
uri_backend_save_image (GFile *file,
|
||||
GFile *local_file,
|
||||
GimpRunMode run_mode,
|
||||
GError **error)
|
||||
{
|
||||
return copy_file (local_file, file, UPLOAD, run_mode, error);
|
||||
}
|
||||
|
||||
GFile *
|
||||
uri_backend_map_image (GFile *file,
|
||||
GimpRunMode run_mode)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
|
||||
if (run_mode == GIMP_RUN_INTERACTIVE)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (! mount_enclosing_volume (file, &error))
|
||||
{
|
||||
if (error->domain != G_IO_ERROR ||
|
||||
error->code != G_IO_ERROR_ALREADY_MOUNTED)
|
||||
success = FALSE;
|
||||
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
if (success && g_file_is_native (file))
|
||||
return g_object_ref (file);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static gchar *
|
||||
get_protocols (void)
|
||||
{
|
||||
const gchar * const *schemes;
|
||||
GString *string = g_string_new (NULL);
|
||||
gint i;
|
||||
|
||||
schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
|
||||
|
||||
for (i = 0; schemes && schemes[i]; i++)
|
||||
{
|
||||
if (string->len > 0)
|
||||
g_string_append_c (string, ',');
|
||||
|
||||
g_string_append (string, schemes[i]);
|
||||
g_string_append_c (string, ':');
|
||||
}
|
||||
|
||||
return g_string_free (string, FALSE);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Mode mode;
|
||||
GTimeVal last_time;
|
||||
} UriProgress;
|
||||
|
||||
static void
|
||||
uri_progress_callback (goffset current_num_bytes,
|
||||
goffset total_num_bytes,
|
||||
gpointer user_data)
|
||||
{
|
||||
UriProgress *progress = user_data;
|
||||
GTimeVal now;
|
||||
|
||||
/* update the progress only up to 10 times a second */
|
||||
g_get_current_time (&now);
|
||||
|
||||
if (progress->last_time.tv_sec &&
|
||||
((now.tv_sec - progress->last_time.tv_sec) * 1000 +
|
||||
(now.tv_usec - progress->last_time.tv_usec) / 1000) < 100)
|
||||
return;
|
||||
|
||||
progress->last_time = now;
|
||||
|
||||
if (total_num_bytes > 0)
|
||||
{
|
||||
const gchar *format;
|
||||
gchar *done = g_format_size (current_num_bytes);
|
||||
gchar *total = g_format_size (total_num_bytes);
|
||||
|
||||
switch (progress->mode)
|
||||
{
|
||||
case DOWNLOAD:
|
||||
format = _("Downloading image (%s of %s)");
|
||||
break;
|
||||
|
||||
case UPLOAD:
|
||||
format = _("Uploading image (%s of %s)");
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
gimp_progress_set_text_printf (format, done, total);
|
||||
gimp_progress_update ((gdouble) current_num_bytes /
|
||||
(gdouble) total_num_bytes);
|
||||
|
||||
g_free (total);
|
||||
g_free (done);
|
||||
}
|
||||
else
|
||||
{
|
||||
const gchar *format;
|
||||
gchar *done = g_format_size (current_num_bytes);
|
||||
|
||||
switch (progress->mode)
|
||||
{
|
||||
case DOWNLOAD:
|
||||
format = _("Downloaded %s of image data");
|
||||
break;
|
||||
|
||||
case UPLOAD:
|
||||
format = _("Uploaded %s of image data");
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
gimp_progress_set_text_printf (format, done);
|
||||
gimp_progress_pulse ();
|
||||
|
||||
g_free (done);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mount_volume_ready (GFile *file,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
g_file_mount_enclosing_volume_finish (file, res, error);
|
||||
|
||||
gtk_main_quit ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mount_enclosing_volume (GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
GMountOperation *operation = gtk_mount_operation_new (NULL);
|
||||
|
||||
g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE,
|
||||
operation,
|
||||
NULL,
|
||||
(GAsyncReadyCallback) mount_volume_ready,
|
||||
error);
|
||||
gtk_main ();
|
||||
|
||||
g_object_unref (operation);
|
||||
|
||||
return (*error == NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
copy_file (GFile *src_file,
|
||||
GFile *dest_file,
|
||||
Mode mode,
|
||||
GimpRunMode run_mode,
|
||||
GError **error)
|
||||
{
|
||||
UriProgress progress = { 0, };
|
||||
gboolean success;
|
||||
|
||||
gimp_progress_init (_("Connecting to server"));
|
||||
|
||||
progress.mode = mode;
|
||||
|
||||
success = g_file_copy (src_file, dest_file, G_FILE_COPY_OVERWRITE, NULL,
|
||||
uri_progress_callback, &progress,
|
||||
error);
|
||||
gimp_progress_update (1.0);
|
||||
|
||||
if (! success &&
|
||||
run_mode == GIMP_RUN_INTERACTIVE &&
|
||||
(*error)->domain == G_IO_ERROR &&
|
||||
(*error)->code == G_IO_ERROR_NOT_MOUNTED)
|
||||
{
|
||||
g_clear_error (error);
|
||||
|
||||
if (mount_enclosing_volume (mode == DOWNLOAD ? src_file : dest_file,
|
||||
error))
|
||||
{
|
||||
success = g_file_copy (src_file, dest_file, 0, NULL,
|
||||
uri_progress_callback, &progress,
|
||||
error);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __URI_BACKEND_H__
|
||||
#define __URI_BACKEND_H__
|
||||
|
||||
|
||||
gboolean uri_backend_init (const gchar *plugin_name,
|
||||
gboolean run,
|
||||
GimpRunMode run_mode,
|
||||
GError **error);
|
||||
void uri_backend_shutdown (void);
|
||||
|
||||
const gchar * uri_backend_get_load_help (void);
|
||||
const gchar * uri_backend_get_save_help (void);
|
||||
|
||||
const gchar * uri_backend_get_load_protocols (void);
|
||||
const gchar * uri_backend_get_save_protocols (void);
|
||||
|
||||
gboolean uri_backend_load_image (GFile *file,
|
||||
GFile *local_file,
|
||||
GimpRunMode run_mode,
|
||||
GError **error);
|
||||
gboolean uri_backend_save_image (GFile *file,
|
||||
GFile *local_file,
|
||||
GimpRunMode run_mode,
|
||||
GError **error);
|
||||
GFile * uri_backend_map_image (GFile *file,
|
||||
GimpRunMode run_mode);
|
||||
|
||||
|
||||
#endif /* __URI_BACKEND_H__ */
|
@ -1,400 +0,0 @@
|
||||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Author: Josh MacDonald. */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include <libgimp/gimp.h>
|
||||
#include <libgimp/gimpui.h>
|
||||
|
||||
#include "uri-backend.h"
|
||||
|
||||
#include "libgimp/stdplugins-intl.h"
|
||||
|
||||
|
||||
#define LOAD_PROC "file-uri-load"
|
||||
#define SAVE_PROC "file-uri-save"
|
||||
#define PLUG_IN_BINARY "file-uri"
|
||||
#define PLUG_IN_ROLE "gimp-file-uri"
|
||||
|
||||
|
||||
static void query (void);
|
||||
static void run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static gint32 load_image (GFile *file,
|
||||
GimpRunMode run_mode,
|
||||
GError **error);
|
||||
static GimpPDBStatusType save_image (GFile *file,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
gint32 run_mode,
|
||||
GError **error);
|
||||
|
||||
static GFile * get_temp_file (GFile *file,
|
||||
gboolean *name_image);
|
||||
static gboolean valid_file (GFile *file);
|
||||
|
||||
|
||||
const GimpPlugInInfo PLUG_IN_INFO =
|
||||
{
|
||||
NULL, /* init_proc */
|
||||
NULL, /* quit_proc */
|
||||
query, /* query_proc */
|
||||
run, /* run_proc */
|
||||
};
|
||||
|
||||
MAIN ()
|
||||
|
||||
static void
|
||||
query (void)
|
||||
{
|
||||
static const GimpParamDef load_args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_STRING, "raw-filename", "The name entered" }
|
||||
};
|
||||
|
||||
static const GimpParamDef load_return_vals[] =
|
||||
{
|
||||
{ GIMP_PDB_IMAGE, "image", "Output image" }
|
||||
};
|
||||
|
||||
static const GimpParamDef save_args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
||||
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
||||
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
|
||||
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" }
|
||||
};
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
if (g_getenv ("GIMP_HANDLE_REMOTE_FILES"))
|
||||
return;
|
||||
|
||||
if (! uri_backend_init (PLUG_IN_BINARY,
|
||||
FALSE,
|
||||
GIMP_RUN_NONINTERACTIVE,
|
||||
&error))
|
||||
{
|
||||
g_message ("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (uri_backend_get_load_protocols ())
|
||||
{
|
||||
gimp_install_procedure (LOAD_PROC,
|
||||
"loads files given an URI",
|
||||
uri_backend_get_load_help (),
|
||||
"Spencer Kimball & Peter Mattis",
|
||||
"Spencer Kimball & Peter Mattis",
|
||||
"1995-2008",
|
||||
N_("URI"),
|
||||
NULL,
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (load_args),
|
||||
G_N_ELEMENTS (load_return_vals),
|
||||
load_args, load_return_vals);
|
||||
|
||||
gimp_plugin_icon_register (LOAD_PROC, GIMP_ICON_TYPE_ICON_NAME,
|
||||
(const guint8 *) GIMP_STOCK_WEB);
|
||||
gimp_register_load_handler (LOAD_PROC,
|
||||
"", uri_backend_get_load_protocols ());
|
||||
gimp_register_file_handler_uri (LOAD_PROC);
|
||||
}
|
||||
|
||||
if (uri_backend_get_save_protocols ())
|
||||
{
|
||||
gimp_install_procedure (SAVE_PROC,
|
||||
"saves files given an URI",
|
||||
uri_backend_get_save_help (),
|
||||
"Michael Natterer, Sven Neumann",
|
||||
"Michael Natterer",
|
||||
"2005-2008",
|
||||
N_("URI"),
|
||||
"RGB*, GRAY*, INDEXED*",
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (save_args), 0,
|
||||
save_args, NULL);
|
||||
|
||||
gimp_plugin_icon_register (SAVE_PROC, GIMP_ICON_TYPE_ICON_NAME,
|
||||
(const guint8 *) GIMP_STOCK_WEB);
|
||||
gimp_register_save_handler (SAVE_PROC,
|
||||
"", uri_backend_get_save_protocols ());
|
||||
gimp_register_file_handler_uri (SAVE_PROC);
|
||||
}
|
||||
|
||||
uri_backend_shutdown ();
|
||||
}
|
||||
|
||||
static void
|
||||
run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
{
|
||||
static GimpParam values[2];
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
|
||||
gint32 image_ID;
|
||||
GError *error = NULL;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
*nreturn_vals = 1;
|
||||
*return_vals = values;
|
||||
|
||||
values[0].type = GIMP_PDB_STATUS;
|
||||
values[0].data.d_status = status;
|
||||
|
||||
if (! uri_backend_init (PLUG_IN_BINARY, TRUE, run_mode, &error))
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* We handle PDB errors by forwarding them to the caller in
|
||||
* our return values.
|
||||
*/
|
||||
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);
|
||||
|
||||
if (! strcmp (name, LOAD_PROC) && uri_backend_get_load_protocols ())
|
||||
{
|
||||
image_ID = load_image (g_file_new_for_uri (param[2].data.d_string),
|
||||
run_mode, &error);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
status = GIMP_PDB_SUCCESS;
|
||||
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_IMAGE;
|
||||
values[1].data.d_image = image_ID;
|
||||
}
|
||||
}
|
||||
else if (! strcmp (name, SAVE_PROC) && uri_backend_get_save_protocols ())
|
||||
{
|
||||
status = save_image (g_file_new_for_uri (param[3].data.d_string),
|
||||
param[1].data.d_int32,
|
||||
param[2].data.d_int32,
|
||||
run_mode, &error);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
}
|
||||
|
||||
uri_backend_shutdown ();
|
||||
|
||||
if (status != GIMP_PDB_SUCCESS && error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
|
||||
values[0].data.d_status = status;
|
||||
}
|
||||
|
||||
static gint32
|
||||
load_image (GFile *file,
|
||||
GimpRunMode run_mode,
|
||||
GError **error)
|
||||
{
|
||||
gint32 image_ID = -1;
|
||||
gboolean name_image = FALSE;
|
||||
GFile *local_file;
|
||||
gboolean mapped = FALSE;
|
||||
|
||||
local_file = uri_backend_map_image (file, run_mode);
|
||||
|
||||
if (local_file)
|
||||
{
|
||||
mapped = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
local_file = get_temp_file (file, &name_image);
|
||||
|
||||
if (! uri_backend_load_image (file, local_file, run_mode, error))
|
||||
return -1;
|
||||
}
|
||||
|
||||
image_ID = gimp_file_load (run_mode,
|
||||
g_file_get_path (local_file),
|
||||
g_file_get_path (local_file));
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
if (mapped || name_image)
|
||||
gimp_image_set_filename (image_ID, g_file_get_uri (file));
|
||||
else
|
||||
gimp_image_set_filename (image_ID, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
"%s", gimp_get_pdb_error ());
|
||||
}
|
||||
|
||||
if (! mapped)
|
||||
g_file_delete (local_file, NULL, NULL);
|
||||
|
||||
g_object_unref (local_file);
|
||||
|
||||
return image_ID;
|
||||
}
|
||||
|
||||
static GimpPDBStatusType
|
||||
save_image (GFile *file,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
gint32 run_mode,
|
||||
GError **error)
|
||||
{
|
||||
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
|
||||
GFile *local_file;
|
||||
gboolean mapped = FALSE;
|
||||
|
||||
local_file = uri_backend_map_image (file, run_mode);
|
||||
|
||||
if (local_file)
|
||||
mapped = TRUE;
|
||||
else
|
||||
local_file = get_temp_file (file, NULL);
|
||||
|
||||
if (gimp_file_save (run_mode,
|
||||
image_ID,
|
||||
drawable_ID,
|
||||
g_file_get_path (local_file),
|
||||
g_file_get_path (local_file)))
|
||||
{
|
||||
if (mapped)
|
||||
{
|
||||
status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
else if (valid_file (local_file))
|
||||
{
|
||||
if (uri_backend_save_image (file, local_file, run_mode, error))
|
||||
{
|
||||
status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
_("Failed to save to temporary file '%s'"),
|
||||
gimp_file_get_utf8_name (local_file));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
"%s", gimp_get_pdb_error ());
|
||||
}
|
||||
|
||||
if (! mapped)
|
||||
g_file_delete (local_file, NULL, NULL);
|
||||
|
||||
g_object_unref (local_file);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static GFile *
|
||||
get_temp_file (GFile *file,
|
||||
gboolean *name_image)
|
||||
{
|
||||
gchar *basename;
|
||||
gchar *tmpname = NULL;
|
||||
GFile *tmpfile;
|
||||
|
||||
if (name_image)
|
||||
*name_image = FALSE;
|
||||
|
||||
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
||||
|
||||
if (basename)
|
||||
{
|
||||
gchar *ext = strchr (basename, '.');
|
||||
|
||||
if (ext && strlen (ext))
|
||||
{
|
||||
tmpname = gimp_temp_name (ext + 1);
|
||||
|
||||
if (name_image)
|
||||
*name_image = TRUE;
|
||||
}
|
||||
|
||||
g_free (basename);
|
||||
}
|
||||
|
||||
if (! tmpname)
|
||||
tmpname = gimp_temp_name ("xxx");
|
||||
|
||||
tmpfile = g_file_new_for_path (tmpname);
|
||||
|
||||
g_free (tmpname);
|
||||
|
||||
return tmpfile;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
valid_file (GFile *file)
|
||||
{
|
||||
GFileInfo *info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_SIZE,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, NULL);
|
||||
|
||||
if (info)
|
||||
{
|
||||
goffset size = g_file_info_get_size (info);
|
||||
|
||||
g_object_unref (info);
|
||||
|
||||
return size > 0;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
@ -139,8 +139,6 @@ plug-ins/file-psd/psd-thumb-load.c
|
||||
plug-ins/file-psd/psd-util.c
|
||||
plug-ins/file-psd/psd.c
|
||||
plug-ins/file-sgi/sgi.c
|
||||
plug-ins/file-uri/uri-backend-gvfs.c
|
||||
plug-ins/file-uri/uri.c
|
||||
plug-ins/flame/flame.c
|
||||
plug-ins/fractal-explorer/fractal-explorer-dialogs.c
|
||||
plug-ins/fractal-explorer/fractal-explorer.c
|
||||
|
Reference in New Issue
Block a user