summaryrefslogtreecommitdiff
path: root/noncore/net/networksetup/interfaces/interfaces.cpp
Unidiff
Diffstat (limited to 'noncore/net/networksetup/interfaces/interfaces.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.cpp71
1 files changed, 37 insertions, 34 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
@@ -6,2 +6,3 @@
6 6
7// The three stanza's
7#define AUTO "auto" 8#define AUTO "auto"
@@ -104,2 +105,3 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
104 } 105 }
106 // else see if we need to remove from this one
105 else{ 107 else{
@@ -107,6 +109,4 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
107 (*it) = (*it).replace(QRegExp(interface), ""); 109 (*it) = (*it).replace(QRegExp(interface), "");
108 // clean up 110 // if AUTO is the only thing left clear the line
109 QString line = (*it).simplifyWhiteSpace(); 111 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
110 line = line.replace(QRegExp(" "),"");
111 if(line == AUTO)
112 (*it) = ""; 112 (*it) = "";
@@ -118,9 +118,5 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
118 } 118 }
119 if(changed == false){ 119 // In the case where there is no AUTO field add one.
120 if(setAuto == true) 120 if(!changed && setAuto)
121 interfaces.append(QString(AUTO" %1").arg(interface)); 121 interfaces.append(QString(AUTO" %1").arg(interface));
122 else{
123 qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
124 }
125 }
126 return true; 122 return true;
@@ -159,3 +155,3 @@ bool Interfaces::isInterfaceSet(){
159bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ 155bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
160 if(acceptedFamily.contains(family)==0) 156 if(0 == acceptedFamily.contains(family))
161 return false; 157 return false;
@@ -174,4 +170,6 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c
174bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ 170bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
175 if(!setInterface(interface)) return false; 171 if(!setInterface(interface))
172 return false;
176 173
174 // Store the old interface and bump past the stanza line.
177 QStringList::Iterator it = currentIface; 175 QStringList::Iterator it = currentIface;
@@ -179,5 +177,8 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
179 177
178 // Add the new interface
180 bool error; 179 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); 180 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false; 181 if(!setInterface(newInterface))
182 return false;
183
183 QStringList::Iterator newIface = currentIface; 184 QStringList::Iterator newIface = currentIface;
@@ -185,2 +186,3 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
185 186
187 // Copy all of the lines
186 for ( ; it != interfaces.end(); ++it ){ 188 for ( ; it != interfaces.end(); ++it ){
@@ -199,6 +201,3 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
199bool Interfaces::removeInterface(){ 201bool Interfaces::removeInterface(){
200 if(currentIface == interfaces.end()) 202 return removeStanza(currentIface);
201 return false;
202 (*currentIface) = "";
203 return removeAllInterfaceOptions();
204} 203}
@@ -234,6 +233,4 @@ QString Interfaces::getInterfaceFamily(bool &error){
234 QString name = getInterfaceName(error); 233 QString name = getInterfaceName(error);
235 if(error){ 234 if(error)
236 error = true;
237 return QString(); 235 return QString();
238 }
239 QString line = (*currentIface); 236 QString line = (*currentIface);
@@ -259,11 +256,7 @@ QString Interfaces::getInterfaceMethod(bool &error){
259 QString name = getInterfaceName(error); 256 QString name = getInterfaceName(error);
260 if(error){ 257 if(error)
261 error = true;
262 return QString(); 258 return QString();
263 }
264 QString family = getInterfaceFamily(error); 259 QString family = getInterfaceFamily(error);
265 if(error){ 260 if(error)
266 error = true;
267 return QString(); 261 return QString();
268 }
269 QString line = (*currentIface); 262 QString line = (*currentIface);
@@ -393,6 +386,3 @@ void Interfaces::addMapping(const QString &option){
393bool Interfaces::removeMapping(){ 386bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end()) 387 return removeStanza(currentMapping);
395 return false;
396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping);
398} 388}
@@ -522,2 +512,15 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op
522} 512}
513
514/**
515 * Removes a stanza and all of its options
516 * @param stanza the stanza to remove
517 * @return bool true if successfull.
518 */
519bool Interfaces::removeStanza(QStringList::Iterator &stanza){
520 if(stanza == interfaces.end())
521 return false;
522 (*stanza) = "";
523 return removeAllOptions(stanza);
524}
525
523/** 526/**
@@ -593,3 +596,3 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
593 if(found) 596 if(found)
594 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 597 qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
595 found = true; 598 found = true;
@@ -597,6 +600,6 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
597 int space = line.find(" ", option.length()); 600 int space = line.find(" ", option.length());
598 if(space != -1) 601 if(space != -1){
599 value = line.mid(space+1, line.length()); 602 value = line.mid(space+1, line.length());
600 else 603 break;
601 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); 604 }
602 } 605 }