[gnome-software] Award a Kudo if an application has perfect screenshots



commit d1ae4810d246f2b82b172a44e0d34cb43fcf657f
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jul 2 15:36:34 2014 +0100

    Award a Kudo if an application has perfect screenshots
    
    'Perfect' in this sense means with a sensible size range, and 16:9 aspect.

 src/gs-app.c                      |    4 +++
 src/gs-app.h                      |    1 +
 src/plugins/gs-plugin-appstream.c |   46 +++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index bf49c21..2aeecc8 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -205,6 +205,8 @@ gs_app_to_string (GsApp *app)
                g_string_append (str, "\tkudo:\tpopular\n");
        if ((priv->kudos & GS_APP_KUDO_IBUS_HAS_SYMBOL) > 0)
                g_string_append (str, "\tkudo:\tibus-has-symbol\n");
+       if ((priv->kudos & GS_APP_KUDO_PERFECT_SCREENSHOTS) > 0)
+               g_string_append (str, "\tkudo:\tperfect-screenshots\n");
        g_string_append_printf (str, "\tkudo-percentage:\t%i\n",
                                gs_app_get_kudos_percentage (app));
        if (priv->name != NULL)
@@ -1679,6 +1681,8 @@ gs_app_get_kudos_percentage (GsApp *app)
                percentage += 20;
        if ((app->priv->kudos & GS_APP_KUDO_IBUS_HAS_SYMBOL) > 0)
                percentage += 20;
+       if ((app->priv->kudos & GS_APP_KUDO_PERFECT_SCREENSHOTS) > 0)
+               percentage += 20;
 
        /* popular apps should be at *least* 50% */
        if ((app->priv->kudos & GS_APP_KUDO_POPULAR) > 0)
diff --git a/src/gs-app.h b/src/gs-app.h
index dc267b1..3c64f04 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -87,6 +87,7 @@ typedef enum {
        GS_APP_KUDO_HAS_SCREENSHOTS             = 1 << 9,
        GS_APP_KUDO_POPULAR                     = 1 << 10,
        GS_APP_KUDO_IBUS_HAS_SYMBOL             = 1 << 11,
+       GS_APP_KUDO_PERFECT_SCREENSHOTS         = 1 << 12,
        GS_APP_KUDO_LAST
 } GsAppKudo;
 
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 6ea69f0..2229bc7 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -410,6 +410,48 @@ gs_plugin_appstream_is_recent_release (AsApp *app)
 }
 
 /**
+ * gs_plugin_appstream_are_screenshots_perfect:
+ */
+static gboolean
+gs_plugin_appstream_are_screenshots_perfect (AsApp *app)
+{
+       AsImage *image;
+       AsScreenshot *screenshot;
+       GPtrArray *screenshots;
+       guint height;
+       guint i;
+       guint width;
+
+       screenshots = as_app_get_screenshots (app);
+       if (screenshots->len == 0)
+               return FALSE;
+       for (i = 0; i < screenshots->len; i++) {
+
+               /* get the source image as the thumbs will be resized & padded */
+               screenshot = g_ptr_array_index (screenshots, i);
+               image = as_screenshot_get_source (screenshot);
+               if (image == NULL)
+                       return FALSE;
+
+               width = as_image_get_width (image);
+               height = as_image_get_height (image);
+
+               /* too small */
+               if (width < AS_IMAGE_LARGE_WIDTH || height < AS_IMAGE_LARGE_HEIGHT)
+                       return FALSE;
+
+               /* too large */
+               if (width > AS_IMAGE_LARGE_WIDTH * 2 || height > AS_IMAGE_LARGE_HEIGHT * 2)
+                       return FALSE;
+
+               /* not 16:9 */
+               if ((width / 16) * 9 != height)
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+/**
  * gs_plugin_refine_item:
  */
 static gboolean
@@ -549,6 +591,10 @@ gs_plugin_refine_item (GsPlugin *plugin,
        /* set screenshots */
        gs_plugin_refine_add_screenshots (app, item);
 
+       /* are the screenshots perfect */
+       if (gs_plugin_appstream_are_screenshots_perfect (item))
+               gs_app_add_kudo (app, GS_APP_KUDO_PERFECT_SCREENSHOTS);
+
        /* was this application released recently */
        if (gs_plugin_appstream_is_recent_release (item))
                gs_app_add_kudo (app, GS_APP_KUDO_RECENT_RELEASE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]