[PC-BSD Commits] r7943 - in pcbsd/current/src-qt4/pc-netmanager/src: NetworkManager NetworkTray ethernetconfig wificonfig
svn at pcbsd.org
svn at pcbsd.org
Fri Oct 29 09:56:45 PDT 2010
Author: kris
Date: 2010-10-29 09:56:45 -0700 (Fri, 29 Oct 2010)
New Revision: 7943
Modified:
pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp
pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.h
pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.ui
pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.cpp
pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.h
pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp
pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.h
pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h
Log:
Large update to Network Manager. Added toggle for using lagg0 device
with wifi/wired, cleanup wifi / ethernet tools to use libpcbsd functions
Modified: pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp 2010-10-29 16:56:45 UTC (rev 7943)
@@ -12,14 +12,16 @@
#include <iostream>
#include <QDir>
#include <QFile>
+#include <QMenu>
+#include <QSettings>
+#include <QString>
#include <QTemporaryFile>
#include <QTextStream>
+#include <pcbsd-netif.h>
+#include <pcbsd-utils.h>
+
#include "networkman.h"
#include "ui_networkman.h"
-#include <pcbsd-netif.h>
-#include <pcbsd-utils.h>
-#include <qstring.h>
-#include <QMenu>
#include "../../../config.h"
// Set our max number of wlan[0-9] devices we'll support
@@ -360,7 +362,7 @@
// Check to see if the network tray icon is enabled or not
- QString filename = PREFIX + "/etc/xdg/autostart/tray-" + Devs[sel] + ".desktop";
+ QString filename = PREFIX + "/share/pcbsd/xstartup/tray-" + Devs[sel] + ".sh";
// First run a check to if we need to enable or disable the checkbox
@@ -670,6 +672,10 @@
else
groupIPv6->setChecked(FALSE);
+
+ // Check if we want to use the lagg interface
+ QSettings settings("PCBSD");
+ checkLagg->setChecked(settings.value("/pc-netmanager/useLagg", false).toBool());
// Load the PPPOE Configuration
@@ -810,23 +816,27 @@
if (checkSysTray->isChecked() )
{
// Save the new file
- QFile fileout( PREFIX + "/etc/xdg/autostart/tray-" + Devs[sel] + ".desktop" );
+ QFile fileout( PREFIX + "/share/pcbsd/xstartup/tray-" + Devs[sel] + ".sh");
if ( fileout.open( QIODevice::WriteOnly ) ) {
QTextStream streamout( &fileout );
- streamout << "[Desktop Entry]\nExec=pc-nettray " + Devs[sel];
- streamout << "\nIcon=network\nStartupNotify=false\nType=Application\n";
+ streamout << "pc-nettray " + Devs[sel];
fileout.close();
- runCommand("chmod 644 \"" + PREFIX + "/etc/xdg/autostart/tray-" + Devs[sel] + ".desktop\"");
+ runCommand("chmod 755 \"" + PREFIX + "/share/pcbsd/xstartup/tray-" + Devs[sel] + ".sh\"");
+ runCommand("sync");
// Now start the tray icon
- //runCommand("pc-nettray " + Devs[sel] + " &");
+ ExeProc = new QProcess();
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+ ExeProc->setProcessEnvironment(env);
+ ExeProc->start(QString("su"), QStringList() << username << "-m -c" \
+ << "pc-nettray " + Devs[sel] );
}
} else {
// Kill the tray applet
- runCommand("rm -f \"" + PREFIX + "/etc/xdg/autostart/tray-" + Devs[sel] + ".desktop\"");
+ runCommand("rm -f \"" + PREFIX + "/share/pcbsd/xstartup/tray-" + Devs[sel] + ".sh\"");
}
}
@@ -1179,10 +1189,15 @@
saveValue("/etc/rc.conf", "ipv6_defaultrouter=", "", -1);
}
+ // Save the lagg preference
+ QSettings settings("PCBSD");
+ settings.setValue("/pc-netmanager/useLagg", checkLagg->isChecked());
+
// Save the proxy config
saveProxyConfig();
restartNetwork();
+
}
Modified: pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.h
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.h 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.h 2010-10-29 16:56:45 UTC (rev 7943)
@@ -95,6 +95,8 @@
void otherPPPOEDevs();
void savePPPOEConfig();
void updatePPPconf();
+
+ QProcess *ExeProc;
signals:
void changed(bool);
Modified: pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.ui
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.ui 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.ui 2010-10-29 16:56:45 UTC (rev 7943)
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>658</width>
+ <width>664</width>
<height>525</height>
</rect>
</property>
@@ -484,7 +484,7 @@
</layout>
</widget>
</item>
- <item row="2" column="0" colspan="2">
+ <item row="3" column="0" colspan="2">
<spacer name="spacer33">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -500,6 +500,22 @@
</property>
</spacer>
</item>
+ <item row="2" column="0">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Misc</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_10">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="checkLagg">
+ <property name="text">
+ <string>Enable wireless / wired failover via lagg0 interface</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
@@ -679,8 +695,8 @@
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
-</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:10pt; font-weight:400; font-style:normal;">
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></string>
+</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Bitstream Vera Sans'; font-size:10pt;"></p></body></html></string>
</property>
<property name="acceptRichText">
<bool>false</bool>
Modified: pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.cpp 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.cpp 2010-10-29 16:56:45 UTC (rev 7943)
@@ -1,19 +1,20 @@
/* Qt */
-#include <qtimer.h>
+#include <QDebug>
+#include <QFile>
+#include <QImage>
+#include <QMenu>
#include <QProcess>
-#include <QFile>
-#include <qtooltip.h>
-#include <qimage.h>
-#include <qtranslator.h>
-#include <qtextstream.h>
-#include <qmenu.h>
-#include <QDebug>
+#include <QToolTip>
+#include <QTextStream>
+#include <QTimer>
+#include <QTranslator>
#include <iostream>
#include "NetworkTray.h"
#include <pcbsd-netif.h>
#include <pcbsd-utils.h>
+#include "../../../config.h"
/* Update interval in ms */
@@ -51,6 +52,14 @@
DeviceName = Device;
DeviceType = getTypeForIdent(DeviceName);
+ QString cmd = "ifconfig lagg0 2>/dev/null | grep " + DeviceName;
+ QString checkLagg = getLineFromCommandOutput(cmd.toLatin1());
+ if ( ! checkLagg.isEmpty() )
+ usingLagg = true;
+ else
+ usingLagg = false;
+
+
// Get the username of the person we are running as
username = QString::fromLocal8Bit(getenv("LOGNAME"));
@@ -149,10 +158,10 @@
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 + "/.config/autostart/tray-" + device + ".desktop");
- if ( desktopfile.exists() )
- desktopfile.remove(); // Remove this file
+ // First run a check to see if this device has a auto-start associated with it
+ QFile startfile(PREFIX + "/share/pcbsd/xstartup/tray-" + device + ".sh");
+ if ( startfile.exists() )
+ startfile.remove(); // Remove this file
exit(1);
}
}
@@ -186,10 +195,16 @@
{
QString inputLine = ifconfigOutput;
QString ip= "";
- QString cmd = "ifconfig lagg0 | grep " + DeviceName;
+ QString tDev;
+ if ( usingLagg )
+ tDev = "lagg0";
+ else
+ tDev = DeviceName;
+
+ QString cmd = "ifconfig " + tDev + " | grep " + DeviceName;
QString checkLagg = getLineFromCommandOutput(cmd.toLatin1());
if ( ! checkLagg.isEmpty() ) {
- cmd = "ifconfig lagg0 | grep 'inet ' ";
+ cmd = "ifconfig " + tDev + " | grep 'inet ' ";
inputLine = getLineFromCommandOutput(cmd.toLatin1());
}
@@ -393,7 +408,7 @@
QString tmp;
QIcon Icon;
QString NotifyText = "";
- QString filename = "/home/" + username + "/.config/autostart/tray-" + DeviceName + ".desktop";
+ QString filename = PREFIX + "/share/pcbsd/xstartup/tray-" + DeviceName + ".sh";
// First run a check to see if this applet has been disabled in the network manager
Modified: pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.h
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.h 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/NetworkTray/NetworkTray.h 2010-10-29 16:56:45 UTC (rev 7943)
@@ -66,4 +66,5 @@
QIcon iconWifiConnect85;
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
+ bool usingLagg;
};
Modified: pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp 2010-10-29 16:56:45 UTC (rev 7943)
@@ -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/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.h
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.h 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.h 2010-10-29 16:56:45 UTC (rev 7943)
@@ -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);
Modified: pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp 2010-10-29 16:56:45 UTC (rev 7943)
@@ -9,15 +9,18 @@
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
-#include "wificonfigwidgetbase.h"
-#include "ui_wificonfigwidgetbase.h"
#include <QFile>
-#include <qtextstream.h>
-#include <unistd.h>
+#include <QSettings>
+#include <QTextStream>
+
#include <pcbsd-utils.h>
#include <pcbsd-netif.h>
+#include <unistd.h>
+#include "wificonfigwidgetbase.h"
+#include "ui_wificonfigwidgetbase.h"
+
void wificonfigwidgetbase::slotClose()
{
exit(0);
@@ -61,21 +64,15 @@
// If we have a valid wired device, clone the MAC of it to the wireless device
if ( ! wiredDev.isEmpty() )
{
- // Don't need to mark a wired device as "up" to get its MAC
- //tmp = getValue( "/etc/rc.conf", "ifconfig_" + wiredDev + "=\"up\"", 1 );
- //if ( ! tmp.isEmpty() ) {
- // saveValue( "/etc/rc.conf", "ifconfig_" + wiredDev, "ifconfig_" + wiredDev + "=\"up\"", -1);
- //}
-
// If we are using wlan device
if ( ! DeviceNameParent.isEmpty() ) {
- saveValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"`ifconfig " + wiredDev + " ether`\"", 1);
- saveValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"ether ${ifconfig_" + DeviceNameParent + "##*ether }\"", 2);
- saveValue( "/etc/rc.conf", "wlans_" + DeviceNameParent, "wlans_" + DeviceNameParent + "=\"" + DeviceName + "\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"`ifconfig " + wiredDev + " ether`\"", 1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"ether ${ifconfig_" + DeviceNameParent + "##*ether }\"", 2);
+ Utils::setConfFileValue( "/etc/rc.conf", "wlans_" + DeviceNameParent, "wlans_" + DeviceNameParent + "=\"" + DeviceName + "\"", -1);
} else {
// On 7.x, no wlan0 device needed
- saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
- saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"ether ${ifconfig_" + dev + "##*ether }\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"ether ${ifconfig_" + dev + "##*ether }\"", -1);
}
}
@@ -94,19 +91,19 @@
// Check if we have a WPA setting, and put it in the right device slot
if ( config.indexOf("WPA") != -1 )
{
- saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
config = config.remove(0, config.indexOf("WPA") + 3);
config = config.simplified();
}
// Enable the lagg0 interface
- saveValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
wiredDev = getFirstWiredDevice();
if ( ! wiredDev.isEmpty() )
- saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + config + "\"", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + config + "\"", -1);
else
- 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);
}
void wificonfigwidgetbase::slotApply()
@@ -121,7 +118,7 @@
// If the user disabled the device, do so now
if ( checkDisableWireless->isChecked() )
{
- saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "", -1);
runCommand("ifconfig " + DeviceName + " down");
pushApply->setEnabled(FALSE);
return;
@@ -158,10 +155,16 @@
} else {
ifConfigLine="DHCP";
- }
+ }
-
- saveLaggLine(DeviceName, "WPA " + ifConfigLine);
+ // Check if we want to use the lagg interface
+ if ( usingLagg )
+ saveLaggLine(DeviceName, "WPA " + ifConfigLine);
+ else {
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "", -1);
+ Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, \
+ "ifconfig_" + DeviceName + "=\"WPA " + ifConfigLine + "\"", -1);
+ }
// Now create the wpa_supplicant file based on saved configuration
QFile fileout( "/etc/wpa_supplicant.conf" );
@@ -282,12 +285,15 @@
DeviceName = Device;
// Center the dialog window
- QDesktopWidget *d = QApplication::desktop();
- move(d->width() / 3, d->height() / 4);
+ QDesktopWidget *d = QApplication::desktop();
+ move(d->width() / 3, d->height() / 4);
// Connect the slot to refresh
QTimer::singleShot(100, this, SLOT(slotFinishLoading() ) );
+ // Check if we are using the lagg0 device
+ QSettings settings("PCBSD");
+ usingLagg = settings.value("/pc-netmanager/useLagg", false).toBool();
}
@@ -328,159 +334,6 @@
return TRUE;
}
-
-void wificonfigwidgetbase::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();
- }
-
-}
-
-
-QString wificonfigwidgetbase::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.lastIndexOf('"'));
- }
-
- return line;
-
- } else {
- found++;
- }
-
-
- }
-
-
-
- }
- file.close();
- }
-
- return "";
-}
-
// Slot which moves a SSID higher in the connection priority
void wificonfigwidgetbase::slotMoveUp()
{
@@ -1074,12 +927,19 @@
}
- textIP->setText(getIpForIdent("lagg0") );
- textNetmask->setText(getNetmaskForIdent( "lagg0" ) );
+ if ( usingLagg ) {
+ textIP->setText(getIpForIdent("lagg0") );
+ textNetmask->setText(getNetmaskForIdent( "lagg0" ) );
+ textGateway->setText(getGatewayForIdent( "lagg0" ) );
+ } else {
+ textIP->setText(getIpForIdent(DeviceName) );
+ textNetmask->setText(getNetmaskForIdent( DeviceName ) );
+ textGateway->setText(getGatewayForIdent( DeviceName ) );
+ }
+
textMac->setText(getMacForIdent( DeviceName ) );
textStatus->setText(getStatusForIdent( DeviceName ) );
textIPv6->setText(getIPv6ForIdent( DeviceName) );
- textGateway->setText(getGatewayForIdent( "lagg0" ) );
tmp = getMediaForIdent(DeviceName);
tmp.truncate(20);
textMedia->setText(tmp);
@@ -1107,7 +967,11 @@
bool ok;
// Get the ifconfig string
- tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+ if ( usingLagg )
+ tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+ else
+ tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
+
if ( ! tmp.isEmpty() ) {
// If the device is setup, start loading the settings
Modified: pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h 2010-10-29 14:12:20 UTC (rev 7942)
+++ pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h 2010-10-29 16:56:45 UTC (rev 7943)
@@ -60,8 +60,6 @@
private:
bool checkRange( QString IP );
- void saveValue( QString File, QString oldKey, QString newKey, int occur );
- QString getValue( QString File, QString Key, int occur );
void runCommand( QString Command );
QString getLineFromCommandOutput( QString command );
QString getNetmaskForIdent( QString ident );
@@ -99,6 +97,7 @@
QString WPAEPrivKeyFile[150];
QString WPAEPassword[150];
int WPAEType[150];
+ bool usingLagg;
signals:
More information about the Commits
mailing list