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

svn at pcbsd.org svn at pcbsd.org
Fri Jan 8 09:37:14 PST 2010


Author: kris
Date: 2010-01-08 09:37:14 -0800 (Fri, 08 Jan 2010)
New Revision: 5891

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

Got networkTray fixed up now, fstat shows no more files / pipes getting opened, causing maxfiles to fill up :P



Modified: pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp	2010-01-08 16:22:26 UTC (rev 5890)
+++ pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.cpp	2010-01-08 17:37:14 UTC (rev 5891)
@@ -46,6 +46,9 @@
 
 void NetworkTray::programInit(QString Device)
 {
+  // Load the icons we'll be using into memory
+  loadIcons();
+
   // Connect our double-click slot
   connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason)));
 
@@ -81,7 +84,7 @@
   }
 
   // Add configuration button to the context menu
-  setIcon(Icon);
+  //setIcon(Icon);
   contextMenu()->clear();
   contextMenu()->addSeparator();
   contextMenu()->addAction( tr("Configure ") + DeviceName, this, SLOT(openConfigDlg()));
@@ -178,10 +181,17 @@
 }
 
 
-QString NetworkTray::getIpForIdent( QString ident )
+QString NetworkTray::getIpForIdent()
 {
-  NetworkInterface ifr(ident);
-  return ifr.ipAsString();
+  QString inputLine = ifconfigOutput;
+  QString ip= "";
+	
+  if (inputLine != "" && inputLine.indexOf("inet ") != -1){
+    ip = inputLine.remove(0, inputLine.indexOf("inet ") + 5);
+    ip.truncate(ip.indexOf(" "));
+  }
+	
+  return ip;
 }
 
 
@@ -191,7 +201,7 @@
   return ifr.macAsString();
 }
 
-QString NetworkTray::getSSIDForIdent( QString ident )
+QString NetworkTray::getSSIDForIdent()
 {
   QString inputLine = ifconfigOutput;
   QString SSID = "";
@@ -204,18 +214,19 @@
   return SSID;
 }
 
-QString NetworkTray::getStatusForIdent( QString ident )
+QString NetworkTray::getNetmaskForIdent()
 {
-  NetworkInterface ifr(ident);
-  return ifr.mediaStatusAsString();
+  QString inputLine = ifconfigOutput;
+  QString netmask= "";
+	
+  if (inputLine != "" && inputLine.indexOf("netmask ") != -1){
+    netmask = inputLine.remove(0, inputLine.indexOf("netmask ") + 8);
+    netmask.truncate(netmask.indexOf(" "));
+  }
+	
+  return netmask;
 }
 
-QString NetworkTray::getNetmaskForIdent( QString ident )
-{
-   NetworkInterface ifr(ident);
-   return ifr.netmaskAsString();        
-}
-
 QString NetworkTray::getSignalStrengthForIdent( QString ident )
 {
   QString command = "ifconfig " + ident + " scan | grep " + DeviceSSID;
@@ -289,7 +300,6 @@
      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;
@@ -305,7 +315,6 @@
      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;
@@ -325,71 +334,81 @@
    
 }
 
-void  NetworkTray::monitorStatus() {
+// Load all the icons we'll be using
+void NetworkTray::loadIcons() {
+  iconWiredConnect.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local.png"));
+  iconWiredDisconnect.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local_dis.png"));
+  iconWifiConnect.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi.png"));
+  iconWifiDisconnect.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi_dis.png"));
+  iconWifiConnect30.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi30.png"));
+  iconWifiConnect60.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi60.png"));
+  iconWifiConnect85.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi85.png"));
+}
+
+void NetworkTray::monitorStatus() {
   // Start checking to see if the device has changed, and if it has inform the user
   QString tmp;  
   QIcon Icon;
   QString NotifyText = "";
   QString filename = "/home/" + username + "/.kde4/Autostart/tray-" + DeviceName + ".desktop";
 
+
   // First run a check to see if this applet has been disabled in the network manager
   QFile testFile(filename);
   if ( ! testFile.exists() )
     exit(0);
 
-  qDebug() << "Starting Probe...\n";
-
   // Update the ifconfig output of this device
   updateIfStatus(DeviceName);
 
   // Check the media status of this device
-  DeviceMedia = getMediaForIdent( DeviceName );
+  DeviceMedia = getMediaForIdent();
 
   // Check for IPv6 Changes
-  DeviceIPv6 = getIPv6ForIdent( DeviceName);
+  DeviceIPv6 = getIPv6ForIdent();
 
   // Get the device up status
-  DeviceUpStatus = getUpStatusForIdent( DeviceName );
+  DeviceUpStatus = getUpStatusForIdent();
 
+
   if ( DeviceType == "Ethernet" )
   {
     if ( (DeviceStatus == "active" || DeviceStatus == "")  && tmp == "UP")
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local.png"));
+      Icon = iconWiredConnect;
     else
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local_dis.png"));
+      Icon = iconWiredDisconnect;
   } else {
     if ( DeviceStatus == "associated" && tmp == "UP" )
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi.png"));
+      Icon = iconWifiConnect;
     else
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi_dis.png"));
+      Icon = iconWifiDisconnect;
   }
 
 
   // First check the status of the device
-  DeviceStatus = getStatusForIdent(DeviceName);
+  DeviceStatus = getStatusForIdent();
   if ( DeviceType == "Ethernet" )
   {
-    if ( (tmp == "active" || tmp == "")  && DeviceUpStatus == "UP")
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local.png"));
+    if ( (DeviceStatus == "active" || DeviceStatus == "")  && DeviceUpStatus == "UP")
+      Icon = iconWiredConnect;
     else
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_local_dis.png"));
+      Icon = iconWiredDisconnect;
 
   } else {
-    if ( tmp == "associated" && DeviceUpStatus == "UP" )
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi.png"));
+    if ( DeviceStatus == "associated" && DeviceUpStatus == "UP" )
+      Icon = iconWifiConnect;
     else
-      Icon.addFile(KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi_dis.png"));
+      Icon = iconWifiDisconnect;
   }
 
   // Now check the IP Address for changes
-  DeviceIP = getIpForIdent(DeviceName);
+  DeviceIP = getIpForIdent();
+  DeviceNetmask = getNetmaskForIdent();
 
-  DeviceNetmask = getNetmaskForIdent( DeviceName );
-
   if ( DeviceType == "Wireless" && DeviceStatus == "associated" )
   {
     // Now check the SSID Address for changes
-    DeviceSSID = getSSIDForIdent(DeviceName);
+    DeviceSSID = getSSIDForIdent();
 
     if (! DeviceSSID.isEmpty() )
     {
@@ -406,18 +425,17 @@
 	 if ( newStrength < 5 )
          {	
 	   iconStrength = 0;
-	   FileLoad=KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi.png");
+           Icon = iconWifiConnect;
          } else if ( newStrength < 50 ) {
 	   iconStrength = 30;
-	   FileLoad=KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi30.png");
+           Icon = iconWifiConnect30;
 	 } else if ( newStrength < 75 ) {
 	   iconStrength = 60;
-	   FileLoad=KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi60.png");
+           Icon = iconWifiConnect60;
          } else {
 	   iconStrength = 85;
-	   FileLoad=KStandardDirs::locate("data", "pc-netmanager/pics/tray_wifi85.png");
+           Icon = iconWifiConnect85;
 	 }
-           Icon.addFile(FileLoad);
         }
         // Get the connection speed being used
         DeviceWirelessSpeed = getWirelessSpeedForIdent( DeviceName );
@@ -426,7 +444,6 @@
   }
 
   // Set the tray icon now
-  qDebug() << "Updating Icon...\n";
   setIcon(Icon);
 
 
@@ -439,7 +456,6 @@
 
   QTimer::singleShot(UPDATE_MSEC,  this,  SLOT(monitorStatus()));
 
-  qDebug() << "Probe Done...\n";
 }
 
 // If the user wants to restart the network, do so
@@ -528,11 +544,27 @@
    return "Ethernet";
 }
 
-QString NetworkTray::getUpStatusForIdent( QString ident )
+QString NetworkTray::getStatusForIdent()
 {
   QString inputLine = ifconfigOutput;
   QString status = "";
 	
+  if (inputLine != "" && inputLine.indexOf("associated") != -1)
+    status = "associated";
+  else if (inputLine != "" && inputLine.indexOf("active") != -1)
+    status = "active";
+  else
+    status = "DOWN";  
+	
+  return status;
+    
+}
+
+QString NetworkTray::getUpStatusForIdent()
+{
+  QString inputLine = ifconfigOutput;
+  QString status = "";
+	
   if (inputLine != "" && inputLine.indexOf("<UP") != -1)
     status = "UP";
   else
@@ -542,7 +574,7 @@
     
 }
 
-QString NetworkTray::getMediaForIdent( QString ident )
+QString NetworkTray::getMediaForIdent()
 {
   QString inputLine = ifconfigOutput;
   QString status = "";
@@ -555,7 +587,7 @@
   return status;
 }
 
-QString NetworkTray::getIPv6ForIdent( QString ident )
+QString NetworkTray::getIPv6ForIdent()
 {
   QString inputLine = ifconfigOutput;
   QString ip= "";

Modified: pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h	2010-01-08 16:22:26 UTC (rev 5890)
+++ pcbsd/trunk/pcbsd-netmanager/src/NetworkTray/NetworkTray.h	2010-01-08 17:37:14 UTC (rev 5891)
@@ -35,24 +35,32 @@
 private:
    void displayTooltip();
    void confirmDevice( QString device );
+   void loadIcons();
    QString getLineFromCommandOutput( QString command );
    QString getNameForIdent( QString ident );
-   QString getIpForIdent( QString ident );
+   QString getIpForIdent();
    QString getMacForIdent( QString ident );
-   QString getStatusForIdent( QString ident );
-   QString getSSIDForIdent( QString ident );
-   QString getNetmaskForIdent( QString ident );
+   QString getSSIDForIdent();
+   QString getNetmaskForIdent();
    QString getSignalStrengthForIdent( QString ident );
    QString getWirelessSpeedForIdent( QString ident );
    QString getValue( QString File, QString Key, int occur );
-   QString getUpStatusForIdent( QString ident );
-   QString getMediaForIdent( QString ident );
-   QString getIPv6ForIdent( QString ident );
+   QString getUpStatusForIdent();
+   QString getStatusForIdent();
+   QString getMediaForIdent();
+   QString getIPv6ForIdent();
    QString getWifiParent( QString dev );
    QString getTypeForIdent( QString ident );
    void updateIfStatus( QString ident );
    QString ifconfigOutput;
    QProcess *runCommandProc;
    QProcess *getIfProc;
+   QIcon iconWiredConnect;
+   QIcon iconWiredDisconnect;
+   QIcon iconWifiConnect;
+   QIcon iconWifiDisconnect;
+   QIcon iconWifiConnect30;
+   QIcon iconWifiConnect60;
+   QIcon iconWifiConnect85;
 
 };



More information about the Commits mailing list