[gimp] pdb: allow file procedures to register themselves for handling URIs
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb: allow file procedures to register themselves for handling URIs
- Date: Sat, 17 Nov 2012 15:03:55 +0000 (UTC)
commit 07f77e5ec8c745a58786ffda4f341238f9ada10c
Author: Michael Natterer <mitch gimp org>
Date: Sat Nov 17 16:01:52 2012 +0100
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.
app/pdb/fileops-cmds.c | 51 ++++++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
app/plug-in/gimppluginmanager-file.c | 25 ++++++++++++++++
app/plug-in/gimppluginmanager-file.h | 3 ++
app/plug-in/gimppluginprocedure.c | 8 +++++
app/plug-in/gimppluginprocedure.h | 2 +
app/plug-in/plug-in-rc.c | 19 +++++++++++-
libgimp/gimp.def | 1 +
libgimp/gimpfileops_pdb.c | 34 ++++++++++++++++++++++
libgimp/gimpfileops_pdb.h | 1 +
tools/pdbgen/pdb/fileops.pdb | 34 ++++++++++++++++++++++-
11 files changed, 176 insertions(+), 4 deletions(-)
---
diff --git a/app/pdb/fileops-cmds.c b/app/pdb/fileops-cmds.c
index 954b479..f2a2dc5 100644
--- a/app/pdb/fileops-cmds.c
+++ b/app/pdb/fileops-cmds.c
@@ -527,6 +527,33 @@ register_file_handler_mime_invoker (GimpProcedure *procedure,
}
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,
GimpContext *context,
@@ -1014,6 +1041,30 @@ register_fileops_procs (GimpPDB *pdb)
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
*/
procedure = gimp_procedure_new (register_thumbnail_loader_invoker);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index ff65aef..64376c8 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 680 procedures registered total */
+/* 681 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/app/plug-in/gimppluginmanager-file.c b/app/plug-in/gimppluginmanager-file.c
index 15d6aa3..8e1495e 100644
--- a/app/plug-in/gimppluginmanager-file.c
+++ b/app/plug-in/gimppluginmanager-file.c
@@ -178,6 +178,31 @@ gimp_plug_in_manager_register_mime_type (GimpPlugInManager *manager,
}
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,
const gchar *thumb_proc)
diff --git a/app/plug-in/gimppluginmanager-file.h b/app/plug-in/gimppluginmanager-file.h
index 0aa3a2b..6865cd8 100644
--- a/app/plug-in/gimppluginmanager-file.h
+++ b/app/plug-in/gimppluginmanager-file.h
@@ -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);
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index 74fb5c7..abfd0ed 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -943,6 +943,14 @@ gimp_plug_in_procedure_set_mime_type (GimpPlugInProcedure *proc,
}
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)
{
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index 57dba9f..caf21c2 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -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);
diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c
index f521bfd..f448d51 100644
--- a/app/plug-in/plug-in-rc.c
+++ b/app/plug-in/plug-in-rc.c
@@ -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
};
@@ -154,6 +155,8 @@ plug_in_rc_parse (Gimp *gimp,
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));
g_scanner_scope_add_symbol (scanner, SAVE_PROC,
@@ -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");
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 710a8b2..3da1f8a 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -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
diff --git a/libgimp/gimpfileops_pdb.c b/libgimp/gimpfileops_pdb.c
index e442e41..d254b20 100644
--- a/libgimp/gimpfileops_pdb.c
+++ b/libgimp/gimpfileops_pdb.c
@@ -432,6 +432,40 @@ gimp_register_file_handler_mime (const gchar *procedure_name,
}
/**
+ * 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.
* @thumb_proc: The name of the thumbnail load procedure.
diff --git a/libgimp/gimpfileops_pdb.h b/libgimp/gimpfileops_pdb.h
index f22bed7..f7403d1 100644
--- a/libgimp/gimpfileops_pdb.h
+++ b/libgimp/gimpfileops_pdb.h
@@ -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);
diff --git a/tools/pdbgen/pdb/fileops.pdb b/tools/pdbgen/pdb/fileops.pdb
index 41f58c0..64667f2 100644
--- a/tools/pdbgen/pdb/fileops.pdb
+++ b/tools/pdbgen/pdb/fileops.pdb
@@ -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';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]