[gimp/gimp-2-10] plug-ins: improve error handling and use GError in metadata-editor/viewer.
- From: Jacob Boerema <jboerema src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] plug-ins: improve error handling and use GError in metadata-editor/viewer.
- Date: Wed, 2 Dec 2020 00:10:48 +0000 (UTC)
commit 3f3dd3cfc96cdbe8985baf75f0955fa60a65ce6c
Author: Jacob Boerema <jgboerema gmail com>
Date: Mon Nov 30 21:38:44 2020 -0500
plug-ins: improve error handling and use GError in metadata-editor/viewer.
metadata-editor and metadata-viewer did return GIMP_PDB_SUCCESS when
loading the dialog ui failed, we changed this to GIMP_PDB_EXECUTION_ERROR
and now use a GError to report it back to GIMP.
In metadata-editor also improve the error handling when loading the calendar
dialog fails.
The error also only showed in the console so change that to show a dialog
or the error console.
(cherry picked from commit 0ffee001bf1dfbd97ad866bc5c157c59d3433a9e)
# Conflicts:
# plug-ins/metadata/metadata-editor.c
# plug-ins/metadata/metadata-viewer.c
plug-ins/metadata/metadata-editor.c | 50 +++++++++++++++++++++++--------------
plug-ins/metadata/metadata-viewer.c | 36 ++++++++++++++++++--------
2 files changed, 56 insertions(+), 30 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index 8a76546703..b0b05c5f25 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -56,7 +56,8 @@ static void run (const gchar *name,
GimpParam **return_vals);
static gboolean metadata_editor_dialog (gint32 image_id,
- GimpMetadata *metadata);
+ GimpMetadata *metadata,
+ GError **error);
static void metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
GtkBuilder *builder);
@@ -440,6 +441,7 @@ run (const gchar *name,
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
+ GError *error = NULL;
*nreturn_vals = 1;
*return_vals = values;
@@ -471,9 +473,18 @@ run (const gchar *name,
gimp_image_set_metadata (image_ID, metadata);
}
- metadata_editor_dialog (image_ID, metadata);
-
- status = GIMP_PDB_SUCCESS;
+ if (metadata_editor_dialog (image_ID, metadata, &error))
+ status = GIMP_PDB_SUCCESS;
+ else
+ {
+ status = GIMP_PDB_EXECUTION_ERROR;
+ if (error)
+ {
+ *nreturn_vals = 2;
+ values[1].type = GIMP_PDB_STRING;
+ values[1].data.d_string = error->message;
+ }
+ }
}
else
{
@@ -498,8 +509,9 @@ builder_get_widget (GtkBuilder *builder,
}
static gboolean
-metadata_editor_dialog (gint32 image_id,
- GimpMetadata *g_metadata)
+metadata_editor_dialog (gint32 image_id,
+ GimpMetadata *g_metadata,
+ GError **error)
{
GtkBuilder *builder;
GtkWidget *dialog;
@@ -510,7 +522,7 @@ metadata_editor_dialog (gint32 image_id,
gchar *ui_file;
gchar *title;
gchar *name;
- GError *error = NULL;
+ GError *local_error = NULL;
gboolean run;
metadata = GEXIV2_METADATA (g_metadata);
@@ -526,13 +538,14 @@ metadata_editor_dialog (gint32 image_id,
ui_file = g_build_filename (gimp_data_directory (),
"ui", "plug-ins", "plug-in-metadata-editor.ui", NULL);
- if (! gtk_builder_add_from_file (builder, ui_file, &error))
+ if (! gtk_builder_add_from_file (builder, ui_file, &local_error))
{
- g_printerr ("Error occurred while loading UI file!\n");
- g_printerr ("Message: %s\n", error->message);
- g_clear_error (&error);
- if (ui_file)
- g_free (ui_file);
+ if (! local_error)
+ local_error = g_error_new_literal (G_FILE_ERROR, 0,
+ _("Error loading metadata-editor dialog."));
+ g_propagate_error (error, local_error);
+
+ g_free (ui_file);
g_object_unref (builder);
return FALSE;
}
@@ -782,12 +795,11 @@ on_date_button_clicked (GtkButton *widget,
if (! gtk_builder_add_from_file (builder, ui_file, &error))
{
- g_printerr ("Error occurred while loading UI file!\n");
- if (error != NULL)
- {
- g_printerr ("Message: %s\n", error->message);
- g_clear_error (&error);
- }
+ g_log ("", G_LOG_LEVEL_MESSAGE,
+ _("Error loading calendar. %s"),
+ error ? error->message : "");
+ g_clear_error (&error);
+
if (ui_file)
g_free (ui_file);
g_object_unref (builder);
diff --git a/plug-ins/metadata/metadata-viewer.c b/plug-ins/metadata/metadata-viewer.c
index 34d44cb7d1..e0bf39c09f 100644
--- a/plug-ins/metadata/metadata-viewer.c
+++ b/plug-ins/metadata/metadata-viewer.c
@@ -81,7 +81,8 @@ static void run (const gchar *name,
GimpParam **return_vals);
static gboolean metadata_viewer_dialog (gint32 image_id,
- GimpMetadata *g_metadata);
+ GimpMetadata *g_metadata,
+ GError **error);
static void metadata_dialog_set_metadata (GExiv2Metadata *metadata,
GtkBuilder *builder);
static void metadata_dialog_append_tags (GExiv2Metadata *metadata,
@@ -157,6 +158,7 @@ run (const gchar *name,
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
+ GError *error = NULL;
*nreturn_vals = 1;
*return_vals = values;
@@ -186,9 +188,18 @@ run (const gchar *name,
gimp_image_set_metadata (image_ID, metadata);
}
- metadata_viewer_dialog (image_ID, metadata);
-
- status = GIMP_PDB_SUCCESS;
+ if (metadata_viewer_dialog (image_ID, metadata, &error))
+ status = GIMP_PDB_SUCCESS;
+ else
+ {
+ status = GIMP_PDB_EXECUTION_ERROR;
+ if (error)
+ {
+ *nreturn_vals = 2;
+ values[1].type = GIMP_PDB_STRING;
+ values[1].data.d_string = error->message;
+ }
+ }
}
else
{
@@ -199,8 +210,9 @@ run (const gchar *name,
}
static gboolean
-metadata_viewer_dialog (gint32 image_id,
- GimpMetadata *g_metadata)
+metadata_viewer_dialog (gint32 image_id,
+ GimpMetadata *g_metadata,
+ GError **error)
{
GtkBuilder *builder;
GtkWidget *dialog;
@@ -209,7 +221,7 @@ metadata_viewer_dialog (gint32 image_id,
gchar *ui_file;
gchar *title;
gchar *name;
- GError *error = NULL;
+ GError *local_error = NULL;
GExiv2Metadata *metadata;
metadata = GEXIV2_METADATA(g_metadata);
@@ -219,11 +231,13 @@ metadata_viewer_dialog (gint32 image_id,
ui_file = g_build_filename (gimp_data_directory (),
"ui", "plug-ins", "plug-in-metadata-viewer.ui", NULL);
- if (! gtk_builder_add_from_file (builder, ui_file, &error))
+ if (! gtk_builder_add_from_file (builder, ui_file, &local_error))
{
- g_printerr ("Error occurred while loading UI file!\n");
- g_printerr ("Message: %s\n", error->message);
- g_clear_error (&error);
+ if (! local_error)
+ local_error = g_error_new_literal (G_FILE_ERROR, 0,
+ _("Error loading metadata-viewer dialog."));
+ g_propagate_error (error, local_error);
+
g_free (ui_file);
g_object_unref (builder);
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]