author | kergoth <kergoth> | 2003-04-14 23:27:22 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-04-14 23:27:22 (UTC) |
commit | 68c558ca78e5416145b64ca87fd01361f033ef34 (patch) (unidiff) | |
tree | 53287d7a641fc37d4f52e0e13dfb576149e41f8e | |
parent | 9c0ba9922e12081ba87cce6583fe413ab5794cf6 (diff) | |
download | opie-68c558ca78e5416145b64ca87fd01361f033ef34.zip opie-68c558ca78e5416145b64ca87fd01361f033ef34.tar.gz opie-68c558ca78e5416145b64ca87fd01361f033ef34.tar.bz2 |
Add remove methods which do not require that you pass the current value of the option, to avoid having to retain that information unnecessarily
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.cpp | 37 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.h | 2 |
2 files changed, 39 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 8f685fe..8d3e151 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp | |||
@@ -312,64 +312,74 @@ bool Interfaces::setInterfaceMethod(const QString &newName){ | |||
312 | return !returnValue; | 312 | return !returnValue; |
313 | } | 313 | } |
314 | 314 | ||
315 | /** | 315 | /** |
316 | * Get a value for an option in the currently selected interface. For example | 316 | * Get a value for an option in the currently selected interface. For example |
317 | * calling getInterfaceOption("address") on the following stanza would | 317 | * calling getInterfaceOption("address") on the following stanza would |
318 | * return 192.168.1.1. | 318 | * return 192.168.1.1. |
319 | * iface eth0 static | 319 | * iface eth0 static |
320 | * address 192.168.1.1 | 320 | * address 192.168.1.1 |
321 | * @param option the options to get the value. | 321 | * @param option the options to get the value. |
322 | * @param error set to true if any error occurs, false otherwise. | 322 | * @param error set to true if any error occurs, false otherwise. |
323 | * @return QString the options value. QString::null if error == true | 323 | * @return QString the options value. QString::null if error == true |
324 | */ | 324 | */ |
325 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ | 325 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ |
326 | return getOption(currentIface, option, error); | 326 | return getOption(currentIface, option, error); |
327 | } | 327 | } |
328 | 328 | ||
329 | /** | 329 | /** |
330 | * Set a value for an option in the currently selected interface. If option | 330 | * Set a value for an option in the currently selected interface. If option |
331 | * doesn't exist then it is added along with the value. | 331 | * doesn't exist then it is added along with the value. |
332 | * @param option the options to set the value. | 332 | * @param option the options to set the value. |
333 | * @param value the value that option should be set to. | 333 | * @param value the value that option should be set to. |
334 | * @param error set to true if any error occurs, false otherwise. | 334 | * @param error set to true if any error occurs, false otherwise. |
335 | * @return QString the options value. QString::null if error == true | 335 | * @return QString the options value. QString::null if error == true |
336 | */ | 336 | */ |
337 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ | 337 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ |
338 | return setOption(currentIface, option, value); | 338 | return setOption(currentIface, option, value); |
339 | } | 339 | } |
340 | 340 | ||
341 | /** | 341 | /** |
342 | * Removes a value for an option in the currently selected interface. | 342 | * Removes a value for an option in the currently selected interface. |
343 | * @param option the options to set the value. | 343 | * @param option the options to set the value. |
344 | * @param error set to true if any error occurs, false otherwise. | ||
345 | * @return QString the options value. QString::null if error == true | ||
346 | */ | ||
347 | bool Interfaces::removeInterfaceOption(const QString &option){ | ||
348 | return removeOption(currentIface, option); | ||
349 | } | ||
350 | |||
351 | /** | ||
352 | * Removes a value for an option in the currently selected interface. | ||
353 | * @param option the options to set the value. | ||
344 | * @param value the value that option should be set to. | 354 | * @param value the value that option should be set to. |
345 | * @param error set to true if any error occurs, false otherwise. | 355 | * @param error set to true if any error occurs, false otherwise. |
346 | * @return QString the options value. QString::null if error == true | 356 | * @return QString the options value. QString::null if error == true |
347 | */ | 357 | */ |
348 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ | 358 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ |
349 | return removeOption(currentIface, option, value); | 359 | return removeOption(currentIface, option, value); |
350 | } | 360 | } |
351 | 361 | ||
352 | /** | 362 | /** |
353 | * Removes all of the options from the currently selected interface. | 363 | * Removes all of the options from the currently selected interface. |
354 | * @return bool error if if successfull | 364 | * @return bool error if if successfull |
355 | */ | 365 | */ |
356 | bool Interfaces::removeAllInterfaceOptions(){ | 366 | bool Interfaces::removeAllInterfaceOptions(){ |
357 | return removeAllOptions(currentIface); | 367 | return removeAllOptions(currentIface); |
358 | } | 368 | } |
359 | 369 | ||
360 | /** | 370 | /** |
361 | * Set the current map to interface's map. This needs to be done before you | 371 | * Set the current map to interface's map. This needs to be done before you |
362 | * can call addMapping(), set/getMap(), and get/setScript(). | 372 | * can call addMapping(), set/getMap(), and get/setScript(). |
363 | * @param interface the name of the interface to set. All whitespace is | 373 | * @param interface the name of the interface to set. All whitespace is |
364 | * removed from the interface name. | 374 | * removed from the interface name. |
365 | * @return bool true if it is successfull. | 375 | * @return bool true if it is successfull. |
366 | */ | 376 | */ |
367 | bool Interfaces::setMapping(const QString &interface){ | 377 | bool Interfaces::setMapping(const QString &interface){ |
368 | QString interfaceName = interface.simplifyWhiteSpace(); | 378 | QString interfaceName = interface.simplifyWhiteSpace(); |
369 | interfaceName = interfaceName.replace(QRegExp(" "), ""); | 379 | interfaceName = interfaceName.replace(QRegExp(" "), ""); |
370 | return setStanza(MAPPING, interfaceName, currentMapping); | 380 | return setStanza(MAPPING, interfaceName, currentMapping); |
371 | } | 381 | } |
372 | 382 | ||
373 | /** | 383 | /** |
374 | * Adds a new Mapping to the interfaces file with interfaces. | 384 | * Adds a new Mapping to the interfaces file with interfaces. |
375 | * @param interface the name(s) of the interfaces to set to this mapping | 385 | * @param interface the name(s) of the interfaces to set to this mapping |
@@ -497,64 +507,91 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op | |||
497 | } | 507 | } |
498 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 508 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
499 | // Found it in stanza so replace it. | 509 | // Found it in stanza so replace it. |
500 | if(found) | 510 | if(found) |
501 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 511 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
502 | found = true; | 512 | found = true; |
503 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 513 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
504 | } | 514 | } |
505 | } | 515 | } |
506 | if(!found){ | 516 | if(!found){ |
507 | QStringList::Iterator p = start; | 517 | QStringList::Iterator p = start; |
508 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 518 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
509 | found = true; | 519 | found = true; |
510 | } | 520 | } |
511 | return found; | 521 | return found; |
512 | } | 522 | } |
513 | 523 | ||
514 | /** | 524 | /** |
515 | * Removes a stanza and all of its options | 525 | * Removes a stanza and all of its options |
516 | * @param stanza the stanza to remove | 526 | * @param stanza the stanza to remove |
517 | * @return bool true if successfull. | 527 | * @return bool true if successfull. |
518 | */ | 528 | */ |
519 | bool Interfaces::removeStanza(QStringList::Iterator &stanza){ | 529 | bool Interfaces::removeStanza(QStringList::Iterator &stanza){ |
520 | if(stanza == interfaces.end()) | 530 | if(stanza == interfaces.end()) |
521 | return false; | 531 | return false; |
522 | (*stanza) = ""; | 532 | (*stanza) = ""; |
523 | return removeAllOptions(stanza); | 533 | return removeAllOptions(stanza); |
524 | } | 534 | } |
525 | 535 | ||
526 | /** | 536 | /** |
527 | * Removes a option in a stanza | 537 | * Removes a option in a stanza |
528 | * @param start the start of the stanza | 538 | * @param start the start of the stanza |
539 | * @param option the option to remove | ||
540 | * @return bool true if successfull, false otherwise. | ||
541 | */ | ||
542 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){ | ||
543 | if(start == interfaces.end()) | ||
544 | return false; | ||
545 | |||
546 | bool found = false; | ||
547 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | ||
548 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
549 | // got to the end without finding it | ||
550 | break; | ||
551 | } | ||
552 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | ||
553 | // Found it in stanza so replace it. | ||
554 | if(found) | ||
555 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | ||
556 | found = true; | ||
557 | (*it) = ""; | ||
558 | } | ||
559 | } | ||
560 | return found; | ||
561 | } | ||
562 | |||
563 | /** | ||
564 | * Removes a option in a stanza | ||
565 | * @param start the start of the stanza | ||
529 | * @param option the option to use when setting value. | 566 | * @param option the option to use when setting value. |
530 | * @return bool true if successfull, false otherwise. | 567 | * @return bool true if successfull, false otherwise. |
531 | */ | 568 | */ |
532 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 569 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
533 | if(start == interfaces.end()) | 570 | if(start == interfaces.end()) |
534 | return false; | 571 | return false; |
535 | 572 | ||
536 | bool found = false; | 573 | bool found = false; |
537 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 574 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
538 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 575 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
539 | // got to the end without finding it | 576 | // got to the end without finding it |
540 | break; | 577 | break; |
541 | } | 578 | } |
542 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 579 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
543 | // Found it in stanza so replace it. | 580 | // Found it in stanza so replace it. |
544 | if(found) | 581 | if(found) |
545 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 582 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
546 | found = true; | 583 | found = true; |
547 | (*it) = ""; | 584 | (*it) = ""; |
548 | } | 585 | } |
549 | } | 586 | } |
550 | return found; | 587 | return found; |
551 | } | 588 | } |
552 | 589 | ||
553 | /** | 590 | /** |
554 | * Removes all options in a stanza | 591 | * Removes all options in a stanza |
555 | * @param start the start of the stanza | 592 | * @param start the start of the stanza |
556 | * @return bool true if successfull, false otherwise. | 593 | * @return bool true if successfull, false otherwise. |
557 | */ | 594 | */ |
558 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ | 595 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ |
559 | if(start == interfaces.end()) | 596 | if(start == interfaces.end()) |
560 | return false; | 597 | return false; |
diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h index bac2a7e..bc9eaaa 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.h +++ b/noncore/settings/networksettings/interfaces/interfaces.h | |||
@@ -12,66 +12,68 @@ | |||
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(const QString &interface) const ; | 28 | bool isAuto(const QString &interface) const ; |
29 | bool setAuto(const QString &interface, bool setAuto); | 29 | bool setAuto(const QString &interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | bool removeInterface(); |
32 | bool addInterface(const QString &interface, const QString &family, const QString &method); | 32 | bool addInterface(const QString &interface, const QString &family, const QString &method); |
33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); | 33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | bool isInterfaceSet() const ; | 35 | bool isInterfaceSet() const ; |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(const QString &newName); | 37 | bool setInterfaceName(const QString &newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(const QString &newName); | 39 | bool setInterfaceFamily(const QString &newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(const QString &newName); | 41 | bool setInterfaceMethod(const QString &newName); |
42 | QString getInterfaceOption(const QString &option, bool &error); | 42 | QString getInterfaceOption(const QString &option, bool &error); |
43 | bool setInterfaceOption(const QString &option, const QString &value); | 43 | bool setInterfaceOption(const QString &option, const QString &value); |
44 | bool removeInterfaceOption(const QString &option); | ||
44 | bool removeInterfaceOption(const QString &option, const QString &value); | 45 | bool removeInterfaceOption(const QString &option, const QString &value); |
45 | bool removeAllInterfaceOptions(); | 46 | bool removeAllInterfaceOptions(); |
46 | 47 | ||
47 | bool setMapping(const QString &interface); | 48 | bool setMapping(const QString &interface); |
48 | bool removeMapping(); | 49 | bool removeMapping(); |
49 | void addMapping(const QString &options); | 50 | void addMapping(const QString &options); |
50 | bool setMap(const QString &map, const QString &value); | 51 | bool setMap(const QString &map, const QString &value); |
51 | bool removeMap(const QString &map, const QString &value); | 52 | bool removeMap(const QString &map, const QString &value); |
52 | QString getMap(const QString &map, bool &error); | 53 | QString getMap(const QString &map, bool &error); |
53 | bool setScript(const QString &argument); | 54 | bool setScript(const QString &argument); |
54 | QString getScript(bool &error); | 55 | QString getScript(bool &error); |
55 | 56 | ||
56 | bool write(); | 57 | bool write(); |
57 | 58 | ||
58 | private: | 59 | private: |
59 | bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); | 60 | bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); |
60 | bool removeStanza(QStringList::Iterator &stanza); | 61 | bool removeStanza(QStringList::Iterator &stanza); |
61 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); | 62 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
62 | bool removeAllOptions(const QStringList::Iterator &start); | 63 | bool removeAllOptions(const QStringList::Iterator &start); |
64 | bool removeOption(const QStringList::Iterator &start, const QString &option); | ||
63 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); | 65 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
64 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); | 66 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); |
65 | 67 | ||
66 | QString interfacesFile; | 68 | QString interfacesFile; |
67 | QStringList interfaces; | 69 | QStringList interfaces; |
68 | QStringList::Iterator currentIface; | 70 | QStringList::Iterator currentIface; |
69 | QStringList::Iterator currentMapping; | 71 | QStringList::Iterator currentMapping; |
70 | 72 | ||
71 | QStringList acceptedFamily; | 73 | QStringList acceptedFamily; |
72 | }; | 74 | }; |
73 | 75 | ||
74 | #endif | 76 | #endif |
75 | 77 | ||
76 | // interfaces | 78 | // interfaces |
77 | 79 | ||