~harryhaaren/gnome-control-center/profilesShownInUI

« back to all changes in this revision

Viewing changes to panels/sound/gvc-mixer-dialog.c

  • Committer: Harry van Haaren
  • Date: 2011-08-05 09:57:26 UTC
  • Revision ID: harryhaaren@gmail.com-20110805095726-ooyme1caksbupjvy
UI now shows profiles instead of Cards, hardware tab removed. Profile selection needs some work

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
        PROP_MIXER_CONTROL
113
113
};
114
114
 
 
115
// Here we create some variables to store information about profiles,
 
116
// profile indexs, and card indexs
 
117
static guint      unique_profile_index_counter = 0;
 
118
static GHashTable *unique_profile_index_to_card_index = NULL;
 
119
static GHashTable *unique_profile_index_to_profile_index = NULL;
 
120
 
115
121
static void     gvc_mixer_dialog_class_init (GvcMixerDialogClass *klass);
116
122
static void     gvc_mixer_dialog_init       (GvcMixerDialog      *mixer_dialog);
117
123
static void     gvc_mixer_dialog_finalize   (GObject             *object);
335
341
 
336
342
                gvc_combo_box_set_size_group (GVC_COMBO_BOX (dialog->priv->output_port_combo), dialog->priv->size_group, FALSE);
337
343
 
 
344
                // comment show() here to remove the "Connector" selector in the output tab
338
345
                gtk_widget_show (dialog->priv->output_port_combo);
339
346
        }
340
347
 
355
362
                gboolean        is_default;
356
363
                guint           id;
357
364
                GvcMixerStream *stream;
358
 
 
 
365
                GvcMixerCard   *card;
 
366
                
359
367
                gtk_tree_model_get (model, &iter,
360
368
                                    ID_COLUMN, &id,
361
369
                                    ACTIVE_COLUMN, &toggled,
362
370
                                    -1);
 
371
                
 
372
/*
 
373
                g_debug("Searching for %i in hashtable", id);
 
374
                gpointer card_index_pointer = g_hash_table_lookup(unique_profile_index_to_card_index, GINT_TO_POINTER (id));
 
375
                gpointer profile_index_pointer = g_hash_table_lookup(unique_profile_index_to_profile_index, GINT_TO_POINTER (id));
363
376
 
 
377
                // both can be equal to 0, so can't assert
 
378
                id = GPOINTER_TO_INT (card_index_pointer);
 
379
                guint profile_id = GPOINTER_TO_INT (profile_index_pointer);
 
380
        
 
381
        // returns a GvcMixerCard* from a card index
 
382
        card = gvc_mixer_control_lookup_card_id (dialog->priv->mixer_control, id);
 
383
        
 
384
        if (card == NULL) {
 
385
                g_warning ("Unable to find card for id: %u", id);
 
386
                return;
 
387
        }
 
388
        
 
389
        // get the current profile, for the UI to display
 
390
        GvcMixerCardProfile *current_profile = gvc_mixer_card_get_profile (card);
 
391
        
 
392
        // now we still need to get from the profile ID to the profile 
 
393
        // const char* to set the values. To do this we have "id", which
 
394
        // is now our target profile number. This is *not* an index, its
 
395
        // the position of the profile in the list of profiles for that card.
 
396
        const GList* profiles = gvc_mixer_card_get_profiles (card);
 
397
        
 
398
        // cycle trough profiles, and once we hit  id  iterations, were
 
399
        // pointing to the target profile.
 
400
        guint i = 0;
 
401
        while ( profiles != NULL )
 
402
        {
 
403
          profiles = profiles->next;
 
404
          if ( i == profile_id )
 
405
            break;
 
406
          else
 
407
            i++;
 
408
        }
 
409
        GvcMixerCardProfile* p = profiles->data;
 
410
        
 
411
        //gvc_mixer_card_change_profile (card, p->profile);
 
412
*/
 
413
                id = 0;
364
414
                stream = gvc_mixer_control_lookup_stream_id (dialog->priv->mixer_control, id);
365
415
                if (stream == NULL) {
366
 
                        g_warning ("Unable to find stream for id: %u", id);
 
416
                        g_warning ("OUTPUT: Unable to find stream for id: %u", id);
367
417
                        continue;
368
418
                }
369
419
 
1082
1132
        bar = NULL;
1083
1133
        is_default = FALSE;
1084
1134
        id = gvc_mixer_stream_get_application_id (stream);
 
1135
        
 
1136
        g_debug("add_stream()");
1085
1137
 
1086
1138
        if (stream == gvc_mixer_control_get_default_sink (dialog->priv->mixer_control)) {
1087
1139
                bar = dialog->priv->output_bar;
1195
1247
                         guint            id,
1196
1248
                         GvcMixerDialog  *dialog)
1197
1249
{
 
1250
        g_debug("on_control_stream_added()");
 
1251
  
1198
1252
        GvcMixerStream *stream;
1199
1253
        GtkWidget      *bar;
1200
1254
 
1297
1351
        GtkTreeSelection    *selection;
1298
1352
        GvcMixerCardProfile *profile;
1299
1353
        GIcon               *icon;
1300
 
        guint                index;
 
1354
        guint                card_index;
1301
1355
 
 
1356
        // get data of the model:
1302
1357
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->hw_treeview));
1303
 
        index = gvc_mixer_card_get_index (card);
1304
 
        if (find_item_by_id (GTK_TREE_MODEL (model), index, HW_ID_COLUMN, &iter) == FALSE)
1305
 
                gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1306
 
        profile = gvc_mixer_card_get_profile (card);
1307
 
        g_assert (profile != NULL);
1308
 
        icon = g_themed_icon_new_with_default_fallbacks (gvc_mixer_card_get_icon_name (card));
1309
 
        //FIXME we need the status (default for a profile?) here
1310
 
        gtk_list_store_set (GTK_LIST_STORE (model),
1311
 
                            &iter,
1312
 
                            HW_NAME_COLUMN, gvc_mixer_card_get_name (card),
1313
 
                            HW_ID_COLUMN, index,
1314
 
                            HW_ICON_COLUMN, icon,
1315
 
                            HW_PROFILE_COLUMN, profile->profile,
1316
 
                            HW_PROFILE_HUMAN_COLUMN, profile->human_profile,
1317
 
                            HW_STATUS_COLUMN, profile->status,
1318
 
                            HW_SENSITIVE_COLUMN, g_strcmp0 (profile->profile, "off") != 0,
1319
 
                            -1);
1320
 
        if (icon != NULL)
1321
 
                g_object_unref (icon);
1322
 
 
 
1358
        
 
1359
        // get the index of the card to retrieve info from the model
 
1360
        card_index = gvc_mixer_card_get_index (card);
 
1361
        
 
1362
        
 
1363
        g_debug("Getting list of profiles NOW!");
 
1364
        const GList * profileList = gvc_mixer_card_get_profiles(card);
 
1365
        
 
1366
        g_assert(profileList);
 
1367
        
 
1368
        guint i;
 
1369
        
 
1370
        g_debug("Iterating over list of profiles...");
 
1371
        for ( i = 0; profileList != NULL; profileList = profileList->next, i++)
 
1372
        {
 
1373
                g_debug("itering list: current Name:");// %s, Desc: %s",gvc_mixer_card_get_name (card),profile->human_profile);
 
1374
                
 
1375
                if (profileList == NULL) {
 
1376
                  break;
 
1377
                }
 
1378
                profile = profileList->data;
 
1379
                if (profile == NULL) {
 
1380
                  break;
 
1381
                }
 
1382
                
 
1383
                // FIXME: we don't want to show input only profiles either,
 
1384
                // here we can regex trough the profile->profile, and if it includes
 
1385
                // "input" but not "output" then don't display it.
 
1386
                
 
1387
                // we don't want to show the "off" profile
 
1388
                if (g_strcmp0 (profile->profile, "off") != 0) {
 
1389
                  
 
1390
                  // if the model doesn't contain info on the current index, create a new one
 
1391
                  if (find_item_by_id (GTK_TREE_MODEL (model), i , HW_ID_COLUMN, &iter) == FALSE)
 
1392
                          gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
1393
                  
 
1394
                  icon = g_themed_icon_new_with_default_fallbacks (gvc_mixer_card_get_icon_name (card));
 
1395
                  //FIXME we need the status (default for a profile?) here
 
1396
                  
 
1397
 
 
1398
                  gtk_list_store_set (GTK_LIST_STORE (model),
 
1399
                                      &iter,
 
1400
                                      HW_NAME_COLUMN, profile->human_profile, // top row
 
1401
                                      HW_ID_COLUMN, card_index,
 
1402
                                      HW_ICON_COLUMN, icon,
 
1403
                                      HW_PROFILE_COLUMN, profile->profile,
 
1404
                                      HW_PROFILE_HUMAN_COLUMN, "", // profile->profile, // bottom row
 
1405
                                      HW_STATUS_COLUMN, gvc_mixer_card_get_name(card), // center row
 
1406
                                      HW_SENSITIVE_COLUMN, 1, // always selectable
 
1407
                                      -1);
 
1408
                  if (icon != NULL)
 
1409
                        g_object_unref (icon);
 
1410
                  
 
1411
                  // now that we've inserted this card's profile into the UI, store
 
1412
                  // the card index and the profile index, in relation to the unique
 
1413
                  // profile index: that way we can work backwards from unique profile
 
1414
                  // to the card & profile indexs when the user selects a different output
 
1415
                  g_hash_table_insert( unique_profile_index_to_card_index,
 
1416
                                      GINT_TO_POINTER(unique_profile_index_counter),
 
1417
                                      GINT_TO_POINTER(card_index));
 
1418
                  
 
1419
                  g_hash_table_insert( unique_profile_index_to_profile_index,
 
1420
                                      GINT_TO_POINTER(unique_profile_index_counter),
 
1421
                                      GINT_TO_POINTER(card_index));
 
1422
                  
 
1423
                  unique_profile_index_counter++;
 
1424
                }
 
1425
        }
 
1426
 
 
1427
        // here we get the selection from the HW (output tab) treeview 
1323
1428
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->hw_treeview));
 
1429
        
1324
1430
        if (gtk_tree_selection_get_selected (selection, NULL, NULL) == FALSE) {
1325
1431
                gtk_tree_selection_select_iter (selection, &iter);
1326
 
        } else if (dialog->priv->hw_profile_combo != NULL) {
 
1432
        }
 
1433
        else if (dialog->priv->hw_profile_combo != NULL)
 
1434
        {
1327
1435
                GvcMixerCard *selected;
1328
1436
 
1329
1437
                /* Set the current profile if it changed for the selected card */
1330
1438
                selected = g_object_get_data (G_OBJECT (dialog->priv->hw_profile_combo), "card");
1331
 
                if (gvc_mixer_card_get_index (selected) == gvc_mixer_card_get_index (card)) {
 
1439
                
 
1440
                if (gvc_mixer_card_get_index (selected) == gvc_mixer_card_get_index (card))
 
1441
                {
1332
1442
                        gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->hw_profile_combo),
1333
1443
                                                  profile->profile);
 
1444
                        
1334
1445
                        g_object_set (G_OBJECT (dialog->priv->hw_profile_combo),
1335
1446
                                      "show-button", profile->n_sinks == 1,
1336
1447
                                      NULL);
1343
1454
                       guint            id,
1344
1455
                       GvcMixerDialog  *dialog)
1345
1456
{
 
1457
        g_debug("on_control_card_added()");
 
1458
  
1346
1459
        GvcMixerCard *card;
1347
1460
 
1348
1461
        card = gvc_mixer_control_lookup_card_id (control, id);
1435
1548
        GtkTreeModel *model;
1436
1549
        GtkTreeIter   iter;
1437
1550
        gboolean      toggled;
1438
 
        guint         id;
1439
 
 
 
1551
        guint         id = 0;
 
1552
        
 
1553
        
1440
1554
        if (gtk_tree_selection_get_selected (selection, &model, &iter) == FALSE) {
1441
1555
                g_debug ("Could not get default output from selection");
1442
1556
                return;
1446
1560
                            ID_COLUMN, &id,
1447
1561
                            ACTIVE_COLUMN, &toggled,
1448
1562
                            -1);
 
1563
        
 
1564
        GvcMixerStream *streams;
 
1565
        GvcMixerSink *sink_stream;
 
1566
        
 
1567
        // get a list of sinks on the system
 
1568
        const GSList *sinkList = gvc_mixer_control_get_streams(dialog->priv->mixer_control);
 
1569
        
 
1570
        g_warning("on_output_selection_changed() id = %i", id);
 
1571
        
 
1572
        while (sinkList != NULL)
 
1573
        {
 
1574
          streams = sinkList->data;
 
1575
          g_warning("AllStreams index: %i, CardIndex: %i, Name: %s",
 
1576
                    gvc_mixer_stream_get_index(streams),
 
1577
                    gvc_mixer_stream_get_card_index(streams),
 
1578
                    gvc_mixer_stream_get_name(streams) );
 
1579
          
 
1580
          if ( gvc_mixer_stream_get_index(streams) == 0 &&
 
1581
               gvc_mixer_stream_get_card_index(streams) == 0 )
 
1582
          {
 
1583
            gvc_mixer_control_set_default_sink (dialog->priv->mixer_control, streams);
 
1584
            return;
 
1585
          }
 
1586
          sinkList = sinkList->next;
 
1587
        }
1449
1588
 
 
1589
/*
1450
1590
        toggled ^= 1;
1451
1591
        if (toggled) {
1452
1592
                GvcMixerStream *stream;
1453
 
 
 
1593
                
 
1594
                id = 0;
1454
1595
                g_debug ("Default output selected: %u", id);
1455
1596
                stream = gvc_mixer_control_lookup_stream_id (dialog->priv->mixer_control, id);
1456
1597
                if (stream == NULL) {
1457
 
                        g_warning ("Unable to find stream for id: %u", id);
 
1598
                        g_warning ("onOutputSelectionChanged():Unable to find stream for id: %u", id);
1458
1599
                        return;
1459
1600
                }
1460
1601
 
1461
 
                gvc_mixer_control_set_default_sink (dialog->priv->mixer_control, stream);
 
1602
                
1462
1603
        }
 
1604
*/
1463
1605
}
1464
1606
 
1465
1607
static void
1558
1700
                return;
1559
1701
        }
1560
1702
 
1561
 
        g_debug ("Profile changed to %s for card %s", profile,
1562
 
                 gvc_mixer_card_get_name (card));
 
1703
        g_debug ("Profile changed to %s for card %s", profile, gvc_mixer_card_get_name (card));
1563
1704
 
1564
1705
        gvc_mixer_card_change_profile (card, profile);
1565
1706
}
1613
1754
        GtkTreeIter          iter;
1614
1755
        const GList         *profiles;
1615
1756
        guint                id;
 
1757
        guint                profile_id;
1616
1758
        GvcMixerCard        *card;
1617
1759
        GvcMixerCardProfile *current_profile;
 
1760
        
 
1761
        on_output_selection_changed(selection, dialog);
 
1762
 
 
1763
        return;
1618
1764
 
1619
1765
        g_debug ("Card selection changed");
1620
1766
 
1634
1780
        gtk_tree_model_get (model, &iter,
1635
1781
                            HW_ID_COLUMN, &id,
1636
1782
                            -1);
1637
 
        card = gvc_mixer_control_lookup_card_id (dialog->priv->mixer_control, id);
1638
 
        if (card == NULL) {
1639
 
                g_warning ("Unable to find card for id: %u", id);
1640
 
                return;
1641
 
        }
1642
 
 
1643
 
        current_profile = gvc_mixer_card_get_profile (card);
1644
 
        profiles = gvc_mixer_card_get_profiles (card);
 
1783
        
1645
1784
        dialog->priv->hw_profile_combo = gvc_combo_box_new (_("_Profile:"));
1646
1785
        g_object_set (G_OBJECT (dialog->priv->hw_profile_combo), "button-label", _("_Test Speakers"), NULL);
 
1786
        
1647
1787
        gvc_combo_box_set_profiles (GVC_COMBO_BOX (dialog->priv->hw_profile_combo), profiles);
1648
 
        gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->hw_profile_combo), current_profile->profile);
 
1788
        //gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->hw_profile_combo), current_profile->profile);
1649
1789
 
1650
1790
        gtk_box_pack_start (GTK_BOX (dialog->priv->hw_settings_box),
1651
1791
                            dialog->priv->hw_profile_combo,
1660
1800
                          G_CALLBACK (on_profile_changed), dialog);
1661
1801
        g_signal_connect (G_OBJECT (dialog->priv->hw_profile_combo), "button-clicked",
1662
1802
                          G_CALLBACK (on_test_speakers_clicked), dialog);
 
1803
        
1663
1804
}
1664
1805
 
1665
1806
static void
1809
1950
        self->priv->hw_box = gtk_vbox_new (FALSE, 12);
1810
1951
        gtk_container_set_border_width (GTK_CONTAINER (self->priv->hw_box), 12);
1811
1952
        label = gtk_label_new (_("Hardware"));
 
1953
        /*
1812
1954
        gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
1813
1955
                                  self->priv->hw_box,
1814
1956
                                  label);
 
1957
        */
1815
1958
 
1816
1959
        box = gtk_frame_new (_("C_hoose a device to configure:"));
1817
1960
        label = gtk_frame_get_label_widget (GTK_FRAME (box));
1847
1990
        gtk_frame_set_shadow_type (GTK_FRAME (box), GTK_SHADOW_NONE);
1848
1991
        gtk_box_pack_start (GTK_BOX (self->priv->hw_box), box, FALSE, TRUE, 12);
1849
1992
        self->priv->hw_settings_box = gtk_vbox_new (FALSE, 12);
1850
 
        gtk_container_add (GTK_CONTAINER (box), self->priv->hw_settings_box);
 
1993
        //gtk_container_add (GTK_CONTAINER (box), self->priv->hw_settings_box);
1851
1994
 
1852
1995
        /* Input page */
1853
1996
        self->priv->input_box = gtk_vbox_new (FALSE, 12);
1954
2097
        self->priv->output_treeview = create_stream_treeview (self,
1955
2098
                                                              G_CALLBACK (on_output_selection_changed));
1956
2099
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), self->priv->output_treeview);
 
2100
        
 
2101
        self->priv->hw_treeview = create_cards_treeview (self,
 
2102
                                                 G_CALLBACK (on_card_selection_changed));
1957
2103
 
1958
2104
        box = gtk_scrolled_window_new (NULL, NULL);
1959
2105
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (box),
1961
2107
                                        GTK_POLICY_AUTOMATIC);
1962
2108
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (box),
1963
2109
                                             GTK_SHADOW_IN);
1964
 
        gtk_container_add (GTK_CONTAINER (box), self->priv->output_treeview);
 
2110
        gtk_container_add (GTK_CONTAINER (box), self->priv->hw_treeview);
 
2111
        gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (box), 150);
 
2112
        
1965
2113
        gtk_container_add (GTK_CONTAINER (alignment), box);
1966
2114
 
1967
2115
        box = gtk_frame_new (_("Settings for the selected device:"));
1971
2119
        gtk_box_pack_start (GTK_BOX (self->priv->output_box), box, FALSE, FALSE, 12);
1972
2120
        self->priv->output_settings_box = gtk_vbox_new (FALSE, 0);
1973
2121
        gtk_container_add (GTK_CONTAINER (box), self->priv->output_settings_box);
 
2122
        
 
2123
        // for storing uniqueProfileIndex -> cardIndex & profileIndex, init static hash
 
2124
        unique_profile_index_to_card_index    = g_hash_table_new(g_direct_hash, g_direct_equal);
 
2125
        unique_profile_index_to_profile_index = g_hash_table_new(g_direct_hash, g_direct_equal);
1974
2126
 
1975
2127
        /* Applications */
1976
2128
        self->priv->applications_box = gtk_vbox_new (FALSE, 12);