wpa_gui-qt4: Improve scan results signal display
authorKel Modderman <kel@otaku42.de>
Sat, 19 Nov 2011 18:10:37 +0000 (20:10 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 19 Nov 2011 18:10:37 +0000 (20:10 +0200)
Display signal strength in dBm with visual indicator in the form of a
bar for scan results displayed by wpa_gui-qt4. Any signal > -35dBm is
treated as full signal bar, signals between range of -95<->-35dBm are
displayed linearly. Convert WEXT signal level value to scale that
nl80211 typically reports in dBm. The condition which differentiates
8-bit WEXT dBm and regular dBm is probably fragile, but there is
currently no way to know what the driver is going to report for signal
strength.

Signed-off-by: Kel Modderman <kel@otaku42.de>
wpa_supplicant/wpa_gui-qt4/scanresults.cpp
wpa_supplicant/wpa_gui-qt4/signalbar.cpp [new file with mode: 0644]
wpa_supplicant/wpa_gui-qt4/signalbar.h [new file with mode: 0644]
wpa_supplicant/wpa_gui-qt4/wpa_gui.pro

index 459aa8c..f75f02a 100644 (file)
@@ -15,6 +15,7 @@
 #include <cstdio>
 
 #include "scanresults.h"
+#include "signalbar.h"
 #include "wpagui.h"
 #include "networkconfig.h"
 
@@ -33,6 +34,7 @@ ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
        wpagui = NULL;
        scanResultsWidget->setItemsExpandable(FALSE);
        scanResultsWidget->setRootIsDecorated(FALSE);
+       scanResultsWidget->setItemDelegate(new SignalBar(scanResultsWidget));
 }
 
 
@@ -91,7 +93,7 @@ void ScanResults::updateResults()
                                bssid = (*it).mid(pos);
                        else if ((*it).startsWith("freq="))
                                freq = (*it).mid(pos);
-                       else if ((*it).startsWith("qual="))
+                       else if ((*it).startsWith("level="))
                                signal = (*it).mid(pos);
                        else if ((*it).startsWith("flags="))
                                flags = (*it).mid(pos);
diff --git a/wpa_supplicant/wpa_gui-qt4/signalbar.cpp b/wpa_supplicant/wpa_gui-qt4/signalbar.cpp
new file mode 100644 (file)
index 0000000..f2688d5
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * wpa_gui - SignalBar class
+ * Copyright (c) 2011, Kel Modderman <kel@otaku42.de>
+ *
+ * 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 <cstdio>
+#include <qapplication.h>
+
+#include "signalbar.h"
+
+
+SignalBar::SignalBar(QObject *parent)
+       : QStyledItemDelegate(parent)
+{
+}
+
+
+SignalBar::~SignalBar()
+{
+}
+
+
+void SignalBar::paint(QPainter *painter,
+                     const QStyleOptionViewItem &option,
+                     const QModelIndex &index) const
+{
+       QStyleOptionProgressBar opts;
+       int signal;
+
+       if (index.column() != 3) {
+               QStyledItemDelegate::paint(painter, option, index);
+               return;
+       }
+
+       if (index.data().toInt() > 0)
+               signal = 0 - (256 - index.data().toInt());
+       else
+               signal = index.data().toInt();
+
+       opts.minimum = -95;
+       opts.maximum = -35;
+       if (signal < opts.minimum)
+               opts.progress = opts.minimum;
+       else if (signal > opts.maximum)
+               opts.progress = opts.maximum;
+       else
+               opts.progress = signal;
+
+       opts.text = QString::number(signal) + " dBm";
+       opts.textVisible = true;
+       opts.rect = option.rect;
+
+       QApplication::style()->drawControl(QStyle::CE_ProgressBar,
+                                          &opts, painter);
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/signalbar.h b/wpa_supplicant/wpa_gui-qt4/signalbar.h
new file mode 100644 (file)
index 0000000..3d5dec1
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * wpa_gui - SignalBar class
+ * Copyright (c) 2011, Kel Modderman <kel@otaku42.de>
+ *
+ * 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 SIGNALBAR_H
+#define SIGNALBAR_H
+
+#include <QObject>
+#include <QStyledItemDelegate>
+
+class SignalBar : public QStyledItemDelegate
+{
+       Q_OBJECT
+
+public:
+       SignalBar(QObject *parent = 0);
+       ~SignalBar();
+
+       virtual void paint(QPainter *painter,
+                          const QStyleOptionViewItem &option,
+                          const QModelIndex &index) const ;
+};
+
+#endif /* SIGNALBAR_H */
index 85848d7..3c81929 100644 (file)
@@ -34,6 +34,7 @@ HEADERS       += wpamsg.h \
        wpagui.h \
        eventhistory.h \
        scanresults.h \
+       signalbar.h \
        userdatarequest.h \
        networkconfig.h \
        addinterface.h \
@@ -44,6 +45,7 @@ SOURCES       += main.cpp \
        wpagui.cpp \
        eventhistory.cpp \
        scanresults.cpp \
+       signalbar.cpp \
        userdatarequest.cpp \
        networkconfig.cpp \
        addinterface.cpp \