[gnome-software/mwleeds/pwa-plugin] WIP



commit ea8058258a2453e613f2d6e9014727b5e06a55e5
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Wed Dec 15 14:28:37 2021 -0800

    WIP

 lib/gs-utils.c                        | 31 +++++++++++++++++++++++++++++++
 lib/gs-utils.h                        |  1 +
 plugins/epiphany/gs-plugin-epiphany.c |  1 +
 3 files changed, 33 insertions(+)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 8e81d11cf..6023b6fb6 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -41,6 +41,7 @@
 #include "gs-app.h"
 #include "gs-utils.h"
 #include "gs-plugin.h"
+#include "gs-icon.h"
 
 #define MB_IN_BYTES (1024 * 1024)
 
@@ -1427,6 +1428,36 @@ gs_utils_pixbuf_blur (GdkPixbuf *src, guint radius, guint iterations)
                gs_pixbuf_blur_private (src, tmp, radius, div_kernel_size);
 }
 
+/**
+ * gs_utils_file_icon_ensure_size:
+ * @icon: the #GIcon created with g_file_icon_new()
+ *
+ * This ensures that gs_icon_set_width() and gs_icon_set_height() have been
+ * called on @icon, by loading the width and height from the underlying file if
+ * needed.
+ **/
+void
+gs_utils_file_icon_ensure_size (GIcon *icon)
+{
+       GFile *file;
+       g_autofree char *file_path = NULL;
+       g_autoptr(GdkPixbuf) pixbuf = NULL;
+
+       if (gs_icon_get_width (icon) != 0)
+               return;
+
+       file = g_file_icon_get_file (G_FILE_ICON (icon));
+       g_assert (G_IS_FILE (file));
+       file_path = g_file_get_path (file);
+       pixbuf = gdk_pixbuf_new_from_file (file_path, NULL);
+       if (pixbuf == NULL)
+               g_warning ("%s: Failed to load pixbuf from %s", G_STRFUNC, file_path);
+       else {
+               gs_icon_set_width (icon, gdk_pixbuf_get_width (pixbuf));
+               gs_icon_set_height (icon, gdk_pixbuf_get_height (pixbuf));
+       }
+}
+
 /**
  * gs_utils_get_file_size:
  * @filename: a file name to get the size of; it can be a file or a directory
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index b5f590df8..ba9898737 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -111,6 +111,7 @@ gchar               *gs_utils_build_unique_id       (AsComponentScope scope,
 void            gs_utils_pixbuf_blur           (GdkPixbuf      *src,
                                                 guint          radius,
                                                 guint          iterations);
+void            gs_utils_file_icon_ensure_size (GIcon  *icon);
 
 /**
  * GsFileSizeIncludeFunc:
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index 32eabf257..ddff6b5dd 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -225,6 +225,7 @@ gs_plugin_add_installed (GsPlugin      *plugin,
                if (icon_path) {
                        g_autoptr(GFile) icon_file = g_file_new_for_path (icon_path);
                        g_autoptr(GIcon) icon = g_file_icon_new (icon_file);
+                       gs_utils_file_icon_ensure_size (icon);
                        gs_app_add_icon (app, icon);
                }
                if (install_date) {


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