wpa_gui: Port to Qt5

This adds support for Qt5 while still preserving support for building
with Qt4. The same source code builds with both Qt versions now. The
functionality should be identical.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2015-05-08 23:01:01 +02:00 committed by Jouni Malinen
parent e1ede80d3b
commit 8d2ed87d82
17 changed files with 99 additions and 91 deletions

View File

@ -41,8 +41,8 @@ AddInterface::AddInterface(WpaGui *_wpagui, QWidget *parent)
interfaceWidget->headerItem()->setText(0, tr("driver"));
interfaceWidget->headerItem()->setText(1, tr("interface"));
interfaceWidget->headerItem()->setText(2, tr("description"));
interfaceWidget->setItemsExpandable(FALSE);
interfaceWidget->setRootIsDecorated(FALSE);
interfaceWidget->setItemsExpandable(false);
interfaceWidget->setRootIsDecorated(false);
vboxLayout->addWidget(interfaceWidget);
connect(interfaceWidget,
@ -196,9 +196,9 @@ void AddInterface::interfaceSelected(QTreeWidgetItem *sel)
*/
snprintf(cmd, sizeof(cmd),
"INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
sel->text(1).toAscii().constData(),
sel->text(1).toLocal8Bit().constData(),
"default",
sel->text(0).toAscii().constData(),
sel->text(0).toLocal8Bit().constData(),
"yes", "", "");
cmd[sizeof(cmd) - 1] = '\0';

View File

@ -11,9 +11,9 @@
#include <QObject>
#include <QtGui/QDialog>
#include <QtGui/QTreeWidget>
#include <QtGui/QVBoxLayout>
#include <QDialog>
#include <QTreeWidget>
#include <QVBoxLayout>
class WpaGui;

View File

@ -73,15 +73,15 @@ void EventListModel::addEvent(QString time, QString msg)
}
EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WFlags)
EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WindowFlags)
: QDialog(parent)
{
setupUi(this);
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
eventListView->setItemsExpandable(FALSE);
eventListView->setRootIsDecorated(FALSE);
eventListView->setItemsExpandable(false);
eventListView->setRootIsDecorated(false);
elm = new EventListModel(parent);
eventListView->setModel(elm);
}

View File

@ -40,7 +40,7 @@ class EventHistory : public QDialog, public Ui::EventHistory
public:
EventHistory(QWidget *parent = 0, const char *name = 0,
bool modal = false, Qt::WFlags fl = 0);
bool modal = false, Qt::WindowFlags fl = 0);
~EventHistory();
public slots:

View File

@ -14,24 +14,14 @@
#include <QtCore/QTranslator>
#include "wpagui.h"
class WpaGuiApp : public QApplication
{
public:
WpaGuiApp(int &argc, char **argv);
#ifndef QT_NO_SESSIONMANAGER
virtual void saveState(QSessionManager &manager);
#endif
WpaGui *w;
};
WpaGuiApp::WpaGuiApp(int &argc, char **argv) : QApplication(argc, argv)
WpaGuiApp::WpaGuiApp(int &argc, char **argv) :
QApplication(argc, argv),
argc(argc),
argv(argv)
{
}
#ifndef QT_NO_SESSIONMANAGER
#if !defined(QT_NO_SESSIONMANAGER) && QT_VERSION < 0x050000
void WpaGuiApp::saveState(QSessionManager &manager)
{
QApplication::saveState(manager);

View File

@ -26,7 +26,8 @@ enum {
#define WPA_GUI_KEY_DATA "[key is configured]"
NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool, Qt::WFlags)
NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool,
Qt::WindowFlags)
: QDialog(parent)
{
setupUi(this);
@ -237,7 +238,7 @@ void NetworkConfig::addNetwork()
} else
id = edit_network_id;
setNetworkParam(id, "ssid", ssidEdit->text().toAscii().constData(),
setNetworkParam(id, "ssid", ssidEdit->text().toLocal8Bit().constData(),
true);
const char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL;
@ -291,14 +292,14 @@ void NetworkConfig::addNetwork()
setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false);
}
if (pskEdit->isEnabled() &&
strcmp(pskEdit->text().toAscii().constData(),
strcmp(pskEdit->text().toLocal8Bit().constData(),
WPA_GUI_KEY_DATA) != 0)
setNetworkParam(id, "psk",
pskEdit->text().toAscii().constData(),
pskEdit->text().toLocal8Bit().constData(),
psklen != 64);
if (eapSelect->isEnabled()) {
const char *eap =
eapSelect->currentText().toAscii().constData();
eapSelect->currentText().toLocal8Bit().constData();
setNetworkParam(id, "eap", eap, false);
if (strcmp(eap, "SIM") == 0 || strcmp(eap, "AKA") == 0)
setNetworkParam(id, "pcsc", "", true);
@ -314,21 +315,21 @@ void NetworkConfig::addNetwork()
if (inner.startsWith("EAP-"))
snprintf(phase2, sizeof(phase2), "auth=%s",
inner.right(inner.size() - 4).
toAscii().constData());
toLocal8Bit().constData());
} else if (eap.compare("TTLS") == 0) {
if (inner.startsWith("EAP-"))
snprintf(phase2, sizeof(phase2), "autheap=%s",
inner.right(inner.size() - 4).
toAscii().constData());
toLocal8Bit().constData());
else
snprintf(phase2, sizeof(phase2), "auth=%s",
inner.toAscii().constData());
inner.toLocal8Bit().constData());
} else if (eap.compare("FAST") == 0) {
const char *provisioning = NULL;
if (inner.startsWith("EAP-")) {
snprintf(phase2, sizeof(phase2), "auth=%s",
inner.right(inner.size() - 4).
toAscii().constData());
toLocal8Bit().constData());
provisioning = "fast_provisioning=2";
} else if (inner.compare("GTC(auth) + MSCHAPv2(prov)")
== 0) {
@ -354,21 +355,21 @@ void NetworkConfig::addNetwork()
setNetworkParam(id, "phase2", "NULL", false);
if (identityEdit->isEnabled() && identityEdit->text().length() > 0)
setNetworkParam(id, "identity",
identityEdit->text().toAscii().constData(),
identityEdit->text().toLocal8Bit().constData(),
true);
else
setNetworkParam(id, "identity", "NULL", false);
if (passwordEdit->isEnabled() && passwordEdit->text().length() > 0 &&
strcmp(passwordEdit->text().toAscii().constData(),
strcmp(passwordEdit->text().toLocal8Bit().constData(),
WPA_GUI_KEY_DATA) != 0)
setNetworkParam(id, "password",
passwordEdit->text().toAscii().constData(),
passwordEdit->text().toLocal8Bit().constData(),
true);
else if (passwordEdit->text().length() == 0)
setNetworkParam(id, "password", "NULL", false);
if (cacertEdit->isEnabled() && cacertEdit->text().length() > 0)
setNetworkParam(id, "ca_cert",
cacertEdit->text().toAscii().constData(),
cacertEdit->text().toLocal8Bit().constData(),
true);
else
setNetworkParam(id, "ca_cert", "NULL", false);
@ -388,7 +389,7 @@ void NetworkConfig::addNetwork()
if (idstrEdit->isEnabled() && idstrEdit->text().length() > 0)
setNetworkParam(id, "id_str",
idstrEdit->text().toAscii().constData(),
idstrEdit->text().toLocal8Bit().constData(),
true);
else
setNetworkParam(id, "id_str", "NULL", false);
@ -396,7 +397,7 @@ void NetworkConfig::addNetwork()
if (prioritySpinBox->isEnabled()) {
QString prio;
prio = prio.setNum(prioritySpinBox->value());
setNetworkParam(id, "priority", prio.toAscii().constData(),
setNetworkParam(id, "priority", prio.toLocal8Bit().constData(),
false);
}
@ -468,7 +469,7 @@ void NetworkConfig::writeWepKey(int network_id, QLineEdit *edit, int id)
* Assume hex key if only hex characters are present and length matches
* with 40, 104, or 128-bit key
*/
txt = edit->text().toAscii().constData();
txt = edit->text().toLocal8Bit().constData();
if (strcmp(txt, WPA_GUI_KEY_DATA) == 0)
return;
len = strlen(txt);

View File

@ -20,7 +20,7 @@ class NetworkConfig : public QDialog, public Ui::NetworkConfig
public:
NetworkConfig(QWidget *parent = 0, const char *name = 0,
bool modal = false, Qt::WFlags fl = 0);
bool modal = false, Qt::WindowFlags fl = 0);
~NetworkConfig();
virtual void paramsFromScanResults(QTreeWidgetItem *sel);

View File

@ -62,7 +62,7 @@ enum peer_type {
};
Peers::Peers(QWidget *parent, const char *, bool, Qt::WFlags)
Peers::Peers(QWidget *parent, const char *, bool, Qt::WindowFlags)
: QDialog(parent)
{
setupUi(this);
@ -323,13 +323,13 @@ void Peers::enter_pin()
if (peer_type == PEER_TYPE_WPS_ER_ENROLLEE) {
snprintf(cmd, sizeof(cmd), "WPS_ER_PIN %s %s %s",
uuid.toAscii().constData(),
input.get_string().toAscii().constData(),
addr.toAscii().constData());
uuid.toLocal8Bit().constData(),
input.get_string().toLocal8Bit().constData(),
addr.toLocal8Bit().constData());
} else {
snprintf(cmd, sizeof(cmd), "WPS_PIN %s %s",
addr.toAscii().constData(),
input.get_string().toAscii().constData());
addr.toLocal8Bit().constData(),
input.get_string().toLocal8Bit().constData());
}
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
@ -868,7 +868,7 @@ void Peers::event_notify(WpaMsg msg)
QStandardItem *item = find_addr(addr);
if (item == NULL || item->data(peer_role_type).toInt() !=
PEER_TYPE_ASSOCIATED_STATION)
add_single_station(addr.toAscii().constData());
add_single_station(addr.toLocal8Bit().constData());
return;
}
@ -1350,8 +1350,8 @@ void Peers::ctx_p2p_connect()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s display",
addr.toAscii().constData(),
arg.toAscii().constData());
addr.toLocal8Bit().constData(),
arg.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1384,8 +1384,8 @@ void Peers::ctx_p2p_connect()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s",
addr.toAscii().constData(),
arg.toAscii().constData());
addr.toLocal8Bit().constData(),
arg.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1408,7 +1408,7 @@ void Peers::ctx_p2p_req_pin()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s display",
addr.toAscii().constData());
addr.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1431,7 +1431,7 @@ void Peers::ctx_p2p_show_pin()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s keypad",
addr.toAscii().constData());
addr.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1452,7 +1452,7 @@ void Peers::ctx_p2p_display_pin()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s pin",
addr.toAscii().constData());
addr.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1480,8 +1480,8 @@ void Peers::ctx_p2p_display_pin_pd()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s display",
addr.toAscii().constData(),
arg.toAscii().constData());
addr.toLocal8Bit().constData(),
arg.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1515,8 +1515,8 @@ void Peers::ctx_p2p_enter_pin()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s keypad",
addr.toAscii().constData(),
arg.toAscii().constData());
addr.toLocal8Bit().constData(),
arg.toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;
@ -1535,7 +1535,7 @@ void Peers::ctx_p2p_remove_group()
char reply[100];
size_t reply_len;
snprintf(cmd, sizeof(cmd), "P2P_GROUP_REMOVE %s",
ctx_item->data(peer_role_ifname).toString().toAscii().
ctx_item->data(peer_role_ifname).toString().toLocal8Bit().
constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
@ -1713,13 +1713,13 @@ void Peers::connect_pbc()
int peer_type = ctx_item->data(peer_role_type).toInt();
if (peer_type == PEER_TYPE_WPS_ER_ENROLLEE) {
snprintf(cmd, sizeof(cmd), "WPS_ER_PBC %s",
ctx_item->data(peer_role_uuid).toString().toAscii().
ctx_item->data(peer_role_uuid).toString().toLocal8Bit().
constData());
} else if (peer_type == PEER_TYPE_P2P ||
peer_type == PEER_TYPE_P2P_CLIENT) {
snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s pbc",
ctx_item->data(peer_role_address).toString().
toAscii().constData());
toLocal8Bit().constData());
} else {
snprintf(cmd, sizeof(cmd), "WPS_PBC");
}
@ -1750,8 +1750,8 @@ void Peers::learn_ap_config()
size_t reply_len;
snprintf(cmd, sizeof(cmd), "WPS_ER_LEARN %s %s",
uuid.toAscii().constData(),
input.get_string().toAscii().constData());
uuid.toLocal8Bit().constData(),
input.get_string().toLocal8Bit().constData());
reply_len = sizeof(reply) - 1;
if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
QMessageBox msg;

View File

@ -22,7 +22,7 @@ class Peers : public QDialog, public Ui::Peers
public:
Peers(QWidget *parent = 0, const char *name = 0,
bool modal = false, Qt::WFlags fl = 0);
bool modal = false, Qt::WindowFlags fl = 0);
~Peers();
void setWpaGui(WpaGui *_wpagui);
void event_notify(WpaMsg msg);

View File

@ -15,7 +15,7 @@
#include "scanresultsitem.h"
ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WindowFlags)
: QDialog(parent)
{
setupUi(this);
@ -27,8 +27,8 @@ ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
SLOT(bssSelected(QTreeWidgetItem *)));
wpagui = NULL;
scanResultsWidget->setItemsExpandable(FALSE);
scanResultsWidget->setRootIsDecorated(FALSE);
scanResultsWidget->setItemsExpandable(false);
scanResultsWidget->setRootIsDecorated(false);
scanResultsWidget->setItemDelegate(new SignalBar(scanResultsWidget));
}

View File

@ -20,7 +20,7 @@ class ScanResults : public QDialog, public Ui::ScanResults
public:
ScanResults(QWidget *parent = 0, const char *name = 0,
bool modal = false, Qt::WFlags fl = 0);
bool modal = false, Qt::WindowFlags fl = 0);
~ScanResults();
public slots:

View File

@ -9,7 +9,7 @@
#ifndef SCANRESULTSITEM_H
#define SCANRESULTSITEM_H
#include <QtGui>
#include <QTreeWidgetItem>
class ScanResultsItem : public QTreeWidgetItem
{

View File

@ -12,7 +12,7 @@
UserDataRequest::UserDataRequest(QWidget *parent, const char *, bool,
Qt::WFlags)
Qt::WindowFlags)
: QDialog(parent)
{
setupUi(this);
@ -89,6 +89,6 @@ void UserDataRequest::sendReply()
QString cmd = QString(WPA_CTRL_RSP) + field + '-' +
QString::number(networkid) + ':' +
queryEdit->text();
wpagui->ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
wpagui->ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len);
accept();
}

View File

@ -20,7 +20,7 @@ class UserDataRequest : public QDialog, public Ui::UserDataRequest
public:
UserDataRequest(QWidget *parent = 0, const char *name = 0,
bool modal = false, Qt::WFlags fl = 0);
bool modal = false, Qt::WindowFlags fl = 0);
~UserDataRequest();
int setParams(WpaGui *_wpagui, const char *reqMsg);

View File

@ -1,6 +1,7 @@
TEMPLATE = app
LANGUAGE = C++
TRANSLATIONS = lang/wpa_gui_de.ts
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += qt warn_on release

View File

@ -31,7 +31,8 @@
#endif
WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags)
WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *,
Qt::WindowFlags)
: QMainWindow(parent), app(_app)
{
setupUi(this);
@ -159,7 +160,7 @@ WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags)
textStatus->setText(tr("connecting to wpa_supplicant"));
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(ping()));
timer->setSingleShot(FALSE);
timer->setSingleShot(false);
timer->start(1000);
signalMeterTimer = new QTimer(this);
@ -238,8 +239,9 @@ void WpaGui::languageChange()
void WpaGui::parse_argv()
{
int c;
WpaGuiApp *app = qobject_cast<WpaGuiApp*>(qApp);
for (;;) {
c = getopt(qApp->argc(), qApp->argv(), "i:m:p:tq");
c = getopt(app->argc, app->argv, "i:m:p:tq");
if (c < 0)
break;
switch (c) {
@ -750,7 +752,7 @@ void WpaGui::helpContents()
void WpaGui::helpAbout()
{
QMessageBox::about(this, "wpa_gui for wpa_supplicant",
"Copyright (c) 2003-2013,\n"
"Copyright (c) 2003-2015,\n"
"Jouni Malinen <j@w1.fi>\n"
"and contributors.\n"
"\n"
@ -1066,7 +1068,7 @@ void WpaGui::selectNetwork( const QString &sel )
else
cmd = "any";
cmd.prepend("SELECT_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len);
triggerUpdate();
stopWpsRun(false);
}
@ -1082,11 +1084,11 @@ void WpaGui::enableNetwork(const QString &sel)
cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) {
debug("Invalid editNetwork '%s'",
cmd.toAscii().constData());
cmd.toLocal8Bit().constData());
return;
}
cmd.prepend("ENABLE_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len);
triggerUpdate();
}
@ -1101,11 +1103,11 @@ void WpaGui::disableNetwork(const QString &sel)
cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) {
debug("Invalid editNetwork '%s'",
cmd.toAscii().constData());
cmd.toLocal8Bit().constData());
return;
}
cmd.prepend("DISABLE_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len);
triggerUpdate();
}
@ -1191,11 +1193,11 @@ void WpaGui::removeNetwork(const QString &sel)
cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) {
debug("Invalid editNetwork '%s'",
cmd.toAscii().constData());
cmd.toLocal8Bit().constData());
return;
}
cmd.prepend("REMOVE_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len);
triggerUpdate();
}
@ -1255,14 +1257,14 @@ int WpaGui::getNetworkDisabled(const QString &sel)
int pos = cmd.indexOf(':');
if (pos < 0) {
debug("Invalid getNetworkDisabled '%s'",
cmd.toAscii().constData());
cmd.toLocal8Bit().constData());
return -1;
}
cmd.truncate(pos);
cmd.prepend("GET_NETWORK ");
cmd.append(" disabled");
if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) >= 0
if (ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len) >= 0
&& reply_len >= 1) {
reply[reply_len] = '\0';
if (!str_match(reply, "FAIL"))
@ -1345,7 +1347,7 @@ void WpaGui::saveConfig()
void WpaGui::selectAdapter( const QString & sel )
{
if (openCtrlConnection(sel.toAscii().constData()) < 0)
if (openCtrlConnection(sel.toLocal8Bit().constData()) < 0)
debug("Failed to open control connection to "
"wpa_supplicant.");
updateStatus();
@ -1719,7 +1721,7 @@ void WpaGui::wpsApPin()
size_t reply_len = sizeof(reply);
QString cmd("WPS_REG " + bssFromScan + " " + wpsApPinEdit->text());
if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) < 0)
if (ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len) < 0)
return;
wpsStatusText->setText(tr("Waiting for AP/Enrollee"));

View File

@ -16,6 +16,20 @@
class UserDataRequest;
class WpaGuiApp : public QApplication
{
Q_OBJECT
public:
WpaGuiApp(int &argc, char **argv);
#if !defined(QT_NO_SESSIONMANAGER) && QT_VERSION < 0x050000
virtual void saveState(QSessionManager &manager);
#endif
WpaGui *w;
int argc;
char **argv;
};
class WpaGui : public QMainWindow, public Ui::WpaGui
{
@ -35,7 +49,7 @@ public:
};
WpaGui(QApplication *app, QWidget *parent = 0, const char *name = 0,
Qt::WFlags fl = 0);
Qt::WindowFlags fl = 0);
~WpaGui();
virtual int ctrlRequest(const char *cmd, char *buf, size_t *buflen);