~cjcurran/+junk/soundnua-gtk-warnings

« back to all changes in this revision

Viewing changes to soundnua/gvc-mixer-ui-device.c

  • Committer: Conor Curran
  • Date: 2012-04-26 06:52:48 UTC
  • Revision ID: conor.curran@canonical.com-20120426065248-90249j6dmopyh8hz
add some notes

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
                case PROP_DESC_LINE_1:
123
123
                        g_free (self->priv->first_line_desc);
124
124
                        self->priv->first_line_desc = g_value_dup_string (value);
125
 
                        /*g_debug ("gvc-mixer-output-set-property - 1st line: %s\n",
126
 
                                 self->priv->first_line_desc);*/
 
125
                        g_debug ("gvc-mixer-output-set-property - 1st line: %s\n",
 
126
                                 self->priv->first_line_desc);
127
127
                        break;
128
128
                case PROP_DESC_LINE_2:
129
129
                        g_free (self->priv->second_line_desc);
130
130
                        self->priv->second_line_desc = g_value_dup_string (value);
131
 
                        /*g_debug ("gvc-mixer-output-set-property - 2nd line: %s\n",
132
 
                                 self->priv->second_line_desc);*/
 
131
                        g_debug ("gvc-mixer-output-set-property - 2nd line: %s\n",
 
132
                                 self->priv->second_line_desc);
133
133
                        break;  
134
134
                case PROP_CARD_ID:
135
135
                        self->priv->card_id = g_value_get_int (value);
136
 
                        /*g_debug ("gvc-mixer-output-set-property - card id: %i\n",
137
 
                                 self->priv->gvc_card_id);*/
 
136
                        g_debug ("gvc-mixer-output-set-property - card id: %i\n",
 
137
                                 self->priv->card_id);
138
138
                        break;  
139
139
                case PROP_PORT_NAME:
140
140
                        g_free (self->priv->port_name);
141
141
                        self->priv->port_name = g_value_dup_string (value);
142
 
                        /*g_debug ("gvc-mixer-output-set-property - card port name: %s\n",
143
 
                                 self->priv->card_port_name);*/
 
142
                        g_debug ("gvc-mixer-output-set-property - card port name: %s\n",
 
143
                                 self->priv->port_name);
144
144
                        break;  
145
145
                case PROP_STREAM_ID:
146
146
                        self->priv->stream_id = g_value_get_int (value);
147
 
                        /*g_debug ("gvc-mixer-output-set-property - sink id: %i\n",
148
 
                                 self->priv->stream_id);*/
 
147
                        g_debug ("gvc-mixer-output-set-property - sink id: %i\n",
 
148
                                 self->priv->stream_id);
149
149
                        break;  
150
150
                case PROP_UI_DEVICE_TYPE:
151
151
                        self->priv->type = (UiDeviceDirection)g_value_get_uint (value);
152
152
                        break;
153
153
                case PROP_PORT_AVAILABLE:
154
154
                        self->priv->port_available = g_value_get_boolean (value);
155
 
                        /*g_debug ("gvc-mixer-output-set-property - port available %i, value passed in %i \n",
156
 
                                 self->priv->port_available, g_value_get_boolean (value));*/
 
155
                        g_debug ("gvc-mixer-output-set-property - port available %i, value passed in %i \n",
 
156
                                 self->priv->port_available, g_value_get_boolean (value));
157
157
                        break;                  
158
158
                default:
159
159
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
315
315
        g_type_class_add_private (klass, sizeof (GvcMixerUIDevicePrivate));                                                                     
316
316
}
317
317
 
318
 
// TODO
319
 
// Optimise so as on the first pass you can 'choose' which profiles to hold on to and
320
 
// which are useles because they are essentially duplicates.
321
 
// => a Breadthfirst approach is needed ...
 
318
/*
 
319
 gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device, const GList *in_profiles)
 
320
 
 
321
 This method attempts to reduce the list of profiles visible to the user by figuring out 
 
322
 from the context of that device (whether it's an input or an output) what profiles actually provide an alternative.
 
323
 
 
324
 It does this by the following.
 
325
  - It ignores off profiles.
 
326
  - Sorts the incoming profiles by attempting to split each profile on the char '+'.
 
327
     -- This will pull out the relevant aspect of the profile for the type of device this is.
 
328
        e.g stereo analog out, bluetooth or HDMI for an output, stereo analog in or bluetooth for the input coming from  
 
329
        a typical setup of a onboard HDA intel card and bluetooth headset.
 
330
     -- Will store this shortened string against the profile full length name.
 
331
 
 
332
  - Next it tries to determine from our prepared hash above if we want to allow the user to change
 
333
    the profile on the device i.e.  if the profile combo should be visible to the user on the UI.
 
334
    -- Is there any actual choice or just much of the same thing from the 
 
335
       context of the direction on this device.
 
336
  -If there is a choice
 
337
    -- It will gather the groups of identical profiles and choose the one that has the highest priority to insert
 
338
       into the final list to be presented to the user.
 
339
    - if the shortened profiles are identical so that the profile combo is to be hidden from the user
 
340
     -- It will choose the profile with the highest priority. (the pattern assumes a device will always have a profile in it's profile list)
 
341
Note: 
 
342
 I think this algorithm is inherently flawed.
 
343
 https://bugs.launchpad.net/ubuntu/+source/gnome-control-center/+bug/972554
 
344
 An issue arises in this bug whereby the user needs to get at a specific profile which allows him a certain input and output
 
345
 configuration. But this algorithem because of priority values etc will reject that one profile that he needs to get at. 
 
346
TODO
 
347
 Optimise so as on the first pass you can 'choose' which profiles to hold on to and
 
348
 which are useles because they are essentially duplicates.
 
349
 => a depthfirst like approach is needed ...
 
350
*/
322
351
void
323
352
gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device, const GList *in_profiles)
324
353
{
325
354
        g_debug ("\n SET PROFILES %s", gvc_mixer_ui_device_get_description(device));
326
355
                
327
 
        gint profile_count;
328
356
        GList* t;
329
 
 
330
357
        GHashTable *profile_descriptions;
 
358
        
331
359
        if (in_profiles == NULL)
332
360
                return;
333
361
        
334
362
        device->priv->supported_profiles = g_list_copy (in_profiles);
335
 
        
336
 
        // Is this being used ? TODO    
337
 
        profile_count = g_list_length (in_profiles);
338
 
 
339
363
        profile_descriptions = g_hash_table_new_full (g_str_hash,
340
364
                                                      g_str_equal,
341
365
                                                      g_free,
342
366
                                                      g_free);
343
367
 
344
 
 
345
368
        // Store each profile in a hash with the shortened relevant string as the key
346
369
        for (t = in_profiles; t != NULL; t = t->next) {
347
370
 
442
465
 
443
466
                        g_debug ("\n Not identical - examine  %s -> %s \n\n", short_name, p->profile);
444
467
                        
445
 
                        // If we have already populated for this short name - trust our prioritisation below and move on.
 
468
                        // If we have already populated for this short name - trust?? our prioritisation below and move on
446
469
                        if (g_hash_table_contains (device->priv->profiles, short_name) == TRUE){
447
470
                                g_debug ("\n already populated for %s => ignore %s \n", short_name, p->profile);
448
471
                                continue;
469
492
                                                                                                 l);    
470
493
                                }
471
494
                        }
472
 
                                                        
 
495
                        // Algorithm flaw                               
473
496
                        GList* ordered = NULL;
474
497
                        ordered = g_list_sort (profiles_with_identical_shortened_names,
475
498
                                               (GCompareFunc) sort_profiles);   
486
509
                }
487
510
        }
488
511
        else{
489
 
                // If it's identical (=> combo is insensitive) we want to find the profile that is
490
 
                // relevant to the context of the device for the sake of the UI - avoid user confusion.
491
 
                GList* profile_descriptions_keys;
492
 
                profile_descriptions_keys = g_hash_table_get_keys (profile_descriptions);
493
 
                GList* c;
494
 
                gboolean matched = FALSE;
495
 
                for (c = profile_descriptions_keys; c != NULL; c = c->next) {
496
 
                        gchar* prof;
497
 
                        prof = c->data;
498
 
                        gchar* shortened_value;
499
 
                        shortened_value = g_hash_table_lookup (profile_descriptions, prof);
500
 
                        if (g_strcmp0 (shortened_value, prof) == 0){
501
 
                                GList *j;
502
 
                                for (j = in_profiles; j != NULL; j = j->next) {
503
 
                                        GvcMixerCardProfile* l;
504
 
                                        l = j->data;
505
 
                                        if (g_strcmp0 (l->profile, prof) == 0){
506
 
                                                g_hash_table_insert (device->priv->profiles, 
507
 
                                                                     g_strdup(shortened_value),
508
 
                                                                     l);
509
 
                                                
510
 
                                                matched = TRUE;
511
 
                                        }
512
 
                                }
513
 
                        }               
514
 
                }
515
 
                // We can't find the ideal profile for the insensitive combo
516
 
                // just pick the one with the highest priority.
517
 
                if (!matched){  
518
 
                        GvcMixerCardProfile* p = NULL;
519
 
                        // Since the profile list was already sorted on card port creation
520
 
                        // we just need to take the last one as this will have the highest priority
521
 
                        p = g_list_last (in_profiles)->data;
522
 
                        if (p != NULL && p->human_profile != NULL)
523
 
                                g_debug ("\n fail to match on profile %s \n", p->human_profile);
524
 
                                g_hash_table_insert (device->priv->profiles, 
525
 
                                                     p->human_profile,
526
 
                                                     p);                
527
 
                }
 
512
                // Since the profile list was already sorted on card port creation
 
513
                // we just need to take the last one as this will have the highest priority
 
514
                GvcMixerCardProfile* p = NULL;
 
515
                p = g_list_last (in_profiles)->data;
 
516
                if (p != NULL && p->human_profile != NULL)
 
517
                        g_hash_table_insert (device->priv->profiles, 
 
518
                                             p->human_profile,
 
519
                                             p);                
528
520
        }
529
521
        /* DEBUG */
530
 
        GList* final_keys;
 
522
        /*GList* final_keys;
531
523
        final_keys = g_hash_table_get_keys (device->priv->profiles);
532
524
        GList* o;
533
525
        g_debug ("\n\n Profile population \n FOR DEVICE %s", gvc_mixer_ui_device_get_description (device));
539
531
                g_debug ("\n key %s against \n profile %s \n", 
540
532
                        key,
541
533
                        l->profile);
542
 
        }
 
534
        }*/
543
535
        g_hash_table_destroy (profile_descriptions);
544
536
}
545
537