[PC-BSD Commits] r8090 - pcbsd/stable/pcbsd-netmanager/src/ethernetconfig

svn at pcbsd.org svn at pcbsd.org
Tue Nov 30 08:56:32 PST 2010


Author: kris
Date: 2010-11-30 08:56:32 -0800 (Tue, 30 Nov 2010)
New Revision: 8090

Modified:
   pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp
   pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h
Log:

MFC changes to ethernetconfig, which includes being able to not use the lagg interface



Modified: pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp
===================================================================
--- pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp	2010-11-30 16:52:17 UTC (rev 8089)
+++ pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp	2010-11-30 16:56:32 UTC (rev 8090)
@@ -22,24 +22,21 @@
  *   OTHER DEALINGS IN THE SOFTWARE.                                       *
  ***************************************************************************/
 
-
-#include <qlabel.h>
-#include <qcheckbox.h>
-#include <qlineedit.h>
-#include <qmessagebox.h>
-#include <qgroupbox.h>
-#include <qfile.h>
-#include <qtabwidget.h>
 #include <iostream>
-#include <qtranslator.h>
-#include <qdesktopwidget.h>
-#include <qapplication.h>
-#include <qtimer.h>
-#include <qpushbutton.h>
-#include <qtextstream.h>
+#include <QCheckBox>
+#include <QDesktopWidget>
+#include <QFile>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QPushButton>
+#include <QSettings>
+#include <QTabWidget>
+#include <QTextStream>
+#include <QTimer>
+#include <QTranslator>
 
-#include <iostream>
-
 #include <pcbsd-netif.h>
 #include <pcbsd-utils.h>
 
@@ -112,12 +109,11 @@
   QString tmp, devices, tmp2;
 
   // Enable the lagg0 interface
-  //saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"up\"", -1);
-  saveValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
+  Utils::setConfFileValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
 
-  tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+  tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
   if ( tmp.isEmpty() ) {
-    saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
+    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
   } else {
     if ( tmp.indexOf("laggport "+ dev ) != -1 )
      tmp = tmp.remove(tmp.indexOf("laggport " + dev), 9 + dev.size()); // Remove the current laggport
@@ -132,7 +128,7 @@
       tmp = tmp.remove(tmp.indexOf("laggport "), 9 + tmp2.size()); 
     }
 
-    saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover" + devices + " laggport " + dev + " " + config + "\"", -1);
+    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover" + devices + " laggport " + dev + " " + config + "\"", -1);
   }
 }
 
@@ -148,7 +144,7 @@
     // If the user disabled the device, do so now
     if ( checkDisableNetwork->isChecked() )
     {
-      saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "", -1);
+      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "", -1);
       runCommand("ifconfig " + DeviceName + " down");
       buttonApply->setEnabled(FALSE);
       return;
@@ -188,17 +184,17 @@
 
     if ( checkIPv6Enable->isChecked() ) {
        // Get rid of the ifconfig line for the ipv6 interface
-       saveValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", "", -1);
+       Utils::setConfFileValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", "", -1);
     } else {
-       saveValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", "ipv6_ifconfig_" + DeviceName + "=\"" + lineIPv6Address->text() + "\"", -1);
+       Utils::setConfFileValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", "ipv6_ifconfig_" + DeviceName + "=\"" + lineIPv6Address->text() + "\"", -1);
     }
     
-   // Check if we are doing lagg for wifi failover
-   if ( isWifiEnabled() ) {
+   // Check if we want to use the lagg interface
+   if ( useLagg ) {
    	saveLaggLine(DeviceName, ifConfigLine);
         runCommand("ifconfig lagg0 destroy");
    } else {
-        saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "ifconfig_" + DeviceName + "=\"" + ifConfigLine + "\"", -1); 
+        Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "ifconfig_" + DeviceName + "=\"" + ifConfigLine + "\"", -1); 
    }
 
    getLineFromCommandOutput("sync");
@@ -243,109 +239,6 @@
 
 }
 
-void ethernetconfig::saveValue( QString File, QString oldKey, QString newKey, int occur )
-{
-    // Lets the dev save a value into a specified config file. The occur value tells which occurance of "oldKey" to replace
-    // If occur is set to -1, it will remove any duplicates of "oldKey"
-    
-    
-    QString SavedFile;
-
-    int found = 1;
-    int wroteKey = 0;
-    
-    int firstLine = 0;
-    
-    if ( occur == -1 && newKey.isEmpty() )
-    {
-	
-    }
-    
-    
-    // Load the old file, find the oldKey, remove it and replace with newKey
-    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 and this matches the occurance that must be processed
-            if ( line.indexOf(oldKey, 0) != -1 && wroteKey == 0 && found == occur && line.indexOf("#", 0) != 0)
-           {
-	   if ( firstLine == 0) {
-		
-	    SavedFile = SavedFile + newKey;
-	    found++;
-	    firstLine = 1;
-	    } else {
-	    SavedFile = SavedFile + "\n" + newKey;
-	    found++;	
-	    wroteKey = 1;
-	    }
-	    
-	  // If the KEY is found, and we are just on wrong occurance, save it and continue to search  
-            } else if (line.indexOf(oldKey, 0) != -1 && occur != -1 && found != occur && line.indexOf("#", 0) != 0 ) {
-	    if ( firstLine == 0) {
-	         SavedFile = SavedFile + line ;
-                        firstLine = 1;
-	     } else {
-	         SavedFile = SavedFile + "\n" + line ;     
-                   }
-	     
-	found++;
-	
-	
-             // if we are trying to remove the key, don't save it	
-            } else if (line.indexOf(oldKey, 0) != -1 && occur == -1 && newKey.isEmpty() && line.indexOf("#", 0) != 0 ) {
-	
-             // We just want one occurance of the key
-            } else if (line.indexOf(oldKey, 0) != -1 && occur == -1 && ! newKey.isEmpty() && line.indexOf("#", 0) != 0 ) {
-	   if ( firstLine == 0) {
-	       SavedFile = SavedFile + newKey;
-	       found++;
-	       firstLine = 1;
-	    } else {
-		SavedFile = SavedFile + "\n" + newKey;
-		found++;	
-		wroteKey = 1;
-	    }
-	    
-	    
-	// String not found at all
-            } else {
-	    
-	    if ( firstLine == 0) {
-	         SavedFile = SavedFile + line ;
-                        firstLine = 1;
-	     } else {
-	         SavedFile = SavedFile + "\n" + line ;     
-                   }
-	}
-	    
-	    
-	    
-        }
-	// Didnt find the key? Write it!
-	if ( wroteKey == 0 && ! newKey.isEmpty())
-	{
-	    SavedFile = SavedFile + "\n" + newKey;
-	}
-	
-        file.close();
-    }
-    
-    
-    // Save the new file
-    QFile fileout( File );
-    if ( fileout.open( QIODevice::WriteOnly ) ) {
-        QTextStream streamout( &fileout );
-                    streamout << SavedFile;
-        fileout.close();
-    }
-
-}
-
 void ethernetconfig::setDevice(QString Device)
 {
    
@@ -370,56 +263,7 @@
 	fclose(file);
 }
 
-QString ethernetconfig::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) {
-	    
-	    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++;  
-	    }
-	    
-	    
-	}
-	    
-	    
-	    
-        }
-        file.close();
-    }
-    
-    return "";
-}
-
-
 void ethernetconfig::slotDisableCheck()
 {
   if ( checkDisableNetwork->isChecked() )
@@ -579,14 +423,16 @@
 void ethernetconfig::slotFinishLoad()
 {
    QString tmp, tmp2;
-   useLagg = true;
-   // Start loading the device information, first lagg0, then DeviceName
-   tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
-   if ( tmp.isEmpty() )  {
-      tmp = getValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
-      useLagg = false;
-   }
 
+   QSettings settings("PCBSD");
+   useLagg = settings.value("/pc-netmanager/useLagg", false).toBool();
+
+   // Start loading the device information
+   if ( useLagg )
+      tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+   else
+      tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
+
    if ( tmp.isEmpty() ) {
       checkDisableNetwork->setChecked(TRUE);
       tabMainWidget->setEnabled(FALSE);
@@ -657,7 +503,7 @@
 
   // Check for the IPv6 Configuration
   // Start loading the device information
-   tmp = getValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", 1 );
+   tmp = Utils::getConfFileValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", 1 );
    if ( tmp.isEmpty() ) {
         checkIPv6Enable->setChecked(TRUE);
    } else {

Modified: pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h
===================================================================
--- pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h	2010-11-30 16:52:17 UTC (rev 8089)
+++ pcbsd/stable/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h	2010-11-30 16:56:32 UTC (rev 8090)
@@ -56,8 +56,6 @@
 
 private:
     virtual void runCommand( QString command );
-    virtual void saveValue( QString File, QString oldKey, QString newKey, int occur );
-    virtual QString getValue( QString File, QString Key, int occur );
     virtual QString getNetmaskForIdent( QString ident );
     virtual QString getOutErrorsForIdent(QString ident);
     virtual QString getOutPacketsForIdent(QString ident);



More information about the Commits mailing list