-rw-r--r-- | noncore/net/networksetup/interfaces.cpp | 64 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces.h | 4 | ||||
-rw-r--r-- | noncore/net/networksetup/interfacesetupimp.cpp | 1 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 38 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.h | 1 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces.cpp | 64 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces.h | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfacesetupimp.cpp | 1 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 38 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.h | 1 |
10 files changed, 186 insertions, 30 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp index 0927258..9155890 100644 --- a/noncore/net/networksetup/interfaces.cpp +++ b/noncore/net/networksetup/interfaces.cpp | |||
@@ -290,251 +290,305 @@ bool Interfaces::setInterfaceName(QString newName){ | |||
290 | return !returnValue; | 290 | return !returnValue; |
291 | } | 291 | } |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Sets the interface family to newName. | 294 | * Sets the interface family to newName. |
295 | * @param newName the new name of the interface. Must be one of the families | 295 | * @param newName the new name of the interface. Must be one of the families |
296 | * defined in the interfaces.h file. | 296 | * defined in the interfaces.h file. |
297 | * @return bool true if successfull. | 297 | * @return bool true if successfull. |
298 | */ | 298 | */ |
299 | bool Interfaces::setInterfaceFamily(QString newName){ | 299 | bool Interfaces::setInterfaceFamily(QString newName){ |
300 | if(currentIface == interfaces.end()) | 300 | if(currentIface == interfaces.end()) |
301 | return false; | 301 | return false; |
302 | if(acceptedFamily.contains(newName)==0) | 302 | if(acceptedFamily.contains(newName)==0) |
303 | return false; | 303 | return false; |
304 | bool returnValue = false; | 304 | bool returnValue = false; |
305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
306 | return !returnValue; | 306 | return !returnValue; |
307 | } | 307 | } |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Sets the interface method to newName | 310 | * Sets the interface method to newName |
311 | * @param newName the new name of the interface | 311 | * @param newName the new name of the interface |
312 | * @return bool true if successfull. | 312 | * @return bool true if successfull. |
313 | */ | 313 | */ |
314 | bool Interfaces::setInterfaceMethod(QString newName){ | 314 | bool Interfaces::setInterfaceMethod(QString newName){ |
315 | if(currentIface == interfaces.end()) | 315 | if(currentIface == interfaces.end()) |
316 | return false; | 316 | return false; |
317 | bool returnValue = false; | 317 | bool returnValue = false; |
318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
319 | return !returnValue; | 319 | return !returnValue; |
320 | } | 320 | } |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Get a value for an option in the currently selected interface. For example | 323 | * Get a value for an option in the currently selected interface. For example |
324 | * calling getInterfaceOption("address") on the following stanza would | 324 | * calling getInterfaceOption("address") on the following stanza would |
325 | * return 192.168.1.1. | 325 | * return 192.168.1.1. |
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 | */ |
332 | QString Interfaces::getInterfaceOption(QString option, bool &error){ | 332 | QString 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 | */ |
345 | bool Interfaces::setInterfaceOption(QString option, QString value){ | 344 | bool 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 | */ | ||
355 | bool 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 | */ |
353 | bool Interfaces::removeAllInterfaceOptions(){ | 363 | bool 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. |
362 | * @return bool true if it is successfull. | 372 | * @return bool true if it is successfull. |
363 | */ | 373 | */ |
364 | bool Interfaces::setMapping(QString interface){ | 374 | bool Interfaces::setMapping(QString interface){ |
365 | interface = interface.simplifyWhiteSpace(); | 375 | interface = interface.simplifyWhiteSpace(); |
366 | interface = interface.replace(QRegExp(" "), ""); | 376 | interface = interface.replace(QRegExp(" "), ""); |
367 | return setStanza(MAPPING, interface, currentMapping); | 377 | return setStanza(MAPPING, interface, currentMapping); |
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 | */ |
374 | void Interfaces::addMapping(QString option){ | 384 | void 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 | */ | ||
393 | bool 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 | */ |
385 | bool Interfaces::setMap(QString map, QString value){ | 406 | bool 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 | */ | ||
416 | bool 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 | */ |
395 | QString Interfaces::getMap(QString map, bool &error){ | 426 | QString 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. |
402 | * @return true if successfull. | 433 | * @return true if successfull. |
403 | */ | 434 | */ |
404 | bool Interfaces::setScript(QString argument){ | 435 | bool Interfaces::setScript(QString argument){ |
405 | return setOption(currentMapping, "script", argument); | 436 | return setOption(currentMapping, "script", argument); |
406 | } | 437 | } |
407 | 438 | ||
408 | /** | 439 | /** |
409 | * @param error true if could not retrieve the current script argument. | 440 | * @param error true if could not retrieve the current script argument. |
410 | * @return QString the argument of the script for the current mapping. | 441 | * @return QString the argument of the script for the current mapping. |
411 | */ | 442 | */ |
412 | QString Interfaces::getScript(bool &error){ | 443 | QString Interfaces::getScript(bool &error){ |
413 | return getOption(currentMapping, "script", error); | 444 | return getOption(currentMapping, "script", error); |
414 | } | 445 | } |
415 | 446 | ||
416 | /** | 447 | /** |
417 | * Helper function used to parse through the QStringList and put pointers in | 448 | * Helper function used to parse through the QStringList and put pointers in |
418 | * the correct place. | 449 | * the correct place. |
419 | * @param stanza The stanza (auto, iface, mapping) to look for. | 450 | * @param stanza The stanza (auto, iface, mapping) to look for. |
420 | * @param option string that must be in the stanza's main line. | 451 | * @param option string that must be in the stanza's main line. |
421 | * @param interator interator to place at location of stanza if successfull. | 452 | * @param interator interator to place at location of stanza if successfull. |
422 | * @return bool true if the stanza is found. | 453 | * @return bool true if the stanza is found. |
423 | */ | 454 | */ |
424 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | 455 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ |
425 | bool found = false; | 456 | bool found = false; |
426 | iterator = interfaces.end(); | 457 | iterator = interfaces.end(); |
427 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 458 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
428 | QString line = (*it).simplifyWhiteSpace(); | 459 | QString line = (*it).simplifyWhiteSpace(); |
429 | if(line.contains(stanza) && line.contains(option)){ | 460 | if(line.contains(stanza) && line.contains(option)){ |
430 | uint point = line.find(option); | 461 | uint point = line.find(option); |
431 | bool valid = true; | 462 | bool valid = true; |
432 | if(point > 0){ | 463 | if(point > 0){ |
433 | // There are more chars in the line. check +1 | 464 | // There are more chars in the line. check +1 |
434 | if(line.at(point-1) != ' ') | 465 | if(line.at(point-1) != ' ') |
435 | valid = false; | 466 | valid = false; |
436 | } | 467 | } |
437 | point += option.length(); | 468 | point += option.length(); |
438 | if(point < line.length()-1){ | 469 | if(point < line.length()-1){ |
439 | // There are more chars in the line. check -1 | 470 | // There are more chars in the line. check -1 |
440 | if(line.at(point) != ' ') | 471 | if(line.at(point) != ' ') |
441 | valid = false; | 472 | valid = false; |
442 | } | 473 | } |
443 | if(valid){ | 474 | if(valid){ |
444 | if(found == true){ | 475 | if(found == true){ |
445 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 476 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
446 | } | 477 | } |
447 | found = true; | 478 | found = true; |
448 | iterator = it; | 479 | iterator = it; |
449 | } | 480 | } |
450 | } | 481 | } |
451 | } | 482 | } |
452 | return found; | 483 | return found; |
453 | } | 484 | } |
454 | 485 | ||
455 | /** | 486 | /** |
456 | * Sets a value of an option in a stanza | 487 | * Sets a value of an option in a stanza |
457 | * @param start the start of the stanza | 488 | * @param start the start of the stanza |
458 | * @param option the option to use when setting value. | 489 | * @param option the option to use when setting value. |
459 | * @return bool true if successfull, false otherwise. | 490 | * @return bool true if successfull, false otherwise. |
460 | */ | 491 | */ |
461 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ |
462 | if(start == interfaces.end()) | 493 | if(start == interfaces.end()) |
463 | return false; | 494 | return false; |
464 | 495 | ||
465 | bool found = false; | 496 | bool found = false; |
466 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
467 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 498 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
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 | */ | ||
527 | bool 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 | */ |
499 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | 553 | bool 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; |
505 | for (it; it != interfaces.end(); ++it ) { | 559 | for (it; it != interfaces.end(); ++it ) { |
506 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 560 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
507 | break; | 561 | break; |
508 | } | 562 | } |
509 | it = interfaces.remove(it); | 563 | it = interfaces.remove(it); |
510 | it = --it; | 564 | it = --it; |
511 | } | 565 | } |
512 | // Leave a space between this interface and the next. | 566 | // Leave a space between this interface and the next. |
513 | interfaces.insert(it, QString("")); | 567 | interfaces.insert(it, QString("")); |
514 | return true; | 568 | return true; |
515 | } | 569 | } |
516 | 570 | ||
517 | /** | 571 | /** |
518 | * Gets a value of an option in a stanza | 572 | * Gets a value of an option in a stanza |
519 | * @param start the start of the stanza | 573 | * @param start the start of the stanza |
520 | * @param option the option to use when getting the value. | 574 | * @param option the option to use when getting the value. |
521 | * @param bool true if errors false otherwise. | 575 | * @param bool true if errors false otherwise. |
522 | * @return QString the value of option QString::null() if error == true. | 576 | * @return QString the value of option QString::null() if error == true. |
523 | */ | 577 | */ |
524 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | 578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ |
525 | if(start == interfaces.end()){ | 579 | if(start == interfaces.end()){ |
526 | error = false; | 580 | error = false; |
527 | return QString(); | 581 | return QString(); |
528 | } | 582 | } |
529 | 583 | ||
530 | QString value; | 584 | QString value; |
531 | bool found = false; | 585 | bool found = false; |
532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 587 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
534 | break; | 588 | break; |
535 | } | 589 | } |
536 | if((*it).contains(option)){ | 590 | if((*it).contains(option)){ |
537 | if(found) | 591 | if(found) |
538 | qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); | 592 | qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); |
539 | found = true; | 593 | found = true; |
540 | QString line = (*it).simplifyWhiteSpace(); | 594 | QString line = (*it).simplifyWhiteSpace(); |
diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h index 7cf04f0..e09ea71 100644 --- a/noncore/net/networksetup/interfaces.h +++ b/noncore/net/networksetup/interfaces.h | |||
@@ -1,72 +1,76 @@ | |||
1 | #ifndef INTERFACES_H | 1 | #ifndef INTERFACES_H |
2 | #define INTERFACES_H | 2 | #define INTERFACES_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | #define INTERFACES_LOOPBACK "loopback" | 7 | #define INTERFACES_LOOPBACK "loopback" |
8 | 8 | ||
9 | #define INTERFACES_FAMILY_INET "inet" | 9 | #define INTERFACES_FAMILY_INET "inet" |
10 | #define INTERFACES_FAMILY_IPX "ipx" | 10 | #define INTERFACES_FAMILY_IPX "ipx" |
11 | #define INTERFACES_FAMILY_INET6 "inet6" | 11 | #define INTERFACES_FAMILY_INET6 "inet6" |
12 | 12 | ||
13 | #define INTERFACES_METHOD_DHCP "dhcp" | 13 | #define INTERFACES_METHOD_DHCP "dhcp" |
14 | #define INTERFACES_METHOD_STATIC "static" | 14 | #define INTERFACES_METHOD_STATIC "static" |
15 | #define INTERFACES_METHOD_PPP "ppp" | 15 | #define INTERFACES_METHOD_PPP "ppp" |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * This class provides a clean frontend for parsing the network interfaces file. | 18 | * This class provides a clean frontend for parsing the network interfaces file. |
19 | * It provides helper functions to minipulate the options within the file. | 19 | * It provides helper functions to minipulate the options within the file. |
20 | * See the interfaces man page for the syntax rules. | 20 | * See the interfaces man page for the syntax rules. |
21 | */ | 21 | */ |
22 | class Interfaces { | 22 | class Interfaces { |
23 | 23 | ||
24 | public: | 24 | public: |
25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); | 25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); |
26 | QStringList getInterfaceList(); | 26 | QStringList getInterfaceList(); |
27 | 27 | ||
28 | bool isAuto(QString interface); | 28 | bool isAuto(QString interface); |
29 | bool setAuto(QString interface, bool setAuto); | 29 | bool setAuto(QString interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | bool removeInterface(); |
32 | bool addInterface(QString interface, QString family, QString method); | 32 | bool addInterface(QString interface, QString family, QString method); |
33 | bool copyInterface(QString oldInterface, QString newInterface); | 33 | bool copyInterface(QString oldInterface, QString newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | bool isInterfaceSet(); | 35 | bool isInterfaceSet(); |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(QString newName); | 37 | bool setInterfaceName(QString newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(QString newName); | 39 | bool setInterfaceFamily(QString newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(QString newName); | 41 | bool setInterfaceMethod(QString newName); |
42 | QString getInterfaceOption(QString option, bool &error); | 42 | QString getInterfaceOption(QString option, bool &error); |
43 | bool setInterfaceOption(QString option, QString value); | 43 | bool setInterfaceOption(QString option, QString value); |
44 | bool removeInterfaceOption(QString option, QString value); | ||
44 | bool removeAllInterfaceOptions(); | 45 | bool removeAllInterfaceOptions(); |
45 | 46 | ||
46 | bool setMapping(QString interface); | 47 | bool setMapping(QString interface); |
48 | bool removeMapping(); | ||
47 | void addMapping(QString options); | 49 | void addMapping(QString options); |
48 | bool setMap(QString map, QString value); | 50 | bool setMap(QString map, QString value); |
51 | bool removeMap(QString map, QString value); | ||
49 | QString getMap(QString map, bool &error); | 52 | QString getMap(QString map, bool &error); |
50 | bool setScript(QString); | 53 | bool setScript(QString); |
51 | QString getScript(bool &error); | 54 | QString getScript(bool &error); |
52 | 55 | ||
53 | bool write(); | 56 | bool write(); |
54 | 57 | ||
55 | private: | 58 | private: |
56 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); | 59 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); |
57 | bool setOption(QStringList::Iterator start, QString option, QString value); | 60 | bool setOption(QStringList::Iterator start, QString option, QString value); |
61 | bool removeOption(QStringList::Iterator start, QString option, QString value); | ||
58 | QString getOption(QStringList::Iterator start, QString option, bool &error); | 62 | QString getOption(QStringList::Iterator start, QString option, bool &error); |
59 | bool removeAllOptions(QStringList::Iterator start); | 63 | bool removeAllOptions(QStringList::Iterator start); |
60 | 64 | ||
61 | QString interfacesFile; | 65 | QString interfacesFile; |
62 | QStringList interfaces; | 66 | QStringList interfaces; |
63 | QStringList::Iterator currentIface; | 67 | QStringList::Iterator currentIface; |
64 | QStringList::Iterator currentMapping; | 68 | QStringList::Iterator currentMapping; |
65 | 69 | ||
66 | QStringList acceptedFamily; | 70 | QStringList acceptedFamily; |
67 | }; | 71 | }; |
68 | 72 | ||
69 | #endif | 73 | #endif |
70 | 74 | ||
71 | // interfaces | 75 | // interfaces |
72 | 76 | ||
diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp index bdbdfde..1327726 100644 --- a/noncore/net/networksetup/interfacesetupimp.cpp +++ b/noncore/net/networksetup/interfacesetupimp.cpp | |||
@@ -47,97 +47,96 @@ void InterfaceSetupImp::accept(){ | |||
47 | */ | 47 | */ |
48 | bool InterfaceSetupImp::saveSettings(){ | 48 | bool InterfaceSetupImp::saveSettings(){ |
49 | // eh can't really do anything about it other then return. :-D | 49 | // eh can't really do anything about it other then return. :-D |
50 | if(!interfaces->isInterfaceSet()) | 50 | if(!interfaces->isInterfaceSet()) |
51 | return true; | 51 | return true; |
52 | 52 | ||
53 | bool error = false; | 53 | bool error = false; |
54 | // Loopback case | 54 | // Loopback case |
55 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 55 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
56 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 56 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
57 | return true; | 57 | return true; |
58 | } | 58 | } |
59 | 59 | ||
60 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ | 60 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ |
61 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); | 61 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); |
62 | return false; | 62 | return false; |
63 | } | 63 | } |
64 | interfaces->removeAllInterfaceOptions(); | 64 | interfaces->removeAllInterfaceOptions(); |
65 | 65 | ||
66 | // DHCP | 66 | // DHCP |
67 | if(dhcpCheckBox->isChecked()){ | 67 | if(dhcpCheckBox->isChecked()){ |
68 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 68 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); |
69 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 69 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
70 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 70 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
71 | } | 71 | } |
72 | else{ | 72 | else{ |
73 | interfaces->setInterfaceMethod("static"); | 73 | interfaces->setInterfaceMethod("static"); |
74 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 74 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); |
75 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 75 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); |
76 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 76 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); |
77 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 77 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
78 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); | 78 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); |
79 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); | 79 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); |
80 | } | 80 | } |
81 | 81 | ||
82 | // IP Information | 82 | // IP Information |
83 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 83 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
84 | return true; | 84 | return true; |
85 | } | 85 | } |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * The Profile has changed. | 88 | * The Profile has changed. |
89 | * @profile the new profile. | 89 | * @profile the new profile. |
90 | */ | 90 | */ |
91 | void InterfaceSetupImp::setProfile(const QString &profile){ | 91 | void InterfaceSetupImp::setProfile(const QString &profile){ |
92 | QString newInterfaceName = interface->getInterfaceName(); | 92 | QString newInterfaceName = interface->getInterfaceName(); |
93 | if(profile.length() > 0) | 93 | if(profile.length() > 0) |
94 | newInterfaceName += "_" + profile; | 94 | newInterfaceName += "_" + profile; |
95 | qDebug( newInterfaceName.latin1()); | ||
96 | // See if we have to make a interface. | 95 | // See if we have to make a interface. |
97 | if(!interfaces->setInterface(newInterfaceName)){ | 96 | if(!interfaces->setInterface(newInterfaceName)){ |
98 | // Add making for this new interface if need too | 97 | // Add making for this new interface if need too |
99 | if(profile != ""){ | 98 | if(profile != ""){ |
100 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 99 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); |
101 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 100 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
102 | interfaces->addMapping(interface->getInterfaceName()); | 101 | interfaces->addMapping(interface->getInterfaceName()); |
103 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 102 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
104 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 103 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); |
105 | return; | 104 | return; |
106 | } | 105 | } |
107 | } | 106 | } |
108 | interfaces->setMap("map", newInterfaceName); | 107 | interfaces->setMap("map", newInterfaceName); |
109 | interfaces->setScript("getprofile.sh"); | 108 | interfaces->setScript("getprofile.sh"); |
110 | } | 109 | } |
111 | else{ | 110 | else{ |
112 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 111 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
113 | if(!interfaces->setInterface(newInterfaceName)){ | 112 | if(!interfaces->setInterface(newInterfaceName)){ |
114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 113 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); |
115 | return; | 114 | return; |
116 | } | 115 | } |
117 | } | 116 | } |
118 | } | 117 | } |
119 | 118 | ||
120 | // We must have a valid interface to get this far so read some settings. | 119 | // We must have a valid interface to get this far so read some settings. |
121 | 120 | ||
122 | // DHCP | 121 | // DHCP |
123 | bool error = false; | 122 | bool error = false; |
124 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 123 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
125 | dhcpCheckBox->setChecked(true); | 124 | dhcpCheckBox->setChecked(true); |
126 | else | 125 | else |
127 | dhcpCheckBox->setChecked(false); | 126 | dhcpCheckBox->setChecked(false); |
128 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 127 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); |
129 | if(error) | 128 | if(error) |
130 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 129 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); |
131 | if(error) | 130 | if(error) |
132 | leaseTime->setValue(24); | 131 | leaseTime->setValue(24); |
133 | 132 | ||
134 | // IP Information | 133 | // IP Information |
135 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 134 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); |
136 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); | 135 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); |
137 | if(dns.contains(" ")){ | 136 | if(dns.contains(" ")){ |
138 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 137 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
139 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 138 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
140 | } | 139 | } |
141 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 140 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); |
142 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 141 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); |
143 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 142 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); |
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 9f07f0d..01063c2 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -1,171 +1,173 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addconnectionimp.h" | 2 | #include "addconnectionimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "interfaces.h" | 5 | #include "interfaces.h" |
6 | 6 | ||
7 | #include "module.h" | 7 | #include "module.h" |
8 | 8 | ||
9 | #include "kprocess.h" | 9 | #include "kprocess.h" |
10 | 10 | ||
11 | #include <qpushbutton.h> | 11 | #include <qpushbutton.h> |
12 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
13 | #include <qlistbox.h> | 13 | #include <qlistbox.h> |
14 | #include <qlineedit.h> | 14 | #include <qlineedit.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | #include <qheader.h> | 16 | #include <qheader.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | 18 | ||
19 | #include <qmainwindow.h> | 19 | #include <qmainwindow.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qlibrary.h> | 23 | #include <qpe/qlibrary.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | 26 | ||
27 | #include <qlist.h> | 27 | #include <qlist.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | 31 | ||
32 | #define TEMP_ALL "/tmp/ifconfig-a" | 32 | #define TEMP_ALL "/tmp/ifconfig-a" |
33 | #define TEMP_UP "/tmp/ifconfig" | 33 | #define TEMP_UP "/tmp/ifconfig" |
34 | 34 | ||
35 | #define SCHEME "/var/lib/pcmcia/scheme" | 35 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
36 | |||
36 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 37 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
37 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 38 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
38 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 39 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
39 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 40 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
40 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 41 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
41 | 42 | ||
42 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 43 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
43 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 44 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
44 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 45 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
45 | 46 | ||
46 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 47 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
47 | // Load connections. | 48 | // Load connections. |
48 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 49 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
49 | getInterfaceList(); | 50 | getInterfaceList(); |
50 | connectionList->header()->hide(); | 51 | connectionList->header()->hide(); |
51 | 52 | ||
52 | 53 | ||
53 | Config cfg("NetworkSetup"); | 54 | Config cfg("NetworkSetup"); |
54 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 55 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
55 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 56 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
56 | profilesList->insertItem((*it)); | 57 | profilesList->insertItem((*it)); |
57 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 58 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
58 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 59 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
60 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | ||
59 | 61 | ||
60 | QFile file(SCHEME); | 62 | QFile file(scheme); |
61 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 63 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
62 | QTextStream stream( &file ); // use a text stream | 64 | QTextStream stream( &file ); // use a text stream |
63 | while ( !stream.eof() ) { // until end of file... | 65 | while ( !stream.eof() ) { // until end of file... |
64 | QString line = stream.readLine(); // line of text excluding '\n' | 66 | QString line = stream.readLine(); // line of text excluding '\n' |
65 | if(line.contains("SCHEME")){ | 67 | if(line.contains("SCHEME")){ |
66 | line = line.mid(7, line.length()); | 68 | line = line.mid(7, line.length()); |
67 | currentProfileLabel->setText(line); | 69 | currentProfileLabel->setText(line); |
68 | break; | 70 | break; |
69 | } | 71 | } |
70 | } | 72 | } |
71 | file.close(); | 73 | file.close(); |
72 | } | 74 | } |
73 | } | 75 | } |
74 | 76 | ||
75 | /** | 77 | /** |
76 | * Deconstructor. Save profiles. Delete loaded libraries. | 78 | * Deconstructor. Save profiles. Delete loaded libraries. |
77 | */ | 79 | */ |
78 | MainWindowImp::~MainWindowImp(){ | 80 | MainWindowImp::~MainWindowImp(){ |
79 | // Save profiles. | 81 | // Save profiles. |
80 | Config cfg("NetworkSetup"); | 82 | Config cfg("NetworkSetup"); |
81 | cfg.setGroup("General"); | 83 | cfg.setGroup("General"); |
82 | cfg.writeEntry("Profiles", profiles.join(" ")); | 84 | cfg.writeEntry("Profiles", profiles.join(" ")); |
83 | 85 | ||
84 | // Delete Modules and Libraries | 86 | // Delete Modules and Libraries |
85 | QMap<Module*, QLibrary*>::Iterator it; | 87 | QMap<Module*, QLibrary*>::Iterator it; |
86 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
87 | delete it.key(); | 89 | delete it.key(); |
88 | delete it.data(); | 90 | delete it.data(); |
89 | } | 91 | } |
90 | } | 92 | } |
91 | 93 | ||
92 | /** | 94 | /** |
93 | * Load all modules that are found in the path | 95 | * Load all modules that are found in the path |
94 | * @param path a directory that is scaned for any plugins that can be loaded | 96 | * @param path a directory that is scaned for any plugins that can be loaded |
95 | * and attempts to load them | 97 | * and attempts to load them |
96 | */ | 98 | */ |
97 | void MainWindowImp::loadModules(QString path){ | 99 | void MainWindowImp::loadModules(QString path){ |
98 | qDebug(path.latin1()); | 100 | //qDebug(path.latin1()); |
99 | QDir d(path); | 101 | QDir d(path); |
100 | if(!d.exists()) | 102 | if(!d.exists()) |
101 | return; | 103 | return; |
102 | 104 | ||
103 | // Don't want sym links | 105 | // Don't want sym links |
104 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
105 | const QFileInfoList *list = d.entryInfoList(); | 107 | const QFileInfoList *list = d.entryInfoList(); |
106 | QFileInfoListIterator it( *list ); | 108 | QFileInfoListIterator it( *list ); |
107 | QFileInfo *fi; | 109 | QFileInfo *fi; |
108 | while ( (fi=it.current()) ) { | 110 | while ( (fi=it.current()) ) { |
109 | if(fi->fileName().contains(".so")){ | 111 | if(fi->fileName().contains(".so")){ |
110 | loadPlugin(path + "/" + fi->fileName()); | 112 | loadPlugin(path + "/" + fi->fileName()); |
111 | } | 113 | } |
112 | ++it; | 114 | ++it; |
113 | } | 115 | } |
114 | } | 116 | } |
115 | 117 | ||
116 | /** | 118 | /** |
117 | * Attempt to load a function and resolve a function. | 119 | * Attempt to load a function and resolve a function. |
118 | * @param pluginFileName - the name of the file in which to attempt to load | 120 | * @param pluginFileName - the name of the file in which to attempt to load |
119 | * @param resolveString - function pointer to resolve | 121 | * @param resolveString - function pointer to resolve |
120 | * @return pointer to the function with name resolveString or NULL | 122 | * @return pointer to the function with name resolveString or NULL |
121 | */ | 123 | */ |
122 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
123 | qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
124 | QLibrary *lib = new QLibrary(pluginFileName); | 126 | QLibrary *lib = new QLibrary(pluginFileName); |
125 | void *functionPointer = lib->resolve(resolveString); | 127 | void *functionPointer = lib->resolve(resolveString); |
126 | if( !functionPointer ){ | 128 | if( !functionPointer ){ |
127 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
128 | delete lib; | 130 | delete lib; |
129 | return NULL; | 131 | return NULL; |
130 | } | 132 | } |
131 | 133 | ||
132 | // Try to get an object. | 134 | // Try to get an object. |
133 | Module *object = ((Module* (*)()) functionPointer)(); | 135 | Module *object = ((Module* (*)()) functionPointer)(); |
134 | if(object == NULL){ | 136 | if(object == NULL){ |
135 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
136 | delete lib; | 138 | delete lib; |
137 | return NULL; | 139 | return NULL; |
138 | } | 140 | } |
139 | 141 | ||
140 | // Store for deletion later | 142 | // Store for deletion later |
141 | libraries.insert(object, lib); | 143 | libraries.insert(object, lib); |
142 | return object; | 144 | return object; |
143 | } | 145 | } |
144 | 146 | ||
145 | /** | 147 | /** |
146 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 148 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
147 | * load the plugin and append it to the list | 149 | * load the plugin and append it to the list |
148 | */ | 150 | */ |
149 | void MainWindowImp::addClicked(){ | 151 | void MainWindowImp::addClicked(){ |
150 | QMap<Module*, QLibrary*>::Iterator it; | 152 | QMap<Module*, QLibrary*>::Iterator it; |
151 | QMap<QString, QString> list; | 153 | QMap<QString, QString> list; |
152 | QMap<QString, Module*> newInterfaceOwners; | 154 | QMap<QString, Module*> newInterfaceOwners; |
153 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 155 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
154 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | 156 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
155 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
156 | if(it.key()){ | 158 | if(it.key()){ |
157 | (it.key())->possibleNewInterfaces(list); | 159 | (it.key())->possibleNewInterfaces(list); |
158 | } | 160 | } |
159 | } | 161 | } |
160 | // See if the list has anything that we can add. | 162 | // See if the list has anything that we can add. |
161 | if(list.count() == 0){ | 163 | if(list.count() == 0){ |
162 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | 164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); |
163 | return; | 165 | return; |
164 | } | 166 | } |
165 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
166 | addNewConnection.addConnections(list); | 168 | addNewConnection.addConnections(list); |
167 | addNewConnection.showMaximized(); | 169 | addNewConnection.showMaximized(); |
168 | if(QDialog::Accepted == addNewConnection.exec()){ | 170 | if(QDialog::Accepted == addNewConnection.exec()){ |
169 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
170 | if(!item) | 172 | if(!item) |
171 | return; | 173 | return; |
@@ -445,87 +447,105 @@ void MainWindowImp::updateInterface(Interface *i){ | |||
445 | void MainWindowImp::newProfileChanged(const QString& newText){ | 447 | void MainWindowImp::newProfileChanged(const QString& newText){ |
446 | if(newText.length() > 0) | 448 | if(newText.length() > 0) |
447 | newProfileButton->setEnabled(true); | 449 | newProfileButton->setEnabled(true); |
448 | else | 450 | else |
449 | newProfileButton->setEnabled(false); | 451 | newProfileButton->setEnabled(false); |
450 | } | 452 | } |
451 | 453 | ||
452 | /** | 454 | /** |
453 | * Adds a new profile to the list of profiles. | 455 | * Adds a new profile to the list of profiles. |
454 | * Don't add profiles that already exists. | 456 | * Don't add profiles that already exists. |
455 | * Appends to the list and QStringList | 457 | * Appends to the list and QStringList |
456 | */ | 458 | */ |
457 | void MainWindowImp::addProfile(){ | 459 | void MainWindowImp::addProfile(){ |
458 | QString newProfileName = newProfile->text(); | 460 | QString newProfileName = newProfile->text(); |
459 | if(profiles.grep(newProfileName).count() > 0){ | 461 | if(profiles.grep(newProfileName).count() > 0){ |
460 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
461 | return; | 463 | return; |
462 | } | 464 | } |
463 | profiles.append(newProfileName); | 465 | profiles.append(newProfileName); |
464 | profilesList->insertItem(newProfileName); | 466 | profilesList->insertItem(newProfileName); |
465 | } | 467 | } |
466 | 468 | ||
467 | /** | 469 | /** |
468 | * Removes the currently selected profile in the combo. | 470 | * Removes the currently selected profile in the combo. |
469 | * Doesn't delete if there are less then 2 profiles. | 471 | * Doesn't delete if there are less then 2 profiles. |
470 | */ | 472 | */ |
471 | void MainWindowImp::removeProfile(){ | 473 | void MainWindowImp::removeProfile(){ |
472 | if(profilesList->count() <= 1){ | 474 | if(profilesList->count() <= 1){ |
473 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); | 475 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); |
474 | return; | 476 | return; |
475 | } | 477 | } |
476 | QString profileToRemove = profilesList->currentText(); | 478 | QString profileToRemove = profilesList->currentText(); |
477 | if(profileToRemove == "All"){ | 479 | if(profileToRemove == "All"){ |
478 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); | 480 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); |
479 | return; | 481 | return; |
480 | } | 482 | } |
481 | // Can't remove the curent profile | 483 | // Can't remove the curent profile |
482 | if(profileToRemove == currentProfileLabel->text()){ | 484 | if(profileToRemove == currentProfileLabel->text()){ |
483 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); | 485 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); |
484 | return; | 486 | return; |
485 | 487 | ||
486 | } | 488 | } |
487 | 489 | ||
488 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 490 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
489 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 491 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
490 | profilesList->clear(); | 492 | profilesList->clear(); |
491 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 493 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
492 | profilesList->insertItem((*it)); | 494 | profilesList->insertItem((*it)); |
493 | } | ||
494 | 495 | ||
495 | // Remove any interface settings and mappings. | 496 | // Remove any interface settings and mappings. |
496 | //TODO | 497 | Interfaces interfaces; |
498 | // Go through them one by one | ||
499 | QMap<Interface*, QListViewItem*>::Iterator it; | ||
500 | for( it = items.begin(); it != items.end(); ++it ){ | ||
501 | QString interfaceName = it.key()->getInterfaceName(); | ||
502 | qDebug(interfaceName.latin1()); | ||
503 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ | ||
504 | interfaces.removeInterface(); | ||
505 | if(interfaces.setMapping(interfaceName)){ | ||
506 | if(profilesList->count() == 1) | ||
507 | interfaces.removeMapping(); | ||
508 | else{ | ||
509 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); | ||
510 | } | ||
511 | } | ||
512 | interfaces.write(); | ||
513 | break; | ||
514 | } | ||
515 | } | ||
516 | } | ||
497 | } | 517 | } |
498 | 518 | ||
499 | /** | 519 | /** |
500 | * A new profile has been selected, change. | 520 | * A new profile has been selected, change. |
501 | * @param newProfile the new profile. | 521 | * @param newProfile the new profile. |
502 | */ | 522 | */ |
503 | void MainWindowImp::changeProfile(){ | 523 | void MainWindowImp::changeProfile(){ |
504 | if(profilesList->currentItem() == -1){ | 524 | if(profilesList->currentItem() == -1){ |
505 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); | 525 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); |
506 | return; | 526 | return; |
507 | } | 527 | } |
508 | QString newProfile = profilesList->text(profilesList->currentItem()); | 528 | QString newProfile = profilesList->text(profilesList->currentItem()); |
509 | if(newProfile != currentProfileLabel->text()){ | 529 | if(newProfile != currentProfileLabel->text()){ |
510 | currentProfileLabel->setText(newProfile); | 530 | currentProfileLabel->setText(newProfile); |
511 | QFile::remove(SCHEME); | 531 | QFile::remove(scheme); |
512 | QFile file(SCHEME); | 532 | QFile file(scheme); |
513 | if ( file.open(IO_ReadWrite) ) { | 533 | if ( file.open(IO_ReadWrite) ) { |
514 | QTextStream stream( &file ); | 534 | QTextStream stream( &file ); |
515 | stream << QString("SCHEME=%1").arg(newProfile); | 535 | stream << QString("SCHEME=%1").arg(newProfile); |
516 | file.close(); | 536 | file.close(); |
517 | } | 537 | } |
518 | // restart all up devices? | 538 | // restart all up devices? |
519 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ | 539 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ |
520 | // Go through them one by one | 540 | // Go through them one by one |
521 | QMap<Interface*, QListViewItem*>::Iterator it; | 541 | QMap<Interface*, QListViewItem*>::Iterator it; |
522 | for( it = items.begin(); it != items.end(); ++it ){ | 542 | for( it = items.begin(); it != items.end(); ++it ){ |
523 | if(it.key()->getStatus() == true) | 543 | if(it.key()->getStatus() == true) |
524 | it.key()->restart(); | 544 | it.key()->restart(); |
525 | } | 545 | } |
526 | } | 546 | } |
527 | } | 547 | } |
528 | } | 548 | } |
529 | 549 | ||
530 | // mainwindowimp.cpp | 550 | // mainwindowimp.cpp |
531 | 551 | ||
diff --git a/noncore/net/networksetup/mainwindowimp.h b/noncore/net/networksetup/mainwindowimp.h index c67c161..e5284b4 100644 --- a/noncore/net/networksetup/mainwindowimp.h +++ b/noncore/net/networksetup/mainwindowimp.h | |||
@@ -5,54 +5,55 @@ | |||
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | class Module; | 8 | class Module; |
9 | class Interface; | 9 | class Interface; |
10 | class QLibrary; | 10 | class QLibrary; |
11 | class KProcess; | 11 | class KProcess; |
12 | 12 | ||
13 | class MainWindowImp : public MainWindow { | 13 | class MainWindowImp : public MainWindow { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | MainWindowImp(QWidget *parent=0, const char *name=0); | 17 | MainWindowImp(QWidget *parent=0, const char *name=0); |
18 | ~MainWindowImp(); | 18 | ~MainWindowImp(); |
19 | 19 | ||
20 | private slots: | 20 | private slots: |
21 | void addClicked(); | 21 | void addClicked(); |
22 | void removeClicked(); | 22 | void removeClicked(); |
23 | void configureClicked(); | 23 | void configureClicked(); |
24 | void informationClicked(); | 24 | void informationClicked(); |
25 | 25 | ||
26 | void jobDone(KProcess *process); | 26 | void jobDone(KProcess *process); |
27 | void getInterfaceList(); | 27 | void getInterfaceList(); |
28 | 28 | ||
29 | void addProfile(); | 29 | void addProfile(); |
30 | void removeProfile(); | 30 | void removeProfile(); |
31 | void changeProfile(); | 31 | void changeProfile(); |
32 | 32 | ||
33 | void updateInterface(Interface *i); | 33 | void updateInterface(Interface *i); |
34 | void newProfileChanged(const QString& newText); | 34 | void newProfileChanged(const QString& newText); |
35 | 35 | ||
36 | private: | 36 | private: |
37 | void loadModules(QString path); | 37 | void loadModules(QString path); |
38 | 38 | ||
39 | Module* loadPlugin(QString pluginFileName, | 39 | Module* loadPlugin(QString pluginFileName, |
40 | QString resolveString = "create_plugin"); | 40 | QString resolveString = "create_plugin"); |
41 | 41 | ||
42 | // For our local list of names | 42 | // For our local list of names |
43 | QMap<QString, Interface*> interfaceNames; | 43 | QMap<QString, Interface*> interfaceNames; |
44 | 44 | ||
45 | QMap<Module*, QLibrary*> libraries; | 45 | QMap<Module*, QLibrary*> libraries; |
46 | QMap<Interface*, QListViewItem*> items; | 46 | QMap<Interface*, QListViewItem*> items; |
47 | QMap<QListViewItem*, Interface*> interfaceItems; | 47 | QMap<QListViewItem*, Interface*> interfaceItems; |
48 | 48 | ||
49 | QMap<KProcess*, QString> threads; | 49 | QMap<KProcess*, QString> threads; |
50 | QStringList profiles; | 50 | QStringList profiles; |
51 | 51 | ||
52 | bool advancedUserMode; | 52 | bool advancedUserMode; |
53 | QString scheme; | ||
53 | }; | 54 | }; |
54 | 55 | ||
55 | #endif | 56 | #endif |
56 | 57 | ||
57 | // mainwindowimp.h | 58 | // mainwindowimp.h |
58 | 59 | ||
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 | |||
@@ -290,251 +290,305 @@ bool Interfaces::setInterfaceName(QString newName){ | |||
290 | return !returnValue; | 290 | return !returnValue; |
291 | } | 291 | } |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Sets the interface family to newName. | 294 | * Sets the interface family to newName. |
295 | * @param newName the new name of the interface. Must be one of the families | 295 | * @param newName the new name of the interface. Must be one of the families |
296 | * defined in the interfaces.h file. | 296 | * defined in the interfaces.h file. |
297 | * @return bool true if successfull. | 297 | * @return bool true if successfull. |
298 | */ | 298 | */ |
299 | bool Interfaces::setInterfaceFamily(QString newName){ | 299 | bool Interfaces::setInterfaceFamily(QString newName){ |
300 | if(currentIface == interfaces.end()) | 300 | if(currentIface == interfaces.end()) |
301 | return false; | 301 | return false; |
302 | if(acceptedFamily.contains(newName)==0) | 302 | if(acceptedFamily.contains(newName)==0) |
303 | return false; | 303 | return false; |
304 | bool returnValue = false; | 304 | bool returnValue = false; |
305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
306 | return !returnValue; | 306 | return !returnValue; |
307 | } | 307 | } |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Sets the interface method to newName | 310 | * Sets the interface method to newName |
311 | * @param newName the new name of the interface | 311 | * @param newName the new name of the interface |
312 | * @return bool true if successfull. | 312 | * @return bool true if successfull. |
313 | */ | 313 | */ |
314 | bool Interfaces::setInterfaceMethod(QString newName){ | 314 | bool Interfaces::setInterfaceMethod(QString newName){ |
315 | if(currentIface == interfaces.end()) | 315 | if(currentIface == interfaces.end()) |
316 | return false; | 316 | return false; |
317 | bool returnValue = false; | 317 | bool returnValue = false; |
318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
319 | return !returnValue; | 319 | return !returnValue; |
320 | } | 320 | } |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Get a value for an option in the currently selected interface. For example | 323 | * Get a value for an option in the currently selected interface. For example |
324 | * calling getInterfaceOption("address") on the following stanza would | 324 | * calling getInterfaceOption("address") on the following stanza would |
325 | * return 192.168.1.1. | 325 | * return 192.168.1.1. |
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 | */ |
332 | QString Interfaces::getInterfaceOption(QString option, bool &error){ | 332 | QString 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 | */ |
345 | bool Interfaces::setInterfaceOption(QString option, QString value){ | 344 | bool 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 | */ | ||
355 | bool 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 | */ |
353 | bool Interfaces::removeAllInterfaceOptions(){ | 363 | bool 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. |
362 | * @return bool true if it is successfull. | 372 | * @return bool true if it is successfull. |
363 | */ | 373 | */ |
364 | bool Interfaces::setMapping(QString interface){ | 374 | bool Interfaces::setMapping(QString interface){ |
365 | interface = interface.simplifyWhiteSpace(); | 375 | interface = interface.simplifyWhiteSpace(); |
366 | interface = interface.replace(QRegExp(" "), ""); | 376 | interface = interface.replace(QRegExp(" "), ""); |
367 | return setStanza(MAPPING, interface, currentMapping); | 377 | return setStanza(MAPPING, interface, currentMapping); |
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 | */ |
374 | void Interfaces::addMapping(QString option){ | 384 | void 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 | */ | ||
393 | bool 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 | */ |
385 | bool Interfaces::setMap(QString map, QString value){ | 406 | bool 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 | */ | ||
416 | bool 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 | */ |
395 | QString Interfaces::getMap(QString map, bool &error){ | 426 | QString 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. |
402 | * @return true if successfull. | 433 | * @return true if successfull. |
403 | */ | 434 | */ |
404 | bool Interfaces::setScript(QString argument){ | 435 | bool Interfaces::setScript(QString argument){ |
405 | return setOption(currentMapping, "script", argument); | 436 | return setOption(currentMapping, "script", argument); |
406 | } | 437 | } |
407 | 438 | ||
408 | /** | 439 | /** |
409 | * @param error true if could not retrieve the current script argument. | 440 | * @param error true if could not retrieve the current script argument. |
410 | * @return QString the argument of the script for the current mapping. | 441 | * @return QString the argument of the script for the current mapping. |
411 | */ | 442 | */ |
412 | QString Interfaces::getScript(bool &error){ | 443 | QString Interfaces::getScript(bool &error){ |
413 | return getOption(currentMapping, "script", error); | 444 | return getOption(currentMapping, "script", error); |
414 | } | 445 | } |
415 | 446 | ||
416 | /** | 447 | /** |
417 | * Helper function used to parse through the QStringList and put pointers in | 448 | * Helper function used to parse through the QStringList and put pointers in |
418 | * the correct place. | 449 | * the correct place. |
419 | * @param stanza The stanza (auto, iface, mapping) to look for. | 450 | * @param stanza The stanza (auto, iface, mapping) to look for. |
420 | * @param option string that must be in the stanza's main line. | 451 | * @param option string that must be in the stanza's main line. |
421 | * @param interator interator to place at location of stanza if successfull. | 452 | * @param interator interator to place at location of stanza if successfull. |
422 | * @return bool true if the stanza is found. | 453 | * @return bool true if the stanza is found. |
423 | */ | 454 | */ |
424 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | 455 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ |
425 | bool found = false; | 456 | bool found = false; |
426 | iterator = interfaces.end(); | 457 | iterator = interfaces.end(); |
427 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 458 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
428 | QString line = (*it).simplifyWhiteSpace(); | 459 | QString line = (*it).simplifyWhiteSpace(); |
429 | if(line.contains(stanza) && line.contains(option)){ | 460 | if(line.contains(stanza) && line.contains(option)){ |
430 | uint point = line.find(option); | 461 | uint point = line.find(option); |
431 | bool valid = true; | 462 | bool valid = true; |
432 | if(point > 0){ | 463 | if(point > 0){ |
433 | // There are more chars in the line. check +1 | 464 | // There are more chars in the line. check +1 |
434 | if(line.at(point-1) != ' ') | 465 | if(line.at(point-1) != ' ') |
435 | valid = false; | 466 | valid = false; |
436 | } | 467 | } |
437 | point += option.length(); | 468 | point += option.length(); |
438 | if(point < line.length()-1){ | 469 | if(point < line.length()-1){ |
439 | // There are more chars in the line. check -1 | 470 | // There are more chars in the line. check -1 |
440 | if(line.at(point) != ' ') | 471 | if(line.at(point) != ' ') |
441 | valid = false; | 472 | valid = false; |
442 | } | 473 | } |
443 | if(valid){ | 474 | if(valid){ |
444 | if(found == true){ | 475 | if(found == true){ |
445 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 476 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
446 | } | 477 | } |
447 | found = true; | 478 | found = true; |
448 | iterator = it; | 479 | iterator = it; |
449 | } | 480 | } |
450 | } | 481 | } |
451 | } | 482 | } |
452 | return found; | 483 | return found; |
453 | } | 484 | } |
454 | 485 | ||
455 | /** | 486 | /** |
456 | * Sets a value of an option in a stanza | 487 | * Sets a value of an option in a stanza |
457 | * @param start the start of the stanza | 488 | * @param start the start of the stanza |
458 | * @param option the option to use when setting value. | 489 | * @param option the option to use when setting value. |
459 | * @return bool true if successfull, false otherwise. | 490 | * @return bool true if successfull, false otherwise. |
460 | */ | 491 | */ |
461 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ |
462 | if(start == interfaces.end()) | 493 | if(start == interfaces.end()) |
463 | return false; | 494 | return false; |
464 | 495 | ||
465 | bool found = false; | 496 | bool found = false; |
466 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
467 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 498 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
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 | */ | ||
527 | bool 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 | */ |
499 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | 553 | bool 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; |
505 | for (it; it != interfaces.end(); ++it ) { | 559 | for (it; it != interfaces.end(); ++it ) { |
506 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 560 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
507 | break; | 561 | break; |
508 | } | 562 | } |
509 | it = interfaces.remove(it); | 563 | it = interfaces.remove(it); |
510 | it = --it; | 564 | it = --it; |
511 | } | 565 | } |
512 | // Leave a space between this interface and the next. | 566 | // Leave a space between this interface and the next. |
513 | interfaces.insert(it, QString("")); | 567 | interfaces.insert(it, QString("")); |
514 | return true; | 568 | return true; |
515 | } | 569 | } |
516 | 570 | ||
517 | /** | 571 | /** |
518 | * Gets a value of an option in a stanza | 572 | * Gets a value of an option in a stanza |
519 | * @param start the start of the stanza | 573 | * @param start the start of the stanza |
520 | * @param option the option to use when getting the value. | 574 | * @param option the option to use when getting the value. |
521 | * @param bool true if errors false otherwise. | 575 | * @param bool true if errors false otherwise. |
522 | * @return QString the value of option QString::null() if error == true. | 576 | * @return QString the value of option QString::null() if error == true. |
523 | */ | 577 | */ |
524 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | 578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ |
525 | if(start == interfaces.end()){ | 579 | if(start == interfaces.end()){ |
526 | error = false; | 580 | error = false; |
527 | return QString(); | 581 | return QString(); |
528 | } | 582 | } |
529 | 583 | ||
530 | QString value; | 584 | QString value; |
531 | bool found = false; | 585 | bool found = false; |
532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 587 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
534 | break; | 588 | break; |
535 | } | 589 | } |
536 | if((*it).contains(option)){ | 590 | if((*it).contains(option)){ |
537 | if(found) | 591 | if(found) |
538 | qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); | 592 | qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); |
539 | found = true; | 593 | found = true; |
540 | QString line = (*it).simplifyWhiteSpace(); | 594 | QString line = (*it).simplifyWhiteSpace(); |
diff --git a/noncore/settings/networksettings/interfaces.h b/noncore/settings/networksettings/interfaces.h index 7cf04f0..e09ea71 100644 --- a/noncore/settings/networksettings/interfaces.h +++ b/noncore/settings/networksettings/interfaces.h | |||
@@ -1,72 +1,76 @@ | |||
1 | #ifndef INTERFACES_H | 1 | #ifndef INTERFACES_H |
2 | #define INTERFACES_H | 2 | #define INTERFACES_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | #define INTERFACES_LOOPBACK "loopback" | 7 | #define INTERFACES_LOOPBACK "loopback" |
8 | 8 | ||
9 | #define INTERFACES_FAMILY_INET "inet" | 9 | #define INTERFACES_FAMILY_INET "inet" |
10 | #define INTERFACES_FAMILY_IPX "ipx" | 10 | #define INTERFACES_FAMILY_IPX "ipx" |
11 | #define INTERFACES_FAMILY_INET6 "inet6" | 11 | #define INTERFACES_FAMILY_INET6 "inet6" |
12 | 12 | ||
13 | #define INTERFACES_METHOD_DHCP "dhcp" | 13 | #define INTERFACES_METHOD_DHCP "dhcp" |
14 | #define INTERFACES_METHOD_STATIC "static" | 14 | #define INTERFACES_METHOD_STATIC "static" |
15 | #define INTERFACES_METHOD_PPP "ppp" | 15 | #define INTERFACES_METHOD_PPP "ppp" |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * This class provides a clean frontend for parsing the network interfaces file. | 18 | * This class provides a clean frontend for parsing the network interfaces file. |
19 | * It provides helper functions to minipulate the options within the file. | 19 | * It provides helper functions to minipulate the options within the file. |
20 | * See the interfaces man page for the syntax rules. | 20 | * See the interfaces man page for the syntax rules. |
21 | */ | 21 | */ |
22 | class Interfaces { | 22 | class Interfaces { |
23 | 23 | ||
24 | public: | 24 | public: |
25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); | 25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); |
26 | QStringList getInterfaceList(); | 26 | QStringList getInterfaceList(); |
27 | 27 | ||
28 | bool isAuto(QString interface); | 28 | bool isAuto(QString interface); |
29 | bool setAuto(QString interface, bool setAuto); | 29 | bool setAuto(QString interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | bool removeInterface(); |
32 | bool addInterface(QString interface, QString family, QString method); | 32 | bool addInterface(QString interface, QString family, QString method); |
33 | bool copyInterface(QString oldInterface, QString newInterface); | 33 | bool copyInterface(QString oldInterface, QString newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | bool isInterfaceSet(); | 35 | bool isInterfaceSet(); |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(QString newName); | 37 | bool setInterfaceName(QString newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(QString newName); | 39 | bool setInterfaceFamily(QString newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(QString newName); | 41 | bool setInterfaceMethod(QString newName); |
42 | QString getInterfaceOption(QString option, bool &error); | 42 | QString getInterfaceOption(QString option, bool &error); |
43 | bool setInterfaceOption(QString option, QString value); | 43 | bool setInterfaceOption(QString option, QString value); |
44 | bool removeInterfaceOption(QString option, QString value); | ||
44 | bool removeAllInterfaceOptions(); | 45 | bool removeAllInterfaceOptions(); |
45 | 46 | ||
46 | bool setMapping(QString interface); | 47 | bool setMapping(QString interface); |
48 | bool removeMapping(); | ||
47 | void addMapping(QString options); | 49 | void addMapping(QString options); |
48 | bool setMap(QString map, QString value); | 50 | bool setMap(QString map, QString value); |
51 | bool removeMap(QString map, QString value); | ||
49 | QString getMap(QString map, bool &error); | 52 | QString getMap(QString map, bool &error); |
50 | bool setScript(QString); | 53 | bool setScript(QString); |
51 | QString getScript(bool &error); | 54 | QString getScript(bool &error); |
52 | 55 | ||
53 | bool write(); | 56 | bool write(); |
54 | 57 | ||
55 | private: | 58 | private: |
56 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); | 59 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); |
57 | bool setOption(QStringList::Iterator start, QString option, QString value); | 60 | bool setOption(QStringList::Iterator start, QString option, QString value); |
61 | bool removeOption(QStringList::Iterator start, QString option, QString value); | ||
58 | QString getOption(QStringList::Iterator start, QString option, bool &error); | 62 | QString getOption(QStringList::Iterator start, QString option, bool &error); |
59 | bool removeAllOptions(QStringList::Iterator start); | 63 | bool removeAllOptions(QStringList::Iterator start); |
60 | 64 | ||
61 | QString interfacesFile; | 65 | QString interfacesFile; |
62 | QStringList interfaces; | 66 | QStringList interfaces; |
63 | QStringList::Iterator currentIface; | 67 | QStringList::Iterator currentIface; |
64 | QStringList::Iterator currentMapping; | 68 | QStringList::Iterator currentMapping; |
65 | 69 | ||
66 | QStringList acceptedFamily; | 70 | QStringList acceptedFamily; |
67 | }; | 71 | }; |
68 | 72 | ||
69 | #endif | 73 | #endif |
70 | 74 | ||
71 | // interfaces | 75 | // interfaces |
72 | 76 | ||
diff --git a/noncore/settings/networksettings/interfacesetupimp.cpp b/noncore/settings/networksettings/interfacesetupimp.cpp index bdbdfde..1327726 100644 --- a/noncore/settings/networksettings/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfacesetupimp.cpp | |||
@@ -47,97 +47,96 @@ void InterfaceSetupImp::accept(){ | |||
47 | */ | 47 | */ |
48 | bool InterfaceSetupImp::saveSettings(){ | 48 | bool InterfaceSetupImp::saveSettings(){ |
49 | // eh can't really do anything about it other then return. :-D | 49 | // eh can't really do anything about it other then return. :-D |
50 | if(!interfaces->isInterfaceSet()) | 50 | if(!interfaces->isInterfaceSet()) |
51 | return true; | 51 | return true; |
52 | 52 | ||
53 | bool error = false; | 53 | bool error = false; |
54 | // Loopback case | 54 | // Loopback case |
55 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 55 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
56 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 56 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
57 | return true; | 57 | return true; |
58 | } | 58 | } |
59 | 59 | ||
60 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ | 60 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ |
61 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); | 61 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); |
62 | return false; | 62 | return false; |
63 | } | 63 | } |
64 | interfaces->removeAllInterfaceOptions(); | 64 | interfaces->removeAllInterfaceOptions(); |
65 | 65 | ||
66 | // DHCP | 66 | // DHCP |
67 | if(dhcpCheckBox->isChecked()){ | 67 | if(dhcpCheckBox->isChecked()){ |
68 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 68 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); |
69 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 69 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
70 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 70 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
71 | } | 71 | } |
72 | else{ | 72 | else{ |
73 | interfaces->setInterfaceMethod("static"); | 73 | interfaces->setInterfaceMethod("static"); |
74 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 74 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); |
75 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 75 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); |
76 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 76 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); |
77 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 77 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
78 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); | 78 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); |
79 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); | 79 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); |
80 | } | 80 | } |
81 | 81 | ||
82 | // IP Information | 82 | // IP Information |
83 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 83 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
84 | return true; | 84 | return true; |
85 | } | 85 | } |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * The Profile has changed. | 88 | * The Profile has changed. |
89 | * @profile the new profile. | 89 | * @profile the new profile. |
90 | */ | 90 | */ |
91 | void InterfaceSetupImp::setProfile(const QString &profile){ | 91 | void InterfaceSetupImp::setProfile(const QString &profile){ |
92 | QString newInterfaceName = interface->getInterfaceName(); | 92 | QString newInterfaceName = interface->getInterfaceName(); |
93 | if(profile.length() > 0) | 93 | if(profile.length() > 0) |
94 | newInterfaceName += "_" + profile; | 94 | newInterfaceName += "_" + profile; |
95 | qDebug( newInterfaceName.latin1()); | ||
96 | // See if we have to make a interface. | 95 | // See if we have to make a interface. |
97 | if(!interfaces->setInterface(newInterfaceName)){ | 96 | if(!interfaces->setInterface(newInterfaceName)){ |
98 | // Add making for this new interface if need too | 97 | // Add making for this new interface if need too |
99 | if(profile != ""){ | 98 | if(profile != ""){ |
100 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 99 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); |
101 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 100 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
102 | interfaces->addMapping(interface->getInterfaceName()); | 101 | interfaces->addMapping(interface->getInterfaceName()); |
103 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 102 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
104 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 103 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); |
105 | return; | 104 | return; |
106 | } | 105 | } |
107 | } | 106 | } |
108 | interfaces->setMap("map", newInterfaceName); | 107 | interfaces->setMap("map", newInterfaceName); |
109 | interfaces->setScript("getprofile.sh"); | 108 | interfaces->setScript("getprofile.sh"); |
110 | } | 109 | } |
111 | else{ | 110 | else{ |
112 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 111 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
113 | if(!interfaces->setInterface(newInterfaceName)){ | 112 | if(!interfaces->setInterface(newInterfaceName)){ |
114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 113 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); |
115 | return; | 114 | return; |
116 | } | 115 | } |
117 | } | 116 | } |
118 | } | 117 | } |
119 | 118 | ||
120 | // We must have a valid interface to get this far so read some settings. | 119 | // We must have a valid interface to get this far so read some settings. |
121 | 120 | ||
122 | // DHCP | 121 | // DHCP |
123 | bool error = false; | 122 | bool error = false; |
124 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 123 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
125 | dhcpCheckBox->setChecked(true); | 124 | dhcpCheckBox->setChecked(true); |
126 | else | 125 | else |
127 | dhcpCheckBox->setChecked(false); | 126 | dhcpCheckBox->setChecked(false); |
128 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 127 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); |
129 | if(error) | 128 | if(error) |
130 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 129 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); |
131 | if(error) | 130 | if(error) |
132 | leaseTime->setValue(24); | 131 | leaseTime->setValue(24); |
133 | 132 | ||
134 | // IP Information | 133 | // IP Information |
135 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 134 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); |
136 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); | 135 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); |
137 | if(dns.contains(" ")){ | 136 | if(dns.contains(" ")){ |
138 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 137 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
139 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 138 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
140 | } | 139 | } |
141 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 140 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); |
142 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 141 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); |
143 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 142 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); |
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 9f07f0d..01063c2 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,171 +1,173 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addconnectionimp.h" | 2 | #include "addconnectionimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "interfaces.h" | 5 | #include "interfaces.h" |
6 | 6 | ||
7 | #include "module.h" | 7 | #include "module.h" |
8 | 8 | ||
9 | #include "kprocess.h" | 9 | #include "kprocess.h" |
10 | 10 | ||
11 | #include <qpushbutton.h> | 11 | #include <qpushbutton.h> |
12 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
13 | #include <qlistbox.h> | 13 | #include <qlistbox.h> |
14 | #include <qlineedit.h> | 14 | #include <qlineedit.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | #include <qheader.h> | 16 | #include <qheader.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | 18 | ||
19 | #include <qmainwindow.h> | 19 | #include <qmainwindow.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qlibrary.h> | 23 | #include <qpe/qlibrary.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | 26 | ||
27 | #include <qlist.h> | 27 | #include <qlist.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | 31 | ||
32 | #define TEMP_ALL "/tmp/ifconfig-a" | 32 | #define TEMP_ALL "/tmp/ifconfig-a" |
33 | #define TEMP_UP "/tmp/ifconfig" | 33 | #define TEMP_UP "/tmp/ifconfig" |
34 | 34 | ||
35 | #define SCHEME "/var/lib/pcmcia/scheme" | 35 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
36 | |||
36 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 37 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
37 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 38 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
38 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 39 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
39 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 40 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
40 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 41 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
41 | 42 | ||
42 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 43 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
43 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 44 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
44 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 45 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
45 | 46 | ||
46 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 47 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
47 | // Load connections. | 48 | // Load connections. |
48 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 49 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
49 | getInterfaceList(); | 50 | getInterfaceList(); |
50 | connectionList->header()->hide(); | 51 | connectionList->header()->hide(); |
51 | 52 | ||
52 | 53 | ||
53 | Config cfg("NetworkSetup"); | 54 | Config cfg("NetworkSetup"); |
54 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 55 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
55 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 56 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
56 | profilesList->insertItem((*it)); | 57 | profilesList->insertItem((*it)); |
57 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 58 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
58 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 59 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
60 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | ||
59 | 61 | ||
60 | QFile file(SCHEME); | 62 | QFile file(scheme); |
61 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 63 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
62 | QTextStream stream( &file ); // use a text stream | 64 | QTextStream stream( &file ); // use a text stream |
63 | while ( !stream.eof() ) { // until end of file... | 65 | while ( !stream.eof() ) { // until end of file... |
64 | QString line = stream.readLine(); // line of text excluding '\n' | 66 | QString line = stream.readLine(); // line of text excluding '\n' |
65 | if(line.contains("SCHEME")){ | 67 | if(line.contains("SCHEME")){ |
66 | line = line.mid(7, line.length()); | 68 | line = line.mid(7, line.length()); |
67 | currentProfileLabel->setText(line); | 69 | currentProfileLabel->setText(line); |
68 | break; | 70 | break; |
69 | } | 71 | } |
70 | } | 72 | } |
71 | file.close(); | 73 | file.close(); |
72 | } | 74 | } |
73 | } | 75 | } |
74 | 76 | ||
75 | /** | 77 | /** |
76 | * Deconstructor. Save profiles. Delete loaded libraries. | 78 | * Deconstructor. Save profiles. Delete loaded libraries. |
77 | */ | 79 | */ |
78 | MainWindowImp::~MainWindowImp(){ | 80 | MainWindowImp::~MainWindowImp(){ |
79 | // Save profiles. | 81 | // Save profiles. |
80 | Config cfg("NetworkSetup"); | 82 | Config cfg("NetworkSetup"); |
81 | cfg.setGroup("General"); | 83 | cfg.setGroup("General"); |
82 | cfg.writeEntry("Profiles", profiles.join(" ")); | 84 | cfg.writeEntry("Profiles", profiles.join(" ")); |
83 | 85 | ||
84 | // Delete Modules and Libraries | 86 | // Delete Modules and Libraries |
85 | QMap<Module*, QLibrary*>::Iterator it; | 87 | QMap<Module*, QLibrary*>::Iterator it; |
86 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
87 | delete it.key(); | 89 | delete it.key(); |
88 | delete it.data(); | 90 | delete it.data(); |
89 | } | 91 | } |
90 | } | 92 | } |
91 | 93 | ||
92 | /** | 94 | /** |
93 | * Load all modules that are found in the path | 95 | * Load all modules that are found in the path |
94 | * @param path a directory that is scaned for any plugins that can be loaded | 96 | * @param path a directory that is scaned for any plugins that can be loaded |
95 | * and attempts to load them | 97 | * and attempts to load them |
96 | */ | 98 | */ |
97 | void MainWindowImp::loadModules(QString path){ | 99 | void MainWindowImp::loadModules(QString path){ |
98 | qDebug(path.latin1()); | 100 | //qDebug(path.latin1()); |
99 | QDir d(path); | 101 | QDir d(path); |
100 | if(!d.exists()) | 102 | if(!d.exists()) |
101 | return; | 103 | return; |
102 | 104 | ||
103 | // Don't want sym links | 105 | // Don't want sym links |
104 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
105 | const QFileInfoList *list = d.entryInfoList(); | 107 | const QFileInfoList *list = d.entryInfoList(); |
106 | QFileInfoListIterator it( *list ); | 108 | QFileInfoListIterator it( *list ); |
107 | QFileInfo *fi; | 109 | QFileInfo *fi; |
108 | while ( (fi=it.current()) ) { | 110 | while ( (fi=it.current()) ) { |
109 | if(fi->fileName().contains(".so")){ | 111 | if(fi->fileName().contains(".so")){ |
110 | loadPlugin(path + "/" + fi->fileName()); | 112 | loadPlugin(path + "/" + fi->fileName()); |
111 | } | 113 | } |
112 | ++it; | 114 | ++it; |
113 | } | 115 | } |
114 | } | 116 | } |
115 | 117 | ||
116 | /** | 118 | /** |
117 | * Attempt to load a function and resolve a function. | 119 | * Attempt to load a function and resolve a function. |
118 | * @param pluginFileName - the name of the file in which to attempt to load | 120 | * @param pluginFileName - the name of the file in which to attempt to load |
119 | * @param resolveString - function pointer to resolve | 121 | * @param resolveString - function pointer to resolve |
120 | * @return pointer to the function with name resolveString or NULL | 122 | * @return pointer to the function with name resolveString or NULL |
121 | */ | 123 | */ |
122 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
123 | qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
124 | QLibrary *lib = new QLibrary(pluginFileName); | 126 | QLibrary *lib = new QLibrary(pluginFileName); |
125 | void *functionPointer = lib->resolve(resolveString); | 127 | void *functionPointer = lib->resolve(resolveString); |
126 | if( !functionPointer ){ | 128 | if( !functionPointer ){ |
127 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
128 | delete lib; | 130 | delete lib; |
129 | return NULL; | 131 | return NULL; |
130 | } | 132 | } |
131 | 133 | ||
132 | // Try to get an object. | 134 | // Try to get an object. |
133 | Module *object = ((Module* (*)()) functionPointer)(); | 135 | Module *object = ((Module* (*)()) functionPointer)(); |
134 | if(object == NULL){ | 136 | if(object == NULL){ |
135 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
136 | delete lib; | 138 | delete lib; |
137 | return NULL; | 139 | return NULL; |
138 | } | 140 | } |
139 | 141 | ||
140 | // Store for deletion later | 142 | // Store for deletion later |
141 | libraries.insert(object, lib); | 143 | libraries.insert(object, lib); |
142 | return object; | 144 | return object; |
143 | } | 145 | } |
144 | 146 | ||
145 | /** | 147 | /** |
146 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 148 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
147 | * load the plugin and append it to the list | 149 | * load the plugin and append it to the list |
148 | */ | 150 | */ |
149 | void MainWindowImp::addClicked(){ | 151 | void MainWindowImp::addClicked(){ |
150 | QMap<Module*, QLibrary*>::Iterator it; | 152 | QMap<Module*, QLibrary*>::Iterator it; |
151 | QMap<QString, QString> list; | 153 | QMap<QString, QString> list; |
152 | QMap<QString, Module*> newInterfaceOwners; | 154 | QMap<QString, Module*> newInterfaceOwners; |
153 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 155 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
154 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | 156 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
155 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
156 | if(it.key()){ | 158 | if(it.key()){ |
157 | (it.key())->possibleNewInterfaces(list); | 159 | (it.key())->possibleNewInterfaces(list); |
158 | } | 160 | } |
159 | } | 161 | } |
160 | // See if the list has anything that we can add. | 162 | // See if the list has anything that we can add. |
161 | if(list.count() == 0){ | 163 | if(list.count() == 0){ |
162 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | 164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); |
163 | return; | 165 | return; |
164 | } | 166 | } |
165 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
166 | addNewConnection.addConnections(list); | 168 | addNewConnection.addConnections(list); |
167 | addNewConnection.showMaximized(); | 169 | addNewConnection.showMaximized(); |
168 | if(QDialog::Accepted == addNewConnection.exec()){ | 170 | if(QDialog::Accepted == addNewConnection.exec()){ |
169 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
170 | if(!item) | 172 | if(!item) |
171 | return; | 173 | return; |
@@ -445,87 +447,105 @@ void MainWindowImp::updateInterface(Interface *i){ | |||
445 | void MainWindowImp::newProfileChanged(const QString& newText){ | 447 | void MainWindowImp::newProfileChanged(const QString& newText){ |
446 | if(newText.length() > 0) | 448 | if(newText.length() > 0) |
447 | newProfileButton->setEnabled(true); | 449 | newProfileButton->setEnabled(true); |
448 | else | 450 | else |
449 | newProfileButton->setEnabled(false); | 451 | newProfileButton->setEnabled(false); |
450 | } | 452 | } |
451 | 453 | ||
452 | /** | 454 | /** |
453 | * Adds a new profile to the list of profiles. | 455 | * Adds a new profile to the list of profiles. |
454 | * Don't add profiles that already exists. | 456 | * Don't add profiles that already exists. |
455 | * Appends to the list and QStringList | 457 | * Appends to the list and QStringList |
456 | */ | 458 | */ |
457 | void MainWindowImp::addProfile(){ | 459 | void MainWindowImp::addProfile(){ |
458 | QString newProfileName = newProfile->text(); | 460 | QString newProfileName = newProfile->text(); |
459 | if(profiles.grep(newProfileName).count() > 0){ | 461 | if(profiles.grep(newProfileName).count() > 0){ |
460 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
461 | return; | 463 | return; |
462 | } | 464 | } |
463 | profiles.append(newProfileName); | 465 | profiles.append(newProfileName); |
464 | profilesList->insertItem(newProfileName); | 466 | profilesList->insertItem(newProfileName); |
465 | } | 467 | } |
466 | 468 | ||
467 | /** | 469 | /** |
468 | * Removes the currently selected profile in the combo. | 470 | * Removes the currently selected profile in the combo. |
469 | * Doesn't delete if there are less then 2 profiles. | 471 | * Doesn't delete if there are less then 2 profiles. |
470 | */ | 472 | */ |
471 | void MainWindowImp::removeProfile(){ | 473 | void MainWindowImp::removeProfile(){ |
472 | if(profilesList->count() <= 1){ | 474 | if(profilesList->count() <= 1){ |
473 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); | 475 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); |
474 | return; | 476 | return; |
475 | } | 477 | } |
476 | QString profileToRemove = profilesList->currentText(); | 478 | QString profileToRemove = profilesList->currentText(); |
477 | if(profileToRemove == "All"){ | 479 | if(profileToRemove == "All"){ |
478 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); | 480 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); |
479 | return; | 481 | return; |
480 | } | 482 | } |
481 | // Can't remove the curent profile | 483 | // Can't remove the curent profile |
482 | if(profileToRemove == currentProfileLabel->text()){ | 484 | if(profileToRemove == currentProfileLabel->text()){ |
483 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); | 485 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); |
484 | return; | 486 | return; |
485 | 487 | ||
486 | } | 488 | } |
487 | 489 | ||
488 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 490 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
489 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 491 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
490 | profilesList->clear(); | 492 | profilesList->clear(); |
491 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 493 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
492 | profilesList->insertItem((*it)); | 494 | profilesList->insertItem((*it)); |
493 | } | ||
494 | 495 | ||
495 | // Remove any interface settings and mappings. | 496 | // Remove any interface settings and mappings. |
496 | //TODO | 497 | Interfaces interfaces; |
498 | // Go through them one by one | ||
499 | QMap<Interface*, QListViewItem*>::Iterator it; | ||
500 | for( it = items.begin(); it != items.end(); ++it ){ | ||
501 | QString interfaceName = it.key()->getInterfaceName(); | ||
502 | qDebug(interfaceName.latin1()); | ||
503 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ | ||
504 | interfaces.removeInterface(); | ||
505 | if(interfaces.setMapping(interfaceName)){ | ||
506 | if(profilesList->count() == 1) | ||
507 | interfaces.removeMapping(); | ||
508 | else{ | ||
509 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); | ||
510 | } | ||
511 | } | ||
512 | interfaces.write(); | ||
513 | break; | ||
514 | } | ||
515 | } | ||
516 | } | ||
497 | } | 517 | } |
498 | 518 | ||
499 | /** | 519 | /** |
500 | * A new profile has been selected, change. | 520 | * A new profile has been selected, change. |
501 | * @param newProfile the new profile. | 521 | * @param newProfile the new profile. |
502 | */ | 522 | */ |
503 | void MainWindowImp::changeProfile(){ | 523 | void MainWindowImp::changeProfile(){ |
504 | if(profilesList->currentItem() == -1){ | 524 | if(profilesList->currentItem() == -1){ |
505 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); | 525 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); |
506 | return; | 526 | return; |
507 | } | 527 | } |
508 | QString newProfile = profilesList->text(profilesList->currentItem()); | 528 | QString newProfile = profilesList->text(profilesList->currentItem()); |
509 | if(newProfile != currentProfileLabel->text()){ | 529 | if(newProfile != currentProfileLabel->text()){ |
510 | currentProfileLabel->setText(newProfile); | 530 | currentProfileLabel->setText(newProfile); |
511 | QFile::remove(SCHEME); | 531 | QFile::remove(scheme); |
512 | QFile file(SCHEME); | 532 | QFile file(scheme); |
513 | if ( file.open(IO_ReadWrite) ) { | 533 | if ( file.open(IO_ReadWrite) ) { |
514 | QTextStream stream( &file ); | 534 | QTextStream stream( &file ); |
515 | stream << QString("SCHEME=%1").arg(newProfile); | 535 | stream << QString("SCHEME=%1").arg(newProfile); |
516 | file.close(); | 536 | file.close(); |
517 | } | 537 | } |
518 | // restart all up devices? | 538 | // restart all up devices? |
519 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ | 539 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ |
520 | // Go through them one by one | 540 | // Go through them one by one |
521 | QMap<Interface*, QListViewItem*>::Iterator it; | 541 | QMap<Interface*, QListViewItem*>::Iterator it; |
522 | for( it = items.begin(); it != items.end(); ++it ){ | 542 | for( it = items.begin(); it != items.end(); ++it ){ |
523 | if(it.key()->getStatus() == true) | 543 | if(it.key()->getStatus() == true) |
524 | it.key()->restart(); | 544 | it.key()->restart(); |
525 | } | 545 | } |
526 | } | 546 | } |
527 | } | 547 | } |
528 | } | 548 | } |
529 | 549 | ||
530 | // mainwindowimp.cpp | 550 | // mainwindowimp.cpp |
531 | 551 | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.h b/noncore/settings/networksettings/mainwindowimp.h index c67c161..e5284b4 100644 --- a/noncore/settings/networksettings/mainwindowimp.h +++ b/noncore/settings/networksettings/mainwindowimp.h | |||
@@ -5,54 +5,55 @@ | |||
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | class Module; | 8 | class Module; |
9 | class Interface; | 9 | class Interface; |
10 | class QLibrary; | 10 | class QLibrary; |
11 | class KProcess; | 11 | class KProcess; |
12 | 12 | ||
13 | class MainWindowImp : public MainWindow { | 13 | class MainWindowImp : public MainWindow { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | MainWindowImp(QWidget *parent=0, const char *name=0); | 17 | MainWindowImp(QWidget *parent=0, const char *name=0); |
18 | ~MainWindowImp(); | 18 | ~MainWindowImp(); |
19 | 19 | ||
20 | private slots: | 20 | private slots: |
21 | void addClicked(); | 21 | void addClicked(); |
22 | void removeClicked(); | 22 | void removeClicked(); |
23 | void configureClicked(); | 23 | void configureClicked(); |
24 | void informationClicked(); | 24 | void informationClicked(); |
25 | 25 | ||
26 | void jobDone(KProcess *process); | 26 | void jobDone(KProcess *process); |
27 | void getInterfaceList(); | 27 | void getInterfaceList(); |
28 | 28 | ||
29 | void addProfile(); | 29 | void addProfile(); |
30 | void removeProfile(); | 30 | void removeProfile(); |
31 | void changeProfile(); | 31 | void changeProfile(); |
32 | 32 | ||
33 | void updateInterface(Interface *i); | 33 | void updateInterface(Interface *i); |
34 | void newProfileChanged(const QString& newText); | 34 | void newProfileChanged(const QString& newText); |
35 | 35 | ||
36 | private: | 36 | private: |
37 | void loadModules(QString path); | 37 | void loadModules(QString path); |
38 | 38 | ||
39 | Module* loadPlugin(QString pluginFileName, | 39 | Module* loadPlugin(QString pluginFileName, |
40 | QString resolveString = "create_plugin"); | 40 | QString resolveString = "create_plugin"); |
41 | 41 | ||
42 | // For our local list of names | 42 | // For our local list of names |
43 | QMap<QString, Interface*> interfaceNames; | 43 | QMap<QString, Interface*> interfaceNames; |
44 | 44 | ||
45 | QMap<Module*, QLibrary*> libraries; | 45 | QMap<Module*, QLibrary*> libraries; |
46 | QMap<Interface*, QListViewItem*> items; | 46 | QMap<Interface*, QListViewItem*> items; |
47 | QMap<QListViewItem*, Interface*> interfaceItems; | 47 | QMap<QListViewItem*, Interface*> interfaceItems; |
48 | 48 | ||
49 | QMap<KProcess*, QString> threads; | 49 | QMap<KProcess*, QString> threads; |
50 | QStringList profiles; | 50 | QStringList profiles; |
51 | 51 | ||
52 | bool advancedUserMode; | 52 | bool advancedUserMode; |
53 | QString scheme; | ||
53 | }; | 54 | }; |
54 | 55 | ||
55 | #endif | 56 | #endif |
56 | 57 | ||
57 | // mainwindowimp.h | 58 | // mainwindowimp.h |
58 | 59 | ||