summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-10-18 15:40:50 (UTC)
committer benmeyer <benmeyer>2002-10-18 15:40:50 (UTC)
commitc16dcab3fe45ae7193cbdfb2f62bf7e5482d449b (patch) (unidiff)
tree39e69706b24b032364ad4483d2f33688e7054390
parent0910b94b5b6618c84b3eb6c457c9137d63a7277f (diff)
downloadopie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.zip
opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.gz
opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.bz2
Profiles copy
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces.cpp50
-rw-r--r--noncore/net/networksetup/interfaces.h1
-rw-r--r--noncore/net/networksetup/interfacesetupimp.cpp21
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp24
-rw-r--r--noncore/settings/networksettings/interfaces.cpp50
-rw-r--r--noncore/settings/networksettings/interfaces.h1
-rw-r--r--noncore/settings/networksettings/interfacesetupimp.cpp21
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp24
8 files changed, 148 insertions, 44 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp
index eef42df..0927258 100644
--- a/noncore/net/networksetup/interfaces.cpp
+++ b/noncore/net/networksetup/interfaces.cpp
@@ -42,496 +42,536 @@ Interfaces::Interfaces(QString useInterfacesFile){
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)){ 54 if(line.contains(IFACE)){
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
171 * @param newInterface name of the new interface.
172 * @return bool true if successfull
173 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){
175 if(!setInterface(interface)) return false;
176
177 QStringList::Iterator it = currentIface;
178 it++;
179
180 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false;
183 QStringList::Iterator newIface = currentIface;
184 newIface++;
185
186 for ( it; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break;
189 newIface = interfaces.insert(newIface, *it);
190 }
191
192 return true;
193}
194
195/**
170 * Remove the currently selected interface and all of its options. 196 * Remove the currently selected interface and all of its options.
171 * @return bool if successfull or not. 197 * @return bool if successfull or not.
172 */ 198 */
173bool Interfaces::removeInterface(){ 199bool Interfaces::removeInterface(){
174 if(currentIface == interfaces.end()) 200 if(currentIface == interfaces.end())
175 return false; 201 return false;
176 (*currentIface) = ""; 202 (*currentIface) = "";
177 return removeAllInterfaceOptions(); 203 return removeAllInterfaceOptions();
178} 204}
179 205
180/** 206/**
181 * Gets the hardware name of the interface that is currently selected. 207 * Gets the hardware name of the interface that is currently selected.
182 * @return QString name of the hardware interface (eth0, usb2, wlan1...). 208 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
183 * @param error set to true if any error occurs, false otherwise. 209 * @param error set to true if any error occurs, false otherwise.
184 */ 210 */
185QString Interfaces::getInterfaceName(bool &error){ 211QString Interfaces::getInterfaceName(bool &error){
186 if(currentIface == interfaces.end()){ 212 if(currentIface == interfaces.end()){
187 error = true; 213 error = true;
188 return QString(); 214 return QString();
189 } 215 }
190 QString line = (*currentIface); 216 QString line = (*currentIface);
191 line = line.mid(QString(IFACE).length() +1, line.length()); 217 line = line.mid(QString(IFACE).length() +1, line.length());
192 line = line.simplifyWhiteSpace(); 218 line = line.simplifyWhiteSpace();
193 int findSpace = line.find(" "); 219 int findSpace = line.find(" ");
194 if( findSpace < 0){ 220 if( findSpace < 0){
195 error = true; 221 error = true;
196 return QString(); 222 return QString();
197 } 223 }
198 error = false; 224 error = false;
199 return line.mid(0, findSpace); 225 return line.mid(0, findSpace);
200} 226}
201 227
202/** 228/**
203 * Gets the family name of the interface that is currently selected. 229 * Gets the family name of the interface that is currently selected.
204 * @return QString name of the family (inet, inet6, ipx). 230 * @return QString name of the family (inet, inet6, ipx).
205 * @param error set to true if any error occurs, false otherwise. 231 * @param error set to true if any error occurs, false otherwise.
206 */ 232 */
207QString Interfaces::getInterfaceFamily(bool &error){ 233QString Interfaces::getInterfaceFamily(bool &error){
208 QString name = getInterfaceName(error); 234 QString name = getInterfaceName(error);
209 if(error){ 235 if(error){
210 error = true; 236 error = true;
211 return QString(); 237 return QString();
212 } 238 }
213 QString line = (*currentIface); 239 QString line = (*currentIface);
214 line = line.mid(QString(IFACE).length() +1, line.length()); 240 line = line.mid(QString(IFACE).length() +1, line.length());
215 line = line.mid(name.length()+1, line.length()); 241 line = line.mid(name.length()+1, line.length());
216 line = line.simplifyWhiteSpace(); 242 line = line.simplifyWhiteSpace();
217 int findSpace = line.find(" "); 243 int findSpace = line.find(" ");
218 if( findSpace < 0){ 244 if( findSpace < 0){
219 error = true; 245 error = true;
220 return QString(); 246 return QString();
221 } 247 }
222 error = false; 248 error = false;
223 return line.mid(0, findSpace); 249 return line.mid(0, findSpace);
224} 250}
225 251
226/** 252/**
227 * Gets the method of the interface that is currently selected. 253 * Gets the method of the interface that is currently selected.
228 * @return QString name of the method such as staic or dhcp. 254 * @return QString name of the method such as staic or dhcp.
229 * 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.
230 * @param error set to true if any error occurs, false otherwise. 256 * @param error set to true if any error occurs, false otherwise.
231 */ 257 */
232QString Interfaces::getInterfaceMethod(bool &error){ 258QString Interfaces::getInterfaceMethod(bool &error){
233 QString name = getInterfaceName(error); 259 QString name = getInterfaceName(error);
234 if(error){ 260 if(error){
235 error = true; 261 error = true;
236 return QString(); 262 return QString();
237 } 263 }
238 QString family = getInterfaceFamily(error); 264 QString family = getInterfaceFamily(error);
239 if(error){ 265 if(error){
240 error = true; 266 error = true;
241 return QString(); 267 return QString();
242 } 268 }
243 QString line = (*currentIface); 269 QString line = (*currentIface);
244 line = line.mid(QString(IFACE).length()+1, line.length()); 270 line = line.mid(QString(IFACE).length()+1, line.length());
245 line = line.mid(name.length()+1, line.length()); 271 line = line.mid(name.length()+1, line.length());
246 line = line.mid(family.length()+1, line.length()); 272 line = line.mid(family.length()+1, line.length());
247 line = line.simplifyWhiteSpace(); 273 line = line.simplifyWhiteSpace();
248 error = false; 274 error = false;
249 return line; 275 return line;
250} 276}
251 277
252/** 278/**
253 * Sets the interface name to newName. 279 * Sets the interface name to newName.
254 * @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.
255 * @return bool true if successfull. 281 * @return bool true if successfull.
256 */ 282 */
257bool Interfaces::setInterfaceName(QString newName){ 283bool Interfaces::setInterfaceName(QString newName){
258 if(currentIface == interfaces.end()) 284 if(currentIface == interfaces.end())
259 return false; 285 return false;
260 newName = newName.simplifyWhiteSpace(); 286 newName = newName.simplifyWhiteSpace();
261 newName = newName.replace(QRegExp(" "), ""); 287 newName = newName.replace(QRegExp(" "), "");
262 bool returnValue = false; 288 bool returnValue = false;
263 (*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));
264 return !returnValue; 290 return !returnValue;
265} 291}
266 292
267/** 293/**
268 * Sets the interface family to newName. 294 * Sets the interface family to newName.
269 * @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
270 * defined in the interfaces.h file. 296 * defined in the interfaces.h file.
271 * @return bool true if successfull. 297 * @return bool true if successfull.
272 */ 298 */
273bool Interfaces::setInterfaceFamily(QString newName){ 299bool Interfaces::setInterfaceFamily(QString newName){
274 if(currentIface == interfaces.end()) 300 if(currentIface == interfaces.end())
275 return false; 301 return false;
276 if(acceptedFamily.contains(newName)==0) 302 if(acceptedFamily.contains(newName)==0)
277 return false; 303 return false;
278 bool returnValue = false; 304 bool returnValue = false;
279 (*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));
280 return !returnValue; 306 return !returnValue;
281} 307}
282 308
283/** 309/**
284 * Sets the interface method to newName 310 * Sets the interface method to newName
285 * @param newName the new name of the interface 311 * @param newName the new name of the interface
286 * @return bool true if successfull. 312 * @return bool true if successfull.
287 */ 313 */
288bool Interfaces::setInterfaceMethod(QString newName){ 314bool Interfaces::setInterfaceMethod(QString newName){
289 if(currentIface == interfaces.end()) 315 if(currentIface == interfaces.end())
290 return false; 316 return false;
291 bool returnValue = false; 317 bool returnValue = false;
292 (*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);
293 return !returnValue; 319 return !returnValue;
294} 320}
295 321
296/** 322/**
297 * 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
298 * calling getInterfaceOption("address") on the following stanza would 324 * calling getInterfaceOption("address") on the following stanza would
299 * return 192.168.1.1. 325 * return 192.168.1.1.
300 * iface eth0 static 326 * iface eth0 static
301 * address 192.168.1.1 327 * address 192.168.1.1
302 * @param option the options to get the value. 328 * @param option the options to get the value.
303 * @param error set to true if any error occurs, false otherwise. 329 * @param error set to true if any error occurs, false otherwise.
304 * @return QString the options value. QString::null if error == true 330 * @return QString the options value. QString::null if error == true
305 */ 331 */
306QString Interfaces::getInterfaceOption(QString option, bool &error){ 332QString Interfaces::getInterfaceOption(QString option, bool &error){
307 return getOption(currentIface, option, error); 333 return getOption(currentIface, option, error);
308} 334}
309 335
310/** 336/**
311 * 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
312 * doesn't exist then it is added along with the value. If value is set to an 338 * doesn't exist then it is added along with the value. If value is set to an
313 * empty string then option is removed. 339 * empty string then option is removed.
314 * @param option the options to set the value. 340 * @param option the options to set the value.
315 * @param value the value that option should be set to. 341 * @param value the value that option should be set to.
316 * @param error set to true if any error occurs, false otherwise. 342 * @param error set to true if any error occurs, false otherwise.
317 * @return QString the options value. QString::null if error == true 343 * @return QString the options value. QString::null if error == true
318 */ 344 */
319bool Interfaces::setInterfaceOption(QString option, QString value){ 345bool Interfaces::setInterfaceOption(QString option, QString value){
320 return setOption(currentIface, option, value); 346 return setOption(currentIface, option, value);
321} 347}
322 348
323/** 349/**
324 * Removes all of the options from the currently selected interface. 350 * Removes all of the options from the currently selected interface.
325 * @return bool error if if successfull 351 * @return bool error if if successfull
326 */ 352 */
327bool Interfaces::removeAllInterfaceOptions(){ 353bool Interfaces::removeAllInterfaceOptions(){
328 return removeAllOptions(currentIface); 354 return removeAllOptions(currentIface);
329} 355}
330 356
331/** 357/**
332 * Set the current map to interface's map. This needs to be done before you 358 * Set the current map to interface's map. This needs to be done before you
333 * can call addMapping(), set/getMap(), and get/setScript(). 359 * can call addMapping(), set/getMap(), and get/setScript().
334 * @param interface the name of the interface to set. All whitespace is 360 * @param interface the name of the interface to set. All whitespace is
335 * removed from the interface name. 361 * removed from the interface name.
336 * @return bool true if it is successfull. 362 * @return bool true if it is successfull.
337 */ 363 */
338bool Interfaces::setMapping(QString interface){ 364bool Interfaces::setMapping(QString interface){
339 interface = interface.simplifyWhiteSpace(); 365 interface = interface.simplifyWhiteSpace();
340 interface = interface.replace(QRegExp(" "), ""); 366 interface = interface.replace(QRegExp(" "), "");
341 return setStanza(MAPPING, interface, currentMapping); 367 return setStanza(MAPPING, interface, currentMapping);
342} 368}
343 369
344/** 370/**
345 * Adds a new Mapping to the interfaces file with interfaces. 371 * Adds a new Mapping to the interfaces file with interfaces.
346 * @param interface the name(s) of the interfaces to set to this mapping 372 * @param interface the name(s) of the interfaces to set to this mapping
347 */ 373 */
348void Interfaces::addMapping(QString option){ 374void Interfaces::addMapping(QString option){
349 interfaces.append(""); 375 interfaces.append("");
350 interfaces.append(QString(MAPPING " %1").arg(option)); 376 interfaces.append(QString(MAPPING " %1").arg(option));
351} 377}
352 378
353/** 379/**
354 * Set a map option within a mapping. 380 * Set a map option within a mapping.
355 * @param map map to use 381 * @param map map to use
356 * @param value value to go with map 382 * @param value value to go with map
357 * @return bool true if it is successfull. 383 * @return bool true if it is successfull.
358 */ 384 */
359bool Interfaces::setMap(QString map, QString value){ 385bool Interfaces::setMap(QString map, QString value){
360 return setOption(currentMapping, map, value); 386 return setOption(currentMapping, map, value);
361} 387}
362 388
363/** 389/**
364 * Get a map value within a mapping. 390 * Get a map value within a mapping.
365 * @param map map to get value of 391 * @param map map to get value of
366 * @param bool true if it is successfull. 392 * @param bool true if it is successfull.
367 * @return value that goes to the map 393 * @return value that goes to the map
368 */ 394 */
369QString Interfaces::getMap(QString map, bool &error){ 395QString Interfaces::getMap(QString map, bool &error){
370 return getOption(currentMapping, map, error); 396 return getOption(currentMapping, map, error);
371} 397}
372 398
373/** 399/**
374 * Sets a script value of the current mapping to argument. 400 * Sets a script value of the current mapping to argument.
375 * @param argument the script name. 401 * @param argument the script name.
376 * @return true if successfull. 402 * @return true if successfull.
377 */ 403 */
378bool Interfaces::setScript(QString argument){ 404bool Interfaces::setScript(QString argument){
379 return setOption(currentMapping, "script", argument); 405 return setOption(currentMapping, "script", argument);
380} 406}
381 407
382/** 408/**
383 * @param error true if could not retrieve the current script argument. 409 * @param error true if could not retrieve the current script argument.
384 * @return QString the argument of the script for the current mapping. 410 * @return QString the argument of the script for the current mapping.
385 */ 411 */
386QString Interfaces::getScript(bool &error){ 412QString Interfaces::getScript(bool &error){
387 return getOption(currentMapping, "script", error); 413 return getOption(currentMapping, "script", error);
388} 414}
389 415
390/** 416/**
391 * Helper function used to parse through the QStringList and put pointers in 417 * Helper function used to parse through the QStringList and put pointers in
392 * the correct place. 418 * the correct place.
393 * @param stanza The stanza (auto, iface, mapping) to look for. 419 * @param stanza The stanza (auto, iface, mapping) to look for.
394 * @param option string that must be in the stanza's main line. 420 * @param option string that must be in the stanza's main line.
395 * @param interator interator to place at location of stanza if successfull. 421 * @param interator interator to place at location of stanza if successfull.
396 * @return bool true if the stanza is found. 422 * @return bool true if the stanza is found.
397 */ 423 */
398bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 424bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
399 bool found = false; 425 bool found = false;
400 iterator = interfaces.end(); 426 iterator = interfaces.end();
401 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 427 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
402 QString line = (*it).simplifyWhiteSpace(); 428 QString line = (*it).simplifyWhiteSpace();
403 if(line.contains(stanza) && line.contains(option)){ 429 if(line.contains(stanza) && line.contains(option)){
404 if(found == true){ 430 uint point = line.find(option);
405 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); 431 bool valid = true;
432 if(point > 0){
433 // There are more chars in the line. check +1
434 if(line.at(point-1) != ' ')
435 valid = false;
436 }
437 point += option.length();
438 if(point < line.length()-1){
439 // There are more chars in the line. check -1
440 if(line.at(point) != ' ')
441 valid = false;
442 }
443 if(valid){
444 if(found == true){
445 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
446 }
447 found = true;
448 iterator = it;
406 } 449 }
407 qDebug("Found");
408 found = true;
409 iterator = it;
410 } 450 }
411 } 451 }
412 return found; 452 return found;
413} 453}
414 454
415/** 455/**
416 * Sets a value of an option in a stanza 456 * Sets a value of an option in a stanza
417 * @param start the start of the stanza 457 * @param start the start of the stanza
418 * @param option the option to use when setting value. 458 * @param option the option to use when setting value.
419 * @return bool true if successfull, false otherwise. 459 * @return bool true if successfull, false otherwise.
420 */ 460 */
421bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 461bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
422 if(start == interfaces.end()) 462 if(start == interfaces.end())
423 return false; 463 return false;
424 464
425 bool found = false; 465 bool found = false;
426 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 466 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
427 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 467 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
428 if(!found && value != ""){ 468 if(!found && value != ""){
429 // Got to the end of the stanza without finding it, so append it. 469 // Got to the end of the stanza without finding it, so append it.
430 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 470 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
431 } 471 }
432 found = true; 472 found = true;
433 break; 473 break;
434 } 474 }
435 if((*it).contains(option) && it != start){ 475 if((*it).contains(option) && it != start){
436 // Found it in stanza so replace it. 476 // Found it in stanza so replace it.
437 if(found) 477 if(found)
438 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 478 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
439 found = true; 479 found = true;
440 if(value == "") 480 if(value == "")
441 (*it) = ""; 481 (*it) = "";
442 else 482 else
443 (*it) = QString("\t%1 %2").arg(option).arg(value); 483 (*it) = QString("\t%1 %2").arg(option).arg(value);
444 } 484 }
445 } 485 }
446 if(!found){ 486 if(!found){
447 QStringList::Iterator p = start; 487 QStringList::Iterator p = start;
448 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); 488 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
449 found = true; 489 found = true;
450 } 490 }
451 return found; 491 return found;
452} 492}
453 493
454/** 494/**
455 * Removes all options in a stanza 495 * Removes all options in a stanza
456 * @param start the start of the stanza 496 * @param start the start of the stanza
457 * @return bool true if successfull, false otherwise. 497 * @return bool true if successfull, false otherwise.
458 */ 498 */
459bool Interfaces::removeAllOptions(QStringList::Iterator start){ 499bool Interfaces::removeAllOptions(QStringList::Iterator start){
460 if(start == interfaces.end()) 500 if(start == interfaces.end())
461 return false; 501 return false;
462 502
463 QStringList::Iterator it = start; 503 QStringList::Iterator it = start;
464 it = ++it; 504 it = ++it;
465 for (it; it != interfaces.end(); ++it ) { 505 for (it; it != interfaces.end(); ++it ) {
466 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 506 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
467 break; 507 break;
468 } 508 }
469 it = interfaces.remove(it); 509 it = interfaces.remove(it);
470 it = --it; 510 it = --it;
471 } 511 }
472 // Leave a space between this interface and the next. 512 // Leave a space between this interface and the next.
473 interfaces.insert(it, QString("")); 513 interfaces.insert(it, QString(""));
474 return true; 514 return true;
475} 515}
476 516
477/** 517/**
478 * Gets a value of an option in a stanza 518 * Gets a value of an option in a stanza
479 * @param start the start of the stanza 519 * @param start the start of the stanza
480 * @param option the option to use when getting the value. 520 * @param option the option to use when getting the value.
481 * @param bool true if errors false otherwise. 521 * @param bool true if errors false otherwise.
482 * @return QString the value of option QString::null() if error == true. 522 * @return QString the value of option QString::null() if error == true.
483 */ 523 */
484QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ 524QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){
485 if(start == interfaces.end()){ 525 if(start == interfaces.end()){
486 error = false; 526 error = false;
487 return QString(); 527 return QString();
488 } 528 }
489 529
490 QString value; 530 QString value;
491 bool found = false; 531 bool found = false;
492 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 532 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
493 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){
494 break; 534 break;
495 } 535 }
496 if((*it).contains(option)){ 536 if((*it).contains(option)){
497 if(found) 537 if(found)
498 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 538 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
499 found = true; 539 found = true;
500 QString line = (*it).simplifyWhiteSpace(); 540 QString line = (*it).simplifyWhiteSpace();
501 int space = line.find(" ", option.length()); 541 int space = line.find(" ", option.length());
502 if(space != -1) 542 if(space != -1)
503 value = line.mid(space+1, line.length()); 543 value = line.mid(space+1, line.length());
504 else 544 else
505 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); 545 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1());
506 } 546 }
507 } 547 }
508 error = !found; 548 error = !found;
509 return value; 549 return value;
510} 550}
511 551
512/** 552/**
513 * Write out the interfaces file to the file passed into the constructor. 553 * Write out the interfaces file to the file passed into the constructor.
514 * Removes any excess blank lines over 1 line long. 554 * Removes any excess blank lines over 1 line long.
515 * @return bool true if successfull, false if not. 555 * @return bool true if successfull, false if not.
516 */ 556 */
517bool Interfaces::write(){ 557bool Interfaces::write(){
518 QFile::remove(interfacesFile); 558 QFile::remove(interfacesFile);
519 QFile file(interfacesFile); 559 QFile file(interfacesFile);
520 560
521 if (!file.open(IO_ReadWrite)){ 561 if (!file.open(IO_ReadWrite)){
522 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); 562 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
523 return false; 563 return false;
524 } 564 }
525 QTextStream stream( &file ); 565 QTextStream stream( &file );
526 int whiteSpaceCount = 0; 566 int whiteSpaceCount = 0;
527 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 567 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
528 QString line = (*it).simplifyWhiteSpace(); 568 QString line = (*it).simplifyWhiteSpace();
529 line = line.replace(QRegExp(" "),""); 569 line = line.replace(QRegExp(" "),"");
530 if(line.length() == 0) 570 if(line.length() == 0)
531 whiteSpaceCount++; 571 whiteSpaceCount++;
532 else 572 else
533 whiteSpaceCount = 0; 573 whiteSpaceCount = 0;
534 if(whiteSpaceCount < 2){ 574 if(whiteSpaceCount < 2){
535 qDebug((*it).latin1()); 575 qDebug((*it).latin1());
536 stream << (*it) << '\n'; 576 stream << (*it) << '\n';
537 } 577 }
diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h
index e617c17..7cf04f0 100644
--- a/noncore/net/networksetup/interfaces.h
+++ b/noncore/net/networksetup/interfaces.h
@@ -1,71 +1,72 @@
1#ifndef INTERFACES_H 1#ifndef INTERFACES_H
2#define INTERFACES_H 2#define INTERFACES_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6 6
7#define INTERFACES_LOOPBACK "loopback" 7#define INTERFACES_LOOPBACK "loopback"
8 8
9#define INTERFACES_FAMILY_INET "inet" 9#define INTERFACES_FAMILY_INET "inet"
10#define INTERFACES_FAMILY_IPX "ipx" 10#define INTERFACES_FAMILY_IPX "ipx"
11#define INTERFACES_FAMILY_INET6 "inet6" 11#define INTERFACES_FAMILY_INET6 "inet6"
12 12
13#define INTERFACES_METHOD_DHCP "dhcp" 13#define INTERFACES_METHOD_DHCP "dhcp"
14#define INTERFACES_METHOD_STATIC "static" 14#define INTERFACES_METHOD_STATIC "static"
15#define INTERFACES_METHOD_PPP "ppp" 15#define INTERFACES_METHOD_PPP "ppp"
16 16
17/** 17/**
18 * This class provides a clean frontend for parsing the network interfaces file. 18 * This class provides a clean frontend for parsing the network interfaces file.
19 * It provides helper functions to minipulate the options within the file. 19 * It provides helper functions to minipulate the options within the file.
20 * See the interfaces man page for the syntax rules. 20 * See the interfaces man page for the syntax rules.
21 */ 21 */
22class Interfaces { 22class Interfaces {
23 23
24public: 24public:
25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); 25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
26 QStringList getInterfaceList(); 26 QStringList getInterfaceList();
27 27
28 bool isAuto(QString interface); 28 bool isAuto(QString interface);
29 bool setAuto(QString interface, bool setAuto); 29 bool setAuto(QString interface, bool setAuto);
30 30
31 bool removeInterface(); 31 bool removeInterface();
32 bool addInterface(QString interface, QString family, QString method); 32 bool addInterface(QString interface, QString family, QString method);
33 bool copyInterface(QString oldInterface, QString newInterface);
33 bool setInterface(QString interface); 34 bool setInterface(QString interface);
34 bool isInterfaceSet(); 35 bool isInterfaceSet();
35 QString getInterfaceName(bool &error); 36 QString getInterfaceName(bool &error);
36 bool setInterfaceName(QString newName); 37 bool setInterfaceName(QString newName);
37 QString getInterfaceFamily(bool &error); 38 QString getInterfaceFamily(bool &error);
38 bool setInterfaceFamily(QString newName); 39 bool setInterfaceFamily(QString newName);
39 QString getInterfaceMethod(bool &error); 40 QString getInterfaceMethod(bool &error);
40 bool setInterfaceMethod(QString newName); 41 bool setInterfaceMethod(QString newName);
41 QString getInterfaceOption(QString option, bool &error); 42 QString getInterfaceOption(QString option, bool &error);
42 bool setInterfaceOption(QString option, QString value); 43 bool setInterfaceOption(QString option, QString value);
43 bool removeAllInterfaceOptions(); 44 bool removeAllInterfaceOptions();
44 45
45 bool setMapping(QString interface); 46 bool setMapping(QString interface);
46 void addMapping(QString options); 47 void addMapping(QString options);
47 bool setMap(QString map, QString value); 48 bool setMap(QString map, QString value);
48 QString getMap(QString map, bool &error); 49 QString getMap(QString map, bool &error);
49 bool setScript(QString); 50 bool setScript(QString);
50 QString getScript(bool &error); 51 QString getScript(bool &error);
51 52
52 bool write(); 53 bool write();
53 54
54private: 55private:
55 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); 56 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
56 bool setOption(QStringList::Iterator start, QString option, QString value); 57 bool setOption(QStringList::Iterator start, QString option, QString value);
57 QString getOption(QStringList::Iterator start, QString option, bool &error); 58 QString getOption(QStringList::Iterator start, QString option, bool &error);
58 bool removeAllOptions(QStringList::Iterator start); 59 bool removeAllOptions(QStringList::Iterator start);
59 60
60 QString interfacesFile; 61 QString interfacesFile;
61 QStringList interfaces; 62 QStringList interfaces;
62 QStringList::Iterator currentIface; 63 QStringList::Iterator currentIface;
63 QStringList::Iterator currentMapping; 64 QStringList::Iterator currentMapping;
64 65
65 QStringList acceptedFamily; 66 QStringList acceptedFamily;
66}; 67};
67 68
68#endif 69#endif
69 70
70// interfaces 71// interfaces
71 72
diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp
index c16d821..bdbdfde 100644
--- a/noncore/net/networksetup/interfacesetupimp.cpp
+++ b/noncore/net/networksetup/interfacesetupimp.cpp
@@ -1,143 +1,148 @@
1#include "interfacesetupimp.h" 1#include "interfacesetupimp.h"
2#include "interface.h" 2#include "interface.h"
3#include "interfaces.h" 3#include "interfaces.h"
4 4
5#include <qcombobox.h> 5#include <qcombobox.h>
6#include <qcheckbox.h> 6#include <qcheckbox.h>
7#include <qlineedit.h> 7#include <qlineedit.h>
8#include <qspinbox.h> 8#include <qspinbox.h>
9#include <qgroupbox.h> 9#include <qgroupbox.h>
10#include <qlabel.h> 10#include <qlabel.h>
11 11
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13 13
14#include <assert.h> 14#include <assert.h>
15 15
16#define DNSSCRIPT "interfacednsscript" 16#define DNSSCRIPT "interfacednsscript"
17 17
18/** 18/**
19 * Constuctor. Set up the connection and load the first profile. 19 * Constuctor. Set up the connection and load the first profile.
20 */ 20 */
21InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : InterfaceSetup(parent, name, modal, fl){ 21InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : InterfaceSetup(parent, name, modal, fl){
22 assert(i); 22 assert(i);
23 interface = i; 23 interface = i;
24 interfaces = new Interfaces(); 24 interfaces = new Interfaces();
25 bool error = false; 25 bool error = false;
26 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 26 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
27 staticGroupBox->hide(); 27 staticGroupBox->hide();
28 dhcpCheckBox->hide(); 28 dhcpCheckBox->hide();
29 leaseTime->hide(); 29 leaseTime->hide();
30 leaseHoursLabel->hide(); 30 leaseHoursLabel->hide();
31 } 31 }
32} 32}
33 33
34/** 34/**
35 * Save the current settings, then write out the interfaces file and close. 35 * Save the current settings, then write out the interfaces file and close.
36 */ 36 */
37void InterfaceSetupImp::accept(){ 37void InterfaceSetupImp::accept(){
38 if(!saveSettings()) 38 if(!saveSettings())
39 return; 39 return;
40 interfaces->write(); 40 interfaces->write();
41 close(true); 41 close(true);
42} 42}
43 43
44/** 44/**
45 * Save the settings for the current Interface. 45 * Save the settings for the current Interface.
46 * @return bool true if successfull, false otherwise 46 * @return bool true if successfull, false otherwise
47 */ 47 */
48bool InterfaceSetupImp::saveSettings(){ 48bool InterfaceSetupImp::saveSettings(){
49 // eh can't really do anything about it other then return. :-D 49 // eh can't really do anything about it other then return. :-D
50 if(!interfaces->isInterfaceSet()) 50 if(!interfaces->isInterfaceSet())
51 return true; 51 return true;
52 52
53 bool error = false; 53 bool error = false;
54 // Loopback case 54 // Loopback case
55 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 55 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
56 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 56 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
57 return true; 57 return true;
58 } 58 }
59 59
60 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ 60 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){
61 QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); 61 QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok");
62 return false; 62 return false;
63 } 63 }
64 interfaces->removeAllInterfaceOptions(); 64 interfaces->removeAllInterfaceOptions();
65 65
66 // DHCP 66 // DHCP
67 if(dhcpCheckBox->isChecked()){ 67 if(dhcpCheckBox->isChecked()){
68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); 69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); 70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
71 } 71 }
72 else{ 72 else{
73 interfaces->setInterfaceMethod("static"); 73 interfaces->setInterfaceMethod("static");
74 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 74 interfaces->setInterfaceOption("address", ipAddressEdit->text());
75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
76 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 76 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); 78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); 79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
80 } 80 }
81 81
82 // IP Information 82 // IP Information
83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
84 return true; 84 return true;
85} 85}
86 86
87/** 87/**
88 * The Profile has changed. 88 * The Profile has changed.
89 * @profile the new profile. 89 * @profile the new profile.
90 */ 90 */
91void InterfaceSetupImp::setProfile(const QString &profile){ 91void InterfaceSetupImp::setProfile(const QString &profile){
92 QString newInterfaceName = interface->getInterfaceName() + profile; 92 QString newInterfaceName = interface->getInterfaceName();
93 93 if(profile.length() > 0)
94 newInterfaceName += "_" + profile;
95 qDebug( newInterfaceName.latin1());
94 // See if we have to make a interface. 96 // See if we have to make a interface.
95 if(!interfaces->setInterface(newInterfaceName)){ 97 if(!interfaces->setInterface(newInterfaceName)){
96 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
97 if(!interfaces->setInterface(newInterfaceName)){
98 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
99 return;
100 }
101 // Add making for this new interface if need too 98 // Add making for this new interface if need too
102 if(profile != ""){ 99 if(profile != ""){
100 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
103 if(!interfaces->setMapping(interface->getInterfaceName())){ 101 if(!interfaces->setMapping(interface->getInterfaceName())){
104 interfaces->addMapping(interface->getInterfaceName()); 102 interfaces->addMapping(interface->getInterfaceName());
105 if(!interfaces->setMapping(interface->getInterfaceName())){ 103 if(!interfaces->setMapping(interface->getInterfaceName())){
106 qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); 104 qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
107 return; 105 return;
108 } 106 }
109 } 107 }
110 interfaces->setScript("getprofile.sh");
111 interfaces->setMap("map", newInterfaceName); 108 interfaces->setMap("map", newInterfaceName);
109 interfaces->setScript("getprofile.sh");
110 }
111 else{
112 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
113 if(!interfaces->setInterface(newInterfaceName)){
114 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
115 return;
116 }
112 } 117 }
113 } 118 }
114 119
115 // We must have a valid interface to get this far so read some settings. 120 // We must have a valid interface to get this far so read some settings.
116 121
117 // DHCP 122 // DHCP
118 bool error = false; 123 bool error = false;
119 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 124 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
120 dhcpCheckBox->setChecked(true); 125 dhcpCheckBox->setChecked(true);
121 else 126 else
122 dhcpCheckBox->setChecked(false); 127 dhcpCheckBox->setChecked(false);
123 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); 128 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
124 if(error) 129 if(error)
125 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); 130 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
126 if(error) 131 if(error)
127 leaseTime->setValue(24); 132 leaseTime->setValue(24);
128 133
129 // IP Information 134 // IP Information
130 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 135 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
131 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); 136 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
132 if(dns.contains(" ")){ 137 if(dns.contains(" ")){
133 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 138 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
134 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 139 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
135 } 140 }
136 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 141 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
137 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 142 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
138 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 143 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
139} 144}
140 145
141 146
142// interfacesetup.cpp 147// interfacesetup.cpp
143 148
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index 3c0af6a..9f07f0d 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -103,423 +103,429 @@ void MainWindowImp::loadModules(QString path){
103 // Don't want sym links 103 // Don't want sym links
104 d.setFilter( QDir::Files | QDir::NoSymLinks ); 104 d.setFilter( QDir::Files | QDir::NoSymLinks );
105 const QFileInfoList *list = d.entryInfoList(); 105 const QFileInfoList *list = d.entryInfoList();
106 QFileInfoListIterator it( *list ); 106 QFileInfoListIterator it( *list );
107 QFileInfo *fi; 107 QFileInfo *fi;
108 while ( (fi=it.current()) ) { 108 while ( (fi=it.current()) ) {
109 if(fi->fileName().contains(".so")){ 109 if(fi->fileName().contains(".so")){
110 loadPlugin(path + "/" + fi->fileName()); 110 loadPlugin(path + "/" + fi->fileName());
111 } 111 }
112 ++it; 112 ++it;
113 } 113 }
114} 114}
115 115
116/** 116/**
117 * Attempt to load a function and resolve a function. 117 * Attempt to load a function and resolve a function.
118 * @param pluginFileName - the name of the file in which to attempt to load 118 * @param pluginFileName - the name of the file in which to attempt to load
119 * @param resolveString - function pointer to resolve 119 * @param resolveString - function pointer to resolve
120 * @return pointer to the function with name resolveString or NULL 120 * @return pointer to the function with name resolveString or NULL
121 */ 121 */
122Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ 122Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
123 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 123 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
124 QLibrary *lib = new QLibrary(pluginFileName); 124 QLibrary *lib = new QLibrary(pluginFileName);
125 void *functionPointer = lib->resolve(resolveString); 125 void *functionPointer = lib->resolve(resolveString);
126 if( !functionPointer ){ 126 if( !functionPointer ){
127 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 127 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
128 delete lib; 128 delete lib;
129 return NULL; 129 return NULL;
130 } 130 }
131 131
132 // Try to get an object. 132 // Try to get an object.
133 Module *object = ((Module* (*)()) functionPointer)(); 133 Module *object = ((Module* (*)()) functionPointer)();
134 if(object == NULL){ 134 if(object == NULL){
135 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 135 qDebug("MainWindowImp: Couldn't create object, but did load library!");
136 delete lib; 136 delete lib;
137 return NULL; 137 return NULL;
138 } 138 }
139 139
140 // Store for deletion later 140 // Store for deletion later
141 libraries.insert(object, lib); 141 libraries.insert(object, lib);
142 return object; 142 return object;
143} 143}
144 144
145/** 145/**
146 * The Add button was clicked. Bring up the add dialog and if OK is hit 146 * The Add button was clicked. Bring up the add dialog and if OK is hit
147 * load the plugin and append it to the list 147 * load the plugin and append it to the list
148 */ 148 */
149void MainWindowImp::addClicked(){ 149void MainWindowImp::addClicked(){
150 QMap<Module*, QLibrary*>::Iterator it; 150 QMap<Module*, QLibrary*>::Iterator it;
151 QMap<QString, QString> list; 151 QMap<QString, QString> list;
152 QMap<QString, Module*> newInterfaceOwners; 152 QMap<QString, Module*> newInterfaceOwners;
153 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 153 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
154 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 154 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
155 for( it = libraries.begin(); it != libraries.end(); ++it ){ 155 for( it = libraries.begin(); it != libraries.end(); ++it ){
156 if(it.key()){ 156 if(it.key()){
157 (it.key())->possibleNewInterfaces(list); 157 (it.key())->possibleNewInterfaces(list);
158 } 158 }
159 } 159 }
160 // See if the list has anything that we can add. 160 // See if the list has anything that we can add.
161 if(list.count() == 0){ 161 if(list.count() == 0){
162 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); 162 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
163 return; 163 return;
164 } 164 }
165 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 165 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
166 addNewConnection.addConnections(list); 166 addNewConnection.addConnections(list);
167 addNewConnection.showMaximized(); 167 addNewConnection.showMaximized();
168 if(QDialog::Accepted == addNewConnection.exec()){ 168 if(QDialog::Accepted == addNewConnection.exec()){
169 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 169 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
170 if(!item) 170 if(!item)
171 return; 171 return;
172 172
173 for( it = libraries.begin(); it != libraries.end(); ++it ){ 173 for( it = libraries.begin(); it != libraries.end(); ++it ){
174 if(it.key()){ 174 if(it.key()){
175 Interface *i = (it.key())->addNewInterface(item->text(0)); 175 Interface *i = (it.key())->addNewInterface(item->text(0));
176 if(i){ 176 if(i){
177 interfaceNames.insert(i->getInterfaceName(), i); 177 interfaceNames.insert(i->getInterfaceName(), i);
178 updateInterface(i); 178 updateInterface(i);
179 } 179 }
180 } 180 }
181 } 181 }
182 } 182 }
183} 183}
184 184
185/** 185/**
186 * Prompt the user to see if they really want to do this. 186 * Prompt the user to see if they really want to do this.
187 * If they do then remove from the list and unload. 187 * If they do then remove from the list and unload.
188 */ 188 */
189void MainWindowImp::removeClicked(){ 189void MainWindowImp::removeClicked(){
190 QListViewItem *item = connectionList->currentItem(); 190 QListViewItem *item = connectionList->currentItem();
191 if(!item) { 191 if(!item) {
192 QMessageBox::information(this, "Error","Please select an interface.", "Ok"); 192 QMessageBox::information(this, "Error","Please select an interface.", "Ok");
193 return; 193 return;
194 } 194 }
195 195
196 Interface *i = interfaceItems[item]; 196 Interface *i = interfaceItems[item];
197 if(i->getModuleOwner() == NULL){ 197 if(i->getModuleOwner() == NULL){
198 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); 198 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
199 } 199 }
200 else{ 200 else{
201 if(!i->getModuleOwner()->remove(i)) 201 if(!i->getModuleOwner()->remove(i))
202 QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); 202 QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
203 else{ 203 else{
204 QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); 204 QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
205 // TODO memory managment.... 205 // TODO memory managment....
206 // who deletes the interface? 206 // who deletes the interface?
207 } 207 }
208 } 208 }
209} 209}
210 210
211/** 211/**
212 * Pull up the configure about the currently selected interface. 212 * Pull up the configure about the currently selected interface.
213 * Report an error if no interface is selected. 213 * Report an error if no interface is selected.
214 * If the interface has a module owner then request its configure with a empty 214 * If the interface has a module owner then request its configure with a empty
215 * tab. If tab is !NULL then append the interfaces setup widget to it. 215 * tab. If tab is !NULL then append the interfaces setup widget to it.
216 */ 216 */
217void MainWindowImp::configureClicked(){ 217void MainWindowImp::configureClicked(){
218 QListViewItem *item = connectionList->currentItem(); 218 QListViewItem *item = connectionList->currentItem();
219 if(!item){ 219 if(!item){
220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
221 return; 221 return;
222 } 222 }
223 223
224 QString currentProfile = currentProfileLabel->text(); 224 QString currentProfile = currentProfileLabel->text();
225 if(profilesList->count() <= 1 || currentProfile == "All"){ 225 if(profilesList->count() <= 1 || currentProfile == "All"){
226 currentProfile = ""; 226 currentProfile = "";
227 } 227 }
228 228
229 Interface *i = interfaceItems[item]; 229 Interface *i = interfaceItems[item];
230 if(i->getModuleOwner()){ 230 if(i->getModuleOwner()){
231 i->getModuleOwner()->setProfile(currentProfileLabel->text()); 231 i->getModuleOwner()->setProfile(currentProfile);
232 QTabWidget *tabWidget = NULL; 232 QTabWidget *tabWidget = NULL;
233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
234 if(moduleConfigure != NULL){ 234 if(moduleConfigure != NULL){
235 if(tabWidget != NULL){ 235 if(tabWidget != NULL){
236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
237 configure->setProfile(currentProfileLabel->text()); 237 configure->setProfile(currentProfile);
238 tabWidget->insertTab(configure, "TCP/IP"); 238 tabWidget->insertTab(configure, "TCP/IP");
239 239
240 } 240 }
241 moduleConfigure->showMaximized(); 241 moduleConfigure->showMaximized();
242 moduleConfigure->show(); 242 moduleConfigure->show();
243 return; 243 return;
244 } 244 }
245 } 245 }
246 246
247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
248 configure->setProfile(currentProfileLabel->text()); 248 configure->setProfile(currentProfile);
249 configure->showMaximized(); 249 configure->showMaximized();
250 configure->show(); 250 configure->show();
251} 251}
252 252
253/** 253/**
254 * Pull up the information about the currently selected interface. 254 * Pull up the information about the currently selected interface.
255 * Report an error if no interface is selected. 255 * Report an error if no interface is selected.
256 * If the interface has a module owner then request its configure with a empty 256 * If the interface has a module owner then request its configure with a empty
257 * tab. If tab is !NULL then append the interfaces setup widget to it. 257 * tab. If tab is !NULL then append the interfaces setup widget to it.
258 */ 258 */
259void MainWindowImp::informationClicked(){ 259void MainWindowImp::informationClicked(){
260 QListViewItem *item = connectionList->currentItem(); 260 QListViewItem *item = connectionList->currentItem();
261 if(!item){ 261 if(!item){
262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
263 return; 263 return;
264 } 264 }
265 265
266 Interface *i = interfaceItems[item]; 266 Interface *i = interfaceItems[item];
267 if(!i->isAttached()){ 267 if(!i->isAttached()){
268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); 268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
269 return; 269 return;
270 } 270 }
271 271
272 QStringList list; 272 QStringList list;
273 for(uint i = 0; i < profilesList->count(); i++){ 273 for(uint i = 0; i < profilesList->count(); i++){
274 list.append(profilesList->text(i)); 274 list.append(profilesList->text(i));
275 } 275 }
276 276
277 if(i->getModuleOwner()){ 277 if(i->getModuleOwner()){
278 QTabWidget *tabWidget = NULL; 278 QTabWidget *tabWidget = NULL;
279 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 279 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
280 if(moduleInformation != NULL){ 280 if(moduleInformation != NULL){
281 if(tabWidget != NULL){ 281 if(tabWidget != NULL){
282 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 282 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
283 tabWidget->insertTab(information, "TCP/IP"); 283 tabWidget->insertTab(information, "TCP/IP");
284 } 284 }
285 moduleInformation->showMaximized(); 285 moduleInformation->showMaximized();
286 moduleInformation->show(); 286 moduleInformation->show();
287 return; 287 return;
288 } 288 }
289 } 289 }
290 290
291 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 291 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
292 information->showMaximized(); 292 information->showMaximized();
293 information->show(); 293 information->show();
294} 294}
295 295
296/** 296/**
297 * Aquire the list of active interfaces from ifconfig 297 * Aquire the list of active interfaces from ifconfig
298 * Call ifconfig and ifconfig -a 298 * Call ifconfig and ifconfig -a
299 */ 299 */
300void MainWindowImp::getInterfaceList(){ 300void MainWindowImp::getInterfaceList(){
301 KShellProcess *processAll = new KShellProcess(); 301 KShellProcess *processAll = new KShellProcess();
302 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 302 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
303 connect(processAll, SIGNAL(processExited(KProcess *)), 303 connect(processAll, SIGNAL(processExited(KProcess *)),
304 this, SLOT(jobDone(KProcess *))); 304 this, SLOT(jobDone(KProcess *)));
305 threads.insert(processAll, TEMP_ALL); 305 threads.insert(processAll, TEMP_ALL);
306 306
307 KShellProcess *process = new KShellProcess(); 307 KShellProcess *process = new KShellProcess();
308 *process << "/sbin/ifconfig" << " > " TEMP_UP; 308 *process << "/sbin/ifconfig" << " > " TEMP_UP;
309 connect(process, SIGNAL(processExited(KProcess *)), 309 connect(process, SIGNAL(processExited(KProcess *)),
310 this, SLOT(jobDone(KProcess *))); 310 this, SLOT(jobDone(KProcess *)));
311 threads.insert(process, TEMP_UP); 311 threads.insert(process, TEMP_UP);
312 312
313 processAll->start(KShellProcess::NotifyOnExit); 313 processAll->start(KShellProcess::NotifyOnExit);
314 process->start(KShellProcess::NotifyOnExit); 314 process->start(KShellProcess::NotifyOnExit);
315} 315}
316 316
317void MainWindowImp::jobDone(KProcess *process){ 317void MainWindowImp::jobDone(KProcess *process){
318 QString fileName = threads[process]; 318 QString fileName = threads[process];
319 threads.remove(process); 319 threads.remove(process);
320 delete process; 320 delete process;
321 321
322 QFile file(fileName); 322 QFile file(fileName);
323 if (!file.open(IO_ReadOnly)){ 323 if (!file.open(IO_ReadOnly)){
324 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 324 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
325 return; 325 return;
326 } 326 }
327 327
328 QTextStream stream( &file ); 328 QTextStream stream( &file );
329 QString line; 329 QString line;
330 while ( !stream.eof() ) { 330 while ( !stream.eof() ) {
331 line = stream.readLine(); 331 line = stream.readLine();
332 int space = line.find(" "); 332 int space = line.find(" ");
333 if(space > 1){ 333 if(space > 1){
334 // We have found an interface 334 // We have found an interface
335 QString interfaceName = line.mid(0, space); 335 QString interfaceName = line.mid(0, space);
336 Interface *i; 336 Interface *i;
337 // We have found an interface 337 // We have found an interface
338 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 338 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
339 // See if we already have it 339 // See if we already have it
340 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 340 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
341 if(fileName == TEMP_ALL) 341 if(fileName == TEMP_ALL)
342 i = new Interface(this, interfaceName, false); 342 i = new Interface(this, interfaceName, false);
343 else 343 else
344 i = new Interface(this, interfaceName, true); 344 i = new Interface(this, interfaceName, true);
345 i->setAttached(true); 345 i->setAttached(true);
346 346
347 QString hardName = "Ethernet"; 347 QString hardName = "Ethernet";
348 int hardwareName = line.find("Link encap:"); 348 int hardwareName = line.find("Link encap:");
349 int macAddress = line.find("HWaddr"); 349 int macAddress = line.find("HWaddr");
350 if(macAddress == -1) 350 if(macAddress == -1)
351 macAddress = line.length(); 351 macAddress = line.length();
352 if(hardwareName != -1) 352 if(hardwareName != -1)
353 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); 353 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) );
354 354
355 interfaceNames.insert(i->getInterfaceName(), i); 355 interfaceNames.insert(i->getInterfaceName(), i);
356 updateInterface(i); 356 updateInterface(i);
357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
358 } 358 }
359 // It was an interface we already had. 359 // It was an interface we already had.
360 else{ 360 else{
361 if(fileName != TEMP_ALL) 361 if(fileName != TEMP_ALL)
362 (interfaceNames[interfaceName])->setStatus(true); 362 (interfaceNames[interfaceName])->setStatus(true);
363 } 363 }
364 } 364 }
365 } 365 }
366 file.close(); 366 file.close();
367 QFile::remove(fileName); 367 QFile::remove(fileName);
368 368
369 if(threads.count() == 0){ 369 if(threads.count() == 0){
370 Interfaces i; 370 Interfaces i;
371 QStringList list = i.getInterfaceList(); 371 QStringList list = i.getInterfaceList();
372 QMap<QString, Interface*>::Iterator it; 372 QMap<QString, Interface*>::Iterator it;
373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
374 bool found = false; 374 bool found = false;
375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
376 if(it.key() == (*ni)) 376 if(it.key() == (*ni))
377 found = true; 377 found = true;
378 } 378 }
379 if(!found){ 379 if(!found){
380 Interface *i = new Interface(this, *ni, false); 380 if(!(*ni).contains("_")){
381 i->setAttached(false); 381 Interface *i = new Interface(this, *ni, false);
382 i->setHardwareName("Disconnected"); 382 i->setAttached(false);
383 interfaceNames.insert(i->getInterfaceName(), i); 383 i->setHardwareName("Disconnected");
384 updateInterface(i); 384 interfaceNames.insert(i->getInterfaceName(), i);
385 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 385 updateInterface(i);
386 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
387 }
386 } 388 }
387 } 389 }
388 } 390 }
389} 391}
390 392
391/** 393/**
392 * Update this interface. If no QListViewItem exists create one. 394 * Update this interface. If no QListViewItem exists create one.
393 * @param Interface* pointer to the interface that needs to be updated. 395 * @param Interface* pointer to the interface that needs to be updated.
394 */ 396 */
395void MainWindowImp::updateInterface(Interface *i){ 397void MainWindowImp::updateInterface(Interface *i){
396 if(!advancedUserMode){ 398 if(!advancedUserMode){
397 if(i->getInterfaceName() == "lo") 399 if(i->getInterfaceName() == "lo")
398 return; 400 return;
399 } 401 }
400 402
401 QListViewItem *item = NULL; 403 QListViewItem *item = NULL;
402 404
403 // Find the interface, making it if needed. 405 // Find the interface, making it if needed.
404 if(items.find(i) == items.end()){ 406 if(items.find(i) == items.end()){
405 item = new QListViewItem(connectionList, "", "", ""); 407 item = new QListViewItem(connectionList, "", "", "");
406 // See if you can't find a module owner for this interface 408 // See if you can't find a module owner for this interface
407 QMap<Module*, QLibrary*>::Iterator it; 409 QMap<Module*, QLibrary*>::Iterator it;
408 for( it = libraries.begin(); it != libraries.end(); ++it ){ 410 for( it = libraries.begin(); it != libraries.end(); ++it ){
409 if(it.key()->isOwner(i)) 411 if(it.key()->isOwner(i))
410 i->setModuleOwner(it.key()); 412 i->setModuleOwner(it.key());
411 } 413 }
412 items.insert(i, item); 414 items.insert(i, item);
413 interfaceItems.insert(item, i); 415 interfaceItems.insert(item, i);
414 } 416 }
415 else 417 else
416 item = items[i]; 418 item = items[i];
417 419
418 // Update the icons and information 420 // Update the icons and information
419 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 421 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
420 422
421 QString typeName = "lan"; 423 QString typeName = "lan";
422 if(i->getHardwareName().contains("Local Loopback")) 424 if(i->getHardwareName().contains("Local Loopback"))
423 typeName = "lo"; 425 typeName = "lo";
424 if(i->getInterfaceName().contains("irda")) 426 if(i->getInterfaceName().contains("irda"))
425 typeName = "irda"; 427 typeName = "irda";
426 if(i->getInterfaceName().contains("wlan")) 428 if(i->getInterfaceName().contains("wlan"))
427 typeName = "wlan"; 429 typeName = "wlan";
428 if(i->getInterfaceName().contains("usb")) 430 if(i->getInterfaceName().contains("usb"))
429 typeName = "usb"; 431 typeName = "usb";
430 432
431 if(!i->isAttached()) 433 if(!i->isAttached())
432 typeName = "connect_no"; 434 typeName = "connect_no";
433 // Actually try to use the Module 435 // Actually try to use the Module
434 if(i->getModuleOwner() != NULL) 436 if(i->getModuleOwner() != NULL)
435 typeName = i->getModuleOwner()->getPixmapName(i); 437 typeName = i->getModuleOwner()->getPixmapName(i);
436 438
437 item->setPixmap(1, (Resource::loadPixmap(typeName))); 439 item->setPixmap(1, (Resource::loadPixmap(typeName)));
438 item->setText(2, i->getHardwareName()); 440 item->setText(2, i->getHardwareName());
439 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 441 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
440 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 442 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
441} 443}
442 444
443void MainWindowImp::newProfileChanged(const QString& newText){ 445void MainWindowImp::newProfileChanged(const QString& newText){
444 if(newText.length() > 0) 446 if(newText.length() > 0)
445 newProfileButton->setEnabled(true); 447 newProfileButton->setEnabled(true);
446 else 448 else
447 newProfileButton->setEnabled(false); 449 newProfileButton->setEnabled(false);
448} 450}
449 451
450/** 452/**
451 * Adds a new profile to the list of profiles. 453 * Adds a new profile to the list of profiles.
452 * Don't add profiles that already exists. 454 * Don't add profiles that already exists.
453 * Appends to the list and QStringList 455 * Appends to the list and QStringList
454 */ 456 */
455void MainWindowImp::addProfile(){ 457void MainWindowImp::addProfile(){
456 QString newProfileName = newProfile->text(); 458 QString newProfileName = newProfile->text();
457 if(profiles.grep(newProfileName).count() > 0){ 459 if(profiles.grep(newProfileName).count() > 0){
458 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); 460 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
459 return; 461 return;
460 } 462 }
461 profiles.append(newProfileName); 463 profiles.append(newProfileName);
462 profilesList->insertItem(newProfileName); 464 profilesList->insertItem(newProfileName);
463} 465}
464 466
465/** 467/**
466 * Removes the currently selected profile in the combo. 468 * Removes the currently selected profile in the combo.
467 * Doesn't delete if there are less then 2 profiles. 469 * Doesn't delete if there are less then 2 profiles.
468 */ 470 */
469void MainWindowImp::removeProfile(){ 471void MainWindowImp::removeProfile(){
470 if(profilesList->count() <= 1){ 472 if(profilesList->count() <= 1){
471 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); 473 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
472 return; 474 return;
473 } 475 }
474 QString profileToRemove = profilesList->currentText(); 476 QString profileToRemove = profilesList->currentText();
475 if(profileToRemove == "All"){ 477 if(profileToRemove == "All"){
476 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); 478 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
477 return; 479 return;
478 } 480 }
479 // Can't remove the curent profile 481 // Can't remove the curent profile
480 if(profileToRemove == currentProfileLabel->text()){ 482 if(profileToRemove == currentProfileLabel->text()){
481 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); 483 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
482 return; 484 return;
483 485
484 } 486 }
485 487
486 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 488 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
487 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 489 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
488 profilesList->clear(); 490 profilesList->clear();
489 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 491 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
490 profilesList->insertItem((*it)); 492 profilesList->insertItem((*it));
491 } 493 }
494
495 // Remove any interface settings and mappings.
496 //TODO
492} 497}
493 498
494/** 499/**
495 * A new profile has been selected, change. 500 * A new profile has been selected, change.
496 * @param newProfile the new profile. 501 * @param newProfile the new profile.
497 */ 502 */
498void MainWindowImp::changeProfile(){ 503void MainWindowImp::changeProfile(){
499 if(profilesList->currentItem() == -1){ 504 if(profilesList->currentItem() == -1){
500 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); 505 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok");
501 return; 506 return;
502 } 507 }
503 QString newProfile = profilesList->text(profilesList->currentItem()); 508 QString newProfile = profilesList->text(profilesList->currentItem());
504 if(newProfile != currentProfileLabel->text()){ 509 if(newProfile != currentProfileLabel->text()){
505 currentProfileLabel->setText(newProfile); 510 currentProfileLabel->setText(newProfile);
511 QFile::remove(SCHEME);
506 QFile file(SCHEME); 512 QFile file(SCHEME);
507 if ( file.open(IO_ReadWrite) ) { 513 if ( file.open(IO_ReadWrite) ) {
508 QTextStream stream( &file ); 514 QTextStream stream( &file );
509 stream << QString("SCHEME=%1").arg(newProfile); 515 stream << QString("SCHEME=%1").arg(newProfile);
510 file.close(); 516 file.close();
511 } 517 }
512 // restart all up devices? 518 // restart all up devices?
513 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 519 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
514 // Go through them one by one 520 // Go through them one by one
515 QMap<Interface*, QListViewItem*>::Iterator it; 521 QMap<Interface*, QListViewItem*>::Iterator it;
516 for( it = items.begin(); it != items.end(); ++it ){ 522 for( it = items.begin(); it != items.end(); ++it ){
517 if(it.key()->getStatus() == true) 523 if(it.key()->getStatus() == true)
518 it.key()->restart(); 524 it.key()->restart();
519 } 525 }
520 } 526 }
521 } 527 }
522} 528}
523 529
524// mainwindowimp.cpp 530// mainwindowimp.cpp
525 531
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp
index eef42df..0927258 100644
--- a/noncore/settings/networksettings/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces.cpp
@@ -42,496 +42,536 @@ Interfaces::Interfaces(QString useInterfacesFile){
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)){ 54 if(line.contains(IFACE)){
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
171 * @param newInterface name of the new interface.
172 * @return bool true if successfull
173 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){
175 if(!setInterface(interface)) return false;
176
177 QStringList::Iterator it = currentIface;
178 it++;
179
180 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false;
183 QStringList::Iterator newIface = currentIface;
184 newIface++;
185
186 for ( it; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break;
189 newIface = interfaces.insert(newIface, *it);
190 }
191
192 return true;
193}
194
195/**
170 * Remove the currently selected interface and all of its options. 196 * Remove the currently selected interface and all of its options.
171 * @return bool if successfull or not. 197 * @return bool if successfull or not.
172 */ 198 */
173bool Interfaces::removeInterface(){ 199bool Interfaces::removeInterface(){
174 if(currentIface == interfaces.end()) 200 if(currentIface == interfaces.end())
175 return false; 201 return false;
176 (*currentIface) = ""; 202 (*currentIface) = "";
177 return removeAllInterfaceOptions(); 203 return removeAllInterfaceOptions();
178} 204}
179 205
180/** 206/**
181 * Gets the hardware name of the interface that is currently selected. 207 * Gets the hardware name of the interface that is currently selected.
182 * @return QString name of the hardware interface (eth0, usb2, wlan1...). 208 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
183 * @param error set to true if any error occurs, false otherwise. 209 * @param error set to true if any error occurs, false otherwise.
184 */ 210 */
185QString Interfaces::getInterfaceName(bool &error){ 211QString Interfaces::getInterfaceName(bool &error){
186 if(currentIface == interfaces.end()){ 212 if(currentIface == interfaces.end()){
187 error = true; 213 error = true;
188 return QString(); 214 return QString();
189 } 215 }
190 QString line = (*currentIface); 216 QString line = (*currentIface);
191 line = line.mid(QString(IFACE).length() +1, line.length()); 217 line = line.mid(QString(IFACE).length() +1, line.length());
192 line = line.simplifyWhiteSpace(); 218 line = line.simplifyWhiteSpace();
193 int findSpace = line.find(" "); 219 int findSpace = line.find(" ");
194 if( findSpace < 0){ 220 if( findSpace < 0){
195 error = true; 221 error = true;
196 return QString(); 222 return QString();
197 } 223 }
198 error = false; 224 error = false;
199 return line.mid(0, findSpace); 225 return line.mid(0, findSpace);
200} 226}
201 227
202/** 228/**
203 * Gets the family name of the interface that is currently selected. 229 * Gets the family name of the interface that is currently selected.
204 * @return QString name of the family (inet, inet6, ipx). 230 * @return QString name of the family (inet, inet6, ipx).
205 * @param error set to true if any error occurs, false otherwise. 231 * @param error set to true if any error occurs, false otherwise.
206 */ 232 */
207QString Interfaces::getInterfaceFamily(bool &error){ 233QString Interfaces::getInterfaceFamily(bool &error){
208 QString name = getInterfaceName(error); 234 QString name = getInterfaceName(error);
209 if(error){ 235 if(error){
210 error = true; 236 error = true;
211 return QString(); 237 return QString();
212 } 238 }
213 QString line = (*currentIface); 239 QString line = (*currentIface);
214 line = line.mid(QString(IFACE).length() +1, line.length()); 240 line = line.mid(QString(IFACE).length() +1, line.length());
215 line = line.mid(name.length()+1, line.length()); 241 line = line.mid(name.length()+1, line.length());
216 line = line.simplifyWhiteSpace(); 242 line = line.simplifyWhiteSpace();
217 int findSpace = line.find(" "); 243 int findSpace = line.find(" ");
218 if( findSpace < 0){ 244 if( findSpace < 0){
219 error = true; 245 error = true;
220 return QString(); 246 return QString();
221 } 247 }
222 error = false; 248 error = false;
223 return line.mid(0, findSpace); 249 return line.mid(0, findSpace);
224} 250}
225 251
226/** 252/**
227 * Gets the method of the interface that is currently selected. 253 * Gets the method of the interface that is currently selected.
228 * @return QString name of the method such as staic or dhcp. 254 * @return QString name of the method such as staic or dhcp.
229 * 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.
230 * @param error set to true if any error occurs, false otherwise. 256 * @param error set to true if any error occurs, false otherwise.
231 */ 257 */
232QString Interfaces::getInterfaceMethod(bool &error){ 258QString Interfaces::getInterfaceMethod(bool &error){
233 QString name = getInterfaceName(error); 259 QString name = getInterfaceName(error);
234 if(error){ 260 if(error){
235 error = true; 261 error = true;
236 return QString(); 262 return QString();
237 } 263 }
238 QString family = getInterfaceFamily(error); 264 QString family = getInterfaceFamily(error);
239 if(error){ 265 if(error){
240 error = true; 266 error = true;
241 return QString(); 267 return QString();
242 } 268 }
243 QString line = (*currentIface); 269 QString line = (*currentIface);
244 line = line.mid(QString(IFACE).length()+1, line.length()); 270 line = line.mid(QString(IFACE).length()+1, line.length());
245 line = line.mid(name.length()+1, line.length()); 271 line = line.mid(name.length()+1, line.length());
246 line = line.mid(family.length()+1, line.length()); 272 line = line.mid(family.length()+1, line.length());
247 line = line.simplifyWhiteSpace(); 273 line = line.simplifyWhiteSpace();
248 error = false; 274 error = false;
249 return line; 275 return line;
250} 276}
251 277
252/** 278/**
253 * Sets the interface name to newName. 279 * Sets the interface name to newName.
254 * @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.
255 * @return bool true if successfull. 281 * @return bool true if successfull.
256 */ 282 */
257bool Interfaces::setInterfaceName(QString newName){ 283bool Interfaces::setInterfaceName(QString newName){
258 if(currentIface == interfaces.end()) 284 if(currentIface == interfaces.end())
259 return false; 285 return false;
260 newName = newName.simplifyWhiteSpace(); 286 newName = newName.simplifyWhiteSpace();
261 newName = newName.replace(QRegExp(" "), ""); 287 newName = newName.replace(QRegExp(" "), "");
262 bool returnValue = false; 288 bool returnValue = false;
263 (*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));
264 return !returnValue; 290 return !returnValue;
265} 291}
266 292
267/** 293/**
268 * Sets the interface family to newName. 294 * Sets the interface family to newName.
269 * @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
270 * defined in the interfaces.h file. 296 * defined in the interfaces.h file.
271 * @return bool true if successfull. 297 * @return bool true if successfull.
272 */ 298 */
273bool Interfaces::setInterfaceFamily(QString newName){ 299bool Interfaces::setInterfaceFamily(QString newName){
274 if(currentIface == interfaces.end()) 300 if(currentIface == interfaces.end())
275 return false; 301 return false;
276 if(acceptedFamily.contains(newName)==0) 302 if(acceptedFamily.contains(newName)==0)
277 return false; 303 return false;
278 bool returnValue = false; 304 bool returnValue = false;
279 (*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));
280 return !returnValue; 306 return !returnValue;
281} 307}
282 308
283/** 309/**
284 * Sets the interface method to newName 310 * Sets the interface method to newName
285 * @param newName the new name of the interface 311 * @param newName the new name of the interface
286 * @return bool true if successfull. 312 * @return bool true if successfull.
287 */ 313 */
288bool Interfaces::setInterfaceMethod(QString newName){ 314bool Interfaces::setInterfaceMethod(QString newName){
289 if(currentIface == interfaces.end()) 315 if(currentIface == interfaces.end())
290 return false; 316 return false;
291 bool returnValue = false; 317 bool returnValue = false;
292 (*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);
293 return !returnValue; 319 return !returnValue;
294} 320}
295 321
296/** 322/**
297 * 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
298 * calling getInterfaceOption("address") on the following stanza would 324 * calling getInterfaceOption("address") on the following stanza would
299 * return 192.168.1.1. 325 * return 192.168.1.1.
300 * iface eth0 static 326 * iface eth0 static
301 * address 192.168.1.1 327 * address 192.168.1.1
302 * @param option the options to get the value. 328 * @param option the options to get the value.
303 * @param error set to true if any error occurs, false otherwise. 329 * @param error set to true if any error occurs, false otherwise.
304 * @return QString the options value. QString::null if error == true 330 * @return QString the options value. QString::null if error == true
305 */ 331 */
306QString Interfaces::getInterfaceOption(QString option, bool &error){ 332QString Interfaces::getInterfaceOption(QString option, bool &error){
307 return getOption(currentIface, option, error); 333 return getOption(currentIface, option, error);
308} 334}
309 335
310/** 336/**
311 * 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
312 * doesn't exist then it is added along with the value. If value is set to an 338 * doesn't exist then it is added along with the value. If value is set to an
313 * empty string then option is removed. 339 * empty string then option is removed.
314 * @param option the options to set the value. 340 * @param option the options to set the value.
315 * @param value the value that option should be set to. 341 * @param value the value that option should be set to.
316 * @param error set to true if any error occurs, false otherwise. 342 * @param error set to true if any error occurs, false otherwise.
317 * @return QString the options value. QString::null if error == true 343 * @return QString the options value. QString::null if error == true
318 */ 344 */
319bool Interfaces::setInterfaceOption(QString option, QString value){ 345bool Interfaces::setInterfaceOption(QString option, QString value){
320 return setOption(currentIface, option, value); 346 return setOption(currentIface, option, value);
321} 347}
322 348
323/** 349/**
324 * Removes all of the options from the currently selected interface. 350 * Removes all of the options from the currently selected interface.
325 * @return bool error if if successfull 351 * @return bool error if if successfull
326 */ 352 */
327bool Interfaces::removeAllInterfaceOptions(){ 353bool Interfaces::removeAllInterfaceOptions(){
328 return removeAllOptions(currentIface); 354 return removeAllOptions(currentIface);
329} 355}
330 356
331/** 357/**
332 * Set the current map to interface's map. This needs to be done before you 358 * Set the current map to interface's map. This needs to be done before you
333 * can call addMapping(), set/getMap(), and get/setScript(). 359 * can call addMapping(), set/getMap(), and get/setScript().
334 * @param interface the name of the interface to set. All whitespace is 360 * @param interface the name of the interface to set. All whitespace is
335 * removed from the interface name. 361 * removed from the interface name.
336 * @return bool true if it is successfull. 362 * @return bool true if it is successfull.
337 */ 363 */
338bool Interfaces::setMapping(QString interface){ 364bool Interfaces::setMapping(QString interface){
339 interface = interface.simplifyWhiteSpace(); 365 interface = interface.simplifyWhiteSpace();
340 interface = interface.replace(QRegExp(" "), ""); 366 interface = interface.replace(QRegExp(" "), "");
341 return setStanza(MAPPING, interface, currentMapping); 367 return setStanza(MAPPING, interface, currentMapping);
342} 368}
343 369
344/** 370/**
345 * Adds a new Mapping to the interfaces file with interfaces. 371 * Adds a new Mapping to the interfaces file with interfaces.
346 * @param interface the name(s) of the interfaces to set to this mapping 372 * @param interface the name(s) of the interfaces to set to this mapping
347 */ 373 */
348void Interfaces::addMapping(QString option){ 374void Interfaces::addMapping(QString option){
349 interfaces.append(""); 375 interfaces.append("");
350 interfaces.append(QString(MAPPING " %1").arg(option)); 376 interfaces.append(QString(MAPPING " %1").arg(option));
351} 377}
352 378
353/** 379/**
354 * Set a map option within a mapping. 380 * Set a map option within a mapping.
355 * @param map map to use 381 * @param map map to use
356 * @param value value to go with map 382 * @param value value to go with map
357 * @return bool true if it is successfull. 383 * @return bool true if it is successfull.
358 */ 384 */
359bool Interfaces::setMap(QString map, QString value){ 385bool Interfaces::setMap(QString map, QString value){
360 return setOption(currentMapping, map, value); 386 return setOption(currentMapping, map, value);
361} 387}
362 388
363/** 389/**
364 * Get a map value within a mapping. 390 * Get a map value within a mapping.
365 * @param map map to get value of 391 * @param map map to get value of
366 * @param bool true if it is successfull. 392 * @param bool true if it is successfull.
367 * @return value that goes to the map 393 * @return value that goes to the map
368 */ 394 */
369QString Interfaces::getMap(QString map, bool &error){ 395QString Interfaces::getMap(QString map, bool &error){
370 return getOption(currentMapping, map, error); 396 return getOption(currentMapping, map, error);
371} 397}
372 398
373/** 399/**
374 * Sets a script value of the current mapping to argument. 400 * Sets a script value of the current mapping to argument.
375 * @param argument the script name. 401 * @param argument the script name.
376 * @return true if successfull. 402 * @return true if successfull.
377 */ 403 */
378bool Interfaces::setScript(QString argument){ 404bool Interfaces::setScript(QString argument){
379 return setOption(currentMapping, "script", argument); 405 return setOption(currentMapping, "script", argument);
380} 406}
381 407
382/** 408/**
383 * @param error true if could not retrieve the current script argument. 409 * @param error true if could not retrieve the current script argument.
384 * @return QString the argument of the script for the current mapping. 410 * @return QString the argument of the script for the current mapping.
385 */ 411 */
386QString Interfaces::getScript(bool &error){ 412QString Interfaces::getScript(bool &error){
387 return getOption(currentMapping, "script", error); 413 return getOption(currentMapping, "script", error);
388} 414}
389 415
390/** 416/**
391 * Helper function used to parse through the QStringList and put pointers in 417 * Helper function used to parse through the QStringList and put pointers in
392 * the correct place. 418 * the correct place.
393 * @param stanza The stanza (auto, iface, mapping) to look for. 419 * @param stanza The stanza (auto, iface, mapping) to look for.
394 * @param option string that must be in the stanza's main line. 420 * @param option string that must be in the stanza's main line.
395 * @param interator interator to place at location of stanza if successfull. 421 * @param interator interator to place at location of stanza if successfull.
396 * @return bool true if the stanza is found. 422 * @return bool true if the stanza is found.
397 */ 423 */
398bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 424bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
399 bool found = false; 425 bool found = false;
400 iterator = interfaces.end(); 426 iterator = interfaces.end();
401 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 427 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
402 QString line = (*it).simplifyWhiteSpace(); 428 QString line = (*it).simplifyWhiteSpace();
403 if(line.contains(stanza) && line.contains(option)){ 429 if(line.contains(stanza) && line.contains(option)){
404 if(found == true){ 430 uint point = line.find(option);
405 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); 431 bool valid = true;
432 if(point > 0){
433 // There are more chars in the line. check +1
434 if(line.at(point-1) != ' ')
435 valid = false;
436 }
437 point += option.length();
438 if(point < line.length()-1){
439 // There are more chars in the line. check -1
440 if(line.at(point) != ' ')
441 valid = false;
442 }
443 if(valid){
444 if(found == true){
445 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
446 }
447 found = true;
448 iterator = it;
406 } 449 }
407 qDebug("Found");
408 found = true;
409 iterator = it;
410 } 450 }
411 } 451 }
412 return found; 452 return found;
413} 453}
414 454
415/** 455/**
416 * Sets a value of an option in a stanza 456 * Sets a value of an option in a stanza
417 * @param start the start of the stanza 457 * @param start the start of the stanza
418 * @param option the option to use when setting value. 458 * @param option the option to use when setting value.
419 * @return bool true if successfull, false otherwise. 459 * @return bool true if successfull, false otherwise.
420 */ 460 */
421bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 461bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
422 if(start == interfaces.end()) 462 if(start == interfaces.end())
423 return false; 463 return false;
424 464
425 bool found = false; 465 bool found = false;
426 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 466 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
427 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 467 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
428 if(!found && value != ""){ 468 if(!found && value != ""){
429 // Got to the end of the stanza without finding it, so append it. 469 // Got to the end of the stanza without finding it, so append it.
430 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 470 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
431 } 471 }
432 found = true; 472 found = true;
433 break; 473 break;
434 } 474 }
435 if((*it).contains(option) && it != start){ 475 if((*it).contains(option) && it != start){
436 // Found it in stanza so replace it. 476 // Found it in stanza so replace it.
437 if(found) 477 if(found)
438 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 478 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
439 found = true; 479 found = true;
440 if(value == "") 480 if(value == "")
441 (*it) = ""; 481 (*it) = "";
442 else 482 else
443 (*it) = QString("\t%1 %2").arg(option).arg(value); 483 (*it) = QString("\t%1 %2").arg(option).arg(value);
444 } 484 }
445 } 485 }
446 if(!found){ 486 if(!found){
447 QStringList::Iterator p = start; 487 QStringList::Iterator p = start;
448 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); 488 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
449 found = true; 489 found = true;
450 } 490 }
451 return found; 491 return found;
452} 492}
453 493
454/** 494/**
455 * Removes all options in a stanza 495 * Removes all options in a stanza
456 * @param start the start of the stanza 496 * @param start the start of the stanza
457 * @return bool true if successfull, false otherwise. 497 * @return bool true if successfull, false otherwise.
458 */ 498 */
459bool Interfaces::removeAllOptions(QStringList::Iterator start){ 499bool Interfaces::removeAllOptions(QStringList::Iterator start){
460 if(start == interfaces.end()) 500 if(start == interfaces.end())
461 return false; 501 return false;
462 502
463 QStringList::Iterator it = start; 503 QStringList::Iterator it = start;
464 it = ++it; 504 it = ++it;
465 for (it; it != interfaces.end(); ++it ) { 505 for (it; it != interfaces.end(); ++it ) {
466 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 506 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
467 break; 507 break;
468 } 508 }
469 it = interfaces.remove(it); 509 it = interfaces.remove(it);
470 it = --it; 510 it = --it;
471 } 511 }
472 // Leave a space between this interface and the next. 512 // Leave a space between this interface and the next.
473 interfaces.insert(it, QString("")); 513 interfaces.insert(it, QString(""));
474 return true; 514 return true;
475} 515}
476 516
477/** 517/**
478 * Gets a value of an option in a stanza 518 * Gets a value of an option in a stanza
479 * @param start the start of the stanza 519 * @param start the start of the stanza
480 * @param option the option to use when getting the value. 520 * @param option the option to use when getting the value.
481 * @param bool true if errors false otherwise. 521 * @param bool true if errors false otherwise.
482 * @return QString the value of option QString::null() if error == true. 522 * @return QString the value of option QString::null() if error == true.
483 */ 523 */
484QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ 524QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){
485 if(start == interfaces.end()){ 525 if(start == interfaces.end()){
486 error = false; 526 error = false;
487 return QString(); 527 return QString();
488 } 528 }
489 529
490 QString value; 530 QString value;
491 bool found = false; 531 bool found = false;
492 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 532 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
493 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){
494 break; 534 break;
495 } 535 }
496 if((*it).contains(option)){ 536 if((*it).contains(option)){
497 if(found) 537 if(found)
498 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 538 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
499 found = true; 539 found = true;
500 QString line = (*it).simplifyWhiteSpace(); 540 QString line = (*it).simplifyWhiteSpace();
501 int space = line.find(" ", option.length()); 541 int space = line.find(" ", option.length());
502 if(space != -1) 542 if(space != -1)
503 value = line.mid(space+1, line.length()); 543 value = line.mid(space+1, line.length());
504 else 544 else
505 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); 545 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1());
506 } 546 }
507 } 547 }
508 error = !found; 548 error = !found;
509 return value; 549 return value;
510} 550}
511 551
512/** 552/**
513 * Write out the interfaces file to the file passed into the constructor. 553 * Write out the interfaces file to the file passed into the constructor.
514 * Removes any excess blank lines over 1 line long. 554 * Removes any excess blank lines over 1 line long.
515 * @return bool true if successfull, false if not. 555 * @return bool true if successfull, false if not.
516 */ 556 */
517bool Interfaces::write(){ 557bool Interfaces::write(){
518 QFile::remove(interfacesFile); 558 QFile::remove(interfacesFile);
519 QFile file(interfacesFile); 559 QFile file(interfacesFile);
520 560
521 if (!file.open(IO_ReadWrite)){ 561 if (!file.open(IO_ReadWrite)){
522 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); 562 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
523 return false; 563 return false;
524 } 564 }
525 QTextStream stream( &file ); 565 QTextStream stream( &file );
526 int whiteSpaceCount = 0; 566 int whiteSpaceCount = 0;
527 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 567 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
528 QString line = (*it).simplifyWhiteSpace(); 568 QString line = (*it).simplifyWhiteSpace();
529 line = line.replace(QRegExp(" "),""); 569 line = line.replace(QRegExp(" "),"");
530 if(line.length() == 0) 570 if(line.length() == 0)
531 whiteSpaceCount++; 571 whiteSpaceCount++;
532 else 572 else
533 whiteSpaceCount = 0; 573 whiteSpaceCount = 0;
534 if(whiteSpaceCount < 2){ 574 if(whiteSpaceCount < 2){
535 qDebug((*it).latin1()); 575 qDebug((*it).latin1());
536 stream << (*it) << '\n'; 576 stream << (*it) << '\n';
537 } 577 }
diff --git a/noncore/settings/networksettings/interfaces.h b/noncore/settings/networksettings/interfaces.h
index e617c17..7cf04f0 100644
--- a/noncore/settings/networksettings/interfaces.h
+++ b/noncore/settings/networksettings/interfaces.h
@@ -1,71 +1,72 @@
1#ifndef INTERFACES_H 1#ifndef INTERFACES_H
2#define INTERFACES_H 2#define INTERFACES_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6 6
7#define INTERFACES_LOOPBACK "loopback" 7#define INTERFACES_LOOPBACK "loopback"
8 8
9#define INTERFACES_FAMILY_INET "inet" 9#define INTERFACES_FAMILY_INET "inet"
10#define INTERFACES_FAMILY_IPX "ipx" 10#define INTERFACES_FAMILY_IPX "ipx"
11#define INTERFACES_FAMILY_INET6 "inet6" 11#define INTERFACES_FAMILY_INET6 "inet6"
12 12
13#define INTERFACES_METHOD_DHCP "dhcp" 13#define INTERFACES_METHOD_DHCP "dhcp"
14#define INTERFACES_METHOD_STATIC "static" 14#define INTERFACES_METHOD_STATIC "static"
15#define INTERFACES_METHOD_PPP "ppp" 15#define INTERFACES_METHOD_PPP "ppp"
16 16
17/** 17/**
18 * This class provides a clean frontend for parsing the network interfaces file. 18 * This class provides a clean frontend for parsing the network interfaces file.
19 * It provides helper functions to minipulate the options within the file. 19 * It provides helper functions to minipulate the options within the file.
20 * See the interfaces man page for the syntax rules. 20 * See the interfaces man page for the syntax rules.
21 */ 21 */
22class Interfaces { 22class Interfaces {
23 23
24public: 24public:
25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); 25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
26 QStringList getInterfaceList(); 26 QStringList getInterfaceList();
27 27
28 bool isAuto(QString interface); 28 bool isAuto(QString interface);
29 bool setAuto(QString interface, bool setAuto); 29 bool setAuto(QString interface, bool setAuto);
30 30
31 bool removeInterface(); 31 bool removeInterface();
32 bool addInterface(QString interface, QString family, QString method); 32 bool addInterface(QString interface, QString family, QString method);
33 bool copyInterface(QString oldInterface, QString newInterface);
33 bool setInterface(QString interface); 34 bool setInterface(QString interface);
34 bool isInterfaceSet(); 35 bool isInterfaceSet();
35 QString getInterfaceName(bool &error); 36 QString getInterfaceName(bool &error);
36 bool setInterfaceName(QString newName); 37 bool setInterfaceName(QString newName);
37 QString getInterfaceFamily(bool &error); 38 QString getInterfaceFamily(bool &error);
38 bool setInterfaceFamily(QString newName); 39 bool setInterfaceFamily(QString newName);
39 QString getInterfaceMethod(bool &error); 40 QString getInterfaceMethod(bool &error);
40 bool setInterfaceMethod(QString newName); 41 bool setInterfaceMethod(QString newName);
41 QString getInterfaceOption(QString option, bool &error); 42 QString getInterfaceOption(QString option, bool &error);
42 bool setInterfaceOption(QString option, QString value); 43 bool setInterfaceOption(QString option, QString value);
43 bool removeAllInterfaceOptions(); 44 bool removeAllInterfaceOptions();
44 45
45 bool setMapping(QString interface); 46 bool setMapping(QString interface);
46 void addMapping(QString options); 47 void addMapping(QString options);
47 bool setMap(QString map, QString value); 48 bool setMap(QString map, QString value);
48 QString getMap(QString map, bool &error); 49 QString getMap(QString map, bool &error);
49 bool setScript(QString); 50 bool setScript(QString);
50 QString getScript(bool &error); 51 QString getScript(bool &error);
51 52
52 bool write(); 53 bool write();
53 54
54private: 55private:
55 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); 56 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
56 bool setOption(QStringList::Iterator start, QString option, QString value); 57 bool setOption(QStringList::Iterator start, QString option, QString value);
57 QString getOption(QStringList::Iterator start, QString option, bool &error); 58 QString getOption(QStringList::Iterator start, QString option, bool &error);
58 bool removeAllOptions(QStringList::Iterator start); 59 bool removeAllOptions(QStringList::Iterator start);
59 60
60 QString interfacesFile; 61 QString interfacesFile;
61 QStringList interfaces; 62 QStringList interfaces;
62 QStringList::Iterator currentIface; 63 QStringList::Iterator currentIface;
63 QStringList::Iterator currentMapping; 64 QStringList::Iterator currentMapping;
64 65
65 QStringList acceptedFamily; 66 QStringList acceptedFamily;
66}; 67};
67 68
68#endif 69#endif
69 70
70// interfaces 71// interfaces
71 72
diff --git a/noncore/settings/networksettings/interfacesetupimp.cpp b/noncore/settings/networksettings/interfacesetupimp.cpp
index c16d821..bdbdfde 100644
--- a/noncore/settings/networksettings/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfacesetupimp.cpp
@@ -1,143 +1,148 @@
1#include "interfacesetupimp.h" 1#include "interfacesetupimp.h"
2#include "interface.h" 2#include "interface.h"
3#include "interfaces.h" 3#include "interfaces.h"
4 4
5#include <qcombobox.h> 5#include <qcombobox.h>
6#include <qcheckbox.h> 6#include <qcheckbox.h>
7#include <qlineedit.h> 7#include <qlineedit.h>
8#include <qspinbox.h> 8#include <qspinbox.h>
9#include <qgroupbox.h> 9#include <qgroupbox.h>
10#include <qlabel.h> 10#include <qlabel.h>
11 11
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13 13
14#include <assert.h> 14#include <assert.h>
15 15
16#define DNSSCRIPT "interfacednsscript" 16#define DNSSCRIPT "interfacednsscript"
17 17
18/** 18/**
19 * Constuctor. Set up the connection and load the first profile. 19 * Constuctor. Set up the connection and load the first profile.
20 */ 20 */
21InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : InterfaceSetup(parent, name, modal, fl){ 21InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : InterfaceSetup(parent, name, modal, fl){
22 assert(i); 22 assert(i);
23 interface = i; 23 interface = i;
24 interfaces = new Interfaces(); 24 interfaces = new Interfaces();
25 bool error = false; 25 bool error = false;
26 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 26 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
27 staticGroupBox->hide(); 27 staticGroupBox->hide();
28 dhcpCheckBox->hide(); 28 dhcpCheckBox->hide();
29 leaseTime->hide(); 29 leaseTime->hide();
30 leaseHoursLabel->hide(); 30 leaseHoursLabel->hide();
31 } 31 }
32} 32}
33 33
34/** 34/**
35 * Save the current settings, then write out the interfaces file and close. 35 * Save the current settings, then write out the interfaces file and close.
36 */ 36 */
37void InterfaceSetupImp::accept(){ 37void InterfaceSetupImp::accept(){
38 if(!saveSettings()) 38 if(!saveSettings())
39 return; 39 return;
40 interfaces->write(); 40 interfaces->write();
41 close(true); 41 close(true);
42} 42}
43 43
44/** 44/**
45 * Save the settings for the current Interface. 45 * Save the settings for the current Interface.
46 * @return bool true if successfull, false otherwise 46 * @return bool true if successfull, false otherwise
47 */ 47 */
48bool InterfaceSetupImp::saveSettings(){ 48bool InterfaceSetupImp::saveSettings(){
49 // eh can't really do anything about it other then return. :-D 49 // eh can't really do anything about it other then return. :-D
50 if(!interfaces->isInterfaceSet()) 50 if(!interfaces->isInterfaceSet())
51 return true; 51 return true;
52 52
53 bool error = false; 53 bool error = false;
54 // Loopback case 54 // Loopback case
55 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 55 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
56 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 56 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
57 return true; 57 return true;
58 } 58 }
59 59
60 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ 60 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){
61 QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); 61 QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok");
62 return false; 62 return false;
63 } 63 }
64 interfaces->removeAllInterfaceOptions(); 64 interfaces->removeAllInterfaceOptions();
65 65
66 // DHCP 66 // DHCP
67 if(dhcpCheckBox->isChecked()){ 67 if(dhcpCheckBox->isChecked()){
68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); 69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); 70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
71 } 71 }
72 else{ 72 else{
73 interfaces->setInterfaceMethod("static"); 73 interfaces->setInterfaceMethod("static");
74 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 74 interfaces->setInterfaceOption("address", ipAddressEdit->text());
75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
76 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 76 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); 78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); 79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
80 } 80 }
81 81
82 // IP Information 82 // IP Information
83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
84 return true; 84 return true;
85} 85}
86 86
87/** 87/**
88 * The Profile has changed. 88 * The Profile has changed.
89 * @profile the new profile. 89 * @profile the new profile.
90 */ 90 */
91void InterfaceSetupImp::setProfile(const QString &profile){ 91void InterfaceSetupImp::setProfile(const QString &profile){
92 QString newInterfaceName = interface->getInterfaceName() + profile; 92 QString newInterfaceName = interface->getInterfaceName();
93 93 if(profile.length() > 0)
94 newInterfaceName += "_" + profile;
95 qDebug( newInterfaceName.latin1());
94 // See if we have to make a interface. 96 // See if we have to make a interface.
95 if(!interfaces->setInterface(newInterfaceName)){ 97 if(!interfaces->setInterface(newInterfaceName)){
96 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
97 if(!interfaces->setInterface(newInterfaceName)){
98 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
99 return;
100 }
101 // Add making for this new interface if need too 98 // Add making for this new interface if need too
102 if(profile != ""){ 99 if(profile != ""){
100 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
103 if(!interfaces->setMapping(interface->getInterfaceName())){ 101 if(!interfaces->setMapping(interface->getInterfaceName())){
104 interfaces->addMapping(interface->getInterfaceName()); 102 interfaces->addMapping(interface->getInterfaceName());
105 if(!interfaces->setMapping(interface->getInterfaceName())){ 103 if(!interfaces->setMapping(interface->getInterfaceName())){
106 qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); 104 qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
107 return; 105 return;
108 } 106 }
109 } 107 }
110 interfaces->setScript("getprofile.sh");
111 interfaces->setMap("map", newInterfaceName); 108 interfaces->setMap("map", newInterfaceName);
109 interfaces->setScript("getprofile.sh");
110 }
111 else{
112 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
113 if(!interfaces->setInterface(newInterfaceName)){
114 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
115 return;
116 }
112 } 117 }
113 } 118 }
114 119
115 // We must have a valid interface to get this far so read some settings. 120 // We must have a valid interface to get this far so read some settings.
116 121
117 // DHCP 122 // DHCP
118 bool error = false; 123 bool error = false;
119 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 124 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
120 dhcpCheckBox->setChecked(true); 125 dhcpCheckBox->setChecked(true);
121 else 126 else
122 dhcpCheckBox->setChecked(false); 127 dhcpCheckBox->setChecked(false);
123 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); 128 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
124 if(error) 129 if(error)
125 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); 130 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
126 if(error) 131 if(error)
127 leaseTime->setValue(24); 132 leaseTime->setValue(24);
128 133
129 // IP Information 134 // IP Information
130 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 135 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
131 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); 136 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
132 if(dns.contains(" ")){ 137 if(dns.contains(" ")){
133 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 138 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
134 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 139 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
135 } 140 }
136 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 141 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
137 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 142 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
138 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 143 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
139} 144}
140 145
141 146
142// interfacesetup.cpp 147// interfacesetup.cpp
143 148
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 3c0af6a..9f07f0d 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -103,423 +103,429 @@ void MainWindowImp::loadModules(QString path){
103 // Don't want sym links 103 // Don't want sym links
104 d.setFilter( QDir::Files | QDir::NoSymLinks ); 104 d.setFilter( QDir::Files | QDir::NoSymLinks );
105 const QFileInfoList *list = d.entryInfoList(); 105 const QFileInfoList *list = d.entryInfoList();
106 QFileInfoListIterator it( *list ); 106 QFileInfoListIterator it( *list );
107 QFileInfo *fi; 107 QFileInfo *fi;
108 while ( (fi=it.current()) ) { 108 while ( (fi=it.current()) ) {
109 if(fi->fileName().contains(".so")){ 109 if(fi->fileName().contains(".so")){
110 loadPlugin(path + "/" + fi->fileName()); 110 loadPlugin(path + "/" + fi->fileName());
111 } 111 }
112 ++it; 112 ++it;
113 } 113 }
114} 114}
115 115
116/** 116/**
117 * Attempt to load a function and resolve a function. 117 * Attempt to load a function and resolve a function.
118 * @param pluginFileName - the name of the file in which to attempt to load 118 * @param pluginFileName - the name of the file in which to attempt to load
119 * @param resolveString - function pointer to resolve 119 * @param resolveString - function pointer to resolve
120 * @return pointer to the function with name resolveString or NULL 120 * @return pointer to the function with name resolveString or NULL
121 */ 121 */
122Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ 122Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
123 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 123 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
124 QLibrary *lib = new QLibrary(pluginFileName); 124 QLibrary *lib = new QLibrary(pluginFileName);
125 void *functionPointer = lib->resolve(resolveString); 125 void *functionPointer = lib->resolve(resolveString);
126 if( !functionPointer ){ 126 if( !functionPointer ){
127 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 127 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
128 delete lib; 128 delete lib;
129 return NULL; 129 return NULL;
130 } 130 }
131 131
132 // Try to get an object. 132 // Try to get an object.
133 Module *object = ((Module* (*)()) functionPointer)(); 133 Module *object = ((Module* (*)()) functionPointer)();
134 if(object == NULL){ 134 if(object == NULL){
135 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 135 qDebug("MainWindowImp: Couldn't create object, but did load library!");
136 delete lib; 136 delete lib;
137 return NULL; 137 return NULL;
138 } 138 }
139 139
140 // Store for deletion later 140 // Store for deletion later
141 libraries.insert(object, lib); 141 libraries.insert(object, lib);
142 return object; 142 return object;
143} 143}
144 144
145/** 145/**
146 * The Add button was clicked. Bring up the add dialog and if OK is hit 146 * The Add button was clicked. Bring up the add dialog and if OK is hit
147 * load the plugin and append it to the list 147 * load the plugin and append it to the list
148 */ 148 */
149void MainWindowImp::addClicked(){ 149void MainWindowImp::addClicked(){
150 QMap<Module*, QLibrary*>::Iterator it; 150 QMap<Module*, QLibrary*>::Iterator it;
151 QMap<QString, QString> list; 151 QMap<QString, QString> list;
152 QMap<QString, Module*> newInterfaceOwners; 152 QMap<QString, Module*> newInterfaceOwners;
153 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 153 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
154 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 154 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
155 for( it = libraries.begin(); it != libraries.end(); ++it ){ 155 for( it = libraries.begin(); it != libraries.end(); ++it ){
156 if(it.key()){ 156 if(it.key()){
157 (it.key())->possibleNewInterfaces(list); 157 (it.key())->possibleNewInterfaces(list);
158 } 158 }
159 } 159 }
160 // See if the list has anything that we can add. 160 // See if the list has anything that we can add.
161 if(list.count() == 0){ 161 if(list.count() == 0){
162 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); 162 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
163 return; 163 return;
164 } 164 }
165 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 165 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
166 addNewConnection.addConnections(list); 166 addNewConnection.addConnections(list);
167 addNewConnection.showMaximized(); 167 addNewConnection.showMaximized();
168 if(QDialog::Accepted == addNewConnection.exec()){ 168 if(QDialog::Accepted == addNewConnection.exec()){
169 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 169 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
170 if(!item) 170 if(!item)
171 return; 171 return;
172 172
173 for( it = libraries.begin(); it != libraries.end(); ++it ){ 173 for( it = libraries.begin(); it != libraries.end(); ++it ){
174 if(it.key()){ 174 if(it.key()){
175 Interface *i = (it.key())->addNewInterface(item->text(0)); 175 Interface *i = (it.key())->addNewInterface(item->text(0));
176 if(i){ 176 if(i){
177 interfaceNames.insert(i->getInterfaceName(), i); 177 interfaceNames.insert(i->getInterfaceName(), i);
178 updateInterface(i); 178 updateInterface(i);
179 } 179 }
180 } 180 }
181 } 181 }
182 } 182 }
183} 183}
184 184
185/** 185/**
186 * Prompt the user to see if they really want to do this. 186 * Prompt the user to see if they really want to do this.
187 * If they do then remove from the list and unload. 187 * If they do then remove from the list and unload.
188 */ 188 */
189void MainWindowImp::removeClicked(){ 189void MainWindowImp::removeClicked(){
190 QListViewItem *item = connectionList->currentItem(); 190 QListViewItem *item = connectionList->currentItem();
191 if(!item) { 191 if(!item) {
192 QMessageBox::information(this, "Error","Please select an interface.", "Ok"); 192 QMessageBox::information(this, "Error","Please select an interface.", "Ok");
193 return; 193 return;
194 } 194 }
195 195
196 Interface *i = interfaceItems[item]; 196 Interface *i = interfaceItems[item];
197 if(i->getModuleOwner() == NULL){ 197 if(i->getModuleOwner() == NULL){
198 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); 198 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
199 } 199 }
200 else{ 200 else{
201 if(!i->getModuleOwner()->remove(i)) 201 if(!i->getModuleOwner()->remove(i))
202 QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); 202 QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
203 else{ 203 else{
204 QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); 204 QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
205 // TODO memory managment.... 205 // TODO memory managment....
206 // who deletes the interface? 206 // who deletes the interface?
207 } 207 }
208 } 208 }
209} 209}
210 210
211/** 211/**
212 * Pull up the configure about the currently selected interface. 212 * Pull up the configure about the currently selected interface.
213 * Report an error if no interface is selected. 213 * Report an error if no interface is selected.
214 * If the interface has a module owner then request its configure with a empty 214 * If the interface has a module owner then request its configure with a empty
215 * tab. If tab is !NULL then append the interfaces setup widget to it. 215 * tab. If tab is !NULL then append the interfaces setup widget to it.
216 */ 216 */
217void MainWindowImp::configureClicked(){ 217void MainWindowImp::configureClicked(){
218 QListViewItem *item = connectionList->currentItem(); 218 QListViewItem *item = connectionList->currentItem();
219 if(!item){ 219 if(!item){
220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
221 return; 221 return;
222 } 222 }
223 223
224 QString currentProfile = currentProfileLabel->text(); 224 QString currentProfile = currentProfileLabel->text();
225 if(profilesList->count() <= 1 || currentProfile == "All"){ 225 if(profilesList->count() <= 1 || currentProfile == "All"){
226 currentProfile = ""; 226 currentProfile = "";
227 } 227 }
228 228
229 Interface *i = interfaceItems[item]; 229 Interface *i = interfaceItems[item];
230 if(i->getModuleOwner()){ 230 if(i->getModuleOwner()){
231 i->getModuleOwner()->setProfile(currentProfileLabel->text()); 231 i->getModuleOwner()->setProfile(currentProfile);
232 QTabWidget *tabWidget = NULL; 232 QTabWidget *tabWidget = NULL;
233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
234 if(moduleConfigure != NULL){ 234 if(moduleConfigure != NULL){
235 if(tabWidget != NULL){ 235 if(tabWidget != NULL){
236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
237 configure->setProfile(currentProfileLabel->text()); 237 configure->setProfile(currentProfile);
238 tabWidget->insertTab(configure, "TCP/IP"); 238 tabWidget->insertTab(configure, "TCP/IP");
239 239
240 } 240 }
241 moduleConfigure->showMaximized(); 241 moduleConfigure->showMaximized();
242 moduleConfigure->show(); 242 moduleConfigure->show();
243 return; 243 return;
244 } 244 }
245 } 245 }
246 246
247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
248 configure->setProfile(currentProfileLabel->text()); 248 configure->setProfile(currentProfile);
249 configure->showMaximized(); 249 configure->showMaximized();
250 configure->show(); 250 configure->show();
251} 251}
252 252
253/** 253/**
254 * Pull up the information about the currently selected interface. 254 * Pull up the information about the currently selected interface.
255 * Report an error if no interface is selected. 255 * Report an error if no interface is selected.
256 * If the interface has a module owner then request its configure with a empty 256 * If the interface has a module owner then request its configure with a empty
257 * tab. If tab is !NULL then append the interfaces setup widget to it. 257 * tab. If tab is !NULL then append the interfaces setup widget to it.
258 */ 258 */
259void MainWindowImp::informationClicked(){ 259void MainWindowImp::informationClicked(){
260 QListViewItem *item = connectionList->currentItem(); 260 QListViewItem *item = connectionList->currentItem();
261 if(!item){ 261 if(!item){
262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
263 return; 263 return;
264 } 264 }
265 265
266 Interface *i = interfaceItems[item]; 266 Interface *i = interfaceItems[item];
267 if(!i->isAttached()){ 267 if(!i->isAttached()){
268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); 268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
269 return; 269 return;
270 } 270 }
271 271
272 QStringList list; 272 QStringList list;
273 for(uint i = 0; i < profilesList->count(); i++){ 273 for(uint i = 0; i < profilesList->count(); i++){
274 list.append(profilesList->text(i)); 274 list.append(profilesList->text(i));
275 } 275 }
276 276
277 if(i->getModuleOwner()){ 277 if(i->getModuleOwner()){
278 QTabWidget *tabWidget = NULL; 278 QTabWidget *tabWidget = NULL;
279 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 279 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
280 if(moduleInformation != NULL){ 280 if(moduleInformation != NULL){
281 if(tabWidget != NULL){ 281 if(tabWidget != NULL){
282 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 282 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
283 tabWidget->insertTab(information, "TCP/IP"); 283 tabWidget->insertTab(information, "TCP/IP");
284 } 284 }
285 moduleInformation->showMaximized(); 285 moduleInformation->showMaximized();
286 moduleInformation->show(); 286 moduleInformation->show();
287 return; 287 return;
288 } 288 }
289 } 289 }
290 290
291 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 291 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
292 information->showMaximized(); 292 information->showMaximized();
293 information->show(); 293 information->show();
294} 294}
295 295
296/** 296/**
297 * Aquire the list of active interfaces from ifconfig 297 * Aquire the list of active interfaces from ifconfig
298 * Call ifconfig and ifconfig -a 298 * Call ifconfig and ifconfig -a
299 */ 299 */
300void MainWindowImp::getInterfaceList(){ 300void MainWindowImp::getInterfaceList(){
301 KShellProcess *processAll = new KShellProcess(); 301 KShellProcess *processAll = new KShellProcess();
302 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 302 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
303 connect(processAll, SIGNAL(processExited(KProcess *)), 303 connect(processAll, SIGNAL(processExited(KProcess *)),
304 this, SLOT(jobDone(KProcess *))); 304 this, SLOT(jobDone(KProcess *)));
305 threads.insert(processAll, TEMP_ALL); 305 threads.insert(processAll, TEMP_ALL);
306 306
307 KShellProcess *process = new KShellProcess(); 307 KShellProcess *process = new KShellProcess();
308 *process << "/sbin/ifconfig" << " > " TEMP_UP; 308 *process << "/sbin/ifconfig" << " > " TEMP_UP;
309 connect(process, SIGNAL(processExited(KProcess *)), 309 connect(process, SIGNAL(processExited(KProcess *)),
310 this, SLOT(jobDone(KProcess *))); 310 this, SLOT(jobDone(KProcess *)));
311 threads.insert(process, TEMP_UP); 311 threads.insert(process, TEMP_UP);
312 312
313 processAll->start(KShellProcess::NotifyOnExit); 313 processAll->start(KShellProcess::NotifyOnExit);
314 process->start(KShellProcess::NotifyOnExit); 314 process->start(KShellProcess::NotifyOnExit);
315} 315}
316 316
317void MainWindowImp::jobDone(KProcess *process){ 317void MainWindowImp::jobDone(KProcess *process){
318 QString fileName = threads[process]; 318 QString fileName = threads[process];
319 threads.remove(process); 319 threads.remove(process);
320 delete process; 320 delete process;
321 321
322 QFile file(fileName); 322 QFile file(fileName);
323 if (!file.open(IO_ReadOnly)){ 323 if (!file.open(IO_ReadOnly)){
324 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 324 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
325 return; 325 return;
326 } 326 }
327 327
328 QTextStream stream( &file ); 328 QTextStream stream( &file );
329 QString line; 329 QString line;
330 while ( !stream.eof() ) { 330 while ( !stream.eof() ) {
331 line = stream.readLine(); 331 line = stream.readLine();
332 int space = line.find(" "); 332 int space = line.find(" ");
333 if(space > 1){ 333 if(space > 1){
334 // We have found an interface 334 // We have found an interface
335 QString interfaceName = line.mid(0, space); 335 QString interfaceName = line.mid(0, space);
336 Interface *i; 336 Interface *i;
337 // We have found an interface 337 // We have found an interface
338 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 338 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
339 // See if we already have it 339 // See if we already have it
340 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 340 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
341 if(fileName == TEMP_ALL) 341 if(fileName == TEMP_ALL)
342 i = new Interface(this, interfaceName, false); 342 i = new Interface(this, interfaceName, false);
343 else 343 else
344 i = new Interface(this, interfaceName, true); 344 i = new Interface(this, interfaceName, true);
345 i->setAttached(true); 345 i->setAttached(true);
346 346
347 QString hardName = "Ethernet"; 347 QString hardName = "Ethernet";
348 int hardwareName = line.find("Link encap:"); 348 int hardwareName = line.find("Link encap:");
349 int macAddress = line.find("HWaddr"); 349 int macAddress = line.find("HWaddr");
350 if(macAddress == -1) 350 if(macAddress == -1)
351 macAddress = line.length(); 351 macAddress = line.length();
352 if(hardwareName != -1) 352 if(hardwareName != -1)
353 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); 353 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) );
354 354
355 interfaceNames.insert(i->getInterfaceName(), i); 355 interfaceNames.insert(i->getInterfaceName(), i);
356 updateInterface(i); 356 updateInterface(i);
357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
358 } 358 }
359 // It was an interface we already had. 359 // It was an interface we already had.
360 else{ 360 else{
361 if(fileName != TEMP_ALL) 361 if(fileName != TEMP_ALL)
362 (interfaceNames[interfaceName])->setStatus(true); 362 (interfaceNames[interfaceName])->setStatus(true);
363 } 363 }
364 } 364 }
365 } 365 }
366 file.close(); 366 file.close();
367 QFile::remove(fileName); 367 QFile::remove(fileName);
368 368
369 if(threads.count() == 0){ 369 if(threads.count() == 0){
370 Interfaces i; 370 Interfaces i;
371 QStringList list = i.getInterfaceList(); 371 QStringList list = i.getInterfaceList();
372 QMap<QString, Interface*>::Iterator it; 372 QMap<QString, Interface*>::Iterator it;
373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
374 bool found = false; 374 bool found = false;
375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
376 if(it.key() == (*ni)) 376 if(it.key() == (*ni))
377 found = true; 377 found = true;
378 } 378 }
379 if(!found){ 379 if(!found){
380 Interface *i = new Interface(this, *ni, false); 380 if(!(*ni).contains("_")){
381 i->setAttached(false); 381 Interface *i = new Interface(this, *ni, false);
382 i->setHardwareName("Disconnected"); 382 i->setAttached(false);
383 interfaceNames.insert(i->getInterfaceName(), i); 383 i->setHardwareName("Disconnected");
384 updateInterface(i); 384 interfaceNames.insert(i->getInterfaceName(), i);
385 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 385 updateInterface(i);
386 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
387 }
386 } 388 }
387 } 389 }
388 } 390 }
389} 391}
390 392
391/** 393/**
392 * Update this interface. If no QListViewItem exists create one. 394 * Update this interface. If no QListViewItem exists create one.
393 * @param Interface* pointer to the interface that needs to be updated. 395 * @param Interface* pointer to the interface that needs to be updated.
394 */ 396 */
395void MainWindowImp::updateInterface(Interface *i){ 397void MainWindowImp::updateInterface(Interface *i){
396 if(!advancedUserMode){ 398 if(!advancedUserMode){
397 if(i->getInterfaceName() == "lo") 399 if(i->getInterfaceName() == "lo")
398 return; 400 return;
399 } 401 }
400 402
401 QListViewItem *item = NULL; 403 QListViewItem *item = NULL;
402 404
403 // Find the interface, making it if needed. 405 // Find the interface, making it if needed.
404 if(items.find(i) == items.end()){ 406 if(items.find(i) == items.end()){
405 item = new QListViewItem(connectionList, "", "", ""); 407 item = new QListViewItem(connectionList, "", "", "");
406 // See if you can't find a module owner for this interface 408 // See if you can't find a module owner for this interface
407 QMap<Module*, QLibrary*>::Iterator it; 409 QMap<Module*, QLibrary*>::Iterator it;
408 for( it = libraries.begin(); it != libraries.end(); ++it ){ 410 for( it = libraries.begin(); it != libraries.end(); ++it ){
409 if(it.key()->isOwner(i)) 411 if(it.key()->isOwner(i))
410 i->setModuleOwner(it.key()); 412 i->setModuleOwner(it.key());
411 } 413 }
412 items.insert(i, item); 414 items.insert(i, item);
413 interfaceItems.insert(item, i); 415 interfaceItems.insert(item, i);
414 } 416 }
415 else 417 else
416 item = items[i]; 418 item = items[i];
417 419
418 // Update the icons and information 420 // Update the icons and information
419 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 421 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
420 422
421 QString typeName = "lan"; 423 QString typeName = "lan";
422 if(i->getHardwareName().contains("Local Loopback")) 424 if(i->getHardwareName().contains("Local Loopback"))
423 typeName = "lo"; 425 typeName = "lo";
424 if(i->getInterfaceName().contains("irda")) 426 if(i->getInterfaceName().contains("irda"))
425 typeName = "irda"; 427 typeName = "irda";
426 if(i->getInterfaceName().contains("wlan")) 428 if(i->getInterfaceName().contains("wlan"))
427 typeName = "wlan"; 429 typeName = "wlan";
428 if(i->getInterfaceName().contains("usb")) 430 if(i->getInterfaceName().contains("usb"))
429 typeName = "usb"; 431 typeName = "usb";
430 432
431 if(!i->isAttached()) 433 if(!i->isAttached())
432 typeName = "connect_no"; 434 typeName = "connect_no";
433 // Actually try to use the Module 435 // Actually try to use the Module
434 if(i->getModuleOwner() != NULL) 436 if(i->getModuleOwner() != NULL)
435 typeName = i->getModuleOwner()->getPixmapName(i); 437 typeName = i->getModuleOwner()->getPixmapName(i);
436 438
437 item->setPixmap(1, (Resource::loadPixmap(typeName))); 439 item->setPixmap(1, (Resource::loadPixmap(typeName)));
438 item->setText(2, i->getHardwareName()); 440 item->setText(2, i->getHardwareName());
439 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 441 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
440 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 442 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
441} 443}
442 444
443void MainWindowImp::newProfileChanged(const QString& newText){ 445void MainWindowImp::newProfileChanged(const QString& newText){
444 if(newText.length() > 0) 446 if(newText.length() > 0)
445 newProfileButton->setEnabled(true); 447 newProfileButton->setEnabled(true);
446 else 448 else
447 newProfileButton->setEnabled(false); 449 newProfileButton->setEnabled(false);
448} 450}
449 451
450/** 452/**
451 * Adds a new profile to the list of profiles. 453 * Adds a new profile to the list of profiles.
452 * Don't add profiles that already exists. 454 * Don't add profiles that already exists.
453 * Appends to the list and QStringList 455 * Appends to the list and QStringList
454 */ 456 */
455void MainWindowImp::addProfile(){ 457void MainWindowImp::addProfile(){
456 QString newProfileName = newProfile->text(); 458 QString newProfileName = newProfile->text();
457 if(profiles.grep(newProfileName).count() > 0){ 459 if(profiles.grep(newProfileName).count() > 0){
458 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); 460 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
459 return; 461 return;
460 } 462 }
461 profiles.append(newProfileName); 463 profiles.append(newProfileName);
462 profilesList->insertItem(newProfileName); 464 profilesList->insertItem(newProfileName);
463} 465}
464 466
465/** 467/**
466 * Removes the currently selected profile in the combo. 468 * Removes the currently selected profile in the combo.
467 * Doesn't delete if there are less then 2 profiles. 469 * Doesn't delete if there are less then 2 profiles.
468 */ 470 */
469void MainWindowImp::removeProfile(){ 471void MainWindowImp::removeProfile(){
470 if(profilesList->count() <= 1){ 472 if(profilesList->count() <= 1){
471 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); 473 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
472 return; 474 return;
473 } 475 }
474 QString profileToRemove = profilesList->currentText(); 476 QString profileToRemove = profilesList->currentText();
475 if(profileToRemove == "All"){ 477 if(profileToRemove == "All"){
476 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); 478 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
477 return; 479 return;
478 } 480 }
479 // Can't remove the curent profile 481 // Can't remove the curent profile
480 if(profileToRemove == currentProfileLabel->text()){ 482 if(profileToRemove == currentProfileLabel->text()){
481 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); 483 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
482 return; 484 return;
483 485
484 } 486 }
485 487
486 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 488 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
487 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 489 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
488 profilesList->clear(); 490 profilesList->clear();
489 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 491 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
490 profilesList->insertItem((*it)); 492 profilesList->insertItem((*it));
491 } 493 }
494
495 // Remove any interface settings and mappings.
496 //TODO
492} 497}
493 498
494/** 499/**
495 * A new profile has been selected, change. 500 * A new profile has been selected, change.
496 * @param newProfile the new profile. 501 * @param newProfile the new profile.
497 */ 502 */
498void MainWindowImp::changeProfile(){ 503void MainWindowImp::changeProfile(){
499 if(profilesList->currentItem() == -1){ 504 if(profilesList->currentItem() == -1){
500 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); 505 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok");
501 return; 506 return;
502 } 507 }
503 QString newProfile = profilesList->text(profilesList->currentItem()); 508 QString newProfile = profilesList->text(profilesList->currentItem());
504 if(newProfile != currentProfileLabel->text()){ 509 if(newProfile != currentProfileLabel->text()){
505 currentProfileLabel->setText(newProfile); 510 currentProfileLabel->setText(newProfile);
511 QFile::remove(SCHEME);
506 QFile file(SCHEME); 512 QFile file(SCHEME);
507 if ( file.open(IO_ReadWrite) ) { 513 if ( file.open(IO_ReadWrite) ) {
508 QTextStream stream( &file ); 514 QTextStream stream( &file );
509 stream << QString("SCHEME=%1").arg(newProfile); 515 stream << QString("SCHEME=%1").arg(newProfile);
510 file.close(); 516 file.close();
511 } 517 }
512 // restart all up devices? 518 // restart all up devices?
513 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 519 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
514 // Go through them one by one 520 // Go through them one by one
515 QMap<Interface*, QListViewItem*>::Iterator it; 521 QMap<Interface*, QListViewItem*>::Iterator it;
516 for( it = items.begin(); it != items.end(); ++it ){ 522 for( it = items.begin(); it != items.end(); ++it ){
517 if(it.key()->getStatus() == true) 523 if(it.key()->getStatus() == true)
518 it.key()->restart(); 524 it.key()->restart();
519 } 525 }
520 } 526 }
521 } 527 }
522} 528}
523 529
524// mainwindowimp.cpp 530// mainwindowimp.cpp
525 531