[gnome-software: 1/5] gs-details-page: Refactor icon fallback code




commit 589858c57596249172da0dd2328c18166891d88d
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Aug 5 17:34:40 2021 +0100

    gs-details-page: Refactor icon fallback code
    
    Make it data-driven rather than a load of mostly-duplicated `if` blocks.
    
    This introduces no functional changes.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1350

 src/gs-details-page.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 39d4e4bef..418289315 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1020,24 +1020,23 @@ gs_details_page_refresh_all (GsDetailsPage *self)
 
        /* set the icon; fall back to 64px if 96px isn’t available, which sometimes
         * happens at 2× scale factor (hi-DPI) */
-       icon_size = 96;
-       icon = gs_app_get_icon_for_size (self->app,
-                                        icon_size,
-                                        gtk_widget_get_scale_factor (self->application_details_icon),
-                                        NULL);
-       if (icon == NULL) {
-               icon_size = 64;
-               icon = gs_app_get_icon_for_size (self->app,
-                                                icon_size,
-                                                gtk_widget_get_scale_factor (self->application_details_icon),
-                                                NULL);
-       }
-       if (icon == NULL) {
-               icon_size = 96;
-               icon = gs_app_get_icon_for_size (self->app,
-                                                icon_size,
-                                                gtk_widget_get_scale_factor (self->application_details_icon),
-                                                "system-component-application");
+       {
+               const struct {
+                       guint icon_size;
+                       const gchar *fallback_icon_name;  /* (nullable) */
+               } icon_fallbacks[] = {
+                       { 96, NULL },
+                       { 64, NULL },
+                       { 96, "system-component-application" },
+               };
+
+               for (gsize i = 0; i < G_N_ELEMENTS (icon_fallbacks) && icon == NULL; i++) {
+                       icon_size = icon_fallbacks[i].icon_size;
+                       icon = gs_app_get_icon_for_size (self->app,
+                                                        icon_size,
+                                                        gtk_widget_get_scale_factor 
(self->application_details_icon),
+                                                        icon_fallbacks[i].fallback_icon_name);
+               }
        }
 
        gtk_image_set_pixel_size (GTK_IMAGE (self->application_details_icon), icon_size);


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