source: src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.cpp @ 0cfe72f

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 0cfe72f was 0cfe72f, checked in by Kris Moore <kris@…>, 21 months ago

Add all the changes for related using of split pcbsd-utils libs

  • Property mode set to 100644
File size: 20.1 KB
Line 
1
2/* Qt */
3#include <QDebug>
4#include <QFile>
5#include <QImage>
6#include <QMenu>
7#include <QProcess>
8#include <QToolTip>
9#include <QTextStream>
10#include <QTimer>
11#include <QTranslator>
12#include <iostream>
13
14#include "NetworkTray.h"
15#include <pcbsd-netif.h>
16#include <pcbsd-utils.h>
17#include "../../../config.h"
18
19
20/* Update interval in ms */
21#define  UPDATE_MSEC 15000
22
23// Public Variables
24QString DeviceName;
25QString DeviceType;
26QString DeviceParent;
27QString DeviceIP;
28QString DeviceIPv6;
29QString DeviceMAC;
30QString DeviceSSID;
31QString DeviceSignalStrength = "";
32int     DeviceSavedStrength = 0;
33QString DeviceWirelessSpeed = "";
34QString DeviceStatus;
35QString DeviceUpStatus;
36QString DeviceIdent;
37QString DeviceNetmask;
38QString DeviceMedia;
39QString username;
40
41void NetworkTray::programInit(QString Device)
42{
43  // Load the icons we'll be using into memory
44  loadIcons();
45
46  QString tmp;
47  QIcon Icon;
48  DeviceName = Device;
49  DeviceType = getTypeForIdent(DeviceName);
50
51  QString cmd = IFCONFIG + " lagg0 2>/dev/null | grep " + DeviceName;
52  QString checkLagg = getLineFromCommandOutput(cmd.toLatin1());
53  if ( ! checkLagg.isEmpty() )
54    usingLagg = true;
55  else
56    usingLagg = false;
57 
58
59  // Get the username of the person we are running as
60  username = QString::fromLocal8Bit(getenv("LOGNAME"));
61 
62  // Confirm this is a legit device
63  confirmDevice(DeviceName); 
64
65  // Update the ifconfig line we will be parsing
66  slotUpdateIfStatus();
67
68  // Get the MAC for this device
69  DeviceMAC=getMacForIdent(DeviceName);
70
71  if ( DeviceName.indexOf("wlan") != -1 )
72  {
73     DeviceParent = getWifiParent(DeviceName);
74
75     // Get HW Identify line
76     DeviceIdent = getNameForIdent(DeviceParent);
77
78     // If the name comes up bogus for some reason
79     if ( DeviceIdent.isEmpty() ) 
80       DeviceIdent = tr("Unknown Wireless Device");
81  } else {
82      DeviceIdent = getNameForIdent( DeviceName );
83  }
84
85  trayIcon = new QSystemTrayIcon(this);
86 
87  // Connect our double-click slot and message clicked slot
88  connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason)));
89  connect(trayIcon, SIGNAL( messageClicked() ), this,SLOT( openConfigDlg() )); 
90  trayIcon->setIcon(iconWifiDisconnect);
91  trayIcon->show();
92 
93  //Display a message about the wireless status
94  QTimer::singleShot(5000,this,SLOT(slotCheckWifiAvailability() ));
95
96  // Create the tooltip popup now
97  displayTooltip();
98
99  // Start the monitor service on a refresh loop
100  monitorStatus();
101
102}
103
104
105// Function which locates the parent device of a wlan child device
106QString NetworkTray::getWifiParent(QString dev)
107{
108   dev.remove(0, dev.size() -1 );
109   QString DevNum = dev;
110   return pcbsd::Utils::sysctl("net.wlan." + DevNum + ".%parent");
111}
112
113void NetworkTray::confirmDevice( QString device )
114{
115   QString command = IFCONFIG + " -l | grep " + device;
116   QString line = getLineFromCommandOutput(command);
117   if ( line.isEmpty() )
118   {
119      // Opps, this device doesn't seem to exist!
120      exit(1);
121   }
122}
123
124QString NetworkTray::getLineFromCommandOutput( QString command )
125{
126  FILE *file = popen(command.toLatin1(),"r"); 
127       
128  char buffer[100];
129       
130  QString line = ""; 
131  char firstChar;
132       
133  if ((firstChar = fgetc(file)) != -1){
134     line += firstChar;
135     line += fgets(buffer,100,file);
136  }
137  pclose(file);
138  return line;
139}
140
141
142QString NetworkTray::getNameForIdent( QString ident )
143{
144  NetworkInterface ifr(ident);
145  return ifr.desc();
146}
147
148
149QString NetworkTray::getIpForIdent()
150{
151  QString inputLine = ifconfigOutput;
152  QString ip= "";
153  QString tDev;
154  if ( usingLagg ) {
155    tDev = "lagg0";
156    QString cmd = IFCONFIG + " " + tDev + " | grep " + DeviceName;
157    QString checkLagg = getLineFromCommandOutput(cmd.toLatin1());
158    if ( ! checkLagg.isEmpty() ) {
159      cmd = IFCONFIG + " " + tDev + " | grep 'inet ' ";
160      inputLine = getLineFromCommandOutput(cmd.toLatin1());
161    }
162
163    if (inputLine != "" && inputLine.indexOf("inet ") != -1){
164      ip = inputLine.remove(0, inputLine.indexOf("inet ") + 5);
165      ip.truncate(inputLine.indexOf(" "));
166    }
167    return ip;
168  }
169
170  if (inputLine != "" && inputLine.indexOf("inet ") != -1){
171    ip = inputLine.remove(0, inputLine.indexOf("inet ") + 5);
172    ip.truncate(inputLine.indexOf(" "));
173  }
174       
175  return ip;
176}
177
178
179QString NetworkTray::getMacForIdent( QString ident )
180{
181  NetworkInterface ifr(ident);
182  return ifr.macAsString();
183}
184
185QString NetworkTray::getSSIDForIdent()
186{
187  QString inputLine = ifconfigOutput;
188  QString SSID = "";
189       
190  if (inputLine != "" && inputLine.indexOf("ssid ") != -1){
191    SSID = inputLine.remove(0, inputLine.indexOf("ssid ") + 5);
192    SSID.truncate(inputLine.indexOf("channel") - 1 );
193  }
194       
195  return SSID;
196}
197
198QString NetworkTray::getNetmaskForIdent()
199{
200  QString inputLine = ifconfigOutput;
201  QString netmask= "";
202       
203  if (inputLine != "" && inputLine.indexOf("netmask ") != -1){
204    netmask = inputLine.remove(0, inputLine.indexOf("netmask ") + 8);
205    netmask.truncate(netmask.indexOf(" "));
206  }
207       
208  return netmask;
209}
210
211QString NetworkTray::getSignalStrengthForIdent( QString ident )
212{
213  // Get the signal strength of this device
214  QString command = IFCONFIG + " " + ident + " list scan | grep " + DeviceSSID;
215  QString line = getLineFromCommandOutput(command);
216  QString tmp, sig, noise;
217  bool ok, ok2;
218  int isig, inoise, percent;
219       
220  tmp = line.simplified();
221
222  // Lets find the signal strength / noise variables now
223  tmp.remove(0, tmp.indexOf(":"));
224  tmp.remove(0, tmp.indexOf(" "));
225
226  // Get the noise
227  noise = tmp.simplified();
228  noise.remove(0, noise.lastIndexOf(":") + 1);
229  noise.remove(noise.indexOf(" "), noise.size());
230  noise = noise.simplified();
231  if ( noise.indexOf("-") == 0)
232        noise.remove(0, 1);
233
234  // Get the signal
235  sig = tmp.simplified();
236  sig.remove(sig.indexOf(":"), sig.size());
237  sig.remove(0, sig.lastIndexOf(" "));
238  sig = sig.simplified();
239  if ( sig.indexOf("-") == 0)
240        sig.remove(0, 1);
241
242  //qDebug() << "Signal:" << sig << " Noise:" << noise;
243
244  // Now figure out the percentage
245  isig = sig.toInt(&ok);
246  inoise = noise.toInt(&ok2);
247  if ( ok && ok2 ) {
248     percent = (inoise - isig) * 4;
249     // Sanity check
250     if ( percent > 100 )
251        percent = 100;
252     if ( percent < 0 )
253        percent = 0;
254     tmp.setNum(percent);
255  } else {
256     tmp = "";
257  }
258
259  return tmp;   
260}
261
262QString NetworkTray::getWirelessSpeedForIdent( QString ident )
263{
264  QString command = IFCONFIG + " " + ident + " list scan | grep " + DeviceSSID;
265  QString line = getLineFromCommandOutput(command);
266  QString tmp;
267
268  // Get the signal strength of this device
269  tmp = line;
270  tmp = tmp.simplified();
271
272  // First remove the SSID which may have spaces in it
273  tmp.remove(0, tmp.indexOf(":"));
274
275  // Now find the Speed section
276  tmp = tmp.section(" ", 2, 2);
277  return tmp;
278}
279
280void NetworkTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) {
281   if(reason == QSystemTrayIcon::Trigger) {
282      //openNetManager();
283      openConfigDlg();
284   }
285}
286
287
288void  NetworkTray::openConfigDlg() {
289
290  if ( DeviceType == "Ethernet" )
291  {
292    QString program = "sudo";
293    QStringList arguments;
294    arguments << "pc-ethernetconfig" << DeviceName;
295    QProcess *runCommandProc = new QProcess(this);
296    runCommandProc->start(program, arguments);
297  } else {
298    QString program = "sudo";
299    QStringList arguments;
300    arguments << "pc-wificonfig" << DeviceName;
301    QProcess *runCommandProc = new QProcess(this);
302    runCommandProc->start(program, arguments);
303  }
304
305}
306
307void  NetworkTray::displayTooltip() {
308
309  QString  tooltipStr;
310  tooltipStr = QString(tr("Device Name:") + " /dev/" + DeviceName);
311  tooltipStr += "<br>" + DeviceIdent +"<hr>";
312  if ( DeviceType == "Ethernet" )
313  {
314     if ( DeviceStatus == "active" || DeviceStatus == "" ) {
315       tooltipStr += "<br>" + tr("IP:") + " " + DeviceIP;
316       tooltipStr += "<br>" + tr("IPv6:") + " " + DeviceIPv6;
317       tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
318       tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
319       tooltipStr += "<br>" + tr("Status:") + " " + DeviceUpStatus;
320     } else {
321       tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
322       tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
323       tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
324       tooltipStr += "<br>" + tr("No connection detected.<br> Check your cable connection and try again!");
325     }
326
327   } else {
328     // If this is a wireless device, give different output
329     if ( DeviceStatus == "associated" ) {
330        tooltipStr += "<br>" + tr("IP:") + " " + DeviceIP;
331        tooltipStr += "<br>" + tr("IPv6:") + " " + DeviceIPv6;
332        tooltipStr += "<br>" + tr("SSID:") + " " + DeviceSSID;
333        tooltipStr += "<br>" + tr("Connection Strength:") + " " + DeviceSignalStrength + "%";
334        tooltipStr += "<br>" + tr("Connection Speed:") + " " + DeviceWirelessSpeed;
335        tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
336        tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
337        tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
338      } else {
339        tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
340        tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
341        tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
342        tooltipStr += "<br>" + tr("No wireless connection detected.<br> Double-click to start the wireless configuration wizard.");
343      }
344   }
345
346  // Update the tooltop
347  trayIcon->setToolTip(tooltipStr);
348   
349}
350
351// Load all the icons we'll be using
352void NetworkTray::loadIcons() {
353  iconWiredConnect.addFile(PROGPATH + "/pics/tray_local.png");
354  iconWiredDisconnect.addFile( PROGPATH + "/pics/tray_local_dis.png");
355  iconWifiConnect.addFile( PROGPATH + "/pics/tray_wifi.png");
356  iconWifiDisconnect.addFile( PROGPATH + "/pics/tray_wifi_dis.png");
357  iconWifiConnect30.addFile( PROGPATH + "/pics/tray_wifi30.png");
358  iconWifiConnect60.addFile( PROGPATH + "/pics/tray_wifi60.png");
359  iconWifiConnect85.addFile( PROGPATH + "/pics/tray_wifi85.png");
360  iconLocked.addFile( PROGPATH + "/pics/object-locked.png");
361  iconUnlocked.addFile( PROGPATH + "/pics/object-unlocked.png");
362}
363
364void NetworkTray::slotQuit() {
365   exit(0);
366}
367
368void NetworkTray::slotTriggerFileChanged() {
369}
370
371void NetworkTray::monitorStatus(bool noloop) {
372  // Start checking to see if the device has changed, and if it has inform the user
373  QString tmp; 
374  QIcon Icon;
375  QString NotifyText = "";
376
377  // Check the media status of this device
378  DeviceMedia = getMediaForIdent();
379
380  // Check for IPv6 Changes
381  DeviceIPv6 = getIPv6ForIdent();
382
383  // Get the device up status
384  DeviceUpStatus = getUpStatusForIdent();
385
386
387  if ( DeviceType == "Ethernet" )
388  {
389    if ( (DeviceStatus == "active" || DeviceStatus == "")  && tmp == "UP")
390      Icon = iconWiredConnect;
391    else
392      Icon = iconWiredDisconnect;
393  } else {
394    if ( DeviceStatus == "associated" && tmp == "UP" )
395      Icon = iconWifiConnect;
396    else
397      Icon = iconWifiDisconnect;
398  }
399
400
401  // First check the status of the device
402  DeviceStatus = getStatusForIdent();
403  if ( DeviceType == "Ethernet" )
404  {
405    if ( (DeviceStatus == "active" || DeviceStatus == "")  && DeviceUpStatus == "UP")
406      Icon = iconWiredConnect;
407    else
408      Icon = iconWiredDisconnect;
409
410  } else {
411    if ( DeviceStatus == "associated" && DeviceUpStatus == "UP" )
412      Icon = iconWifiConnect;
413    else
414      Icon = iconWifiDisconnect;
415  }
416
417  // Now check the IP Address for changes
418  DeviceIP = getIpForIdent();
419  DeviceNetmask = getNetmaskForIdent();
420
421  if ( DeviceType == "Wireless" && DeviceStatus == "associated" )
422  {
423    // Now check the SSID Address for changes
424    DeviceSSID = getSSIDForIdent();
425
426    if (! DeviceSSID.isEmpty() )
427    {
428       int newStrength = 0;
429       int iconStrength = 0;
430       QString FileLoad;
431       bool ok;
432       // Get the strength of the signal
433       tmp = getSignalStrengthForIdent( DeviceName );
434       DeviceSignalStrength = tmp;
435       // Figure out if we need to change the strength icon
436       tmp.toInt(&ok);
437       if ( ok ) {
438         newStrength = tmp.toInt(&ok);
439         if ( newStrength < 5 )
440         {     
441           iconStrength = 0;
442           Icon = iconWifiConnect;
443         } else if ( newStrength < 50 ) {
444           iconStrength = 30;
445           Icon = iconWifiConnect30;
446         } else if ( newStrength < 75 ) {
447           iconStrength = 60;
448           Icon = iconWifiConnect60;
449         } else {
450           iconStrength = 85;
451           Icon = iconWifiConnect85;
452         }
453       } else {
454          DeviceSignalStrength = tr("Unknown");
455       }
456       // Get the connection speed being used
457       DeviceWirelessSpeed = getWirelessSpeedForIdent( DeviceName );
458     }
459
460  }
461
462  // Set the tray icon now
463  trayIcon->setIcon(Icon);
464
465
466  displayTooltip();
467  updateWifiNetworks();
468 
469  if(!noloop){
470    QTimer::singleShot(UPDATE_MSEC,  this,  SLOT(monitorStatus()));
471  }
472
473}
474
475// If the user wants to restart the network, do so
476void NetworkTray::slotRestartNetwork() {
477  //trayIcon->showMessage( tr("Please Wait"),tr("Restarting Network"),QSystemTrayIcon::NoIcon,5000); 
478  pcbsd::Utils::restartNetworking();
479}
480
481void NetworkTray::openNetManager() {
482  QString arguments;
483  arguments = "pc-netmanager";
484  pcbsd::Utils::runShellCommand(arguments);
485}
486
487void  NetworkTray::openDeviceInfo() {
488
489  QString program = "sudo";
490  QStringList arguments;
491  if ( DeviceType == "Ethernet" )
492  {
493    arguments << "pc-ethernetconfig" << "info" << DeviceName;
494  } else {
495    arguments << "pc-wificonfig" << "info" << DeviceName;
496  }
497
498  QProcess *runCommandProc = new QProcess(this);
499  runCommandProc->start(program, arguments);
500}
501
502QString NetworkTray::getTypeForIdent( QString ident )
503{
504   NetworkInterface ifr(ident);
505   if (ifr.isWireless()) return "Wireless";
506   return "Ethernet";
507}
508
509QString NetworkTray::getStatusForIdent()
510{
511  QString inputLine = ifconfigOutput;
512  QString status = "";
513       
514  if (inputLine != "" && inputLine.indexOf("associated") != -1)
515    status = "associated";
516  else if (inputLine != "" && inputLine.indexOf("active") != -1)
517    status = "active";
518  else
519    status = "DOWN"; 
520       
521  return status;
522   
523}
524
525QString NetworkTray::getUpStatusForIdent()
526{
527  QString inputLine = ifconfigOutput;
528  QString status = "";
529       
530  if (inputLine != "" && inputLine.indexOf("<UP") != -1)
531    status = "UP";
532  else
533    status = "DOWN"; 
534       
535  return status;
536   
537}
538
539QString NetworkTray::getMediaForIdent()
540{
541  QString inputLine = ifconfigOutput;
542  QString status = "";
543
544  if (inputLine != "" && inputLine.indexOf("media:") != -1){
545    status = inputLine.remove(0, inputLine.indexOf("media:") + 7);
546    status.truncate(inputLine.indexOf("status:") - 1 );
547  }
548       
549  return status;
550}
551
552QString NetworkTray::getIPv6ForIdent()
553{
554  QString inputLine = ifconfigOutput;
555  QString ip= "";
556       
557  if (inputLine != "" && inputLine.indexOf("inet6 ") != -1){
558    ip = inputLine.remove(0, inputLine.indexOf("inet6 ") + 5);
559    ip.truncate(ip.indexOf("%"));
560  }
561       
562  return ip;
563}
564
565void NetworkTray::slotUpdateIfStatus()
566{
567   QProcess *getIfProc = new QProcess();
568   getIfProc->start(IFCONFIG, QStringList() << DeviceName);
569   while(getIfProc->state() == QProcess::Starting || getIfProc->state() == QProcess::Running) {
570      getIfProc->waitForFinished(50);
571      //QCoreApplication::processEvents();
572   }
573
574   ifconfigOutput.clear();
575   ifconfigOutput = getIfProc->readAllStandardOutput().simplified();
576
577   //qDebug() << IFCONFIG + " output: " << ifconfigOutput <<"\n";
578
579   getIfProc->kill();
580   delete getIfProc;
581
582   QTimer::singleShot(UPDATE_MSEC, this,  SLOT(slotUpdateIfStatus()) );
583}
584
585void NetworkTray::slotCheckWifiAvailability(){
586  if(DeviceType == "Wireless"){
587    // Get the device up status
588    DeviceStatus = getStatusForIdent();
589    //Show a message if the wifi is down
590    if(DeviceStatus == "DOWN"){
591      trayIcon->showMessage( tr("No Wireless Network Connection"),tr("Click here to configure wireless connections"),QSystemTrayIcon::NoIcon,15000);
592    }
593  }
594}
595
596void NetworkTray::updateWifiNetworks(){
597  // Change the right-click of the tray icon to show all available wireless networks
598 
599  //update the list of wifi networks available
600  QString cmd = "ifconfig "+DeviceName+" list scan";
601  QStringList wifinet = pcbsd::Utils::runShellCommand(cmd);
602 
603 //Redo the tray menu
604  trayIconMenu = new QMenu(this);
605  trayActionGroup = new QActionGroup(this);
606  trayIconMenu->clear();
607  //QAction *act = trayIconMenu->addAction( tr("Wifi Quick-Connect") );
608  //act->setEnabled(false);
609  trayIconMenu->addSeparator();
610  QIcon ssidIcon;
611 //add an entry for each wifi network detected
612  for(int i=1; i<wifinet.length(); i++){ //skip the first line (labels)
613    //Get the ssid and Security for this network
614    QStringList wdata = NetworkInterface::parseWifiScanLine(wifinet[i],false);
615    QString ssid = wdata[0];
616    QString strength = wdata[4];
617    //Add this network to the list
618    QString entry = ssid+" ("+strength+")"; // SSID (%Strength)
619    //Get the proper "locked" or "unlocked" icon for the network
620    if(wdata[6].contains("None")){
621      ssidIcon = iconUnlocked;
622    }else{
623      ssidIcon = iconLocked;
624    }
625    //Make sure there is an ssid (don't show blank entry points)
626    if( !ssid.isEmpty() ){
627
628    //Check for duplicate SSID entries
629    bool duplicateSSID = FALSE;
630    int dupRow;
631    for ( int z = 0 ; z < trayIconMenu->actions().count() ; z++){
632      //qDebug() << listWifi->item(z)->text() << ssid;
633      if ( trayIconMenu->actions()[z]->text().contains(ssid+" (") ){
634        duplicateSSID = TRUE;
635        dupRow = z;
636        break;
637      }
638    }
639    if(!duplicateSSID){
640      //Create the action
641      QAction* tempAct = new QAction(entry, this); //set the label for the action on creation
642      tempAct->setObjectName(wdata[0]); //set the action name as the SSID
643      tempAct->setIcon(ssidIcon); //set the action icon
644      //add the action to the action group
645      trayActionGroup->addAction(tempAct); 
646      //Add the action to the menu
647      trayIconMenu->addAction(tempAct);
648    }else{
649      //Check if the new signal strength is greater, replace if it is
650      QString oldStrength = trayIconMenu->actions()[dupRow]->text();
651      oldStrength = oldStrength.section("(",1,1).section("%)",0,0).simplified();
652      if( strength.section("%",0,0).toInt() > oldStrength.toInt() ){
653        //New signal strength is greater - replace the string
654        //qDebug() << "Changing signal strength for "+ssid+" to reflect a stronger signal found";
655        //qDebug() << strength << oldStrength;
656        trayIconMenu->actions()[dupRow]->setText( ssid+" ("+strength+")" );
657      }
658    }
659    } //end of the empty ssid check
660  }
661  //Connect the actionGroup signal with slotQuickConnect
662  QObject::connect(trayActionGroup, SIGNAL(triggered(QAction*)),this,SLOT(slotGetNetKey(QAction*)));
663  //Add the configuration options to the bottom
664  trayIconMenu->addSeparator();
665  trayIconMenu->addAction( tr("Configure ") + DeviceName, this, SLOT(openConfigDlg()));
666  trayIconMenu->addAction( tr("Start the Network Manager"), this, SLOT(openNetManager()));
667  trayIconMenu->addAction( tr("Restart the Network"), this, SLOT(slotRestartNetwork()));
668  trayIconMenu->addAction( tr("Close the Network Monitor"), this, SLOT(slotQuit()));
669 
670  //attach the new menu to the tray
671  trayIcon->setContextMenu(trayIconMenu); 
672 
673}
674
675void NetworkTray::slotGetNetKey(QAction* act){
676  //Get the small SSID from the action
677  QString smSSID = act->objectName();
678  //trim the small ssid to remove any dots at the end
679  smSSID = smSSID.section(".",0,0,QString::SectionSkipEmpty);
680 
681  //get the full SSID string
682  QString dat = pcbsd::Utils::runShellCommandSearch("ifconfig -v "+DeviceName+" list scan",smSSID);
683  QStringList wdat = NetworkInterface::parseWifiScanLine(dat,true);
684  QString SSID = wdat[0];
685 
686  //Get the Security Type
687  QString sectype = wdat[6];
688 
689  if(sectype == "None"){
690    //run the Quick-Connect slot without a key
691    slotQuickConnect("",SSID);
692   
693  }else{
694    //Open the dialog to prompt for the Network Security Key
695    dialogNetKey = new netKey();
696    //Insert the SSID into the dialog
697    dialogNetKey->setSSID(SSID);
698    //connect the signal from the dialog to the quick-connect slot
699    connect(dialogNetKey,SIGNAL( saved(QString,QString) ),this,SLOT( slotQuickConnect(QString,QString) ) );
700    //Activate the dialog
701    dialogNetKey->exec();
702  }
703}
704
705void NetworkTray::slotQuickConnect(QString key,QString SSID){
706 
707  //Run the wifiQuickConnect function
708  NetworkInterface::wifiQuickConnect(SSID,key,DeviceName);
709 
710  //Inform the user that it is connecting
711  QString msg = tr("Connecting to ") + SSID;
712  trayIcon->showMessage( tr("Please Wait"),msg,QSystemTrayIcon::NoIcon,10000);
713}
Note: See TracBrowser for help on using the repository browser.