summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interfaces.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/interfaces.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp
index 1287d90..eef42df 100644
--- a/noncore/settings/networksettings/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces.cpp
@@ -300,193 +300,200 @@ bool Interfaces::setInterfaceMethod(QString newName){
300 * iface eth0 static 300 * iface eth0 static
301 * address 192.168.1.1 301 * address 192.168.1.1
302 * @param option the options to get the value. 302 * @param option the options to get the value.
303 * @param error set to true if any error occurs, false otherwise. 303 * @param error set to true if any error occurs, false otherwise.
304 * @return QString the options value. QString::null if error == true 304 * @return QString the options value. QString::null if error == true
305 */ 305 */
306QString Interfaces::getInterfaceOption(QString option, bool &error){ 306QString Interfaces::getInterfaceOption(QString option, bool &error){
307 return getOption(currentIface, option, error); 307 return getOption(currentIface, option, error);
308} 308}
309 309
310/** 310/**
311 * Set a value for an option in the currently selected interface. If option 311 * Set a value for an option in the currently selected interface. If option
312 * doesn't exist then it is added along with the value. If value is set to an 312 * doesn't exist then it is added along with the value. If value is set to an
313 * empty string then option is removed. 313 * empty string then option is removed.
314 * @param option the options to set the value. 314 * @param option the options to set the value.
315 * @param value the value that option should be set to. 315 * @param value the value that option should be set to.
316 * @param error set to true if any error occurs, false otherwise. 316 * @param error set to true if any error occurs, false otherwise.
317 * @return QString the options value. QString::null if error == true 317 * @return QString the options value. QString::null if error == true
318 */ 318 */
319bool Interfaces::setInterfaceOption(QString option, QString value){ 319bool Interfaces::setInterfaceOption(QString option, QString value){
320 return setOption(currentIface, option, value); 320 return setOption(currentIface, option, value);
321} 321}
322 322
323/** 323/**
324 * Removes all of the options from the currently selected interface. 324 * Removes all of the options from the currently selected interface.
325 * @return bool error if if successfull 325 * @return bool error if if successfull
326 */ 326 */
327bool Interfaces::removeAllInterfaceOptions(){ 327bool Interfaces::removeAllInterfaceOptions(){
328 return removeAllOptions(currentIface); 328 return removeAllOptions(currentIface);
329} 329}
330 330
331/** 331/**
332 * Set the current map to interface's map. This needs to be done before you 332 * Set the current map to interface's map. This needs to be done before you
333 * can call addMapping(), set/getMap(), and get/setScript(). 333 * can call addMapping(), set/getMap(), and get/setScript().
334 * @param interface the name of the interface to set. All whitespace is 334 * @param interface the name of the interface to set. All whitespace is
335 * removed from the interface name. 335 * removed from the interface name.
336 * @return bool true if it is successfull. 336 * @return bool true if it is successfull.
337 */ 337 */
338bool Interfaces::setMapping(QString interface){ 338bool Interfaces::setMapping(QString interface){
339 interface = interface.simplifyWhiteSpace(); 339 interface = interface.simplifyWhiteSpace();
340 interface = interface.replace(QRegExp(" "), ""); 340 interface = interface.replace(QRegExp(" "), "");
341 return setStanza(MAPPING, interface, currentMapping); 341 return setStanza(MAPPING, interface, currentMapping);
342} 342}
343 343
344/** 344/**
345 * Adds a new Mapping to the interfaces file with interfaces. 345 * Adds a new Mapping to the interfaces file with interfaces.
346 * @param interface the name(s) of the interfaces to set to this mapping 346 * @param interface the name(s) of the interfaces to set to this mapping
347 */ 347 */
348void Interfaces::addMapping(QString interfaces){ 348void Interfaces::addMapping(QString option){
349 interfaces.append(""); 349 interfaces.append("");
350 interfaces.append(QString(MAPPING " %1").arg(interfaces)); 350 interfaces.append(QString(MAPPING " %1").arg(option));
351} 351}
352 352
353/** 353/**
354 * Set a map option within a mapping. 354 * Set a map option within a mapping.
355 * @param map map to use 355 * @param map map to use
356 * @param value value to go with map 356 * @param value value to go with map
357 * @return bool true if it is successfull. 357 * @return bool true if it is successfull.
358 */ 358 */
359bool Interfaces::setMap(QString map, QString value){ 359bool Interfaces::setMap(QString map, QString value){
360 return setOption(currentMapping, map, value); 360 return setOption(currentMapping, map, value);
361} 361}
362 362
363/** 363/**
364 * Get a map value within a mapping. 364 * Get a map value within a mapping.
365 * @param map map to get value of 365 * @param map map to get value of
366 * @param bool true if it is successfull. 366 * @param bool true if it is successfull.
367 * @return value that goes to the map 367 * @return value that goes to the map
368 */ 368 */
369QString Interfaces::getMap(QString map, bool &error){ 369QString Interfaces::getMap(QString map, bool &error){
370 return getOption(currentMapping, map, error); 370 return getOption(currentMapping, map, error);
371} 371}
372 372
373/** 373/**
374 * Sets a script value of the current mapping to argument. 374 * Sets a script value of the current mapping to argument.
375 * @param argument the script name. 375 * @param argument the script name.
376 * @return true if successfull. 376 * @return true if successfull.
377 */ 377 */
378bool Interfaces::setScript(QString argument){ 378bool Interfaces::setScript(QString argument){
379 return setOption(currentMapping, "script", argument); 379 return setOption(currentMapping, "script", argument);
380} 380}
381 381
382/** 382/**
383 * @param error true if could not retrieve the current script argument. 383 * @param error true if could not retrieve the current script argument.
384 * @return QString the argument of the script for the current mapping. 384 * @return QString the argument of the script for the current mapping.
385 */ 385 */
386QString Interfaces::getScript(bool &error){ 386QString Interfaces::getScript(bool &error){
387 return getOption(currentMapping, "script", error); 387 return getOption(currentMapping, "script", error);
388} 388}
389 389
390/** 390/**
391 * Helper function used to parse through the QStringList and put pointers in 391 * Helper function used to parse through the QStringList and put pointers in
392 * the correct place. 392 * the correct place.
393 * @param stanza The stanza (auto, iface, mapping) to look for. 393 * @param stanza The stanza (auto, iface, mapping) to look for.
394 * @param option string that must be in the stanza's main line. 394 * @param option string that must be in the stanza's main line.
395 * @param interator interator to place at location of stanza if successfull. 395 * @param interator interator to place at location of stanza if successfull.
396 * @return bool true if the stanza is found. 396 * @return bool true if the stanza is found.
397 */ 397 */
398bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 398bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
399 bool found = false; 399 bool found = false;
400 iterator = interfaces.end(); 400 iterator = interfaces.end();
401 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 401 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
402 QString line = (*it).simplifyWhiteSpace(); 402 QString line = (*it).simplifyWhiteSpace();
403 if(line.contains(stanza) && line.contains(option)){ 403 if(line.contains(stanza) && line.contains(option)){
404 if(found == true){ 404 if(found == true){
405 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); 405 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
406 } 406 }
407 qDebug("Found");
407 found = true; 408 found = true;
408 iterator = it; 409 iterator = it;
409 } 410 }
410 } 411 }
411 return !found; 412 return found;
412} 413}
413 414
414/** 415/**
415 * Sets a value of an option in a stanza 416 * Sets a value of an option in a stanza
416 * @param start the start of the stanza 417 * @param start the start of the stanza
417 * @param option the option to use when setting value. 418 * @param option the option to use when setting value.
418 * @return bool true if successfull, false otherwise. 419 * @return bool true if successfull, false otherwise.
419 */ 420 */
420bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 421bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
421 if(start == interfaces.end()) 422 if(start == interfaces.end())
422 return false; 423 return false;
423 424
424 bool found = false; 425 bool found = false;
425 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 426 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
426 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 427 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
427 if(!found && value != ""){ 428 if(!found && value != ""){
428 // Got to the end of the stanza without finding it, so append it. 429 // Got to the end of the stanza without finding it, so append it.
429 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 430 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
430 } 431 }
432 found = true;
431 break; 433 break;
432 } 434 }
433 if((*it).contains(option)){ 435 if((*it).contains(option) && it != start){
434 // Found it in stanza so replace it. 436 // Found it in stanza so replace it.
435 if(found) 437 if(found)
436 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 438 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
437 found = true; 439 found = true;
438 if(value == "") 440 if(value == "")
439 (*it) = ""; 441 (*it) = "";
440 else 442 else
441 (*it) = QString("\t%1 %2").arg(option).arg(value); 443 (*it) = QString("\t%1 %2").arg(option).arg(value);
442 } 444 }
443 } 445 }
444 return true; 446 if(!found){
447 QStringList::Iterator p = start;
448 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
449 found = true;
450 }
451 return found;
445} 452}
446 453
447/** 454/**
448 * Removes all options in a stanza 455 * Removes all options in a stanza
449 * @param start the start of the stanza 456 * @param start the start of the stanza
450 * @return bool true if successfull, false otherwise. 457 * @return bool true if successfull, false otherwise.
451 */ 458 */
452bool Interfaces::removeAllOptions(QStringList::Iterator start){ 459bool Interfaces::removeAllOptions(QStringList::Iterator start){
453 if(start == interfaces.end()) 460 if(start == interfaces.end())
454 return false; 461 return false;
455 462
456 QStringList::Iterator it = start; 463 QStringList::Iterator it = start;
457 it = ++it; 464 it = ++it;
458 for (it; it != interfaces.end(); ++it ) { 465 for (it; it != interfaces.end(); ++it ) {
459 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 466 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
460 break; 467 break;
461 } 468 }
462 it = interfaces.remove(it); 469 it = interfaces.remove(it);
463 it = --it; 470 it = --it;
464 } 471 }
465 // Leave a space between this interface and the next. 472 // Leave a space between this interface and the next.
466 interfaces.insert(it, QString("")); 473 interfaces.insert(it, QString(""));
467 return true; 474 return true;
468} 475}
469 476
470/** 477/**
471 * Gets a value of an option in a stanza 478 * Gets a value of an option in a stanza
472 * @param start the start of the stanza 479 * @param start the start of the stanza
473 * @param option the option to use when getting the value. 480 * @param option the option to use when getting the value.
474 * @param bool true if errors false otherwise. 481 * @param bool true if errors false otherwise.
475 * @return QString the value of option QString::null() if error == true. 482 * @return QString the value of option QString::null() if error == true.
476 */ 483 */
477QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ 484QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){
478 if(start == interfaces.end()){ 485 if(start == interfaces.end()){
479 error = false; 486 error = false;
480 return QString(); 487 return QString();
481 } 488 }
482 489
483 QString value; 490 QString value;
484 bool found = false; 491 bool found = false;
485 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 492 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
486 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 493 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
487 break; 494 break;
488 } 495 }
489 if((*it).contains(option)){ 496 if((*it).contains(option)){
490 if(found) 497 if(found)
491 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 498 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
492 found = true; 499 found = true;