-rw-r--r-- | noncore/net/networksetup/interfaces/interfaces.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.cpp | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp index 377a6db..f1b8067 100644 --- a/noncore/net/networksetup/interfaces/interfaces.cpp +++ b/noncore/net/networksetup/interfaces/interfaces.cpp | |||
@@ -90,193 +90,193 @@ bool Interfaces::setAuto(QString interface, bool setAuto){ | |||
90 | // Don't need to set it if it is already set. | 90 | // Don't need to set it if it is already set. |
91 | if(isAuto(interface) == setAuto) | 91 | if(isAuto(interface) == setAuto) |
92 | return false; | 92 | return false; |
93 | 93 | ||
94 | bool changed = false; | 94 | bool changed = false; |
95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
96 | if((*it).contains(AUTO)){ | 96 | if((*it).contains(AUTO)){ |
97 | //We know that they are not in any group so let add to this auto. | 97 | //We know that they are not in any group so let add to this auto. |
98 | if(setAuto){ | 98 | if(setAuto){ |
99 | (*it) = (*it) += " " + interface; | 99 | (*it) = (*it) += " " + interface; |
100 | // Don't care to have such thins as: auto eth0 lo usb0 | 100 | // Don't care to have such thins as: auto eth0 lo usb0 |
101 | (*it) = (*it).simplifyWhiteSpace(); | 101 | (*it) = (*it).simplifyWhiteSpace(); |
102 | changed = true; | 102 | changed = true; |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | else{ | 105 | else{ |
106 | if((*it).contains(interface)){ | 106 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 107 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // clean up | 108 | // clean up |
109 | QString line = (*it).simplifyWhiteSpace(); | 109 | QString line = (*it).simplifyWhiteSpace(); |
110 | line = line.replace(QRegExp(" "),""); | 110 | line = line.replace(QRegExp(" "),""); |
111 | if(line == AUTO) | 111 | if(line == AUTO) |
112 | (*it) = ""; | 112 | (*it) = ""; |
113 | changed = true; | 113 | changed = true; |
114 | // Don't break because we want to make sure we remove all cases. | 114 | // Don't break because we want to make sure we remove all cases. |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | if(changed == false){ | 119 | if(changed == false){ |
120 | if(setAuto == true) | 120 | if(setAuto == true) |
121 | interfaces.append(QString(AUTO" %1").arg(interface)); | 121 | interfaces.append(QString(AUTO" %1").arg(interface)); |
122 | else{ | 122 | else{ |
123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | 123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | return true; | 126 | return true; |
127 | } | 127 | } |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Set the current interface to interface. This needs to be done before you | 130 | * Set the current interface to interface. This needs to be done before you |
131 | * can call getFamily(), getMethod, and get/setOption(). | 131 | * can call getFamily(), getMethod, and get/setOption(). |
132 | * @param interface the name of the interface to set. All whitespace is | 132 | * @param interface the name of the interface to set. All whitespace is |
133 | * removed from the interface name. | 133 | * removed from the interface name. |
134 | * @return bool true if it is successfull. | 134 | * @return bool true if it is successfull. |
135 | */ | 135 | */ |
136 | bool Interfaces::setInterface(QString interface){ | 136 | bool Interfaces::setInterface(QString interface){ |
137 | interface = interface.simplifyWhiteSpace(); | 137 | interface = interface.simplifyWhiteSpace(); |
138 | interface = interface.replace(QRegExp(" "), ""); | 138 | interface = interface.replace(QRegExp(" "), ""); |
139 | return setStanza(IFACE, interface, currentIface); | 139 | return setStanza(IFACE, interface, currentIface); |
140 | } | 140 | } |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * A quick helper funtion to see if the current interface is set. | 143 | * A quick helper funtion to see if the current interface is set. |
144 | * @return bool true if set, false otherwise. | 144 | * @return bool true if set, false otherwise. |
145 | */ | 145 | */ |
146 | bool Interfaces::isInterfaceSet(){ | 146 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 147 | return (currentIface != interfaces.end()); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Add a new interface of with the settings - family and method | 151 | * Add a new interface of with the settings - family and method |
152 | * @param interface the name of the interface to set. All whitespace is | 152 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 153 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 154 | * @param family the family of this interface inet or inet, ipx or inet6 |
155 | * Must of one of the families defined in interfaces.h | 155 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 156 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 157 | * @return true if successfull. |
158 | */ | 158 | */ |
159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | 159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ |
160 | if(acceptedFamily.contains(family)==0) | 160 | if(acceptedFamily.contains(family)==0) |
161 | return false; | 161 | return false; |
162 | interface = interface.simplifyWhiteSpace(); | 162 | interface = interface.simplifyWhiteSpace(); |
163 | interface = interface.replace(QRegExp(" "), ""); | 163 | interface = interface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 164 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | 165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Copies interface with name interface to name newInterface | 170 | * Copies interface with name interface to name newInterface |
171 | * @param newInterface name of the new interface. | 171 | * @param newInterface name of the new interface. |
172 | * @return bool true if successfull | 172 | * @return bool true if successfull |
173 | */ | 173 | */ |
174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ | 174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ |
175 | if(!setInterface(interface)) return false; | 175 | if(!setInterface(interface)) return false; |
176 | 176 | ||
177 | QStringList::Iterator it = currentIface; | 177 | QStringList::Iterator it = currentIface; |
178 | it++; | 178 | it++; |
179 | 179 | ||
180 | bool error; | 180 | bool error; |
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
182 | if(!setInterface(newInterface)) return false; | 182 | if(!setInterface(newInterface)) return false; |
183 | QStringList::Iterator newIface = currentIface; | 183 | QStringList::Iterator newIface = currentIface; |
184 | newIface++; | 184 | newIface++; |
185 | 185 | ||
186 | for ( it; it != interfaces.end(); ++it ){ | 186 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 188 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 189 | newIface = interfaces.insert(newIface, *it); |
190 | } | 190 | } |
191 | 191 | ||
192 | return true; | 192 | return true; |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Remove the currently selected interface and all of its options. | 196 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 197 | * @return bool if successfull or not. |
198 | */ | 198 | */ |
199 | bool Interfaces::removeInterface(){ | 199 | bool Interfaces::removeInterface(){ |
200 | if(currentIface == interfaces.end()) | 200 | if(currentIface == interfaces.end()) |
201 | return false; | 201 | return false; |
202 | (*currentIface) = ""; | 202 | (*currentIface) = ""; |
203 | return removeAllInterfaceOptions(); | 203 | return removeAllInterfaceOptions(); |
204 | } | 204 | } |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Gets the hardware name of the interface that is currently selected. | 207 | * Gets the hardware name of the interface that is currently selected. |
208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
209 | * @param error set to true if any error occurs, false otherwise. | 209 | * @param error set to true if any error occurs, false otherwise. |
210 | */ | 210 | */ |
211 | QString Interfaces::getInterfaceName(bool &error){ | 211 | QString Interfaces::getInterfaceName(bool &error){ |
212 | if(currentIface == interfaces.end()){ | 212 | if(currentIface == interfaces.end()){ |
213 | error = true; | 213 | error = true; |
214 | return QString(); | 214 | return QString(); |
215 | } | 215 | } |
216 | QString line = (*currentIface); | 216 | QString line = (*currentIface); |
217 | line = line.mid(QString(IFACE).length() +1, line.length()); | 217 | line = line.mid(QString(IFACE).length() +1, line.length()); |
218 | line = line.simplifyWhiteSpace(); | 218 | line = line.simplifyWhiteSpace(); |
219 | int findSpace = line.find(" "); | 219 | int findSpace = line.find(" "); |
220 | if( findSpace < 0){ | 220 | if( findSpace < 0){ |
221 | error = true; | 221 | error = true; |
222 | return QString(); | 222 | return QString(); |
223 | } | 223 | } |
224 | error = false; | 224 | error = false; |
225 | return line.mid(0, findSpace); | 225 | return line.mid(0, findSpace); |
226 | } | 226 | } |
227 | 227 | ||
228 | /** | 228 | /** |
229 | * Gets the family name of the interface that is currently selected. | 229 | * Gets the family name of the interface that is currently selected. |
230 | * @return QString name of the family (inet, inet6, ipx). | 230 | * @return QString name of the family (inet, inet6, ipx). |
231 | * @param error set to true if any error occurs, false otherwise. | 231 | * @param error set to true if any error occurs, false otherwise. |
232 | */ | 232 | */ |
233 | QString Interfaces::getInterfaceFamily(bool &error){ | 233 | QString Interfaces::getInterfaceFamily(bool &error){ |
234 | QString name = getInterfaceName(error); | 234 | QString name = getInterfaceName(error); |
235 | if(error){ | 235 | if(error){ |
236 | error = true; | 236 | error = true; |
237 | return QString(); | 237 | return QString(); |
238 | } | 238 | } |
239 | QString line = (*currentIface); | 239 | QString line = (*currentIface); |
240 | line = line.mid(QString(IFACE).length() +1, line.length()); | 240 | line = line.mid(QString(IFACE).length() +1, line.length()); |
241 | line = line.mid(name.length()+1, line.length()); | 241 | line = line.mid(name.length()+1, line.length()); |
242 | line = line.simplifyWhiteSpace(); | 242 | line = line.simplifyWhiteSpace(); |
243 | int findSpace = line.find(" "); | 243 | int findSpace = line.find(" "); |
244 | if( findSpace < 0){ | 244 | if( findSpace < 0){ |
245 | error = true; | 245 | error = true; |
246 | return QString(); | 246 | return QString(); |
247 | } | 247 | } |
248 | error = false; | 248 | error = false; |
249 | return line.mid(0, findSpace); | 249 | return line.mid(0, findSpace); |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Gets the method of the interface that is currently selected. | 253 | * Gets the method of the interface that is currently selected. |
254 | * @return QString name of the method such as staic or dhcp. | 254 | * @return QString name of the method such as staic or dhcp. |
255 | * See the man page of interfaces for possible methods depending on the family. | 255 | * See the man page of interfaces for possible methods depending on the family. |
256 | * @param error set to true if any error occurs, false otherwise. | 256 | * @param error set to true if any error occurs, false otherwise. |
257 | */ | 257 | */ |
258 | QString Interfaces::getInterfaceMethod(bool &error){ | 258 | QString Interfaces::getInterfaceMethod(bool &error){ |
259 | QString name = getInterfaceName(error); | 259 | QString name = getInterfaceName(error); |
260 | if(error){ | 260 | if(error){ |
261 | error = true; | 261 | error = true; |
262 | return QString(); | 262 | return QString(); |
263 | } | 263 | } |
264 | QString family = getInterfaceFamily(error); | 264 | QString family = getInterfaceFamily(error); |
265 | if(error){ | 265 | if(error){ |
266 | error = true; | 266 | error = true; |
267 | return QString(); | 267 | return QString(); |
268 | } | 268 | } |
269 | QString line = (*currentIface); | 269 | QString line = (*currentIface); |
270 | line = line.mid(QString(IFACE).length()+1, line.length()); | 270 | line = line.mid(QString(IFACE).length()+1, line.length()); |
271 | line = line.mid(name.length()+1, line.length()); | 271 | line = line.mid(name.length()+1, line.length()); |
272 | line = line.mid(family.length()+1, line.length()); | 272 | line = line.mid(family.length()+1, line.length()); |
273 | line = line.simplifyWhiteSpace(); | 273 | line = line.simplifyWhiteSpace(); |
274 | error = false; | 274 | error = false; |
275 | return line; | 275 | return line; |
276 | } | 276 | } |
277 | 277 | ||
278 | /** | 278 | /** |
279 | * Sets the interface name to newName. | 279 | * Sets the interface name to newName. |
280 | * @param newName the new name of the interface. All whitespace is removed. | 280 | * @param newName the new name of the interface. All whitespace is removed. |
281 | * @return bool true if successfull. | 281 | * @return bool true if successfull. |
282 | */ | 282 | */ |
@@ -463,176 +463,176 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator | |||
463 | if(point > 0){ | 463 | if(point > 0){ |
464 | // There are more chars in the line. check +1 | 464 | // There are more chars in the line. check +1 |
465 | if(line.at(point-1) != ' ') | 465 | if(line.at(point-1) != ' ') |
466 | valid = false; | 466 | valid = false; |
467 | } | 467 | } |
468 | point += option.length(); | 468 | point += option.length(); |
469 | if(point < line.length()-1){ | 469 | if(point < line.length()-1){ |
470 | // There are more chars in the line. check -1 | 470 | // There are more chars in the line. check -1 |
471 | if(line.at(point) != ' ') | 471 | if(line.at(point) != ' ') |
472 | valid = false; | 472 | valid = false; |
473 | } | 473 | } |
474 | if(valid){ | 474 | if(valid){ |
475 | if(found == true){ | 475 | if(found == true){ |
476 | 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()); |
477 | } | 477 | } |
478 | found = true; | 478 | found = true; |
479 | iterator = it; | 479 | iterator = it; |
480 | } | 480 | } |
481 | } | 481 | } |
482 | } | 482 | } |
483 | return found; | 483 | return found; |
484 | } | 484 | } |
485 | 485 | ||
486 | /** | 486 | /** |
487 | * Sets a value of an option in a stanza | 487 | * Sets a value of an option in a stanza |
488 | * @param start the start of the stanza | 488 | * @param start the start of the stanza |
489 | * @param option the option to use when setting value. | 489 | * @param option the option to use when setting value. |
490 | * @return bool true if successfull, false otherwise. | 490 | * @return bool true if successfull, false otherwise. |
491 | */ | 491 | */ |
492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ |
493 | if(start == interfaces.end()) | 493 | if(start == interfaces.end()) |
494 | return false; | 494 | return false; |
495 | 495 | ||
496 | bool found = false; | 496 | bool found = false; |
497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
498 | 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){ |
499 | if(!found && value != ""){ | 499 | if(!found && value != ""){ |
500 | // 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. |
501 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | 501 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
502 | } | 502 | } |
503 | found = true; | 503 | found = true; |
504 | break; | 504 | break; |
505 | } | 505 | } |
506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
507 | // Found it in stanza so replace it. | 507 | // Found it in stanza so replace it. |
508 | if(found) | 508 | if(found) |
509 | 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()); |
510 | found = true; | 510 | found = true; |
511 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 511 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | if(!found){ | 514 | if(!found){ |
515 | QStringList::Iterator p = start; | 515 | QStringList::Iterator p = start; |
516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
517 | found = true; | 517 | found = true; |
518 | } | 518 | } |
519 | return found; | 519 | return found; |
520 | } | 520 | } |
521 | /** | 521 | /** |
522 | * Removes a option in a stanza | 522 | * Removes a option in a stanza |
523 | * @param start the start of the stanza | 523 | * @param start the start of the stanza |
524 | * @param option the option to use when setting value. | 524 | * @param option the option to use when setting value. |
525 | * @return bool true if successfull, false otherwise. | 525 | * @return bool true if successfull, false otherwise. |
526 | */ | 526 | */ |
527 | bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ | 527 | bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ |
528 | if(start == interfaces.end()) | 528 | if(start == interfaces.end()) |
529 | return false; | 529 | return false; |
530 | 530 | ||
531 | bool found = false; | 531 | bool found = false; |
532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
534 | // got to the end without finding it | 534 | // got to the end without finding it |
535 | break; | 535 | break; |
536 | } | 536 | } |
537 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 537 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
538 | // Found it in stanza so replace it. | 538 | // Found it in stanza so replace it. |
539 | if(found) | 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()); | 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; | 541 | found = true; |
542 | (*it) = ""; | 542 | (*it) = ""; |
543 | } | 543 | } |
544 | } | 544 | } |
545 | return found; | 545 | return found; |
546 | } | 546 | } |
547 | 547 | ||
548 | /** | 548 | /** |
549 | * Removes all options in a stanza | 549 | * Removes all options in a stanza |
550 | * @param start the start of the stanza | 550 | * @param start the start of the stanza |
551 | * @return bool true if successfull, false otherwise. | 551 | * @return bool true if successfull, false otherwise. |
552 | */ | 552 | */ |
553 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | 553 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ |
554 | if(start == interfaces.end()) | 554 | if(start == interfaces.end()) |
555 | return false; | 555 | return false; |
556 | 556 | ||
557 | QStringList::Iterator it = start; | 557 | QStringList::Iterator it = start; |
558 | it = ++it; | 558 | it = ++it; |
559 | for (it; it != interfaces.end(); ++it ) { | 559 | for (; it != interfaces.end(); ++it ) { |
560 | 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){ |
561 | break; | 561 | break; |
562 | } | 562 | } |
563 | it = interfaces.remove(it); | 563 | it = interfaces.remove(it); |
564 | it = --it; | 564 | it = --it; |
565 | } | 565 | } |
566 | // Leave a space between this interface and the next. | 566 | // Leave a space between this interface and the next. |
567 | interfaces.insert(it, QString("")); | 567 | interfaces.insert(it, QString("")); |
568 | return true; | 568 | return true; |
569 | } | 569 | } |
570 | 570 | ||
571 | /** | 571 | /** |
572 | * Gets a value of an option in a stanza | 572 | * Gets a value of an option in a stanza |
573 | * @param start the start of the stanza | 573 | * @param start the start of the stanza |
574 | * @param option the option to use when getting the value. | 574 | * @param option the option to use when getting the value. |
575 | * @param bool true if errors false otherwise. | 575 | * @param bool true if errors false otherwise. |
576 | * @return QString the value of option QString::null() if error == true. | 576 | * @return QString the value of option QString::null() if error == true. |
577 | */ | 577 | */ |
578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | 578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ |
579 | if(start == interfaces.end()){ | 579 | if(start == interfaces.end()){ |
580 | error = false; | 580 | error = false; |
581 | return QString(); | 581 | return QString(); |
582 | } | 582 | } |
583 | 583 | ||
584 | QString value; | 584 | QString value; |
585 | bool found = false; | 585 | bool found = false; |
586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
587 | 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){ |
588 | break; | 588 | break; |
589 | } | 589 | } |
590 | if((*it).contains(option) && (*it).at(0) != '#'){ | 590 | if((*it).contains(option) && (*it).at(0) != '#'){ |
591 | if(found) | 591 | if(found) |
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()); | 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()); |
593 | found = true; | 593 | found = true; |
594 | QString line = (*it).simplifyWhiteSpace(); | 594 | QString line = (*it).simplifyWhiteSpace(); |
595 | int space = line.find(" ", option.length()); | 595 | int space = line.find(" ", option.length()); |
596 | if(space != -1) | 596 | if(space != -1) |
597 | value = line.mid(space+1, line.length()); | 597 | value = line.mid(space+1, line.length()); |
598 | else | 598 | else |
599 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | 599 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); |
600 | } | 600 | } |
601 | } | 601 | } |
602 | error = !found; | 602 | error = !found; |
603 | return value; | 603 | return value; |
604 | } | 604 | } |
605 | 605 | ||
606 | /** | 606 | /** |
607 | * Write out the interfaces file to the file passed into the constructor. | 607 | * Write out the interfaces file to the file passed into the constructor. |
608 | * Removes any excess blank lines over 1 line long. | 608 | * Removes any excess blank lines over 1 line long. |
609 | * @return bool true if successfull, false if not. | 609 | * @return bool true if successfull, false if not. |
610 | */ | 610 | */ |
611 | bool Interfaces::write(){ | 611 | bool Interfaces::write(){ |
612 | QFile::remove(interfacesFile); | 612 | QFile::remove(interfacesFile); |
613 | QFile file(interfacesFile); | 613 | QFile file(interfacesFile); |
614 | 614 | ||
615 | if (!file.open(IO_ReadWrite)){ | 615 | if (!file.open(IO_ReadWrite)){ |
616 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 616 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
617 | return false; | 617 | return false; |
618 | } | 618 | } |
619 | QTextStream stream( &file ); | 619 | QTextStream stream( &file ); |
620 | int whiteSpaceCount = 0; | 620 | int whiteSpaceCount = 0; |
621 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 621 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
622 | QString line = (*it).simplifyWhiteSpace(); | 622 | QString line = (*it).simplifyWhiteSpace(); |
623 | line = line.replace(QRegExp(" "),""); | 623 | line = line.replace(QRegExp(" "),""); |
624 | if(line.length() == 0) | 624 | if(line.length() == 0) |
625 | whiteSpaceCount++; | 625 | whiteSpaceCount++; |
626 | else | 626 | else |
627 | whiteSpaceCount = 0; | 627 | whiteSpaceCount = 0; |
628 | if(whiteSpaceCount < 2){ | 628 | if(whiteSpaceCount < 2){ |
629 | qDebug((*it).latin1()); | 629 | qDebug((*it).latin1()); |
630 | stream << (*it) << '\n'; | 630 | stream << (*it) << '\n'; |
631 | } | 631 | } |
632 | } | 632 | } |
633 | file.close(); | 633 | file.close(); |
634 | return true; | 634 | return true; |
635 | } | 635 | } |
636 | 636 | ||
637 | // interfaces.cpp | 637 | // interfaces.cpp |
638 | 638 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 377a6db..f1b8067 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp | |||
@@ -90,193 +90,193 @@ bool Interfaces::setAuto(QString interface, bool setAuto){ | |||
90 | // Don't need to set it if it is already set. | 90 | // Don't need to set it if it is already set. |
91 | if(isAuto(interface) == setAuto) | 91 | if(isAuto(interface) == setAuto) |
92 | return false; | 92 | return false; |
93 | 93 | ||
94 | bool changed = false; | 94 | bool changed = false; |
95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
96 | if((*it).contains(AUTO)){ | 96 | if((*it).contains(AUTO)){ |
97 | //We know that they are not in any group so let add to this auto. | 97 | //We know that they are not in any group so let add to this auto. |
98 | if(setAuto){ | 98 | if(setAuto){ |
99 | (*it) = (*it) += " " + interface; | 99 | (*it) = (*it) += " " + interface; |
100 | // Don't care to have such thins as: auto eth0 lo usb0 | 100 | // Don't care to have such thins as: auto eth0 lo usb0 |
101 | (*it) = (*it).simplifyWhiteSpace(); | 101 | (*it) = (*it).simplifyWhiteSpace(); |
102 | changed = true; | 102 | changed = true; |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | else{ | 105 | else{ |
106 | if((*it).contains(interface)){ | 106 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 107 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // clean up | 108 | // clean up |
109 | QString line = (*it).simplifyWhiteSpace(); | 109 | QString line = (*it).simplifyWhiteSpace(); |
110 | line = line.replace(QRegExp(" "),""); | 110 | line = line.replace(QRegExp(" "),""); |
111 | if(line == AUTO) | 111 | if(line == AUTO) |
112 | (*it) = ""; | 112 | (*it) = ""; |
113 | changed = true; | 113 | changed = true; |
114 | // Don't break because we want to make sure we remove all cases. | 114 | // Don't break because we want to make sure we remove all cases. |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | if(changed == false){ | 119 | if(changed == false){ |
120 | if(setAuto == true) | 120 | if(setAuto == true) |
121 | interfaces.append(QString(AUTO" %1").arg(interface)); | 121 | interfaces.append(QString(AUTO" %1").arg(interface)); |
122 | else{ | 122 | else{ |
123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | 123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | return true; | 126 | return true; |
127 | } | 127 | } |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Set the current interface to interface. This needs to be done before you | 130 | * Set the current interface to interface. This needs to be done before you |
131 | * can call getFamily(), getMethod, and get/setOption(). | 131 | * can call getFamily(), getMethod, and get/setOption(). |
132 | * @param interface the name of the interface to set. All whitespace is | 132 | * @param interface the name of the interface to set. All whitespace is |
133 | * removed from the interface name. | 133 | * removed from the interface name. |
134 | * @return bool true if it is successfull. | 134 | * @return bool true if it is successfull. |
135 | */ | 135 | */ |
136 | bool Interfaces::setInterface(QString interface){ | 136 | bool Interfaces::setInterface(QString interface){ |
137 | interface = interface.simplifyWhiteSpace(); | 137 | interface = interface.simplifyWhiteSpace(); |
138 | interface = interface.replace(QRegExp(" "), ""); | 138 | interface = interface.replace(QRegExp(" "), ""); |
139 | return setStanza(IFACE, interface, currentIface); | 139 | return setStanza(IFACE, interface, currentIface); |
140 | } | 140 | } |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * A quick helper funtion to see if the current interface is set. | 143 | * A quick helper funtion to see if the current interface is set. |
144 | * @return bool true if set, false otherwise. | 144 | * @return bool true if set, false otherwise. |
145 | */ | 145 | */ |
146 | bool Interfaces::isInterfaceSet(){ | 146 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 147 | return (currentIface != interfaces.end()); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Add a new interface of with the settings - family and method | 151 | * Add a new interface of with the settings - family and method |
152 | * @param interface the name of the interface to set. All whitespace is | 152 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 153 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 154 | * @param family the family of this interface inet or inet, ipx or inet6 |
155 | * Must of one of the families defined in interfaces.h | 155 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 156 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 157 | * @return true if successfull. |
158 | */ | 158 | */ |
159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | 159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ |
160 | if(acceptedFamily.contains(family)==0) | 160 | if(acceptedFamily.contains(family)==0) |
161 | return false; | 161 | return false; |
162 | interface = interface.simplifyWhiteSpace(); | 162 | interface = interface.simplifyWhiteSpace(); |
163 | interface = interface.replace(QRegExp(" "), ""); | 163 | interface = interface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 164 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | 165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Copies interface with name interface to name newInterface | 170 | * Copies interface with name interface to name newInterface |
171 | * @param newInterface name of the new interface. | 171 | * @param newInterface name of the new interface. |
172 | * @return bool true if successfull | 172 | * @return bool true if successfull |
173 | */ | 173 | */ |
174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ | 174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ |
175 | if(!setInterface(interface)) return false; | 175 | if(!setInterface(interface)) return false; |
176 | 176 | ||
177 | QStringList::Iterator it = currentIface; | 177 | QStringList::Iterator it = currentIface; |
178 | it++; | 178 | it++; |
179 | 179 | ||
180 | bool error; | 180 | bool error; |
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
182 | if(!setInterface(newInterface)) return false; | 182 | if(!setInterface(newInterface)) return false; |
183 | QStringList::Iterator newIface = currentIface; | 183 | QStringList::Iterator newIface = currentIface; |
184 | newIface++; | 184 | newIface++; |
185 | 185 | ||
186 | for ( it; it != interfaces.end(); ++it ){ | 186 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 188 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 189 | newIface = interfaces.insert(newIface, *it); |
190 | } | 190 | } |
191 | 191 | ||
192 | return true; | 192 | return true; |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Remove the currently selected interface and all of its options. | 196 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 197 | * @return bool if successfull or not. |
198 | */ | 198 | */ |
199 | bool Interfaces::removeInterface(){ | 199 | bool Interfaces::removeInterface(){ |
200 | if(currentIface == interfaces.end()) | 200 | if(currentIface == interfaces.end()) |
201 | return false; | 201 | return false; |
202 | (*currentIface) = ""; | 202 | (*currentIface) = ""; |
203 | return removeAllInterfaceOptions(); | 203 | return removeAllInterfaceOptions(); |
204 | } | 204 | } |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Gets the hardware name of the interface that is currently selected. | 207 | * Gets the hardware name of the interface that is currently selected. |
208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
209 | * @param error set to true if any error occurs, false otherwise. | 209 | * @param error set to true if any error occurs, false otherwise. |
210 | */ | 210 | */ |
211 | QString Interfaces::getInterfaceName(bool &error){ | 211 | QString Interfaces::getInterfaceName(bool &error){ |
212 | if(currentIface == interfaces.end()){ | 212 | if(currentIface == interfaces.end()){ |
213 | error = true; | 213 | error = true; |
214 | return QString(); | 214 | return QString(); |
215 | } | 215 | } |
216 | QString line = (*currentIface); | 216 | QString line = (*currentIface); |
217 | line = line.mid(QString(IFACE).length() +1, line.length()); | 217 | line = line.mid(QString(IFACE).length() +1, line.length()); |
218 | line = line.simplifyWhiteSpace(); | 218 | line = line.simplifyWhiteSpace(); |
219 | int findSpace = line.find(" "); | 219 | int findSpace = line.find(" "); |
220 | if( findSpace < 0){ | 220 | if( findSpace < 0){ |
221 | error = true; | 221 | error = true; |
222 | return QString(); | 222 | return QString(); |
223 | } | 223 | } |
224 | error = false; | 224 | error = false; |
225 | return line.mid(0, findSpace); | 225 | return line.mid(0, findSpace); |
226 | } | 226 | } |
227 | 227 | ||
228 | /** | 228 | /** |
229 | * Gets the family name of the interface that is currently selected. | 229 | * Gets the family name of the interface that is currently selected. |
230 | * @return QString name of the family (inet, inet6, ipx). | 230 | * @return QString name of the family (inet, inet6, ipx). |
231 | * @param error set to true if any error occurs, false otherwise. | 231 | * @param error set to true if any error occurs, false otherwise. |
232 | */ | 232 | */ |
233 | QString Interfaces::getInterfaceFamily(bool &error){ | 233 | QString Interfaces::getInterfaceFamily(bool &error){ |
234 | QString name = getInterfaceName(error); | 234 | QString name = getInterfaceName(error); |
235 | if(error){ | 235 | if(error){ |
236 | error = true; | 236 | error = true; |
237 | return QString(); | 237 | return QString(); |
238 | } | 238 | } |
239 | QString line = (*currentIface); | 239 | QString line = (*currentIface); |
240 | line = line.mid(QString(IFACE).length() +1, line.length()); | 240 | line = line.mid(QString(IFACE).length() +1, line.length()); |
241 | line = line.mid(name.length()+1, line.length()); | 241 | line = line.mid(name.length()+1, line.length()); |
242 | line = line.simplifyWhiteSpace(); | 242 | line = line.simplifyWhiteSpace(); |
243 | int findSpace = line.find(" "); | 243 | int findSpace = line.find(" "); |
244 | if( findSpace < 0){ | 244 | if( findSpace < 0){ |
245 | error = true; | 245 | error = true; |
246 | return QString(); | 246 | return QString(); |
247 | } | 247 | } |
248 | error = false; | 248 | error = false; |
249 | return line.mid(0, findSpace); | 249 | return line.mid(0, findSpace); |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Gets the method of the interface that is currently selected. | 253 | * Gets the method of the interface that is currently selected. |
254 | * @return QString name of the method such as staic or dhcp. | 254 | * @return QString name of the method such as staic or dhcp. |
255 | * See the man page of interfaces for possible methods depending on the family. | 255 | * See the man page of interfaces for possible methods depending on the family. |
256 | * @param error set to true if any error occurs, false otherwise. | 256 | * @param error set to true if any error occurs, false otherwise. |
257 | */ | 257 | */ |
258 | QString Interfaces::getInterfaceMethod(bool &error){ | 258 | QString Interfaces::getInterfaceMethod(bool &error){ |
259 | QString name = getInterfaceName(error); | 259 | QString name = getInterfaceName(error); |
260 | if(error){ | 260 | if(error){ |
261 | error = true; | 261 | error = true; |
262 | return QString(); | 262 | return QString(); |
263 | } | 263 | } |
264 | QString family = getInterfaceFamily(error); | 264 | QString family = getInterfaceFamily(error); |
265 | if(error){ | 265 | if(error){ |
266 | error = true; | 266 | error = true; |
267 | return QString(); | 267 | return QString(); |
268 | } | 268 | } |
269 | QString line = (*currentIface); | 269 | QString line = (*currentIface); |
270 | line = line.mid(QString(IFACE).length()+1, line.length()); | 270 | line = line.mid(QString(IFACE).length()+1, line.length()); |
271 | line = line.mid(name.length()+1, line.length()); | 271 | line = line.mid(name.length()+1, line.length()); |
272 | line = line.mid(family.length()+1, line.length()); | 272 | line = line.mid(family.length()+1, line.length()); |
273 | line = line.simplifyWhiteSpace(); | 273 | line = line.simplifyWhiteSpace(); |
274 | error = false; | 274 | error = false; |
275 | return line; | 275 | return line; |
276 | } | 276 | } |
277 | 277 | ||
278 | /** | 278 | /** |
279 | * Sets the interface name to newName. | 279 | * Sets the interface name to newName. |
280 | * @param newName the new name of the interface. All whitespace is removed. | 280 | * @param newName the new name of the interface. All whitespace is removed. |
281 | * @return bool true if successfull. | 281 | * @return bool true if successfull. |
282 | */ | 282 | */ |
@@ -463,176 +463,176 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator | |||
463 | if(point > 0){ | 463 | if(point > 0){ |
464 | // There are more chars in the line. check +1 | 464 | // There are more chars in the line. check +1 |
465 | if(line.at(point-1) != ' ') | 465 | if(line.at(point-1) != ' ') |
466 | valid = false; | 466 | valid = false; |
467 | } | 467 | } |
468 | point += option.length(); | 468 | point += option.length(); |
469 | if(point < line.length()-1){ | 469 | if(point < line.length()-1){ |
470 | // There are more chars in the line. check -1 | 470 | // There are more chars in the line. check -1 |
471 | if(line.at(point) != ' ') | 471 | if(line.at(point) != ' ') |
472 | valid = false; | 472 | valid = false; |
473 | } | 473 | } |
474 | if(valid){ | 474 | if(valid){ |
475 | if(found == true){ | 475 | if(found == true){ |
476 | 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()); |
477 | } | 477 | } |
478 | found = true; | 478 | found = true; |
479 | iterator = it; | 479 | iterator = it; |
480 | } | 480 | } |
481 | } | 481 | } |
482 | } | 482 | } |
483 | return found; | 483 | return found; |
484 | } | 484 | } |
485 | 485 | ||
486 | /** | 486 | /** |
487 | * Sets a value of an option in a stanza | 487 | * Sets a value of an option in a stanza |
488 | * @param start the start of the stanza | 488 | * @param start the start of the stanza |
489 | * @param option the option to use when setting value. | 489 | * @param option the option to use when setting value. |
490 | * @return bool true if successfull, false otherwise. | 490 | * @return bool true if successfull, false otherwise. |
491 | */ | 491 | */ |
492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ |
493 | if(start == interfaces.end()) | 493 | if(start == interfaces.end()) |
494 | return false; | 494 | return false; |
495 | 495 | ||
496 | bool found = false; | 496 | bool found = false; |
497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
498 | 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){ |
499 | if(!found && value != ""){ | 499 | if(!found && value != ""){ |
500 | // 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. |
501 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | 501 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
502 | } | 502 | } |
503 | found = true; | 503 | found = true; |
504 | break; | 504 | break; |
505 | } | 505 | } |
506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
507 | // Found it in stanza so replace it. | 507 | // Found it in stanza so replace it. |
508 | if(found) | 508 | if(found) |
509 | 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()); |
510 | found = true; | 510 | found = true; |
511 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 511 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | if(!found){ | 514 | if(!found){ |
515 | QStringList::Iterator p = start; | 515 | QStringList::Iterator p = start; |
516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
517 | found = true; | 517 | found = true; |
518 | } | 518 | } |
519 | return found; | 519 | return found; |
520 | } | 520 | } |
521 | /** | 521 | /** |
522 | * Removes a option in a stanza | 522 | * Removes a option in a stanza |
523 | * @param start the start of the stanza | 523 | * @param start the start of the stanza |
524 | * @param option the option to use when setting value. | 524 | * @param option the option to use when setting value. |
525 | * @return bool true if successfull, false otherwise. | 525 | * @return bool true if successfull, false otherwise. |
526 | */ | 526 | */ |
527 | bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ | 527 | bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ |
528 | if(start == interfaces.end()) | 528 | if(start == interfaces.end()) |
529 | return false; | 529 | return false; |
530 | 530 | ||
531 | bool found = false; | 531 | bool found = false; |
532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
534 | // got to the end without finding it | 534 | // got to the end without finding it |
535 | break; | 535 | break; |
536 | } | 536 | } |
537 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 537 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
538 | // Found it in stanza so replace it. | 538 | // Found it in stanza so replace it. |
539 | if(found) | 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()); | 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; | 541 | found = true; |
542 | (*it) = ""; | 542 | (*it) = ""; |
543 | } | 543 | } |
544 | } | 544 | } |
545 | return found; | 545 | return found; |
546 | } | 546 | } |
547 | 547 | ||
548 | /** | 548 | /** |
549 | * Removes all options in a stanza | 549 | * Removes all options in a stanza |
550 | * @param start the start of the stanza | 550 | * @param start the start of the stanza |
551 | * @return bool true if successfull, false otherwise. | 551 | * @return bool true if successfull, false otherwise. |
552 | */ | 552 | */ |
553 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | 553 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ |
554 | if(start == interfaces.end()) | 554 | if(start == interfaces.end()) |
555 | return false; | 555 | return false; |
556 | 556 | ||
557 | QStringList::Iterator it = start; | 557 | QStringList::Iterator it = start; |
558 | it = ++it; | 558 | it = ++it; |
559 | for (it; it != interfaces.end(); ++it ) { | 559 | for (; it != interfaces.end(); ++it ) { |
560 | 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){ |
561 | break; | 561 | break; |
562 | } | 562 | } |
563 | it = interfaces.remove(it); | 563 | it = interfaces.remove(it); |
564 | it = --it; | 564 | it = --it; |
565 | } | 565 | } |
566 | // Leave a space between this interface and the next. | 566 | // Leave a space between this interface and the next. |
567 | interfaces.insert(it, QString("")); | 567 | interfaces.insert(it, QString("")); |
568 | return true; | 568 | return true; |
569 | } | 569 | } |
570 | 570 | ||
571 | /** | 571 | /** |
572 | * Gets a value of an option in a stanza | 572 | * Gets a value of an option in a stanza |
573 | * @param start the start of the stanza | 573 | * @param start the start of the stanza |
574 | * @param option the option to use when getting the value. | 574 | * @param option the option to use when getting the value. |
575 | * @param bool true if errors false otherwise. | 575 | * @param bool true if errors false otherwise. |
576 | * @return QString the value of option QString::null() if error == true. | 576 | * @return QString the value of option QString::null() if error == true. |
577 | */ | 577 | */ |
578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | 578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ |
579 | if(start == interfaces.end()){ | 579 | if(start == interfaces.end()){ |
580 | error = false; | 580 | error = false; |
581 | return QString(); | 581 | return QString(); |
582 | } | 582 | } |
583 | 583 | ||
584 | QString value; | 584 | QString value; |
585 | bool found = false; | 585 | bool found = false; |
586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
587 | 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){ |
588 | break; | 588 | break; |
589 | } | 589 | } |
590 | if((*it).contains(option) && (*it).at(0) != '#'){ | 590 | if((*it).contains(option) && (*it).at(0) != '#'){ |
591 | if(found) | 591 | if(found) |
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()); | 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()); |
593 | found = true; | 593 | found = true; |
594 | QString line = (*it).simplifyWhiteSpace(); | 594 | QString line = (*it).simplifyWhiteSpace(); |
595 | int space = line.find(" ", option.length()); | 595 | int space = line.find(" ", option.length()); |
596 | if(space != -1) | 596 | if(space != -1) |
597 | value = line.mid(space+1, line.length()); | 597 | value = line.mid(space+1, line.length()); |
598 | else | 598 | else |
599 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | 599 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); |
600 | } | 600 | } |
601 | } | 601 | } |
602 | error = !found; | 602 | error = !found; |
603 | return value; | 603 | return value; |
604 | } | 604 | } |
605 | 605 | ||
606 | /** | 606 | /** |
607 | * Write out the interfaces file to the file passed into the constructor. | 607 | * Write out the interfaces file to the file passed into the constructor. |
608 | * Removes any excess blank lines over 1 line long. | 608 | * Removes any excess blank lines over 1 line long. |
609 | * @return bool true if successfull, false if not. | 609 | * @return bool true if successfull, false if not. |
610 | */ | 610 | */ |
611 | bool Interfaces::write(){ | 611 | bool Interfaces::write(){ |
612 | QFile::remove(interfacesFile); | 612 | QFile::remove(interfacesFile); |
613 | QFile file(interfacesFile); | 613 | QFile file(interfacesFile); |
614 | 614 | ||
615 | if (!file.open(IO_ReadWrite)){ | 615 | if (!file.open(IO_ReadWrite)){ |
616 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 616 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
617 | return false; | 617 | return false; |
618 | } | 618 | } |
619 | QTextStream stream( &file ); | 619 | QTextStream stream( &file ); |
620 | int whiteSpaceCount = 0; | 620 | int whiteSpaceCount = 0; |
621 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 621 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
622 | QString line = (*it).simplifyWhiteSpace(); | 622 | QString line = (*it).simplifyWhiteSpace(); |
623 | line = line.replace(QRegExp(" "),""); | 623 | line = line.replace(QRegExp(" "),""); |
624 | if(line.length() == 0) | 624 | if(line.length() == 0) |
625 | whiteSpaceCount++; | 625 | whiteSpaceCount++; |
626 | else | 626 | else |
627 | whiteSpaceCount = 0; | 627 | whiteSpaceCount = 0; |
628 | if(whiteSpaceCount < 2){ | 628 | if(whiteSpaceCount < 2){ |
629 | qDebug((*it).latin1()); | 629 | qDebug((*it).latin1()); |
630 | stream << (*it) << '\n'; | 630 | stream << (*it) << '\n'; |
631 | } | 631 | } |
632 | } | 632 | } |
633 | file.close(); | 633 | file.close(); |
634 | return true; | 634 | return true; |
635 | } | 635 | } |
636 | 636 | ||
637 | // interfaces.cpp | 637 | // interfaces.cpp |
638 | 638 | ||