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
@@ -4,6 +4,7 @@
4#include <qtextstream.h> 4#include <qtextstream.h>
5#include <qregexp.h> 5#include <qregexp.h>
6 6
7// The three stanza's
7#define AUTO "auto" 8#define AUTO "auto"
8#define IFACE "iface" 9#define IFACE "iface"
9#define MAPPING "mapping" 10#define MAPPING "mapping"
@@ -102,13 +103,12 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
102 changed = true; 103 changed = true;
103 break; 104 break;
104 } 105 }
106 // else see if we need to remove from this one
105 else{ 107 else{
106 if((*it).contains(interface)){ 108 if((*it).contains(interface)){
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) = "";
113 changed = true; 113 changed = true;
114 // Don't break because we want to make sure we remove all cases. 114 // Don't break because we want to make sure we remove all cases.
@@ -116,13 +116,9 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
116 } 116 }
117 } 117 }
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;
127} 123}
128 124
@@ -157,7 +153,7 @@ bool Interfaces::isInterfaceSet(){
157 * @return true if successfull. 153 * @return true if successfull.
158 */ 154 */
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;
162 QString newInterface = interface.simplifyWhiteSpace(); 158 QString newInterface = interface.simplifyWhiteSpace();
163 newInterface = newInterface.replace(QRegExp(" "), ""); 159 newInterface = newInterface.replace(QRegExp(" "), "");
@@ -172,17 +168,23 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c
172 * @return bool true if successfull 168 * @return bool true if successfull
173 */ 169 */
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;
178 it++; 176 it++;
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;
184 newIface++; 185 newIface++;
185 186
187 // Copy all of the lines
186 for ( ; it != interfaces.end(); ++it ){ 188 for ( ; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) 189 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break; 190 break;
@@ -197,10 +199,7 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
197 * @return bool if successfull or not. 199 * @return bool if successfull or not.
198 */ 200 */
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}
205 204
206/** 205/**
@@ -232,10 +231,8 @@ QString Interfaces::getInterfaceName(bool &error){
232 */ 231 */
233QString Interfaces::getInterfaceFamily(bool &error){ 232QString 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);
240 line = line.mid(QString(IFACE).length() +1, line.length()); 237 line = line.mid(QString(IFACE).length() +1, line.length());
241 line = line.mid(name.length()+1, line.length()); 238 line = line.mid(name.length()+1, line.length());
@@ -257,15 +254,11 @@ QString Interfaces::getInterfaceFamily(bool &error){
257 */ 254 */
258QString Interfaces::getInterfaceMethod(bool &error){ 255QString 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);
270 line = line.mid(QString(IFACE).length()+1, line.length()); 263 line = line.mid(QString(IFACE).length()+1, line.length());
271 line = line.mid(name.length()+1, line.length()); 264 line = line.mid(name.length()+1, line.length());
@@ -391,10 +384,7 @@ void Interfaces::addMapping(const QString &option){
391 * @return bool if successfull or not. 384 * @return bool if successfull or not.
392 */ 385 */
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}
399 389
400/** 390/**
@@ -520,6 +510,19 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op
520 } 510 }
521 return found; 511 return found;
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/**
524 * Removes a option in a stanza 527 * Removes a option in a stanza
525 * @param start the start of the stanza 528 * @param start the start of the stanza
@@ -591,14 +594,14 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
591 } 594 }
592 if((*it).contains(option) && (*it).at(0) != '#'){ 595 if((*it).contains(option) && (*it).at(0) != '#'){
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;
596 QString line = (*it).simplifyWhiteSpace(); 599 QString line = (*it).simplifyWhiteSpace();
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 }
603 } 606 }
604 error = !found; 607 error = !found;