[PATCH 7/14]: wpa_gui-qt4: connect Enabled/Disabled radio buttons to signal/slot pairs

Kel Modderman kel at otaku42.de
Tue Jan 29 02:15:38 EST 2008


Connect the Enabled/Disabled radio button group up to signal/slot pairs.
Also connect to network listbox changed item selection signal to collectively
provide interface to display and toggle "disabled" configuration item for
network currently selected in the listbox.

Add enableNetwork(), disableNetwork() and getNetworkDisabled() public
functions and updateNetworkDisabledStatus(), enableListedNetwork() and
disableListedNetwork() public slot functions.

When item selection is changed the enabled/disabled radio buttons are updated
to reflect the selected networks "disabled" configuration value. This happens
when user selects item or when updateNetworks() is triggered (which causes a
new selection event after rebuilding network list).

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
@@ -62,6 +62,12 @@
 		SLOT(editListedNetwork()));
 	connect(removeNetworkButton, SIGNAL(clicked()), this,
 		SLOT(removeListedNetwork()));
+	connect(networkList, SIGNAL(itemSelectionChanged()), this,
+		SLOT(updateNetworkDisabledStatus()));
+	connect(enableRadioButton, SIGNAL(toggled(bool)), this,
+		SLOT(enableListedNetwork(bool)));
+	connect(disableRadioButton, SIGNAL(toggled(bool)), this,
+		SLOT(disableListedNetwork(bool)));
 
 	eh = NULL;
 	scanres = NULL;
@@ -749,6 +755,40 @@
 }
 
 
+void WpaGui::enableNetwork(const QString &sel)
+{
+	QString cmd(sel);
+	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(const QString &sel)
+{
+	QString cmd(sel);
+	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::editNetwork(const QString &sel)
 {
 	QString cmd(sel);
@@ -867,6 +907,76 @@
 }
 
 
+int WpaGui::getNetworkDisabled(const QString &sel)
+{
+	QString cmd(sel);
+	char reply[10];
+	size_t reply_len = sizeof(reply) - 1;
+	int pos = cmd.indexOf(':');
+	if (pos < 0) {
+		printf("Invalid getNetworkDisabled '%s'\n",
+		       cmd.toAscii().constData());
+		return -1;
+	}
+	cmd.truncate(pos);
+	cmd.prepend("GET_NETWORK ");
+	cmd.append(" disabled");
+
+	if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) >= 0
+	    && reply_len >= 1) {
+		reply[reply_len] = '\0';
+		if (!str_match(reply, "FAIL"))
+			return atoi(reply);
+	}
+
+	return -1;
+}
+
+
+void WpaGui::updateNetworkDisabledStatus()
+{
+	if (networkList->currentRow() < 0)
+		return;
+
+	QString sel(networkList->currentItem()->text());
+
+	switch (getNetworkDisabled(sel)) {
+	case 0:
+		if (!enableRadioButton->isChecked())
+			enableRadioButton->setChecked(true);
+		return;
+	case 1:
+		if (!disableRadioButton->isChecked())
+			disableRadioButton->setChecked(true);
+		return;
+	}
+}
+
+
+void WpaGui::enableListedNetwork(bool enabled)
+{
+	if (networkList->currentRow() < 0 || !enabled)
+		return;
+
+	QString sel(networkList->currentItem()->text());
+
+	if (getNetworkDisabled(sel) == 1)
+		enableNetwork(sel);
+}
+
+
+void WpaGui::disableListedNetwork(bool disabled)
+{
+	if (networkList->currentRow() < 0 || !disabled)
+		return;
+
+	QString sel(networkList->currentItem()->text());
+
+	if (getNetworkDisabled(sel) == 0)
+		disableNetwork(sel);
+}
+
+
 void WpaGui::saveConfig()
 {
 	char buf[10];
--- a/wpa_supplicant/wpa_gui-qt4/wpagui.h
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.h
@@ -34,6 +34,9 @@
 	virtual void triggerUpdate();
 	virtual void editNetwork(const QString &sel);
 	virtual void removeNetwork(const QString &sel);
+	virtual void enableNetwork(const QString &sel);
+	virtual void disableNetwork(const QString &sel);
+	virtual int getNetworkDisabled(const QString &sel);
 
 public slots:
 	virtual void parse_argv();
@@ -59,6 +62,9 @@
 	virtual void disableAllNetworks();
 	virtual void saveConfig();
 	virtual void selectAdapter(const QString &sel);
+	virtual void updateNetworkDisabledStatus();
+	virtual void enableListedNetwork(bool);
+	virtual void disableListedNetwork(bool);
 
 protected slots:
 	virtual void languageChange();
---


More information about the HostAP mailing list