[gimp] plug-ins: port the metadata plug-ins to GimpPlugIn and object
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port the metadata plug-ins to GimpPlugIn and object
- Date: Tue, 27 Aug 2019 16:29:17 +0000 (UTC)
commit b6b84f7afa44d1a3adc94c2cecb51878629c0e74
Author: Michael Natterer <mitch gimp org>
Date: Tue Aug 27 18:28:56 2019 +0200
plug-ins: port the metadata plug-ins to GimpPlugIn and object
plug-ins/metadata/Makefile.am | 1 -
plug-ins/metadata/metadata-editor.c | 218 +++++++++++++++++++-----------------
plug-ins/metadata/metadata-editor.h | 2 +-
plug-ins/metadata/metadata-impexp.c | 4 +-
plug-ins/metadata/metadata-impexp.h | 7 +-
plug-ins/metadata/metadata-misc.h | 2 +-
plug-ins/metadata/metadata-viewer.c | 209 +++++++++++++++++++---------------
plug-ins/print/Makefile.am | 2 +-
8 files changed, 243 insertions(+), 202 deletions(-)
---
diff --git a/plug-ins/metadata/Makefile.am b/plug-ins/metadata/Makefile.am
index c764359e3f..8133193f7d 100644
--- a/plug-ins/metadata/Makefile.am
+++ b/plug-ins/metadata/Makefile.am
@@ -42,7 +42,6 @@ metadata_viewer_SOURCES = \
metadata-viewer.c
AM_CPPFLAGS = \
- -DGIMP_DEPRECATED_REPLACE_NEW_API \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
$(GEGL_CFLAGS) \
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index ff91414114..f40232f3cc 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -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 ]=============================================================
- * ==[ ]=============================================================
- * ============================================================================
- */
+static void
+metadata_class_init (MetadataClass *klass)
+{
+ GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
-MAIN ()
-
-/* ============================================================================
- * ==[ QUERY ]=================================================================
- * ============================================================================
- */
+ plug_in_class->query_procedures = metadata_query_procedures;
+ plug_in_class->create_procedure = metadata_create_procedure;
+}
static void
-query (void)
+metadata_init (Metadata *metadata)
{
- static const GimpParamDef metadata_args[] =
- {
- { GIMP_PDB_INT32, "run-mode", "Run mode { RUN-INTERACTIVE (0) }" },
- { GIMP_PDB_IMAGE, "image", "Input image" }
- };
-
- 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");
}
-/* ============================================================================
- * ==[ RUN ]===================================================================
- * ============================================================================
- */
+static GList *
+metadata_query_procedures (GimpPlugIn *plug_in)
+{
+ return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
+}
-static void
-run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals)
+static GimpProcedure *
+metadata_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name)
{
- static GimpParam values[1];
- GimpPDBStatusType status = GIMP_PDB_SUCCESS;
+ GimpProcedure *procedure = NULL;
- *nreturn_vals = 1;
- *return_vals = values;
+ if (! strcmp (name, PLUG_IN_PROC))
+ {
+ procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
+ metadata_run, NULL, NULL);
+
+ gimp_procedure_set_image_types (procedure, "*");
+
+ gimp_procedure_set_menu_label (procedure, N_("_Edit Metadata"));
+ gimp_procedure_add_menu_path (procedure, "<Image>/Image/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");
+
+ GIMP_PROC_ARG_ENUM (procedure, "run-mode",
+ "Run mode",
+ "The run mode",
+ GIMP_TYPE_RUN_MODE,
+ GIMP_RUN_INTERACTIVE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_IMAGE (procedure, "image",
+ "Image",
+ "The input image",
+ G_PARAM_READWRITE);
+ }
- values[0].type = GIMP_PDB_STATUS;
- values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+ return procedure;
+}
- force_write = FALSE;
+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);
-
- if (! strcmp (name, PLUG_IN_PROC))
- {
- GimpMetadata *metadata;
- gint32 image_ID = param[1].data.d_image;
-
- metadata = gimp_image_get_metadata (image_ID);
- /* 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_ui_init (PLUG_IN_BINARY, TRUE);
- if (!metadata)
- {
- metadata = gimp_metadata_new ();
- gimp_image_set_metadata (image_ID, metadata);
- }
+ image = GIMP_VALUES_GET_IMAGE (args, 1);
- metadata_editor_dialog (image_ID, metadata);
+ metadata = gimp_image_get_metadata (image);
- status = GIMP_PDB_SUCCESS;
- }
- else
+ /* 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_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);
}
/* ============================================================================
diff --git a/plug-ins/metadata/metadata-editor.h b/plug-ins/metadata/metadata-editor.h
index c3fe93c339..1d00355374 100644
--- a/plug-ins/metadata/metadata-editor.h
+++ b/plug-ins/metadata/metadata-editor.h
@@ -22,6 +22,6 @@
extern void metadata_editor_write_callback (GtkWidget *dialog,
GtkBuilder *builder,
- gint32 image_id);
+ GimpImage *image);
#endif /* __METADATA_EDITOR_H__ */
diff --git a/plug-ins/metadata/metadata-impexp.c b/plug-ins/metadata/metadata-impexp.c
index a0dc7334f7..b1f563b36c 100644
--- a/plug-ins/metadata/metadata-impexp.c
+++ b/plug-ins/metadata/metadata-impexp.c
@@ -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",
diff --git a/plug-ins/metadata/metadata-impexp.h b/plug-ins/metadata/metadata-impexp.h
index 022975176c..55bb3fe200 100644
--- a/plug-ins/metadata/metadata-impexp.h
+++ b/plug-ins/metadata/metadata-impexp.h
@@ -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__ */
diff --git a/plug-ins/metadata/metadata-misc.h b/plug-ins/metadata/metadata-misc.h
index 4ba27d53c6..2ea0551746 100644
--- a/plug-ins/metadata/metadata-misc.h
+++ b/plug-ins/metadata/metadata-misc.h
@@ -25,7 +25,7 @@ typedef struct
GtkWidget *dialog;
GtkBuilder *builder;
GExiv2Metadata *metadata;
- gint32 image_id;
+ GimpImage *image;
gchar *filename;
} metadata_editor;
diff --git a/plug-ins/metadata/metadata-viewer.c b/plug-ins/metadata/metadata-viewer.c
index e7323d7058..93348ee145 100644
--- a/plug-ins/metadata/metadata-viewer.c
+++ b/plug-ins/metadata/metadata-viewer.c
@@ -70,121 +70,152 @@ enum
};
-/* local function prototypes */
-
-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 =
+typedef struct _Metadata Metadata;
+typedef struct _MetadataClass MetadataClass;
+
+struct _Metadata
+{
+ GimpPlugIn parent_instance;
+};
+
+struct _MetadataClass
{
- NULL, /* init_proc */
- NULL, /* quit_proc */
- query, /* query_proc */
- run, /* run_proc */
+ GimpPlugInClass parent_class;
};
-/* functions */
-MAIN ()
+#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)
+
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" }
- };
-
- 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");
+ GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+ 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;
+}
- values[0].type = GIMP_PDB_STATUS;
- values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+static GList *
+metadata_query_procedures (GimpPlugIn *plug_in)
+{
+ return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
+}
- 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);
+
+ gimp_procedure_set_image_types (procedure, "*");
+
+ gimp_procedure_set_menu_label (procedure, N_("_View Metadata"));
+ gimp_procedure_add_menu_path (procedure, "<Image>/Image/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");
+
+ GIMP_PROC_ARG_ENUM (procedure, "run-mode",
+ "Run mode",
+ "The run mode",
+ GIMP_TYPE_RUN_MODE,
+ GIMP_RUN_INTERACTIVE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_IMAGE (procedure, "image",
+ "Image",
+ "The input image",
+ G_PARAM_READWRITE);
+ }
- metadata = gimp_image_get_metadata (image_ID);
+ return 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. */
+static GimpValueArray *
+metadata_run (GimpProcedure *procedure,
+ const GimpValueArray *args,
+ gpointer run_data)
+{
+ GimpImage *image;
+ GimpMetadata *metadata;
- if (!metadata)
- {
- metadata = gimp_metadata_new();
- gimp_image_set_metadata (image_ID, metadata);
- }
+ INIT_I18N ();
- metadata_viewer_dialog (image_ID, metadata);
+ gimp_ui_init (PLUG_IN_BINARY, TRUE);
- status = GIMP_PDB_SUCCESS;
- }
- else
+ 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);
diff --git a/plug-ins/print/Makefile.am b/plug-ins/print/Makefile.am
index fed7f8ef44..9c8b6c3f31 100644
--- a/plug-ins/print/Makefile.am
+++ b/plug-ins/print/Makefile.am
@@ -22,7 +22,7 @@ AM_LDFLAGS = $(mwindows)
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
- $(GEGL_CFLAGS) \
+ $(GEGL_CFLAGS) \
-I$(includedir)
LDADD = \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]