Diffstat (limited to 'noncore/net/networksetup/interfaces.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/networksetup/interfaces.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp index eef42df..0927258 100644 --- a/noncore/net/networksetup/interfaces.cpp +++ b/noncore/net/networksetup/interfaces.cpp | |||
@@ -158,24 +158,50 @@ bool Interfaces::isInterfaceSet(){ | |||
158 | */ | 158 | */ |
159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | 159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ |
160 | if(acceptedFamily.contains(family)==0) | 160 | if(acceptedFamily.contains(family)==0) |
161 | return false; | 161 | return false; |
162 | interface = interface.simplifyWhiteSpace(); | 162 | interface = interface.simplifyWhiteSpace(); |
163 | interface = interface.replace(QRegExp(" "), ""); | 163 | interface = interface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 164 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | 165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Copies interface with name interface to name newInterface | ||
171 | * @param newInterface name of the new interface. | ||
172 | * @return bool true if successfull | ||
173 | */ | ||
174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ | ||
175 | if(!setInterface(interface)) return false; | ||
176 | |||
177 | QStringList::Iterator it = currentIface; | ||
178 | it++; | ||
179 | |||
180 | bool error; | ||
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | ||
182 | if(!setInterface(newInterface)) return false; | ||
183 | QStringList::Iterator newIface = currentIface; | ||
184 | newIface++; | ||
185 | |||
186 | for ( it; it != interfaces.end(); ++it ){ | ||
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | ||
188 | break; | ||
189 | newIface = interfaces.insert(newIface, *it); | ||
190 | } | ||
191 | |||
192 | return true; | ||
193 | } | ||
194 | |||
195 | /** | ||
170 | * Remove the currently selected interface and all of its options. | 196 | * Remove the currently selected interface and all of its options. |
171 | * @return bool if successfull or not. | 197 | * @return bool if successfull or not. |
172 | */ | 198 | */ |
173 | bool Interfaces::removeInterface(){ | 199 | bool Interfaces::removeInterface(){ |
174 | if(currentIface == interfaces.end()) | 200 | if(currentIface == interfaces.end()) |
175 | return false; | 201 | return false; |
176 | (*currentIface) = ""; | 202 | (*currentIface) = ""; |
177 | return removeAllInterfaceOptions(); | 203 | return removeAllInterfaceOptions(); |
178 | } | 204 | } |
179 | 205 | ||
180 | /** | 206 | /** |
181 | * Gets the hardware name of the interface that is currently selected. | 207 | * Gets the hardware name of the interface that is currently selected. |
@@ -392,30 +418,44 @@ QString Interfaces::getScript(bool &error){ | |||
392 | * the correct place. | 418 | * the correct place. |
393 | * @param stanza The stanza (auto, iface, mapping) to look for. | 419 | * @param stanza The stanza (auto, iface, mapping) to look for. |
394 | * @param option string that must be in the stanza's main line. | 420 | * @param option string that must be in the stanza's main line. |
395 | * @param interator interator to place at location of stanza if successfull. | 421 | * @param interator interator to place at location of stanza if successfull. |
396 | * @return bool true if the stanza is found. | 422 | * @return bool true if the stanza is found. |
397 | */ | 423 | */ |
398 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | 424 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ |
399 | bool found = false; | 425 | bool found = false; |
400 | iterator = interfaces.end(); | 426 | iterator = interfaces.end(); |
401 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 427 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
402 | QString line = (*it).simplifyWhiteSpace(); | 428 | QString line = (*it).simplifyWhiteSpace(); |
403 | if(line.contains(stanza) && line.contains(option)){ | 429 | if(line.contains(stanza) && line.contains(option)){ |
404 | if(found == true){ | 430 | uint point = line.find(option); |
405 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 431 | bool valid = true; |
432 | if(point > 0){ | ||
433 | // There are more chars in the line. check +1 | ||
434 | if(line.at(point-1) != ' ') | ||
435 | valid = false; | ||
436 | } | ||
437 | point += option.length(); | ||
438 | if(point < line.length()-1){ | ||
439 | // There are more chars in the line. check -1 | ||
440 | if(line.at(point) != ' ') | ||
441 | valid = false; | ||
442 | } | ||
443 | if(valid){ | ||
444 | if(found == true){ | ||
445 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | ||
446 | } | ||
447 | found = true; | ||
448 | iterator = it; | ||
406 | } | 449 | } |
407 | qDebug("Found"); | ||
408 | found = true; | ||
409 | iterator = it; | ||
410 | } | 450 | } |
411 | } | 451 | } |
412 | return found; | 452 | return found; |
413 | } | 453 | } |
414 | 454 | ||
415 | /** | 455 | /** |
416 | * Sets a value of an option in a stanza | 456 | * Sets a value of an option in a stanza |
417 | * @param start the start of the stanza | 457 | * @param start the start of the stanza |
418 | * @param option the option to use when setting value. | 458 | * @param option the option to use when setting value. |
419 | * @return bool true if successfull, false otherwise. | 459 | * @return bool true if successfull, false otherwise. |
420 | */ | 460 | */ |
421 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 461 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ |