source: src-qt4/pc-netmanager/src/wificonfig/wifiscanssid.cpp @ 1f0939e

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 1f0939e was 1f0939e, checked in by Kris Moore <kris@…>, 19 months ago
  • Initial merge of code from PC-BSD SVN repo for my private (pre-release) hacking
  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include "wifiscanssid.h"
2#include "ui_wifiscanssid.h"
3#include <qtextstream.h>
4#include <qtimer.h>
5#include <pcbsd-utils.h>
6#include <pcbsd-netif.h>
7#include <QDebug>
8
9
10void wifiscanssid::init(QString device)
11{
12   DeviceName = device;
13   pushSelect->setEnabled(FALSE);
14   
15   QTimer::singleShot(500,  this,  SLOT(slotRescan()));
16
17   connect( pushRescan, SIGNAL( clicked() ), this, SLOT(slotRescan()) );
18   connect( pushSelect, SIGNAL( clicked() ), this, SLOT(slotConnect()) );
19   connect( pushCancel, SIGNAL( clicked() ), this, SLOT(slotCancel()) );
20}
21   
22void wifiscanssid::scanWifi()
23{
24    QString strength, ssid, tmp, FileLoad;
25    QStringList ifconfout, ifline;   
26    int newStrength;
27    int foundItem = 0;
28
29    // Clear the list box
30    listWifi->clear();
31    textTop->setText(tr("Scanning for wireless networks...") );
32           
33    // Start the scan and get the output
34    ifconfout = Utils::runShellCommand("ifconfig -v " + DeviceName + " up list scan");
35
36    //display the info for each wifi access point
37    for(int i=1; i<ifconfout.size(); i++){    //Skip the header line by starting at 1
38      ifline = NetworkInterface::parseWifiScanLine(ifconfout[i],true); //get a single line
39      //save the info for this wifi
40      ssid = ifline[0];
41      strength = ifline[4];
42      //determine the icon based on the signal strength
43      tmp = strength.section("%",0,0,QString::SectionSkipEmpty); //remove the % from the end
44      newStrength = tmp.toInt(); //integer strength value
45      bool duplicateSSID = FALSE;
46      for ( int z = 0 ; z < listWifi->count() ; z++){
47        qDebug() << listWifi->item(z)->text() << ssid;
48        if ( listWifi->item(z)->text().contains(ssid+" (") ){
49          duplicateSSID = TRUE;
50          break;
51        }
52      }
53
54      if( !duplicateSSID ){
55        if ( newStrength < 25 ){       
56          FileLoad= PROGPATH + "/pics/tray_wifi.png";
57        } else if ( newStrength < 50 ) {
58          FileLoad= PROGPATH + "/pics/tray_wifi30.png";
59        }  else if ( newStrength < 75 ) {
60          FileLoad= PROGPATH + "/pics/tray_wifi60.png";
61        } else {
62          FileLoad= PROGPATH + "/pics/tray_wifi85.png";
63        }
64        QImage *Icon = new QImage(FileLoad);
65        QPixmap PixmapIcon;
66        PixmapIcon.fromImage(Icon->scaled(22,22));
67        //Add the wifi access point to the list
68        listWifi->addItem(new QListWidgetItem(PixmapIcon, ssid + " (signal strength: " +strength + ")") );
69        foundItem = 1; //set the flag for wifi signals found
70      }else{
71        //if the new signal is stronger, change the current label to reflect it
72
73      } 
74    }
75   
76    if ( foundItem == 1 ){
77      textTop->setText(tr("Select a wireless network to connect.") );
78      listWifi->setCurrentRow(0);
79      pushSelect->setEnabled(TRUE);
80    } else {
81      textTop->setText(tr("No wireless networks found!") );
82      pushSelect->setEnabled(FALSE);
83    }
84
85}
86
87
88void wifiscanssid::slotCancel()
89{
90    close();
91}
92
93
94void wifiscanssid::slotConnect()
95{
96    QString selectedSSID;
97   
98    // Make sure a device was selected
99    int sel = listWifi->currentRow();
100    if ( sel == -1 )
101    {
102        QMessageBox::warning( this, tr("No selection"),
103                            tr("Error: You must select a network to connect!\n") );
104        return;
105    }
106   
107    QListWidgetItem *selected = listWifi->currentItem(); 
108    selectedSSID = selected->text();
109    selectedSSID.truncate( selectedSSID.indexOf("(") - 1 );
110   
111    // Emit the new network SSID the user selected
112    emit saved(selectedSSID);
113    close();
114}
115
116void wifiscanssid::slotRescan()
117{
118    pushSelect->setEnabled(FALSE);
119    scanWifi();
120}
121
122
123
Note: See TracBrowser for help on using the repository browser.