[Xfce4-commits] <xfce4-mixer:gber/improvements> Populate the mixer with whitelisted controls by default (bug #4945)

Guido Berhoerster noreply at xfce.org
Fri Sep 21 17:18:21 CEST 2012


Updating branch refs/heads/gber/improvements
         to 262dc4c272c28b0d4411fb8dfbdf8a58574f96bd (commit)
       from e44805b64256bf4c62820c30576e3e1953ffc35d (commit)

commit 262dc4c272c28b0d4411fb8dfbdf8a58574f96bd
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date:   Fri Sep 21 12:00:36 2012 +0200

    Populate the mixer with whitelisted controls by default (bug #4945)
    
    Populate the mixer with whitelisted controls in the absence of an existing
    configuration. Select controls either based on the whitelist flag for mixers
    that support it or fall back to a static whitelist.

 NEWS                                   |    2 +
 libxfce4mixer/libxfce4mixer.c          |   80 ++++++++++++++++++++++++++++++--
 libxfce4mixer/libxfce4mixer.h          |    1 +
 libxfce4mixer/xfce-mixer-preferences.c |   59 +++++++++++++++++++-----
 4 files changed, 126 insertions(+), 16 deletions(-)

diff --git a/NEWS b/NEWS
index f2e2825..6d04cab 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@
   muting (bug #5314).
 - Set the main window to normal rather than dialog type (bug #7623).
 - Keep the sound card and controls in sync between the mixer and xfconf.
+- Populate the mixer with whitelisted controls in the absence of an existing
+  configuration (bug #4945).
 
 
 4.8.0
diff --git a/libxfce4mixer/libxfce4mixer.c b/libxfce4mixer/libxfce4mixer.c
index 7bb9293..6ca9466 100644
--- a/libxfce4mixer/libxfce4mixer.c
+++ b/libxfce4mixer/libxfce4mixer.c
@@ -42,10 +42,25 @@ static void     _xfce_mixer_destroy_mixer (GstMixer *mixer);
 
 
 
-static guint       refcount = 0;
-static GList      *mixers = NULL;
-static GstBus     *bus = NULL;
-static GstElement *selected_card = NULL;
+static guint        refcount = 0;
+static GList       *mixers = NULL;
+static GstBus      *bus = NULL;
+static GstElement  *selected_card = NULL;
+static const gchar *tracks_whitelist[] =
+{
+  "cd",
+  "digital output",
+  "front",
+  "headphone",
+  "line",
+  "master",
+  "mic",
+  "pcm",
+  "recording",
+  "speaker",
+  "volume",
+  NULL
+};
 
 
 
@@ -235,6 +250,63 @@ xfce_mixer_get_default_track (GstElement *card)
 
 
 
+GList *
+xfce_mixer_get_default_track_list (GstElement *card)
+{
+  gboolean       mixer_has_whitelist = FALSE;
+  const GList   *iter;
+  GList         *track_list = NULL;
+  GstMixerTrack *track;
+  gchar         *track_label;
+  gchar         *track_label_lower;
+  gint           i;
+
+  g_return_val_if_fail (GST_IS_MIXER (card), NULL);
+
+  if (gst_mixer_get_mixer_flags (GST_MIXER (card)) & GST_MIXER_FLAG_HAS_WHITELIST)
+    mixer_has_whitelist = TRUE;
+
+  for (iter = gst_mixer_list_tracks (GST_MIXER (card)); iter != NULL; iter = g_list_next (iter))
+    {
+      track = GST_MIXER_TRACK (iter->data);
+
+      /* Use the whitelist flag when available and fall back to a static whitelist */
+      if (mixer_has_whitelist)
+        {
+          if (GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_WHITELIST))
+            track_list = g_list_prepend (track_list, track);
+        }
+      else
+        {
+          track_label = NULL;
+
+          if (g_object_class_find_property (G_OBJECT_GET_CLASS (track), "untranslated-label"))
+            g_object_get (track, "untranslated-label", &track_label, NULL);
+
+          if (track_label == NULL)
+            g_object_get (track, "label", &track_label, NULL);
+
+          track_label_lower = g_utf8_strdown (track_label, -1);
+
+          for (i = 0; tracks_whitelist[i] != NULL; ++i)
+            {
+              if (strstr (track_label_lower, tracks_whitelist[i]) != NULL)
+                {
+                  track_list = g_list_prepend (track_list, track);
+                  break;
+                }
+            }
+
+          g_free (track_label_lower);
+          g_free (track_label);
+        }
+    }
+
+  return track_list;
+}
+
+
+
 guint
 xfce_mixer_bus_connect (GCallback callback,
                         gpointer  user_data)
diff --git a/libxfce4mixer/libxfce4mixer.h b/libxfce4mixer/libxfce4mixer.h
index 187db3f..473817c 100644
--- a/libxfce4mixer/libxfce4mixer.h
+++ b/libxfce4mixer/libxfce4mixer.h
@@ -49,6 +49,7 @@ void           xfce_mixer_select_card            (GstElement    *card);
 GstMixerTrack *xfce_mixer_get_track              (GstElement    *card,
                                                   const gchar   *track_name);
 GstMixerTrack *xfce_mixer_get_default_track      (GstElement    *card);
+GList         *xfce_mixer_get_default_track_list (GstElement    *card);
 guint          xfce_mixer_bus_connect            (GCallback      callback,
                                                   gpointer       user_data);
 void           xfce_mixer_bus_disconnect         (guint          signal_handler_id);
diff --git a/libxfce4mixer/xfce-mixer-preferences.c b/libxfce4mixer/xfce-mixer-preferences.c
index 2cb7edb..21faefc 100644
--- a/libxfce4mixer/xfce-mixer-preferences.c
+++ b/libxfce4mixer/xfce-mixer-preferences.c
@@ -44,17 +44,18 @@ enum
 
 
 
-static void   xfce_mixer_preferences_class_init        (XfceMixerPreferencesClass *klass);
-static void   xfce_mixer_preferences_init              (XfceMixerPreferences      *preferences);
-static void   xfce_mixer_preferences_finalize          (GObject                   *object);
-static void   xfce_mixer_preferences_get_property      (GObject                   *object,
-                                                        guint                      prop_id,
-                                                        GValue                    *value,
-                                                        GParamSpec                *pspec);
-static void   xfce_mixer_preferences_set_property      (GObject                   *object,
-                                                        guint                      prop_id,
-                                                        const GValue              *value,
-                                                        GParamSpec                *pspec);
+static void       xfce_mixer_preferences_class_init         (XfceMixerPreferencesClass *klass);
+static void       xfce_mixer_preferences_init               (XfceMixerPreferences      *preferences);
+static void       xfce_mixer_preferences_finalize           (GObject                   *object);
+static void       xfce_mixer_preferences_get_property       (GObject                   *object,
+                                                             guint                      prop_id,
+                                                             GValue                    *value,
+                                                             GParamSpec                *pspec);
+static void       xfce_mixer_preferences_set_property       (GObject                   *object,
+                                                             guint                      prop_id,
+                                                             const GValue              *value,
+                                                             GParamSpec                *pspec);
+static GPtrArray *xfce_mixer_preferences_get_default_tracks (XfceMixerPreferences *preferences);
 
 
 
@@ -305,7 +306,7 @@ xfce_mixer_preferences_set_property (GObject      *object,
             }
         }
       else
-        preferences->controls = g_ptr_array_new ();
+        preferences->controls = xfce_mixer_preferences_get_default_tracks (preferences);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -381,3 +382,37 @@ xfce_mixer_preferences_get_control_visible (XfceMixerPreferences *preferences,
   return visible;
 }
 
+
+
+static GPtrArray *
+xfce_mixer_preferences_get_default_tracks (XfceMixerPreferences *preferences)
+{
+  GList      *track_list;
+  GList      *iter;
+  GPtrArray  *tracks;
+  GstElement *card;
+  gchar      *track_label;
+  GValue     *value;
+
+  tracks = g_ptr_array_new ();
+
+  if (preferences->sound_card != NULL)
+    {
+      card = xfce_mixer_get_card (preferences->sound_card);
+
+      if (GST_IS_MIXER (card))
+        {
+          track_list = xfce_mixer_get_default_track_list (card);
+          for (iter = track_list; iter != NULL; iter = g_list_next (iter))
+            {
+              value = g_value_init (g_new0 (GValue, 1), G_TYPE_STRING);
+              g_object_get (G_OBJECT (iter->data), "label", &track_label, NULL);
+              g_value_take_string (value, track_label);
+              g_ptr_array_add (tracks, value);
+            }
+        }
+    }
+
+  return tracks;
+}
+


More information about the Xfce4-commits mailing list