[PC-BSD Commits] r9725 - pcbsd/current/src-qt4/pc-netmanager/src/wificonfig

svn at pcbsd.org svn at pcbsd.org
Fri Mar 18 12:06:06 PDT 2011


Author: kenmoore
Date: 2011-03-18 12:06:06 -0700 (Fri, 18 Mar 2011)
New Revision: 9725

Modified:
   pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wifiscanssid.cpp
Log:
Update the wifiscanssid to work faster using the new libpcbsd functions


Modified: pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wifiscanssid.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wifiscanssid.cpp	2011-03-18 17:24:21 UTC (rev 9724)
+++ pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wifiscanssid.cpp	2011-03-18 19:06:06 UTC (rev 9725)
@@ -2,7 +2,10 @@
 #include "ui_wifiscanssid.h"
 #include <qtextstream.h>
 #include <qtimer.h>
+#include <pcbsd-utils.h>
+#include <pcbsd-netif.h>
 
+
 void wifiscanssid::init(QString device)
 {
    DeviceName = device;
@@ -69,97 +72,56 @@
    
 void wifiscanssid::scanWifi()
 {
-    QString tmp;
-    QString strength;
-    QString ssid;
+    QString strength, ssid, tmp, FileLoad;
+    QStringList ifconfout, ifline;    
     int newStrength;
-    bool ok;
     int foundItem = 0;
-    QString FileLoad;
-    QString line;
-    
+
     // Clear the list box
     listWifi->clear();
     textTop->setText(tr("Scanning for wireless networks...") );
             
     // Start the scan and get the output
-    line = getLineFromCommandOutput("ifconfig -v " + DeviceName + " up list scan >/tmp/.wifilist 2>/tmp/.wifilist");
+    ifconfout = Utils::runShellCommand("ifconfig -v " + DeviceName + " list scan");
 
-    // Now read the output file
-    QFile file( "/tmp/.wifilist" );
-    if ( file.open( QIODevice::ReadOnly ) ) {
-        QTextStream stream( &file );
-        while ( !stream.atEnd() ) {
-                 line = stream.readLine(); // line of text excluding '\n'
-	     // exclude the header line
-	     if ( line.indexOf("BSSID") == -1) {
-		     
-		 // Get the ssid of the network
-		 tmp = line;
-		 tmp = tmp.simplified();
-		 tmp.remove(0, tmp.indexOf("SSID<") + 5);
-		 tmp.truncate(tmp.indexOf(">"));
-		 ssid = tmp;
-
-		 // Get the signal strength of this device
-		 strength = getSignalStrengthForIdent( line );
-
-	         //QMessageBox::warning( this, "Testing", "SSID:" + ssid + " STR:" + strength );
-		 // Add the device to the list box
-		 strength.toInt(&ok);
-		 if ( ok && !ssid.isEmpty() && ssid != " " ) {
-		     newStrength = tmp.toInt(&ok);
-		     if ( newStrength < 25 )
-		     {	
-			 FileLoad= PROGPATH + "/pics/tray_wifi.png";
-		     } else if ( newStrength < 50 ) {
-			 FileLoad= PROGPATH + "/pics/tray_wifi30.png";
-		     }  else if ( newStrength < 75 ) {
-			 FileLoad= PROGPATH + "/pics/tray_wifi60.png";
-		     } else {;
-			 FileLoad= PROGPATH + "/pics/tray_wifi85.png";
-		     }
-		 
-		       QImage *Icon = new QImage(FileLoad);
-		       QPixmap PixmapIcon;
-	                     PixmapIcon.fromImage(Icon->scaled(22,22));
-		       listWifi->addItem(new QListWidgetItem(PixmapIcon, ssid + " (signal strength: " +strength + "%)") );
-		       
-		       foundItem = 1;
-		 
-	     } else {
-		  if ( ! ssid.isEmpty() && ssid != " " ) {
-		       // If we didn't get the signal strength, still display the SSID
-		       FileLoad= PROGPATH + "/pics/tray_wifi.png";
-		       QImage *Icon = new QImage(FileLoad);
-		       QPixmap PixmapIcon;
-	                     PixmapIcon.fromImage(Icon->scaled(22,22));
-		       listWifi->addItem(new QListWidgetItem(PixmapIcon, ssid + " (signal strength: unknown)") );
-		       
-		       foundItem = 1;
-                  }
-	     }
-	    
-	}
-	
+    //display the info for each wifi access point
+    for(int i=1; i<ifconfout.size(); i++){    //Skip the header line by starting at 1
+      ifline = NetworkInterface::parseWifiScanLine(ifconfout[i],true); //get a single line
+      //save the info for this wifi
+      ssid = ifline[0];
+      strength = ifline[4];
+      //determine the icon based on the signal strength
+      tmp = strength.section("%",0,0,QString::SectionSkipEmpty); //remove the % from the end
+      newStrength = tmp.toInt(); //integer strength value      
+      if ( newStrength < 25 ){	
+	FileLoad= PROGPATH + "/pics/tray_wifi.png";
+      } else if ( newStrength < 50 ) {
+	FileLoad= PROGPATH + "/pics/tray_wifi30.png";
+      }  else if ( newStrength < 75 ) {
+	FileLoad= PROGPATH + "/pics/tray_wifi60.png";
+      } else {
+	FileLoad= PROGPATH + "/pics/tray_wifi85.png";
+      }
+      QImage *Icon = new QImage(FileLoad);
+      QPixmap PixmapIcon;
+      PixmapIcon.fromImage(Icon->scaled(22,22));
+      //Add the wifi access point to the list
+      listWifi->addItem(new QListWidgetItem(PixmapIcon, ssid + " (signal strength: " +strength + ")") );
+      foundItem = 1; //set the flag for wifi signals found  
     }
-	
-	
-	if ( foundItem == 1 )
-	{
-	    textTop->setText(tr("Select a wireless network to connect.") );
-	    listWifi->setCurrentRow(0);
-	    pushSelect->setEnabled(TRUE);
-              } else {
-                  textTop->setText(tr("No wireless networks found!") );
-	    pushSelect->setEnabled(FALSE);
-	}
-    }
     
+    if ( foundItem == 1 ){
+      textTop->setText(tr("Select a wireless network to connect.") );
+      listWifi->setCurrentRow(0);
+      pushSelect->setEnabled(TRUE);
+    } else {
+      textTop->setText(tr("No wireless networks found!") );
+      pushSelect->setEnabled(FALSE);
+    }
+
 }
 
 
-
 void wifiscanssid::slotCancel()
 {
     close();



More information about the Commits mailing list