Commit 57e6b22b authored by Michael Natterer's avatar Michael Natterer 😴

app, plug-ins: remove file-uri completely

and enable the new file-remote code in app unconditionally.
parent f6823bdc
...@@ -148,7 +148,7 @@ file_open_image (Gimp *gimp, ...@@ -148,7 +148,7 @@ file_open_image (Gimp *gimp,
{ {
path = g_file_get_path (file); path = g_file_get_path (file);
if (! path && g_getenv ("GIMP_HANDLE_REMOTE_FILES")) if (! path)
{ {
GError *my_error = NULL; GError *my_error = NULL;
......
...@@ -254,7 +254,6 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc, ...@@ -254,7 +254,6 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc,
const gchar *name = gimp_object_get_name (file_proc); const gchar *name = gimp_object_get_name (file_proc);
gboolean is_xcf_save = FALSE; gboolean is_xcf_save = FALSE;
gboolean is_filter = FALSE; gboolean is_filter = FALSE;
gboolean is_uri = FALSE;
is_xcf_save = (strcmp (name, "gimp-xcf-save") == 0); is_xcf_save = (strcmp (name, "gimp-xcf-save") == 0);
...@@ -262,17 +261,15 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc, ...@@ -262,17 +261,15 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc,
strcmp (name, "file-bz2-save") == 0 || strcmp (name, "file-bz2-save") == 0 ||
strcmp (name, "file-xz-save") == 0); strcmp (name, "file-xz-save") == 0);
is_uri = (strcmp (name, "file-uri-save") == 0);
switch (group) switch (group)
{ {
case FILE_PROCEDURE_GROUP_SAVE: case FILE_PROCEDURE_GROUP_SAVE:
/* Only .xcf shall pass */ /* Only .xcf shall pass */
return is_xcf_save || is_filter || is_uri; return is_xcf_save || is_filter;
case FILE_PROCEDURE_GROUP_EXPORT: case FILE_PROCEDURE_GROUP_EXPORT:
/* Anything but .xcf shall pass */ /* Anything but .xcf shall pass */
return ! is_xcf_save || is_uri; return ! is_xcf_save;
case FILE_PROCEDURE_GROUP_OPEN: case FILE_PROCEDURE_GROUP_OPEN:
/* No filter applied for Open */ /* No filter applied for Open */
......
...@@ -129,7 +129,7 @@ file_save (Gimp *gimp, ...@@ -129,7 +129,7 @@ file_save (Gimp *gimp,
{ {
path = g_file_get_path (file); path = g_file_get_path (file);
if (! path && g_getenv ("GIMP_HANDLE_REMOTE_FILES")) if (! path)
{ {
GError *my_error = NULL; GError *my_error = NULL;
......
...@@ -310,7 +310,6 @@ gimp_file_dialog_new (Gimp *gimp, ...@@ -310,7 +310,6 @@ gimp_file_dialog_new (Gimp *gimp,
GSList *file_procs_all_images = NULL; GSList *file_procs_all_images = NULL;
const gchar *automatic = NULL; const gchar *automatic = NULL;
const gchar *automatic_help_id = NULL; const gchar *automatic_help_id = NULL;
gboolean local_only = FALSE;
GtkFileChooserAction gtk_action = 0; GtkFileChooserAction gtk_action = 0;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
...@@ -327,10 +326,6 @@ gimp_file_dialog_new (Gimp *gimp, ...@@ -327,10 +326,6 @@ gimp_file_dialog_new (Gimp *gimp,
file_procs_all_images = NULL; file_procs_all_images = NULL;
automatic = _("Automatically Detected"); automatic = _("Automatically Detected");
automatic_help_id = GIMP_HELP_FILE_OPEN_BY_EXTENSION; 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; break;
case GIMP_FILE_CHOOSER_ACTION_SAVE: case GIMP_FILE_CHOOSER_ACTION_SAVE:
...@@ -344,10 +339,6 @@ gimp_file_dialog_new (Gimp *gimp, ...@@ -344,10 +339,6 @@ gimp_file_dialog_new (Gimp *gimp,
gimp->plug_in_manager->save_procs); gimp->plug_in_manager->save_procs);
automatic = _("By Extension"); automatic = _("By Extension");
automatic_help_id = GIMP_HELP_FILE_SAVE_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; break;
default: default:
...@@ -359,7 +350,7 @@ gimp_file_dialog_new (Gimp *gimp, ...@@ -359,7 +350,7 @@ gimp_file_dialog_new (Gimp *gimp,
"title", title, "title", title,
"role", role, "role", role,
"action", gtk_action, "action", gtk_action,
"local-only", local_only, "local-only", FALSE,
"do-overwrite-confirmation", TRUE, "do-overwrite-confirmation", TRUE,
NULL); NULL);
......
...@@ -2201,7 +2201,6 @@ plug-ins/file-ico/Makefile ...@@ -2201,7 +2201,6 @@ plug-ins/file-ico/Makefile
plug-ins/file-jpeg/Makefile plug-ins/file-jpeg/Makefile
plug-ins/file-psd/Makefile plug-ins/file-psd/Makefile
plug-ins/file-sgi/Makefile plug-ins/file-sgi/Makefile
plug-ins/file-uri/Makefile
plug-ins/flame/Makefile plug-ins/flame/Makefile
plug-ins/fractal-explorer/Makefile plug-ins/fractal-explorer/Makefile
plug-ins/fractal-explorer/examples/Makefile plug-ins/fractal-explorer/examples/Makefile
......
...@@ -42,7 +42,6 @@ SUBDIRS = \ ...@@ -42,7 +42,6 @@ SUBDIRS = \
file-jpeg \ file-jpeg \
file-psd \ file-psd \
file-sgi \ file-sgi \
file-uri \
flame \ flame \
fractal-explorer \ fractal-explorer \
gfig \ gfig \
......
/Makefile.in
/Makefile
/.deps
/_libs
/.libs
/file-uri
/file-uri.exe
\ No newline at end of file
## 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)
/* 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;
}
/* 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__ */
/* 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;