wpa_gui-qt4: Add a new window for showing peer information
authorJouni Malinen <jouni.malinen@atheros.com>
Tue, 8 Sep 2009 13:28:41 +0000 (16:28 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 8 Sep 2009 13:28:41 +0000 (16:28 +0300)
This provides some initial functionality for showing peer information,
i.e., showing information about other devices that has been discovered.
Currently, information is only available in the AP mode (list of
associated stations), but this is expected to increase in the future
(e.g., show the current AP in station mode, other stations in IBSS,
etc.). Furthermore, there will be actions available for doing things
like providing a WPS PIN for a station.

wpa_supplicant/wpa_gui-qt4/peers.cpp [new file with mode: 0644]
wpa_supplicant/wpa_gui-qt4/peers.h [new file with mode: 0644]
wpa_supplicant/wpa_gui-qt4/peers.ui [new file with mode: 0644]
wpa_supplicant/wpa_gui-qt4/wpa_gui.pro
wpa_supplicant/wpa_gui-qt4/wpagui.cpp
wpa_supplicant/wpa_gui-qt4/wpagui.h
wpa_supplicant/wpa_gui-qt4/wpagui.ui

diff --git a/wpa_supplicant/wpa_gui-qt4/peers.cpp b/wpa_supplicant/wpa_gui-qt4/peers.cpp
new file mode 100644 (file)
index 0000000..12626f5
--- /dev/null
@@ -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 <QImageReader>
+
+#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 (file)
index 0000000..67eaff4
--- /dev/null
@@ -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 <QObject>
+#include <QStandardItemModel>
+#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 (file)
index 0000000..9508c25
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Peers</class>
+ <widget class="QDialog" name="Peers">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Peers</string>
+  </property>
+  <layout class="QGridLayout">
+   <item row="0" column="0">
+    <widget class="QListView" name="peers">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="mouseTracking">
+      <bool>true</bool>
+     </property>
+     <property name="editTriggers">
+      <set>QAbstractItemView::NoEditTriggers</set>
+     </property>
+     <property name="viewMode">
+      <enum>QListView::IconMode</enum>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index 2317cbd..32272f6 100644 (file)
@@ -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 {
index dcd33b9..6371c8b 100644 (file)
@@ -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)
index a533965..4b206c6 100644 (file)
@@ -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;
index cd67ecb..9f9039f 100644 (file)
     <addaction name="fileEventHistoryAction" />
     <addaction name="fileSaveConfigAction" />
     <addaction name="actionWPS" />
+    <addaction name="actionPeers" />
     <addaction name="separator" />
     <addaction name="fileExitAction" />
    </widget>
     <string>&amp;Wi-Fi Protected Setup</string>
    </property>
   </action>
+  <action name="actionPeers" >
+   <property name="text" >
+    <string>&amp;Peers</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11" />
  <pixmapfunction></pixmapfunction>
   <include location="local" >wpamsg.h</include>
   <include location="local" >eventhistory.h</include>
   <include location="local" >scanresults.h</include>
+  <include location="local" >peers.h</include>
  </includes>
  <resources>
   <include location="icons.qrc" />