summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.cpp71
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.h5
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.cpp103
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.h4
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp71
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.h5
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp103
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.h4
8 files changed, 180 insertions, 186 deletions
diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp
index 708f399..e49998e 100644
--- a/noncore/net/networksetup/interfaces/interfaces.cpp
+++ b/noncore/net/networksetup/interfaces/interfaces.cpp
@@ -1,30 +1,31 @@
#include "interfaces.h"
#include <qfile.h>
#include <qtextstream.h>
#include <qregexp.h>
+// The three stanza's
#define AUTO "auto"
#define IFACE "iface"
#define MAPPING "mapping"
/**
* Constructor. Reads in the interfaces file and then split the file up by
* the \n for interfaces variable.
* @param useInterfacesFile if an interface file other then the default is
* desired to be used it should be passed in.
*/
Interfaces::Interfaces(QString useInterfacesFile){
acceptedFamily.append(INTERFACES_FAMILY_INET);
acceptedFamily.append(INTERFACES_FAMILY_IPX);
acceptedFamily.append(INTERFACES_FAMILY_INET6);
interfacesFile = useInterfacesFile;
QFile file(interfacesFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1());
currentIface = interfaces.end();
currentMapping = interfaces.end();
return;
}
QTextStream stream( &file );
@@ -81,212 +82,204 @@ bool Interfaces::isAuto(const QString &interface){
}
/**
* Attempt to set the auto option for interface to setAuto.
* @param interface the interface to set
* @param setAuto the value to set interface to.
* @return false if already set to setAuto.
* */
bool Interfaces::setAuto(const QString &interface, bool setAuto){
// Don't need to set it if it is already set.
if(isAuto(interface) == setAuto)
return false;
bool changed = false;
for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
if((*it).contains(AUTO)){
//We know that they are not in any group so let add to this auto.
if(setAuto){
(*it) = (*it) += " " + interface;
// Don't care to have such thins as: auto eth0 lo usb0
(*it) = (*it).simplifyWhiteSpace();
changed = true;
break;
}
+ // else see if we need to remove from this one
else{
if((*it).contains(interface)){
(*it) = (*it).replace(QRegExp(interface), "");
- // clean up
- QString line = (*it).simplifyWhiteSpace();
- line = line.replace(QRegExp(" "),"");
- if(line == AUTO)
+ // if AUTO is the only thing left clear the line
+ if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
(*it) = "";
changed = true;
// Don't break because we want to make sure we remove all cases.
}
}
}
}
- if(changed == false){
- if(setAuto == true)
+ // In the case where there is no AUTO field add one.
+ if(!changed && setAuto)
interfaces.append(QString(AUTO" %1").arg(interface));
- else{
- qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
- }
- }
return true;
}
/**
* Set the current interface to interface. This needs to be done before you
* can call getFamily(), getMethod, and get/setOption().
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @return bool true if it is successfull.
*/
bool Interfaces::setInterface(QString interface){
interface = interface.simplifyWhiteSpace();
interface = interface.replace(QRegExp(" "), "");
return setStanza(IFACE, interface, currentIface);
}
/**
* A quick helper funtion to see if the current interface is set.
* @return bool true if set, false otherwise.
*/
bool Interfaces::isInterfaceSet(){
return (currentIface != interfaces.end());
}
/**
* Add a new interface of with the settings - family and method
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @param family the family of this interface inet or inet, ipx or inet6
* Must of one of the families defined in interfaces.h
* @param method for the family. see interfaces man page for family methods.
* @return true if successfull.
*/
bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
- if(acceptedFamily.contains(family)==0)
+ if(0 == acceptedFamily.contains(family))
return false;
QString newInterface = interface.simplifyWhiteSpace();
newInterface = newInterface.replace(QRegExp(" "), "");
interfaces.append("");
interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method));
return true;
}
/**
* Copies interface with name interface to name newInterface
* @param newInterface name of the new interface.
* @return bool true if successfull
*/
bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
- if(!setInterface(interface)) return false;
+ if(!setInterface(interface))
+ return false;
+ // Store the old interface and bump past the stanza line.
QStringList::Iterator it = currentIface;
it++;
+ // Add the new interface
bool error;
addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
- if(!setInterface(newInterface)) return false;
+ if(!setInterface(newInterface))
+ return false;
+
QStringList::Iterator newIface = currentIface;
newIface++;
+ // Copy all of the lines
for ( ; it != interfaces.end(); ++it ){
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
break;
newIface = interfaces.insert(newIface, *it);
}
return true;
}
/**
* Remove the currently selected interface and all of its options.
* @return bool if successfull or not.
*/
bool Interfaces::removeInterface(){
- if(currentIface == interfaces.end())
- return false;
- (*currentIface) = "";
- return removeAllInterfaceOptions();
+ return removeStanza(currentIface);
}
/**
* Gets the hardware name of the interface that is currently selected.
* @return QString name of the hardware interface (eth0, usb2, wlan1...).
* @param error set to true if any error occurs, false otherwise.
*/
QString Interfaces::getInterfaceName(bool &error){
if(currentIface == interfaces.end()){
error = true;
return QString();
}
QString line = (*currentIface);
line = line.mid(QString(IFACE).length() +1, line.length());
line = line.simplifyWhiteSpace();
int findSpace = line.find(" ");
if( findSpace < 0){
error = true;
return QString();
}
error = false;
return line.mid(0, findSpace);
}
/**
* Gets the family name of the interface that is currently selected.
* @return QString name of the family (inet, inet6, ipx).
* @param error set to true if any error occurs, false otherwise.
*/
QString Interfaces::getInterfaceFamily(bool &error){
QString name = getInterfaceName(error);
- if(error){
- error = true;
+ if(error)
return QString();
- }
QString line = (*currentIface);
line = line.mid(QString(IFACE).length() +1, line.length());
line = line.mid(name.length()+1, line.length());
line = line.simplifyWhiteSpace();
int findSpace = line.find(" ");
if( findSpace < 0){
error = true;
return QString();
}
error = false;
return line.mid(0, findSpace);
}
/**
* Gets the method of the interface that is currently selected.
* @return QString name of the method such as staic or dhcp.
* See the man page of interfaces for possible methods depending on the family.
* @param error set to true if any error occurs, false otherwise.
*/
QString Interfaces::getInterfaceMethod(bool &error){
QString name = getInterfaceName(error);
- if(error){
- error = true;
+ if(error)
return QString();
- }
QString family = getInterfaceFamily(error);
- if(error){
- error = true;
+ if(error)
return QString();
- }
QString line = (*currentIface);
line = line.mid(QString(IFACE).length()+1, line.length());
line = line.mid(name.length()+1, line.length());
line = line.mid(family.length()+1, line.length());
line = line.simplifyWhiteSpace();
error = false;
return line;
}
/**
* Sets the interface name to newName.
* @param newName the new name of the interface. All whitespace is removed.
* @return bool true if successfull.
*/
bool Interfaces::setInterfaceName(const QString &newName){
if(currentIface == interfaces.end())
return false;
QString name = newName.simplifyWhiteSpace();
name = name.replace(QRegExp(" "), "");
bool returnValue = false;
(*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
return !returnValue;
}
@@ -370,52 +363,49 @@ bool Interfaces::removeAllInterfaceOptions(){
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @return bool true if it is successfull.
*/
bool Interfaces::setMapping(const QString &interface){
QString interfaceName = interface.simplifyWhiteSpace();
interfaceName = interfaceName.replace(QRegExp(" "), "");
return setStanza(MAPPING, interfaceName, currentMapping);
}
/**
* Adds a new Mapping to the interfaces file with interfaces.
* @param interface the name(s) of the interfaces to set to this mapping
*/
void Interfaces::addMapping(const QString &option){
interfaces.append("");
interfaces.append(QString(MAPPING " %1").arg(option));
}
/**
* Remove the currently selected map and all of its options.
* @return bool if successfull or not.
*/
bool Interfaces::removeMapping(){
- if(currentMapping == interfaces.end())
- return false;
- (*currentMapping) = "";
- return removeAllOptions(currentMapping);
+ return removeStanza(currentMapping);
}
/**
* Set a map option within a mapping.
* @param map map to use
* @param value value to go with map
* @return bool true if it is successfull.
*/
bool Interfaces::setMap(const QString &map, const QString &value){
return setOption(currentMapping, map, value);
}
/**
* Removes a map option within a mapping.
* @param map map to use
* @param value value to go with map
* @return bool true if it is successfull.
*/
bool Interfaces::removeMap(const QString &map, const QString &value){
return removeOption(currentMapping, map, value);
}
/**
* Get a map value within a mapping.
@@ -499,48 +489,61 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op
for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
if(!found && value != ""){
// Got to the end of the stanza without finding it, so append it.
interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
}
found = true;
break;
}
if((*it).contains(option) && it != start && (*it).at(0) != '#'){
// Found it in stanza so replace it.
if(found)
qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
found = true;
(*it) = QString("\t%1 %2").arg(option).arg(value);
}
}
if(!found){
QStringList::Iterator p = start;
interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
found = true;
}
return found;
}
+
+/**
+ * Removes a stanza and all of its options
+ * @param stanza the stanza to remove
+ * @return bool true if successfull.
+ */
+bool Interfaces::removeStanza(QStringList::Iterator &stanza){
+ if(stanza == interfaces.end())
+ return false;
+ (*stanza) = "";
+ return removeAllOptions(stanza);
+}
+
/**
* Removes a option in a stanza
* @param start the start of the stanza
* @param option the option to use when setting value.
* @return bool true if successfull, false otherwise.
*/
bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){
if(start == interfaces.end())
return false;
bool found = false;
for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
// got to the end without finding it
break;
}
if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
// Found it in stanza so replace it.
if(found)
qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
found = true;
(*it) = "";
}
}
@@ -570,56 +573,56 @@ bool Interfaces::removeAllOptions(const QStringList::Iterator &start){
return true;
}
/**
* Gets a value of an option in a stanza
* @param start the start of the stanza
* @param option the option to use when getting the value.
* @param bool true if errors false otherwise.
* @return QString the value of option QString::null() if error == true.
*/
QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){
if(start == interfaces.end()){
error = false;
return QString();
}
QString value;
bool found = false;
for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
break;
}
if((*it).contains(option) && (*it).at(0) != '#'){
if(found)
- qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
+ qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
found = true;
QString line = (*it).simplifyWhiteSpace();
int space = line.find(" ", option.length());
- if(space != -1)
+ if(space != -1){
value = line.mid(space+1, line.length());
- else
- qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1());
+ break;
+ }
}
}
error = !found;
return value;
}
/**
* Write out the interfaces file to the file passed into the constructor.
* Removes any excess blank lines over 1 line long.
* @return bool true if successfull, false if not.
*/
bool Interfaces::write(){
QFile::remove(interfacesFile);
QFile file(interfacesFile);
if (!file.open(IO_ReadWrite)){
qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
return false;
}
QTextStream stream( &file );
int whiteSpaceCount = 0;
for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
QString line = (*it).simplifyWhiteSpace();
line = line.replace(QRegExp(" "),"");
diff --git a/noncore/net/networksetup/interfaces/interfaces.h b/noncore/net/networksetup/interfaces/interfaces.h
index 26abb73..5a8feb6 100644
--- a/noncore/net/networksetup/interfaces/interfaces.h
+++ b/noncore/net/networksetup/interfaces/interfaces.h
@@ -7,70 +7,71 @@
#define INTERFACES_LOOPBACK "loopback"
#define INTERFACES_FAMILY_INET "inet"
#define INTERFACES_FAMILY_IPX "ipx"
#define INTERFACES_FAMILY_INET6 "inet6"
#define INTERFACES_METHOD_DHCP "dhcp"
#define INTERFACES_METHOD_STATIC "static"
#define INTERFACES_METHOD_PPP "ppp"
/**
* This class provides a clean frontend for parsing the network interfaces file.
* It provides helper functions to minipulate the options within the file.
* See the interfaces man page for the syntax rules.
*/
class Interfaces {
public:
Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
QStringList getInterfaceList();
bool isAuto(const QString &interface);
bool setAuto(const QString &interface, bool setAuto);
- bool removeInterface();
+ inline bool removeInterface();
bool addInterface(const QString &interface, const QString &family, const QString &method);
bool copyInterface(const QString &oldInterface, const QString &newInterface);
bool setInterface(QString interface);
inline bool isInterfaceSet();
QString getInterfaceName(bool &error);
bool setInterfaceName(const QString &newName);
QString getInterfaceFamily(bool &error);
bool setInterfaceFamily(const QString &newName);
QString getInterfaceMethod(bool &error);
bool setInterfaceMethod(const QString &newName);
inline QString getInterfaceOption(const QString &option, bool &error);
inline bool setInterfaceOption(const QString &option, const QString &value);
inline bool removeInterfaceOption(const QString &option, const QString &value);
inline bool removeAllInterfaceOptions();
bool setMapping(const QString &interface);
- bool removeMapping();
+ inline bool removeMapping();
inline void addMapping(const QString &options);
inline bool setMap(const QString &map, const QString &value);
inline bool removeMap(const QString &map, const QString &value);
inline QString getMap(const QString &map, bool &error);
inline bool setScript(const QString &argument);
inline QString getScript(bool &error);
bool write();
private:
bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator);
bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value);
bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value);
QString getOption(const QStringList::Iterator &start, const QString &option, bool &error);
+ bool removeStanza(QStringList::Iterator &stanza);
bool removeAllOptions(const QStringList::Iterator &start);
QString interfacesFile;
QStringList interfaces;
QStringList::Iterator currentIface;
QStringList::Iterator currentMapping;
QStringList acceptedFamily;
};
#endif
// interfaces
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
index 3b1a4de..4818e37 100644
--- a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
@@ -1,152 +1,145 @@
#include "interfacesetupimp.h"
#include "interface.h"
-#include "interfaces.h"
-#include <qdialog.h>
-#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qmessagebox.h>
-#include <assert.h>
-
#define DNSSCRIPT "changedns"
/**
- * Constuctor. Set up the connection and load the first profile.
+ * Constuctor. Set up the connection. A profile must be set.
*/
-InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){
- assert(parent);
- assert(i);
- interface = i;
- interfaces = new Interfaces();
- bool error = false;
- if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
- staticGroupBox->hide();
- dhcpCheckBox->hide();
- leaseTime->hide();
- leaseHoursLabel->hide();
- }
+InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){
}
/**
* Save the current settings, then write out the interfaces file and close.
*/
bool InterfaceSetupImp::saveChanges(){
if(!saveSettings())
return false;
- interfaces->write();
+ interfaces.write();
return true;
}
/**
* Save the settings for the current Interface.
* @return bool true if successfull, false otherwise
*/
bool InterfaceSetupImp::saveSettings(){
// eh can't really do anything about it other then return. :-D
- if(!interfaces->isInterfaceSet())
+ if(!interfaces.isInterfaceSet())
return true;
bool error = false;
// Loopback case
- if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
- interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
+ if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
+ interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){
QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok);
return false;
}
- interfaces->removeAllInterfaceOptions();
+ interfaces.removeAllInterfaceOptions();
// DHCP
if(dhcpCheckBox->isChecked()){
- interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
- interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
- interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
+ interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP);
+ interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
+ interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
}
else{
- interfaces->setInterfaceMethod("static");
- interfaces->setInterfaceOption("address", ipAddressEdit->text());
- interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
- interfaces->setInterfaceOption("gateway", gatewayEdit->text());
+ interfaces.setInterfaceMethod("static");
+ interfaces.setInterfaceOption("address", ipAddressEdit->text());
+ interfaces.setInterfaceOption("netmask", subnetMaskEdit->text());
+ interfaces.setInterfaceOption("gateway", gatewayEdit->text());
if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){
QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
- interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns);
- interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns);
+ interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns);
+ interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns);
}
}
// IP Information
- interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
+ interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
/**
* The Profile has changed.
- * @profile the new profile.
+ * @param QString profile the new profile.
*/
void InterfaceSetupImp::setProfile(const QString &profile){
+ /*
+ bool error = false;
+ if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
+ staticGroupBox->hide();
+ dhcpCheckBox->hide();
+ leaseTime->hide();
+ leaseHoursLabel->hide();
+ }
+ */
+
QString newInterfaceName = interface->getInterfaceName();
if(profile.length() > 0)
newInterfaceName += "_" + profile;
- qDebug("InterfaceSetupImp::setProfile");
// See if we have to make a interface.
- if(!interfaces->setInterface(newInterfaceName)){
+ if(!interfaces.setInterface(newInterfaceName)){
// Add making for this new interface if need too
if(profile != ""){
- interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
- if(!interfaces->setMapping(interface->getInterfaceName())){
- interfaces->addMapping(interface->getInterfaceName());
- if(!interfaces->setMapping(interface->getInterfaceName())){
- qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
+ interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName);
+ if(!interfaces.setMapping(interface->getInterfaceName())){
+ interfaces.addMapping(interface->getInterfaceName());
+ if(!interfaces.setMapping(interface->getInterfaceName())){
+ qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface.");
return;
}
}
- interfaces->setMap("map", newInterfaceName);
- interfaces->setScript("getprofile.sh");
+ interfaces.setMap("map", newInterfaceName);
+ interfaces.setScript("getprofile.sh");
}
else{
- interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
- if(!interfaces->setInterface(newInterfaceName)){
- qDebug("InterfaceSetupImp: Added interface, but still can't set.");
+ interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
+ if(!interfaces.setInterface(newInterfaceName)){
+ qDebug("InterfaceSetupImp: Added interface, but still can't setInterface.");
return;
}
}
}
// We must have a valid interface to get this far so read some settings.
// DHCP
bool error = false;
- if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
+ if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
dhcpCheckBox->setChecked(true);
else
dhcpCheckBox->setChecked(false);
- leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
+ leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt());
if(error)
- leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
+ leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60);
if(error)
leaseTime->setValue(24);
// IP Information
- autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
- QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error);
+ autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName()));
+ QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error);
if(dns.contains(" ")){
firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
}
- ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
- subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
- gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
-}
+ ipAddressEdit->setText(interfaces.getInterfaceOption("address", error));
+ subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error));
+ gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error));
+}
// interfacesetup.cpp
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.h b/noncore/net/networksetup/interfaces/interfacesetupimp.h
index 60933aa..9ec526c 100644
--- a/noncore/net/networksetup/interfaces/interfacesetupimp.h
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.h
@@ -1,46 +1,46 @@
#ifndef INTERFACESETUPIMP_H
#define INTERFACESETUPIMP_H
#include "interfacesetup.h"
+#include "interfaces.h"
#include <qdialog.h>
class Interface;
-class Interfaces;
class InterfaceSetupImp : public InterfaceSetup {
Q_OBJECT
public:
InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0);
bool saveChanges();
public slots:
void setProfile(const QString &profile);
bool saveSettings();
private:
- Interfaces *interfaces;
+ Interfaces interfaces;
Interface *interface;
};
#include <qlayout.h>
class InterfaceSetupImpDialog : public QDialog {
Q_OBJECT
public:
InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){
QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this );
setCaption("Interface Setup");
interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl);
InterfaceSetupLayout->addWidget( interfaceSetup );
};
void setProfile(QString &profile){ interfaceSetup->setProfile(profile);};
private:
InterfaceSetupImp *interfaceSetup;
protected slots:
void accept(){
if(interfaceSetup->saveChanges())
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp
index 708f399..e49998e 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces/interfaces.cpp
@@ -1,30 +1,31 @@
#include "interfaces.h"
#include <qfile.h>
#include <qtextstream.h>
#include <qregexp.h>
+// The three stanza's
#define AUTO "auto"
#define IFACE "iface"
#define MAPPING "mapping"
/**
* Constructor. Reads in the interfaces file and then split the file up by
* the \n for interfaces variable.
* @param useInterfacesFile if an interface file other then the default is
* desired to be used it should be passed in.
*/
Interfaces::Interfaces(QString useInterfacesFile){
acceptedFamily.append(INTERFACES_FAMILY_INET);
acceptedFamily.append(INTERFACES_FAMILY_IPX);
acceptedFamily.append(INTERFACES_FAMILY_INET6);
interfacesFile = useInterfacesFile;
QFile file(interfacesFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1());
currentIface = interfaces.end();
currentMapping = interfaces.end();
return;
}
QTextStream stream( &file );
@@ -81,212 +82,204 @@ bool Interfaces::isAuto(const QString &interface){
}
/**
* Attempt to set the auto option for interface to setAuto.
* @param interface the interface to set
* @param setAuto the value to set interface to.
* @return false if already set to setAuto.
* */
bool Interfaces::setAuto(const QString &interface, bool setAuto){
// Don't need to set it if it is already set.
if(isAuto(interface) == setAuto)
return false;
bool changed = false;
for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
if((*it).contains(AUTO)){
//We know that they are not in any group so let add to this auto.
if(setAuto){
(*it) = (*it) += " " + interface;
// Don't care to have such thins as: auto eth0 lo usb0
(*it) = (*it).simplifyWhiteSpace();
changed = true;
break;
}
+ // else see if we need to remove from this one
else{
if((*it).contains(interface)){
(*it) = (*it).replace(QRegExp(interface), "");
- // clean up
- QString line = (*it).simplifyWhiteSpace();
- line = line.replace(QRegExp(" "),"");
- if(line == AUTO)
+ // if AUTO is the only thing left clear the line
+ if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
(*it) = "";
changed = true;
// Don't break because we want to make sure we remove all cases.
}
}
}
}
- if(changed == false){
- if(setAuto == true)
+ // In the case where there is no AUTO field add one.
+ if(!changed && setAuto)
interfaces.append(QString(AUTO" %1").arg(interface));
- else{
- qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
- }
- }
return true;
}
/**
* Set the current interface to interface. This needs to be done before you
* can call getFamily(), getMethod, and get/setOption().
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @return bool true if it is successfull.
*/
bool Interfaces::setInterface(QString interface){
interface = interface.simplifyWhiteSpace();
interface = interface.replace(QRegExp(" "), "");
return setStanza(IFACE, interface, currentIface);
}
/**
* A quick helper funtion to see if the current interface is set.
* @return bool true if set, false otherwise.
*/
bool Interfaces::isInterfaceSet(){
return (currentIface != interfaces.end());
}
/**
* Add a new interface of with the settings - family and method
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @param family the family of this interface inet or inet, ipx or inet6
* Must of one of the families defined in interfaces.h
* @param method for the family. see interfaces man page for family methods.
* @return true if successfull.
*/
bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
- if(acceptedFamily.contains(family)==0)
+ if(0 == acceptedFamily.contains(family))
return false;
QString newInterface = interface.simplifyWhiteSpace();
newInterface = newInterface.replace(QRegExp(" "), "");
interfaces.append("");
interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method));
return true;
}
/**
* Copies interface with name interface to name newInterface
* @param newInterface name of the new interface.
* @return bool true if successfull
*/
bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
- if(!setInterface(interface)) return false;
+ if(!setInterface(interface))
+ return false;
+ // Store the old interface and bump past the stanza line.
QStringList::Iterator it = currentIface;
it++;
+ // Add the new interface
bool error;
addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
- if(!setInterface(newInterface)) return false;
+ if(!setInterface(newInterface))
+ return false;
+
QStringList::Iterator newIface = currentIface;
newIface++;
+ // Copy all of the lines
for ( ; it != interfaces.end(); ++it ){
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
break;
newIface = interfaces.insert(newIface, *it);
}
return true;
}
/**
* Remove the currently selected interface and all of its options.
* @return bool if successfull or not.
*/
bool Interfaces::removeInterface(){
- if(currentIface == interfaces.end())
- return false;
- (*currentIface) = "";
- return removeAllInterfaceOptions();
+ return removeStanza(currentIface);
}
/**
* Gets the hardware name of the interface that is currently selected.
* @return QString name of the hardware interface (eth0, usb2, wlan1...).
* @param error set to true if any error occurs, false otherwise.
*/
QString Interfaces::getInterfaceName(bool &error){
if(currentIface == interfaces.end()){
error = true;
return QString();
}
QString line = (*currentIface);
line = line.mid(QString(IFACE).length() +1, line.length());
line = line.simplifyWhiteSpace();
int findSpace = line.find(" ");
if( findSpace < 0){
error = true;
return QString();
}
error = false;
return line.mid(0, findSpace);
}
/**
* Gets the family name of the interface that is currently selected.
* @return QString name of the family (inet, inet6, ipx).
* @param error set to true if any error occurs, false otherwise.
*/
QString Interfaces::getInterfaceFamily(bool &error){
QString name = getInterfaceName(error);
- if(error){
- error = true;
+ if(error)
return QString();
- }
QString line = (*currentIface);
line = line.mid(QString(IFACE).length() +1, line.length());
line = line.mid(name.length()+1, line.length());
line = line.simplifyWhiteSpace();
int findSpace = line.find(" ");
if( findSpace < 0){
error = true;
return QString();
}
error = false;
return line.mid(0, findSpace);
}
/**
* Gets the method of the interface that is currently selected.
* @return QString name of the method such as staic or dhcp.
* See the man page of interfaces for possible methods depending on the family.
* @param error set to true if any error occurs, false otherwise.
*/
QString Interfaces::getInterfaceMethod(bool &error){
QString name = getInterfaceName(error);
- if(error){
- error = true;
+ if(error)
return QString();
- }
QString family = getInterfaceFamily(error);
- if(error){
- error = true;
+ if(error)
return QString();
- }
QString line = (*currentIface);
line = line.mid(QString(IFACE).length()+1, line.length());
line = line.mid(name.length()+1, line.length());
line = line.mid(family.length()+1, line.length());
line = line.simplifyWhiteSpace();
error = false;
return line;
}
/**
* Sets the interface name to newName.
* @param newName the new name of the interface. All whitespace is removed.
* @return bool true if successfull.
*/
bool Interfaces::setInterfaceName(const QString &newName){
if(currentIface == interfaces.end())
return false;
QString name = newName.simplifyWhiteSpace();
name = name.replace(QRegExp(" "), "");
bool returnValue = false;
(*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
return !returnValue;
}
@@ -370,52 +363,49 @@ bool Interfaces::removeAllInterfaceOptions(){
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @return bool true if it is successfull.
*/
bool Interfaces::setMapping(const QString &interface){
QString interfaceName = interface.simplifyWhiteSpace();
interfaceName = interfaceName.replace(QRegExp(" "), "");
return setStanza(MAPPING, interfaceName, currentMapping);
}
/**
* Adds a new Mapping to the interfaces file with interfaces.
* @param interface the name(s) of the interfaces to set to this mapping
*/
void Interfaces::addMapping(const QString &option){
interfaces.append("");
interfaces.append(QString(MAPPING " %1").arg(option));
}
/**
* Remove the currently selected map and all of its options.
* @return bool if successfull or not.
*/
bool Interfaces::removeMapping(){
- if(currentMapping == interfaces.end())
- return false;
- (*currentMapping) = "";
- return removeAllOptions(currentMapping);
+ return removeStanza(currentMapping);
}
/**
* Set a map option within a mapping.
* @param map map to use
* @param value value to go with map
* @return bool true if it is successfull.
*/
bool Interfaces::setMap(const QString &map, const QString &value){
return setOption(currentMapping, map, value);
}
/**
* Removes a map option within a mapping.
* @param map map to use
* @param value value to go with map
* @return bool true if it is successfull.
*/
bool Interfaces::removeMap(const QString &map, const QString &value){
return removeOption(currentMapping, map, value);
}
/**
* Get a map value within a mapping.
@@ -499,48 +489,61 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op
for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
if(!found && value != ""){
// Got to the end of the stanza without finding it, so append it.
interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
}
found = true;
break;
}
if((*it).contains(option) && it != start && (*it).at(0) != '#'){
// Found it in stanza so replace it.
if(found)
qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
found = true;
(*it) = QString("\t%1 %2").arg(option).arg(value);
}
}
if(!found){
QStringList::Iterator p = start;
interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
found = true;
}
return found;
}
+
+/**
+ * Removes a stanza and all of its options
+ * @param stanza the stanza to remove
+ * @return bool true if successfull.
+ */
+bool Interfaces::removeStanza(QStringList::Iterator &stanza){
+ if(stanza == interfaces.end())
+ return false;
+ (*stanza) = "";
+ return removeAllOptions(stanza);
+}
+
/**
* Removes a option in a stanza
* @param start the start of the stanza
* @param option the option to use when setting value.
* @return bool true if successfull, false otherwise.
*/
bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){
if(start == interfaces.end())
return false;
bool found = false;
for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
// got to the end without finding it
break;
}
if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
// Found it in stanza so replace it.
if(found)
qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
found = true;
(*it) = "";
}
}
@@ -570,56 +573,56 @@ bool Interfaces::removeAllOptions(const QStringList::Iterator &start){
return true;
}
/**
* Gets a value of an option in a stanza
* @param start the start of the stanza
* @param option the option to use when getting the value.
* @param bool true if errors false otherwise.
* @return QString the value of option QString::null() if error == true.
*/
QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){
if(start == interfaces.end()){
error = false;
return QString();
}
QString value;
bool found = false;
for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
break;
}
if((*it).contains(option) && (*it).at(0) != '#'){
if(found)
- qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
+ qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
found = true;
QString line = (*it).simplifyWhiteSpace();
int space = line.find(" ", option.length());
- if(space != -1)
+ if(space != -1){
value = line.mid(space+1, line.length());
- else
- qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1());
+ break;
+ }
}
}
error = !found;
return value;
}
/**
* Write out the interfaces file to the file passed into the constructor.
* Removes any excess blank lines over 1 line long.
* @return bool true if successfull, false if not.
*/
bool Interfaces::write(){
QFile::remove(interfacesFile);
QFile file(interfacesFile);
if (!file.open(IO_ReadWrite)){
qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
return false;
}
QTextStream stream( &file );
int whiteSpaceCount = 0;
for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
QString line = (*it).simplifyWhiteSpace();
line = line.replace(QRegExp(" "),"");
diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h
index 26abb73..5a8feb6 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.h
+++ b/noncore/settings/networksettings/interfaces/interfaces.h
@@ -7,70 +7,71 @@
#define INTERFACES_LOOPBACK "loopback"
#define INTERFACES_FAMILY_INET "inet"
#define INTERFACES_FAMILY_IPX "ipx"
#define INTERFACES_FAMILY_INET6 "inet6"
#define INTERFACES_METHOD_DHCP "dhcp"
#define INTERFACES_METHOD_STATIC "static"
#define INTERFACES_METHOD_PPP "ppp"
/**
* This class provides a clean frontend for parsing the network interfaces file.
* It provides helper functions to minipulate the options within the file.
* See the interfaces man page for the syntax rules.
*/
class Interfaces {
public:
Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
QStringList getInterfaceList();
bool isAuto(const QString &interface);
bool setAuto(const QString &interface, bool setAuto);
- bool removeInterface();
+ inline bool removeInterface();
bool addInterface(const QString &interface, const QString &family, const QString &method);
bool copyInterface(const QString &oldInterface, const QString &newInterface);
bool setInterface(QString interface);
inline bool isInterfaceSet();
QString getInterfaceName(bool &error);
bool setInterfaceName(const QString &newName);
QString getInterfaceFamily(bool &error);
bool setInterfaceFamily(const QString &newName);
QString getInterfaceMethod(bool &error);
bool setInterfaceMethod(const QString &newName);
inline QString getInterfaceOption(const QString &option, bool &error);
inline bool setInterfaceOption(const QString &option, const QString &value);
inline bool removeInterfaceOption(const QString &option, const QString &value);
inline bool removeAllInterfaceOptions();
bool setMapping(const QString &interface);
- bool removeMapping();
+ inline bool removeMapping();
inline void addMapping(const QString &options);
inline bool setMap(const QString &map, const QString &value);
inline bool removeMap(const QString &map, const QString &value);
inline QString getMap(const QString &map, bool &error);
inline bool setScript(const QString &argument);
inline QString getScript(bool &error);
bool write();
private:
bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator);
bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value);
bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value);
QString getOption(const QStringList::Iterator &start, const QString &option, bool &error);
+ bool removeStanza(QStringList::Iterator &stanza);
bool removeAllOptions(const QStringList::Iterator &start);
QString interfacesFile;
QStringList interfaces;
QStringList::Iterator currentIface;
QStringList::Iterator currentMapping;
QStringList acceptedFamily;
};
#endif
// interfaces
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index 3b1a4de..4818e37 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -1,152 +1,145 @@
#include "interfacesetupimp.h"
#include "interface.h"
-#include "interfaces.h"
-#include <qdialog.h>
-#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qmessagebox.h>
-#include <assert.h>
-
#define DNSSCRIPT "changedns"
/**
- * Constuctor. Set up the connection and load the first profile.
+ * Constuctor. Set up the connection. A profile must be set.
*/
-InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){
- assert(parent);
- assert(i);
- interface = i;
- interfaces = new Interfaces();
- bool error = false;
- if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
- staticGroupBox->hide();
- dhcpCheckBox->hide();
- leaseTime->hide();
- leaseHoursLabel->hide();
- }
+InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){
}
/**
* Save the current settings, then write out the interfaces file and close.
*/
bool InterfaceSetupImp::saveChanges(){
if(!saveSettings())
return false;
- interfaces->write();
+ interfaces.write();
return true;
}
/**
* Save the settings for the current Interface.
* @return bool true if successfull, false otherwise
*/
bool InterfaceSetupImp::saveSettings(){
// eh can't really do anything about it other then return. :-D
- if(!interfaces->isInterfaceSet())
+ if(!interfaces.isInterfaceSet())
return true;
bool error = false;
// Loopback case
- if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
- interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
+ if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
+ interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){
QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok);
return false;
}
- interfaces->removeAllInterfaceOptions();
+ interfaces.removeAllInterfaceOptions();
// DHCP
if(dhcpCheckBox->isChecked()){
- interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
- interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
- interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
+ interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP);
+ interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
+ interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
}
else{
- interfaces->setInterfaceMethod("static");
- interfaces->setInterfaceOption("address", ipAddressEdit->text());
- interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
- interfaces->setInterfaceOption("gateway", gatewayEdit->text());
+ interfaces.setInterfaceMethod("static");
+ interfaces.setInterfaceOption("address", ipAddressEdit->text());
+ interfaces.setInterfaceOption("netmask", subnetMaskEdit->text());
+ interfaces.setInterfaceOption("gateway", gatewayEdit->text());
if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){
QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
- interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns);
- interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns);
+ interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns);
+ interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns);
}
}
// IP Information
- interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
+ interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
/**
* The Profile has changed.
- * @profile the new profile.
+ * @param QString profile the new profile.
*/
void InterfaceSetupImp::setProfile(const QString &profile){
+ /*
+ bool error = false;
+ if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
+ staticGroupBox->hide();
+ dhcpCheckBox->hide();
+ leaseTime->hide();
+ leaseHoursLabel->hide();
+ }
+ */
+
QString newInterfaceName = interface->getInterfaceName();
if(profile.length() > 0)
newInterfaceName += "_" + profile;
- qDebug("InterfaceSetupImp::setProfile");
// See if we have to make a interface.
- if(!interfaces->setInterface(newInterfaceName)){
+ if(!interfaces.setInterface(newInterfaceName)){
// Add making for this new interface if need too
if(profile != ""){
- interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
- if(!interfaces->setMapping(interface->getInterfaceName())){
- interfaces->addMapping(interface->getInterfaceName());
- if(!interfaces->setMapping(interface->getInterfaceName())){
- qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
+ interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName);
+ if(!interfaces.setMapping(interface->getInterfaceName())){
+ interfaces.addMapping(interface->getInterfaceName());
+ if(!interfaces.setMapping(interface->getInterfaceName())){
+ qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface.");
return;
}
}
- interfaces->setMap("map", newInterfaceName);
- interfaces->setScript("getprofile.sh");
+ interfaces.setMap("map", newInterfaceName);
+ interfaces.setScript("getprofile.sh");
}
else{
- interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
- if(!interfaces->setInterface(newInterfaceName)){
- qDebug("InterfaceSetupImp: Added interface, but still can't set.");
+ interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
+ if(!interfaces.setInterface(newInterfaceName)){
+ qDebug("InterfaceSetupImp: Added interface, but still can't setInterface.");
return;
}
}
}
// We must have a valid interface to get this far so read some settings.
// DHCP
bool error = false;
- if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
+ if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
dhcpCheckBox->setChecked(true);
else
dhcpCheckBox->setChecked(false);
- leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
+ leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt());
if(error)
- leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
+ leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60);
if(error)
leaseTime->setValue(24);
// IP Information
- autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
- QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error);
+ autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName()));
+ QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error);
if(dns.contains(" ")){
firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
}
- ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
- subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
- gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
-}
+ ipAddressEdit->setText(interfaces.getInterfaceOption("address", error));
+ subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error));
+ gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error));
+}
// interfacesetup.cpp
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.h b/noncore/settings/networksettings/interfaces/interfacesetupimp.h
index 60933aa..9ec526c 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.h
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.h
@@ -1,46 +1,46 @@
#ifndef INTERFACESETUPIMP_H
#define INTERFACESETUPIMP_H
#include "interfacesetup.h"
+#include "interfaces.h"
#include <qdialog.h>
class Interface;
-class Interfaces;
class InterfaceSetupImp : public InterfaceSetup {
Q_OBJECT
public:
InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0);
bool saveChanges();
public slots:
void setProfile(const QString &profile);
bool saveSettings();
private:
- Interfaces *interfaces;
+ Interfaces interfaces;
Interface *interface;
};
#include <qlayout.h>
class InterfaceSetupImpDialog : public QDialog {
Q_OBJECT
public:
InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){
QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this );
setCaption("Interface Setup");
interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl);
InterfaceSetupLayout->addWidget( interfaceSetup );
};
void setProfile(QString &profile){ interfaceSetup->setProfile(profile);};
private:
InterfaceSetupImp *interfaceSetup;
protected slots:
void accept(){
if(interfaceSetup->saveChanges())