ui: don't lose the interface setting
authorAndreas Henriksson <andreas@fatal.se>
Sat, 18 May 2013 11:10:52 +0000 (13:10 +0200)
committerJens Georg <jensg@openismus.com>
Tue, 28 May 2013 07:58:16 +0000 (09:58 +0200)
Just opening and closing rygel-preferences would result in
the interface setting getting set to blank in the configuration.
Fixing the TODO item in the source to set the active interface
(last added item) was all that was needed.

https://bugzilla.gnome.org/show_bug.cgi?id=700570

src/ui/rygel-network-pref-section.vala

index d0b440a..0c4d8d5 100644 (file)
@@ -42,9 +42,11 @@ public class Rygel.NetworkPrefSection : PreferencesSection {
         try {
             var interfaces = config.get_interfaces ();
             if (interfaces != null) {
+                int num_items;
+
                 this.iface_entry.append_text (interfaces[0]);
-                // TODO: Set the current interface to be active.
-                this.iface_entry.set_active (0);
+                num_items = this.count_items (this.iface_entry.model);
+                this.iface_entry.set_active (num_items - 1);
             }
         } catch (GLib.Error err) {
             // No problem if we fail to read the config, the default values
@@ -106,4 +108,17 @@ public class Rygel.NetworkPrefSection : PreferencesSection {
 
         return more;
     }
+
+    private int count_items (TreeModel model) {
+        TreeIter iter;
+        int count = 0;
+        var more = model.get_iter_first (out iter);
+
+        while (more) {
+            count++;
+            more = model.iter_next (ref iter);
+        }
+
+        return count;
+    }
 }