summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interface.cpp4
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp10
-rw-r--r--noncore/net/networksetup/wlan/wlanimp.cpp8
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp4
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp10
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.cpp8
6 files changed, 18 insertions, 26 deletions
diff --git a/noncore/net/networksetup/interfaces/interface.cpp b/noncore/net/networksetup/interfaces/interface.cpp
index 7ffa76f..d964961 100644
--- a/noncore/net/networksetup/interfaces/interface.cpp
+++ b/noncore/net/networksetup/interfaces/interface.cpp
@@ -1,297 +1,297 @@
1#include "interface.h" 1#include "interface.h"
2#include <qdatetime.h> 2#include <qdatetime.h>
3#include <qfile.h> 3#include <qfile.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfileinfo.h> 5#include <qfileinfo.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7 7
8#define IFCONFIG "/sbin/ifconfig" 8#define IFCONFIG "/sbin/ifconfig"
9#define DHCP_INFO_DIR "/etc/dhcpc" 9#define DHCP_INFO_DIR "/etc/dhcpc"
10 10
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13 13
14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ 14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){
15 refresh(); 15 refresh();
16} 16}
17 17
18/** 18/**
19 * Set status 19 * Set status
20 * @param newStatus - the new status 20 * @param newStatus - the new status
21 * emit updateInterface 21 * emit updateInterface
22 */ 22 */
23void Interface::setStatus(bool newStatus){ 23void Interface::setStatus(bool newStatus){
24 if(status != newStatus){ 24 if(status != newStatus){
25 status = newStatus; 25 status = newStatus;
26 refresh(); 26 refresh();
27 } 27 }
28}; 28};
29 29
30/** 30/**
31 * Set if attached or not (802.11 card pulled out for example) 31 * Set if attached or not (802.11 card pulled out for example)
32 * @param isAttached - if attached 32 * @param isAttached - if attached
33 * emit updateInterface 33 * emit updateInterface
34 */ 34 */
35void Interface::setAttached(bool isAttached){ 35void Interface::setAttached(bool isAttached){
36 attached = isAttached; 36 attached = isAttached;
37 emit(updateInterface(this)); 37 emit(updateInterface(this));
38}; 38};
39 39
40/** 40/**
41 * Set Hardware name 41 * Set Hardware name
42 * @param name - the new name 42 * @param name - the new name
43 * emit updateInterface 43 * emit updateInterface
44 */ 44 */
45void Interface::setHardwareName(const QString &name){ 45void Interface::setHardwareName(const QString &name){
46 hardwareName = name; 46 hardwareName = name;
47 emit(updateInterface(this)); 47 emit(updateInterface(this));
48}; 48};
49 49
50/** 50/**
51 * Set Module owner 51 * Set Module owner
52 * @param owner - the new owner 52 * @param owner - the new owner
53 * emit updateInterface 53 * emit updateInterface
54 */ 54 */
55void Interface::setModuleOwner(Module *owner){ 55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner; 56 moduleOwner = owner;
57 emit(updateInterface(this)); 57 emit(updateInterface(this));
58}; 58};
59 59
60 60
61/** 61/**
62 * Try to start the interface. 62 * Try to start the interface.
63 */ 63 */
64void Interface::start(){ 64void Interface::start(){
65 // check to see if we are already running. 65 // check to see if we are already running.
66 if(true == status){ 66 if(true == status){
67 emit (updateMessage("Unable to start interface,\n already started")); 67 emit (updateMessage("Unable to start interface,\n already started"));
68 return; 68 return;
69 } 69 }
70 70
71 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 71 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
72 // See if it was successfull... 72 // See if it was successfull...
73 if(ret != 0){ 73 if(ret != 0){
74 emit (updateMessage("Starting interface failed.")); 74 emit (updateMessage("Starting interface failed"));
75 return; 75 return;
76 } 76 }
77 77
78 status = true; 78 status = true;
79 refresh(); 79 refresh();
80 emit (updateMessage("Start successfull")); 80 emit (updateMessage("Start successfull"));
81} 81}
82 82
83/** 83/**
84 * Try to stop the interface. 84 * Try to stop the interface.
85 */ 85 */
86void Interface::stop(){ 86void Interface::stop(){
87 // check to see if we are already stopped. 87 // check to see if we are already stopped.
88 if(false == status){ 88 if(false == status){
89 emit (updateMessage("Unable to stop interface,\n already stopped")); 89 emit (updateMessage("Unable to stop interface,\n already stopped"));
90 return; 90 return;
91 } 91 }
92 92
93 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 93 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
94 if(ret != 0){ 94 if(ret != 0){
95 emit (updateMessage("Stopping interface failed.")); 95 emit (updateMessage("Stopping interface failed"));
96 return; 96 return;
97 } 97 }
98 98
99 status = false; 99 status = false;
100 refresh(); 100 refresh();
101 emit (updateMessage("Stop successfull")); 101 emit (updateMessage("Stop successfull"));
102} 102}
103 103
104/** 104/**
105 * Try to restart the interface. 105 * Try to restart the interface.
106 */ 106 */
107void Interface::restart(){ 107void Interface::restart(){
108 stop(); 108 stop();
109 start(); 109 start();
110} 110}
111 111
112/** 112/**
113 * Try to refresh the information about the interface. 113 * Try to refresh the information about the interface.
114 * First call ifconfig, then check the dhcp-info file 114 * First call ifconfig, then check the dhcp-info file
115 * @return bool true if successfull. 115 * @return bool true if successfull.
116 */ 116 */
117bool Interface::refresh(){ 117bool Interface::refresh(){
118 // See if we are up. 118 // See if we are up.
119 if(status == false){ 119 if(status == false){
120 macAddress = ""; 120 macAddress = "";
121 ip = "0.0.0.0"; 121 ip = "0.0.0.0";
122 subnetMask = "0.0.0.0"; 122 subnetMask = "0.0.0.0";
123 broadcast = ""; 123 broadcast = "";
124 dhcp = false; 124 dhcp = false;
125 dhcpServerIp = ""; 125 dhcpServerIp = "";
126 leaseObtained = ""; 126 leaseObtained = "";
127 leaseExpires = ""; 127 leaseExpires = "";
128 emit(updateInterface(this)); 128 emit(updateInterface(this));
129 return true; 129 return true;
130 } 130 }
131 131
132 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 132 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
133 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 133 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
134 if(ret != 0){ 134 if(ret != 0){
135 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 135 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
136 return false; 136 return false;
137 } 137 }
138 138
139 QFile file(fileName); 139 QFile file(fileName);
140 if (!file.open(IO_ReadOnly)){ 140 if (!file.open(IO_ReadOnly)){
141 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 141 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
142 return false; 142 return false;
143 } 143 }
144 144
145 // Set to the defaults 145 // Set to the defaults
146 macAddress = ""; 146 macAddress = "";
147 ip = "0.0.0.0"; 147 ip = "0.0.0.0";
148 subnetMask = "0.0.0.0"; 148 subnetMask = "0.0.0.0";
149 broadcast = ""; 149 broadcast = "";
150 150
151 QTextStream stream( &file ); 151 QTextStream stream( &file );
152 QString line; 152 QString line;
153 while ( !stream.eof() ) { 153 while ( !stream.eof() ) {
154 line = stream.readLine(); 154 line = stream.readLine();
155 if(line.contains("HWaddr")){ 155 if(line.contains("HWaddr")){
156 int mac = line.find("HWaddr"); 156 int mac = line.find("HWaddr");
157 macAddress = line.mid(mac+7, line.length()); 157 macAddress = line.mid(mac+7, line.length());
158 } 158 }
159 if(line.contains("inet addr")){ 159 if(line.contains("inet addr")){
160 int ipl = line.find("inet addr"); 160 int ipl = line.find("inet addr");
161 int space = line.find(" ", ipl+10); 161 int space = line.find(" ", ipl+10);
162 ip = line.mid(ipl+10, space-ipl-10); 162 ip = line.mid(ipl+10, space-ipl-10);
163 } 163 }
164 if(line.contains("Mask")){ 164 if(line.contains("Mask")){
165 int mask = line.find("Mask"); 165 int mask = line.find("Mask");
166 subnetMask = line.mid(mask+5, line.length()); 166 subnetMask = line.mid(mask+5, line.length());
167 } 167 }
168 if(line.contains("Bcast")){ 168 if(line.contains("Bcast")){
169 int mask = line.find("Bcast"); 169 int mask = line.find("Bcast");
170 int space = line.find(" ", mask+6); 170 int space = line.find(" ", mask+6);
171 broadcast = line.mid(mask+6, space-mask-6); 171 broadcast = line.mid(mask+6, space-mask-6);
172 } 172 }
173 } 173 }
174 file.close(); 174 file.close();
175 QFile::remove(fileName); 175 QFile::remove(fileName);
176 176
177 // DHCP TESTING 177 // DHCP TESTING
178 // reset DHCP info 178 // reset DHCP info
179 dhcpServerIp = ""; 179 dhcpServerIp = "";
180 leaseObtained = ""; 180 leaseObtained = "";
181 leaseExpires = ""; 181 leaseExpires = "";
182 dhcp = false; 182 dhcp = false;
183 183
184 QString dhcpDirectory(DHCP_INFO_DIR); 184 QString dhcpDirectory(DHCP_INFO_DIR);
185 QDir d(dhcpDirectory); 185 QDir d(dhcpDirectory);
186 if(!d.exists(dhcpDirectory)) 186 if(!d.exists(dhcpDirectory))
187 dhcpDirectory = "/var/run"; 187 dhcpDirectory = "/var/run";
188 188
189 // See if we have 189 // See if we have
190 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 190 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
191 // If there is no DHCP information then exit now with no errors. 191 // If there is no DHCP information then exit now with no errors.
192 if(!QFile::exists(dhcpFile)){ 192 if(!QFile::exists(dhcpFile)){
193 emit(updateInterface(this)); 193 emit(updateInterface(this));
194 return true; 194 return true;
195 } 195 }
196 196
197 file.setName(dhcpFile); 197 file.setName(dhcpFile);
198 if (!file.open(IO_ReadOnly)){ 198 if (!file.open(IO_ReadOnly)){
199 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 199 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
200 return false; 200 return false;
201 } 201 }
202 202
203 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 203 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
204 int leaseTime = 0; 204 int leaseTime = 0;
205 int renewalTime = 0; 205 int renewalTime = 0;
206 206
207 stream.setDevice( &file ); 207 stream.setDevice( &file );
208 while ( !stream.eof() ) { 208 while ( !stream.eof() ) {
209 line = stream.readLine(); 209 line = stream.readLine();
210 if(line.contains("DHCPSIADDR=")) 210 if(line.contains("DHCPSIADDR="))
211 dhcpServerIp = line.mid(11, line.length()); 211 dhcpServerIp = line.mid(11, line.length());
212 if(line.contains("LEASETIME=")) 212 if(line.contains("LEASETIME="))
213 leaseTime = line.mid(10, line.length()).toInt(); 213 leaseTime = line.mid(10, line.length()).toInt();
214 if(line.contains("RENEWALTIME=")) 214 if(line.contains("RENEWALTIME="))
215 renewalTime = line.mid(12, line.length()).toInt(); 215 renewalTime = line.mid(12, line.length()).toInt();
216 } 216 }
217 file.close(); 217 file.close();
218 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 218 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
219 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 219 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
220 220
221 // Get the pid of the deamond 221 // Get the pid of the deamond
222 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 222 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
223 file.setName(dhcpFile); 223 file.setName(dhcpFile);
224 if (!file.open(IO_ReadOnly)){ 224 if (!file.open(IO_ReadOnly)){
225 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 225 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
226 return false; 226 return false;
227 } 227 }
228 228
229 int pid = -1; 229 int pid = -1;
230 stream.setDevice( &file ); 230 stream.setDevice( &file );
231 while ( !stream.eof() ) { 231 while ( !stream.eof() ) {
232 line = stream.readLine(); 232 line = stream.readLine();
233 pid = line.toInt(); 233 pid = line.toInt();
234 } 234 }
235 file.close(); 235 file.close();
236 236
237 if( pid == -1){ 237 if( pid == -1){
238 qDebug("Interface: Could not get pid of dhcpc deamon."); 238 qDebug("Interface: Could not get pid of dhcpc deamon.");
239 return false; 239 return false;
240 } 240 }
241 241
242 // Get the start running time of the deamon 242 // Get the start running time of the deamon
243 fileName = (QString("/proc/%1/stat").arg(pid)); 243 fileName = (QString("/proc/%1/stat").arg(pid));
244 file.setName(fileName); 244 file.setName(fileName);
245 stream.setDevice( &file ); 245 stream.setDevice( &file );
246 if (!file.open(IO_ReadOnly)){ 246 if (!file.open(IO_ReadOnly)){
247 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 247 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
248 return false; 248 return false;
249 } 249 }
250 while ( !stream.eof() ) { 250 while ( !stream.eof() ) {
251 line = stream.readLine(); 251 line = stream.readLine();
252 } 252 }
253 file.close(); 253 file.close();
254 long time = 0; 254 long time = 0;
255 // Grab the start time 255 // Grab the start time
256 // pid com state ppid pgrp session tty_nr tpgid flags 256 // pid com state ppid pgrp session tty_nr tpgid flags
257 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 257 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
258 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 258 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
259 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 259 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
260 // nice 0 itrealvalue starttime 260 // nice 0 itrealvalue starttime
261 "%*d %*d %*d %lu", (long*) &time); 261 "%*d %*d %*d %lu", (long*) &time);
262 time = time/100; 262 time = time/100;
263 263
264 QDateTime datetime(QDateTime::currentDateTime()); 264 QDateTime datetime(QDateTime::currentDateTime());
265 265
266 // Get the uptime of the computer. 266 // Get the uptime of the computer.
267 QFile f("/proc/uptime"); 267 QFile f("/proc/uptime");
268 if ( f.open(IO_ReadOnly) ) { // file opened successfully 268 if ( f.open(IO_ReadOnly) ) { // file opened successfully
269 QTextStream t( &f ); // use a text stream 269 QTextStream t( &f ); // use a text stream
270 int sec = 0; 270 int sec = 0;
271 t >> sec; 271 t >> sec;
272 datetime = datetime.addSecs((-1*sec)); 272 datetime = datetime.addSecs((-1*sec));
273 f.close(); 273 f.close();
274 } 274 }
275 else{ 275 else{
276 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 276 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
277 return false; 277 return false;
278 } 278 }
279 279
280 datetime = datetime.addSecs(time); 280 datetime = datetime.addSecs(time);
281 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 281 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
282 282
283 // Calculate the start and renew times 283 // Calculate the start and renew times
284 leaseObtained= datetime.toString(); 284 leaseObtained= datetime.toString();
285 285
286 // Calculate the start and renew times 286 // Calculate the start and renew times
287 datetime = datetime.addSecs(leaseTime); 287 datetime = datetime.addSecs(leaseTime);
288 leaseExpires = datetime.toString(); 288 leaseExpires = datetime.toString();
289 289
290 dhcp = true; 290 dhcp = true;
291 291
292 emit(updateInterface(this)); 292 emit(updateInterface(this));
293 return true; 293 return true;
294} 294}
295 295
296// interface.cpp 296// interface.cpp
297 297
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index 7b93554..9a17743 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -1,525 +1,521 @@
1#include "mainwindowimp.h" 1#include "mainwindowimp.h"
2#include "addconnectionimp.h" 2#include "addconnectionimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4#include "interfacesetupimp.h" 4#include "interfacesetupimp.h"
5#include "interfaces.h" 5#include "interfaces.h"
6#include "module.h" 6#include "module.h"
7 7
8#include <qpushbutton.h> 8#include <qpushbutton.h>
9#include <qlistbox.h> 9#include <qlistbox.h>
10#include <qlineedit.h> 10#include <qlineedit.h>
11#include <qlistview.h> 11#include <qlistview.h>
12#include <qheader.h> 12#include <qheader.h>
13#include <qlabel.h> 13#include <qlabel.h>
14 14
15#include <qmainwindow.h> 15#include <qmainwindow.h>
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17 17
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/qlibrary.h> 19#include <qpe/qlibrary.h>
20#include <qpe/resource.h> 20#include <qpe/resource.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22 22
23#include <qlist.h> 23#include <qlist.h>
24#include <qdir.h> 24#include <qdir.h>
25#include <qfile.h> 25#include <qfile.h>
26#include <qtextstream.h> 26#include <qtextstream.h>
27 27
28#include <net/if.h> 28#include <net/if.h>
29#include <sys/ioctl.h> 29#include <sys/ioctl.h>
30 30
31#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 31#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
32 32
33MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false), scheme(DEFAULT_SCHEME){ 33MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false), scheme(DEFAULT_SCHEME){
34 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 34 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
35 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 35 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
36 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 36 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
37 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 37 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
38 38
39 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 39 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
40 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 40 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
41 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 41 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
42 42
43 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 43 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
44 // Load connections. 44 // Load connections.
45 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); 45 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
46 getAllInterfaces(); 46 getAllInterfaces();
47 47
48 Interfaces i; 48 Interfaces i;
49 QStringList list = i.getInterfaceList(); 49 QStringList list = i.getInterfaceList();
50 QMap<QString, Interface*>::Iterator it; 50 QMap<QString, Interface*>::Iterator it;
51 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 51 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
52 bool found = false; 52 bool found = false;
53 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 53 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
54 if(it.key() == (*ni)) 54 if(it.key() == (*ni))
55 found = true; 55 found = true;
56 } 56 }
57 if(!found){ 57 if(!found){
58 if(!(*ni).contains("_")){ 58 if(!(*ni).contains("_")){
59 Interface *i = new Interface(this, *ni, false); 59 Interface *i = new Interface(this, *ni, false);
60 i->setAttached(false); 60 i->setAttached(false);
61 i->setHardwareName("Disconnected"); 61 i->setHardwareName("Disconnected");
62 interfaceNames.insert(i->getInterfaceName(), i); 62 interfaceNames.insert(i->getInterfaceName(), i);
63 updateInterface(i); 63 updateInterface(i);
64 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 64 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
65 } 65 }
66 } 66 }
67 } 67 }
68 68
69 //getInterfaceList(); 69 //getInterfaceList();
70 connectionList->header()->hide(); 70 connectionList->header()->hide();
71 71
72 Config cfg("NetworkSetup"); 72 Config cfg("NetworkSetup");
73 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 73 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
74 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 74 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
75 profilesList->insertItem((*it)); 75 profilesList->insertItem((*it));
76 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 76 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
77 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 77 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
78 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 78 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
79 79
80 QFile file(scheme); 80 QFile file(scheme);
81 if ( file.open(IO_ReadOnly) ) { // file opened successfully 81 if ( file.open(IO_ReadOnly) ) { // file opened successfully
82 QTextStream stream( &file ); // use a text stream 82 QTextStream stream( &file ); // use a text stream
83 while ( !stream.eof() ) { // until end of file... 83 while ( !stream.eof() ) { // until end of file...
84 QString line = stream.readLine(); // line of text excluding '\n' 84 QString line = stream.readLine(); // line of text excluding '\n'
85 if(line.contains("SCHEME")){ 85 if(line.contains("SCHEME")){
86 line = line.mid(7, line.length()); 86 line = line.mid(7, line.length());
87 currentProfileLabel->setText(line); 87 currentProfileLabel->setText(line);
88 break; 88 break;
89 } 89 }
90 } 90 }
91 file.close(); 91 file.close();
92 } 92 }
93} 93}
94 94
95/** 95/**
96 * Deconstructor. Save profiles. Delete loaded libraries. 96 * Deconstructor. Save profiles. Delete loaded libraries.
97 */ 97 */
98MainWindowImp::~MainWindowImp(){ 98MainWindowImp::~MainWindowImp(){
99 // Save profiles. 99 // Save profiles.
100 Config cfg("NetworkSetup"); 100 Config cfg("NetworkSetup");
101 cfg.setGroup("General"); 101 cfg.setGroup("General");
102 cfg.writeEntry("Profiles", profiles.join(" ")); 102 cfg.writeEntry("Profiles", profiles.join(" "));
103 103
104 // Delete all interfaces that don't have owners. 104 // Delete all interfaces that don't have owners.
105 QMap<Interface*, QListViewItem*>::Iterator iIt; 105 QMap<Interface*, QListViewItem*>::Iterator iIt;
106 for( iIt = items.begin(); iIt != items.end(); ++iIt ){ 106 for( iIt = items.begin(); iIt != items.end(); ++iIt ){
107 if(iIt.key()->getModuleOwner() == NULL) 107 if(iIt.key()->getModuleOwner() == NULL)
108 delete iIt.key(); 108 delete iIt.key();
109 } 109 }
110 110
111 // Delete Modules and Libraries 111 // Delete Modules and Libraries
112 QMap<Module*, QLibrary*>::Iterator it; 112 QMap<Module*, QLibrary*>::Iterator it;
113 for( it = libraries.begin(); it != libraries.end(); ++it ){ 113 for( it = libraries.begin(); it != libraries.end(); ++it ){
114 delete it.key(); 114 delete it.key();
115 // I wonder why I can't delete the libraries 115 // I wonder why I can't delete the libraries
116 // What fucking shit this is. 116 // What fucking shit this is.
117 //delete it.data(); 117 //delete it.data();
118 } 118 }
119} 119}
120 120
121/** 121/**
122 * Query the kernel for all of the interfaces. 122 * Query the kernel for all of the interfaces.
123 */ 123 */
124void MainWindowImp::getAllInterfaces(){ 124void MainWindowImp::getAllInterfaces(){
125 int sockfd = socket(AF_INET, SOCK_DGRAM, 0); 125 int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
126 if(sockfd == -1) 126 if(sockfd == -1)
127 return; 127 return;
128 128
129 char buf[8*1024]; 129 char buf[8*1024];
130 struct ifconf ifc; 130 struct ifconf ifc;
131 ifc.ifc_len = sizeof(buf); 131 ifc.ifc_len = sizeof(buf);
132 ifc.ifc_req = (struct ifreq *) buf; 132 ifc.ifc_req = (struct ifreq *) buf;
133 int result=ioctl(sockfd, SIOCGIFCONF, &ifc); 133 int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
134 134
135 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ 135 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){
136 struct ifreq *ifr =(struct ifreq *) ptr; 136 struct ifreq *ifr =(struct ifreq *) ptr;
137 int len = sizeof(struct sockaddr); 137 int len = sizeof(struct sockaddr);
138#ifdef HAVE_SOCKADDR_SA_LEN 138#ifdef HAVE_SOCKADDR_SA_LEN
139 if (ifr->ifr_addr.sa_len > len) 139 if (ifr->ifr_addr.sa_len > len)
140 len = ifr->ifr_addr.sa_len; /* length > 16 */ 140 len = ifr->ifr_addr.sa_len; /* length > 16 */
141#endif 141#endif
142 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 142 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
143 143
144 int flags; 144 int flags;
145 struct sockaddr_in *sinptr; 145 struct sockaddr_in *sinptr;
146 Interface *i = NULL; 146 Interface *i = NULL;
147 switch (ifr->ifr_addr.sa_family){ 147 switch (ifr->ifr_addr.sa_family){
148 case AF_INET: 148 case AF_INET:
149 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; 149 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
150 flags=0; 150 flags=0;
151 151
152 struct ifreq ifcopy; 152 struct ifreq ifcopy;
153 ifcopy=*ifr; 153 ifcopy=*ifr;
154 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); 154 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
155 flags=ifcopy.ifr_flags; 155 flags=ifcopy.ifr_flags;
156 i = new Interface(this, ifr->ifr_name, false); 156 i = new Interface(this, ifr->ifr_name, false);
157 i->setAttached(true); 157 i->setAttached(true);
158 if ((flags & IFF_UP) == IFF_UP) 158 if ((flags & IFF_UP) == IFF_UP)
159 i->setStatus(true); 159 i->setStatus(true);
160 else 160 else
161 i->setStatus(false); 161 i->setStatus(false);
162 162
163 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 163 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
164 i->setHardwareName("Ethernet"); 164 i->setHardwareName("Ethernet");
165 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 165 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
166 i->setHardwareName("Point to Point"); 166 i->setHardwareName("Point to Point");
167 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 167 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
168 i->setHardwareName("Multicast"); 168 i->setHardwareName("Multicast");
169 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 169 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
170 i->setHardwareName("Loopback"); 170 i->setHardwareName("Loopback");
171 else 171 else
172 i->setHardwareName("Unknown"); 172 i->setHardwareName("Unknown");
173 173
174 interfaceNames.insert(i->getInterfaceName(), i); 174 interfaceNames.insert(i->getInterfaceName(), i);
175 updateInterface(i); 175 updateInterface(i);
176 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 176 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
177 break; 177 break;
178 178
179 default: 179 default:
180 qDebug(ifr->ifr_name); 180 qDebug(ifr->ifr_name);
181 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); 181 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1());
182 break; 182 break;
183 } 183 }
184 } 184 }
185} 185}
186 186
187/** 187/**
188 * Load all modules that are found in the path 188 * Load all modules that are found in the path
189 * @param path a directory that is scaned for any plugins that can be loaded 189 * @param path a directory that is scaned for any plugins that can be loaded
190 * and attempts to load them 190 * and attempts to load them
191 */ 191 */
192void MainWindowImp::loadModules(const QString &path){ 192void MainWindowImp::loadModules(const QString &path){
193 //qDebug(path.latin1()); 193 //qDebug(path.latin1());
194 QDir d(path); 194 QDir d(path);
195 if(!d.exists()) 195 if(!d.exists())
196 return; 196 return;
197 197
198 // Don't want sym links 198 // Don't want sym links
199 d.setFilter( QDir::Files | QDir::NoSymLinks ); 199 d.setFilter( QDir::Files | QDir::NoSymLinks );
200 const QFileInfoList *list = d.entryInfoList(); 200 const QFileInfoList *list = d.entryInfoList();
201 QFileInfoListIterator it( *list ); 201 QFileInfoListIterator it( *list );
202 QFileInfo *fi; 202 QFileInfo *fi;
203 while ( (fi=it.current()) ) { 203 while ( (fi=it.current()) ) {
204 if(fi->fileName().contains(".so")){ 204 if(fi->fileName().contains(".so")){
205 loadPlugin(path + "/" + fi->fileName()); 205 loadPlugin(path + "/" + fi->fileName());
206 } 206 }
207 ++it; 207 ++it;
208 } 208 }
209} 209}
210 210
211/** 211/**
212 * Attempt to load a function and resolve a function. 212 * Attempt to load a function and resolve a function.
213 * @param pluginFileName - the name of the file in which to attempt to load 213 * @param pluginFileName - the name of the file in which to attempt to load
214 * @param resolveString - function pointer to resolve 214 * @param resolveString - function pointer to resolve
215 * @return pointer to the function with name resolveString or NULL 215 * @return pointer to the function with name resolveString or NULL
216 */ 216 */
217Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ 217Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){
218 //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 218 //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
219 QLibrary *lib = new QLibrary(pluginFileName); 219 QLibrary *lib = new QLibrary(pluginFileName);
220 void *functionPointer = lib->resolve(resolveString); 220 void *functionPointer = lib->resolve(resolveString);
221 if( !functionPointer ){ 221 if( !functionPointer ){
222 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 222 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
223 delete lib; 223 delete lib;
224 return NULL; 224 return NULL;
225 } 225 }
226 226
227 // Try to get an object. 227 // Try to get an object.
228 Module *object = ((Module* (*)()) functionPointer)(); 228 Module *object = ((Module* (*)()) functionPointer)();
229 if(object == NULL){ 229 if(object == NULL){
230 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 230 qDebug("MainWindowImp: Couldn't create object, but did load library!");
231 delete lib; 231 delete lib;
232 return NULL; 232 return NULL;
233 } 233 }
234 234
235 // Store for deletion later 235 // Store for deletion later
236 libraries.insert(object, lib); 236 libraries.insert(object, lib);
237 return object; 237 return object;
238} 238}
239 239
240/** 240/**
241 * The Add button was clicked. Bring up the add dialog and if OK is hit 241 * The Add button was clicked. Bring up the add dialog and if OK is hit
242 * load the plugin and append it to the list 242 * load the plugin and append it to the list
243 */ 243 */
244void MainWindowImp::addClicked(){ 244void MainWindowImp::addClicked(){
245 QMap<Module*, QLibrary*>::Iterator it; 245 QMap<Module*, QLibrary*>::Iterator it;
246 QMap<QString, QString> list; 246 QMap<QString, QString> list;
247 QMap<QString, Module*> newInterfaceOwners; 247 QMap<QString, Module*> newInterfaceOwners;
248 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 248 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
249 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 249 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
250 for( it = libraries.begin(); it != libraries.end(); ++it ){ 250 for( it = libraries.begin(); it != libraries.end(); ++it ){
251 if(it.key()){ 251 if(it.key()){
252 (it.key())->possibleNewInterfaces(list); 252 (it.key())->possibleNewInterfaces(list);
253 } 253 }
254 } 254 }
255 // See if the list has anything that we can add. 255 // See if the list has anything that we can add.
256 if(list.count() == 0){ 256 if(list.count() == 0){
257 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 257 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
258 return; 258 return;
259 } 259 }
260 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 260 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
261 addNewConnection.addConnections(list); 261 addNewConnection.addConnections(list);
262 addNewConnection.showMaximized(); 262 addNewConnection.showMaximized();
263 if(QDialog::Accepted == addNewConnection.exec()){ 263 if(QDialog::Accepted == addNewConnection.exec()){
264 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 264 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
265 if(!item) 265 if(!item)
266 return; 266 return;
267 267
268 for( it = libraries.begin(); it != libraries.end(); ++it ){ 268 for( it = libraries.begin(); it != libraries.end(); ++it ){
269 if(it.key()){ 269 if(it.key()){
270 Interface *i = (it.key())->addNewInterface(item->text(0)); 270 Interface *i = (it.key())->addNewInterface(item->text(0));
271 if(i){ 271 if(i){
272 interfaceNames.insert(i->getInterfaceName(), i); 272 interfaceNames.insert(i->getInterfaceName(), i);
273 updateInterface(i); 273 updateInterface(i);
274 } 274 }
275 } 275 }
276 } 276 }
277 } 277 }
278} 278}
279 279
280/** 280/**
281 * Prompt the user to see if they really want to do this. 281 * Prompt the user to see if they really want to do this.
282 * If they do then remove from the list and unload. 282 * If they do then remove from the list and unload.
283 */ 283 */
284void MainWindowImp::removeClicked(){ 284void MainWindowImp::removeClicked(){
285 QListViewItem *item = connectionList->currentItem(); 285 QListViewItem *item = connectionList->currentItem();
286 if(!item) { 286 if(!item) {
287 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 287 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
288 return; 288 return;
289 } 289 }
290 290
291 Interface *i = interfaceItems[item]; 291 Interface *i = interfaceItems[item];
292 if(i->getModuleOwner() == NULL){ 292 if(i->getModuleOwner() == NULL){
293 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 293 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
294 } 294 }
295 else{ 295 else{
296 if(!i->getModuleOwner()->remove(i)) 296 if(!i->getModuleOwner()->remove(i))
297 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); 297 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
298 else{ 298 else{
299 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 299 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
300 // TODO memory managment.... 300 // TODO memory managment....
301 // who deletes the interface? 301 // who deletes the interface?
302 } 302 }
303 } 303 }
304} 304}
305 305
306/** 306/**
307 * Pull up the configure about the currently selected interface. 307 * Pull up the configure about the currently selected interface.
308 * Report an error if no interface is selected. 308 * Report an error if no interface is selected.
309 * If the interface has a module owner then request its configure. 309 * If the interface has a module owner then request its configure.
310 */ 310 */
311void MainWindowImp::configureClicked(){ 311void MainWindowImp::configureClicked(){
312 QListViewItem *item = connectionList->currentItem(); 312 QListViewItem *item = connectionList->currentItem();
313 if(!item){ 313 if(!item){
314 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); 314 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
315 return; 315 return;
316 } 316 }
317 317
318 Interface *i = interfaceItems[item]; 318 Interface *i = interfaceItems[item];
319 if(i->getModuleOwner()){ 319 if(i->getModuleOwner()){
320 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 320 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
321 if(moduleConfigure != NULL){ 321 if(moduleConfigure != NULL){
322 moduleConfigure->showMaximized(); 322 moduleConfigure->showMaximized();
323 moduleConfigure->show();
324 return; 323 return;
325 } 324 }
326 } 325 }
327 326
328 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); 327 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose);
329 QString currentProfileText = currentProfileLabel->text(); 328 QString currentProfileText = currentProfileLabel->text();
330 if(currentProfileText.upper() == "ALL"); 329 if(currentProfileText.upper() == "ALL");
331 currentProfileText = ""; 330 currentProfileText = "";
332 configure->setProfile(currentProfileText); 331 configure->setProfile(currentProfileText);
333 configure->showMaximized(); 332 configure->showMaximized();
334 configure->show();
335} 333}
336 334
337/** 335/**
338 * Pull up the information about the currently selected interface. 336 * Pull up the information about the currently selected interface.
339 * Report an error if no interface is selected. 337 * Report an error if no interface is selected.
340 * If the interface has a module owner then request its configure. 338 * If the interface has a module owner then request its configure.
341 */ 339 */
342void MainWindowImp::informationClicked(){ 340void MainWindowImp::informationClicked(){
343 QListViewItem *item = connectionList->currentItem(); 341 QListViewItem *item = connectionList->currentItem();
344 if(!item){ 342 if(!item){
345 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 343 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
346 return; 344 return;
347 } 345 }
348 346
349 Interface *i = interfaceItems[item]; 347 Interface *i = interfaceItems[item];
350 if(!i->isAttached()){ 348 if(!i->isAttached()){
351 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 349 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
352 return; 350 return;
353 } 351 }
354 352
355 if(i->getModuleOwner()){ 353 if(i->getModuleOwner()){
356 QWidget *moduleInformation = i->getModuleOwner()->information(i); 354 QWidget *moduleInformation = i->getModuleOwner()->information(i);
357 if(moduleInformation != NULL){ 355 if(moduleInformation != NULL){
358 moduleInformation->showMaximized(); 356 moduleInformation->showMaximized();
359 moduleInformation->show();
360 return; 357 return;
361 } 358 }
362 } 359 }
363 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 360 InterfaceInformationImp information(0, "InterfaceSetupImp", i);
364 information->showMaximized(); 361 information.showMaximized();
365 information->show();
366} 362}
367 363
368/** 364/**
369 * Update this interface. If no QListViewItem exists create one. 365 * Update this interface. If no QListViewItem exists create one.
370 * @param Interface* pointer to the interface that needs to be updated. 366 * @param Interface* pointer to the interface that needs to be updated.
371 */ 367 */
372void MainWindowImp::updateInterface(Interface *i){ 368void MainWindowImp::updateInterface(Interface *i){
373 if(!advancedUserMode){ 369 if(!advancedUserMode){
374 if(i->getInterfaceName() == "lo") 370 if(i->getInterfaceName() == "lo")
375 return; 371 return;
376 } 372 }
377 373
378 QListViewItem *item = NULL; 374 QListViewItem *item = NULL;
379 375
380 // Find the interface, making it if needed. 376 // Find the interface, making it if needed.
381 if(items.find(i) == items.end()){ 377 if(items.find(i) == items.end()){
382 item = new QListViewItem(connectionList, "", "", ""); 378 item = new QListViewItem(connectionList, "", "", "");
383 // See if you can't find a module owner for this interface 379 // See if you can't find a module owner for this interface
384 QMap<Module*, QLibrary*>::Iterator it; 380 QMap<Module*, QLibrary*>::Iterator it;
385 for( it = libraries.begin(); it != libraries.end(); ++it ){ 381 for( it = libraries.begin(); it != libraries.end(); ++it ){
386 if(it.key()->isOwner(i)) 382 if(it.key()->isOwner(i))
387 i->setModuleOwner(it.key()); 383 i->setModuleOwner(it.key());
388 } 384 }
389 items.insert(i, item); 385 items.insert(i, item);
390 interfaceItems.insert(item, i); 386 interfaceItems.insert(item, i);
391 } 387 }
392 else 388 else
393 item = items[i]; 389 item = items[i];
394 390
395 // Update the icons and information 391 // Update the icons and information
396 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 392 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
397 393
398 QString typeName = "lan"; 394 QString typeName = "lan";
399 if(i->getHardwareName().contains("Local Loopback")) 395 if(i->getHardwareName().contains("Local Loopback"))
400 typeName = "lo"; 396 typeName = "lo";
401 if(i->getInterfaceName().contains("irda")) 397 if(i->getInterfaceName().contains("irda"))
402 typeName = "irda"; 398 typeName = "irda";
403 if(i->getInterfaceName().contains("wlan")) 399 if(i->getInterfaceName().contains("wlan"))
404 typeName = "wlan"; 400 typeName = "wlan";
405 if(i->getInterfaceName().contains("usb")) 401 if(i->getInterfaceName().contains("usb"))
406 typeName = "usb"; 402 typeName = "usb";
407 403
408 if(!i->isAttached()) 404 if(!i->isAttached())
409 typeName = "connect_no"; 405 typeName = "connect_no";
410 // Actually try to use the Module 406 // Actually try to use the Module
411 if(i->getModuleOwner() != NULL) 407 if(i->getModuleOwner() != NULL)
412 typeName = i->getModuleOwner()->getPixmapName(i); 408 typeName = i->getModuleOwner()->getPixmapName(i);
413 409
414 item->setPixmap(1, (Resource::loadPixmap(typeName))); 410 item->setPixmap(1, (Resource::loadPixmap(QString("networksetup/") + typeName)));
415 item->setText(2, i->getHardwareName()); 411 item->setText(2, i->getHardwareName());
416 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 412 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
417 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 413 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
418} 414}
419 415
420void MainWindowImp::newProfileChanged(const QString& newText){ 416void MainWindowImp::newProfileChanged(const QString& newText){
421 if(newText.length() > 0) 417 if(newText.length() > 0)
422 newProfileButton->setEnabled(true); 418 newProfileButton->setEnabled(true);
423 else 419 else
424 newProfileButton->setEnabled(false); 420 newProfileButton->setEnabled(false);
425} 421}
426 422
427/** 423/**
428 * Adds a new profile to the list of profiles. 424 * Adds a new profile to the list of profiles.
429 * Don't add profiles that already exists. 425 * Don't add profiles that already exists.
430 * Appends to the list and QStringList 426 * Appends to the list and QStringList
431 */ 427 */
432void MainWindowImp::addProfile(){ 428void MainWindowImp::addProfile(){
433 QString newProfileName = newProfile->text(); 429 QString newProfileName = newProfile->text();
434 if(profiles.grep(newProfileName).count() > 0){ 430 if(profiles.grep(newProfileName).count() > 0){
435 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 431 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
436 return; 432 return;
437 } 433 }
438 profiles.append(newProfileName); 434 profiles.append(newProfileName);
439 profilesList->insertItem(newProfileName); 435 profilesList->insertItem(newProfileName);
440} 436}
441 437
442/** 438/**
443 * Removes the currently selected profile in the combo. 439 * Removes the currently selected profile in the combo.
444 * Doesn't delete if there are less then 2 profiles. 440 * Doesn't delete if there are less then 2 profiles.
445 */ 441 */
446void MainWindowImp::removeProfile(){ 442void MainWindowImp::removeProfile(){
447 if(profilesList->count() <= 1){ 443 if(profilesList->count() <= 1){
448 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 444 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
449 return; 445 return;
450 } 446 }
451 QString profileToRemove = profilesList->currentText(); 447 QString profileToRemove = profilesList->currentText();
452 if(profileToRemove == "All"){ 448 if(profileToRemove == "All"){
453 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 449 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
454 return; 450 return;
455 } 451 }
456 // Can't remove the curent profile 452 // Can't remove the curent profile
457 if(profileToRemove == currentProfileLabel->text()){ 453 if(profileToRemove == currentProfileLabel->text()){
458 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 454 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
459 return; 455 return;
460 456
461 } 457 }
462 458
463 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 459 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
464 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 460 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
465 profilesList->clear(); 461 profilesList->clear();
466 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 462 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
467 profilesList->insertItem((*it)); 463 profilesList->insertItem((*it));
468 464
469 // Remove any interface settings and mappings. 465 // Remove any interface settings and mappings.
470 Interfaces interfaces; 466 Interfaces interfaces;
471 // Go through them one by one 467 // Go through them one by one
472 QMap<Interface*, QListViewItem*>::Iterator it; 468 QMap<Interface*, QListViewItem*>::Iterator it;
473 for( it = items.begin(); it != items.end(); ++it ){ 469 for( it = items.begin(); it != items.end(); ++it ){
474 QString interfaceName = it.key()->getInterfaceName(); 470 QString interfaceName = it.key()->getInterfaceName();
475 qDebug(interfaceName.latin1()); 471 qDebug(interfaceName.latin1());
476 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ 472 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){
477 interfaces.removeInterface(); 473 interfaces.removeInterface();
478 if(interfaces.setMapping(interfaceName)){ 474 if(interfaces.setMapping(interfaceName)){
479 if(profilesList->count() == 1) 475 if(profilesList->count() == 1)
480 interfaces.removeMapping(); 476 interfaces.removeMapping();
481 else{ 477 else{
482 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 478 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
483 } 479 }
484 } 480 }
485 interfaces.write(); 481 interfaces.write();
486 break; 482 break;
487 } 483 }
488 } 484 }
489 } 485 }
490} 486}
491 487
492/** 488/**
493 * A new profile has been selected, change. 489 * A new profile has been selected, change.
494 * @param newProfile the new profile. 490 * @param newProfile the new profile.
495 */ 491 */
496void MainWindowImp::changeProfile(){ 492void MainWindowImp::changeProfile(){
497 if(profilesList->currentItem() == -1){ 493 if(profilesList->currentItem() == -1){
498 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 494 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
499 return; 495 return;
500 } 496 }
501 QString newProfile = profilesList->text(profilesList->currentItem()); 497 QString newProfile = profilesList->text(profilesList->currentItem());
502 if(newProfile != currentProfileLabel->text()){ 498 if(newProfile != currentProfileLabel->text()){
503 currentProfileLabel->setText(newProfile); 499 currentProfileLabel->setText(newProfile);
504 QFile::remove(scheme); 500 QFile::remove(scheme);
505 QFile file(scheme); 501 QFile file(scheme);
506 if ( file.open(IO_ReadWrite) ) { 502 if ( file.open(IO_ReadWrite) ) {
507 QTextStream stream( &file ); 503 QTextStream stream( &file );
508 stream << QString("SCHEME=%1").arg(newProfile); 504 stream << QString("SCHEME=%1").arg(newProfile);
509 file.close(); 505 file.close();
510 } 506 }
511 // restart all up devices? 507 // restart all up devices?
512 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 508 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
513 // Go through them one by one 509 // Go through them one by one
514 QMap<Interface*, QListViewItem*>::Iterator it; 510 QMap<Interface*, QListViewItem*>::Iterator it;
515 for( it = items.begin(); it != items.end(); ++it ){ 511 for( it = items.begin(); it != items.end(); ++it ){
516 if(it.key()->getStatus() == true) 512 if(it.key()->getStatus() == true)
517 it.key()->restart(); 513 it.key()->restart();
518 } 514 }
519 } 515 }
520 } 516 }
521 // TODO change the profile in the modules 517 // TODO change the profile in the modules
522} 518}
523 519
524// mainwindowimp.cpp 520// mainwindowimp.cpp
525 521
diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp
index cc18fba..648932f 100644
--- a/noncore/net/networksetup/wlan/wlanimp.cpp
+++ b/noncore/net/networksetup/wlan/wlanimp.cpp
@@ -1,244 +1,244 @@
1#include "wlanimp.h" 1#include "wlanimp.h"
2#include "interfacesetupimp.h" 2#include "interfacesetupimp.h"
3 3
4#include <qfile.h> 4#include <qfile.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qlineedit.h> 8#include <qlineedit.h>
9#include <qlabel.h> 9#include <qlabel.h>
10#include <qspinbox.h> 10#include <qspinbox.h>
11#include <qradiobutton.h> 11#include <qradiobutton.h>
12#include <qcheckbox.h> 12#include <qcheckbox.h>
13#include <qtabwidget.h> 13#include <qtabwidget.h>
14#include <qcombobox.h> 14#include <qcombobox.h>
15 15
16/* system() */ 16/* system() */
17#include <stdlib.h> 17#include <stdlib.h>
18 18
19#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 19#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
20 20
21/** 21/**
22 * Constructor, read in the wireless.opts file for parsing later. 22 * Constructor, read in the wireless.opts file for parsing later.
23 */ 23 */
24WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { 24WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") {
25 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); 25 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);
26 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 26 tabWidget->insertTab(interfaceSetup, "TCP/IP");
27 27
28 // Read in the config file. 28 // Read in the config file.
29 QString wlanFile = WIRELESS_OPTS; 29 QString wlanFile = WIRELESS_OPTS;
30 QFile file(wlanFile); 30 QFile file(wlanFile);
31 if (file.open(IO_ReadOnly)){ 31 if (file.open(IO_ReadOnly)){
32 QTextStream stream( &file ); 32 QTextStream stream( &file );
33 QString line = ""; 33 QString line = "";
34 while ( !stream.eof() ) { 34 while ( !stream.eof() ) {
35 line += stream.readLine(); 35 line += stream.readLine();
36 line += "\n"; 36 line += "\n";
37 } 37 }
38 file.close(); 38 file.close();
39 settingsFileText = QStringList::split("\n", line, true); 39 settingsFileText = QStringList::split("\n", line, true);
40 parseSettingFile(); 40 parseSettingFile();
41 } 41 }
42 else 42 else
43 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); 43 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1());
44 connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); 44 connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
45} 45}
46 46
47void WLANImp::typeChanged(int mod){ 47void WLANImp::typeChanged(int mod){
48 networkChannel->setEnabled(mod); 48 networkChannel->setEnabled(mod);
49 channelLabel->setEnabled(mod); 49 channelLabel->setEnabled(mod);
50} 50}
51 51
52/** 52/**
53 * Change the profile for both wireless settings and network settings. 53 * Change the profile for both wireless settings and network settings.
54 */ 54 */
55void WLANImp::setProfile(const QString &profile){ 55void WLANImp::setProfile(const QString &profile){
56 interfaceSetup->setProfile(profile); 56 interfaceSetup->setProfile(profile);
57 parseSettingFile(); 57 parseSettingFile();
58} 58}
59 59
60/** 60/**
61 * Parses the settings file that was read in and gets any setting from it. 61 * Parses the settings file that was read in and gets any setting from it.
62 */ 62 */
63void WLANImp::parseSettingFile(){ 63void WLANImp::parseSettingFile(){
64 bool foundCase = false; 64 bool foundCase = false;
65 bool found = false; 65 bool found = false;
66 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { 66 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
67 QString line = (*it).simplifyWhiteSpace(); 67 QString line = (*it).simplifyWhiteSpace();
68 if(line.contains("case")) 68 if(line.contains("case"))
69 foundCase = true; 69 foundCase = true;
70 // See if we found our scheme to write or the sceme couldn't be found 70 // See if we found our scheme to write or the sceme couldn't be found
71 if((foundCase && line.contains("esac")) || 71 if((foundCase && line.contains("esac")) ||
72 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) 72 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
73 found = true; 73 found = true;
74 74
75 if(line.contains(";;")) 75 if(line.contains(";;"))
76 found = false; 76 found = false;
77 if(found){ 77 if(found){
78 // write out scheme 78 // write out scheme
79 if(line.contains("ESSID=")){ 79 if(line.contains("ESSID=")){
80 QString id = line.mid(line.find("ESSID=")+6, line.length()); 80 QString id = line.mid(line.find("ESSID=")+6, line.length());
81 if(id == "any"){ 81 if(id == "any"){
82 essAny->setChecked(false); 82 essAny->setChecked(false);
83 }else{ 83 }else{
84 essAny->setChecked(true); 84 essAny->setChecked(true);
85 essSpecificLineEdit->setText(id); 85 essSpecificLineEdit->setText(id);
86 } 86 }
87 } 87 }
88 if(line.contains("MODE=")){ 88 if(line.contains("MODE=")){
89 QString mode = line.mid(line.find("MODE=")+5, line.length()); 89 QString mode = line.mid(line.find("MODE=")+5, line.length());
90 if(mode == "Managed"){ 90 if(mode == "Managed"){
91 networkType->setCurrentItem(0); 91 networkType->setCurrentItem(0);
92 channelLabel->setEnabled(false); 92 channelLabel->setEnabled(false);
93 networkChannel->setEnabled(false); 93 networkChannel->setEnabled(false);
94 } 94 }
95 else{ 95 else{
96 networkType->setCurrentItem(1); 96 networkType->setCurrentItem(1);
97 networkChannel->setEnabled(true); 97 networkChannel->setEnabled(true);
98 channelLabel->setEnabled(true); 98 channelLabel->setEnabled(true);
99 } 99 }
100 } 100 }
101 if(line.contains("#KEY0=")) 101 if(line.contains("#KEY0="))
102 keyLineEdit0->setText(line.mid(5, line.length())); 102 keyLineEdit0->setText(line.mid(6, line.length()));
103 if(line.contains("#KEY1=")) 103 if(line.contains("#KEY1="))
104 keyLineEdit1->setText(line.mid(5, line.length())); 104 keyLineEdit1->setText(line.mid(6, line.length()));
105 if(line.contains("#KEY2=")) 105 if(line.contains("#KEY2="))
106 keyLineEdit2->setText(line.mid(5, line.length())); 106 keyLineEdit2->setText(line.mid(6, line.length()));
107 if(line.contains("#KEY3=")) 107 if(line.contains("#KEY3="))
108 keyLineEdit3->setText(line.mid(5, line.length())); 108 keyLineEdit3->setText(line.mid(6, line.length()));
109 109
110 if(line.contains("KEY=")){ 110 if(line.contains("KEY=")){
111 wepEnabled->setChecked(true); 111 wepEnabled->setChecked(true);
112 QString key; 112 QString key;
113 if(line.right(5) == (" open")){ 113 if(line.right(5) == (" open")){
114 key = line.mid(4, line.length()-5); 114 key = line.mid(4, line.length()-5);
115 authOpen->setChecked(true); 115 authOpen->setChecked(true);
116 authShared->setChecked(false); 116 authShared->setChecked(false);
117 } 117 }
118 else{ 118 else{
119 authOpen->setChecked(false); 119 authOpen->setChecked(false);
120 authShared->setChecked(true); 120 authShared->setChecked(true);
121 key = line.mid(4, line.length()); 121 key = line.mid(4, line.length());
122 } 122 }
123 if(key == keyLineEdit0->text()) keyRadio0->setChecked(true); 123 if(key == keyLineEdit0->text()) keyRadio0->setChecked(true);
124 if(key == keyLineEdit1->text()) keyRadio1->setChecked(true); 124 if(key == keyLineEdit1->text()) keyRadio1->setChecked(true);
125 if(key == keyLineEdit2->text()) keyRadio2->setChecked(true); 125 if(key == keyLineEdit2->text()) keyRadio2->setChecked(true);
126 if(key == keyLineEdit3->text()) keyRadio3->setChecked(true); 126 if(key == keyLineEdit3->text()) keyRadio3->setChecked(true);
127 } 127 }
128 if(line.contains("CHANNEL=")){ 128 if(line.contains("CHANNEL=")){
129 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); 129 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt());
130 } 130 }
131 } 131 }
132 } 132 }
133} 133}
134 134
135/** 135/**
136 * Saves settings to the wireless.opts file using the current profile 136 * Saves settings to the wireless.opts file using the current profile
137 */ 137 */
138void WLANImp::changeAndSaveSettingFile(){ 138void WLANImp::changeAndSaveSettingFile(){
139 QString wlanFile = WIRELESS_OPTS; 139 QString wlanFile = WIRELESS_OPTS;
140 QFile::remove(wlanFile); 140 QFile::remove(wlanFile);
141 QFile file(wlanFile); 141 QFile file(wlanFile);
142 142
143 if (!file.open(IO_ReadWrite)){ 143 if (!file.open(IO_ReadWrite)){
144 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); 144 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
145 return; 145 return;
146 } 146 }
147 147
148 QTextStream stream( &file ); 148 QTextStream stream( &file );
149 bool foundCase = false; 149 bool foundCase = false;
150 bool found = false; 150 bool found = false;
151 bool output = true; 151 bool output = true;
152 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { 152 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
153 QString line = (*it).simplifyWhiteSpace(); 153 QString line = (*it).simplifyWhiteSpace();
154 if(line.contains("case")) 154 if(line.contains("case"))
155 foundCase = true; 155 foundCase = true;
156 // See if we found our scheme to write or the sceme couldn't be found 156 // See if we found our scheme to write or the sceme couldn't be found
157 if((foundCase && line.contains("esac") && !found) || 157 if((foundCase && line.contains("esac") && !found) ||
158 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ 158 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
159 // write out scheme 159 // write out scheme
160 found = true; 160 found = true;
161 output = false; 161 output = false;
162 162
163 if(!line.contains("esac")) 163 if(!line.contains("esac"))
164 stream << line << "\n"; 164 stream << line << "\n";
165 if(!essAny->isChecked() == true){ 165 if(!essAny->isChecked() == true){
166 stream << "\tESSID=any\n"; 166 stream << "\tESSID=any\n";
167 stream << "\tMODE=Managed\n"; 167 stream << "\tMODE=Managed\n";
168 } 168 }
169 else{ 169 else{
170 stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; 170 stream << "\tESSID=" << essSpecificLineEdit->text() << '\n';
171 stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; 171 stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n';
172 stream << "\tCHANNEL=" << networkChannel->value() << "\n"; 172 stream << "\tCHANNEL=" << networkChannel->value() << "\n";
173 } 173 }
174 174
175 stream << "\t#KEY0=" << keyLineEdit0->text() << "\n"; 175 stream << "\t#KEY0=" << keyLineEdit0->text() << "\n";
176 stream << "\t#KEY1=" << keyLineEdit1->text() << "\n"; 176 stream << "\t#KEY1=" << keyLineEdit1->text() << "\n";
177 stream << "\t#KEY2=" << keyLineEdit2->text() << "\n"; 177 stream << "\t#KEY2=" << keyLineEdit2->text() << "\n";
178 stream << "\t#KEY3=" << keyLineEdit3->text() << "\n"; 178 stream << "\t#KEY3=" << keyLineEdit3->text() << "\n";
179 179
180 if(wepEnabled->isChecked()){ 180 if(wepEnabled->isChecked()){
181 stream << "\tKEY=\""; 181 stream << "\tKEY=\"";
182 if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); 182 if(keyRadio0->isChecked()) stream << keyLineEdit0->text();
183 if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); 183 if(keyRadio1->isChecked()) stream << keyLineEdit1->text();
184 if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); 184 if(keyRadio2->isChecked()) stream << keyLineEdit2->text();
185 if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); 185 if(keyRadio3->isChecked()) stream << keyLineEdit3->text();
186 if(authOpen->isChecked()) 186 if(authOpen->isChecked())
187 stream << " open"; 187 stream << " open";
188 else 188 else
189 stream << " restricted"; 189 stream << " restricted";
190 stream << "\"\n"; 190 stream << "\"\n";
191 } 191 }
192 stream << "\tRATE=auto\n"; 192 stream << "\tRATE=auto\n";
193 if(line.contains("esac")) 193 if(line.contains("esac"))
194 stream << line << "\n"; 194 stream << line << "\n";
195 } 195 }
196 if(line.contains(";;")) 196 if(line.contains(";;"))
197 output = true; 197 output = true;
198 if(output && (*it).length() ) 198 if(output && (*it).length() )
199 stream << (*it) << '\n'; 199 stream << (*it) << '\n';
200 } 200 }
201 file.close(); 201 file.close();
202} 202}
203 203
204/** 204/**
205 * Check to see if the current config is valid 205 * Check to see if the current config is valid
206 * Save wireless.opts, save interfaces 206 * Save wireless.opts, save interfaces
207 */ 207 */
208void WLANImp::accept(){ 208void WLANImp::accept(){
209 if(wepEnabled->isChecked()){ 209 if(wepEnabled->isChecked()){
210 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){ 210 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){
211 QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); 211 QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok);
212 return; 212 return;
213 } 213 }
214 } 214 }
215 215
216 if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){ 216 if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){
217 QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok); 217 QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok);
218 return; 218 return;
219 } 219 }
220 220
221 // Ok settings are good here, save 221 // Ok settings are good here, save
222 changeAndSaveSettingFile(); 222 changeAndSaveSettingFile();
223 223
224 // Try to save the interfaces settings. 224 // Try to save the interfaces settings.
225 if(!interfaceSetup->saveChanges()) 225 if(!interfaceSetup->saveChanges())
226 return; 226 return;
227 227
228 // Restart the device now that the settings have changed 228 // Restart the device now that the settings have changed
229 QString initpath; 229 QString initpath;
230 if( QDir("/etc/rc.d/init.d").exists() ) 230 if( QDir("/etc/rc.d/init.d").exists() )
231 initpath = "/etc/rc.d/init.d"; 231 initpath = "/etc/rc.d/init.d";
232 else if( QDir("/etc/init.d").exists() ) 232 else if( QDir("/etc/init.d").exists() )
233 initpath = "/etc/init.d"; 233 initpath = "/etc/init.d";
234 if( initpath ) 234 if( initpath )
235 system(QString("%1/pcmcia stop").arg(initpath)); 235 system(QString("%1/pcmcia stop").arg(initpath));
236 if( initpath ) 236 if( initpath )
237 system(QString("%1/pcmcia start").arg(initpath)); 237 system(QString("%1/pcmcia start").arg(initpath));
238 238
239 // Close out the dialog 239 // Close out the dialog
240 QDialog::accept(); 240 QDialog::accept();
241} 241}
242 242
243// wlanimp.cpp 243// wlanimp.cpp
244 244
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
index 7ffa76f..d964961 100644
--- a/noncore/settings/networksettings/interfaces/interface.cpp
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -1,297 +1,297 @@
1#include "interface.h" 1#include "interface.h"
2#include <qdatetime.h> 2#include <qdatetime.h>
3#include <qfile.h> 3#include <qfile.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfileinfo.h> 5#include <qfileinfo.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7 7
8#define IFCONFIG "/sbin/ifconfig" 8#define IFCONFIG "/sbin/ifconfig"
9#define DHCP_INFO_DIR "/etc/dhcpc" 9#define DHCP_INFO_DIR "/etc/dhcpc"
10 10
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13 13
14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ 14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){
15 refresh(); 15 refresh();
16} 16}
17 17
18/** 18/**
19 * Set status 19 * Set status
20 * @param newStatus - the new status 20 * @param newStatus - the new status
21 * emit updateInterface 21 * emit updateInterface
22 */ 22 */
23void Interface::setStatus(bool newStatus){ 23void Interface::setStatus(bool newStatus){
24 if(status != newStatus){ 24 if(status != newStatus){
25 status = newStatus; 25 status = newStatus;
26 refresh(); 26 refresh();
27 } 27 }
28}; 28};
29 29
30/** 30/**
31 * Set if attached or not (802.11 card pulled out for example) 31 * Set if attached or not (802.11 card pulled out for example)
32 * @param isAttached - if attached 32 * @param isAttached - if attached
33 * emit updateInterface 33 * emit updateInterface
34 */ 34 */
35void Interface::setAttached(bool isAttached){ 35void Interface::setAttached(bool isAttached){
36 attached = isAttached; 36 attached = isAttached;
37 emit(updateInterface(this)); 37 emit(updateInterface(this));
38}; 38};
39 39
40/** 40/**
41 * Set Hardware name 41 * Set Hardware name
42 * @param name - the new name 42 * @param name - the new name
43 * emit updateInterface 43 * emit updateInterface
44 */ 44 */
45void Interface::setHardwareName(const QString &name){ 45void Interface::setHardwareName(const QString &name){
46 hardwareName = name; 46 hardwareName = name;
47 emit(updateInterface(this)); 47 emit(updateInterface(this));
48}; 48};
49 49
50/** 50/**
51 * Set Module owner 51 * Set Module owner
52 * @param owner - the new owner 52 * @param owner - the new owner
53 * emit updateInterface 53 * emit updateInterface
54 */ 54 */
55void Interface::setModuleOwner(Module *owner){ 55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner; 56 moduleOwner = owner;
57 emit(updateInterface(this)); 57 emit(updateInterface(this));
58}; 58};
59 59
60 60
61/** 61/**
62 * Try to start the interface. 62 * Try to start the interface.
63 */ 63 */
64void Interface::start(){ 64void Interface::start(){
65 // check to see if we are already running. 65 // check to see if we are already running.
66 if(true == status){ 66 if(true == status){
67 emit (updateMessage("Unable to start interface,\n already started")); 67 emit (updateMessage("Unable to start interface,\n already started"));
68 return; 68 return;
69 } 69 }
70 70
71 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 71 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
72 // See if it was successfull... 72 // See if it was successfull...
73 if(ret != 0){ 73 if(ret != 0){
74 emit (updateMessage("Starting interface failed.")); 74 emit (updateMessage("Starting interface failed"));
75 return; 75 return;
76 } 76 }
77 77
78 status = true; 78 status = true;
79 refresh(); 79 refresh();
80 emit (updateMessage("Start successfull")); 80 emit (updateMessage("Start successfull"));
81} 81}
82 82
83/** 83/**
84 * Try to stop the interface. 84 * Try to stop the interface.
85 */ 85 */
86void Interface::stop(){ 86void Interface::stop(){
87 // check to see if we are already stopped. 87 // check to see if we are already stopped.
88 if(false == status){ 88 if(false == status){
89 emit (updateMessage("Unable to stop interface,\n already stopped")); 89 emit (updateMessage("Unable to stop interface,\n already stopped"));
90 return; 90 return;
91 } 91 }
92 92
93 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 93 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
94 if(ret != 0){ 94 if(ret != 0){
95 emit (updateMessage("Stopping interface failed.")); 95 emit (updateMessage("Stopping interface failed"));
96 return; 96 return;
97 } 97 }
98 98
99 status = false; 99 status = false;
100 refresh(); 100 refresh();
101 emit (updateMessage("Stop successfull")); 101 emit (updateMessage("Stop successfull"));
102} 102}
103 103
104/** 104/**
105 * Try to restart the interface. 105 * Try to restart the interface.
106 */ 106 */
107void Interface::restart(){ 107void Interface::restart(){
108 stop(); 108 stop();
109 start(); 109 start();
110} 110}
111 111
112/** 112/**
113 * Try to refresh the information about the interface. 113 * Try to refresh the information about the interface.
114 * First call ifconfig, then check the dhcp-info file 114 * First call ifconfig, then check the dhcp-info file
115 * @return bool true if successfull. 115 * @return bool true if successfull.
116 */ 116 */
117bool Interface::refresh(){ 117bool Interface::refresh(){
118 // See if we are up. 118 // See if we are up.
119 if(status == false){ 119 if(status == false){
120 macAddress = ""; 120 macAddress = "";
121 ip = "0.0.0.0"; 121 ip = "0.0.0.0";
122 subnetMask = "0.0.0.0"; 122 subnetMask = "0.0.0.0";
123 broadcast = ""; 123 broadcast = "";
124 dhcp = false; 124 dhcp = false;
125 dhcpServerIp = ""; 125 dhcpServerIp = "";
126 leaseObtained = ""; 126 leaseObtained = "";
127 leaseExpires = ""; 127 leaseExpires = "";
128 emit(updateInterface(this)); 128 emit(updateInterface(this));
129 return true; 129 return true;
130 } 130 }
131 131
132 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 132 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
133 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 133 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
134 if(ret != 0){ 134 if(ret != 0){
135 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 135 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
136 return false; 136 return false;
137 } 137 }
138 138
139 QFile file(fileName); 139 QFile file(fileName);
140 if (!file.open(IO_ReadOnly)){ 140 if (!file.open(IO_ReadOnly)){
141 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 141 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
142 return false; 142 return false;
143 } 143 }
144 144
145 // Set to the defaults 145 // Set to the defaults
146 macAddress = ""; 146 macAddress = "";
147 ip = "0.0.0.0"; 147 ip = "0.0.0.0";
148 subnetMask = "0.0.0.0"; 148 subnetMask = "0.0.0.0";
149 broadcast = ""; 149 broadcast = "";
150 150
151 QTextStream stream( &file ); 151 QTextStream stream( &file );
152 QString line; 152 QString line;
153 while ( !stream.eof() ) { 153 while ( !stream.eof() ) {
154 line = stream.readLine(); 154 line = stream.readLine();
155 if(line.contains("HWaddr")){ 155 if(line.contains("HWaddr")){
156 int mac = line.find("HWaddr"); 156 int mac = line.find("HWaddr");
157 macAddress = line.mid(mac+7, line.length()); 157 macAddress = line.mid(mac+7, line.length());
158 } 158 }
159 if(line.contains("inet addr")){ 159 if(line.contains("inet addr")){
160 int ipl = line.find("inet addr"); 160 int ipl = line.find("inet addr");
161 int space = line.find(" ", ipl+10); 161 int space = line.find(" ", ipl+10);
162 ip = line.mid(ipl+10, space-ipl-10); 162 ip = line.mid(ipl+10, space-ipl-10);
163 } 163 }
164 if(line.contains("Mask")){ 164 if(line.contains("Mask")){
165 int mask = line.find("Mask"); 165 int mask = line.find("Mask");
166 subnetMask = line.mid(mask+5, line.length()); 166 subnetMask = line.mid(mask+5, line.length());
167 } 167 }
168 if(line.contains("Bcast")){ 168 if(line.contains("Bcast")){
169 int mask = line.find("Bcast"); 169 int mask = line.find("Bcast");
170 int space = line.find(" ", mask+6); 170 int space = line.find(" ", mask+6);
171 broadcast = line.mid(mask+6, space-mask-6); 171 broadcast = line.mid(mask+6, space-mask-6);
172 } 172 }
173 } 173 }
174 file.close(); 174 file.close();
175 QFile::remove(fileName); 175 QFile::remove(fileName);
176 176
177 // DHCP TESTING 177 // DHCP TESTING
178 // reset DHCP info 178 // reset DHCP info
179 dhcpServerIp = ""; 179 dhcpServerIp = "";
180 leaseObtained = ""; 180 leaseObtained = "";
181 leaseExpires = ""; 181 leaseExpires = "";
182 dhcp = false; 182 dhcp = false;
183 183
184 QString dhcpDirectory(DHCP_INFO_DIR); 184 QString dhcpDirectory(DHCP_INFO_DIR);
185 QDir d(dhcpDirectory); 185 QDir d(dhcpDirectory);
186 if(!d.exists(dhcpDirectory)) 186 if(!d.exists(dhcpDirectory))
187 dhcpDirectory = "/var/run"; 187 dhcpDirectory = "/var/run";
188 188
189 // See if we have 189 // See if we have
190 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 190 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
191 // If there is no DHCP information then exit now with no errors. 191 // If there is no DHCP information then exit now with no errors.
192 if(!QFile::exists(dhcpFile)){ 192 if(!QFile::exists(dhcpFile)){
193 emit(updateInterface(this)); 193 emit(updateInterface(this));
194 return true; 194 return true;
195 } 195 }
196 196
197 file.setName(dhcpFile); 197 file.setName(dhcpFile);
198 if (!file.open(IO_ReadOnly)){ 198 if (!file.open(IO_ReadOnly)){
199 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 199 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
200 return false; 200 return false;
201 } 201 }
202 202
203 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 203 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
204 int leaseTime = 0; 204 int leaseTime = 0;
205 int renewalTime = 0; 205 int renewalTime = 0;
206 206
207 stream.setDevice( &file ); 207 stream.setDevice( &file );
208 while ( !stream.eof() ) { 208 while ( !stream.eof() ) {
209 line = stream.readLine(); 209 line = stream.readLine();
210 if(line.contains("DHCPSIADDR=")) 210 if(line.contains("DHCPSIADDR="))
211 dhcpServerIp = line.mid(11, line.length()); 211 dhcpServerIp = line.mid(11, line.length());
212 if(line.contains("LEASETIME=")) 212 if(line.contains("LEASETIME="))
213 leaseTime = line.mid(10, line.length()).toInt(); 213 leaseTime = line.mid(10, line.length()).toInt();
214 if(line.contains("RENEWALTIME=")) 214 if(line.contains("RENEWALTIME="))
215 renewalTime = line.mid(12, line.length()).toInt(); 215 renewalTime = line.mid(12, line.length()).toInt();
216 } 216 }
217 file.close(); 217 file.close();
218 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 218 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
219 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 219 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
220 220
221 // Get the pid of the deamond 221 // Get the pid of the deamond
222 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 222 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
223 file.setName(dhcpFile); 223 file.setName(dhcpFile);
224 if (!file.open(IO_ReadOnly)){ 224 if (!file.open(IO_ReadOnly)){
225 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 225 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
226 return false; 226 return false;
227 } 227 }
228 228
229 int pid = -1; 229 int pid = -1;
230 stream.setDevice( &file ); 230 stream.setDevice( &file );
231 while ( !stream.eof() ) { 231 while ( !stream.eof() ) {
232 line = stream.readLine(); 232 line = stream.readLine();
233 pid = line.toInt(); 233 pid = line.toInt();
234 } 234 }
235 file.close(); 235 file.close();
236 236
237 if( pid == -1){ 237 if( pid == -1){
238 qDebug("Interface: Could not get pid of dhcpc deamon."); 238 qDebug("Interface: Could not get pid of dhcpc deamon.");
239 return false; 239 return false;
240 } 240 }
241 241
242 // Get the start running time of the deamon 242 // Get the start running time of the deamon
243 fileName = (QString("/proc/%1/stat").arg(pid)); 243 fileName = (QString("/proc/%1/stat").arg(pid));
244 file.setName(fileName); 244 file.setName(fileName);
245 stream.setDevice( &file ); 245 stream.setDevice( &file );
246 if (!file.open(IO_ReadOnly)){ 246 if (!file.open(IO_ReadOnly)){
247 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 247 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
248 return false; 248 return false;
249 } 249 }
250 while ( !stream.eof() ) { 250 while ( !stream.eof() ) {
251 line = stream.readLine(); 251 line = stream.readLine();
252 } 252 }
253 file.close(); 253 file.close();
254 long time = 0; 254 long time = 0;
255 // Grab the start time 255 // Grab the start time
256 // pid com state ppid pgrp session tty_nr tpgid flags 256 // pid com state ppid pgrp session tty_nr tpgid flags
257 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 257 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
258 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 258 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
259 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 259 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
260 // nice 0 itrealvalue starttime 260 // nice 0 itrealvalue starttime
261 "%*d %*d %*d %lu", (long*) &time); 261 "%*d %*d %*d %lu", (long*) &time);
262 time = time/100; 262 time = time/100;
263 263
264 QDateTime datetime(QDateTime::currentDateTime()); 264 QDateTime datetime(QDateTime::currentDateTime());
265 265
266 // Get the uptime of the computer. 266 // Get the uptime of the computer.
267 QFile f("/proc/uptime"); 267 QFile f("/proc/uptime");
268 if ( f.open(IO_ReadOnly) ) { // file opened successfully 268 if ( f.open(IO_ReadOnly) ) { // file opened successfully
269 QTextStream t( &f ); // use a text stream 269 QTextStream t( &f ); // use a text stream
270 int sec = 0; 270 int sec = 0;
271 t >> sec; 271 t >> sec;
272 datetime = datetime.addSecs((-1*sec)); 272 datetime = datetime.addSecs((-1*sec));
273 f.close(); 273 f.close();
274 } 274 }
275 else{ 275 else{
276 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 276 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
277 return false; 277 return false;
278 } 278 }
279 279
280 datetime = datetime.addSecs(time); 280 datetime = datetime.addSecs(time);
281 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 281 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
282 282
283 // Calculate the start and renew times 283 // Calculate the start and renew times
284 leaseObtained= datetime.toString(); 284 leaseObtained= datetime.toString();
285 285
286 // Calculate the start and renew times 286 // Calculate the start and renew times
287 datetime = datetime.addSecs(leaseTime); 287 datetime = datetime.addSecs(leaseTime);
288 leaseExpires = datetime.toString(); 288 leaseExpires = datetime.toString();
289 289
290 dhcp = true; 290 dhcp = true;
291 291
292 emit(updateInterface(this)); 292 emit(updateInterface(this));
293 return true; 293 return true;
294} 294}
295 295
296// interface.cpp 296// interface.cpp
297 297
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 7b93554..9a17743 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,525 +1,521 @@
1#include "mainwindowimp.h" 1#include "mainwindowimp.h"
2#include "addconnectionimp.h" 2#include "addconnectionimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4#include "interfacesetupimp.h" 4#include "interfacesetupimp.h"
5#include "interfaces.h" 5#include "interfaces.h"
6#include "module.h" 6#include "module.h"
7 7
8#include <qpushbutton.h> 8#include <qpushbutton.h>
9#include <qlistbox.h> 9#include <qlistbox.h>
10#include <qlineedit.h> 10#include <qlineedit.h>
11#include <qlistview.h> 11#include <qlistview.h>
12#include <qheader.h> 12#include <qheader.h>
13#include <qlabel.h> 13#include <qlabel.h>
14 14
15#include <qmainwindow.h> 15#include <qmainwindow.h>
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17 17
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/qlibrary.h> 19#include <qpe/qlibrary.h>
20#include <qpe/resource.h> 20#include <qpe/resource.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22 22
23#include <qlist.h> 23#include <qlist.h>
24#include <qdir.h> 24#include <qdir.h>
25#include <qfile.h> 25#include <qfile.h>
26#include <qtextstream.h> 26#include <qtextstream.h>
27 27
28#include <net/if.h> 28#include <net/if.h>
29#include <sys/ioctl.h> 29#include <sys/ioctl.h>
30 30
31#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 31#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
32 32
33MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false), scheme(DEFAULT_SCHEME){ 33MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false), scheme(DEFAULT_SCHEME){
34 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 34 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
35 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 35 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
36 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 36 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
37 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 37 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
38 38
39 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 39 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
40 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 40 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
41 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 41 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
42 42
43 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 43 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
44 // Load connections. 44 // Load connections.
45 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); 45 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
46 getAllInterfaces(); 46 getAllInterfaces();
47 47
48 Interfaces i; 48 Interfaces i;
49 QStringList list = i.getInterfaceList(); 49 QStringList list = i.getInterfaceList();
50 QMap<QString, Interface*>::Iterator it; 50 QMap<QString, Interface*>::Iterator it;
51 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 51 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
52 bool found = false; 52 bool found = false;
53 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 53 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
54 if(it.key() == (*ni)) 54 if(it.key() == (*ni))
55 found = true; 55 found = true;
56 } 56 }
57 if(!found){ 57 if(!found){
58 if(!(*ni).contains("_")){ 58 if(!(*ni).contains("_")){
59 Interface *i = new Interface(this, *ni, false); 59 Interface *i = new Interface(this, *ni, false);
60 i->setAttached(false); 60 i->setAttached(false);
61 i->setHardwareName("Disconnected"); 61 i->setHardwareName("Disconnected");
62 interfaceNames.insert(i->getInterfaceName(), i); 62 interfaceNames.insert(i->getInterfaceName(), i);
63 updateInterface(i); 63 updateInterface(i);
64 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 64 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
65 } 65 }
66 } 66 }
67 } 67 }
68 68
69 //getInterfaceList(); 69 //getInterfaceList();
70 connectionList->header()->hide(); 70 connectionList->header()->hide();
71 71
72 Config cfg("NetworkSetup"); 72 Config cfg("NetworkSetup");
73 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 73 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
74 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 74 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
75 profilesList->insertItem((*it)); 75 profilesList->insertItem((*it));
76 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 76 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
77 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 77 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
78 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 78 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
79 79
80 QFile file(scheme); 80 QFile file(scheme);
81 if ( file.open(IO_ReadOnly) ) { // file opened successfully 81 if ( file.open(IO_ReadOnly) ) { // file opened successfully
82 QTextStream stream( &file ); // use a text stream 82 QTextStream stream( &file ); // use a text stream
83 while ( !stream.eof() ) { // until end of file... 83 while ( !stream.eof() ) { // until end of file...
84 QString line = stream.readLine(); // line of text excluding '\n' 84 QString line = stream.readLine(); // line of text excluding '\n'
85 if(line.contains("SCHEME")){ 85 if(line.contains("SCHEME")){
86 line = line.mid(7, line.length()); 86 line = line.mid(7, line.length());
87 currentProfileLabel->setText(line); 87 currentProfileLabel->setText(line);
88 break; 88 break;
89 } 89 }
90 } 90 }
91 file.close(); 91 file.close();
92 } 92 }
93} 93}
94 94
95/** 95/**
96 * Deconstructor. Save profiles. Delete loaded libraries. 96 * Deconstructor. Save profiles. Delete loaded libraries.
97 */ 97 */
98MainWindowImp::~MainWindowImp(){ 98MainWindowImp::~MainWindowImp(){
99 // Save profiles. 99 // Save profiles.
100 Config cfg("NetworkSetup"); 100 Config cfg("NetworkSetup");
101 cfg.setGroup("General"); 101 cfg.setGroup("General");
102 cfg.writeEntry("Profiles", profiles.join(" ")); 102 cfg.writeEntry("Profiles", profiles.join(" "));
103 103
104 // Delete all interfaces that don't have owners. 104 // Delete all interfaces that don't have owners.
105 QMap<Interface*, QListViewItem*>::Iterator iIt; 105 QMap<Interface*, QListViewItem*>::Iterator iIt;
106 for( iIt = items.begin(); iIt != items.end(); ++iIt ){ 106 for( iIt = items.begin(); iIt != items.end(); ++iIt ){
107 if(iIt.key()->getModuleOwner() == NULL) 107 if(iIt.key()->getModuleOwner() == NULL)
108 delete iIt.key(); 108 delete iIt.key();
109 } 109 }
110 110
111 // Delete Modules and Libraries 111 // Delete Modules and Libraries
112 QMap<Module*, QLibrary*>::Iterator it; 112 QMap<Module*, QLibrary*>::Iterator it;
113 for( it = libraries.begin(); it != libraries.end(); ++it ){ 113 for( it = libraries.begin(); it != libraries.end(); ++it ){
114 delete it.key(); 114 delete it.key();
115 // I wonder why I can't delete the libraries 115 // I wonder why I can't delete the libraries
116 // What fucking shit this is. 116 // What fucking shit this is.
117 //delete it.data(); 117 //delete it.data();
118 } 118 }
119} 119}
120 120
121/** 121/**
122 * Query the kernel for all of the interfaces. 122 * Query the kernel for all of the interfaces.
123 */ 123 */
124void MainWindowImp::getAllInterfaces(){ 124void MainWindowImp::getAllInterfaces(){
125 int sockfd = socket(AF_INET, SOCK_DGRAM, 0); 125 int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
126 if(sockfd == -1) 126 if(sockfd == -1)
127 return; 127 return;
128 128
129 char buf[8*1024]; 129 char buf[8*1024];
130 struct ifconf ifc; 130 struct ifconf ifc;
131 ifc.ifc_len = sizeof(buf); 131 ifc.ifc_len = sizeof(buf);
132 ifc.ifc_req = (struct ifreq *) buf; 132 ifc.ifc_req = (struct ifreq *) buf;
133 int result=ioctl(sockfd, SIOCGIFCONF, &ifc); 133 int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
134 134
135 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ 135 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){
136 struct ifreq *ifr =(struct ifreq *) ptr; 136 struct ifreq *ifr =(struct ifreq *) ptr;
137 int len = sizeof(struct sockaddr); 137 int len = sizeof(struct sockaddr);
138#ifdef HAVE_SOCKADDR_SA_LEN 138#ifdef HAVE_SOCKADDR_SA_LEN
139 if (ifr->ifr_addr.sa_len > len) 139 if (ifr->ifr_addr.sa_len > len)
140 len = ifr->ifr_addr.sa_len; /* length > 16 */ 140 len = ifr->ifr_addr.sa_len; /* length > 16 */
141#endif 141#endif
142 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 142 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
143 143
144 int flags; 144 int flags;
145 struct sockaddr_in *sinptr; 145 struct sockaddr_in *sinptr;
146 Interface *i = NULL; 146 Interface *i = NULL;
147 switch (ifr->ifr_addr.sa_family){ 147 switch (ifr->ifr_addr.sa_family){
148 case AF_INET: 148 case AF_INET:
149 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; 149 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
150 flags=0; 150 flags=0;
151 151
152 struct ifreq ifcopy; 152 struct ifreq ifcopy;
153 ifcopy=*ifr; 153 ifcopy=*ifr;
154 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); 154 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
155 flags=ifcopy.ifr_flags; 155 flags=ifcopy.ifr_flags;
156 i = new Interface(this, ifr->ifr_name, false); 156 i = new Interface(this, ifr->ifr_name, false);
157 i->setAttached(true); 157 i->setAttached(true);
158 if ((flags & IFF_UP) == IFF_UP) 158 if ((flags & IFF_UP) == IFF_UP)
159 i->setStatus(true); 159 i->setStatus(true);
160 else 160 else
161 i->setStatus(false); 161 i->setStatus(false);
162 162
163 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 163 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
164 i->setHardwareName("Ethernet"); 164 i->setHardwareName("Ethernet");
165 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 165 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
166 i->setHardwareName("Point to Point"); 166 i->setHardwareName("Point to Point");
167 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 167 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
168 i->setHardwareName("Multicast"); 168 i->setHardwareName("Multicast");
169 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 169 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
170 i->setHardwareName("Loopback"); 170 i->setHardwareName("Loopback");
171 else 171 else
172 i->setHardwareName("Unknown"); 172 i->setHardwareName("Unknown");
173 173
174 interfaceNames.insert(i->getInterfaceName(), i); 174 interfaceNames.insert(i->getInterfaceName(), i);
175 updateInterface(i); 175 updateInterface(i);
176 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 176 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
177 break; 177 break;
178 178
179 default: 179 default:
180 qDebug(ifr->ifr_name); 180 qDebug(ifr->ifr_name);
181 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); 181 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1());
182 break; 182 break;
183 } 183 }
184 } 184 }
185} 185}
186 186
187/** 187/**
188 * Load all modules that are found in the path 188 * Load all modules that are found in the path
189 * @param path a directory that is scaned for any plugins that can be loaded 189 * @param path a directory that is scaned for any plugins that can be loaded
190 * and attempts to load them 190 * and attempts to load them
191 */ 191 */
192void MainWindowImp::loadModules(const QString &path){ 192void MainWindowImp::loadModules(const QString &path){
193 //qDebug(path.latin1()); 193 //qDebug(path.latin1());
194 QDir d(path); 194 QDir d(path);
195 if(!d.exists()) 195 if(!d.exists())
196 return; 196 return;
197 197
198 // Don't want sym links 198 // Don't want sym links
199 d.setFilter( QDir::Files | QDir::NoSymLinks ); 199 d.setFilter( QDir::Files | QDir::NoSymLinks );
200 const QFileInfoList *list = d.entryInfoList(); 200 const QFileInfoList *list = d.entryInfoList();
201 QFileInfoListIterator it( *list ); 201 QFileInfoListIterator it( *list );
202 QFileInfo *fi; 202 QFileInfo *fi;
203 while ( (fi=it.current()) ) { 203 while ( (fi=it.current()) ) {
204 if(fi->fileName().contains(".so")){ 204 if(fi->fileName().contains(".so")){
205 loadPlugin(path + "/" + fi->fileName()); 205 loadPlugin(path + "/" + fi->fileName());
206 } 206 }
207 ++it; 207 ++it;
208 } 208 }
209} 209}
210 210
211/** 211/**
212 * Attempt to load a function and resolve a function. 212 * Attempt to load a function and resolve a function.
213 * @param pluginFileName - the name of the file in which to attempt to load 213 * @param pluginFileName - the name of the file in which to attempt to load
214 * @param resolveString - function pointer to resolve 214 * @param resolveString - function pointer to resolve
215 * @return pointer to the function with name resolveString or NULL 215 * @return pointer to the function with name resolveString or NULL
216 */ 216 */
217Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ 217Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){
218 //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 218 //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
219 QLibrary *lib = new QLibrary(pluginFileName); 219 QLibrary *lib = new QLibrary(pluginFileName);
220 void *functionPointer = lib->resolve(resolveString); 220 void *functionPointer = lib->resolve(resolveString);
221 if( !functionPointer ){ 221 if( !functionPointer ){
222 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 222 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
223 delete lib; 223 delete lib;
224 return NULL; 224 return NULL;
225 } 225 }
226 226
227 // Try to get an object. 227 // Try to get an object.
228 Module *object = ((Module* (*)()) functionPointer)(); 228 Module *object = ((Module* (*)()) functionPointer)();
229 if(object == NULL){ 229 if(object == NULL){
230 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 230 qDebug("MainWindowImp: Couldn't create object, but did load library!");
231 delete lib; 231 delete lib;
232 return NULL; 232 return NULL;
233 } 233 }
234 234
235 // Store for deletion later 235 // Store for deletion later
236 libraries.insert(object, lib); 236 libraries.insert(object, lib);
237 return object; 237 return object;
238} 238}
239 239
240/** 240/**
241 * The Add button was clicked. Bring up the add dialog and if OK is hit 241 * The Add button was clicked. Bring up the add dialog and if OK is hit
242 * load the plugin and append it to the list 242 * load the plugin and append it to the list
243 */ 243 */
244void MainWindowImp::addClicked(){ 244void MainWindowImp::addClicked(){
245 QMap<Module*, QLibrary*>::Iterator it; 245 QMap<Module*, QLibrary*>::Iterator it;
246 QMap<QString, QString> list; 246 QMap<QString, QString> list;
247 QMap<QString, Module*> newInterfaceOwners; 247 QMap<QString, Module*> newInterfaceOwners;
248 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 248 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
249 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 249 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
250 for( it = libraries.begin(); it != libraries.end(); ++it ){ 250 for( it = libraries.begin(); it != libraries.end(); ++it ){
251 if(it.key()){ 251 if(it.key()){
252 (it.key())->possibleNewInterfaces(list); 252 (it.key())->possibleNewInterfaces(list);
253 } 253 }
254 } 254 }
255 // See if the list has anything that we can add. 255 // See if the list has anything that we can add.
256 if(list.count() == 0){ 256 if(list.count() == 0){
257 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 257 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
258 return; 258 return;
259 } 259 }
260 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 260 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
261 addNewConnection.addConnections(list); 261 addNewConnection.addConnections(list);
262 addNewConnection.showMaximized(); 262 addNewConnection.showMaximized();
263 if(QDialog::Accepted == addNewConnection.exec()){ 263 if(QDialog::Accepted == addNewConnection.exec()){
264 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 264 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
265 if(!item) 265 if(!item)
266 return; 266 return;
267 267
268 for( it = libraries.begin(); it != libraries.end(); ++it ){ 268 for( it = libraries.begin(); it != libraries.end(); ++it ){
269 if(it.key()){ 269 if(it.key()){
270 Interface *i = (it.key())->addNewInterface(item->text(0)); 270 Interface *i = (it.key())->addNewInterface(item->text(0));
271 if(i){ 271 if(i){
272 interfaceNames.insert(i->getInterfaceName(), i); 272 interfaceNames.insert(i->getInterfaceName(), i);
273 updateInterface(i); 273 updateInterface(i);
274 } 274 }
275 } 275 }
276 } 276 }
277 } 277 }
278} 278}
279 279
280/** 280/**
281 * Prompt the user to see if they really want to do this. 281 * Prompt the user to see if they really want to do this.
282 * If they do then remove from the list and unload. 282 * If they do then remove from the list and unload.
283 */ 283 */
284void MainWindowImp::removeClicked(){ 284void MainWindowImp::removeClicked(){
285 QListViewItem *item = connectionList->currentItem(); 285 QListViewItem *item = connectionList->currentItem();
286 if(!item) { 286 if(!item) {
287 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 287 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
288 return; 288 return;
289 } 289 }
290 290
291 Interface *i = interfaceItems[item]; 291 Interface *i = interfaceItems[item];
292 if(i->getModuleOwner() == NULL){ 292 if(i->getModuleOwner() == NULL){
293 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 293 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
294 } 294 }
295 else{ 295 else{
296 if(!i->getModuleOwner()->remove(i)) 296 if(!i->getModuleOwner()->remove(i))
297 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); 297 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
298 else{ 298 else{
299 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 299 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
300 // TODO memory managment.... 300 // TODO memory managment....
301 // who deletes the interface? 301 // who deletes the interface?
302 } 302 }
303 } 303 }
304} 304}
305 305
306/** 306/**
307 * Pull up the configure about the currently selected interface. 307 * Pull up the configure about the currently selected interface.
308 * Report an error if no interface is selected. 308 * Report an error if no interface is selected.
309 * If the interface has a module owner then request its configure. 309 * If the interface has a module owner then request its configure.
310 */ 310 */
311void MainWindowImp::configureClicked(){ 311void MainWindowImp::configureClicked(){
312 QListViewItem *item = connectionList->currentItem(); 312 QListViewItem *item = connectionList->currentItem();
313 if(!item){ 313 if(!item){
314 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); 314 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
315 return; 315 return;
316 } 316 }
317 317
318 Interface *i = interfaceItems[item]; 318 Interface *i = interfaceItems[item];
319 if(i->getModuleOwner()){ 319 if(i->getModuleOwner()){
320 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 320 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
321 if(moduleConfigure != NULL){ 321 if(moduleConfigure != NULL){
322 moduleConfigure->showMaximized(); 322 moduleConfigure->showMaximized();
323 moduleConfigure->show();
324 return; 323 return;
325 } 324 }
326 } 325 }
327 326
328 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); 327 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose);
329 QString currentProfileText = currentProfileLabel->text(); 328 QString currentProfileText = currentProfileLabel->text();
330 if(currentProfileText.upper() == "ALL"); 329 if(currentProfileText.upper() == "ALL");
331 currentProfileText = ""; 330 currentProfileText = "";
332 configure->setProfile(currentProfileText); 331 configure->setProfile(currentProfileText);
333 configure->showMaximized(); 332 configure->showMaximized();
334 configure->show();
335} 333}
336 334
337/** 335/**
338 * Pull up the information about the currently selected interface. 336 * Pull up the information about the currently selected interface.
339 * Report an error if no interface is selected. 337 * Report an error if no interface is selected.
340 * If the interface has a module owner then request its configure. 338 * If the interface has a module owner then request its configure.
341 */ 339 */
342void MainWindowImp::informationClicked(){ 340void MainWindowImp::informationClicked(){
343 QListViewItem *item = connectionList->currentItem(); 341 QListViewItem *item = connectionList->currentItem();
344 if(!item){ 342 if(!item){
345 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 343 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
346 return; 344 return;
347 } 345 }
348 346
349 Interface *i = interfaceItems[item]; 347 Interface *i = interfaceItems[item];
350 if(!i->isAttached()){ 348 if(!i->isAttached()){
351 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 349 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
352 return; 350 return;
353 } 351 }
354 352
355 if(i->getModuleOwner()){ 353 if(i->getModuleOwner()){
356 QWidget *moduleInformation = i->getModuleOwner()->information(i); 354 QWidget *moduleInformation = i->getModuleOwner()->information(i);
357 if(moduleInformation != NULL){ 355 if(moduleInformation != NULL){
358 moduleInformation->showMaximized(); 356 moduleInformation->showMaximized();
359 moduleInformation->show();
360 return; 357 return;
361 } 358 }
362 } 359 }
363 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 360 InterfaceInformationImp information(0, "InterfaceSetupImp", i);
364 information->showMaximized(); 361 information.showMaximized();
365 information->show();
366} 362}
367 363
368/** 364/**
369 * Update this interface. If no QListViewItem exists create one. 365 * Update this interface. If no QListViewItem exists create one.
370 * @param Interface* pointer to the interface that needs to be updated. 366 * @param Interface* pointer to the interface that needs to be updated.
371 */ 367 */
372void MainWindowImp::updateInterface(Interface *i){ 368void MainWindowImp::updateInterface(Interface *i){
373 if(!advancedUserMode){ 369 if(!advancedUserMode){
374 if(i->getInterfaceName() == "lo") 370 if(i->getInterfaceName() == "lo")
375 return; 371 return;
376 } 372 }
377 373
378 QListViewItem *item = NULL; 374 QListViewItem *item = NULL;
379 375
380 // Find the interface, making it if needed. 376 // Find the interface, making it if needed.
381 if(items.find(i) == items.end()){ 377 if(items.find(i) == items.end()){
382 item = new QListViewItem(connectionList, "", "", ""); 378 item = new QListViewItem(connectionList, "", "", "");
383 // See if you can't find a module owner for this interface 379 // See if you can't find a module owner for this interface
384 QMap<Module*, QLibrary*>::Iterator it; 380 QMap<Module*, QLibrary*>::Iterator it;
385 for( it = libraries.begin(); it != libraries.end(); ++it ){ 381 for( it = libraries.begin(); it != libraries.end(); ++it ){
386 if(it.key()->isOwner(i)) 382 if(it.key()->isOwner(i))
387 i->setModuleOwner(it.key()); 383 i->setModuleOwner(it.key());
388 } 384 }
389 items.insert(i, item); 385 items.insert(i, item);
390 interfaceItems.insert(item, i); 386 interfaceItems.insert(item, i);
391 } 387 }
392 else 388 else
393 item = items[i]; 389 item = items[i];
394 390
395 // Update the icons and information 391 // Update the icons and information
396 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 392 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
397 393
398 QString typeName = "lan"; 394 QString typeName = "lan";
399 if(i->getHardwareName().contains("Local Loopback")) 395 if(i->getHardwareName().contains("Local Loopback"))
400 typeName = "lo"; 396 typeName = "lo";
401 if(i->getInterfaceName().contains("irda")) 397 if(i->getInterfaceName().contains("irda"))
402 typeName = "irda"; 398 typeName = "irda";
403 if(i->getInterfaceName().contains("wlan")) 399 if(i->getInterfaceName().contains("wlan"))
404 typeName = "wlan"; 400 typeName = "wlan";
405 if(i->getInterfaceName().contains("usb")) 401 if(i->getInterfaceName().contains("usb"))
406 typeName = "usb"; 402 typeName = "usb";
407 403
408 if(!i->isAttached()) 404 if(!i->isAttached())
409 typeName = "connect_no"; 405 typeName = "connect_no";
410 // Actually try to use the Module 406 // Actually try to use the Module
411 if(i->getModuleOwner() != NULL) 407 if(i->getModuleOwner() != NULL)
412 typeName = i->getModuleOwner()->getPixmapName(i); 408 typeName = i->getModuleOwner()->getPixmapName(i);
413 409
414 item->setPixmap(1, (Resource::loadPixmap(typeName))); 410 item->setPixmap(1, (Resource::loadPixmap(QString("networksetup/") + typeName)));
415 item->setText(2, i->getHardwareName()); 411 item->setText(2, i->getHardwareName());
416 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 412 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
417 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 413 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
418} 414}
419 415
420void MainWindowImp::newProfileChanged(const QString& newText){ 416void MainWindowImp::newProfileChanged(const QString& newText){
421 if(newText.length() > 0) 417 if(newText.length() > 0)
422 newProfileButton->setEnabled(true); 418 newProfileButton->setEnabled(true);
423 else 419 else
424 newProfileButton->setEnabled(false); 420 newProfileButton->setEnabled(false);
425} 421}
426 422
427/** 423/**
428 * Adds a new profile to the list of profiles. 424 * Adds a new profile to the list of profiles.
429 * Don't add profiles that already exists. 425 * Don't add profiles that already exists.
430 * Appends to the list and QStringList 426 * Appends to the list and QStringList
431 */ 427 */
432void MainWindowImp::addProfile(){ 428void MainWindowImp::addProfile(){
433 QString newProfileName = newProfile->text(); 429 QString newProfileName = newProfile->text();
434 if(profiles.grep(newProfileName).count() > 0){ 430 if(profiles.grep(newProfileName).count() > 0){
435 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 431 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
436 return; 432 return;
437 } 433 }
438 profiles.append(newProfileName); 434 profiles.append(newProfileName);
439 profilesList->insertItem(newProfileName); 435 profilesList->insertItem(newProfileName);
440} 436}
441 437
442/** 438/**
443 * Removes the currently selected profile in the combo. 439 * Removes the currently selected profile in the combo.
444 * Doesn't delete if there are less then 2 profiles. 440 * Doesn't delete if there are less then 2 profiles.
445 */ 441 */
446void MainWindowImp::removeProfile(){ 442void MainWindowImp::removeProfile(){
447 if(profilesList->count() <= 1){ 443 if(profilesList->count() <= 1){
448 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 444 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
449 return; 445 return;
450 } 446 }
451 QString profileToRemove = profilesList->currentText(); 447 QString profileToRemove = profilesList->currentText();
452 if(profileToRemove == "All"){ 448 if(profileToRemove == "All"){
453 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 449 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
454 return; 450 return;
455 } 451 }
456 // Can't remove the curent profile 452 // Can't remove the curent profile
457 if(profileToRemove == currentProfileLabel->text()){ 453 if(profileToRemove == currentProfileLabel->text()){
458 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 454 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
459 return; 455 return;
460 456
461 } 457 }
462 458
463 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 459 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
464 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 460 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
465 profilesList->clear(); 461 profilesList->clear();
466 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 462 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
467 profilesList->insertItem((*it)); 463 profilesList->insertItem((*it));
468 464
469 // Remove any interface settings and mappings. 465 // Remove any interface settings and mappings.
470 Interfaces interfaces; 466 Interfaces interfaces;
471 // Go through them one by one 467 // Go through them one by one
472 QMap<Interface*, QListViewItem*>::Iterator it; 468 QMap<Interface*, QListViewItem*>::Iterator it;
473 for( it = items.begin(); it != items.end(); ++it ){ 469 for( it = items.begin(); it != items.end(); ++it ){
474 QString interfaceName = it.key()->getInterfaceName(); 470 QString interfaceName = it.key()->getInterfaceName();
475 qDebug(interfaceName.latin1()); 471 qDebug(interfaceName.latin1());
476 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ 472 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){
477 interfaces.removeInterface(); 473 interfaces.removeInterface();
478 if(interfaces.setMapping(interfaceName)){ 474 if(interfaces.setMapping(interfaceName)){
479 if(profilesList->count() == 1) 475 if(profilesList->count() == 1)
480 interfaces.removeMapping(); 476 interfaces.removeMapping();
481 else{ 477 else{
482 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 478 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
483 } 479 }
484 } 480 }
485 interfaces.write(); 481 interfaces.write();
486 break; 482 break;
487 } 483 }
488 } 484 }
489 } 485 }
490} 486}
491 487
492/** 488/**
493 * A new profile has been selected, change. 489 * A new profile has been selected, change.
494 * @param newProfile the new profile. 490 * @param newProfile the new profile.
495 */ 491 */
496void MainWindowImp::changeProfile(){ 492void MainWindowImp::changeProfile(){
497 if(profilesList->currentItem() == -1){ 493 if(profilesList->currentItem() == -1){
498 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 494 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
499 return; 495 return;
500 } 496 }
501 QString newProfile = profilesList->text(profilesList->currentItem()); 497 QString newProfile = profilesList->text(profilesList->currentItem());
502 if(newProfile != currentProfileLabel->text()){ 498 if(newProfile != currentProfileLabel->text()){
503 currentProfileLabel->setText(newProfile); 499 currentProfileLabel->setText(newProfile);
504 QFile::remove(scheme); 500 QFile::remove(scheme);
505 QFile file(scheme); 501 QFile file(scheme);
506 if ( file.open(IO_ReadWrite) ) { 502 if ( file.open(IO_ReadWrite) ) {
507 QTextStream stream( &file ); 503 QTextStream stream( &file );
508 stream << QString("SCHEME=%1").arg(newProfile); 504 stream << QString("SCHEME=%1").arg(newProfile);
509 file.close(); 505 file.close();
510 } 506 }
511 // restart all up devices? 507 // restart all up devices?
512 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 508 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
513 // Go through them one by one 509 // Go through them one by one
514 QMap<Interface*, QListViewItem*>::Iterator it; 510 QMap<Interface*, QListViewItem*>::Iterator it;
515 for( it = items.begin(); it != items.end(); ++it ){ 511 for( it = items.begin(); it != items.end(); ++it ){
516 if(it.key()->getStatus() == true) 512 if(it.key()->getStatus() == true)
517 it.key()->restart(); 513 it.key()->restart();
518 } 514 }
519 } 515 }
520 } 516 }
521 // TODO change the profile in the modules 517 // TODO change the profile in the modules
522} 518}
523 519
524// mainwindowimp.cpp 520// mainwindowimp.cpp
525 521
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp
index cc18fba..648932f 100644
--- a/noncore/settings/networksettings/wlan/wlanimp.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp.cpp
@@ -1,244 +1,244 @@
1#include "wlanimp.h" 1#include "wlanimp.h"
2#include "interfacesetupimp.h" 2#include "interfacesetupimp.h"
3 3
4#include <qfile.h> 4#include <qfile.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qlineedit.h> 8#include <qlineedit.h>
9#include <qlabel.h> 9#include <qlabel.h>
10#include <qspinbox.h> 10#include <qspinbox.h>
11#include <qradiobutton.h> 11#include <qradiobutton.h>
12#include <qcheckbox.h> 12#include <qcheckbox.h>
13#include <qtabwidget.h> 13#include <qtabwidget.h>
14#include <qcombobox.h> 14#include <qcombobox.h>
15 15
16/* system() */ 16/* system() */
17#include <stdlib.h> 17#include <stdlib.h>
18 18
19#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 19#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
20 20
21/** 21/**
22 * Constructor, read in the wireless.opts file for parsing later. 22 * Constructor, read in the wireless.opts file for parsing later.
23 */ 23 */
24WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { 24WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") {
25 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); 25 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);
26 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 26 tabWidget->insertTab(interfaceSetup, "TCP/IP");
27 27
28 // Read in the config file. 28 // Read in the config file.
29 QString wlanFile = WIRELESS_OPTS; 29 QString wlanFile = WIRELESS_OPTS;
30 QFile file(wlanFile); 30 QFile file(wlanFile);
31 if (file.open(IO_ReadOnly)){ 31 if (file.open(IO_ReadOnly)){
32 QTextStream stream( &file ); 32 QTextStream stream( &file );
33 QString line = ""; 33 QString line = "";
34 while ( !stream.eof() ) { 34 while ( !stream.eof() ) {
35 line += stream.readLine(); 35 line += stream.readLine();
36 line += "\n"; 36 line += "\n";
37 } 37 }
38 file.close(); 38 file.close();
39 settingsFileText = QStringList::split("\n", line, true); 39 settingsFileText = QStringList::split("\n", line, true);
40 parseSettingFile(); 40 parseSettingFile();
41 } 41 }
42 else 42 else
43 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); 43 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1());
44 connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); 44 connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
45} 45}
46 46
47void WLANImp::typeChanged(int mod){ 47void WLANImp::typeChanged(int mod){
48 networkChannel->setEnabled(mod); 48 networkChannel->setEnabled(mod);
49 channelLabel->setEnabled(mod); 49 channelLabel->setEnabled(mod);
50} 50}
51 51
52/** 52/**
53 * Change the profile for both wireless settings and network settings. 53 * Change the profile for both wireless settings and network settings.
54 */ 54 */
55void WLANImp::setProfile(const QString &profile){ 55void WLANImp::setProfile(const QString &profile){
56 interfaceSetup->setProfile(profile); 56 interfaceSetup->setProfile(profile);
57 parseSettingFile(); 57 parseSettingFile();
58} 58}
59 59
60/** 60/**
61 * Parses the settings file that was read in and gets any setting from it. 61 * Parses the settings file that was read in and gets any setting from it.
62 */ 62 */
63void WLANImp::parseSettingFile(){ 63void WLANImp::parseSettingFile(){
64 bool foundCase = false; 64 bool foundCase = false;
65 bool found = false; 65 bool found = false;
66 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { 66 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
67 QString line = (*it).simplifyWhiteSpace(); 67 QString line = (*it).simplifyWhiteSpace();
68 if(line.contains("case")) 68 if(line.contains("case"))
69 foundCase = true; 69 foundCase = true;
70 // See if we found our scheme to write or the sceme couldn't be found 70 // See if we found our scheme to write or the sceme couldn't be found
71 if((foundCase && line.contains("esac")) || 71 if((foundCase && line.contains("esac")) ||
72 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) 72 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
73 found = true; 73 found = true;
74 74
75 if(line.contains(";;")) 75 if(line.contains(";;"))
76 found = false; 76 found = false;
77 if(found){ 77 if(found){
78 // write out scheme 78 // write out scheme
79 if(line.contains("ESSID=")){ 79 if(line.contains("ESSID=")){
80 QString id = line.mid(line.find("ESSID=")+6, line.length()); 80 QString id = line.mid(line.find("ESSID=")+6, line.length());
81 if(id == "any"){ 81 if(id == "any"){
82 essAny->setChecked(false); 82 essAny->setChecked(false);
83 }else{ 83 }else{
84 essAny->setChecked(true); 84 essAny->setChecked(true);
85 essSpecificLineEdit->setText(id); 85 essSpecificLineEdit->setText(id);
86 } 86 }
87 } 87 }
88 if(line.contains("MODE=")){ 88 if(line.contains("MODE=")){
89 QString mode = line.mid(line.find("MODE=")+5, line.length()); 89 QString mode = line.mid(line.find("MODE=")+5, line.length());
90 if(mode == "Managed"){ 90 if(mode == "Managed"){
91 networkType->setCurrentItem(0); 91 networkType->setCurrentItem(0);
92 channelLabel->setEnabled(false); 92 channelLabel->setEnabled(false);
93 networkChannel->setEnabled(false); 93 networkChannel->setEnabled(false);
94 } 94 }
95 else{ 95 else{
96 networkType->setCurrentItem(1); 96 networkType->setCurrentItem(1);
97 networkChannel->setEnabled(true); 97 networkChannel->setEnabled(true);
98 channelLabel->setEnabled(true); 98 channelLabel->setEnabled(true);
99 } 99 }
100 } 100 }
101 if(line.contains("#KEY0=")) 101 if(line.contains("#KEY0="))
102 keyLineEdit0->setText(line.mid(5, line.length())); 102 keyLineEdit0->setText(line.mid(6, line.length()));
103 if(line.contains("#KEY1=")) 103 if(line.contains("#KEY1="))
104 keyLineEdit1->setText(line.mid(5, line.length())); 104 keyLineEdit1->setText(line.mid(6, line.length()));
105 if(line.contains("#KEY2=")) 105 if(line.contains("#KEY2="))
106 keyLineEdit2->setText(line.mid(5, line.length())); 106 keyLineEdit2->setText(line.mid(6, line.length()));
107 if(line.contains("#KEY3=")) 107 if(line.contains("#KEY3="))
108 keyLineEdit3->setText(line.mid(5, line.length())); 108 keyLineEdit3->setText(line.mid(6, line.length()));
109 109
110 if(line.contains("KEY=")){ 110 if(line.contains("KEY=")){
111 wepEnabled->setChecked(true); 111 wepEnabled->setChecked(true);
112 QString key; 112 QString key;
113 if(line.right(5) == (" open")){ 113 if(line.right(5) == (" open")){
114 key = line.mid(4, line.length()-5); 114 key = line.mid(4, line.length()-5);
115 authOpen->setChecked(true); 115 authOpen->setChecked(true);
116 authShared->setChecked(false); 116 authShared->setChecked(false);
117 } 117 }
118 else{ 118 else{
119 authOpen->setChecked(false); 119 authOpen->setChecked(false);
120 authShared->setChecked(true); 120 authShared->setChecked(true);
121 key = line.mid(4, line.length()); 121 key = line.mid(4, line.length());
122 } 122 }
123 if(key == keyLineEdit0->text()) keyRadio0->setChecked(true); 123 if(key == keyLineEdit0->text()) keyRadio0->setChecked(true);
124 if(key == keyLineEdit1->text()) keyRadio1->setChecked(true); 124 if(key == keyLineEdit1->text()) keyRadio1->setChecked(true);
125 if(key == keyLineEdit2->text()) keyRadio2->setChecked(true); 125 if(key == keyLineEdit2->text()) keyRadio2->setChecked(true);
126 if(key == keyLineEdit3->text()) keyRadio3->setChecked(true); 126 if(key == keyLineEdit3->text()) keyRadio3->setChecked(true);
127 } 127 }
128 if(line.contains("CHANNEL=")){ 128 if(line.contains("CHANNEL=")){
129 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); 129 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt());
130 } 130 }
131 } 131 }
132 } 132 }
133} 133}
134 134
135/** 135/**
136 * Saves settings to the wireless.opts file using the current profile 136 * Saves settings to the wireless.opts file using the current profile
137 */ 137 */
138void WLANImp::changeAndSaveSettingFile(){ 138void WLANImp::changeAndSaveSettingFile(){
139 QString wlanFile = WIRELESS_OPTS; 139 QString wlanFile = WIRELESS_OPTS;
140 QFile::remove(wlanFile); 140 QFile::remove(wlanFile);
141 QFile file(wlanFile); 141 QFile file(wlanFile);
142 142
143 if (!file.open(IO_ReadWrite)){ 143 if (!file.open(IO_ReadWrite)){
144 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); 144 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
145 return; 145 return;
146 } 146 }
147 147
148 QTextStream stream( &file ); 148 QTextStream stream( &file );
149 bool foundCase = false; 149 bool foundCase = false;
150 bool found = false; 150 bool found = false;
151 bool output = true; 151 bool output = true;
152 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { 152 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
153 QString line = (*it).simplifyWhiteSpace(); 153 QString line = (*it).simplifyWhiteSpace();
154 if(line.contains("case")) 154 if(line.contains("case"))
155 foundCase = true; 155 foundCase = true;
156 // See if we found our scheme to write or the sceme couldn't be found 156 // See if we found our scheme to write or the sceme couldn't be found
157 if((foundCase && line.contains("esac") && !found) || 157 if((foundCase && line.contains("esac") && !found) ||
158 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ 158 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
159 // write out scheme 159 // write out scheme
160 found = true; 160 found = true;
161 output = false; 161 output = false;
162 162
163 if(!line.contains("esac")) 163 if(!line.contains("esac"))
164 stream << line << "\n"; 164 stream << line << "\n";
165 if(!essAny->isChecked() == true){ 165 if(!essAny->isChecked() == true){
166 stream << "\tESSID=any\n"; 166 stream << "\tESSID=any\n";
167 stream << "\tMODE=Managed\n"; 167 stream << "\tMODE=Managed\n";
168 } 168 }
169 else{ 169 else{
170 stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; 170 stream << "\tESSID=" << essSpecificLineEdit->text() << '\n';
171 stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; 171 stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n';
172 stream << "\tCHANNEL=" << networkChannel->value() << "\n"; 172 stream << "\tCHANNEL=" << networkChannel->value() << "\n";
173 } 173 }
174 174
175 stream << "\t#KEY0=" << keyLineEdit0->text() << "\n"; 175 stream << "\t#KEY0=" << keyLineEdit0->text() << "\n";
176 stream << "\t#KEY1=" << keyLineEdit1->text() << "\n"; 176 stream << "\t#KEY1=" << keyLineEdit1->text() << "\n";
177 stream << "\t#KEY2=" << keyLineEdit2->text() << "\n"; 177 stream << "\t#KEY2=" << keyLineEdit2->text() << "\n";
178 stream << "\t#KEY3=" << keyLineEdit3->text() << "\n"; 178 stream << "\t#KEY3=" << keyLineEdit3->text() << "\n";
179 179
180 if(wepEnabled->isChecked()){ 180 if(wepEnabled->isChecked()){
181 stream << "\tKEY=\""; 181 stream << "\tKEY=\"";
182 if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); 182 if(keyRadio0->isChecked()) stream << keyLineEdit0->text();
183 if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); 183 if(keyRadio1->isChecked()) stream << keyLineEdit1->text();
184 if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); 184 if(keyRadio2->isChecked()) stream << keyLineEdit2->text();
185 if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); 185 if(keyRadio3->isChecked()) stream << keyLineEdit3->text();
186 if(authOpen->isChecked()) 186 if(authOpen->isChecked())
187 stream << " open"; 187 stream << " open";
188 else 188 else
189 stream << " restricted"; 189 stream << " restricted";
190 stream << "\"\n"; 190 stream << "\"\n";
191 } 191 }
192 stream << "\tRATE=auto\n"; 192 stream << "\tRATE=auto\n";
193 if(line.contains("esac")) 193 if(line.contains("esac"))
194 stream << line << "\n"; 194 stream << line << "\n";
195 } 195 }
196 if(line.contains(";;")) 196 if(line.contains(";;"))
197 output = true; 197 output = true;
198 if(output && (*it).length() ) 198 if(output && (*it).length() )
199 stream << (*it) << '\n'; 199 stream << (*it) << '\n';
200 } 200 }
201 file.close(); 201 file.close();
202} 202}
203 203
204/** 204/**
205 * Check to see if the current config is valid 205 * Check to see if the current config is valid
206 * Save wireless.opts, save interfaces 206 * Save wireless.opts, save interfaces
207 */ 207 */
208void WLANImp::accept(){ 208void WLANImp::accept(){
209 if(wepEnabled->isChecked()){ 209 if(wepEnabled->isChecked()){
210 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){ 210 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){
211 QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); 211 QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok);
212 return; 212 return;
213 } 213 }
214 } 214 }
215 215
216 if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){ 216 if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){
217 QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok); 217 QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok);
218 return; 218 return;
219 } 219 }
220 220
221 // Ok settings are good here, save 221 // Ok settings are good here, save
222 changeAndSaveSettingFile(); 222 changeAndSaveSettingFile();
223 223
224 // Try to save the interfaces settings. 224 // Try to save the interfaces settings.
225 if(!interfaceSetup->saveChanges()) 225 if(!interfaceSetup->saveChanges())
226 return; 226 return;
227 227
228 // Restart the device now that the settings have changed 228 // Restart the device now that the settings have changed
229 QString initpath; 229 QString initpath;
230 if( QDir("/etc/rc.d/init.d").exists() ) 230 if( QDir("/etc/rc.d/init.d").exists() )
231 initpath = "/etc/rc.d/init.d"; 231 initpath = "/etc/rc.d/init.d";
232 else if( QDir("/etc/init.d").exists() ) 232 else if( QDir("/etc/init.d").exists() )
233 initpath = "/etc/init.d"; 233 initpath = "/etc/init.d";
234 if( initpath ) 234 if( initpath )
235 system(QString("%1/pcmcia stop").arg(initpath)); 235 system(QString("%1/pcmcia stop").arg(initpath));
236 if( initpath ) 236 if( initpath )
237 system(QString("%1/pcmcia start").arg(initpath)); 237 system(QString("%1/pcmcia start").arg(initpath));
238 238
239 // Close out the dialog 239 // Close out the dialog
240 QDialog::accept(); 240 QDialog::accept();
241} 241}
242 242
243// wlanimp.cpp 243// wlanimp.cpp
244 244