From 13f1b126a3ec00c7f199aeee9ee37f412a7337c9 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 13 May 2014 17:14:07 +0100 Subject: Add as_image_get_md5() This is not supposed to be a secure hash. --- libappstream-glib/as-image.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libappstream-glib/as-image.c') diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c index 4ddcdbd..9df7616 100644 --- a/libappstream-glib/as-image.c +++ b/libappstream-glib/as-image.c @@ -43,6 +43,7 @@ struct _AsImagePrivate { AsImageKind kind; gchar *url; + gchar *md5; guint width; guint height; GdkPixbuf *pixbuf; @@ -64,6 +65,7 @@ as_image_finalize (GObject *object) if (priv->pixbuf != NULL) g_object_unref (priv->pixbuf); g_free (priv->url); + g_free (priv->md5); G_OBJECT_CLASS (as_image_parent_class)->finalize (object); } @@ -144,6 +146,23 @@ as_image_get_url (AsImage *image) return priv->url; } +/** + * as_image_get_md5: + * @image: a #AsImage instance. + * + * Gets the string representation of the pixbuf hash value. + * + * Returns: string representing the MD5 sum, or %NULL if unset + * + * Since: 0.1.6 + **/ +const gchar * +as_image_get_md5 (AsImage *image) +{ + AsImagePrivate *priv = GET_PRIVATE (image); + return priv->md5; +} + /** * as_image_get_width: * @image: a #AsImage instance. @@ -291,8 +310,16 @@ void as_image_set_pixbuf (AsImage *image, GdkPixbuf *pixbuf) { AsImagePrivate *priv = GET_PRIVATE (image); + guchar *data; + guint len; + if (priv->pixbuf != NULL) g_object_unref (priv->pixbuf); + if (priv->md5 == NULL) { + data = gdk_pixbuf_get_pixels_with_length (pixbuf, &len); + priv->md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5, + data, len); + } priv->pixbuf = g_object_ref (pixbuf); } -- cgit v1.2.1