plug-ins: port the metadata plug-ins to GimpPlugIn and object

This commit is contained in:
Michael Natterer 2019-08-27 18:28:56 +02:00
parent 1178f54522
commit b6b84f7afa
8 changed files with 241 additions and 200 deletions

View File

@ -42,7 +42,6 @@ metadata_viewer_SOURCES = \
metadata-viewer.c
AM_CPPFLAGS = \
-DGIMP_DEPRECATED_REPLACE_NEW_API \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
$(GEGL_CFLAGS) \

View File

@ -46,16 +46,35 @@
#define DEFAULT_TEMPLATE_FILE "gimp_metadata_template.xml"
/* local function prototypes */
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
typedef struct _Metadata Metadata;
typedef struct _MetadataClass MetadataClass;
static gboolean metadata_editor_dialog (gint32 image_id,
struct _Metadata
{
GimpPlugIn parent_instance;
};
struct _MetadataClass
{
GimpPlugInClass parent_class;
};
#define METADATA_TYPE (metadata_get_type ())
#define METADATA (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), METADATA_TYPE, Metadata))
GType metadata_get_type (void) G_GNUC_CONST;
static GList * metadata_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * metadata_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * metadata_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
static gboolean metadata_editor_dialog (GimpImage *image,
GimpMetadata *metadata);
static void metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
@ -63,7 +82,7 @@ static void metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
void metadata_editor_write_callback (GtkWidget *dialog,
GtkBuilder *builder,
gint32 image_id);
GimpImage *image);
static void impex_combo_callback (GtkComboBoxText *combo,
gpointer data);
@ -357,7 +376,10 @@ cell_edited_callback_combo (GtkCellRendererCombo *cell,
int index);
/* local variables */
G_DEFINE_TYPE (Metadata, metadata, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (METADATA_TYPE)
gchar *tagdata[256][256];
@ -372,113 +394,105 @@ static const gchar *bag_default = "type=\"Bag\"";
metadata_editor meta_args;
const GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
/* ============================================================================
* ==[ ]=============================================================
* ==[ FUNCTIONS ]=============================================================
* ==[ ]=============================================================
* ============================================================================
*/
MAIN ()
/* ============================================================================
* ==[ QUERY ]=================================================================
* ============================================================================
*/
static void
query (void)
metadata_class_init (MetadataClass *klass)
{
static const GimpParamDef metadata_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "Run mode { RUN-INTERACTIVE (0) }" },
{ GIMP_PDB_IMAGE, "image", "Input image" }
};
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
gimp_install_procedure (PLUG_IN_PROC,
N_("Edit metadata (IPTC, EXIF, XMP)"),
"Edit metadata information attached to the "
"current image. Some or all of this metadata "
"will be saved in the file, depending on the output "
"file format.",
"Ben Touchette",
"Ben Touchette",
"2017",
N_("_Edit Metadata"),
"*",
GIMP_PLUGIN,
G_N_ELEMENTS (metadata_args), 0,
metadata_args, NULL);
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Image/Metadata");
plug_in_class->query_procedures = metadata_query_procedures;
plug_in_class->create_procedure = metadata_create_procedure;
}
/* ============================================================================
* ==[ RUN ]===================================================================
* ============================================================================
*/
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
metadata_init (Metadata *metadata)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
}
*nreturn_vals = 1;
*return_vals = values;
static GList *
metadata_query_procedures (GimpPlugIn *plug_in)
{
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
}
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
force_write = FALSE;
INIT_I18N ();
gimp_ui_init (PLUG_IN_BINARY, TRUE);
static GimpProcedure *
metadata_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
if (! strcmp (name, PLUG_IN_PROC))
{
GimpMetadata *metadata;
gint32 image_ID = param[1].data.d_image;
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
metadata_run, NULL, NULL);
metadata = gimp_image_get_metadata (image_ID);
gimp_procedure_set_image_types (procedure, "*");
/* Always show metadata dialog so we can add
appropriate iptc data as needed. Sometimes
license data needs to be added after the
fact and the image may not contain metadata
but should have it added as needed. */
gimp_procedure_set_menu_label (procedure, N_("_Edit Metadata"));
gimp_procedure_add_menu_path (procedure, "<Image>/Image/Metadata");
if (!metadata)
{
metadata = gimp_metadata_new ();
gimp_image_set_metadata (image_ID, metadata);
}
gimp_procedure_set_documentation (procedure,
N_("Edit metadata (IPTC, EXIF, XMP)"),
"Edit metadata information attached "
"to the current image. Some or all "
"of this metadata will be saved in "
"the file, depending on the output "
"file format.",
name);
gimp_procedure_set_attribution (procedure,
"Ben Touchette",
"Ben Touchette",
"2017");
metadata_editor_dialog (image_ID, metadata);
GIMP_PROC_ARG_ENUM (procedure, "run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE);
status = GIMP_PDB_SUCCESS;
}
else
{
status = GIMP_PDB_CALLING_ERROR;
GIMP_PROC_ARG_IMAGE (procedure, "image",
"Image",
"The input image",
G_PARAM_READWRITE);
}
values[0].data.d_status = status;
return procedure;
}
static GimpValueArray *
metadata_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data)
{
GimpImage *image;
GimpMetadata *metadata;
INIT_I18N ();
gimp_ui_init (PLUG_IN_BINARY, TRUE);
image = GIMP_VALUES_GET_IMAGE (args, 1);
metadata = gimp_image_get_metadata (image);
/* Always show metadata dialog so we can add appropriate iptc data
* as needed. Sometimes license data needs to be added after the
* fact and the image may not contain metadata but should have it
* added as needed.
*/
if (! metadata)
{
metadata = gimp_metadata_new ();
gimp_image_set_metadata (image, metadata);
}
metadata_editor_dialog (image, metadata);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}
/* ============================================================================
* ==[ EDITOR DIALOG UI ]======================================================
* ============================================================================
@ -494,7 +508,7 @@ builder_get_widget (GtkBuilder *builder,
}
static gboolean
metadata_editor_dialog (gint32 image_id,
metadata_editor_dialog (GimpImage *image,
GimpMetadata *g_metadata)
{
GtkBuilder *builder;
@ -513,8 +527,8 @@ metadata_editor_dialog (gint32 image_id,
builder = gtk_builder_new ();
meta_args.image_id = image_id;
meta_args.builder = builder;
meta_args.image = image;
meta_args.builder = builder;
meta_args.metadata = metadata;
meta_args.filename = g_strconcat (g_get_home_dir (), "/", DEFAULT_TEMPLATE_FILE,
NULL);
@ -535,7 +549,7 @@ metadata_editor_dialog (gint32 image_id,
g_free (ui_file);
name = gimp_image_get_name (image_id);
name = gimp_image_get_name (image);
title = g_strdup_printf (_("Metadata Editor: %s"), name);
if (name)
g_free (name);
@ -585,7 +599,7 @@ metadata_editor_dialog (gint32 image_id,
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_YES);
if (run)
{
metadata_editor_write_callback (dialog, builder, image_id);
metadata_editor_write_callback (dialog, builder, image);
}
if (meta_args.filename)
@ -4345,7 +4359,7 @@ set_tag_string (GimpMetadata *metadata,
void
metadata_editor_write_callback (GtkWidget *dialog,
GtkBuilder *builder,
gint32 image_id)
GimpImage *image)
{
GimpMetadata *g_metadata;
gint max_elements;
@ -4362,7 +4376,7 @@ metadata_editor_write_callback (GtkWidget *dialog,
i = 0;
g_metadata = gimp_image_get_metadata (image_id);
g_metadata = gimp_image_get_metadata (image);
gimp_metadata_add_xmp_history (g_metadata, "metadata");
@ -5628,7 +5642,7 @@ metadata_editor_write_callback (GtkWidget *dialog,
}
}
gimp_image_set_metadata (image_id, g_metadata);
gimp_image_set_metadata (image, g_metadata);
}
/* ============================================================================

View File

@ -22,6 +22,6 @@
extern void metadata_editor_write_callback (GtkWidget *dialog,
GtkBuilder *builder,
gint32 image_id);
GimpImage *image);
#endif /* __METADATA_EDITOR_H__ */

View File

@ -110,9 +110,9 @@ export_file_metadata (metadata_editor *args)
if (force_write == TRUE)
{
/* Save fields in case of updates */
metadata_editor_write_callback (args->dialog, args->builder, args->image_id);
metadata_editor_write_callback (args->dialog, args->builder, args->image);
/* Fetch a fresh copy of the metadata */
args->metadata = GEXIV2_METADATA (gimp_image_get_metadata (args->image_id));
args->metadata = GEXIV2_METADATA (gimp_image_get_metadata (args->image));
}
xmldata = g_strconcat ("<?xml version=“1.0” encoding=“utf-8”?>\n",

View File

@ -20,11 +20,8 @@
#ifndef __METADATA_IMPEXP_H__
#define __METADATA_IMPEXP_H__
void
import_file_metadata (metadata_editor *args);
void
export_file_metadata (metadata_editor *args);
void import_file_metadata (metadata_editor *args);
void export_file_metadata (metadata_editor *args);
#endif /* __METADATA_IMPEXP_H__ */

View File

@ -25,7 +25,7 @@ typedef struct
GtkWidget *dialog;
GtkBuilder *builder;
GExiv2Metadata *metadata;
gint32 image_id;
GimpImage *image;
gchar *filename;
} metadata_editor;

View File

@ -70,121 +70,152 @@ enum
};
/* local function prototypes */
typedef struct _Metadata Metadata;
typedef struct _MetadataClass MetadataClass;
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static gboolean metadata_viewer_dialog (gint32 image_id,
GimpMetadata *g_metadata);
static void metadata_dialog_set_metadata (GExiv2Metadata *metadata,
GtkBuilder *builder);
static void metadata_dialog_append_tags (GExiv2Metadata *metadata,
gchar **tags,
GtkListStore *store,
gint tag_column,
gint value_column);
static gchar * metadata_dialog_format_tag_value (GExiv2Metadata *metadata,
const gchar *tag,
gboolean truncate);
/* local variables */
const GimpPlugInInfo PLUG_IN_INFO =
struct _Metadata
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
GimpPlugIn parent_instance;
};
/* functions */
struct _MetadataClass
{
GimpPlugInClass parent_class;
};
#define METADATA_TYPE (metadata_get_type ())
#define METADATA (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), METADATA_TYPE, Metadata))
GType metadata_get_type (void) G_GNUC_CONST;
static GList * metadata_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * metadata_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * metadata_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
static gboolean metadata_viewer_dialog (GimpImage *image,
GimpMetadata *g_metadata);
static void metadata_dialog_set_metadata (GExiv2Metadata *metadata,
GtkBuilder *builder);
static void metadata_dialog_append_tags (GExiv2Metadata *metadata,
gchar **tags,
GtkListStore *store,
gint tag_column,
gint value_column);
static gchar * metadata_dialog_format_tag_value (GExiv2Metadata *metadata,
const gchar *tag,
gboolean truncate);
G_DEFINE_TYPE (Metadata, metadata, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (METADATA_TYPE)
MAIN ()
static void
query (void)
metadata_class_init (MetadataClass *klass)
{
static const GimpParamDef metadata_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "Run mode { RUN-INTERACTIVE (0) }" },
{ GIMP_PDB_IMAGE, "image", "Input image" }
};
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
gimp_install_procedure (PLUG_IN_PROC,
N_("View metadata (Exif, IPTC, XMP)"),
"View metadata information attached to the "
"current image. This can include Exif, IPTC and/or "
"XMP information.",
"Hartmut Kuhse, Michael Natterer, Ben Touchette",
"Hartmut Kuhse, Michael Natterer, Ben Touchette",
"2013, 2017",
N_("_View Metadata"),
"*",
GIMP_PLUGIN,
G_N_ELEMENTS (metadata_args), 0,
metadata_args, NULL);
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Image/Metadata");
plug_in_class->query_procedures = metadata_query_procedures;
plug_in_class->create_procedure = metadata_create_procedure;
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
metadata_init (Metadata *metadata)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
}
*nreturn_vals = 1;
*return_vals = values;
static GList *
metadata_query_procedures (GimpPlugIn *plug_in)
{
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
}
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
INIT_I18N();
gimp_ui_init (PLUG_IN_BINARY, TRUE);
static GimpProcedure *
metadata_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
if (! strcmp (name, PLUG_IN_PROC))
{
GimpMetadata *metadata;
gint32 image_ID = param[1].data.d_image;
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
metadata_run, NULL, NULL);
metadata = gimp_image_get_metadata (image_ID);
gimp_procedure_set_image_types (procedure, "*");
/* Always show metadata dialog so we can add
appropriate iptc data as needed. Sometimes
license data needs to be added after the
fact and the image may not contain metadata
but should have it added as needed. */
gimp_procedure_set_menu_label (procedure, N_("_View Metadata"));
gimp_procedure_add_menu_path (procedure, "<Image>/Image/Metadata");
if (!metadata)
{
metadata = gimp_metadata_new();
gimp_image_set_metadata (image_ID, metadata);
}
gimp_procedure_set_documentation (procedure,
N_("View metadata (Exif, IPTC, XMP)"),
"View metadata information attached "
"to the current image. This can "
"include Exif, IPTC and/or XMP "
"information.",
name);
gimp_procedure_set_attribution (procedure,
"Hartmut Kuhse, Michael Natterer, "
"Ben Touchette",
"Hartmut Kuhse, Michael Natterer, "
"Ben Touchette",
"2013, 2017");
metadata_viewer_dialog (image_ID, metadata);
GIMP_PROC_ARG_ENUM (procedure, "run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE);
status = GIMP_PDB_SUCCESS;
GIMP_PROC_ARG_IMAGE (procedure, "image",
"Image",
"The input image",
G_PARAM_READWRITE);
}
else
return procedure;
}
static GimpValueArray *
metadata_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data)
{
GimpImage *image;
GimpMetadata *metadata;
INIT_I18N ();
gimp_ui_init (PLUG_IN_BINARY, TRUE);
image = GIMP_VALUES_GET_IMAGE (args, 1);
metadata = gimp_image_get_metadata (image);
/* Always show metadata dialog so we can add appropriate iptc data
* as needed. Sometimes license data needs to be added after the
* fact and the image may not contain metadata but should have it
* added as needed.
*/
if (! metadata)
{
status = GIMP_PDB_CALLING_ERROR;
metadata = gimp_metadata_new ();
gimp_image_set_metadata (image, metadata);
}
values[0].data.d_status = status;
metadata_viewer_dialog (image, metadata);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}
static gboolean
metadata_viewer_dialog (gint32 image_id,
metadata_viewer_dialog (GimpImage *image,
GimpMetadata *g_metadata)
{
GtkBuilder *builder;
@ -216,7 +247,7 @@ metadata_viewer_dialog (gint32 image_id,
g_free (ui_file);
name = gimp_image_get_name (image_id);
name = gimp_image_get_name (image);
title = g_strdup_printf (_("Metadata Viewer: %s"), name);
g_free (name);

View File

@ -22,7 +22,7 @@ AM_LDFLAGS = $(mwindows)
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
$(GEGL_CFLAGS) \
$(GEGL_CFLAGS) \
-I$(includedir)
LDADD = \