From 1f9e5a1b9a88a8b87929861bc5c94506c44a135e Mon Sep 17 00:00:00 2001 From: Jason Hearne-McGuiness Date: Wed, 4 Sep 2013 14:33:22 +0100 Subject: [PATCH] Add exo and Atk bindings to the PNG table. Also extract the row names to make them fit in better with the header & Exif style of display. --- plugins/thunar-apr/thunar-apr-image-page.c | 86 ++++++++++++++++----------- plugins/thunar-apr/thunar-apr-png-read-data.c | 62 +++++++++---------- plugins/thunar-apr/thunar-apr-png-read-data.h | 10 +++- 3 files changed, 91 insertions(+), 67 deletions(-) diff --git a/plugins/thunar-apr/thunar-apr-image-page.c b/plugins/thunar-apr/thunar-apr-image-page.c index 8f57df6..920225f 100644 --- a/plugins/thunar-apr/thunar-apr-image-page.c +++ b/plugins/thunar-apr/thunar-apr-image-page.c @@ -80,7 +80,8 @@ struct _ThunarAprImagePage #endif #ifdef HAVE_PNG GtkWidget *png_container; - GtkWidget *png_labels[number_of_png_chunks]; + GtkWidget *png_name_labels[number_of_png_chunks]; + GtkWidget *png_data_labels[number_of_png_chunks]; #endif }; @@ -101,18 +102,41 @@ thunar_apr_image_page_class_init (ThunarAprImagePageClass *klass) thunarapr_abstract_page_class->file_changed = thunar_apr_image_page_file_changed; } +#if defined(HAVE_EXIF) || defined(HAVE_PNG) +void +thunar_apr_image_page_Atk_bindlabels(GtkWidget *left, GtkWidget *right); + +void +thunar_apr_image_page_Atk_bindlabels(GtkWidget *left, GtkWidget *right) +{ + AtkRelationSet *relations; + AtkRelation *relation; + AtkObject *object; + + exo_binding_new (G_OBJECT (right), "visible", G_OBJECT (left), "visible"); + + /* set Atk label relation for the label */ + object = gtk_widget_get_accessible (right); + relations = atk_object_ref_relation_set (gtk_widget_get_accessible (left)); + relation = atk_relation_new (&object, 1, ATK_RELATION_LABEL_FOR); + atk_relation_set_add (relations, relation); + g_object_unref (G_OBJECT (relation)); +} + +#endif + #ifdef HAVE_PNG void -thunar_apr_image_page_init_png(ThunarAprImagePage *image_page, GtkWidget *table); +thunar_apr_image_page_init_png(ThunarAprImagePage *image_page, GtkWidget *table, PangoAttrList *attr_list); void -thunar_apr_image_page_init_png(ThunarAprImagePage *image_page, GtkWidget *table) +thunar_apr_image_page_init_png(ThunarAprImagePage *image_page, GtkWidget *table, PangoAttrList *attr_list) { GtkWidget *png_table; unsigned short n; image_page->png_container = gtk_scrolled_window_new (NULL, NULL); - png_table = gtk_table_new (1, 1, FALSE); + png_table = gtk_table_new (2, 1, FALSE); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(image_page->png_container), png_table); gtk_table_set_row_spacings (GTK_TABLE (png_table), 0); @@ -123,16 +147,24 @@ thunar_apr_image_page_init_png(ThunarAprImagePage *image_page, GtkWidget *table) /* add labels for the PNG info */ for (n = 0; n < number_of_png_chunks; ++n) { - image_page->png_labels[n] = gtk_label_new (""); - gtk_label_set_selectable (GTK_LABEL (image_page->png_labels[n]), TRUE); - gtk_misc_set_alignment (GTK_MISC (image_page->png_labels[n]), 0.0f, 0.5f); - gtk_label_set_single_line_mode (GTK_LABEL (image_page->png_labels[n]), FALSE); - gtk_label_set_line_wrap (GTK_LABEL (image_page->png_labels[n]), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (image_page->png_labels[n]), TRUE); - gtk_label_set_line_wrap_mode (GTK_LABEL (image_page->png_labels[n]), PANGO_WRAP_WORD); - gtk_table_attach (GTK_TABLE (png_table), image_page->png_labels[n], 0, 1, n, n + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); - gtk_widget_show (image_page->png_labels[n]); - } + image_page->png_name_labels[n] = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC (image_page->png_name_labels[n]), 1.0f, 0.5f); + gtk_label_set_attributes (GTK_LABEL (image_page->png_name_labels[n]), attr_list); + gtk_table_attach (GTK_TABLE (png_table), image_page->png_name_labels[n], 0, 1, n, n + 1, GTK_FILL, GTK_FILL, 0, 3); + gtk_widget_show (image_page->png_name_labels[n]); + + image_page->png_data_labels[n] = gtk_label_new (""); + gtk_label_set_selectable (GTK_LABEL (image_page->png_data_labels[n]), TRUE); + gtk_misc_set_alignment (GTK_MISC (image_page->png_data_labels[n]), 0.0f, 0.5f); + gtk_label_set_single_line_mode (GTK_LABEL (image_page->png_data_labels[n]), FALSE); + gtk_label_set_line_wrap (GTK_LABEL (image_page->png_data_labels[n]), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (image_page->png_data_labels[n]), TRUE); + gtk_label_set_line_wrap_mode (GTK_LABEL (image_page->png_data_labels[n]), PANGO_WRAP_WORD); + gtk_table_attach (GTK_TABLE (png_table), image_page->png_data_labels[n], 1, 2, n, n + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); + gtk_widget_show (image_page->png_data_labels[n]); + + thunar_apr_image_page_Atk_bindlabels (image_page->png_name_labels[n], image_page->png_data_labels[n]); + } } #endif @@ -179,12 +211,7 @@ thunar_apr_image_page_init (ThunarAprImagePage *image_page) gtk_table_attach (GTK_TABLE (table), image_page->type_label, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); gtk_widget_show (image_page->type_label); - /* set Atk label relation for the label */ - object = gtk_widget_get_accessible (image_page->type_label); - relations = atk_object_ref_relation_set (gtk_widget_get_accessible (label)); - relation = atk_relation_new (&object, 1, ATK_RELATION_LABEL_FOR); - atk_relation_set_add (relations, relation); - g_object_unref (G_OBJECT (relation)); + thunar_apr_image_page_Atk_bindlabels (label, image_page->type_label); label = gtk_label_new (_("Image Size:")); gtk_misc_set_alignment (GTK_MISC (label), 1.0f, 0.5f); @@ -199,12 +226,7 @@ thunar_apr_image_page_init (ThunarAprImagePage *image_page) gtk_table_attach (GTK_TABLE (table), image_page->dimensions_label, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); gtk_widget_show (image_page->dimensions_label); - /* set Atk label relation for the label */ - object = gtk_widget_get_accessible (image_page->dimensions_label); - relations = atk_object_ref_relation_set (gtk_widget_get_accessible (label)); - relation = atk_relation_new (&object, 1, ATK_RELATION_LABEL_FOR); - atk_relation_set_add (relations, relation); - g_object_unref (G_OBJECT (relation)); + thunar_apr_image_page_Atk_bindlabels (label, image_page->dimensions_label); #ifdef HAVE_EXIF /* some spacing between the General info and the Exif info */ @@ -228,17 +250,12 @@ thunar_apr_image_page_init (ThunarAprImagePage *image_page) exo_binding_new (G_OBJECT (image_page->exif_labels[n]), "visible", G_OBJECT (label), "visible"); - /* set Atk label relation for the label */ - object = gtk_widget_get_accessible (image_page->exif_labels[n]); - relations = atk_object_ref_relation_set (gtk_widget_get_accessible (label)); - relation = atk_relation_new (&object, 1, ATK_RELATION_LABEL_FOR); - atk_relation_set_add (relations, relation); - g_object_unref (G_OBJECT (relation)); + thunar_apr_image_page_Atk_bindlabels (label, image_page->exif_labels[n]); } #endif #ifdef HAVE_PNG - thunar_apr_image_page_init_png(image_page, table); + thunar_apr_image_page_init_png(image_page, table, attr_list); #endif /* release shared bold Pango attributes */ @@ -340,7 +357,8 @@ thunar_apr_image_page_file_changed (ThunarAprAbstractPage *abstract_page, { if (G_LIKELY (png_chunks->data != NULL)) { - gtk_label_set_text (GTK_LABEL (image_page->png_labels[n]), png_chunks->data); + gtk_label_set_text (GTK_LABEL (image_page->png_name_labels[n]), png_chunks->trans.name); + gtk_label_set_text (GTK_LABEL (image_page->png_data_labels[n]), png_chunks->data); ++n; } } diff --git a/plugins/thunar-apr/thunar-apr-png-read-data.c b/plugins/thunar-apr/thunar-apr-png-read-data.c index afd6037..73e55d5 100644 --- a/plugins/thunar-apr/thunar-apr-png-read-data.c +++ b/plugins/thunar-apr/thunar-apr-png-read-data.c @@ -109,38 +109,38 @@ typedef enum { typedef struct { - char const *name; ///< A chunk name from png_chunk_names. - char const *fmt_str; ///< The format string for converting the raw data into human-readable form. + png_chunk_name_translate_t const trans; ///< The translation of the chunk. + char const *fmt_str; ///< The format string for converting the raw chunk-data into human-readable form. } png_chunk_fmt_t; /** * These must be in the same order as png_chunk_names. */ static const png_chunk_fmt_t png_chunk_details[number_of_png_chunks]={ - {"IHDR", "Width=%u, height=%u, bit depth=%i, colour type: %s, interlace type: %s"}, - {"tIME", "Modification time: %hu/%hhu/%hhu %02hhu:%02hhu:%02hhu"}, ///< In ISO format, because Linux is international. - {"PLTE", "Number of entries in the palette=%i, RGB=(%hhu, %hhu, %hhu)"}, - {"bKGD", "Palette index=%hhu, RGB=(%hu, %hu, %hu), gray=%hu"}, - {"cHRM", ""}, ///< TODO Need to complete representing this. - {"fRAc", ""}, ///< No specification in PNG spec. - {"gAMA", "Gamma factor=%f"}, - {"gIFg", ""}, ///< TODO Need to complete representing this. - {"gIFt", ""}, ///< TODO Need to complete representing this. - {"gIFx", ""}, ///< TODO Need to complete representing this. - {"hIST", "Histogram=%hu"}, - {"iCCP", ""}, ///< TODO Need to complete representing this. - {"iTXt", ""}, ///< TODO Need to complete representing this. - {"oFFs", "Offset: (%i, %i) %s"}, - {"pCAL", ""}, ///< TODO Need to complete representing this. - {"pHYs", "Resolution: (%u, %u) %s"}, - {"sBIT", ""}, ///< TODO Need to complete representing this. - {"sCAL", ""}, ///< TODO Need to complete representing this. - {"sPLT", ""}, ///< TODO Need to complete representing this. - {"sRGB", "Intent: %s"}, - {"sTER", ""}, ///< TODO Need to complete representing this. - {"tEXt", "%s"}, ///< Format specifier not used, as the various components are concatenated in the code. Just here to symbolically indicate that this has been implemented. - {"tRNS", ""}, ///< TODO Need to complete representing this. - {"zTXt", ""} ///< TODO Need to complete representing this. + {{"IHDR", "Header:"}, "Width=%u, height=%u, bit depth=%i, colour type: %s, interlace type: %s"}, + {{"tIME", "Modification time:"}, "%hu/%hhu/%hhu %02hhu:%02hhu:%02hhu"}, ///< In ISO format, because Linux is international. + {{"PLTE", "Palette entries:"}, "%i, RGB=(%hhu, %hhu, %hhu)"}, + {{"bKGD", "Palette index:"}, "%hhu, RGB=(%hu, %hu, %hu), gray=%hu"}, + {{"cHRM", ""}, ""}, ///< TODO Need to complete representing this. + {{"fRAc", ""}, ""}, ///< No specification in PNG spec. + {{"gAMA", "Gamma factor:"}, "%f"}, + {{"gIFg", ""}, ""}, ///< TODO Need to complete representing this. + {{"gIFt", ""}, ""}, ///< TODO Need to complete representing this. + {{"gIFx", ""}, ""}, ///< TODO Need to complete representing this. + {{"hIST", "Histogram:"}, "%hu"}, + {{"iCCP", ""}, ""}, ///< TODO Need to complete representing this. + {{"iTXt", ""}, ""}, ///< TODO Need to complete representing this. + {{"oFFs", "Offset:"}, "(%i, %i) %s"}, + {{"pCAL", ""}, ""}, ///< TODO Need to complete representing this. + {{"pHYs", "Resolution:"}, "(%u, %u) %s"}, + {{"sBIT", ""}, ""}, ///< TODO Need to complete representing this. + {{"sCAL", ""}, ""}, ///< TODO Need to complete representing this. + {{"sPLT", ""}, ""}, ///< TODO Need to complete representing this. + {{"sRGB", "Intent:"}, "%s"}, + {{"sTER", ""}, ""}, ///< TODO Need to complete representing this. + {{"tEXt", "Text:"}, "%s"}, ///< Format specifier not used, as the various components are concatenated in the code. Just here to symbolically indicate that this has been implemented. + {{"tRNS", ""}, ""}, ///< TODO Need to complete representing this. + {{"zTXt", ""}, ""} ///< TODO Need to complete representing this. }; // Mr.compiler you are a liar: see this is constant. @@ -177,7 +177,8 @@ init_png_data(void) // Make sure the chunk names are set correctly, as per the interface. for(i=0; ichunk_name, last_png_chunk_detail_item())!=0) + if (strcmp(png_chunk_data->trans.chunk, last_png_chunk_detail_item())!=0) { return ++png_chunk_data; } diff --git a/plugins/thunar-apr/thunar-apr-png-read-data.h b/plugins/thunar-apr/thunar-apr-png-read-data.h index 8fc032b..81a636f 100644 --- a/plugins/thunar-apr/thunar-apr-png-read-data.h +++ b/plugins/thunar-apr/thunar-apr-png-read-data.h @@ -57,12 +57,18 @@ enum { number_of_png_chunks=24 }; +/// The structure that maps the name of the chunk into a human-readable name. +typedef struct +{ + char const *chunk; ///< A chunk name from png_chunk_names. + char const *name; ///< A human-readable chunk name derived from png_chunk_names. +} png_chunk_name_translate_t; /** * TODO This should really be private... */ typedef struct { - char const *name; ///< A chunk name from png_chunk_names. + png_chunk_name_translate_t trans; ///< The translation of the chunk. char *data; ///< The converted, human-readable data, if the chunk in the PNG file was present and read correctly, otherwise NULL. } private_png_chunk_details_t; @@ -77,7 +83,7 @@ typedef private_png_chunk_details_t const * png_read_data_ptr_t; /// The structure that maps the name of the chunk to the data it contains. typedef struct { - char const *chunk_name; ///< A chunk name from png_chunk_names. + png_chunk_name_translate_t const trans; ///< The translation of the chunk. char const *data; ///< The converted, human-readable data, if the chunk in the PNG file was present and read correctly, otherwise NULL. } png_chunk_details_t; -- 1.8.1.5