author | benmeyer <benmeyer> | 2002-10-17 16:30:44 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-17 16:30:44 (UTC) |
commit | 18cc7321db186865629a5c4702074211e42b92fd (patch) (unidiff) | |
tree | beb15112009c1cc966115904a322b32d465e47e6 | |
parent | 75f078ec92376db2c90a327bbc50d9bb5c1fb57a (diff) | |
download | opie-18cc7321db186865629a5c4702074211e42b92fd.zip opie-18cc7321db186865629a5c4702074211e42b92fd.tar.gz opie-18cc7321db186865629a5c4702074211e42b92fd.tar.bz2 |
interface is now a qobject
-rw-r--r-- | noncore/net/networksetup/TODO | 2 | ||||
-rw-r--r-- | noncore/net/networksetup/interface.cpp | 77 | ||||
-rw-r--r-- | noncore/net/networksetup/interface.h | 31 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaceadvanced.ui | 11 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaceinformationimp.cpp | 51 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaceinformationimp.h | 6 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 43 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanmodule.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/TODO | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/interface.cpp | 77 | ||||
-rw-r--r-- | noncore/settings/networksettings/interface.h | 31 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceadvanced.ui | 11 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceinformationimp.cpp | 51 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceinformationimp.h | 6 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 43 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanmodule.cpp | 4 |
16 files changed, 258 insertions, 192 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO index 7386646..c8e2989 100644 --- a/noncore/net/networksetup/TODO +++ b/noncore/net/networksetup/TODO | |||
@@ -1,8 +1,10 @@ | |||
1 | Write a class that parses /proc and not ifconfig | ||
2 | |||
1 | [ ] Wlanmodule needs to check if an interface supports wireless | 3 | [ ] Wlanmodule needs to check if an interface supports wireless |
2 | extensions. | 4 | extensions. |
3 | [x] When you set options in wlanmodule, hit OK, it exits all of | 5 | [x] When you set options in wlanmodule, hit OK, it exits all of |
4 | networksetup, doesnt bring you back to the main screen. | 6 | networksetup, doesnt bring you back to the main screen. |
5 | [x] Wlanmodule isnt writing out wireless.opts | 7 | [x] Wlanmodule isnt writing out wireless.opts |
6 | [ ] Need a means of bringing an interface up and down (calling | 8 | [ ] Need a means of bringing an interface up and down (calling |
7 | out ifup/ifdown) from the gui. | 9 | out ifup/ifdown) from the gui. |
8 | -Ben- Click information, then click up or down... :-D | 10 | -Ben- Click information, then click up or down... :-D |
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp index 1f32093..1e01da4 100644 --- a/noncore/net/networksetup/interface.cpp +++ b/noncore/net/networksetup/interface.cpp | |||
@@ -1,242 +1,287 @@ | |||
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 HDCP_INFO_DIR "/etc/dhcpc" | 9 | #define HDCP_INFO_DIR "/etc/dhcpc" |
10 | 10 | ||
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | 13 | ||
14 | Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ | 14 | Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | ||
20 | * @param newStatus - the new status | ||
21 | * emit updateInterface | ||
22 | */ | ||
23 | void Interface::setStatus(bool newStatus){ | ||
24 | if(status != newStatus){ | ||
25 | status = newStatus; | ||
26 | refresh(); | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * Set if attached or not (802.11 card pulled out for example) | ||
32 | * @param isAttached - if attached | ||
33 | * emit updateInterface | ||
34 | */ | ||
35 | void Interface::setAttached(bool isAttached){ | ||
36 | attached = isAttached; | ||
37 | emit(updateInterface(this)); | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * Set Hardware name | ||
42 | * @param name - the new name | ||
43 | * emit updateInterface | ||
44 | */ | ||
45 | void Interface::setHardwareName(QString name){ | ||
46 | hardareName = name; | ||
47 | emit(updateInterface(this)); | ||
48 | }; | ||
49 | |||
50 | /** | ||
51 | * Set Module owner | ||
52 | * @param owner - the new owner | ||
53 | * emit updateInterface | ||
54 | */ | ||
55 | void Interface::setModuleOwner(Module *owner){ | ||
56 | moduleOwner = owner; | ||
57 | emit(updateInterface(this)); | ||
58 | }; | ||
59 | |||
60 | |||
61 | /** | ||
19 | * Try to start the interface. | 62 | * Try to start the interface. |
20 | * @return bool true if successfull. | ||
21 | */ | 63 | */ |
22 | bool Interface::start(){ | 64 | void Interface::start(){ |
23 | // check to see if we are already running. | 65 | // check to see if we are already running. |
24 | if(status) | 66 | if(true == status) |
25 | return false; | 67 | return; |
26 | 68 | ||
27 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | 69 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); |
70 | // See if it was successfull... | ||
28 | if(ret != 0) | 71 | if(ret != 0) |
29 | return false; | 72 | return; |
30 | 73 | ||
31 | status = true; | 74 | status = true; |
32 | refresh(); | 75 | refresh(); |
33 | return true; | ||
34 | } | 76 | } |
35 | 77 | ||
36 | /** | 78 | /** |
37 | * Try to stop the interface. | 79 | * Try to stop the interface. |
38 | * @return bool true if successfull. | ||
39 | */ | 80 | */ |
40 | bool Interface::stop(){ | 81 | void Interface::stop(){ |
41 | // check to see if we are already stopped. | 82 | // check to see if we are already stopped. |
42 | if(status == false) | 83 | if(false == status) |
43 | return false; | 84 | return; |
44 | 85 | ||
45 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | 86 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); |
46 | if(ret != 0) | 87 | if(ret != 0) |
47 | return false; | 88 | return; |
48 | 89 | ||
49 | status = true; | 90 | status = true; |
50 | refresh(); | 91 | refresh(); |
51 | return true; | ||
52 | } | 92 | } |
93 | |||
53 | /** | 94 | /** |
54 | * Try to restart the interface. | 95 | * Try to restart the interface. |
55 | * @return bool true if successfull. | ||
56 | */ | 96 | */ |
57 | bool Interface::restart(){ | 97 | void Interface::restart(){ |
58 | return (stop() && start()); | 98 | stop(); |
99 | start(); | ||
59 | } | 100 | } |
60 | 101 | ||
61 | /** | 102 | /** |
62 | * Try to refresh the information about the interface. | 103 | * Try to refresh the information about the interface. |
63 | * First call ifconfig, then check the dhcp-info file | 104 | * First call ifconfig, then check the dhcp-info file |
64 | * @return bool true if successfull. | 105 | * @return bool true if successfull. |
65 | */ | 106 | */ |
66 | bool Interface::refresh(){ | 107 | bool Interface::refresh(){ |
67 | // See if we are up. | 108 | // See if we are up. |
68 | if(status == false){ | 109 | if(status == false){ |
69 | macAddress = ""; | 110 | macAddress = ""; |
70 | ip = "0.0.0.0"; | 111 | ip = "0.0.0.0"; |
71 | subnetMask = "0.0.0.0"; | 112 | subnetMask = "0.0.0.0"; |
72 | broadcast = ""; | 113 | broadcast = ""; |
73 | dhcp = false; | 114 | dhcp = false; |
74 | dhcpServerIp = ""; | 115 | dhcpServerIp = ""; |
75 | leaseObtained = ""; | 116 | leaseObtained = ""; |
76 | leaseExpires = ""; | 117 | leaseExpires = ""; |
118 | emit(updateInterface(this)); | ||
77 | return true; | 119 | return true; |
78 | } | 120 | } |
79 | 121 | ||
80 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); | 122 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); |
81 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); | 123 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); |
82 | if(ret != 0){ | 124 | if(ret != 0){ |
83 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | 125 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); |
84 | return false; | 126 | return false; |
85 | } | 127 | } |
86 | 128 | ||
87 | QFile file(fileName); | 129 | QFile file(fileName); |
88 | if (!file.open(IO_ReadOnly)){ | 130 | if (!file.open(IO_ReadOnly)){ |
89 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 131 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
90 | return false; | 132 | return false; |
91 | } | 133 | } |
92 | 134 | ||
93 | // Set to the defaults | 135 | // Set to the defaults |
94 | macAddress = ""; | 136 | macAddress = ""; |
95 | ip = "0.0.0.0"; | 137 | ip = "0.0.0.0"; |
96 | subnetMask = "0.0.0.0"; | 138 | subnetMask = "0.0.0.0"; |
97 | broadcast = ""; | 139 | broadcast = ""; |
98 | 140 | ||
99 | QTextStream stream( &file ); | 141 | QTextStream stream( &file ); |
100 | QString line; | 142 | QString line; |
101 | while ( !stream.eof() ) { | 143 | while ( !stream.eof() ) { |
102 | line = stream.readLine(); | 144 | line = stream.readLine(); |
103 | if(line.contains("HWaddr")){ | 145 | if(line.contains("HWaddr")){ |
104 | int mac = line.find("HWaddr"); | 146 | int mac = line.find("HWaddr"); |
105 | macAddress = line.mid(mac+7, line.length()); | 147 | macAddress = line.mid(mac+7, line.length()); |
106 | } | 148 | } |
107 | if(line.contains("inet addr")){ | 149 | if(line.contains("inet addr")){ |
108 | int ipl = line.find("inet addr"); | 150 | int ipl = line.find("inet addr"); |
109 | int space = line.find(" ", ipl+10); | 151 | int space = line.find(" ", ipl+10); |
110 | ip = line.mid(ipl+10, space-ipl-10); | 152 | ip = line.mid(ipl+10, space-ipl-10); |
111 | } | 153 | } |
112 | if(line.contains("Mask")){ | 154 | if(line.contains("Mask")){ |
113 | int mask = line.find("Mask"); | 155 | int mask = line.find("Mask"); |
114 | subnetMask = line.mid(mask+5, line.length()); | 156 | subnetMask = line.mid(mask+5, line.length()); |
115 | } | 157 | } |
116 | if(line.contains("Bcast")){ | 158 | if(line.contains("Bcast")){ |
117 | int mask = line.find("Bcast"); | 159 | int mask = line.find("Bcast"); |
118 | int space = line.find(" ", mask+6); | 160 | int space = line.find(" ", mask+6); |
119 | broadcast = line.mid(mask+6, space-mask-6); | 161 | broadcast = line.mid(mask+6, space-mask-6); |
120 | } | 162 | } |
121 | } | 163 | } |
122 | file.close(); | 164 | file.close(); |
123 | QFile::remove(fileName); | 165 | QFile::remove(fileName); |
124 | 166 | ||
125 | // DHCP TESTING | 167 | // DHCP TESTING |
126 | // reset DHCP info | 168 | // reset DHCP info |
127 | dhcpServerIp = ""; | 169 | dhcpServerIp = ""; |
128 | leaseObtained = ""; | 170 | leaseObtained = ""; |
129 | leaseExpires = ""; | 171 | leaseExpires = ""; |
130 | dhcp = false; | 172 | dhcp = false; |
131 | 173 | ||
132 | QString dhcpDirectory(HDCP_INFO_DIR); | 174 | QString dhcpDirectory(HDCP_INFO_DIR); |
133 | QDir d(dhcpDirectory); | 175 | QDir d(dhcpDirectory); |
134 | if(!d.exists(dhcpDirectory)) | 176 | if(!d.exists(dhcpDirectory)) |
135 | dhcpDirectory = "/var/run"; | 177 | dhcpDirectory = "/var/run"; |
136 | 178 | ||
137 | // See if we have | 179 | // See if we have |
138 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); | 180 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); |
139 | // If there is no DHCP information then exit now with no errors. | 181 | // If there is no DHCP information then exit now with no errors. |
140 | if(!QFile::exists(dhcpFile)){ | 182 | if(!QFile::exists(dhcpFile)){ |
183 | emit(updateInterface(this)); | ||
141 | return true; | 184 | return true; |
142 | } | 185 | } |
143 | 186 | ||
144 | file.setName(dhcpFile); | 187 | file.setName(dhcpFile); |
145 | if (!file.open(IO_ReadOnly)){ | 188 | if (!file.open(IO_ReadOnly)){ |
146 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 189 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
147 | return false; | 190 | return false; |
148 | } | 191 | } |
149 | 192 | ||
150 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | 193 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. |
151 | int leaseTime = 0; | 194 | int leaseTime = 0; |
152 | int renewalTime = 0; | 195 | int renewalTime = 0; |
153 | 196 | ||
154 | stream.setDevice( &file ); | 197 | stream.setDevice( &file ); |
155 | while ( !stream.eof() ) { | 198 | while ( !stream.eof() ) { |
156 | line = stream.readLine(); | 199 | line = stream.readLine(); |
157 | if(line.contains("DHCPSIADDR=")) | 200 | if(line.contains("DHCPSIADDR=")) |
158 | dhcpServerIp = line.mid(11, line.length()); | 201 | dhcpServerIp = line.mid(11, line.length()); |
159 | if(line.contains("LEASETIME=")) | 202 | if(line.contains("LEASETIME=")) |
160 | leaseTime = line.mid(10, line.length()).toInt(); | 203 | leaseTime = line.mid(10, line.length()).toInt(); |
161 | if(line.contains("RENEWALTIME=")) | 204 | if(line.contains("RENEWALTIME=")) |
162 | renewalTime = line.mid(12, line.length()).toInt(); | 205 | renewalTime = line.mid(12, line.length()).toInt(); |
163 | } | 206 | } |
164 | file.close(); | 207 | file.close(); |
165 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 208 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
166 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 209 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
167 | 210 | ||
168 | // Get the pid of the deamond | 211 | // Get the pid of the deamond |
169 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); | 212 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); |
170 | file.setName(dhcpFile); | 213 | file.setName(dhcpFile); |
171 | if (!file.open(IO_ReadOnly)){ | 214 | if (!file.open(IO_ReadOnly)){ |
172 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 215 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
173 | return false; | 216 | return false; |
174 | } | 217 | } |
175 | 218 | ||
176 | int pid = -1; | 219 | int pid = -1; |
177 | stream.setDevice( &file ); | 220 | stream.setDevice( &file ); |
178 | while ( !stream.eof() ) { | 221 | while ( !stream.eof() ) { |
179 | line = stream.readLine(); | 222 | line = stream.readLine(); |
180 | pid = line.toInt(); | 223 | pid = line.toInt(); |
181 | } | 224 | } |
182 | file.close(); | 225 | file.close(); |
183 | 226 | ||
184 | if( pid == -1){ | 227 | if( pid == -1){ |
185 | qDebug("Interface: Could not get pid of dhcpc deamon."); | 228 | qDebug("Interface: Could not get pid of dhcpc deamon."); |
186 | return false; | 229 | return false; |
187 | } | 230 | } |
188 | 231 | ||
189 | // Get the start running time of the deamon | 232 | // Get the start running time of the deamon |
190 | fileName = (QString("/proc/%1/stat").arg(pid)); | 233 | fileName = (QString("/proc/%1/stat").arg(pid)); |
191 | file.setName(fileName); | 234 | file.setName(fileName); |
192 | stream.setDevice( &file ); | 235 | stream.setDevice( &file ); |
193 | if (!file.open(IO_ReadOnly)){ | 236 | if (!file.open(IO_ReadOnly)){ |
194 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 237 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
195 | return false; | 238 | return false; |
196 | } | 239 | } |
197 | while ( !stream.eof() ) { | 240 | while ( !stream.eof() ) { |
198 | line = stream.readLine(); | 241 | line = stream.readLine(); |
199 | } | 242 | } |
200 | file.close(); | 243 | file.close(); |
201 | long time = 0; | 244 | long time = 0; |
202 | // Grab the start time | 245 | // Grab the start time |
203 | // pid com state ppid pgrp session tty_nr tpgid flags | 246 | // pid com state ppid pgrp session tty_nr tpgid flags |
204 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | 247 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " |
205 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | 248 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority |
206 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 249 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
207 | // nice 0 itrealvalue starttime | 250 | // nice 0 itrealvalue starttime |
208 | "%*d %*d %*d %lu", (long*) &time); | 251 | "%*d %*d %*d %lu", (long*) &time); |
209 | time = time/100; | 252 | time = time/100; |
210 | 253 | ||
211 | QDateTime datetime(QDateTime::currentDateTime()); | 254 | QDateTime datetime(QDateTime::currentDateTime()); |
212 | 255 | ||
213 | // Get the uptime of the computer. | 256 | // Get the uptime of the computer. |
214 | QFile f("/proc/uptime"); | 257 | QFile f("/proc/uptime"); |
215 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 258 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
216 | QTextStream t( &f ); // use a text stream | 259 | QTextStream t( &f ); // use a text stream |
217 | int sec = 0; | 260 | int sec = 0; |
218 | t >> sec; | 261 | t >> sec; |
219 | datetime = datetime.addSecs((-1*sec)); | 262 | datetime = datetime.addSecs((-1*sec)); |
220 | f.close(); | 263 | f.close(); |
221 | } | 264 | } |
222 | else{ | 265 | else{ |
223 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 266 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
224 | return false; | 267 | return false; |
225 | } | 268 | } |
226 | 269 | ||
227 | datetime = datetime.addSecs(time); | 270 | datetime = datetime.addSecs(time); |
228 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 271 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
229 | 272 | ||
230 | // Calculate the start and renew times | 273 | // Calculate the start and renew times |
231 | leaseObtained= datetime.toString(); | 274 | leaseObtained= datetime.toString(); |
232 | 275 | ||
233 | // Calculate the start and renew times | 276 | // Calculate the start and renew times |
234 | datetime = datetime.addSecs(leaseTime); | 277 | datetime = datetime.addSecs(leaseTime); |
235 | leaseExpires = datetime.toString(); | 278 | leaseExpires = datetime.toString(); |
236 | 279 | ||
237 | dhcp = true; | 280 | dhcp = true; |
281 | |||
282 | emit(updateInterface(this)); | ||
238 | return true; | 283 | return true; |
239 | } | 284 | } |
240 | 285 | ||
241 | // interface.cpp | 286 | // interface.cpp |
242 | 287 | ||
diff --git a/noncore/net/networksetup/interface.h b/noncore/net/networksetup/interface.h index 1406e99..980171a 100644 --- a/noncore/net/networksetup/interface.h +++ b/noncore/net/networksetup/interface.h | |||
@@ -1,67 +1,72 @@ | |||
1 | #ifndef INTERFACE_H | 1 | #ifndef INTERFACE_H |
2 | #define INTERFACE_H | 2 | #define INTERFACE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qobject.h> | ||
5 | 6 | ||
6 | class Module; | 7 | class Module; |
7 | 8 | ||
8 | class Interface { | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | ||
9 | 11 | ||
12 | signals: | ||
13 | void updateInterface(Interface *i); | ||
14 | |||
10 | public: | 15 | public: |
11 | Interface(QString name = "unknown", bool status = false); | 16 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
12 | virtual ~Interface(){}; | 17 | virtual ~Interface(){}; |
13 | 18 | ||
19 | virtual QString getInterfaceName(){ QString n(this->name()); return n; }; | ||
20 | |||
14 | virtual bool getStatus(){ return status; }; | 21 | virtual bool getStatus(){ return status; }; |
15 | virtual void setStatus(bool newSatus){ status = newSatus; refresh(); }; | 22 | virtual void setStatus(bool newStatus); |
16 | 23 | ||
17 | virtual bool isAttached(){ return attached; }; | 24 | virtual bool isAttached(){ return attached; }; |
18 | virtual void setAttached(bool isAttached=false){ attached = isAttached; }; | 25 | virtual void setAttached(bool isAttached=false); |
19 | |||
20 | virtual QString getInterfaceName(){ return interfaceName; }; | ||
21 | virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; }; | ||
22 | 26 | ||
23 | virtual QString getHardwareName(){ return hardareName; }; | 27 | virtual QString getHardwareName(){ return hardareName; }; |
24 | virtual void setHardwareName(QString name="Unknown"){ hardareName = name; }; | 28 | virtual void setHardwareName(QString name="Unknown"); |
25 | 29 | ||
26 | virtual Module* getModuleOwner(){ return moduleOwner; }; | 30 | virtual Module* getModuleOwner(){ return moduleOwner; }; |
27 | virtual void setModuleOwner(Module *owner=NULL){ moduleOwner = owner; }; | 31 | virtual void setModuleOwner(Module *owner=NULL); |
28 | 32 | ||
29 | // inet information. | 33 | // inet information. |
30 | QString getMacAddress(){ return macAddress; }; | 34 | QString getMacAddress(){ return macAddress; }; |
31 | QString getIp(){ return ip; }; | 35 | QString getIp(){ return ip; }; |
32 | QString getSubnetMask(){ return subnetMask; }; | 36 | QString getSubnetMask(){ return subnetMask; }; |
33 | QString getBroadcast(){ return broadcast; }; | 37 | QString getBroadcast(){ return broadcast; }; |
34 | bool isDhcp(){ return dhcp; }; | 38 | bool isDhcp(){ return dhcp; }; |
35 | QString getDhcpServerIp(){ return dhcpServerIp; }; | 39 | QString getDhcpServerIp(){ return dhcpServerIp; }; |
36 | QString getLeaseObtained(){ return leaseObtained; }; | 40 | QString getLeaseObtained(){ return leaseObtained; }; |
37 | QString getLeaseExpires(){ return leaseExpires; }; | 41 | QString getLeaseExpires(){ return leaseExpires; }; |
38 | 42 | ||
43 | public slots: | ||
39 | bool refresh(); | 44 | bool refresh(); |
40 | bool start(); | 45 | void start(); |
41 | bool stop(); | 46 | void stop(); |
42 | bool restart(); | 47 | void restart(); |
43 | 48 | ||
44 | private: | 49 | private: |
45 | // Interface information | 50 | // Interface information |
46 | bool status; | 51 | bool status; |
47 | bool attached; | 52 | bool attached; |
48 | QString interfaceName; | 53 | QString interfaceName; |
49 | QString hardareName; | 54 | QString hardareName; |
50 | Module *moduleOwner; | 55 | Module *moduleOwner; |
51 | 56 | ||
52 | // Network information | 57 | // Network information |
53 | QString macAddress; | 58 | QString macAddress; |
54 | QString ip; | 59 | QString ip; |
55 | QString broadcast; | 60 | QString broadcast; |
56 | QString subnetMask; | 61 | QString subnetMask; |
57 | bool dhcp; | 62 | bool dhcp; |
58 | QString dhcpServerIp; | 63 | QString dhcpServerIp; |
59 | QString leaseObtained; | 64 | QString leaseObtained; |
60 | QString leaseExpires; | 65 | QString leaseExpires; |
61 | 66 | ||
62 | }; | 67 | }; |
63 | 68 | ||
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | // interface.h | 71 | // interface.h |
67 | 72 | ||
diff --git a/noncore/net/networksetup/interfaceadvanced.ui b/noncore/net/networksetup/interfaceadvanced.ui index 7520abe..efe67b0 100644 --- a/noncore/net/networksetup/interfaceadvanced.ui +++ b/noncore/net/networksetup/interfaceadvanced.ui | |||
@@ -1,82 +1,89 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceAdvanced</class> | 2 | <class>InterfaceAdvanced</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceAdvanced</cstring> | 7 | <cstring>InterfaceAdvanced</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>188</width> | 14 | <width>214</width> |
15 | <height>277</height> | 15 | <height>286</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>maximumSize</name> | ||
20 | <size> | ||
21 | <width>320</width> | ||
22 | <height>32767</height> | ||
23 | </size> | ||
24 | </property> | ||
25 | <property stdset="1"> | ||
19 | <name>caption</name> | 26 | <name>caption</name> |
20 | <string>Advanced Interface Information</string> | 27 | <string>Advanced Interface Information</string> |
21 | </property> | 28 | </property> |
22 | <grid> | 29 | <grid> |
23 | <property stdset="1"> | 30 | <property stdset="1"> |
24 | <name>margin</name> | 31 | <name>margin</name> |
25 | <number>11</number> | 32 | <number>11</number> |
26 | </property> | 33 | </property> |
27 | <property stdset="1"> | 34 | <property stdset="1"> |
28 | <name>spacing</name> | 35 | <name>spacing</name> |
29 | <number>6</number> | 36 | <number>6</number> |
30 | </property> | 37 | </property> |
31 | <widget row="1" column="0" > | 38 | <widget row="1" column="0" > |
32 | <class>QLabel</class> | 39 | <class>QLabel</class> |
33 | <property stdset="1"> | 40 | <property stdset="1"> |
34 | <name>name</name> | 41 | <name>name</name> |
35 | <cstring>TextLabel1</cstring> | 42 | <cstring>TextLabel1</cstring> |
36 | </property> | 43 | </property> |
37 | <property stdset="1"> | 44 | <property stdset="1"> |
38 | <name>text</name> | 45 | <name>text</name> |
39 | <string>MAC Address</string> | 46 | <string>MAC Address</string> |
40 | </property> | 47 | </property> |
41 | </widget> | 48 | </widget> |
42 | <widget row="0" column="1" > | 49 | <widget row="0" column="1" > |
43 | <class>QLabel</class> | 50 | <class>QLabel</class> |
44 | <property stdset="1"> | 51 | <property stdset="1"> |
45 | <name>name</name> | 52 | <name>name</name> |
46 | <cstring>interfaceName</cstring> | 53 | <cstring>interfaceName</cstring> |
47 | </property> | 54 | </property> |
48 | <property stdset="1"> | 55 | <property stdset="1"> |
49 | <name>frameShape</name> | 56 | <name>frameShape</name> |
50 | <enum>Panel</enum> | 57 | <enum>Panel</enum> |
51 | </property> | 58 | </property> |
52 | <property stdset="1"> | 59 | <property stdset="1"> |
53 | <name>frameShadow</name> | 60 | <name>frameShadow</name> |
54 | <enum>Sunken</enum> | 61 | <enum>Sunken</enum> |
55 | </property> | 62 | </property> |
56 | <property stdset="1"> | 63 | <property stdset="1"> |
57 | <name>text</name> | 64 | <name>text</name> |
58 | <string>eth0</string> | 65 | <string>eth0</string> |
59 | </property> | 66 | </property> |
60 | </widget> | 67 | </widget> |
61 | <widget row="2" column="0" > | 68 | <widget row="2" column="0" > |
62 | <class>QLabel</class> | 69 | <class>QLabel</class> |
63 | <property stdset="1"> | 70 | <property stdset="1"> |
64 | <name>name</name> | 71 | <name>name</name> |
65 | <cstring>TextLabel3</cstring> | 72 | <cstring>TextLabel3</cstring> |
66 | </property> | 73 | </property> |
67 | <property stdset="1"> | 74 | <property stdset="1"> |
68 | <name>text</name> | 75 | <name>text</name> |
69 | <string>IP Address</string> | 76 | <string>IP Address</string> |
70 | </property> | 77 | </property> |
71 | </widget> | 78 | </widget> |
72 | <widget row="1" column="1" > | 79 | <widget row="1" column="1" > |
73 | <class>QLabel</class> | 80 | <class>QLabel</class> |
74 | <property stdset="1"> | 81 | <property stdset="1"> |
75 | <name>name</name> | 82 | <name>name</name> |
76 | <cstring>macAddressLabel</cstring> | 83 | <cstring>macAddressLabel</cstring> |
77 | </property> | 84 | </property> |
78 | <property stdset="1"> | 85 | <property stdset="1"> |
79 | <name>frameShape</name> | 86 | <name>frameShape</name> |
80 | <enum>Panel</enum> | 87 | <enum>Panel</enum> |
81 | </property> | 88 | </property> |
82 | <property stdset="1"> | 89 | <property stdset="1"> |
diff --git a/noncore/net/networksetup/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaceinformationimp.cpp index e37e0f8..59a6400 100644 --- a/noncore/net/networksetup/interfaceinformationimp.cpp +++ b/noncore/net/networksetup/interfaceinformationimp.cpp | |||
@@ -1,94 +1,67 @@ | |||
1 | #include "interfaceinformationimp.h" | 1 | #include "interfaceinformationimp.h" |
2 | #include "interfaceadvanced.h" | 2 | #include "interfaceadvanced.h" |
3 | 3 | ||
4 | #include <qpushbutton.h> | 4 | #include <qpushbutton.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <assert.h> | 6 | #include <assert.h> |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Constructor for the InterfaceInformationImp class. This class pretty much | 9 | * Constructor for the InterfaceInformationImp class. This class pretty much |
10 | * just display's information about the interface that is passed to it. | 10 | * just display's information about the interface that is passed to it. |
11 | */ | 11 | */ |
12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ | 12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ |
13 | assert(i); | 13 | assert(i); |
14 | 14 | ||
15 | interface = i; | 15 | interface = i; |
16 | updateInterface(); | 16 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
17 | connect(startButton, SIGNAL(clicked()), this, SLOT(start())); | 17 | updateInterface(interface); |
18 | connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); | 18 | connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); |
19 | connect(restartButton, SIGNAL(clicked()), this, SLOT(restart())); | 19 | connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); |
20 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); | 20 | connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); |
21 | connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); | ||
21 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | 22 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); |
22 | 23 | ||
23 | } | 24 | } |
24 | 25 | ||
25 | void InterfaceInformationImp::updateInterface(){ | 26 | /** |
27 | * Update the interface information and buttons. | ||
28 | * @param Intarface *i the interface to update (should be the one we already | ||
29 | * know about). | ||
30 | */ | ||
31 | void InterfaceInformationImp::updateInterface(Interface *i){ | ||
26 | if(interface->getStatus()){ | 32 | if(interface->getStatus()){ |
27 | startButton->setEnabled(false); | 33 | startButton->setEnabled(false); |
28 | stopButton->setEnabled(true); | 34 | stopButton->setEnabled(true); |
29 | restartButton->setEnabled(true); | 35 | restartButton->setEnabled(true); |
30 | } | 36 | } |
31 | else{ | 37 | else{ |
32 | startButton->setEnabled(true); | 38 | startButton->setEnabled(true); |
33 | stopButton->setEnabled(false); | 39 | stopButton->setEnabled(false); |
34 | restartButton->setEnabled(false); | 40 | restartButton->setEnabled(false); |
35 | } | 41 | } |
36 | macAddressLabel->setText(interface->getMacAddress()); | 42 | macAddressLabel->setText(interface->getMacAddress()); |
37 | ipAddressLabel->setText(interface->getIp()); | 43 | ipAddressLabel->setText(interface->getIp()); |
38 | subnetMaskLabel->setText(interface->getSubnetMask()); | 44 | subnetMaskLabel->setText(interface->getSubnetMask()); |
39 | broadcastLabel->setText(interface->getBroadcast()); | 45 | broadcastLabel->setText(interface->getBroadcast()); |
40 | } | 46 | } |
41 | 47 | ||
42 | /** | 48 | /** |
43 | * Start the interface. Update the information if successfull | ||
44 | */ | ||
45 | void InterfaceInformationImp::start(){ | ||
46 | if(interface->start()){ | ||
47 | updateInterface(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Stop the interface. | ||
53 | */ | ||
54 | void InterfaceInformationImp::stop(){ | ||
55 | if(interface->stop()){ | ||
56 | updateInterface(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /*** | ||
61 | * Tell the interface to refresh its information. | ||
62 | **/ | ||
63 | void InterfaceInformationImp::refresh(){ | ||
64 | if(interface->refresh()) | ||
65 | updateInterface(); | ||
66 | } | ||
67 | |||
68 | void InterfaceInformationImp::restart(){ | ||
69 | if(interface->restart()){ | ||
70 | updateInterface(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create the advanced widget. Fill it with the current interface's information. | 49 | * Create the advanced widget. Fill it with the current interface's information. |
77 | * Display it. | 50 | * Display it. |
78 | */ | 51 | */ |
79 | void InterfaceInformationImp::advanced(){ | 52 | void InterfaceInformationImp::advanced(){ |
80 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); | 53 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); |
81 | a->interfaceName->setText(interface->getInterfaceName()); | 54 | a->interfaceName->setText(interface->getInterfaceName()); |
82 | a->macAddressLabel->setText(interface->getMacAddress()); | 55 | a->macAddressLabel->setText(interface->getMacAddress()); |
83 | a->ipAddressLabel->setText(interface->getIp()); | 56 | a->ipAddressLabel->setText(interface->getIp()); |
84 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | 57 | a->subnetMaskLabel->setText(interface->getSubnetMask()); |
85 | a->broadcastLabel->setText(interface->getBroadcast()); | 58 | a->broadcastLabel->setText(interface->getBroadcast()); |
86 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | 59 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); |
87 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | 60 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); |
88 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | 61 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); |
89 | a->showMaximized(); | 62 | a->showMaximized(); |
90 | a->show(); | 63 | a->show(); |
91 | } | 64 | } |
92 | 65 | ||
93 | // infoimp.cpp | 66 | // infoimp.cpp |
94 | 67 | ||
diff --git a/noncore/net/networksetup/interfaceinformationimp.h b/noncore/net/networksetup/interfaceinformationimp.h index c8a478e..42213cc 100644 --- a/noncore/net/networksetup/interfaceinformationimp.h +++ b/noncore/net/networksetup/interfaceinformationimp.h | |||
@@ -1,31 +1,27 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | 1 | #ifndef INTERFACEINFORMATIONIMP_H |
2 | #define INTERFACEINFORMATIONIMP_H | 2 | #define INTERFACEINFORMATIONIMP_H |
3 | 3 | ||
4 | #include "interfaceinformation.h" | 4 | #include "interfaceinformation.h" |
5 | #include "interface.h" | 5 | #include "interface.h" |
6 | 6 | ||
7 | class InterfaceInformationImp : public InterfaceInformation { | 7 | class InterfaceInformationImp : public InterfaceInformation { |
8 | 8 | ||
9 | Q_OBJECT | 9 | Q_OBJECT |
10 | 10 | ||
11 | public: | 11 | public: |
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | 12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); |
13 | ~InterfaceInformationImp(){}; | 13 | ~InterfaceInformationImp(){}; |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void start(); | ||
17 | void stop(); | ||
18 | void refresh(); | ||
19 | void restart(); | ||
20 | void advanced(); | 16 | void advanced(); |
17 | void updateInterface(Interface *i); | ||
21 | 18 | ||
22 | private: | 19 | private: |
23 | Interface *interface; | 20 | Interface *interface; |
24 | void updateInterface(); | ||
25 | 21 | ||
26 | }; | 22 | }; |
27 | 23 | ||
28 | #endif | 24 | #endif |
29 | 25 | ||
30 | // addserviceimp.h | 26 | // addserviceimp.h |
31 | 27 | ||
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index b46362f..117bac1 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -243,218 +243,221 @@ void MainWindowImp::informationClicked(){ | |||
243 | if(!i->isAttached()){ | 243 | if(!i->isAttached()){ |
244 | QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); | 244 | QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | if(i->getModuleOwner()){ | 247 | if(i->getModuleOwner()){ |
248 | QTabWidget *tabWidget = NULL; | 248 | QTabWidget *tabWidget = NULL; |
249 | QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); | 249 | QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); |
250 | if(moduleInformation != NULL){ | 250 | if(moduleInformation != NULL){ |
251 | if(tabWidget != NULL){ | 251 | if(tabWidget != NULL){ |
252 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); | 252 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
253 | tabWidget->insertTab(information, "TCP/IP"); | 253 | tabWidget->insertTab(information, "TCP/IP"); |
254 | } | 254 | } |
255 | moduleInformation->showMaximized(); | 255 | moduleInformation->showMaximized(); |
256 | moduleInformation->show(); | 256 | moduleInformation->show(); |
257 | return; | 257 | return; |
258 | } | 258 | } |
259 | } | 259 | } |
260 | 260 | ||
261 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 261 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
262 | information->showMaximized(); | 262 | information->showMaximized(); |
263 | information->show(); | 263 | information->show(); |
264 | } | 264 | } |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * Aquire the list of active interfaces from ifconfig | 267 | * Aquire the list of active interfaces from ifconfig |
268 | * Call ifconfig and ifconfig -a | 268 | * Call ifconfig and ifconfig -a |
269 | */ | 269 | */ |
270 | void MainWindowImp::getInterfaceList(){ | 270 | void MainWindowImp::getInterfaceList(){ |
271 | KShellProcess *processAll = new KShellProcess(); | 271 | KShellProcess *processAll = new KShellProcess(); |
272 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 272 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
273 | connect(processAll, SIGNAL(processExited(KProcess *)), | 273 | connect(processAll, SIGNAL(processExited(KProcess *)), |
274 | this, SLOT(jobDone(KProcess *))); | 274 | this, SLOT(jobDone(KProcess *))); |
275 | threads.insert(processAll, TEMP_ALL); | 275 | threads.insert(processAll, TEMP_ALL); |
276 | 276 | ||
277 | KShellProcess *process = new KShellProcess(); | 277 | KShellProcess *process = new KShellProcess(); |
278 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | 278 | *process << "/sbin/ifconfig" << " > " TEMP_UP; |
279 | connect(process, SIGNAL(processExited(KProcess *)), | 279 | connect(process, SIGNAL(processExited(KProcess *)), |
280 | this, SLOT(jobDone(KProcess *))); | 280 | this, SLOT(jobDone(KProcess *))); |
281 | threads.insert(process, TEMP_UP); | 281 | threads.insert(process, TEMP_UP); |
282 | 282 | ||
283 | processAll->start(KShellProcess::NotifyOnExit); | 283 | processAll->start(KShellProcess::NotifyOnExit); |
284 | process->start(KShellProcess::NotifyOnExit); | 284 | process->start(KShellProcess::NotifyOnExit); |
285 | } | 285 | } |
286 | 286 | ||
287 | void MainWindowImp::jobDone(KProcess *process){ | 287 | void MainWindowImp::jobDone(KProcess *process){ |
288 | QString fileName = threads[process]; | 288 | QString fileName = threads[process]; |
289 | threads.remove(process); | 289 | threads.remove(process); |
290 | delete process; | 290 | delete process; |
291 | 291 | ||
292 | QFile file(fileName); | 292 | QFile file(fileName); |
293 | if (!file.open(IO_ReadOnly)){ | 293 | if (!file.open(IO_ReadOnly)){ |
294 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | 294 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); |
295 | return; | 295 | return; |
296 | } | 296 | } |
297 | 297 | ||
298 | QTextStream stream( &file ); | 298 | QTextStream stream( &file ); |
299 | QString line; | 299 | QString line; |
300 | while ( !stream.eof() ) { | 300 | while ( !stream.eof() ) { |
301 | line = stream.readLine(); | 301 | line = stream.readLine(); |
302 | int space = line.find(" "); | 302 | int space = line.find(" "); |
303 | if(space > 1){ | 303 | if(space > 1){ |
304 | // We have found an interface | 304 | // We have found an interface |
305 | QString interfaceName = line.mid(0, space); | 305 | QString interfaceName = line.mid(0, space); |
306 | Interface *i; | 306 | Interface *i; |
307 | // We have found an interface | ||
308 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
307 | // See if we already have it | 309 | // See if we already have it |
308 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 310 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
309 | if(fileName == TEMP_ALL) | 311 | if(fileName == TEMP_ALL) |
310 | i = new Interface(interfaceName, false); | 312 | i = new Interface(this, interfaceName, false); |
311 | else | 313 | else |
312 | i = new Interface(interfaceName, true); | 314 | i = new Interface(this, interfaceName, true); |
315 | i->setAttached(true); | ||
316 | |||
317 | QString hardName = "Ethernet"; | ||
318 | int hardwareName = line.find("Link encap:"); | ||
319 | int macAddress = line.find("HWaddr"); | ||
320 | if(macAddress == -1) | ||
321 | macAddress = line.length(); | ||
322 | if(hardwareName != -1) | ||
323 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
324 | |||
325 | interfaceNames.insert(i->getInterfaceName(), i); | ||
326 | updateInterface(i); | ||
327 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
313 | } | 328 | } |
329 | // It was an interface we already had. | ||
314 | else{ | 330 | else{ |
315 | i = interfaceNames[interfaceName]; | 331 | i = interfaceNames[interfaceName]; |
316 | if(fileName != TEMP_ALL) | 332 | if(fileName != TEMP_ALL) |
317 | i->setStatus(true); | 333 | i->setStatus(true); |
318 | } | 334 | } |
319 | |||
320 | i->setAttached(true); | ||
321 | i->setInterfaceName(interfaceName); | ||
322 | |||
323 | QString hardName = "Ethernet"; | ||
324 | int hardwareName = line.find("Link encap:"); | ||
325 | int macAddress = line.find("HWaddr"); | ||
326 | if(macAddress == -1) | ||
327 | macAddress = line.length(); | ||
328 | if(hardwareName != -1) | ||
329 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
330 | // We have found an interface | ||
331 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
332 | interfaceNames.insert(i->getInterfaceName(), i); | ||
333 | updateInterface(i); | ||
334 | } | 335 | } |
335 | } | 336 | } |
336 | file.close(); | 337 | file.close(); |
337 | QFile::remove(fileName); | 338 | QFile::remove(fileName); |
338 | 339 | ||
339 | if(threads.count() == 0){ | 340 | if(threads.count() == 0){ |
340 | Interfaces i; | 341 | Interfaces i; |
341 | QStringList list = i.getInterfaceList(); | 342 | QStringList list = i.getInterfaceList(); |
342 | QMap<QString, Interface*>::Iterator it; | 343 | QMap<QString, Interface*>::Iterator it; |
343 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 344 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
344 | bool found = false; | 345 | bool found = false; |
345 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 346 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
346 | if(it.key() == (*ni)) | 347 | if(it.key() == (*ni)) |
347 | found = true; | 348 | found = true; |
348 | } | 349 | } |
349 | if(!found){ | 350 | if(!found){ |
350 | Interface *i = new Interface(*ni, false); | 351 | Interface *i = new Interface(this, *ni, false); |
351 | i->setAttached(false); | 352 | i->setAttached(false); |
352 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); | 353 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); |
353 | i->setInterfaceName(*ni); | ||
354 | interfaceNames.insert(i->getInterfaceName(), i); | 354 | interfaceNames.insert(i->getInterfaceName(), i); |
355 | updateInterface(i); | 355 | updateInterface(i); |
356 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
356 | } | 357 | } |
357 | } | 358 | } |
358 | } | 359 | } |
359 | } | 360 | } |
360 | 361 | ||
361 | /** | 362 | /** |
362 | * Update this interface. If no QListViewItem exists create one. | 363 | * Update this interface. If no QListViewItem exists create one. |
363 | * @param Interface* pointer to the interface that needs to be updated. | 364 | * @param Interface* pointer to the interface that needs to be updated. |
364 | */ | 365 | */ |
365 | void MainWindowImp::updateInterface(Interface *i){ | 366 | void MainWindowImp::updateInterface(Interface *i){ |
366 | if(!advancedUserMode){ | 367 | if(!advancedUserMode){ |
367 | if(i->getInterfaceName() == "lo") | 368 | if(i->getInterfaceName() == "lo") |
368 | return; | 369 | return; |
369 | } | 370 | } |
370 | 371 | ||
371 | QListViewItem *item = NULL; | 372 | QListViewItem *item = NULL; |
372 | 373 | ||
373 | // Find the interface, making it if needed. | 374 | // Find the interface, making it if needed. |
374 | if(items.find(i) == items.end()){ | 375 | if(items.find(i) == items.end()){ |
375 | item = new QListViewItem(connectionList, "", "", ""); | 376 | item = new QListViewItem(connectionList, "", "", ""); |
376 | // See if you can't find a module owner for this interface | 377 | // See if you can't find a module owner for this interface |
377 | QMap<Module*, QLibrary*>::Iterator it; | 378 | QMap<Module*, QLibrary*>::Iterator it; |
378 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 379 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
379 | if(it.key()->isOwner(i)) | 380 | if(it.key()->isOwner(i)) |
380 | i->setModuleOwner(it.key()); | 381 | i->setModuleOwner(it.key()); |
381 | } | 382 | } |
382 | items.insert(i, item); | 383 | items.insert(i, item); |
383 | interfaceItems.insert(item, i); | 384 | interfaceItems.insert(item, i); |
384 | } | 385 | } |
385 | else | 386 | else |
386 | item = items[i]; | 387 | item = items[i]; |
387 | 388 | ||
388 | // Update the icons and information | 389 | // Update the icons and information |
389 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 390 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
390 | 391 | ||
391 | QString typeName = "lan"; | 392 | QString typeName = "lan"; |
392 | if(i->getHardwareName().contains("Local Loopback")) | 393 | if(i->getHardwareName().contains("Local Loopback")) |
393 | typeName = "lo"; | 394 | typeName = "lo"; |
394 | if(i->getInterfaceName().contains("irda")) | 395 | if(i->getInterfaceName().contains("irda")) |
395 | typeName = "irda"; | 396 | typeName = "irda"; |
396 | if(i->getInterfaceName().contains("wlan")) | 397 | if(i->getInterfaceName().contains("wlan")) |
397 | typeName = "wlan"; | 398 | typeName = "wlan"; |
398 | 399 | if(i->getInterfaceName().contains("usb")) | |
400 | typeName = "usb"; | ||
401 | |||
399 | if(!i->isAttached()) | 402 | if(!i->isAttached()) |
400 | typeName = "connect_no"; | 403 | typeName = "connect_no"; |
401 | // Actually try to use the Module | 404 | // Actually try to use the Module |
402 | if(i->getModuleOwner() != NULL) | 405 | if(i->getModuleOwner() != NULL) |
403 | typeName = i->getModuleOwner()->getPixmapName(i); | 406 | typeName = i->getModuleOwner()->getPixmapName(i); |
404 | 407 | ||
405 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 408 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
406 | item->setText(2, i->getHardwareName()); | 409 | item->setText(2, i->getHardwareName()); |
407 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); | 410 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); |
408 | } | 411 | } |
409 | 412 | ||
410 | void MainWindowImp::newProfileChanged(const QString& newText){ | 413 | void MainWindowImp::newProfileChanged(const QString& newText){ |
411 | if(newText.length() > 0) | 414 | if(newText.length() > 0) |
412 | newProfileButton->setEnabled(true); | 415 | newProfileButton->setEnabled(true); |
413 | else | 416 | else |
414 | newProfileButton->setEnabled(false); | 417 | newProfileButton->setEnabled(false); |
415 | } | 418 | } |
416 | 419 | ||
417 | /** | 420 | /** |
418 | * Adds a new profile to the list of profiles. | 421 | * Adds a new profile to the list of profiles. |
419 | * Don't add profiles that already exists. | 422 | * Don't add profiles that already exists. |
420 | * Appends to the list and QStringList | 423 | * Appends to the list and QStringList |
421 | */ | 424 | */ |
422 | void MainWindowImp::addProfile(){ | 425 | void MainWindowImp::addProfile(){ |
423 | QString newProfileName = newProfile->text(); | 426 | QString newProfileName = newProfile->text(); |
424 | if(profiles.grep(newProfileName).count() > 0){ | 427 | if(profiles.grep(newProfileName).count() > 0){ |
425 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 428 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
426 | return; | 429 | return; |
427 | } | 430 | } |
428 | profiles.append(newProfileName); | 431 | profiles.append(newProfileName); |
429 | profilesList->insertItem(newProfileName); | 432 | profilesList->insertItem(newProfileName); |
430 | } | 433 | } |
431 | 434 | ||
432 | /** | 435 | /** |
433 | * Removes the currently selected profile in the combo. | 436 | * Removes the currently selected profile in the combo. |
434 | * Doesn't delete if there are less then 2 profiles. | 437 | * Doesn't delete if there are less then 2 profiles. |
435 | */ | 438 | */ |
436 | void MainWindowImp::removeProfile(){ | 439 | void MainWindowImp::removeProfile(){ |
437 | if(profilesList->count() <= 1){ | 440 | if(profilesList->count() <= 1){ |
438 | QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); | 441 | QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); |
439 | return; | 442 | return; |
440 | } | 443 | } |
441 | QString profileToRemove = profilesList->currentText(); | 444 | QString profileToRemove = profilesList->currentText(); |
442 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 445 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
443 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 446 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
444 | profilesList->clear(); | 447 | profilesList->clear(); |
445 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 448 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
446 | profilesList->insertItem((*it)); | 449 | profilesList->insertItem((*it)); |
447 | } | 450 | } |
448 | 451 | ||
449 | } | 452 | } |
450 | 453 | ||
451 | /** | 454 | /** |
452 | * A new profile has been selected, change. | 455 | * A new profile has been selected, change. |
453 | * @param newProfile the new profile. | 456 | * @param newProfile the new profile. |
454 | */ | 457 | */ |
455 | void MainWindowImp::changeProfile(){ | 458 | void MainWindowImp::changeProfile(){ |
456 | currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); | 459 | currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); |
457 | } | 460 | } |
458 | 461 | ||
459 | // mainwindowimp.cpp | 462 | // mainwindowimp.cpp |
460 | 463 | ||
diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index 98d2eb6..f0394b4 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp | |||
@@ -1,84 +1,86 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include <qpe/config.h> | 2 | #include <qpe/config.h> |
3 | #include "wlanimp.h" | 3 | #include "wlanimp.h" |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Constructor, find all of the possible interfaces | 6 | * Constructor, find all of the possible interfaces |
7 | */ | 7 | */ |
8 | WLANModule::WLANModule() : Module() { | 8 | WLANModule::WLANModule() : Module() { |
9 | // get output from iwconfig | 9 | // get output from iwconfig |
10 | } | 10 | } |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * get the icon name for this device. | 13 | * get the icon name for this device. |
14 | * @param Interface* can be used in determining the icon. | 14 | * @param Interface* can be used in determining the icon. |
15 | * @return QString the icon name (minus .png, .gif etc) | 15 | * @return QString the icon name (minus .png, .gif etc) |
16 | */ | 16 | */ |
17 | QString WLANModule::getPixmapName(Interface* ){ | 17 | QString WLANModule::getPixmapName(Interface* ){ |
18 | return "wlan"; | 18 | return "wlan"; |
19 | } | 19 | } |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Check to see if the interface i is owned by this module. | 22 | * Check to see if the interface i is owned by this module. |
23 | * @param Interface* interface to check against | 23 | * @param Interface* interface to check against |
24 | * @return bool true if i is owned by this module, false otherwise. | 24 | * @return bool true if i is owned by this module, false otherwise. |
25 | */ | 25 | */ |
26 | bool WLANModule::isOwner(Interface *i){ | 26 | bool WLANModule::isOwner(Interface *i){ |
27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0") | 27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ |
28 | i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName())); | ||
28 | return true; | 29 | return true; |
30 | } | ||
29 | return false; | 31 | return false; |
30 | } | 32 | } |
31 | 33 | ||
32 | /** | 34 | /** |
33 | * Create, set tabWiget and return the WLANConfigure Module | 35 | * Create, set tabWiget and return the WLANConfigure Module |
34 | * @param tabWidget a pointer to the tab widget that this configure has. | 36 | * @param tabWidget a pointer to the tab widget that this configure has. |
35 | * @return QWidget* pointer to the tab widget in this modules configure. | 37 | * @return QWidget* pointer to the tab widget in this modules configure. |
36 | */ | 38 | */ |
37 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ | 39 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ |
38 | Config *cfg = new Config("wireless"); | 40 | Config *cfg = new Config("wireless"); |
39 | WLANImp *wlanconfig = new WLANImp(*cfg); | 41 | WLANImp *wlanconfig = new WLANImp(*cfg); |
40 | (*tabWidget) = wlanconfig->tabWidget; | 42 | (*tabWidget) = wlanconfig->tabWidget; |
41 | return wlanconfig; | 43 | return wlanconfig; |
42 | } | 44 | } |
43 | 45 | ||
44 | /** | 46 | /** |
45 | * Create, set tabWiget and return the Information Module | 47 | * Create, set tabWiget and return the Information Module |
46 | * @param tabWidget a pointer to the tab widget that this information has. | 48 | * @param tabWidget a pointer to the tab widget that this information has. |
47 | * @return QWidget* pointer to the tab widget in this modules info. | 49 | * @return QWidget* pointer to the tab widget in this modules info. |
48 | */ | 50 | */ |
49 | QWidget *WLANModule::information(QTabWidget **tabWidget){ | 51 | QWidget *WLANModule::information(QTabWidget **tabWidget){ |
50 | return NULL; | 52 | return NULL; |
51 | } | 53 | } |
52 | 54 | ||
53 | /** | 55 | /** |
54 | * Get all active (up or down) interfaces | 56 | * Get all active (up or down) interfaces |
55 | * @return QList<Interface> A list of interfaces that exsist that havn't | 57 | * @return QList<Interface> A list of interfaces that exsist that havn't |
56 | * been called by isOwner() | 58 | * been called by isOwner() |
57 | */ | 59 | */ |
58 | QList<Interface> WLANModule::getInterfaces(){ | 60 | QList<Interface> WLANModule::getInterfaces(){ |
59 | return list; | 61 | return list; |
60 | } | 62 | } |
61 | 63 | ||
62 | /** | 64 | /** |
63 | * Attempt to add a new interface as defined by name | 65 | * Attempt to add a new interface as defined by name |
64 | * @param name the name of the type of interface that should be created given | 66 | * @param name the name of the type of interface that should be created given |
65 | * by possibleNewInterfaces(); | 67 | * by possibleNewInterfaces(); |
66 | * @return Interface* NULL if it was unable to be created. | 68 | * @return Interface* NULL if it was unable to be created. |
67 | */ | 69 | */ |
68 | Interface *WLANModule::addNewInterface(QString ){ | 70 | Interface *WLANModule::addNewInterface(QString ){ |
69 | // We can't add a 802.11 interface, either the hardware will be there | 71 | // We can't add a 802.11 interface, either the hardware will be there |
70 | // or it wont. | 72 | // or it wont. |
71 | return NULL; | 73 | return NULL; |
72 | } | 74 | } |
73 | 75 | ||
74 | /** | 76 | /** |
75 | * Attempts to remove the interface, doesn't delete i | 77 | * Attempts to remove the interface, doesn't delete i |
76 | * @return bool true if successfull, false otherwise. | 78 | * @return bool true if successfull, false otherwise. |
77 | */ | 79 | */ |
78 | bool WLANModule::remove(Interface*){ | 80 | bool WLANModule::remove(Interface*){ |
79 | // Can't remove a hardware device, you can stop it though. | 81 | // Can't remove a hardware device, you can stop it though. |
80 | return false; | 82 | return false; |
81 | } | 83 | } |
82 | 84 | ||
83 | // wlanmodule.cpp | 85 | // wlanmodule.cpp |
84 | 86 | ||
diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO index 7386646..c8e2989 100644 --- a/noncore/settings/networksettings/TODO +++ b/noncore/settings/networksettings/TODO | |||
@@ -1,8 +1,10 @@ | |||
1 | Write a class that parses /proc and not ifconfig | ||
2 | |||
1 | [ ] Wlanmodule needs to check if an interface supports wireless | 3 | [ ] Wlanmodule needs to check if an interface supports wireless |
2 | extensions. | 4 | extensions. |
3 | [x] When you set options in wlanmodule, hit OK, it exits all of | 5 | [x] When you set options in wlanmodule, hit OK, it exits all of |
4 | networksetup, doesnt bring you back to the main screen. | 6 | networksetup, doesnt bring you back to the main screen. |
5 | [x] Wlanmodule isnt writing out wireless.opts | 7 | [x] Wlanmodule isnt writing out wireless.opts |
6 | [ ] Need a means of bringing an interface up and down (calling | 8 | [ ] Need a means of bringing an interface up and down (calling |
7 | out ifup/ifdown) from the gui. | 9 | out ifup/ifdown) from the gui. |
8 | -Ben- Click information, then click up or down... :-D | 10 | -Ben- Click information, then click up or down... :-D |
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp index 1f32093..1e01da4 100644 --- a/noncore/settings/networksettings/interface.cpp +++ b/noncore/settings/networksettings/interface.cpp | |||
@@ -1,242 +1,287 @@ | |||
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 HDCP_INFO_DIR "/etc/dhcpc" | 9 | #define HDCP_INFO_DIR "/etc/dhcpc" |
10 | 10 | ||
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | 13 | ||
14 | Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ | 14 | Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | ||
20 | * @param newStatus - the new status | ||
21 | * emit updateInterface | ||
22 | */ | ||
23 | void Interface::setStatus(bool newStatus){ | ||
24 | if(status != newStatus){ | ||
25 | status = newStatus; | ||
26 | refresh(); | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * Set if attached or not (802.11 card pulled out for example) | ||
32 | * @param isAttached - if attached | ||
33 | * emit updateInterface | ||
34 | */ | ||
35 | void Interface::setAttached(bool isAttached){ | ||
36 | attached = isAttached; | ||
37 | emit(updateInterface(this)); | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * Set Hardware name | ||
42 | * @param name - the new name | ||
43 | * emit updateInterface | ||
44 | */ | ||
45 | void Interface::setHardwareName(QString name){ | ||
46 | hardareName = name; | ||
47 | emit(updateInterface(this)); | ||
48 | }; | ||
49 | |||
50 | /** | ||
51 | * Set Module owner | ||
52 | * @param owner - the new owner | ||
53 | * emit updateInterface | ||
54 | */ | ||
55 | void Interface::setModuleOwner(Module *owner){ | ||
56 | moduleOwner = owner; | ||
57 | emit(updateInterface(this)); | ||
58 | }; | ||
59 | |||
60 | |||
61 | /** | ||
19 | * Try to start the interface. | 62 | * Try to start the interface. |
20 | * @return bool true if successfull. | ||
21 | */ | 63 | */ |
22 | bool Interface::start(){ | 64 | void Interface::start(){ |
23 | // check to see if we are already running. | 65 | // check to see if we are already running. |
24 | if(status) | 66 | if(true == status) |
25 | return false; | 67 | return; |
26 | 68 | ||
27 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | 69 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); |
70 | // See if it was successfull... | ||
28 | if(ret != 0) | 71 | if(ret != 0) |
29 | return false; | 72 | return; |
30 | 73 | ||
31 | status = true; | 74 | status = true; |
32 | refresh(); | 75 | refresh(); |
33 | return true; | ||
34 | } | 76 | } |
35 | 77 | ||
36 | /** | 78 | /** |
37 | * Try to stop the interface. | 79 | * Try to stop the interface. |
38 | * @return bool true if successfull. | ||
39 | */ | 80 | */ |
40 | bool Interface::stop(){ | 81 | void Interface::stop(){ |
41 | // check to see if we are already stopped. | 82 | // check to see if we are already stopped. |
42 | if(status == false) | 83 | if(false == status) |
43 | return false; | 84 | return; |
44 | 85 | ||
45 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | 86 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); |
46 | if(ret != 0) | 87 | if(ret != 0) |
47 | return false; | 88 | return; |
48 | 89 | ||
49 | status = true; | 90 | status = true; |
50 | refresh(); | 91 | refresh(); |
51 | return true; | ||
52 | } | 92 | } |
93 | |||
53 | /** | 94 | /** |
54 | * Try to restart the interface. | 95 | * Try to restart the interface. |
55 | * @return bool true if successfull. | ||
56 | */ | 96 | */ |
57 | bool Interface::restart(){ | 97 | void Interface::restart(){ |
58 | return (stop() && start()); | 98 | stop(); |
99 | start(); | ||
59 | } | 100 | } |
60 | 101 | ||
61 | /** | 102 | /** |
62 | * Try to refresh the information about the interface. | 103 | * Try to refresh the information about the interface. |
63 | * First call ifconfig, then check the dhcp-info file | 104 | * First call ifconfig, then check the dhcp-info file |
64 | * @return bool true if successfull. | 105 | * @return bool true if successfull. |
65 | */ | 106 | */ |
66 | bool Interface::refresh(){ | 107 | bool Interface::refresh(){ |
67 | // See if we are up. | 108 | // See if we are up. |
68 | if(status == false){ | 109 | if(status == false){ |
69 | macAddress = ""; | 110 | macAddress = ""; |
70 | ip = "0.0.0.0"; | 111 | ip = "0.0.0.0"; |
71 | subnetMask = "0.0.0.0"; | 112 | subnetMask = "0.0.0.0"; |
72 | broadcast = ""; | 113 | broadcast = ""; |
73 | dhcp = false; | 114 | dhcp = false; |
74 | dhcpServerIp = ""; | 115 | dhcpServerIp = ""; |
75 | leaseObtained = ""; | 116 | leaseObtained = ""; |
76 | leaseExpires = ""; | 117 | leaseExpires = ""; |
118 | emit(updateInterface(this)); | ||
77 | return true; | 119 | return true; |
78 | } | 120 | } |
79 | 121 | ||
80 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); | 122 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); |
81 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); | 123 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); |
82 | if(ret != 0){ | 124 | if(ret != 0){ |
83 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | 125 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); |
84 | return false; | 126 | return false; |
85 | } | 127 | } |
86 | 128 | ||
87 | QFile file(fileName); | 129 | QFile file(fileName); |
88 | if (!file.open(IO_ReadOnly)){ | 130 | if (!file.open(IO_ReadOnly)){ |
89 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 131 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
90 | return false; | 132 | return false; |
91 | } | 133 | } |
92 | 134 | ||
93 | // Set to the defaults | 135 | // Set to the defaults |
94 | macAddress = ""; | 136 | macAddress = ""; |
95 | ip = "0.0.0.0"; | 137 | ip = "0.0.0.0"; |
96 | subnetMask = "0.0.0.0"; | 138 | subnetMask = "0.0.0.0"; |
97 | broadcast = ""; | 139 | broadcast = ""; |
98 | 140 | ||
99 | QTextStream stream( &file ); | 141 | QTextStream stream( &file ); |
100 | QString line; | 142 | QString line; |
101 | while ( !stream.eof() ) { | 143 | while ( !stream.eof() ) { |
102 | line = stream.readLine(); | 144 | line = stream.readLine(); |
103 | if(line.contains("HWaddr")){ | 145 | if(line.contains("HWaddr")){ |
104 | int mac = line.find("HWaddr"); | 146 | int mac = line.find("HWaddr"); |
105 | macAddress = line.mid(mac+7, line.length()); | 147 | macAddress = line.mid(mac+7, line.length()); |
106 | } | 148 | } |
107 | if(line.contains("inet addr")){ | 149 | if(line.contains("inet addr")){ |
108 | int ipl = line.find("inet addr"); | 150 | int ipl = line.find("inet addr"); |
109 | int space = line.find(" ", ipl+10); | 151 | int space = line.find(" ", ipl+10); |
110 | ip = line.mid(ipl+10, space-ipl-10); | 152 | ip = line.mid(ipl+10, space-ipl-10); |
111 | } | 153 | } |
112 | if(line.contains("Mask")){ | 154 | if(line.contains("Mask")){ |
113 | int mask = line.find("Mask"); | 155 | int mask = line.find("Mask"); |
114 | subnetMask = line.mid(mask+5, line.length()); | 156 | subnetMask = line.mid(mask+5, line.length()); |
115 | } | 157 | } |
116 | if(line.contains("Bcast")){ | 158 | if(line.contains("Bcast")){ |
117 | int mask = line.find("Bcast"); | 159 | int mask = line.find("Bcast"); |
118 | int space = line.find(" ", mask+6); | 160 | int space = line.find(" ", mask+6); |
119 | broadcast = line.mid(mask+6, space-mask-6); | 161 | broadcast = line.mid(mask+6, space-mask-6); |
120 | } | 162 | } |
121 | } | 163 | } |
122 | file.close(); | 164 | file.close(); |
123 | QFile::remove(fileName); | 165 | QFile::remove(fileName); |
124 | 166 | ||
125 | // DHCP TESTING | 167 | // DHCP TESTING |
126 | // reset DHCP info | 168 | // reset DHCP info |
127 | dhcpServerIp = ""; | 169 | dhcpServerIp = ""; |
128 | leaseObtained = ""; | 170 | leaseObtained = ""; |
129 | leaseExpires = ""; | 171 | leaseExpires = ""; |
130 | dhcp = false; | 172 | dhcp = false; |
131 | 173 | ||
132 | QString dhcpDirectory(HDCP_INFO_DIR); | 174 | QString dhcpDirectory(HDCP_INFO_DIR); |
133 | QDir d(dhcpDirectory); | 175 | QDir d(dhcpDirectory); |
134 | if(!d.exists(dhcpDirectory)) | 176 | if(!d.exists(dhcpDirectory)) |
135 | dhcpDirectory = "/var/run"; | 177 | dhcpDirectory = "/var/run"; |
136 | 178 | ||
137 | // See if we have | 179 | // See if we have |
138 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); | 180 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); |
139 | // If there is no DHCP information then exit now with no errors. | 181 | // If there is no DHCP information then exit now with no errors. |
140 | if(!QFile::exists(dhcpFile)){ | 182 | if(!QFile::exists(dhcpFile)){ |
183 | emit(updateInterface(this)); | ||
141 | return true; | 184 | return true; |
142 | } | 185 | } |
143 | 186 | ||
144 | file.setName(dhcpFile); | 187 | file.setName(dhcpFile); |
145 | if (!file.open(IO_ReadOnly)){ | 188 | if (!file.open(IO_ReadOnly)){ |
146 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 189 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
147 | return false; | 190 | return false; |
148 | } | 191 | } |
149 | 192 | ||
150 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | 193 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. |
151 | int leaseTime = 0; | 194 | int leaseTime = 0; |
152 | int renewalTime = 0; | 195 | int renewalTime = 0; |
153 | 196 | ||
154 | stream.setDevice( &file ); | 197 | stream.setDevice( &file ); |
155 | while ( !stream.eof() ) { | 198 | while ( !stream.eof() ) { |
156 | line = stream.readLine(); | 199 | line = stream.readLine(); |
157 | if(line.contains("DHCPSIADDR=")) | 200 | if(line.contains("DHCPSIADDR=")) |
158 | dhcpServerIp = line.mid(11, line.length()); | 201 | dhcpServerIp = line.mid(11, line.length()); |
159 | if(line.contains("LEASETIME=")) | 202 | if(line.contains("LEASETIME=")) |
160 | leaseTime = line.mid(10, line.length()).toInt(); | 203 | leaseTime = line.mid(10, line.length()).toInt(); |
161 | if(line.contains("RENEWALTIME=")) | 204 | if(line.contains("RENEWALTIME=")) |
162 | renewalTime = line.mid(12, line.length()).toInt(); | 205 | renewalTime = line.mid(12, line.length()).toInt(); |
163 | } | 206 | } |
164 | file.close(); | 207 | file.close(); |
165 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 208 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
166 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 209 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
167 | 210 | ||
168 | // Get the pid of the deamond | 211 | // Get the pid of the deamond |
169 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); | 212 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); |
170 | file.setName(dhcpFile); | 213 | file.setName(dhcpFile); |
171 | if (!file.open(IO_ReadOnly)){ | 214 | if (!file.open(IO_ReadOnly)){ |
172 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 215 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
173 | return false; | 216 | return false; |
174 | } | 217 | } |
175 | 218 | ||
176 | int pid = -1; | 219 | int pid = -1; |
177 | stream.setDevice( &file ); | 220 | stream.setDevice( &file ); |
178 | while ( !stream.eof() ) { | 221 | while ( !stream.eof() ) { |
179 | line = stream.readLine(); | 222 | line = stream.readLine(); |
180 | pid = line.toInt(); | 223 | pid = line.toInt(); |
181 | } | 224 | } |
182 | file.close(); | 225 | file.close(); |
183 | 226 | ||
184 | if( pid == -1){ | 227 | if( pid == -1){ |
185 | qDebug("Interface: Could not get pid of dhcpc deamon."); | 228 | qDebug("Interface: Could not get pid of dhcpc deamon."); |
186 | return false; | 229 | return false; |
187 | } | 230 | } |
188 | 231 | ||
189 | // Get the start running time of the deamon | 232 | // Get the start running time of the deamon |
190 | fileName = (QString("/proc/%1/stat").arg(pid)); | 233 | fileName = (QString("/proc/%1/stat").arg(pid)); |
191 | file.setName(fileName); | 234 | file.setName(fileName); |
192 | stream.setDevice( &file ); | 235 | stream.setDevice( &file ); |
193 | if (!file.open(IO_ReadOnly)){ | 236 | if (!file.open(IO_ReadOnly)){ |
194 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 237 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
195 | return false; | 238 | return false; |
196 | } | 239 | } |
197 | while ( !stream.eof() ) { | 240 | while ( !stream.eof() ) { |
198 | line = stream.readLine(); | 241 | line = stream.readLine(); |
199 | } | 242 | } |
200 | file.close(); | 243 | file.close(); |
201 | long time = 0; | 244 | long time = 0; |
202 | // Grab the start time | 245 | // Grab the start time |
203 | // pid com state ppid pgrp session tty_nr tpgid flags | 246 | // pid com state ppid pgrp session tty_nr tpgid flags |
204 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | 247 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " |
205 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | 248 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority |
206 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 249 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
207 | // nice 0 itrealvalue starttime | 250 | // nice 0 itrealvalue starttime |
208 | "%*d %*d %*d %lu", (long*) &time); | 251 | "%*d %*d %*d %lu", (long*) &time); |
209 | time = time/100; | 252 | time = time/100; |
210 | 253 | ||
211 | QDateTime datetime(QDateTime::currentDateTime()); | 254 | QDateTime datetime(QDateTime::currentDateTime()); |
212 | 255 | ||
213 | // Get the uptime of the computer. | 256 | // Get the uptime of the computer. |
214 | QFile f("/proc/uptime"); | 257 | QFile f("/proc/uptime"); |
215 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 258 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
216 | QTextStream t( &f ); // use a text stream | 259 | QTextStream t( &f ); // use a text stream |
217 | int sec = 0; | 260 | int sec = 0; |
218 | t >> sec; | 261 | t >> sec; |
219 | datetime = datetime.addSecs((-1*sec)); | 262 | datetime = datetime.addSecs((-1*sec)); |
220 | f.close(); | 263 | f.close(); |
221 | } | 264 | } |
222 | else{ | 265 | else{ |
223 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 266 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
224 | return false; | 267 | return false; |
225 | } | 268 | } |
226 | 269 | ||
227 | datetime = datetime.addSecs(time); | 270 | datetime = datetime.addSecs(time); |
228 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 271 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
229 | 272 | ||
230 | // Calculate the start and renew times | 273 | // Calculate the start and renew times |
231 | leaseObtained= datetime.toString(); | 274 | leaseObtained= datetime.toString(); |
232 | 275 | ||
233 | // Calculate the start and renew times | 276 | // Calculate the start and renew times |
234 | datetime = datetime.addSecs(leaseTime); | 277 | datetime = datetime.addSecs(leaseTime); |
235 | leaseExpires = datetime.toString(); | 278 | leaseExpires = datetime.toString(); |
236 | 279 | ||
237 | dhcp = true; | 280 | dhcp = true; |
281 | |||
282 | emit(updateInterface(this)); | ||
238 | return true; | 283 | return true; |
239 | } | 284 | } |
240 | 285 | ||
241 | // interface.cpp | 286 | // interface.cpp |
242 | 287 | ||
diff --git a/noncore/settings/networksettings/interface.h b/noncore/settings/networksettings/interface.h index 1406e99..980171a 100644 --- a/noncore/settings/networksettings/interface.h +++ b/noncore/settings/networksettings/interface.h | |||
@@ -1,67 +1,72 @@ | |||
1 | #ifndef INTERFACE_H | 1 | #ifndef INTERFACE_H |
2 | #define INTERFACE_H | 2 | #define INTERFACE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qobject.h> | ||
5 | 6 | ||
6 | class Module; | 7 | class Module; |
7 | 8 | ||
8 | class Interface { | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | ||
9 | 11 | ||
12 | signals: | ||
13 | void updateInterface(Interface *i); | ||
14 | |||
10 | public: | 15 | public: |
11 | Interface(QString name = "unknown", bool status = false); | 16 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
12 | virtual ~Interface(){}; | 17 | virtual ~Interface(){}; |
13 | 18 | ||
19 | virtual QString getInterfaceName(){ QString n(this->name()); return n; }; | ||
20 | |||
14 | virtual bool getStatus(){ return status; }; | 21 | virtual bool getStatus(){ return status; }; |
15 | virtual void setStatus(bool newSatus){ status = newSatus; refresh(); }; | 22 | virtual void setStatus(bool newStatus); |
16 | 23 | ||
17 | virtual bool isAttached(){ return attached; }; | 24 | virtual bool isAttached(){ return attached; }; |
18 | virtual void setAttached(bool isAttached=false){ attached = isAttached; }; | 25 | virtual void setAttached(bool isAttached=false); |
19 | |||
20 | virtual QString getInterfaceName(){ return interfaceName; }; | ||
21 | virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; }; | ||
22 | 26 | ||
23 | virtual QString getHardwareName(){ return hardareName; }; | 27 | virtual QString getHardwareName(){ return hardareName; }; |
24 | virtual void setHardwareName(QString name="Unknown"){ hardareName = name; }; | 28 | virtual void setHardwareName(QString name="Unknown"); |
25 | 29 | ||
26 | virtual Module* getModuleOwner(){ return moduleOwner; }; | 30 | virtual Module* getModuleOwner(){ return moduleOwner; }; |
27 | virtual void setModuleOwner(Module *owner=NULL){ moduleOwner = owner; }; | 31 | virtual void setModuleOwner(Module *owner=NULL); |
28 | 32 | ||
29 | // inet information. | 33 | // inet information. |
30 | QString getMacAddress(){ return macAddress; }; | 34 | QString getMacAddress(){ return macAddress; }; |
31 | QString getIp(){ return ip; }; | 35 | QString getIp(){ return ip; }; |
32 | QString getSubnetMask(){ return subnetMask; }; | 36 | QString getSubnetMask(){ return subnetMask; }; |
33 | QString getBroadcast(){ return broadcast; }; | 37 | QString getBroadcast(){ return broadcast; }; |
34 | bool isDhcp(){ return dhcp; }; | 38 | bool isDhcp(){ return dhcp; }; |
35 | QString getDhcpServerIp(){ return dhcpServerIp; }; | 39 | QString getDhcpServerIp(){ return dhcpServerIp; }; |
36 | QString getLeaseObtained(){ return leaseObtained; }; | 40 | QString getLeaseObtained(){ return leaseObtained; }; |
37 | QString getLeaseExpires(){ return leaseExpires; }; | 41 | QString getLeaseExpires(){ return leaseExpires; }; |
38 | 42 | ||
43 | public slots: | ||
39 | bool refresh(); | 44 | bool refresh(); |
40 | bool start(); | 45 | void start(); |
41 | bool stop(); | 46 | void stop(); |
42 | bool restart(); | 47 | void restart(); |
43 | 48 | ||
44 | private: | 49 | private: |
45 | // Interface information | 50 | // Interface information |
46 | bool status; | 51 | bool status; |
47 | bool attached; | 52 | bool attached; |
48 | QString interfaceName; | 53 | QString interfaceName; |
49 | QString hardareName; | 54 | QString hardareName; |
50 | Module *moduleOwner; | 55 | Module *moduleOwner; |
51 | 56 | ||
52 | // Network information | 57 | // Network information |
53 | QString macAddress; | 58 | QString macAddress; |
54 | QString ip; | 59 | QString ip; |
55 | QString broadcast; | 60 | QString broadcast; |
56 | QString subnetMask; | 61 | QString subnetMask; |
57 | bool dhcp; | 62 | bool dhcp; |
58 | QString dhcpServerIp; | 63 | QString dhcpServerIp; |
59 | QString leaseObtained; | 64 | QString leaseObtained; |
60 | QString leaseExpires; | 65 | QString leaseExpires; |
61 | 66 | ||
62 | }; | 67 | }; |
63 | 68 | ||
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | // interface.h | 71 | // interface.h |
67 | 72 | ||
diff --git a/noncore/settings/networksettings/interfaceadvanced.ui b/noncore/settings/networksettings/interfaceadvanced.ui index 7520abe..efe67b0 100644 --- a/noncore/settings/networksettings/interfaceadvanced.ui +++ b/noncore/settings/networksettings/interfaceadvanced.ui | |||
@@ -1,82 +1,89 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceAdvanced</class> | 2 | <class>InterfaceAdvanced</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceAdvanced</cstring> | 7 | <cstring>InterfaceAdvanced</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>188</width> | 14 | <width>214</width> |
15 | <height>277</height> | 15 | <height>286</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>maximumSize</name> | ||
20 | <size> | ||
21 | <width>320</width> | ||
22 | <height>32767</height> | ||
23 | </size> | ||
24 | </property> | ||
25 | <property stdset="1"> | ||
19 | <name>caption</name> | 26 | <name>caption</name> |
20 | <string>Advanced Interface Information</string> | 27 | <string>Advanced Interface Information</string> |
21 | </property> | 28 | </property> |
22 | <grid> | 29 | <grid> |
23 | <property stdset="1"> | 30 | <property stdset="1"> |
24 | <name>margin</name> | 31 | <name>margin</name> |
25 | <number>11</number> | 32 | <number>11</number> |
26 | </property> | 33 | </property> |
27 | <property stdset="1"> | 34 | <property stdset="1"> |
28 | <name>spacing</name> | 35 | <name>spacing</name> |
29 | <number>6</number> | 36 | <number>6</number> |
30 | </property> | 37 | </property> |
31 | <widget row="1" column="0" > | 38 | <widget row="1" column="0" > |
32 | <class>QLabel</class> | 39 | <class>QLabel</class> |
33 | <property stdset="1"> | 40 | <property stdset="1"> |
34 | <name>name</name> | 41 | <name>name</name> |
35 | <cstring>TextLabel1</cstring> | 42 | <cstring>TextLabel1</cstring> |
36 | </property> | 43 | </property> |
37 | <property stdset="1"> | 44 | <property stdset="1"> |
38 | <name>text</name> | 45 | <name>text</name> |
39 | <string>MAC Address</string> | 46 | <string>MAC Address</string> |
40 | </property> | 47 | </property> |
41 | </widget> | 48 | </widget> |
42 | <widget row="0" column="1" > | 49 | <widget row="0" column="1" > |
43 | <class>QLabel</class> | 50 | <class>QLabel</class> |
44 | <property stdset="1"> | 51 | <property stdset="1"> |
45 | <name>name</name> | 52 | <name>name</name> |
46 | <cstring>interfaceName</cstring> | 53 | <cstring>interfaceName</cstring> |
47 | </property> | 54 | </property> |
48 | <property stdset="1"> | 55 | <property stdset="1"> |
49 | <name>frameShape</name> | 56 | <name>frameShape</name> |
50 | <enum>Panel</enum> | 57 | <enum>Panel</enum> |
51 | </property> | 58 | </property> |
52 | <property stdset="1"> | 59 | <property stdset="1"> |
53 | <name>frameShadow</name> | 60 | <name>frameShadow</name> |
54 | <enum>Sunken</enum> | 61 | <enum>Sunken</enum> |
55 | </property> | 62 | </property> |
56 | <property stdset="1"> | 63 | <property stdset="1"> |
57 | <name>text</name> | 64 | <name>text</name> |
58 | <string>eth0</string> | 65 | <string>eth0</string> |
59 | </property> | 66 | </property> |
60 | </widget> | 67 | </widget> |
61 | <widget row="2" column="0" > | 68 | <widget row="2" column="0" > |
62 | <class>QLabel</class> | 69 | <class>QLabel</class> |
63 | <property stdset="1"> | 70 | <property stdset="1"> |
64 | <name>name</name> | 71 | <name>name</name> |
65 | <cstring>TextLabel3</cstring> | 72 | <cstring>TextLabel3</cstring> |
66 | </property> | 73 | </property> |
67 | <property stdset="1"> | 74 | <property stdset="1"> |
68 | <name>text</name> | 75 | <name>text</name> |
69 | <string>IP Address</string> | 76 | <string>IP Address</string> |
70 | </property> | 77 | </property> |
71 | </widget> | 78 | </widget> |
72 | <widget row="1" column="1" > | 79 | <widget row="1" column="1" > |
73 | <class>QLabel</class> | 80 | <class>QLabel</class> |
74 | <property stdset="1"> | 81 | <property stdset="1"> |
75 | <name>name</name> | 82 | <name>name</name> |
76 | <cstring>macAddressLabel</cstring> | 83 | <cstring>macAddressLabel</cstring> |
77 | </property> | 84 | </property> |
78 | <property stdset="1"> | 85 | <property stdset="1"> |
79 | <name>frameShape</name> | 86 | <name>frameShape</name> |
80 | <enum>Panel</enum> | 87 | <enum>Panel</enum> |
81 | </property> | 88 | </property> |
82 | <property stdset="1"> | 89 | <property stdset="1"> |
diff --git a/noncore/settings/networksettings/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaceinformationimp.cpp index e37e0f8..59a6400 100644 --- a/noncore/settings/networksettings/interfaceinformationimp.cpp +++ b/noncore/settings/networksettings/interfaceinformationimp.cpp | |||
@@ -1,94 +1,67 @@ | |||
1 | #include "interfaceinformationimp.h" | 1 | #include "interfaceinformationimp.h" |
2 | #include "interfaceadvanced.h" | 2 | #include "interfaceadvanced.h" |
3 | 3 | ||
4 | #include <qpushbutton.h> | 4 | #include <qpushbutton.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <assert.h> | 6 | #include <assert.h> |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Constructor for the InterfaceInformationImp class. This class pretty much | 9 | * Constructor for the InterfaceInformationImp class. This class pretty much |
10 | * just display's information about the interface that is passed to it. | 10 | * just display's information about the interface that is passed to it. |
11 | */ | 11 | */ |
12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ | 12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ |
13 | assert(i); | 13 | assert(i); |
14 | 14 | ||
15 | interface = i; | 15 | interface = i; |
16 | updateInterface(); | 16 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
17 | connect(startButton, SIGNAL(clicked()), this, SLOT(start())); | 17 | updateInterface(interface); |
18 | connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); | 18 | connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); |
19 | connect(restartButton, SIGNAL(clicked()), this, SLOT(restart())); | 19 | connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); |
20 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); | 20 | connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); |
21 | connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); | ||
21 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | 22 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); |
22 | 23 | ||
23 | } | 24 | } |
24 | 25 | ||
25 | void InterfaceInformationImp::updateInterface(){ | 26 | /** |
27 | * Update the interface information and buttons. | ||
28 | * @param Intarface *i the interface to update (should be the one we already | ||
29 | * know about). | ||
30 | */ | ||
31 | void InterfaceInformationImp::updateInterface(Interface *i){ | ||
26 | if(interface->getStatus()){ | 32 | if(interface->getStatus()){ |
27 | startButton->setEnabled(false); | 33 | startButton->setEnabled(false); |
28 | stopButton->setEnabled(true); | 34 | stopButton->setEnabled(true); |
29 | restartButton->setEnabled(true); | 35 | restartButton->setEnabled(true); |
30 | } | 36 | } |
31 | else{ | 37 | else{ |
32 | startButton->setEnabled(true); | 38 | startButton->setEnabled(true); |
33 | stopButton->setEnabled(false); | 39 | stopButton->setEnabled(false); |
34 | restartButton->setEnabled(false); | 40 | restartButton->setEnabled(false); |
35 | } | 41 | } |
36 | macAddressLabel->setText(interface->getMacAddress()); | 42 | macAddressLabel->setText(interface->getMacAddress()); |
37 | ipAddressLabel->setText(interface->getIp()); | 43 | ipAddressLabel->setText(interface->getIp()); |
38 | subnetMaskLabel->setText(interface->getSubnetMask()); | 44 | subnetMaskLabel->setText(interface->getSubnetMask()); |
39 | broadcastLabel->setText(interface->getBroadcast()); | 45 | broadcastLabel->setText(interface->getBroadcast()); |
40 | } | 46 | } |
41 | 47 | ||
42 | /** | 48 | /** |
43 | * Start the interface. Update the information if successfull | ||
44 | */ | ||
45 | void InterfaceInformationImp::start(){ | ||
46 | if(interface->start()){ | ||
47 | updateInterface(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Stop the interface. | ||
53 | */ | ||
54 | void InterfaceInformationImp::stop(){ | ||
55 | if(interface->stop()){ | ||
56 | updateInterface(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /*** | ||
61 | * Tell the interface to refresh its information. | ||
62 | **/ | ||
63 | void InterfaceInformationImp::refresh(){ | ||
64 | if(interface->refresh()) | ||
65 | updateInterface(); | ||
66 | } | ||
67 | |||
68 | void InterfaceInformationImp::restart(){ | ||
69 | if(interface->restart()){ | ||
70 | updateInterface(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create the advanced widget. Fill it with the current interface's information. | 49 | * Create the advanced widget. Fill it with the current interface's information. |
77 | * Display it. | 50 | * Display it. |
78 | */ | 51 | */ |
79 | void InterfaceInformationImp::advanced(){ | 52 | void InterfaceInformationImp::advanced(){ |
80 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); | 53 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); |
81 | a->interfaceName->setText(interface->getInterfaceName()); | 54 | a->interfaceName->setText(interface->getInterfaceName()); |
82 | a->macAddressLabel->setText(interface->getMacAddress()); | 55 | a->macAddressLabel->setText(interface->getMacAddress()); |
83 | a->ipAddressLabel->setText(interface->getIp()); | 56 | a->ipAddressLabel->setText(interface->getIp()); |
84 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | 57 | a->subnetMaskLabel->setText(interface->getSubnetMask()); |
85 | a->broadcastLabel->setText(interface->getBroadcast()); | 58 | a->broadcastLabel->setText(interface->getBroadcast()); |
86 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | 59 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); |
87 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | 60 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); |
88 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | 61 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); |
89 | a->showMaximized(); | 62 | a->showMaximized(); |
90 | a->show(); | 63 | a->show(); |
91 | } | 64 | } |
92 | 65 | ||
93 | // infoimp.cpp | 66 | // infoimp.cpp |
94 | 67 | ||
diff --git a/noncore/settings/networksettings/interfaceinformationimp.h b/noncore/settings/networksettings/interfaceinformationimp.h index c8a478e..42213cc 100644 --- a/noncore/settings/networksettings/interfaceinformationimp.h +++ b/noncore/settings/networksettings/interfaceinformationimp.h | |||
@@ -1,31 +1,27 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | 1 | #ifndef INTERFACEINFORMATIONIMP_H |
2 | #define INTERFACEINFORMATIONIMP_H | 2 | #define INTERFACEINFORMATIONIMP_H |
3 | 3 | ||
4 | #include "interfaceinformation.h" | 4 | #include "interfaceinformation.h" |
5 | #include "interface.h" | 5 | #include "interface.h" |
6 | 6 | ||
7 | class InterfaceInformationImp : public InterfaceInformation { | 7 | class InterfaceInformationImp : public InterfaceInformation { |
8 | 8 | ||
9 | Q_OBJECT | 9 | Q_OBJECT |
10 | 10 | ||
11 | public: | 11 | public: |
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | 12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); |
13 | ~InterfaceInformationImp(){}; | 13 | ~InterfaceInformationImp(){}; |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void start(); | ||
17 | void stop(); | ||
18 | void refresh(); | ||
19 | void restart(); | ||
20 | void advanced(); | 16 | void advanced(); |
17 | void updateInterface(Interface *i); | ||
21 | 18 | ||
22 | private: | 19 | private: |
23 | Interface *interface; | 20 | Interface *interface; |
24 | void updateInterface(); | ||
25 | 21 | ||
26 | }; | 22 | }; |
27 | 23 | ||
28 | #endif | 24 | #endif |
29 | 25 | ||
30 | // addserviceimp.h | 26 | // addserviceimp.h |
31 | 27 | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index b46362f..117bac1 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -243,218 +243,221 @@ void MainWindowImp::informationClicked(){ | |||
243 | if(!i->isAttached()){ | 243 | if(!i->isAttached()){ |
244 | QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); | 244 | QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | if(i->getModuleOwner()){ | 247 | if(i->getModuleOwner()){ |
248 | QTabWidget *tabWidget = NULL; | 248 | QTabWidget *tabWidget = NULL; |
249 | QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); | 249 | QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); |
250 | if(moduleInformation != NULL){ | 250 | if(moduleInformation != NULL){ |
251 | if(tabWidget != NULL){ | 251 | if(tabWidget != NULL){ |
252 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); | 252 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
253 | tabWidget->insertTab(information, "TCP/IP"); | 253 | tabWidget->insertTab(information, "TCP/IP"); |
254 | } | 254 | } |
255 | moduleInformation->showMaximized(); | 255 | moduleInformation->showMaximized(); |
256 | moduleInformation->show(); | 256 | moduleInformation->show(); |
257 | return; | 257 | return; |
258 | } | 258 | } |
259 | } | 259 | } |
260 | 260 | ||
261 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 261 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
262 | information->showMaximized(); | 262 | information->showMaximized(); |
263 | information->show(); | 263 | information->show(); |
264 | } | 264 | } |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * Aquire the list of active interfaces from ifconfig | 267 | * Aquire the list of active interfaces from ifconfig |
268 | * Call ifconfig and ifconfig -a | 268 | * Call ifconfig and ifconfig -a |
269 | */ | 269 | */ |
270 | void MainWindowImp::getInterfaceList(){ | 270 | void MainWindowImp::getInterfaceList(){ |
271 | KShellProcess *processAll = new KShellProcess(); | 271 | KShellProcess *processAll = new KShellProcess(); |
272 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 272 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
273 | connect(processAll, SIGNAL(processExited(KProcess *)), | 273 | connect(processAll, SIGNAL(processExited(KProcess *)), |
274 | this, SLOT(jobDone(KProcess *))); | 274 | this, SLOT(jobDone(KProcess *))); |
275 | threads.insert(processAll, TEMP_ALL); | 275 | threads.insert(processAll, TEMP_ALL); |
276 | 276 | ||
277 | KShellProcess *process = new KShellProcess(); | 277 | KShellProcess *process = new KShellProcess(); |
278 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | 278 | *process << "/sbin/ifconfig" << " > " TEMP_UP; |
279 | connect(process, SIGNAL(processExited(KProcess *)), | 279 | connect(process, SIGNAL(processExited(KProcess *)), |
280 | this, SLOT(jobDone(KProcess *))); | 280 | this, SLOT(jobDone(KProcess *))); |
281 | threads.insert(process, TEMP_UP); | 281 | threads.insert(process, TEMP_UP); |
282 | 282 | ||
283 | processAll->start(KShellProcess::NotifyOnExit); | 283 | processAll->start(KShellProcess::NotifyOnExit); |
284 | process->start(KShellProcess::NotifyOnExit); | 284 | process->start(KShellProcess::NotifyOnExit); |
285 | } | 285 | } |
286 | 286 | ||
287 | void MainWindowImp::jobDone(KProcess *process){ | 287 | void MainWindowImp::jobDone(KProcess *process){ |
288 | QString fileName = threads[process]; | 288 | QString fileName = threads[process]; |
289 | threads.remove(process); | 289 | threads.remove(process); |
290 | delete process; | 290 | delete process; |
291 | 291 | ||
292 | QFile file(fileName); | 292 | QFile file(fileName); |
293 | if (!file.open(IO_ReadOnly)){ | 293 | if (!file.open(IO_ReadOnly)){ |
294 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | 294 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); |
295 | return; | 295 | return; |
296 | } | 296 | } |
297 | 297 | ||
298 | QTextStream stream( &file ); | 298 | QTextStream stream( &file ); |
299 | QString line; | 299 | QString line; |
300 | while ( !stream.eof() ) { | 300 | while ( !stream.eof() ) { |
301 | line = stream.readLine(); | 301 | line = stream.readLine(); |
302 | int space = line.find(" "); | 302 | int space = line.find(" "); |
303 | if(space > 1){ | 303 | if(space > 1){ |
304 | // We have found an interface | 304 | // We have found an interface |
305 | QString interfaceName = line.mid(0, space); | 305 | QString interfaceName = line.mid(0, space); |
306 | Interface *i; | 306 | Interface *i; |
307 | // We have found an interface | ||
308 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
307 | // See if we already have it | 309 | // See if we already have it |
308 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 310 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
309 | if(fileName == TEMP_ALL) | 311 | if(fileName == TEMP_ALL) |
310 | i = new Interface(interfaceName, false); | 312 | i = new Interface(this, interfaceName, false); |
311 | else | 313 | else |
312 | i = new Interface(interfaceName, true); | 314 | i = new Interface(this, interfaceName, true); |
315 | i->setAttached(true); | ||
316 | |||
317 | QString hardName = "Ethernet"; | ||
318 | int hardwareName = line.find("Link encap:"); | ||
319 | int macAddress = line.find("HWaddr"); | ||
320 | if(macAddress == -1) | ||
321 | macAddress = line.length(); | ||
322 | if(hardwareName != -1) | ||
323 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
324 | |||
325 | interfaceNames.insert(i->getInterfaceName(), i); | ||
326 | updateInterface(i); | ||
327 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
313 | } | 328 | } |
329 | // It was an interface we already had. | ||
314 | else{ | 330 | else{ |
315 | i = interfaceNames[interfaceName]; | 331 | i = interfaceNames[interfaceName]; |
316 | if(fileName != TEMP_ALL) | 332 | if(fileName != TEMP_ALL) |
317 | i->setStatus(true); | 333 | i->setStatus(true); |
318 | } | 334 | } |
319 | |||
320 | i->setAttached(true); | ||
321 | i->setInterfaceName(interfaceName); | ||
322 | |||
323 | QString hardName = "Ethernet"; | ||
324 | int hardwareName = line.find("Link encap:"); | ||
325 | int macAddress = line.find("HWaddr"); | ||
326 | if(macAddress == -1) | ||
327 | macAddress = line.length(); | ||
328 | if(hardwareName != -1) | ||
329 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
330 | // We have found an interface | ||
331 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
332 | interfaceNames.insert(i->getInterfaceName(), i); | ||
333 | updateInterface(i); | ||
334 | } | 335 | } |
335 | } | 336 | } |
336 | file.close(); | 337 | file.close(); |
337 | QFile::remove(fileName); | 338 | QFile::remove(fileName); |
338 | 339 | ||
339 | if(threads.count() == 0){ | 340 | if(threads.count() == 0){ |
340 | Interfaces i; | 341 | Interfaces i; |
341 | QStringList list = i.getInterfaceList(); | 342 | QStringList list = i.getInterfaceList(); |
342 | QMap<QString, Interface*>::Iterator it; | 343 | QMap<QString, Interface*>::Iterator it; |
343 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 344 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
344 | bool found = false; | 345 | bool found = false; |
345 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 346 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
346 | if(it.key() == (*ni)) | 347 | if(it.key() == (*ni)) |
347 | found = true; | 348 | found = true; |
348 | } | 349 | } |
349 | if(!found){ | 350 | if(!found){ |
350 | Interface *i = new Interface(*ni, false); | 351 | Interface *i = new Interface(this, *ni, false); |
351 | i->setAttached(false); | 352 | i->setAttached(false); |
352 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); | 353 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); |
353 | i->setInterfaceName(*ni); | ||
354 | interfaceNames.insert(i->getInterfaceName(), i); | 354 | interfaceNames.insert(i->getInterfaceName(), i); |
355 | updateInterface(i); | 355 | updateInterface(i); |
356 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
356 | } | 357 | } |
357 | } | 358 | } |
358 | } | 359 | } |
359 | } | 360 | } |
360 | 361 | ||
361 | /** | 362 | /** |
362 | * Update this interface. If no QListViewItem exists create one. | 363 | * Update this interface. If no QListViewItem exists create one. |
363 | * @param Interface* pointer to the interface that needs to be updated. | 364 | * @param Interface* pointer to the interface that needs to be updated. |
364 | */ | 365 | */ |
365 | void MainWindowImp::updateInterface(Interface *i){ | 366 | void MainWindowImp::updateInterface(Interface *i){ |
366 | if(!advancedUserMode){ | 367 | if(!advancedUserMode){ |
367 | if(i->getInterfaceName() == "lo") | 368 | if(i->getInterfaceName() == "lo") |
368 | return; | 369 | return; |
369 | } | 370 | } |
370 | 371 | ||
371 | QListViewItem *item = NULL; | 372 | QListViewItem *item = NULL; |
372 | 373 | ||
373 | // Find the interface, making it if needed. | 374 | // Find the interface, making it if needed. |
374 | if(items.find(i) == items.end()){ | 375 | if(items.find(i) == items.end()){ |
375 | item = new QListViewItem(connectionList, "", "", ""); | 376 | item = new QListViewItem(connectionList, "", "", ""); |
376 | // See if you can't find a module owner for this interface | 377 | // See if you can't find a module owner for this interface |
377 | QMap<Module*, QLibrary*>::Iterator it; | 378 | QMap<Module*, QLibrary*>::Iterator it; |
378 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 379 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
379 | if(it.key()->isOwner(i)) | 380 | if(it.key()->isOwner(i)) |
380 | i->setModuleOwner(it.key()); | 381 | i->setModuleOwner(it.key()); |
381 | } | 382 | } |
382 | items.insert(i, item); | 383 | items.insert(i, item); |
383 | interfaceItems.insert(item, i); | 384 | interfaceItems.insert(item, i); |
384 | } | 385 | } |
385 | else | 386 | else |
386 | item = items[i]; | 387 | item = items[i]; |
387 | 388 | ||
388 | // Update the icons and information | 389 | // Update the icons and information |
389 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 390 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
390 | 391 | ||
391 | QString typeName = "lan"; | 392 | QString typeName = "lan"; |
392 | if(i->getHardwareName().contains("Local Loopback")) | 393 | if(i->getHardwareName().contains("Local Loopback")) |
393 | typeName = "lo"; | 394 | typeName = "lo"; |
394 | if(i->getInterfaceName().contains("irda")) | 395 | if(i->getInterfaceName().contains("irda")) |
395 | typeName = "irda"; | 396 | typeName = "irda"; |
396 | if(i->getInterfaceName().contains("wlan")) | 397 | if(i->getInterfaceName().contains("wlan")) |
397 | typeName = "wlan"; | 398 | typeName = "wlan"; |
398 | 399 | if(i->getInterfaceName().contains("usb")) | |
400 | typeName = "usb"; | ||
401 | |||
399 | if(!i->isAttached()) | 402 | if(!i->isAttached()) |
400 | typeName = "connect_no"; | 403 | typeName = "connect_no"; |
401 | // Actually try to use the Module | 404 | // Actually try to use the Module |
402 | if(i->getModuleOwner() != NULL) | 405 | if(i->getModuleOwner() != NULL) |
403 | typeName = i->getModuleOwner()->getPixmapName(i); | 406 | typeName = i->getModuleOwner()->getPixmapName(i); |
404 | 407 | ||
405 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 408 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
406 | item->setText(2, i->getHardwareName()); | 409 | item->setText(2, i->getHardwareName()); |
407 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); | 410 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); |
408 | } | 411 | } |
409 | 412 | ||
410 | void MainWindowImp::newProfileChanged(const QString& newText){ | 413 | void MainWindowImp::newProfileChanged(const QString& newText){ |
411 | if(newText.length() > 0) | 414 | if(newText.length() > 0) |
412 | newProfileButton->setEnabled(true); | 415 | newProfileButton->setEnabled(true); |
413 | else | 416 | else |
414 | newProfileButton->setEnabled(false); | 417 | newProfileButton->setEnabled(false); |
415 | } | 418 | } |
416 | 419 | ||
417 | /** | 420 | /** |
418 | * Adds a new profile to the list of profiles. | 421 | * Adds a new profile to the list of profiles. |
419 | * Don't add profiles that already exists. | 422 | * Don't add profiles that already exists. |
420 | * Appends to the list and QStringList | 423 | * Appends to the list and QStringList |
421 | */ | 424 | */ |
422 | void MainWindowImp::addProfile(){ | 425 | void MainWindowImp::addProfile(){ |
423 | QString newProfileName = newProfile->text(); | 426 | QString newProfileName = newProfile->text(); |
424 | if(profiles.grep(newProfileName).count() > 0){ | 427 | if(profiles.grep(newProfileName).count() > 0){ |
425 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 428 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
426 | return; | 429 | return; |
427 | } | 430 | } |
428 | profiles.append(newProfileName); | 431 | profiles.append(newProfileName); |
429 | profilesList->insertItem(newProfileName); | 432 | profilesList->insertItem(newProfileName); |
430 | } | 433 | } |
431 | 434 | ||
432 | /** | 435 | /** |
433 | * Removes the currently selected profile in the combo. | 436 | * Removes the currently selected profile in the combo. |
434 | * Doesn't delete if there are less then 2 profiles. | 437 | * Doesn't delete if there are less then 2 profiles. |
435 | */ | 438 | */ |
436 | void MainWindowImp::removeProfile(){ | 439 | void MainWindowImp::removeProfile(){ |
437 | if(profilesList->count() <= 1){ | 440 | if(profilesList->count() <= 1){ |
438 | QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); | 441 | QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); |
439 | return; | 442 | return; |
440 | } | 443 | } |
441 | QString profileToRemove = profilesList->currentText(); | 444 | QString profileToRemove = profilesList->currentText(); |
442 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 445 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
443 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 446 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
444 | profilesList->clear(); | 447 | profilesList->clear(); |
445 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 448 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
446 | profilesList->insertItem((*it)); | 449 | profilesList->insertItem((*it)); |
447 | } | 450 | } |
448 | 451 | ||
449 | } | 452 | } |
450 | 453 | ||
451 | /** | 454 | /** |
452 | * A new profile has been selected, change. | 455 | * A new profile has been selected, change. |
453 | * @param newProfile the new profile. | 456 | * @param newProfile the new profile. |
454 | */ | 457 | */ |
455 | void MainWindowImp::changeProfile(){ | 458 | void MainWindowImp::changeProfile(){ |
456 | currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); | 459 | currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); |
457 | } | 460 | } |
458 | 461 | ||
459 | // mainwindowimp.cpp | 462 | // mainwindowimp.cpp |
460 | 463 | ||
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index 98d2eb6..f0394b4 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp | |||
@@ -1,84 +1,86 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include <qpe/config.h> | 2 | #include <qpe/config.h> |
3 | #include "wlanimp.h" | 3 | #include "wlanimp.h" |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Constructor, find all of the possible interfaces | 6 | * Constructor, find all of the possible interfaces |
7 | */ | 7 | */ |
8 | WLANModule::WLANModule() : Module() { | 8 | WLANModule::WLANModule() : Module() { |
9 | // get output from iwconfig | 9 | // get output from iwconfig |
10 | } | 10 | } |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * get the icon name for this device. | 13 | * get the icon name for this device. |
14 | * @param Interface* can be used in determining the icon. | 14 | * @param Interface* can be used in determining the icon. |
15 | * @return QString the icon name (minus .png, .gif etc) | 15 | * @return QString the icon name (minus .png, .gif etc) |
16 | */ | 16 | */ |
17 | QString WLANModule::getPixmapName(Interface* ){ | 17 | QString WLANModule::getPixmapName(Interface* ){ |
18 | return "wlan"; | 18 | return "wlan"; |
19 | } | 19 | } |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Check to see if the interface i is owned by this module. | 22 | * Check to see if the interface i is owned by this module. |
23 | * @param Interface* interface to check against | 23 | * @param Interface* interface to check against |
24 | * @return bool true if i is owned by this module, false otherwise. | 24 | * @return bool true if i is owned by this module, false otherwise. |
25 | */ | 25 | */ |
26 | bool WLANModule::isOwner(Interface *i){ | 26 | bool WLANModule::isOwner(Interface *i){ |
27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0") | 27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ |
28 | i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName())); | ||
28 | return true; | 29 | return true; |
30 | } | ||
29 | return false; | 31 | return false; |
30 | } | 32 | } |
31 | 33 | ||
32 | /** | 34 | /** |
33 | * Create, set tabWiget and return the WLANConfigure Module | 35 | * Create, set tabWiget and return the WLANConfigure Module |
34 | * @param tabWidget a pointer to the tab widget that this configure has. | 36 | * @param tabWidget a pointer to the tab widget that this configure has. |
35 | * @return QWidget* pointer to the tab widget in this modules configure. | 37 | * @return QWidget* pointer to the tab widget in this modules configure. |
36 | */ | 38 | */ |
37 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ | 39 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ |
38 | Config *cfg = new Config("wireless"); | 40 | Config *cfg = new Config("wireless"); |
39 | WLANImp *wlanconfig = new WLANImp(*cfg); | 41 | WLANImp *wlanconfig = new WLANImp(*cfg); |
40 | (*tabWidget) = wlanconfig->tabWidget; | 42 | (*tabWidget) = wlanconfig->tabWidget; |
41 | return wlanconfig; | 43 | return wlanconfig; |
42 | } | 44 | } |
43 | 45 | ||
44 | /** | 46 | /** |
45 | * Create, set tabWiget and return the Information Module | 47 | * Create, set tabWiget and return the Information Module |
46 | * @param tabWidget a pointer to the tab widget that this information has. | 48 | * @param tabWidget a pointer to the tab widget that this information has. |
47 | * @return QWidget* pointer to the tab widget in this modules info. | 49 | * @return QWidget* pointer to the tab widget in this modules info. |
48 | */ | 50 | */ |
49 | QWidget *WLANModule::information(QTabWidget **tabWidget){ | 51 | QWidget *WLANModule::information(QTabWidget **tabWidget){ |
50 | return NULL; | 52 | return NULL; |
51 | } | 53 | } |
52 | 54 | ||
53 | /** | 55 | /** |
54 | * Get all active (up or down) interfaces | 56 | * Get all active (up or down) interfaces |
55 | * @return QList<Interface> A list of interfaces that exsist that havn't | 57 | * @return QList<Interface> A list of interfaces that exsist that havn't |
56 | * been called by isOwner() | 58 | * been called by isOwner() |
57 | */ | 59 | */ |
58 | QList<Interface> WLANModule::getInterfaces(){ | 60 | QList<Interface> WLANModule::getInterfaces(){ |
59 | return list; | 61 | return list; |
60 | } | 62 | } |
61 | 63 | ||
62 | /** | 64 | /** |
63 | * Attempt to add a new interface as defined by name | 65 | * Attempt to add a new interface as defined by name |
64 | * @param name the name of the type of interface that should be created given | 66 | * @param name the name of the type of interface that should be created given |
65 | * by possibleNewInterfaces(); | 67 | * by possibleNewInterfaces(); |
66 | * @return Interface* NULL if it was unable to be created. | 68 | * @return Interface* NULL if it was unable to be created. |
67 | */ | 69 | */ |
68 | Interface *WLANModule::addNewInterface(QString ){ | 70 | Interface *WLANModule::addNewInterface(QString ){ |
69 | // We can't add a 802.11 interface, either the hardware will be there | 71 | // We can't add a 802.11 interface, either the hardware will be there |
70 | // or it wont. | 72 | // or it wont. |
71 | return NULL; | 73 | return NULL; |
72 | } | 74 | } |
73 | 75 | ||
74 | /** | 76 | /** |
75 | * Attempts to remove the interface, doesn't delete i | 77 | * Attempts to remove the interface, doesn't delete i |
76 | * @return bool true if successfull, false otherwise. | 78 | * @return bool true if successfull, false otherwise. |
77 | */ | 79 | */ |
78 | bool WLANModule::remove(Interface*){ | 80 | bool WLANModule::remove(Interface*){ |
79 | // Can't remove a hardware device, you can stop it though. | 81 | // Can't remove a hardware device, you can stop it though. |
80 | return false; | 82 | return false; |
81 | } | 83 | } |
82 | 84 | ||
83 | // wlanmodule.cpp | 85 | // wlanmodule.cpp |
84 | 86 | ||