]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / wpa_supplicant / wpa_gui-qt4 / scanresults.cpp
1 /*
2  * wpa_gui - ScanResults class
3  * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include <QTimer>
16
17 #include "scanresults.h"
18 #include "wpagui.h"
19 #include "networkconfig.h"
20
21
22 ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
23         : QDialog(parent)
24 {
25         setupUi(this);
26
27         connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
28         connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest()));
29         connect(scanResultsView, SIGNAL(doubleClicked(Q3ListViewItem *)), this,
30                 SLOT(bssSelected(Q3ListViewItem *)));
31
32         wpagui = NULL;
33 }
34
35
36 ScanResults::~ScanResults()
37 {
38         delete timer;
39 }
40
41
42 void ScanResults::languageChange()
43 {
44         retranslateUi(this);
45 }
46
47
48 void ScanResults::setWpaGui(WpaGui *_wpagui)
49 {
50         wpagui = _wpagui;
51         updateResults();
52     
53         timer = new QTimer(this);
54         connect(timer, SIGNAL(timeout()), SLOT(getResults()));
55         timer->start(10000, FALSE);
56 }
57
58
59 void ScanResults::updateResults()
60 {
61         char reply[8192];
62         size_t reply_len;
63     
64         if (wpagui == NULL)
65                 return;
66
67         reply_len = sizeof(reply) - 1;
68         if (wpagui->ctrlRequest("SCAN_RESULTS", reply, &reply_len) < 0)
69                 return;
70         reply[reply_len] = '\0';
71
72         scanResultsView->clear();
73     
74         QString res(reply);
75         QStringList lines = QStringList::split(QChar('\n'), res);
76         bool first = true;
77         for (QStringList::Iterator it = lines.begin(); it != lines.end(); it++)
78         {
79                 if (first) {
80                         first = false;
81                         continue;
82                 }
83         
84                 QStringList cols = QStringList::split(QChar('\t'), *it, true);
85                 QString ssid, bssid, freq, signal, flags;
86                 bssid = cols.count() > 0 ? cols[0] : "";
87                 freq = cols.count() > 1 ? cols[1] : "";
88                 signal = cols.count() > 2 ? cols[2] : "";
89                 flags = cols.count() > 3 ? cols[3] : "";
90                 ssid = cols.count() > 4 ? cols[4] : "";
91                 new Q3ListViewItem(scanResultsView, ssid, bssid, freq, signal,
92                                    flags);
93         }
94 }
95
96
97 void ScanResults::scanRequest()
98 {
99         char reply[10];
100         size_t reply_len = sizeof(reply);
101     
102         if (wpagui == NULL)
103                 return;
104     
105         wpagui->ctrlRequest("SCAN", reply, &reply_len);
106 }
107
108
109 void ScanResults::getResults()
110 {
111         updateResults();
112 }
113
114
115 void ScanResults::bssSelected( Q3ListViewItem * sel )
116 {
117         NetworkConfig *nc = new NetworkConfig();
118         if (nc == NULL)
119                 return;
120         nc->setWpaGui(wpagui);
121         nc->paramsFromScanResults(sel);
122         nc->show();
123         nc->exec();
124 }