[gnome-control-center] Show icons for devices



commit 744871943ab0b60fbf4b2192951b2dec05dd887f
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Oct 13 13:34:15 2009 +0100

    Show icons for devices
    
    Show device icons in the stream treeviews. Use GIcon
    to get automatic fallback.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=581917

 panels/sound/gvc-mixer-control.c |  104 ++++++++++++++++++++------------------
 panels/sound/gvc-mixer-dialog.c  |   32 ++++++++++--
 panels/sound/gvc-mixer-stream.c  |    9 +++
 panels/sound/gvc-mixer-stream.h  |    2 +
 4 files changed, 93 insertions(+), 54 deletions(-)
---
diff --git a/panels/sound/gvc-mixer-control.c b/panels/sound/gvc-mixer-control.c
index d8d80f6..6f05be3 100644
--- a/panels/sound/gvc-mixer-control.c
+++ b/panels/sound/gvc-mixer-control.c
@@ -711,6 +711,58 @@ add_stream (GvcMixerControl *control,
 }
 
 static void
+set_icon_name_from_proplist (GvcMixerStream *stream,
+                             pa_proplist    *l,
+                             const char     *default_icon_name)
+{
+        const char *t;
+
+        if ((t = pa_proplist_gets (l, PA_PROP_DEVICE_ICON_NAME))) {
+                goto finish;
+        }
+
+        if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ICON_NAME))) {
+                goto finish;
+        }
+
+        if ((t = pa_proplist_gets (l, PA_PROP_WINDOW_ICON_NAME))) {
+                goto finish;
+        }
+
+        if ((t = pa_proplist_gets (l, PA_PROP_APPLICATION_ICON_NAME))) {
+                goto finish;
+        }
+
+        if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ROLE))) {
+
+                if (strcmp (t, "video") == 0 ||
+                    strcmp (t, "phone") == 0) {
+                        goto finish;
+                }
+
+                if (strcmp (t, "music") == 0) {
+                        t = "audio";
+                        goto finish;
+                }
+
+                if (strcmp (t, "game") == 0) {
+                        t = "applications-games";
+                        goto finish;
+                }
+
+                if (strcmp (t, "event") == 0) {
+                        t = "dialog-information";
+                        goto finish;
+                }
+        }
+
+        t = default_icon_name;
+
+ finish:
+        gvc_mixer_stream_set_icon_name (stream, t);
+}
+
+static void
 update_sink (GvcMixerControl    *control,
              const pa_sink_info *info)
 {
@@ -767,7 +819,7 @@ update_sink (GvcMixerControl    *control,
         gvc_mixer_stream_set_name (stream, info->name);
         gvc_mixer_stream_set_card_index (stream, info->card);
         gvc_mixer_stream_set_description (stream, info->description);
-        gvc_mixer_stream_set_icon_name (stream, "audio-card");
+        set_icon_name_from_proplist (stream, info->proplist, "audio-card");
         gvc_mixer_stream_set_volume (stream, (guint)max_volume);
         gvc_mixer_stream_set_is_muted (stream, info->mute);
         gvc_mixer_stream_set_can_decibel (stream, !!(info->flags & PA_SINK_DECIBEL_VOLUME));
@@ -856,7 +908,7 @@ update_source (GvcMixerControl      *control,
         gvc_mixer_stream_set_name (stream, info->name);
         gvc_mixer_stream_set_card_index (stream, info->card);
         gvc_mixer_stream_set_description (stream, info->description);
-        gvc_mixer_stream_set_icon_name (stream, "audio-input-microphone");
+        set_icon_name_from_proplist (stream, info->proplist, "audio-input-microphone");
         gvc_mixer_stream_set_volume (stream, (guint)max_volume);
         gvc_mixer_stream_set_is_muted (stream, info->mute);
         gvc_mixer_stream_set_can_decibel (stream, !!(info->flags & PA_SOURCE_DECIBEL_VOLUME));
@@ -881,54 +933,6 @@ update_source (GvcMixerControl      *control,
 }
 
 static void
-set_icon_name_from_proplist (GvcMixerStream *stream,
-                             pa_proplist    *l,
-                             const char     *default_icon_name)
-{
-        const char *t;
-
-        if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ICON_NAME))) {
-                goto finish;
-        }
-
-        if ((t = pa_proplist_gets (l, PA_PROP_WINDOW_ICON_NAME))) {
-                goto finish;
-        }
-
-        if ((t = pa_proplist_gets (l, PA_PROP_APPLICATION_ICON_NAME))) {
-                goto finish;
-        }
-
-        if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ROLE))) {
-
-                if (strcmp (t, "video") == 0 ||
-                    strcmp (t, "phone") == 0) {
-                        goto finish;
-                }
-
-                if (strcmp (t, "music") == 0) {
-                        t = "audio";
-                        goto finish;
-                }
-
-                if (strcmp (t, "game") == 0) {
-                        t = "applications-games";
-                        goto finish;
-                }
-
-                if (strcmp (t, "event") == 0) {
-                        t = "dialog-information";
-                        goto finish;
-                }
-        }
-
-        t = default_icon_name;
-
- finish:
-        gvc_mixer_stream_set_icon_name (stream, t);
-}
-
-static void
 set_is_event_stream_from_proplist (GvcMixerStream *stream,
                                    pa_proplist    *l)
 {
diff --git a/panels/sound/gvc-mixer-dialog.c b/panels/sound/gvc-mixer-dialog.c
index fa4ca3b..c1b3ecf 100644
--- a/panels/sound/gvc-mixer-dialog.c
+++ b/panels/sound/gvc-mixer-dialog.c
@@ -91,6 +91,7 @@ enum {
         ACTIVE_COLUMN,
         ID_COLUMN,
         SPEAKERS_COLUMN,
+        ICON_COLUMN,
         NUM_COLUMNS
 };
 
@@ -1093,16 +1094,21 @@ add_stream (GvcMixerDialog *dialog,
         if (GVC_IS_MIXER_SOURCE (stream)) {
                 GtkTreeModel *model;
                 GtkTreeIter   iter;
+                GIcon        *icon;
 
                 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->input_treeview));
                 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+                icon = gvc_mixer_stream_get_gicon (stream);
                 gtk_list_store_set (GTK_LIST_STORE (model),
                                     &iter,
                                     NAME_COLUMN, gvc_mixer_stream_get_description (stream),
                                     DEVICE_COLUMN, "",
                                     ACTIVE_COLUMN, is_default,
+                                    ICON_COLUMN, icon,
                                     ID_COLUMN, gvc_mixer_stream_get_id (stream),
                                     -1);
+                if (icon != NULL)
+                        g_object_unref (icon);
                 g_signal_connect (stream,
                                   "notify::description",
                                   G_CALLBACK (on_stream_description_notify),
@@ -1111,10 +1117,12 @@ add_stream (GvcMixerDialog *dialog,
                 GtkTreeModel        *model;
                 GtkTreeIter          iter;
                 const GvcChannelMap *map;
+                GIcon               *icon;
 
                 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview));
                 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
                 map = gvc_mixer_stream_get_channel_map (stream);
+                icon = gvc_mixer_stream_get_gicon (stream);
                 gtk_list_store_set (GTK_LIST_STORE (model),
                                     &iter,
                                     NAME_COLUMN, gvc_mixer_stream_get_description (stream),
@@ -1123,6 +1131,8 @@ add_stream (GvcMixerDialog *dialog,
                                     ID_COLUMN, gvc_mixer_stream_get_id (stream),
                                     SPEAKERS_COLUMN, gvc_channel_map_get_mapping (map),
                                     -1);
+                if (icon != NULL)
+                        g_object_unref (icon);
                 g_signal_connect (stream,
                                   "notify::description",
                                   G_CALLBACK (on_stream_description_notify),
@@ -1262,6 +1272,8 @@ add_card (GvcMixerDialog *dialog,
                             HW_STATUS_COLUMN, profile->status,
                             HW_SENSITIVE_COLUMN, g_strcmp0 (profile->profile, "off") != 0,
                             -1);
+        if (icon != NULL)
+                g_object_unref (icon);
 
         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->hw_treeview));
         if (gtk_tree_selection_get_selected (selection, NULL, NULL) == FALSE) {
@@ -1457,7 +1469,8 @@ create_stream_treeview (GvcMixerDialog *dialog,
                                     G_TYPE_STRING,
                                     G_TYPE_BOOLEAN,
                                     G_TYPE_UINT,
-                                    G_TYPE_STRING);
+                                    G_TYPE_STRING,
+                                    G_TYPE_ICON);
         gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
                                  GTK_TREE_MODEL (store));
 
@@ -1474,9 +1487,20 @@ create_stream_treeview (GvcMixerDialog *dialog,
                           G_CALLBACK (on_toggled),
                           dialog);
 
-        gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview), -1,
-                                                    _("Name"), gtk_cell_renderer_text_new (),
-                                                    name_to_text, NULL, NULL);
+        column = gtk_tree_view_column_new ();
+        gtk_tree_view_column_set_title (column, _("Name"));
+        renderer = gtk_cell_renderer_pixbuf_new ();
+        gtk_tree_view_column_pack_start (column, renderer, FALSE);
+        g_object_set (G_OBJECT (renderer), "stock-size", GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
+        gtk_tree_view_column_set_attributes (column, renderer,
+                                             "gicon", ICON_COLUMN,
+                                             NULL);
+
+        renderer = gtk_cell_renderer_text_new ();
+        gtk_tree_view_column_pack_start (column, renderer, TRUE);
+        gtk_tree_view_column_set_cell_data_func (column, renderer,
+                                                 name_to_text, NULL, NULL);
+        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
 #if 0
         renderer = gtk_cell_renderer_text_new ();
diff --git a/panels/sound/gvc-mixer-stream.c b/panels/sound/gvc-mixer-stream.c
index 3b4953a..3f5fe56 100644
--- a/panels/sound/gvc-mixer-stream.c
+++ b/panels/sound/gvc-mixer-stream.c
@@ -390,6 +390,15 @@ gvc_mixer_stream_get_icon_name (GvcMixerStream *stream)
         return stream->priv->icon_name;
 }
 
+GIcon *
+gvc_mixer_stream_get_gicon (GvcMixerStream *stream)
+{
+        g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL);
+        if (stream->priv->icon_name == NULL)
+                return NULL;
+        return g_themed_icon_new_with_default_fallbacks (stream->priv->icon_name);
+}
+
 gboolean
 gvc_mixer_stream_set_icon_name (GvcMixerStream *stream,
                                 const char     *icon_name)
diff --git a/panels/sound/gvc-mixer-stream.h b/panels/sound/gvc-mixer-stream.h
index 53b7eb6..1c38e6b 100644
--- a/panels/sound/gvc-mixer-stream.h
+++ b/panels/sound/gvc-mixer-stream.h
@@ -24,6 +24,7 @@
 #include <glib-object.h>
 #include "gvc-pulseaudio-fake.h"
 #include "gvc-channel-map.h"
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -84,6 +85,7 @@ gboolean            gvc_mixer_stream_change_is_muted (GvcMixerStream *stream,
 gboolean            gvc_mixer_stream_is_running      (GvcMixerStream *stream);
 const char *        gvc_mixer_stream_get_name        (GvcMixerStream *stream);
 const char *        gvc_mixer_stream_get_icon_name   (GvcMixerStream *stream);
+GIcon *             gvc_mixer_stream_get_gicon       (GvcMixerStream *stream);
 const char *        gvc_mixer_stream_get_description (GvcMixerStream *stream);
 const char *        gvc_mixer_stream_get_application_id (GvcMixerStream *stream);
 gboolean            gvc_mixer_stream_is_event_stream (GvcMixerStream *stream);



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