1 /*
2 * wpa_gui - ScanResults class
3 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include <cstdio>
10
11 #include "scanresults.h"
12 #include "signalbar.h"
13 #include "wpagui.h"
14 #include "networkconfig.h"
15
16
ScanResults(QWidget * parent,const char *,bool,Qt::WFlags)17 ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
18 : QDialog(parent)
19 {
20 setupUi(this);
21
22 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
23 connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest()));
24 connect(scanResultsWidget,
25 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
26 SLOT(bssSelected(QTreeWidgetItem *)));
27
28 wpagui = NULL;
29 scanResultsWidget->setItemsExpandable(FALSE);
30 scanResultsWidget->setRootIsDecorated(FALSE);
31 scanResultsWidget->setItemDelegate(new SignalBar(scanResultsWidget));
32 }
33
34
~ScanResults()35 ScanResults::~ScanResults()
36 {
37 }
38
39
languageChange()40 void ScanResults::languageChange()
41 {
42 retranslateUi(this);
43 }
44
45
setWpaGui(WpaGui * _wpagui)46 void ScanResults::setWpaGui(WpaGui *_wpagui)
47 {
48 wpagui = _wpagui;
49 updateResults();
50 }
51
52
updateResults()53 void ScanResults::updateResults()
54 {
55 char reply[2048];
56 size_t reply_len;
57 int index;
58 char cmd[20];
59
60 scanResultsWidget->clear();
61
62 index = 0;
63 while (wpagui) {
64 snprintf(cmd, sizeof(cmd), "BSS %d", index++);
65 if (index > 1000)
66 break;
67
68 reply_len = sizeof(reply) - 1;
69 if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0)
70 break;
71 reply[reply_len] = '\0';
72
73 QString bss(reply);
74 if (bss.isEmpty() || bss.startsWith("FAIL"))
75 break;
76
77 QString ssid, bssid, freq, signal, flags;
78
79 QStringList lines = bss.split(QRegExp("\\n"));
80 for (QStringList::Iterator it = lines.begin();
81 it != lines.end(); it++) {
82 int pos = (*it).indexOf('=') + 1;
83 if (pos < 1)
84 continue;
85
86 if ((*it).startsWith("bssid="))
87 bssid = (*it).mid(pos);
88 else if ((*it).startsWith("freq="))
89 freq = (*it).mid(pos);
90 else if ((*it).startsWith("level="))
91 signal = (*it).mid(pos);
92 else if ((*it).startsWith("flags="))
93 flags = (*it).mid(pos);
94 else if ((*it).startsWith("ssid="))
95 ssid = (*it).mid(pos);
96 }
97
98 QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
99 if (item) {
100 item->setText(0, ssid);
101 item->setText(1, bssid);
102 item->setText(2, freq);
103 item->setText(3, signal);
104 item->setText(4, flags);
105 }
106
107 if (bssid.isEmpty())
108 break;
109 }
110 }
111
112
scanRequest()113 void ScanResults::scanRequest()
114 {
115 char reply[10];
116 size_t reply_len = sizeof(reply);
117
118 if (wpagui == NULL)
119 return;
120
121 wpagui->ctrlRequest("SCAN", reply, &reply_len);
122 }
123
124
getResults()125 void ScanResults::getResults()
126 {
127 updateResults();
128 }
129
130
bssSelected(QTreeWidgetItem * sel)131 void ScanResults::bssSelected(QTreeWidgetItem *sel)
132 {
133 NetworkConfig *nc = new NetworkConfig();
134 if (nc == NULL)
135 return;
136 nc->setWpaGui(wpagui);
137 nc->paramsFromScanResults(sel);
138 nc->show();
139 nc->exec();
140 }
141