[gnome-control-center/wip/every-detail-matters-round1] sound: Use fallback icon when stream's icon doesn't exist



commit 920d8d75cb2cb4104f95b19e96ff48c53083cd28
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jun 14 12:34:39 2019 -0300

    sound: Use fallback icon when stream's icon doesn't exist
    
    Some streams may give us an icon name that doesn't exist in the
    icon theme (e.g. Spotify giving "audio"). While it's fundamentally
    an application problem, we can deal with this case a bit better
    than showing the ugly "image-missing" icon.
    
    Detect when an icon doesn't exist by performing an icon theme
    lookup and, if the icon really doesn't exist, use a proper fallback
    icon.
    
    It also avoids a small GIcon leak.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-control-center/issues/548

 panels/sound/cc-stream-row.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/panels/sound/cc-stream-row.c b/panels/sound/cc-stream-row.c
index a750e82e4..a450f97c4 100644
--- a/panels/sound/cc-stream-row.c
+++ b/panels/sound/cc-stream-row.c
@@ -75,12 +75,30 @@ cc_stream_row_new (GtkSizeGroup   *size_group,
                    guint           id)
 {
   CcStreamRow *self;
+  g_autoptr(GtkIconInfo) icon_info = NULL;
+  g_autoptr(GIcon) gicon = NULL;
+  const gchar *icon_name;
 
   self = g_object_new (CC_TYPE_STREAM_ROW, NULL);
   self->stream = g_object_ref (stream);
   self->id = id;
 
-  gtk_image_set_from_gicon (self->icon_image, gvc_mixer_stream_get_gicon (stream), 
GTK_ICON_SIZE_LARGE_TOOLBAR);
+  icon_name = gvc_mixer_stream_get_icon_name (stream);
+
+  /* Explicitly lookup for the icon, since some streams may give us an
+   * icon name (e.g. "audio") that doesn't really exist in the theme.
+   */
+  icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+                                          icon_name,
+                                          24,
+                                          GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+
+  if (icon_info)
+    gicon = g_themed_icon_new_with_default_fallbacks (icon_name);
+  else
+    gicon = g_themed_icon_new_with_default_fallbacks ("applications-multimedia-symbolic");
+
+  gtk_image_set_from_gicon (self->icon_image, gicon, GTK_ICON_SIZE_LARGE_TOOLBAR);
 
   gtk_label_set_label (self->name_label, gvc_mixer_stream_get_name (stream));
   cc_volume_slider_set_stream (self->volume_slider, stream);


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