[gimp] plug-ins: properly check widget class holding tag data.



commit 4fdf301dea96f607aba3d4c1a5ab6e5e4232f3c3
Author: Jehan <jehan girinstud io>
Date:   Fri Mar 16 20:20:24 2018 +0100

    plug-ins: properly check widget class holding tag data.
    
    Some tag data is hold in GtkEntry, other in GtkTextView, which are not
    parent to each other. Previous checks were wrong and resulted in
    "invalid cast from 'GtkEntry' to 'GtkTextView'" WARNINGs (followed by
    many CRITICALs because of this first error).
    
    Also properly free the data returned by gtk_text_buffer_get_text() which
    is allocated (unlike strings returned by gtk_entry_get_text() which must
    not be freed).

 plug-ins/metadata/metadata-editor.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index 16cbfe1..1db0fd1 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -877,28 +877,29 @@ hasPropertyReleaseTagData (GtkBuilder *builder)
 gboolean
 hasCreatorTagData (GtkBuilder *builder)
 {
-  gint loop;
+  gboolean has_data = FALSE;
+  gint     loop;
 
   for (loop = 0; loop < creatorContactInfoHeader.size; loop++)
     {
-      GObject     *object;
-      const gchar *text;
+      GObject *object;
 
       object = gtk_builder_get_object (builder, default_metadata_tags[loop].tag);
 
-      if (! strcmp (creatorContactInfoTags[loop].mode, "single"))
+      if (GTK_IS_ENTRY (object))
         {
-          text = gtk_entry_get_text (GTK_ENTRY (object));
+          const gchar *text = gtk_entry_get_text (GTK_ENTRY (object));
 
           if (text && *text)
-            return TRUE;
+            has_data = TRUE;
         }
-      else if (! strcmp (creatorContactInfoTags[loop].mode, "multi"))
+      else if (GTK_IS_TEXT_VIEW (object))
         {
           GtkTextView   *text_view = GTK_TEXT_VIEW (object);
           GtkTextBuffer *buffer    = gtk_text_view_get_buffer (text_view);
           GtkTextIter    start;
           GtkTextIter    end;
+          gchar         *text;
 
           gtk_text_buffer_get_start_iter (buffer, &start);
           gtk_text_buffer_get_end_iter (buffer, &end);
@@ -906,11 +907,14 @@ hasCreatorTagData (GtkBuilder *builder)
           text = gtk_text_buffer_get_text (buffer, &start, &end, TRUE);
 
           if (text && *text)
-            return TRUE;
+            has_data = TRUE;
+
+          if (text)
+            g_free (text);
         }
     }
 
-  return FALSE;
+  return has_data;
 }
 
 /* ============================================================================


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]