1 /* 2 * wpa_gui - ScanResults class 3 * Copyright (c) 2005-2006, Jouni Malinen <j (at) 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 <cstdio> 18 19 #include "scanresults.h" 20 #include "wpagui.h" 21 #include "networkconfig.h" 22 23 24 ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags) 25 : QDialog(parent) 26 { 27 setupUi(this); 28 29 connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); 30 connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest())); 31 connect(scanResultsView, SIGNAL(doubleClicked(Q3ListViewItem *)), this, 32 SLOT(bssSelected(Q3ListViewItem *))); 33 34 wpagui = NULL; 35 } 36 37 38 ScanResults::~ScanResults() 39 { 40 delete timer; 41 } 42 43 44 void ScanResults::languageChange() 45 { 46 retranslateUi(this); 47 } 48 49 50 void ScanResults::setWpaGui(WpaGui *_wpagui) 51 { 52 wpagui = _wpagui; 53 updateResults(); 54 55 timer = new QTimer(this); 56 connect(timer, SIGNAL(timeout()), SLOT(getResults())); 57 timer->start(10000, FALSE); 58 } 59 60 61 void ScanResults::updateResults() 62 { 63 char reply[8192]; 64 size_t reply_len; 65 66 if (wpagui == NULL) 67 return; 68 69 reply_len = sizeof(reply) - 1; 70 if (wpagui->ctrlRequest("SCAN_RESULTS", reply, &reply_len) < 0) 71 return; 72 reply[reply_len] = '\0'; 73 74 scanResultsView->clear(); 75 76 QString res(reply); 77 QStringList lines = QStringList::split(QChar('\n'), res); 78 bool first = true; 79 for (QStringList::Iterator it = lines.begin(); it != lines.end(); it++) 80 { 81 if (first) { 82 first = false; 83 continue; 84 } 85 86 QStringList cols = QStringList::split(QChar('\t'), *it, true); 87 QString ssid, bssid, freq, signal, flags; 88 bssid = cols.count() > 0 ? cols[0] : ""; 89 freq = cols.count() > 1 ? cols[1] : ""; 90 signal = cols.count() > 2 ? cols[2] : ""; 91 flags = cols.count() > 3 ? cols[3] : ""; 92 ssid = cols.count() > 4 ? cols[4] : ""; 93 new Q3ListViewItem(scanResultsView, ssid, bssid, freq, signal, 94 flags); 95 } 96 } 97 98 99 void ScanResults::scanRequest() 100 { 101 char reply[10]; 102 size_t reply_len = sizeof(reply); 103 104 if (wpagui == NULL) 105 return; 106 107 wpagui->ctrlRequest("SCAN", reply, &reply_len); 108 } 109 110 111 void ScanResults::getResults() 112 { 113 updateResults(); 114 } 115 116 117 void ScanResults::bssSelected( Q3ListViewItem * sel ) 118 { 119 NetworkConfig *nc = new NetworkConfig(); 120 if (nc == NULL) 121 return; 122 nc->setWpaGui(wpagui); 123 nc->paramsFromScanResults(sel); 124 nc->show(); 125 nc->exec(); 126 } 127