[PC-BSD Commits] r15336 - in users/kris/pc-firstbootgui: . images

svn at pcbsd.org svn at pcbsd.org
Tue Feb 14 10:18:23 PST 2012


Author: kris
Date: 2012-02-14 18:18:22 +0000 (Tue, 14 Feb 2012)
New Revision: 15336

Added:
   users/kris/pc-firstbootgui/images/object-locked.png
   users/kris/pc-firstbootgui/images/object-unlocked.png
   users/kris/pc-firstbootgui/netKey.cpp
   users/kris/pc-firstbootgui/netKey.h
   users/kris/pc-firstbootgui/netKey.ui
Modified:
   users/kris/pc-firstbootgui/firstboot.cpp
   users/kris/pc-firstbootgui/firstboot.h
   users/kris/pc-firstbootgui/pc-firstboot.pro
   users/kris/pc-firstbootgui/pc-firstboot.qrc
Log:

Add functionality to firstboot which detects wifi networks, and lets the user connect to one
as apart of the initial setup.



Modified: users/kris/pc-firstbootgui/firstboot.cpp
===================================================================
--- users/kris/pc-firstbootgui/firstboot.cpp	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/firstboot.cpp	2012-02-14 18:18:22 UTC (rev 15336)
@@ -1,6 +1,8 @@
 #include <QProcess>
 #include <QTimer>
 #include <QGraphicsPixmapItem>
+#include <pcbsd-netif.h>
+#include <pcbsd-utils.h>
 
 #include "backend.h"
 #include "ui_firstboot.h"
@@ -39,10 +41,14 @@
     if (index != -1)
        comboBoxTimezone->setCurrentIndex(index);
 
-    if ( system("ifconfig wlan0") == 0 )
+    if ( system("ifconfig wlan0") == 0 ) {
       haveWifi = true;
-    else
+      QTimer::singleShot(500,this,SLOT(slotScanNetwork()));
+      connect(pushButtonRescan, SIGNAL(clicked()), this, SLOT(slotScanNetwork()));
+      connect(listWidgetWifi, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(slotAddNewWifi()));
+    } else {
       haveWifi = false;
+    }
 
     // Start on the first screen
     installStackWidget->setCurrentIndex(0);
@@ -102,11 +108,6 @@
             (index == count ? count : index + 1) :
             (index == 0 ? 0 : index - 1);
 
-    if ( index > 0 && index != 4)
-      backButton->setVisible(true);
-    else
-      backButton->setVisible(false);
-
     installStackWidget->setCurrentIndex(index);
 }
 
@@ -150,6 +151,7 @@
 void Installer::slotNext()
 {
    QString tmp;
+   backButton->setVisible(true);
 
    // Check rootPW match
    if ( installStackWidget->currentIndex() == 1)
@@ -161,6 +163,7 @@
    if ( installStackWidget->currentIndex() == 3 && ! haveWifi) {
       installStackWidget->setCurrentIndex(5);
       // Save the settings
+      saveSettings();
       nextButton->setText("Finish");
       backButton->setVisible(false);
       nextButton->disconnect();
@@ -171,6 +174,7 @@
    // Finished screen
    if ( installStackWidget->currentIndex() == 4 ) {
       // Save the settings
+      saveSettings();
       nextButton->setText("Finish");
       backButton->setVisible(false);
       nextButton->disconnect();
@@ -182,6 +186,11 @@
 
 void Installer::slotBack()
 {
+   if ( installStackWidget->currentIndex() == 1 )
+     backButton->setVisible(false);
+   else
+     backButton->setVisible(true);
+
    proceed(false);
 }
 
@@ -241,3 +250,99 @@
 	pcHelp->show();
 }
 
+void Installer::slotScanNetwork()
+{
+  QString strength, ssid, security, FileLoad;
+  QStringList ifconfout, ifline;
+  int foundItem = 0;
+
+  // Clear the list box and disable the add button
+  listWidgetWifi->clear();
+
+  // Start the scan and get the output
+  //ifconfout = Utils::runShellCommand("ifconfig -v wlan0 up list scan");
+  ifconfout = Utils::runShellCommand("ifconfig -v wlan0 list scan");
+  
+  qDebug() << ifconfout;
+
+  //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 if there is security encryption
+    security = ifline[6]; //NetworkInterface::getWifiSecurity(ssid,DeviceName);
+    if(security.contains("None")){
+      FileLoad = ":/modules/images/object-unlocked.png";
+    }else{
+      FileLoad = ":/modules/images/object-locked.png";
+    }
+    //Add the wifi access point to the list
+    listWidgetWifi->addItem(new QListWidgetItem(QIcon(FileLoad), ssid + " (signal: " +strength + ")") );
+    foundItem = 1; //set the flag for wifi signals found
+  }
+   
+  if ( foundItem == 1 )
+    listWidgetWifi->setCurrentRow(-1);
+}
+
+void Installer::slotAddNewWifi()
+{
+  if ((listWidgetWifi->currentRow()) ==-1 )
+     return;
+
+  QString line = listWidgetWifi->item(listWidgetWifi->currentRow())->text();
+  QString ssidc = line.section(" (",0,0,QString::SectionSkipEmpty);
+  addNetworkProfile(ssidc);
+}
+
+void Installer::addNetworkProfile(QString ssid)
+{
+  //get the full SSID string
+  QString dat = Utils::runShellCommandSearch("ifconfig -v wlan0 list scan",ssid);
+  QStringList wdat = NetworkInterface::parseWifiScanLine(dat,true);
+  QString SSID = wdat[0];
+ 
+  //Get the Security Type
+  QString sectype = wdat[6];
+ 
+  if(sectype == "None"){
+    //run the Quick-Connect slot without a key
+    slotQuickConnect("",SSID);
+  }else{
+    //Open the dialog to prompt for the Network Security Key
+    dialogNetKey = new netKey();
+    //Insert the SSID into the dialog
+    dialogNetKey->setSSID(SSID);
+    //connect the signal from the dialog to the quick-connect slot
+    connect(dialogNetKey,SIGNAL( saved(QString,QString) ),this,SLOT( slotQuickConnect(QString,QString) ) );
+    //Activate the dialog
+    dialogNetKey->exec();
+  }
+}
+
+void Installer::slotQuickConnect(QString key,QString SSID){
+ 
+  // Run the wifiQuickConnect function
+  NetworkInterface::wifiQuickConnect(SSID,key,"wlan0");
+ 
+  // Move to finish screen
+  installStackWidget->setCurrentIndex(5);
+
+  // Save the settings
+  saveSettings();
+  nextButton->setText("Finish");
+  backButton->setVisible(false);
+  nextButton->disconnect();
+  connect(nextButton, SIGNAL(clicked()), this, SLOT(slotFinished()));
+}
+
+void Installer::saveSettings()
+{
+  if ( comboLanguage->currentIndex() != 0 )
+  {
+
+  }
+
+}

Modified: users/kris/pc-firstbootgui/firstboot.h
===================================================================
--- users/kris/pc-firstbootgui/firstboot.h	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/firstboot.h	2012-02-14 18:18:22 UTC (rev 15336)
@@ -10,6 +10,7 @@
 #include "dialogHelp.h"
 #include "dialogKeyboard.h"
 #include "dialogInfoBox.h"
+#include "netKey.h"
 
 #include "backend.h"
 
@@ -42,16 +43,32 @@
     // User validators
     void slotCheckUser();
     void slotSuggestUsername();
+    
+    // Start a scan of the network
+    void slotScanNetwork();
 
+    // Add new wifi
+    void slotAddNewWifi();
+    void slotQuickConnect(QString key,QString SSID);
+
 private:
     void proceed(bool);
     bool haveWifi;
 
+    // Get network pass
+    void addNetworkProfile(QString ssid);
+
+    // Apply the settings
+    void saveSettings(); 
+
     QStringList languages;
 
     // Help Stuff
     dialogHelp *pcHelp;
 
+    // Network key dialog
+    netKey *dialogNetKey;
+
     // Infobox 
     dialogInfoBox *dIB;
     QMenu *popup;

Index: users/kris/pc-firstbootgui/images/object-locked.png
===================================================================
--- users/kris/pc-firstbootgui/images/object-locked.png	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/images/object-locked.png	2012-02-14 18:18:22 UTC (rev 15336)

Property changes on: users/kris/pc-firstbootgui/images/object-locked.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: users/kris/pc-firstbootgui/images/object-unlocked.png
===================================================================
--- users/kris/pc-firstbootgui/images/object-unlocked.png	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/images/object-unlocked.png	2012-02-14 18:18:22 UTC (rev 15336)

Property changes on: users/kris/pc-firstbootgui/images/object-unlocked.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: users/kris/pc-firstbootgui/netKey.ui
===================================================================
--- users/kris/pc-firstbootgui/netKey.ui	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/netKey.ui	2012-02-14 18:18:22 UTC (rev 15336)

Property changes on: users/kris/pc-firstbootgui/netKey.ui
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/xml
Modified: users/kris/pc-firstbootgui/pc-firstboot.pro
===================================================================
--- users/kris/pc-firstbootgui/pc-firstboot.pro	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/pc-firstboot.pro	2012-02-14 18:18:22 UTC (rev 15336)
@@ -3,18 +3,22 @@
 # -------------------------------------------------
 TARGET = pc-firstboot
 DESTDIR=/usr/local/bin
+LIBS    += -lpcbsd
+INCLUDEPATH+= ../../pcbsd/current/src-qt4/libpcbsd/
 TEMPLATE = app
 SOURCES += main.cpp \
     dialogInfoBox.cpp \
     dialogKeyboard.cpp \
     dialogHelp.cpp \
     firstboot.cpp \
+    netKey.cpp \
     backend.cpp
 HEADERS += firstboot.h \
     dialogInfoBox.h \
     dialogKeyboard.h \
     dialogHelp.h \
     helpText.h \
+    netKey.h \
     backend.h
 TRANSLATIONS =  i18n/FirstBoot_af.ts \
 		i18n/FirstBoot_ar.ts \
@@ -86,5 +90,5 @@
 
 INSTALLS += dotrans
 
-FORMS += firstboot.ui dialogHelp.ui dialogKeyboard.ui dialogInfoBox.ui
+FORMS += firstboot.ui dialogHelp.ui dialogKeyboard.ui dialogInfoBox.ui netKey.ui
 RESOURCES += pc-firstboot.qrc

Modified: users/kris/pc-firstbootgui/pc-firstboot.qrc
===================================================================
--- users/kris/pc-firstbootgui/pc-firstboot.qrc	2012-02-14 16:36:39 UTC (rev 15335)
+++ users/kris/pc-firstbootgui/pc-firstboot.qrc	2012-02-14 18:18:22 UTC (rev 15336)
@@ -1,5 +1,7 @@
 <RCC>
   <qresource prefix="/modules">
+    <file>images/object-locked.png</file>
+    <file>images/object-unlocked.png</file>
     <file>images/backgroundimage.jpg</file>
     <file>images/basic.png</file>
     <file>images/advanced.png</file>



More information about the Commits mailing list