From 29dc790c690117771429bc3b1e585fa6f45310a9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 20 Feb 2010 02:59:35 +0100 Subject: be a little smarter when selecting the initial device to show --- gnome-speaker-setup.vala | 58 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/gnome-speaker-setup.vala b/gnome-speaker-setup.vala index fea5eeb..d00dc1c 100644 --- a/gnome-speaker-setup.vala +++ b/gnome-speaker-setup.vala @@ -522,21 +522,12 @@ public class SpeakerSetupWindow : Window { bool select_card(uint32 index) { TreeIter iter; - if (!cards.get_iter_first(out iter)) - return false; - - do { - uint32 j; - cards.get(iter, 1, out j); - if (j == index) { - card_combo_box.set_active_iter(iter); - return true; - } - - } while (cards.iter_next(ref iter)); + if (!find_card_iter(index, out iter)) + return false; - return false; + card_combo_box.set_active_iter(iter); + return true; } bool select_device(uint32 index) { @@ -559,21 +550,12 @@ public class SpeakerSetupWindow : Window { } TreeIter iter; - if (!devices->get_iter_first(out iter)) - return false; - - do { - uint32 j; - devices->get(iter, 1, out j); - - if (j == index) { - device_combo_box.set_active_iter(iter); - return true; - } - } while (devices->iter_next(ref iter)); + if (!find_device_iter(devices, index, out iter)) + return false; - return false; + device_combo_box.set_active_iter(iter); + return true; } bool pick_initial_selection() { @@ -605,15 +587,27 @@ public class SpeakerSetupWindow : Window { card_combo_box.set_sensitive(!lock_selection); } else { + if (card_combo_box.get_active() >= 0) return true; - TreeIter i; - if (cards.get_iter_first(out i) && - cards.iter_next(ref i)) - card_combo_box.set_active_iter(i); - else - card_combo_box.set_active(0); + /* Select a device if there is one */ + MapIterator diter = device_lookup.map_iterator(); + if (diter.first()) { + DeviceData *d = diter.get_value(); + if (select_device(d->index)) + return true; + } + + /* No device, so let's startup with a card if there is one */ + MapIterator citer = card_lookup.map_iterator(); + if (citer.first()) { + CardData *d = citer.get_value(); + if (select_card(d->index)) + return true; + } + + card_combo_box.set_active(0); } return true; -- cgit