added backend methods uri_backend_init() and uri_backend_shutdown().

2005-02-07  Michael Natterer  <mitch@gimp.org>

	* plug-ins/uri/uri-backend.h: added backend methods
	uri_backend_init() and uri_backend_shutdown().

	* plug-ins/uri/uri.c: call them around using other backend
	functions (both in query() and run()).

	* plug-ins/uri/uri-backend-gnomevfs.c: moved init()/shutdown() of
	GnomeVFS into the new backend methods. Create the list of
	supported protocols dynamically. Get rid of one translatable
	string.

	* plug-ins/uri/uri-backend-wget.c: implement the new methods as
	empty stubs which always succeed.
This commit is contained in:
Michael Natterer 2005-02-07 17:03:41 +00:00 committed by Michael Natterer
parent 5257aa9cbb
commit 796898f72a
5 changed files with 150 additions and 40 deletions

View File

@ -1,3 +1,19 @@
2005-02-07 Michael Natterer <mitch@gimp.org>
* plug-ins/uri/uri-backend.h: added backend methods
uri_backend_init() and uri_backend_shutdown().
* plug-ins/uri/uri.c: call them around using other backend
functions (both in query() and run()).
* plug-ins/uri/uri-backend-gnomevfs.c: moved init()/shutdown() of
GnomeVFS into the new backend methods. Create the list of
supported protocols dynamically. Get rid of one translatable
string.
* plug-ins/uri/uri-backend-wget.c: implement the new methods as
empty stubs which always succeed.
2005-02-07 Sven Neumann <sven@gimp.org>
* libgimpconfig/Makefile.am

View File

@ -35,11 +35,76 @@ static gboolean copy_uri (const gchar *src_uri,
GError **error);
/* private variables */
static gchar *supported_protocols = NULL;
/* public functions */
gboolean
uri_backend_init (GError **error)
{
if (! gnome_vfs_init ())
{
g_set_error (error, 0, 0, "Could not initialize GnomeVFS");
return FALSE;
}
return TRUE;
}
void
uri_backend_shutdown (void)
{
gnome_vfs_shutdown ();
}
const gchar *
uri_backend_get_load_protocols (void)
{
if (! supported_protocols)
{
static const gchar *protocols[] =
{
"http:",
"https:",
"ftp:",
"sftp:",
"ssh:",
"smb:",
"dav:",
"davs:"
};
GString *string = g_string_new (NULL);
gint i;
for (i = 0; i < G_N_ELEMENTS (protocols); i++)
{
gchar *uri;
GnomeVFSURI *vfs_uri;
uri = g_strdup_printf ("%s//foo/bar.xcf", protocols[i]);
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri)
{
if (string->len > 0)
g_string_append_c (string, ',');
g_string_append (string, protocols[i]);
gnome_vfs_uri_unref (vfs_uri);
}
g_free (uri);
}
supported_protocols = g_string_free (string, FALSE);
}
return "http:,https:,ftp:,sftp:,ssh:,smb:,dav:,davs:";
}
@ -56,8 +121,6 @@ uri_backend_load_image (const gchar *uri,
success = copy_uri (uri, dest_uri, error);
g_free (dest_uri);
gnome_vfs_shutdown ();
return success;
}
@ -78,12 +141,6 @@ copy_uri (const gchar *src_uri,
GnomeVFSResult result;
gchar *message;
if (! gnome_vfs_init ())
{
g_set_error (error, 0, 0, "Could not initialize GnomeVFS");
return FALSE;
}
gimp_progress_init (_("Connecting to server..."));
src_info = gnome_vfs_file_info_new ();
@ -121,16 +178,14 @@ copy_uri (const gchar *src_uri,
}
if (file_size > 0)
{
message = g_strdup_printf (_("Downloading %llu bytes of image data..."),
file_size);
else
message = g_strdup_printf (_("Downloaded %llu bytes of image data"),
(GnomeVFSFileSize) 0);
gimp_progress_init (message);
g_free (message);
}
else
{
gimp_progress_init (_("Downloaded 0 bytes of image data"));
}
while (TRUE)
{
@ -193,4 +248,3 @@ copy_uri (const gchar *src_uri,
return TRUE;
}

View File

@ -41,6 +41,17 @@
#define BUFSIZE 1024
gboolean
uri_backend_init (GError **error)
{
return TRUE;
}
void
uri_backend_shutdown (void)
{
}
const gchar *
uri_backend_get_load_protocols (void)
{

View File

@ -20,6 +20,9 @@
#define __URI_BACKEND_H__
gboolean uri_backend_init (GError **error);
void uri_backend_shutdown (void);
const gchar * uri_backend_get_load_protocols (void);
gboolean uri_backend_load_image (const gchar *uri,
const gchar *tmpname,

View File

@ -70,6 +70,18 @@ query (void)
{ GIMP_PDB_IMAGE, "image", "Output image" }
};
GError *error = NULL;
if (! uri_backend_init (&error))
{
g_message (error->message);
g_clear_error (&error);
return;
}
if (uri_backend_get_load_protocols ())
{
gimp_install_procedure ("file_uri_load",
"loads files given an URI",
"You need to have GNU Wget installed.",
@ -90,6 +102,9 @@ query (void)
uri_backend_get_load_protocols ());
}
uri_backend_shutdown ();
}
static void
run (const gchar *name,
gint nparams,
@ -101,6 +116,7 @@ run (const gchar *name,
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
gint32 image_ID;
GError *error = NULL;
run_mode = param[0].data.d_int32;
@ -110,7 +126,15 @@ run (const gchar *name,
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
if (strcmp (name, "file_uri_load") == 0)
if (! uri_backend_init (&error))
{
g_message (error->message);
g_clear_error (&error);
return;
}
if (! strcmp (name, "file_uri_load") && uri_backend_get_load_protocols ())
{
image_ID = load_image (param[2].data.d_string, run_mode);
@ -128,6 +152,8 @@ run (const gchar *name,
status = GIMP_PDB_CALLING_ERROR;
}
uri_backend_shutdown ();
values[0].data.d_status = status;
}