Skip to content

Commit a0d4774

Browse files
committed
Merge pull request #26 from ebbes/imageproperties
Improve the Image properties page
2 parents 4c58f30 + 237cc6d commit a0d4774

File tree

1 file changed

+58
-71
lines changed

1 file changed

+58
-71
lines changed

src/nemo-image-properties-page.c

Lines changed: 58 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848

4949
struct NemoImagePropertiesPageDetails {
5050
GCancellable *cancellable;
51-
GtkWidget *vbox;
52-
GtkWidget *loading_label;
51+
GtkWidget *grid;
5352
GdkPixbufLoader *loader;
5453
gboolean got_size;
5554
gboolean pixbuf_still_loading;
@@ -128,39 +127,32 @@ file_close_callback (GObject *object,
128127
page->details->cancellable = NULL;
129128
}
130129

131-
static GtkWidget *
132-
append_label (GtkWidget *vbox,
133-
const char *str)
130+
static void
131+
append_item (NemoImagePropertiesPage *page,
132+
const char *name,
133+
const char *value)
134134
{
135+
GtkWidget *name_label;
135136
GtkWidget *label;
136-
137-
label = gtk_label_new (NULL);
138-
gtk_label_set_markup (GTK_LABEL (label), str);
139-
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
140-
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
141-
142-
/* setting can_focus to FALSE will allow to make the label
143-
* selectable but without the cursor showing.
144-
*/
145-
gtk_widget_set_can_focus (label, FALSE);
146-
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
147-
148-
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
149-
gtk_widget_show (label);
150-
151-
return label;
152-
}
153-
154-
static GtkWidget *
155-
append_label_take_str (GtkWidget *vbox,
156-
char *str)
157-
{
158-
GtkWidget *retval;
159-
160-
retval = append_label (vbox, str);
161-
g_free (str);
162-
163-
return retval;
137+
PangoAttrList *attrs;
138+
139+
name_label = gtk_label_new (name);
140+
attrs = pango_attr_list_new ();
141+
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
142+
gtk_label_set_attributes (GTK_LABEL (name_label), attrs);
143+
pango_attr_list_unref (attrs);
144+
gtk_misc_set_alignment (GTK_MISC (name_label), 0, 0);
145+
gtk_container_add (GTK_CONTAINER (page->details->grid), name_label);
146+
gtk_widget_show (name_label);
147+
148+
if (value != NULL) {
149+
label = gtk_label_new (value);
150+
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
151+
gtk_grid_attach_next_to (GTK_GRID (page->details->grid), label,
152+
name_label, GTK_POS_RIGHT,
153+
1, 1);
154+
gtk_widget_show (label);
155+
}
164156
}
165157

166158
#ifdef HAVE_EXIF
@@ -245,14 +237,13 @@ append_tag_value_pair (NemoImagePropertiesPage *page,
245237
return FALSE;
246238
}
247239

248-
append_label_take_str
249-
(page->details->vbox,
250-
g_strdup_printf ("<b>%s:</b> %s",
251-
description ? description : utf_attribute,
252-
utf_value));
240+
append_item (page,
241+
description ? description : utf_attribute,
242+
utf_value);
253243

254244
g_free (utf_attribute);
255245
g_free (utf_value);
246+
256247
return TRUE;
257248
}
258249

@@ -298,10 +289,7 @@ append_xmp_value_pair (NemoImagePropertiesPage *page,
298289
value = xmp_string_new();
299290
if (xmp_get_property (xmp, ns, propname, value, &options)) {
300291
if (XMP_IS_PROP_SIMPLE (options)) {
301-
append_label_take_str
302-
(page->details->vbox,
303-
g_strdup_printf ("<b>%s:</b> %s",
304-
descr, xmp_string_cstr (value)));
292+
append_item (page, descr, xmp_string_cstr (value));
305293
}
306294
else if (XMP_IS_PROP_ARRAY (options)) {
307295
XmpIteratorPtr iter;
@@ -313,8 +301,6 @@ append_xmp_value_pair (NemoImagePropertiesPage *page,
313301

314302
str = g_string_new (NULL);
315303

316-
g_string_append_printf (str, "<b>%s:</b> ",
317-
descr);
318304
while (xmp_iterator_next (iter, NULL, NULL, value, &options)
319305
&& !XMP_IS_PROP_QUALIFIER(options)) {
320306
if (!first) {
@@ -328,8 +314,7 @@ append_xmp_value_pair (NemoImagePropertiesPage *page,
328314
xmp_string_cstr(value));
329315
}
330316
xmp_iterator_free(iter);
331-
append_label_take_str (page->details->vbox,
332-
g_string_free (str, FALSE));
317+
append_item (page, descr, g_string_free (str, FALSE));
333318
}
334319
}
335320
}
@@ -355,9 +340,12 @@ static void
355340
load_finished (NemoImagePropertiesPage *page)
356341
{
357342
GdkPixbufFormat *format;
343+
GtkWidget *label;
358344
char *name, *desc;
345+
char *value;
359346

360-
gtk_widget_destroy (page->details->loading_label);
347+
label = gtk_grid_get_child_at (GTK_GRID (page->details->grid), 0, 0);
348+
gtk_container_remove (GTK_CONTAINER (page->details->grid), label);
361349

362350
if (page->details->loader != NULL) {
363351
gdk_pixbuf_loader_close (page->details->loader, NULL);
@@ -372,25 +360,23 @@ load_finished (NemoImagePropertiesPage *page)
372360

373361
name = gdk_pixbuf_format_get_name (format);
374362
desc = gdk_pixbuf_format_get_description (format);
375-
append_label_take_str
376-
(page->details->vbox,
377-
g_strdup_printf ("<b>%s</b> %s (%s)",
378-
_("Image Type:"), name, desc));
379-
append_label_take_str
380-
(page->details->vbox,
381-
g_strdup_printf (ngettext ("<b>Width:</b> %d pixel",
382-
"<b>Width:</b> %d pixels",
383-
page->details->width),
384-
page->details->width));
385-
append_label_take_str
386-
(page->details->vbox,
387-
g_strdup_printf (ngettext ("<b>Height:</b> %d pixel",
388-
"<b>Height:</b> %d pixels",
389-
page->details->height),
390-
page->details->height));
363+
value = g_strdup_printf ("%s (%s)", name, desc);
391364
g_free (name);
392365
g_free (desc);
393-
366+
append_item (page, _("Image Type"), value);
367+
g_free (value);
368+
value = g_strdup_printf (ngettext ("%d pixel",
369+
"%d pixels",
370+
page->details->width),
371+
page->details->width);
372+
append_item (page, _("Width"), value);
373+
g_free (value);
374+
value = g_strdup_printf (ngettext ("%d pixel",
375+
"%d pixels",
376+
page->details->height),
377+
page->details->height);
378+
append_item (page, _("Height"), value);
379+
g_free (value);
394380
#ifdef HAVE_EXIF
395381
exif_data = exif_loader_get_data (page->details->exifldr);
396382
append_exifdata_string (exif_data, page);
@@ -400,8 +386,7 @@ load_finished (NemoImagePropertiesPage *page)
400386
append_xmpdata_string (page->details->xmp, page);
401387
#endif /*HAVE EXEMPI*/
402388
} else {
403-
append_label (page->details->vbox,
404-
_("Failed to load image information"));
389+
append_item (page, _("Failed to load image information"), NULL);
405390
}
406391

407392
if (page->details->loader != NULL) {
@@ -416,7 +401,7 @@ load_finished (NemoImagePropertiesPage *page)
416401
#endif /*HAVE_EXIF*/
417402
#ifdef HAVE_EXEMPI
418403
if (page->details->xmp != NULL) {
419-
xmp_free(page->details->xmp);
404+
xmp_free (page->details->xmp);
420405
page->details->xmp = NULL;
421406
}
422407
#endif
@@ -613,11 +598,13 @@ nemo_image_properties_page_init (NemoImagePropertiesPage *page)
613598
gtk_box_set_spacing (GTK_BOX (page), 2);
614599
gtk_container_set_border_width (GTK_CONTAINER (page), 6);
615600

616-
page->details->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
617-
page->details->loading_label =
618-
append_label (page->details->vbox,_("loading..."));
601+
page->details->grid = gtk_grid_new ();
602+
gtk_orientable_set_orientation (GTK_ORIENTABLE (page->details->grid), GTK_ORIENTATION_VERTICAL);
603+
gtk_grid_set_row_spacing (GTK_GRID (page->details->grid), 6);
604+
gtk_grid_set_column_spacing (GTK_GRID (page->details->grid), 20);
605+
append_item (page, _("Loading..."), NULL);
619606
gtk_box_pack_start (GTK_BOX (page),
620-
page->details->vbox,
607+
page->details->grid,
621608
FALSE, TRUE, 2);
622609

623610
gtk_widget_show_all (GTK_WIDGET (page));

0 commit comments

Comments
 (0)