scanresults.cpp
Go to the documentation of this file.
00001 /*
00002  * wpa_gui - ScanResults class
00003  * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include <cstdio>
00016 
00017 #include "scanresults.h"
00018 #include "wpagui.h"
00019 #include "networkconfig.h"
00020 
00021 
00022 ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
00023         : QDialog(parent)
00024 {
00025         setupUi(this);
00026 
00027         connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00028         connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest()));
00029         connect(scanResultsWidget,
00030                 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
00031                 SLOT(bssSelected(QTreeWidgetItem *)));
00032 
00033         wpagui = NULL;
00034         scanResultsWidget->setItemsExpandable(FALSE);
00035         scanResultsWidget->setRootIsDecorated(FALSE);
00036 }
00037 
00038 
00039 ScanResults::~ScanResults()
00040 {
00041 }
00042 
00043 
00044 void ScanResults::languageChange()
00045 {
00046         retranslateUi(this);
00047 }
00048 
00049 
00050 void ScanResults::setWpaGui(WpaGui *_wpagui)
00051 {
00052         wpagui = _wpagui;
00053         updateResults();
00054 }
00055 
00056 
00057 void ScanResults::updateResults()
00058 {
00059         char reply[2048];
00060         size_t reply_len;
00061         int index;
00062         char cmd[20];
00063 
00064         scanResultsWidget->clear();
00065 
00066         index = 0;
00067         while (wpagui) {
00068                 snprintf(cmd, sizeof(cmd), "BSS %d", index++);
00069                 if (index > 1000)
00070                         break;
00071 
00072                 reply_len = sizeof(reply) - 1;
00073                 if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0)
00074                         break;
00075                 reply[reply_len] = '\0';
00076 
00077                 QString bss(reply);
00078                 if (bss.isEmpty() || bss.startsWith("FAIL"))
00079                         break;
00080 
00081                 QString ssid, bssid, freq, signal, flags;
00082 
00083                 QStringList lines = bss.split(QRegExp("\\n"));
00084                 for (QStringList::Iterator it = lines.begin();
00085                      it != lines.end(); it++) {
00086                         int pos = (*it).indexOf('=') + 1;
00087                         if (pos < 1)
00088                                 continue;
00089 
00090                         if ((*it).startsWith("bssid="))
00091                                 bssid = (*it).mid(pos);
00092                         else if ((*it).startsWith("freq="))
00093                                 freq = (*it).mid(pos);
00094                         else if ((*it).startsWith("qual="))
00095                                 signal = (*it).mid(pos);
00096                         else if ((*it).startsWith("flags="))
00097                                 flags = (*it).mid(pos);
00098                         else if ((*it).startsWith("ssid="))
00099                                 ssid = (*it).mid(pos);
00100                 }
00101 
00102                 QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
00103                 if (item) {
00104                         item->setText(0, ssid);
00105                         item->setText(1, bssid);
00106                         item->setText(2, freq);
00107                         item->setText(3, signal);
00108                         item->setText(4, flags);
00109                 }
00110 
00111                 if (bssid.isEmpty())
00112                         break;
00113         }
00114 }
00115 
00116 
00117 void ScanResults::scanRequest()
00118 {
00119         char reply[10];
00120         size_t reply_len = sizeof(reply);
00121     
00122         if (wpagui == NULL)
00123                 return;
00124     
00125         wpagui->ctrlRequest("SCAN", reply, &reply_len);
00126 }
00127 
00128 
00129 void ScanResults::getResults()
00130 {
00131         updateResults();
00132 }
00133 
00134 
00135 void ScanResults::bssSelected(QTreeWidgetItem *sel)
00136 {
00137         NetworkConfig *nc = new NetworkConfig();
00138         if (nc == NULL)
00139                 return;
00140         nc->setWpaGui(wpagui);
00141         nc->paramsFromScanResults(sel);
00142         nc->show();
00143         nc->exec();
00144 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:25:14