pdb: allow file procedures to register themselves for handling URIs

and store the flag in pluginrc. There are no URIs passed to procedures
yet and no procedure registers as such, this is just preparation.
This commit is contained in:
Michael Natterer 2012-11-17 16:01:52 +01:00
parent c5f1fd1fda
commit 07f77e5ec8
11 changed files with 176 additions and 4 deletions

View File

@ -526,6 +526,33 @@ register_file_handler_mime_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
register_file_handler_uri_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
const gchar *procedure_name;
procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_handles_uri (gimp->plug_in_manager,
canonical);
g_free (canonical);
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
register_thumbnail_loader_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -1013,6 +1040,30 @@ register_fileops_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-register-file-handler-uri
*/
procedure = gimp_procedure_new (register_file_handler_uri_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-register-file-handler-uri");
gimp_procedure_set_static_strings (procedure,
"gimp-register-file-handler-uri",
"Registers a file handler procedure as capable of handling URIs.",
"Registers a file handler procedure as capable of handling URIs. This allows GIMP to call the procecure directly for all kinds of URIs, and the 'filename' traditionally passed to file procesures turns into an URI.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2012",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("procedure-name",
"procedure name",
"The name of the procedure to enable URIs for.",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-register-thumbnail-loader
*/

View File

@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 680 procedures registered total */
/* 681 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -177,6 +177,31 @@ gimp_plug_in_manager_register_mime_type (GimpPlugInManager *manager,
return TRUE;
}
gboolean
gimp_plug_in_manager_register_handles_uri (GimpPlugInManager *manager,
const gchar *name)
{
GimpPlugInProcedure *file_proc;
GSList *list;
g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
if (manager->current_plug_in && manager->current_plug_in->plug_in_def)
list = manager->current_plug_in->plug_in_def->procedures;
else
list = manager->plug_in_procedures;
file_proc = gimp_plug_in_procedure_find (list, name);
if (! file_proc)
return FALSE;
gimp_plug_in_procedure_set_handles_uri (file_proc);
return TRUE;
}
gboolean
gimp_plug_in_manager_register_thumb_loader (GimpPlugInManager *manager,
const gchar *load_proc,

View File

@ -35,6 +35,9 @@ gboolean gimp_plug_in_manager_register_mime_type (GimpPlugInManager *manage
const gchar *name,
const gchar *mime_type);
gboolean gimp_plug_in_manager_register_handles_uri (GimpPlugInManager *manager,
const gchar *name);
gboolean gimp_plug_in_manager_register_thumb_loader (GimpPlugInManager *manager,
const gchar *load_proc,
const gchar *thumb_proc);

View File

@ -942,6 +942,14 @@ gimp_plug_in_procedure_set_mime_type (GimpPlugInProcedure *proc,
proc->mime_type = g_strdup (mime_type);
}
void
gimp_plug_in_procedure_set_handles_uri (GimpPlugInProcedure *proc)
{
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
proc->handles_uri = TRUE;
}
void
gimp_plug_in_procedure_set_thumb_loader (GimpPlugInProcedure *proc,
const gchar *thumb_loader)

View File

@ -62,6 +62,7 @@ struct _GimpPlugInProcedure
gchar *prefixes;
gchar *magics;
gchar *mime_type;
gboolean handles_uri;
GSList *extensions_list;
GSList *prefixes_list;
GSList *magics_list;
@ -126,6 +127,7 @@ void gimp_plug_in_procedure_set_file_proc (GimpPlugInProcedure
const gchar *magics);
void gimp_plug_in_procedure_set_mime_type (GimpPlugInProcedure *proc,
const gchar *mime_ype);
void gimp_plug_in_procedure_set_handles_uri (GimpPlugInProcedure *proc);
void gimp_plug_in_procedure_set_thumb_loader(GimpPlugInProcedure *proc,
const gchar *thumbnailer);

View File

@ -39,7 +39,7 @@
#include "gimp-intl.h"
#define PLUG_IN_RC_FILE_VERSION 1
#define PLUG_IN_RC_FILE_VERSION 2
/*
@ -90,6 +90,7 @@ enum
PREFIX,
MAGIC,
MIME_TYPE,
HANDLES_URI,
THUMB_LOADER
};
@ -153,6 +154,8 @@ plug_in_rc_parse (Gimp *gimp,
"magic", GINT_TO_POINTER (MAGIC));
g_scanner_scope_add_symbol (scanner, LOAD_PROC,
"mime-type", GINT_TO_POINTER (MIME_TYPE));
g_scanner_scope_add_symbol (scanner, LOAD_PROC,
"handles-uri", GINT_TO_POINTER (HANDLES_URI));
g_scanner_scope_add_symbol (scanner, LOAD_PROC,
"thumb-loader", GINT_TO_POINTER (THUMB_LOADER));
@ -162,6 +165,8 @@ plug_in_rc_parse (Gimp *gimp,
"prefix", GINT_TO_POINTER (PREFIX));
g_scanner_scope_add_symbol (scanner, SAVE_PROC,
"mime-type", GINT_TO_POINTER (MIME_TYPE));
g_scanner_scope_add_symbol (scanner, SAVE_PROC,
"handles-uri", GINT_TO_POINTER (HANDLES_URI));
token = G_TOKEN_LEFT_PAREN;
@ -598,7 +603,7 @@ plug_in_file_proc_deserialize (GScanner *scanner,
if (! gimp_scanner_parse_string_no_validate (scanner, &value))
return G_TOKEN_STRING;
}
else
else if (symbol != HANDLES_URI)
{
if (! gimp_scanner_parse_string (scanner, &value))
return G_TOKEN_STRING;
@ -626,6 +631,10 @@ plug_in_file_proc_deserialize (GScanner *scanner,
g_free (value);
break;
case HANDLES_URI:
gimp_plug_in_procedure_set_handles_uri (proc);
break;
case THUMB_LOADER:
gimp_plug_in_procedure_set_thumb_loader (proc, value);
g_free (value);
@ -917,6 +926,12 @@ plug_in_rc_write (GSList *plug_in_defs,
gimp_config_writer_close (writer);
}
if (proc->handles_uri)
{
gimp_config_writer_open (writer, "handles-uri");
gimp_config_writer_close (writer);
}
if (proc->thumb_loader)
{
gimp_config_writer_open (writer, "thumb-loader");

View File

@ -708,6 +708,7 @@ EXPORTS
gimp_read_expect_msg
gimp_rect_select
gimp_register_file_handler_mime
gimp_register_file_handler_uri
gimp_register_load_handler
gimp_register_magic_load_handler
gimp_register_save_handler

View File

@ -431,6 +431,40 @@ gimp_register_file_handler_mime (const gchar *procedure_name,
return success;
}
/**
* gimp_register_file_handler_uri:
* @procedure_name: The name of the procedure to enable URIs for.
*
* Registers a file handler procedure as capable of handling URIs.
*
* Registers a file handler procedure as capable of handling URIs. This
* allows GIMP to call the procecure directly for all kinds of URIs,
* and the 'filename' traditionally passed to file procesures turns
* into an URI.
*
* Returns: TRUE on success.
*
* Since: GIMP 2.10
**/
gboolean
gimp_register_file_handler_uri (const gchar *procedure_name)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-register-file-handler-uri",
&nreturn_vals,
GIMP_PDB_STRING, procedure_name,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_register_thumbnail_loader:
* @load_proc: The name of the procedure the thumbnail loader with.

View File

@ -62,6 +62,7 @@ gboolean gimp_register_save_handler (const gchar *procedure_name,
const gchar *prefixes);
gboolean gimp_register_file_handler_mime (const gchar *procedure_name,
const gchar *mime_type);
gboolean gimp_register_file_handler_uri (const gchar *procedure_name);
gboolean gimp_register_thumbnail_loader (const gchar *load_proc,
const gchar *thumb_proc);

View File

@ -545,6 +545,37 @@ CODE
);
}
sub register_file_handler_uri {
$blurb = 'Registers a file handler procedure as capable of handling URIs.';
$help = <<'HELP';
Registers a file handler procedure as capable of handling URIs. This
allows GIMP to call the procecure directly for all kinds of URIs, and
the 'filename' traditionally passed to file procesures turns into an
URI.
HELP
&mitch_pdb_misc('2012', '2.10');
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => "The name of the procedure to enable URIs for." }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_handles_uri (gimp->plug_in_manager,
canonical);
g_free (canonical);
}
CODE
);
}
sub register_file_handler_mime {
$blurb = 'Associates a MIME type with a file handler procedure.';
@ -636,9 +667,10 @@ CODE
register_load_handler
register_save_handler
register_file_handler_mime
register_file_handler_uri
register_thumbnail_loader);
%exports = (app => [@procs], lib => [@procs[0..3,5..11]]);
%exports = (app => [@procs], lib => [@procs[0..3,5..12]]);
$desc = 'File Operations';
$doc_title = 'gimpfileops';