static void
load_finished (CajaImagePropertiesPage *page)
{
    GdkPixbufFormat *format;
    char *name, *desc;

    gtk_widget_destroy (page->details->loading_label);

    if (page->details->loader != NULL) {
        gdk_pixbuf_loader_close (page->details->loader, NULL);
    }

    if (page->details->got_size)
    {
#ifdef HAVE_EXIF
        ExifData *exif_data;
#endif /*HAVE_EXIF*/

        format = gdk_pixbuf_loader_get_format (page->details->loader);

        name = gdk_pixbuf_format_get_name (format);
        desc = gdk_pixbuf_format_get_description (format);
        append_label_take_str
        (page->details->vbox,
         g_strdup_printf ("<b>%s</b> %s (%s)",
                          _("Image Type:"), name, desc));
        append_label_take_str
        (page->details->vbox,
         g_strdup_printf (ngettext ("<b>Width:</b> %d pixel",
                                    "<b>Width:</b> %d pixels",
                                    page->details->width),
                          page->details->width));
        append_label_take_str
        (page->details->vbox,
         g_strdup_printf (ngettext ("<b>Height:</b> %d pixel",
                                    "<b>Height:</b> %d pixels",
                                    page->details->height),
                          page->details->height));
        g_free (name);
        g_free (desc);

#ifdef HAVE_EXIF
        exif_data = exif_loader_get_data (page->details->exifldr);
        append_exifdata_string (exif_data, page);
        exif_data_unref (exif_data);
#endif /*HAVE_EXIF*/
#ifdef HAVE_EXEMPI
        append_xmpdata_string (page->details->xmp, page);
#endif /*HAVE_EXEMPI*/
    }
    else
    {
        append_label (page->details->vbox,
                      _("Failed to load image information"));
    }

    if (page->details->loader != NULL)
    {
        g_object_unref (page->details->loader);
        page->details->loader = NULL;
    }
#ifdef HAVE_EXIF
    if (page->details->exifldr != NULL)
    {
        exif_loader_unref (page->details->exifldr);
        page->details->exifldr = NULL;
    }
#endif /*HAVE_EXIF*/
#ifdef HAVE_EXEMPI
    if (page->details->xmp != NULL)
    {
        xmp_free(page->details->xmp);
        page->details->xmp = NULL;
    }
#endif /*HAVE_EXEMPI*/
}
static void
append_xmp_value_pair (GString    *string,
		       XmpPtr      xmp,
		       const char *ns,
		       const char *propname,
		       char       *descr)
{
	uint32_t options;
	XmpStringPtr value;

	value = xmp_string_new();
#ifdef HAVE_EXEMPI_NEW_API
	if (xmp_get_property (xmp, ns, propname, value, &options)) {
#else
	if (xmp_get_property_and_bits (xmp, ns, propname, value, &options)) {
#endif
		if (XMP_IS_PROP_SIMPLE (options)) {
			g_string_append_printf (string,
						"<b>%s:</b> %s\n",
						descr,
						xmp_string_cstr (value));
		}
		else if (XMP_IS_PROP_ARRAY (options)) {
			XmpIteratorPtr iter;

			iter = xmp_iterator_new (xmp, ns, propname, XMP_ITER_JUSTLEAFNODES);
			if (iter) {
				gboolean first = TRUE;
				g_string_append_printf (string, "<b>%s:</b> ", descr);
				while (xmp_iterator_next (iter, NULL, NULL, value, &options) 
				       && !XMP_IS_PROP_QUALIFIER(options)) {
					if (!first) {
						g_string_append_printf (string, ", ");
					}
					else {
						first = FALSE;
					}
					g_string_append_printf (string,
								"%s",
								xmp_string_cstr(value));
				}
				xmp_iterator_free(iter);
				g_string_append_printf(string, "\n");
			}
		}
	}
	xmp_string_free(value);
}

static void
append_xmpdata_string(XmpPtr xmp, GString *string)
{
	if(xmp != NULL) {
		append_xmp_value_pair(string, xmp, NS_IPTC4XMP, "Location", _("Location"));
		append_xmp_value_pair(string, xmp, NS_DC, "description", _("Description"));
		append_xmp_value_pair(string, xmp, NS_DC, "subject", _("Keywords"));
		append_xmp_value_pair(string, xmp, NS_DC, "creator", _("Creator"));
		append_xmp_value_pair(string, xmp, NS_DC, "rights", _("Copyright"));
		append_xmp_value_pair(string, xmp, NS_XAP,"Rating", _("Rating"));
		/* TODO add CC licenses */
	}
}
#endif

static void
load_finished (NautilusImagePropertiesPage *page)
{
	GdkPixbufFormat *format;
	char *name, *desc;
	GString *str;

	if (page->details->got_size) {
#ifdef HAVE_EXIF
                ExifData *exif_data;
#endif

		str = g_string_new (NULL);
		format = gdk_pixbuf_loader_get_format (page->details->loader);
	
		name = gdk_pixbuf_format_get_name (format);
		desc = gdk_pixbuf_format_get_description (format);
		g_string_append_printf (str, "<b>%s</b> %s (%s)\n",
					_("Image Type:"), name, desc);
		g_string_append_printf (str, ngettext ("<b>Width:</b> %d pixel\n",
						       "<b>Width:</b> %d pixels\n",
						       page->details->width),
					page->details->width);
		g_string_append_printf (str, ngettext ("<b>Height:</b> %d pixel\n",
						       "<b>Height:</b> %d pixels\n",
						       page->details->height),
					page->details->height);
		g_free (name);
		g_free (desc);
		
#ifdef HAVE_EXIF
		exif_data = exif_loader_get_data (page->details->exifldr);
                append_exifdata_string (exif_data, str);
                exif_data_unref (exif_data);
#endif /*HAVE_EXIF*/
#ifdef HAVE_EXEMPI
		append_xmpdata_string(page->details->xmp, str);
#endif /*HAVE EXEMPI*/
		
		gtk_label_set_markup (GTK_LABEL (page->details->resolution), str->str);
		gtk_label_set_selectable (GTK_LABEL (page->details->resolution), TRUE);
		g_string_free (str, TRUE);
	} else {
		gtk_label_set_text (GTK_LABEL (page->details->resolution), _("Failed to load image information"));
	}

	if (page->details->loader != NULL) {
		gdk_pixbuf_loader_close (page->details->loader, NULL);
		g_object_unref (page->details->loader);
		page->details->loader = NULL;
	}
#ifdef HAVE_EXIF
	if (page->details->exifldr != NULL) {
		exif_loader_unref (page->details->exifldr);
		page->details->exifldr = NULL;
	}
#endif /*HAVE_EXIF*/
#ifdef HAVE_EXEMPI
	if (page->details->xmp != NULL) {
		xmp_free(page->details->xmp);
		page->details->xmp = NULL;
	}
#endif
}