[gnome-media] Fix card profile selection



commit 7e64d29bfd0132b18f0c67d12d02a5bab4b0752b
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 23 10:47:23 2009 +0100

    Fix card profile selection
    
    Set up the profiles on the GvcMixerCard object, and be able to get
    them back.

 gnome-volume-control/src/gvc-mixer-card.c    |   77 +++++++++++++-------------
 gnome-volume-control/src/gvc-mixer-card.h    |   46 ++++++++-------
 gnome-volume-control/src/gvc-mixer-control.c |   15 ++++-
 3 files changed, 77 insertions(+), 61 deletions(-)
---
diff --git a/gnome-volume-control/src/gvc-mixer-card.c b/gnome-volume-control/src/gvc-mixer-card.c
index 34a3df1..1ae3a52 100644
--- a/gnome-volume-control/src/gvc-mixer-card.c
+++ b/gnome-volume-control/src/gvc-mixer-card.c
@@ -45,7 +45,7 @@ struct GvcMixerCardPrivate
         char          *icon_name;
         char          *profile;
         char          *human_profile;
-        GHashTable    *profiles;
+        GList         *profiles;
 };
 
 enum
@@ -141,72 +141,75 @@ gvc_mixer_card_set_icon_name (GvcMixerCard *card,
         return TRUE;
 }
 
-const char *
+GvcMixerCardProfile *
 gvc_mixer_card_get_profile (GvcMixerCard *card)
 {
-        g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
-        return card->priv->profile;
-}
+        GList *l;
+        GvcMixerCardProfile *ret;
 
-const char *
-gvc_mixer_card_get_human_profile (GvcMixerCard *card)
-{
         g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
-        return card->priv->human_profile;
+
+        ret = NULL;
+        for (l = card->priv->profiles; l != NULL; l = l->next) {
+                GvcMixerCardProfile *p = l->data;
+                if (g_str_equal (card->priv->profile, p->profile)) {
+                        ret = p;
+                        break;
+                }
+        }
+
+        return ret;
 }
 
 gboolean
 gvc_mixer_card_set_profile (GvcMixerCard *card,
                             const char     *profile)
 {
+        GList *l;
+
         g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
+        g_return_val_if_fail (card->priv->profiles != NULL, FALSE);
+
+        if (g_strcmp0 (card->priv->profile, profile) == 0)
+                return TRUE;
 
         if (card->priv->profile != NULL) {
                 g_free (card->priv->profile);
                 card->priv->profile = g_strdup (profile);
                 g_object_notify (G_OBJECT (card), "profile");
+                g_free (card->priv->human_profile);
+                card->priv->human_profile = NULL;
         } else {
                 card->priv->profile = g_strdup (profile);
+                g_assert (card->priv->human_profile == NULL);
         }
 
-        return TRUE;
-}
-
-gboolean
-gvc_mixer_card_set_human_profile (GvcMixerCard *card,
-                                  const char     *profile)
-{
-        g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
-
-        if (card->priv->human_profile != NULL) {
-                g_free (card->priv->human_profile);
-                card->priv->human_profile = g_strdup (profile);
-                g_object_notify (G_OBJECT (card), "human-profile");
-        } else {
-                card->priv->human_profile = g_strdup (profile);
+        for (l = card->priv->profiles; l != NULL; l = l->next) {
+                GvcMixerCardProfile *p = l->data;
+                if (g_str_equal (profile, p->profile)) {
+                        card->priv->human_profile = g_strdup (p->human_profile);
+                        break;
+                }
         }
 
         return TRUE;
 }
 
-GHashTable *
+const GList *
 gvc_mixer_card_get_profiles (GvcMixerCard *card)
 {
         g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
-        return g_hash_table_ref (card->priv->profiles);
+        return card->priv->profiles;
 }
 
 gboolean
 gvc_mixer_card_set_profiles (GvcMixerCard *card,
-                             GHashTable   *profiles)
+                             GList        *profiles)
 {
         g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
+        g_return_val_if_fail (card->priv->profiles == NULL, FALSE);
 
-        g_hash_table_unref (card->priv->profiles);
-        if (profiles == NULL)
-                card->priv->profiles = NULL;
-        else
-                card->priv->profiles = g_hash_table_ref (profiles);
+        card->priv->profiles = profiles;
 
         return TRUE;
 }
@@ -238,9 +241,6 @@ gvc_mixer_card_set_property (GObject       *object,
         case PROP_PROFILE:
                 gvc_mixer_card_set_profile (self, g_value_get_string (value));
                 break;
-        case PROP_HUMAN_PROFILE:
-                gvc_mixer_card_set_human_profile (self, g_value_get_string (value));
-                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -351,14 +351,14 @@ gvc_mixer_card_class_init (GvcMixerCardClass *klass)
                                                               "Profile",
                                                               "Name of current profile for this card",
                                                               NULL,
-                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+                                                              G_PARAM_READWRITE));
         g_object_class_install_property (gobject_class,
                                          PROP_HUMAN_PROFILE,
                                          g_param_spec_string ("human-profile",
                                                               "Profile (Human readable)",
                                                               "Name of current profile for this card in human readable form",
                                                               NULL,
-                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+                                                              G_PARAM_READABLE));
 
         g_type_class_add_private (klass, sizeof (GvcMixerCardPrivate));
 }
@@ -406,7 +406,8 @@ gvc_mixer_card_finalize (GObject *object)
         g_free (mixer_card->priv->human_profile);
         mixer_card->priv->human_profile = NULL;
 
-        g_hash_table_unref (mixer_card->priv->profiles);
+        g_list_foreach (mixer_card->priv->profiles, (GFunc) g_free, NULL);
+        g_list_free (mixer_card->priv->profiles);
         mixer_card->priv->profiles = NULL;
 
         G_OBJECT_CLASS (gvc_mixer_card_parent_class)->finalize (object);
diff --git a/gnome-volume-control/src/gvc-mixer-card.h b/gnome-volume-control/src/gvc-mixer-card.h
index cefb1ca..68d3ea2 100644
--- a/gnome-volume-control/src/gvc-mixer-card.h
+++ b/gnome-volume-control/src/gvc-mixer-card.h
@@ -48,31 +48,35 @@ typedef struct
         /* vtable */
 } GvcMixerCardClass;
 
-GType               gvc_mixer_card_get_type          (void);
-GvcMixerCard *      gvc_mixer_card_new               (pa_context   *context,
-                                                      guint         index);
+typedef struct
+{
+        const char *profile;
+        const char *human_profile;
+        guint priority;
+} GvcMixerCardProfile;
+
+GType                 gvc_mixer_card_get_type          (void);
+GvcMixerCard *        gvc_mixer_card_new               (pa_context   *context,
+                                                        guint         index);
 
-guint               gvc_mixer_card_get_id            (GvcMixerCard *card);
-guint               gvc_mixer_card_get_index         (GvcMixerCard *card);
-const char *        gvc_mixer_card_get_name          (GvcMixerCard *card);
-const char *        gvc_mixer_card_get_icon_name     (GvcMixerCard *card);
-const char *        gvc_mixer_card_get_profile       (GvcMixerCard *card);
-const char *        gvc_mixer_card_get_human_profile (GvcMixerCard *card);
-GHashTable *        gvc_mixer_card_get_profiles      (GvcMixerCard *card);
+guint                 gvc_mixer_card_get_id            (GvcMixerCard *card);
+guint                 gvc_mixer_card_get_index         (GvcMixerCard *card);
+const char *          gvc_mixer_card_get_name          (GvcMixerCard *card);
+const char *          gvc_mixer_card_get_icon_name     (GvcMixerCard *card);
+GvcMixerCardProfile * gvc_mixer_card_get_profile       (GvcMixerCard *card);
+const GList *         gvc_mixer_card_get_profiles      (GvcMixerCard *card);
 
-pa_context *        gvc_mixer_card_get_pa_context  (GvcMixerCard *card);
+pa_context *          gvc_mixer_card_get_pa_context  (GvcMixerCard *card);
 
 /* private */
-gboolean            gvc_mixer_card_set_name          (GvcMixerCard *card,
-                                                      const char   *name);
-gboolean            gvc_mixer_card_set_icon_name     (GvcMixerCard *card,
-                                                      const char   *name);
-gboolean            gvc_mixer_card_set_profile       (GvcMixerCard *card,
-                                                      const char   *profile);
-gboolean            gvc_mixer_card_set_human_profile (GvcMixerCard *card,
-                                                      const char   *profile);
-gboolean            gvc_mixer_card_set_profiles      (GvcMixerCard *card,
-                                                      GHashTable   *profiles);
+gboolean              gvc_mixer_card_set_name          (GvcMixerCard *card,
+                                                        const char   *name);
+gboolean              gvc_mixer_card_set_icon_name     (GvcMixerCard *card,
+                                                        const char   *name);
+gboolean              gvc_mixer_card_set_profile       (GvcMixerCard *card,
+                                                        const char   *profile);
+gboolean              gvc_mixer_card_set_profiles      (GvcMixerCard *card,
+                                                        GList        *profiles);
 
 G_END_DECLS
 
diff --git a/gnome-volume-control/src/gvc-mixer-control.c b/gnome-volume-control/src/gvc-mixer-control.c
index d3837f4..e5953a0 100644
--- a/gnome-volume-control/src/gvc-mixer-control.c
+++ b/gnome-volume-control/src/gvc-mixer-control.c
@@ -943,8 +943,21 @@ update_card (GvcMixerControl      *control,
         card = g_hash_table_lookup (control->priv->cards,
                                     GUINT_TO_POINTER (info->index));
         if (card == NULL) {
+                GList *list = NULL;
+
+                for (i = 0; i < info->n_profiles; i++) {
+                        struct pa_card_profile_info pi = info->profiles[i];
+                        GvcMixerCardProfile *profile;
+
+                        profile = g_new0 (GvcMixerCardProfile, 1);
+                        profile->profile = pi.name;
+                        profile->human_profile = pi.description;
+                        profile->priority = pi.priority;
+                        list = g_list_prepend (list, profile);
+                }
                 card = gvc_mixer_card_new (control->priv->pa_context,
                                            info->index);
+                gvc_mixer_card_set_profiles (card, list);
                 is_new = TRUE;
         }
 
@@ -953,8 +966,6 @@ update_card (GvcMixerControl      *control,
 //FIXME set the icon name properly
 //        gvc_mixer_card_set_icon_name (card, pa_proplist_gets (info->proplist, "device.icon_name"));
         gvc_mixer_card_set_profile (card, info->active_profile->name);
-        gvc_mixer_card_set_human_profile (card, info->active_profile->description);
-        //FIXME set profiles here
 
         if (is_new) {
                 g_hash_table_insert (control->priv->cards,



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