319
319
// Optimise so as on the first pass you can 'choose' which profiles to hold on to and
320
320
// which are useles because they are essentially duplicates.
321
// => a Breadthfirst approach is needed ...
322
323
gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device, const GList *in_profiles)
325
g_print ("\n SET PROFILES %s", gvc_mixer_ui_device_get_description(device));
324
327
gint profile_count;
326
329
GHashTable *profile_descriptions;
327
330
if (in_profiles == NULL)
331
333
device->priv->supported_profiles = in_profiles;
333
335
profile_count = g_list_length (in_profiles);
340
gboolean is_input = device->priv->type != UiDeviceOutput;
341
gboolean is_output = device->priv->type == UiDeviceOutput;
343
341
// Store each profile in a hash with the shortened relevant string as the key
344
342
for (t = in_profiles; t != NULL; t = t->next) {
346
344
GvcMixerCardProfile* p;
350
//g_print ("\n check if this %s has already passed %i", p->profile, g_hash_table_contains (profile_descriptions, p->profile));
352
347
gchar** modified;
354
349
modified = g_strsplit (p->profile, "+", 0);
357
352
count = g_strv_length (modified);
353
// It's a profile that only handles one direction, cache it and move on
360
355
/*g_print ("\n Single profile, %i, key %s against value %s for device %s \n",
423
418
if (!identical) {
424
419
for (y = in_profiles; y != NULL; y = y->next) {
420
GList *profiles_with_identical_shortened_names = NULL;
425
421
GvcMixerCardProfile* p;
427
423
gchar* short_name;
428
424
short_name = g_hash_table_lookup (profile_descriptions, p->profile);
430
g_print ("\n\n has this profile passed already- %s , %s \n\n", short_name, p->profile);
426
g_print ("\n Not identical - examine %s -> %s \n\n", short_name, p->profile);
429
if (g_strcmp0 (p->profile, "off") == 0){
430
g_print ("\n Bluetooth off profile - ignore it \n");
434
// If we have already populated for this short name - trust our prioritisation below and move on.
435
if (g_hash_table_contains (device->priv->profiles, short_name) == TRUE){
436
g_print ("\n already populated for %s => ignore %s \n", short_name, p->profile);
440
profiles_with_identical_shortened_names = g_list_append (profiles_with_identical_shortened_names, p);
432
442
for (x = in_profiles; x != NULL; x = x->next) {
433
443
GvcMixerCardProfile* l;
435
445
gchar* other_modified;
437
if (g_strcmp0 (p->profile, "off") == 0){
438
g_print ("\n\n Bluetooth off profile - ignore it");
447
// no point in comparing it against itself now.
448
if (g_strcmp0 (p->profile, l->profile) == 0)
442
if (g_hash_table_contains (device->priv->profiles, short_name) == TRUE){
443
g_print ("\n\n SHORT NAME already populated move on - %s \n\n", p->profile);
447
451
other_modified = g_hash_table_lookup (profile_descriptions, l->profile);
449
453
if (g_strcmp0 (other_modified, short_name) == 0){
450
if (sort_profiles (p, l) > 0){
451
g_hash_table_insert (device->priv->profiles, short_name, p);
452
g_print ("\n Sensitive comb - Populate the profile combo with %s", p->profile);
455
g_hash_table_insert (device->priv->profiles, short_name, l);
456
g_print ("\n Sensitive comb - Populate the profile combo with %s", p->profile);
460
g_print ("failed to match %s with %s", other_modified, short_name);
454
profiles_with_identical_shortened_names = g_list_append (profiles_with_identical_shortened_names,
459
// EDGE case noticed with bluetooth.
460
if (g_list_length (profiles_with_identical_shortened_names) < 2){
461
g_hash_table_insert (device->priv->profiles,
462
g_strdup(short_name),
464
g_list_free (profiles_with_identical_shortened_names);
465
device->priv->disable_profile_swapping = TRUE;
469
GList* ordered = NULL;
470
ordered = g_list_sort (profiles_with_identical_shortened_names,
471
(GCompareFunc) sort_profiles);
473
GvcMixerCardProfile* priority_profile = g_list_last(ordered)->data;
475
g_print ("\n Sensitive combo - Populate the profile combo with profile %s against short name %s",
476
priority_profile->profile, short_name);
478
g_hash_table_insert (device->priv->profiles,
479
g_strdup(short_name),
481
g_list_free (profiles_with_identical_shortened_names);
466
// If it's identical we want to find the profile that is relevant to the context of the device
467
// For the sake of the UI - avoid user confusion.
485
// If it's identical (=> combo is insensitive) we want to find the profile that is
486
// relevant to the context of the device for the sake of the UI - avoid user confusion.
468
487
GList* profile_descriptions_keys;
469
488
profile_descriptions_keys = g_hash_table_get_keys (profile_descriptions);