Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / wpa / wpa_supplicant / wpa_gui-qt4 / scanresults.cpp
blobbceef8ac2fd23283e134e61d2d9251ccdf389dab
1 /*
2 * wpa_gui - ScanResults class
3 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "scanresults.h"
16 #include "wpagui.h"
17 #include "networkconfig.h"
20 ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
21 : QDialog(parent)
23 setupUi(this);
25 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
26 connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest()));
27 connect(scanResultsWidget,
28 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
29 SLOT(bssSelected(QTreeWidgetItem *)));
31 wpagui = NULL;
32 scanResultsWidget->setItemsExpandable(FALSE);
33 scanResultsWidget->setRootIsDecorated(FALSE);
37 ScanResults::~ScanResults()
42 void ScanResults::languageChange()
44 retranslateUi(this);
48 void ScanResults::setWpaGui(WpaGui *_wpagui)
50 wpagui = _wpagui;
51 updateResults();
55 void ScanResults::updateResults()
57 char reply[2048];
58 size_t reply_len;
59 int index;
60 char cmd[20];
62 scanResultsWidget->clear();
64 index = 0;
65 while (wpagui) {
66 snprintf(cmd, sizeof(cmd), "BSS %d", index++);
67 if (index > 1000)
68 break;
70 reply_len = sizeof(reply) - 1;
71 if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0)
72 break;
73 reply[reply_len] = '\0';
75 QString bss(reply);
76 if (bss.isEmpty() || bss.startsWith("FAIL"))
77 break;
79 QString ssid, bssid, freq, signal, flags;
81 QStringList lines = bss.split(QRegExp("\\n"));
82 for (QStringList::Iterator it = lines.begin();
83 it != lines.end(); it++) {
84 int pos = (*it).indexOf('=') + 1;
85 if (pos < 1)
86 continue;
88 if ((*it).startsWith("bssid="))
89 bssid = (*it).mid(pos);
90 else if ((*it).startsWith("freq="))
91 freq = (*it).mid(pos);
92 else if ((*it).startsWith("qual="))
93 signal = (*it).mid(pos);
94 else if ((*it).startsWith("flags="))
95 flags = (*it).mid(pos);
96 else if ((*it).startsWith("ssid="))
97 ssid = (*it).mid(pos);
100 QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
101 if (item) {
102 item->setText(0, ssid);
103 item->setText(1, bssid);
104 item->setText(2, freq);
105 item->setText(3, signal);
106 item->setText(4, flags);
109 if (bssid.isEmpty())
110 break;
115 void ScanResults::scanRequest()
117 char reply[10];
118 size_t reply_len = sizeof(reply);
120 if (wpagui == NULL)
121 return;
123 wpagui->ctrlRequest("SCAN", reply, &reply_len);
127 void ScanResults::getResults()
129 updateResults();
133 void ScanResults::bssSelected(QTreeWidgetItem *sel)
135 NetworkConfig *nc = new NetworkConfig();
136 if (nc == NULL)
137 return;
138 nc->setWpaGui(wpagui);
139 nc->paramsFromScanResults(sel);
140 nc->show();
141 nc->exec();