Added a test for MUIA_Listview_SelectChange.
[AROS.git] / workbench / network / WirelessManager / wpa_supplicant / wpa_gui-qt4 / scanresults.cpp
blob459aa8c69637c31de9bad3e18dbec77c3407453a
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 <cstdio>
17 #include "scanresults.h"
18 #include "wpagui.h"
19 #include "networkconfig.h"
22 ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
23 : QDialog(parent)
25 setupUi(this);
27 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
28 connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest()));
29 connect(scanResultsWidget,
30 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
31 SLOT(bssSelected(QTreeWidgetItem *)));
33 wpagui = NULL;
34 scanResultsWidget->setItemsExpandable(FALSE);
35 scanResultsWidget->setRootIsDecorated(FALSE);
39 ScanResults::~ScanResults()
44 void ScanResults::languageChange()
46 retranslateUi(this);
50 void ScanResults::setWpaGui(WpaGui *_wpagui)
52 wpagui = _wpagui;
53 updateResults();
57 void ScanResults::updateResults()
59 char reply[2048];
60 size_t reply_len;
61 int index;
62 char cmd[20];
64 scanResultsWidget->clear();
66 index = 0;
67 while (wpagui) {
68 snprintf(cmd, sizeof(cmd), "BSS %d", index++);
69 if (index > 1000)
70 break;
72 reply_len = sizeof(reply) - 1;
73 if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0)
74 break;
75 reply[reply_len] = '\0';
77 QString bss(reply);
78 if (bss.isEmpty() || bss.startsWith("FAIL"))
79 break;
81 QString ssid, bssid, freq, signal, flags;
83 QStringList lines = bss.split(QRegExp("\\n"));
84 for (QStringList::Iterator it = lines.begin();
85 it != lines.end(); it++) {
86 int pos = (*it).indexOf('=') + 1;
87 if (pos < 1)
88 continue;
90 if ((*it).startsWith("bssid="))
91 bssid = (*it).mid(pos);
92 else if ((*it).startsWith("freq="))
93 freq = (*it).mid(pos);
94 else if ((*it).startsWith("qual="))
95 signal = (*it).mid(pos);
96 else if ((*it).startsWith("flags="))
97 flags = (*it).mid(pos);
98 else if ((*it).startsWith("ssid="))
99 ssid = (*it).mid(pos);
102 QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
103 if (item) {
104 item->setText(0, ssid);
105 item->setText(1, bssid);
106 item->setText(2, freq);
107 item->setText(3, signal);
108 item->setText(4, flags);
111 if (bssid.isEmpty())
112 break;
117 void ScanResults::scanRequest()
119 char reply[10];
120 size_t reply_len = sizeof(reply);
122 if (wpagui == NULL)
123 return;
125 wpagui->ctrlRequest("SCAN", reply, &reply_len);
129 void ScanResults::getResults()
131 updateResults();
135 void ScanResults::bssSelected(QTreeWidgetItem *sel)
137 NetworkConfig *nc = new NetworkConfig();
138 if (nc == NULL)
139 return;
140 nc->setWpaGui(wpagui);
141 nc->paramsFromScanResults(sel);
142 nc->show();
143 nc->exec();