[PATCH 13/14]: wpa_gui-qt4: consistent network index selection during update of network list

Kel Modderman kel
Mon Jan 28 23:23:11 PST 2008


When triggerUpdate() causes the network lists to be updated, store the
index of the of the currently selected network listbox item and reselect
that row/index post-update if it still exists. If the pre-selected index no
longer exists, select the last item in the list. This gives the widget a more
consistent behaviour when removing networks too.

When no network has been preselected, select the same network that
is currently shown in the network combobox.

Rename the "selected" boolean to "current".

Signed-off-by: Kel Modderman <kel at otaku42.de>
---
--- a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
@@ -452,11 +452,15 @@
 	char buf[2048], *start, *end, *id, *ssid, *bssid, *flags;
 	size_t len;
 	int first_active = -1;
-	bool selected = false;
+	int was_selected = -1;
+	bool current = false;
 
 	if (!networkMayHaveChanged)
 		return;
 
+	if (networkList->currentRow() >= 0)
+		was_selected = networkList->currentRow();
+
 	networkSelect->clear();
 	networkList->clear();
 
@@ -507,7 +511,7 @@
 		if (strstr(flags, "[CURRENT]")) {
 			networkSelect->setCurrentIndex(networkSelect->count() -
 						      1);
-			selected = true;
+			current = true;
 		} else if (first_active < 0 &&
 			   strstr(flags, "[DISABLED]") == NULL)
 			first_active = networkSelect->count() - 1;
@@ -520,9 +524,18 @@
 	if (networkSelect->count() > 1)
 		networkSelect->addItem("Select any network");
 
-	if (!selected && first_active >= 0)
+	if (!current && first_active >= 0)
 		networkSelect->setCurrentIndex(first_active);
 
+	if (was_selected >= 0 && networkList->count() > 0) {
+		if (was_selected < networkList->count())
+			networkList->setCurrentRow(was_selected);
+		else
+			networkList->setCurrentRow(networkList->count() - 1);
+	}
+	else
+		networkList->setCurrentRow(networkSelect->currentIndex());
+
 	networkMayHaveChanged = false;
 }
 
---



More information about the Hostap mailing list