diff options
author | Richard Hughes <richard@hughsie.com> | 2016-01-15 15:30:22 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-01-17 09:10:04 +0000 |
commit | 0395e6656832e61c660e85422a940949a2fa74f8 (patch) | |
tree | 00b62f32b89c947857ebcb0dbd43e3d1bb0ffd00 /libappstream-glib | |
parent | 1b3311c5dee9a2a0ae334ebad25edbdd81832401 (diff) | |
download | appstream-glib-0395e6656832e61c660e85422a940949a2fa74f8.tar.gz |
Make the check for screenshot equality more robust
This avoids us exporting multiple screenshots when reusing metadata.
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-app.c | 2 | ||||
-rw-r--r-- | libappstream-glib/as-image.c | 37 | ||||
-rw-r--r-- | libappstream-glib/as-image.h | 2 | ||||
-rw-r--r-- | libappstream-glib/as-screenshot.c | 44 | ||||
-rw-r--r-- | libappstream-glib/as-screenshot.h | 2 |
5 files changed, 86 insertions, 1 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 31ffd58..a86902d 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -2230,7 +2230,7 @@ as_app_add_screenshot (AsApp *app, AsScreenshot *screenshot) if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_DUPLICATES) > 0) { for (i = 0; i < priv->screenshots->len; i++) { ss = g_ptr_array_index (priv->screenshots, i); - if (ss == screenshot) + if (as_screenshot_equal (ss, screenshot)) return; } } diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c index ff09339..bc008e6 100644 --- a/libappstream-glib/as-image.c +++ b/libappstream-glib/as-image.c @@ -784,6 +784,43 @@ as_image_get_alpha_flags (AsImage *image) } /** + * as_image_equal: + * @image1: a #AsImage instance. + * @image2: a #AsImage instance. + * + * Checks if two images are the same. + * + * Returns: %TRUE for success + * + * Since: 0.5.7 + **/ +gboolean +as_image_equal (AsImage *image1, AsImage *image2) +{ + AsImagePrivate *priv1 = GET_PRIVATE (image1); + AsImagePrivate *priv2 = GET_PRIVATE (image2); + + /* trivial */ + if (image1 == image2) + return TRUE; + + /* check for equality */ + if (priv1->kind != priv2->kind) + return FALSE; + if (priv1->width != priv2->width) + return FALSE; + if (priv1->height != priv2->height) + return FALSE; + if (g_strcmp0 (priv1->url, priv2->url) != 0) + return FALSE; + if (g_strcmp0 (priv1->md5, priv2->md5) != 0) + return FALSE; + + /* success */ + return TRUE; +} + +/** * as_image_new: * * Creates a new #AsImage. diff --git a/libappstream-glib/as-image.h b/libappstream-glib/as-image.h index 8e14b66..03e7bb5 100644 --- a/libappstream-glib/as-image.h +++ b/libappstream-glib/as-image.h @@ -156,6 +156,8 @@ gboolean as_image_save_filename (AsImage *image, guint height, AsImageSaveFlags flags, GError **error); +gboolean as_image_equal (AsImage *image1, + AsImage *image2); G_END_DECLS diff --git a/libappstream-glib/as-screenshot.c b/libappstream-glib/as-screenshot.c index f025800..3f411f3 100644 --- a/libappstream-glib/as-screenshot.c +++ b/libappstream-glib/as-screenshot.c @@ -506,6 +506,50 @@ as_screenshot_node_parse_dep11 (AsScreenshot *ss, GNode *node, } /** + * as_screenshot_equal: + * @screenshot1: a #AsScreenshot instance. + * @screenshot2: a #AsScreenshot instance. + * + * Checks if two screenshots are the same. + * + * Returns: %TRUE for success + * + * Since: 0.5.7 + **/ +gboolean +as_screenshot_equal (AsScreenshot *screenshot1, AsScreenshot *screenshot2) +{ + AsScreenshotPrivate *priv1 = GET_PRIVATE (screenshot1); + AsScreenshotPrivate *priv2 = GET_PRIVATE (screenshot2); + AsImage *im1; + AsImage *im2; + + /* trivial */ + if (screenshot1 == screenshot2) + return TRUE; + + /* check for equality */ + if (priv1->priority != priv2->priority) + return FALSE; + if (priv1->images->len != priv2->images->len) + return FALSE; + if (g_strcmp0 (as_screenshot_get_caption (screenshot1, NULL), + as_screenshot_get_caption (screenshot2, NULL)) != 0) + return FALSE; + + /* check source images */ + im1 = as_screenshot_get_source (screenshot1); + im2 = as_screenshot_get_source (screenshot2); + if (im1 != NULL && im2 != NULL) { + if (!as_image_equal (im1, im2)) + return FALSE; + } + + /* success */ + return TRUE; +} + +/** * as_screenshot_new: * * Creates a new #AsScreenshot. diff --git a/libappstream-glib/as-screenshot.h b/libappstream-glib/as-screenshot.h index 008c902..74a39c7 100644 --- a/libappstream-glib/as-screenshot.h +++ b/libappstream-glib/as-screenshot.h @@ -92,6 +92,8 @@ void as_screenshot_set_caption (AsScreenshot *screenshot, const gchar *caption); void as_screenshot_add_image (AsScreenshot *screenshot, AsImage *image); +gboolean as_screenshot_equal (AsScreenshot *screenshot1, + AsScreenshot *screenshot2); G_END_DECLS |