static void append_xmp_value_pair (CajaImagePropertiesPage *page, XmpPtr xmp, const char *ns, const char *propname, char *descr) { uint32_t options; XmpStringPtr value; value = xmp_string_new(); if (xmp_get_property (xmp, ns, propname, value, &options)) { if (XMP_IS_PROP_SIMPLE (options)) { append_label_take_str (page->details->vbox, g_strdup_printf ("<b>%s:</b> %s", 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) { GString *str; gboolean first = TRUE; str = g_string_new (NULL); g_string_append_printf (str, "<b>%s:</b> ", descr); while (xmp_iterator_next (iter, NULL, NULL, value, &options) && !XMP_IS_PROP_QUALIFIER(options)) { if (!first) { g_string_append_printf (str, ", "); } else { first = FALSE; } g_string_append_printf (str, "%s", xmp_string_cstr(value)); } xmp_iterator_free(iter); append_label_take_str (page->details->vbox, g_string_free (str, FALSE)); } } } xmp_string_free(value); }
static void eom_xmp_set_label (XmpPtr xmp, const char *ns, const char *propname, GtkWidget *w) { uint32_t options; XmpStringPtr value = xmp_string_new (); if (xmp_get_property (xmp, ns, propname, value, &options)) { if (XMP_IS_PROP_SIMPLE (options)) { gtk_label_set_text (GTK_LABEL (w), xmp_string_cstr (value)); } else if (XMP_IS_PROP_ARRAY (options)) { XmpIteratorPtr iter = xmp_iterator_new (xmp, ns, propname, XMP_ITER_JUSTLEAFNODES); GString *string = g_string_new (""); if (iter) { gboolean first = TRUE; 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); } gtk_label_set_text (GTK_LABEL (w), string->str); g_string_free (string, TRUE); } } else { /* Property was not found */ /* Clear label so it won't show bogus data */ gtk_label_set_text (GTK_LABEL (w), NULL); } xmp_string_free (value); }
static void set_xmp_prop(const char * filename, const std::string & value_name, const std::string & prop_value, bool no_reconcile, bool is_an_xmp, bool write_in_place, FILE *outio) { xmp::ScopedPtr<XmpPtr> xmp(get_xmp_from_file(filename, no_reconcile, is_an_xmp)); std::string prefix; size_t idx = value_name.find(':'); if(idx != std::string::npos) { prefix = std::string(value_name, 0, idx); } xmp::ScopedPtr<XmpStringPtr> ns(xmp_string_new()); xmp_prefix_namespace_uri(prefix.c_str(), ns); if(!xmp_set_property(xmp, xmp_string_cstr(ns), value_name.c_str() + idx + 1, prop_value.c_str(), 0)) { fprintf(stderr, "set error = %d\n", xmp_get_error()); } if(write_in_place) { xmp::ScopedPtr<XmpFilePtr> f(xmp_files_open_new(filename, (XmpOpenFileOptions)(XMP_OPEN_FORUPDATE | (no_reconcile ? XMP_OPEN_ONLYXMP : 0)))); if(!xmp_files_can_put_xmp(f, xmp)) { fprintf(stderr, "can put xmp error = %d\n", xmp_get_error()); } if(!xmp_files_put_xmp(f, xmp)) { fprintf(stderr, "put xmp error = %d\n", xmp_get_error()); } if(!xmp_files_close(f, XMP_CLOSE_SAFEUPDATE)) { fprintf(stderr, "close error = %d\n", xmp_get_error()); } } }
/** get an xmp prop and dump it to the output IO */ static void get_xmp_prop(const char * filename, const std::string & value_name, bool no_reconcile, bool is_an_xmp, FILE *outio) { xmp::ScopedPtr<XmpPtr> xmp(get_xmp_from_file(filename, no_reconcile, is_an_xmp)); std::string prefix; size_t idx = value_name.find(':'); if(idx != std::string::npos) { prefix = std::string(value_name, 0, idx); } xmp::ScopedPtr<XmpStringPtr> property(xmp_string_new()); xmp::ScopedPtr<XmpStringPtr> ns(xmp_string_new()); xmp_prefix_namespace_uri(prefix.c_str(), ns); xmp_get_property(xmp, xmp_string_cstr(ns), value_name.c_str(), property, NULL); fprintf(outio, "%s\n", xmp_string_cstr(property)); }
/** dump the XMP xml to the output IO */ static void dump_xmp(const char *filename, bool no_reconcile, bool is_an_xmp, FILE *outio) { printf("dump_xmp for file %s\n", filename); xmp::ScopedPtr<XmpPtr> xmp(get_xmp_from_file(filename, no_reconcile, is_an_xmp)); xmp::ScopedPtr<XmpStringPtr> output(xmp_string_new()); xmp_serialize_and_format(xmp, output, XMP_SERIAL_OMITPACKETWRAPPER, 0, "\n", " ", 0); fprintf(outio, "%s", xmp_string_cstr(output)); }
static ExifCategory get_xmp_category (XmpStringPtr schema) { ExifCategory cat = XMP_CATEGORY_OTHER; const char *s = xmp_string_cstr(schema); int i; for (i = 0; xmp_ns_category_map[i].id != NULL; i++) { if (strcmp (xmp_ns_category_map[i].id, s) == 0) { cat = xmp_ns_category_map[i].category; break; } } return cat; }
static void xmp_entry_insert (EogExifDetails *view, XmpStringPtr xmp_schema, XmpStringPtr xmp_path, XmpStringPtr xmp_prop) { GtkTreeStore *store; EogExifDetailsPrivate *priv; ExifCategory cat; char *path; gchar *key; priv = view->priv; key = g_strconcat (xmp_string_cstr (xmp_schema), ":", xmp_string_cstr (xmp_path), NULL); store = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view))); path = g_hash_table_lookup (priv->id_path_hash, key); if (path != NULL) { set_row_data (store, path, NULL, xmp_string_cstr (xmp_path), xmp_string_cstr (xmp_prop)); g_free(key); } else { cat = get_xmp_category (xmp_schema); path = set_row_data (store, NULL, exif_categories[cat].path, xmp_string_cstr(xmp_path), xmp_string_cstr(xmp_prop)); g_hash_table_insert (priv->id_path_hash, key, path); } }
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 }