[gnome-software] Always resize the screenshots to the required UI size



commit 42925aa5a83c17338f669f56de5b6b12f0a8bb3a
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jul 1 09:42:45 2014 +0100

    Always resize the screenshots to the required UI size
    
    This will look bad for non-standard screenshots, but non-padded images will
    only be loaded when using local files.
    
    Also, we'll be using the huge 'source' screenshots for the thumbnails, but
    that's probably okay.

 src/gs-app.c              |    3 +--
 src/gs-screenshot-image.c |   23 +++++++++++++++++++----
 src/gs-screenshot.c       |   11 +----------
 src/gs-screenshot.h       |    3 +--
 src/gs-shell-details.c    |   18 ++++++------------
 5 files changed, 28 insertions(+), 30 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index e2d84f7..3b3a5f2 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -280,8 +280,7 @@ gs_app_to_string (GsApp *app)
                g_string_append_printf (str, "\tscreenshot-%02i:\t%s [%s]\n",
                                        i, gs_screenshot_get_url (ss,
                                                                  G_MAXUINT,
-                                                                 G_MAXUINT,
-                                                                 NULL),
+                                                                 G_MAXUINT),
                                        tmp != NULL ? tmp : "<none>");
        }
        for (i = 0; i < priv->sources->len; i++) {
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 49739d4..c095588 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -95,16 +95,32 @@ gs_screenshot_image_set_error (GsScreenshotImage *ssimg, const gchar *message)
 static void
 gs_screenshot_show_image (GsScreenshotImage *ssimg)
 {
+       GdkPixbuf *pixbuf;
        GsScreenshotImagePrivate *priv;
+
        priv = gs_screenshot_image_get_instance_private (ssimg);
 
        /* show icon */
        if (g_strcmp0 (priv->current_image, "image1") == 0) {
-               gtk_image_set_from_file (GTK_IMAGE (priv->image2), priv->filename);
+               pixbuf = gdk_pixbuf_new_from_file_at_scale (priv->filename,
+                                                           priv->width,
+                                                           priv->height,
+                                                           FALSE, NULL);
+               if (pixbuf != NULL) {
+                       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image2), pixbuf);
+                       g_object_unref (pixbuf);
+               }
                gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "image2");
                priv->current_image = "image2";
        } else {
-               gtk_image_set_from_file (GTK_IMAGE (priv->image1), priv->filename);
+               pixbuf = gdk_pixbuf_new_from_file_at_scale (priv->filename,
+                                                           priv->width,
+                                                           priv->height,
+                                                           FALSE, NULL);
+               if (pixbuf != NULL) {
+                       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image1), pixbuf);
+                       g_object_unref (pixbuf);
+               }
                gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "image1");
                priv->current_image = "image1";
        }
@@ -230,8 +246,7 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
        /* test if size specific cachdir exists */
        url = gs_screenshot_get_url (priv->screenshot,
                                     priv->width,
-                                    priv->height,
-                                    NULL);
+                                    priv->height);
        if (url == NULL) {
                /* TRANSLATORS: this is when we request a screenshot size that
                 * the generator did not create or the parser did not add */
diff --git a/src/gs-screenshot.c b/src/gs-screenshot.c
index 2174cfa..3a296ae 100644
--- a/src/gs-screenshot.c
+++ b/src/gs-screenshot.c
@@ -130,10 +130,7 @@ gs_screenshot_add_image (GsScreenshot *screenshot,
  *
  **/
 const gchar *
-gs_screenshot_get_url (GsScreenshot *screenshot,
-                      guint width,
-                      guint height,
-                      GtkRequisition *provided)
+gs_screenshot_get_url (GsScreenshot *screenshot, guint width, guint height)
 {
        GsScreenshotItem *item_tmp;
        GsScreenshotItem *item = NULL;
@@ -158,12 +155,6 @@ gs_screenshot_get_url (GsScreenshot *screenshot,
 
        if (item == NULL)
                return NULL;
-
-       if (provided != NULL) {
-               provided->width = item->width;
-               provided->height = item->height;
-       }
-
        return item->url;
 }
 
diff --git a/src/gs-screenshot.h b/src/gs-screenshot.h
index e9a37c7..46aeea4 100644
--- a/src/gs-screenshot.h
+++ b/src/gs-screenshot.h
@@ -70,8 +70,7 @@ void           gs_screenshot_add_image        (GsScreenshot           *screenshot,
                                                 guint                   height);
 const gchar    *gs_screenshot_get_url          (GsScreenshot           *screenshot,
                                                 guint                   width,
-                                                guint                   height,
-                                                GtkRequisition         *provided);
+                                                guint                   height);
 
 G_END_DECLS
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 5edef28..3c8d184 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -329,7 +329,6 @@ gs_shell_details_refresh_screenshots (GsShellDetails *shell_details)
        GtkWidget *list;
        GtkWidget *ssimg;
        guint i;
-       GtkRequisition provided;
 
        /* treat screenshots differently */
        if (gs_app_get_id_kind (priv->app) == GS_APP_ID_KIND_FONT) {
@@ -381,19 +380,14 @@ gs_shell_details_refresh_screenshots (GsShellDetails *shell_details)
 
        /* use a slightly larger screenshot if it's the only screenshot */
        if (screenshots->len == 1) {
-               gs_screenshot_get_url (ss,
-                                      GS_SCREENSHOT_SIZE_MAIN_ONLY_WIDTH,
-                                      GS_SCREENSHOT_SIZE_MAIN_ONLY_HEIGHT,
-                                      &provided);
+               gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
+                                             GS_SCREENSHOT_SIZE_MAIN_ONLY_WIDTH,
+                                             GS_SCREENSHOT_SIZE_MAIN_ONLY_HEIGHT);
        } else {
-               gs_screenshot_get_url (ss,
-                                      GS_SCREENSHOT_SIZE_MAIN_WIDTH,
-                                      GS_SCREENSHOT_SIZE_MAIN_HEIGHT,
-                                      &provided);
+               gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
+                                             GS_SCREENSHOT_SIZE_MAIN_WIDTH,
+                                             GS_SCREENSHOT_SIZE_MAIN_HEIGHT);
        }
-       gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
-                                     provided.width, provided.height);
-
        gs_screenshot_image_load_async (GS_SCREENSHOT_IMAGE (ssimg), NULL);
        gtk_box_pack_start (GTK_BOX (priv->box_details_screenshot_main), ssimg, FALSE, FALSE, 0);
        gtk_widget_set_visible (ssimg, TRUE);


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