summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp114
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp2
-rw-r--r--noncore/settings/networksettings/wlan/wlanmodule.cpp36
3 files changed, 92 insertions, 60 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp
index a62a90c..71d0cf5 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces/interfaces.cpp
@@ -1,674 +1,674 @@
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// The three stanza's 7// The three stanza's
8#define AUTO "auto" 8#define AUTO "auto"
9#define IFACE "iface" 9#define IFACE "iface"
10#define MAPPING "mapping" 10#define MAPPING "mapping"
11 11
12/** 12/**
13 * Constructor. Reads in the interfaces file and then split the file up by 13 * Constructor. Reads in the interfaces file and then split the file up by
14 * the \n for interfaces variable. 14 * the \n for interfaces variable.
15 * @param useInterfacesFile if an interface file other then the default is 15 * @param useInterfacesFile if an interface file other then the default is
16 * desired to be used it should be passed in. 16 * desired to be used it should be passed in.
17 */ 17 */
18Interfaces::Interfaces(QString useInterfacesFile){ 18Interfaces::Interfaces(QString useInterfacesFile){
19 acceptedFamily.append(INTERFACES_FAMILY_INET); 19 acceptedFamily.append(INTERFACES_FAMILY_INET);
20 acceptedFamily.append(INTERFACES_FAMILY_IPX); 20 acceptedFamily.append(INTERFACES_FAMILY_IPX);
21 acceptedFamily.append(INTERFACES_FAMILY_INET6); 21 acceptedFamily.append(INTERFACES_FAMILY_INET6);
22 22
23 interfacesFile = useInterfacesFile; 23 interfacesFile = useInterfacesFile;
24 QFile file(interfacesFile); 24 QFile file(interfacesFile);
25 if (!file.open(IO_ReadOnly)){ 25 if (!file.open(IO_ReadOnly)){
26 qDebug("Interfaces: Can't open file: %s for reading.", interfacesFile.latin1() ); 26 qDebug("Interfaces: Can't open file: %s for reading.", interfacesFile.latin1() );
27 currentIface = interfaces.end(); 27 currentIface = interfaces.end();
28 currentMapping = interfaces.end(); 28 currentMapping = interfaces.end();
29 return; 29 return;
30 } 30 }
31 QTextStream stream( &file ); 31 QTextStream stream( &file );
32 QString line; 32 QString line;
33 while ( !stream.eof() ) { 33 while ( !stream.eof() ) {
34 line += stream.readLine(); 34 line += stream.readLine();
35 line += "\n"; 35 line += "\n";
36 } 36 }
37 file.close(); 37 file.close();
38 interfaces = QStringList::split("\n", line, true); 38 interfaces = QStringList::split("\n", line, true);
39 39
40 currentIface = interfaces.end(); 40 currentIface = interfaces.end();
41 currentMapping = interfaces.end(); 41 currentMapping = interfaces.end();
42} 42}
43 43
44 44
45/** 45/**
46 * Get a list of all interfaces in the interface file. Usefull for 46 * Get a list of all interfaces in the interface file. Usefull for
47 * hardware that is not currently connected such as an 802.11b card 47 * hardware that is not currently connected such as an 802.11b card
48 * not plugged in, but configured for when it is plugged in. 48 * not plugged in, but configured for when it is plugged in.
49 * @return Return string list of interfaces. 49 * @return Return string list of interfaces.
50 **/ 50 **/
51QStringList Interfaces::getInterfaceList(){ 51QStringList Interfaces::getInterfaceList(){
52 QStringList list; 52 QStringList list;
53 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 53 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
54 QString line = (*it).simplifyWhiteSpace(); 54 QString line = (*it).simplifyWhiteSpace();
55 if(line.contains(IFACE) && line.at(0) != '#'){ 55 if(line.contains(IFACE) && line.at(0) != '#'){
56 line = line.mid(QString(IFACE).length() +1, line.length()); 56 line = line.mid(QString(IFACE).length() +1, line.length());
57 line = line.simplifyWhiteSpace(); 57 line = line.simplifyWhiteSpace();
58 int findSpace = line.find(" "); 58 int findSpace = line.find(" ");
59 if( findSpace >= 0){ 59 if( findSpace >= 0){
60 line = line.mid(0, findSpace); 60 line = line.mid(0, findSpace);
61 list.append(line); 61 list.append(line);
62 } 62 }
63 } 63 }
64 } 64 }
65 return list; 65 return list;
66} 66}
67 67
68/** 68/**
69 * Find out if interface is in an "auto" group or not. 69 * Find out if interface is in an "auto" group or not.
70 * Report any duplicates such as eth0 being in two differnt auto's 70 * Report any duplicates such as eth0 being in two differnt auto's
71 * @param interface interface to check to see if it is on or not. 71 * @param interface interface to check to see if it is on or not.
72 * @return true is interface is in auto 72 * @return true is interface is in auto
73 */ 73 */
74bool Interfaces::isAuto(const QString &interface) const { 74bool Interfaces::isAuto(const QString &interface) const {
75 QStringList autoLines = interfaces.grep(QRegExp(AUTO)); 75 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
76 QStringList awi = autoLines.grep(QRegExp(interface)); 76 QStringList awi = autoLines.grep(QRegExp(interface));
77 if(awi.count() > 1) 77 if(awi.count() > 1)
78 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); 78 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1());
79 return awi.count() > 0; 79 return awi.count() > 0;
80} 80}
81 81
82/** 82/**
83 * Attempt to set the auto option for interface to setAuto. 83 * Attempt to set the auto option for interface to setAuto.
84 * @param interface the interface to set 84 * @param interface the interface to set
85 * @param setAuto the value to set interface to. 85 * @param setAuto the value to set interface to.
86 * @return false if already set to setAuto. 86 * @return false if already set to setAuto.
87 * */ 87 * */
88bool Interfaces::setAuto(const QString &interface, bool setAuto){ 88bool Interfaces::setAuto(const QString &interface, bool setAuto){
89 // Don't need to set it if it is already set. 89 // Don't need to set it if it is already set.
90 if(isAuto(interface) == setAuto) 90 if(isAuto(interface) == setAuto)
91 return false; 91 return false;
92 92
93 bool changed = false; 93 bool changed = false;
94 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 94 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
95 if((*it).contains(AUTO)){ 95 if((*it).contains(AUTO)){
96 //We know that they are not in any group so let add to this auto. 96 //We know that they are not in any group so let add to this auto.
97 if(setAuto){ 97 if(setAuto){
98 (*it) = (*it) += " " + interface; 98 (*it) = (*it) += " " + interface;
99 // Don't care to have such thins as: auto eth0 lo usb0 99 // Don't care to have such thins as: auto eth0 lo usb0
100 (*it) = (*it).simplifyWhiteSpace(); 100 (*it) = (*it).simplifyWhiteSpace();
101 changed = true; 101 changed = true;
102 break; 102 break;
103 } 103 }
104 // else see if we need to remove from this one 104 // else see if we need to remove from this one
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 // if AUTO is the only thing left clear the line 108 // if AUTO is the only thing left clear the line
109 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) 109 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
110 (*it) = ""; 110 (*it) = "";
111 changed = true; 111 changed = true;
112 // Don't break because we want to make sure we remove all cases. 112 // Don't break because we want to make sure we remove all cases.
113 } 113 }
114 } 114 }
115 } 115 }
116 } 116 }
117 // In the case where there is no AUTO field add one. 117 // In the case where there is no AUTO field add one.
118 if(!changed && setAuto) 118 if(!changed && setAuto)
119 interfaces.append(QString(AUTO" %1").arg(interface)); 119 interfaces.append(QString(AUTO" %1").arg(interface));
120 return true; 120 return true;
121} 121}
122 122
123/** 123/**
124 * Set the current interface to interface. This needs to be done before you 124 * Set the current interface to interface. This needs to be done before you
125 * can call getFamily(), getMethod, and get/setOption(). 125 * can call getFamily(), getMethod, and get/setOption().
126 * @param interface the name of the interface to set. All whitespace is 126 * @param interface the name of the interface to set. All whitespace is
127 * removed from the interface name. 127 * removed from the interface name.
128 * @return bool true if it is successfull. 128 * @return bool true if it is successfull.
129 */ 129 */
130bool Interfaces::setInterface(QString interface){ 130bool Interfaces::setInterface(QString interface){
131 interface = interface.simplifyWhiteSpace(); 131 interface = interface.simplifyWhiteSpace();
132 interface = interface.replace(QRegExp(" "), ""); 132 interface = interface.replace(QRegExp(" "), "");
133 return setStanza(IFACE, interface, currentIface); 133 return setStanza(IFACE, interface, currentIface);
134} 134}
135 135
136/** 136/**
137 * A quick helper funtion to see if the current interface is set. 137 * A quick helper funtion to see if the current interface is set.
138 * @return bool true if set, false otherwise. 138 * @return bool true if set, false otherwise.
139 */ 139 */
140bool Interfaces::isInterfaceSet() const { 140bool Interfaces::isInterfaceSet() const {
141 return (interfaces.end() != currentIface); 141 return (interfaces.end() != currentIface);
142} 142}
143 143
144/** 144/**
145 * Add a new interface of with the settings - family and method 145 * Add a new interface of with the settings - family and method
146 * @param interface the name of the interface to set. All whitespace is 146 * @param interface the name of the interface to set. All whitespace is
147 * removed from the interface name. 147 * removed from the interface name.
148 * @param family the family of this interface inet or inet, ipx or inet6 148 * @param family the family of this interface inet or inet, ipx or inet6
149 * Must of one of the families defined in interfaces.h 149 * Must of one of the families defined in interfaces.h
150 * @param method for the family. see interfaces man page for family methods. 150 * @param method for the family. see interfaces man page for family methods.
151 * @return true if successfull. 151 * @return true if successfull.
152 */ 152 */
153bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ 153bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
154 if(0 == acceptedFamily.contains(family)) 154 if(0 == acceptedFamily.contains(family))
155 return false; 155 return false;
156 QString newInterface = interface.simplifyWhiteSpace(); 156 QString newInterface = interface.simplifyWhiteSpace();
157 newInterface = newInterface.replace(QRegExp(" "), ""); 157 newInterface = newInterface.replace(QRegExp(" "), "");
158 interfaces.append(""); 158 interfaces.append("");
159 interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); 159 interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method));
160 return true; 160 return true;
161} 161}
162 162
163/** 163/**
164 * Copies interface with name interface to name newInterface 164 * Copies interface with name interface to name newInterface
165 * @param newInterface name of the new interface. 165 * @param newInterface name of the new interface.
166 * @return bool true if successfull 166 * @return bool true if successfull
167 */ 167 */
168bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ 168bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
169 if(!setInterface(interface)) 169 if(!setInterface(interface))
170 return false; 170 return false;
171 171
172 // Store the old interface and bump past the stanza line. 172 // Store the old interface and bump past the stanza line.
173 QStringList::Iterator it = currentIface; 173 QStringList::Iterator it = currentIface;
174 it++; 174 it++;
175 175
176 // Add the new interface 176 // Add the new interface
177 bool error; 177 bool error;
178 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); 178 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
179 if(!setInterface(newInterface)) 179 if(!setInterface(newInterface))
180 return false; 180 return false;
181 181
182 QStringList::Iterator newIface = currentIface; 182 QStringList::Iterator newIface = currentIface;
183 newIface++; 183 newIface++;
184 184
185 // Copy all of the lines 185 // Copy all of the lines
186 for ( ; 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 return removeStanza(currentIface); 200 return removeStanza(currentIface);
201} 201}
202 202
203/** 203/**
204 * Gets the hardware name of the interface that is currently selected. 204 * Gets the hardware name of the interface that is currently selected.
205 * @return QString name of the hardware interface (eth0, usb2, wlan1...). 205 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
206 * @param error set to true if any error occurs, false otherwise. 206 * @param error set to true if any error occurs, false otherwise.
207 */ 207 */
208QString Interfaces::getInterfaceName(bool &error){ 208QString Interfaces::getInterfaceName(bool &error){
209 if(currentIface == interfaces.end()){ 209 if(currentIface == interfaces.end()){
210 error = true; 210 error = true;
211 return QString(); 211 return QString();
212 } 212 }
213 QString line = (*currentIface); 213 QString line = (*currentIface);
214 line = line.mid(QString(IFACE).length() +1, line.length()); 214 line = line.mid(QString(IFACE).length() +1, line.length());
215 line = line.simplifyWhiteSpace(); 215 line = line.simplifyWhiteSpace();
216 int findSpace = line.find(" "); 216 int findSpace = line.find(" ");
217 if( findSpace < 0){ 217 if( findSpace < 0){
218 error = true; 218 error = true;
219 return QString(); 219 return QString();
220 } 220 }
221 error = false; 221 error = false;
222 return line.mid(0, findSpace); 222 return line.mid(0, findSpace);
223} 223}
224 224
225/** 225/**
226 * Gets the family name of the interface that is currently selected. 226 * Gets the family name of the interface that is currently selected.
227 * @return QString name of the family (inet, inet6, ipx). 227 * @return QString name of the family (inet, inet6, ipx).
228 * @param error set to true if any error occurs, false otherwise. 228 * @param error set to true if any error occurs, false otherwise.
229 */ 229 */
230QString Interfaces::getInterfaceFamily(bool &error){ 230QString Interfaces::getInterfaceFamily(bool &error){
231 QString name = getInterfaceName(error); 231 QString name = getInterfaceName(error);
232 if(error) 232 if(error)
233 return QString(); 233 return QString();
234 QString line = (*currentIface); 234 QString line = (*currentIface);
235 line = line.mid(QString(IFACE).length() +1, line.length()); 235 line = line.mid(QString(IFACE).length() +1, line.length());
236 line = line.mid(name.length()+1, line.length()); 236 line = line.mid(name.length()+1, line.length());
237 line = line.simplifyWhiteSpace(); 237 line = line.simplifyWhiteSpace();
238 int findSpace = line.find(" "); 238 int findSpace = line.find(" ");
239 if( findSpace < 0){ 239 if( findSpace < 0){
240 error = true; 240 error = true;
241 return QString(); 241 return QString();
242 } 242 }
243 error = false; 243 error = false;
244 return line.mid(0, findSpace); 244 return line.mid(0, findSpace);
245} 245}
246 246
247/** 247/**
248 * Gets the method of the interface that is currently selected. 248 * Gets the method of the interface that is currently selected.
249 * @return QString name of the method such as staic or dhcp. 249 * @return QString name of the method such as staic or dhcp.
250 * See the man page of interfaces for possible methods depending on the family. 250 * See the man page of interfaces for possible methods depending on the family.
251 * @param error set to true if any error occurs, false otherwise. 251 * @param error set to true if any error occurs, false otherwise.
252 */ 252 */
253QString Interfaces::getInterfaceMethod(bool &error){ 253QString Interfaces::getInterfaceMethod(bool &error){
254 QString name = getInterfaceName(error); 254 QString name = getInterfaceName(error);
255 if(error) 255 if(error)
256 return QString(); 256 return QString();
257 QString family = getInterfaceFamily(error); 257 QString family = getInterfaceFamily(error);
258 if(error) 258 if(error)
259 return QString(); 259 return QString();
260 QString line = (*currentIface); 260 QString line = (*currentIface);
261 line = line.mid(QString(IFACE).length()+1, line.length()); 261 line = line.mid(QString(IFACE).length()+1, line.length());
262 line = line.mid(name.length()+1, line.length()); 262 line = line.mid(name.length()+1, line.length());
263 line = line.mid(family.length()+1, line.length()); 263 line = line.mid(family.length()+1, line.length());
264 line = line.simplifyWhiteSpace(); 264 line = line.simplifyWhiteSpace();
265 error = false; 265 error = false;
266 return line; 266 return line;
267} 267}
268 268
269/** 269/**
270 * Sets the interface name to newName. 270 * Sets the interface name to newName.
271 * @param newName the new name of the interface. All whitespace is removed. 271 * @param newName the new name of the interface. All whitespace is removed.
272 * @return bool true if successfull. 272 * @return bool true if successfull.
273 */ 273 */
274bool Interfaces::setInterfaceName(const QString &newName){ 274bool Interfaces::setInterfaceName(const QString &newName){
275 if(currentIface == interfaces.end()) 275 if(currentIface == interfaces.end())
276 return false; 276 return false;
277 QString name = newName.simplifyWhiteSpace(); 277 QString name = newName.simplifyWhiteSpace();
278 name = name.replace(QRegExp(" "), ""); 278 name = name.replace(QRegExp(" "), "");
279 bool returnValue = false; 279 bool returnValue = false;
280 (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); 280 (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
281 return !returnValue; 281 return !returnValue;
282} 282}
283 283
284/** 284/**
285 * Sets the interface family to newName. 285 * Sets the interface family to newName.
286 * @param newName the new name of the interface. Must be one of the families 286 * @param newName the new name of the interface. Must be one of the families
287 * defined in the interfaces.h file. 287 * defined in the interfaces.h file.
288 * @return bool true if successfull. 288 * @return bool true if successfull.
289 */ 289 */
290bool Interfaces::setInterfaceFamily(const QString &newName){ 290bool Interfaces::setInterfaceFamily(const QString &newName){
291 if(currentIface == interfaces.end()) 291 if(currentIface == interfaces.end())
292 return false; 292 return false;
293 if(acceptedFamily.contains(newName)==0) 293 if(acceptedFamily.contains(newName)==0)
294 return false; 294 return false;
295 bool returnValue = false; 295 bool returnValue = false;
296 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); 296 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue));
297 return !returnValue; 297 return !returnValue;
298} 298}
299 299
300/** 300/**
301 * Sets the interface method to newName 301 * Sets the interface method to newName
302 * @param newName the new name of the interface 302 * @param newName the new name of the interface
303 * @return bool true if successfull. 303 * @return bool true if successfull.
304 */ 304 */
305bool Interfaces::setInterfaceMethod(const QString &newName){ 305bool Interfaces::setInterfaceMethod(const QString &newName){
306 if(currentIface == interfaces.end()) 306 if(currentIface == interfaces.end())
307 return false; 307 return false;
308 bool returnValue = false; 308 bool returnValue = false;
309 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); 309 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName);
310 return !returnValue; 310 return !returnValue;
311} 311}
312 312
313/** 313/**
314 * Get a value for an option in the currently selected interface. For example 314 * Get a value for an option in the currently selected interface. For example
315 * calling getInterfaceOption("address") on the following stanza would 315 * calling getInterfaceOption("address") on the following stanza would
316 * return 192.168.1.1. 316 * return 192.168.1.1.
317 * iface eth0 static 317 * iface eth0 static
318 * address 192.168.1.1 318 * address 192.168.1.1
319 * @param option the options to get the value. 319 * @param option the options to get the value.
320 * @param error set to true if any error occurs, false otherwise. 320 * @param error set to true if any error occurs, false otherwise.
321 * @return QString the options value. QString::null if error == true 321 * @return QString the options value. QString::null if error == true
322 */ 322 */
323QString Interfaces::getInterfaceOption(const QString &option, bool &error){ 323QString Interfaces::getInterfaceOption(const QString &option, bool &error){
324 return getOption(currentIface, option, error); 324 return getOption(currentIface, option, error);
325} 325}
326 326
327/** 327/**
328 * Set a value for an option in the currently selected interface. If option 328 * Set a value for an option in the currently selected interface. If option
329 * doesn't exist then it is added along with the value. 329 * doesn't exist then it is added along with the value.
330 * @param option the options to set the value. 330 * @param option the options to set the value.
331 * @param value the value that option should be set to. 331 * @param value the value that option should be set to.
332 * @param error set to true if any error occurs, false otherwise. 332 * @param error set to true if any error occurs, false otherwise.
333 * @return QString the options value. QString::null if error == true 333 * @return QString the options value. QString::null if error == true
334 */ 334 */
335bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ 335bool Interfaces::setInterfaceOption(const QString &option, const QString &value){
336 return setOption(currentIface, option, value); 336 return setOption(currentIface, option, value);
337} 337}
338 338
339/** 339/**
340 * Removes a value for an option in the currently selected interface. 340 * Removes a value for an option in the currently selected interface.
341 * @param option the options to set the value. 341 * @param option the options to set the value.
342 * @param error set to true if any error occurs, false otherwise. 342 * @param error set to true if any error occurs, false otherwise.
343 * @return QString the options value. QString::null if error == true 343 * @return QString the options value. QString::null if error == true
344 */ 344 */
345bool Interfaces::removeInterfaceOption(const QString &option){ 345bool Interfaces::removeInterfaceOption(const QString &option){
346 return removeOption(currentIface, option); 346 return removeOption(currentIface, option);
347} 347}
348 348
349/** 349/**
350 * Removes a value for an option in the currently selected interface. 350 * Removes a value for an option in the currently selected interface.
351 * @param option the options to set the value. 351 * @param option the options to set the value.
352 * @param value the value that option should be set to. 352 * @param value the value that option should be set to.
353 * @param error set to true if any error occurs, false otherwise. 353 * @param error set to true if any error occurs, false otherwise.
354 * @return QString the options value. QString::null if error == true 354 * @return QString the options value. QString::null if error == true
355 */ 355 */
356bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ 356bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){
357 return removeOption(currentIface, option, value); 357 return removeOption(currentIface, option, value);
358} 358}
359 359
360/** 360/**
361 * Removes all of the options from the currently selected interface. 361 * Removes all of the options from the currently selected interface.
362 * @return bool error if if successfull 362 * @return bool error if if successfull
363 */ 363 */
364bool Interfaces::removeAllInterfaceOptions(){ 364bool Interfaces::removeAllInterfaceOptions(){
365 return removeAllOptions(currentIface); 365 return removeAllOptions(currentIface);
366} 366}
367 367
368/** 368/**
369 * Set the current map to interface's map. This needs to be done before you 369 * Set the current map to interface's map. This needs to be done before you
370 * can call addMapping(), set/getMap(), and get/setScript(). 370 * can call addMapping(), set/getMap(), and get/setScript().
371 * @param interface the name of the interface to set. All whitespace is 371 * @param interface the name of the interface to set. All whitespace is
372 * removed from the interface name. 372 * removed from the interface name.
373 * @return bool true if it is successfull. 373 * @return bool true if it is successfull.
374 */ 374 */
375bool Interfaces::setMapping(const QString &interface){ 375bool Interfaces::setMapping(const QString &interface){
376 QString interfaceName = interface.simplifyWhiteSpace(); 376 QString interfaceName = interface.simplifyWhiteSpace();
377 interfaceName = interfaceName.replace(QRegExp(" "), ""); 377 interfaceName = interfaceName.replace(QRegExp(" "), "");
378 return setStanza(MAPPING, interfaceName, currentMapping); 378 return setStanza(MAPPING, interfaceName, currentMapping);
379} 379}
380 380
381/** 381/**
382 * Adds a new Mapping to the interfaces file with interfaces. 382 * Adds a new Mapping to the interfaces file with interfaces.
383 * @param interface the name(s) of the interfaces to set to this mapping 383 * @param interface the name(s) of the interfaces to set to this mapping
384 */ 384 */
385void Interfaces::addMapping(const QString &option){ 385void Interfaces::addMapping(const QString &option){
386 interfaces.append(""); 386 interfaces.append("");
387 interfaces.append(QString(MAPPING " %1").arg(option)); 387 interfaces.append(QString(MAPPING " %1").arg(option));
388} 388}
389 389
390/** 390/**
391 * Remove the currently selected map and all of its options. 391 * Remove the currently selected map and all of its options.
392 * @return bool if successfull or not. 392 * @return bool if successfull or not.
393 */ 393 */
394bool Interfaces::removeMapping(){ 394bool Interfaces::removeMapping(){
395 return removeStanza(currentMapping); 395 return removeStanza(currentMapping);
396} 396}
397 397
398/** 398/**
399 * Set a map option within a mapping. 399 * Set a map option within a mapping.
400 * @param map map to use 400 * @param map map to use
401 * @param value value to go with map 401 * @param value value to go with map
402 * @return bool true if it is successfull. 402 * @return bool true if it is successfull.
403 */ 403 */
404bool Interfaces::setMap(const QString &map, const QString &value){ 404bool Interfaces::setMap(const QString &map, const QString &value){
405 return setOption(currentMapping, map, value); 405 return setOption(currentMapping, map, value);
406} 406}
407 407
408/** 408/**
409 * Removes a map option within a mapping. 409 * Removes a map option within a mapping.
410 * @param map map to use 410 * @param map map to use
411 * @param value value to go with map 411 * @param value value to go with map
412 * @return bool true if it is successfull. 412 * @return bool true if it is successfull.
413 */ 413 */
414bool Interfaces::removeMap(const QString &map, const QString &value){ 414bool Interfaces::removeMap(const QString &map, const QString &value){
415 return removeOption(currentMapping, map, value); 415 return removeOption(currentMapping, map, value);
416} 416}
417 417
418/** 418/**
419 * Get a map value within a mapping. 419 * Get a map value within a mapping.
420 * @param map map to get value of 420 * @param map map to get value of
421 * @param bool true if it is successfull. 421 * @param bool true if it is successfull.
422 * @return value that goes to the map 422 * @return value that goes to the map
423 */ 423 */
424QString Interfaces::getMap(const QString &map, bool &error){ 424QString Interfaces::getMap(const QString &map, bool &error){
425 return getOption(currentMapping, map, error); 425 return getOption(currentMapping, map, error);
426} 426}
427 427
428/** 428/**
429 * Sets a script value of the current mapping to argument. 429 * Sets a script value of the current mapping to argument.
430 * @param argument the script name. 430 * @param argument the script name.
431 * @return true if successfull. 431 * @return true if successfull.
432 */ 432 */
433bool Interfaces::setScript(const QString &argument){ 433bool Interfaces::setScript(const QString &argument){
434 return setOption(currentMapping, "script", argument); 434 return setOption(currentMapping, "script", argument);
435} 435}
436 436
437/** 437/**
438 * @param error true if could not retrieve the current script argument. 438 * @param error true if could not retrieve the current script argument.
439 * @return QString the argument of the script for the current mapping. 439 * @return QString the argument of the script for the current mapping.
440 */ 440 */
441QString Interfaces::getScript(bool &error){ 441QString Interfaces::getScript(bool &error){
442 return getOption(currentMapping, "script", error); 442 return getOption(currentMapping, "script", error);
443} 443}
444 444
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(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ 455bool Interfaces::setStanza(const QString &stanza, const 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(const QStringList::Iterator &start, const QString &option, const QString &value){ 492bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const 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/** 522/**
523 * Removes a stanza and all of its options 523 * Removes a stanza and all of its options
524 * @param stanza the stanza to remove 524 * @param stanza the stanza to remove
525 * @return bool true if successfull. 525 * @return bool true if successfull.
526 */ 526 */
527bool Interfaces::removeStanza(QStringList::Iterator &stanza){ 527bool Interfaces::removeStanza(QStringList::Iterator &stanza){
528 if(stanza == interfaces.end()) 528 if(stanza == interfaces.end())
529 return false; 529 return false;
530 (*stanza) = ""; 530 (*stanza) = "";
531 return removeAllOptions(stanza); 531 return removeAllOptions(stanza);
532} 532}
533 533
534/** 534/**
535 * Removes a option in a stanza 535 * Removes a option in a stanza
536 * @param start the start of the stanza 536 * @param start the start of the stanza
537 * @param option the option to remove 537 * @param option the option to remove
538 * @return bool true if successfull, false otherwise. 538 * @return bool true if successfull, false otherwise.
539 */ 539 */
540bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){ 540bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){
541 if(start == interfaces.end()) 541 if(start == interfaces.end())
542 return false; 542 return false;
543 543
544 bool found = false; 544 bool found = false;
545 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 545 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
546 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 546 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
547 // got to the end without finding it 547 // got to the end without finding it
548 break; 548 break;
549 } 549 }
550 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 550 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
551 // Found it in stanza so replace it. 551 // Found it in stanza so replace it.
552 if(found) 552 if(found)
553 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 553 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
554 found = true; 554 found = true;
555 (*it) = ""; 555 (*it) = "";
556 } 556 }
557 } 557 }
558 return found; 558 return found;
559} 559}
560 560
561/** 561/**
562 * Removes a option in a stanza 562 * Removes a option in a stanza
563 * @param start the start of the stanza 563 * @param start the start of the stanza
564 * @param option the option to use when setting value. 564 * @param option the option to use when setting value.
565 * @return bool true if successfull, false otherwise. 565 * @return bool true if successfull, false otherwise.
566 */ 566 */
567bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ 567bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){
568 if(start == interfaces.end()) 568 if(start == interfaces.end())
569 return false; 569 return false;
570 570
571 bool found = false; 571 bool found = false;
572 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 572 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
573 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 573 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
574 // got to the end without finding it 574 // got to the end without finding it
575 break; 575 break;
576 } 576 }
577 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ 577 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
578 // Found it in stanza so replace it. 578 // Found it in stanza so replace it.
579 if(found) 579 if(found)
580 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 580 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
581 found = true; 581 found = true;
582 (*it) = ""; 582 (*it) = "";
583 } 583 }
584 } 584 }
585 return found; 585 return found;
586} 586}
587 587
588/** 588/**
589 * Removes all options in a stanza 589 * Removes all options in a stanza
590 * @param start the start of the stanza 590 * @param start the start of the stanza
591 * @return bool true if successfull, false otherwise. 591 * @return bool true if successfull, false otherwise.
592 */ 592 */
593bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ 593bool Interfaces::removeAllOptions(const QStringList::Iterator &start){
594 if(start == interfaces.end()) 594 if(start == interfaces.end())
595 return false; 595 return false;
596 596
597 QStringList::Iterator it = start; 597 QStringList::Iterator it = start;
598 it = ++it; 598 it = ++it;
599 for (; it != interfaces.end(); ++it ) { 599 for (; it != interfaces.end(); ++it ) {
600 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 600 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
601 break; 601 break;
602 } 602 }
603 it = interfaces.remove(it); 603 it = interfaces.remove(it);
604 it = --it; 604 it = --it;
605 } 605 }
606 // Leave a space between this interface and the next. 606 // Leave a space between this interface and the next.
607 interfaces.insert(it, QString("")); 607 interfaces.insert(it, QString(""));
608 return true; 608 return true;
609} 609}
610 610
611/** 611/**
612 * Gets a value of an option in a stanza 612 * Gets a value of an option in a stanza
613 * @param start the start of the stanza 613 * @param start the start of the stanza
614 * @param option the option to use when getting the value. 614 * @param option the option to use when getting the value.
615 * @param bool true if errors false otherwise. 615 * @param bool true if errors false otherwise.
616 * @return QString the value of option QString::null() if error == true. 616 * @return QString the value of option QString::null() if error == true.
617 */ 617 */
618QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ 618QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){
619 if(start == interfaces.end()){ 619 if(start == interfaces.end()){
620 error = false; 620 error = false;
621 return QString(); 621 return QString();
622 } 622 }
623 623
624 QString value; 624 QString value;
625 bool found = false; 625 bool found = false;
626 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 626 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
627 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 627 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
628 break; 628 break;
629 } 629 }
630 if((*it).contains(option) && (*it).at(0) != '#'){ 630 if((*it).contains(option) && (*it).at(0) != '#'){
631 if(found) 631 if(found)
632 qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 632 qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
633 found = true; 633 found = true;
634 QString line = (*it).simplifyWhiteSpace(); 634 QString line = (*it).simplifyWhiteSpace();
635 int space = line.find(" ", option.length()); 635 int space = line.find(" ", option.length());
636 if(space != -1){ 636 if(space != -1){
637 value = line.mid(space+1, line.length()); 637 value = line.mid(space+1, line.length());
638 break; 638 break;
639 } 639 }
640 } 640 }
641 } 641 }
642 error = !found; 642 error = !found;
643 return value; 643 return value;
644} 644}
645 645
646/** 646/**
647 * Write out the interfaces file to the file passed into the constructor. 647 * Write out the interfaces file to the file passed into the constructor.
648 * Removes any excess blank lines over 1 line long. 648 * Removes any excess blank lines over 1 line long.
649 * @return bool true if successfull, false if not. 649 * @return bool true if successfull, false if not.
650 */ 650 */
651bool Interfaces::write(){ 651bool Interfaces::write(){
652 QFile::remove(interfacesFile); 652 QFile::remove(interfacesFile);
653 QFile file(interfacesFile); 653 QFile file(interfacesFile);
654 654
655 if (!file.open(IO_ReadWrite)){ 655 if (!file.open(IO_ReadWrite)){
656 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); 656 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
657 return false; 657 return false;
658 } 658 }
659 QTextStream stream( &file ); 659 QTextStream stream( &file );
660 int whiteSpaceCount = 0; 660 int whiteSpaceCount = 0;
661 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 661 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
662 QString line = (*it).simplifyWhiteSpace(); 662 QString line = (*it).simplifyWhiteSpace();
663 line = line.replace(QRegExp(" "),""); 663 line = line.replace(QRegExp(" "),"");
664 if(line.length() == 0) 664 if(line.length() == 0)
665 whiteSpaceCount++; 665 whiteSpaceCount++;
666 else 666 else
667 whiteSpaceCount = 0; 667 whiteSpaceCount = 0;
668 if(whiteSpaceCount < 2){ 668 if(whiteSpaceCount < 2){
669 qDebug((*it).latin1()); 669 qDebug((*it).latin1());
670 stream << (*it) << '\n'; 670 stream << (*it) << '\n';
671 } 671 }
672 } 672 }
673 file.close(); 673 file.close();
674 return true; 674 return true;
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index f19cbdd..b40d101 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -166,35 +166,37 @@ void InterfaceSetupImp::setProfile(const QString &profile){
166 } 166 }
167 } 167 }
168 } 168 }
169 169
170 // We must have a valid interface to get this far so read some settings. 170 // We must have a valid interface to get this far so read some settings.
171 171
172 // DHCP 172 // DHCP
173 bool error = false; 173 bool error = false;
174 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 174 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
175 dhcpCheckBox->setChecked(true); 175 dhcpCheckBox->setChecked(true);
176 else 176 else
177 dhcpCheckBox->setChecked(false); 177 dhcpCheckBox->setChecked(false);
178 178
179 // IP Information 179 // IP Information
180 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 180 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
181 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); 181 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error);
182 qDebug("dns >%s<",dns.latin1()); 182 qDebug("dns >%s<",dns.latin1());
183 if(dns.contains(" ")){ 183 if(dns.contains(" ")){
184 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 184 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
185 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 185 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
186 }else firstDNSLineEdit->setText(dns); 186 }else firstDNSLineEdit->setText(dns);
187 187
188 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 188 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
189 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 189 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
190 if (subnetMaskEdit->text().isEmpty())
191 subnetMaskEdit->setText( "255.255.255.0" );
190 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 192 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
191 193
192 194
193 195
194 qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1()); 196 qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1());
195 qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1()); 197 qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1());
196 198
197} 199}
198 200
199// interfacesetup.cpp 201// interfacesetup.cpp
200 202
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp
index 7bded85..a4488f9 100644
--- a/noncore/settings/networksettings/wlan/wlanmodule.cpp
+++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp
@@ -111,112 +111,142 @@ Interface *WLANModule::addNewInterface(const QString &){
111/** 111/**
112 * Attempts to remove the interface, doesn't delete i 112 * Attempts to remove the interface, doesn't delete i
113 * @return bool true if successfull, false otherwise. 113 * @return bool true if successfull, false otherwise.
114 */ 114 */
115bool WLANModule::remove(Interface*){ 115bool WLANModule::remove(Interface*){
116 // Can't remove a hardware device, you can stop it though. 116 // Can't remove a hardware device, you can stop it though.
117 return false; 117 return false;
118} 118}
119 119
120void WLANModule::receive(const QCString &param, const QByteArray &arg) 120void WLANModule::receive(const QCString &param, const QByteArray &arg)
121{ 121{
122 qDebug("WLANModule::receive "+param); 122 qDebug("WLANModule::receive "+param);
123 QStringList params = QStringList::split(",",param); 123 QStringList params = QStringList::split(",",param);
124 int count = params.count(); 124 int count = params.count();
125 qDebug("WLANModule got %i params", count ); 125 qDebug("WLANModule got %i params", count );
126 if (count < 2){ 126 if (count < 2){
127 qDebug("Erorr less than 2 parameter"); 127 qDebug("Erorr less than 2 parameter");
128 qDebug("RETURNING"); 128 qDebug("RETURNING");
129 return; 129 return;
130 } 130 }
131 131
132 QDataStream stream(arg,IO_ReadOnly); 132 QDataStream stream(arg,IO_ReadOnly);
133 QString interface; 133 QString interface;
134 QString action; 134 QString action;
135 int countMsgs = 0;
136 stream >> interface;
137 qDebug("got count? >%s<",interface.latin1());
138 if (interface == "count"){
139 qDebug("got count");
140 stream >> action;
141 qDebug("Got count num >%s<", action.latin1());
142 countMsgs = action.toInt();
143 }
144
135 QDialog *toShow; 145 QDialog *toShow;
136 while (! stream.atEnd() ){ 146 //while (! stream.atEnd() ){
147 for (int i = 0; i < countMsgs; i++){
148 qDebug("start stream %d/%d",i,countMsgs);
149 if (stream.atEnd()){
150 qDebug("end of stream");
151 return;
152 }
137 stream >> interface; 153 stream >> interface;
154 qDebug("got iface");
138 stream >> action; 155 stream >> action;
139 qDebug("WLANModule got interface %s and acion %s", interface.latin1(), action.latin1()); 156 qDebug("WLANModule got interface %s and acion %s", interface.latin1(), action.latin1());
140 // find interfaces 157 // find interfaces
141 Interface *ifa=0; 158 Interface *ifa=0;
142 for ( Interface *i=list.first(); i != 0; i=list.next() ){ 159 for ( Interface *i=list.first(); i != 0; i=list.next() ){
143 if (i->getInterfaceName() == interface){ 160 if (i->getInterfaceName() == interface){
144 qDebug("WLANModule found interface %s",interface.latin1()); 161 qDebug("WLANModule found interface %s",interface.latin1());
145 ifa = i; 162 ifa = i;
146 } 163 }
147 } 164 }
148 165
149 if (ifa == 0){ 166 if (ifa == 0){
150 qDebug("WLANModule Did not find %s",interface.latin1()); 167 qDebug("WLANModule Did not find %s",interface.latin1());
151 qDebug("skipping"); 168 qDebug("skipping");
152 count = 0; 169 count = 0;
153 } 170 }
154 171
155 if (count == 2){ 172 if (count == 2){
156 // those should call the interface directly 173 // those should call the interface directly
157 QWidget *info = getInfo( ifa ); 174 QWidget *info = getInfo( ifa );
158 info->showMaximized(); 175 info->showMaximized();
159 176
160 if ( action.contains("start" ) ){ 177 if ( action.contains("start" ) ){
161 ifa->start(); 178 ifa->start();
162 } else if ( action.contains("restart" ) ){ 179 } else if ( action.contains("restart" ) ){
163 ifa->restart(); 180 ifa->restart();
164 } else if ( action.contains("stop" ) ){ 181 } else if ( action.contains("stop" ) ){
165 ifa->stop(); 182 ifa->stop();
166 }else if ( action.contains("refresh" ) ){ 183 }else if ( action.contains("refresh" ) ){
167 ifa->refresh(); 184 ifa->refresh();
168 } 185 }
169 }else if (count == 3){ 186 }else if (count == 3){
170 QString value; 187 QString value;
171 if (!wlanconfigWiget){ 188 if (!wlanconfigWiget){
172 //FIXME: what if it got closed meanwhile? 189 //FIXME: what if it got closed meanwhile?
173 wlanconfigWiget = (WLANImp*) configure(ifa); 190 wlanconfigWiget = (WLANImp*) configure(ifa);
174 toShow = (QDialog*) wlanconfigWiget; 191 toShow = (QDialog*) wlanconfigWiget;
175 } 192 }
176 wlanconfigWiget->showMaximized(); 193 wlanconfigWiget->showMaximized();
177 stream >> value; 194 stream >> value;
178 qDebug("WLANModule is setting %s of %s to %s", action.latin1(), interface.latin1(), value.latin1() ); 195 qDebug("WLANModule (build 4) is setting %s of %s to %s", action.latin1(), interface.latin1(), value.latin1() );
196 if (value.isEmpty()){
197 qDebug("value is empty!!!\nreturning");
198 return;
199 }
179 if ( action.contains("ESSID") ){ 200 if ( action.contains("ESSID") ){
180 QComboBox *combo = wlanconfigWiget->essid; 201 QComboBox *combo = wlanconfigWiget->essid;
181 bool found = false; 202 bool found = false;
182 for ( int i = 0; i < combo->count(); i++) 203 for ( int i = 0; i < combo->count(); i++)
183 if ( combo->text( i ) == value ){ 204 if ( combo->text( i ) == value ){
184 combo->setCurrentItem( i ); 205 combo->setCurrentItem( i );
185 found = true; 206 found = true;
186 } 207 }
187 if (!found) combo->insertItem( value, 0 ); 208 if (!found) combo->insertItem( value, 0 );
188 }else if ( action.contains("Mode") ){ 209 }else if ( action.contains("Mode") ){
189 QComboBox *combo = wlanconfigWiget->mode; 210 QComboBox *combo = wlanconfigWiget->mode;
190 for ( int i = 0; i < combo->count(); i++) 211 for ( int i = 0; i < combo->count(); i++)
191 if ( combo->text( i ) == value ){ 212 if ( combo->text( i ) == value ){
192 combo->setCurrentItem( i ); 213 combo->setCurrentItem( i );
193 } 214 }
194 215
195 }else if (action.contains("Channel")){ 216 }else if (action.contains("Channel")){
196 bool ok; 217 bool ok;
218 qDebug("converting channel");
197 int chan = value.toInt( &ok ); 219 int chan = value.toInt( &ok );
198 if (ok){ 220 if (ok){
221 qDebug("ok setting channel");
199 wlanconfigWiget->specifyChan->setChecked( true ); 222 wlanconfigWiget->specifyChan->setChecked( true );
200 wlanconfigWiget->networkChannel->setValue( chan ); 223 wlanconfigWiget->networkChannel->setValue( chan );
201 } 224 }
202 }else if (action.contains("MacAddr")){ 225 }else if (action.contains("MacAddr")){
203 wlanconfigWiget->specifyAp->setChecked( true ); 226 wlanconfigWiget->specifyAp->setChecked( true );
204 wlanconfigWiget->macEdit->setText( value ); 227 wlanconfigWiget->macEdit->setText( value );
205 }else 228 }else
206 qDebug("wlan plugin has no clue"); 229 qDebug("wlan plugin has no clue");
207 } 230 }
231 qDebug("next stream");
208 }// while stream 232 }// while stream
233 qDebug("end of stream");
209 if (toShow) toShow->exec(); 234 if (toShow) toShow->exec();
235 qDebug("returning");
210} 236}
211 237
212QWidget *WLANModule::getInfo( Interface *i) 238QWidget *WLANModule::getInfo( Interface *i)
213{ 239{
214 qDebug("WLANModule::getInfo start"); 240 qDebug("WLANModule::getInfo start");
215 WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); 241 WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose);
216 InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); 242 InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i);
217 info->tabWidget->insertTab(information, "TCP/IP", 0); 243 info->tabWidget->insertTab(information, "TCP/IP", 0);
218 244 info->tabWidget->setCurrentPage( 0 );
245 info->tabWidget->showPage( information );
246 if (info->tabWidget->currentPage() == information ) qDebug("infotab OK");
247 else qDebug("infotab NOT OK");
248 qDebug("current idx %d", info->tabWidget->currentPageIndex());
219 qDebug("WLANModule::getInfo return"); 249 qDebug("WLANModule::getInfo return");
220 return info; 250 return info;
221} 251}
222 252