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).
This commit is contained in:
Jehan 2018-03-16 20:20:24 +01:00
parent 8aaf77ba11
commit 4fdf301dea
1 changed files with 13 additions and 9 deletions

View File

@ -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;
}
/* ============================================================================