author | benmeyer <benmeyer> | 2002-10-18 15:40:50 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-18 15:40:50 (UTC) |
commit | c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b (patch) (unidiff) | |
tree | 39e69706b24b032364ad4483d2f33688e7054390 /noncore/net/networksetup/interfaces.cpp | |
parent | 0910b94b5b6618c84b3eb6c457c9137d63a7277f (diff) | |
download | opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.zip opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.gz opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.bz2 |
Profiles copy
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 | |||
@@ -146,48 +146,74 @@ bool Interfaces::setInterface(QString interface){ | |||
146 | bool Interfaces::isInterfaceSet(){ | 146 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 147 | return (currentIface != interfaces.end()); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Add a new interface of with the settings - family and method | 151 | * Add a new interface of with the settings - family and method |
152 | * @param interface the name of the interface to set. All whitespace is | 152 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 153 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 154 | * @param family the family of this interface inet or inet, ipx or inet6 |
155 | * Must of one of the families defined in interfaces.h | 155 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 156 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 157 | * @return true if successfull. |
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. |
182 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
183 | * @param error set to true if any error occurs, false otherwise. | 209 | * @param error set to true if any error occurs, false otherwise. |
184 | */ | 210 | */ |
185 | QString Interfaces::getInterfaceName(bool &error){ | 211 | QString Interfaces::getInterfaceName(bool &error){ |
186 | if(currentIface == interfaces.end()){ | 212 | if(currentIface == interfaces.end()){ |
187 | error = true; | 213 | error = true; |
188 | return QString(); | 214 | return QString(); |
189 | } | 215 | } |
190 | QString line = (*currentIface); | 216 | QString line = (*currentIface); |
191 | line = line.mid(QString(IFACE).length() +1, line.length()); | 217 | line = line.mid(QString(IFACE).length() +1, line.length()); |
192 | line = line.simplifyWhiteSpace(); | 218 | line = line.simplifyWhiteSpace(); |
193 | int findSpace = line.find(" "); | 219 | int findSpace = line.find(" "); |
@@ -380,54 +406,68 @@ bool Interfaces::setScript(QString argument){ | |||
380 | } | 406 | } |
381 | 407 | ||
382 | /** | 408 | /** |
383 | * @param error true if could not retrieve the current script argument. | 409 | * @param error true if could not retrieve the current script argument. |
384 | * @return QString the argument of the script for the current mapping. | 410 | * @return QString the argument of the script for the current mapping. |
385 | */ | 411 | */ |
386 | QString Interfaces::getScript(bool &error){ | 412 | QString Interfaces::getScript(bool &error){ |
387 | return getOption(currentMapping, "script", error); | 413 | return getOption(currentMapping, "script", error); |
388 | } | 414 | } |
389 | 415 | ||
390 | /** | 416 | /** |
391 | * Helper function used to parse through the QStringList and put pointers in | 417 | * Helper function used to parse through the QStringList and put pointers in |
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){ |
422 | if(start == interfaces.end()) | 462 | if(start == interfaces.end()) |
423 | return false; | 463 | return false; |
424 | 464 | ||
425 | bool found = false; | 465 | bool found = false; |
426 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 466 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
427 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 467 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
428 | if(!found && value != ""){ | 468 | if(!found && value != ""){ |
429 | // Got to the end of the stanza without finding it, so append it. | 469 | // Got to the end of the stanza without finding it, so append it. |
430 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | 470 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
431 | } | 471 | } |
432 | found = true; | 472 | found = true; |
433 | break; | 473 | break; |