summaryrefslogtreecommitdiff
authorsimon <simon>2002-11-08 15:17:49 (UTC)
committer simon <simon>2002-11-08 15:17:49 (UTC)
commit447735be20fad2642617e3ba4f7ef0b598f597db (patch) (unidiff)
tree2627703ed5020debe5c408f42e31841618fbb47c
parentc2d39953b626147400114dbde85d87bdf5081576 (diff)
downloadopie-447735be20fad2642617e3ba4f7ef0b598f597db.zip
opie-447735be20fad2642617e3ba4f7ef0b598f597db.tar.gz
opie-447735be20fad2642617e3ba4f7ef0b598f597db.tar.bz2
- fix some more gcc3 warnings by removing statements with no effect:
- for ( it; it != interfaces.end(); ++it ){ + for ( ; it != interfaces.end(); ++it ){
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.cpp4
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp4
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
@@ -1,638 +1,638 @@
1#include "interfaces.h" 1#include "interfaces.h"
2 2
3#include <qfile.h> 3#include <qfile.h>
4#include <qtextstream.h> 4#include <qtextstream.h>
5#include <qregexp.h> 5#include <qregexp.h>
6 6
7#define AUTO "auto" 7#define AUTO "auto"
8#define IFACE "iface" 8#define IFACE "iface"
9#define MAPPING "mapping" 9#define MAPPING "mapping"
10 10
11/** 11/**
12 * Constructor. Reads in the interfaces file and then split the file up by 12 * Constructor. Reads in the interfaces file and then split the file up by
13 * the \n for interfaces variable. 13 * the \n for interfaces variable.
14 * @param useInterfacesFile if an interface file other then the default is 14 * @param useInterfacesFile if an interface file other then the default is
15 * desired to be used it should be passed in. 15 * desired to be used it should be passed in.
16 */ 16 */
17Interfaces::Interfaces(QString useInterfacesFile){ 17Interfaces::Interfaces(QString useInterfacesFile){
18 acceptedFamily.append(INTERFACES_FAMILY_INET); 18 acceptedFamily.append(INTERFACES_FAMILY_INET);
19 acceptedFamily.append(INTERFACES_FAMILY_IPX); 19 acceptedFamily.append(INTERFACES_FAMILY_IPX);
20 acceptedFamily.append(INTERFACES_FAMILY_INET6); 20 acceptedFamily.append(INTERFACES_FAMILY_INET6);
21 21
22 interfacesFile = useInterfacesFile; 22 interfacesFile = useInterfacesFile;
23 QFile file(interfacesFile); 23 QFile file(interfacesFile);
24 if (!file.open(IO_ReadOnly)){ 24 if (!file.open(IO_ReadOnly)){
25 qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); 25 qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1());
26 currentIface = interfaces.end(); 26 currentIface = interfaces.end();
27 currentMapping = interfaces.end(); 27 currentMapping = interfaces.end();
28 return; 28 return;
29 } 29 }
30 QTextStream stream( &file ); 30 QTextStream stream( &file );
31 QString line; 31 QString line;
32 while ( !stream.eof() ) { 32 while ( !stream.eof() ) {
33 line += stream.readLine(); 33 line += stream.readLine();
34 line += "\n"; 34 line += "\n";
35 } 35 }
36 file.close(); 36 file.close();
37 interfaces = QStringList::split("\n", line, true); 37 interfaces = QStringList::split("\n", line, true);
38 38
39 currentIface = interfaces.end(); 39 currentIface = interfaces.end();
40 currentMapping = interfaces.end(); 40 currentMapping = interfaces.end();
41} 41}
42 42
43 43
44/** 44/**
45 * Get a list of all interfaces in the interface file. Usefull for 45 * Get a list of all interfaces in the interface file. Usefull for
46 * hardware that is not currently connected such as an 802.11b card 46 * hardware that is not currently connected such as an 802.11b card
47 * not plugged in, but configured for when it is plugged in. 47 * not plugged in, but configured for when it is plugged in.
48 * @return Return string list of interfaces. 48 * @return Return string list of interfaces.
49 **/ 49 **/
50QStringList Interfaces::getInterfaceList(){ 50QStringList Interfaces::getInterfaceList(){
51 QStringList list; 51 QStringList list;
52 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 52 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
53 QString line = (*it).simplifyWhiteSpace(); 53 QString line = (*it).simplifyWhiteSpace();
54 if(line.contains(IFACE) && line.at(0) != '#'){ 54 if(line.contains(IFACE) && line.at(0) != '#'){
55 line = line.mid(QString(IFACE).length() +1, line.length()); 55 line = line.mid(QString(IFACE).length() +1, line.length());
56 line = line.simplifyWhiteSpace(); 56 line = line.simplifyWhiteSpace();
57 int findSpace = line.find(" "); 57 int findSpace = line.find(" ");
58 if( findSpace >= 0){ 58 if( findSpace >= 0){
59 line = line.mid(0, findSpace); 59 line = line.mid(0, findSpace);
60 list.append(line); 60 list.append(line);
61 } 61 }
62 } 62 }
63 } 63 }
64 return list; 64 return list;
65} 65}
66 66
67/** 67/**
68 * Find out if interface is in an "auto" group or not. 68 * Find out if interface is in an "auto" group or not.
69 * Report any duplicates such as eth0 being in two differnt auto's 69 * Report any duplicates such as eth0 being in two differnt auto's
70 * @param interface interface to check to see if it is on or not. 70 * @param interface interface to check to see if it is on or not.
71 * @return true is interface is in auto 71 * @return true is interface is in auto
72 */ 72 */
73bool Interfaces::isAuto(QString interface){ 73bool Interfaces::isAuto(QString interface){
74 QStringList autoLines = interfaces.grep(QRegExp(AUTO)); 74 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
75 QStringList awi = autoLines.grep(QRegExp(interface)); 75 QStringList awi = autoLines.grep(QRegExp(interface));
76 if(awi.count() > 1) 76 if(awi.count() > 1)
77 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); 77 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1());
78 if(awi.count() < 1) 78 if(awi.count() < 1)
79 return false; 79 return false;
80 return true; 80 return true;
81} 81}
82 82
83/** 83/**
84 * Attempt to set the auto option for interface to setAuto. 84 * Attempt to set the auto option for interface to setAuto.
85 * @param interface the interface to set 85 * @param interface the interface to set
86 * @param setAuto the value to set interface to. 86 * @param setAuto the value to set interface to.
87 * @return false if already set to setAuto. 87 * @return false if already set to setAuto.
88 * */ 88 * */
89bool Interfaces::setAuto(QString interface, bool setAuto){ 89bool 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 */
136bool Interfaces::setInterface(QString interface){ 136bool 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 */
146bool Interfaces::isInterfaceSet(){ 146bool 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 */
159bool Interfaces::addInterface(QString interface, QString family, QString method){ 159bool 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 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){ 174bool 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 */
199bool Interfaces::removeInterface(){ 199bool 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 */
211QString Interfaces::getInterfaceName(bool &error){ 211QString 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 */
233QString Interfaces::getInterfaceFamily(bool &error){ 233QString 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 */
258QString Interfaces::getInterfaceMethod(bool &error){ 258QString 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 */
283bool Interfaces::setInterfaceName(QString newName){ 283bool Interfaces::setInterfaceName(QString newName){
284 if(currentIface == interfaces.end()) 284 if(currentIface == interfaces.end())
285 return false; 285 return false;
286 newName = newName.simplifyWhiteSpace(); 286 newName = newName.simplifyWhiteSpace();
287 newName = newName.replace(QRegExp(" "), ""); 287 newName = newName.replace(QRegExp(" "), "");
288 bool returnValue = false; 288 bool returnValue = false;
289 (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); 289 (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
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 */
299bool Interfaces::setInterfaceFamily(QString newName){ 299bool 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 */
314bool Interfaces::setInterfaceMethod(QString newName){ 314bool 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 */
332QString Interfaces::getInterfaceOption(QString option, bool &error){ 332QString Interfaces::getInterfaceOption(QString option, bool &error){
333 return getOption(currentIface, option, error); 333 return getOption(currentIface, option, error);
334} 334}
335 335
336/** 336/**
337 * Set a value for an option in the currently selected interface. If option 337 * Set a value for an option in the currently selected interface. If option
338 * doesn't exist then it is added along with the value. 338 * doesn't exist then it is added along with the value.
339 * @param option the options to set the value. 339 * @param option the options to set the value.
340 * @param value the value that option should be set to. 340 * @param value the value that option should be set to.
341 * @param error set to true if any error occurs, false otherwise. 341 * @param error set to true if any error occurs, false otherwise.
342 * @return QString the options value. QString::null if error == true 342 * @return QString the options value. QString::null if error == true
343 */ 343 */
344bool Interfaces::setInterfaceOption(QString option, QString value){ 344bool Interfaces::setInterfaceOption(QString option, QString value){
345 return setOption(currentIface, option, value); 345 return setOption(currentIface, option, value);
346} 346}
347 347
348/** 348/**
349 * Removes a value for an option in the currently selected interface. 349 * Removes a value for an option in the currently selected interface.
350 * @param option the options to set the value. 350 * @param option the options to set the value.
351 * @param value the value that option should be set to. 351 * @param value the value that option should be set to.
352 * @param error set to true if any error occurs, false otherwise. 352 * @param error set to true if any error occurs, false otherwise.
353 * @return QString the options value. QString::null if error == true 353 * @return QString the options value. QString::null if error == true
354 */ 354 */
355bool Interfaces::removeInterfaceOption(QString option, QString value){ 355bool Interfaces::removeInterfaceOption(QString option, QString value){
356 return removeOption(currentIface, option, value); 356 return removeOption(currentIface, option, value);
357} 357}
358 358
359/** 359/**
360 * Removes all of the options from the currently selected interface. 360 * Removes all of the options from the currently selected interface.
361 * @return bool error if if successfull 361 * @return bool error if if successfull
362 */ 362 */
363bool Interfaces::removeAllInterfaceOptions(){ 363bool Interfaces::removeAllInterfaceOptions(){
364 return removeAllOptions(currentIface); 364 return removeAllOptions(currentIface);
365} 365}
366 366
367/** 367/**
368 * 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
369 * can call addMapping(), set/getMap(), and get/setScript(). 369 * can call addMapping(), set/getMap(), and get/setScript().
370 * @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
371 * removed from the interface name. 371 * removed from the interface name.
372 * @return bool true if it is successfull. 372 * @return bool true if it is successfull.
373 */ 373 */
374bool Interfaces::setMapping(QString interface){ 374bool Interfaces::setMapping(QString interface){
375 interface = interface.simplifyWhiteSpace(); 375 interface = interface.simplifyWhiteSpace();
376 interface = interface.replace(QRegExp(" "), ""); 376 interface = interface.replace(QRegExp(" "), "");
377 return setStanza(MAPPING, interface, currentMapping); 377 return setStanza(MAPPING, interface, currentMapping);
378} 378}
379 379
380/** 380/**
381 * Adds a new Mapping to the interfaces file with interfaces. 381 * Adds a new Mapping to the interfaces file with interfaces.
382 * @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
383 */ 383 */
384void Interfaces::addMapping(QString option){ 384void Interfaces::addMapping(QString option){
385 interfaces.append(""); 385 interfaces.append("");
386 interfaces.append(QString(MAPPING " %1").arg(option)); 386 interfaces.append(QString(MAPPING " %1").arg(option));
387} 387}
388 388
389/** 389/**
390 * Remove the currently selected map and all of its options. 390 * Remove the currently selected map and all of its options.
391 * @return bool if successfull or not. 391 * @return bool if successfull or not.
392 */ 392 */
393bool Interfaces::removeMapping(){ 393bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end()) 394 if(currentMapping == interfaces.end())
395 return false; 395 return false;
396 (*currentMapping) = ""; 396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping); 397 return removeAllOptions(currentMapping);
398} 398}
399 399
400/** 400/**
401 * Set a map option within a mapping. 401 * Set a map option within a mapping.
402 * @param map map to use 402 * @param map map to use
403 * @param value value to go with map 403 * @param value value to go with map
404 * @return bool true if it is successfull. 404 * @return bool true if it is successfull.
405 */ 405 */
406bool Interfaces::setMap(QString map, QString value){ 406bool Interfaces::setMap(QString map, QString value){
407 return setOption(currentMapping, map, value); 407 return setOption(currentMapping, map, value);
408} 408}
409 409
410/** 410/**
411 * Removes a map option within a mapping. 411 * Removes a map option within a mapping.
412 * @param map map to use 412 * @param map map to use
413 * @param value value to go with map 413 * @param value value to go with map
414 * @return bool true if it is successfull. 414 * @return bool true if it is successfull.
415 */ 415 */
416bool Interfaces::removeMap(QString map, QString value){ 416bool Interfaces::removeMap(QString map, QString value){
417 return removeOption(currentMapping, map, value); 417 return removeOption(currentMapping, map, value);
418} 418}
419 419
420/** 420/**
421 * Get a map value within a mapping. 421 * Get a map value within a mapping.
422 * @param map map to get value of 422 * @param map map to get value of
423 * @param bool true if it is successfull. 423 * @param bool true if it is successfull.
424 * @return value that goes to the map 424 * @return value that goes to the map
425 */ 425 */
426QString Interfaces::getMap(QString map, bool &error){ 426QString Interfaces::getMap(QString map, bool &error){
427 return getOption(currentMapping, map, error); 427 return getOption(currentMapping, map, error);
428} 428}
429 429
430/** 430/**
431 * Sets a script value of the current mapping to argument. 431 * Sets a script value of the current mapping to argument.
432 * @param argument the script name. 432 * @param argument the script name.
433 * @return true if successfull. 433 * @return true if successfull.
434 */ 434 */
435bool Interfaces::setScript(QString argument){ 435bool Interfaces::setScript(QString argument){
436 return setOption(currentMapping, "script", argument); 436 return setOption(currentMapping, "script", argument);
437} 437}
438 438
439/** 439/**
440 * @param error true if could not retrieve the current script argument. 440 * @param error true if could not retrieve the current script argument.
441 * @return QString the argument of the script for the current mapping. 441 * @return QString the argument of the script for the current mapping.
442 */ 442 */
443QString Interfaces::getScript(bool &error){ 443QString Interfaces::getScript(bool &error){
444 return getOption(currentMapping, "script", error); 444 return getOption(currentMapping, "script", error);
445} 445}
446 446
447/** 447/**
448 * 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
449 * the correct place. 449 * the correct place.
450 * @param stanza The stanza (auto, iface, mapping) to look for. 450 * @param stanza The stanza (auto, iface, mapping) to look for.
451 * @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.
452 * @param interator interator to place at location of stanza if successfull. 452 * @param interator interator to place at location of stanza if successfull.
453 * @return bool true if the stanza is found. 453 * @return bool true if the stanza is found.
454 */ 454 */
455bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 455bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
456 bool found = false; 456 bool found = false;
457 iterator = interfaces.end(); 457 iterator = interfaces.end();
458 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 458 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
459 QString line = (*it).simplifyWhiteSpace(); 459 QString line = (*it).simplifyWhiteSpace();
460 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ 460 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){
461 uint point = line.find(option); 461 uint point = line.find(option);
462 bool valid = true; 462 bool valid = true;
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 */
492bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 492bool 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 */
527bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ 527bool 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 */
553bool Interfaces::removeAllOptions(QStringList::Iterator start){ 553bool 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 */
578QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ 578QString 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 */
611bool Interfaces::write(){ 611bool 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
@@ -1,638 +1,638 @@
1#include "interfaces.h" 1#include "interfaces.h"
2 2
3#include <qfile.h> 3#include <qfile.h>
4#include <qtextstream.h> 4#include <qtextstream.h>
5#include <qregexp.h> 5#include <qregexp.h>
6 6
7#define AUTO "auto" 7#define AUTO "auto"
8#define IFACE "iface" 8#define IFACE "iface"
9#define MAPPING "mapping" 9#define MAPPING "mapping"
10 10
11/** 11/**
12 * Constructor. Reads in the interfaces file and then split the file up by 12 * Constructor. Reads in the interfaces file and then split the file up by
13 * the \n for interfaces variable. 13 * the \n for interfaces variable.
14 * @param useInterfacesFile if an interface file other then the default is 14 * @param useInterfacesFile if an interface file other then the default is
15 * desired to be used it should be passed in. 15 * desired to be used it should be passed in.
16 */ 16 */
17Interfaces::Interfaces(QString useInterfacesFile){ 17Interfaces::Interfaces(QString useInterfacesFile){
18 acceptedFamily.append(INTERFACES_FAMILY_INET); 18 acceptedFamily.append(INTERFACES_FAMILY_INET);
19 acceptedFamily.append(INTERFACES_FAMILY_IPX); 19 acceptedFamily.append(INTERFACES_FAMILY_IPX);
20 acceptedFamily.append(INTERFACES_FAMILY_INET6); 20 acceptedFamily.append(INTERFACES_FAMILY_INET6);
21 21
22 interfacesFile = useInterfacesFile; 22 interfacesFile = useInterfacesFile;
23 QFile file(interfacesFile); 23 QFile file(interfacesFile);
24 if (!file.open(IO_ReadOnly)){ 24 if (!file.open(IO_ReadOnly)){
25 qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); 25 qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1());
26 currentIface = interfaces.end(); 26 currentIface = interfaces.end();
27 currentMapping = interfaces.end(); 27 currentMapping = interfaces.end();
28 return; 28 return;
29 } 29 }
30 QTextStream stream( &file ); 30 QTextStream stream( &file );
31 QString line; 31 QString line;
32 while ( !stream.eof() ) { 32 while ( !stream.eof() ) {
33 line += stream.readLine(); 33 line += stream.readLine();
34 line += "\n"; 34 line += "\n";
35 } 35 }
36 file.close(); 36 file.close();
37 interfaces = QStringList::split("\n", line, true); 37 interfaces = QStringList::split("\n", line, true);
38 38
39 currentIface = interfaces.end(); 39 currentIface = interfaces.end();
40 currentMapping = interfaces.end(); 40 currentMapping = interfaces.end();
41} 41}
42 42
43 43
44/** 44/**
45 * Get a list of all interfaces in the interface file. Usefull for 45 * Get a list of all interfaces in the interface file. Usefull for
46 * hardware that is not currently connected such as an 802.11b card 46 * hardware that is not currently connected such as an 802.11b card
47 * not plugged in, but configured for when it is plugged in. 47 * not plugged in, but configured for when it is plugged in.
48 * @return Return string list of interfaces. 48 * @return Return string list of interfaces.
49 **/ 49 **/
50QStringList Interfaces::getInterfaceList(){ 50QStringList Interfaces::getInterfaceList(){
51 QStringList list; 51 QStringList list;
52 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 52 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
53 QString line = (*it).simplifyWhiteSpace(); 53 QString line = (*it).simplifyWhiteSpace();
54 if(line.contains(IFACE) && line.at(0) != '#'){ 54 if(line.contains(IFACE) && line.at(0) != '#'){
55 line = line.mid(QString(IFACE).length() +1, line.length()); 55 line = line.mid(QString(IFACE).length() +1, line.length());
56 line = line.simplifyWhiteSpace(); 56 line = line.simplifyWhiteSpace();
57 int findSpace = line.find(" "); 57 int findSpace = line.find(" ");
58 if( findSpace >= 0){ 58 if( findSpace >= 0){
59 line = line.mid(0, findSpace); 59 line = line.mid(0, findSpace);
60 list.append(line); 60 list.append(line);
61 } 61 }
62 } 62 }
63 } 63 }
64 return list; 64 return list;
65} 65}
66 66
67/** 67/**
68 * Find out if interface is in an "auto" group or not. 68 * Find out if interface is in an "auto" group or not.
69 * Report any duplicates such as eth0 being in two differnt auto's 69 * Report any duplicates such as eth0 being in two differnt auto's
70 * @param interface interface to check to see if it is on or not. 70 * @param interface interface to check to see if it is on or not.
71 * @return true is interface is in auto 71 * @return true is interface is in auto
72 */ 72 */
73bool Interfaces::isAuto(QString interface){ 73bool Interfaces::isAuto(QString interface){
74 QStringList autoLines = interfaces.grep(QRegExp(AUTO)); 74 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
75 QStringList awi = autoLines.grep(QRegExp(interface)); 75 QStringList awi = autoLines.grep(QRegExp(interface));
76 if(awi.count() > 1) 76 if(awi.count() > 1)
77 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); 77 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1());
78 if(awi.count() < 1) 78 if(awi.count() < 1)
79 return false; 79 return false;
80 return true; 80 return true;
81} 81}
82 82
83/** 83/**
84 * Attempt to set the auto option for interface to setAuto. 84 * Attempt to set the auto option for interface to setAuto.
85 * @param interface the interface to set 85 * @param interface the interface to set
86 * @param setAuto the value to set interface to. 86 * @param setAuto the value to set interface to.
87 * @return false if already set to setAuto. 87 * @return false if already set to setAuto.
88 * */ 88 * */
89bool Interfaces::setAuto(QString interface, bool setAuto){ 89bool 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 */
136bool Interfaces::setInterface(QString interface){ 136bool 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 */
146bool Interfaces::isInterfaceSet(){ 146bool 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 */
159bool Interfaces::addInterface(QString interface, QString family, QString method){ 159bool 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 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){ 174bool 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 */
199bool Interfaces::removeInterface(){ 199bool 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 */
211QString Interfaces::getInterfaceName(bool &error){ 211QString 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 */
233QString Interfaces::getInterfaceFamily(bool &error){ 233QString 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 */
258QString Interfaces::getInterfaceMethod(bool &error){ 258QString 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 */
283bool Interfaces::setInterfaceName(QString newName){ 283bool Interfaces::setInterfaceName(QString newName){
284 if(currentIface == interfaces.end()) 284 if(currentIface == interfaces.end())
285 return false; 285 return false;
286 newName = newName.simplifyWhiteSpace(); 286 newName = newName.simplifyWhiteSpace();
287 newName = newName.replace(QRegExp(" "), ""); 287 newName = newName.replace(QRegExp(" "), "");
288 bool returnValue = false; 288 bool returnValue = false;
289 (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); 289 (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
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 */
299bool Interfaces::setInterfaceFamily(QString newName){ 299bool 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 */
314bool Interfaces::setInterfaceMethod(QString newName){ 314bool 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 */
332QString Interfaces::getInterfaceOption(QString option, bool &error){ 332QString Interfaces::getInterfaceOption(QString option, bool &error){
333 return getOption(currentIface, option, error); 333 return getOption(currentIface, option, error);
334} 334}
335 335
336/** 336/**
337 * Set a value for an option in the currently selected interface. If option 337 * Set a value for an option in the currently selected interface. If option
338 * doesn't exist then it is added along with the value. 338 * doesn't exist then it is added along with the value.
339 * @param option the options to set the value. 339 * @param option the options to set the value.
340 * @param value the value that option should be set to. 340 * @param value the value that option should be set to.
341 * @param error set to true if any error occurs, false otherwise. 341 * @param error set to true if any error occurs, false otherwise.
342 * @return QString the options value. QString::null if error == true 342 * @return QString the options value. QString::null if error == true
343 */ 343 */
344bool Interfaces::setInterfaceOption(QString option, QString value){ 344bool Interfaces::setInterfaceOption(QString option, QString value){
345 return setOption(currentIface, option, value); 345 return setOption(currentIface, option, value);
346} 346}
347 347
348/** 348/**
349 * Removes a value for an option in the currently selected interface. 349 * Removes a value for an option in the currently selected interface.
350 * @param option the options to set the value. 350 * @param option the options to set the value.
351 * @param value the value that option should be set to. 351 * @param value the value that option should be set to.
352 * @param error set to true if any error occurs, false otherwise. 352 * @param error set to true if any error occurs, false otherwise.
353 * @return QString the options value. QString::null if error == true 353 * @return QString the options value. QString::null if error == true
354 */ 354 */
355bool Interfaces::removeInterfaceOption(QString option, QString value){ 355bool Interfaces::removeInterfaceOption(QString option, QString value){
356 return removeOption(currentIface, option, value); 356 return removeOption(currentIface, option, value);
357} 357}
358 358
359/** 359/**
360 * Removes all of the options from the currently selected interface. 360 * Removes all of the options from the currently selected interface.
361 * @return bool error if if successfull 361 * @return bool error if if successfull
362 */ 362 */
363bool Interfaces::removeAllInterfaceOptions(){ 363bool Interfaces::removeAllInterfaceOptions(){
364 return removeAllOptions(currentIface); 364 return removeAllOptions(currentIface);
365} 365}
366 366
367/** 367/**
368 * 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
369 * can call addMapping(), set/getMap(), and get/setScript(). 369 * can call addMapping(), set/getMap(), and get/setScript().
370 * @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
371 * removed from the interface name. 371 * removed from the interface name.
372 * @return bool true if it is successfull. 372 * @return bool true if it is successfull.
373 */ 373 */
374bool Interfaces::setMapping(QString interface){ 374bool Interfaces::setMapping(QString interface){
375 interface = interface.simplifyWhiteSpace(); 375 interface = interface.simplifyWhiteSpace();
376 interface = interface.replace(QRegExp(" "), ""); 376 interface = interface.replace(QRegExp(" "), "");
377 return setStanza(MAPPING, interface, currentMapping); 377 return setStanza(MAPPING, interface, currentMapping);
378} 378}
379 379
380/** 380/**
381 * Adds a new Mapping to the interfaces file with interfaces. 381 * Adds a new Mapping to the interfaces file with interfaces.
382 * @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
383 */ 383 */
384void Interfaces::addMapping(QString option){ 384void Interfaces::addMapping(QString option){
385 interfaces.append(""); 385 interfaces.append("");
386 interfaces.append(QString(MAPPING " %1").arg(option)); 386 interfaces.append(QString(MAPPING " %1").arg(option));
387} 387}
388 388
389/** 389/**
390 * Remove the currently selected map and all of its options. 390 * Remove the currently selected map and all of its options.
391 * @return bool if successfull or not. 391 * @return bool if successfull or not.
392 */ 392 */
393bool Interfaces::removeMapping(){ 393bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end()) 394 if(currentMapping == interfaces.end())
395 return false; 395 return false;
396 (*currentMapping) = ""; 396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping); 397 return removeAllOptions(currentMapping);
398} 398}
399 399
400/** 400/**
401 * Set a map option within a mapping. 401 * Set a map option within a mapping.
402 * @param map map to use 402 * @param map map to use
403 * @param value value to go with map 403 * @param value value to go with map
404 * @return bool true if it is successfull. 404 * @return bool true if it is successfull.
405 */ 405 */
406bool Interfaces::setMap(QString map, QString value){ 406bool Interfaces::setMap(QString map, QString value){
407 return setOption(currentMapping, map, value); 407 return setOption(currentMapping, map, value);
408} 408}
409 409
410/** 410/**
411 * Removes a map option within a mapping. 411 * Removes a map option within a mapping.
412 * @param map map to use 412 * @param map map to use
413 * @param value value to go with map 413 * @param value value to go with map
414 * @return bool true if it is successfull. 414 * @return bool true if it is successfull.
415 */ 415 */
416bool Interfaces::removeMap(QString map, QString value){ 416bool Interfaces::removeMap(QString map, QString value){
417 return removeOption(currentMapping, map, value); 417 return removeOption(currentMapping, map, value);
418} 418}
419 419
420/** 420/**
421 * Get a map value within a mapping. 421 * Get a map value within a mapping.
422 * @param map map to get value of 422 * @param map map to get value of
423 * @param bool true if it is successfull. 423 * @param bool true if it is successfull.
424 * @return value that goes to the map 424 * @return value that goes to the map
425 */ 425 */
426QString Interfaces::getMap(QString map, bool &error){ 426QString Interfaces::getMap(QString map, bool &error){
427 return getOption(currentMapping, map, error); 427 return getOption(currentMapping, map, error);
428} 428}
429 429
430/** 430/**
431 * Sets a script value of the current mapping to argument. 431 * Sets a script value of the current mapping to argument.
432 * @param argument the script name. 432 * @param argument the script name.
433 * @return true if successfull. 433 * @return true if successfull.
434 */ 434 */
435bool Interfaces::setScript(QString argument){ 435bool Interfaces::setScript(QString argument){
436 return setOption(currentMapping, "script", argument); 436 return setOption(currentMapping, "script", argument);
437} 437}
438 438
439/** 439/**
440 * @param error true if could not retrieve the current script argument. 440 * @param error true if could not retrieve the current script argument.
441 * @return QString the argument of the script for the current mapping. 441 * @return QString the argument of the script for the current mapping.
442 */ 442 */
443QString Interfaces::getScript(bool &error){ 443QString Interfaces::getScript(bool &error){
444 return getOption(currentMapping, "script", error); 444 return getOption(currentMapping, "script", error);
445} 445}
446 446
447/** 447/**
448 * 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
449 * the correct place. 449 * the correct place.
450 * @param stanza The stanza (auto, iface, mapping) to look for. 450 * @param stanza The stanza (auto, iface, mapping) to look for.
451 * @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.
452 * @param interator interator to place at location of stanza if successfull. 452 * @param interator interator to place at location of stanza if successfull.
453 * @return bool true if the stanza is found. 453 * @return bool true if the stanza is found.
454 */ 454 */
455bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 455bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
456 bool found = false; 456 bool found = false;
457 iterator = interfaces.end(); 457 iterator = interfaces.end();
458 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 458 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
459 QString line = (*it).simplifyWhiteSpace(); 459 QString line = (*it).simplifyWhiteSpace();
460 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ 460 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){
461 uint point = line.find(option); 461 uint point = line.find(option);
462 bool valid = true; 462 bool valid = true;
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 */
492bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 492bool 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 */
527bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ 527bool 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 */
553bool Interfaces::removeAllOptions(QStringList::Iterator start){ 553bool 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 */
578QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ 578QString 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 */
611bool Interfaces::write(){ 611bool 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