[PATCH 3/3]: wpa_gui-qt4: wpagui backend changes to adapt to new form layout

Kel Modderman kel at otaku42.de
Thu Jan 24 11:32:45 EST 2008


This patch is an accumulative changeset to adapt to the form layout
and widget changes introduced in the previous patch. While doing so, also
reordered the signal/slot declarations for sanity, fixed misspelling of adaptor
(was adapter) and renames connectB() to reassociate().

"Select any network" is no longer appended to network list, so the
selectNetwork() and editNetwork() functions no longer need to handle that.

There is a possible opportunity to merge enableNetwork(), disableNetwork()
and removeNetwork() functions into one to reduce code duplication.

Any comments/criticism welcome on what could be done better or different.

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
@@ -33,29 +33,42 @@
 
 	(void) statusBar();
 
+	/* File menu */
+	connect(fileEventHistoryAction, SIGNAL(triggered()), this,
+		SLOT(eventHistory()));
+	connect(fileSaveConfig, SIGNAL(triggered()), this, SLOT(saveConfig()));
+	connect(fileExitAction, SIGNAL(triggered()), this, SLOT(close()));
+	/* Networks menu */
+	connect(networksEnableAllAction, SIGNAL(triggered()), this,
+		SLOT(enableAllNetworks()));
+	connect(networksDisableAllAction, SIGNAL(triggered()), this,
+		SLOT(disableAllNetworks()));
+	connect(networksRemoveAllAction, SIGNAL(triggered()), this,
+		SLOT(removeAllNetworks()));
+	/* Help menu */
 	connect(helpIndexAction, SIGNAL(triggered()), this, SLOT(helpIndex()));
 	connect(helpContentsAction, SIGNAL(triggered()), this,
 		SLOT(helpContents()));
 	connect(helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()));
-	connect(fileExitAction, SIGNAL(triggered()), this, SLOT(close()));
-	connect(disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));
-	connect(scanButton, SIGNAL(clicked()), this, SLOT(scan()));
-	connect(connectButton, SIGNAL(clicked()), this, SLOT(connectB()));
-	connect(fileEventHistoryAction, SIGNAL(triggered()), this,
-		SLOT(eventHistory()));
-	connect(networkSelect, SIGNAL(activated(const QString&)), this,
-		SLOT(selectNetwork(const QString&)));
-	connect(fileEdit_networkAction, SIGNAL(triggered()), this,
+	/* Main User Interface */
+	connect(adaptorSelect, SIGNAL(activated(const QString&)), this,
+		SLOT(selectAdaptor(const QString&)));
+	connect(networkList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
+		this, SLOT(selectNetwork(QListWidgetItem *)));
+	connect(editNetworkButton, SIGNAL(clicked()), this,
 		SLOT(editNetwork()));
-	connect(fileAdd_NetworkAction, SIGNAL(triggered()), this,
-		SLOT(addNetwork()));
-	connect(fileEnableALLNetworksAction, SIGNAL(triggered()), this,
-		SLOT(enableAllNetworks()));
-	connect(fileDisableALLNetworksAction, SIGNAL(triggered()), this,
-		SLOT(disableAllNetworks()));
-	connect(fileSaveConfig, SIGNAL(triggered()), this, SLOT(saveConfig()));
-	connect(adapterSelect, SIGNAL(activated(const QString&)), this,
-		SLOT(selectAdapter(const QString&)));
+	connect(addNetworkButton, SIGNAL(clicked()), this, SLOT(addNetwork()));
+	connect(removeNetworkButton, SIGNAL(clicked()), this,
+		SLOT(removeNetwork()));
+	connect(enableNetworkButton, SIGNAL(clicked()), this,
+		SLOT(enableNetwork()));
+	connect(disableNetworkButton, SIGNAL(clicked()), this,
+		SLOT(disableNetwork()));
+	connect(selectAnyNetworkButton, SIGNAL(clicked()), this,
+		SLOT(selectAnyNetwork()));
+	connect(scanButton, SIGNAL(clicked()), this, SLOT(scan()));
+	connect(connectButton, SIGNAL(clicked()), this, SLOT(reassociate()));
+	connect(disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));
 
 	eh = NULL;
 	scanres = NULL;
@@ -278,9 +291,9 @@
 	connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
 #endif
 
-	adapterSelect->clear();
-	adapterSelect->addItem(ctrl_iface);
-	adapterSelect->setCurrentIndex(0);
+	adaptorSelect->clear();
+	adaptorSelect->addItem(ctrl_iface);
+	adaptorSelect->setCurrentIndex(0);
 
 	len = sizeof(buf) - 1;
 	if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
@@ -292,7 +305,7 @@
 			if (pos2)
 				*pos2 = '\0';
 			if (strcmp(pos, ctrl_iface) != 0)
-				adapterSelect->addItem(pos);
+				adaptorSelect->addItem(pos);
 			if (pos2)
 				pos = pos2 + 1;
 			else
@@ -438,7 +451,7 @@
 	if (!networkMayHaveChanged)
 		return;
 
-	networkSelect->clear();
+	networkList->clear();
 
 	if (ctrl_conn == NULL)
 		return;
@@ -481,26 +494,22 @@
 		QString network(id);
 		network.append(": ");
 		network.append(ssid);
-		networkSelect->addItem(network);
+		networkList->addItem(network);
 
 		if (strstr(flags, "[CURRENT]")) {
-			networkSelect->setCurrentIndex(networkSelect->count() -
-						      1);
+			networkList->setCurrentRow(networkList->count() - 1);
 			selected = true;
 		} else if (first_active < 0 &&
 			   strstr(flags, "[DISABLED]") == NULL)
-			first_active = networkSelect->count() - 1;
+			first_active = networkList->count() - 1;
 
 		if (last)
 			break;
 		start = end + 1;
 	}
 
-	if (networkSelect->count() > 1)
-		networkSelect->addItem("Select any network");
-
 	if (!selected && first_active >= 0)
-		networkSelect->setCurrentIndex(first_active);
+		networkList->setCurrentRow(first_active);
 
 	networkMayHaveChanged = false;
 }
@@ -711,7 +720,7 @@
 }
 
 
-void WpaGui::connectB()
+void WpaGui::reassociate()
 {
 	char reply[10];
 	size_t reply_len = sizeof(reply);
@@ -719,23 +728,19 @@
 }
 
 
-void WpaGui::selectNetwork( const QString &sel )
+void WpaGui::selectNetwork(QListWidgetItem *sel)
 {
-	QString cmd(sel);
+	QString cmd(sel->text());
 	char reply[10];
 	size_t reply_len = sizeof(reply);
 
-	if (cmd.startsWith("Select any")) {
-		cmd = "any";
-	} else {
-		int pos = cmd.indexOf(':');
-		if (pos < 0) {
-			printf("Invalid selectNetwork '%s'\n",
-			       cmd.toAscii().constData());
-			return;
-		}
-		cmd.truncate(pos);
+	int pos = cmd.indexOf(':');
+	if (pos < 0) {
+		printf("Invalid selectNetwork '%s'\n",
+		       cmd.toAscii().constData());
+		return;
 	}
+	cmd.truncate(pos);
 	cmd.prepend("SELECT_NETWORK ");
 	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
 }
@@ -743,13 +748,13 @@
 
 void WpaGui::editNetwork()
 {
-	QString sel(networkSelect->currentText());
 	int id = -1;
 
-	if (!sel.startsWith("Select any")) {
+	if (networkList->count() > 0) {
+		QString sel(networkList->currentItem()->text());
 		int pos = sel.indexOf(':');
 		if (pos < 0) {
-			printf("Invalid selectNetwork '%s'\n",
+			printf("Invalid editNetwork '%s'\n",
 			       sel.toAscii().constData());
 			return;
 		}
@@ -792,6 +797,58 @@
 }
 
 
+void WpaGui::enableNetwork()
+{
+	QString cmd(networkList->currentItem()->text());
+	char reply[10];
+	size_t reply_len = sizeof(reply);
+	int pos = cmd.indexOf(':');
+	if (pos < 0) {
+		printf("Invalid enableNetwork '%s'\n",
+		       cmd.toAscii().constData());
+		return;
+	}
+	cmd.truncate(pos);
+	cmd.prepend("ENABLE_NETWORK ");
+	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+}
+
+void WpaGui::disableNetwork()
+{
+	QString cmd(networkList->currentItem()->text());
+	char reply[10];
+	size_t reply_len = sizeof(reply);
+	int pos = cmd.indexOf(':');
+	if (pos < 0) {
+		printf("Invalid disableNetwork '%s'\n",
+		       cmd.toAscii().constData());
+		return;
+	}
+	cmd.truncate(pos);
+	cmd.prepend("DISABLE_NETWORK ");
+	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+}
+
+
+void WpaGui::removeNetwork()
+{
+	QString cmd(networkList->currentItem()->text());
+	char reply[10];
+	size_t reply_len = sizeof(reply);
+	int pos = cmd.indexOf(':');
+	if (pos < 0) {
+		printf("Invalid removeNetwork '%s'\n",
+		       cmd.toAscii().constData());
+		return;
+	}
+	cmd.truncate(pos);
+	cmd.prepend("REMOVE_NETWORK ");
+	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+	networkList->removeItemWidget(networkList->currentItem());
+	triggerUpdate();
+}
+
+
 void WpaGui::enableAllNetworks()
 {
 	char reply[10];
@@ -808,6 +865,24 @@
 }
 
 
+void WpaGui::removeAllNetworks()
+{
+	char reply[10];
+	size_t reply_len = sizeof(reply);
+	ctrlRequest("REMOVE_NETWORK all", reply, &reply_len);
+	networkList->clear();
+	triggerUpdate();
+}
+
+
+void WpaGui::selectAnyNetwork()
+{
+	char reply[10];
+	size_t reply_len = sizeof(reply);
+	ctrlRequest("SELECT_NETWORK any", reply, &reply_len);
+}
+
+
 void WpaGui::saveConfig()
 {
 	char buf[10];
@@ -832,7 +907,7 @@
 }
 
 
-void WpaGui::selectAdapter( const QString & sel )
+void WpaGui::selectAdaptor(const QString &sel)
 {
 	if (openCtrlConnection(sel.toAscii().constData()) < 0)
 		printf("Failed to open control connection to "
--- a/wpa_supplicant/wpa_gui-qt4/wpagui.h
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.h
@@ -40,6 +40,7 @@
 	virtual void helpIndex();
 	virtual void helpContents();
 	virtual void helpAbout();
+	virtual void reassociate();
 	virtual void disconnect();
 	virtual void scan();
 	virtual void eventHistory();
@@ -47,14 +48,18 @@
 	virtual void processMsg(char *msg);
 	virtual void processCtrlReq(const char *req);
 	virtual void receiveMsgs();
-	virtual void connectB();
-	virtual void selectNetwork(const QString &sel);
+	virtual void selectNetwork(QListWidgetItem *sel);
 	virtual void editNetwork();
 	virtual void addNetwork();
+	virtual void enableNetwork();
+	virtual void disableNetwork();
+	virtual void removeNetwork();
 	virtual void enableAllNetworks();
 	virtual void disableAllNetworks();
+	virtual void removeAllNetworks();
+	virtual void selectAnyNetwork();
 	virtual void saveConfig();
-	virtual void selectAdapter(const QString &sel);
+	virtual void selectAdaptor(const QString &sel);
 
 protected slots:
 	virtual void languageChange();
---


More information about the HostAP mailing list