[PC-BSD Commits] r5784 - pcbsd/trunk/pcbsd-netmanager/src/NetworkTray

svn at pcbsd.org svn at pcbsd.org
Tue Jan 5 11:06:02 PST 2010


Author: kris
Date: 2010-01-05 11:06:01 -0800 (Tue, 05 Jan 2010)
New Revision: 5784

Modified:
   pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp
   pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h
Log:

Updated the network tray, should help address crashing issues, plus make it more efficient



Modified: pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp	2010-01-05 16:18:43 UTC (rev 5783)
+++ pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp	2010-01-05 19:06:01 UTC (rev 5784)
@@ -8,6 +8,7 @@
 #include <qtranslator.h>
 #include <qtextstream.h>
 #include <qmenu.h>
+#include <QDebug>
 
 /* KDE */
 #include <kiconloader.h>
@@ -22,7 +23,7 @@
 
 
 /* Update interval in ms */
-#define  UPDATE_MSEC 4000
+#define  UPDATE_MSEC 6000
 
 // Public Variables
 QString DeviceName;
@@ -40,77 +41,45 @@
 QString DeviceIdent;
 QString DeviceNetmask;
 QString DeviceMedia;
-QString DeviceGateway;
 QString username;
 
 
 void NetworkTray::programInit(QString Device)
 {
-    // Connect our double-click slot
-    connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason)));
+  // Connect our double-click slot
+  connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason)));
 
-    QString tmp;
-    QIcon Icon;
-    DeviceName = Device;
-    DeviceType = getTypeForIdent(DeviceName);
+  QString tmp;
+  QIcon Icon;
+  DeviceName = Device;
+  DeviceType = getTypeForIdent(DeviceName);
 
-    username = QString::fromLocal8Bit(getenv("LOGNAME"));
-    
-    // Confirm this is a legit device
-    confirmDevice(DeviceName); 
+  // Get the username of the person we are running as
+  username = QString::fromLocal8Bit(getenv("LOGNAME"));
+  
+  // Confirm this is a legit device
+  confirmDevice(DeviceName); 
 
-    DeviceStatus = getStatusForIdent( DeviceName );
-    DeviceIP = getIpForIdent( DeviceName );
-    DeviceIPv6 = getIPv6ForIdent( DeviceName);
-    DeviceMAC = getMacForIdent( DeviceName );
-    DeviceStatus = getStatusForIdent( DeviceName );
-    if ( DeviceName.indexOf("wlan") != -1 )
-    {
-       DeviceParent = getWifiParent(DeviceName);
+  // Update the ifconfig line we will be parsing
+  updateIfStatus(DeviceName);
 
-       // Get HW Identify line
-       DeviceIdent = getNameForIdent(DeviceParent);
+  // Get the MAC for this device
+  DeviceMAC=getMacForIdent(DeviceName);
 
-       //QMessageBox::warning( this, "Testing", DevsName[i]);
-       // If the name comes up bogus for some reason
-       if( DeviceIdent.isEmpty() ) {
-          DeviceIdent = tr("Unknown Wireless Device");
-      }
-    } else {
-      DeviceIdent = getNameForIdent( DeviceName );
-    }
-    DeviceNetmask = getNetmaskForIdent( DeviceName );
-    DeviceUpStatus = getUpStatusForIdent( DeviceName );
-    DeviceMedia = getMediaForIdent( DeviceName );
-    DeviceGateway = getGatewayForIdent( DeviceName );
+  if ( DeviceName.indexOf("wlan") != -1 )
+  {
+     DeviceParent = getWifiParent(DeviceName);
 
-//QMessageBox::information( this, "Application name",  "IP: " );
+     // Get HW Identify line
+     DeviceIdent = getNameForIdent(DeviceParent);
 
+     // If the name comes up bogus for some reason
+     if ( DeviceIdent.isEmpty() ) 
+       DeviceIdent = tr("Unknown Wireless Device");
+  } else {
+      DeviceIdent = getNameForIdent( DeviceName );
+  }
 
-    if ( DeviceType == "Ethernet" )
-    {
-        if ( (DeviceStatus == "active" || DeviceStatus == "") && DeviceUpStatus == "UP" )
-        {
-	   Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local.png"));
-	} else {
-    	   Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local_dis.png"));
-        }
-    } else {
-        if ( DeviceStatus == "associated" && DeviceUpStatus == "UP" )
-        {
-	   Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi.png"));
-	} else {
-    	   Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi_dis.png"));
-        }
-        DeviceSSID = getSSIDForIdent(DeviceName);
-        if (! DeviceSSID.isEmpty() )
-	{
-	  DeviceSignalStrength = getSignalStrengthForIdent( DeviceName );
-	  DeviceWirelessSpeed = getWirelessSpeedForIdent(DeviceName);
-	}
-    }
-
-
   // Add configuration button to the context menu
   setIcon(Icon);
   contextMenu()->clear();
@@ -122,34 +91,28 @@
   contextMenu()->addAction( tr("Restart the Network"), this, SLOT(slotRestartNetwork()));
 
   // Check if we are on a ethernet device and PPPOE is enabled
-     if ( DeviceType == "Ethernet" )
-    {
-        // Check for PPPOE configuration
-	tmp = getValue( "/etc/rc.conf", "ppp_enable=", 1 );
-	if ( tmp == "YES") {
- 	  QFile filein( "/etc/ppp/ppp.conf" );
-       	 
-     	  QString ProfileName = "internet";
+  if ( DeviceType == "Ethernet" )
+  {
+     // Check for PPPOE configuration
+     tmp = getValue( "/etc/rc.conf", "ppp_enable=", 1 );
+     if ( tmp == "YES") {
+        QFile filein( "/etc/ppp/ppp.conf" );
+    	QString ProfileName = "internet";
           
-	  // Now load the ppp.conf file
-	  if ( filein.open( QIODevice::ReadOnly ) ) {
-          QTextStream stream( &filein );
-          QString line;
-          while ( !stream.atEnd() ) {
-            line = stream.readLine(); // line of text excluding '\n'
+	// Now load the ppp.conf file
+	if ( filein.open( QIODevice::ReadOnly ) ) {
+        QTextStream stream( &filein );
+        QString line;
+        while ( !stream.atEnd() ) {
+          line = stream.readLine(); // line of text excluding '\n'
 
-	    // Check if we are on a profile line
-	    if ( line.indexOf(":") == line.length() -1  ) {
-		if ( line.indexOf(ProfileName) != -1 ) {
-		    // If we find the existing profile for this device, add the context menu shortcuts
-		     contextMenu()->addSeparator();
-  		     contextMenu()->addAction( tr("Connect to PPPoE service."), this, SLOT(slotEnablePPPOE()));
-		     contextMenu()->addAction( tr("Disconnect from PPPoE service."), this, SLOT(slotDisablePPPOE()));
-
-		} 
-	    }
-
-
+          // Check if we are on a profile line
+	  if ( line.indexOf(":") == line.length() -1 && line.indexOf(ProfileName) != -1  ) {
+	    // If we find the existing profile for this device, add the context menu shortcuts
+	    contextMenu()->addSeparator();
+  	    contextMenu()->addAction( tr("Connect to PPPoE service."), this, SLOT(slotEnablePPPOE()));
+	    contextMenu()->addAction( tr("Disconnect from PPPoE service."), this, SLOT(slotDisablePPPOE()));
+	  }
 	}
      }
 
@@ -161,7 +124,8 @@
   displayTooltip();
 
   // Start the monitor service
-  QTimer::singleShot(UPDATE_MSEC,  this,  SLOT(monitorStatus()));
+  //QTimer::singleShot(UPDATE_MSEC,  this,  SLOT(monitorStatus()));
+  monitorStatus();
 
 }
 
@@ -176,48 +140,41 @@
 
 void NetworkTray::confirmDevice( QString device )
 {
-        QString command = "ifconfig -l | grep " + device;
-        QString line = getLineFromCommandOutput(command);
-        if ( line.isEmpty() )
-        {
-           // Opps, this device doesn't seem to exist!
-           // First run a check to see if this device has a auto-start .desktop associated with it
-           QFile desktopfile("/home/" + username + "/.kde4/Autostart/tray-" + device + ".desktop");
-           if ( desktopfile.exists() )
-           {
-              // Remove this file
-              desktopfile.remove();
-           }
-           exit(1);
-        }
+   QString command = "ifconfig -l | grep " + device;
+   QString line = getLineFromCommandOutput(command);
+   if ( line.isEmpty() )
+   {
+      // Opps, this device doesn't seem to exist!
+      // First run a check to see if this device has a auto-start .desktop associated with it
+      QFile desktopfile("/home/" + username + "/.kde4/Autostart/tray-" + device + ".desktop");
+      if ( desktopfile.exists() )
+         desktopfile.remove(); // Remove this file
+      exit(1);
+   }
 }
 
 QString NetworkTray::getLineFromCommandOutput( QString command )
 {
-	FILE *file = popen(command.toLatin1(),"r"); 
+  FILE *file = popen(command.toLatin1(),"r"); 
 	
-	char buffer[100];
+  char buffer[100];
 	
-	QString line = ""; 
-	char firstChar;
+  QString line = ""; 
+  char firstChar;
 	
-	if ((firstChar = fgetc(file)) != -1){
-		line += firstChar;
-		line += fgets(buffer,100,file);
-	}
-	
-	
-	pclose(file);
-	
-	
-	return line;
+  if ((firstChar = fgetc(file)) != -1){
+     line += firstChar;
+     line += fgets(buffer,100,file);
+  }
+  pclose(file);
+  return line;
 }
 
 
 QString NetworkTray::getNameForIdent( QString ident )
 {
-    NetworkInterface ifr(ident);
-    return ifr.desc();
+  NetworkInterface ifr(ident);
+  return ifr.desc();
 }
 
 
@@ -236,20 +193,15 @@
 
 QString NetworkTray::getSSIDForIdent( QString ident )
 {
-    	QString command = "nice ifconfig " +ident + " | grep \"ssid\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString SSID = "";
+  QString inputLine = ifconfigOutput;
+  QString SSID = "";
 	
-	if (inputLine != "" && inputLine.indexOf("ssid ") != -1){
-	 
-		SSID = inputLine.remove(0, inputLine.indexOf(" ") + 1);
-		SSID.truncate(inputLine.indexOf("channel") - 1 );
-	}
+  if (inputLine != "" && inputLine.indexOf("ssid ") != -1){
+    SSID = inputLine.remove(0, inputLine.indexOf(" ") + 1);
+    SSID.truncate(inputLine.indexOf("channel") - 1 );
+  }
 	
-	return SSID;
-	
-
-
+  return SSID;
 }
 
 QString NetworkTray::getStatusForIdent( QString ident )
@@ -266,42 +218,39 @@
 
 QString NetworkTray::getSignalStrengthForIdent( QString ident )
 {
+  QString command = "ifconfig " + ident + " scan | grep " + DeviceSSID;
+  QString line = getLineFromCommandOutput(command);
+  QString tmp;
 	
-	QString command = "ifconfig " + ident + " scan | grep " + DeviceSSID;
-	QString line = getLineFromCommandOutput(command);
-        QString tmp;
-	
-        // Get the signal strength of this device
-        tmp = line;
-        tmp = tmp.simplified();
+  // Get the signal strength of this device
+  tmp = line.simplified();
 
-        // First remove the SSID which may have spaces in it
-        tmp.remove(0, tmp.indexOf(":"));
+  // First remove the SSID which may have spaces in it
+  tmp.remove(0, tmp.indexOf(":"));
 
-        // Now find the strength section
-        tmp = tmp.section(" ", 3, 3);
-        tmp.truncate(tmp.indexOf(":"));
+  // Now find the strength section
+  tmp = tmp.section(" ", 3, 3);
+  tmp.truncate(tmp.indexOf(":"));
 
-	return tmp;	
+  return tmp;	
 }
 
 QString NetworkTray::getWirelessSpeedForIdent( QString ident )
 {
-	
-	QString command = "ifconfig " + ident + " list scan | grep " + DeviceSSID;
-	QString line = getLineFromCommandOutput(command);
-        QString tmp;
+  QString command = "ifconfig " + ident + " list scan | grep " + DeviceSSID;
+  QString line = getLineFromCommandOutput(command);
+  QString tmp;
 
-        // Get the signal strength of this device
-        tmp = line;
-        tmp = tmp.simplified();
+  // Get the signal strength of this device
+  tmp = line;
+  tmp = tmp.simplified();
 
-        // First remove the SSID which may have spaces in it
-        tmp.remove(0, tmp.indexOf(":"));
+  // First remove the SSID which may have spaces in it
+  tmp.remove(0, tmp.indexOf(":"));
 
-        // Now find the Speed section
-        tmp = tmp.section(" ", 2, 2);
-        return tmp;
+  // Now find the Speed section
+  tmp = tmp.section(" ", 2, 2);
+  return tmp;
 }
 
 void NetworkTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) {
@@ -313,74 +262,66 @@
 
 void  NetworkTray::openConfigDlg() {
 
-	if ( DeviceType == "Ethernet" )
-	{
-           QString program = "kdesu";
-           QStringList arguments;
-           arguments << "--noignorebutton" << "-d" << "pc-ethernetconfig " + DeviceName;
-	   QProcess *runCommandProc = new QProcess(this);
-           runCommandProc->start(program, arguments);
-	} else {
-	   QString program = "kdesu";
-           QStringList arguments;
-           arguments << "--noignorebutton" << "-d" << "pc-wificonfig " + DeviceName;
-	   QProcess *runCommandProc = new QProcess(this);
-           runCommandProc->start(program, arguments);
-	}
+  if ( DeviceType == "Ethernet" )
+  {
+    QString program = "kdesu";
+    QStringList arguments;
+    arguments << "--noignorebutton" << "-d" << "pc-ethernetconfig " + DeviceName;
+    QProcess *runCommandProc = new QProcess(this);
+    runCommandProc->start(program, arguments);
+  } else {
+    QString program = "kdesu";
+    QStringList arguments;
+    arguments << "--noignorebutton" << "-d" << "pc-wificonfig " + DeviceName;
+    QProcess *runCommandProc = new QProcess(this);
+    runCommandProc->start(program, arguments);
+  }
 
 }
 
 void  NetworkTray::displayTooltip() {
 
+  QString  tooltipStr;
+  tooltipStr = QString(tr("Device Name:") + " /dev/" + DeviceName);
+  tooltipStr += "<br>" + DeviceIdent +"<hr>";
+  if ( DeviceType == "Ethernet" )
+  {
+     if ( DeviceStatus == "active" || DeviceStatus == "" ) {
+       tooltipStr += "<br>" + tr("IP:") + " " + DeviceIP;
+       tooltipStr += "<br>" + tr("IPv6:") + " " + DeviceIPv6;
+       tooltipStr += "<br>" + tr("Netmask:") + " " + DeviceNetmask;
+       tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
+       tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
+       tooltipStr += "<br>" + tr("Status:") + " " + DeviceUpStatus;
+     } else {
+       tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
+       tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
+       tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
+       tooltipStr += "<br>" + tr("No connection detected.<br> Check your cable connection and try again!");
+     }
 
-   QString  tooltipStr;
+   } else {
+     // If this is a wireless device, give different output
+     if ( DeviceStatus == "associated" ) {
+	tooltipStr += "<br>" + tr("IP:") + " " + DeviceIP;
+	tooltipStr += "<br>" + tr("IPv6:") + " " + DeviceIPv6;
+	tooltipStr += "<br>" + tr("Netmask:") + " " + DeviceNetmask;
+      	tooltipStr += "<br>" + tr("SSID:") + " " + DeviceSSID;
+      	tooltipStr += "<br>" + tr("Connection Strength:") + " " + DeviceSignalStrength + "%";
+      	tooltipStr += "<br>" + tr("Connection Speed:") + " " + DeviceWirelessSpeed;
+	tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
+	tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
+   	tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
+      } else {
+	tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
+	tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
+   	tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
+	tooltipStr += "<br>" + tr("No wireless connection detected.<br> Double-click to start the wireless configuration wizard.");
+      }
+   }
 
-   tooltipStr = QString(tr("Device Name:") + " /dev/" + DeviceName);
-
-   tooltipStr += "<br>" + DeviceIdent +"<hr>";
-
-
-       if ( DeviceType == "Ethernet" )
-       {
-            if ( DeviceStatus == "active" || DeviceStatus == "" ) {
-   		tooltipStr += "<br>" + tr("IP:") + " " + DeviceIP;
-	        tooltipStr += "<br>" + tr("IPv6:") + " " + DeviceIPv6;
-		tooltipStr += "<br>" + tr("Netmask:") + " " + DeviceNetmask;
-		tooltipStr += "<br>" + tr("Gateway:") + " " + DeviceGateway;
-		tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
-		tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
-   		tooltipStr += "<br>" + tr("Status:") + " " + DeviceUpStatus;
-	    } else {
-   		tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
-		tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
-   		tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
-		tooltipStr += "<br>" + tr("No connection detected.<br> Check your cable connection and try again!");
-	    }
-
-       } else {
-	// If this is a wireless device, give different output
-            if ( DeviceStatus == "associated" ) {
-		tooltipStr += "<br>" + tr("IP:") + " " + DeviceIP;
-		tooltipStr += "<br>" + tr("IPv6:") + " " + DeviceIPv6;
-		tooltipStr += "<br>" + tr("Netmask:") + " " + DeviceNetmask;
-		tooltipStr += "<br>" + tr("Gateway:") + " " + DeviceGateway;
-      		tooltipStr += "<br>" + tr("SSID:") + " " + DeviceSSID;
-      		tooltipStr += "<br>" + tr("Connection Strength:") + " " + DeviceSignalStrength + "%";
-      		tooltipStr += "<br>" + tr("Connection Speed:") + " " + DeviceWirelessSpeed;
-		tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
-		tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
-   		tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
-	    } else {
-		tooltipStr += "<br>" + tr("Mac/Ether:") + " " + DeviceMAC;
-		tooltipStr += "<br>" + tr("Media:") + " " + DeviceMedia;
-   		tooltipStr += "<br>" + tr("Status:") + " " + DeviceStatus;
-		tooltipStr += "<br>" + tr("No wireless connection detected.<br> Double-click to start the wireless configuration wizard.");
-	    }
-       }
-
-   // Update the tooltop
-   setToolTip(tooltipStr);
-
+  // Update the tooltop
+  setToolTip(tooltipStr);
    
 }
 
@@ -401,6 +342,9 @@
     exit(0);
   }
 
+  // Update the ifconfig output of this device
+  updateIfStatus(DeviceName);
+
   // Check the media status of this device
   tmp = getMediaForIdent( DeviceName );
   if ( DeviceMedia != tmp )
@@ -410,18 +354,6 @@
      updateTooltip = 1;
   }
 
-  // Check for Gateway Changes
-  tmp = getGatewayForIdent( DeviceName);
-  if ( DeviceGateway != tmp )
-  {
-     NotifyText+="Gateway changed to: " + tmp + "<br>";
-     displayPassivePopup = 1;
-     // Save the status as the new status now
-     DeviceGateway= tmp;
-     updateTooltip = 1;
-  }
-
-
   // Check for IPv6 Changes
   tmp = getIPv6ForIdent( DeviceName);
   if ( DeviceIPv6 != tmp )
@@ -564,145 +496,122 @@
 		FileLoad=KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi85.png");
 	  }
 
-	  // If the strength has changed enough, change the loaded icon
-  	  if ( DeviceSavedStrength != iconStrength  )
-	  {
-		QIcon Icon3;
-	 	DeviceSavedStrength = iconStrength;
+	 // If the strength has changed enough, change the loaded icon
+  	 if ( DeviceSavedStrength != iconStrength  )
+	 {
+	  QIcon Icon3;
+	  DeviceSavedStrength = iconStrength;
+          Icon3.addFile(FileLoad);
+          setIcon(Icon3);
+         }
 
-             	Icon3.addFile(FileLoad);
-     	     	setIcon(Icon3);
-	  }
+        }
+        DeviceSignalStrength = tmp; 
+        updateTooltip = 1;
 
-          }
-          DeviceSignalStrength = tmp; 
-          updateTooltip = 1;
+        // Get the connection speed being used
+        DeviceWirelessSpeed = getWirelessSpeedForIdent( DeviceName );
+        updateTooltip = 1;
+    }
 
-          // Get the connection speed being used
-          DeviceWirelessSpeed = getWirelessSpeedForIdent( DeviceName );
-          updateTooltip = 1;
-	}
+  }
 
-   }
 
-
-   if ( updateTooltip == 1)
-   {
-	// Show the notification that something important changed
-      if ( displayPassivePopup == 1) {
-
+  if ( updateTooltip == 1)
+  {
+    // Show the notification that something important changed
+    if ( displayPassivePopup == 1) {
       Icon2.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/info.png"));
- 
-     	KPassivePopup::message("Device " + DeviceName + ":", NotifyText,  Icon2.pixmap(22,22),  this);
-      }
+      KPassivePopup::message("Device " + DeviceName + ":", NotifyText,  Icon2.pixmap(22,22),  this);
+    }
+    displayTooltip();
+  }
 
-      displayTooltip();
-   }
 
+  // First run a check to see if this applet has been disabled in the network manager
+  if ( ! QFile::exists( filename ) )
+    close(0);
 
-     // First run a check to see if this applet has been disabled in the network manager
-    if ( ! QFile::exists( filename ) )
-    {
-      close(0);
-    }
-
-   QTimer::singleShot(UPDATE_MSEC,  this,  SLOT(monitorStatus()));
+  QTimer::singleShot(UPDATE_MSEC,  this,  SLOT(monitorStatus()));
 }
 
 // If the user wants to restart the network, do so
 void NetworkTray::slotRestartNetwork() {
-    QString program = "kdesu";
-    QStringList arguments;
-    arguments << "--noignorebutton" << "-d" << "/etc/rc.d/netif restart ; /etc/rc.d/routing restart ; /etc/rc.d/ppp restart";
-    QProcess *runCommandProc = new QProcess(this);
-    runCommandProc->start(program, arguments);
+  QString program = "kdesu";
+  QStringList arguments;
+  arguments << "--noignorebutton" << "-d" << "/etc/rc.d/netif restart ; /etc/rc.d/routing restart ; /etc/rc.d/ppp restart";
+  QProcess *runCommandProc = new QProcess(this);
+  runCommandProc->start(program, arguments);
 }
 
 void NetworkTray::slotEnablePPPOE() {
-    QString ProfileName = "internet";
-    QString program = "kdesu";
-    QStringList arguments;
-    arguments << "--noignorebutton" << "-d" << "ppp -background " + ProfileName;
-    QProcess *runCommandProc = new QProcess(this);
-    runCommandProc->start(program, arguments);
+  QString ProfileName = "internet";
+  QString program = "kdesu";
+  QStringList arguments;
+  arguments << "--noignorebutton" << "-d" << "ppp -background " + ProfileName;
+  QProcess *runCommandProc = new QProcess(this);
+  runCommandProc->start(program, arguments);
 }
 void NetworkTray::slotDisablePPPOE() {
-    QString program = "kdesu";
-    QStringList arguments;
-    arguments << "--noignorebutton" << "-d" << "kilalll ppp";
-    QProcess *runCommandProc = new QProcess(this);
-    runCommandProc->start(program, arguments);
+  QString program = "kdesu";
+  QStringList arguments;
+  arguments << "--noignorebutton" << "-d" << "kilalll ppp";
+  QProcess *runCommandProc = new QProcess(this);
+  runCommandProc->start(program, arguments);
 }
 
 void NetworkTray::openNetManager() {
-    QString program = "kcmshell4";
-    QStringList arguments;
-    arguments << "pcnetwork";
-    QProcess *runCommandProc = new QProcess(this);
-    runCommandProc->start(program, arguments);
+  QString program = "kcmshell4";
+  QStringList arguments;
+  arguments << "pcnetwork";
+  QProcess *runCommandProc = new QProcess(this);
+  runCommandProc->start(program, arguments);
 }
 
 QString NetworkTray::getValue( QString File, QString Key, int occur ) {
 
-int found = 1;
-    
-    QFile file( File );
-    if ( file.open( QIODevice::ReadOnly ) ) {
-        QTextStream stream( &file );
-        QString line;
-        while ( !stream.atEnd() ) {
-            line = stream.readLine(); // line of text excluding '\n'
-            
-               // If the KEY is found in the line, continue processing 
-	if ( line.indexOf(Key, 0) != -1 && line.indexOf("#", 0) != 0)
-	{
-	    if ( found == occur) {
+  int found = 1;
+  QFile file( File );
+  if ( file.open( QIODevice::ReadOnly ) ) {
+    QTextStream stream( &file );
+    QString line;
+    while ( !stream.atEnd() ) {
+      line = stream.readLine(); // line of text excluding '\n'
+      // If the KEY is found in the line, continue processing 
+      if ( line.indexOf(Key, 0) != -1 && line.indexOf("#", 0) != 0) {
+         if ( found == occur) {
+         line.remove(line.indexOf(Key, 0), Key.length());
+	 // Remove any quotes
+	 if ( line.indexOf('"') == 0 )
+	 line = line.remove(0, 1);
 	    
-	    line.remove(line.indexOf(Key, 0), Key.length());
-	       
-	    
-	    // Remove any quotes
-	    if ( line.indexOf('"') == 0 )
-	    {
-		line = line.remove(0, 1);
-	    }
-	    
-	    if ( line.indexOf('"') != -1  )
-	    {
-		line.truncate(line.indexOf('"'));
-	    }
-
-	    return line;
-	    
-	    } else {
-	       found++;  
-	    }
-	    
-	    
-	}
-	    
-	    
-	    
+  	  if ( line.indexOf('"') != -1  )
+	    line.truncate(line.indexOf('"'));
+	  return line;
+        } else {
+          found++;  
         }
-        file.close();
+      }
     }
-    
-    return "";
+    file.close();
+  }
+
+  return "";
 }
 
 void  NetworkTray::openDeviceInfo() {
 
-        QString program = "kdesu";
-        QStringList arguments;
-	if ( DeviceType == "Ethernet" )
-	{
-           arguments << "--noignorebutton" << "-d" << "pc-ethernetconfig info " + DeviceName;
-	} else {
-           arguments << "--noignorebutton" << "-d" << "pc-wificonfig info " + DeviceName;
-	}
-        QProcess *runCommandProc = new QProcess(this);
-        runCommandProc->start(program, arguments);
+  QString program = "kdesu";
+  QStringList arguments;
+  if ( DeviceType == "Ethernet" )
+  {
+    arguments << "--noignorebutton" << "-d" << "pc-ethernetconfig info " + DeviceName;
+  } else {
+    arguments << "--noignorebutton" << "-d" << "pc-wificonfig info " + DeviceName;
+  }
 
+  QProcess *runCommandProc = new QProcess(this);
+  runCommandProc->start(program, arguments);
 }
 
 QString NetworkTray::getTypeForIdent( QString ident )
@@ -714,67 +623,50 @@
 
 QString NetworkTray::getUpStatusForIdent( QString ident )
 {
-        	QString command = "nice ifconfig " +ident + " | grep \"flags=\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString status = "";
+  QString inputLine = ifconfigOutput;
+  QString status = "";
 	
-	if (inputLine != "" && inputLine.indexOf("<UP") != -1){
-	    status = "UP";
-	} else {
-	    status = "DOWN";  
-	}
+  if (inputLine != "" && inputLine.indexOf("<UP") != -1)
+    status = "UP";
+  else
+    status = "DOWN";  
 	
-	return status;
+  return status;
     
 }
 
 QString NetworkTray::getMediaForIdent( QString ident )
 {
-    	QString command = "nice ifconfig " +ident + " | grep \"media:\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString status = "";
-	
-	if (inputLine != "" && inputLine.indexOf("media:") != -1){
-		
-		status = inputLine.remove(0, inputLine.indexOf("media:") + 7);
-		status.truncate(inputLine.indexOf("\n") );
-	
-	}
-	
-	return status;
-	
+  QString inputLine = ifconfigOutput;
+  QString status = "";
 
-
+  if (inputLine != "" && inputLine.indexOf("media:") != -1){
+    status = inputLine.remove(0, inputLine.indexOf("media:") + 7);
+    status.truncate(inputLine.indexOf("status:") - 1 );
+  }
+	
+  return status;
 }
 
 QString NetworkTray::getIPv6ForIdent( QString ident )
 {
-	QString command = "nice ifconfig " +ident + " | grep \"inet6 \"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString ip= "";
+  QString inputLine = ifconfigOutput;
+  QString ip= "";
 	
-	if (inputLine != "" && inputLine.indexOf("inet6 ") != -1){
-		
-		ip = inputLine.remove(0, inputLine.indexOf("inet6 ") + 5);
-		ip.truncate(ip.indexOf("%"));
-		
-		
-	}
+  if (inputLine != "" && inputLine.indexOf("inet6 ") != -1){
+    ip = inputLine.remove(0, inputLine.indexOf("inet6 ") + 5);
+    ip.truncate(ip.indexOf("%"));
+  }
 	
-	return ip;
+  return ip;
 }
 
-QString NetworkTray::getGatewayForIdent( QString ident )
+void NetworkTray::updateIfStatus( QString ident )
 {
-        QString command = "nice netstat -n -r | grep \"default\" | grep " + ident;
-	QString inputLine = getLineFromCommandOutput(command);
-	QString packets = "";
-	
-	if (inputLine != "" ){
-		inputLine = inputLine.simplified();
-		packets = inputLine.section(' ', 1, 1 );
-	}
-	
-	return packets;
+   ifconfigOutput.clear();
+   QProcess p;
+   p.start(QString("ifconfig"), QStringList() << ident);
+   if (p.waitForFinished())
+     ifconfigOutput = p.readAllStandardOutput().simplified();
+   //qDebug() << "ifconfig output: " << ifconfigOutput <<"\n";
 }
-

Modified: pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h	2010-01-05 16:18:43 UTC (rev 5783)
+++ pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h	2010-01-05 19:06:01 UTC (rev 5784)
@@ -48,9 +48,10 @@
    QString getUpStatusForIdent( QString ident );
    QString getMediaForIdent( QString ident );
    QString getIPv6ForIdent( QString ident );
-   QString getGatewayForIdent( QString ident );
    QString getWifiParent( QString dev );
    QString getTypeForIdent( QString ident );
+   void updateIfStatus( QString ident );
+   QString ifconfigOutput;
    QProcess *runCommandProc;
 
 };



More information about the Commits mailing list