summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interfaces.cpp
authorbenmeyer <benmeyer>2002-10-18 16:27:02 (UTC)
committer benmeyer <benmeyer>2002-10-18 16:27:02 (UTC)
commit12851a09a2761ca6e189f080e9ca69bf4974302f (patch) (unidiff)
tree1b9a368fc5e424d4bf60f4c582b87b23a975c26a /noncore/settings/networksettings/interfaces.cpp
parent47e60a8dc20f46dd00b9405f7fde122792018627 (diff)
downloadopie-12851a09a2761ca6e189f080e9ca69bf4974302f.zip
opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.gz
opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.bz2
Can now remove mapping and is done so automagicly when you delete a profile
Diffstat (limited to 'noncore/settings/networksettings/interfaces.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces.cpp64
1 files changed, 59 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp
index 0927258..9155890 100644
--- a/noncore/settings/networksettings/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces.cpp
@@ -326,36 +326,46 @@ bool Interfaces::setInterfaceMethod(QString newName){
326 * iface eth0 static 326 * iface eth0 static
327 * address 192.168.1.1 327 * address 192.168.1.1
328 * @param option the options to get the value. 328 * @param option the options to get the value.
329 * @param error set to true if any error occurs, false otherwise. 329 * @param error set to true if any error occurs, false otherwise.
330 * @return QString the options value. QString::null if error == true 330 * @return QString the options value. QString::null if error == true
331 */ 331 */
332QString Interfaces::getInterfaceOption(QString option, bool &error){ 332QString Interfaces::getInterfaceOption(QString option, bool &error){
333 return getOption(currentIface, option, error); 333 return getOption(currentIface, option, error);
334} 334}
335 335
336/** 336/**
337 * Set a value for an option in the currently selected interface. If option 337 * Set a value for an option in the currently selected interface. If option
338 * doesn't exist then it is added along with the value. If value is set to an 338 * doesn't exist then it is added along with the value.
339 * empty string then option is removed.
340 * @param option the options to set the value. 339 * @param option the options to set the value.
341 * @param value the value that option should be set to. 340 * @param value the value that option should be set to.
342 * @param error set to true if any error occurs, false otherwise. 341 * @param error set to true if any error occurs, false otherwise.
343 * @return QString the options value. QString::null if error == true 342 * @return QString the options value. QString::null if error == true
344 */ 343 */
345bool Interfaces::setInterfaceOption(QString option, QString value){ 344bool Interfaces::setInterfaceOption(QString option, QString value){
346 return setOption(currentIface, option, value); 345 return setOption(currentIface, option, value);
347} 346}
348 347
349/** 348/**
349 * Removes a value for an option in the currently selected interface.
350 * @param option the options to set the value.
351 * @param value the value that option should be set to.
352 * @param error set to true if any error occurs, false otherwise.
353 * @return QString the options value. QString::null if error == true
354 */
355bool Interfaces::removeInterfaceOption(QString option, QString value){
356 return removeOption(currentIface, option, value);
357}
358
359/**
350 * Removes all of the options from the currently selected interface. 360 * Removes all of the options from the currently selected interface.
351 * @return bool error if if successfull 361 * @return bool error if if successfull
352 */ 362 */
353bool Interfaces::removeAllInterfaceOptions(){ 363bool Interfaces::removeAllInterfaceOptions(){
354 return removeAllOptions(currentIface); 364 return removeAllOptions(currentIface);
355} 365}
356 366
357/** 367/**
358 * Set the current map to interface's map. This needs to be done before you 368 * Set the current map to interface's map. This needs to be done before you
359 * can call addMapping(), set/getMap(), and get/setScript(). 369 * can call addMapping(), set/getMap(), and get/setScript().
360 * @param interface the name of the interface to set. All whitespace is 370 * @param interface the name of the interface to set. All whitespace is
361 * removed from the interface name. 371 * removed from the interface name.
@@ -368,34 +378,55 @@ bool Interfaces::setMapping(QString interface){
368} 378}
369 379
370/** 380/**
371 * Adds a new Mapping to the interfaces file with interfaces. 381 * Adds a new Mapping to the interfaces file with interfaces.
372 * @param interface the name(s) of the interfaces to set to this mapping 382 * @param interface the name(s) of the interfaces to set to this mapping
373 */ 383 */
374void Interfaces::addMapping(QString option){ 384void Interfaces::addMapping(QString option){
375 interfaces.append(""); 385 interfaces.append("");
376 interfaces.append(QString(MAPPING " %1").arg(option)); 386 interfaces.append(QString(MAPPING " %1").arg(option));
377} 387}
378 388
379/** 389/**
390 * Remove the currently selected map and all of its options.
391 * @return bool if successfull or not.
392 */
393bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end())
395 return false;
396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping);
398}
399
400/**
380 * Set a map option within a mapping. 401 * Set a map option within a mapping.
381 * @param map map to use 402 * @param map map to use
382 * @param value value to go with map 403 * @param value value to go with map
383 * @return bool true if it is successfull. 404 * @return bool true if it is successfull.
384 */ 405 */
385bool Interfaces::setMap(QString map, QString value){ 406bool Interfaces::setMap(QString map, QString value){
386 return setOption(currentMapping, map, value); 407 return setOption(currentMapping, map, value);
387} 408}
388 409
389/** 410/**
411 * Removes a map option within a mapping.
412 * @param map map to use
413 * @param value value to go with map
414 * @return bool true if it is successfull.
415 */
416bool Interfaces::removeMap(QString map, QString value){
417 return removeOption(currentMapping, map, value);
418}
419
420/**
390 * Get a map value within a mapping. 421 * Get a map value within a mapping.
391 * @param map map to get value of 422 * @param map map to get value of
392 * @param bool true if it is successfull. 423 * @param bool true if it is successfull.
393 * @return value that goes to the map 424 * @return value that goes to the map
394 */ 425 */
395QString Interfaces::getMap(QString map, bool &error){ 426QString Interfaces::getMap(QString map, bool &error){
396 return getOption(currentMapping, map, error); 427 return getOption(currentMapping, map, error);
397} 428}
398 429
399/** 430/**
400 * Sets a script value of the current mapping to argument. 431 * Sets a script value of the current mapping to argument.
401 * @param argument the script name. 432 * @param argument the script name.
@@ -468,37 +499,60 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString
468 if(!found && value != ""){ 499 if(!found && value != ""){
469 // Got to the end of the stanza without finding it, so append it. 500 // Got to the end of the stanza without finding it, so append it.
470 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 501 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
471 } 502 }
472 found = true; 503 found = true;
473 break; 504 break;
474 } 505 }
475 if((*it).contains(option) && it != start){ 506 if((*it).contains(option) && it != start){
476 // Found it in stanza so replace it. 507 // Found it in stanza so replace it.
477 if(found) 508 if(found)
478 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 509 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
479 found = true; 510 found = true;
480 if(value == "")
481 (*it) = "";
482 else
483 (*it) = QString("\t%1 %2").arg(option).arg(value); 511 (*it) = QString("\t%1 %2").arg(option).arg(value);
484 } 512 }
485 } 513 }
486 if(!found){ 514 if(!found){
487 QStringList::Iterator p = start; 515 QStringList::Iterator p = start;
488 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); 516 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
489 found = true; 517 found = true;
490 } 518 }
491 return found; 519 return found;
492} 520}
521/**
522 * Removes a option in a stanza
523 * @param start the start of the stanza
524 * @param option the option to use when setting value.
525 * @return bool true if successfull, false otherwise.
526 */
527bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){
528 if(start == interfaces.end())
529 return false;
530
531 bool found = false;
532 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
533 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
534 // got to the end without finding it
535 break;
536 }
537 if((*it).contains(option) && (*it).contains(value) &&it != start){
538 // Found it in stanza so replace it.
539 if(found)
540 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
541 found = true;
542 (*it) = "";
543 }
544 }
545 return found;
546}
493 547
494/** 548/**
495 * Removes all options in a stanza 549 * Removes all options in a stanza
496 * @param start the start of the stanza 550 * @param start the start of the stanza
497 * @return bool true if successfull, false otherwise. 551 * @return bool true if successfull, false otherwise.
498 */ 552 */
499bool Interfaces::removeAllOptions(QStringList::Iterator start){ 553bool Interfaces::removeAllOptions(QStringList::Iterator start){
500 if(start == interfaces.end()) 554 if(start == interfaces.end())
501 return false; 555 return false;
502 556
503 QStringList::Iterator it = start; 557 QStringList::Iterator it = start;
504 it = ++it; 558 it = ++it;