diff --git a/wpa_supplicant/wpa_gui-qt4/peers.cpp b/wpa_supplicant/wpa_gui-qt4/peers.cpp new file mode 100644 index 000000000..12626f591 --- /dev/null +++ b/wpa_supplicant/wpa_gui-qt4/peers.cpp @@ -0,0 +1,125 @@ +/* + * wpa_gui - Peers class + * Copyright (c) 2009, Atheros Communications + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Alternatively, this software may be distributed under the terms of BSD + * license. + * + * See README and COPYING for more details. + */ + +#include + +#include "wpagui.h" +#include "peers.h" + +/* + * TODO: + * - add pending WPS queries (from M1/PIN, PBC?) + * - add current AP info (e.g., from WPS) in station mode + * - different icons to indicate peer type + */ + +Peers::Peers(QWidget *parent, const char *, bool, Qt::WFlags) + : QDialog(parent) +{ + setupUi(this); + + connect(peers, SIGNAL(clicked(QModelIndex)), this, + SLOT(clicked(QModelIndex))); + + if (QImageReader::supportedImageFormats().contains(QByteArray("svg"))) + default_icon = new QIcon(":/icons/wpa_gui.svg"); + else + default_icon = new QIcon(":/icons/wpa_gui.png"); + + peers->setModel(&model); + peers->setResizeMode(QListView::Adjust); + + wpagui = NULL; +} + + +void Peers::setWpaGui(WpaGui *_wpagui) +{ + wpagui = _wpagui; + update_peers(); +} + + +Peers::~Peers() +{ + delete default_icon; +} + + +void Peers::languageChange() +{ + retranslateUi(this); +} + + +void Peers::clicked(const QModelIndex & /*index*/) +{ + /* QStandardItem *item = model.itemFromIndex(index); */ + /* TODO: give an option to provide PIN for WPS, etc. */ + /* printf("Clicked: %s\n", item->text().toAscii().constData()); */ +} + + +void Peers::update_peers() +{ + char reply[2048]; + size_t reply_len; + char cmd[20]; + int res; + + model.clear(); + if (wpagui == NULL) + return; + + reply_len = sizeof(reply) - 1; + if (wpagui->ctrlRequest("STA-FIRST", reply, &reply_len) < 0) + return; + + do { + reply[reply_len] = '\0'; + QString info(reply); + char *txt = reply; + while (*txt != '\0' && *txt != '\n') + txt++; + *txt++ = '\0'; + if (strncmp(reply, "FAIL", 4) == 0) + break; + + QStringList lines = info.split(QRegExp("\\n")); + QString name; + + for (QStringList::Iterator it = lines.begin(); + it != lines.end(); it++) { + int pos = (*it).indexOf('=') + 1; + if (pos < 1) + continue; + + if ((*it).startsWith("wpsDeviceName=")) + name = (*it).mid(pos); + } + + if (name.isEmpty()) + name = reply; + + QStandardItem *item = new QStandardItem(*default_icon, name); + if (item) { + item->setToolTip(info); + model.appendRow(item); + } + + reply_len = sizeof(reply) - 1; + snprintf(cmd, sizeof(cmd), "STA-NEXT %s", reply); + res = wpagui->ctrlRequest(cmd, reply, &reply_len); + } while (res >= 0); +} diff --git a/wpa_supplicant/wpa_gui-qt4/peers.h b/wpa_supplicant/wpa_gui-qt4/peers.h new file mode 100644 index 000000000..67eaff419 --- /dev/null +++ b/wpa_supplicant/wpa_gui-qt4/peers.h @@ -0,0 +1,48 @@ +/* + * wpa_gui - Peers class + * Copyright (c) 2009, Atheros Communications + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Alternatively, this software may be distributed under the terms of BSD + * license. + * + * See README and COPYING for more details. + */ + +#ifndef PEERS_H +#define PEERS_H + +#include +#include +#include "ui_peers.h" + +class WpaGui; + +class Peers : public QDialog, public Ui::Peers +{ + Q_OBJECT + +public: + Peers(QWidget *parent = 0, const char *name = 0, + bool modal = false, Qt::WFlags fl = 0); + ~Peers(); + void setWpaGui(WpaGui *_wpagui); + +public slots: + virtual void clicked(const QModelIndex &index); + +protected slots: + virtual void languageChange(); + +private: + void update_peers(); + + WpaGui *wpagui; + QStandardItemModel model; + QIcon *default_icon; +}; + +#endif /* PEERS_H */ diff --git a/wpa_supplicant/wpa_gui-qt4/peers.ui b/wpa_supplicant/wpa_gui-qt4/peers.ui new file mode 100644 index 000000000..9508c254b --- /dev/null +++ b/wpa_supplicant/wpa_gui-qt4/peers.ui @@ -0,0 +1,40 @@ + + + Peers + + + + 0 + 0 + 400 + 300 + + + + Peers + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::NoEditTriggers + + + QListView::IconMode + + + + + + + + diff --git a/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro b/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro index 2317cbd48..32272f6e6 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro +++ b/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro @@ -35,7 +35,8 @@ HEADERS += wpamsg.h \ scanresults.h \ userdatarequest.h \ networkconfig.h \ - addinterface.h + addinterface.h \ + peers.h SOURCES += main.cpp \ wpagui.cpp \ @@ -44,6 +45,7 @@ SOURCES += main.cpp \ userdatarequest.cpp \ networkconfig.cpp \ addinterface.cpp \ + peers.cpp \ ../../src/common/wpa_ctrl.c RESOURCES += icons.qrc @@ -52,7 +54,8 @@ FORMS = wpagui.ui \ eventhistory.ui \ scanresults.ui \ userdatarequest.ui \ - networkconfig.ui + networkconfig.ui \ + peers.ui unix { diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp index dcd33b945..6371c8bc9 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp @@ -85,6 +85,7 @@ WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags) connect(fileSaveConfigAction, SIGNAL(triggered()), this, SLOT(saveConfig())); connect(actionWPS, SIGNAL(triggered()), this, SLOT(wpsDialog())); + connect(actionPeers, SIGNAL(triggered()), this, SLOT(peersDialog())); connect(fileExitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(networkAddAction, SIGNAL(triggered()), this, SLOT(addNetwork())); @@ -133,6 +134,7 @@ WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags) eh = NULL; scanres = NULL; + peers = NULL; add_iface = NULL; udr = NULL; tray_icon = NULL; @@ -203,6 +205,12 @@ WpaGui::~WpaGui() scanres = NULL; } + if (peers) { + peers->close(); + delete peers; + peers = NULL; + } + if (add_iface) { add_iface->close(); delete add_iface; @@ -1412,6 +1420,12 @@ void WpaGui::closeEvent(QCloseEvent *event) scanres = NULL; } + if (peers) { + peers->close(); + delete peers; + peers = NULL; + } + if (udr) { udr->close(); delete udr; @@ -1444,6 +1458,22 @@ void WpaGui::wpsDialog() } +void WpaGui::peersDialog() +{ + if (peers) { + peers->close(); + delete peers; + } + + peers = new Peers(); + if (peers == NULL) + return; + peers->setWpaGui(this); + peers->show(); + peers->exec(); +} + + void WpaGui::tabChanged(int index) { if (index != 2) diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.h b/wpa_supplicant/wpa_gui-qt4/wpagui.h index a53396541..4b206c643 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.h +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.h @@ -75,6 +75,7 @@ public slots: int sec, const QString &msg); virtual void showTrayStatus(); virtual void wpsDialog(); + virtual void peersDialog(); virtual void tabChanged(int index); virtual void wpsPbc(); virtual void wpsGeneratePin(); @@ -93,6 +94,7 @@ protected slots: private: ScanResults *scanres; + Peers *peers; bool networkMayHaveChanged; char *ctrl_iface; EventHistory *eh; diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.ui b/wpa_supplicant/wpa_gui-qt4/wpagui.ui index cd67ecb78..9f9039f6c 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.ui +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.ui @@ -392,6 +392,7 @@ + @@ -500,6 +501,11 @@ &Wi-Fi Protected Setup + + + &Peers + + @@ -509,6 +515,7 @@ wpamsg.h eventhistory.h scanresults.h + peers.h