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



commit a9f02483761fd30b5065560b3e8c1f88b3db667e
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 | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/panels/sound/cc-stream-row.c b/panels/sound/cc-stream-row.c
index a750e82e4..62bac6943 100644
--- a/panels/sound/cc-stream-row.c
+++ b/panels/sound/cc-stream-row.c
@@ -20,6 +20,8 @@
 #include "cc-stream-row.h"
 #include "cc-volume-slider.h"
 
+#define SPEECH_DISPATCHER_PREFIX "speech-dispatcher-"
+
 struct _CcStreamRow
 {
   GtkListBoxRow   parent_instance;
@@ -75,12 +77,34 @@ cc_stream_row_new (GtkSizeGroup   *size_group,
                    guint           id)
 {
   CcStreamRow *self;
+  g_autoptr(GtkIconInfo) icon_info = NULL;
+  g_autoptr(GIcon) gicon = NULL;
+  const gchar *stream_name;
+  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);
+  stream_name = gvc_mixer_stream_get_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 if (g_str_has_prefix (stream_name, SPEECH_DISPATCHER_PREFIX))
+    gicon = g_themed_icon_new_with_default_fallbacks ("preferences-desktop-accessibility-symbolic");
+  else
+    gicon = g_themed_icon_new_with_default_fallbacks ("application-x-executable-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]