summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-10-02 18:52:50 (UTC)
committer benmeyer <benmeyer>2002-10-02 18:52:50 (UTC)
commit56a0a990842a5b57b961c064809aae27f087562d (patch) (unidiff)
treee16ec644bff60c88c710ef6beedc5b033b39624c
parent527e77d8244fb25d0bab39857eebbdfbcbfb807a (diff)
downloadopie-56a0a990842a5b57b961c064809aae27f087562d.zip
opie-56a0a990842a5b57b961c064809aae27f087562d.tar.gz
opie-56a0a990842a5b57b961c064809aae27f087562d.tar.bz2
DHCP works, addProfile works
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interface.cpp16
-rw-r--r--noncore/net/networksetup/mainwindow.ui16
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp73
-rw-r--r--noncore/net/networksetup/networksetup.pro4
-rw-r--r--noncore/settings/networksettings/interface.cpp16
-rw-r--r--noncore/settings/networksettings/mainwindow.ui16
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp73
-rw-r--r--noncore/settings/networksettings/networksetup.pro4
8 files changed, 148 insertions, 70 deletions
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp
index 5b21364..1f32093 100644
--- a/noncore/net/networksetup/interface.cpp
+++ b/noncore/net/networksetup/interface.cpp
@@ -1,236 +1,242 @@
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 <qfileinfo.h> 5#include <qfileinfo.h>
5#include <qtextstream.h> 6#include <qtextstream.h>
6 7
7#define IFCONFIG "/sbin/ifconfig" 8#define IFCONFIG "/sbin/ifconfig"
8#define HDCP_INFO_DIR "/etc/dhcpc" 9#define HDCP_INFO_DIR "/etc/dhcpc"
9 10
10#include <stdio.h> 11#include <stdio.h>
11#include <stdlib.h> 12#include <stdlib.h>
12 13
13Interface::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){ 14Interface::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 refresh(); 15 refresh();
15} 16}
16 17
17/** 18/**
18 * Try to start the interface. 19 * Try to start the interface.
19 * @return bool true if successfull. 20 * @return bool true if successfull.
20 */ 21 */
21bool Interface::start(){ 22bool Interface::start(){
22 // check to see if we are already running. 23 // check to see if we are already running.
23 if(status) 24 if(status)
24 return false; 25 return false;
25 26
26 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); 27 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
27 if(ret != 0) 28 if(ret != 0)
28 return false; 29 return false;
29 30
30 status = true; 31 status = true;
31 refresh(); 32 refresh();
32 return true; 33 return true;
33} 34}
34 35
35/** 36/**
36 * Try to stop the interface. 37 * Try to stop the interface.
37 * @return bool true if successfull. 38 * @return bool true if successfull.
38 */ 39 */
39bool Interface::stop(){ 40bool Interface::stop(){
40 // check to see if we are already stopped. 41 // check to see if we are already stopped.
41 if(status == false) 42 if(status == false)
42 return false; 43 return false;
43 44
44 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); 45 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
45 if(ret != 0) 46 if(ret != 0)
46 return false; 47 return false;
47 48
48 status = true; 49 status = true;
49 refresh(); 50 refresh();
50 return true; 51 return true;
51} 52}
52/** 53/**
53 * Try to restart the interface. 54 * Try to restart the interface.
54 * @return bool true if successfull. 55 * @return bool true if successfull.
55 */ 56 */
56bool Interface::restart(){ 57bool Interface::restart(){
57 return (stop() && start()); 58 return (stop() && start());
58} 59}
59 60
60/** 61/**
61 * Try to refresh the information about the interface. 62 * Try to refresh the information about the interface.
62 * First call ifconfig, then check the dhcp-info file 63 * First call ifconfig, then check the dhcp-info file
63 * @return bool true if successfull. 64 * @return bool true if successfull.
64 */ 65 */
65bool Interface::refresh(){ 66bool Interface::refresh(){
66 // See if we are up. 67 // See if we are up.
67 if(status == false){ 68 if(status == false){
68 macAddress = ""; 69 macAddress = "";
69 ip = "0.0.0.0"; 70 ip = "0.0.0.0";
70 subnetMask = "0.0.0.0"; 71 subnetMask = "0.0.0.0";
71 broadcast = ""; 72 broadcast = "";
72 dhcp = false; 73 dhcp = false;
73 dhcpServerIp = ""; 74 dhcpServerIp = "";
74 leaseObtained = ""; 75 leaseObtained = "";
75 leaseExpires = ""; 76 leaseExpires = "";
76 return true; 77 return true;
77 } 78 }
78 79
79 QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); 80 QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName);
80 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); 81 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1());
81 if(ret != 0){ 82 if(ret != 0){
82 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 83 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
83 return false; 84 return false;
84 } 85 }
85 86
86 QFile file(fileName); 87 QFile file(fileName);
87 if (!file.open(IO_ReadOnly)){ 88 if (!file.open(IO_ReadOnly)){
88 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 89 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
89 return false; 90 return false;
90 } 91 }
91 92
92 // Set to the defaults 93 // Set to the defaults
93 macAddress = ""; 94 macAddress = "";
94 ip = "0.0.0.0"; 95 ip = "0.0.0.0";
95 subnetMask = "0.0.0.0"; 96 subnetMask = "0.0.0.0";
96 broadcast = ""; 97 broadcast = "";
97 98
98 QTextStream stream( &file ); 99 QTextStream stream( &file );
99 QString line; 100 QString line;
100 while ( !stream.eof() ) { 101 while ( !stream.eof() ) {
101 line = stream.readLine(); 102 line = stream.readLine();
102 if(line.contains("HWaddr")){ 103 if(line.contains("HWaddr")){
103 int mac = line.find("HWaddr"); 104 int mac = line.find("HWaddr");
104 macAddress = line.mid(mac+7, line.length()); 105 macAddress = line.mid(mac+7, line.length());
105 } 106 }
106 if(line.contains("inet addr")){ 107 if(line.contains("inet addr")){
107 int ipl = line.find("inet addr"); 108 int ipl = line.find("inet addr");
108 int space = line.find(" ", ipl+10); 109 int space = line.find(" ", ipl+10);
109 ip = line.mid(ipl+10, space-ipl-10); 110 ip = line.mid(ipl+10, space-ipl-10);
110 } 111 }
111 if(line.contains("Mask")){ 112 if(line.contains("Mask")){
112 int mask = line.find("Mask"); 113 int mask = line.find("Mask");
113 subnetMask = line.mid(mask+5, line.length()); 114 subnetMask = line.mid(mask+5, line.length());
114 } 115 }
115 if(line.contains("Bcast")){ 116 if(line.contains("Bcast")){
116 int mask = line.find("Bcast"); 117 int mask = line.find("Bcast");
117 int space = line.find(" ", mask+6); 118 int space = line.find(" ", mask+6);
118 broadcast = line.mid(mask+6, space-mask-6); 119 broadcast = line.mid(mask+6, space-mask-6);
119 } 120 }
120 } 121 }
121 file.close(); 122 file.close();
122 QFile::remove(fileName); 123 QFile::remove(fileName);
123 124
124 // DHCP TESTING 125 // DHCP TESTING
125 // reset DHCP info 126 // reset DHCP info
126 dhcpServerIp = ""; 127 dhcpServerIp = "";
127 leaseObtained = ""; 128 leaseObtained = "";
128 leaseExpires = ""; 129 leaseExpires = "";
129 dhcp = false; 130 dhcp = false;
130 131
132 QString dhcpDirectory(HDCP_INFO_DIR);
133 QDir d(dhcpDirectory);
134 if(!d.exists(dhcpDirectory))
135 dhcpDirectory = "/var/run";
136
131 // See if we have 137 // See if we have
132 QString dhcpFile(QString(HDCP_INFO_DIR "/dhcpcd-%1.info").arg(interfaceName)); 138 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
133 // If there is no DHCP information then exit now with no errors. 139 // If there is no DHCP information then exit now with no errors.
134 if(!QFile::exists(dhcpFile)){ 140 if(!QFile::exists(dhcpFile)){
135 return true; 141 return true;
136 } 142 }
137 143
138 file.setName(dhcpFile); 144 file.setName(dhcpFile);
139 if (!file.open(IO_ReadOnly)){ 145 if (!file.open(IO_ReadOnly)){
140 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 146 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
141 return false; 147 return false;
142 } 148 }
143 149
144 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 150 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
145 int leaseTime = 0; 151 int leaseTime = 0;
146 int renewalTime = 0; 152 int renewalTime = 0;
147 153
148 stream.setDevice( &file ); 154 stream.setDevice( &file );
149 while ( !stream.eof() ) { 155 while ( !stream.eof() ) {
150 line = stream.readLine(); 156 line = stream.readLine();
151 if(line.contains("DHCPSID=")) 157 if(line.contains("DHCPSIADDR="))
152 dhcpServerIp = line.mid(8, line.length()); 158 dhcpServerIp = line.mid(11, line.length());
153 if(line.contains("LEASETIME=")) 159 if(line.contains("LEASETIME="))
154 leaseTime = line.mid(10, line.length()).toInt(); 160 leaseTime = line.mid(10, line.length()).toInt();
155 if(line.contains("RENEWALTIME=")) 161 if(line.contains("RENEWALTIME="))
156 renewalTime = line.mid(12, line.length()).toInt(); 162 renewalTime = line.mid(12, line.length()).toInt();
157 } 163 }
158 file.close(); 164 file.close();
159 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 165 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
160 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 166 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
161 167
162 // Get the pid of the deamond 168 // Get the pid of the deamond
163 dhcpFile = (QString(HDCP_INFO_DIR "/dhcpcd-%1.pid").arg(interfaceName)); 169 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName));
164 file.setName(dhcpFile); 170 file.setName(dhcpFile);
165 if (!file.open(IO_ReadOnly)){ 171 if (!file.open(IO_ReadOnly)){
166 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 172 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
167 return false; 173 return false;
168 } 174 }
169 175
170 int pid = -1; 176 int pid = -1;
171 stream.setDevice( &file ); 177 stream.setDevice( &file );
172 while ( !stream.eof() ) { 178 while ( !stream.eof() ) {
173 line = stream.readLine(); 179 line = stream.readLine();
174 pid = line.toInt(); 180 pid = line.toInt();
175 } 181 }
176 file.close(); 182 file.close();
177 183
178 if( pid == -1){ 184 if( pid == -1){
179 qDebug("Interface: Could not get pid of dhcpc deamon."); 185 qDebug("Interface: Could not get pid of dhcpc deamon.");
180 return false; 186 return false;
181 } 187 }
182 188
183 // Get the start running time of the deamon 189 // Get the start running time of the deamon
184 fileName = (QString("/proc/%1/stat").arg(pid)); 190 fileName = (QString("/proc/%1/stat").arg(pid));
185 file.setName(fileName); 191 file.setName(fileName);
186 stream.setDevice( &file ); 192 stream.setDevice( &file );
187 if (!file.open(IO_ReadOnly)){ 193 if (!file.open(IO_ReadOnly)){
188 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 194 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
189 return false; 195 return false;
190 } 196 }
191 while ( !stream.eof() ) { 197 while ( !stream.eof() ) {
192 line = stream.readLine(); 198 line = stream.readLine();
193 } 199 }
194 file.close(); 200 file.close();
195 long time = 0; 201 long time = 0;
196 // Grab the start time 202 // Grab the start time
197 // pid com state ppid pgrp session tty_nr tpgid flags 203 // pid com state ppid pgrp session tty_nr tpgid flags
198 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 204 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
199 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 205 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
200 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 206 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
201 // nice 0 itrealvalue starttime 207 // nice 0 itrealvalue starttime
202 "%*d %*d %*d %lu", (long*) &time); 208 "%*d %*d %*d %lu", (long*) &time);
203 time = time/100; 209 time = time/100;
204 210
205 QDateTime datetime(QDateTime::currentDateTime()); 211 QDateTime datetime(QDateTime::currentDateTime());
206 212
207 // Get the uptime of the computer. 213 // Get the uptime of the computer.
208 QFile f("/proc/uptime"); 214 QFile f("/proc/uptime");
209 if ( f.open(IO_ReadOnly) ) { // file opened successfully 215 if ( f.open(IO_ReadOnly) ) { // file opened successfully
210 QTextStream t( &f ); // use a text stream 216 QTextStream t( &f ); // use a text stream
211 int sec = 0; 217 int sec = 0;
212 t >> sec; 218 t >> sec;
213 datetime = datetime.addSecs((-1*sec)); 219 datetime = datetime.addSecs((-1*sec));
214 f.close(); 220 f.close();
215 } 221 }
216 else{ 222 else{
217 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 223 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
218 return false; 224 return false;
219 } 225 }
220 226
221 datetime = datetime.addSecs(time); 227 datetime = datetime.addSecs(time);
222 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 228 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
223 229
224 // Calculate the start and renew times 230 // Calculate the start and renew times
225 leaseObtained= datetime.toString(); 231 leaseObtained= datetime.toString();
226 232
227 // Calculate the start and renew times 233 // Calculate the start and renew times
228 datetime = datetime.addSecs(leaseTime); 234 datetime = datetime.addSecs(leaseTime);
229 leaseExpires = datetime.toString(); 235 leaseExpires = datetime.toString();
230 236
231 dhcp = true; 237 dhcp = true;
232 return true; 238 return true;
233} 239}
234 240
235// interface.cpp 241// interface.cpp
236 242
diff --git a/noncore/net/networksetup/mainwindow.ui b/noncore/net/networksetup/mainwindow.ui
index f5b104a..3538aeb 100644
--- a/noncore/net/networksetup/mainwindow.ui
+++ b/noncore/net/networksetup/mainwindow.ui
@@ -1,198 +1,212 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>MainWindow</class> 2<class>MainWindow</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>MainWindow</cstring> 7 <cstring>MainWindow</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>217</width> 14 <width>217</width>
15 <height>289</height> 15 <height>289</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Network Setup</string> 20 <string>Network Setup</string>
21 </property> 21 </property>
22 <vbox> 22 <vbox>
23 <property stdset="1"> 23 <property stdset="1">
24 <name>margin</name> 24 <name>margin</name>
25 <number>0</number> 25 <number>0</number>
26 </property> 26 </property>
27 <property stdset="1"> 27 <property stdset="1">
28 <name>spacing</name> 28 <name>spacing</name>
29 <number>6</number> 29 <number>6</number>
30 </property> 30 </property>
31 <widget> 31 <widget>
32 <class>QTabWidget</class> 32 <class>QTabWidget</class>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>name</name> 34 <name>name</name>
35 <cstring>tabWidget</cstring> 35 <cstring>tabWidget</cstring>
36 </property> 36 </property>
37 <property> 37 <property>
38 <name>layoutMargin</name> 38 <name>layoutMargin</name>
39 </property> 39 </property>
40 <widget> 40 <widget>
41 <class>QWidget</class> 41 <class>QWidget</class>
42 <property stdset="1"> 42 <property stdset="1">
43 <name>name</name> 43 <name>name</name>
44 <cstring>Widget3</cstring> 44 <cstring>Widget3</cstring>
45 </property> 45 </property>
46 <attribute> 46 <attribute>
47 <name>title</name> 47 <name>title</name>
48 <string>Interfaces</string> 48 <string>Connections</string>
49 </attribute> 49 </attribute>
50 <vbox> 50 <vbox>
51 <property stdset="1"> 51 <property stdset="1">
52 <name>margin</name> 52 <name>margin</name>
53 <number>0</number> 53 <number>0</number>
54 </property> 54 </property>
55 <property stdset="1"> 55 <property stdset="1">
56 <name>spacing</name> 56 <name>spacing</name>
57 <number>6</number> 57 <number>6</number>
58 </property> 58 </property>
59 <widget> 59 <widget>
60 <class>QListView</class> 60 <class>QListView</class>
61 <column> 61 <column>
62 <property> 62 <property>
63 <name>text</name> 63 <name>text</name>
64 <string>i</string> 64 <string>i</string>
65 </property> 65 </property>
66 <property> 66 <property>
67 <name>clickable</name> 67 <name>clickable</name>
68 <bool>true</bool> 68 <bool>true</bool>
69 </property> 69 </property>
70 <property> 70 <property>
71 <name>resizeable</name> 71 <name>resizeable</name>
72 <bool>true</bool> 72 <bool>true</bool>
73 </property> 73 </property>
74 </column> 74 </column>
75 <column> 75 <column>
76 <property> 76 <property>
77 <name>text</name> 77 <name>text</name>
78 <string>t</string> 78 <string>t</string>
79 </property> 79 </property>
80 <property> 80 <property>
81 <name>clickable</name> 81 <name>clickable</name>
82 <bool>true</bool> 82 <bool>true</bool>
83 </property> 83 </property>
84 <property> 84 <property>
85 <name>resizeable</name> 85 <name>resizeable</name>
86 <bool>true</bool> 86 <bool>true</bool>
87 </property> 87 </property>
88 </column> 88 </column>
89 <column> 89 <column>
90 <property> 90 <property>
91 <name>text</name> 91 <name>text</name>
92 <string>Name</string> 92 <string>Name</string>
93 </property> 93 </property>
94 <property> 94 <property>
95 <name>clickable</name> 95 <name>clickable</name>
96 <bool>true</bool> 96 <bool>true</bool>
97 </property> 97 </property>
98 <property> 98 <property>
99 <name>resizeable</name> 99 <name>resizeable</name>
100 <bool>true</bool> 100 <bool>true</bool>
101 </property> 101 </property>
102 </column> 102 </column>
103 <column>
104 <property>
105 <name>text</name>
106 <string>IP</string>
107 </property>
108 <property>
109 <name>clickable</name>
110 <bool>true</bool>
111 </property>
112 <property>
113 <name>resizeable</name>
114 <bool>true</bool>
115 </property>
116 </column>
103 <property stdset="1"> 117 <property stdset="1">
104 <name>name</name> 118 <name>name</name>
105 <cstring>connectionList</cstring> 119 <cstring>connectionList</cstring>
106 </property> 120 </property>
107 <property stdset="1"> 121 <property stdset="1">
108 <name>allColumnsShowFocus</name> 122 <name>allColumnsShowFocus</name>
109 <bool>true</bool> 123 <bool>true</bool>
110 </property> 124 </property>
111 </widget> 125 </widget>
112 <widget> 126 <widget>
113 <class>QLayoutWidget</class> 127 <class>QLayoutWidget</class>
114 <property stdset="1"> 128 <property stdset="1">
115 <name>name</name> 129 <name>name</name>
116 <cstring>Layout2</cstring> 130 <cstring>Layout2</cstring>
117 </property> 131 </property>
118 <property> 132 <property>
119 <name>layoutMargin</name> 133 <name>layoutMargin</name>
120 </property> 134 </property>
121 <grid> 135 <grid>
122 <property stdset="1"> 136 <property stdset="1">
123 <name>margin</name> 137 <name>margin</name>
124 <number>5</number> 138 <number>5</number>
125 </property> 139 </property>
126 <property stdset="1"> 140 <property stdset="1">
127 <name>spacing</name> 141 <name>spacing</name>
128 <number>6</number> 142 <number>6</number>
129 </property> 143 </property>
130 <widget row="1" column="0" > 144 <widget row="1" column="0" >
131 <class>QPushButton</class> 145 <class>QPushButton</class>
132 <property stdset="1"> 146 <property stdset="1">
133 <name>name</name> 147 <name>name</name>
134 <cstring>addConnectionButton</cstring> 148 <cstring>addConnectionButton</cstring>
135 </property> 149 </property>
136 <property stdset="1"> 150 <property stdset="1">
137 <name>text</name> 151 <name>text</name>
138 <string>&amp;Add</string> 152 <string>&amp;Add</string>
139 </property> 153 </property>
140 </widget> 154 </widget>
141 <widget row="0" column="0" > 155 <widget row="0" column="0" >
142 <class>QPushButton</class> 156 <class>QPushButton</class>
143 <property stdset="1"> 157 <property stdset="1">
144 <name>name</name> 158 <name>name</name>
145 <cstring>informationConnectionButton</cstring> 159 <cstring>informationConnectionButton</cstring>
146 </property> 160 </property>
147 <property stdset="1"> 161 <property stdset="1">
148 <name>text</name> 162 <name>text</name>
149 <string>&amp;Information</string> 163 <string>&amp;Information</string>
150 </property> 164 </property>
151 </widget> 165 </widget>
152 <widget row="0" column="1" > 166 <widget row="0" column="1" >
153 <class>QPushButton</class> 167 <class>QPushButton</class>
154 <property stdset="1"> 168 <property stdset="1">
155 <name>name</name> 169 <name>name</name>
156 <cstring>configureConnectionButton</cstring> 170 <cstring>configureConnectionButton</cstring>
157 </property> 171 </property>
158 <property stdset="1"> 172 <property stdset="1">
159 <name>text</name> 173 <name>text</name>
160 <string>&amp;Configure</string> 174 <string>&amp;Configure</string>
161 </property> 175 </property>
162 </widget> 176 </widget>
163 <widget row="1" column="1" > 177 <widget row="1" column="1" >
164 <class>QPushButton</class> 178 <class>QPushButton</class>
165 <property stdset="1"> 179 <property stdset="1">
166 <name>name</name> 180 <name>name</name>
167 <cstring>removeConnectionButton</cstring> 181 <cstring>removeConnectionButton</cstring>
168 </property> 182 </property>
169 <property stdset="1"> 183 <property stdset="1">
170 <name>text</name> 184 <name>text</name>
171 <string>&amp;Remove</string> 185 <string>&amp;Remove</string>
172 </property> 186 </property>
173 </widget> 187 </widget>
174 </grid> 188 </grid>
175 </widget> 189 </widget>
176 </vbox> 190 </vbox>
177 </widget> 191 </widget>
178 <widget> 192 <widget>
179 <class>QWidget</class> 193 <class>QWidget</class>
180 <property stdset="1"> 194 <property stdset="1">
181 <name>name</name> 195 <name>name</name>
182 <cstring>tab</cstring> 196 <cstring>tab</cstring>
183 </property> 197 </property>
184 <attribute> 198 <attribute>
185 <name>title</name> 199 <name>title</name>
186 <string>Profiles</string> 200 <string>Profiles</string>
187 </attribute> 201 </attribute>
188 <grid> 202 <grid>
189 <property stdset="1"> 203 <property stdset="1">
190 <name>margin</name> 204 <name>margin</name>
191 <number>11</number> 205 <number>11</number>
192 </property> 206 </property>
193 <property stdset="1"> 207 <property stdset="1">
194 <name>spacing</name> 208 <name>spacing</name>
195 <number>6</number> 209 <number>6</number>
196 </property> 210 </property>
197 <widget row="1" column="0" rowspan="1" colspan="3" > 211 <widget row="1" column="0" rowspan="1" colspan="3" >
198 <class>Line</class> 212 <class>Line</class>
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index 66ec8b5..e9429e3 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -1,403 +1,422 @@
1#include "mainwindowimp.h" 1#include "mainwindowimp.h"
2#include "addconnectionimp.h" 2#include "addconnectionimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4#include "interfacesetupimp.h" 4#include "interfacesetupimp.h"
5#include "module.h" 5#include "module.h"
6 6
7#include "kprocess.h" 7#include "kprocess.h"
8#include "namedialog.h"
8 9
9#include <qpushbutton.h> 10#include <qpushbutton.h>
10#include <qtabwidget.h> 11#include <qtabwidget.h>
11#include <qlistbox.h> 12#include <qlistbox.h>
12#include <qlistview.h> 13#include <qlistview.h>
13#include <qheader.h> 14#include <qheader.h>
14#include <qlabel.h> 15#include <qlabel.h>
15 16
16#include <qmainwindow.h> 17#include <qmainwindow.h>
17#include <qmessagebox.h> 18#include <qmessagebox.h>
18 19
19#include <qpe/config.h> 20#include <qpe/config.h>
20#include <qpe/qlibrary.h> 21#include <qpe/qlibrary.h>
21#include <qpe/resource.h> 22#include <qpe/resource.h>
22 23
23#include <qlist.h> 24#include <qlist.h>
24#include <qdir.h> 25#include <qdir.h>
25#include <qfile.h> 26#include <qfile.h>
26#include <qtextstream.h> 27#include <qtextstream.h>
27 28
28#define TEMP_ALL "/tmp/ifconfig-a" 29#define TEMP_ALL "/tmp/ifconfig-a"
29#define TEMP_UP "/tmp/ifconfig" 30#define TEMP_UP "/tmp/ifconfig"
30 31
31MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ 32MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
32 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 33 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
33 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 34 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
34 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 35 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
35 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 36 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
36 37
37 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 38 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
38 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 39 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
39 connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); 40 connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&)));
40 41
41 // Load connections. 42 // Load connections.
42 loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); 43 loadModules(QDir::homeDirPath() + "/.networksetup/plugins");
43 getInterfaceList(); 44 getInterfaceList();
44 connectionList->header()->hide(); 45 connectionList->header()->hide();
45 46
46 47
47 Config cfg("NetworkSetup"); 48 Config cfg("NetworkSetup");
48 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 49 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
49 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 50 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
50 profilesList->insertItem((*it)); 51 profilesList->insertItem((*it));
51 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 52 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
52} 53}
53 54
54/** 55/**
55 * Deconstructor. Save profiles. Delete loaded libraries. 56 * Deconstructor. Save profiles. Delete loaded libraries.
56 */ 57 */
57MainWindowImp::~MainWindowImp(){ 58MainWindowImp::~MainWindowImp(){
58 // Save profiles. 59 // Save profiles.
59 if(profiles.count() > 1){ 60 if(profiles.count() > 1){
60 Config cfg("NetworkSetup"); 61 Config cfg("NetworkSetup");
61 cfg.writeEntry("Profiles", profiles.join(" ")); 62 cfg.writeEntry("Profiles", profiles.join(" "));
62 } 63 }
63 // Delete Modules and Libraries 64 // Delete Modules and Libraries
64 QMap<Module*, QLibrary*>::Iterator it; 65 QMap<Module*, QLibrary*>::Iterator it;
65 for( it = libraries.begin(); it != libraries.end(); ++it ){ 66 for( it = libraries.begin(); it != libraries.end(); ++it ){
66 delete it.key(); 67 delete it.key();
67 delete it.data(); 68 delete it.data();
68 } 69 }
69} 70}
70 71
71/** 72/**
72 * Load all modules that are found in the path 73 * Load all modules that are found in the path
73 * @param path a directory that is scaned for any plugins that can be loaded 74 * @param path a directory that is scaned for any plugins that can be loaded
74 * and attempts to load them 75 * and attempts to load them
75 */ 76 */
76void MainWindowImp::loadModules(QString path){ 77void MainWindowImp::loadModules(QString path){
77 qDebug(path.latin1()); 78 qDebug(path.latin1());
78 QDir d(path); 79 QDir d(path);
79 if(!d.exists()) 80 if(!d.exists())
80 return; 81 return;
81 82
82 // Don't want sym links 83 // Don't want sym links
83 d.setFilter( QDir::Files | QDir::NoSymLinks ); 84 d.setFilter( QDir::Files | QDir::NoSymLinks );
84 const QFileInfoList *list = d.entryInfoList(); 85 const QFileInfoList *list = d.entryInfoList();
85 QFileInfoListIterator it( *list ); 86 QFileInfoListIterator it( *list );
86 QFileInfo *fi; 87 QFileInfo *fi;
87 while ( (fi=it.current()) ) { 88 while ( (fi=it.current()) ) {
88 if(fi->fileName().contains(".so")){ 89 if(fi->fileName().contains(".so")){
89 loadPlugin(path + "/" + fi->fileName()); 90 loadPlugin(path + "/" + fi->fileName());
90 } 91 }
91 ++it; 92 ++it;
92 } 93 }
93} 94}
94 95
95/** 96/**
96 * Attempt to load a function and resolve a function. 97 * Attempt to load a function and resolve a function.
97 * @param pluginFileName - the name of the file in which to attempt to load 98 * @param pluginFileName - the name of the file in which to attempt to load
98 * @param resolveString - function pointer to resolve 99 * @param resolveString - function pointer to resolve
99 * @return pointer to the function with name resolveString or NULL 100 * @return pointer to the function with name resolveString or NULL
100 */ 101 */
101Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ 102Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
102 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 103 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
103 QLibrary *lib = new QLibrary(pluginFileName); 104 QLibrary *lib = new QLibrary(pluginFileName);
104 void *functionPointer = lib->resolve(resolveString); 105 void *functionPointer = lib->resolve(resolveString);
105 if( !functionPointer ){ 106 if( !functionPointer ){
106 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 107 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
107 delete lib; 108 delete lib;
108 return NULL; 109 return NULL;
109 } 110 }
110 111
111 // Try to get an object. 112 // Try to get an object.
112 Module *object = ((Module* (*)()) functionPointer)(); 113 Module *object = ((Module* (*)()) functionPointer)();
113 if(object == NULL){ 114 if(object == NULL){
114 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 115 qDebug("MainWindowImp: Couldn't create object, but did load library!");
115 delete lib; 116 delete lib;
116 return NULL; 117 return NULL;
117 } 118 }
118 119
119 // Store for deletion later 120 // Store for deletion later
120 libraries.insert(object, lib); 121 libraries.insert(object, lib);
121 return object; 122 return object;
122} 123}
123 124
124/** 125/**
125 * The Add button was clicked. Bring up the add dialog and if OK is hit 126 * The Add button was clicked. Bring up the add dialog and if OK is hit
126 * load the plugin and append it to the list 127 * load the plugin and append it to the list
127 */ 128 */
128void MainWindowImp::addClicked(){ 129void MainWindowImp::addClicked(){
129 QMap<Module*, QLibrary*>::Iterator it; 130 QMap<Module*, QLibrary*>::Iterator it;
130 QMap<QString, QString> list; 131 QMap<QString, QString> list;
132 QMap<QString, Module*> newInterfaceOwners;
131 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 133 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
132 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 134 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
133 for( it = libraries.begin(); it != libraries.end(); ++it ){ 135 for( it = libraries.begin(); it != libraries.end(); ++it ){
134 if(it.key()) 136 if(it.key()){
135 (it.key())->possibleNewInterfaces(list); 137 (it.key())->possibleNewInterfaces(list);
138 }
136 } 139 }
137 // See if the list has anything that we can add. 140 // See if the list has anything that we can add.
138 if(list.count() == 0){ 141 if(list.count() == 0){
139 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); 142 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
140 return; 143 return;
141 } 144 }
142 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 145 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
143 addNewConnection.addConnections(list); 146 addNewConnection.addConnections(list);
144 addNewConnection.showMaximized(); 147 addNewConnection.showMaximized();
145 if(QDialog::Accepted == addNewConnection.exec()){ 148 if(QDialog::Accepted == addNewConnection.exec()){
146 149 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
150 if(!item)
151 return;
152
153 for( it = libraries.begin(); it != libraries.end(); ++it ){
154 if(it.key()){
155 Interface *i = (it.key())->addNewInterface(item->text(0));
156 if(i){
157 interfaceNames.insert(i->getInterfaceName(), i);
158 updateInterface(i);
159 }
160 }
161 }
147 } 162 }
148} 163}
149 164
150/** 165/**
151 * Prompt the user to see if they really want to do this. 166 * Prompt the user to see if they really want to do this.
152 * If they do then remove from the list and unload. 167 * If they do then remove from the list and unload.
153 */ 168 */
154void MainWindowImp::removeClicked(){ 169void MainWindowImp::removeClicked(){
155 QListViewItem *item = connectionList->currentItem(); 170 QListViewItem *item = connectionList->currentItem();
156 if(item == NULL) { 171 if(!item) {
157 QMessageBox::information(this, "Error","Please select an interface.", "Ok"); 172 QMessageBox::information(this, "Error","Please select an interface.", "Ok");
158 return; 173 return;
159 } 174 }
160 175
161 if((interfaceItems[item])->getModuleOwner() == NULL){ 176 Interface *i = interfaceItems[item];
177 if(i->getModuleOwner() == NULL){
162 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); 178 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
163 } 179 }
164 else{ 180 else{
165 // Try to remove. 181 if(!i->getModuleOwner()->remove(i))
182 QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
183 else{
184 QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
185 // TODO memory managment....
186 // who deletes the interface?
187 }
166 } 188 }
167
168} 189}
169 190
170/** 191/**
171 * Pull up the configure about the currently selected interface. 192 * Pull up the configure about the currently selected interface.
172 * Report an error if no interface is selected. 193 * Report an error if no interface is selected.
173 * If the interface has a module owner then request its configure with a empty 194 * If the interface has a module owner then request its configure with a empty
174 * tab. If tab is !NULL then append the interfaces setup widget to it. 195 * tab. If tab is !NULL then append the interfaces setup widget to it.
175 */ 196 */
176void MainWindowImp::configureClicked(){ 197void MainWindowImp::configureClicked(){
177 QListViewItem *item = connectionList->currentItem(); 198 QListViewItem *item = connectionList->currentItem();
178 if(!item){ 199 if(!item){
179 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 200 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
180 return; 201 return;
181 } 202 }
182 203
183 Interface *i = interfaceItems[item]; 204 Interface *i = interfaceItems[item];
184 if(i->getModuleOwner()){ 205 if(i->getModuleOwner()){
185 QTabWidget *tabWidget = NULL; 206 QTabWidget *tabWidget = NULL;
186 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 207 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
187 if(moduleConfigure != NULL){ 208 if(moduleConfigure != NULL){
188 if(tabWidget != NULL){ 209 if(tabWidget != NULL){
189 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 210 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
190 tabWidget->insertTab(configure, "TCP/IP"); 211 tabWidget->insertTab(configure, "TCP/IP");
191 } 212 }
192 moduleConfigure->showMaximized(); 213 moduleConfigure->showMaximized();
193 moduleConfigure->show(); 214 moduleConfigure->show();
194 return; 215 return;
195 } 216 }
196 } 217 }
197 218
198 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 219 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
199 configure->showMaximized(); 220 configure->showMaximized();
200 configure->show(); 221 configure->show();
201} 222}
202 223
203/** 224/**
204 * Pull up the information about the currently selected interface. 225 * Pull up the information about the currently selected interface.
205 * Report an error if no interface is selected. 226 * Report an error if no interface is selected.
206 * If the interface has a module owner then request its configure with a empty 227 * If the interface has a module owner then request its configure with a empty
207 * tab. If tab is !NULL then append the interfaces setup widget to it. 228 * tab. If tab is !NULL then append the interfaces setup widget to it.
208 */ 229 */
209void MainWindowImp::informationClicked(){ 230void MainWindowImp::informationClicked(){
210 QListViewItem *item = connectionList->currentItem(); 231 QListViewItem *item = connectionList->currentItem();
211 if(!item){ 232 if(!item){
212 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 233 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
213 return; 234 return;
214 } 235 }
215 236
216 Interface *i = interfaceItems[item]; 237 Interface *i = interfaceItems[item];
217 if(i->getModuleOwner()){ 238 if(i->getModuleOwner()){
218 QTabWidget *tabWidget = NULL; 239 QTabWidget *tabWidget = NULL;
219 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 240 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
220 if(moduleInformation != NULL){ 241 if(moduleInformation != NULL){
221 if(tabWidget != NULL){ 242 if(tabWidget != NULL){
222 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 243 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
223 tabWidget->insertTab(information, "TCP/IP"); 244 tabWidget->insertTab(information, "TCP/IP");
224 } 245 }
225 moduleInformation->showMaximized(); 246 moduleInformation->showMaximized();
226 moduleInformation->show(); 247 moduleInformation->show();
227 return; 248 return;
228 } 249 }
229 } 250 }
230 251
231 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 252 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
232 information->showMaximized(); 253 information->showMaximized();
233 information->show(); 254 information->show();
234} 255}
235 256
236/** 257/**
237 * Aquire the list of active interfaces from ifconfig 258 * Aquire the list of active interfaces from ifconfig
238 * Call ifconfig and ifconfig -a 259 * Call ifconfig and ifconfig -a
239 */ 260 */
240void MainWindowImp::getInterfaceList(){ 261void MainWindowImp::getInterfaceList(){
241 KShellProcess *processAll = new KShellProcess(); 262 KShellProcess *processAll = new KShellProcess();
242 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 263 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
243 connect(processAll, SIGNAL(processExited(KProcess *)), 264 connect(processAll, SIGNAL(processExited(KProcess *)),
244 this, SLOT(jobDone(KProcess *))); 265 this, SLOT(jobDone(KProcess *)));
245 threads.insert(processAll, TEMP_ALL); 266 threads.insert(processAll, TEMP_ALL);
246 processAll->start(KShellProcess::NotifyOnExit); 267 processAll->start(KShellProcess::NotifyOnExit);
247 268
248 KShellProcess *process = new KShellProcess(); 269 KShellProcess *process = new KShellProcess();
249 *process << "/sbin/ifconfig" << " > " TEMP_UP; 270 *process << "/sbin/ifconfig" << " > " TEMP_UP;
250 connect(process, SIGNAL(processExited(KProcess *)), 271 connect(process, SIGNAL(processExited(KProcess *)),
251 this, SLOT(jobDone(KProcess *))); 272 this, SLOT(jobDone(KProcess *)));
252 threads.insert(process, TEMP_UP); 273 threads.insert(process, TEMP_UP);
253 process->start(KShellProcess::NotifyOnExit); 274 process->start(KShellProcess::NotifyOnExit);
254} 275}
255 276
256void MainWindowImp::jobDone(KProcess *process){ 277void MainWindowImp::jobDone(KProcess *process){
257 QString fileName = threads[process]; 278 QString fileName = threads[process];
258 threads.remove(process); 279 threads.remove(process);
259 delete process; 280 delete process;
260 281
261 QFile file(fileName); 282 QFile file(fileName);
262 if (!file.open(IO_ReadOnly)){ 283 if (!file.open(IO_ReadOnly)){
263 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 284 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
264 return; 285 return;
265 } 286 }
266 287
267 QTextStream stream( &file ); 288 QTextStream stream( &file );
268 QString line; 289 QString line;
269 while ( !stream.eof() ) { 290 while ( !stream.eof() ) {
270 line = stream.readLine(); 291 line = stream.readLine();
271 int space = line.find(" "); 292 int space = line.find(" ");
272 if(space > 1){ 293 if(space > 1){
273 // We have found an interface 294 // We have found an interface
274 QString interfaceName = line.mid(0, space); 295 QString interfaceName = line.mid(0, space);
275 if(!advancedUserMode){ 296 if(!advancedUserMode){
276 if(interfaceName == "lo") 297 if(interfaceName == "lo")
277 break; 298 break;
278 } 299 }
279 Interface *i; 300 Interface *i;
280 // See if we already have it 301 // See if we already have it
281 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 302 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
282 if(fileName == TEMP_ALL) 303 if(fileName == TEMP_ALL)
283 i = new Interface(interfaceName, false); 304 i = new Interface(interfaceName, false);
284 else 305 else
285 i = new Interface(interfaceName, true); 306 i = new Interface(interfaceName, true);
286 } 307 }
287 else{ 308 else{
288 i = interfaceNames[interfaceName]; 309 i = interfaceNames[interfaceName];
289 if(fileName != TEMP_ALL) 310 if(fileName != TEMP_ALL)
290 i->setStatus(true); 311 i->setStatus(true);
291 } 312 }
292 313
293 i->setAttached(true); 314 i->setAttached(true);
294 i->setInterfaceName(interfaceName); 315 i->setInterfaceName(interfaceName);
295 316
296 QString hardName = "Ethernet"; 317 QString hardName = "Ethernet";
297 int hardwareName = line.find("Link encap:"); 318 int hardwareName = line.find("Link encap:");
298 int macAddress = line.find("HWaddr"); 319 int macAddress = line.find("HWaddr");
299 if(macAddress == -1) 320 if(macAddress == -1)
300 macAddress = line.length(); 321 macAddress = line.length();
301 if(hardwareName != -1) 322 if(hardwareName != -1)
302 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
303 // We have found an interface 324 // We have found an interface
304 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 325 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
305 interfaceNames.insert(i->getInterfaceName(), i); 326 interfaceNames.insert(i->getInterfaceName(), i);
306 updateInterface(i); 327 updateInterface(i);
307 } 328 }
308 } 329 }
309 file.close(); 330 file.close();
310 QFile::remove(fileName); 331 QFile::remove(fileName);
311} 332}
312 333
313/** 334/**
314 * 335 * Update this interface. If no QListViewItem exists create one.
336 * @param Interface* pointer to the interface that needs to be updated.
315 */ 337 */
316void MainWindowImp::updateInterface(Interface *i){ 338void MainWindowImp::updateInterface(Interface *i){
317 QListViewItem *item = NULL; 339 QListViewItem *item = NULL;
318 340
319 // See if we already have it 341 // Find the interface, making it if needed.
320 if(items.find(i) == items.end()){ 342 if(items.find(i) == items.end()){
321 item = new QListViewItem(connectionList, "", "", ""); 343 item = new QListViewItem(connectionList, "", "", "");
322 // See if you can't find a module owner for this interface 344 // See if you can't find a module owner for this interface
323 QMap<Module*, QLibrary*>::Iterator it; 345 QMap<Module*, QLibrary*>::Iterator it;
324 for( it = libraries.begin(); it != libraries.end(); ++it ){ 346 for( it = libraries.begin(); it != libraries.end(); ++it ){
325 if(it.key()->isOwner(i)) 347 if(it.key()->isOwner(i))
326 i->setModuleOwner(it.key()); 348 i->setModuleOwner(it.key());
327 } 349 }
328
329 items.insert(i, item); 350 items.insert(i, item);
330 interfaceItems.insert(item, i); 351 interfaceItems.insert(item, i);
331 } 352 }
332 else 353 else
333 item = items[i]; 354 item = items[i];
334 355
335 QString statusImage = "down"; 356 // Update the icons and information
336 if(i->getStatus()) 357 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
337 statusImage = "up";
338 QPixmap status = (Resource::loadPixmap(statusImage));
339 item->setPixmap(0, status);
340 358
341 QString typeName = "lan"; 359 QString typeName = "lan";
342 if(i->getHardwareName().contains("Local Loopback")) 360 if(i->getHardwareName().contains("Local Loopback"))
343 typeName = "lo"; 361 typeName = "lo";
344 if(i->getInterfaceName().contains("irda")) 362 if(i->getInterfaceName().contains("irda"))
345 typeName = "irda"; 363 typeName = "irda";
346 if(i->getInterfaceName().contains("wlan")) 364 if(i->getInterfaceName().contains("wlan"))
347 typeName = "wlan"; 365 typeName = "wlan";
348 // Actually try to use the Module 366 // Actually try to use the Module
349 if(i->getModuleOwner() != NULL){ 367 if(i->getModuleOwner() != NULL)
350 typeName = i->getModuleOwner()->getPixmapName(i); 368 typeName = i->getModuleOwner()->getPixmapName(i);
351 }
352 QPixmap type = (Resource::loadPixmap(typeName));
353 item->setPixmap(1, type);
354
355 item->setText(2, i->getHardwareName());
356 369
370 item->setPixmap(1, (Resource::loadPixmap(typeName)));
371 item->setText(2, i->getHardwareName());
372 item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
357} 373}
358 374
359/** 375/**
360 * Adds a new profile to the list of profiles. 376 * Adds a new profile to the list of profiles.
361 * Don't add profiles that already exists. 377 * Don't add profiles that already exists.
362 * Appends to the combo and QStringList 378 * Appends to the list and QStringList
363 */ 379 */
364void MainWindowImp::addProfile(){ 380void MainWindowImp::addProfile(){
365 QString newProfileName = "New"; 381 NameDialog foo(this, "namedialog", true);
382 QString newProfileName = foo.go();
383 if(newProfileName.length() == 0)
384 return;
385
366 if(profiles.grep(newProfileName).count() > 0){ 386 if(profiles.grep(newProfileName).count() > 0){
367 QMessageBox::information(this, "Can't Add.","Profile already exists.", "Ok"); 387 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
368 return; 388 return;
369 } 389 }
370 profiles.append(newProfileName); 390 profiles.append(newProfileName);
371 profilesList->insertItem(newProfileName); 391 profilesList->insertItem(newProfileName);
372
373} 392}
374 393
375/** 394/**
376 * Removes the currently selected profile in the combo. 395 * Removes the currently selected profile in the combo.
377 * Doesn't delete if there are less then 2 profiles. 396 * Doesn't delete if there are less then 2 profiles.
378 */ 397 */
379void MainWindowImp::removeProfile(){ 398void MainWindowImp::removeProfile(){
380 if(profilesList->count() <= 1){ 399 if(profilesList->count() <= 1){
381 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 400 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
382 return; 401 return;
383 } 402 }
384 QString profileToRemove = profilesList->currentText(); 403 QString profileToRemove = profilesList->currentText();
385 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 404 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
386 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 405 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
387 profilesList->clear(); 406 profilesList->clear();
388 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 407 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
389 profilesList->insertItem((*it)); 408 profilesList->insertItem((*it));
390 } 409 }
391 410
392} 411}
393 412
394/** 413/**
395 * A new profile has been selected, change. 414 * A new profile has been selected, change.
396 * @param newProfile the new profile. 415 * @param newProfile the new profile.
397 */ 416 */
398void MainWindowImp::changeProfile(const QString& newProfile){ 417void MainWindowImp::changeProfile(const QString& newProfile){
399 currentProfileLabel->setText(newProfile); 418 currentProfileLabel->setText(newProfile);
400} 419}
401 420
402// mainwindowimp.cpp 421// mainwindowimp.cpp
403 422
diff --git a/noncore/net/networksetup/networksetup.pro b/noncore/net/networksetup/networksetup.pro
index ba70180..e146eb4 100644
--- a/noncore/net/networksetup/networksetup.pro
+++ b/noncore/net/networksetup/networksetup.pro
@@ -1,10 +1,10 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 #CONFIG = qt warn_on debug 2 #CONFIG = qt warn_on debug
3 CONFIG = qt warn_on release 3 CONFIG = qt warn_on release
4 HEADERS = mainwindowimp.h addconnectionimp.h interface.h interfaceinformationimp.h interfacesetupimp.h interfaces.h defaultmodule.h kprocctrl.h module.h kprocess.h 4 HEADERS = mainwindowimp.h addconnectionimp.h interface.h interfaceinformationimp.h interfacesetupimp.h interfaces.h defaultmodule.h kprocctrl.h module.h kprocess.h namedialog.h
5 SOURCES = main.cpp mainwindowimp.cpp addconnectionimp.cpp interface.cpp interfaceinformationimp.cpp interfacesetupimp.cpp kprocctrl.cpp kprocess.cpp interfaces.cpp 5 SOURCES = main.cpp namedialog.cpp mainwindowimp.cpp addconnectionimp.cpp interface.cpp interfaceinformationimp.cpp interfacesetupimp.cpp kprocctrl.cpp kprocess.cpp interfaces.cpp
6 #INCLUDEPATH+= $(QPEDIR)/include 6 #INCLUDEPATH+= $(QPEDIR)/include
7 #DEPENDPATH+= $(QPEDIR)/include 7 #DEPENDPATH+= $(QPEDIR)/include
8LIBS += -lqpe 8LIBS += -lqpe
9 INTERFACES= mainwindow.ui addconnection.ui interfaceinformation.ui interfaceadvanced.ui interfacesetup.ui 9 INTERFACES= mainwindow.ui addconnection.ui interfaceinformation.ui interfaceadvanced.ui interfacesetup.ui
10 TARGET = networksetup 10 TARGET = networksetup
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp
index 5b21364..1f32093 100644
--- a/noncore/settings/networksettings/interface.cpp
+++ b/noncore/settings/networksettings/interface.cpp
@@ -1,236 +1,242 @@
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 <qfileinfo.h> 5#include <qfileinfo.h>
5#include <qtextstream.h> 6#include <qtextstream.h>
6 7
7#define IFCONFIG "/sbin/ifconfig" 8#define IFCONFIG "/sbin/ifconfig"
8#define HDCP_INFO_DIR "/etc/dhcpc" 9#define HDCP_INFO_DIR "/etc/dhcpc"
9 10
10#include <stdio.h> 11#include <stdio.h>
11#include <stdlib.h> 12#include <stdlib.h>
12 13
13Interface::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){ 14Interface::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 refresh(); 15 refresh();
15} 16}
16 17
17/** 18/**
18 * Try to start the interface. 19 * Try to start the interface.
19 * @return bool true if successfull. 20 * @return bool true if successfull.
20 */ 21 */
21bool Interface::start(){ 22bool Interface::start(){
22 // check to see if we are already running. 23 // check to see if we are already running.
23 if(status) 24 if(status)
24 return false; 25 return false;
25 26
26 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); 27 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
27 if(ret != 0) 28 if(ret != 0)
28 return false; 29 return false;
29 30
30 status = true; 31 status = true;
31 refresh(); 32 refresh();
32 return true; 33 return true;
33} 34}
34 35
35/** 36/**
36 * Try to stop the interface. 37 * Try to stop the interface.
37 * @return bool true if successfull. 38 * @return bool true if successfull.
38 */ 39 */
39bool Interface::stop(){ 40bool Interface::stop(){
40 // check to see if we are already stopped. 41 // check to see if we are already stopped.
41 if(status == false) 42 if(status == false)
42 return false; 43 return false;
43 44
44 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); 45 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
45 if(ret != 0) 46 if(ret != 0)
46 return false; 47 return false;
47 48
48 status = true; 49 status = true;
49 refresh(); 50 refresh();
50 return true; 51 return true;
51} 52}
52/** 53/**
53 * Try to restart the interface. 54 * Try to restart the interface.
54 * @return bool true if successfull. 55 * @return bool true if successfull.
55 */ 56 */
56bool Interface::restart(){ 57bool Interface::restart(){
57 return (stop() && start()); 58 return (stop() && start());
58} 59}
59 60
60/** 61/**
61 * Try to refresh the information about the interface. 62 * Try to refresh the information about the interface.
62 * First call ifconfig, then check the dhcp-info file 63 * First call ifconfig, then check the dhcp-info file
63 * @return bool true if successfull. 64 * @return bool true if successfull.
64 */ 65 */
65bool Interface::refresh(){ 66bool Interface::refresh(){
66 // See if we are up. 67 // See if we are up.
67 if(status == false){ 68 if(status == false){
68 macAddress = ""; 69 macAddress = "";
69 ip = "0.0.0.0"; 70 ip = "0.0.0.0";
70 subnetMask = "0.0.0.0"; 71 subnetMask = "0.0.0.0";
71 broadcast = ""; 72 broadcast = "";
72 dhcp = false; 73 dhcp = false;
73 dhcpServerIp = ""; 74 dhcpServerIp = "";
74 leaseObtained = ""; 75 leaseObtained = "";
75 leaseExpires = ""; 76 leaseExpires = "";
76 return true; 77 return true;
77 } 78 }
78 79
79 QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); 80 QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName);
80 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); 81 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1());
81 if(ret != 0){ 82 if(ret != 0){
82 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 83 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
83 return false; 84 return false;
84 } 85 }
85 86
86 QFile file(fileName); 87 QFile file(fileName);
87 if (!file.open(IO_ReadOnly)){ 88 if (!file.open(IO_ReadOnly)){
88 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 89 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
89 return false; 90 return false;
90 } 91 }
91 92
92 // Set to the defaults 93 // Set to the defaults
93 macAddress = ""; 94 macAddress = "";
94 ip = "0.0.0.0"; 95 ip = "0.0.0.0";
95 subnetMask = "0.0.0.0"; 96 subnetMask = "0.0.0.0";
96 broadcast = ""; 97 broadcast = "";
97 98
98 QTextStream stream( &file ); 99 QTextStream stream( &file );
99 QString line; 100 QString line;
100 while ( !stream.eof() ) { 101 while ( !stream.eof() ) {
101 line = stream.readLine(); 102 line = stream.readLine();
102 if(line.contains("HWaddr")){ 103 if(line.contains("HWaddr")){
103 int mac = line.find("HWaddr"); 104 int mac = line.find("HWaddr");
104 macAddress = line.mid(mac+7, line.length()); 105 macAddress = line.mid(mac+7, line.length());
105 } 106 }
106 if(line.contains("inet addr")){ 107 if(line.contains("inet addr")){
107 int ipl = line.find("inet addr"); 108 int ipl = line.find("inet addr");
108 int space = line.find(" ", ipl+10); 109 int space = line.find(" ", ipl+10);
109 ip = line.mid(ipl+10, space-ipl-10); 110 ip = line.mid(ipl+10, space-ipl-10);
110 } 111 }
111 if(line.contains("Mask")){ 112 if(line.contains("Mask")){
112 int mask = line.find("Mask"); 113 int mask = line.find("Mask");
113 subnetMask = line.mid(mask+5, line.length()); 114 subnetMask = line.mid(mask+5, line.length());
114 } 115 }
115 if(line.contains("Bcast")){ 116 if(line.contains("Bcast")){
116 int mask = line.find("Bcast"); 117 int mask = line.find("Bcast");
117 int space = line.find(" ", mask+6); 118 int space = line.find(" ", mask+6);
118 broadcast = line.mid(mask+6, space-mask-6); 119 broadcast = line.mid(mask+6, space-mask-6);
119 } 120 }
120 } 121 }
121 file.close(); 122 file.close();
122 QFile::remove(fileName); 123 QFile::remove(fileName);
123 124
124 // DHCP TESTING 125 // DHCP TESTING
125 // reset DHCP info 126 // reset DHCP info
126 dhcpServerIp = ""; 127 dhcpServerIp = "";
127 leaseObtained = ""; 128 leaseObtained = "";
128 leaseExpires = ""; 129 leaseExpires = "";
129 dhcp = false; 130 dhcp = false;
130 131
132 QString dhcpDirectory(HDCP_INFO_DIR);
133 QDir d(dhcpDirectory);
134 if(!d.exists(dhcpDirectory))
135 dhcpDirectory = "/var/run";
136
131 // See if we have 137 // See if we have
132 QString dhcpFile(QString(HDCP_INFO_DIR "/dhcpcd-%1.info").arg(interfaceName)); 138 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
133 // If there is no DHCP information then exit now with no errors. 139 // If there is no DHCP information then exit now with no errors.
134 if(!QFile::exists(dhcpFile)){ 140 if(!QFile::exists(dhcpFile)){
135 return true; 141 return true;
136 } 142 }
137 143
138 file.setName(dhcpFile); 144 file.setName(dhcpFile);
139 if (!file.open(IO_ReadOnly)){ 145 if (!file.open(IO_ReadOnly)){
140 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 146 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
141 return false; 147 return false;
142 } 148 }
143 149
144 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 150 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
145 int leaseTime = 0; 151 int leaseTime = 0;
146 int renewalTime = 0; 152 int renewalTime = 0;
147 153
148 stream.setDevice( &file ); 154 stream.setDevice( &file );
149 while ( !stream.eof() ) { 155 while ( !stream.eof() ) {
150 line = stream.readLine(); 156 line = stream.readLine();
151 if(line.contains("DHCPSID=")) 157 if(line.contains("DHCPSIADDR="))
152 dhcpServerIp = line.mid(8, line.length()); 158 dhcpServerIp = line.mid(11, line.length());
153 if(line.contains("LEASETIME=")) 159 if(line.contains("LEASETIME="))
154 leaseTime = line.mid(10, line.length()).toInt(); 160 leaseTime = line.mid(10, line.length()).toInt();
155 if(line.contains("RENEWALTIME=")) 161 if(line.contains("RENEWALTIME="))
156 renewalTime = line.mid(12, line.length()).toInt(); 162 renewalTime = line.mid(12, line.length()).toInt();
157 } 163 }
158 file.close(); 164 file.close();
159 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 165 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
160 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 166 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
161 167
162 // Get the pid of the deamond 168 // Get the pid of the deamond
163 dhcpFile = (QString(HDCP_INFO_DIR "/dhcpcd-%1.pid").arg(interfaceName)); 169 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName));
164 file.setName(dhcpFile); 170 file.setName(dhcpFile);
165 if (!file.open(IO_ReadOnly)){ 171 if (!file.open(IO_ReadOnly)){
166 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 172 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
167 return false; 173 return false;
168 } 174 }
169 175
170 int pid = -1; 176 int pid = -1;
171 stream.setDevice( &file ); 177 stream.setDevice( &file );
172 while ( !stream.eof() ) { 178 while ( !stream.eof() ) {
173 line = stream.readLine(); 179 line = stream.readLine();
174 pid = line.toInt(); 180 pid = line.toInt();
175 } 181 }
176 file.close(); 182 file.close();
177 183
178 if( pid == -1){ 184 if( pid == -1){
179 qDebug("Interface: Could not get pid of dhcpc deamon."); 185 qDebug("Interface: Could not get pid of dhcpc deamon.");
180 return false; 186 return false;
181 } 187 }
182 188
183 // Get the start running time of the deamon 189 // Get the start running time of the deamon
184 fileName = (QString("/proc/%1/stat").arg(pid)); 190 fileName = (QString("/proc/%1/stat").arg(pid));
185 file.setName(fileName); 191 file.setName(fileName);
186 stream.setDevice( &file ); 192 stream.setDevice( &file );
187 if (!file.open(IO_ReadOnly)){ 193 if (!file.open(IO_ReadOnly)){
188 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 194 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
189 return false; 195 return false;
190 } 196 }
191 while ( !stream.eof() ) { 197 while ( !stream.eof() ) {
192 line = stream.readLine(); 198 line = stream.readLine();
193 } 199 }
194 file.close(); 200 file.close();
195 long time = 0; 201 long time = 0;
196 // Grab the start time 202 // Grab the start time
197 // pid com state ppid pgrp session tty_nr tpgid flags 203 // pid com state ppid pgrp session tty_nr tpgid flags
198 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 204 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
199 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 205 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
200 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 206 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
201 // nice 0 itrealvalue starttime 207 // nice 0 itrealvalue starttime
202 "%*d %*d %*d %lu", (long*) &time); 208 "%*d %*d %*d %lu", (long*) &time);
203 time = time/100; 209 time = time/100;
204 210
205 QDateTime datetime(QDateTime::currentDateTime()); 211 QDateTime datetime(QDateTime::currentDateTime());
206 212
207 // Get the uptime of the computer. 213 // Get the uptime of the computer.
208 QFile f("/proc/uptime"); 214 QFile f("/proc/uptime");
209 if ( f.open(IO_ReadOnly) ) { // file opened successfully 215 if ( f.open(IO_ReadOnly) ) { // file opened successfully
210 QTextStream t( &f ); // use a text stream 216 QTextStream t( &f ); // use a text stream
211 int sec = 0; 217 int sec = 0;
212 t >> sec; 218 t >> sec;
213 datetime = datetime.addSecs((-1*sec)); 219 datetime = datetime.addSecs((-1*sec));
214 f.close(); 220 f.close();
215 } 221 }
216 else{ 222 else{
217 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 223 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
218 return false; 224 return false;
219 } 225 }
220 226
221 datetime = datetime.addSecs(time); 227 datetime = datetime.addSecs(time);
222 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 228 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
223 229
224 // Calculate the start and renew times 230 // Calculate the start and renew times
225 leaseObtained= datetime.toString(); 231 leaseObtained= datetime.toString();
226 232
227 // Calculate the start and renew times 233 // Calculate the start and renew times
228 datetime = datetime.addSecs(leaseTime); 234 datetime = datetime.addSecs(leaseTime);
229 leaseExpires = datetime.toString(); 235 leaseExpires = datetime.toString();
230 236
231 dhcp = true; 237 dhcp = true;
232 return true; 238 return true;
233} 239}
234 240
235// interface.cpp 241// interface.cpp
236 242
diff --git a/noncore/settings/networksettings/mainwindow.ui b/noncore/settings/networksettings/mainwindow.ui
index f5b104a..3538aeb 100644
--- a/noncore/settings/networksettings/mainwindow.ui
+++ b/noncore/settings/networksettings/mainwindow.ui
@@ -1,198 +1,212 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>MainWindow</class> 2<class>MainWindow</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>MainWindow</cstring> 7 <cstring>MainWindow</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>217</width> 14 <width>217</width>
15 <height>289</height> 15 <height>289</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Network Setup</string> 20 <string>Network Setup</string>
21 </property> 21 </property>
22 <vbox> 22 <vbox>
23 <property stdset="1"> 23 <property stdset="1">
24 <name>margin</name> 24 <name>margin</name>
25 <number>0</number> 25 <number>0</number>
26 </property> 26 </property>
27 <property stdset="1"> 27 <property stdset="1">
28 <name>spacing</name> 28 <name>spacing</name>
29 <number>6</number> 29 <number>6</number>
30 </property> 30 </property>
31 <widget> 31 <widget>
32 <class>QTabWidget</class> 32 <class>QTabWidget</class>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>name</name> 34 <name>name</name>
35 <cstring>tabWidget</cstring> 35 <cstring>tabWidget</cstring>
36 </property> 36 </property>
37 <property> 37 <property>
38 <name>layoutMargin</name> 38 <name>layoutMargin</name>
39 </property> 39 </property>
40 <widget> 40 <widget>
41 <class>QWidget</class> 41 <class>QWidget</class>
42 <property stdset="1"> 42 <property stdset="1">
43 <name>name</name> 43 <name>name</name>
44 <cstring>Widget3</cstring> 44 <cstring>Widget3</cstring>
45 </property> 45 </property>
46 <attribute> 46 <attribute>
47 <name>title</name> 47 <name>title</name>
48 <string>Interfaces</string> 48 <string>Connections</string>
49 </attribute> 49 </attribute>
50 <vbox> 50 <vbox>
51 <property stdset="1"> 51 <property stdset="1">
52 <name>margin</name> 52 <name>margin</name>
53 <number>0</number> 53 <number>0</number>
54 </property> 54 </property>
55 <property stdset="1"> 55 <property stdset="1">
56 <name>spacing</name> 56 <name>spacing</name>
57 <number>6</number> 57 <number>6</number>
58 </property> 58 </property>
59 <widget> 59 <widget>
60 <class>QListView</class> 60 <class>QListView</class>
61 <column> 61 <column>
62 <property> 62 <property>
63 <name>text</name> 63 <name>text</name>
64 <string>i</string> 64 <string>i</string>
65 </property> 65 </property>
66 <property> 66 <property>
67 <name>clickable</name> 67 <name>clickable</name>
68 <bool>true</bool> 68 <bool>true</bool>
69 </property> 69 </property>
70 <property> 70 <property>
71 <name>resizeable</name> 71 <name>resizeable</name>
72 <bool>true</bool> 72 <bool>true</bool>
73 </property> 73 </property>
74 </column> 74 </column>
75 <column> 75 <column>
76 <property> 76 <property>
77 <name>text</name> 77 <name>text</name>
78 <string>t</string> 78 <string>t</string>
79 </property> 79 </property>
80 <property> 80 <property>
81 <name>clickable</name> 81 <name>clickable</name>
82 <bool>true</bool> 82 <bool>true</bool>
83 </property> 83 </property>
84 <property> 84 <property>
85 <name>resizeable</name> 85 <name>resizeable</name>
86 <bool>true</bool> 86 <bool>true</bool>
87 </property> 87 </property>
88 </column> 88 </column>
89 <column> 89 <column>
90 <property> 90 <property>
91 <name>text</name> 91 <name>text</name>
92 <string>Name</string> 92 <string>Name</string>
93 </property> 93 </property>
94 <property> 94 <property>
95 <name>clickable</name> 95 <name>clickable</name>
96 <bool>true</bool> 96 <bool>true</bool>
97 </property> 97 </property>
98 <property> 98 <property>
99 <name>resizeable</name> 99 <name>resizeable</name>
100 <bool>true</bool> 100 <bool>true</bool>
101 </property> 101 </property>
102 </column> 102 </column>
103 <column>
104 <property>
105 <name>text</name>
106 <string>IP</string>
107 </property>
108 <property>
109 <name>clickable</name>
110 <bool>true</bool>
111 </property>
112 <property>
113 <name>resizeable</name>
114 <bool>true</bool>
115 </property>
116 </column>
103 <property stdset="1"> 117 <property stdset="1">
104 <name>name</name> 118 <name>name</name>
105 <cstring>connectionList</cstring> 119 <cstring>connectionList</cstring>
106 </property> 120 </property>
107 <property stdset="1"> 121 <property stdset="1">
108 <name>allColumnsShowFocus</name> 122 <name>allColumnsShowFocus</name>
109 <bool>true</bool> 123 <bool>true</bool>
110 </property> 124 </property>
111 </widget> 125 </widget>
112 <widget> 126 <widget>
113 <class>QLayoutWidget</class> 127 <class>QLayoutWidget</class>
114 <property stdset="1"> 128 <property stdset="1">
115 <name>name</name> 129 <name>name</name>
116 <cstring>Layout2</cstring> 130 <cstring>Layout2</cstring>
117 </property> 131 </property>
118 <property> 132 <property>
119 <name>layoutMargin</name> 133 <name>layoutMargin</name>
120 </property> 134 </property>
121 <grid> 135 <grid>
122 <property stdset="1"> 136 <property stdset="1">
123 <name>margin</name> 137 <name>margin</name>
124 <number>5</number> 138 <number>5</number>
125 </property> 139 </property>
126 <property stdset="1"> 140 <property stdset="1">
127 <name>spacing</name> 141 <name>spacing</name>
128 <number>6</number> 142 <number>6</number>
129 </property> 143 </property>
130 <widget row="1" column="0" > 144 <widget row="1" column="0" >
131 <class>QPushButton</class> 145 <class>QPushButton</class>
132 <property stdset="1"> 146 <property stdset="1">
133 <name>name</name> 147 <name>name</name>
134 <cstring>addConnectionButton</cstring> 148 <cstring>addConnectionButton</cstring>
135 </property> 149 </property>
136 <property stdset="1"> 150 <property stdset="1">
137 <name>text</name> 151 <name>text</name>
138 <string>&amp;Add</string> 152 <string>&amp;Add</string>
139 </property> 153 </property>
140 </widget> 154 </widget>
141 <widget row="0" column="0" > 155 <widget row="0" column="0" >
142 <class>QPushButton</class> 156 <class>QPushButton</class>
143 <property stdset="1"> 157 <property stdset="1">
144 <name>name</name> 158 <name>name</name>
145 <cstring>informationConnectionButton</cstring> 159 <cstring>informationConnectionButton</cstring>
146 </property> 160 </property>
147 <property stdset="1"> 161 <property stdset="1">
148 <name>text</name> 162 <name>text</name>
149 <string>&amp;Information</string> 163 <string>&amp;Information</string>
150 </property> 164 </property>
151 </widget> 165 </widget>
152 <widget row="0" column="1" > 166 <widget row="0" column="1" >
153 <class>QPushButton</class> 167 <class>QPushButton</class>
154 <property stdset="1"> 168 <property stdset="1">
155 <name>name</name> 169 <name>name</name>
156 <cstring>configureConnectionButton</cstring> 170 <cstring>configureConnectionButton</cstring>
157 </property> 171 </property>
158 <property stdset="1"> 172 <property stdset="1">
159 <name>text</name> 173 <name>text</name>
160 <string>&amp;Configure</string> 174 <string>&amp;Configure</string>
161 </property> 175 </property>
162 </widget> 176 </widget>
163 <widget row="1" column="1" > 177 <widget row="1" column="1" >
164 <class>QPushButton</class> 178 <class>QPushButton</class>
165 <property stdset="1"> 179 <property stdset="1">
166 <name>name</name> 180 <name>name</name>
167 <cstring>removeConnectionButton</cstring> 181 <cstring>removeConnectionButton</cstring>
168 </property> 182 </property>
169 <property stdset="1"> 183 <property stdset="1">
170 <name>text</name> 184 <name>text</name>
171 <string>&amp;Remove</string> 185 <string>&amp;Remove</string>
172 </property> 186 </property>
173 </widget> 187 </widget>
174 </grid> 188 </grid>
175 </widget> 189 </widget>
176 </vbox> 190 </vbox>
177 </widget> 191 </widget>
178 <widget> 192 <widget>
179 <class>QWidget</class> 193 <class>QWidget</class>
180 <property stdset="1"> 194 <property stdset="1">
181 <name>name</name> 195 <name>name</name>
182 <cstring>tab</cstring> 196 <cstring>tab</cstring>
183 </property> 197 </property>
184 <attribute> 198 <attribute>
185 <name>title</name> 199 <name>title</name>
186 <string>Profiles</string> 200 <string>Profiles</string>
187 </attribute> 201 </attribute>
188 <grid> 202 <grid>
189 <property stdset="1"> 203 <property stdset="1">
190 <name>margin</name> 204 <name>margin</name>
191 <number>11</number> 205 <number>11</number>
192 </property> 206 </property>
193 <property stdset="1"> 207 <property stdset="1">
194 <name>spacing</name> 208 <name>spacing</name>
195 <number>6</number> 209 <number>6</number>
196 </property> 210 </property>
197 <widget row="1" column="0" rowspan="1" colspan="3" > 211 <widget row="1" column="0" rowspan="1" colspan="3" >
198 <class>Line</class> 212 <class>Line</class>
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 66ec8b5..e9429e3 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,403 +1,422 @@
1#include "mainwindowimp.h" 1#include "mainwindowimp.h"
2#include "addconnectionimp.h" 2#include "addconnectionimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4#include "interfacesetupimp.h" 4#include "interfacesetupimp.h"
5#include "module.h" 5#include "module.h"
6 6
7#include "kprocess.h" 7#include "kprocess.h"
8#include "namedialog.h"
8 9
9#include <qpushbutton.h> 10#include <qpushbutton.h>
10#include <qtabwidget.h> 11#include <qtabwidget.h>
11#include <qlistbox.h> 12#include <qlistbox.h>
12#include <qlistview.h> 13#include <qlistview.h>
13#include <qheader.h> 14#include <qheader.h>
14#include <qlabel.h> 15#include <qlabel.h>
15 16
16#include <qmainwindow.h> 17#include <qmainwindow.h>
17#include <qmessagebox.h> 18#include <qmessagebox.h>
18 19
19#include <qpe/config.h> 20#include <qpe/config.h>
20#include <qpe/qlibrary.h> 21#include <qpe/qlibrary.h>
21#include <qpe/resource.h> 22#include <qpe/resource.h>
22 23
23#include <qlist.h> 24#include <qlist.h>
24#include <qdir.h> 25#include <qdir.h>
25#include <qfile.h> 26#include <qfile.h>
26#include <qtextstream.h> 27#include <qtextstream.h>
27 28
28#define TEMP_ALL "/tmp/ifconfig-a" 29#define TEMP_ALL "/tmp/ifconfig-a"
29#define TEMP_UP "/tmp/ifconfig" 30#define TEMP_UP "/tmp/ifconfig"
30 31
31MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ 32MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
32 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 33 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
33 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 34 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
34 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 35 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
35 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 36 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
36 37
37 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 38 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
38 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 39 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
39 connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); 40 connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&)));
40 41
41 // Load connections. 42 // Load connections.
42 loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); 43 loadModules(QDir::homeDirPath() + "/.networksetup/plugins");
43 getInterfaceList(); 44 getInterfaceList();
44 connectionList->header()->hide(); 45 connectionList->header()->hide();
45 46
46 47
47 Config cfg("NetworkSetup"); 48 Config cfg("NetworkSetup");
48 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 49 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
49 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 50 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
50 profilesList->insertItem((*it)); 51 profilesList->insertItem((*it));
51 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 52 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
52} 53}
53 54
54/** 55/**
55 * Deconstructor. Save profiles. Delete loaded libraries. 56 * Deconstructor. Save profiles. Delete loaded libraries.
56 */ 57 */
57MainWindowImp::~MainWindowImp(){ 58MainWindowImp::~MainWindowImp(){
58 // Save profiles. 59 // Save profiles.
59 if(profiles.count() > 1){ 60 if(profiles.count() > 1){
60 Config cfg("NetworkSetup"); 61 Config cfg("NetworkSetup");
61 cfg.writeEntry("Profiles", profiles.join(" ")); 62 cfg.writeEntry("Profiles", profiles.join(" "));
62 } 63 }
63 // Delete Modules and Libraries 64 // Delete Modules and Libraries
64 QMap<Module*, QLibrary*>::Iterator it; 65 QMap<Module*, QLibrary*>::Iterator it;
65 for( it = libraries.begin(); it != libraries.end(); ++it ){ 66 for( it = libraries.begin(); it != libraries.end(); ++it ){
66 delete it.key(); 67 delete it.key();
67 delete it.data(); 68 delete it.data();
68 } 69 }
69} 70}
70 71
71/** 72/**
72 * Load all modules that are found in the path 73 * Load all modules that are found in the path
73 * @param path a directory that is scaned for any plugins that can be loaded 74 * @param path a directory that is scaned for any plugins that can be loaded
74 * and attempts to load them 75 * and attempts to load them
75 */ 76 */
76void MainWindowImp::loadModules(QString path){ 77void MainWindowImp::loadModules(QString path){
77 qDebug(path.latin1()); 78 qDebug(path.latin1());
78 QDir d(path); 79 QDir d(path);
79 if(!d.exists()) 80 if(!d.exists())
80 return; 81 return;
81 82
82 // Don't want sym links 83 // Don't want sym links
83 d.setFilter( QDir::Files | QDir::NoSymLinks ); 84 d.setFilter( QDir::Files | QDir::NoSymLinks );
84 const QFileInfoList *list = d.entryInfoList(); 85 const QFileInfoList *list = d.entryInfoList();
85 QFileInfoListIterator it( *list ); 86 QFileInfoListIterator it( *list );
86 QFileInfo *fi; 87 QFileInfo *fi;
87 while ( (fi=it.current()) ) { 88 while ( (fi=it.current()) ) {
88 if(fi->fileName().contains(".so")){ 89 if(fi->fileName().contains(".so")){
89 loadPlugin(path + "/" + fi->fileName()); 90 loadPlugin(path + "/" + fi->fileName());
90 } 91 }
91 ++it; 92 ++it;
92 } 93 }
93} 94}
94 95
95/** 96/**
96 * Attempt to load a function and resolve a function. 97 * Attempt to load a function and resolve a function.
97 * @param pluginFileName - the name of the file in which to attempt to load 98 * @param pluginFileName - the name of the file in which to attempt to load
98 * @param resolveString - function pointer to resolve 99 * @param resolveString - function pointer to resolve
99 * @return pointer to the function with name resolveString or NULL 100 * @return pointer to the function with name resolveString or NULL
100 */ 101 */
101Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ 102Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
102 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 103 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
103 QLibrary *lib = new QLibrary(pluginFileName); 104 QLibrary *lib = new QLibrary(pluginFileName);
104 void *functionPointer = lib->resolve(resolveString); 105 void *functionPointer = lib->resolve(resolveString);
105 if( !functionPointer ){ 106 if( !functionPointer ){
106 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 107 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
107 delete lib; 108 delete lib;
108 return NULL; 109 return NULL;
109 } 110 }
110 111
111 // Try to get an object. 112 // Try to get an object.
112 Module *object = ((Module* (*)()) functionPointer)(); 113 Module *object = ((Module* (*)()) functionPointer)();
113 if(object == NULL){ 114 if(object == NULL){
114 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 115 qDebug("MainWindowImp: Couldn't create object, but did load library!");
115 delete lib; 116 delete lib;
116 return NULL; 117 return NULL;
117 } 118 }
118 119
119 // Store for deletion later 120 // Store for deletion later
120 libraries.insert(object, lib); 121 libraries.insert(object, lib);
121 return object; 122 return object;
122} 123}
123 124
124/** 125/**
125 * The Add button was clicked. Bring up the add dialog and if OK is hit 126 * The Add button was clicked. Bring up the add dialog and if OK is hit
126 * load the plugin and append it to the list 127 * load the plugin and append it to the list
127 */ 128 */
128void MainWindowImp::addClicked(){ 129void MainWindowImp::addClicked(){
129 QMap<Module*, QLibrary*>::Iterator it; 130 QMap<Module*, QLibrary*>::Iterator it;
130 QMap<QString, QString> list; 131 QMap<QString, QString> list;
132 QMap<QString, Module*> newInterfaceOwners;
131 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 133 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
132 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 134 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
133 for( it = libraries.begin(); it != libraries.end(); ++it ){ 135 for( it = libraries.begin(); it != libraries.end(); ++it ){
134 if(it.key()) 136 if(it.key()){
135 (it.key())->possibleNewInterfaces(list); 137 (it.key())->possibleNewInterfaces(list);
138 }
136 } 139 }
137 // See if the list has anything that we can add. 140 // See if the list has anything that we can add.
138 if(list.count() == 0){ 141 if(list.count() == 0){
139 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); 142 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
140 return; 143 return;
141 } 144 }
142 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 145 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
143 addNewConnection.addConnections(list); 146 addNewConnection.addConnections(list);
144 addNewConnection.showMaximized(); 147 addNewConnection.showMaximized();
145 if(QDialog::Accepted == addNewConnection.exec()){ 148 if(QDialog::Accepted == addNewConnection.exec()){
146 149 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
150 if(!item)
151 return;
152
153 for( it = libraries.begin(); it != libraries.end(); ++it ){
154 if(it.key()){
155 Interface *i = (it.key())->addNewInterface(item->text(0));
156 if(i){
157 interfaceNames.insert(i->getInterfaceName(), i);
158 updateInterface(i);
159 }
160 }
161 }
147 } 162 }
148} 163}
149 164
150/** 165/**
151 * Prompt the user to see if they really want to do this. 166 * Prompt the user to see if they really want to do this.
152 * If they do then remove from the list and unload. 167 * If they do then remove from the list and unload.
153 */ 168 */
154void MainWindowImp::removeClicked(){ 169void MainWindowImp::removeClicked(){
155 QListViewItem *item = connectionList->currentItem(); 170 QListViewItem *item = connectionList->currentItem();
156 if(item == NULL) { 171 if(!item) {
157 QMessageBox::information(this, "Error","Please select an interface.", "Ok"); 172 QMessageBox::information(this, "Error","Please select an interface.", "Ok");
158 return; 173 return;
159 } 174 }
160 175
161 if((interfaceItems[item])->getModuleOwner() == NULL){ 176 Interface *i = interfaceItems[item];
177 if(i->getModuleOwner() == NULL){
162 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); 178 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
163 } 179 }
164 else{ 180 else{
165 // Try to remove. 181 if(!i->getModuleOwner()->remove(i))
182 QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
183 else{
184 QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
185 // TODO memory managment....
186 // who deletes the interface?
187 }
166 } 188 }
167
168} 189}
169 190
170/** 191/**
171 * Pull up the configure about the currently selected interface. 192 * Pull up the configure about the currently selected interface.
172 * Report an error if no interface is selected. 193 * Report an error if no interface is selected.
173 * If the interface has a module owner then request its configure with a empty 194 * If the interface has a module owner then request its configure with a empty
174 * tab. If tab is !NULL then append the interfaces setup widget to it. 195 * tab. If tab is !NULL then append the interfaces setup widget to it.
175 */ 196 */
176void MainWindowImp::configureClicked(){ 197void MainWindowImp::configureClicked(){
177 QListViewItem *item = connectionList->currentItem(); 198 QListViewItem *item = connectionList->currentItem();
178 if(!item){ 199 if(!item){
179 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 200 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
180 return; 201 return;
181 } 202 }
182 203
183 Interface *i = interfaceItems[item]; 204 Interface *i = interfaceItems[item];
184 if(i->getModuleOwner()){ 205 if(i->getModuleOwner()){
185 QTabWidget *tabWidget = NULL; 206 QTabWidget *tabWidget = NULL;
186 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 207 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
187 if(moduleConfigure != NULL){ 208 if(moduleConfigure != NULL){
188 if(tabWidget != NULL){ 209 if(tabWidget != NULL){
189 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 210 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
190 tabWidget->insertTab(configure, "TCP/IP"); 211 tabWidget->insertTab(configure, "TCP/IP");
191 } 212 }
192 moduleConfigure->showMaximized(); 213 moduleConfigure->showMaximized();
193 moduleConfigure->show(); 214 moduleConfigure->show();
194 return; 215 return;
195 } 216 }
196 } 217 }
197 218
198 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 219 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
199 configure->showMaximized(); 220 configure->showMaximized();
200 configure->show(); 221 configure->show();
201} 222}
202 223
203/** 224/**
204 * Pull up the information about the currently selected interface. 225 * Pull up the information about the currently selected interface.
205 * Report an error if no interface is selected. 226 * Report an error if no interface is selected.
206 * If the interface has a module owner then request its configure with a empty 227 * If the interface has a module owner then request its configure with a empty
207 * tab. If tab is !NULL then append the interfaces setup widget to it. 228 * tab. If tab is !NULL then append the interfaces setup widget to it.
208 */ 229 */
209void MainWindowImp::informationClicked(){ 230void MainWindowImp::informationClicked(){
210 QListViewItem *item = connectionList->currentItem(); 231 QListViewItem *item = connectionList->currentItem();
211 if(!item){ 232 if(!item){
212 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 233 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
213 return; 234 return;
214 } 235 }
215 236
216 Interface *i = interfaceItems[item]; 237 Interface *i = interfaceItems[item];
217 if(i->getModuleOwner()){ 238 if(i->getModuleOwner()){
218 QTabWidget *tabWidget = NULL; 239 QTabWidget *tabWidget = NULL;
219 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 240 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
220 if(moduleInformation != NULL){ 241 if(moduleInformation != NULL){
221 if(tabWidget != NULL){ 242 if(tabWidget != NULL){
222 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 243 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
223 tabWidget->insertTab(information, "TCP/IP"); 244 tabWidget->insertTab(information, "TCP/IP");
224 } 245 }
225 moduleInformation->showMaximized(); 246 moduleInformation->showMaximized();
226 moduleInformation->show(); 247 moduleInformation->show();
227 return; 248 return;
228 } 249 }
229 } 250 }
230 251
231 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 252 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
232 information->showMaximized(); 253 information->showMaximized();
233 information->show(); 254 information->show();
234} 255}
235 256
236/** 257/**
237 * Aquire the list of active interfaces from ifconfig 258 * Aquire the list of active interfaces from ifconfig
238 * Call ifconfig and ifconfig -a 259 * Call ifconfig and ifconfig -a
239 */ 260 */
240void MainWindowImp::getInterfaceList(){ 261void MainWindowImp::getInterfaceList(){
241 KShellProcess *processAll = new KShellProcess(); 262 KShellProcess *processAll = new KShellProcess();
242 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 263 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
243 connect(processAll, SIGNAL(processExited(KProcess *)), 264 connect(processAll, SIGNAL(processExited(KProcess *)),
244 this, SLOT(jobDone(KProcess *))); 265 this, SLOT(jobDone(KProcess *)));
245 threads.insert(processAll, TEMP_ALL); 266 threads.insert(processAll, TEMP_ALL);
246 processAll->start(KShellProcess::NotifyOnExit); 267 processAll->start(KShellProcess::NotifyOnExit);
247 268
248 KShellProcess *process = new KShellProcess(); 269 KShellProcess *process = new KShellProcess();
249 *process << "/sbin/ifconfig" << " > " TEMP_UP; 270 *process << "/sbin/ifconfig" << " > " TEMP_UP;
250 connect(process, SIGNAL(processExited(KProcess *)), 271 connect(process, SIGNAL(processExited(KProcess *)),
251 this, SLOT(jobDone(KProcess *))); 272 this, SLOT(jobDone(KProcess *)));
252 threads.insert(process, TEMP_UP); 273 threads.insert(process, TEMP_UP);
253 process->start(KShellProcess::NotifyOnExit); 274 process->start(KShellProcess::NotifyOnExit);
254} 275}
255 276
256void MainWindowImp::jobDone(KProcess *process){ 277void MainWindowImp::jobDone(KProcess *process){
257 QString fileName = threads[process]; 278 QString fileName = threads[process];
258 threads.remove(process); 279 threads.remove(process);
259 delete process; 280 delete process;
260 281
261 QFile file(fileName); 282 QFile file(fileName);
262 if (!file.open(IO_ReadOnly)){ 283 if (!file.open(IO_ReadOnly)){
263 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 284 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
264 return; 285 return;
265 } 286 }
266 287
267 QTextStream stream( &file ); 288 QTextStream stream( &file );
268 QString line; 289 QString line;
269 while ( !stream.eof() ) { 290 while ( !stream.eof() ) {
270 line = stream.readLine(); 291 line = stream.readLine();
271 int space = line.find(" "); 292 int space = line.find(" ");
272 if(space > 1){ 293 if(space > 1){
273 // We have found an interface 294 // We have found an interface
274 QString interfaceName = line.mid(0, space); 295 QString interfaceName = line.mid(0, space);
275 if(!advancedUserMode){ 296 if(!advancedUserMode){
276 if(interfaceName == "lo") 297 if(interfaceName == "lo")
277 break; 298 break;
278 } 299 }
279 Interface *i; 300 Interface *i;
280 // See if we already have it 301 // See if we already have it
281 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 302 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
282 if(fileName == TEMP_ALL) 303 if(fileName == TEMP_ALL)
283 i = new Interface(interfaceName, false); 304 i = new Interface(interfaceName, false);
284 else 305 else
285 i = new Interface(interfaceName, true); 306 i = new Interface(interfaceName, true);
286 } 307 }
287 else{ 308 else{
288 i = interfaceNames[interfaceName]; 309 i = interfaceNames[interfaceName];
289 if(fileName != TEMP_ALL) 310 if(fileName != TEMP_ALL)
290 i->setStatus(true); 311 i->setStatus(true);
291 } 312 }
292 313
293 i->setAttached(true); 314 i->setAttached(true);
294 i->setInterfaceName(interfaceName); 315 i->setInterfaceName(interfaceName);
295 316
296 QString hardName = "Ethernet"; 317 QString hardName = "Ethernet";
297 int hardwareName = line.find("Link encap:"); 318 int hardwareName = line.find("Link encap:");
298 int macAddress = line.find("HWaddr"); 319 int macAddress = line.find("HWaddr");
299 if(macAddress == -1) 320 if(macAddress == -1)
300 macAddress = line.length(); 321 macAddress = line.length();
301 if(hardwareName != -1) 322 if(hardwareName != -1)
302 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
303 // We have found an interface 324 // We have found an interface
304 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 325 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
305 interfaceNames.insert(i->getInterfaceName(), i); 326 interfaceNames.insert(i->getInterfaceName(), i);
306 updateInterface(i); 327 updateInterface(i);
307 } 328 }
308 } 329 }
309 file.close(); 330 file.close();
310 QFile::remove(fileName); 331 QFile::remove(fileName);
311} 332}
312 333
313/** 334/**
314 * 335 * Update this interface. If no QListViewItem exists create one.
336 * @param Interface* pointer to the interface that needs to be updated.
315 */ 337 */
316void MainWindowImp::updateInterface(Interface *i){ 338void MainWindowImp::updateInterface(Interface *i){
317 QListViewItem *item = NULL; 339 QListViewItem *item = NULL;
318 340
319 // See if we already have it 341 // Find the interface, making it if needed.
320 if(items.find(i) == items.end()){ 342 if(items.find(i) == items.end()){
321 item = new QListViewItem(connectionList, "", "", ""); 343 item = new QListViewItem(connectionList, "", "", "");
322 // See if you can't find a module owner for this interface 344 // See if you can't find a module owner for this interface
323 QMap<Module*, QLibrary*>::Iterator it; 345 QMap<Module*, QLibrary*>::Iterator it;
324 for( it = libraries.begin(); it != libraries.end(); ++it ){ 346 for( it = libraries.begin(); it != libraries.end(); ++it ){
325 if(it.key()->isOwner(i)) 347 if(it.key()->isOwner(i))
326 i->setModuleOwner(it.key()); 348 i->setModuleOwner(it.key());
327 } 349 }
328
329 items.insert(i, item); 350 items.insert(i, item);
330 interfaceItems.insert(item, i); 351 interfaceItems.insert(item, i);
331 } 352 }
332 else 353 else
333 item = items[i]; 354 item = items[i];
334 355
335 QString statusImage = "down"; 356 // Update the icons and information
336 if(i->getStatus()) 357 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
337 statusImage = "up";
338 QPixmap status = (Resource::loadPixmap(statusImage));
339 item->setPixmap(0, status);
340 358
341 QString typeName = "lan"; 359 QString typeName = "lan";
342 if(i->getHardwareName().contains("Local Loopback")) 360 if(i->getHardwareName().contains("Local Loopback"))
343 typeName = "lo"; 361 typeName = "lo";
344 if(i->getInterfaceName().contains("irda")) 362 if(i->getInterfaceName().contains("irda"))
345 typeName = "irda"; 363 typeName = "irda";
346 if(i->getInterfaceName().contains("wlan")) 364 if(i->getInterfaceName().contains("wlan"))
347 typeName = "wlan"; 365 typeName = "wlan";
348 // Actually try to use the Module 366 // Actually try to use the Module
349 if(i->getModuleOwner() != NULL){ 367 if(i->getModuleOwner() != NULL)
350 typeName = i->getModuleOwner()->getPixmapName(i); 368 typeName = i->getModuleOwner()->getPixmapName(i);
351 }
352 QPixmap type = (Resource::loadPixmap(typeName));
353 item->setPixmap(1, type);
354
355 item->setText(2, i->getHardwareName());
356 369
370 item->setPixmap(1, (Resource::loadPixmap(typeName)));
371 item->setText(2, i->getHardwareName());
372 item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
357} 373}
358 374
359/** 375/**
360 * Adds a new profile to the list of profiles. 376 * Adds a new profile to the list of profiles.
361 * Don't add profiles that already exists. 377 * Don't add profiles that already exists.
362 * Appends to the combo and QStringList 378 * Appends to the list and QStringList
363 */ 379 */
364void MainWindowImp::addProfile(){ 380void MainWindowImp::addProfile(){
365 QString newProfileName = "New"; 381 NameDialog foo(this, "namedialog", true);
382 QString newProfileName = foo.go();
383 if(newProfileName.length() == 0)
384 return;
385
366 if(profiles.grep(newProfileName).count() > 0){ 386 if(profiles.grep(newProfileName).count() > 0){
367 QMessageBox::information(this, "Can't Add.","Profile already exists.", "Ok"); 387 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
368 return; 388 return;
369 } 389 }
370 profiles.append(newProfileName); 390 profiles.append(newProfileName);
371 profilesList->insertItem(newProfileName); 391 profilesList->insertItem(newProfileName);
372
373} 392}
374 393
375/** 394/**
376 * Removes the currently selected profile in the combo. 395 * Removes the currently selected profile in the combo.
377 * Doesn't delete if there are less then 2 profiles. 396 * Doesn't delete if there are less then 2 profiles.
378 */ 397 */
379void MainWindowImp::removeProfile(){ 398void MainWindowImp::removeProfile(){
380 if(profilesList->count() <= 1){ 399 if(profilesList->count() <= 1){
381 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 400 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
382 return; 401 return;
383 } 402 }
384 QString profileToRemove = profilesList->currentText(); 403 QString profileToRemove = profilesList->currentText();
385 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 404 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
386 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 405 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
387 profilesList->clear(); 406 profilesList->clear();
388 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 407 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
389 profilesList->insertItem((*it)); 408 profilesList->insertItem((*it));
390 } 409 }
391 410
392} 411}
393 412
394/** 413/**
395 * A new profile has been selected, change. 414 * A new profile has been selected, change.
396 * @param newProfile the new profile. 415 * @param newProfile the new profile.
397 */ 416 */
398void MainWindowImp::changeProfile(const QString& newProfile){ 417void MainWindowImp::changeProfile(const QString& newProfile){
399 currentProfileLabel->setText(newProfile); 418 currentProfileLabel->setText(newProfile);
400} 419}
401 420
402// mainwindowimp.cpp 421// mainwindowimp.cpp
403 422
diff --git a/noncore/settings/networksettings/networksetup.pro b/noncore/settings/networksettings/networksetup.pro
index ba70180..e146eb4 100644
--- a/noncore/settings/networksettings/networksetup.pro
+++ b/noncore/settings/networksettings/networksetup.pro
@@ -1,10 +1,10 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 #CONFIG = qt warn_on debug 2 #CONFIG = qt warn_on debug
3 CONFIG = qt warn_on release 3 CONFIG = qt warn_on release
4 HEADERS = mainwindowimp.h addconnectionimp.h interface.h interfaceinformationimp.h interfacesetupimp.h interfaces.h defaultmodule.h kprocctrl.h module.h kprocess.h 4 HEADERS = mainwindowimp.h addconnectionimp.h interface.h interfaceinformationimp.h interfacesetupimp.h interfaces.h defaultmodule.h kprocctrl.h module.h kprocess.h namedialog.h
5 SOURCES = main.cpp mainwindowimp.cpp addconnectionimp.cpp interface.cpp interfaceinformationimp.cpp interfacesetupimp.cpp kprocctrl.cpp kprocess.cpp interfaces.cpp 5 SOURCES = main.cpp namedialog.cpp mainwindowimp.cpp addconnectionimp.cpp interface.cpp interfaceinformationimp.cpp interfacesetupimp.cpp kprocctrl.cpp kprocess.cpp interfaces.cpp
6 #INCLUDEPATH+= $(QPEDIR)/include 6 #INCLUDEPATH+= $(QPEDIR)/include
7 #DEPENDPATH+= $(QPEDIR)/include 7 #DEPENDPATH+= $(QPEDIR)/include
8LIBS += -lqpe 8LIBS += -lqpe
9 INTERFACES= mainwindow.ui addconnection.ui interfaceinformation.ui interfaceadvanced.ui interfacesetup.ui 9 INTERFACES= mainwindow.ui addconnection.ui interfaceinformation.ui interfaceadvanced.ui interfacesetup.ui
10 TARGET = networksetup 10 TARGET = networksetup