src/evix2-glib.cpp (3614B) - raw
1 /* 2 * xmpedit 3 * Copyright 2010 Dan Callaghan <djc@djc.id.au> 4 * Released under GPLv2 5 */ 6 7 #include <exiv2/image.hpp> 8 #include "exiv2-glib.h" 9 10 G_DEFINE_TYPE (Exiv2Image, exiv2_image, G_TYPE_OBJECT) 11 12 #define GET_PRIVATE(o) \ 13 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EXIV2_TYPE_IMAGE, Exiv2ImagePrivate)) 14 15 typedef struct { 16 Exiv2::Image *image; 17 } Exiv2ImagePrivate; 18 19 static void exiv2_image_get_property(GObject *object, guint property_id, 20 GValue *value, GParamSpec *pspec) { 21 switch (property_id) { 22 default: 23 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 24 } 25 } 26 27 static void exiv2_image_set_property(GObject *object, guint property_id, 28 const GValue *value, GParamSpec *pspec) { 29 switch (property_id) { 30 default: 31 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 32 } 33 } 34 35 static void exiv2_image_dispose(GObject *object) { 36 G_OBJECT_CLASS(exiv2_image_parent_class)->dispose(object); 37 } 38 39 static void exiv2_image_finalize(GObject *object) { 40 G_OBJECT_CLASS(exiv2_image_parent_class)->finalize(object); 41 // XXX maybe this should be in dispose instead?? 42 g_return_if_fail(object != NULL); 43 Exiv2ImagePrivate *priv = GET_PRIVATE(object); 44 g_return_if_fail(priv->image != NULL); 45 delete priv->image; 46 } 47 48 static void exiv2_image_class_init(Exiv2ImageClass *klass) { 49 GObjectClass *object_class = G_OBJECT_CLASS(klass); 50 51 g_type_class_add_private(klass, sizeof(Exiv2ImagePrivate)); 52 53 object_class->get_property = exiv2_image_get_property; 54 object_class->set_property = exiv2_image_set_property; 55 object_class->dispose = exiv2_image_dispose; 56 object_class->finalize = exiv2_image_finalize; 57 } 58 59 static void exiv2_image_init(Exiv2Image *self) { 60 } 61 62 Exiv2Image *exiv2_image_new_from_path(gchar *path) { 63 g_return_val_if_fail(path != NULL, NULL); 64 Exiv2Image *self = (Exiv2Image *)g_object_new(EXIV2_TYPE_IMAGE, NULL); 65 g_return_val_if_fail(self != NULL, NULL); 66 Exiv2ImagePrivate *priv = GET_PRIVATE(self); 67 try { 68 priv->image = Exiv2::ImageFactory::open(path).release(); 69 } catch (Exiv2::Error e) { 70 g_critical("unhandled"); // XXX 71 } 72 return self; 73 } 74 75 void exiv2_image_read_metadata(Exiv2Image *self) { 76 g_return_if_fail(self != NULL); 77 Exiv2ImagePrivate *priv = GET_PRIVATE(self); 78 g_return_if_fail(priv->image != NULL); 79 try { 80 priv->image->readMetadata(); 81 } catch (Exiv2::Error e) { 82 g_critical("unhandled"); // XXX 83 } 84 } 85 86 void exiv2_image_write_metadata(Exiv2Image *self) { 87 g_return_if_fail(self != NULL); 88 Exiv2ImagePrivate *priv = GET_PRIVATE(self); 89 g_return_if_fail(priv->image != NULL); 90 try { 91 priv->image->writeMetadata(); 92 } catch (Exiv2::Error e) { 93 g_critical("unhandled"); // XXX 94 } 95 } 96 97 const gchar *exiv2_image_get_xmp_packet(Exiv2Image *self) { 98 g_return_val_if_fail(self != NULL, NULL); 99 Exiv2ImagePrivate *priv = GET_PRIVATE(self); 100 g_return_val_if_fail(priv->image != NULL, NULL); 101 try { 102 const std::string& xmp_packet = priv->image->xmpPacket(); 103 if (!xmp_packet.empty()) 104 return xmp_packet.c_str(); 105 } catch (Exiv2::Error e) { 106 g_critical("unhandled"); // XXX 107 } 108 return NULL; 109 } 110 111 void exiv2_image_set_xmp_packet(Exiv2Image *self, const gchar *xmp_packet) { 112 g_return_if_fail(self != NULL); 113 Exiv2ImagePrivate *priv = GET_PRIVATE(self); 114 g_return_if_fail(priv->image != NULL); 115 try { 116 priv->image->setXmpPacket(xmp_packet); 117 } catch (Exiv2::Error e) { 118 g_critical("unhandled"); // XXX 119 } 120 }