From fe58de7f81aeaa6b6a2248b866db5d275dd83b59 Mon Sep 17 00:00:00 2001 From: Jehan Date: Thu, 20 Jul 2023 00:46:06 +0200 Subject: [PATCH] app, libgimp, pdb: new private PDB call _gimp_resource_get_identifiers(). --- app/pdb/internal-procs.c | 2 +- app/pdb/resource-cmds.c | 79 ++++++++++++++++++++++++++++++++++++++ libgimp/gimpresource_pdb.c | 54 ++++++++++++++++++++++++++ libgimp/gimpresource_pdb.h | 31 ++++++++------- pdb/groups/resource.pdb | 44 +++++++++++++++++++++ 5 files changed, 195 insertions(+), 15 deletions(-) diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 3ed42ff289..b1519dea9f 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 773 procedures registered total */ +/* 774 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/resource-cmds.c b/app/pdb/resource-cmds.c index 9b70e96baf..7e9d7e3091 100644 --- a/app/pdb/resource-cmds.c +++ b/app/pdb/resource-cmds.c @@ -297,6 +297,41 @@ resource_get_name_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +resource_get_identifiers_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpResource *resource; + gboolean is_internal = FALSE; + gchar *name = NULL; + gchar *collection_id = NULL; + + resource = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + gimp_data_get_identifiers (GIMP_DATA (resource), &name, &collection_id, &is_internal); + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + { + g_value_set_boolean (gimp_value_array_index (return_vals, 1), is_internal); + g_value_take_string (gimp_value_array_index (return_vals, 2), name); + g_value_take_string (gimp_value_array_index (return_vals, 3), collection_id); + } + + return return_vals; +} + static GimpValueArray * resource_is_editable_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -673,6 +708,50 @@ register_resource_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-resource-get-identifiers + */ + procedure = gimp_procedure_new (resource_get_identifiers_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-resource-get-identifiers"); + gimp_procedure_set_static_help (procedure, + "Returns a triplet identifying the resource.", + "This procedure returns 2 strings and a boolean. The first string is the resource name, similar to what you would obtain calling 'gimp-resource-get-name'. The second is an opaque identifier for the collection this resource belongs to.\n" + "Note: as far as GIMP is concerned, a collection of resource usually corresponds to a single file on disk (which may or may not contain several resources). Therefore the identifier may be derived from the local file path. Nevertheless you should not use this string as such as this is not guaranteed to be always the case. You should consider it as an opaque identifier only to be used again through _'gimp-resource-get-by-identifier'.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Jehan", + "Jehan", + "2023"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_resource ("resource", + "resource", + "The resource", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + g_param_spec_boolean ("is-internal", + "is internal", + "Whether this is the identifier for internal data", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("name", + "name", + "The resource's name", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_string ("collection-id", + "collection id", + "The resource's collection identifier", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-resource-is-editable */ diff --git a/libgimp/gimpresource_pdb.c b/libgimp/gimpresource_pdb.c index 4fafba6d47..fdfd190b0a 100644 --- a/libgimp/gimpresource_pdb.c +++ b/libgimp/gimpresource_pdb.c @@ -332,6 +332,60 @@ gimp_resource_get_name (GimpResource *resource) return name; } +/** + * _gimp_resource_get_identifiers: + * @resource: The resource. + * @name: (out) (transfer full): The resource's name. + * @collection_id: (out) (transfer full): The resource's collection identifier. + * + * Returns a triplet identifying the resource. + * + * This procedure returns 2 strings and a boolean. The first string is + * the resource name, similar to what you would obtain calling + * gimp_resource_get_name(). The second is an opaque identifier for the + * collection this resource belongs to. + * Note: as far as GIMP is concerned, a collection of resource usually + * corresponds to a single file on disk (which may or may not contain + * several resources). Therefore the identifier may be derived from the + * local file path. Nevertheless you should not use this string as such + * as this is not guaranteed to be always the case. You should consider + * it as an opaque identifier only to be used again through + * _gimp_resource_get_by_identifier(). + * + * Returns: Whether this is the identifier for internal data. + * + * Since: 3.0 + **/ +gboolean +_gimp_resource_get_identifiers (GimpResource *resource, + gchar **name, + gchar **collection_id) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean is_internal = FALSE; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_RESOURCE, resource, + G_TYPE_NONE); + + return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-resource-get-identifiers", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + { + is_internal = GIMP_VALUES_GET_BOOLEAN (return_vals, 1); + *name = GIMP_VALUES_DUP_STRING (return_vals, 2); + *collection_id = GIMP_VALUES_DUP_STRING (return_vals, 3); + } + + gimp_value_array_unref (return_vals); + + return is_internal; +} + /** * gimp_resource_is_editable: * @resource: The resource. diff --git a/libgimp/gimpresource_pdb.h b/libgimp/gimpresource_pdb.h index 1ce10519f7..8424890388 100644 --- a/libgimp/gimpresource_pdb.h +++ b/libgimp/gimpresource_pdb.h @@ -32,20 +32,23 @@ G_BEGIN_DECLS /* For information look into the C source or the html documentation */ -G_GNUC_INTERNAL GimpResource* _gimp_resource_get_by_name (const gchar *type_name, - const gchar *resource_name); -gboolean gimp_resource_id_is_valid (gint resource_id); -gboolean gimp_resource_id_is_brush (gint resource_id); -gboolean gimp_resource_id_is_pattern (gint resource_id); -gboolean gimp_resource_id_is_gradient (gint resource_id); -gboolean gimp_resource_id_is_palette (gint resource_id); -gboolean gimp_resource_id_is_font (gint resource_id); -gchar* gimp_resource_get_name (GimpResource *resource); -gboolean gimp_resource_is_editable (GimpResource *resource); -GimpResource* gimp_resource_duplicate (GimpResource *resource); -gboolean gimp_resource_rename (GimpResource *resource, - const gchar *new_name); -gboolean gimp_resource_delete (GimpResource *resource); +G_GNUC_INTERNAL GimpResource* _gimp_resource_get_by_name (const gchar *type_name, + const gchar *resource_name); +gboolean gimp_resource_id_is_valid (gint resource_id); +gboolean gimp_resource_id_is_brush (gint resource_id); +gboolean gimp_resource_id_is_pattern (gint resource_id); +gboolean gimp_resource_id_is_gradient (gint resource_id); +gboolean gimp_resource_id_is_palette (gint resource_id); +gboolean gimp_resource_id_is_font (gint resource_id); +gchar* gimp_resource_get_name (GimpResource *resource); +G_GNUC_INTERNAL gboolean _gimp_resource_get_identifiers (GimpResource *resource, + gchar **name, + gchar **collection_id); +gboolean gimp_resource_is_editable (GimpResource *resource); +GimpResource* gimp_resource_duplicate (GimpResource *resource); +gboolean gimp_resource_rename (GimpResource *resource, + const gchar *new_name); +gboolean gimp_resource_delete (GimpResource *resource); G_END_DECLS diff --git a/pdb/groups/resource.pdb b/pdb/groups/resource.pdb index 143bce404a..078ced4606 100644 --- a/pdb/groups/resource.pdb +++ b/pdb/groups/resource.pdb @@ -259,6 +259,49 @@ CODE ); } +sub resource_get_identifiers { + $blurb = "Returns a triplet identifying the resource."; + + $help = < 'resource', type => 'resource', + desc => 'The resource' } + ); + + @outargs = ( + { name => 'is_internal', type => 'boolean', + desc => 'Whether this is the identifier for internal data'}, + { name => 'name', type => 'string', + desc => "The resource's name" }, + { name => 'collection_id', type => 'string', + desc => "The resource's collection identifier" } + ); + + %invoke = ( + code => <<'CODE' +{ + gimp_data_get_identifiers (GIMP_DATA (resource), &name, &collection_id, &is_internal); +} +CODE + ); +} + sub resource_is_editable { $blurb = "Whether the resource can be edited."; $help = "Returns TRUE if you have permission to change the resource."; @@ -404,6 +447,7 @@ CODE resource_id_is_palette resource_id_is_font resource_get_name + resource_get_identifiers resource_is_editable resource_duplicate resource_rename