diff --git a/wpa_supplicant/wpa_gui-qt4/peers.cpp b/wpa_supplicant/wpa_gui-qt4/peers.cpp index f963e318d..6cfb7a66e 100644 --- a/wpa_supplicant/wpa_gui-qt4/peers.cpp +++ b/wpa_supplicant/wpa_gui-qt4/peers.cpp @@ -14,10 +14,15 @@ #include #include +#include #include "wpagui.h" +#include "stringquery.h" #include "peers.h" + +static const int peer_role_address = Qt::UserRole + 1; + /* * TODO: * - add pending WPS queries (from M1/PIN, PBC?) @@ -30,9 +35,6 @@ Peers::Peers(QWidget *parent, const char *, bool, Qt::WFlags) { 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 @@ -41,6 +43,10 @@ Peers::Peers(QWidget *parent, const char *, bool, Qt::WFlags) peers->setModel(&model); peers->setResizeMode(QListView::Adjust); + peers->setContextMenuPolicy(Qt::CustomContextMenu); + connect(peers, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(context_menu(const QPoint &))); + wpagui = NULL; } @@ -64,11 +70,56 @@ void Peers::languageChange() } -void Peers::clicked(const QModelIndex & /*index*/) +void Peers::context_menu(const QPoint &pos) { - /* QStandardItem *item = model.itemFromIndex(index); */ - /* TODO: give an option to provide PIN for WPS, etc. */ - /* printf("Clicked: %s\n", item->text().toAscii().constData()); */ + QMenu *menu = new QMenu; + if (menu == NULL) + return; + + QModelIndex idx = peers->indexAt(pos); + if (idx.isValid()) { + ctx_item = model.itemFromIndex(idx); + /* TODO: only for peers that are requesting WPS PIN method */ + menu->addAction(QString("Enter WPS PIN"), this, + SLOT(enter_pin())); + } else { + ctx_item = NULL; + menu->addAction(QString("Refresh"), this, SLOT(ctx_refresh())); + } + + menu->exec(peers->mapToGlobal(pos)); +} + + +void Peers::enter_pin() +{ + if (ctx_item == NULL) + return; + QString addr = ctx_item->data(peer_role_address).toString(); + StringQuery input(tr("PIN:")); + input.setWindowTitle(tr("PIN for ") + ctx_item->text()); + if (input.exec() != QDialog::Accepted) + return; + + char cmd[100]; + char reply[100]; + size_t reply_len; + snprintf(cmd, sizeof(cmd), "WPS_PIN %s %s", + addr.toAscii().constData(), + input.get_string().toAscii().constData()); + reply_len = sizeof(reply) - 1; + if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) { + QMessageBox msg; + msg.setIcon(QMessageBox::Warning); + msg.setText("Failed to set the WPS PIN."); + msg.exec(); + } +} + + +void Peers::ctx_refresh() +{ + update_peers(); } @@ -115,6 +166,7 @@ void Peers::update_peers() QStandardItem *item = new QStandardItem(*default_icon, name); if (item) { + item->setData(QString(reply), peer_role_address); item->setToolTip(info); model.appendRow(item); } diff --git a/wpa_supplicant/wpa_gui-qt4/peers.h b/wpa_supplicant/wpa_gui-qt4/peers.h index 67eaff419..b8c5056ae 100644 --- a/wpa_supplicant/wpa_gui-qt4/peers.h +++ b/wpa_supplicant/wpa_gui-qt4/peers.h @@ -32,7 +32,9 @@ public: void setWpaGui(WpaGui *_wpagui); public slots: - virtual void clicked(const QModelIndex &index); + virtual void context_menu(const QPoint &pos); + virtual void enter_pin(); + virtual void ctx_refresh(); protected slots: virtual void languageChange(); @@ -43,6 +45,7 @@ private: WpaGui *wpagui; QStandardItemModel model; QIcon *default_icon; + QStandardItem *ctx_item; }; #endif /* PEERS_H */ diff --git a/wpa_supplicant/wpa_gui-qt4/stringquery.cpp b/wpa_supplicant/wpa_gui-qt4/stringquery.cpp new file mode 100644 index 000000000..1ca98d9ff --- /dev/null +++ b/wpa_supplicant/wpa_gui-qt4/stringquery.cpp @@ -0,0 +1,37 @@ +/* + * wpa_gui - StringQuery 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 + +#include "stringquery.h" + + +StringQuery::StringQuery(QString label) +{ + edit = new QLineEdit; + edit->setFocus(); + QGridLayout *layout = new QGridLayout; + layout->addWidget(new QLabel(label), 0, 0); + layout->addWidget(edit, 0, 1); + setLayout(layout); + + connect(edit, SIGNAL(returnPressed()), this, SLOT(accept())); +} + + +QString StringQuery::get_string() +{ + return edit->text(); +} diff --git a/wpa_supplicant/wpa_gui-qt4/stringquery.h b/wpa_supplicant/wpa_gui-qt4/stringquery.h new file mode 100644 index 000000000..1b68217c7 --- /dev/null +++ b/wpa_supplicant/wpa_gui-qt4/stringquery.h @@ -0,0 +1,34 @@ +/* + * wpa_gui - StringQuery 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 STRINGQUERY_H +#define STRINGQUERY_H + +#include +#include +#include + +class StringQuery : public QDialog +{ + Q_OBJECT + +public: + StringQuery(QString label); + QString get_string(); + +private: + QLineEdit *edit; +}; + +#endif /* STRINGQUERY_H */ diff --git a/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro b/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro index 32272f6e6..ec01b3b7d 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro +++ b/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro @@ -36,7 +36,8 @@ HEADERS += wpamsg.h \ userdatarequest.h \ networkconfig.h \ addinterface.h \ - peers.h + peers.h \ + stringquery.h SOURCES += main.cpp \ wpagui.cpp \ @@ -46,6 +47,7 @@ SOURCES += main.cpp \ networkconfig.cpp \ addinterface.cpp \ peers.cpp \ + stringquery.cpp \ ../../src/common/wpa_ctrl.c RESOURCES += icons.qrc