58 files changed, 11642 insertions, 0 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO new file mode 100644 index 0000000..9a1657a --- a/dev/null +++ b/noncore/net/networksetup/TODO | |||
@@ -0,0 +1 @@ | |||
Fix DHCP obtained and expoired info | |||
diff --git a/noncore/net/networksetup/addservice.ui b/noncore/net/networksetup/addservice.ui new file mode 100644 index 0000000..929f4fb --- a/dev/null +++ b/noncore/net/networksetup/addservice.ui | |||
@@ -0,0 +1,154 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>AddService</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>AddService</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>245</width> | ||
15 | <height>268</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Add Network Service</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="3" column="1" > | ||
32 | <class>QPushButton</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>cancelButton</cstring> | ||
36 | </property> | ||
37 | <property stdset="1"> | ||
38 | <name>text</name> | ||
39 | <string>Cancel</string> | ||
40 | </property> | ||
41 | </widget> | ||
42 | <widget row="3" column="0" > | ||
43 | <class>QPushButton</class> | ||
44 | <property stdset="1"> | ||
45 | <name>name</name> | ||
46 | <cstring>addButton</cstring> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>text</name> | ||
50 | <string>Add</string> | ||
51 | </property> | ||
52 | </widget> | ||
53 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
54 | <class>QListView</class> | ||
55 | <column> | ||
56 | <property> | ||
57 | <name>text</name> | ||
58 | <string>Services</string> | ||
59 | </property> | ||
60 | <property> | ||
61 | <name>clickable</name> | ||
62 | <bool>true</bool> | ||
63 | </property> | ||
64 | <property> | ||
65 | <name>resizeable</name> | ||
66 | <bool>true</bool> | ||
67 | </property> | ||
68 | </column> | ||
69 | <property stdset="1"> | ||
70 | <name>name</name> | ||
71 | <cstring>registeredServicesList</cstring> | ||
72 | </property> | ||
73 | <property stdset="1"> | ||
74 | <name>sizePolicy</name> | ||
75 | <sizepolicy> | ||
76 | <hsizetype>7</hsizetype> | ||
77 | <vsizetype>3</vsizetype> | ||
78 | </sizepolicy> | ||
79 | </property> | ||
80 | <property stdset="1"> | ||
81 | <name>minimumSize</name> | ||
82 | <size> | ||
83 | <width>0</width> | ||
84 | <height>75</height> | ||
85 | </size> | ||
86 | </property> | ||
87 | </widget> | ||
88 | <spacer row="2" column="1" > | ||
89 | <property> | ||
90 | <name>name</name> | ||
91 | <cstring>Spacer12</cstring> | ||
92 | </property> | ||
93 | <property stdset="1"> | ||
94 | <name>orientation</name> | ||
95 | <enum>Vertical</enum> | ||
96 | </property> | ||
97 | <property stdset="1"> | ||
98 | <name>sizeType</name> | ||
99 | <enum>Expanding</enum> | ||
100 | </property> | ||
101 | <property> | ||
102 | <name>sizeHint</name> | ||
103 | <size> | ||
104 | <width>20</width> | ||
105 | <height>20</height> | ||
106 | </size> | ||
107 | </property> | ||
108 | </spacer> | ||
109 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
110 | <class>QLabel</class> | ||
111 | <property stdset="1"> | ||
112 | <name>name</name> | ||
113 | <cstring>help</cstring> | ||
114 | </property> | ||
115 | <property stdset="1"> | ||
116 | <name>sizePolicy</name> | ||
117 | <sizepolicy> | ||
118 | <hsizetype>5</hsizetype> | ||
119 | <vsizetype>4</vsizetype> | ||
120 | </sizepolicy> | ||
121 | </property> | ||
122 | <property stdset="1"> | ||
123 | <name>text</name> | ||
124 | <string>LAN - TCP/IP | ||
125 | For Local-area network connections through PC_CARD network interfdace cards.</string> | ||
126 | </property> | ||
127 | <property stdset="1"> | ||
128 | <name>alignment</name> | ||
129 | <set>WordBreak|AlignTop|AlignLeft</set> | ||
130 | </property> | ||
131 | <property> | ||
132 | <name>vAlign</name> | ||
133 | </property> | ||
134 | <property> | ||
135 | <name>wordwrap</name> | ||
136 | </property> | ||
137 | </widget> | ||
138 | </grid> | ||
139 | </widget> | ||
140 | <connections> | ||
141 | <connection> | ||
142 | <sender>cancelButton</sender> | ||
143 | <signal>clicked()</signal> | ||
144 | <receiver>AddService</receiver> | ||
145 | <slot>reject()</slot> | ||
146 | </connection> | ||
147 | <connection> | ||
148 | <sender>addButton</sender> | ||
149 | <signal>clicked()</signal> | ||
150 | <receiver>AddService</receiver> | ||
151 | <slot>accept()</slot> | ||
152 | </connection> | ||
153 | </connections> | ||
154 | </UI> | ||
diff --git a/noncore/net/networksetup/addserviceimp.cpp b/noncore/net/networksetup/addserviceimp.cpp new file mode 100644 index 0000000..ac79d06 --- a/dev/null +++ b/noncore/net/networksetup/addserviceimp.cpp | |||
@@ -0,0 +1,26 @@ | |||
1 | #include "addserviceimp.h" | ||
2 | #include <qpe/qlibrary.h> | ||
3 | #include <qlistview.h> | ||
4 | #include <qlist.h> | ||
5 | |||
6 | void AddServiceImp::addServices(QList<QString> list){ | ||
7 | list.setAutoDelete(true); | ||
8 | |||
9 | for(uint i = 0; i < list.count(); i++){ | ||
10 | QString pluginFileName = ""; | ||
11 | QLibrary *lib = new QLibrary(pluginFileName); | ||
12 | void *functionPointer = lib->resolve("info"); | ||
13 | if( !functionPointer ){ | ||
14 | qDebug(QString("AddServiceImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | ||
15 | delete lib; | ||
16 | break; | ||
17 | } | ||
18 | |||
19 | // Try to get an info. | ||
20 | QString info = ((QString (*)()) functionPointer)(); | ||
21 | QListViewItem *newItem = new QListViewItem(registeredServicesList, info); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | |||
26 | // addserviceimp.cpp | ||
diff --git a/noncore/net/networksetup/addserviceimp.h b/noncore/net/networksetup/addserviceimp.h new file mode 100644 index 0000000..7cacb97 --- a/dev/null +++ b/noncore/net/networksetup/addserviceimp.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef ADDSERVICEIMP_H | ||
2 | #define ADDSERVICEIMP_H | ||
3 | |||
4 | #include "addservice.h" | ||
5 | #include <qmap.h> | ||
6 | #include <qlist.h> | ||
7 | |||
8 | class QListViewItem; | ||
9 | |||
10 | class AddServiceImp : public AddService { | ||
11 | |||
12 | Q_OBJECT | ||
13 | |||
14 | public: | ||
15 | AddServiceImp(QWidget *parent=0, const char *name=0, WFlags f=0):AddService(parent, name, f){}; | ||
16 | void addServices(QList<QString> list); | ||
17 | |||
18 | private: | ||
19 | QMap<QListViewItem*, QString> pluginInfo; | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
24 | |||
25 | // addserviceimp.h | ||
26 | |||
diff --git a/noncore/net/networksetup/defaultmodule.h b/noncore/net/networksetup/defaultmodule.h new file mode 100644 index 0000000..c7791d5 --- a/dev/null +++ b/noncore/net/networksetup/defaultmodule.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef MODULE_H | ||
2 | #define MODULE_H | ||
3 | |||
4 | #include "module.h" | ||
5 | |||
6 | class QWidget; | ||
7 | |||
8 | class DefaultModule : Module{ | ||
9 | |||
10 | public: | ||
11 | DefaultModule(){}; | ||
12 | |||
13 | virtual bool isOwner(Interface *i); | ||
14 | virtual QWidget *configure(); | ||
15 | virtual QWidget *information()}; | ||
16 | virtual QList<Interface> getInterfaces(); | ||
17 | virtual QMap<QString, QString> possibleNewInterfaces(); | ||
18 | virtual Interface *addNewInterface(QString name); | ||
19 | virtual bool remove(Interface* i); | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
24 | |||
25 | // module.h | ||
26 | |||
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp new file mode 100644 index 0000000..b9b09ad --- a/dev/null +++ b/noncore/net/networksetup/interface.cpp | |||
@@ -0,0 +1,236 @@ | |||
1 | #include "interface.h" | ||
2 | #include <qdatetime.h> | ||
3 | #include <qfile.h> | ||
4 | #include <qfileinfo.h> | ||
5 | #include <qtextstream.h> | ||
6 | |||
7 | #define IFCONFIG "/sbin/ifconfig" | ||
8 | #define HDCP_INFO_DIR "/etc/dhcpc" | ||
9 | |||
10 | #include <stdio.h> | ||
11 | #include <stdlib.h> | ||
12 | |||
13 | Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner("Default"), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ | ||
14 | refresh(); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * Try to start the interface. | ||
19 | * @return bool true if successfull. | ||
20 | */ | ||
21 | bool Interface::start(){ | ||
22 | // check to see if we are already running. | ||
23 | if(status) | ||
24 | return false; | ||
25 | |||
26 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | ||
27 | if(ret != 0) | ||
28 | return false; | ||
29 | |||
30 | status = true; | ||
31 | refresh(); | ||
32 | return true; | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Try to stop the interface. | ||
37 | * @return bool true if successfull. | ||
38 | */ | ||
39 | bool Interface::stop(){ | ||
40 | // check to see if we are already stopped. | ||
41 | if(status == false) | ||
42 | return false; | ||
43 | |||
44 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | ||
45 | if(ret != 0) | ||
46 | return false; | ||
47 | |||
48 | status = true; | ||
49 | refresh(); | ||
50 | return true; | ||
51 | } | ||
52 | /** | ||
53 | * Try to restart the interface. | ||
54 | * @return bool true if successfull. | ||
55 | */ | ||
56 | bool Interface::restart(){ | ||
57 | return (stop() && start()); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Try to refresh the information about the interface. | ||
62 | * First call ifconfig, then check the dhcp-info file | ||
63 | * @return bool true if successfull. | ||
64 | */ | ||
65 | bool Interface::refresh(){ | ||
66 | // See if we are up. | ||
67 | if(status == false){ | ||
68 | macAddress = ""; | ||
69 | ip = "0.0.0.0"; | ||
70 | subnetMask = "0.0.0.0"; | ||
71 | broadcast = ""; | ||
72 | dhcp = false; | ||
73 | dhcpServerIp = ""; | ||
74 | leaseObtained = ""; | ||
75 | leaseExpires = ""; | ||
76 | return true; | ||
77 | } | ||
78 | |||
79 | 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 | if(ret != 0){ | ||
82 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | QFile file(fileName); | ||
87 | if (!file.open(IO_ReadOnly)){ | ||
88 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | // Set to the defaults | ||
93 | macAddress = ""; | ||
94 | ip = "0.0.0.0"; | ||
95 | subnetMask = "0.0.0.0"; | ||
96 | broadcast = ""; | ||
97 | |||
98 | QTextStream stream( &file ); | ||
99 | QString line; | ||
100 | while ( !stream.eof() ) { | ||
101 | line = stream.readLine(); | ||
102 | if(line.contains("HWaddr")){ | ||
103 | int mac = line.find("HWaddr"); | ||
104 | macAddress = line.mid(mac+7, line.length()); | ||
105 | } | ||
106 | if(line.contains("inet addr")){ | ||
107 | int ipl = line.find("inet addr"); | ||
108 | int space = line.find(" ", ipl+10); | ||
109 | ip = line.mid(ipl+10, space-ipl-10); | ||
110 | } | ||
111 | if(line.contains("Mask")){ | ||
112 | int mask = line.find("Mask"); | ||
113 | subnetMask = line.mid(mask+5, line.length()); | ||
114 | } | ||
115 | if(line.contains("Bcast")){ | ||
116 | int mask = line.find("Bcast"); | ||
117 | int space = line.find(" ", mask+6); | ||
118 | broadcast = line.mid(mask+6, space-mask-6); | ||
119 | } | ||
120 | } | ||
121 | file.close(); | ||
122 | QFile::remove(fileName); | ||
123 | |||
124 | // DHCP TESTING | ||
125 | // reset DHCP info | ||
126 | dhcpServerIp = ""; | ||
127 | leaseObtained = ""; | ||
128 | leaseExpires = ""; | ||
129 | dhcp = false; | ||
130 | |||
131 | // See if we have | ||
132 | QString dhcpFile(QString(HDCP_INFO_DIR "/dhcpcd-%1.info").arg(interfaceName)); | ||
133 | // If there is no DHCP information then exit now with no errors. | ||
134 | if(!QFile::exists(dhcpFile)){ | ||
135 | return true; | ||
136 | } | ||
137 | |||
138 | file.setName(dhcpFile); | ||
139 | if (!file.open(IO_ReadOnly)){ | ||
140 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | ||
141 | return false; | ||
142 | } | ||
143 | |||
144 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | ||
145 | int leaseTime = 0; | ||
146 | int renewalTime = 0; | ||
147 | |||
148 | stream.setDevice( &file ); | ||
149 | while ( !stream.eof() ) { | ||
150 | line = stream.readLine(); | ||
151 | if(line.contains("DHCPSID=")) | ||
152 | dhcpServerIp = line.mid(8, line.length()); | ||
153 | if(line.contains("LEASETIME=")) | ||
154 | leaseTime = line.mid(10, line.length()).toInt(); | ||
155 | if(line.contains("RENEWALTIME=")) | ||
156 | renewalTime = line.mid(12, line.length()).toInt(); | ||
157 | } | ||
158 | file.close(); | ||
159 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | ||
160 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | ||
161 | |||
162 | // Get the pid of the deamond | ||
163 | dhcpFile = (QString(HDCP_INFO_DIR "/dhcpcd-%1.pid").arg(interfaceName)); | ||
164 | file.setName(dhcpFile); | ||
165 | if (!file.open(IO_ReadOnly)){ | ||
166 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | ||
167 | return false; | ||
168 | } | ||
169 | |||
170 | int pid = -1; | ||
171 | stream.setDevice( &file ); | ||
172 | while ( !stream.eof() ) { | ||
173 | line = stream.readLine(); | ||
174 | pid = line.toInt(); | ||
175 | } | ||
176 | file.close(); | ||
177 | |||
178 | if( pid == -1){ | ||
179 | qDebug("Interface: Could not get pid of dhcpc deamon."); | ||
180 | return false; | ||
181 | } | ||
182 | |||
183 | // Get the start running time of the deamon | ||
184 | fileName = (QString("/proc/%1/stat").arg(pid)); | ||
185 | file.setName(fileName); | ||
186 | stream.setDevice( &file ); | ||
187 | if (!file.open(IO_ReadOnly)){ | ||
188 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | ||
189 | return false; | ||
190 | } | ||
191 | while ( !stream.eof() ) { | ||
192 | line = stream.readLine(); | ||
193 | } | ||
194 | file.close(); | ||
195 | long time = 0; | ||
196 | // Grab the start time | ||
197 | // pid com state ppid pgrp session tty_nr tpgid flags | ||
198 | int r = sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | ||
199 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | ||
200 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | ||
201 | // nice 0 itrealvalue starttime | ||
202 | "%*d %*d %*d %lu", (long*) &time); | ||
203 | time = time/100; | ||
204 | |||
205 | QDateTime datetime(QDateTime::currentDateTime()); | ||
206 | |||
207 | // Get the uptime of the computer. | ||
208 | QFile f("/proc/uptime"); | ||
209 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | ||
210 | QTextStream t( &f ); // use a text stream | ||
211 | int sec = 0; | ||
212 | t >> sec; | ||
213 | datetime = datetime.addSecs((-1*sec)); | ||
214 | f.close(); | ||
215 | } | ||
216 | else{ | ||
217 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | datetime = datetime.addSecs(time); | ||
222 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | ||
223 | |||
224 | // Calculate the start and renew times | ||
225 | leaseObtained= datetime.toString(); | ||
226 | |||
227 | // Calculate the start and renew times | ||
228 | datetime = datetime.addSecs(leaseTime); | ||
229 | leaseExpires = datetime.toString(); | ||
230 | |||
231 | dhcp = true; | ||
232 | return true; | ||
233 | } | ||
234 | |||
235 | // interface.cpp | ||
236 | |||
diff --git a/noncore/net/networksetup/interface.h b/noncore/net/networksetup/interface.h new file mode 100644 index 0000000..1ad71eb --- a/dev/null +++ b/noncore/net/networksetup/interface.h | |||
@@ -0,0 +1,65 @@ | |||
1 | #ifndef INTERFACE_H | ||
2 | #define INTERFACE_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | |||
6 | class Interface { | ||
7 | |||
8 | public: | ||
9 | Interface(QString name = "unknown", bool status = false); | ||
10 | virtual ~Interface(){}; | ||
11 | |||
12 | virtual bool getStatus(){ return status; }; | ||
13 | virtual void setStatus(bool newSatus){ status = newSatus; refresh(); }; | ||
14 | |||
15 | virtual bool isAttached(){ return attached; }; | ||
16 | virtual void setAttached(bool isAttached=false){ attached = isAttached; }; | ||
17 | |||
18 | virtual QString getInterfaceName(){ return interfaceName; }; | ||
19 | virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; }; | ||
20 | |||
21 | virtual QString getHardwareName(){ return hardareName; }; | ||
22 | virtual void setHardwareName(QString name="Unknown"){ hardareName = name; }; | ||
23 | |||
24 | virtual QString getModuleOwner(){ return moduleOwner; }; | ||
25 | virtual void setModuleOwner(QString owner="Default"){ moduleOwner = owner; }; | ||
26 | |||
27 | // inet information. | ||
28 | QString getMacAddress(){ return macAddress; }; | ||
29 | QString getIp(){ return ip; }; | ||
30 | QString getSubnetMask(){ return subnetMask; }; | ||
31 | QString getBroadcast(){ return broadcast; }; | ||
32 | bool isDhcp(){ return dhcp; }; | ||
33 | QString getDhcpServerIp(){ return dhcpServerIp; }; | ||
34 | QString getLeaseObtained(){ return leaseObtained; }; | ||
35 | QString getLeaseExpires(){ return leaseExpires; }; | ||
36 | |||
37 | bool refresh(); | ||
38 | bool start(); | ||
39 | bool stop(); | ||
40 | bool restart(); | ||
41 | |||
42 | private: | ||
43 | // Interface information | ||
44 | bool status; | ||
45 | bool attached; | ||
46 | QString interfaceName; | ||
47 | QString hardareName; | ||
48 | QString moduleOwner; | ||
49 | |||
50 | // Network information | ||
51 | QString macAddress; | ||
52 | QString ip; | ||
53 | QString broadcast; | ||
54 | QString subnetMask; | ||
55 | bool dhcp; | ||
56 | QString dhcpServerIp; | ||
57 | QString leaseObtained; | ||
58 | QString leaseExpires; | ||
59 | |||
60 | }; | ||
61 | |||
62 | #endif | ||
63 | |||
64 | // interface.h | ||
65 | |||
diff --git a/noncore/net/networksetup/interfaceadvanced.ui b/noncore/net/networksetup/interfaceadvanced.ui new file mode 100644 index 0000000..8ef0b29 --- a/dev/null +++ b/noncore/net/networksetup/interfaceadvanced.ui | |||
@@ -0,0 +1,323 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InterfaceAdvanced</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>InterfaceAdvanced</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>197</width> | ||
15 | <height>253</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Advanced Interface Information</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="1" column="0" > | ||
32 | <class>QLabel</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>TextLabel1</cstring> | ||
36 | </property> | ||
37 | <property stdset="1"> | ||
38 | <name>text</name> | ||
39 | <string>MAC Address</string> | ||
40 | </property> | ||
41 | </widget> | ||
42 | <widget row="0" column="1" > | ||
43 | <class>QLabel</class> | ||
44 | <property stdset="1"> | ||
45 | <name>name</name> | ||
46 | <cstring>interfaceName</cstring> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>frameShape</name> | ||
50 | <enum>Panel</enum> | ||
51 | </property> | ||
52 | <property stdset="1"> | ||
53 | <name>frameShadow</name> | ||
54 | <enum>Sunken</enum> | ||
55 | </property> | ||
56 | <property stdset="1"> | ||
57 | <name>text</name> | ||
58 | <string>eth0</string> | ||
59 | </property> | ||
60 | </widget> | ||
61 | <widget row="2" column="0" > | ||
62 | <class>QLabel</class> | ||
63 | <property stdset="1"> | ||
64 | <name>name</name> | ||
65 | <cstring>TextLabel3</cstring> | ||
66 | </property> | ||
67 | <property stdset="1"> | ||
68 | <name>text</name> | ||
69 | <string>IP Address</string> | ||
70 | </property> | ||
71 | </widget> | ||
72 | <widget row="1" column="1" > | ||
73 | <class>QLabel</class> | ||
74 | <property stdset="1"> | ||
75 | <name>name</name> | ||
76 | <cstring>macAddressLabel</cstring> | ||
77 | </property> | ||
78 | <property stdset="1"> | ||
79 | <name>frameShape</name> | ||
80 | <enum>Panel</enum> | ||
81 | </property> | ||
82 | <property stdset="1"> | ||
83 | <name>frameShadow</name> | ||
84 | <enum>Sunken</enum> | ||
85 | </property> | ||
86 | <property stdset="1"> | ||
87 | <name>text</name> | ||
88 | <string>00:00:00:00:00:00</string> | ||
89 | </property> | ||
90 | </widget> | ||
91 | <widget row="0" column="0" > | ||
92 | <class>QLabel</class> | ||
93 | <property stdset="1"> | ||
94 | <name>name</name> | ||
95 | <cstring>TextLabel7</cstring> | ||
96 | </property> | ||
97 | <property stdset="1"> | ||
98 | <name>text</name> | ||
99 | <string>Interface</string> | ||
100 | </property> | ||
101 | </widget> | ||
102 | <widget row="8" column="0" > | ||
103 | <class>QLabel</class> | ||
104 | <property stdset="1"> | ||
105 | <name>name</name> | ||
106 | <cstring>TextLabel9</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>text</name> | ||
110 | <string>Lease Expires</string> | ||
111 | </property> | ||
112 | </widget> | ||
113 | <widget row="8" column="1" > | ||
114 | <class>QLabel</class> | ||
115 | <property stdset="1"> | ||
116 | <name>name</name> | ||
117 | <cstring>leaseExpiresLabel</cstring> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>frameShape</name> | ||
121 | <enum>Panel</enum> | ||
122 | </property> | ||
123 | <property stdset="1"> | ||
124 | <name>frameShadow</name> | ||
125 | <enum>Sunken</enum> | ||
126 | </property> | ||
127 | <property stdset="1"> | ||
128 | <name>text</name> | ||
129 | <string></string> | ||
130 | </property> | ||
131 | </widget> | ||
132 | <widget row="7" column="1" > | ||
133 | <class>QLabel</class> | ||
134 | <property stdset="1"> | ||
135 | <name>name</name> | ||
136 | <cstring>leaseObtainedLabel</cstring> | ||
137 | </property> | ||
138 | <property stdset="1"> | ||
139 | <name>frameShape</name> | ||
140 | <enum>Panel</enum> | ||
141 | </property> | ||
142 | <property stdset="1"> | ||
143 | <name>frameShadow</name> | ||
144 | <enum>Sunken</enum> | ||
145 | </property> | ||
146 | <property stdset="1"> | ||
147 | <name>text</name> | ||
148 | <string></string> | ||
149 | </property> | ||
150 | </widget> | ||
151 | <widget row="7" column="0" > | ||
152 | <class>QLabel</class> | ||
153 | <property stdset="1"> | ||
154 | <name>name</name> | ||
155 | <cstring>TextLabel8</cstring> | ||
156 | </property> | ||
157 | <property stdset="1"> | ||
158 | <name>text</name> | ||
159 | <string>Lease Obtained</string> | ||
160 | </property> | ||
161 | </widget> | ||
162 | <widget row="6" column="1" > | ||
163 | <class>QLabel</class> | ||
164 | <property stdset="1"> | ||
165 | <name>name</name> | ||
166 | <cstring>dhcpServerLabel</cstring> | ||
167 | </property> | ||
168 | <property stdset="1"> | ||
169 | <name>frameShape</name> | ||
170 | <enum>Panel</enum> | ||
171 | </property> | ||
172 | <property stdset="1"> | ||
173 | <name>frameShadow</name> | ||
174 | <enum>Sunken</enum> | ||
175 | </property> | ||
176 | <property stdset="1"> | ||
177 | <name>text</name> | ||
178 | <string>255.255.255.255</string> | ||
179 | </property> | ||
180 | </widget> | ||
181 | <widget row="6" column="0" > | ||
182 | <class>QLabel</class> | ||
183 | <property stdset="1"> | ||
184 | <name>name</name> | ||
185 | <cstring>TextLabel6</cstring> | ||
186 | </property> | ||
187 | <property stdset="1"> | ||
188 | <name>text</name> | ||
189 | <string>DHCP Server</string> | ||
190 | </property> | ||
191 | </widget> | ||
192 | <widget row="4" column="0" > | ||
193 | <class>QLabel</class> | ||
194 | <property stdset="1"> | ||
195 | <name>name</name> | ||
196 | <cstring>TextLabel4</cstring> | ||
197 | </property> | ||
198 | <property stdset="1"> | ||
199 | <name>text</name> | ||
200 | <string>Subnet Mask</string> | ||
201 | </property> | ||
202 | </widget> | ||
203 | <widget row="2" column="1" > | ||
204 | <class>QLabel</class> | ||
205 | <property stdset="1"> | ||
206 | <name>name</name> | ||
207 | <cstring>ipAddressLabel</cstring> | ||
208 | </property> | ||
209 | <property stdset="1"> | ||
210 | <name>frameShape</name> | ||
211 | <enum>Panel</enum> | ||
212 | </property> | ||
213 | <property stdset="1"> | ||
214 | <name>frameShadow</name> | ||
215 | <enum>Sunken</enum> | ||
216 | </property> | ||
217 | <property stdset="1"> | ||
218 | <name>text</name> | ||
219 | <string>0.0.0.0</string> | ||
220 | </property> | ||
221 | </widget> | ||
222 | <widget row="4" column="1" > | ||
223 | <class>QLabel</class> | ||
224 | <property stdset="1"> | ||
225 | <name>name</name> | ||
226 | <cstring>subnetMaskLabel</cstring> | ||
227 | </property> | ||
228 | <property stdset="1"> | ||
229 | <name>frameShape</name> | ||
230 | <enum>Panel</enum> | ||
231 | </property> | ||
232 | <property stdset="1"> | ||
233 | <name>frameShadow</name> | ||
234 | <enum>Sunken</enum> | ||
235 | </property> | ||
236 | <property stdset="1"> | ||
237 | <name>text</name> | ||
238 | <string>0.0.0.0</string> | ||
239 | </property> | ||
240 | </widget> | ||
241 | <spacer row="9" column="1" > | ||
242 | <property> | ||
243 | <name>name</name> | ||
244 | <cstring>Spacer2</cstring> | ||
245 | </property> | ||
246 | <property stdset="1"> | ||
247 | <name>orientation</name> | ||
248 | <enum>Vertical</enum> | ||
249 | </property> | ||
250 | <property stdset="1"> | ||
251 | <name>sizeType</name> | ||
252 | <enum>Expanding</enum> | ||
253 | </property> | ||
254 | <property> | ||
255 | <name>sizeHint</name> | ||
256 | <size> | ||
257 | <width>20</width> | ||
258 | <height>20</height> | ||
259 | </size> | ||
260 | </property> | ||
261 | </spacer> | ||
262 | <widget row="3" column="0" > | ||
263 | <class>QLabel</class> | ||
264 | <property stdset="1"> | ||
265 | <name>name</name> | ||
266 | <cstring>TextLabel2</cstring> | ||
267 | </property> | ||
268 | <property stdset="1"> | ||
269 | <name>text</name> | ||
270 | <string>Broadcast</string> | ||
271 | </property> | ||
272 | </widget> | ||
273 | <widget row="3" column="1" > | ||
274 | <class>QLabel</class> | ||
275 | <property stdset="1"> | ||
276 | <name>name</name> | ||
277 | <cstring>broadcastLabel</cstring> | ||
278 | </property> | ||
279 | <property stdset="1"> | ||
280 | <name>frameShape</name> | ||
281 | <enum>Panel</enum> | ||
282 | </property> | ||
283 | <property stdset="1"> | ||
284 | <name>frameShadow</name> | ||
285 | <enum>Sunken</enum> | ||
286 | </property> | ||
287 | </widget> | ||
288 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
289 | <class>Line</class> | ||
290 | <property stdset="1"> | ||
291 | <name>name</name> | ||
292 | <cstring>Line2</cstring> | ||
293 | </property> | ||
294 | <property stdset="1"> | ||
295 | <name>orientation</name> | ||
296 | <enum>Horizontal</enum> | ||
297 | </property> | ||
298 | </widget> | ||
299 | </grid> | ||
300 | </widget> | ||
301 | <customwidgets> | ||
302 | <customwidget> | ||
303 | <class>QWidget</class> | ||
304 | <header location="local">qwidget.h</header> | ||
305 | <sizehint> | ||
306 | <width>100</width> | ||
307 | <height>100</height> | ||
308 | </sizehint> | ||
309 | <container>0</container> | ||
310 | <sizepolicy> | ||
311 | <hordata>7</hordata> | ||
312 | <verdata>7</verdata> | ||
313 | </sizepolicy> | ||
314 | <pixmap>image0</pixmap> | ||
315 | </customwidget> | ||
316 | </customwidgets> | ||
317 | <images> | ||
318 | <image> | ||
319 | <name>image0</name> | ||
320 | <data format="XPM.GZ" length="45">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523250004143a55a6b2e0026630c4f</data> | ||
321 | </image> | ||
322 | </images> | ||
323 | </UI> | ||
diff --git a/noncore/net/networksetup/interfaceedit.cpp b/noncore/net/networksetup/interfaceedit.cpp new file mode 100644 index 0000000..25599ef --- a/dev/null +++ b/noncore/net/networksetup/interfaceedit.cpp | |||
@@ -0,0 +1,141 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Form implementation generated from reading ui file 'interfaceedit.ui' | ||
3 | ** | ||
4 | ** Created: Mon Sep 23 12:18:55 2002 | ||
5 | ** by: The User Interface Compiler (uic) | ||
6 | ** | ||
7 | ** WARNING! All changes made in this file will be lost! | ||
8 | ****************************************************************************/ | ||
9 | #include "interfaceedit.h" | ||
10 | |||
11 | #include <qcheckbox.h> | ||
12 | #include <qcombobox.h> | ||
13 | #include <qframe.h> | ||
14 | #include <qgroupbox.h> | ||
15 | #include <qlabel.h> | ||
16 | #include <qlineedit.h> | ||
17 | #include <qpushbutton.h> | ||
18 | #include <qspinbox.h> | ||
19 | #include "qwidget.h" | ||
20 | #include <qlayout.h> | ||
21 | #include <qvariant.h> | ||
22 | #include <qtooltip.h> | ||
23 | #include <qwhatsthis.h> | ||
24 | |||
25 | /* | ||
26 | * Constructs a InterfaceConfiguration which is a child of 'parent', with the | ||
27 | * name 'name' and widget flags set to 'f' | ||
28 | */ | ||
29 | InterfaceConfiguration::InterfaceConfiguration( QWidget* parent, const char* name, WFlags fl ) | ||
30 | : QWidget( parent, name, fl ) | ||
31 | { | ||
32 | if ( !name ) | ||
33 | setName( "InterfaceConfiguration" ); | ||
34 | resize( 177, 306 ); | ||
35 | setCaption( tr( "Interface Configuration" ) ); | ||
36 | InterfaceConfigurationLayout = new QGridLayout( this ); | ||
37 | InterfaceConfigurationLayout->setSpacing( 6 ); | ||
38 | InterfaceConfigurationLayout->setMargin( 11 ); | ||
39 | |||
40 | profile = new QComboBox( FALSE, this, "profile" ); | ||
41 | profile->insertItem( tr( "All" ) ); | ||
42 | |||
43 | InterfaceConfigurationLayout->addWidget( profile, 2, 1 ); | ||
44 | |||
45 | TextLabel1 = new QLabel( this, "TextLabel1" ); | ||
46 | TextLabel1->setText( tr( "Profile:" ) ); | ||
47 | |||
48 | InterfaceConfigurationLayout->addWidget( TextLabel1, 2, 0 ); | ||
49 | |||
50 | Line1 = new QFrame( this, "Line1" ); | ||
51 | Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
52 | |||
53 | InterfaceConfigurationLayout->addMultiCellWidget( Line1, 1, 1, 0, 1 ); | ||
54 | |||
55 | CheckBox3 = new QCheckBox( this, "CheckBox3" ); | ||
56 | CheckBox3->setText( tr( "Automaticly bring up" ) ); | ||
57 | |||
58 | InterfaceConfigurationLayout->addMultiCellWidget( CheckBox3, 0, 0, 0, 1 ); | ||
59 | |||
60 | dhcpCheckBox = new QCheckBox( this, "dhcpCheckBox" ); | ||
61 | dhcpCheckBox->setText( tr( "DHCP" ) ); | ||
62 | |||
63 | InterfaceConfigurationLayout->addMultiCellWidget( dhcpCheckBox, 3, 3, 0, 1 ); | ||
64 | |||
65 | TextLabel3_3_2 = new QLabel( this, "TextLabel3_3_2" ); | ||
66 | TextLabel3_3_2->setText( tr( "Lease Hours" ) ); | ||
67 | |||
68 | InterfaceConfigurationLayout->addWidget( TextLabel3_3_2, 4, 0 ); | ||
69 | |||
70 | SpinBox1_2 = new QSpinBox( this, "SpinBox1_2" ); | ||
71 | SpinBox1_2->setMaxValue( 336 ); | ||
72 | SpinBox1_2->setMinValue( 1 ); | ||
73 | SpinBox1_2->setValue( 24 ); | ||
74 | |||
75 | InterfaceConfigurationLayout->addWidget( SpinBox1_2, 4, 1 ); | ||
76 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | ||
77 | InterfaceConfigurationLayout->addItem( spacer, 11, 1 ); | ||
78 | |||
79 | TextLabel4 = new QLabel( this, "TextLabel4" ); | ||
80 | TextLabel4->setText( tr( "IP Address" ) ); | ||
81 | |||
82 | InterfaceConfigurationLayout->addWidget( TextLabel4, 6, 0 ); | ||
83 | |||
84 | ipAddressEdit = new QLineEdit( this, "ipAddressEdit" ); | ||
85 | |||
86 | InterfaceConfigurationLayout->addWidget( ipAddressEdit, 6, 1 ); | ||
87 | |||
88 | TextLabel5 = new QLabel( this, "TextLabel5" ); | ||
89 | TextLabel5->setText( tr( "Subnet Mask" ) ); | ||
90 | |||
91 | InterfaceConfigurationLayout->addWidget( TextLabel5, 7, 0 ); | ||
92 | |||
93 | firstDNSLineEdit = new QLineEdit( this, "firstDNSLineEdit" ); | ||
94 | |||
95 | InterfaceConfigurationLayout->addWidget( firstDNSLineEdit, 9, 1 ); | ||
96 | |||
97 | TextLabel3 = new QLabel( this, "TextLabel3" ); | ||
98 | TextLabel3->setText( tr( "Second DNS" ) ); | ||
99 | |||
100 | InterfaceConfigurationLayout->addWidget( TextLabel3, 10, 0 ); | ||
101 | |||
102 | subnetMaskEdit = new QLineEdit( this, "subnetMaskEdit" ); | ||
103 | |||
104 | InterfaceConfigurationLayout->addWidget( subnetMaskEdit, 7, 1 ); | ||
105 | |||
106 | gatewayEdit = new QLineEdit( this, "gatewayEdit" ); | ||
107 | |||
108 | InterfaceConfigurationLayout->addWidget( gatewayEdit, 8, 1 ); | ||
109 | |||
110 | TextLabel7 = new QLabel( this, "TextLabel7" ); | ||
111 | TextLabel7->setText( tr( "Gateway" ) ); | ||
112 | |||
113 | InterfaceConfigurationLayout->addWidget( TextLabel7, 8, 0 ); | ||
114 | |||
115 | TextLabel2 = new QLabel( this, "TextLabel2" ); | ||
116 | TextLabel2->setText( tr( "First DNS" ) ); | ||
117 | |||
118 | InterfaceConfigurationLayout->addWidget( TextLabel2, 9, 0 ); | ||
119 | |||
120 | secondDNSLineEdit = new QLineEdit( this, "secondDNSLineEdit" ); | ||
121 | |||
122 | InterfaceConfigurationLayout->addWidget( secondDNSLineEdit, 10, 1 ); | ||
123 | |||
124 | GroupBox2 = new QGroupBox( this, "GroupBox2" ); | ||
125 | GroupBox2->setTitle( tr( "Static Ip Configuration" ) ); | ||
126 | |||
127 | InterfaceConfigurationLayout->addMultiCellWidget( GroupBox2, 5, 5, 0, 1 ); | ||
128 | |||
129 | // signals and slots connections | ||
130 | connect( dhcpCheckBox, SIGNAL( toggled(bool) ), SpinBox1_2, SLOT( setEnabled(bool) ) ); | ||
131 | connect( dhcpCheckBox, SIGNAL( toggled(bool) ), GroupBox2, SLOT( setDisabled(bool) ) ); | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Destroys the object and frees any allocated resources | ||
136 | */ | ||
137 | InterfaceConfiguration::~InterfaceConfiguration() | ||
138 | { | ||
139 | // no need to delete child widgets, Qt does it all for us | ||
140 | } | ||
141 | |||
diff --git a/noncore/net/networksetup/interfaceedit.h b/noncore/net/networksetup/interfaceedit.h new file mode 100644 index 0000000..a65c030 --- a/dev/null +++ b/noncore/net/networksetup/interfaceedit.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Form interface generated from reading ui file 'interfaceedit.ui' | ||
3 | ** | ||
4 | ** Created: Mon Sep 23 12:18:55 2002 | ||
5 | ** by: The User Interface Compiler (uic) | ||
6 | ** | ||
7 | ** WARNING! All changes made in this file will be lost! | ||
8 | ****************************************************************************/ | ||
9 | #ifndef INTERFACECONFIGURATION_H | ||
10 | #define INTERFACECONFIGURATION_H | ||
11 | |||
12 | #include <qvariant.h> | ||
13 | #include <qwidget.h> | ||
14 | class QVBoxLayout; | ||
15 | class QHBoxLayout; | ||
16 | class QGridLayout; | ||
17 | class QCheckBox; | ||
18 | class QComboBox; | ||
19 | class QFrame; | ||
20 | class QGroupBox; | ||
21 | class QLabel; | ||
22 | class QLineEdit; | ||
23 | class QSpinBox; | ||
24 | |||
25 | class InterfaceConfiguration : public QWidget | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | |||
29 | public: | ||
30 | InterfaceConfiguration( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | ||
31 | ~InterfaceConfiguration(); | ||
32 | |||
33 | QComboBox* profile; | ||
34 | QLabel* TextLabel1; | ||
35 | QFrame* Line1; | ||
36 | QCheckBox* CheckBox3; | ||
37 | QCheckBox* dhcpCheckBox; | ||
38 | QLabel* TextLabel3_3_2; | ||
39 | QSpinBox* SpinBox1_2; | ||
40 | QLabel* TextLabel4; | ||
41 | QLineEdit* ipAddressEdit; | ||
42 | QLabel* TextLabel5; | ||
43 | QLineEdit* firstDNSLineEdit; | ||
44 | QLabel* TextLabel3; | ||
45 | QLineEdit* subnetMaskEdit; | ||
46 | QLineEdit* gatewayEdit; | ||
47 | QLabel* TextLabel7; | ||
48 | QLabel* TextLabel2; | ||
49 | QLineEdit* secondDNSLineEdit; | ||
50 | QGroupBox* GroupBox2; | ||
51 | |||
52 | protected: | ||
53 | QGridLayout* InterfaceConfigurationLayout; | ||
54 | }; | ||
55 | |||
56 | #endif // INTERFACECONFIGURATION_H | ||
diff --git a/noncore/net/networksetup/interfaceinformation.ui b/noncore/net/networksetup/interfaceinformation.ui new file mode 100644 index 0000000..2a9b3fb --- a/dev/null +++ b/noncore/net/networksetup/interfaceinformation.ui | |||
@@ -0,0 +1,317 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InterfaceInformation</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>InterfaceInformation</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>191</width> | ||
15 | <height>241</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Interface Information</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="4" column="0" rowspan="1" colspan="2" > | ||
32 | <class>QLayoutWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>Layout1</cstring> | ||
36 | </property> | ||
37 | <grid> | ||
38 | <property stdset="1"> | ||
39 | <name>margin</name> | ||
40 | <number>0</number> | ||
41 | </property> | ||
42 | <property stdset="1"> | ||
43 | <name>spacing</name> | ||
44 | <number>6</number> | ||
45 | </property> | ||
46 | <widget row="1" column="0" > | ||
47 | <class>QPushButton</class> | ||
48 | <property stdset="1"> | ||
49 | <name>name</name> | ||
50 | <cstring>refreshButton</cstring> | ||
51 | </property> | ||
52 | <property stdset="1"> | ||
53 | <name>text</name> | ||
54 | <string>Refresh</string> | ||
55 | </property> | ||
56 | </widget> | ||
57 | <widget row="0" column="1" > | ||
58 | <class>QPushButton</class> | ||
59 | <property stdset="1"> | ||
60 | <name>name</name> | ||
61 | <cstring>stopButton</cstring> | ||
62 | </property> | ||
63 | <property stdset="1"> | ||
64 | <name>text</name> | ||
65 | <string>Stop</string> | ||
66 | </property> | ||
67 | </widget> | ||
68 | <widget row="1" column="1" > | ||
69 | <class>QPushButton</class> | ||
70 | <property stdset="1"> | ||
71 | <name>name</name> | ||
72 | <cstring>restartButton</cstring> | ||
73 | </property> | ||
74 | <property stdset="1"> | ||
75 | <name>text</name> | ||
76 | <string>Restart</string> | ||
77 | </property> | ||
78 | </widget> | ||
79 | <widget row="0" column="0" > | ||
80 | <class>QPushButton</class> | ||
81 | <property stdset="1"> | ||
82 | <name>name</name> | ||
83 | <cstring>startButton</cstring> | ||
84 | </property> | ||
85 | <property stdset="1"> | ||
86 | <name>text</name> | ||
87 | <string>Start</string> | ||
88 | </property> | ||
89 | </widget> | ||
90 | </grid> | ||
91 | </widget> | ||
92 | <widget row="0" column="0" > | ||
93 | <class>Line</class> | ||
94 | <property stdset="1"> | ||
95 | <name>name</name> | ||
96 | <cstring>Line1</cstring> | ||
97 | </property> | ||
98 | <property stdset="1"> | ||
99 | <name>orientation</name> | ||
100 | <enum>Horizontal</enum> | ||
101 | </property> | ||
102 | </widget> | ||
103 | <spacer row="6" column="1" > | ||
104 | <property> | ||
105 | <name>name</name> | ||
106 | <cstring>Spacer18</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>orientation</name> | ||
110 | <enum>Vertical</enum> | ||
111 | </property> | ||
112 | <property stdset="1"> | ||
113 | <name>sizeType</name> | ||
114 | <enum>Expanding</enum> | ||
115 | </property> | ||
116 | <property> | ||
117 | <name>sizeHint</name> | ||
118 | <size> | ||
119 | <width>20</width> | ||
120 | <height>20</height> | ||
121 | </size> | ||
122 | </property> | ||
123 | </spacer> | ||
124 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
125 | <class>QLayoutWidget</class> | ||
126 | <property stdset="1"> | ||
127 | <name>name</name> | ||
128 | <cstring>Layout2</cstring> | ||
129 | </property> | ||
130 | <hbox> | ||
131 | <property stdset="1"> | ||
132 | <name>margin</name> | ||
133 | <number>0</number> | ||
134 | </property> | ||
135 | <property stdset="1"> | ||
136 | <name>spacing</name> | ||
137 | <number>6</number> | ||
138 | </property> | ||
139 | <spacer> | ||
140 | <property> | ||
141 | <name>name</name> | ||
142 | <cstring>Spacer10</cstring> | ||
143 | </property> | ||
144 | <property stdset="1"> | ||
145 | <name>orientation</name> | ||
146 | <enum>Horizontal</enum> | ||
147 | </property> | ||
148 | <property stdset="1"> | ||
149 | <name>sizeType</name> | ||
150 | <enum>Expanding</enum> | ||
151 | </property> | ||
152 | <property> | ||
153 | <name>sizeHint</name> | ||
154 | <size> | ||
155 | <width>20</width> | ||
156 | <height>20</height> | ||
157 | </size> | ||
158 | </property> | ||
159 | </spacer> | ||
160 | <widget> | ||
161 | <class>QPushButton</class> | ||
162 | <property stdset="1"> | ||
163 | <name>name</name> | ||
164 | <cstring>advancedButton</cstring> | ||
165 | </property> | ||
166 | <property stdset="1"> | ||
167 | <name>text</name> | ||
168 | <string>View Advanced Information</string> | ||
169 | </property> | ||
170 | </widget> | ||
171 | </hbox> | ||
172 | </widget> | ||
173 | <widget row="0" column="0" > | ||
174 | <class>QLabel</class> | ||
175 | <property stdset="1"> | ||
176 | <name>name</name> | ||
177 | <cstring>TextLabel22</cstring> | ||
178 | </property> | ||
179 | <property stdset="1"> | ||
180 | <name>text</name> | ||
181 | <string>IP Address</string> | ||
182 | </property> | ||
183 | </widget> | ||
184 | <widget row="1" column="0" > | ||
185 | <class>QLabel</class> | ||
186 | <property stdset="1"> | ||
187 | <name>name</name> | ||
188 | <cstring>TextLabel23</cstring> | ||
189 | </property> | ||
190 | <property stdset="1"> | ||
191 | <name>text</name> | ||
192 | <string>Subnet Mask</string> | ||
193 | </property> | ||
194 | </widget> | ||
195 | <widget row="2" column="0" > | ||
196 | <class>QLabel</class> | ||
197 | <property stdset="1"> | ||
198 | <name>name</name> | ||
199 | <cstring>TextLabel21</cstring> | ||
200 | </property> | ||
201 | <property stdset="1"> | ||
202 | <name>text</name> | ||
203 | <string>MAC Address</string> | ||
204 | </property> | ||
205 | </widget> | ||
206 | <widget row="3" column="0" > | ||
207 | <class>QLabel</class> | ||
208 | <property stdset="1"> | ||
209 | <name>name</name> | ||
210 | <cstring>TextLabel24</cstring> | ||
211 | </property> | ||
212 | <property stdset="1"> | ||
213 | <name>text</name> | ||
214 | <string>Broadcast</string> | ||
215 | </property> | ||
216 | </widget> | ||
217 | <widget row="1" column="1" > | ||
218 | <class>QLabel</class> | ||
219 | <property stdset="1"> | ||
220 | <name>name</name> | ||
221 | <cstring>subnetMaskLabel</cstring> | ||
222 | </property> | ||
223 | <property stdset="1"> | ||
224 | <name>frameShape</name> | ||
225 | <enum>Panel</enum> | ||
226 | </property> | ||
227 | <property stdset="1"> | ||
228 | <name>frameShadow</name> | ||
229 | <enum>Sunken</enum> | ||
230 | </property> | ||
231 | <property stdset="1"> | ||
232 | <name>text</name> | ||
233 | <string>0.0.0.0</string> | ||
234 | </property> | ||
235 | </widget> | ||
236 | <widget row="2" column="1" > | ||
237 | <class>QLabel</class> | ||
238 | <property stdset="1"> | ||
239 | <name>name</name> | ||
240 | <cstring>macAddressLabel</cstring> | ||
241 | </property> | ||
242 | <property stdset="1"> | ||
243 | <name>frameShape</name> | ||
244 | <enum>Panel</enum> | ||
245 | </property> | ||
246 | <property stdset="1"> | ||
247 | <name>frameShadow</name> | ||
248 | <enum>Sunken</enum> | ||
249 | </property> | ||
250 | <property stdset="1"> | ||
251 | <name>text</name> | ||
252 | <string>00:00:00:00:00:00</string> | ||
253 | </property> | ||
254 | </widget> | ||
255 | <widget row="3" column="1" > | ||
256 | <class>QLabel</class> | ||
257 | <property stdset="1"> | ||
258 | <name>name</name> | ||
259 | <cstring>broadcastLabel</cstring> | ||
260 | </property> | ||
261 | <property stdset="1"> | ||
262 | <name>frameShape</name> | ||
263 | <enum>Panel</enum> | ||
264 | </property> | ||
265 | <property stdset="1"> | ||
266 | <name>frameShadow</name> | ||
267 | <enum>Sunken</enum> | ||
268 | </property> | ||
269 | <property stdset="1"> | ||
270 | <name>text</name> | ||
271 | <string></string> | ||
272 | </property> | ||
273 | </widget> | ||
274 | <widget row="0" column="1" > | ||
275 | <class>QLabel</class> | ||
276 | <property stdset="1"> | ||
277 | <name>name</name> | ||
278 | <cstring>ipAddressLabel</cstring> | ||
279 | </property> | ||
280 | <property stdset="1"> | ||
281 | <name>frameShape</name> | ||
282 | <enum>Panel</enum> | ||
283 | </property> | ||
284 | <property stdset="1"> | ||
285 | <name>frameShadow</name> | ||
286 | <enum>Sunken</enum> | ||
287 | </property> | ||
288 | <property stdset="1"> | ||
289 | <name>text</name> | ||
290 | <string>0.0.0.0</string> | ||
291 | </property> | ||
292 | </widget> | ||
293 | </grid> | ||
294 | </widget> | ||
295 | <customwidgets> | ||
296 | <customwidget> | ||
297 | <class>QWidget</class> | ||
298 | <header location="local">qwidget.h</header> | ||
299 | <sizehint> | ||
300 | <width>100</width> | ||
301 | <height>100</height> | ||
302 | </sizehint> | ||
303 | <container>0</container> | ||
304 | <sizepolicy> | ||
305 | <hordata>7</hordata> | ||
306 | <verdata>7</verdata> | ||
307 | </sizepolicy> | ||
308 | <pixmap>image0</pixmap> | ||
309 | </customwidget> | ||
310 | </customwidgets> | ||
311 | <images> | ||
312 | <image> | ||
313 | <name>image0</name> | ||
314 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
315 | </image> | ||
316 | </images> | ||
317 | </UI> | ||
diff --git a/noncore/net/networksetup/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaceinformationimp.cpp new file mode 100644 index 0000000..e37e0f8 --- a/dev/null +++ b/noncore/net/networksetup/interfaceinformationimp.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | #include "interfaceinformationimp.h" | ||
2 | #include "interfaceadvanced.h" | ||
3 | |||
4 | #include <qpushbutton.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <assert.h> | ||
7 | |||
8 | /** | ||
9 | * Constructor for the InterfaceInformationImp class. This class pretty much | ||
10 | * just display's information about the interface that is passed to it. | ||
11 | */ | ||
12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ | ||
13 | assert(i); | ||
14 | |||
15 | interface = i; | ||
16 | updateInterface(); | ||
17 | connect(startButton, SIGNAL(clicked()), this, SLOT(start())); | ||
18 | connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); | ||
19 | connect(restartButton, SIGNAL(clicked()), this, SLOT(restart())); | ||
20 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); | ||
21 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | ||
22 | |||
23 | } | ||
24 | |||
25 | void InterfaceInformationImp::updateInterface(){ | ||
26 | if(interface->getStatus()){ | ||
27 | startButton->setEnabled(false); | ||
28 | stopButton->setEnabled(true); | ||
29 | restartButton->setEnabled(true); | ||
30 | } | ||
31 | else{ | ||
32 | startButton->setEnabled(true); | ||
33 | stopButton->setEnabled(false); | ||
34 | restartButton->setEnabled(false); | ||
35 | } | ||
36 | macAddressLabel->setText(interface->getMacAddress()); | ||
37 | ipAddressLabel->setText(interface->getIp()); | ||
38 | subnetMaskLabel->setText(interface->getSubnetMask()); | ||
39 | broadcastLabel->setText(interface->getBroadcast()); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Start the interface. Update the information if successfull | ||
44 | */ | ||
45 | void InterfaceInformationImp::start(){ | ||
46 | if(interface->start()){ | ||
47 | updateInterface(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Stop the interface. | ||
53 | */ | ||
54 | void InterfaceInformationImp::stop(){ | ||
55 | if(interface->stop()){ | ||
56 | updateInterface(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /*** | ||
61 | * Tell the interface to refresh its information. | ||
62 | **/ | ||
63 | void InterfaceInformationImp::refresh(){ | ||
64 | if(interface->refresh()) | ||
65 | updateInterface(); | ||
66 | } | ||
67 | |||
68 | void InterfaceInformationImp::restart(){ | ||
69 | if(interface->restart()){ | ||
70 | updateInterface(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create the advanced widget. Fill it with the current interface's information. | ||
77 | * Display it. | ||
78 | */ | ||
79 | void InterfaceInformationImp::advanced(){ | ||
80 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); | ||
81 | a->interfaceName->setText(interface->getInterfaceName()); | ||
82 | a->macAddressLabel->setText(interface->getMacAddress()); | ||
83 | a->ipAddressLabel->setText(interface->getIp()); | ||
84 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | ||
85 | a->broadcastLabel->setText(interface->getBroadcast()); | ||
86 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | ||
87 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | ||
88 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | ||
89 | a->showMaximized(); | ||
90 | a->show(); | ||
91 | } | ||
92 | |||
93 | // infoimp.cpp | ||
94 | |||
diff --git a/noncore/net/networksetup/interfaceinformationimp.h b/noncore/net/networksetup/interfaceinformationimp.h new file mode 100644 index 0000000..6fc2384 --- a/dev/null +++ b/noncore/net/networksetup/interfaceinformationimp.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | ||
2 | #define INTERFACEINFORMATIONIMP_H | ||
3 | |||
4 | #include "interfaceinformation.h" | ||
5 | #include "interface.h" | ||
6 | |||
7 | class InterfaceInformationImp : public InterfaceInformation { | ||
8 | |||
9 | Q_OBJECT | ||
10 | |||
11 | public: | ||
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | ||
13 | ~InterfaceInformationImp(){}; | ||
14 | |||
15 | private slots: | ||
16 | void start(); | ||
17 | void stop(); | ||
18 | void refresh(); | ||
19 | void restart(); | ||
20 | void advanced(); | ||
21 | Interface *interface; | ||
22 | |||
23 | private: | ||
24 | void updateInterface(); | ||
25 | |||
26 | }; | ||
27 | |||
28 | #endif | ||
29 | |||
30 | // addserviceimp.h | ||
31 | |||
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp new file mode 100644 index 0000000..b8a3e7f --- a/dev/null +++ b/noncore/net/networksetup/interfaces.cpp | |||
@@ -0,0 +1,513 @@ | |||
1 | #include "interfaces.h" | ||
2 | |||
3 | #include <qfile.h> | ||
4 | #include <qtextstream.h> | ||
5 | #include <qregexp.h> | ||
6 | |||
7 | #define AUTO "auto" | ||
8 | #define IFACE "iface" | ||
9 | #define MAPPING "mapping" | ||
10 | |||
11 | /** | ||
12 | * Constructor. Reads in the interfaces file and then split the file up by | ||
13 | * the \n for interfaces variable. | ||
14 | * @param useInterfacesFile if an interface file other then the default is | ||
15 | * desired to be used it should be passed in. | ||
16 | */ | ||
17 | Interfaces::Interfaces(QString useInterfacesFile){ | ||
18 | acceptedFamily.append(INTERFACES_FAMILY_INET); | ||
19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | ||
20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | ||
21 | |||
22 | interfacesFile = useInterfacesFile; | ||
23 | QFile file(interfacesFile); | ||
24 | if (!file.open(IO_ReadOnly)){ | ||
25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | ||
26 | currentIface = interfaces.end(); | ||
27 | currentMapping = interfaces.end(); | ||
28 | return; | ||
29 | } | ||
30 | QTextStream stream( &file ); | ||
31 | QString line; | ||
32 | while ( !stream.eof() ) { | ||
33 | line += stream.readLine(); | ||
34 | line += "\n"; | ||
35 | } | ||
36 | file.close(); | ||
37 | interfaces = QStringList::split("\n", line, true); | ||
38 | |||
39 | currentIface = interfaces.end(); | ||
40 | currentMapping = interfaces.end(); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Find out if interface is in an "auto" group or not. | ||
45 | * Report any duplicates such as eth0 being in two differnt auto's | ||
46 | * @param | ||
47 | * @return true is interface is in auto | ||
48 | */ | ||
49 | bool Interfaces::isAuto(QString interface){ | ||
50 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | ||
51 | QStringList awi = autoLines.grep(QRegExp(interface)); | ||
52 | if(awi.count() > 1) | ||
53 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | ||
54 | if(awi.count() < 1) | ||
55 | return false; | ||
56 | return true; | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * Attempt to set the auto option for interface to setAuto. | ||
61 | * @param interface the interface to set | ||
62 | * @param setAuto the value to set interface to. | ||
63 | * @return false if already set to setAuto. | ||
64 | * */ | ||
65 | bool Interfaces::setAuto(QString interface, bool setAuto){ | ||
66 | // Don't need to set it if it is already set. | ||
67 | if(isAuto(interface) == setAuto) | ||
68 | return false; | ||
69 | |||
70 | bool changed = false; | ||
71 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | ||
72 | if((*it).contains(AUTO)){ | ||
73 | //We know that they are not in any group so let add to this auto. | ||
74 | if(setAuto){ | ||
75 | (*it) = (*it) += " " + interface; | ||
76 | // Don't care to have such thins as: auto eth0 lo usb0 | ||
77 | (*it) = (*it).simplifyWhiteSpace(); | ||
78 | changed = true; | ||
79 | break; | ||
80 | } | ||
81 | else{ | ||
82 | if((*it).contains(interface)){ | ||
83 | (*it) = (*it).replace(QRegExp(interface), ""); | ||
84 | // clean up | ||
85 | QString line = (*it).simplifyWhiteSpace(); | ||
86 | line = line.replace(QRegExp(" "),""); | ||
87 | if(line == AUTO) | ||
88 | (*it) = ""; | ||
89 | changed = true; | ||
90 | // Don't break because we want to make sure we remove all cases. | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | if(changed == false){ | ||
96 | if(setAuto == true) | ||
97 | interfaces.append(QString(AUTO" %1").arg(interface)); | ||
98 | else{ | ||
99 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | ||
100 | } | ||
101 | } | ||
102 | return true; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Set the current interface to interface. This needs to be done before you | ||
107 | * can call getFamily(), getMethod, and get/setOption(). | ||
108 | * @param interface the name of the interface to set. All whitespace is | ||
109 | * removed from the interface name. | ||
110 | * @return bool true if it is successfull. | ||
111 | */ | ||
112 | bool Interfaces::setInterface(QString interface){ | ||
113 | interface = interface.simplifyWhiteSpace(); | ||
114 | interface = interface.replace(QRegExp(" "), ""); | ||
115 | return setStanza(IFACE, interface, currentIface); | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * A quick helper funtion to see if the current interface is set. | ||
120 | * @return bool true if set, false otherwise. | ||
121 | */ | ||
122 | bool Interfaces::isInterfaceSet(){ | ||
123 | return (currentIface != interfaces.end()); | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * Add a new interface of with the settings - family and method | ||
128 | * @param interface the name of the interface to set. All whitespace is | ||
129 | * removed from the interface name. | ||
130 | * @param family the family of this interface inet or inet, ipx or inet6 | ||
131 | * Must of one of the families defined in interfaces.h | ||
132 | * @param method for the family. see interfaces man page for family methods. | ||
133 | * @return true if successfull. | ||
134 | */ | ||
135 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | ||
136 | if(acceptedFamily.contains(family)==0) | ||
137 | return false; | ||
138 | interface = interface.simplifyWhiteSpace(); | ||
139 | interface = interface.replace(QRegExp(" "), ""); | ||
140 | interfaces.append(""); | ||
141 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | ||
142 | return true; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * Remove the currently selected interface and all of its options. | ||
147 | * @return bool if successfull or not. | ||
148 | */ | ||
149 | bool Interfaces::removeInterface(){ | ||
150 | if(currentIface == interfaces.end()) | ||
151 | return false; | ||
152 | (*currentIface) = ""; | ||
153 | return removeAllInterfaceOptions(); | ||
154 | } | ||
155 | |||
156 | /** | ||
157 | * Gets the hardware name of the interface that is currently selected. | ||
158 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | ||
159 | * @param error set to true if any error occurs, false otherwise. | ||
160 | */ | ||
161 | QString Interfaces::getInterfaceName(bool &error){ | ||
162 | if(currentIface == interfaces.end()){ | ||
163 | error = true; | ||
164 | return QString(); | ||
165 | } | ||
166 | QString line = (*currentIface); | ||
167 | line = line.mid(QString(IFACE).length() +1, line.length()); | ||
168 | line = line.simplifyWhiteSpace(); | ||
169 | int findSpace = line.find(" "); | ||
170 | if( findSpace < 0){ | ||
171 | error = true; | ||
172 | return QString(); | ||
173 | } | ||
174 | error = false; | ||
175 | return line.mid(0, findSpace); | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Gets the family name of the interface that is currently selected. | ||
180 | * @return QString name of the family (inet, inet6, ipx). | ||
181 | * @param error set to true if any error occurs, false otherwise. | ||
182 | */ | ||
183 | QString Interfaces::getInterfaceFamily(bool &error){ | ||
184 | QString name = getInterfaceName(error); | ||
185 | if(error){ | ||
186 | error = true; | ||
187 | return QString(); | ||
188 | } | ||
189 | QString line = (*currentIface); | ||
190 | line = line.mid(QString(IFACE).length() +1, line.length()); | ||
191 | line = line.mid(name.length()+1, line.length()); | ||
192 | line = line.simplifyWhiteSpace(); | ||
193 | int findSpace = line.find(" "); | ||
194 | if( findSpace < 0){ | ||
195 | error = true; | ||
196 | return QString(); | ||
197 | } | ||
198 | error = false; | ||
199 | return line.mid(0, findSpace); | ||
200 | } | ||
201 | |||
202 | /** | ||
203 | * Gets the method of the interface that is currently selected. | ||
204 | * @return QString name of the method such as staic or dhcp. | ||
205 | * See the man page of interfaces for possible methods depending on the family. | ||
206 | * @param error set to true if any error occurs, false otherwise. | ||
207 | */ | ||
208 | QString Interfaces::getInterfaceMethod(bool &error){ | ||
209 | QString name = getInterfaceName(error); | ||
210 | if(error){ | ||
211 | error = true; | ||
212 | return QString(); | ||
213 | } | ||
214 | QString family = getInterfaceFamily(error); | ||
215 | if(error){ | ||
216 | error = true; | ||
217 | return QString(); | ||
218 | } | ||
219 | QString line = (*currentIface); | ||
220 | line = line.mid(QString(IFACE).length()+1, line.length()); | ||
221 | line = line.mid(name.length()+1, line.length()); | ||
222 | line = line.mid(family.length()+1, line.length()); | ||
223 | line = line.simplifyWhiteSpace(); | ||
224 | error = false; | ||
225 | return line; | ||
226 | } | ||
227 | |||
228 | /** | ||
229 | * Sets the interface name to newName. | ||
230 | * @param newName the new name of the interface. All whitespace is removed. | ||
231 | * @return bool true if successfull. | ||
232 | */ | ||
233 | bool Interfaces::setInterfaceName(QString newName){ | ||
234 | if(currentIface == interfaces.end()) | ||
235 | return false; | ||
236 | newName = newName.simplifyWhiteSpace(); | ||
237 | newName = newName.replace(QRegExp(" "), ""); | ||
238 | bool returnValue = false; | ||
239 | (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | ||
240 | return !returnValue; | ||
241 | } | ||
242 | |||
243 | /** | ||
244 | * Sets the interface family to newName. | ||
245 | * @param newName the new name of the interface. Must be one of the families | ||
246 | * defined in the interfaces.h file. | ||
247 | * @return bool true if successfull. | ||
248 | */ | ||
249 | bool Interfaces::setInterfaceFamily(QString newName){ | ||
250 | if(currentIface == interfaces.end()) | ||
251 | return false; | ||
252 | if(acceptedFamily.contains(newName)==0) | ||
253 | return false; | ||
254 | bool returnValue = false; | ||
255 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | ||
256 | return !returnValue; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * Sets the interface method to newName | ||
261 | * @param newName the new name of the interface | ||
262 | * @return bool true if successfull. | ||
263 | */ | ||
264 | bool Interfaces::setInterfaceMethod(QString newName){ | ||
265 | if(currentIface == interfaces.end()) | ||
266 | return false; | ||
267 | bool returnValue = false; | ||
268 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | ||
269 | return !returnValue; | ||
270 | } | ||
271 | |||
272 | /** | ||
273 | * Get a value for an option in the currently selected interface. For example | ||
274 | * calling getInterfaceOption("address") on the following stanza would | ||
275 | * return 192.168.1.1. | ||
276 | * iface eth0 static | ||
277 | * address 192.168.1.1 | ||
278 | * @param option the options to get the value. | ||
279 | * @param error set to true if any error occurs, false otherwise. | ||
280 | * @return QString the options value. QString::null if error == true | ||
281 | */ | ||
282 | QString Interfaces::getInterfaceOption(QString option, bool &error){ | ||
283 | return getOption(currentIface, option, error); | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Set a value for an option in the currently selected interface. If option | ||
288 | * doesn't exist then it is added along with the value. If value is set to an | ||
289 | * empty string then option is removed. | ||
290 | * @param option the options to set the value. | ||
291 | * @param value the value that option should be set to. | ||
292 | * @param error set to true if any error occurs, false otherwise. | ||
293 | * @return QString the options value. QString::null if error == true | ||
294 | */ | ||
295 | bool Interfaces::setInterfaceOption(QString option, QString value){ | ||
296 | return setOption(currentIface, option, value); | ||
297 | } | ||
298 | |||
299 | /** | ||
300 | * Removes all of the options from the currently selected interface. | ||
301 | * @return bool error if if successfull | ||
302 | */ | ||
303 | bool Interfaces::removeAllInterfaceOptions(){ | ||
304 | return removeAllOptions(currentIface); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Set the current map to interface's map. This needs to be done before you | ||
309 | * can call addMapping(), set/getMap(), and get/setScript(). | ||
310 | * @param interface the name of the interface to set. All whitespace is | ||
311 | * removed from the interface name. | ||
312 | * @return bool true if it is successfull. | ||
313 | */ | ||
314 | bool Interfaces::setMapping(QString interface){ | ||
315 | interface = interface.simplifyWhiteSpace(); | ||
316 | interface = interface.replace(QRegExp(" "), ""); | ||
317 | return setStanza(MAPPING, interface, currentMapping); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Adds a new Mapping to the interfaces file with interfaces. | ||
322 | * @param interface the name(s) of the interfaces to set to this mapping | ||
323 | */ | ||
324 | void Interfaces::addMapping(QString interfaces){ | ||
325 | interfaces.append(""); | ||
326 | interfaces.append(QString(MAPPING " %1").arg(interfaces)); | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * Set a map option within a mapping. | ||
331 | * @param map map to use | ||
332 | * @param value value to go with map | ||
333 | * @return bool true if it is successfull. | ||
334 | */ | ||
335 | bool Interfaces::setMap(QString map, QString value){ | ||
336 | return setOption(currentMapping, map, value); | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * Get a map value within a mapping. | ||
341 | * @param map map to get value of | ||
342 | * @param bool true if it is successfull. | ||
343 | * @return value that goes to the map | ||
344 | */ | ||
345 | QString Interfaces::getMap(QString map, bool &error){ | ||
346 | return getOption(currentMapping, map, error); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * Sets a script value of the current mapping to argument. | ||
351 | * @param argument the script name. | ||
352 | * @return true if successfull. | ||
353 | */ | ||
354 | bool Interfaces::setScript(QString argument){ | ||
355 | return setOption(currentMapping, "script", argument); | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * @param error true if could not retrieve the current script argument. | ||
360 | * @return QString the argument of the script for the current mapping. | ||
361 | */ | ||
362 | QString Interfaces::getScript(bool &error){ | ||
363 | return getOption(currentMapping, "script", error); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Helper function used to parse through the QStringList and put pointers in | ||
368 | * the correct place. | ||
369 | * @param stanza The stanza (auto, iface, mapping) to look for. | ||
370 | * @param option string that must be in the stanza's main line. | ||
371 | * @param interator interator to place at location of stanza if successfull. | ||
372 | * @return bool true if the stanza is found. | ||
373 | */ | ||
374 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | ||
375 | bool found = false; | ||
376 | iterator = interfaces.end(); | ||
377 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | ||
378 | QString line = (*it).simplifyWhiteSpace(); | ||
379 | if(line.contains(stanza) && line.contains(option)){ | ||
380 | if(found == true){ | ||
381 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | ||
382 | } | ||
383 | found = true; | ||
384 | iterator = it; | ||
385 | } | ||
386 | } | ||
387 | return !found; | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * Sets a value of an option in a stanza | ||
392 | * @param start the start of the stanza | ||
393 | * @param option the option to use when setting value. | ||
394 | * @return bool true if successfull, false otherwise. | ||
395 | */ | ||
396 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | ||
397 | if(start == interfaces.end()) | ||
398 | return false; | ||
399 | |||
400 | bool found = false; | ||
401 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | ||
402 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
403 | if(!found && value != ""){ | ||
404 | // Got to the end of the stanza without finding it, so append it. | ||
405 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | ||
406 | } | ||
407 | break; | ||
408 | } | ||
409 | if((*it).contains(option)){ | ||
410 | // Found it in stanza so replace it. | ||
411 | if(found) | ||
412 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | ||
413 | found = true; | ||
414 | if(value == "") | ||
415 | (*it) = ""; | ||
416 | else | ||
417 | (*it) = QString("\t%1 %2").arg(option).arg(value); | ||
418 | } | ||
419 | } | ||
420 | return true; | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * Removes all options in a stanza | ||
425 | * @param start the start of the stanza | ||
426 | * @return bool true if successfull, false otherwise. | ||
427 | */ | ||
428 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | ||
429 | if(start == interfaces.end()) | ||
430 | return false; | ||
431 | |||
432 | QStringList::Iterator it = start; | ||
433 | it = ++it; | ||
434 | for (it; it != interfaces.end(); ++it ) { | ||
435 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
436 | break; | ||
437 | } | ||
438 | it = interfaces.remove(it); | ||
439 | it = --it; | ||
440 | } | ||
441 | // Leave a space between this interface and the next. | ||
442 | interfaces.insert(it, QString("")); | ||
443 | return true; | ||
444 | } | ||
445 | |||
446 | /** | ||
447 | * Gets a value of an option in a stanza | ||
448 | * @param start the start of the stanza | ||
449 | * @param option the option to use when getting the value. | ||
450 | * @param bool true if errors false otherwise. | ||
451 | * @return QString the value of option QString::null() if error == true. | ||
452 | */ | ||
453 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | ||
454 | if(start == interfaces.end()){ | ||
455 | error = false; | ||
456 | return QString(); | ||
457 | } | ||
458 | |||
459 | QString value; | ||
460 | bool found = false; | ||
461 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | ||
462 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
463 | break; | ||
464 | } | ||
465 | if((*it).contains(option)){ | ||
466 | if(found) | ||
467 | qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); | ||
468 | found = true; | ||
469 | QString line = (*it).simplifyWhiteSpace(); | ||
470 | int space = line.find(" ", option.length()); | ||
471 | if(space != -1) | ||
472 | value = line.mid(space+1, line.length()); | ||
473 | else | ||
474 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | ||
475 | } | ||
476 | } | ||
477 | error = !found; | ||
478 | return value; | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Write out the interfaces file to the file passed into the constructor. | ||
483 | * Removes any excess blank lines over 1 line long. | ||
484 | * @return bool true if successfull, false if not. | ||
485 | */ | ||
486 | bool Interfaces::write(){ | ||
487 | QFile::remove(interfacesFile); | ||
488 | QFile file(interfacesFile); | ||
489 | |||
490 | if (!file.open(IO_ReadWrite)){ | ||
491 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | ||
492 | return false; | ||
493 | } | ||
494 | QTextStream stream( &file ); | ||
495 | int whiteSpaceCount = 0; | ||
496 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | ||
497 | QString line = (*it).simplifyWhiteSpace(); | ||
498 | line = line.replace(QRegExp(" "),""); | ||
499 | if(line.length() == 0) | ||
500 | whiteSpaceCount++; | ||
501 | else | ||
502 | whiteSpaceCount = 0; | ||
503 | if(whiteSpaceCount < 2){ | ||
504 | qDebug((*it).latin1()); | ||
505 | stream << (*it) << '\n'; | ||
506 | } | ||
507 | } | ||
508 | file.close(); | ||
509 | return true; | ||
510 | } | ||
511 | |||
512 | // interfaces.cpp | ||
513 | |||
diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h new file mode 100644 index 0000000..2cc9689 --- a/dev/null +++ b/noncore/net/networksetup/interfaces.h | |||
@@ -0,0 +1,70 @@ | |||
1 | #ifndef INTERFACES_H | ||
2 | #define INTERFACES_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | |||
7 | #define INTERFACES_LOOPBACK "loopback" | ||
8 | |||
9 | #define INTERFACES_FAMILY_INET "inet" | ||
10 | #define INTERFACES_FAMILY_IPX "ipx" | ||
11 | #define INTERFACES_FAMILY_INET6 "inet6" | ||
12 | |||
13 | #define INTERFACES_METHOD_DHCP "dhcp" | ||
14 | #define INTERFACES_METHOD_STATIC "static" | ||
15 | #define INTERFACES_METHOD_PPP "ppp" | ||
16 | |||
17 | /** | ||
18 | * This class provides a clean frontend for parsing the network interfaces file. | ||
19 | * It provides helper functions to minipulate the options within the file. | ||
20 | * See the interfaces man page for the syntax rules. | ||
21 | */ | ||
22 | class Interfaces { | ||
23 | |||
24 | public: | ||
25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); | ||
26 | |||
27 | bool isAuto(QString interface); | ||
28 | bool setAuto(QString interface, bool setAuto); | ||
29 | |||
30 | bool removeInterface(); | ||
31 | bool addInterface(QString interface, QString family, QString method); | ||
32 | bool setInterface(QString interface); | ||
33 | bool isInterfaceSet(); | ||
34 | QString getInterfaceName(bool &error); | ||
35 | bool setInterfaceName(QString newName); | ||
36 | QString getInterfaceFamily(bool &error); | ||
37 | bool setInterfaceFamily(QString newName); | ||
38 | QString getInterfaceMethod(bool &error); | ||
39 | bool setInterfaceMethod(QString newName); | ||
40 | QString getInterfaceOption(QString option, bool &error); | ||
41 | bool setInterfaceOption(QString option, QString value); | ||
42 | bool removeAllInterfaceOptions(); | ||
43 | |||
44 | bool setMapping(QString interface); | ||
45 | void addMapping(QString interfaces); | ||
46 | bool setMap(QString map, QString value); | ||
47 | QString getMap(QString map, bool &error); | ||
48 | bool setScript(QString); | ||
49 | QString getScript(bool &error); | ||
50 | |||
51 | bool write(); | ||
52 | |||
53 | private: | ||
54 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); | ||
55 | bool setOption(QStringList::Iterator start, QString option, QString value); | ||
56 | QString getOption(QStringList::Iterator start, QString option, bool &error); | ||
57 | bool removeAllOptions(QStringList::Iterator start); | ||
58 | |||
59 | QString interfacesFile; | ||
60 | QStringList interfaces; | ||
61 | QStringList::Iterator currentIface; | ||
62 | QStringList::Iterator currentMapping; | ||
63 | |||
64 | QStringList acceptedFamily; | ||
65 | }; | ||
66 | |||
67 | #endif | ||
68 | |||
69 | // interfaces | ||
70 | |||
diff --git a/noncore/net/networksetup/interfacesetup.ui b/noncore/net/networksetup/interfacesetup.ui new file mode 100644 index 0000000..698422c --- a/dev/null +++ b/noncore/net/networksetup/interfacesetup.ui | |||
@@ -0,0 +1,274 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InterfaceSetup</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>InterfaceSetup</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>193</width> | ||
15 | <height>310</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Interface Configuration</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
32 | <class>Line</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>Line1</cstring> | ||
36 | </property> | ||
37 | <property stdset="1"> | ||
38 | <name>orientation</name> | ||
39 | <enum>Horizontal</enum> | ||
40 | </property> | ||
41 | </widget> | ||
42 | <widget row="6" column="0" > | ||
43 | <class>QLabel</class> | ||
44 | <property stdset="1"> | ||
45 | <name>name</name> | ||
46 | <cstring>TextLabel4</cstring> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>text</name> | ||
50 | <string>IP Address</string> | ||
51 | </property> | ||
52 | </widget> | ||
53 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
54 | <class>QCheckBox</class> | ||
55 | <property stdset="1"> | ||
56 | <name>name</name> | ||
57 | <cstring>autoStart</cstring> | ||
58 | </property> | ||
59 | <property stdset="1"> | ||
60 | <name>text</name> | ||
61 | <string>Automaticly bring up</string> | ||
62 | </property> | ||
63 | </widget> | ||
64 | <widget row="2" column="1" > | ||
65 | <class>QComboBox</class> | ||
66 | <item> | ||
67 | <property> | ||
68 | <name>text</name> | ||
69 | <string>All</string> | ||
70 | </property> | ||
71 | </item> | ||
72 | <property stdset="1"> | ||
73 | <name>name</name> | ||
74 | <cstring>profileCombo</cstring> | ||
75 | </property> | ||
76 | </widget> | ||
77 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
78 | <class>QGroupBox</class> | ||
79 | <property stdset="1"> | ||
80 | <name>name</name> | ||
81 | <cstring>staticGroupBox</cstring> | ||
82 | </property> | ||
83 | <property stdset="1"> | ||
84 | <name>enabled</name> | ||
85 | <bool>false</bool> | ||
86 | </property> | ||
87 | <property stdset="1"> | ||
88 | <name>title</name> | ||
89 | <string>Static Ip Configuration</string> | ||
90 | </property> | ||
91 | </widget> | ||
92 | <widget row="6" column="1" > | ||
93 | <class>QLineEdit</class> | ||
94 | <property stdset="1"> | ||
95 | <name>name</name> | ||
96 | <cstring>ipAddressEdit</cstring> | ||
97 | </property> | ||
98 | </widget> | ||
99 | <widget row="4" column="0" > | ||
100 | <class>QLabel</class> | ||
101 | <property stdset="1"> | ||
102 | <name>name</name> | ||
103 | <cstring>leaseHoursLabel</cstring> | ||
104 | </property> | ||
105 | <property stdset="1"> | ||
106 | <name>text</name> | ||
107 | <string>Requested Lease</string> | ||
108 | </property> | ||
109 | </widget> | ||
110 | <widget row="3" column="0" rowspan="1" colspan="2" > | ||
111 | <class>QCheckBox</class> | ||
112 | <property stdset="1"> | ||
113 | <name>name</name> | ||
114 | <cstring>dhcpCheckBox</cstring> | ||
115 | </property> | ||
116 | <property stdset="1"> | ||
117 | <name>text</name> | ||
118 | <string>DHCP</string> | ||
119 | </property> | ||
120 | <property stdset="1"> | ||
121 | <name>checked</name> | ||
122 | <bool>true</bool> | ||
123 | </property> | ||
124 | </widget> | ||
125 | <widget row="7" column="0" > | ||
126 | <class>QLabel</class> | ||
127 | <property stdset="1"> | ||
128 | <name>name</name> | ||
129 | <cstring>TextLabel5</cstring> | ||
130 | </property> | ||
131 | <property stdset="1"> | ||
132 | <name>text</name> | ||
133 | <string>Subnet Mask</string> | ||
134 | </property> | ||
135 | </widget> | ||
136 | <widget row="2" column="0" > | ||
137 | <class>QLabel</class> | ||
138 | <property stdset="1"> | ||
139 | <name>name</name> | ||
140 | <cstring>TextLabel1</cstring> | ||
141 | </property> | ||
142 | <property stdset="1"> | ||
143 | <name>text</name> | ||
144 | <string>Profile:</string> | ||
145 | </property> | ||
146 | </widget> | ||
147 | <widget row="4" column="1" > | ||
148 | <class>QSpinBox</class> | ||
149 | <property stdset="1"> | ||
150 | <name>name</name> | ||
151 | <cstring>leaseTime</cstring> | ||
152 | </property> | ||
153 | <property stdset="1"> | ||
154 | <name>suffix</name> | ||
155 | <string> hours</string> | ||
156 | </property> | ||
157 | <property stdset="1"> | ||
158 | <name>maxValue</name> | ||
159 | <number>336</number> | ||
160 | </property> | ||
161 | <property stdset="1"> | ||
162 | <name>minValue</name> | ||
163 | <number>1</number> | ||
164 | </property> | ||
165 | <property stdset="1"> | ||
166 | <name>value</name> | ||
167 | <number>24</number> | ||
168 | </property> | ||
169 | </widget> | ||
170 | <spacer row="11" column="1" > | ||
171 | <property> | ||
172 | <name>name</name> | ||
173 | <cstring>Spacer9</cstring> | ||
174 | </property> | ||
175 | <property stdset="1"> | ||
176 | <name>orientation</name> | ||
177 | <enum>Vertical</enum> | ||
178 | </property> | ||
179 | <property stdset="1"> | ||
180 | <name>sizeType</name> | ||
181 | <enum>Expanding</enum> | ||
182 | </property> | ||
183 | <property> | ||
184 | <name>sizeHint</name> | ||
185 | <size> | ||
186 | <width>20</width> | ||
187 | <height>20</height> | ||
188 | </size> | ||
189 | </property> | ||
190 | </spacer> | ||
191 | <widget row="10" column="1" > | ||
192 | <class>QLineEdit</class> | ||
193 | <property stdset="1"> | ||
194 | <name>name</name> | ||
195 | <cstring>secondDNSLineEdit</cstring> | ||
196 | </property> | ||
197 | </widget> | ||
198 | <widget row="10" column="0" > | ||
199 | <class>QLabel</class> | ||
200 | <property stdset="1"> | ||
201 | <name>name</name> | ||
202 | <cstring>TextLabel3</cstring> | ||
203 | </property> | ||
204 | <property stdset="1"> | ||
205 | <name>text</name> | ||
206 | <string>Second DNS</string> | ||
207 | </property> | ||
208 | </widget> | ||
209 | <widget row="9" column="0" > | ||
210 | <class>QLabel</class> | ||
211 | <property stdset="1"> | ||
212 | <name>name</name> | ||
213 | <cstring>TextLabel2</cstring> | ||
214 | </property> | ||
215 | <property stdset="1"> | ||
216 | <name>text</name> | ||
217 | <string>First DNS</string> | ||
218 | </property> | ||
219 | </widget> | ||
220 | <widget row="9" column="1" > | ||
221 | <class>QLineEdit</class> | ||
222 | <property stdset="1"> | ||
223 | <name>name</name> | ||
224 | <cstring>firstDNSLineEdit</cstring> | ||
225 | </property> | ||
226 | </widget> | ||
227 | <widget row="8" column="0" > | ||
228 | <class>QLabel</class> | ||
229 | <property stdset="1"> | ||
230 | <name>name</name> | ||
231 | <cstring>TextLabel1_2</cstring> | ||
232 | </property> | ||
233 | <property stdset="1"> | ||
234 | <name>text</name> | ||
235 | <string>Gateway</string> | ||
236 | </property> | ||
237 | </widget> | ||
238 | <widget row="7" column="1" > | ||
239 | <class>QLineEdit</class> | ||
240 | <property stdset="1"> | ||
241 | <name>name</name> | ||
242 | <cstring>subnetMaskEdit</cstring> | ||
243 | </property> | ||
244 | </widget> | ||
245 | <widget row="8" column="1" > | ||
246 | <class>QLineEdit</class> | ||
247 | <property stdset="1"> | ||
248 | <name>name</name> | ||
249 | <cstring>gatewayEdit</cstring> | ||
250 | </property> | ||
251 | </widget> | ||
252 | </grid> | ||
253 | </widget> | ||
254 | <connections> | ||
255 | <connection> | ||
256 | <sender>dhcpCheckBox</sender> | ||
257 | <signal>toggled(bool)</signal> | ||
258 | <receiver>leaseHoursLabel</receiver> | ||
259 | <slot>setEnabled(bool)</slot> | ||
260 | </connection> | ||
261 | <connection> | ||
262 | <sender>dhcpCheckBox</sender> | ||
263 | <signal>toggled(bool)</signal> | ||
264 | <receiver>leaseTime</receiver> | ||
265 | <slot>setEnabled(bool)</slot> | ||
266 | </connection> | ||
267 | <connection> | ||
268 | <sender>dhcpCheckBox</sender> | ||
269 | <signal>toggled(bool)</signal> | ||
270 | <receiver>staticGroupBox</receiver> | ||
271 | <slot>setDisabled(bool)</slot> | ||
272 | </connection> | ||
273 | </connections> | ||
274 | </UI> | ||
diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp new file mode 100644 index 0000000..6a8449d --- a/dev/null +++ b/noncore/net/networksetup/interfacesetupimp.cpp | |||
@@ -0,0 +1,147 @@ | |||
1 | #include "interfacesetupimp.h" | ||
2 | #include "interface.h" | ||
3 | #include "interfaces.h" | ||
4 | |||
5 | #include <qcombobox.h> | ||
6 | #include <qcheckbox.h> | ||
7 | #include <qlineedit.h> | ||
8 | #include <qspinbox.h> | ||
9 | #include <qgroupbox.h> | ||
10 | #include <qlabel.h> | ||
11 | |||
12 | #include <qmessagebox.h> | ||
13 | |||
14 | #include <assert.h> | ||
15 | |||
16 | #define INTERFACE_FILE "/home/ben/interfaces" | ||
17 | #define DNSSCRIPT "interfacednsscript" | ||
18 | |||
19 | /** | ||
20 | * Constuctor. Set up the connection and load the first profile. | ||
21 | */ | ||
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : InterfaceSetup(parent, name, modal, fl){ | ||
23 | assert(i); | ||
24 | interface = i; | ||
25 | interfaces = new Interfaces(INTERFACE_FILE); | ||
26 | changeProfile(profileCombo->currentText()); | ||
27 | bool error = false; | ||
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
29 | staticGroupBox->hide(); | ||
30 | dhcpCheckBox->hide(); | ||
31 | leaseTime->hide(); | ||
32 | leaseHoursLabel->hide(); | ||
33 | } | ||
34 | connect(profileCombo, SIGNAL(highlighted(const QString &)), this, SLOT(changeProfile(const QString &))); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * Save the current settings, then write out the interfaces file and close. | ||
39 | */ | ||
40 | void InterfaceSetupImp::accept(){ | ||
41 | if(!saveSettings()) | ||
42 | return; | ||
43 | interfaces->write(); | ||
44 | close(true); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Save the settings for the current Interface. | ||
49 | * @return bool true if successfull, false otherwise | ||
50 | */ | ||
51 | bool InterfaceSetupImp::saveSettings(){ | ||
52 | // eh can't really do anything about it other then return. :-D | ||
53 | if(!interfaces->isInterfaceSet()) | ||
54 | return true; | ||
55 | |||
56 | bool error = false; | ||
57 | // Loopback case | ||
58 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
59 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | ||
60 | return true; | ||
61 | } | ||
62 | |||
63 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ | ||
64 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); | ||
65 | return false; | ||
66 | } | ||
67 | interfaces->removeAllInterfaceOptions(); | ||
68 | |||
69 | // DHCP | ||
70 | if(dhcpCheckBox->isChecked()){ | ||
71 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | ||
72 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | ||
73 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | ||
74 | } | ||
75 | else{ | ||
76 | interfaces->setInterfaceMethod("static"); | ||
77 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | ||
78 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | ||
79 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | ||
80 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | ||
81 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); | ||
82 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); | ||
83 | } | ||
84 | |||
85 | // IP Information | ||
86 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | ||
87 | return true; | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * The Profile has changed. | ||
92 | * @profile the new profile. | ||
93 | */ | ||
94 | void InterfaceSetupImp::changeProfile(const QString &profile){ | ||
95 | QString newInterfaceName; | ||
96 | if(profile.lower() == "all") | ||
97 | newInterfaceName = interface->getInterfaceName(); | ||
98 | else | ||
99 | newInterfaceName = interface->getInterfaceName() + "_" + profile; | ||
100 | if(newInterfaceName == currentInterfaceName) | ||
101 | return; | ||
102 | else{ | ||
103 | saveSettings(); | ||
104 | currentInterfaceName = newInterfaceName; | ||
105 | } | ||
106 | bool error = interfaces->setInterface(currentInterfaceName); | ||
107 | |||
108 | // See if we have to make a interface. | ||
109 | if(error){ | ||
110 | qDebug("InterfaceSetupImp: Adding a new interface from profile change."); | ||
111 | interfaces->addInterface(currentInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | ||
112 | error = interfaces->setInterface(currentInterfaceName); | ||
113 | if(error){ | ||
114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | ||
115 | return; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | //qDebug( currentInterfaceName.latin1() ); | ||
120 | // We must have a valid interface to get this far so read some settings. | ||
121 | |||
122 | // DHCP | ||
123 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | ||
124 | dhcpCheckBox->setChecked(true); | ||
125 | else | ||
126 | dhcpCheckBox->setChecked(false); | ||
127 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | ||
128 | if(error) | ||
129 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | ||
130 | if(error) | ||
131 | leaseTime->setValue(24); | ||
132 | |||
133 | // IP Information | ||
134 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | ||
135 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); | ||
136 | if(dns.contains(" ")){ | ||
137 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | ||
138 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | ||
139 | } | ||
140 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | ||
141 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | ||
142 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | ||
143 | } | ||
144 | |||
145 | |||
146 | // interfacesetup.cpp | ||
147 | |||
diff --git a/noncore/net/networksetup/interfacesetupimp.h b/noncore/net/networksetup/interfacesetupimp.h new file mode 100644 index 0000000..6c34718 --- a/dev/null +++ b/noncore/net/networksetup/interfacesetupimp.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef INTERFACESETUPIMP_H | ||
2 | #define INTERFACESETUPIMP_H | ||
3 | |||
4 | #include "interfacesetup.h" | ||
5 | |||
6 | class Interface; | ||
7 | class Interfaces; | ||
8 | |||
9 | class InterfaceSetupImp : public InterfaceSetup { | ||
10 | Q_OBJECT | ||
11 | |||
12 | public: | ||
13 | InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0); | ||
14 | |||
15 | protected slots: | ||
16 | void accept(); | ||
17 | void changeProfile(const QString &profile); | ||
18 | |||
19 | private: | ||
20 | bool saveSettings(); | ||
21 | Interfaces *interfaces; | ||
22 | Interface *interface; | ||
23 | QString currentInterfaceName; | ||
24 | |||
25 | }; | ||
26 | |||
27 | #endif | ||
28 | |||
29 | // interfacesetupimp.h | ||
30 | |||
diff --git a/noncore/net/networksetup/kprocctrl.cpp b/noncore/net/networksetup/kprocctrl.cpp new file mode 100644 index 0000000..cd8711a --- a/dev/null +++ b/noncore/net/networksetup/kprocctrl.cpp | |||
@@ -0,0 +1,267 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | // | ||
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | ||
21 | // | ||
22 | // version 0.3.1, Jan, 8th 1997 | ||
23 | // | ||
24 | // (C) Christian Czezatke | ||
25 | // e9025461@student.tuwien.ac.at | ||
26 | // | ||
27 | |||
28 | //#include <config.h> | ||
29 | |||
30 | #include <sys/types.h> | ||
31 | #include <sys/socket.h> | ||
32 | |||
33 | #include <errno.h> | ||
34 | #include <fcntl.h> | ||
35 | #include <stdio.h> | ||
36 | #include <string.h> | ||
37 | #include <unistd.h> | ||
38 | #include <assert.h> | ||
39 | |||
40 | #include <qsocketnotifier.h> | ||
41 | #include "kprocess.h" | ||
42 | #include "kprocctrl.h" | ||
43 | |||
44 | KProcessController *KProcessController::theKProcessController = 0; | ||
45 | |||
46 | struct sigaction KProcessController::oldChildHandlerData; | ||
47 | bool KProcessController::handlerSet = false; | ||
48 | |||
49 | KProcessController::KProcessController() | ||
50 | { | ||
51 | assert( theKProcessController == 0 ); | ||
52 | |||
53 | if (0 > pipe(fd)) | ||
54 | printf(strerror(errno)); | ||
55 | |||
56 | notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); | ||
57 | notifier->setEnabled(true); | ||
58 | QObject::connect(notifier, SIGNAL(activated(int)), | ||
59 | this, SLOT(slotDoHousekeeping(int))); | ||
60 | connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), | ||
61 | SLOT( delayedChildrenCleanup())); | ||
62 | |||
63 | theKProcessController = this; | ||
64 | |||
65 | setupHandlers(); | ||
66 | } | ||
67 | |||
68 | |||
69 | void KProcessController::setupHandlers() | ||
70 | { | ||
71 | if( handlerSet ) | ||
72 | return; | ||
73 | struct sigaction act; | ||
74 | act.sa_handler=theSigCHLDHandler; | ||
75 | sigemptyset(&(act.sa_mask)); | ||
76 | sigaddset(&(act.sa_mask), SIGCHLD); | ||
77 | // Make sure we don't block this signal. gdb tends to do that :-( | ||
78 | sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); | ||
79 | |||
80 | act.sa_flags = SA_NOCLDSTOP; | ||
81 | |||
82 | // CC: take care of SunOS which automatically restarts interrupted system | ||
83 | // calls (and thus does not have SA_RESTART) | ||
84 | |||
85 | #ifdef SA_RESTART | ||
86 | act.sa_flags |= SA_RESTART; | ||
87 | #endif | ||
88 | |||
89 | sigaction( SIGCHLD, &act, &oldChildHandlerData ); | ||
90 | |||
91 | act.sa_handler=SIG_IGN; | ||
92 | sigemptyset(&(act.sa_mask)); | ||
93 | sigaddset(&(act.sa_mask), SIGPIPE); | ||
94 | act.sa_flags = 0; | ||
95 | sigaction( SIGPIPE, &act, 0L); | ||
96 | handlerSet = true; | ||
97 | } | ||
98 | |||
99 | void KProcessController::resetHandlers() | ||
100 | { | ||
101 | if( !handlerSet ) | ||
102 | return; | ||
103 | sigaction( SIGCHLD, &oldChildHandlerData, 0 ); | ||
104 | // there should be no problem with SIGPIPE staying SIG_IGN | ||
105 | handlerSet = false; | ||
106 | } | ||
107 | |||
108 | // block SIGCHLD handler, because it accesses processList | ||
109 | void KProcessController::addKProcess( KProcess* p ) | ||
110 | { | ||
111 | sigset_t newset, oldset; | ||
112 | sigemptyset( &newset ); | ||
113 | sigaddset( &newset, SIGCHLD ); | ||
114 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | ||
115 | processList.append( p ); | ||
116 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | ||
117 | } | ||
118 | |||
119 | void KProcessController::removeKProcess( KProcess* p ) | ||
120 | { | ||
121 | sigset_t newset, oldset; | ||
122 | sigemptyset( &newset ); | ||
123 | sigaddset( &newset, SIGCHLD ); | ||
124 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | ||
125 | processList.remove( p ); | ||
126 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | ||
127 | } | ||
128 | |||
129 | //using a struct which contains both the pid and the status makes it easier to write | ||
130 | //and read the data into the pipe | ||
131 | //especially this solves a problem which appeared on my box where slotDoHouseKeeping() received | ||
132 | //only 4 bytes (with some debug output around the write()'s it received all 8 bytes) | ||
133 | //don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX | ||
134 | struct waitdata | ||
135 | { | ||
136 | pid_t pid; | ||
137 | int status; | ||
138 | }; | ||
139 | |||
140 | void KProcessController::theSigCHLDHandler(int arg) | ||
141 | { | ||
142 | struct waitdata wd; | ||
143 | // int status; | ||
144 | // pid_t this_pid; | ||
145 | int saved_errno; | ||
146 | |||
147 | saved_errno = errno; | ||
148 | // since waitpid and write change errno, we have to save it and restore it | ||
149 | // (Richard Stevens, Advanced programming in the Unix Environment) | ||
150 | |||
151 | bool found = false; | ||
152 | if( theKProcessController != 0 ) { | ||
153 | // iterating the list doesn't perform any system call | ||
154 | for( QValueList<KProcess*>::ConstIterator it = theKProcessController->processList.begin(); | ||
155 | it != theKProcessController->processList.end(); | ||
156 | ++it ) | ||
157 | { | ||
158 | if( !(*it)->isRunning()) | ||
159 | continue; | ||
160 | wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG ); | ||
161 | if ( wd.pid > 0 ) { | ||
162 | ::write(theKProcessController->fd[1], &wd, sizeof(wd)); | ||
163 | found = true; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | if( !found && oldChildHandlerData.sa_handler != SIG_IGN | ||
168 | && oldChildHandlerData.sa_handler != SIG_DFL ) | ||
169 | oldChildHandlerData.sa_handler( arg ); // call the old handler | ||
170 | // handle the rest | ||
171 | if( theKProcessController != 0 ) { | ||
172 | static const struct waitdata dwd = { 0, 0 }; // delayed waitpid() | ||
173 | ::write(theKProcessController->fd[1], &dwd, sizeof(dwd)); | ||
174 | } else { | ||
175 | int dummy; | ||
176 | while( waitpid( -1, &dummy, WNOHANG ) > 0 ) | ||
177 | ; | ||
178 | } | ||
179 | |||
180 | errno = saved_errno; | ||
181 | } | ||
182 | |||
183 | |||
184 | |||
185 | void KProcessController::slotDoHousekeeping(int ) | ||
186 | { | ||
187 | unsigned int bytes_read = 0; | ||
188 | unsigned int errcnt=0; | ||
189 | // read pid and status from the pipe. | ||
190 | struct waitdata wd; | ||
191 | while ((bytes_read < sizeof(wd)) && (errcnt < 50)) { | ||
192 | int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read); | ||
193 | if (r > 0) bytes_read += r; | ||
194 | else if (r < 0) errcnt++; | ||
195 | } | ||
196 | if (errcnt >= 50) { | ||
197 | fprintf(stderr, | ||
198 | "Error: Max. error count for pipe read " | ||
199 | "exceeded in KProcessController::slotDoHousekeeping\n"); | ||
200 | return; // it makes no sense to continue here! | ||
201 | } | ||
202 | if (bytes_read != sizeof(wd)) { | ||
203 | fprintf(stderr, | ||
204 | "Error: Could not read info from signal handler %d <> %d!\n", | ||
205 | bytes_read, sizeof(wd)); | ||
206 | return; // it makes no sense to continue here! | ||
207 | } | ||
208 | if (wd.pid==0) { // special case, see delayedChildrenCleanup() | ||
209 | delayedChildrenCleanupTimer.start( 1000, true ); | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | for( QValueList<KProcess*>::ConstIterator it = processList.begin(); | ||
214 | it != processList.end(); | ||
215 | ++it ) { | ||
216 | KProcess* proc = *it; | ||
217 | if (proc->pid() == wd.pid) { | ||
218 | // process has exited, so do emit the respective events | ||
219 | if (proc->run_mode == KProcess::Block) { | ||
220 | // If the reads are done blocking then set the status in proc | ||
221 | // but do nothing else because KProcess will perform the other | ||
222 | // actions of processHasExited. | ||
223 | proc->status = wd.status; | ||
224 | proc->runs = false; | ||
225 | } else { | ||
226 | proc->processHasExited(wd.status); | ||
227 | } | ||
228 | return; | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | // this is needed e.g. for popen(), which calls waitpid() checking | ||
234 | // for its forked child, if we did waitpid() directly in the SIGCHLD | ||
235 | // handler, popen()'s waitpid() call would fail | ||
236 | void KProcessController::delayedChildrenCleanup() | ||
237 | { | ||
238 | struct waitdata wd; | ||
239 | while(( wd.pid = waitpid( -1, &wd.status, WNOHANG ) ) > 0 ) { | ||
240 | for( QValueList<KProcess*>::ConstIterator it = processList.begin(); | ||
241 | it != processList.end(); | ||
242 | ++it ) | ||
243 | { | ||
244 | if( !(*it)->isRunning() || (*it)->pid() != wd.pid ) | ||
245 | continue; | ||
246 | // it's KProcess, handle it | ||
247 | ::write(fd[1], &wd, sizeof(wd)); | ||
248 | break; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | KProcessController::~KProcessController() | ||
254 | { | ||
255 | assert( theKProcessController == this ); | ||
256 | resetHandlers(); | ||
257 | |||
258 | notifier->setEnabled(false); | ||
259 | |||
260 | close(fd[0]); | ||
261 | close(fd[1]); | ||
262 | |||
263 | delete notifier; | ||
264 | theKProcessController = 0; | ||
265 | } | ||
266 | |||
267 | //#include "kprocctrl.moc" | ||
diff --git a/noncore/net/networksetup/kprocctrl.h b/noncore/net/networksetup/kprocctrl.h new file mode 100644 index 0000000..ac82b9d --- a/dev/null +++ b/noncore/net/networksetup/kprocctrl.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | // | ||
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | ||
21 | // | ||
22 | // version 0.3.1, Jan 8th 1997 | ||
23 | // | ||
24 | // (C) Christian Czezatke | ||
25 | // e9025461@student.tuwien.ac.at | ||
26 | // | ||
27 | |||
28 | #ifndef __KPROCCTRL_H__ | ||
29 | #define __KPROCCTRL_H__ | ||
30 | |||
31 | #include <qvaluelist.h> | ||
32 | #include <qtimer.h> | ||
33 | |||
34 | #include "kprocess.h" | ||
35 | |||
36 | class KProcessControllerPrivate; | ||
37 | class QSocketNotifier; | ||
38 | |||
39 | /** | ||
40 | * @short Used internally by @ref KProcess | ||
41 | * @internal | ||
42 | * @author Christian Czezakte <e9025461@student.tuwien.ac.at> | ||
43 | * | ||
44 | * A class for internal use by KProcess only. -- Exactly one instance | ||
45 | * of this class is generated by the first instance of KProcess that is | ||
46 | * created (a pointer to it gets stored in @ref theKProcessController ). | ||
47 | * | ||
48 | * This class takes care of the actual (UN*X) signal handling. | ||
49 | */ | ||
50 | class KProcessController : public QObject | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | |||
54 | public: | ||
55 | KProcessController(); | ||
56 | ~KProcessController(); | ||
57 | //CC: WARNING! Destructor Not virtual (but you don't derive classes from this anyhow...) | ||
58 | |||
59 | public: | ||
60 | |||
61 | /** | ||
62 | * Only a single instance of this class is allowed at a time, | ||
63 | * and this static variable is used to track the one instance. | ||
64 | */ | ||
65 | static KProcessController *theKProcessController; | ||
66 | |||
67 | /** | ||
68 | * Automatically called upon SIGCHLD. | ||
69 | * | ||
70 | * Normally you do not need to do anything with this function but | ||
71 | * if your application needs to disable SIGCHLD for some time for | ||
72 | * reasons beyond your control, you should call this function afterwards | ||
73 | * to make sure that no SIGCHLDs where missed. | ||
74 | */ | ||
75 | static void theSigCHLDHandler(int signal); | ||
76 | // handler for sigchld | ||
77 | |||
78 | /** | ||
79 | * @internal | ||
80 | */ | ||
81 | static void setupHandlers(); | ||
82 | /** | ||
83 | * @internal | ||
84 | */ | ||
85 | static void resetHandlers(); | ||
86 | /** | ||
87 | * @internal | ||
88 | */ | ||
89 | void addKProcess( KProcess* ); | ||
90 | /** | ||
91 | * @internal | ||
92 | */ | ||
93 | void removeKProcess( KProcess* ); | ||
94 | public slots: | ||
95 | /** | ||
96 | * @internal | ||
97 | */ | ||
98 | void slotDoHousekeeping(int socket); | ||
99 | |||
100 | private slots: | ||
101 | void delayedChildrenCleanup(); | ||
102 | private: | ||
103 | int fd[2]; | ||
104 | QSocketNotifier *notifier; | ||
105 | static struct sigaction oldChildHandlerData; | ||
106 | static bool handlerSet; | ||
107 | QValueList<KProcess*> processList; | ||
108 | QTimer delayedChildrenCleanupTimer; | ||
109 | |||
110 | // Disallow assignment and copy-construction | ||
111 | KProcessController( const KProcessController& ); | ||
112 | KProcessController& operator= ( const KProcessController& ); | ||
113 | |||
114 | KProcessControllerPrivate *d; | ||
115 | }; | ||
116 | |||
117 | |||
118 | |||
119 | #endif | ||
120 | |||
diff --git a/noncore/net/networksetup/kprocess.cpp b/noncore/net/networksetup/kprocess.cpp new file mode 100644 index 0000000..193ec9b --- a/dev/null +++ b/noncore/net/networksetup/kprocess.cpp | |||
@@ -0,0 +1,919 @@ | |||
1 | /* | ||
2 | |||
3 | $Id$ | ||
4 | |||
5 | This file is part of the KDE libraries | ||
6 | Copyright (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Library General Public | ||
10 | License as published by the Free Software Foundation; either | ||
11 | version 2 of the License, or (at your option) any later version. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Library General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Library General Public License | ||
19 | along with this library; see the file COPYING.LIB. If not, write to | ||
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
21 | Boston, MA 02111-1307, USA. | ||
22 | */ | ||
23 | |||
24 | |||
25 | // | ||
26 | // KPROCESS -- A class for handling child processes in KDE without | ||
27 | // having to take care of Un*x specific implementation details | ||
28 | // | ||
29 | // version 0.3.1, Jan 8th 1998 | ||
30 | // | ||
31 | // (C) Christian Czezatke | ||
32 | // e9025461@student.tuwien.ac.at | ||
33 | // | ||
34 | // Changes: | ||
35 | // | ||
36 | // March 2nd, 1998: Changed parameter list for KShellProcess: | ||
37 | // Arguments are now placed in a single string so that | ||
38 | // <shell> -c <commandstring> is passed to the shell | ||
39 | // to make the use of "operator<<" consistent with KProcess | ||
40 | |||
41 | #include "kprocess.h" | ||
42 | #define _MAY_INCLUDE_KPROCESSCONTROLLER_ | ||
43 | #include "kprocctrl.h" | ||
44 | |||
45 | //#include <config.h> | ||
46 | |||
47 | #include <qglobal.h> | ||
48 | #include <qmap.h> | ||
49 | #include <qfile.h> | ||
50 | #include <qsocketnotifier.h> | ||
51 | #include <qregexp.h> | ||
52 | |||
53 | #include <sys/time.h> | ||
54 | #include <sys/types.h> | ||
55 | #include <sys/stat.h> | ||
56 | #include <sys/socket.h> | ||
57 | |||
58 | #include <errno.h> | ||
59 | #include <fcntl.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <signal.h> | ||
62 | #include <stdio.h> | ||
63 | #include <string.h> | ||
64 | #include <unistd.h> | ||
65 | #ifdef HAVE_SYS_SELECT_H | ||
66 | #include <sys/select.h> | ||
67 | #endif | ||
68 | #ifdef HAVE_INITGROUPS | ||
69 | #include <grp.h> | ||
70 | #endif | ||
71 | #include <pwd.h> | ||
72 | |||
73 | #include <qapplication.h> | ||
74 | //#include <kdebug.h> | ||
75 | |||
76 | ///////////////////////////// | ||
77 | // public member functions // | ||
78 | ///////////////////////////// | ||
79 | |||
80 | class KProcessPrivate { | ||
81 | public: | ||
82 | KProcessPrivate() : useShell(false) { } | ||
83 | |||
84 | bool useShell; | ||
85 | QMap<QString,QString> env; | ||
86 | QString wd; | ||
87 | QCString shell; | ||
88 | }; | ||
89 | |||
90 | #define Q_CHECK_PTR(a) | ||
91 | |||
92 | KProcess::KProcess() | ||
93 | : QObject(), | ||
94 | run_mode(NotifyOnExit), | ||
95 | runs(false), | ||
96 | pid_(0), | ||
97 | status(0), | ||
98 | keepPrivs(false), | ||
99 | innot(0), | ||
100 | outnot(0), | ||
101 | errnot(0), | ||
102 | communication(NoCommunication), | ||
103 | input_data(0), | ||
104 | input_sent(0), | ||
105 | input_total(0), | ||
106 | d(0) | ||
107 | { | ||
108 | if (0 == KProcessController::theKProcessController) { | ||
109 | (void) new KProcessController(); | ||
110 | Q_CHECK_PTR(KProcessController::theKProcessController); | ||
111 | } | ||
112 | |||
113 | KProcessController::theKProcessController->addKProcess(this); | ||
114 | out[0] = out[1] = -1; | ||
115 | in[0] = in[1] = -1; | ||
116 | err[0] = err[1] = -1; | ||
117 | } | ||
118 | |||
119 | void | ||
120 | KProcess::setEnvironment(const QString &name, const QString &value) | ||
121 | { | ||
122 | if (!d) | ||
123 | d = new KProcessPrivate; | ||
124 | d->env.insert(name, value); | ||
125 | } | ||
126 | |||
127 | void | ||
128 | KProcess::setWorkingDirectory(const QString &dir) | ||
129 | { | ||
130 | if (!d) | ||
131 | d = new KProcessPrivate; | ||
132 | d->wd = dir; | ||
133 | } | ||
134 | |||
135 | void | ||
136 | KProcess::setupEnvironment() | ||
137 | { | ||
138 | if (d) | ||
139 | { | ||
140 | QMap<QString,QString>::Iterator it; | ||
141 | for(it = d->env.begin(); it != d->env.end(); ++it) | ||
142 | setenv(QFile::encodeName(it.key()).data(), | ||
143 | QFile::encodeName(it.data()).data(), 1); | ||
144 | if (!d->wd.isEmpty()) | ||
145 | chdir(QFile::encodeName(d->wd).data()); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | void | ||
150 | KProcess::setRunPrivileged(bool keepPrivileges) | ||
151 | { | ||
152 | keepPrivs = keepPrivileges; | ||
153 | } | ||
154 | |||
155 | bool | ||
156 | KProcess::runPrivileged() const | ||
157 | { | ||
158 | return keepPrivs; | ||
159 | } | ||
160 | |||
161 | |||
162 | KProcess::~KProcess() | ||
163 | { | ||
164 | // destroying the KProcess instance sends a SIGKILL to the | ||
165 | // child process (if it is running) after removing it from the | ||
166 | // list of valid processes (if the process is not started as | ||
167 | // "DontCare") | ||
168 | |||
169 | KProcessController::theKProcessController->removeKProcess(this); | ||
170 | // this must happen before we kill the child | ||
171 | // TODO: block the signal while removing the current process from the process list | ||
172 | |||
173 | if (runs && (run_mode != DontCare)) | ||
174 | kill(SIGKILL); | ||
175 | |||
176 | // Clean up open fd's and socket notifiers. | ||
177 | closeStdin(); | ||
178 | closeStdout(); | ||
179 | closeStderr(); | ||
180 | |||
181 | // TODO: restore SIGCHLD and SIGPIPE handler if this is the last KProcess | ||
182 | delete d; | ||
183 | } | ||
184 | |||
185 | void KProcess::detach() | ||
186 | { | ||
187 | KProcessController::theKProcessController->removeKProcess(this); | ||
188 | |||
189 | runs = false; | ||
190 | pid_ = 0; | ||
191 | |||
192 | // Clean up open fd's and socket notifiers. | ||
193 | closeStdin(); | ||
194 | closeStdout(); | ||
195 | closeStderr(); | ||
196 | } | ||
197 | |||
198 | bool KProcess::setExecutable(const QString& proc) | ||
199 | { | ||
200 | if (runs) return false; | ||
201 | |||
202 | if (proc.isEmpty()) return false; | ||
203 | |||
204 | if (!arguments.isEmpty()) | ||
205 | arguments.remove(arguments.begin()); | ||
206 | arguments.prepend(QFile::encodeName(proc)); | ||
207 | |||
208 | return true; | ||
209 | } | ||
210 | |||
211 | KProcess &KProcess::operator<<(const QStringList& args) | ||
212 | { | ||
213 | QStringList::ConstIterator it = args.begin(); | ||
214 | for ( ; it != args.end() ; ++it ) | ||
215 | arguments.append(QFile::encodeName(*it)); | ||
216 | return *this; | ||
217 | } | ||
218 | |||
219 | KProcess &KProcess::operator<<(const QCString& arg) | ||
220 | { | ||
221 | return operator<< (arg.data()); | ||
222 | } | ||
223 | |||
224 | KProcess &KProcess::operator<<(const char* arg) | ||
225 | { | ||
226 | arguments.append(arg); | ||
227 | return *this; | ||
228 | } | ||
229 | |||
230 | KProcess &KProcess::operator<<(const QString& arg) | ||
231 | { | ||
232 | arguments.append(QFile::encodeName(arg)); | ||
233 | return *this; | ||
234 | } | ||
235 | |||
236 | void KProcess::clearArguments() | ||
237 | { | ||
238 | arguments.clear(); | ||
239 | } | ||
240 | |||
241 | bool KProcess::start(RunMode runmode, Communication comm) | ||
242 | { | ||
243 | uint i; | ||
244 | uint n = arguments.count(); | ||
245 | char **arglist; | ||
246 | |||
247 | if (runs || (0 == n)) { | ||
248 | return false; // cannot start a process that is already running | ||
249 | // or if no executable has been assigned | ||
250 | } | ||
251 | run_mode = runmode; | ||
252 | status = 0; | ||
253 | |||
254 | QCString shellCmd; | ||
255 | if (d && d->useShell) | ||
256 | { | ||
257 | if (d->shell.isEmpty()) | ||
258 | { | ||
259 | //kdDebug() << "Could not find a valid shell\n" << endl; | ||
260 | return false; | ||
261 | } | ||
262 | |||
263 | arglist = static_cast<char **>(malloc( (4)*sizeof(char *))); | ||
264 | for (i=0; i < n; i++) { | ||
265 | shellCmd += arguments[i]; | ||
266 | shellCmd += " "; // CC: to separate the arguments | ||
267 | } | ||
268 | |||
269 | arglist[0] = d->shell.data(); | ||
270 | arglist[1] = (char *) "-c"; | ||
271 | arglist[2] = shellCmd.data(); | ||
272 | arglist[3] = 0; | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | arglist = static_cast<char **>(malloc( (n+1)*sizeof(char *))); | ||
277 | for (i=0; i < n; i++) | ||
278 | arglist[i] = arguments[i].data(); | ||
279 | arglist[n]= 0; | ||
280 | } | ||
281 | |||
282 | setupCommunication(comm); | ||
283 | //) | ||
284 | //kdDebug() << "Could not setup Communication!\n"; | ||
285 | |||
286 | // We do this in the parent because if we do it in the child process | ||
287 | // gdb gets confused when the application runs from gdb. | ||
288 | uid_t uid = getuid(); | ||
289 | gid_t gid = getgid(); | ||
290 | #ifdef HAVE_INITGROUPS | ||
291 | struct passwd *pw = getpwuid(uid); | ||
292 | #endif | ||
293 | |||
294 | int fd[2]; | ||
295 | if (0 > pipe(fd)) | ||
296 | { | ||
297 | fd[0] = fd[1] = 0; // Pipe failed.. continue | ||
298 | } | ||
299 | |||
300 | runs = true; | ||
301 | |||
302 | QApplication::flushX(); | ||
303 | |||
304 | // WABA: Note that we use fork() and not vfork() because | ||
305 | // vfork() has unclear semantics and is not standardized. | ||
306 | pid_ = fork(); | ||
307 | |||
308 | if (0 == pid_) { | ||
309 | if (fd[0]) | ||
310 | close(fd[0]); | ||
311 | if (!runPrivileged()) | ||
312 | { | ||
313 | setgid(gid); | ||
314 | #if defined( HAVE_INITGROUPS) | ||
315 | if(pw) | ||
316 | initgroups(pw->pw_name, pw->pw_gid); | ||
317 | #endif | ||
318 | setuid(uid); | ||
319 | } | ||
320 | // The child process | ||
321 | commSetupDoneC(); | ||
322 | //) | ||
323 | //kdDebug() << "Could not finish comm setup in child!" << endl; | ||
324 | |||
325 | setupEnvironment(); | ||
326 | |||
327 | // Matthias | ||
328 | if (run_mode == DontCare) | ||
329 | setpgid(0,0); | ||
330 | // restore default SIGPIPE handler (Harri) | ||
331 | struct sigaction act; | ||
332 | sigemptyset(&(act.sa_mask)); | ||
333 | sigaddset(&(act.sa_mask), SIGPIPE); | ||
334 | act.sa_handler = SIG_DFL; | ||
335 | act.sa_flags = 0; | ||
336 | sigaction(SIGPIPE, &act, 0L); | ||
337 | |||
338 | // We set the close on exec flag. | ||
339 | // Closing of fd[1] indicates that the execvp succeeded! | ||
340 | if (fd[1]) | ||
341 | fcntl(fd[1], F_SETFD, FD_CLOEXEC); | ||
342 | execvp(arglist[0], arglist); | ||
343 | char resultByte = 1; | ||
344 | if (fd[1]) | ||
345 | write(fd[1], &resultByte, 1); | ||
346 | _exit(-1); | ||
347 | } else if (-1 == pid_) { | ||
348 | // forking failed | ||
349 | |||
350 | runs = false; | ||
351 | free(arglist); | ||
352 | return false; | ||
353 | } else { | ||
354 | if (fd[1]) | ||
355 | close(fd[1]); | ||
356 | // the parent continues here | ||
357 | |||
358 | // Discard any data for stdin that might still be there | ||
359 | input_data = 0; | ||
360 | |||
361 | // Check whether client could be started. | ||
362 | if (fd[0]) for(;;) | ||
363 | { | ||
364 | char resultByte; | ||
365 | int n = ::read(fd[0], &resultByte, 1); | ||
366 | if (n == 1) | ||
367 | { | ||
368 | // Error | ||
369 | runs = false; | ||
370 | close(fd[0]); | ||
371 | free(arglist); | ||
372 | pid_ = 0; | ||
373 | return false; | ||
374 | } | ||
375 | if (n == -1) | ||
376 | { | ||
377 | if ((errno == ECHILD) || (errno == EINTR)) | ||
378 | continue; // Ignore | ||
379 | } | ||
380 | break; // success | ||
381 | } | ||
382 | if (fd[0]) | ||
383 | close(fd[0]); | ||
384 | |||
385 | if (!commSetupDoneP()){} // finish communication socket setup for the parent | ||
386 | //kdDebug() << "Could not finish comm setup in parent!" << endl; | ||
387 | |||
388 | if (run_mode == Block) { | ||
389 | commClose(); | ||
390 | |||
391 | // The SIGCHLD handler of the process controller will catch | ||
392 | // the exit and set the status | ||
393 | while(runs) | ||
394 | { | ||
395 | KProcessController::theKProcessController-> | ||
396 | slotDoHousekeeping(0); | ||
397 | } | ||
398 | runs = FALSE; | ||
399 | emit processExited(this); | ||
400 | } | ||
401 | } | ||
402 | free(arglist); | ||
403 | return true; | ||
404 | } | ||
405 | |||
406 | |||
407 | |||
408 | bool KProcess::kill(int signo) | ||
409 | { | ||
410 | bool rv=false; | ||
411 | |||
412 | if (0 != pid_) | ||
413 | rv= (-1 != ::kill(pid_, signo)); | ||
414 | // probably store errno somewhere... | ||
415 | return rv; | ||
416 | } | ||
417 | |||
418 | |||
419 | |||
420 | bool KProcess::isRunning() const | ||
421 | { | ||
422 | return runs; | ||
423 | } | ||
424 | |||
425 | |||
426 | |||
427 | pid_t KProcess::pid() const | ||
428 | { | ||
429 | return pid_; | ||
430 | } | ||
431 | |||
432 | |||
433 | |||
434 | bool KProcess::normalExit() const | ||
435 | { | ||
436 | int _status = status; | ||
437 | return (pid_ != 0) && (!runs) && (WIFEXITED((_status))); | ||
438 | } | ||
439 | |||
440 | |||
441 | |||
442 | int KProcess::exitStatus() const | ||
443 | { | ||
444 | int _status = status; | ||
445 | return WEXITSTATUS((_status)); | ||
446 | } | ||
447 | |||
448 | |||
449 | |||
450 | bool KProcess::writeStdin(const char *buffer, int buflen) | ||
451 | { | ||
452 | bool rv; | ||
453 | |||
454 | // if there is still data pending, writing new data | ||
455 | // to stdout is not allowed (since it could also confuse | ||
456 | // kprocess... | ||
457 | if (0 != input_data) | ||
458 | return false; | ||
459 | |||
460 | if (runs && (communication & Stdin)) { | ||
461 | input_data = buffer; | ||
462 | input_sent = 0; | ||
463 | input_total = buflen; | ||
464 | slotSendData(0); | ||
465 | innot->setEnabled(true); | ||
466 | rv = true; | ||
467 | } else | ||
468 | rv = false; | ||
469 | return rv; | ||
470 | } | ||
471 | |||
472 | void KProcess::suspend() | ||
473 | { | ||
474 | if ((communication & Stdout) && outnot) | ||
475 | outnot->setEnabled(false); | ||
476 | } | ||
477 | |||
478 | void KProcess::resume() | ||
479 | { | ||
480 | if ((communication & Stdout) && outnot) | ||
481 | outnot->setEnabled(true); | ||
482 | } | ||
483 | |||
484 | bool KProcess::closeStdin() | ||
485 | { | ||
486 | bool rv; | ||
487 | |||
488 | if (communication & Stdin) { | ||
489 | communication = (Communication) (communication & ~Stdin); | ||
490 | delete innot; | ||
491 | innot = 0; | ||
492 | close(in[1]); | ||
493 | rv = true; | ||
494 | } else | ||
495 | rv = false; | ||
496 | return rv; | ||
497 | } | ||
498 | |||
499 | bool KProcess::closeStdout() | ||
500 | { | ||
501 | bool rv; | ||
502 | |||
503 | if (communication & Stdout) { | ||
504 | communication = (Communication) (communication & ~Stdout); | ||
505 | delete outnot; | ||
506 | outnot = 0; | ||
507 | close(out[0]); | ||
508 | rv = true; | ||
509 | } else | ||
510 | rv = false; | ||
511 | return rv; | ||
512 | } | ||
513 | |||
514 | bool KProcess::closeStderr() | ||
515 | { | ||
516 | bool rv; | ||
517 | |||
518 | if (communication & Stderr) { | ||
519 | communication = static_cast<Communication>(communication & ~Stderr); | ||
520 | delete errnot; | ||
521 | errnot = 0; | ||
522 | close(err[0]); | ||
523 | rv = true; | ||
524 | } else | ||
525 | rv = false; | ||
526 | return rv; | ||
527 | } | ||
528 | |||
529 | |||
530 | ///////////////////////////// | ||
531 | // protected slots // | ||
532 | ///////////////////////////// | ||
533 | |||
534 | |||
535 | |||
536 | void KProcess::slotChildOutput(int fdno) | ||
537 | { | ||
538 | if (!childOutput(fdno)) | ||
539 | closeStdout(); | ||
540 | } | ||
541 | |||
542 | |||
543 | void KProcess::slotChildError(int fdno) | ||
544 | { | ||
545 | if (!childError(fdno)) | ||
546 | closeStderr(); | ||
547 | } | ||
548 | |||
549 | |||
550 | void KProcess::slotSendData(int) | ||
551 | { | ||
552 | if (input_sent == input_total) { | ||
553 | innot->setEnabled(false); | ||
554 | input_data = 0; | ||
555 | emit wroteStdin(this); | ||
556 | } else | ||
557 | input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent); | ||
558 | } | ||
559 | |||
560 | |||
561 | |||
562 | ////////////////////////////// | ||
563 | // private member functions // | ||
564 | ////////////////////////////// | ||
565 | |||
566 | |||
567 | |||
568 | void KProcess::processHasExited(int state) | ||
569 | { | ||
570 | if (runs) | ||
571 | { | ||
572 | runs = false; | ||
573 | status = state; | ||
574 | |||
575 | commClose(); // cleanup communication sockets | ||
576 | |||
577 | // also emit a signal if the process was run Blocking | ||
578 | if (DontCare != run_mode) | ||
579 | { | ||
580 | emit processExited(this); | ||
581 | } | ||
582 | } | ||
583 | } | ||
584 | |||
585 | |||
586 | |||
587 | int KProcess::childOutput(int fdno) | ||
588 | { | ||
589 | if (communication & NoRead) { | ||
590 | int len = -1; | ||
591 | emit receivedStdout(fdno, len); | ||
592 | errno = 0; // Make sure errno doesn't read "EAGAIN" | ||
593 | return len; | ||
594 | } | ||
595 | else | ||
596 | { | ||
597 | char buffer[1024]; | ||
598 | int len; | ||
599 | |||
600 | len = ::read(fdno, buffer, 1024); | ||
601 | |||
602 | if ( 0 < len) { | ||
603 | emit receivedStdout(this, buffer, len); | ||
604 | } | ||
605 | return len; | ||
606 | } | ||
607 | } | ||
608 | |||
609 | |||
610 | |||
611 | int KProcess::childError(int fdno) | ||
612 | { | ||
613 | char buffer[1024]; | ||
614 | int len; | ||
615 | |||
616 | len = ::read(fdno, buffer, 1024); | ||
617 | |||
618 | if ( 0 < len) | ||
619 | emit receivedStderr(this, buffer, len); | ||
620 | return len; | ||
621 | } | ||
622 | |||
623 | |||
624 | |||
625 | int KProcess::setupCommunication(Communication comm) | ||
626 | { | ||
627 | int ok; | ||
628 | |||
629 | communication = comm; | ||
630 | |||
631 | ok = 1; | ||
632 | if (comm & Stdin) | ||
633 | ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, in) >= 0; | ||
634 | |||
635 | if (comm & Stdout) | ||
636 | ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, out) >= 0; | ||
637 | |||
638 | if (comm & Stderr) | ||
639 | ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0; | ||
640 | |||
641 | return ok; | ||
642 | } | ||
643 | |||
644 | |||
645 | |||
646 | int KProcess::commSetupDoneP() | ||
647 | { | ||
648 | int ok = 1; | ||
649 | |||
650 | if (communication != NoCommunication) { | ||
651 | if (communication & Stdin) | ||
652 | close(in[0]); | ||
653 | if (communication & Stdout) | ||
654 | close(out[1]); | ||
655 | if (communication & Stderr) | ||
656 | close(err[1]); | ||
657 | |||
658 | // Don't create socket notifiers and set the sockets non-blocking if | ||
659 | // blocking is requested. | ||
660 | if (run_mode == Block) return ok; | ||
661 | |||
662 | if (communication & Stdin) { | ||
663 | // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); | ||
664 | innot = new QSocketNotifier(in[1], QSocketNotifier::Write, this); | ||
665 | Q_CHECK_PTR(innot); | ||
666 | innot->setEnabled(false); // will be enabled when data has to be sent | ||
667 | QObject::connect(innot, SIGNAL(activated(int)), | ||
668 | this, SLOT(slotSendData(int))); | ||
669 | } | ||
670 | |||
671 | if (communication & Stdout) { | ||
672 | // ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK)); | ||
673 | outnot = new QSocketNotifier(out[0], QSocketNotifier::Read, this); | ||
674 | Q_CHECK_PTR(outnot); | ||
675 | QObject::connect(outnot, SIGNAL(activated(int)), | ||
676 | this, SLOT(slotChildOutput(int))); | ||
677 | if (communication & NoRead) | ||
678 | suspend(); | ||
679 | } | ||
680 | |||
681 | if (communication & Stderr) { | ||
682 | // ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK)); | ||
683 | errnot = new QSocketNotifier(err[0], QSocketNotifier::Read, this ); | ||
684 | Q_CHECK_PTR(errnot); | ||
685 | QObject::connect(errnot, SIGNAL(activated(int)), | ||
686 | this, SLOT(slotChildError(int))); | ||
687 | } | ||
688 | } | ||
689 | return ok; | ||
690 | } | ||
691 | |||
692 | |||
693 | |||
694 | int KProcess::commSetupDoneC() | ||
695 | { | ||
696 | int ok = 1; | ||
697 | struct linger so; | ||
698 | memset(&so, 0, sizeof(so)); | ||
699 | |||
700 | if (communication & Stdin) | ||
701 | close(in[1]); | ||
702 | if (communication & Stdout) | ||
703 | close(out[0]); | ||
704 | if (communication & Stderr) | ||
705 | close(err[0]); | ||
706 | |||
707 | if (communication & Stdin) | ||
708 | ok &= dup2(in[0], STDIN_FILENO) != -1; | ||
709 | else { | ||
710 | int null_fd = open( "/dev/null", O_RDONLY ); | ||
711 | ok &= dup2( null_fd, STDIN_FILENO ) != -1; | ||
712 | close( null_fd ); | ||
713 | } | ||
714 | if (communication & Stdout) { | ||
715 | ok &= dup2(out[1], STDOUT_FILENO) != -1; | ||
716 | ok &= !setsockopt(out[1], SOL_SOCKET, SO_LINGER, (char*)&so, sizeof(so)); | ||
717 | } | ||
718 | else { | ||
719 | int null_fd = open( "/dev/null", O_WRONLY ); | ||
720 | ok &= dup2( null_fd, STDOUT_FILENO ) != -1; | ||
721 | close( null_fd ); | ||
722 | } | ||
723 | if (communication & Stderr) { | ||
724 | ok &= dup2(err[1], STDERR_FILENO) != -1; | ||
725 | ok &= !setsockopt(err[1], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>(&so), sizeof(so)); | ||
726 | } | ||
727 | else { | ||
728 | int null_fd = open( "/dev/null", O_WRONLY ); | ||
729 | ok &= dup2( null_fd, STDERR_FILENO ) != -1; | ||
730 | close( null_fd ); | ||
731 | } | ||
732 | return ok; | ||
733 | } | ||
734 | |||
735 | |||
736 | |||
737 | void KProcess::commClose() | ||
738 | { | ||
739 | if (NoCommunication != communication) { | ||
740 | bool b_in = (communication & Stdin); | ||
741 | bool b_out = (communication & Stdout); | ||
742 | bool b_err = (communication & Stderr); | ||
743 | if (b_in) | ||
744 | delete innot; | ||
745 | |||
746 | if (b_out || b_err) { | ||
747 | // If both channels are being read we need to make sure that one socket buffer | ||
748 | // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). | ||
749 | // Hence we need to use select. | ||
750 | |||
751 | // Once one or other of the channels has reached EOF (or given an error) go back | ||
752 | // to the usual mechanism. | ||
753 | |||
754 | int fds_ready = 1; | ||
755 | fd_set rfds; | ||
756 | |||
757 | int max_fd = 0; | ||
758 | if (b_out) { | ||
759 | fcntl(out[0], F_SETFL, O_NONBLOCK); | ||
760 | if (out[0] > max_fd) | ||
761 | max_fd = out[0]; | ||
762 | delete outnot; | ||
763 | outnot = 0; | ||
764 | } | ||
765 | if (b_err) { | ||
766 | fcntl(err[0], F_SETFL, O_NONBLOCK); | ||
767 | if (err[0] > max_fd) | ||
768 | max_fd = err[0]; | ||
769 | delete errnot; | ||
770 | errnot = 0; | ||
771 | } | ||
772 | |||
773 | |||
774 | while (b_out || b_err) { | ||
775 | // * If the process is still running we block until we | ||
776 | // receive data. (p_timeout = 0, no timeout) | ||
777 | // * If the process has already exited, we only check | ||
778 | // the available data, we don't wait for more. | ||
779 | // (p_timeout = &timeout, timeout immediately) | ||
780 | struct timeval timeout; | ||
781 | timeout.tv_sec = 0; | ||
782 | timeout.tv_usec = 0; | ||
783 | struct timeval *p_timeout = runs ? 0 : &timeout; | ||
784 | |||
785 | FD_ZERO(&rfds); | ||
786 | if (b_out) | ||
787 | FD_SET(out[0], &rfds); | ||
788 | |||
789 | if (b_err) | ||
790 | FD_SET(err[0], &rfds); | ||
791 | |||
792 | fds_ready = select(max_fd+1, &rfds, 0, 0, p_timeout); | ||
793 | if (fds_ready <= 0) break; | ||
794 | |||
795 | if (b_out && FD_ISSET(out[0], &rfds)) { | ||
796 | int ret = 1; | ||
797 | while (ret > 0) ret = childOutput(out[0]); | ||
798 | if ((ret == -1 && errno != EAGAIN) || ret == 0) | ||
799 | b_out = false; | ||
800 | } | ||
801 | |||
802 | if (b_err && FD_ISSET(err[0], &rfds)) { | ||
803 | int ret = 1; | ||
804 | while (ret > 0) ret = childError(err[0]); | ||
805 | if ((ret == -1 && errno != EAGAIN) || ret == 0) | ||
806 | b_err = false; | ||
807 | } | ||
808 | } | ||
809 | } | ||
810 | |||
811 | if (b_in) { | ||
812 | communication = (Communication) (communication & ~Stdin); | ||
813 | close(in[1]); | ||
814 | } | ||
815 | if (b_out) { | ||
816 | communication = (Communication) (communication & ~Stdout); | ||
817 | close(out[0]); | ||
818 | } | ||
819 | if (b_err) { | ||
820 | communication = (Communication) (communication & ~Stderr); | ||
821 | close(err[0]); | ||
822 | } | ||
823 | } | ||
824 | } | ||
825 | |||
826 | void KProcess::setUseShell(bool useShell, const char *shell) | ||
827 | { | ||
828 | if (!d) | ||
829 | d = new KProcessPrivate; | ||
830 | d->useShell = useShell; | ||
831 | d->shell = shell; | ||
832 | if (d->shell.isEmpty()) | ||
833 | d->shell = searchShell(); | ||
834 | } | ||
835 | |||
836 | QString KProcess::quote(const QString &arg) | ||
837 | { | ||
838 | QString res = arg; | ||
839 | res.replace(QRegExp(QString::fromLatin1("\'")), | ||
840 | QString::fromLatin1("'\"'\"'")); | ||
841 | res.prepend('\''); | ||
842 | res.append('\''); | ||
843 | return res; | ||
844 | } | ||
845 | |||
846 | QCString KProcess::searchShell() | ||
847 | { | ||
848 | QCString tmpShell = QCString(getenv("SHELL")).stripWhiteSpace(); | ||
849 | if (!isExecutable(tmpShell)) | ||
850 | { | ||
851 | tmpShell = "/bin/sh"; | ||
852 | } | ||
853 | |||
854 | return tmpShell; | ||
855 | } | ||
856 | |||
857 | bool KProcess::isExecutable(const QCString &filename) | ||
858 | { | ||
859 | struct stat fileinfo; | ||
860 | |||
861 | if (filename.isEmpty()) return false; | ||
862 | |||
863 | // CC: we've got a valid filename, now let's see whether we can execute that file | ||
864 | |||
865 | if (-1 == stat(filename.data(), &fileinfo)) return false; | ||
866 | // CC: return false if the file does not exist | ||
867 | |||
868 | // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets | ||
869 | if ( (S_ISDIR(fileinfo.st_mode)) || | ||
870 | (S_ISCHR(fileinfo.st_mode)) || | ||
871 | (S_ISBLK(fileinfo.st_mode)) || | ||
872 | #ifdef S_ISSOCK | ||
873 | // CC: SYSVR4 systems don't have that macro | ||
874 | (S_ISSOCK(fileinfo.st_mode)) || | ||
875 | #endif | ||
876 | (S_ISFIFO(fileinfo.st_mode)) || | ||
877 | (S_ISDIR(fileinfo.st_mode)) ) { | ||
878 | return false; | ||
879 | } | ||
880 | |||
881 | // CC: now check for permission to execute the file | ||
882 | if (access(filename.data(), X_OK) != 0) return false; | ||
883 | |||
884 | // CC: we've passed all the tests... | ||
885 | return true; | ||
886 | } | ||
887 | |||
888 | void KProcess::virtual_hook( int, void* ) | ||
889 | { /*BASE::virtual_hook( id, data );*/ } | ||
890 | |||
891 | |||
892 | /////////////////////////// | ||
893 | // CC: Class KShellProcess | ||
894 | /////////////////////////// | ||
895 | |||
896 | KShellProcess::KShellProcess(const char *shellname): | ||
897 | KProcess() | ||
898 | { | ||
899 | setUseShell(true, shellname); | ||
900 | } | ||
901 | |||
902 | |||
903 | KShellProcess::~KShellProcess() { | ||
904 | } | ||
905 | |||
906 | QString KShellProcess::quote(const QString &arg) | ||
907 | { | ||
908 | return KProcess::quote(arg); | ||
909 | } | ||
910 | |||
911 | bool KShellProcess::start(RunMode runmode, Communication comm) | ||
912 | { | ||
913 | return KProcess::start(runmode, comm); | ||
914 | } | ||
915 | |||
916 | void KShellProcess::virtual_hook( int id, void* data ) | ||
917 | { KProcess::virtual_hook( id, data ); } | ||
918 | |||
919 | //#include "kprocess.moc" | ||
diff --git a/noncore/net/networksetup/kprocess.h b/noncore/net/networksetup/kprocess.h new file mode 100644 index 0000000..e70f7e7 --- a/dev/null +++ b/noncore/net/networksetup/kprocess.h | |||
@@ -0,0 +1,804 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | // | ||
20 | // KPROCESS -- A class for handling child processes in KDE without | ||
21 | // having to take care of Un*x specific implementation details | ||
22 | // | ||
23 | // version 0.3.1, Jan 8th 1998 | ||
24 | // | ||
25 | // (C) Christian Czezatke | ||
26 | // e9025461@student.tuwien.ac.at | ||
27 | // | ||
28 | |||
29 | #ifndef __kprocess_h__ | ||
30 | #define __kprocess_h__ | ||
31 | |||
32 | #include <sys/types.h> // for pid_t | ||
33 | #include <sys/wait.h> | ||
34 | #include <signal.h> | ||
35 | #include <unistd.h> | ||
36 | #include <qvaluelist.h> | ||
37 | #include <qcstring.h> | ||
38 | #include <qobject.h> | ||
39 | |||
40 | class QSocketNotifier; | ||
41 | class KProcessPrivate; | ||
42 | |||
43 | /** | ||
44 | * Child process invocation, monitoring and control. | ||
45 | * | ||
46 | * @sect General usage and features | ||
47 | * | ||
48 | *This class allows a KDE application to start child processes without having | ||
49 | *to worry about UN*X signal handling issues and zombie process reaping. | ||
50 | * | ||
51 | *@see KProcIO | ||
52 | * | ||
53 | *Basically, this class distinguishes three different ways of running | ||
54 | *child processes: | ||
55 | * | ||
56 | *@li KProcess::DontCare -- The child process is invoked and both the child | ||
57 | *process and the parent process continue concurrently. | ||
58 | * | ||
59 | *Starting a DontCare child process means that the application is | ||
60 | *not interested in any notification to determine whether the | ||
61 | *child process has already exited or not. | ||
62 | * | ||
63 | *@li KProcess::NotifyOnExit -- The child process is invoked and both the | ||
64 | *child and the parent process run concurrently. | ||
65 | * | ||
66 | *When the child process exits, the KProcess instance | ||
67 | *corresponding to it emits the Qt signal @ref processExited(). | ||
68 | * | ||
69 | *Since this signal is @em not emitted from within a UN*X | ||
70 | *signal handler, arbitrary function calls can be made. | ||
71 | * | ||
72 | *Be aware: When the KProcess objects gets destructed, the child | ||
73 | *process will be killed if it is still running! | ||
74 | *This means in particular, that you cannot use a KProcess on the stack | ||
75 | *with KProcess::NotifyOnExit. | ||
76 | * | ||
77 | *@li KProcess::Block -- The child process starts and the parent process | ||
78 | *is suspended until the child process exits. (@em Really not recommended | ||
79 | *for programs with a GUI.) | ||
80 | * | ||
81 | *KProcess also provides several functions for determining the exit status | ||
82 | *and the pid of the child process it represents. | ||
83 | * | ||
84 | *Furthermore it is possible to supply command-line arguments to the process | ||
85 | *in a clean fashion (no null -- terminated stringlists and such...) | ||
86 | * | ||
87 | *A small usage example: | ||
88 | *<pre> | ||
89 | *KProcess *proc = new KProcess; | ||
90 | * | ||
91 | **proc << "my_executable"; | ||
92 | **proc << "These" << "are" << "the" << "command" << "line" << "args"; | ||
93 | *QApplication::connect(proc, SIGNAL(processExited(KProcess *)), | ||
94 | * pointer_to_my_object, SLOT(my_objects_slot(KProcess *))); | ||
95 | *proc->start(); | ||
96 | *</pre> | ||
97 | * | ||
98 | *This will start "my_executable" with the commandline arguments "These"... | ||
99 | * | ||
100 | *When the child process exits, the respective Qt signal will be emitted. | ||
101 | * | ||
102 | *@sect Communication with the child process | ||
103 | * | ||
104 | *KProcess supports communication with the child process through | ||
105 | *stdin/stdout/stderr. | ||
106 | * | ||
107 | *The following functions are provided for getting data from the child | ||
108 | *process or sending data to the child's stdin (For more information, | ||
109 | *have a look at the documentation of each function): | ||
110 | * | ||
111 | *@li bool @ref writeStdin(char *buffer, int buflen); | ||
112 | *@li -- Transmit data to the child process's stdin. | ||
113 | * | ||
114 | *@li bool @ref closeStdin(); | ||
115 | *@li -- Closes the child process's stdin (which causes it to see an feof(stdin)). | ||
116 | *Returns false if you try to close stdin for a process that has been started | ||
117 | *without a communication channel to stdin. | ||
118 | * | ||
119 | *@li bool @ref closeStdout(); | ||
120 | *@li -- Closes the child process's stdout. | ||
121 | *Returns false if you try to close stdout for a process that has been started | ||
122 | *without a communication channel to stdout. | ||
123 | * | ||
124 | *@li bool @ref closeStderr(); | ||
125 | *@li -- Closes the child process's stderr. | ||
126 | *Returns false if you try to close stderr for a process that has been started | ||
127 | *without a communication channel to stderr. | ||
128 | * | ||
129 | * | ||
130 | *@sect QT signals: | ||
131 | * | ||
132 | *@li void @ref receivedStdout(KProcess *proc, char *buffer, int buflen); | ||
133 | *@li void @ref receivedStderr(KProcess *proc, char *buffer, int buflen); | ||
134 | *@li -- Indicates that new data has arrived from either the | ||
135 | *child process's stdout or stderr. | ||
136 | * | ||
137 | *@li void @ref wroteStdin(KProcess *proc); | ||
138 | *@li -- Indicates that all data that has been sent to the child process | ||
139 | *by a prior call to @ref writeStdin() has actually been transmitted to the | ||
140 | *client . | ||
141 | * | ||
142 | *@author Christian Czezakte e9025461@student.tuwien.ac.at | ||
143 | * | ||
144 | * | ||
145 | **/ | ||
146 | class KProcess : public QObject | ||
147 | { | ||
148 | Q_OBJECT | ||
149 | |||
150 | public: | ||
151 | |||
152 | /** | ||
153 | * Modes in which the communication channel can be opened. | ||
154 | * | ||
155 | * If communication for more than one channel is required, | ||
156 | * the values have to be or'ed together, for example to get | ||
157 | * communication with stdout as well as with stdin, you would | ||
158 | * specify @p Stdin @p | @p Stdout | ||
159 | * | ||
160 | * If @p NoRead is specified in conjunction with @p Stdout, | ||
161 | * no data is actually read from @p Stdout but only | ||
162 | * the signal @ref childOutput(int fd) is emitted. | ||
163 | */ | ||
164 | enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4, | ||
165 | AllOutput = 6, All = 7, | ||
166 | NoRead }; | ||
167 | |||
168 | /** | ||
169 | * Run-modes for a child process. | ||
170 | */ | ||
171 | enum RunMode { | ||
172 | /** | ||
173 | * The application does not receive notifications from the subprocess when | ||
174 | * it is finished or aborted. | ||
175 | */ | ||
176 | DontCare, | ||
177 | /** | ||
178 | * The application is notified when the subprocess dies. | ||
179 | */ | ||
180 | NotifyOnExit, | ||
181 | /** | ||
182 | * The application is suspended until the started process is finished. | ||
183 | */ | ||
184 | Block }; | ||
185 | |||
186 | /** | ||
187 | * Constructor | ||
188 | */ | ||
189 | KProcess(); | ||
190 | |||
191 | /** | ||
192 | *Destructor: | ||
193 | * | ||
194 | * If the process is running when the destructor for this class | ||
195 | * is called, the child process is killed with a SIGKILL, but | ||
196 | * only if the run mode is not of type @p DontCare. | ||
197 | * Processes started as @p DontCare keep running anyway. | ||
198 | */ | ||
199 | virtual ~KProcess(); | ||
200 | |||
201 | /** | ||
202 | @deprecated | ||
203 | |||
204 | The use of this function is now deprecated. -- Please use the | ||
205 | "operator<<" instead of "setExecutable". | ||
206 | |||
207 | Sets the executable to be started with this KProcess object. | ||
208 | Returns false if the process is currently running (in that | ||
209 | case the executable remains unchanged.) | ||
210 | |||
211 | @see operator<< | ||
212 | |||
213 | */ | ||
214 | bool setExecutable(const QString& proc); | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Sets the executable and the command line argument list for this process. | ||
219 | * | ||
220 | * For example, doing an "ls -l /usr/local/bin" can be achieved by: | ||
221 | * <pre> | ||
222 | * KProcess p; | ||
223 | * ... | ||
224 | * p << "ls" << "-l" << "/usr/local/bin" | ||
225 | * </pre> | ||
226 | * | ||
227 | **/ | ||
228 | KProcess &operator<<(const QString& arg); | ||
229 | /** | ||
230 | * Similar to previous method, takes a char *, supposed to be in locale 8 bit already. | ||
231 | */ | ||
232 | KProcess &operator<<(const char * arg); | ||
233 | /** | ||
234 | * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already. | ||
235 | */ | ||
236 | KProcess &operator<<(const QCString & arg); | ||
237 | |||
238 | /** | ||
239 | * Sets the executable and the command line argument list for this process, | ||
240 | * in a single method call, or add a list of arguments. | ||
241 | **/ | ||
242 | KProcess &operator<<(const QStringList& args); | ||
243 | |||
244 | /** | ||
245 | * Clear a command line argument list that has been set by using | ||
246 | * the "operator<<". | ||
247 | */ | ||
248 | void clearArguments(); | ||
249 | |||
250 | /** | ||
251 | * Starts the process. | ||
252 | * For a detailed description of the | ||
253 | * various run modes and communication semantics, have a look at the | ||
254 | * general description of the KProcess class. | ||
255 | * | ||
256 | * The following problems could cause this function to | ||
257 | * return false: | ||
258 | * | ||
259 | * @li The process is already running. | ||
260 | * @li The command line argument list is empty. | ||
261 | * @li The starting of the process failed (could not fork). | ||
262 | * @li The executable was not found. | ||
263 | * | ||
264 | * @param comm Specifies which communication links should be | ||
265 | * established to the child process (stdin/stdout/stderr). By default, | ||
266 | * no communication takes place and the respective communication | ||
267 | * signals will never get emitted. | ||
268 | * | ||
269 | * @return true on success, false on error | ||
270 | * (see above for error conditions) | ||
271 | **/ | ||
272 | virtual bool start(RunMode runmode = NotifyOnExit, | ||
273 | Communication comm = NoCommunication); | ||
274 | |||
275 | /** | ||
276 | * Stop the process (by sending it a signal). | ||
277 | * | ||
278 | * @param signoThe signal to send. The default is SIGTERM. | ||
279 | * @return @p true if the signal was delivered successfully. | ||
280 | */ | ||
281 | virtual bool kill(int signo = SIGTERM); | ||
282 | |||
283 | /** | ||
284 | @return @p true if the process is (still) considered to be running | ||
285 | */ | ||
286 | bool isRunning() const; | ||
287 | |||
288 | /** Returns the process id of the process. | ||
289 | * | ||
290 | * If it is called after | ||
291 | * the process has exited, it returns the process id of the last | ||
292 | * child process that was created by this instance of KProcess. | ||
293 | * | ||
294 | * Calling it before any child process has been started by this | ||
295 | * KProcess instance causes pid() to return 0. | ||
296 | **/ | ||
297 | pid_t pid() const; | ||
298 | |||
299 | /** | ||
300 | * Use pid(). | ||
301 | * @deprecated | ||
302 | */ | ||
303 | pid_t getPid() const { return pid(); } | ||
304 | |||
305 | /** | ||
306 | * Suspend processing of data from stdout of the child process. | ||
307 | */ | ||
308 | void suspend(); | ||
309 | |||
310 | /** | ||
311 | * Resume processing of data from stdout of the child process. | ||
312 | */ | ||
313 | void resume(); | ||
314 | |||
315 | /** | ||
316 | * @return @p true if the process has already finished and has exited | ||
317 | * "voluntarily", ie: it has not been killed by a signal. | ||
318 | * | ||
319 | * Note that you should check @ref KProcess::exitStatus() to determine | ||
320 | * whether the process completed its task successful or not. | ||
321 | */ | ||
322 | bool normalExit() const; | ||
323 | |||
324 | /** | ||
325 | * Returns the exit status of the process. | ||
326 | * | ||
327 | * Please use | ||
328 | * @ref KProcess::normalExit() to check whether the process has exited | ||
329 | * cleanly (i.e., @ref KProcess::normalExit() returns @p true) before calling | ||
330 | * this function because if the process did not exit normally, | ||
331 | * it does not have a valid exit status. | ||
332 | */ | ||
333 | int exitStatus() const; | ||
334 | |||
335 | |||
336 | /** | ||
337 | * Transmit data to the child process's stdin. | ||
338 | * | ||
339 | * KProcess::writeStdin may return false in the following cases: | ||
340 | * | ||
341 | * @li The process is not currently running. | ||
342 | * | ||
343 | * @li Communication to stdin has not been requested in the @ref start() call. | ||
344 | * | ||
345 | * @li Transmission of data to the child process by a previous call to | ||
346 | * @ref writeStdin() is still in progress. | ||
347 | * | ||
348 | * Please note that the data is sent to the client asynchronously, | ||
349 | * so when this function returns, the data might not have been | ||
350 | * processed by the child process. | ||
351 | * | ||
352 | * If all the data has been sent to the client, the signal | ||
353 | * @ref wroteStdin() will be emitted. | ||
354 | * | ||
355 | * Please note that you must not free "buffer" or call @ref writeStdin() | ||
356 | * again until either a @ref wroteStdin() signal indicates that the | ||
357 | * data has been sent or a @ref processHasExited() signal shows that | ||
358 | * the child process is no longer alive... | ||
359 | **/ | ||
360 | bool writeStdin(const char *buffer, int buflen); | ||
361 | |||
362 | /** | ||
363 | * This causes the stdin file descriptor of the child process to be | ||
364 | * closed indicating an "EOF" to the child. | ||
365 | * | ||
366 | * @return @p false if no communication to the process's stdin | ||
367 | * had been specified in the call to @ref start(). | ||
368 | */ | ||
369 | bool closeStdin(); | ||
370 | |||
371 | /** | ||
372 | * This causes the stdout file descriptor of the child process to be | ||
373 | * closed. | ||
374 | * | ||
375 | * @return @p false if no communication to the process's stdout | ||
376 | * had been specified in the call to @ref start(). | ||
377 | */ | ||
378 | bool closeStdout(); | ||
379 | |||
380 | /** | ||
381 | * This causes the stderr file descriptor of the child process to be | ||
382 | * closed. | ||
383 | * | ||
384 | * @return @p false if no communication to the process's stderr | ||
385 | * had been specified in the call to @ref start(). | ||
386 | */ | ||
387 | bool closeStderr(); | ||
388 | |||
389 | /** | ||
390 | * Lets you see what your arguments are for debugging. | ||
391 | */ | ||
392 | |||
393 | const QValueList<QCString> &args() { return arguments; } | ||
394 | |||
395 | /** | ||
396 | * Controls whether the started process should drop any | ||
397 | * setuid/segid privileges or whether it should keep them | ||
398 | * | ||
399 | * The default is @p false : drop privileges | ||
400 | */ | ||
401 | void setRunPrivileged(bool keepPrivileges); | ||
402 | |||
403 | /** | ||
404 | * Returns whether the started process will drop any | ||
405 | * setuid/segid privileges or whether it will keep them | ||
406 | */ | ||
407 | bool runPrivileged() const; | ||
408 | |||
409 | /** | ||
410 | * Modifies the environment of the process to be started. | ||
411 | * This function must be called before starting the process. | ||
412 | */ | ||
413 | void setEnvironment(const QString &name, const QString &value); | ||
414 | |||
415 | /** | ||
416 | * Changes the current working directory (CWD) of the process | ||
417 | * to be started. | ||
418 | * This function must be called before starting the process. | ||
419 | */ | ||
420 | void setWorkingDirectory(const QString &dir); | ||
421 | |||
422 | /** | ||
423 | * Specify whether to start the command via a shell or directly. | ||
424 | * The default is to start the command directly. | ||
425 | * If @p useShell is true @p shell will be used as shell, or | ||
426 | * if shell is empty, the standard shell is used. | ||
427 | * @p quote A flag indicating whether to quote the arguments. | ||
428 | * | ||
429 | * When using a shell, the caller should make sure that all filenames etc. | ||
430 | * are properly quoted when passed as argument. | ||
431 | * @see quote() | ||
432 | */ | ||
433 | void setUseShell(bool useShell, const char *shell = 0); | ||
434 | |||
435 | /** | ||
436 | * This function can be used to quote an argument string such that | ||
437 | * the shell processes it properly. This is e. g. necessary for | ||
438 | * user-provided file names which may contain spaces or quotes. | ||
439 | * It also prevents expansion of wild cards and environment variables. | ||
440 | */ | ||
441 | static QString quote(const QString &arg); | ||
442 | |||
443 | /** | ||
444 | * Detaches KProcess from child process. All communication is closed. | ||
445 | * No exit notification is emitted any more for the child process. | ||
446 | * Deleting the KProcess will no longer kill the child process. | ||
447 | * Note that the current process remains the parent process of the | ||
448 | * child process. | ||
449 | */ | ||
450 | void detach(); | ||
451 | |||
452 | |||
453 | |||
454 | signals: | ||
455 | |||
456 | /** | ||
457 | * Emitted after the process has terminated when | ||
458 | * the process was run in the @p NotifyOnExit (==default option to | ||
459 | * @ref start()) or the @ref Block mode. | ||
460 | **/ | ||
461 | void processExited(KProcess *proc); | ||
462 | |||
463 | |||
464 | /** | ||
465 | * Emitted, when output from the child process has | ||
466 | * been received on stdout. | ||
467 | * | ||
468 | * To actually get | ||
469 | * these signals, the respective communication link (stdout/stderr) | ||
470 | * has to be turned on in @ref start(). | ||
471 | * | ||
472 | * @param buffer The data received. | ||
473 | * @param buflen The number of bytes that are available. | ||
474 | * | ||
475 | * You should copy the information contained in @p buffer to your private | ||
476 | * data structures before returning from this slot. | ||
477 | **/ | ||
478 | void receivedStdout(KProcess *proc, char *buffer, int buflen); | ||
479 | |||
480 | /** | ||
481 | * Emitted when output from the child process has | ||
482 | * been received on stdout. | ||
483 | * | ||
484 | * To actually get these signals, the respective communications link | ||
485 | * (stdout/stderr) has to be turned on in @ref start() and the | ||
486 | * @p NoRead flag should have been passed. | ||
487 | * | ||
488 | * You will need to explicitly call resume() after your call to start() | ||
489 | * to begin processing data from the child process's stdout. This is | ||
490 | * to ensure that this signal is not emitted when no one is connected | ||
491 | * to it, otherwise this signal will not be emitted. | ||
492 | * | ||
493 | * The data still has to be read from file descriptor @p fd. | ||
494 | **/ | ||
495 | void receivedStdout(int fd, int &len); | ||
496 | |||
497 | |||
498 | /** | ||
499 | * Emitted, when output from the child process has | ||
500 | * been received on stderr. | ||
501 | * To actually get | ||
502 | * these signals, the respective communication link (stdout/stderr) | ||
503 | * has to be turned on in @ref start(). | ||
504 | * | ||
505 | * @param buffer The data received. | ||
506 | * @param buflen The number of bytes that are available. | ||
507 | * | ||
508 | * You should copy the information contained in @p buffer to your private | ||
509 | * data structures before returning from this slot. | ||
510 | */ | ||
511 | void receivedStderr(KProcess *proc, char *buffer, int buflen); | ||
512 | |||
513 | /** | ||
514 | * Emitted after all the data that has been | ||
515 | * specified by a prior call to @ref writeStdin() has actually been | ||
516 | * written to the child process. | ||
517 | **/ | ||
518 | void wroteStdin(KProcess *proc); | ||
519 | |||
520 | |||
521 | protected slots: | ||
522 | |||
523 | /** | ||
524 | * This slot gets activated when data from the child's stdout arrives. | ||
525 | * It usually calls "childOutput" | ||
526 | */ | ||
527 | void slotChildOutput(int fdno); | ||
528 | |||
529 | /** | ||
530 | * This slot gets activated when data from the child's stderr arrives. | ||
531 | * It usually calls "childError" | ||
532 | */ | ||
533 | void slotChildError(int fdno); | ||
534 | /* | ||
535 | Slot functions for capturing stdout and stderr of the child | ||
536 | */ | ||
537 | |||
538 | /** | ||
539 | * Called when another bulk of data can be sent to the child's | ||
540 | * stdin. If there is no more data to be sent to stdin currently | ||
541 | * available, this function must disable the QSocketNotifier "innot". | ||
542 | */ | ||
543 | void slotSendData(int dummy); | ||
544 | |||
545 | protected: | ||
546 | |||
547 | /** | ||
548 | * Sets up the environment according to the data passed via | ||
549 | * setEnvironment(...) | ||
550 | */ | ||
551 | void setupEnvironment(); | ||
552 | |||
553 | /** | ||
554 | * The list of the process' command line arguments. The first entry | ||
555 | * in this list is the executable itself. | ||
556 | */ | ||
557 | QValueList<QCString> arguments; | ||
558 | /** | ||
559 | * How to run the process (Block, NotifyOnExit, DontCare). You should | ||
560 | * not modify this data member directly from derived classes. | ||
561 | */ | ||
562 | RunMode run_mode; | ||
563 | /** | ||
564 | * true if the process is currently running. You should not | ||
565 | * modify this data member directly from derived classes. For | ||
566 | * reading the value of this data member, please use "isRunning()" | ||
567 | * since "runs" will probably be made private in later versions | ||
568 | * of KProcess. | ||
569 | */ | ||
570 | bool runs; | ||
571 | |||
572 | /** | ||
573 | * The PID of the currently running process (see "getPid()"). | ||
574 | * You should not modify this data member in derived classes. | ||
575 | * Please use "getPid()" instead of directly accessing this | ||
576 | * member function since it will probably be made private in | ||
577 | * later versions of KProcess. | ||
578 | */ | ||
579 | pid_t pid_; | ||
580 | |||
581 | /** | ||
582 | * The process' exit status as returned by "waitpid". You should not | ||
583 | * modify the value of this data member from derived classes. You should | ||
584 | * rather use @ref exitStatus than accessing this data member directly | ||
585 | * since it will probably be made private in further versions of | ||
586 | * KProcess. | ||
587 | */ | ||
588 | int status; | ||
589 | |||
590 | |||
591 | /** | ||
592 | * See setRunPrivileged() | ||
593 | */ | ||
594 | bool keepPrivs; | ||
595 | |||
596 | /* | ||
597 | Functions for setting up the sockets for communication. | ||
598 | setupCommunication | ||
599 | -- is called from "start" before "fork"ing. | ||
600 | commSetupDoneP | ||
601 | -- completes communication socket setup in the parent | ||
602 | commSetupDoneC | ||
603 | -- completes communication setup in the child process | ||
604 | commClose | ||
605 | -- frees all allocated communication resources in the parent | ||
606 | after the process has exited | ||
607 | */ | ||
608 | |||
609 | /** | ||
610 | * This function is called from "KProcess::start" right before a "fork" takes | ||
611 | * place. According to | ||
612 | * the "comm" parameter this function has to initialize the "in", "out" and | ||
613 | * "err" data member of KProcess. | ||
614 | * | ||
615 | * This function should return 0 if setting the needed communication channels | ||
616 | * was successful. | ||
617 | * | ||
618 | * The default implementation is to create UNIX STREAM sockets for the communication, | ||
619 | * but you could overload this function and establish a TCP/IP communication for | ||
620 | * network communication, for example. | ||
621 | */ | ||
622 | virtual int setupCommunication(Communication comm); | ||
623 | |||
624 | /** | ||
625 | * Called right after a (successful) fork on the parent side. This function | ||
626 | * will usually do some communications cleanup, like closing the reading end | ||
627 | * of the "stdin" communication channel. | ||
628 | * | ||
629 | * Furthermore, it must also create the QSocketNotifiers "innot", "outnot" and | ||
630 | * "errnot" and connect their Qt slots to the respective KProcess member functions. | ||
631 | * | ||
632 | * For a more detailed explanation, it is best to have a look at the default | ||
633 | * implementation of "setupCommunication" in kprocess.cpp. | ||
634 | */ | ||
635 | virtual int commSetupDoneP(); | ||
636 | |||
637 | /** | ||
638 | * Called right after a (successful) fork, but before an "exec" on the child | ||
639 | * process' side. It usually just closes the unused communication ends of | ||
640 | * "in", "out" and "err" (like the writing end of the "in" communication | ||
641 | * channel. | ||
642 | */ | ||
643 | virtual int commSetupDoneC(); | ||
644 | |||
645 | |||
646 | /** | ||
647 | * Immediately called after a process has exited. This function normally | ||
648 | * calls commClose to close all open communication channels to this | ||
649 | * process and emits the "processExited" signal (if the process was | ||
650 | * not running in the "DontCare" mode). | ||
651 | */ | ||
652 | virtual void processHasExited(int state); | ||
653 | |||
654 | /** | ||
655 | * Should clean up the communication links to the child after it has | ||
656 | * exited. Should be called from "processHasExited". | ||
657 | */ | ||
658 | virtual void commClose(); | ||
659 | |||
660 | |||
661 | /** | ||
662 | * the socket descriptors for stdin/stdout/stderr. | ||
663 | */ | ||
664 | int out[2]; | ||
665 | int in[2]; | ||
666 | int err[2]; | ||
667 | |||
668 | /** | ||
669 | * The socket notifiers for the above socket descriptors. | ||
670 | */ | ||
671 | QSocketNotifier *innot; | ||
672 | QSocketNotifier *outnot; | ||
673 | QSocketNotifier *errnot; | ||
674 | |||
675 | /** | ||
676 | * Lists the communication links that are activated for the child | ||
677 | * process. Should not be modified from derived classes. | ||
678 | */ | ||
679 | Communication communication; | ||
680 | |||
681 | /** | ||
682 | * Called by "slotChildOutput" this function copies data arriving from the | ||
683 | * child process's stdout to the respective buffer and emits the signal | ||
684 | * "@ref receivedStderr". | ||
685 | */ | ||
686 | int childOutput(int fdno); | ||
687 | |||
688 | /** | ||
689 | * Called by "slotChildOutput" this function copies data arriving from the | ||
690 | * child process's stdout to the respective buffer and emits the signal | ||
691 | * "@ref receivedStderr" | ||
692 | */ | ||
693 | int childError(int fdno); | ||
694 | |||
695 | // information about the data that has to be sent to the child: | ||
696 | |||
697 | const char *input_data; // the buffer holding the data | ||
698 | int input_sent; // # of bytes already transmitted | ||
699 | int input_total; // total length of input_data | ||
700 | |||
701 | /** | ||
702 | * @ref KProcessController is a friend of KProcess because it has to have | ||
703 | * access to various data members. | ||
704 | */ | ||
705 | friend class KProcessController; | ||
706 | |||
707 | |||
708 | private: | ||
709 | /** | ||
710 | * Searches for a valid shell. | ||
711 | * Here is the algorithm used for finding an executable shell: | ||
712 | * | ||
713 | * @li Try the executable pointed to by the "SHELL" environment | ||
714 | * variable with white spaces stripped off | ||
715 | * | ||
716 | * @li If your process runs with uid != euid or gid != egid, a shell | ||
717 | * not listed in /etc/shells will not used. | ||
718 | * | ||
719 | * @li If no valid shell could be found, "/bin/sh" is used as a last resort. | ||
720 | */ | ||
721 | QCString searchShell(); | ||
722 | |||
723 | /** | ||
724 | * Used by @ref searchShell in order to find out whether the shell found | ||
725 | * is actually executable at all. | ||
726 | */ | ||
727 | bool isExecutable(const QCString &filename); | ||
728 | |||
729 | // Disallow assignment and copy-construction | ||
730 | KProcess( const KProcess& ); | ||
731 | KProcess& operator= ( const KProcess& ); | ||
732 | |||
733 | protected: | ||
734 | virtual void virtual_hook( int id, void* data ); | ||
735 | private: | ||
736 | KProcessPrivate *d; | ||
737 | }; | ||
738 | |||
739 | class KShellProcessPrivate; | ||
740 | |||
741 | /** | ||
742 | * @obsolete | ||
743 | * | ||
744 | * This class is obsolete. Use KProcess and KProcess::setUseShell(true) | ||
745 | * instead. | ||
746 | * | ||
747 | * @short A class derived from @ref KProcess to start child | ||
748 | * processes through a shell. | ||
749 | * @author Christian Czezakte <e9025461@student.tuwien.ac.at> | ||
750 | * @version $Id$ | ||
751 | */ | ||
752 | class KShellProcess: public KProcess | ||
753 | { | ||
754 | Q_OBJECT | ||
755 | |||
756 | public: | ||
757 | |||
758 | /** | ||
759 | * Constructor | ||
760 | * | ||
761 | * By specifying the name of a shell (like "/bin/bash") you can override | ||
762 | * the mechanism for finding a valid shell as described in KProcess::searchShell() | ||
763 | */ | ||
764 | KShellProcess(const char *shellname=0); | ||
765 | |||
766 | /** | ||
767 | * Destructor. | ||
768 | */ | ||
769 | ~KShellProcess(); | ||
770 | |||
771 | /** | ||
772 | * Starts up the process. -- For a detailed description | ||
773 | * have a look at the "start" member function and the detailed | ||
774 | * description of @ref KProcess . | ||
775 | */ | ||
776 | virtual bool start(RunMode runmode = NotifyOnExit, | ||
777 | Communication comm = NoCommunication); | ||
778 | |||
779 | /** | ||
780 | * This function can be used to quote an argument string such that | ||
781 | * the shell processes it properly. This is e. g. necessary for | ||
782 | * user-provided file names which may contain spaces or quotes. | ||
783 | * It also prevents expansion of wild cards and environment variables. | ||
784 | */ | ||
785 | static QString quote(const QString &arg); | ||
786 | |||
787 | private: | ||
788 | |||
789 | QCString shell; | ||
790 | |||
791 | // Disallow assignment and copy-construction | ||
792 | KShellProcess( const KShellProcess& ); | ||
793 | KShellProcess& operator= ( const KShellProcess& ); | ||
794 | |||
795 | protected: | ||
796 | virtual void virtual_hook( int id, void* data ); | ||
797 | private: | ||
798 | KShellProcessPrivate *d; | ||
799 | }; | ||
800 | |||
801 | |||
802 | |||
803 | #endif | ||
804 | |||
diff --git a/noncore/net/networksetup/main.cpp b/noncore/net/networksetup/main.cpp new file mode 100644 index 0000000..52cb92b --- a/dev/null +++ b/noncore/net/networksetup/main.cpp | |||
@@ -0,0 +1,13 @@ | |||
1 | #include "mainwindowimp.h" | ||
2 | #include <qpe/qpeapplication.h> | ||
3 | |||
4 | int main(int argc, char **argv) | ||
5 | { | ||
6 | QPEApplication app(argc, argv); | ||
7 | MainWindowImp window; | ||
8 | window.showMaximized(); | ||
9 | return app.exec(); | ||
10 | } | ||
11 | |||
12 | // main.cpp | ||
13 | |||
diff --git a/noncore/net/networksetup/mainwindow.ui b/noncore/net/networksetup/mainwindow.ui new file mode 100644 index 0000000..b8c0675 --- a/dev/null +++ b/noncore/net/networksetup/mainwindow.ui | |||
@@ -0,0 +1,321 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>MainWindow</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>MainWindow</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>222</width> | ||
15 | <height>289</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Network Setup</string> | ||
21 | </property> | ||
22 | <vbox> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>0</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget> | ||
32 | <class>QTabWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>tabWidget</cstring> | ||
36 | </property> | ||
37 | <property> | ||
38 | <name>layoutMargin</name> | ||
39 | </property> | ||
40 | <widget> | ||
41 | <class>QWidget</class> | ||
42 | <property stdset="1"> | ||
43 | <name>name</name> | ||
44 | <cstring>Widget3</cstring> | ||
45 | </property> | ||
46 | <attribute> | ||
47 | <name>title</name> | ||
48 | <string>Interfaces</string> | ||
49 | </attribute> | ||
50 | <vbox> | ||
51 | <property stdset="1"> | ||
52 | <name>margin</name> | ||
53 | <number>0</number> | ||
54 | </property> | ||
55 | <property stdset="1"> | ||
56 | <name>spacing</name> | ||
57 | <number>6</number> | ||
58 | </property> | ||
59 | <widget> | ||
60 | <class>QListView</class> | ||
61 | <column> | ||
62 | <property> | ||
63 | <name>text</name> | ||
64 | <string>i</string> | ||
65 | </property> | ||
66 | <property> | ||
67 | <name>clickable</name> | ||
68 | <bool>true</bool> | ||
69 | </property> | ||
70 | <property> | ||
71 | <name>resizeable</name> | ||
72 | <bool>true</bool> | ||
73 | </property> | ||
74 | </column> | ||
75 | <column> | ||
76 | <property> | ||
77 | <name>text</name> | ||
78 | <string>t</string> | ||
79 | </property> | ||
80 | <property> | ||
81 | <name>clickable</name> | ||
82 | <bool>true</bool> | ||
83 | </property> | ||
84 | <property> | ||
85 | <name>resizeable</name> | ||
86 | <bool>true</bool> | ||
87 | </property> | ||
88 | </column> | ||
89 | <column> | ||
90 | <property> | ||
91 | <name>text</name> | ||
92 | <string>Name</string> | ||
93 | </property> | ||
94 | <property> | ||
95 | <name>clickable</name> | ||
96 | <bool>true</bool> | ||
97 | </property> | ||
98 | <property> | ||
99 | <name>resizeable</name> | ||
100 | <bool>true</bool> | ||
101 | </property> | ||
102 | </column> | ||
103 | <property stdset="1"> | ||
104 | <name>name</name> | ||
105 | <cstring>serviceList</cstring> | ||
106 | </property> | ||
107 | <property stdset="1"> | ||
108 | <name>allColumnsShowFocus</name> | ||
109 | <bool>true</bool> | ||
110 | </property> | ||
111 | </widget> | ||
112 | <widget> | ||
113 | <class>QLayoutWidget</class> | ||
114 | <property stdset="1"> | ||
115 | <name>name</name> | ||
116 | <cstring>Layout2</cstring> | ||
117 | </property> | ||
118 | <property> | ||
119 | <name>layoutMargin</name> | ||
120 | </property> | ||
121 | <grid> | ||
122 | <property stdset="1"> | ||
123 | <name>margin</name> | ||
124 | <number>5</number> | ||
125 | </property> | ||
126 | <property stdset="1"> | ||
127 | <name>spacing</name> | ||
128 | <number>6</number> | ||
129 | </property> | ||
130 | <widget row="1" column="0" > | ||
131 | <class>QPushButton</class> | ||
132 | <property stdset="1"> | ||
133 | <name>name</name> | ||
134 | <cstring>addServiceButton</cstring> | ||
135 | </property> | ||
136 | <property stdset="1"> | ||
137 | <name>text</name> | ||
138 | <string>&Add</string> | ||
139 | </property> | ||
140 | </widget> | ||
141 | <widget row="0" column="0" > | ||
142 | <class>QPushButton</class> | ||
143 | <property stdset="1"> | ||
144 | <name>name</name> | ||
145 | <cstring>informationServiceButton</cstring> | ||
146 | </property> | ||
147 | <property stdset="1"> | ||
148 | <name>text</name> | ||
149 | <string>&Information</string> | ||
150 | </property> | ||
151 | </widget> | ||
152 | <widget row="0" column="1" > | ||
153 | <class>QPushButton</class> | ||
154 | <property stdset="1"> | ||
155 | <name>name</name> | ||
156 | <cstring>configureServiceButton</cstring> | ||
157 | </property> | ||
158 | <property stdset="1"> | ||
159 | <name>text</name> | ||
160 | <string>&Configure</string> | ||
161 | </property> | ||
162 | </widget> | ||
163 | <widget row="1" column="1" > | ||
164 | <class>QPushButton</class> | ||
165 | <property stdset="1"> | ||
166 | <name>name</name> | ||
167 | <cstring>removeServiceButton</cstring> | ||
168 | </property> | ||
169 | <property stdset="1"> | ||
170 | <name>text</name> | ||
171 | <string>&Remove</string> | ||
172 | </property> | ||
173 | </widget> | ||
174 | </grid> | ||
175 | </widget> | ||
176 | </vbox> | ||
177 | </widget> | ||
178 | <widget> | ||
179 | <class>QWidget</class> | ||
180 | <property stdset="1"> | ||
181 | <name>name</name> | ||
182 | <cstring>tab</cstring> | ||
183 | </property> | ||
184 | <attribute> | ||
185 | <name>title</name> | ||
186 | <string>Profiles</string> | ||
187 | </attribute> | ||
188 | <grid> | ||
189 | <property stdset="1"> | ||
190 | <name>margin</name> | ||
191 | <number>11</number> | ||
192 | </property> | ||
193 | <property stdset="1"> | ||
194 | <name>spacing</name> | ||
195 | <number>6</number> | ||
196 | </property> | ||
197 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
198 | <class>QLabel</class> | ||
199 | <property stdset="1"> | ||
200 | <name>name</name> | ||
201 | <cstring>TextLabel3</cstring> | ||
202 | </property> | ||
203 | <property stdset="1"> | ||
204 | <name>text</name> | ||
205 | <string>Change Profile To</string> | ||
206 | </property> | ||
207 | </widget> | ||
208 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
209 | <class>QLabel</class> | ||
210 | <property stdset="1"> | ||
211 | <name>name</name> | ||
212 | <cstring>TextLabel1</cstring> | ||
213 | </property> | ||
214 | <property stdset="1"> | ||
215 | <name>text</name> | ||
216 | <string>Current Profile</string> | ||
217 | </property> | ||
218 | </widget> | ||
219 | <widget row="0" column="2" > | ||
220 | <class>QLabel</class> | ||
221 | <property stdset="1"> | ||
222 | <name>name</name> | ||
223 | <cstring>TextLabel2</cstring> | ||
224 | </property> | ||
225 | <property stdset="1"> | ||
226 | <name>frameShape</name> | ||
227 | <enum>Panel</enum> | ||
228 | </property> | ||
229 | <property stdset="1"> | ||
230 | <name>frameShadow</name> | ||
231 | <enum>Sunken</enum> | ||
232 | </property> | ||
233 | <property stdset="1"> | ||
234 | <name>text</name> | ||
235 | <string>All</string> | ||
236 | </property> | ||
237 | </widget> | ||
238 | <widget row="1" column="2" > | ||
239 | <class>QComboBox</class> | ||
240 | <item> | ||
241 | <property> | ||
242 | <name>text</name> | ||
243 | <string>All</string> | ||
244 | </property> | ||
245 | </item> | ||
246 | <property stdset="1"> | ||
247 | <name>name</name> | ||
248 | <cstring>ComboBox10</cstring> | ||
249 | </property> | ||
250 | </widget> | ||
251 | <widget row="2" column="1" rowspan="1" colspan="2" > | ||
252 | <class>QPushButton</class> | ||
253 | <property stdset="1"> | ||
254 | <name>name</name> | ||
255 | <cstring>removeProfileButton</cstring> | ||
256 | </property> | ||
257 | <property stdset="1"> | ||
258 | <name>text</name> | ||
259 | <string>&Remove</string> | ||
260 | </property> | ||
261 | </widget> | ||
262 | <widget row="2" column="0" > | ||
263 | <class>QPushButton</class> | ||
264 | <property stdset="1"> | ||
265 | <name>name</name> | ||
266 | <cstring>newProfileButton</cstring> | ||
267 | </property> | ||
268 | <property stdset="1"> | ||
269 | <name>text</name> | ||
270 | <string>&New</string> | ||
271 | </property> | ||
272 | </widget> | ||
273 | <spacer row="3" column="2" > | ||
274 | <property> | ||
275 | <name>name</name> | ||
276 | <cstring>Spacer16</cstring> | ||
277 | </property> | ||
278 | <property stdset="1"> | ||
279 | <name>orientation</name> | ||
280 | <enum>Vertical</enum> | ||
281 | </property> | ||
282 | <property stdset="1"> | ||
283 | <name>sizeType</name> | ||
284 | <enum>Expanding</enum> | ||
285 | </property> | ||
286 | <property> | ||
287 | <name>sizeHint</name> | ||
288 | <size> | ||
289 | <width>20</width> | ||
290 | <height>20</height> | ||
291 | </size> | ||
292 | </property> | ||
293 | </spacer> | ||
294 | </grid> | ||
295 | </widget> | ||
296 | </widget> | ||
297 | </vbox> | ||
298 | </widget> | ||
299 | <customwidgets> | ||
300 | <customwidget> | ||
301 | <class>QWidget</class> | ||
302 | <header location="local">qwidget.h</header> | ||
303 | <sizehint> | ||
304 | <width>100</width> | ||
305 | <height>100</height> | ||
306 | </sizehint> | ||
307 | <container>0</container> | ||
308 | <sizepolicy> | ||
309 | <hordata>7</hordata> | ||
310 | <verdata>7</verdata> | ||
311 | </sizepolicy> | ||
312 | <pixmap>image0</pixmap> | ||
313 | </customwidget> | ||
314 | </customwidgets> | ||
315 | <images> | ||
316 | <image> | ||
317 | <name>image0</name> | ||
318 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
319 | </image> | ||
320 | </images> | ||
321 | </UI> | ||
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp new file mode 100644 index 0000000..3c13143 --- a/dev/null +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -0,0 +1,308 @@ | |||
1 | #include "mainwindowimp.h" | ||
2 | #include "addserviceimp.h" | ||
3 | #include "interfaceinformationimp.h" | ||
4 | #include "interfacesetupimp.h" | ||
5 | |||
6 | #include <qpushbutton.h> | ||
7 | #include <qdir.h> | ||
8 | #include <qtabwidget.h> | ||
9 | #include <qmainwindow.h> | ||
10 | #include <qmessagebox.h> | ||
11 | #include <qlistbox.h> | ||
12 | #include <qpe/config.h> | ||
13 | #include <qpe/qlibrary.h> | ||
14 | #include <qpe/resource.h> | ||
15 | #include <qlist.h> | ||
16 | |||
17 | #include <qfile.h> | ||
18 | #include <qtextstream.h> | ||
19 | #include <qlistview.h> | ||
20 | #include <qheader.h> | ||
21 | // For library loading. | ||
22 | #include <dlfcn.h> | ||
23 | |||
24 | #define TEMP_ALL "/tmp/ifconfig-a" | ||
25 | #define TEMP_UP "/tmp/ifconfig" | ||
26 | |||
27 | #define NO_SELECT_ERROR_AND_RETURN { \ | ||
28 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); \ | ||
29 | return; \ | ||
30 | } | ||
31 | |||
32 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) { | ||
33 | connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked())); | ||
34 | connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | ||
35 | connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | ||
36 | connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | ||
37 | // Make sure we have a plugin directory to scan. | ||
38 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | ||
39 | QDir pluginDir( DirStr ); | ||
40 | pluginDir.mkdir( DirStr ); | ||
41 | pluginDir.mkdir( ( DirStr + "plugins/" ) ); | ||
42 | QString path = DirStr + "plugins"; | ||
43 | pluginDir.setPath(path); | ||
44 | if(!pluginDir.exists()){ | ||
45 | qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1()); | ||
46 | return; | ||
47 | } | ||
48 | |||
49 | // Load any saved services. | ||
50 | loadModules(path); | ||
51 | getInterfaceList(); | ||
52 | serviceList->header()->hide(); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Deconstructor. Unload libraries and save. | ||
57 | */ | ||
58 | MainWindowImp::~MainWindowImp(){ | ||
59 | } | ||
60 | |||
61 | void MainWindowImp::loadModules(QString path){ | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Attempt to load a function and resolve a function. | ||
66 | * @param pluginFileName - the name of the file in which to attempt to load | ||
67 | * @param resolveString - function pointer to resolve | ||
68 | * @return pointer to the function with name resolveString or NULL | ||
69 | */ | ||
70 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | ||
71 | //qDebug(pluginFileName.latin1()); | ||
72 | QLibrary *lib = new QLibrary(pluginFileName); | ||
73 | void *functionPointer = lib->resolve(resolveString); | ||
74 | if( !functionPointer ){ | ||
75 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | ||
76 | delete lib; | ||
77 | return NULL; | ||
78 | } | ||
79 | |||
80 | // Try to get an object. | ||
81 | Module *object = ((Module* (*)()) functionPointer)(); | ||
82 | if(object == NULL){ | ||
83 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | ||
84 | delete lib; | ||
85 | return NULL; | ||
86 | } | ||
87 | |||
88 | // Store for reference | ||
89 | libraries.insert(object, lib); | ||
90 | return object; | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | QList<QString> MainWindowImp::retrieveUnloadedPluginList(){ | ||
95 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | ||
96 | QString path = DirStr + "plugins"; | ||
97 | QDir d(path); | ||
98 | d.setFilter( QDir::Files | QDir::Hidden ); | ||
99 | |||
100 | QMap<QObject*, QLibrary*>::Iterator libraryIt; | ||
101 | QList<QString> rlist; | ||
102 | rlist.setAutoDelete(false); | ||
103 | |||
104 | const QFileInfoList *list = d.entryInfoList(); | ||
105 | QFileInfoListIterator it( *list ); | ||
106 | QFileInfo *fi; | ||
107 | while ( (fi=it.current()) ) { | ||
108 | if(fi->fileName().contains(".so")){ | ||
109 | for( libraryIt = libraries.begin(); libraryIt != libraries.end(); ++libraryIt ) | ||
110 | if((path + "/" + fi->fileName()) != (libraryIt.data())->library()){ | ||
111 | QString *s = new QString(path + "/" + fi->fileName()); | ||
112 | rlist.append(s); | ||
113 | } | ||
114 | } | ||
115 | ++it; | ||
116 | } | ||
117 | return rlist; | ||
118 | } | ||
119 | */ | ||
120 | |||
121 | /** | ||
122 | * The Add button was clicked. Bring up the add dialog and if OK is hit | ||
123 | * load the plugin and append it to the list | ||
124 | */ | ||
125 | void MainWindowImp::addClicked(){ | ||
126 | // Now that we have a list of all of the protocals, list them. | ||
127 | { | ||
128 | QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok"); | ||
129 | return; | ||
130 | } | ||
131 | AddServiceImp service(this, "AddService", true); | ||
132 | service.showMaximized(); | ||
133 | service.exec(); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Prompt the user to see if they really want to do this. | ||
138 | * If they do then remove from the list and unload. | ||
139 | */ | ||
140 | void MainWindowImp::removeClicked(){ | ||
141 | QListViewItem *item = serviceList->currentItem(); | ||
142 | if(item == NULL) NO_SELECT_ERROR_AND_RETURN | ||
143 | |||
144 | if(modules.find(interfaceItems[item]) == modules.end()){ | ||
145 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | ||
146 | } | ||
147 | else{ | ||
148 | // Try to remove. | ||
149 | } | ||
150 | |||
151 | } | ||
152 | |||
153 | /** | ||
154 | * See if there is a configuration for the selected protocal. | ||
155 | * Prompt with errors. | ||
156 | */ | ||
157 | void MainWindowImp::configureClicked(){ | ||
158 | QListViewItem *item = serviceList->currentItem(); | ||
159 | if(item == NULL) NO_SELECT_ERROR_AND_RETURN | ||
160 | |||
161 | if(modules.find(interfaceItems[item]) == modules.end()){ | ||
162 | InterfaceSetupImp *conf = new InterfaceSetupImp(0, "InterfaceConfiguration", interfaceItems[item]); | ||
163 | conf->showMaximized(); | ||
164 | conf->show(); | ||
165 | } | ||
166 | else{ | ||
167 | InterfaceSetupImp *conf = new InterfaceSetupImp(this, "InterfaceConfiguration"); | ||
168 | conf->show(); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * Pull up the information about the selected interface | ||
174 | * Report an error | ||
175 | */ | ||
176 | void MainWindowImp::informationClicked(){ | ||
177 | QListViewItem *item = serviceList->currentItem(); | ||
178 | if(item == NULL)NO_SELECT_ERROR_AND_RETURN | ||
179 | |||
180 | if(modules.find(interfaceItems[item]) == modules.end()){ | ||
181 | InterfaceInformationImp *i = new InterfaceInformationImp(0, "InterfaceInformationImp", interfaceItems[item]); | ||
182 | i->showMaximized(); | ||
183 | i->show(); | ||
184 | } | ||
185 | else{ | ||
186 | QTabWidget *t = new QTabWidget(this, "InterfaceInformationTAB"); | ||
187 | InterfaceInformationImp *i = new InterfaceInformationImp(t, "TCPIPInformation", interfaceItems[item], true); | ||
188 | t->insertTab(i, "TCP/IP"); | ||
189 | t->show(); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Aquire the list of active interfaces from ifconfig | ||
195 | * Call ifconfig and ifconfig -a | ||
196 | */ | ||
197 | void MainWindowImp::getInterfaceList(){ | ||
198 | KShellProcess *processAll = new KShellProcess(); | ||
199 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | ||
200 | connect(processAll, SIGNAL(processExited(KProcess *)), | ||
201 | this, SLOT(jobDone(KProcess *))); | ||
202 | threads.insert(processAll, TEMP_ALL); | ||
203 | processAll->start(KShellProcess::NotifyOnExit); | ||
204 | |||
205 | KShellProcess *process = new KShellProcess(); | ||
206 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | ||
207 | connect(process, SIGNAL(processExited(KProcess *)), | ||
208 | this, SLOT(jobDone(KProcess *))); | ||
209 | threads.insert(process, TEMP_UP); | ||
210 | process->start(KShellProcess::NotifyOnExit); | ||
211 | } | ||
212 | |||
213 | void MainWindowImp::jobDone(KProcess *process){ | ||
214 | QString fileName = threads[process]; | ||
215 | threads.remove(process); | ||
216 | delete process; | ||
217 | |||
218 | QFile file(fileName); | ||
219 | if (!file.open(IO_ReadOnly)){ | ||
220 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | ||
221 | return; | ||
222 | } | ||
223 | |||
224 | QTextStream stream( &file ); | ||
225 | QString line; | ||
226 | while ( !stream.eof() ) { | ||
227 | line = stream.readLine(); | ||
228 | int space = line.find(" "); | ||
229 | if(space > 1){ | ||
230 | // We have found an interface | ||
231 | QString interfaceName = line.mid(0, space); | ||
232 | Interface *i; | ||
233 | // See if we already have it | ||
234 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | ||
235 | if(fileName == TEMP_ALL) | ||
236 | i = new Interface(interfaceName, false); | ||
237 | else | ||
238 | i = new Interface(interfaceName, true); | ||
239 | } | ||
240 | else{ | ||
241 | i = interfaceNames[interfaceName]; | ||
242 | if(fileName != TEMP_ALL) | ||
243 | i->setStatus(true); | ||
244 | } | ||
245 | |||
246 | i->setAttached(true); | ||
247 | i->setInterfaceName(interfaceName); | ||
248 | |||
249 | QString hardName = "Ethernet"; | ||
250 | int hardwareName = line.find("Link encap:"); | ||
251 | int macAddress = line.find("HWaddr"); | ||
252 | if(macAddress == -1) | ||
253 | macAddress = line.length(); | ||
254 | if(hardwareName != -1) | ||
255 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11))); | ||
256 | // We have found an interface | ||
257 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
258 | interfaceNames.insert(i->getInterfaceName(), i); | ||
259 | updateInterface(i); | ||
260 | } | ||
261 | } | ||
262 | file.close(); | ||
263 | QFile::remove(fileName); | ||
264 | } | ||
265 | |||
266 | void MainWindowImp::updateInterface(Interface *i){ | ||
267 | QListViewItem *item = NULL; | ||
268 | |||
269 | // See if we already have it | ||
270 | if(items.find(i) == items.end()){ | ||
271 | item = new QListViewItem(serviceList, "", "", ""); | ||
272 | // See if you can't find a module owner for this interface | ||
273 | //EmployeeMap::Iterator it; | ||
274 | //for( it = map.begin(); it != map.end(); ++it ) | ||
275 | // printf( "%s, %s earns %d\n", it.key().latin1(), it.data().name().latin1(), it.data().salary() ); | ||
276 | |||
277 | items.insert(i, item); | ||
278 | interfaceItems.insert(item, i); | ||
279 | } | ||
280 | else | ||
281 | item = items[i]; | ||
282 | |||
283 | QString statusImage = "down"; | ||
284 | if(i->getStatus()) | ||
285 | statusImage = "up"; | ||
286 | QPixmap status = (Resource::loadPixmap(statusImage)); | ||
287 | item->setPixmap(0, status); | ||
288 | |||
289 | QString typeName = "lan"; | ||
290 | if(i->getHardwareName().contains("Local Loopback")) | ||
291 | typeName = "lo"; | ||
292 | QPixmap type = (Resource::loadPixmap(typeName)); | ||
293 | item->setPixmap(1, type); | ||
294 | |||
295 | item->setText(2, i->getHardwareName()); | ||
296 | |||
297 | } | ||
298 | |||
299 | void MainWindowImp::addProfile(){ | ||
300 | |||
301 | } | ||
302 | |||
303 | void MainWindowImp::removeProfile(){ | ||
304 | |||
305 | } | ||
306 | |||
307 | // mainwindowimp.cpp | ||
308 | |||
diff --git a/noncore/net/networksetup/mainwindowimp.h b/noncore/net/networksetup/mainwindowimp.h new file mode 100644 index 0000000..95ec2a1 --- a/dev/null +++ b/noncore/net/networksetup/mainwindowimp.h | |||
@@ -0,0 +1,53 @@ | |||
1 | #ifndef MAINWINOWIMP_H | ||
2 | #define MAINWINOWIMP_H | ||
3 | |||
4 | #include "mainwindow.h" | ||
5 | #include "module.h" | ||
6 | #include "interface.h" | ||
7 | #include "kprocess.h" | ||
8 | #include <qmap.h> | ||
9 | |||
10 | class QLibrary; | ||
11 | |||
12 | class MainWindowImp : public MainWindow { | ||
13 | Q_OBJECT | ||
14 | |||
15 | public: | ||
16 | MainWindowImp(QWidget *parent=0, const char *name=0); | ||
17 | ~MainWindowImp(); | ||
18 | |||
19 | private slots: | ||
20 | void addClicked(); | ||
21 | void removeClicked(); | ||
22 | void configureClicked(); | ||
23 | void informationClicked(); | ||
24 | |||
25 | void jobDone(KProcess *process); | ||
26 | void getInterfaceList(); | ||
27 | |||
28 | void addProfile(); | ||
29 | void removeProfile(); | ||
30 | |||
31 | void updateInterface(Interface *i); | ||
32 | |||
33 | private: | ||
34 | void loadModules(QString path); | ||
35 | |||
36 | Module* loadPlugin(QString pluginFileName, | ||
37 | QString resolveString = "create_plugin"); | ||
38 | |||
39 | // For our local list of names | ||
40 | QMap<QString, Interface*> interfaceNames; | ||
41 | |||
42 | QMap<Module*, QLibrary*> libraries; | ||
43 | QMap<Interface*, Module*> modules; | ||
44 | QMap<Interface*, QListViewItem*> items; | ||
45 | QMap<QListViewItem*, Interface*> interfaceItems; | ||
46 | |||
47 | QMap<KProcess*, QString> threads; | ||
48 | }; | ||
49 | |||
50 | #endif | ||
51 | |||
52 | // mainwindowimp.h | ||
53 | |||
diff --git a/noncore/net/networksetup/module.h b/noncore/net/networksetup/module.h new file mode 100644 index 0000000..f146d8c --- a/dev/null +++ b/noncore/net/networksetup/module.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef MODULE_H | ||
2 | #define MODULE_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qlist.h> | ||
6 | #include <qmap.h> | ||
7 | #include "interface.h" | ||
8 | |||
9 | class QWidget; | ||
10 | |||
11 | class Module : QObject{ | ||
12 | |||
13 | signals: | ||
14 | void updateInterface(Interface *i); | ||
15 | |||
16 | public: | ||
17 | Module(){}; | ||
18 | |||
19 | virtual bool isOwner(Interface *){ return false; }; | ||
20 | virtual QWidget *configure(){ return NULL; } ; | ||
21 | virtual QWidget *information(){ return NULL; }; | ||
22 | virtual QList<Interface> getInterfaces() = 0; | ||
23 | virtual QMap<QString, QString> possibleNewInterfaces() = 0; | ||
24 | virtual Interface *addNewInterface(QString name) = 0; | ||
25 | virtual bool remove(Interface* i) = 0; | ||
26 | |||
27 | |||
28 | }; | ||
29 | |||
30 | #endif | ||
31 | |||
32 | // module.h | ||
33 | |||
diff --git a/noncore/net/networksetup/networksetup.pro b/noncore/net/networksetup/networksetup.pro new file mode 100644 index 0000000..7d9918b --- a/dev/null +++ b/noncore/net/networksetup/networksetup.pro | |||
@@ -0,0 +1,10 @@ | |||
1 | TEMPLATE= app | ||
2 | CONFIG = qt warn_on debug | ||
3 | #CONFIG = qt warn_on release | ||
4 | HEADERS = mainwindowimp.h addserviceimp.h interface.h interfaceinformationimp.h interfacesetupimp.h interfaces.h defaultmodule.h kprocctrl.h module.h kprocess.h | ||
5 | SOURCES = main.cpp mainwindowimp.cpp addserviceimp.cpp interface.cpp interfaceinformationimp.cpp interfacesetupimp.cpp kprocctrl.cpp kprocess.cpp interfaces.cpp | ||
6 | INCLUDEPATH+= $(QPEDIR)/include | ||
7 | DEPENDPATH+= $(QPEDIR)/include | ||
8 | LIBS += -lqpe | ||
9 | INTERFACES= mainwindow.ui addservice.ui interfaceinformation.ui interfaceadvanced.ui interfacesetup.ui | ||
10 | TARGET = networksetup | ||
diff --git a/noncore/net/networksetup/systemadvanced.ui b/noncore/net/networksetup/systemadvanced.ui new file mode 100644 index 0000000..6ea192c --- a/dev/null +++ b/noncore/net/networksetup/systemadvanced.ui | |||
@@ -0,0 +1,443 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>SystemNetworking</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>SystemNetworking</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>222</width> | ||
15 | <height>289</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>System Networking</string> | ||
21 | </property> | ||
22 | <vbox> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>0</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget> | ||
32 | <class>QTabWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>tabWidget</cstring> | ||
36 | </property> | ||
37 | <property> | ||
38 | <name>layoutMargin</name> | ||
39 | </property> | ||
40 | <widget> | ||
41 | <class>QWidget</class> | ||
42 | <property stdset="1"> | ||
43 | <name>name</name> | ||
44 | <cstring>tab</cstring> | ||
45 | </property> | ||
46 | <attribute> | ||
47 | <name>title</name> | ||
48 | <string>DNS</string> | ||
49 | </attribute> | ||
50 | <grid> | ||
51 | <property stdset="1"> | ||
52 | <name>margin</name> | ||
53 | <number>11</number> | ||
54 | </property> | ||
55 | <property stdset="1"> | ||
56 | <name>spacing</name> | ||
57 | <number>6</number> | ||
58 | </property> | ||
59 | <widget row="0" column="0" > | ||
60 | <class>QLabel</class> | ||
61 | <property stdset="1"> | ||
62 | <name>name</name> | ||
63 | <cstring>TextLabel6</cstring> | ||
64 | </property> | ||
65 | <property stdset="1"> | ||
66 | <name>text</name> | ||
67 | <string>Hostname</string> | ||
68 | </property> | ||
69 | </widget> | ||
70 | <widget row="1" column="0" > | ||
71 | <class>QLabel</class> | ||
72 | <property stdset="1"> | ||
73 | <name>name</name> | ||
74 | <cstring>TextLabel5</cstring> | ||
75 | </property> | ||
76 | <property stdset="1"> | ||
77 | <name>text</name> | ||
78 | <string>DNS</string> | ||
79 | </property> | ||
80 | <property stdset="1"> | ||
81 | <name>alignment</name> | ||
82 | <set>AlignTop|AlignLeft</set> | ||
83 | </property> | ||
84 | <property> | ||
85 | <name>vAlign</name> | ||
86 | </property> | ||
87 | </widget> | ||
88 | <widget row="1" column="1" > | ||
89 | <class>QListBox</class> | ||
90 | <property stdset="1"> | ||
91 | <name>name</name> | ||
92 | <cstring>ListBox5</cstring> | ||
93 | </property> | ||
94 | </widget> | ||
95 | <widget row="0" column="1" > | ||
96 | <class>QLineEdit</class> | ||
97 | <property stdset="1"> | ||
98 | <name>name</name> | ||
99 | <cstring>LineEdit7</cstring> | ||
100 | </property> | ||
101 | </widget> | ||
102 | <widget row="3" column="0" > | ||
103 | <class>QLabel</class> | ||
104 | <property stdset="1"> | ||
105 | <name>name</name> | ||
106 | <cstring>TextLabel7</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>text</name> | ||
110 | <string>Hosts</string> | ||
111 | </property> | ||
112 | </widget> | ||
113 | <widget row="3" column="1" > | ||
114 | <class>QLabel</class> | ||
115 | <property stdset="1"> | ||
116 | <name>name</name> | ||
117 | <cstring>TextLabel9</cstring> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>text</name> | ||
121 | <string>List here....</string> | ||
122 | </property> | ||
123 | </widget> | ||
124 | <widget row="2" column="0" > | ||
125 | <class>QPushButton</class> | ||
126 | <property stdset="1"> | ||
127 | <name>name</name> | ||
128 | <cstring>PushButton15</cstring> | ||
129 | </property> | ||
130 | <property stdset="1"> | ||
131 | <name>text</name> | ||
132 | <string>&Add</string> | ||
133 | </property> | ||
134 | </widget> | ||
135 | <widget row="2" column="1" > | ||
136 | <class>QPushButton</class> | ||
137 | <property stdset="1"> | ||
138 | <name>name</name> | ||
139 | <cstring>PushButton16</cstring> | ||
140 | </property> | ||
141 | <property stdset="1"> | ||
142 | <name>text</name> | ||
143 | <string>&Delete</string> | ||
144 | </property> | ||
145 | </widget> | ||
146 | <spacer row="4" column="1" > | ||
147 | <property> | ||
148 | <name>name</name> | ||
149 | <cstring>Spacer14</cstring> | ||
150 | </property> | ||
151 | <property stdset="1"> | ||
152 | <name>orientation</name> | ||
153 | <enum>Vertical</enum> | ||
154 | </property> | ||
155 | <property stdset="1"> | ||
156 | <name>sizeType</name> | ||
157 | <enum>Expanding</enum> | ||
158 | </property> | ||
159 | <property> | ||
160 | <name>sizeHint</name> | ||
161 | <size> | ||
162 | <width>20</width> | ||
163 | <height>20</height> | ||
164 | </size> | ||
165 | </property> | ||
166 | </spacer> | ||
167 | </grid> | ||
168 | </widget> | ||
169 | <widget> | ||
170 | <class>QWidget</class> | ||
171 | <property stdset="1"> | ||
172 | <name>name</name> | ||
173 | <cstring>tab</cstring> | ||
174 | </property> | ||
175 | <attribute> | ||
176 | <name>title</name> | ||
177 | <string>Routing</string> | ||
178 | </attribute> | ||
179 | <grid> | ||
180 | <property stdset="1"> | ||
181 | <name>margin</name> | ||
182 | <number>11</number> | ||
183 | </property> | ||
184 | <property stdset="1"> | ||
185 | <name>spacing</name> | ||
186 | <number>6</number> | ||
187 | </property> | ||
188 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
189 | <class>QListView</class> | ||
190 | <column> | ||
191 | <property> | ||
192 | <name>text</name> | ||
193 | <string>Destination</string> | ||
194 | </property> | ||
195 | <property> | ||
196 | <name>clickable</name> | ||
197 | <bool>true</bool> | ||
198 | </property> | ||
199 | <property> | ||
200 | <name>resizeable</name> | ||
201 | <bool>true</bool> | ||
202 | </property> | ||
203 | </column> | ||
204 | <column> | ||
205 | <property> | ||
206 | <name>text</name> | ||
207 | <string>Gateway</string> | ||
208 | </property> | ||
209 | <property> | ||
210 | <name>clickable</name> | ||
211 | <bool>true</bool> | ||
212 | </property> | ||
213 | <property> | ||
214 | <name>resizeable</name> | ||
215 | <bool>true</bool> | ||
216 | </property> | ||
217 | </column> | ||
218 | <column> | ||
219 | <property> | ||
220 | <name>text</name> | ||
221 | <string>Genmask</string> | ||
222 | </property> | ||
223 | <property> | ||
224 | <name>clickable</name> | ||
225 | <bool>true</bool> | ||
226 | </property> | ||
227 | <property> | ||
228 | <name>resizeable</name> | ||
229 | <bool>true</bool> | ||
230 | </property> | ||
231 | </column> | ||
232 | <column> | ||
233 | <property> | ||
234 | <name>text</name> | ||
235 | <string>Flags</string> | ||
236 | </property> | ||
237 | <property> | ||
238 | <name>clickable</name> | ||
239 | <bool>true</bool> | ||
240 | </property> | ||
241 | <property> | ||
242 | <name>resizeable</name> | ||
243 | <bool>true</bool> | ||
244 | </property> | ||
245 | </column> | ||
246 | <column> | ||
247 | <property> | ||
248 | <name>text</name> | ||
249 | <string>Metric</string> | ||
250 | </property> | ||
251 | <property> | ||
252 | <name>clickable</name> | ||
253 | <bool>true</bool> | ||
254 | </property> | ||
255 | <property> | ||
256 | <name>resizeable</name> | ||
257 | <bool>true</bool> | ||
258 | </property> | ||
259 | </column> | ||
260 | <column> | ||
261 | <property> | ||
262 | <name>text</name> | ||
263 | <string>Ref</string> | ||
264 | </property> | ||
265 | <property> | ||
266 | <name>clickable</name> | ||
267 | <bool>true</bool> | ||
268 | </property> | ||
269 | <property> | ||
270 | <name>resizeable</name> | ||
271 | <bool>true</bool> | ||
272 | </property> | ||
273 | </column> | ||
274 | <column> | ||
275 | <property> | ||
276 | <name>text</name> | ||
277 | <string>Use</string> | ||
278 | </property> | ||
279 | <property> | ||
280 | <name>clickable</name> | ||
281 | <bool>true</bool> | ||
282 | </property> | ||
283 | <property> | ||
284 | <name>resizeable</name> | ||
285 | <bool>true</bool> | ||
286 | </property> | ||
287 | </column> | ||
288 | <column> | ||
289 | <property> | ||
290 | <name>text</name> | ||
291 | <string>Iface</string> | ||
292 | </property> | ||
293 | <property> | ||
294 | <name>clickable</name> | ||
295 | <bool>true</bool> | ||
296 | </property> | ||
297 | <property> | ||
298 | <name>resizeable</name> | ||
299 | <bool>true</bool> | ||
300 | </property> | ||
301 | </column> | ||
302 | <item> | ||
303 | <property> | ||
304 | <name>text</name> | ||
305 | <string>192.168.1.0</string> | ||
306 | </property> | ||
307 | <property> | ||
308 | <name>text</name> | ||
309 | <string>*</string> | ||
310 | </property> | ||
311 | <property> | ||
312 | <name>text</name> | ||
313 | <string>255.255.255.0</string> | ||
314 | </property> | ||
315 | <property> | ||
316 | <name>text</name> | ||
317 | <string>U</string> | ||
318 | </property> | ||
319 | <property> | ||
320 | <name>text</name> | ||
321 | <string>0</string> | ||
322 | </property> | ||
323 | <property> | ||
324 | <name>text</name> | ||
325 | <string>0</string> | ||
326 | </property> | ||
327 | <property> | ||
328 | <name>text</name> | ||
329 | <string>0</string> | ||
330 | </property> | ||
331 | <property> | ||
332 | <name>text</name> | ||
333 | <string>eth0</string> | ||
334 | </property> | ||
335 | <property> | ||
336 | <name>pixmap</name> | ||
337 | <pixmap></pixmap> | ||
338 | </property> | ||
339 | <property> | ||
340 | <name>pixmap</name> | ||
341 | <pixmap></pixmap> | ||
342 | </property> | ||
343 | <property> | ||
344 | <name>pixmap</name> | ||
345 | <pixmap></pixmap> | ||
346 | </property> | ||
347 | <property> | ||
348 | <name>pixmap</name> | ||
349 | <pixmap></pixmap> | ||
350 | </property> | ||
351 | <property> | ||
352 | <name>pixmap</name> | ||
353 | <pixmap></pixmap> | ||
354 | </property> | ||
355 | <property> | ||
356 | <name>pixmap</name> | ||
357 | <pixmap></pixmap> | ||
358 | </property> | ||
359 | <property> | ||
360 | <name>pixmap</name> | ||
361 | <pixmap></pixmap> | ||
362 | </property> | ||
363 | <property> | ||
364 | <name>pixmap</name> | ||
365 | <pixmap></pixmap> | ||
366 | </property> | ||
367 | </item> | ||
368 | <property stdset="1"> | ||
369 | <name>name</name> | ||
370 | <cstring>ListView4</cstring> | ||
371 | </property> | ||
372 | </widget> | ||
373 | <widget row="1" column="0" > | ||
374 | <class>QPushButton</class> | ||
375 | <property stdset="1"> | ||
376 | <name>name</name> | ||
377 | <cstring>PushButton17</cstring> | ||
378 | </property> | ||
379 | <property stdset="1"> | ||
380 | <name>text</name> | ||
381 | <string>&Add</string> | ||
382 | </property> | ||
383 | </widget> | ||
384 | <widget row="1" column="1" > | ||
385 | <class>QPushButton</class> | ||
386 | <property stdset="1"> | ||
387 | <name>name</name> | ||
388 | <cstring>PushButton18</cstring> | ||
389 | </property> | ||
390 | <property stdset="1"> | ||
391 | <name>text</name> | ||
392 | <string>Remove</string> | ||
393 | </property> | ||
394 | </widget> | ||
395 | <spacer row="2" column="1" > | ||
396 | <property> | ||
397 | <name>name</name> | ||
398 | <cstring>Spacer15</cstring> | ||
399 | </property> | ||
400 | <property stdset="1"> | ||
401 | <name>orientation</name> | ||
402 | <enum>Vertical</enum> | ||
403 | </property> | ||
404 | <property stdset="1"> | ||
405 | <name>sizeType</name> | ||
406 | <enum>Expanding</enum> | ||
407 | </property> | ||
408 | <property> | ||
409 | <name>sizeHint</name> | ||
410 | <size> | ||
411 | <width>20</width> | ||
412 | <height>20</height> | ||
413 | </size> | ||
414 | </property> | ||
415 | </spacer> | ||
416 | </grid> | ||
417 | </widget> | ||
418 | </widget> | ||
419 | </vbox> | ||
420 | </widget> | ||
421 | <customwidgets> | ||
422 | <customwidget> | ||
423 | <class>QWidget</class> | ||
424 | <header location="local">qwidget.h</header> | ||
425 | <sizehint> | ||
426 | <width>100</width> | ||
427 | <height>100</height> | ||
428 | </sizehint> | ||
429 | <container>0</container> | ||
430 | <sizepolicy> | ||
431 | <hordata>7</hordata> | ||
432 | <verdata>7</verdata> | ||
433 | </sizepolicy> | ||
434 | <pixmap>image0</pixmap> | ||
435 | </customwidget> | ||
436 | </customwidgets> | ||
437 | <images> | ||
438 | <image> | ||
439 | <name>image0</name> | ||
440 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
441 | </image> | ||
442 | </images> | ||
443 | </UI> | ||
diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO new file mode 100644 index 0000000..9a1657a --- a/dev/null +++ b/noncore/settings/networksettings/TODO | |||
@@ -0,0 +1 @@ | |||
Fix DHCP obtained and expoired info | |||
diff --git a/noncore/settings/networksettings/addservice.ui b/noncore/settings/networksettings/addservice.ui new file mode 100644 index 0000000..929f4fb --- a/dev/null +++ b/noncore/settings/networksettings/addservice.ui | |||
@@ -0,0 +1,154 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>AddService</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>AddService</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>245</width> | ||
15 | <height>268</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Add Network Service</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="3" column="1" > | ||
32 | <class>QPushButton</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>cancelButton</cstring> | ||
36 | </property> | ||
37 | <property stdset="1"> | ||
38 | <name>text</name> | ||
39 | <string>Cancel</string> | ||
40 | </property> | ||
41 | </widget> | ||
42 | <widget row="3" column="0" > | ||
43 | <class>QPushButton</class> | ||
44 | <property stdset="1"> | ||
45 | <name>name</name> | ||
46 | <cstring>addButton</cstring> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>text</name> | ||
50 | <string>Add</string> | ||
51 | </property> | ||
52 | </widget> | ||
53 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
54 | <class>QListView</class> | ||
55 | <column> | ||
56 | <property> | ||
57 | <name>text</name> | ||
58 | <string>Services</string> | ||
59 | </property> | ||
60 | <property> | ||
61 | <name>clickable</name> | ||
62 | <bool>true</bool> | ||
63 | </property> | ||
64 | <property> | ||
65 | <name>resizeable</name> | ||
66 | <bool>true</bool> | ||
67 | </property> | ||
68 | </column> | ||
69 | <property stdset="1"> | ||
70 | <name>name</name> | ||
71 | <cstring>registeredServicesList</cstring> | ||
72 | </property> | ||
73 | <property stdset="1"> | ||
74 | <name>sizePolicy</name> | ||
75 | <sizepolicy> | ||
76 | <hsizetype>7</hsizetype> | ||
77 | <vsizetype>3</vsizetype> | ||
78 | </sizepolicy> | ||
79 | </property> | ||
80 | <property stdset="1"> | ||
81 | <name>minimumSize</name> | ||
82 | <size> | ||
83 | <width>0</width> | ||
84 | <height>75</height> | ||
85 | </size> | ||
86 | </property> | ||
87 | </widget> | ||
88 | <spacer row="2" column="1" > | ||
89 | <property> | ||
90 | <name>name</name> | ||
91 | <cstring>Spacer12</cstring> | ||
92 | </property> | ||
93 | <property stdset="1"> | ||
94 | <name>orientation</name> | ||
95 | <enum>Vertical</enum> | ||
96 | </property> | ||
97 | <property stdset="1"> | ||
98 | <name>sizeType</name> | ||
99 | <enum>Expanding</enum> | ||
100 | </property> | ||
101 | <property> | ||
102 | <name>sizeHint</name> | ||
103 | <size> | ||
104 | <width>20</width> | ||
105 | <height>20</height> | ||
106 | </size> | ||
107 | </property> | ||
108 | </spacer> | ||
109 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
110 | <class>QLabel</class> | ||
111 | <property stdset="1"> | ||
112 | <name>name</name> | ||
113 | <cstring>help</cstring> | ||
114 | </property> | ||
115 | <property stdset="1"> | ||
116 | <name>sizePolicy</name> | ||
117 | <sizepolicy> | ||
118 | <hsizetype>5</hsizetype> | ||
119 | <vsizetype>4</vsizetype> | ||
120 | </sizepolicy> | ||
121 | </property> | ||
122 | <property stdset="1"> | ||
123 | <name>text</name> | ||
124 | <string>LAN - TCP/IP | ||
125 | For Local-area network connections through PC_CARD network interfdace cards.</string> | ||
126 | </property> | ||
127 | <property stdset="1"> | ||
128 | <name>alignment</name> | ||
129 | <set>WordBreak|AlignTop|AlignLeft</set> | ||
130 | </property> | ||
131 | <property> | ||
132 | <name>vAlign</name> | ||
133 | </property> | ||
134 | <property> | ||
135 | <name>wordwrap</name> | ||
136 | </property> | ||
137 | </widget> | ||
138 | </grid> | ||
139 | </widget> | ||
140 | <connections> | ||
141 | <connection> | ||
142 | <sender>cancelButton</sender> | ||
143 | <signal>clicked()</signal> | ||
144 | <receiver>AddService</receiver> | ||
145 | <slot>reject()</slot> | ||
146 | </connection> | ||
147 | <connection> | ||
148 | <sender>addButton</sender> | ||
149 | <signal>clicked()</signal> | ||
150 | <receiver>AddService</receiver> | ||
151 | <slot>accept()</slot> | ||
152 | </connection> | ||
153 | </connections> | ||
154 | </UI> | ||
diff --git a/noncore/settings/networksettings/addserviceimp.cpp b/noncore/settings/networksettings/addserviceimp.cpp new file mode 100644 index 0000000..ac79d06 --- a/dev/null +++ b/noncore/settings/networksettings/addserviceimp.cpp | |||
@@ -0,0 +1,26 @@ | |||
1 | #include "addserviceimp.h" | ||
2 | #include <qpe/qlibrary.h> | ||
3 | #include <qlistview.h> | ||
4 | #include <qlist.h> | ||
5 | |||
6 | void AddServiceImp::addServices(QList<QString> list){ | ||
7 | list.setAutoDelete(true); | ||
8 | |||
9 | for(uint i = 0; i < list.count(); i++){ | ||
10 | QString pluginFileName = ""; | ||
11 | QLibrary *lib = new QLibrary(pluginFileName); | ||
12 | void *functionPointer = lib->resolve("info"); | ||
13 | if( !functionPointer ){ | ||
14 | qDebug(QString("AddServiceImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | ||
15 | delete lib; | ||
16 | break; | ||
17 | } | ||
18 | |||
19 | // Try to get an info. | ||
20 | QString info = ((QString (*)()) functionPointer)(); | ||
21 | QListViewItem *newItem = new QListViewItem(registeredServicesList, info); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | |||
26 | // addserviceimp.cpp | ||
diff --git a/noncore/settings/networksettings/addserviceimp.h b/noncore/settings/networksettings/addserviceimp.h new file mode 100644 index 0000000..7cacb97 --- a/dev/null +++ b/noncore/settings/networksettings/addserviceimp.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef ADDSERVICEIMP_H | ||
2 | #define ADDSERVICEIMP_H | ||
3 | |||
4 | #include "addservice.h" | ||
5 | #include <qmap.h> | ||
6 | #include <qlist.h> | ||
7 | |||
8 | class QListViewItem; | ||
9 | |||
10 | class AddServiceImp : public AddService { | ||
11 | |||
12 | Q_OBJECT | ||
13 | |||
14 | public: | ||
15 | AddServiceImp(QWidget *parent=0, const char *name=0, WFlags f=0):AddService(parent, name, f){}; | ||
16 | void addServices(QList<QString> list); | ||
17 | |||
18 | private: | ||
19 | QMap<QListViewItem*, QString> pluginInfo; | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
24 | |||
25 | // addserviceimp.h | ||
26 | |||
diff --git a/noncore/settings/networksettings/defaultmodule.h b/noncore/settings/networksettings/defaultmodule.h new file mode 100644 index 0000000..c7791d5 --- a/dev/null +++ b/noncore/settings/networksettings/defaultmodule.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef MODULE_H | ||
2 | #define MODULE_H | ||
3 | |||
4 | #include "module.h" | ||
5 | |||
6 | class QWidget; | ||
7 | |||
8 | class DefaultModule : Module{ | ||
9 | |||
10 | public: | ||
11 | DefaultModule(){}; | ||
12 | |||
13 | virtual bool isOwner(Interface *i); | ||
14 | virtual QWidget *configure(); | ||
15 | virtual QWidget *information()}; | ||
16 | virtual QList<Interface> getInterfaces(); | ||
17 | virtual QMap<QString, QString> possibleNewInterfaces(); | ||
18 | virtual Interface *addNewInterface(QString name); | ||
19 | virtual bool remove(Interface* i); | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
24 | |||
25 | // module.h | ||
26 | |||
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp new file mode 100644 index 0000000..b9b09ad --- a/dev/null +++ b/noncore/settings/networksettings/interface.cpp | |||
@@ -0,0 +1,236 @@ | |||
1 | #include "interface.h" | ||
2 | #include <qdatetime.h> | ||
3 | #include <qfile.h> | ||
4 | #include <qfileinfo.h> | ||
5 | #include <qtextstream.h> | ||
6 | |||
7 | #define IFCONFIG "/sbin/ifconfig" | ||
8 | #define HDCP_INFO_DIR "/etc/dhcpc" | ||
9 | |||
10 | #include <stdio.h> | ||
11 | #include <stdlib.h> | ||
12 | |||
13 | Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner("Default"), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ | ||
14 | refresh(); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * Try to start the interface. | ||
19 | * @return bool true if successfull. | ||
20 | */ | ||
21 | bool Interface::start(){ | ||
22 | // check to see if we are already running. | ||
23 | if(status) | ||
24 | return false; | ||
25 | |||
26 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | ||
27 | if(ret != 0) | ||
28 | return false; | ||
29 | |||
30 | status = true; | ||
31 | refresh(); | ||
32 | return true; | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Try to stop the interface. | ||
37 | * @return bool true if successfull. | ||
38 | */ | ||
39 | bool Interface::stop(){ | ||
40 | // check to see if we are already stopped. | ||
41 | if(status == false) | ||
42 | return false; | ||
43 | |||
44 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | ||
45 | if(ret != 0) | ||
46 | return false; | ||
47 | |||
48 | status = true; | ||
49 | refresh(); | ||
50 | return true; | ||
51 | } | ||
52 | /** | ||
53 | * Try to restart the interface. | ||
54 | * @return bool true if successfull. | ||
55 | */ | ||
56 | bool Interface::restart(){ | ||
57 | return (stop() && start()); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Try to refresh the information about the interface. | ||
62 | * First call ifconfig, then check the dhcp-info file | ||
63 | * @return bool true if successfull. | ||
64 | */ | ||
65 | bool Interface::refresh(){ | ||
66 | // See if we are up. | ||
67 | if(status == false){ | ||
68 | macAddress = ""; | ||
69 | ip = "0.0.0.0"; | ||
70 | subnetMask = "0.0.0.0"; | ||
71 | broadcast = ""; | ||
72 | dhcp = false; | ||
73 | dhcpServerIp = ""; | ||
74 | leaseObtained = ""; | ||
75 | leaseExpires = ""; | ||
76 | return true; | ||
77 | } | ||
78 | |||
79 | 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 | if(ret != 0){ | ||
82 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | QFile file(fileName); | ||
87 | if (!file.open(IO_ReadOnly)){ | ||
88 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | // Set to the defaults | ||
93 | macAddress = ""; | ||
94 | ip = "0.0.0.0"; | ||
95 | subnetMask = "0.0.0.0"; | ||
96 | broadcast = ""; | ||
97 | |||
98 | QTextStream stream( &file ); | ||
99 | QString line; | ||
100 | while ( !stream.eof() ) { | ||
101 | line = stream.readLine(); | ||
102 | if(line.contains("HWaddr")){ | ||
103 | int mac = line.find("HWaddr"); | ||
104 | macAddress = line.mid(mac+7, line.length()); | ||
105 | } | ||
106 | if(line.contains("inet addr")){ | ||
107 | int ipl = line.find("inet addr"); | ||
108 | int space = line.find(" ", ipl+10); | ||
109 | ip = line.mid(ipl+10, space-ipl-10); | ||
110 | } | ||
111 | if(line.contains("Mask")){ | ||
112 | int mask = line.find("Mask"); | ||
113 | subnetMask = line.mid(mask+5, line.length()); | ||
114 | } | ||
115 | if(line.contains("Bcast")){ | ||
116 | int mask = line.find("Bcast"); | ||
117 | int space = line.find(" ", mask+6); | ||
118 | broadcast = line.mid(mask+6, space-mask-6); | ||
119 | } | ||
120 | } | ||
121 | file.close(); | ||
122 | QFile::remove(fileName); | ||
123 | |||
124 | // DHCP TESTING | ||
125 | // reset DHCP info | ||
126 | dhcpServerIp = ""; | ||
127 | leaseObtained = ""; | ||
128 | leaseExpires = ""; | ||
129 | dhcp = false; | ||
130 | |||
131 | // See if we have | ||
132 | QString dhcpFile(QString(HDCP_INFO_DIR "/dhcpcd-%1.info").arg(interfaceName)); | ||
133 | // If there is no DHCP information then exit now with no errors. | ||
134 | if(!QFile::exists(dhcpFile)){ | ||
135 | return true; | ||
136 | } | ||
137 | |||
138 | file.setName(dhcpFile); | ||
139 | if (!file.open(IO_ReadOnly)){ | ||
140 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | ||
141 | return false; | ||
142 | } | ||
143 | |||
144 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | ||
145 | int leaseTime = 0; | ||
146 | int renewalTime = 0; | ||
147 | |||
148 | stream.setDevice( &file ); | ||
149 | while ( !stream.eof() ) { | ||
150 | line = stream.readLine(); | ||
151 | if(line.contains("DHCPSID=")) | ||
152 | dhcpServerIp = line.mid(8, line.length()); | ||
153 | if(line.contains("LEASETIME=")) | ||
154 | leaseTime = line.mid(10, line.length()).toInt(); | ||
155 | if(line.contains("RENEWALTIME=")) | ||
156 | renewalTime = line.mid(12, line.length()).toInt(); | ||
157 | } | ||
158 | file.close(); | ||
159 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | ||
160 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | ||
161 | |||
162 | // Get the pid of the deamond | ||
163 | dhcpFile = (QString(HDCP_INFO_DIR "/dhcpcd-%1.pid").arg(interfaceName)); | ||
164 | file.setName(dhcpFile); | ||
165 | if (!file.open(IO_ReadOnly)){ | ||
166 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | ||
167 | return false; | ||
168 | } | ||
169 | |||
170 | int pid = -1; | ||
171 | stream.setDevice( &file ); | ||
172 | while ( !stream.eof() ) { | ||
173 | line = stream.readLine(); | ||
174 | pid = line.toInt(); | ||
175 | } | ||
176 | file.close(); | ||
177 | |||
178 | if( pid == -1){ | ||
179 | qDebug("Interface: Could not get pid of dhcpc deamon."); | ||
180 | return false; | ||
181 | } | ||
182 | |||
183 | // Get the start running time of the deamon | ||
184 | fileName = (QString("/proc/%1/stat").arg(pid)); | ||
185 | file.setName(fileName); | ||
186 | stream.setDevice( &file ); | ||
187 | if (!file.open(IO_ReadOnly)){ | ||
188 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | ||
189 | return false; | ||
190 | } | ||
191 | while ( !stream.eof() ) { | ||
192 | line = stream.readLine(); | ||
193 | } | ||
194 | file.close(); | ||
195 | long time = 0; | ||
196 | // Grab the start time | ||
197 | // pid com state ppid pgrp session tty_nr tpgid flags | ||
198 | int r = sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | ||
199 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | ||
200 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | ||
201 | // nice 0 itrealvalue starttime | ||
202 | "%*d %*d %*d %lu", (long*) &time); | ||
203 | time = time/100; | ||
204 | |||
205 | QDateTime datetime(QDateTime::currentDateTime()); | ||
206 | |||
207 | // Get the uptime of the computer. | ||
208 | QFile f("/proc/uptime"); | ||
209 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | ||
210 | QTextStream t( &f ); // use a text stream | ||
211 | int sec = 0; | ||
212 | t >> sec; | ||
213 | datetime = datetime.addSecs((-1*sec)); | ||
214 | f.close(); | ||
215 | } | ||
216 | else{ | ||
217 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | datetime = datetime.addSecs(time); | ||
222 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | ||
223 | |||
224 | // Calculate the start and renew times | ||
225 | leaseObtained= datetime.toString(); | ||
226 | |||
227 | // Calculate the start and renew times | ||
228 | datetime = datetime.addSecs(leaseTime); | ||
229 | leaseExpires = datetime.toString(); | ||
230 | |||
231 | dhcp = true; | ||
232 | return true; | ||
233 | } | ||
234 | |||
235 | // interface.cpp | ||
236 | |||
diff --git a/noncore/settings/networksettings/interface.h b/noncore/settings/networksettings/interface.h new file mode 100644 index 0000000..1ad71eb --- a/dev/null +++ b/noncore/settings/networksettings/interface.h | |||
@@ -0,0 +1,65 @@ | |||
1 | #ifndef INTERFACE_H | ||
2 | #define INTERFACE_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | |||
6 | class Interface { | ||
7 | |||
8 | public: | ||
9 | Interface(QString name = "unknown", bool status = false); | ||
10 | virtual ~Interface(){}; | ||
11 | |||
12 | virtual bool getStatus(){ return status; }; | ||
13 | virtual void setStatus(bool newSatus){ status = newSatus; refresh(); }; | ||
14 | |||
15 | virtual bool isAttached(){ return attached; }; | ||
16 | virtual void setAttached(bool isAttached=false){ attached = isAttached; }; | ||
17 | |||
18 | virtual QString getInterfaceName(){ return interfaceName; }; | ||
19 | virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; }; | ||
20 | |||
21 | virtual QString getHardwareName(){ return hardareName; }; | ||
22 | virtual void setHardwareName(QString name="Unknown"){ hardareName = name; }; | ||
23 | |||
24 | virtual QString getModuleOwner(){ return moduleOwner; }; | ||
25 | virtual void setModuleOwner(QString owner="Default"){ moduleOwner = owner; }; | ||
26 | |||
27 | // inet information. | ||
28 | QString getMacAddress(){ return macAddress; }; | ||
29 | QString getIp(){ return ip; }; | ||
30 | QString getSubnetMask(){ return subnetMask; }; | ||
31 | QString getBroadcast(){ return broadcast; }; | ||
32 | bool isDhcp(){ return dhcp; }; | ||
33 | QString getDhcpServerIp(){ return dhcpServerIp; }; | ||
34 | QString getLeaseObtained(){ return leaseObtained; }; | ||
35 | QString getLeaseExpires(){ return leaseExpires; }; | ||
36 | |||
37 | bool refresh(); | ||
38 | bool start(); | ||
39 | bool stop(); | ||
40 | bool restart(); | ||
41 | |||
42 | private: | ||
43 | // Interface information | ||
44 | bool status; | ||
45 | bool attached; | ||
46 | QString interfaceName; | ||
47 | QString hardareName; | ||
48 | QString moduleOwner; | ||
49 | |||
50 | // Network information | ||
51 | QString macAddress; | ||
52 | QString ip; | ||
53 | QString broadcast; | ||
54 | QString subnetMask; | ||
55 | bool dhcp; | ||
56 | QString dhcpServerIp; | ||
57 | QString leaseObtained; | ||
58 | QString leaseExpires; | ||
59 | |||
60 | }; | ||
61 | |||
62 | #endif | ||
63 | |||
64 | // interface.h | ||
65 | |||
diff --git a/noncore/settings/networksettings/interfaceadvanced.ui b/noncore/settings/networksettings/interfaceadvanced.ui new file mode 100644 index 0000000..8ef0b29 --- a/dev/null +++ b/noncore/settings/networksettings/interfaceadvanced.ui | |||
@@ -0,0 +1,323 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InterfaceAdvanced</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>InterfaceAdvanced</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>197</width> | ||
15 | <height>253</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Advanced Interface Information</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="1" column="0" > | ||
32 | <class>QLabel</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>TextLabel1</cstring> | ||
36 | </property> | ||
37 | <property stdset="1"> | ||
38 | <name>text</name> | ||
39 | <string>MAC Address</string> | ||
40 | </property> | ||
41 | </widget> | ||
42 | <widget row="0" column="1" > | ||
43 | <class>QLabel</class> | ||
44 | <property stdset="1"> | ||
45 | <name>name</name> | ||
46 | <cstring>interfaceName</cstring> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>frameShape</name> | ||
50 | <enum>Panel</enum> | ||
51 | </property> | ||
52 | <property stdset="1"> | ||
53 | <name>frameShadow</name> | ||
54 | <enum>Sunken</enum> | ||
55 | </property> | ||
56 | <property stdset="1"> | ||
57 | <name>text</name> | ||
58 | <string>eth0</string> | ||
59 | </property> | ||
60 | </widget> | ||
61 | <widget row="2" column="0" > | ||
62 | <class>QLabel</class> | ||
63 | <property stdset="1"> | ||
64 | <name>name</name> | ||
65 | <cstring>TextLabel3</cstring> | ||
66 | </property> | ||
67 | <property stdset="1"> | ||
68 | <name>text</name> | ||
69 | <string>IP Address</string> | ||
70 | </property> | ||
71 | </widget> | ||
72 | <widget row="1" column="1" > | ||
73 | <class>QLabel</class> | ||
74 | <property stdset="1"> | ||
75 | <name>name</name> | ||
76 | <cstring>macAddressLabel</cstring> | ||
77 | </property> | ||
78 | <property stdset="1"> | ||
79 | <name>frameShape</name> | ||
80 | <enum>Panel</enum> | ||
81 | </property> | ||
82 | <property stdset="1"> | ||
83 | <name>frameShadow</name> | ||
84 | <enum>Sunken</enum> | ||
85 | </property> | ||
86 | <property stdset="1"> | ||
87 | <name>text</name> | ||
88 | <string>00:00:00:00:00:00</string> | ||
89 | </property> | ||
90 | </widget> | ||
91 | <widget row="0" column="0" > | ||
92 | <class>QLabel</class> | ||
93 | <property stdset="1"> | ||
94 | <name>name</name> | ||
95 | <cstring>TextLabel7</cstring> | ||
96 | </property> | ||
97 | <property stdset="1"> | ||
98 | <name>text</name> | ||
99 | <string>Interface</string> | ||
100 | </property> | ||
101 | </widget> | ||
102 | <widget row="8" column="0" > | ||
103 | <class>QLabel</class> | ||
104 | <property stdset="1"> | ||
105 | <name>name</name> | ||
106 | <cstring>TextLabel9</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>text</name> | ||
110 | <string>Lease Expires</string> | ||
111 | </property> | ||
112 | </widget> | ||
113 | <widget row="8" column="1" > | ||
114 | <class>QLabel</class> | ||
115 | <property stdset="1"> | ||
116 | <name>name</name> | ||
117 | <cstring>leaseExpiresLabel</cstring> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>frameShape</name> | ||
121 | <enum>Panel</enum> | ||
122 | </property> | ||
123 | <property stdset="1"> | ||
124 | <name>frameShadow</name> | ||
125 | <enum>Sunken</enum> | ||
126 | </property> | ||
127 | <property stdset="1"> | ||
128 | <name>text</name> | ||
129 | <string></string> | ||
130 | </property> | ||
131 | </widget> | ||
132 | <widget row="7" column="1" > | ||
133 | <class>QLabel</class> | ||
134 | <property stdset="1"> | ||
135 | <name>name</name> | ||
136 | <cstring>leaseObtainedLabel</cstring> | ||
137 | </property> | ||
138 | <property stdset="1"> | ||
139 | <name>frameShape</name> | ||
140 | <enum>Panel</enum> | ||
141 | </property> | ||
142 | <property stdset="1"> | ||
143 | <name>frameShadow</name> | ||
144 | <enum>Sunken</enum> | ||
145 | </property> | ||
146 | <property stdset="1"> | ||
147 | <name>text</name> | ||
148 | <string></string> | ||
149 | </property> | ||
150 | </widget> | ||
151 | <widget row="7" column="0" > | ||
152 | <class>QLabel</class> | ||
153 | <property stdset="1"> | ||
154 | <name>name</name> | ||
155 | <cstring>TextLabel8</cstring> | ||
156 | </property> | ||
157 | <property stdset="1"> | ||
158 | <name>text</name> | ||
159 | <string>Lease Obtained</string> | ||
160 | </property> | ||
161 | </widget> | ||
162 | <widget row="6" column="1" > | ||
163 | <class>QLabel</class> | ||
164 | <property stdset="1"> | ||
165 | <name>name</name> | ||
166 | <cstring>dhcpServerLabel</cstring> | ||
167 | </property> | ||
168 | <property stdset="1"> | ||
169 | <name>frameShape</name> | ||
170 | <enum>Panel</enum> | ||
171 | </property> | ||
172 | <property stdset="1"> | ||
173 | <name>frameShadow</name> | ||
174 | <enum>Sunken</enum> | ||
175 | </property> | ||
176 | <property stdset="1"> | ||
177 | <name>text</name> | ||
178 | <string>255.255.255.255</string> | ||
179 | </property> | ||
180 | </widget> | ||
181 | <widget row="6" column="0" > | ||
182 | <class>QLabel</class> | ||
183 | <property stdset="1"> | ||
184 | <name>name</name> | ||
185 | <cstring>TextLabel6</cstring> | ||
186 | </property> | ||
187 | <property stdset="1"> | ||
188 | <name>text</name> | ||
189 | <string>DHCP Server</string> | ||
190 | </property> | ||
191 | </widget> | ||
192 | <widget row="4" column="0" > | ||
193 | <class>QLabel</class> | ||
194 | <property stdset="1"> | ||
195 | <name>name</name> | ||
196 | <cstring>TextLabel4</cstring> | ||
197 | </property> | ||
198 | <property stdset="1"> | ||
199 | <name>text</name> | ||
200 | <string>Subnet Mask</string> | ||
201 | </property> | ||
202 | </widget> | ||
203 | <widget row="2" column="1" > | ||
204 | <class>QLabel</class> | ||
205 | <property stdset="1"> | ||
206 | <name>name</name> | ||
207 | <cstring>ipAddressLabel</cstring> | ||
208 | </property> | ||
209 | <property stdset="1"> | ||
210 | <name>frameShape</name> | ||
211 | <enum>Panel</enum> | ||
212 | </property> | ||
213 | <property stdset="1"> | ||
214 | <name>frameShadow</name> | ||
215 | <enum>Sunken</enum> | ||
216 | </property> | ||
217 | <property stdset="1"> | ||
218 | <name>text</name> | ||
219 | <string>0.0.0.0</string> | ||
220 | </property> | ||
221 | </widget> | ||
222 | <widget row="4" column="1" > | ||
223 | <class>QLabel</class> | ||
224 | <property stdset="1"> | ||
225 | <name>name</name> | ||
226 | <cstring>subnetMaskLabel</cstring> | ||
227 | </property> | ||
228 | <property stdset="1"> | ||
229 | <name>frameShape</name> | ||
230 | <enum>Panel</enum> | ||
231 | </property> | ||
232 | <property stdset="1"> | ||
233 | <name>frameShadow</name> | ||
234 | <enum>Sunken</enum> | ||
235 | </property> | ||
236 | <property stdset="1"> | ||
237 | <name>text</name> | ||
238 | <string>0.0.0.0</string> | ||
239 | </property> | ||
240 | </widget> | ||
241 | <spacer row="9" column="1" > | ||
242 | <property> | ||
243 | <name>name</name> | ||
244 | <cstring>Spacer2</cstring> | ||
245 | </property> | ||
246 | <property stdset="1"> | ||
247 | <name>orientation</name> | ||
248 | <enum>Vertical</enum> | ||
249 | </property> | ||
250 | <property stdset="1"> | ||
251 | <name>sizeType</name> | ||
252 | <enum>Expanding</enum> | ||
253 | </property> | ||
254 | <property> | ||
255 | <name>sizeHint</name> | ||
256 | <size> | ||
257 | <width>20</width> | ||
258 | <height>20</height> | ||
259 | </size> | ||
260 | </property> | ||
261 | </spacer> | ||
262 | <widget row="3" column="0" > | ||
263 | <class>QLabel</class> | ||
264 | <property stdset="1"> | ||
265 | <name>name</name> | ||
266 | <cstring>TextLabel2</cstring> | ||
267 | </property> | ||
268 | <property stdset="1"> | ||
269 | <name>text</name> | ||
270 | <string>Broadcast</string> | ||
271 | </property> | ||
272 | </widget> | ||
273 | <widget row="3" column="1" > | ||
274 | <class>QLabel</class> | ||
275 | <property stdset="1"> | ||
276 | <name>name</name> | ||
277 | <cstring>broadcastLabel</cstring> | ||
278 | </property> | ||
279 | <property stdset="1"> | ||
280 | <name>frameShape</name> | ||
281 | <enum>Panel</enum> | ||
282 | </property> | ||
283 | <property stdset="1"> | ||
284 | <name>frameShadow</name> | ||
285 | <enum>Sunken</enum> | ||
286 | </property> | ||
287 | </widget> | ||
288 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
289 | <class>Line</class> | ||
290 | <property stdset="1"> | ||
291 | <name>name</name> | ||
292 | <cstring>Line2</cstring> | ||
293 | </property> | ||
294 | <property stdset="1"> | ||
295 | <name>orientation</name> | ||
296 | <enum>Horizontal</enum> | ||
297 | </property> | ||
298 | </widget> | ||
299 | </grid> | ||
300 | </widget> | ||
301 | <customwidgets> | ||
302 | <customwidget> | ||
303 | <class>QWidget</class> | ||
304 | <header location="local">qwidget.h</header> | ||
305 | <sizehint> | ||
306 | <width>100</width> | ||
307 | <height>100</height> | ||
308 | </sizehint> | ||
309 | <container>0</container> | ||
310 | <sizepolicy> | ||
311 | <hordata>7</hordata> | ||
312 | <verdata>7</verdata> | ||
313 | </sizepolicy> | ||
314 | <pixmap>image0</pixmap> | ||
315 | </customwidget> | ||
316 | </customwidgets> | ||
317 | <images> | ||
318 | <image> | ||
319 | <name>image0</name> | ||
320 | <data format="XPM.GZ" length="45">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523250004143a55a6b2e0026630c4f</data> | ||
321 | </image> | ||
322 | </images> | ||
323 | </UI> | ||
diff --git a/noncore/settings/networksettings/interfaceedit.cpp b/noncore/settings/networksettings/interfaceedit.cpp new file mode 100644 index 0000000..25599ef --- a/dev/null +++ b/noncore/settings/networksettings/interfaceedit.cpp | |||
@@ -0,0 +1,141 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Form implementation generated from reading ui file 'interfaceedit.ui' | ||
3 | ** | ||
4 | ** Created: Mon Sep 23 12:18:55 2002 | ||
5 | ** by: The User Interface Compiler (uic) | ||
6 | ** | ||
7 | ** WARNING! All changes made in this file will be lost! | ||
8 | ****************************************************************************/ | ||
9 | #include "interfaceedit.h" | ||
10 | |||
11 | #include <qcheckbox.h> | ||
12 | #include <qcombobox.h> | ||
13 | #include <qframe.h> | ||
14 | #include <qgroupbox.h> | ||
15 | #include <qlabel.h> | ||
16 | #include <qlineedit.h> | ||
17 | #include <qpushbutton.h> | ||
18 | #include <qspinbox.h> | ||
19 | #include "qwidget.h" | ||
20 | #include <qlayout.h> | ||
21 | #include <qvariant.h> | ||
22 | #include <qtooltip.h> | ||
23 | #include <qwhatsthis.h> | ||
24 | |||
25 | /* | ||
26 | * Constructs a InterfaceConfiguration which is a child of 'parent', with the | ||
27 | * name 'name' and widget flags set to 'f' | ||
28 | */ | ||
29 | InterfaceConfiguration::InterfaceConfiguration( QWidget* parent, const char* name, WFlags fl ) | ||
30 | : QWidget( parent, name, fl ) | ||
31 | { | ||
32 | if ( !name ) | ||
33 | setName( "InterfaceConfiguration" ); | ||
34 | resize( 177, 306 ); | ||
35 | setCaption( tr( "Interface Configuration" ) ); | ||
36 | InterfaceConfigurationLayout = new QGridLayout( this ); | ||
37 | InterfaceConfigurationLayout->setSpacing( 6 ); | ||
38 | InterfaceConfigurationLayout->setMargin( 11 ); | ||
39 | |||
40 | profile = new QComboBox( FALSE, this, "profile" ); | ||
41 | profile->insertItem( tr( "All" ) ); | ||
42 | |||
43 | InterfaceConfigurationLayout->addWidget( profile, 2, 1 ); | ||
44 | |||
45 | TextLabel1 = new QLabel( this, "TextLabel1" ); | ||
46 | TextLabel1->setText( tr( "Profile:" ) ); | ||
47 | |||
48 | InterfaceConfigurationLayout->addWidget( TextLabel1, 2, 0 ); | ||
49 | |||
50 | Line1 = new QFrame( this, "Line1" ); | ||
51 | Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
52 | |||
53 | InterfaceConfigurationLayout->addMultiCellWidget( Line1, 1, 1, 0, 1 ); | ||
54 | |||
55 | CheckBox3 = new QCheckBox( this, "CheckBox3" ); | ||
56 | CheckBox3->setText( tr( "Automaticly bring up" ) ); | ||
57 | |||
58 | InterfaceConfigurationLayout->addMultiCellWidget( CheckBox3, 0, 0, 0, 1 ); | ||
59 | |||
60 | dhcpCheckBox = new QCheckBox( this, "dhcpCheckBox" ); | ||
61 | dhcpCheckBox->setText( tr( "DHCP" ) ); | ||
62 | |||
63 | InterfaceConfigurationLayout->addMultiCellWidget( dhcpCheckBox, 3, 3, 0, 1 ); | ||
64 | |||
65 | TextLabel3_3_2 = new QLabel( this, "TextLabel3_3_2" ); | ||
66 | TextLabel3_3_2->setText( tr( "Lease Hours" ) ); | ||
67 | |||
68 | InterfaceConfigurationLayout->addWidget( TextLabel3_3_2, 4, 0 ); | ||
69 | |||
70 | SpinBox1_2 = new QSpinBox( this, "SpinBox1_2" ); | ||
71 | SpinBox1_2->setMaxValue( 336 ); | ||
72 | SpinBox1_2->setMinValue( 1 ); | ||
73 | SpinBox1_2->setValue( 24 ); | ||
74 | |||
75 | InterfaceConfigurationLayout->addWidget( SpinBox1_2, 4, 1 ); | ||
76 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | ||
77 | InterfaceConfigurationLayout->addItem( spacer, 11, 1 ); | ||
78 | |||
79 | TextLabel4 = new QLabel( this, "TextLabel4" ); | ||
80 | TextLabel4->setText( tr( "IP Address" ) ); | ||
81 | |||
82 | InterfaceConfigurationLayout->addWidget( TextLabel4, 6, 0 ); | ||
83 | |||
84 | ipAddressEdit = new QLineEdit( this, "ipAddressEdit" ); | ||
85 | |||
86 | InterfaceConfigurationLayout->addWidget( ipAddressEdit, 6, 1 ); | ||
87 | |||
88 | TextLabel5 = new QLabel( this, "TextLabel5" ); | ||
89 | TextLabel5->setText( tr( "Subnet Mask" ) ); | ||
90 | |||
91 | InterfaceConfigurationLayout->addWidget( TextLabel5, 7, 0 ); | ||
92 | |||
93 | firstDNSLineEdit = new QLineEdit( this, "firstDNSLineEdit" ); | ||
94 | |||
95 | InterfaceConfigurationLayout->addWidget( firstDNSLineEdit, 9, 1 ); | ||
96 | |||
97 | TextLabel3 = new QLabel( this, "TextLabel3" ); | ||
98 | TextLabel3->setText( tr( "Second DNS" ) ); | ||
99 | |||
100 | InterfaceConfigurationLayout->addWidget( TextLabel3, 10, 0 ); | ||
101 | |||
102 | subnetMaskEdit = new QLineEdit( this, "subnetMaskEdit" ); | ||
103 | |||
104 | InterfaceConfigurationLayout->addWidget( subnetMaskEdit, 7, 1 ); | ||
105 | |||
106 | gatewayEdit = new QLineEdit( this, "gatewayEdit" ); | ||
107 | |||
108 | InterfaceConfigurationLayout->addWidget( gatewayEdit, 8, 1 ); | ||
109 | |||
110 | TextLabel7 = new QLabel( this, "TextLabel7" ); | ||
111 | TextLabel7->setText( tr( "Gateway" ) ); | ||
112 | |||
113 | InterfaceConfigurationLayout->addWidget( TextLabel7, 8, 0 ); | ||
114 | |||
115 | TextLabel2 = new QLabel( this, "TextLabel2" ); | ||
116 | TextLabel2->setText( tr( "First DNS" ) ); | ||
117 | |||
118 | InterfaceConfigurationLayout->addWidget( TextLabel2, 9, 0 ); | ||
119 | |||
120 | secondDNSLineEdit = new QLineEdit( this, "secondDNSLineEdit" ); | ||
121 | |||
122 | InterfaceConfigurationLayout->addWidget( secondDNSLineEdit, 10, 1 ); | ||
123 | |||
124 | GroupBox2 = new QGroupBox( this, "GroupBox2" ); | ||
125 | GroupBox2->setTitle( tr( "Static Ip Configuration" ) ); | ||
126 | |||
127 | InterfaceConfigurationLayout->addMultiCellWidget( GroupBox2, 5, 5, 0, 1 ); | ||
128 | |||
129 | // signals and slots connections | ||
130 | connect( dhcpCheckBox, SIGNAL( toggled(bool) ), SpinBox1_2, SLOT( setEnabled(bool) ) ); | ||
131 | connect( dhcpCheckBox, SIGNAL( toggled(bool) ), GroupBox2, SLOT( setDisabled(bool) ) ); | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Destroys the object and frees any allocated resources | ||
136 | */ | ||
137 | InterfaceConfiguration::~InterfaceConfiguration() | ||
138 | { | ||
139 | // no need to delete child widgets, Qt does it all for us | ||
140 | } | ||
141 | |||
diff --git a/noncore/settings/networksettings/interfaceedit.h b/noncore/settings/networksettings/interfaceedit.h new file mode 100644 index 0000000..a65c030 --- a/dev/null +++ b/noncore/settings/networksettings/interfaceedit.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Form interface generated from reading ui file 'interfaceedit.ui' | ||
3 | ** | ||
4 | ** Created: Mon Sep 23 12:18:55 2002 | ||
5 | ** by: The User Interface Compiler (uic) | ||
6 | ** | ||
7 | ** WARNING! All changes made in this file will be lost! | ||
8 | ****************************************************************************/ | ||
9 | #ifndef INTERFACECONFIGURATION_H | ||
10 | #define INTERFACECONFIGURATION_H | ||
11 | |||
12 | #include <qvariant.h> | ||
13 | #include <qwidget.h> | ||
14 | class QVBoxLayout; | ||
15 | class QHBoxLayout; | ||
16 | class QGridLayout; | ||
17 | class QCheckBox; | ||
18 | class QComboBox; | ||
19 | class QFrame; | ||
20 | class QGroupBox; | ||
21 | class QLabel; | ||
22 | class QLineEdit; | ||
23 | class QSpinBox; | ||
24 | |||
25 | class InterfaceConfiguration : public QWidget | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | |||
29 | public: | ||
30 | InterfaceConfiguration( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | ||
31 | ~InterfaceConfiguration(); | ||
32 | |||
33 | QComboBox* profile; | ||
34 | QLabel* TextLabel1; | ||
35 | QFrame* Line1; | ||
36 | QCheckBox* CheckBox3; | ||
37 | QCheckBox* dhcpCheckBox; | ||
38 | QLabel* TextLabel3_3_2; | ||
39 | QSpinBox* SpinBox1_2; | ||
40 | QLabel* TextLabel4; | ||
41 | QLineEdit* ipAddressEdit; | ||
42 | QLabel* TextLabel5; | ||
43 | QLineEdit* firstDNSLineEdit; | ||
44 | QLabel* TextLabel3; | ||
45 | QLineEdit* subnetMaskEdit; | ||
46 | QLineEdit* gatewayEdit; | ||
47 | QLabel* TextLabel7; | ||
48 | QLabel* TextLabel2; | ||
49 | QLineEdit* secondDNSLineEdit; | ||
50 | QGroupBox* GroupBox2; | ||
51 | |||
52 | protected: | ||
53 | QGridLayout* InterfaceConfigurationLayout; | ||
54 | }; | ||
55 | |||
56 | #endif // INTERFACECONFIGURATION_H | ||
diff --git a/noncore/settings/networksettings/interfaceinformation.ui b/noncore/settings/networksettings/interfaceinformation.ui new file mode 100644 index 0000000..2a9b3fb --- a/dev/null +++ b/noncore/settings/networksettings/interfaceinformation.ui | |||
@@ -0,0 +1,317 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InterfaceInformation</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>InterfaceInformation</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>191</width> | ||
15 | <height>241</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Interface Information</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="4" column="0" rowspan="1" colspan="2" > | ||
32 | <class>QLayoutWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>Layout1</cstring> | ||
36 | </property> | ||
37 | <grid> | ||
38 | <property stdset="1"> | ||
39 | <name>margin</name> | ||
40 | <number>0</number> | ||
41 | </property> | ||
42 | <property stdset="1"> | ||
43 | <name>spacing</name> | ||
44 | <number>6</number> | ||
45 | </property> | ||
46 | <widget row="1" column="0" > | ||
47 | <class>QPushButton</class> | ||
48 | <property stdset="1"> | ||
49 | <name>name</name> | ||
50 | <cstring>refreshButton</cstring> | ||
51 | </property> | ||
52 | <property stdset="1"> | ||
53 | <name>text</name> | ||
54 | <string>Refresh</string> | ||
55 | </property> | ||
56 | </widget> | ||
57 | <widget row="0" column="1" > | ||
58 | <class>QPushButton</class> | ||
59 | <property stdset="1"> | ||
60 | <name>name</name> | ||
61 | <cstring>stopButton</cstring> | ||
62 | </property> | ||
63 | <property stdset="1"> | ||
64 | <name>text</name> | ||
65 | <string>Stop</string> | ||
66 | </property> | ||
67 | </widget> | ||
68 | <widget row="1" column="1" > | ||
69 | <class>QPushButton</class> | ||
70 | <property stdset="1"> | ||
71 | <name>name</name> | ||
72 | <cstring>restartButton</cstring> | ||
73 | </property> | ||
74 | <property stdset="1"> | ||
75 | <name>text</name> | ||
76 | <string>Restart</string> | ||
77 | </property> | ||
78 | </widget> | ||
79 | <widget row="0" column="0" > | ||
80 | <class>QPushButton</class> | ||
81 | <property stdset="1"> | ||
82 | <name>name</name> | ||
83 | <cstring>startButton</cstring> | ||
84 | </property> | ||
85 | <property stdset="1"> | ||
86 | <name>text</name> | ||
87 | <string>Start</string> | ||
88 | </property> | ||
89 | </widget> | ||
90 | </grid> | ||
91 | </widget> | ||
92 | <widget row="0" column="0" > | ||
93 | <class>Line</class> | ||
94 | <property stdset="1"> | ||
95 | <name>name</name> | ||
96 | <cstring>Line1</cstring> | ||
97 | </property> | ||
98 | <property stdset="1"> | ||
99 | <name>orientation</name> | ||
100 | <enum>Horizontal</enum> | ||
101 | </property> | ||
102 | </widget> | ||
103 | <spacer row="6" column="1" > | ||
104 | <property> | ||
105 | <name>name</name> | ||
106 | <cstring>Spacer18</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>orientation</name> | ||
110 | <enum>Vertical</enum> | ||
111 | </property> | ||
112 | <property stdset="1"> | ||
113 | <name>sizeType</name> | ||
114 | <enum>Expanding</enum> | ||
115 | </property> | ||
116 | <property> | ||
117 | <name>sizeHint</name> | ||
118 | <size> | ||
119 | <width>20</width> | ||
120 | <height>20</height> | ||
121 | </size> | ||
122 | </property> | ||
123 | </spacer> | ||
124 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
125 | <class>QLayoutWidget</class> | ||
126 | <property stdset="1"> | ||
127 | <name>name</name> | ||
128 | <cstring>Layout2</cstring> | ||
129 | </property> | ||
130 | <hbox> | ||
131 | <property stdset="1"> | ||
132 | <name>margin</name> | ||
133 | <number>0</number> | ||
134 | </property> | ||
135 | <property stdset="1"> | ||
136 | <name>spacing</name> | ||
137 | <number>6</number> | ||
138 | </property> | ||
139 | <spacer> | ||
140 | <property> | ||
141 | <name>name</name> | ||
142 | <cstring>Spacer10</cstring> | ||
143 | </property> | ||
144 | <property stdset="1"> | ||
145 | <name>orientation</name> | ||
146 | <enum>Horizontal</enum> | ||
147 | </property> | ||
148 | <property stdset="1"> | ||
149 | <name>sizeType</name> | ||
150 | <enum>Expanding</enum> | ||
151 | </property> | ||
152 | <property> | ||
153 | <name>sizeHint</name> | ||
154 | <size> | ||
155 | <width>20</width> | ||
156 | <height>20</height> | ||
157 | </size> | ||
158 | </property> | ||
159 | </spacer> | ||
160 | <widget> | ||
161 | <class>QPushButton</class> | ||
162 | <property stdset="1"> | ||
163 | <name>name</name> | ||
164 | <cstring>advancedButton</cstring> | ||
165 | </property> | ||
166 | <property stdset="1"> | ||
167 | <name>text</name> | ||
168 | <string>View Advanced Information</string> | ||
169 | </property> | ||
170 | </widget> | ||
171 | </hbox> | ||
172 | </widget> | ||
173 | <widget row="0" column="0" > | ||
174 | <class>QLabel</class> | ||
175 | <property stdset="1"> | ||
176 | <name>name</name> | ||
177 | <cstring>TextLabel22</cstring> | ||
178 | </property> | ||
179 | <property stdset="1"> | ||
180 | <name>text</name> | ||
181 | <string>IP Address</string> | ||
182 | </property> | ||
183 | </widget> | ||
184 | <widget row="1" column="0" > | ||
185 | <class>QLabel</class> | ||
186 | <property stdset="1"> | ||
187 | <name>name</name> | ||
188 | <cstring>TextLabel23</cstring> | ||
189 | </property> | ||
190 | <property stdset="1"> | ||
191 | <name>text</name> | ||
192 | <string>Subnet Mask</string> | ||
193 | </property> | ||
194 | </widget> | ||
195 | <widget row="2" column="0" > | ||
196 | <class>QLabel</class> | ||
197 | <property stdset="1"> | ||
198 | <name>name</name> | ||
199 | <cstring>TextLabel21</cstring> | ||
200 | </property> | ||
201 | <property stdset="1"> | ||
202 | <name>text</name> | ||
203 | <string>MAC Address</string> | ||
204 | </property> | ||
205 | </widget> | ||
206 | <widget row="3" column="0" > | ||
207 | <class>QLabel</class> | ||
208 | <property stdset="1"> | ||
209 | <name>name</name> | ||
210 | <cstring>TextLabel24</cstring> | ||
211 | </property> | ||
212 | <property stdset="1"> | ||
213 | <name>text</name> | ||
214 | <string>Broadcast</string> | ||
215 | </property> | ||
216 | </widget> | ||
217 | <widget row="1" column="1" > | ||
218 | <class>QLabel</class> | ||
219 | <property stdset="1"> | ||
220 | <name>name</name> | ||
221 | <cstring>subnetMaskLabel</cstring> | ||
222 | </property> | ||
223 | <property stdset="1"> | ||
224 | <name>frameShape</name> | ||
225 | <enum>Panel</enum> | ||
226 | </property> | ||
227 | <property stdset="1"> | ||
228 | <name>frameShadow</name> | ||
229 | <enum>Sunken</enum> | ||
230 | </property> | ||
231 | <property stdset="1"> | ||
232 | <name>text</name> | ||
233 | <string>0.0.0.0</string> | ||
234 | </property> | ||
235 | </widget> | ||
236 | <widget row="2" column="1" > | ||
237 | <class>QLabel</class> | ||
238 | <property stdset="1"> | ||
239 | <name>name</name> | ||
240 | <cstring>macAddressLabel</cstring> | ||
241 | </property> | ||
242 | <property stdset="1"> | ||
243 | <name>frameShape</name> | ||
244 | <enum>Panel</enum> | ||
245 | </property> | ||
246 | <property stdset="1"> | ||
247 | <name>frameShadow</name> | ||
248 | <enum>Sunken</enum> | ||
249 | </property> | ||
250 | <property stdset="1"> | ||
251 | <name>text</name> | ||
252 | <string>00:00:00:00:00:00</string> | ||
253 | </property> | ||
254 | </widget> | ||
255 | <widget row="3" column="1" > | ||
256 | <class>QLabel</class> | ||
257 | <property stdset="1"> | ||
258 | <name>name</name> | ||
259 | <cstring>broadcastLabel</cstring> | ||
260 | </property> | ||
261 | <property stdset="1"> | ||
262 | <name>frameShape</name> | ||
263 | <enum>Panel</enum> | ||
264 | </property> | ||
265 | <property stdset="1"> | ||
266 | <name>frameShadow</name> | ||
267 | <enum>Sunken</enum> | ||
268 | </property> | ||
269 | <property stdset="1"> | ||
270 | <name>text</name> | ||
271 | <string></string> | ||
272 | </property> | ||
273 | </widget> | ||
274 | <widget row="0" column="1" > | ||
275 | <class>QLabel</class> | ||
276 | <property stdset="1"> | ||
277 | <name>name</name> | ||
278 | <cstring>ipAddressLabel</cstring> | ||
279 | </property> | ||
280 | <property stdset="1"> | ||
281 | <name>frameShape</name> | ||
282 | <enum>Panel</enum> | ||
283 | </property> | ||
284 | <property stdset="1"> | ||
285 | <name>frameShadow</name> | ||
286 | <enum>Sunken</enum> | ||
287 | </property> | ||
288 | <property stdset="1"> | ||
289 | <name>text</name> | ||
290 | <string>0.0.0.0</string> | ||
291 | </property> | ||
292 | </widget> | ||
293 | </grid> | ||
294 | </widget> | ||
295 | <customwidgets> | ||
296 | <customwidget> | ||
297 | <class>QWidget</class> | ||
298 | <header location="local">qwidget.h</header> | ||
299 | <sizehint> | ||
300 | <width>100</width> | ||
301 | <height>100</height> | ||
302 | </sizehint> | ||
303 | <container>0</container> | ||
304 | <sizepolicy> | ||
305 | <hordata>7</hordata> | ||
306 | <verdata>7</verdata> | ||
307 | </sizepolicy> | ||
308 | <pixmap>image0</pixmap> | ||
309 | </customwidget> | ||
310 | </customwidgets> | ||
311 | <images> | ||
312 | <image> | ||
313 | <name>image0</name> | ||
314 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
315 | </image> | ||
316 | </images> | ||
317 | </UI> | ||
diff --git a/noncore/settings/networksettings/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaceinformationimp.cpp new file mode 100644 index 0000000..e37e0f8 --- a/dev/null +++ b/noncore/settings/networksettings/interfaceinformationimp.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | #include "interfaceinformationimp.h" | ||
2 | #include "interfaceadvanced.h" | ||
3 | |||
4 | #include <qpushbutton.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <assert.h> | ||
7 | |||
8 | /** | ||
9 | * Constructor for the InterfaceInformationImp class. This class pretty much | ||
10 | * just display's information about the interface that is passed to it. | ||
11 | */ | ||
12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ | ||
13 | assert(i); | ||
14 | |||
15 | interface = i; | ||
16 | updateInterface(); | ||
17 | connect(startButton, SIGNAL(clicked()), this, SLOT(start())); | ||
18 | connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); | ||
19 | connect(restartButton, SIGNAL(clicked()), this, SLOT(restart())); | ||
20 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); | ||
21 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | ||
22 | |||
23 | } | ||
24 | |||
25 | void InterfaceInformationImp::updateInterface(){ | ||
26 | if(interface->getStatus()){ | ||
27 | startButton->setEnabled(false); | ||
28 | stopButton->setEnabled(true); | ||
29 | restartButton->setEnabled(true); | ||
30 | } | ||
31 | else{ | ||
32 | startButton->setEnabled(true); | ||
33 | stopButton->setEnabled(false); | ||
34 | restartButton->setEnabled(false); | ||
35 | } | ||
36 | macAddressLabel->setText(interface->getMacAddress()); | ||
37 | ipAddressLabel->setText(interface->getIp()); | ||
38 | subnetMaskLabel->setText(interface->getSubnetMask()); | ||
39 | broadcastLabel->setText(interface->getBroadcast()); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Start the interface. Update the information if successfull | ||
44 | */ | ||
45 | void InterfaceInformationImp::start(){ | ||
46 | if(interface->start()){ | ||
47 | updateInterface(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Stop the interface. | ||
53 | */ | ||
54 | void InterfaceInformationImp::stop(){ | ||
55 | if(interface->stop()){ | ||
56 | updateInterface(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /*** | ||
61 | * Tell the interface to refresh its information. | ||
62 | **/ | ||
63 | void InterfaceInformationImp::refresh(){ | ||
64 | if(interface->refresh()) | ||
65 | updateInterface(); | ||
66 | } | ||
67 | |||
68 | void InterfaceInformationImp::restart(){ | ||
69 | if(interface->restart()){ | ||
70 | updateInterface(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create the advanced widget. Fill it with the current interface's information. | ||
77 | * Display it. | ||
78 | */ | ||
79 | void InterfaceInformationImp::advanced(){ | ||
80 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); | ||
81 | a->interfaceName->setText(interface->getInterfaceName()); | ||
82 | a->macAddressLabel->setText(interface->getMacAddress()); | ||
83 | a->ipAddressLabel->setText(interface->getIp()); | ||
84 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | ||
85 | a->broadcastLabel->setText(interface->getBroadcast()); | ||
86 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | ||
87 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | ||
88 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | ||
89 | a->showMaximized(); | ||
90 | a->show(); | ||
91 | } | ||
92 | |||
93 | // infoimp.cpp | ||
94 | |||
diff --git a/noncore/settings/networksettings/interfaceinformationimp.h b/noncore/settings/networksettings/interfaceinformationimp.h new file mode 100644 index 0000000..6fc2384 --- a/dev/null +++ b/noncore/settings/networksettings/interfaceinformationimp.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | ||
2 | #define INTERFACEINFORMATIONIMP_H | ||
3 | |||
4 | #include "interfaceinformation.h" | ||
5 | #include "interface.h" | ||
6 | |||
7 | class InterfaceInformationImp : public InterfaceInformation { | ||
8 | |||
9 | Q_OBJECT | ||
10 | |||
11 | public: | ||
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | ||
13 | ~InterfaceInformationImp(){}; | ||
14 | |||
15 | private slots: | ||
16 | void start(); | ||
17 | void stop(); | ||
18 | void refresh(); | ||
19 | void restart(); | ||
20 | void advanced(); | ||
21 | Interface *interface; | ||
22 | |||
23 | private: | ||
24 | void updateInterface(); | ||
25 | |||
26 | }; | ||
27 | |||
28 | #endif | ||
29 | |||
30 | // addserviceimp.h | ||
31 | |||
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp new file mode 100644 index 0000000..b8a3e7f --- a/dev/null +++ b/noncore/settings/networksettings/interfaces.cpp | |||
@@ -0,0 +1,513 @@ | |||
1 | #include "interfaces.h" | ||
2 | |||
3 | #include <qfile.h> | ||
4 | #include <qtextstream.h> | ||
5 | #include <qregexp.h> | ||
6 | |||
7 | #define AUTO "auto" | ||
8 | #define IFACE "iface" | ||
9 | #define MAPPING "mapping" | ||
10 | |||
11 | /** | ||
12 | * Constructor. Reads in the interfaces file and then split the file up by | ||
13 | * the \n for interfaces variable. | ||
14 | * @param useInterfacesFile if an interface file other then the default is | ||
15 | * desired to be used it should be passed in. | ||
16 | */ | ||
17 | Interfaces::Interfaces(QString useInterfacesFile){ | ||
18 | acceptedFamily.append(INTERFACES_FAMILY_INET); | ||
19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | ||
20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | ||
21 | |||
22 | interfacesFile = useInterfacesFile; | ||
23 | QFile file(interfacesFile); | ||
24 | if (!file.open(IO_ReadOnly)){ | ||
25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | ||
26 | currentIface = interfaces.end(); | ||
27 | currentMapping = interfaces.end(); | ||
28 | return; | ||
29 | } | ||
30 | QTextStream stream( &file ); | ||
31 | QString line; | ||
32 | while ( !stream.eof() ) { | ||
33 | line += stream.readLine(); | ||
34 | line += "\n"; | ||
35 | } | ||
36 | file.close(); | ||
37 | interfaces = QStringList::split("\n", line, true); | ||
38 | |||
39 | currentIface = interfaces.end(); | ||
40 | currentMapping = interfaces.end(); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Find out if interface is in an "auto" group or not. | ||
45 | * Report any duplicates such as eth0 being in two differnt auto's | ||
46 | * @param | ||
47 | * @return true is interface is in auto | ||
48 | */ | ||
49 | bool Interfaces::isAuto(QString interface){ | ||
50 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | ||
51 | QStringList awi = autoLines.grep(QRegExp(interface)); | ||
52 | if(awi.count() > 1) | ||
53 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | ||
54 | if(awi.count() < 1) | ||
55 | return false; | ||
56 | return true; | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * Attempt to set the auto option for interface to setAuto. | ||
61 | * @param interface the interface to set | ||
62 | * @param setAuto the value to set interface to. | ||
63 | * @return false if already set to setAuto. | ||
64 | * */ | ||
65 | bool Interfaces::setAuto(QString interface, bool setAuto){ | ||
66 | // Don't need to set it if it is already set. | ||
67 | if(isAuto(interface) == setAuto) | ||
68 | return false; | ||
69 | |||
70 | bool changed = false; | ||
71 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | ||
72 | if((*it).contains(AUTO)){ | ||
73 | //We know that they are not in any group so let add to this auto. | ||
74 | if(setAuto){ | ||
75 | (*it) = (*it) += " " + interface; | ||
76 | // Don't care to have such thins as: auto eth0 lo usb0 | ||
77 | (*it) = (*it).simplifyWhiteSpace(); | ||
78 | changed = true; | ||
79 | break; | ||
80 | } | ||
81 | else{ | ||
82 | if((*it).contains(interface)){ | ||
83 | (*it) = (*it).replace(QRegExp(interface), ""); | ||
84 | // clean up | ||
85 | QString line = (*it).simplifyWhiteSpace(); | ||
86 | line = line.replace(QRegExp(" "),""); | ||
87 | if(line == AUTO) | ||
88 | (*it) = ""; | ||
89 | changed = true; | ||
90 | // Don't break because we want to make sure we remove all cases. | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | if(changed == false){ | ||
96 | if(setAuto == true) | ||
97 | interfaces.append(QString(AUTO" %1").arg(interface)); | ||
98 | else{ | ||
99 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | ||
100 | } | ||
101 | } | ||
102 | return true; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Set the current interface to interface. This needs to be done before you | ||
107 | * can call getFamily(), getMethod, and get/setOption(). | ||
108 | * @param interface the name of the interface to set. All whitespace is | ||
109 | * removed from the interface name. | ||
110 | * @return bool true if it is successfull. | ||
111 | */ | ||
112 | bool Interfaces::setInterface(QString interface){ | ||
113 | interface = interface.simplifyWhiteSpace(); | ||
114 | interface = interface.replace(QRegExp(" "), ""); | ||
115 | return setStanza(IFACE, interface, currentIface); | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * A quick helper funtion to see if the current interface is set. | ||
120 | * @return bool true if set, false otherwise. | ||
121 | */ | ||
122 | bool Interfaces::isInterfaceSet(){ | ||
123 | return (currentIface != interfaces.end()); | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * Add a new interface of with the settings - family and method | ||
128 | * @param interface the name of the interface to set. All whitespace is | ||
129 | * removed from the interface name. | ||
130 | * @param family the family of this interface inet or inet, ipx or inet6 | ||
131 | * Must of one of the families defined in interfaces.h | ||
132 | * @param method for the family. see interfaces man page for family methods. | ||
133 | * @return true if successfull. | ||
134 | */ | ||
135 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | ||
136 | if(acceptedFamily.contains(family)==0) | ||
137 | return false; | ||
138 | interface = interface.simplifyWhiteSpace(); | ||
139 | interface = interface.replace(QRegExp(" "), ""); | ||
140 | interfaces.append(""); | ||
141 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | ||
142 | return true; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * Remove the currently selected interface and all of its options. | ||
147 | * @return bool if successfull or not. | ||
148 | */ | ||
149 | bool Interfaces::removeInterface(){ | ||
150 | if(currentIface == interfaces.end()) | ||
151 | return false; | ||
152 | (*currentIface) = ""; | ||
153 | return removeAllInterfaceOptions(); | ||
154 | } | ||
155 | |||
156 | /** | ||
157 | * Gets the hardware name of the interface that is currently selected. | ||
158 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | ||
159 | * @param error set to true if any error occurs, false otherwise. | ||
160 | */ | ||
161 | QString Interfaces::getInterfaceName(bool &error){ | ||
162 | if(currentIface == interfaces.end()){ | ||
163 | error = true; | ||
164 | return QString(); | ||
165 | } | ||
166 | QString line = (*currentIface); | ||
167 | line = line.mid(QString(IFACE).length() +1, line.length()); | ||
168 | line = line.simplifyWhiteSpace(); | ||
169 | int findSpace = line.find(" "); | ||
170 | if( findSpace < 0){ | ||
171 | error = true; | ||
172 | return QString(); | ||
173 | } | ||
174 | error = false; | ||
175 | return line.mid(0, findSpace); | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Gets the family name of the interface that is currently selected. | ||
180 | * @return QString name of the family (inet, inet6, ipx). | ||
181 | * @param error set to true if any error occurs, false otherwise. | ||
182 | */ | ||
183 | QString Interfaces::getInterfaceFamily(bool &error){ | ||
184 | QString name = getInterfaceName(error); | ||
185 | if(error){ | ||
186 | error = true; | ||
187 | return QString(); | ||
188 | } | ||
189 | QString line = (*currentIface); | ||
190 | line = line.mid(QString(IFACE).length() +1, line.length()); | ||
191 | line = line.mid(name.length()+1, line.length()); | ||
192 | line = line.simplifyWhiteSpace(); | ||
193 | int findSpace = line.find(" "); | ||
194 | if( findSpace < 0){ | ||
195 | error = true; | ||
196 | return QString(); | ||
197 | } | ||
198 | error = false; | ||
199 | return line.mid(0, findSpace); | ||
200 | } | ||
201 | |||
202 | /** | ||
203 | * Gets the method of the interface that is currently selected. | ||
204 | * @return QString name of the method such as staic or dhcp. | ||
205 | * See the man page of interfaces for possible methods depending on the family. | ||
206 | * @param error set to true if any error occurs, false otherwise. | ||
207 | */ | ||
208 | QString Interfaces::getInterfaceMethod(bool &error){ | ||
209 | QString name = getInterfaceName(error); | ||
210 | if(error){ | ||
211 | error = true; | ||
212 | return QString(); | ||
213 | } | ||
214 | QString family = getInterfaceFamily(error); | ||
215 | if(error){ | ||
216 | error = true; | ||
217 | return QString(); | ||
218 | } | ||
219 | QString line = (*currentIface); | ||
220 | line = line.mid(QString(IFACE).length()+1, line.length()); | ||
221 | line = line.mid(name.length()+1, line.length()); | ||
222 | line = line.mid(family.length()+1, line.length()); | ||
223 | line = line.simplifyWhiteSpace(); | ||
224 | error = false; | ||
225 | return line; | ||
226 | } | ||
227 | |||
228 | /** | ||
229 | * Sets the interface name to newName. | ||
230 | * @param newName the new name of the interface. All whitespace is removed. | ||
231 | * @return bool true if successfull. | ||
232 | */ | ||
233 | bool Interfaces::setInterfaceName(QString newName){ | ||
234 | if(currentIface == interfaces.end()) | ||
235 | return false; | ||
236 | newName = newName.simplifyWhiteSpace(); | ||
237 | newName = newName.replace(QRegExp(" "), ""); | ||
238 | bool returnValue = false; | ||
239 | (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | ||
240 | return !returnValue; | ||
241 | } | ||
242 | |||
243 | /** | ||
244 | * Sets the interface family to newName. | ||
245 | * @param newName the new name of the interface. Must be one of the families | ||
246 | * defined in the interfaces.h file. | ||
247 | * @return bool true if successfull. | ||
248 | */ | ||
249 | bool Interfaces::setInterfaceFamily(QString newName){ | ||
250 | if(currentIface == interfaces.end()) | ||
251 | return false; | ||
252 | if(acceptedFamily.contains(newName)==0) | ||
253 | return false; | ||
254 | bool returnValue = false; | ||
255 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | ||
256 | return !returnValue; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * Sets the interface method to newName | ||
261 | * @param newName the new name of the interface | ||
262 | * @return bool true if successfull. | ||
263 | */ | ||
264 | bool Interfaces::setInterfaceMethod(QString newName){ | ||
265 | if(currentIface == interfaces.end()) | ||
266 | return false; | ||
267 | bool returnValue = false; | ||
268 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | ||
269 | return !returnValue; | ||
270 | } | ||
271 | |||
272 | /** | ||
273 | * Get a value for an option in the currently selected interface. For example | ||
274 | * calling getInterfaceOption("address") on the following stanza would | ||
275 | * return 192.168.1.1. | ||
276 | * iface eth0 static | ||
277 | * address 192.168.1.1 | ||
278 | * @param option the options to get the value. | ||
279 | * @param error set to true if any error occurs, false otherwise. | ||
280 | * @return QString the options value. QString::null if error == true | ||
281 | */ | ||
282 | QString Interfaces::getInterfaceOption(QString option, bool &error){ | ||
283 | return getOption(currentIface, option, error); | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Set a value for an option in the currently selected interface. If option | ||
288 | * doesn't exist then it is added along with the value. If value is set to an | ||
289 | * empty string then option is removed. | ||
290 | * @param option the options to set the value. | ||
291 | * @param value the value that option should be set to. | ||
292 | * @param error set to true if any error occurs, false otherwise. | ||
293 | * @return QString the options value. QString::null if error == true | ||
294 | */ | ||
295 | bool Interfaces::setInterfaceOption(QString option, QString value){ | ||
296 | return setOption(currentIface, option, value); | ||
297 | } | ||
298 | |||
299 | /** | ||
300 | * Removes all of the options from the currently selected interface. | ||
301 | * @return bool error if if successfull | ||
302 | */ | ||
303 | bool Interfaces::removeAllInterfaceOptions(){ | ||
304 | return removeAllOptions(currentIface); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Set the current map to interface's map. This needs to be done before you | ||
309 | * can call addMapping(), set/getMap(), and get/setScript(). | ||
310 | * @param interface the name of the interface to set. All whitespace is | ||
311 | * removed from the interface name. | ||
312 | * @return bool true if it is successfull. | ||
313 | */ | ||
314 | bool Interfaces::setMapping(QString interface){ | ||
315 | interface = interface.simplifyWhiteSpace(); | ||
316 | interface = interface.replace(QRegExp(" "), ""); | ||
317 | return setStanza(MAPPING, interface, currentMapping); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Adds a new Mapping to the interfaces file with interfaces. | ||
322 | * @param interface the name(s) of the interfaces to set to this mapping | ||
323 | */ | ||
324 | void Interfaces::addMapping(QString interfaces){ | ||
325 | interfaces.append(""); | ||
326 | interfaces.append(QString(MAPPING " %1").arg(interfaces)); | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * Set a map option within a mapping. | ||
331 | * @param map map to use | ||
332 | * @param value value to go with map | ||
333 | * @return bool true if it is successfull. | ||
334 | */ | ||
335 | bool Interfaces::setMap(QString map, QString value){ | ||
336 | return setOption(currentMapping, map, value); | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * Get a map value within a mapping. | ||
341 | * @param map map to get value of | ||
342 | * @param bool true if it is successfull. | ||
343 | * @return value that goes to the map | ||
344 | */ | ||
345 | QString Interfaces::getMap(QString map, bool &error){ | ||
346 | return getOption(currentMapping, map, error); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * Sets a script value of the current mapping to argument. | ||
351 | * @param argument the script name. | ||
352 | * @return true if successfull. | ||
353 | */ | ||
354 | bool Interfaces::setScript(QString argument){ | ||
355 | return setOption(currentMapping, "script", argument); | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * @param error true if could not retrieve the current script argument. | ||
360 | * @return QString the argument of the script for the current mapping. | ||
361 | */ | ||
362 | QString Interfaces::getScript(bool &error){ | ||
363 | return getOption(currentMapping, "script", error); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Helper function used to parse through the QStringList and put pointers in | ||
368 | * the correct place. | ||
369 | * @param stanza The stanza (auto, iface, mapping) to look for. | ||
370 | * @param option string that must be in the stanza's main line. | ||
371 | * @param interator interator to place at location of stanza if successfull. | ||
372 | * @return bool true if the stanza is found. | ||
373 | */ | ||
374 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | ||
375 | bool found = false; | ||
376 | iterator = interfaces.end(); | ||
377 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | ||
378 | QString line = (*it).simplifyWhiteSpace(); | ||
379 | if(line.contains(stanza) && line.contains(option)){ | ||
380 | if(found == true){ | ||
381 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | ||
382 | } | ||
383 | found = true; | ||
384 | iterator = it; | ||
385 | } | ||
386 | } | ||
387 | return !found; | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * Sets a value of an option in a stanza | ||
392 | * @param start the start of the stanza | ||
393 | * @param option the option to use when setting value. | ||
394 | * @return bool true if successfull, false otherwise. | ||
395 | */ | ||
396 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | ||
397 | if(start == interfaces.end()) | ||
398 | return false; | ||
399 | |||
400 | bool found = false; | ||
401 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | ||
402 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
403 | if(!found && value != ""){ | ||
404 | // Got to the end of the stanza without finding it, so append it. | ||
405 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | ||
406 | } | ||
407 | break; | ||
408 | } | ||
409 | if((*it).contains(option)){ | ||
410 | // Found it in stanza so replace it. | ||
411 | if(found) | ||
412 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | ||
413 | found = true; | ||
414 | if(value == "") | ||
415 | (*it) = ""; | ||
416 | else | ||
417 | (*it) = QString("\t%1 %2").arg(option).arg(value); | ||
418 | } | ||
419 | } | ||
420 | return true; | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * Removes all options in a stanza | ||
425 | * @param start the start of the stanza | ||
426 | * @return bool true if successfull, false otherwise. | ||
427 | */ | ||
428 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | ||
429 | if(start == interfaces.end()) | ||
430 | return false; | ||
431 | |||
432 | QStringList::Iterator it = start; | ||
433 | it = ++it; | ||
434 | for (it; it != interfaces.end(); ++it ) { | ||
435 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
436 | break; | ||
437 | } | ||
438 | it = interfaces.remove(it); | ||
439 | it = --it; | ||
440 | } | ||
441 | // Leave a space between this interface and the next. | ||
442 | interfaces.insert(it, QString("")); | ||
443 | return true; | ||
444 | } | ||
445 | |||
446 | /** | ||
447 | * Gets a value of an option in a stanza | ||
448 | * @param start the start of the stanza | ||
449 | * @param option the option to use when getting the value. | ||
450 | * @param bool true if errors false otherwise. | ||
451 | * @return QString the value of option QString::null() if error == true. | ||
452 | */ | ||
453 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | ||
454 | if(start == interfaces.end()){ | ||
455 | error = false; | ||
456 | return QString(); | ||
457 | } | ||
458 | |||
459 | QString value; | ||
460 | bool found = false; | ||
461 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | ||
462 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | ||
463 | break; | ||
464 | } | ||
465 | if((*it).contains(option)){ | ||
466 | if(found) | ||
467 | qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); | ||
468 | found = true; | ||
469 | QString line = (*it).simplifyWhiteSpace(); | ||
470 | int space = line.find(" ", option.length()); | ||
471 | if(space != -1) | ||
472 | value = line.mid(space+1, line.length()); | ||
473 | else | ||
474 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | ||
475 | } | ||
476 | } | ||
477 | error = !found; | ||
478 | return value; | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Write out the interfaces file to the file passed into the constructor. | ||
483 | * Removes any excess blank lines over 1 line long. | ||
484 | * @return bool true if successfull, false if not. | ||
485 | */ | ||
486 | bool Interfaces::write(){ | ||
487 | QFile::remove(interfacesFile); | ||
488 | QFile file(interfacesFile); | ||
489 | |||
490 | if (!file.open(IO_ReadWrite)){ | ||
491 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | ||
492 | return false; | ||
493 | } | ||
494 | QTextStream stream( &file ); | ||
495 | int whiteSpaceCount = 0; | ||
496 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | ||
497 | QString line = (*it).simplifyWhiteSpace(); | ||
498 | line = line.replace(QRegExp(" "),""); | ||
499 | if(line.length() == 0) | ||
500 | whiteSpaceCount++; | ||
501 | else | ||
502 | whiteSpaceCount = 0; | ||
503 | if(whiteSpaceCount < 2){ | ||
504 | qDebug((*it).latin1()); | ||
505 | stream << (*it) << '\n'; | ||
506 | } | ||
507 | } | ||
508 | file.close(); | ||
509 | return true; | ||
510 | } | ||
511 | |||
512 | // interfaces.cpp | ||
513 | |||
diff --git a/noncore/settings/networksettings/interfaces.h b/noncore/settings/networksettings/interfaces.h new file mode 100644 index 0000000..2cc9689 --- a/dev/null +++ b/noncore/settings/networksettings/interfaces.h | |||
@@ -0,0 +1,70 @@ | |||
1 | #ifndef INTERFACES_H | ||
2 | #define INTERFACES_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | |||
7 | #define INTERFACES_LOOPBACK "loopback" | ||
8 | |||
9 | #define INTERFACES_FAMILY_INET "inet" | ||
10 | #define INTERFACES_FAMILY_IPX "ipx" | ||
11 | #define INTERFACES_FAMILY_INET6 "inet6" | ||
12 | |||
13 | #define INTERFACES_METHOD_DHCP "dhcp" | ||
14 | #define INTERFACES_METHOD_STATIC "static" | ||
15 | #define INTERFACES_METHOD_PPP "ppp" | ||
16 | |||
17 | /** | ||
18 | * This class provides a clean frontend for parsing the network interfaces file. | ||
19 | * It provides helper functions to minipulate the options within the file. | ||
20 | * See the interfaces man page for the syntax rules. | ||
21 | */ | ||
22 | class Interfaces { | ||
23 | |||
24 | public: | ||
25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); | ||
26 | |||
27 | bool isAuto(QString interface); | ||
28 | bool setAuto(QString interface, bool setAuto); | ||
29 | |||
30 | bool removeInterface(); | ||
31 | bool addInterface(QString interface, QString family, QString method); | ||
32 | bool setInterface(QString interface); | ||
33 | bool isInterfaceSet(); | ||
34 | QString getInterfaceName(bool &error); | ||
35 | bool setInterfaceName(QString newName); | ||
36 | QString getInterfaceFamily(bool &error); | ||
37 | bool setInterfaceFamily(QString newName); | ||
38 | QString getInterfaceMethod(bool &error); | ||
39 | bool setInterfaceMethod(QString newName); | ||
40 | QString getInterfaceOption(QString option, bool &error); | ||
41 | bool setInterfaceOption(QString option, QString value); | ||
42 | bool removeAllInterfaceOptions(); | ||
43 | |||
44 | bool setMapping(QString interface); | ||
45 | void addMapping(QString interfaces); | ||
46 | bool setMap(QString map, QString value); | ||
47 | QString getMap(QString map, bool &error); | ||
48 | bool setScript(QString); | ||
49 | QString getScript(bool &error); | ||
50 | |||
51 | bool write(); | ||
52 | |||
53 | private: | ||
54 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); | ||
55 | bool setOption(QStringList::Iterator start, QString option, QString value); | ||
56 | QString getOption(QStringList::Iterator start, QString option, bool &error); | ||
57 | bool removeAllOptions(QStringList::Iterator start); | ||
58 | |||
59 | QString interfacesFile; | ||
60 | QStringList interfaces; | ||
61 | QStringList::Iterator currentIface; | ||
62 | QStringList::Iterator currentMapping; | ||
63 | |||
64 | QStringList acceptedFamily; | ||
65 | }; | ||
66 | |||
67 | #endif | ||
68 | |||
69 | // interfaces | ||
70 | |||
diff --git a/noncore/settings/networksettings/interfacesetup.ui b/noncore/settings/networksettings/interfacesetup.ui new file mode 100644 index 0000000..698422c --- a/dev/null +++ b/noncore/settings/networksettings/interfacesetup.ui | |||
@@ -0,0 +1,274 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InterfaceSetup</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>InterfaceSetup</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>193</width> | ||
15 | <height>310</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Interface Configuration</string> | ||
21 | </property> | ||
22 | <grid> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>11</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
32 | <class>Line</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>Line1</cstring> | ||
36 | </property> | ||
37 | <property stdset="1"> | ||
38 | <name>orientation</name> | ||
39 | <enum>Horizontal</enum> | ||
40 | </property> | ||
41 | </widget> | ||
42 | <widget row="6" column="0" > | ||
43 | <class>QLabel</class> | ||
44 | <property stdset="1"> | ||
45 | <name>name</name> | ||
46 | <cstring>TextLabel4</cstring> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>text</name> | ||
50 | <string>IP Address</string> | ||
51 | </property> | ||
52 | </widget> | ||
53 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
54 | <class>QCheckBox</class> | ||
55 | <property stdset="1"> | ||
56 | <name>name</name> | ||
57 | <cstring>autoStart</cstring> | ||
58 | </property> | ||
59 | <property stdset="1"> | ||
60 | <name>text</name> | ||
61 | <string>Automaticly bring up</string> | ||
62 | </property> | ||
63 | </widget> | ||
64 | <widget row="2" column="1" > | ||
65 | <class>QComboBox</class> | ||
66 | <item> | ||
67 | <property> | ||
68 | <name>text</name> | ||
69 | <string>All</string> | ||
70 | </property> | ||
71 | </item> | ||
72 | <property stdset="1"> | ||
73 | <name>name</name> | ||
74 | <cstring>profileCombo</cstring> | ||
75 | </property> | ||
76 | </widget> | ||
77 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
78 | <class>QGroupBox</class> | ||
79 | <property stdset="1"> | ||
80 | <name>name</name> | ||
81 | <cstring>staticGroupBox</cstring> | ||
82 | </property> | ||
83 | <property stdset="1"> | ||
84 | <name>enabled</name> | ||
85 | <bool>false</bool> | ||
86 | </property> | ||
87 | <property stdset="1"> | ||
88 | <name>title</name> | ||
89 | <string>Static Ip Configuration</string> | ||
90 | </property> | ||
91 | </widget> | ||
92 | <widget row="6" column="1" > | ||
93 | <class>QLineEdit</class> | ||
94 | <property stdset="1"> | ||
95 | <name>name</name> | ||
96 | <cstring>ipAddressEdit</cstring> | ||
97 | </property> | ||
98 | </widget> | ||
99 | <widget row="4" column="0" > | ||
100 | <class>QLabel</class> | ||
101 | <property stdset="1"> | ||
102 | <name>name</name> | ||
103 | <cstring>leaseHoursLabel</cstring> | ||
104 | </property> | ||
105 | <property stdset="1"> | ||
106 | <name>text</name> | ||
107 | <string>Requested Lease</string> | ||
108 | </property> | ||
109 | </widget> | ||
110 | <widget row="3" column="0" rowspan="1" colspan="2" > | ||
111 | <class>QCheckBox</class> | ||
112 | <property stdset="1"> | ||
113 | <name>name</name> | ||
114 | <cstring>dhcpCheckBox</cstring> | ||
115 | </property> | ||
116 | <property stdset="1"> | ||
117 | <name>text</name> | ||
118 | <string>DHCP</string> | ||
119 | </property> | ||
120 | <property stdset="1"> | ||
121 | <name>checked</name> | ||
122 | <bool>true</bool> | ||
123 | </property> | ||
124 | </widget> | ||
125 | <widget row="7" column="0" > | ||
126 | <class>QLabel</class> | ||
127 | <property stdset="1"> | ||
128 | <name>name</name> | ||
129 | <cstring>TextLabel5</cstring> | ||
130 | </property> | ||
131 | <property stdset="1"> | ||
132 | <name>text</name> | ||
133 | <string>Subnet Mask</string> | ||
134 | </property> | ||
135 | </widget> | ||
136 | <widget row="2" column="0" > | ||
137 | <class>QLabel</class> | ||
138 | <property stdset="1"> | ||
139 | <name>name</name> | ||
140 | <cstring>TextLabel1</cstring> | ||
141 | </property> | ||
142 | <property stdset="1"> | ||
143 | <name>text</name> | ||
144 | <string>Profile:</string> | ||
145 | </property> | ||
146 | </widget> | ||
147 | <widget row="4" column="1" > | ||
148 | <class>QSpinBox</class> | ||
149 | <property stdset="1"> | ||
150 | <name>name</name> | ||
151 | <cstring>leaseTime</cstring> | ||
152 | </property> | ||
153 | <property stdset="1"> | ||
154 | <name>suffix</name> | ||
155 | <string> hours</string> | ||
156 | </property> | ||
157 | <property stdset="1"> | ||
158 | <name>maxValue</name> | ||
159 | <number>336</number> | ||
160 | </property> | ||
161 | <property stdset="1"> | ||
162 | <name>minValue</name> | ||
163 | <number>1</number> | ||
164 | </property> | ||
165 | <property stdset="1"> | ||
166 | <name>value</name> | ||
167 | <number>24</number> | ||
168 | </property> | ||
169 | </widget> | ||
170 | <spacer row="11" column="1" > | ||
171 | <property> | ||
172 | <name>name</name> | ||
173 | <cstring>Spacer9</cstring> | ||
174 | </property> | ||
175 | <property stdset="1"> | ||
176 | <name>orientation</name> | ||
177 | <enum>Vertical</enum> | ||
178 | </property> | ||
179 | <property stdset="1"> | ||
180 | <name>sizeType</name> | ||
181 | <enum>Expanding</enum> | ||
182 | </property> | ||
183 | <property> | ||
184 | <name>sizeHint</name> | ||
185 | <size> | ||
186 | <width>20</width> | ||
187 | <height>20</height> | ||
188 | </size> | ||
189 | </property> | ||
190 | </spacer> | ||
191 | <widget row="10" column="1" > | ||
192 | <class>QLineEdit</class> | ||
193 | <property stdset="1"> | ||
194 | <name>name</name> | ||
195 | <cstring>secondDNSLineEdit</cstring> | ||
196 | </property> | ||
197 | </widget> | ||
198 | <widget row="10" column="0" > | ||
199 | <class>QLabel</class> | ||
200 | <property stdset="1"> | ||
201 | <name>name</name> | ||
202 | <cstring>TextLabel3</cstring> | ||
203 | </property> | ||
204 | <property stdset="1"> | ||
205 | <name>text</name> | ||
206 | <string>Second DNS</string> | ||
207 | </property> | ||
208 | </widget> | ||
209 | <widget row="9" column="0" > | ||
210 | <class>QLabel</class> | ||
211 | <property stdset="1"> | ||
212 | <name>name</name> | ||
213 | <cstring>TextLabel2</cstring> | ||
214 | </property> | ||
215 | <property stdset="1"> | ||
216 | <name>text</name> | ||
217 | <string>First DNS</string> | ||
218 | </property> | ||
219 | </widget> | ||
220 | <widget row="9" column="1" > | ||
221 | <class>QLineEdit</class> | ||
222 | <property stdset="1"> | ||
223 | <name>name</name> | ||
224 | <cstring>firstDNSLineEdit</cstring> | ||
225 | </property> | ||
226 | </widget> | ||
227 | <widget row="8" column="0" > | ||
228 | <class>QLabel</class> | ||
229 | <property stdset="1"> | ||
230 | <name>name</name> | ||
231 | <cstring>TextLabel1_2</cstring> | ||
232 | </property> | ||
233 | <property stdset="1"> | ||
234 | <name>text</name> | ||
235 | <string>Gateway</string> | ||
236 | </property> | ||
237 | </widget> | ||
238 | <widget row="7" column="1" > | ||
239 | <class>QLineEdit</class> | ||
240 | <property stdset="1"> | ||
241 | <name>name</name> | ||
242 | <cstring>subnetMaskEdit</cstring> | ||
243 | </property> | ||
244 | </widget> | ||
245 | <widget row="8" column="1" > | ||
246 | <class>QLineEdit</class> | ||
247 | <property stdset="1"> | ||
248 | <name>name</name> | ||
249 | <cstring>gatewayEdit</cstring> | ||
250 | </property> | ||
251 | </widget> | ||
252 | </grid> | ||
253 | </widget> | ||
254 | <connections> | ||
255 | <connection> | ||
256 | <sender>dhcpCheckBox</sender> | ||
257 | <signal>toggled(bool)</signal> | ||
258 | <receiver>leaseHoursLabel</receiver> | ||
259 | <slot>setEnabled(bool)</slot> | ||
260 | </connection> | ||
261 | <connection> | ||
262 | <sender>dhcpCheckBox</sender> | ||
263 | <signal>toggled(bool)</signal> | ||
264 | <receiver>leaseTime</receiver> | ||
265 | <slot>setEnabled(bool)</slot> | ||
266 | </connection> | ||
267 | <connection> | ||
268 | <sender>dhcpCheckBox</sender> | ||
269 | <signal>toggled(bool)</signal> | ||
270 | <receiver>staticGroupBox</receiver> | ||
271 | <slot>setDisabled(bool)</slot> | ||
272 | </connection> | ||
273 | </connections> | ||
274 | </UI> | ||
diff --git a/noncore/settings/networksettings/interfacesetupimp.cpp b/noncore/settings/networksettings/interfacesetupimp.cpp new file mode 100644 index 0000000..6a8449d --- a/dev/null +++ b/noncore/settings/networksettings/interfacesetupimp.cpp | |||
@@ -0,0 +1,147 @@ | |||
1 | #include "interfacesetupimp.h" | ||
2 | #include "interface.h" | ||
3 | #include "interfaces.h" | ||
4 | |||
5 | #include <qcombobox.h> | ||
6 | #include <qcheckbox.h> | ||
7 | #include <qlineedit.h> | ||
8 | #include <qspinbox.h> | ||
9 | #include <qgroupbox.h> | ||
10 | #include <qlabel.h> | ||
11 | |||
12 | #include <qmessagebox.h> | ||
13 | |||
14 | #include <assert.h> | ||
15 | |||
16 | #define INTERFACE_FILE "/home/ben/interfaces" | ||
17 | #define DNSSCRIPT "interfacednsscript" | ||
18 | |||
19 | /** | ||
20 | * Constuctor. Set up the connection and load the first profile. | ||
21 | */ | ||
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : InterfaceSetup(parent, name, modal, fl){ | ||
23 | assert(i); | ||
24 | interface = i; | ||
25 | interfaces = new Interfaces(INTERFACE_FILE); | ||
26 | changeProfile(profileCombo->currentText()); | ||
27 | bool error = false; | ||
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
29 | staticGroupBox->hide(); | ||
30 | dhcpCheckBox->hide(); | ||
31 | leaseTime->hide(); | ||
32 | leaseHoursLabel->hide(); | ||
33 | } | ||
34 | connect(profileCombo, SIGNAL(highlighted(const QString &)), this, SLOT(changeProfile(const QString &))); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * Save the current settings, then write out the interfaces file and close. | ||
39 | */ | ||
40 | void InterfaceSetupImp::accept(){ | ||
41 | if(!saveSettings()) | ||
42 | return; | ||
43 | interfaces->write(); | ||
44 | close(true); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Save the settings for the current Interface. | ||
49 | * @return bool true if successfull, false otherwise | ||
50 | */ | ||
51 | bool InterfaceSetupImp::saveSettings(){ | ||
52 | // eh can't really do anything about it other then return. :-D | ||
53 | if(!interfaces->isInterfaceSet()) | ||
54 | return true; | ||
55 | |||
56 | bool error = false; | ||
57 | // Loopback case | ||
58 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
59 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | ||
60 | return true; | ||
61 | } | ||
62 | |||
63 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ | ||
64 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); | ||
65 | return false; | ||
66 | } | ||
67 | interfaces->removeAllInterfaceOptions(); | ||
68 | |||
69 | // DHCP | ||
70 | if(dhcpCheckBox->isChecked()){ | ||
71 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | ||
72 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | ||
73 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | ||
74 | } | ||
75 | else{ | ||
76 | interfaces->setInterfaceMethod("static"); | ||
77 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | ||
78 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | ||
79 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | ||
80 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | ||
81 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); | ||
82 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); | ||
83 | } | ||
84 | |||
85 | // IP Information | ||
86 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | ||
87 | return true; | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * The Profile has changed. | ||
92 | * @profile the new profile. | ||
93 | */ | ||
94 | void InterfaceSetupImp::changeProfile(const QString &profile){ | ||
95 | QString newInterfaceName; | ||
96 | if(profile.lower() == "all") | ||
97 | newInterfaceName = interface->getInterfaceName(); | ||
98 | else | ||
99 | newInterfaceName = interface->getInterfaceName() + "_" + profile; | ||
100 | if(newInterfaceName == currentInterfaceName) | ||
101 | return; | ||
102 | else{ | ||
103 | saveSettings(); | ||
104 | currentInterfaceName = newInterfaceName; | ||
105 | } | ||
106 | bool error = interfaces->setInterface(currentInterfaceName); | ||
107 | |||
108 | // See if we have to make a interface. | ||
109 | if(error){ | ||
110 | qDebug("InterfaceSetupImp: Adding a new interface from profile change."); | ||
111 | interfaces->addInterface(currentInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | ||
112 | error = interfaces->setInterface(currentInterfaceName); | ||
113 | if(error){ | ||
114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | ||
115 | return; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | //qDebug( currentInterfaceName.latin1() ); | ||
120 | // We must have a valid interface to get this far so read some settings. | ||
121 | |||
122 | // DHCP | ||
123 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | ||
124 | dhcpCheckBox->setChecked(true); | ||
125 | else | ||
126 | dhcpCheckBox->setChecked(false); | ||
127 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | ||
128 | if(error) | ||
129 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | ||
130 | if(error) | ||
131 | leaseTime->setValue(24); | ||
132 | |||
133 | // IP Information | ||
134 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | ||
135 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); | ||
136 | if(dns.contains(" ")){ | ||
137 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | ||
138 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | ||
139 | } | ||
140 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | ||
141 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | ||
142 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | ||
143 | } | ||
144 | |||
145 | |||
146 | // interfacesetup.cpp | ||
147 | |||
diff --git a/noncore/settings/networksettings/interfacesetupimp.h b/noncore/settings/networksettings/interfacesetupimp.h new file mode 100644 index 0000000..6c34718 --- a/dev/null +++ b/noncore/settings/networksettings/interfacesetupimp.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef INTERFACESETUPIMP_H | ||
2 | #define INTERFACESETUPIMP_H | ||
3 | |||
4 | #include "interfacesetup.h" | ||
5 | |||
6 | class Interface; | ||
7 | class Interfaces; | ||
8 | |||
9 | class InterfaceSetupImp : public InterfaceSetup { | ||
10 | Q_OBJECT | ||
11 | |||
12 | public: | ||
13 | InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0); | ||
14 | |||
15 | protected slots: | ||
16 | void accept(); | ||
17 | void changeProfile(const QString &profile); | ||
18 | |||
19 | private: | ||
20 | bool saveSettings(); | ||
21 | Interfaces *interfaces; | ||
22 | Interface *interface; | ||
23 | QString currentInterfaceName; | ||
24 | |||
25 | }; | ||
26 | |||
27 | #endif | ||
28 | |||
29 | // interfacesetupimp.h | ||
30 | |||
diff --git a/noncore/settings/networksettings/kprocctrl.cpp b/noncore/settings/networksettings/kprocctrl.cpp new file mode 100644 index 0000000..cd8711a --- a/dev/null +++ b/noncore/settings/networksettings/kprocctrl.cpp | |||
@@ -0,0 +1,267 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | // | ||
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | ||
21 | // | ||
22 | // version 0.3.1, Jan, 8th 1997 | ||
23 | // | ||
24 | // (C) Christian Czezatke | ||
25 | // e9025461@student.tuwien.ac.at | ||
26 | // | ||
27 | |||
28 | //#include <config.h> | ||
29 | |||
30 | #include <sys/types.h> | ||
31 | #include <sys/socket.h> | ||
32 | |||
33 | #include <errno.h> | ||
34 | #include <fcntl.h> | ||
35 | #include <stdio.h> | ||
36 | #include <string.h> | ||
37 | #include <unistd.h> | ||
38 | #include <assert.h> | ||
39 | |||
40 | #include <qsocketnotifier.h> | ||
41 | #include "kprocess.h" | ||
42 | #include "kprocctrl.h" | ||
43 | |||
44 | KProcessController *KProcessController::theKProcessController = 0; | ||
45 | |||
46 | struct sigaction KProcessController::oldChildHandlerData; | ||
47 | bool KProcessController::handlerSet = false; | ||
48 | |||
49 | KProcessController::KProcessController() | ||
50 | { | ||
51 | assert( theKProcessController == 0 ); | ||
52 | |||
53 | if (0 > pipe(fd)) | ||
54 | printf(strerror(errno)); | ||
55 | |||
56 | notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); | ||
57 | notifier->setEnabled(true); | ||
58 | QObject::connect(notifier, SIGNAL(activated(int)), | ||
59 | this, SLOT(slotDoHousekeeping(int))); | ||
60 | connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), | ||
61 | SLOT( delayedChildrenCleanup())); | ||
62 | |||
63 | theKProcessController = this; | ||
64 | |||
65 | setupHandlers(); | ||
66 | } | ||
67 | |||
68 | |||
69 | void KProcessController::setupHandlers() | ||
70 | { | ||
71 | if( handlerSet ) | ||
72 | return; | ||
73 | struct sigaction act; | ||
74 | act.sa_handler=theSigCHLDHandler; | ||
75 | sigemptyset(&(act.sa_mask)); | ||
76 | sigaddset(&(act.sa_mask), SIGCHLD); | ||
77 | // Make sure we don't block this signal. gdb tends to do that :-( | ||
78 | sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); | ||
79 | |||
80 | act.sa_flags = SA_NOCLDSTOP; | ||
81 | |||
82 | // CC: take care of SunOS which automatically restarts interrupted system | ||
83 | // calls (and thus does not have SA_RESTART) | ||
84 | |||
85 | #ifdef SA_RESTART | ||
86 | act.sa_flags |= SA_RESTART; | ||
87 | #endif | ||
88 | |||
89 | sigaction( SIGCHLD, &act, &oldChildHandlerData ); | ||
90 | |||
91 | act.sa_handler=SIG_IGN; | ||
92 | sigemptyset(&(act.sa_mask)); | ||
93 | sigaddset(&(act.sa_mask), SIGPIPE); | ||
94 | act.sa_flags = 0; | ||
95 | sigaction( SIGPIPE, &act, 0L); | ||
96 | handlerSet = true; | ||
97 | } | ||
98 | |||
99 | void KProcessController::resetHandlers() | ||
100 | { | ||
101 | if( !handlerSet ) | ||
102 | return; | ||
103 | sigaction( SIGCHLD, &oldChildHandlerData, 0 ); | ||
104 | // there should be no problem with SIGPIPE staying SIG_IGN | ||
105 | handlerSet = false; | ||
106 | } | ||
107 | |||
108 | // block SIGCHLD handler, because it accesses processList | ||
109 | void KProcessController::addKProcess( KProcess* p ) | ||
110 | { | ||
111 | sigset_t newset, oldset; | ||
112 | sigemptyset( &newset ); | ||
113 | sigaddset( &newset, SIGCHLD ); | ||
114 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | ||
115 | processList.append( p ); | ||
116 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | ||
117 | } | ||
118 | |||
119 | void KProcessController::removeKProcess( KProcess* p ) | ||
120 | { | ||
121 | sigset_t newset, oldset; | ||
122 | sigemptyset( &newset ); | ||
123 | sigaddset( &newset, SIGCHLD ); | ||
124 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | ||
125 | processList.remove( p ); | ||
126 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | ||
127 | } | ||
128 | |||
129 | //using a struct which contains both the pid and the status makes it easier to write | ||
130 | //and read the data into the pipe | ||
131 | //especially this solves a problem which appeared on my box where slotDoHouseKeeping() received | ||
132 | //only 4 bytes (with some debug output around the write()'s it received all 8 bytes) | ||
133 | //don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX | ||
134 | struct waitdata | ||
135 | { | ||
136 | pid_t pid; | ||
137 | int status; | ||
138 | }; | ||
139 | |||
140 | void KProcessController::theSigCHLDHandler(int arg) | ||
141 | { | ||
142 | struct waitdata wd; | ||
143 | // int status; | ||
144 | // pid_t this_pid; | ||
145 | int saved_errno; | ||
146 | |||
147 | saved_errno = errno; | ||
148 | // since waitpid and write change errno, we have to save it and restore it | ||
149 | // (Richard Stevens, Advanced programming in the Unix Environment) | ||
150 | |||
151 | bool found = false; | ||
152 | if( theKProcessController != 0 ) { | ||
153 | // iterating the list doesn't perform any system call | ||
154 | for( QValueList<KProcess*>::ConstIterator it = theKProcessController->processList.begin(); | ||
155 | it != theKProcessController->processList.end(); | ||
156 | ++it ) | ||
157 | { | ||
158 | if( !(*it)->isRunning()) | ||
159 | continue; | ||
160 | wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG ); | ||
161 | if ( wd.pid > 0 ) { | ||
162 | ::write(theKProcessController->fd[1], &wd, sizeof(wd)); | ||
163 | found = true; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | if( !found && oldChildHandlerData.sa_handler != SIG_IGN | ||
168 | && oldChildHandlerData.sa_handler != SIG_DFL ) | ||
169 | oldChildHandlerData.sa_handler( arg ); // call the old handler | ||
170 | // handle the rest | ||
171 | if( theKProcessController != 0 ) { | ||
172 | static const struct waitdata dwd = { 0, 0 }; // delayed waitpid() | ||
173 | ::write(theKProcessController->fd[1], &dwd, sizeof(dwd)); | ||
174 | } else { | ||
175 | int dummy; | ||
176 | while( waitpid( -1, &dummy, WNOHANG ) > 0 ) | ||
177 | ; | ||
178 | } | ||
179 | |||
180 | errno = saved_errno; | ||
181 | } | ||
182 | |||
183 | |||
184 | |||
185 | void KProcessController::slotDoHousekeeping(int ) | ||
186 | { | ||
187 | unsigned int bytes_read = 0; | ||
188 | unsigned int errcnt=0; | ||
189 | // read pid and status from the pipe. | ||
190 | struct waitdata wd; | ||
191 | while ((bytes_read < sizeof(wd)) && (errcnt < 50)) { | ||
192 | int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read); | ||
193 | if (r > 0) bytes_read += r; | ||
194 | else if (r < 0) errcnt++; | ||
195 | } | ||
196 | if (errcnt >= 50) { | ||
197 | fprintf(stderr, | ||
198 | "Error: Max. error count for pipe read " | ||
199 | "exceeded in KProcessController::slotDoHousekeeping\n"); | ||
200 | return; // it makes no sense to continue here! | ||
201 | } | ||
202 | if (bytes_read != sizeof(wd)) { | ||
203 | fprintf(stderr, | ||
204 | "Error: Could not read info from signal handler %d <> %d!\n", | ||
205 | bytes_read, sizeof(wd)); | ||
206 | return; // it makes no sense to continue here! | ||
207 | } | ||
208 | if (wd.pid==0) { // special case, see delayedChildrenCleanup() | ||
209 | delayedChildrenCleanupTimer.start( 1000, true ); | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | for( QValueList<KProcess*>::ConstIterator it = processList.begin(); | ||
214 | it != processList.end(); | ||
215 | ++it ) { | ||
216 | KProcess* proc = *it; | ||
217 | if (proc->pid() == wd.pid) { | ||
218 | // process has exited, so do emit the respective events | ||
219 | if (proc->run_mode == KProcess::Block) { | ||
220 | // If the reads are done blocking then set the status in proc | ||
221 | // but do nothing else because KProcess will perform the other | ||
222 | // actions of processHasExited. | ||
223 | proc->status = wd.status; | ||
224 | proc->runs = false; | ||
225 | } else { | ||
226 | proc->processHasExited(wd.status); | ||
227 | } | ||
228 | return; | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | // this is needed e.g. for popen(), which calls waitpid() checking | ||
234 | // for its forked child, if we did waitpid() directly in the SIGCHLD | ||
235 | // handler, popen()'s waitpid() call would fail | ||
236 | void KProcessController::delayedChildrenCleanup() | ||
237 | { | ||
238 | struct waitdata wd; | ||
239 | while(( wd.pid = waitpid( -1, &wd.status, WNOHANG ) ) > 0 ) { | ||
240 | for( QValueList<KProcess*>::ConstIterator it = processList.begin(); | ||
241 | it != processList.end(); | ||
242 | ++it ) | ||
243 | { | ||
244 | if( !(*it)->isRunning() || (*it)->pid() != wd.pid ) | ||
245 | continue; | ||
246 | // it's KProcess, handle it | ||
247 | ::write(fd[1], &wd, sizeof(wd)); | ||
248 | break; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | KProcessController::~KProcessController() | ||
254 | { | ||
255 | assert( theKProcessController == this ); | ||
256 | resetHandlers(); | ||
257 | |||
258 | notifier->setEnabled(false); | ||
259 | |||
260 | close(fd[0]); | ||
261 | close(fd[1]); | ||
262 | |||
263 | delete notifier; | ||
264 | theKProcessController = 0; | ||
265 | } | ||
266 | |||
267 | //#include "kprocctrl.moc" | ||
diff --git a/noncore/settings/networksettings/kprocctrl.h b/noncore/settings/networksettings/kprocctrl.h new file mode 100644 index 0000000..ac82b9d --- a/dev/null +++ b/noncore/settings/networksettings/kprocctrl.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | // | ||
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | ||
21 | // | ||
22 | // version 0.3.1, Jan 8th 1997 | ||
23 | // | ||
24 | // (C) Christian Czezatke | ||
25 | // e9025461@student.tuwien.ac.at | ||
26 | // | ||
27 | |||
28 | #ifndef __KPROCCTRL_H__ | ||
29 | #define __KPROCCTRL_H__ | ||
30 | |||
31 | #include <qvaluelist.h> | ||
32 | #include <qtimer.h> | ||
33 | |||
34 | #include "kprocess.h" | ||
35 | |||
36 | class KProcessControllerPrivate; | ||
37 | class QSocketNotifier; | ||
38 | |||
39 | /** | ||
40 | * @short Used internally by @ref KProcess | ||
41 | * @internal | ||
42 | * @author Christian Czezakte <e9025461@student.tuwien.ac.at> | ||
43 | * | ||
44 | * A class for internal use by KProcess only. -- Exactly one instance | ||
45 | * of this class is generated by the first instance of KProcess that is | ||
46 | * created (a pointer to it gets stored in @ref theKProcessController ). | ||
47 | * | ||
48 | * This class takes care of the actual (UN*X) signal handling. | ||
49 | */ | ||
50 | class KProcessController : public QObject | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | |||
54 | public: | ||
55 | KProcessController(); | ||
56 | ~KProcessController(); | ||
57 | //CC: WARNING! Destructor Not virtual (but you don't derive classes from this anyhow...) | ||
58 | |||
59 | public: | ||
60 | |||
61 | /** | ||
62 | * Only a single instance of this class is allowed at a time, | ||
63 | * and this static variable is used to track the one instance. | ||
64 | */ | ||
65 | static KProcessController *theKProcessController; | ||
66 | |||
67 | /** | ||
68 | * Automatically called upon SIGCHLD. | ||
69 | * | ||
70 | * Normally you do not need to do anything with this function but | ||
71 | * if your application needs to disable SIGCHLD for some time for | ||
72 | * reasons beyond your control, you should call this function afterwards | ||
73 | * to make sure that no SIGCHLDs where missed. | ||
74 | */ | ||
75 | static void theSigCHLDHandler(int signal); | ||
76 | // handler for sigchld | ||
77 | |||
78 | /** | ||
79 | * @internal | ||
80 | */ | ||
81 | static void setupHandlers(); | ||
82 | /** | ||
83 | * @internal | ||
84 | */ | ||
85 | static void resetHandlers(); | ||
86 | /** | ||
87 | * @internal | ||
88 | */ | ||
89 | void addKProcess( KProcess* ); | ||
90 | /** | ||
91 | * @internal | ||
92 | */ | ||
93 | void removeKProcess( KProcess* ); | ||
94 | public slots: | ||
95 | /** | ||
96 | * @internal | ||
97 | */ | ||
98 | void slotDoHousekeeping(int socket); | ||
99 | |||
100 | private slots: | ||
101 | void delayedChildrenCleanup(); | ||
102 | private: | ||
103 | int fd[2]; | ||
104 | QSocketNotifier *notifier; | ||
105 | static struct sigaction oldChildHandlerData; | ||
106 | static bool handlerSet; | ||
107 | QValueList<KProcess*> processList; | ||
108 | QTimer delayedChildrenCleanupTimer; | ||
109 | |||
110 | // Disallow assignment and copy-construction | ||
111 | KProcessController( const KProcessController& ); | ||
112 | KProcessController& operator= ( const KProcessController& ); | ||
113 | |||
114 | KProcessControllerPrivate *d; | ||
115 | }; | ||
116 | |||
117 | |||
118 | |||
119 | #endif | ||
120 | |||
diff --git a/noncore/settings/networksettings/kprocess.cpp b/noncore/settings/networksettings/kprocess.cpp new file mode 100644 index 0000000..193ec9b --- a/dev/null +++ b/noncore/settings/networksettings/kprocess.cpp | |||
@@ -0,0 +1,919 @@ | |||
1 | /* | ||
2 | |||
3 | $Id$ | ||
4 | |||
5 | This file is part of the KDE libraries | ||
6 | Copyright (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Library General Public | ||
10 | License as published by the Free Software Foundation; either | ||
11 | version 2 of the License, or (at your option) any later version. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Library General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Library General Public License | ||
19 | along with this library; see the file COPYING.LIB. If not, write to | ||
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
21 | Boston, MA 02111-1307, USA. | ||
22 | */ | ||
23 | |||
24 | |||
25 | // | ||
26 | // KPROCESS -- A class for handling child processes in KDE without | ||
27 | // having to take care of Un*x specific implementation details | ||
28 | // | ||
29 | // version 0.3.1, Jan 8th 1998 | ||
30 | // | ||
31 | // (C) Christian Czezatke | ||
32 | // e9025461@student.tuwien.ac.at | ||
33 | // | ||
34 | // Changes: | ||
35 | // | ||
36 | // March 2nd, 1998: Changed parameter list for KShellProcess: | ||
37 | // Arguments are now placed in a single string so that | ||
38 | // <shell> -c <commandstring> is passed to the shell | ||
39 | // to make the use of "operator<<" consistent with KProcess | ||
40 | |||
41 | #include "kprocess.h" | ||
42 | #define _MAY_INCLUDE_KPROCESSCONTROLLER_ | ||
43 | #include "kprocctrl.h" | ||
44 | |||
45 | //#include <config.h> | ||
46 | |||
47 | #include <qglobal.h> | ||
48 | #include <qmap.h> | ||
49 | #include <qfile.h> | ||
50 | #include <qsocketnotifier.h> | ||
51 | #include <qregexp.h> | ||
52 | |||
53 | #include <sys/time.h> | ||
54 | #include <sys/types.h> | ||
55 | #include <sys/stat.h> | ||
56 | #include <sys/socket.h> | ||
57 | |||
58 | #include <errno.h> | ||
59 | #include <fcntl.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <signal.h> | ||
62 | #include <stdio.h> | ||
63 | #include <string.h> | ||
64 | #include <unistd.h> | ||
65 | #ifdef HAVE_SYS_SELECT_H | ||
66 | #include <sys/select.h> | ||
67 | #endif | ||
68 | #ifdef HAVE_INITGROUPS | ||
69 | #include <grp.h> | ||
70 | #endif | ||
71 | #include <pwd.h> | ||
72 | |||
73 | #include <qapplication.h> | ||
74 | //#include <kdebug.h> | ||
75 | |||
76 | ///////////////////////////// | ||
77 | // public member functions // | ||
78 | ///////////////////////////// | ||
79 | |||
80 | class KProcessPrivate { | ||
81 | public: | ||
82 | KProcessPrivate() : useShell(false) { } | ||
83 | |||
84 | bool useShell; | ||
85 | QMap<QString,QString> env; | ||
86 | QString wd; | ||
87 | QCString shell; | ||
88 | }; | ||
89 | |||
90 | #define Q_CHECK_PTR(a) | ||
91 | |||
92 | KProcess::KProcess() | ||
93 | : QObject(), | ||
94 | run_mode(NotifyOnExit), | ||
95 | runs(false), | ||
96 | pid_(0), | ||
97 | status(0), | ||
98 | keepPrivs(false), | ||
99 | innot(0), | ||
100 | outnot(0), | ||
101 | errnot(0), | ||
102 | communication(NoCommunication), | ||
103 | input_data(0), | ||
104 | input_sent(0), | ||
105 | input_total(0), | ||
106 | d(0) | ||
107 | { | ||
108 | if (0 == KProcessController::theKProcessController) { | ||
109 | (void) new KProcessController(); | ||
110 | Q_CHECK_PTR(KProcessController::theKProcessController); | ||
111 | } | ||
112 | |||
113 | KProcessController::theKProcessController->addKProcess(this); | ||
114 | out[0] = out[1] = -1; | ||
115 | in[0] = in[1] = -1; | ||
116 | err[0] = err[1] = -1; | ||
117 | } | ||
118 | |||
119 | void | ||
120 | KProcess::setEnvironment(const QString &name, const QString &value) | ||
121 | { | ||
122 | if (!d) | ||
123 | d = new KProcessPrivate; | ||
124 | d->env.insert(name, value); | ||
125 | } | ||
126 | |||
127 | void | ||
128 | KProcess::setWorkingDirectory(const QString &dir) | ||
129 | { | ||
130 | if (!d) | ||
131 | d = new KProcessPrivate; | ||
132 | d->wd = dir; | ||
133 | } | ||
134 | |||
135 | void | ||
136 | KProcess::setupEnvironment() | ||
137 | { | ||
138 | if (d) | ||
139 | { | ||
140 | QMap<QString,QString>::Iterator it; | ||
141 | for(it = d->env.begin(); it != d->env.end(); ++it) | ||
142 | setenv(QFile::encodeName(it.key()).data(), | ||
143 | QFile::encodeName(it.data()).data(), 1); | ||
144 | if (!d->wd.isEmpty()) | ||
145 | chdir(QFile::encodeName(d->wd).data()); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | void | ||
150 | KProcess::setRunPrivileged(bool keepPrivileges) | ||
151 | { | ||
152 | keepPrivs = keepPrivileges; | ||
153 | } | ||
154 | |||
155 | bool | ||
156 | KProcess::runPrivileged() const | ||
157 | { | ||
158 | return keepPrivs; | ||
159 | } | ||
160 | |||
161 | |||
162 | KProcess::~KProcess() | ||
163 | { | ||
164 | // destroying the KProcess instance sends a SIGKILL to the | ||
165 | // child process (if it is running) after removing it from the | ||
166 | // list of valid processes (if the process is not started as | ||
167 | // "DontCare") | ||
168 | |||
169 | KProcessController::theKProcessController->removeKProcess(this); | ||
170 | // this must happen before we kill the child | ||
171 | // TODO: block the signal while removing the current process from the process list | ||
172 | |||
173 | if (runs && (run_mode != DontCare)) | ||
174 | kill(SIGKILL); | ||
175 | |||
176 | // Clean up open fd's and socket notifiers. | ||
177 | closeStdin(); | ||
178 | closeStdout(); | ||
179 | closeStderr(); | ||
180 | |||
181 | // TODO: restore SIGCHLD and SIGPIPE handler if this is the last KProcess | ||
182 | delete d; | ||
183 | } | ||
184 | |||
185 | void KProcess::detach() | ||
186 | { | ||
187 | KProcessController::theKProcessController->removeKProcess(this); | ||
188 | |||
189 | runs = false; | ||
190 | pid_ = 0; | ||
191 | |||
192 | // Clean up open fd's and socket notifiers. | ||
193 | closeStdin(); | ||
194 | closeStdout(); | ||
195 | closeStderr(); | ||
196 | } | ||
197 | |||
198 | bool KProcess::setExecutable(const QString& proc) | ||
199 | { | ||
200 | if (runs) return false; | ||
201 | |||
202 | if (proc.isEmpty()) return false; | ||
203 | |||
204 | if (!arguments.isEmpty()) | ||
205 | arguments.remove(arguments.begin()); | ||
206 | arguments.prepend(QFile::encodeName(proc)); | ||
207 | |||
208 | return true; | ||
209 | } | ||
210 | |||
211 | KProcess &KProcess::operator<<(const QStringList& args) | ||
212 | { | ||
213 | QStringList::ConstIterator it = args.begin(); | ||
214 | for ( ; it != args.end() ; ++it ) | ||
215 | arguments.append(QFile::encodeName(*it)); | ||
216 | return *this; | ||
217 | } | ||
218 | |||
219 | KProcess &KProcess::operator<<(const QCString& arg) | ||
220 | { | ||
221 | return operator<< (arg.data()); | ||
222 | } | ||
223 | |||
224 | KProcess &KProcess::operator<<(const char* arg) | ||
225 | { | ||
226 | arguments.append(arg); | ||
227 | return *this; | ||
228 | } | ||
229 | |||
230 | KProcess &KProcess::operator<<(const QString& arg) | ||
231 | { | ||
232 | arguments.append(QFile::encodeName(arg)); | ||
233 | return *this; | ||
234 | } | ||
235 | |||
236 | void KProcess::clearArguments() | ||
237 | { | ||
238 | arguments.clear(); | ||
239 | } | ||
240 | |||
241 | bool KProcess::start(RunMode runmode, Communication comm) | ||
242 | { | ||
243 | uint i; | ||
244 | uint n = arguments.count(); | ||
245 | char **arglist; | ||
246 | |||
247 | if (runs || (0 == n)) { | ||
248 | return false; // cannot start a process that is already running | ||
249 | // or if no executable has been assigned | ||
250 | } | ||
251 | run_mode = runmode; | ||
252 | status = 0; | ||
253 | |||
254 | QCString shellCmd; | ||
255 | if (d && d->useShell) | ||
256 | { | ||
257 | if (d->shell.isEmpty()) | ||
258 | { | ||
259 | //kdDebug() << "Could not find a valid shell\n" << endl; | ||
260 | return false; | ||
261 | } | ||
262 | |||
263 | arglist = static_cast<char **>(malloc( (4)*sizeof(char *))); | ||
264 | for (i=0; i < n; i++) { | ||
265 | shellCmd += arguments[i]; | ||
266 | shellCmd += " "; // CC: to separate the arguments | ||
267 | } | ||
268 | |||
269 | arglist[0] = d->shell.data(); | ||
270 | arglist[1] = (char *) "-c"; | ||
271 | arglist[2] = shellCmd.data(); | ||
272 | arglist[3] = 0; | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | arglist = static_cast<char **>(malloc( (n+1)*sizeof(char *))); | ||
277 | for (i=0; i < n; i++) | ||
278 | arglist[i] = arguments[i].data(); | ||
279 | arglist[n]= 0; | ||
280 | } | ||
281 | |||
282 | setupCommunication(comm); | ||
283 | //) | ||
284 | //kdDebug() << "Could not setup Communication!\n"; | ||
285 | |||
286 | // We do this in the parent because if we do it in the child process | ||
287 | // gdb gets confused when the application runs from gdb. | ||
288 | uid_t uid = getuid(); | ||
289 | gid_t gid = getgid(); | ||
290 | #ifdef HAVE_INITGROUPS | ||
291 | struct passwd *pw = getpwuid(uid); | ||
292 | #endif | ||
293 | |||
294 | int fd[2]; | ||
295 | if (0 > pipe(fd)) | ||
296 | { | ||
297 | fd[0] = fd[1] = 0; // Pipe failed.. continue | ||
298 | } | ||
299 | |||
300 | runs = true; | ||
301 | |||
302 | QApplication::flushX(); | ||
303 | |||
304 | // WABA: Note that we use fork() and not vfork() because | ||
305 | // vfork() has unclear semantics and is not standardized. | ||
306 | pid_ = fork(); | ||
307 | |||
308 | if (0 == pid_) { | ||
309 | if (fd[0]) | ||
310 | close(fd[0]); | ||
311 | if (!runPrivileged()) | ||
312 | { | ||
313 | setgid(gid); | ||
314 | #if defined( HAVE_INITGROUPS) | ||
315 | if(pw) | ||
316 | initgroups(pw->pw_name, pw->pw_gid); | ||
317 | #endif | ||
318 | setuid(uid); | ||
319 | } | ||
320 | // The child process | ||
321 | commSetupDoneC(); | ||
322 | //) | ||
323 | //kdDebug() << "Could not finish comm setup in child!" << endl; | ||
324 | |||
325 | setupEnvironment(); | ||
326 | |||
327 | // Matthias | ||
328 | if (run_mode == DontCare) | ||
329 | setpgid(0,0); | ||
330 | // restore default SIGPIPE handler (Harri) | ||
331 | struct sigaction act; | ||
332 | sigemptyset(&(act.sa_mask)); | ||
333 | sigaddset(&(act.sa_mask), SIGPIPE); | ||
334 | act.sa_handler = SIG_DFL; | ||
335 | act.sa_flags = 0; | ||
336 | sigaction(SIGPIPE, &act, 0L); | ||
337 | |||
338 | // We set the close on exec flag. | ||
339 | // Closing of fd[1] indicates that the execvp succeeded! | ||
340 | if (fd[1]) | ||
341 | fcntl(fd[1], F_SETFD, FD_CLOEXEC); | ||
342 | execvp(arglist[0], arglist); | ||
343 | char resultByte = 1; | ||
344 | if (fd[1]) | ||
345 | write(fd[1], &resultByte, 1); | ||
346 | _exit(-1); | ||
347 | } else if (-1 == pid_) { | ||
348 | // forking failed | ||
349 | |||
350 | runs = false; | ||
351 | free(arglist); | ||
352 | return false; | ||
353 | } else { | ||
354 | if (fd[1]) | ||
355 | close(fd[1]); | ||
356 | // the parent continues here | ||
357 | |||
358 | // Discard any data for stdin that might still be there | ||
359 | input_data = 0; | ||
360 | |||
361 | // Check whether client could be started. | ||
362 | if (fd[0]) for(;;) | ||
363 | { | ||
364 | char resultByte; | ||
365 | int n = ::read(fd[0], &resultByte, 1); | ||
366 | if (n == 1) | ||
367 | { | ||
368 | // Error | ||
369 | runs = false; | ||
370 | close(fd[0]); | ||
371 | free(arglist); | ||
372 | pid_ = 0; | ||
373 | return false; | ||
374 | } | ||
375 | if (n == -1) | ||
376 | { | ||
377 | if ((errno == ECHILD) || (errno == EINTR)) | ||
378 | continue; // Ignore | ||
379 | } | ||
380 | break; // success | ||
381 | } | ||
382 | if (fd[0]) | ||
383 | close(fd[0]); | ||
384 | |||
385 | if (!commSetupDoneP()){} // finish communication socket setup for the parent | ||
386 | //kdDebug() << "Could not finish comm setup in parent!" << endl; | ||
387 | |||
388 | if (run_mode == Block) { | ||
389 | commClose(); | ||
390 | |||
391 | // The SIGCHLD handler of the process controller will catch | ||
392 | // the exit and set the status | ||
393 | while(runs) | ||
394 | { | ||
395 | KProcessController::theKProcessController-> | ||
396 | slotDoHousekeeping(0); | ||
397 | } | ||
398 | runs = FALSE; | ||
399 | emit processExited(this); | ||
400 | } | ||
401 | } | ||
402 | free(arglist); | ||
403 | return true; | ||
404 | } | ||
405 | |||
406 | |||
407 | |||
408 | bool KProcess::kill(int signo) | ||
409 | { | ||
410 | bool rv=false; | ||
411 | |||
412 | if (0 != pid_) | ||
413 | rv= (-1 != ::kill(pid_, signo)); | ||
414 | // probably store errno somewhere... | ||
415 | return rv; | ||
416 | } | ||
417 | |||
418 | |||
419 | |||
420 | bool KProcess::isRunning() const | ||
421 | { | ||
422 | return runs; | ||
423 | } | ||
424 | |||
425 | |||
426 | |||
427 | pid_t KProcess::pid() const | ||
428 | { | ||
429 | return pid_; | ||
430 | } | ||
431 | |||
432 | |||
433 | |||
434 | bool KProcess::normalExit() const | ||
435 | { | ||
436 | int _status = status; | ||
437 | return (pid_ != 0) && (!runs) && (WIFEXITED((_status))); | ||
438 | } | ||
439 | |||
440 | |||
441 | |||
442 | int KProcess::exitStatus() const | ||
443 | { | ||
444 | int _status = status; | ||
445 | return WEXITSTATUS((_status)); | ||
446 | } | ||
447 | |||
448 | |||
449 | |||
450 | bool KProcess::writeStdin(const char *buffer, int buflen) | ||
451 | { | ||
452 | bool rv; | ||
453 | |||
454 | // if there is still data pending, writing new data | ||
455 | // to stdout is not allowed (since it could also confuse | ||
456 | // kprocess... | ||
457 | if (0 != input_data) | ||
458 | return false; | ||
459 | |||
460 | if (runs && (communication & Stdin)) { | ||
461 | input_data = buffer; | ||
462 | input_sent = 0; | ||
463 | input_total = buflen; | ||
464 | slotSendData(0); | ||
465 | innot->setEnabled(true); | ||
466 | rv = true; | ||
467 | } else | ||
468 | rv = false; | ||
469 | return rv; | ||
470 | } | ||
471 | |||
472 | void KProcess::suspend() | ||
473 | { | ||
474 | if ((communication & Stdout) && outnot) | ||
475 | outnot->setEnabled(false); | ||
476 | } | ||
477 | |||
478 | void KProcess::resume() | ||
479 | { | ||
480 | if ((communication & Stdout) && outnot) | ||
481 | outnot->setEnabled(true); | ||
482 | } | ||
483 | |||
484 | bool KProcess::closeStdin() | ||
485 | { | ||
486 | bool rv; | ||
487 | |||
488 | if (communication & Stdin) { | ||
489 | communication = (Communication) (communication & ~Stdin); | ||
490 | delete innot; | ||
491 | innot = 0; | ||
492 | close(in[1]); | ||
493 | rv = true; | ||
494 | } else | ||
495 | rv = false; | ||
496 | return rv; | ||
497 | } | ||
498 | |||
499 | bool KProcess::closeStdout() | ||
500 | { | ||
501 | bool rv; | ||
502 | |||
503 | if (communication & Stdout) { | ||
504 | communication = (Communication) (communication & ~Stdout); | ||
505 | delete outnot; | ||
506 | outnot = 0; | ||
507 | close(out[0]); | ||
508 | rv = true; | ||
509 | } else | ||
510 | rv = false; | ||
511 | return rv; | ||
512 | } | ||
513 | |||
514 | bool KProcess::closeStderr() | ||
515 | { | ||
516 | bool rv; | ||
517 | |||
518 | if (communication & Stderr) { | ||
519 | communication = static_cast<Communication>(communication & ~Stderr); | ||
520 | delete errnot; | ||
521 | errnot = 0; | ||
522 | close(err[0]); | ||
523 | rv = true; | ||
524 | } else | ||
525 | rv = false; | ||
526 | return rv; | ||
527 | } | ||
528 | |||
529 | |||
530 | ///////////////////////////// | ||
531 | // protected slots // | ||
532 | ///////////////////////////// | ||
533 | |||
534 | |||
535 | |||
536 | void KProcess::slotChildOutput(int fdno) | ||
537 | { | ||
538 | if (!childOutput(fdno)) | ||
539 | closeStdout(); | ||
540 | } | ||
541 | |||
542 | |||
543 | void KProcess::slotChildError(int fdno) | ||
544 | { | ||
545 | if (!childError(fdno)) | ||
546 | closeStderr(); | ||
547 | } | ||
548 | |||
549 | |||
550 | void KProcess::slotSendData(int) | ||
551 | { | ||
552 | if (input_sent == input_total) { | ||
553 | innot->setEnabled(false); | ||
554 | input_data = 0; | ||
555 | emit wroteStdin(this); | ||
556 | } else | ||
557 | input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent); | ||
558 | } | ||
559 | |||
560 | |||
561 | |||
562 | ////////////////////////////// | ||
563 | // private member functions // | ||
564 | ////////////////////////////// | ||
565 | |||
566 | |||
567 | |||
568 | void KProcess::processHasExited(int state) | ||
569 | { | ||
570 | if (runs) | ||
571 | { | ||
572 | runs = false; | ||
573 | status = state; | ||
574 | |||
575 | commClose(); // cleanup communication sockets | ||
576 | |||
577 | // also emit a signal if the process was run Blocking | ||
578 | if (DontCare != run_mode) | ||
579 | { | ||
580 | emit processExited(this); | ||
581 | } | ||
582 | } | ||
583 | } | ||
584 | |||
585 | |||
586 | |||
587 | int KProcess::childOutput(int fdno) | ||
588 | { | ||
589 | if (communication & NoRead) { | ||
590 | int len = -1; | ||
591 | emit receivedStdout(fdno, len); | ||
592 | errno = 0; // Make sure errno doesn't read "EAGAIN" | ||
593 | return len; | ||
594 | } | ||
595 | else | ||
596 | { | ||
597 | char buffer[1024]; | ||
598 | int len; | ||
599 | |||
600 | len = ::read(fdno, buffer, 1024); | ||
601 | |||
602 | if ( 0 < len) { | ||
603 | emit receivedStdout(this, buffer, len); | ||
604 | } | ||
605 | return len; | ||
606 | } | ||
607 | } | ||
608 | |||
609 | |||
610 | |||
611 | int KProcess::childError(int fdno) | ||
612 | { | ||
613 | char buffer[1024]; | ||
614 | int len; | ||
615 | |||
616 | len = ::read(fdno, buffer, 1024); | ||
617 | |||
618 | if ( 0 < len) | ||
619 | emit receivedStderr(this, buffer, len); | ||
620 | return len; | ||
621 | } | ||
622 | |||
623 | |||
624 | |||
625 | int KProcess::setupCommunication(Communication comm) | ||
626 | { | ||
627 | int ok; | ||
628 | |||
629 | communication = comm; | ||
630 | |||
631 | ok = 1; | ||
632 | if (comm & Stdin) | ||
633 | ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, in) >= 0; | ||
634 | |||
635 | if (comm & Stdout) | ||
636 | ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, out) >= 0; | ||
637 | |||
638 | if (comm & Stderr) | ||
639 | ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0; | ||
640 | |||
641 | return ok; | ||
642 | } | ||
643 | |||
644 | |||
645 | |||
646 | int KProcess::commSetupDoneP() | ||
647 | { | ||
648 | int ok = 1; | ||
649 | |||
650 | if (communication != NoCommunication) { | ||
651 | if (communication & Stdin) | ||
652 | close(in[0]); | ||
653 | if (communication & Stdout) | ||
654 | close(out[1]); | ||
655 | if (communication & Stderr) | ||
656 | close(err[1]); | ||
657 | |||
658 | // Don't create socket notifiers and set the sockets non-blocking if | ||
659 | // blocking is requested. | ||
660 | if (run_mode == Block) return ok; | ||
661 | |||
662 | if (communication & Stdin) { | ||
663 | // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); | ||
664 | innot = new QSocketNotifier(in[1], QSocketNotifier::Write, this); | ||
665 | Q_CHECK_PTR(innot); | ||
666 | innot->setEnabled(false); // will be enabled when data has to be sent | ||
667 | QObject::connect(innot, SIGNAL(activated(int)), | ||
668 | this, SLOT(slotSendData(int))); | ||
669 | } | ||
670 | |||
671 | if (communication & Stdout) { | ||
672 | // ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK)); | ||
673 | outnot = new QSocketNotifier(out[0], QSocketNotifier::Read, this); | ||
674 | Q_CHECK_PTR(outnot); | ||
675 | QObject::connect(outnot, SIGNAL(activated(int)), | ||
676 | this, SLOT(slotChildOutput(int))); | ||
677 | if (communication & NoRead) | ||
678 | suspend(); | ||
679 | } | ||
680 | |||
681 | if (communication & Stderr) { | ||
682 | // ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK)); | ||
683 | errnot = new QSocketNotifier(err[0], QSocketNotifier::Read, this ); | ||
684 | Q_CHECK_PTR(errnot); | ||
685 | QObject::connect(errnot, SIGNAL(activated(int)), | ||
686 | this, SLOT(slotChildError(int))); | ||
687 | } | ||
688 | } | ||
689 | return ok; | ||
690 | } | ||
691 | |||
692 | |||
693 | |||
694 | int KProcess::commSetupDoneC() | ||
695 | { | ||
696 | int ok = 1; | ||
697 | struct linger so; | ||
698 | memset(&so, 0, sizeof(so)); | ||
699 | |||
700 | if (communication & Stdin) | ||
701 | close(in[1]); | ||
702 | if (communication & Stdout) | ||
703 | close(out[0]); | ||
704 | if (communication & Stderr) | ||
705 | close(err[0]); | ||
706 | |||
707 | if (communication & Stdin) | ||
708 | ok &= dup2(in[0], STDIN_FILENO) != -1; | ||
709 | else { | ||
710 | int null_fd = open( "/dev/null", O_RDONLY ); | ||
711 | ok &= dup2( null_fd, STDIN_FILENO ) != -1; | ||
712 | close( null_fd ); | ||
713 | } | ||
714 | if (communication & Stdout) { | ||
715 | ok &= dup2(out[1], STDOUT_FILENO) != -1; | ||
716 | ok &= !setsockopt(out[1], SOL_SOCKET, SO_LINGER, (char*)&so, sizeof(so)); | ||
717 | } | ||
718 | else { | ||
719 | int null_fd = open( "/dev/null", O_WRONLY ); | ||
720 | ok &= dup2( null_fd, STDOUT_FILENO ) != -1; | ||
721 | close( null_fd ); | ||
722 | } | ||
723 | if (communication & Stderr) { | ||
724 | ok &= dup2(err[1], STDERR_FILENO) != -1; | ||
725 | ok &= !setsockopt(err[1], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>(&so), sizeof(so)); | ||
726 | } | ||
727 | else { | ||
728 | int null_fd = open( "/dev/null", O_WRONLY ); | ||
729 | ok &= dup2( null_fd, STDERR_FILENO ) != -1; | ||
730 | close( null_fd ); | ||
731 | } | ||
732 | return ok; | ||
733 | } | ||
734 | |||
735 | |||
736 | |||
737 | void KProcess::commClose() | ||
738 | { | ||
739 | if (NoCommunication != communication) { | ||
740 | bool b_in = (communication & Stdin); | ||
741 | bool b_out = (communication & Stdout); | ||
742 | bool b_err = (communication & Stderr); | ||
743 | if (b_in) | ||
744 | delete innot; | ||
745 | |||
746 | if (b_out || b_err) { | ||
747 | // If both channels are being read we need to make sure that one socket buffer | ||
748 | // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). | ||
749 | // Hence we need to use select. | ||
750 | |||
751 | // Once one or other of the channels has reached EOF (or given an error) go back | ||
752 | // to the usual mechanism. | ||
753 | |||
754 | int fds_ready = 1; | ||
755 | fd_set rfds; | ||
756 | |||
757 | int max_fd = 0; | ||
758 | if (b_out) { | ||
759 | fcntl(out[0], F_SETFL, O_NONBLOCK); | ||
760 | if (out[0] > max_fd) | ||
761 | max_fd = out[0]; | ||
762 | delete outnot; | ||
763 | outnot = 0; | ||
764 | } | ||
765 | if (b_err) { | ||
766 | fcntl(err[0], F_SETFL, O_NONBLOCK); | ||
767 | if (err[0] > max_fd) | ||
768 | max_fd = err[0]; | ||
769 | delete errnot; | ||
770 | errnot = 0; | ||
771 | } | ||
772 | |||
773 | |||
774 | while (b_out || b_err) { | ||
775 | // * If the process is still running we block until we | ||
776 | // receive data. (p_timeout = 0, no timeout) | ||
777 | // * If the process has already exited, we only check | ||
778 | // the available data, we don't wait for more. | ||
779 | // (p_timeout = &timeout, timeout immediately) | ||
780 | struct timeval timeout; | ||
781 | timeout.tv_sec = 0; | ||
782 | timeout.tv_usec = 0; | ||
783 | struct timeval *p_timeout = runs ? 0 : &timeout; | ||
784 | |||
785 | FD_ZERO(&rfds); | ||
786 | if (b_out) | ||
787 | FD_SET(out[0], &rfds); | ||
788 | |||
789 | if (b_err) | ||
790 | FD_SET(err[0], &rfds); | ||
791 | |||
792 | fds_ready = select(max_fd+1, &rfds, 0, 0, p_timeout); | ||
793 | if (fds_ready <= 0) break; | ||
794 | |||
795 | if (b_out && FD_ISSET(out[0], &rfds)) { | ||
796 | int ret = 1; | ||
797 | while (ret > 0) ret = childOutput(out[0]); | ||
798 | if ((ret == -1 && errno != EAGAIN) || ret == 0) | ||
799 | b_out = false; | ||
800 | } | ||
801 | |||
802 | if (b_err && FD_ISSET(err[0], &rfds)) { | ||
803 | int ret = 1; | ||
804 | while (ret > 0) ret = childError(err[0]); | ||
805 | if ((ret == -1 && errno != EAGAIN) || ret == 0) | ||
806 | b_err = false; | ||
807 | } | ||
808 | } | ||
809 | } | ||
810 | |||
811 | if (b_in) { | ||
812 | communication = (Communication) (communication & ~Stdin); | ||
813 | close(in[1]); | ||
814 | } | ||
815 | if (b_out) { | ||
816 | communication = (Communication) (communication & ~Stdout); | ||
817 | close(out[0]); | ||
818 | } | ||
819 | if (b_err) { | ||
820 | communication = (Communication) (communication & ~Stderr); | ||
821 | close(err[0]); | ||
822 | } | ||
823 | } | ||
824 | } | ||
825 | |||
826 | void KProcess::setUseShell(bool useShell, const char *shell) | ||
827 | { | ||
828 | if (!d) | ||
829 | d = new KProcessPrivate; | ||
830 | d->useShell = useShell; | ||
831 | d->shell = shell; | ||
832 | if (d->shell.isEmpty()) | ||
833 | d->shell = searchShell(); | ||
834 | } | ||
835 | |||
836 | QString KProcess::quote(const QString &arg) | ||
837 | { | ||
838 | QString res = arg; | ||
839 | res.replace(QRegExp(QString::fromLatin1("\'")), | ||
840 | QString::fromLatin1("'\"'\"'")); | ||
841 | res.prepend('\''); | ||
842 | res.append('\''); | ||
843 | return res; | ||
844 | } | ||
845 | |||
846 | QCString KProcess::searchShell() | ||
847 | { | ||
848 | QCString tmpShell = QCString(getenv("SHELL")).stripWhiteSpace(); | ||
849 | if (!isExecutable(tmpShell)) | ||
850 | { | ||
851 | tmpShell = "/bin/sh"; | ||
852 | } | ||
853 | |||
854 | return tmpShell; | ||
855 | } | ||
856 | |||
857 | bool KProcess::isExecutable(const QCString &filename) | ||
858 | { | ||
859 | struct stat fileinfo; | ||
860 | |||
861 | if (filename.isEmpty()) return false; | ||
862 | |||
863 | // CC: we've got a valid filename, now let's see whether we can execute that file | ||
864 | |||
865 | if (-1 == stat(filename.data(), &fileinfo)) return false; | ||
866 | // CC: return false if the file does not exist | ||
867 | |||
868 | // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets | ||
869 | if ( (S_ISDIR(fileinfo.st_mode)) || | ||
870 | (S_ISCHR(fileinfo.st_mode)) || | ||
871 | (S_ISBLK(fileinfo.st_mode)) || | ||
872 | #ifdef S_ISSOCK | ||
873 | // CC: SYSVR4 systems don't have that macro | ||
874 | (S_ISSOCK(fileinfo.st_mode)) || | ||
875 | #endif | ||
876 | (S_ISFIFO(fileinfo.st_mode)) || | ||
877 | (S_ISDIR(fileinfo.st_mode)) ) { | ||
878 | return false; | ||
879 | } | ||
880 | |||
881 | // CC: now check for permission to execute the file | ||
882 | if (access(filename.data(), X_OK) != 0) return false; | ||
883 | |||
884 | // CC: we've passed all the tests... | ||
885 | return true; | ||
886 | } | ||
887 | |||
888 | void KProcess::virtual_hook( int, void* ) | ||
889 | { /*BASE::virtual_hook( id, data );*/ } | ||
890 | |||
891 | |||
892 | /////////////////////////// | ||
893 | // CC: Class KShellProcess | ||
894 | /////////////////////////// | ||
895 | |||
896 | KShellProcess::KShellProcess(const char *shellname): | ||
897 | KProcess() | ||
898 | { | ||
899 | setUseShell(true, shellname); | ||
900 | } | ||
901 | |||
902 | |||
903 | KShellProcess::~KShellProcess() { | ||
904 | } | ||
905 | |||
906 | QString KShellProcess::quote(const QString &arg) | ||
907 | { | ||
908 | return KProcess::quote(arg); | ||
909 | } | ||
910 | |||
911 | bool KShellProcess::start(RunMode runmode, Communication comm) | ||
912 | { | ||
913 | return KProcess::start(runmode, comm); | ||
914 | } | ||
915 | |||
916 | void KShellProcess::virtual_hook( int id, void* data ) | ||
917 | { KProcess::virtual_hook( id, data ); } | ||
918 | |||
919 | //#include "kprocess.moc" | ||
diff --git a/noncore/settings/networksettings/kprocess.h b/noncore/settings/networksettings/kprocess.h new file mode 100644 index 0000000..e70f7e7 --- a/dev/null +++ b/noncore/settings/networksettings/kprocess.h | |||
@@ -0,0 +1,804 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | // | ||
20 | // KPROCESS -- A class for handling child processes in KDE without | ||
21 | // having to take care of Un*x specific implementation details | ||
22 | // | ||
23 | // version 0.3.1, Jan 8th 1998 | ||
24 | // | ||
25 | // (C) Christian Czezatke | ||
26 | // e9025461@student.tuwien.ac.at | ||
27 | // | ||
28 | |||
29 | #ifndef __kprocess_h__ | ||
30 | #define __kprocess_h__ | ||
31 | |||
32 | #include <sys/types.h> // for pid_t | ||
33 | #include <sys/wait.h> | ||
34 | #include <signal.h> | ||
35 | #include <unistd.h> | ||
36 | #include <qvaluelist.h> | ||
37 | #include <qcstring.h> | ||
38 | #include <qobject.h> | ||
39 | |||
40 | class QSocketNotifier; | ||
41 | class KProcessPrivate; | ||
42 | |||
43 | /** | ||
44 | * Child process invocation, monitoring and control. | ||
45 | * | ||
46 | * @sect General usage and features | ||
47 | * | ||
48 | *This class allows a KDE application to start child processes without having | ||
49 | *to worry about UN*X signal handling issues and zombie process reaping. | ||
50 | * | ||
51 | *@see KProcIO | ||
52 | * | ||
53 | *Basically, this class distinguishes three different ways of running | ||
54 | *child processes: | ||
55 | * | ||
56 | *@li KProcess::DontCare -- The child process is invoked and both the child | ||
57 | *process and the parent process continue concurrently. | ||
58 | * | ||
59 | *Starting a DontCare child process means that the application is | ||
60 | *not interested in any notification to determine whether the | ||
61 | *child process has already exited or not. | ||
62 | * | ||
63 | *@li KProcess::NotifyOnExit -- The child process is invoked and both the | ||
64 | *child and the parent process run concurrently. | ||
65 | * | ||
66 | *When the child process exits, the KProcess instance | ||
67 | *corresponding to it emits the Qt signal @ref processExited(). | ||
68 | * | ||
69 | *Since this signal is @em not emitted from within a UN*X | ||
70 | *signal handler, arbitrary function calls can be made. | ||
71 | * | ||
72 | *Be aware: When the KProcess objects gets destructed, the child | ||
73 | *process will be killed if it is still running! | ||
74 | *This means in particular, that you cannot use a KProcess on the stack | ||
75 | *with KProcess::NotifyOnExit. | ||
76 | * | ||
77 | *@li KProcess::Block -- The child process starts and the parent process | ||
78 | *is suspended until the child process exits. (@em Really not recommended | ||
79 | *for programs with a GUI.) | ||
80 | * | ||
81 | *KProcess also provides several functions for determining the exit status | ||
82 | *and the pid of the child process it represents. | ||
83 | * | ||
84 | *Furthermore it is possible to supply command-line arguments to the process | ||
85 | *in a clean fashion (no null -- terminated stringlists and such...) | ||
86 | * | ||
87 | *A small usage example: | ||
88 | *<pre> | ||
89 | *KProcess *proc = new KProcess; | ||
90 | * | ||
91 | **proc << "my_executable"; | ||
92 | **proc << "These" << "are" << "the" << "command" << "line" << "args"; | ||
93 | *QApplication::connect(proc, SIGNAL(processExited(KProcess *)), | ||
94 | * pointer_to_my_object, SLOT(my_objects_slot(KProcess *))); | ||
95 | *proc->start(); | ||
96 | *</pre> | ||
97 | * | ||
98 | *This will start "my_executable" with the commandline arguments "These"... | ||
99 | * | ||
100 | *When the child process exits, the respective Qt signal will be emitted. | ||
101 | * | ||
102 | *@sect Communication with the child process | ||
103 | * | ||
104 | *KProcess supports communication with the child process through | ||
105 | *stdin/stdout/stderr. | ||
106 | * | ||
107 | *The following functions are provided for getting data from the child | ||
108 | *process or sending data to the child's stdin (For more information, | ||
109 | *have a look at the documentation of each function): | ||
110 | * | ||
111 | *@li bool @ref writeStdin(char *buffer, int buflen); | ||
112 | *@li -- Transmit data to the child process's stdin. | ||
113 | * | ||
114 | *@li bool @ref closeStdin(); | ||
115 | *@li -- Closes the child process's stdin (which causes it to see an feof(stdin)). | ||
116 | *Returns false if you try to close stdin for a process that has been started | ||
117 | *without a communication channel to stdin. | ||
118 | * | ||
119 | *@li bool @ref closeStdout(); | ||
120 | *@li -- Closes the child process's stdout. | ||
121 | *Returns false if you try to close stdout for a process that has been started | ||
122 | *without a communication channel to stdout. | ||
123 | * | ||
124 | *@li bool @ref closeStderr(); | ||
125 | *@li -- Closes the child process's stderr. | ||
126 | *Returns false if you try to close stderr for a process that has been started | ||
127 | *without a communication channel to stderr. | ||
128 | * | ||
129 | * | ||
130 | *@sect QT signals: | ||
131 | * | ||
132 | *@li void @ref receivedStdout(KProcess *proc, char *buffer, int buflen); | ||
133 | *@li void @ref receivedStderr(KProcess *proc, char *buffer, int buflen); | ||
134 | *@li -- Indicates that new data has arrived from either the | ||
135 | *child process's stdout or stderr. | ||
136 | * | ||
137 | *@li void @ref wroteStdin(KProcess *proc); | ||
138 | *@li -- Indicates that all data that has been sent to the child process | ||
139 | *by a prior call to @ref writeStdin() has actually been transmitted to the | ||
140 | *client . | ||
141 | * | ||
142 | *@author Christian Czezakte e9025461@student.tuwien.ac.at | ||
143 | * | ||
144 | * | ||
145 | **/ | ||
146 | class KProcess : public QObject | ||
147 | { | ||
148 | Q_OBJECT | ||
149 | |||
150 | public: | ||
151 | |||
152 | /** | ||
153 | * Modes in which the communication channel can be opened. | ||
154 | * | ||
155 | * If communication for more than one channel is required, | ||
156 | * the values have to be or'ed together, for example to get | ||
157 | * communication with stdout as well as with stdin, you would | ||
158 | * specify @p Stdin @p | @p Stdout | ||
159 | * | ||
160 | * If @p NoRead is specified in conjunction with @p Stdout, | ||
161 | * no data is actually read from @p Stdout but only | ||
162 | * the signal @ref childOutput(int fd) is emitted. | ||
163 | */ | ||
164 | enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4, | ||
165 | AllOutput = 6, All = 7, | ||
166 | NoRead }; | ||
167 | |||
168 | /** | ||
169 | * Run-modes for a child process. | ||
170 | */ | ||
171 | enum RunMode { | ||
172 | /** | ||
173 | * The application does not receive notifications from the subprocess when | ||
174 | * it is finished or aborted. | ||
175 | */ | ||
176 | DontCare, | ||
177 | /** | ||
178 | * The application is notified when the subprocess dies. | ||
179 | */ | ||
180 | NotifyOnExit, | ||
181 | /** | ||
182 | * The application is suspended until the started process is finished. | ||
183 | */ | ||
184 | Block }; | ||
185 | |||
186 | /** | ||
187 | * Constructor | ||
188 | */ | ||
189 | KProcess(); | ||
190 | |||
191 | /** | ||
192 | *Destructor: | ||
193 | * | ||
194 | * If the process is running when the destructor for this class | ||
195 | * is called, the child process is killed with a SIGKILL, but | ||
196 | * only if the run mode is not of type @p DontCare. | ||
197 | * Processes started as @p DontCare keep running anyway. | ||
198 | */ | ||
199 | virtual ~KProcess(); | ||
200 | |||
201 | /** | ||
202 | @deprecated | ||
203 | |||
204 | The use of this function is now deprecated. -- Please use the | ||
205 | "operator<<" instead of "setExecutable". | ||
206 | |||
207 | Sets the executable to be started with this KProcess object. | ||
208 | Returns false if the process is currently running (in that | ||
209 | case the executable remains unchanged.) | ||
210 | |||
211 | @see operator<< | ||
212 | |||
213 | */ | ||
214 | bool setExecutable(const QString& proc); | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Sets the executable and the command line argument list for this process. | ||
219 | * | ||
220 | * For example, doing an "ls -l /usr/local/bin" can be achieved by: | ||
221 | * <pre> | ||
222 | * KProcess p; | ||
223 | * ... | ||
224 | * p << "ls" << "-l" << "/usr/local/bin" | ||
225 | * </pre> | ||
226 | * | ||
227 | **/ | ||
228 | KProcess &operator<<(const QString& arg); | ||
229 | /** | ||
230 | * Similar to previous method, takes a char *, supposed to be in locale 8 bit already. | ||
231 | */ | ||
232 | KProcess &operator<<(const char * arg); | ||
233 | /** | ||
234 | * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already. | ||
235 | */ | ||
236 | KProcess &operator<<(const QCString & arg); | ||
237 | |||
238 | /** | ||
239 | * Sets the executable and the command line argument list for this process, | ||
240 | * in a single method call, or add a list of arguments. | ||
241 | **/ | ||
242 | KProcess &operator<<(const QStringList& args); | ||
243 | |||
244 | /** | ||
245 | * Clear a command line argument list that has been set by using | ||
246 | * the "operator<<". | ||
247 | */ | ||
248 | void clearArguments(); | ||
249 | |||
250 | /** | ||
251 | * Starts the process. | ||
252 | * For a detailed description of the | ||
253 | * various run modes and communication semantics, have a look at the | ||
254 | * general description of the KProcess class. | ||
255 | * | ||
256 | * The following problems could cause this function to | ||
257 | * return false: | ||
258 | * | ||
259 | * @li The process is already running. | ||
260 | * @li The command line argument list is empty. | ||
261 | * @li The starting of the process failed (could not fork). | ||
262 | * @li The executable was not found. | ||
263 | * | ||
264 | * @param comm Specifies which communication links should be | ||
265 | * established to the child process (stdin/stdout/stderr). By default, | ||
266 | * no communication takes place and the respective communication | ||
267 | * signals will never get emitted. | ||
268 | * | ||
269 | * @return true on success, false on error | ||
270 | * (see above for error conditions) | ||
271 | **/ | ||
272 | virtual bool start(RunMode runmode = NotifyOnExit, | ||
273 | Communication comm = NoCommunication); | ||
274 | |||
275 | /** | ||
276 | * Stop the process (by sending it a signal). | ||
277 | * | ||
278 | * @param signoThe signal to send. The default is SIGTERM. | ||
279 | * @return @p true if the signal was delivered successfully. | ||
280 | */ | ||
281 | virtual bool kill(int signo = SIGTERM); | ||
282 | |||
283 | /** | ||
284 | @return @p true if the process is (still) considered to be running | ||
285 | */ | ||
286 | bool isRunning() const; | ||
287 | |||
288 | /** Returns the process id of the process. | ||
289 | * | ||
290 | * If it is called after | ||
291 | * the process has exited, it returns the process id of the last | ||
292 | * child process that was created by this instance of KProcess. | ||
293 | * | ||
294 | * Calling it before any child process has been started by this | ||
295 | * KProcess instance causes pid() to return 0. | ||
296 | **/ | ||
297 | pid_t pid() const; | ||
298 | |||
299 | /** | ||
300 | * Use pid(). | ||
301 | * @deprecated | ||
302 | */ | ||
303 | pid_t getPid() const { return pid(); } | ||
304 | |||
305 | /** | ||
306 | * Suspend processing of data from stdout of the child process. | ||
307 | */ | ||
308 | void suspend(); | ||
309 | |||
310 | /** | ||
311 | * Resume processing of data from stdout of the child process. | ||
312 | */ | ||
313 | void resume(); | ||
314 | |||
315 | /** | ||
316 | * @return @p true if the process has already finished and has exited | ||
317 | * "voluntarily", ie: it has not been killed by a signal. | ||
318 | * | ||
319 | * Note that you should check @ref KProcess::exitStatus() to determine | ||
320 | * whether the process completed its task successful or not. | ||
321 | */ | ||
322 | bool normalExit() const; | ||
323 | |||
324 | /** | ||
325 | * Returns the exit status of the process. | ||
326 | * | ||
327 | * Please use | ||
328 | * @ref KProcess::normalExit() to check whether the process has exited | ||
329 | * cleanly (i.e., @ref KProcess::normalExit() returns @p true) before calling | ||
330 | * this function because if the process did not exit normally, | ||
331 | * it does not have a valid exit status. | ||
332 | */ | ||
333 | int exitStatus() const; | ||
334 | |||
335 | |||
336 | /** | ||
337 | * Transmit data to the child process's stdin. | ||
338 | * | ||
339 | * KProcess::writeStdin may return false in the following cases: | ||
340 | * | ||
341 | * @li The process is not currently running. | ||
342 | * | ||
343 | * @li Communication to stdin has not been requested in the @ref start() call. | ||
344 | * | ||
345 | * @li Transmission of data to the child process by a previous call to | ||
346 | * @ref writeStdin() is still in progress. | ||
347 | * | ||
348 | * Please note that the data is sent to the client asynchronously, | ||
349 | * so when this function returns, the data might not have been | ||
350 | * processed by the child process. | ||
351 | * | ||
352 | * If all the data has been sent to the client, the signal | ||
353 | * @ref wroteStdin() will be emitted. | ||
354 | * | ||
355 | * Please note that you must not free "buffer" or call @ref writeStdin() | ||
356 | * again until either a @ref wroteStdin() signal indicates that the | ||
357 | * data has been sent or a @ref processHasExited() signal shows that | ||
358 | * the child process is no longer alive... | ||
359 | **/ | ||
360 | bool writeStdin(const char *buffer, int buflen); | ||
361 | |||
362 | /** | ||
363 | * This causes the stdin file descriptor of the child process to be | ||
364 | * closed indicating an "EOF" to the child. | ||
365 | * | ||
366 | * @return @p false if no communication to the process's stdin | ||
367 | * had been specified in the call to @ref start(). | ||
368 | */ | ||
369 | bool closeStdin(); | ||
370 | |||
371 | /** | ||
372 | * This causes the stdout file descriptor of the child process to be | ||
373 | * closed. | ||
374 | * | ||
375 | * @return @p false if no communication to the process's stdout | ||
376 | * had been specified in the call to @ref start(). | ||
377 | */ | ||
378 | bool closeStdout(); | ||
379 | |||
380 | /** | ||
381 | * This causes the stderr file descriptor of the child process to be | ||
382 | * closed. | ||
383 | * | ||
384 | * @return @p false if no communication to the process's stderr | ||
385 | * had been specified in the call to @ref start(). | ||
386 | */ | ||
387 | bool closeStderr(); | ||
388 | |||
389 | /** | ||
390 | * Lets you see what your arguments are for debugging. | ||
391 | */ | ||
392 | |||
393 | const QValueList<QCString> &args() { return arguments; } | ||
394 | |||
395 | /** | ||
396 | * Controls whether the started process should drop any | ||
397 | * setuid/segid privileges or whether it should keep them | ||
398 | * | ||
399 | * The default is @p false : drop privileges | ||
400 | */ | ||
401 | void setRunPrivileged(bool keepPrivileges); | ||
402 | |||
403 | /** | ||
404 | * Returns whether the started process will drop any | ||
405 | * setuid/segid privileges or whether it will keep them | ||
406 | */ | ||
407 | bool runPrivileged() const; | ||
408 | |||
409 | /** | ||
410 | * Modifies the environment of the process to be started. | ||
411 | * This function must be called before starting the process. | ||
412 | */ | ||
413 | void setEnvironment(const QString &name, const QString &value); | ||
414 | |||
415 | /** | ||
416 | * Changes the current working directory (CWD) of the process | ||
417 | * to be started. | ||
418 | * This function must be called before starting the process. | ||
419 | */ | ||
420 | void setWorkingDirectory(const QString &dir); | ||
421 | |||
422 | /** | ||
423 | * Specify whether to start the command via a shell or directly. | ||
424 | * The default is to start the command directly. | ||
425 | * If @p useShell is true @p shell will be used as shell, or | ||
426 | * if shell is empty, the standard shell is used. | ||
427 | * @p quote A flag indicating whether to quote the arguments. | ||
428 | * | ||
429 | * When using a shell, the caller should make sure that all filenames etc. | ||
430 | * are properly quoted when passed as argument. | ||
431 | * @see quote() | ||
432 | */ | ||
433 | void setUseShell(bool useShell, const char *shell = 0); | ||
434 | |||
435 | /** | ||
436 | * This function can be used to quote an argument string such that | ||
437 | * the shell processes it properly. This is e. g. necessary for | ||
438 | * user-provided file names which may contain spaces or quotes. | ||
439 | * It also prevents expansion of wild cards and environment variables. | ||
440 | */ | ||
441 | static QString quote(const QString &arg); | ||
442 | |||
443 | /** | ||
444 | * Detaches KProcess from child process. All communication is closed. | ||
445 | * No exit notification is emitted any more for the child process. | ||
446 | * Deleting the KProcess will no longer kill the child process. | ||
447 | * Note that the current process remains the parent process of the | ||
448 | * child process. | ||
449 | */ | ||
450 | void detach(); | ||
451 | |||
452 | |||
453 | |||
454 | signals: | ||
455 | |||
456 | /** | ||
457 | * Emitted after the process has terminated when | ||
458 | * the process was run in the @p NotifyOnExit (==default option to | ||
459 | * @ref start()) or the @ref Block mode. | ||
460 | **/ | ||
461 | void processExited(KProcess *proc); | ||
462 | |||
463 | |||
464 | /** | ||
465 | * Emitted, when output from the child process has | ||
466 | * been received on stdout. | ||
467 | * | ||
468 | * To actually get | ||
469 | * these signals, the respective communication link (stdout/stderr) | ||
470 | * has to be turned on in @ref start(). | ||
471 | * | ||
472 | * @param buffer The data received. | ||
473 | * @param buflen The number of bytes that are available. | ||
474 | * | ||
475 | * You should copy the information contained in @p buffer to your private | ||
476 | * data structures before returning from this slot. | ||
477 | **/ | ||
478 | void receivedStdout(KProcess *proc, char *buffer, int buflen); | ||
479 | |||
480 | /** | ||
481 | * Emitted when output from the child process has | ||
482 | * been received on stdout. | ||
483 | * | ||
484 | * To actually get these signals, the respective communications link | ||
485 | * (stdout/stderr) has to be turned on in @ref start() and the | ||
486 | * @p NoRead flag should have been passed. | ||
487 | * | ||
488 | * You will need to explicitly call resume() after your call to start() | ||
489 | * to begin processing data from the child process's stdout. This is | ||
490 | * to ensure that this signal is not emitted when no one is connected | ||
491 | * to it, otherwise this signal will not be emitted. | ||
492 | * | ||
493 | * The data still has to be read from file descriptor @p fd. | ||
494 | **/ | ||
495 | void receivedStdout(int fd, int &len); | ||
496 | |||
497 | |||
498 | /** | ||
499 | * Emitted, when output from the child process has | ||
500 | * been received on stderr. | ||
501 | * To actually get | ||
502 | * these signals, the respective communication link (stdout/stderr) | ||
503 | * has to be turned on in @ref start(). | ||
504 | * | ||
505 | * @param buffer The data received. | ||
506 | * @param buflen The number of bytes that are available. | ||
507 | * | ||
508 | * You should copy the information contained in @p buffer to your private | ||
509 | * data structures before returning from this slot. | ||
510 | */ | ||
511 | void receivedStderr(KProcess *proc, char *buffer, int buflen); | ||
512 | |||
513 | /** | ||
514 | * Emitted after all the data that has been | ||
515 | * specified by a prior call to @ref writeStdin() has actually been | ||
516 | * written to the child process. | ||
517 | **/ | ||
518 | void wroteStdin(KProcess *proc); | ||
519 | |||
520 | |||
521 | protected slots: | ||
522 | |||
523 | /** | ||
524 | * This slot gets activated when data from the child's stdout arrives. | ||
525 | * It usually calls "childOutput" | ||
526 | */ | ||
527 | void slotChildOutput(int fdno); | ||
528 | |||
529 | /** | ||
530 | * This slot gets activated when data from the child's stderr arrives. | ||
531 | * It usually calls "childError" | ||
532 | */ | ||
533 | void slotChildError(int fdno); | ||
534 | /* | ||
535 | Slot functions for capturing stdout and stderr of the child | ||
536 | */ | ||
537 | |||
538 | /** | ||
539 | * Called when another bulk of data can be sent to the child's | ||
540 | * stdin. If there is no more data to be sent to stdin currently | ||
541 | * available, this function must disable the QSocketNotifier "innot". | ||
542 | */ | ||
543 | void slotSendData(int dummy); | ||
544 | |||
545 | protected: | ||
546 | |||
547 | /** | ||
548 | * Sets up the environment according to the data passed via | ||
549 | * setEnvironment(...) | ||
550 | */ | ||
551 | void setupEnvironment(); | ||
552 | |||
553 | /** | ||
554 | * The list of the process' command line arguments. The first entry | ||
555 | * in this list is the executable itself. | ||
556 | */ | ||
557 | QValueList<QCString> arguments; | ||
558 | /** | ||
559 | * How to run the process (Block, NotifyOnExit, DontCare). You should | ||
560 | * not modify this data member directly from derived classes. | ||
561 | */ | ||
562 | RunMode run_mode; | ||
563 | /** | ||
564 | * true if the process is currently running. You should not | ||
565 | * modify this data member directly from derived classes. For | ||
566 | * reading the value of this data member, please use "isRunning()" | ||
567 | * since "runs" will probably be made private in later versions | ||
568 | * of KProcess. | ||
569 | */ | ||
570 | bool runs; | ||
571 | |||
572 | /** | ||
573 | * The PID of the currently running process (see "getPid()"). | ||
574 | * You should not modify this data member in derived classes. | ||
575 | * Please use "getPid()" instead of directly accessing this | ||
576 | * member function since it will probably be made private in | ||
577 | * later versions of KProcess. | ||
578 | */ | ||
579 | pid_t pid_; | ||
580 | |||
581 | /** | ||
582 | * The process' exit status as returned by "waitpid". You should not | ||
583 | * modify the value of this data member from derived classes. You should | ||
584 | * rather use @ref exitStatus than accessing this data member directly | ||
585 | * since it will probably be made private in further versions of | ||
586 | * KProcess. | ||
587 | */ | ||
588 | int status; | ||
589 | |||
590 | |||
591 | /** | ||
592 | * See setRunPrivileged() | ||
593 | */ | ||
594 | bool keepPrivs; | ||
595 | |||
596 | /* | ||
597 | Functions for setting up the sockets for communication. | ||
598 | setupCommunication | ||
599 | -- is called from "start" before "fork"ing. | ||
600 | commSetupDoneP | ||
601 | -- completes communication socket setup in the parent | ||
602 | commSetupDoneC | ||
603 | -- completes communication setup in the child process | ||
604 | commClose | ||
605 | -- frees all allocated communication resources in the parent | ||
606 | after the process has exited | ||
607 | */ | ||
608 | |||
609 | /** | ||
610 | * This function is called from "KProcess::start" right before a "fork" takes | ||
611 | * place. According to | ||
612 | * the "comm" parameter this function has to initialize the "in", "out" and | ||
613 | * "err" data member of KProcess. | ||
614 | * | ||
615 | * This function should return 0 if setting the needed communication channels | ||
616 | * was successful. | ||
617 | * | ||
618 | * The default implementation is to create UNIX STREAM sockets for the communication, | ||
619 | * but you could overload this function and establish a TCP/IP communication for | ||
620 | * network communication, for example. | ||
621 | */ | ||
622 | virtual int setupCommunication(Communication comm); | ||
623 | |||
624 | /** | ||
625 | * Called right after a (successful) fork on the parent side. This function | ||
626 | * will usually do some communications cleanup, like closing the reading end | ||
627 | * of the "stdin" communication channel. | ||
628 | * | ||
629 | * Furthermore, it must also create the QSocketNotifiers "innot", "outnot" and | ||
630 | * "errnot" and connect their Qt slots to the respective KProcess member functions. | ||
631 | * | ||
632 | * For a more detailed explanation, it is best to have a look at the default | ||
633 | * implementation of "setupCommunication" in kprocess.cpp. | ||
634 | */ | ||
635 | virtual int commSetupDoneP(); | ||
636 | |||
637 | /** | ||
638 | * Called right after a (successful) fork, but before an "exec" on the child | ||
639 | * process' side. It usually just closes the unused communication ends of | ||
640 | * "in", "out" and "err" (like the writing end of the "in" communication | ||
641 | * channel. | ||
642 | */ | ||
643 | virtual int commSetupDoneC(); | ||
644 | |||
645 | |||
646 | /** | ||
647 | * Immediately called after a process has exited. This function normally | ||
648 | * calls commClose to close all open communication channels to this | ||
649 | * process and emits the "processExited" signal (if the process was | ||
650 | * not running in the "DontCare" mode). | ||
651 | */ | ||
652 | virtual void processHasExited(int state); | ||
653 | |||
654 | /** | ||
655 | * Should clean up the communication links to the child after it has | ||
656 | * exited. Should be called from "processHasExited". | ||
657 | */ | ||
658 | virtual void commClose(); | ||
659 | |||
660 | |||
661 | /** | ||
662 | * the socket descriptors for stdin/stdout/stderr. | ||
663 | */ | ||
664 | int out[2]; | ||
665 | int in[2]; | ||
666 | int err[2]; | ||
667 | |||
668 | /** | ||
669 | * The socket notifiers for the above socket descriptors. | ||
670 | */ | ||
671 | QSocketNotifier *innot; | ||
672 | QSocketNotifier *outnot; | ||
673 | QSocketNotifier *errnot; | ||
674 | |||
675 | /** | ||
676 | * Lists the communication links that are activated for the child | ||
677 | * process. Should not be modified from derived classes. | ||
678 | */ | ||
679 | Communication communication; | ||
680 | |||
681 | /** | ||
682 | * Called by "slotChildOutput" this function copies data arriving from the | ||
683 | * child process's stdout to the respective buffer and emits the signal | ||
684 | * "@ref receivedStderr". | ||
685 | */ | ||
686 | int childOutput(int fdno); | ||
687 | |||
688 | /** | ||
689 | * Called by "slotChildOutput" this function copies data arriving from the | ||
690 | * child process's stdout to the respective buffer and emits the signal | ||
691 | * "@ref receivedStderr" | ||
692 | */ | ||
693 | int childError(int fdno); | ||
694 | |||
695 | // information about the data that has to be sent to the child: | ||
696 | |||
697 | const char *input_data; // the buffer holding the data | ||
698 | int input_sent; // # of bytes already transmitted | ||
699 | int input_total; // total length of input_data | ||
700 | |||
701 | /** | ||
702 | * @ref KProcessController is a friend of KProcess because it has to have | ||
703 | * access to various data members. | ||
704 | */ | ||
705 | friend class KProcessController; | ||
706 | |||
707 | |||
708 | private: | ||
709 | /** | ||
710 | * Searches for a valid shell. | ||
711 | * Here is the algorithm used for finding an executable shell: | ||
712 | * | ||
713 | * @li Try the executable pointed to by the "SHELL" environment | ||
714 | * variable with white spaces stripped off | ||
715 | * | ||
716 | * @li If your process runs with uid != euid or gid != egid, a shell | ||
717 | * not listed in /etc/shells will not used. | ||
718 | * | ||
719 | * @li If no valid shell could be found, "/bin/sh" is used as a last resort. | ||
720 | */ | ||
721 | QCString searchShell(); | ||
722 | |||
723 | /** | ||
724 | * Used by @ref searchShell in order to find out whether the shell found | ||
725 | * is actually executable at all. | ||
726 | */ | ||
727 | bool isExecutable(const QCString &filename); | ||
728 | |||
729 | // Disallow assignment and copy-construction | ||
730 | KProcess( const KProcess& ); | ||
731 | KProcess& operator= ( const KProcess& ); | ||
732 | |||
733 | protected: | ||
734 | virtual void virtual_hook( int id, void* data ); | ||
735 | private: | ||
736 | KProcessPrivate *d; | ||
737 | }; | ||
738 | |||
739 | class KShellProcessPrivate; | ||
740 | |||
741 | /** | ||
742 | * @obsolete | ||
743 | * | ||
744 | * This class is obsolete. Use KProcess and KProcess::setUseShell(true) | ||
745 | * instead. | ||
746 | * | ||
747 | * @short A class derived from @ref KProcess to start child | ||
748 | * processes through a shell. | ||
749 | * @author Christian Czezakte <e9025461@student.tuwien.ac.at> | ||
750 | * @version $Id$ | ||
751 | */ | ||
752 | class KShellProcess: public KProcess | ||
753 | { | ||
754 | Q_OBJECT | ||
755 | |||
756 | public: | ||
757 | |||
758 | /** | ||
759 | * Constructor | ||
760 | * | ||
761 | * By specifying the name of a shell (like "/bin/bash") you can override | ||
762 | * the mechanism for finding a valid shell as described in KProcess::searchShell() | ||
763 | */ | ||
764 | KShellProcess(const char *shellname=0); | ||
765 | |||
766 | /** | ||
767 | * Destructor. | ||
768 | */ | ||
769 | ~KShellProcess(); | ||
770 | |||
771 | /** | ||
772 | * Starts up the process. -- For a detailed description | ||
773 | * have a look at the "start" member function and the detailed | ||
774 | * description of @ref KProcess . | ||
775 | */ | ||
776 | virtual bool start(RunMode runmode = NotifyOnExit, | ||
777 | Communication comm = NoCommunication); | ||
778 | |||
779 | /** | ||
780 | * This function can be used to quote an argument string such that | ||
781 | * the shell processes it properly. This is e. g. necessary for | ||
782 | * user-provided file names which may contain spaces or quotes. | ||
783 | * It also prevents expansion of wild cards and environment variables. | ||
784 | */ | ||
785 | static QString quote(const QString &arg); | ||
786 | |||
787 | private: | ||
788 | |||
789 | QCString shell; | ||
790 | |||
791 | // Disallow assignment and copy-construction | ||
792 | KShellProcess( const KShellProcess& ); | ||
793 | KShellProcess& operator= ( const KShellProcess& ); | ||
794 | |||
795 | protected: | ||
796 | virtual void virtual_hook( int id, void* data ); | ||
797 | private: | ||
798 | KShellProcessPrivate *d; | ||
799 | }; | ||
800 | |||
801 | |||
802 | |||
803 | #endif | ||
804 | |||
diff --git a/noncore/settings/networksettings/main.cpp b/noncore/settings/networksettings/main.cpp new file mode 100644 index 0000000..52cb92b --- a/dev/null +++ b/noncore/settings/networksettings/main.cpp | |||
@@ -0,0 +1,13 @@ | |||
1 | #include "mainwindowimp.h" | ||
2 | #include <qpe/qpeapplication.h> | ||
3 | |||
4 | int main(int argc, char **argv) | ||
5 | { | ||
6 | QPEApplication app(argc, argv); | ||
7 | MainWindowImp window; | ||
8 | window.showMaximized(); | ||
9 | return app.exec(); | ||
10 | } | ||
11 | |||
12 | // main.cpp | ||
13 | |||
diff --git a/noncore/settings/networksettings/mainwindow.ui b/noncore/settings/networksettings/mainwindow.ui new file mode 100644 index 0000000..b8c0675 --- a/dev/null +++ b/noncore/settings/networksettings/mainwindow.ui | |||
@@ -0,0 +1,321 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>MainWindow</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>MainWindow</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>222</width> | ||
15 | <height>289</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Network Setup</string> | ||
21 | </property> | ||
22 | <vbox> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>0</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget> | ||
32 | <class>QTabWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>tabWidget</cstring> | ||
36 | </property> | ||
37 | <property> | ||
38 | <name>layoutMargin</name> | ||
39 | </property> | ||
40 | <widget> | ||
41 | <class>QWidget</class> | ||
42 | <property stdset="1"> | ||
43 | <name>name</name> | ||
44 | <cstring>Widget3</cstring> | ||
45 | </property> | ||
46 | <attribute> | ||
47 | <name>title</name> | ||
48 | <string>Interfaces</string> | ||
49 | </attribute> | ||
50 | <vbox> | ||
51 | <property stdset="1"> | ||
52 | <name>margin</name> | ||
53 | <number>0</number> | ||
54 | </property> | ||
55 | <property stdset="1"> | ||
56 | <name>spacing</name> | ||
57 | <number>6</number> | ||
58 | </property> | ||
59 | <widget> | ||
60 | <class>QListView</class> | ||
61 | <column> | ||
62 | <property> | ||
63 | <name>text</name> | ||
64 | <string>i</string> | ||
65 | </property> | ||
66 | <property> | ||
67 | <name>clickable</name> | ||
68 | <bool>true</bool> | ||
69 | </property> | ||
70 | <property> | ||
71 | <name>resizeable</name> | ||
72 | <bool>true</bool> | ||
73 | </property> | ||
74 | </column> | ||
75 | <column> | ||
76 | <property> | ||
77 | <name>text</name> | ||
78 | <string>t</string> | ||
79 | </property> | ||
80 | <property> | ||
81 | <name>clickable</name> | ||
82 | <bool>true</bool> | ||
83 | </property> | ||
84 | <property> | ||
85 | <name>resizeable</name> | ||
86 | <bool>true</bool> | ||
87 | </property> | ||
88 | </column> | ||
89 | <column> | ||
90 | <property> | ||
91 | <name>text</name> | ||
92 | <string>Name</string> | ||
93 | </property> | ||
94 | <property> | ||
95 | <name>clickable</name> | ||
96 | <bool>true</bool> | ||
97 | </property> | ||
98 | <property> | ||
99 | <name>resizeable</name> | ||
100 | <bool>true</bool> | ||
101 | </property> | ||
102 | </column> | ||
103 | <property stdset="1"> | ||
104 | <name>name</name> | ||
105 | <cstring>serviceList</cstring> | ||
106 | </property> | ||
107 | <property stdset="1"> | ||
108 | <name>allColumnsShowFocus</name> | ||
109 | <bool>true</bool> | ||
110 | </property> | ||
111 | </widget> | ||
112 | <widget> | ||
113 | <class>QLayoutWidget</class> | ||
114 | <property stdset="1"> | ||
115 | <name>name</name> | ||
116 | <cstring>Layout2</cstring> | ||
117 | </property> | ||
118 | <property> | ||
119 | <name>layoutMargin</name> | ||
120 | </property> | ||
121 | <grid> | ||
122 | <property stdset="1"> | ||
123 | <name>margin</name> | ||
124 | <number>5</number> | ||
125 | </property> | ||
126 | <property stdset="1"> | ||
127 | <name>spacing</name> | ||
128 | <number>6</number> | ||
129 | </property> | ||
130 | <widget row="1" column="0" > | ||
131 | <class>QPushButton</class> | ||
132 | <property stdset="1"> | ||
133 | <name>name</name> | ||
134 | <cstring>addServiceButton</cstring> | ||
135 | </property> | ||
136 | <property stdset="1"> | ||
137 | <name>text</name> | ||
138 | <string>&Add</string> | ||
139 | </property> | ||
140 | </widget> | ||
141 | <widget row="0" column="0" > | ||
142 | <class>QPushButton</class> | ||
143 | <property stdset="1"> | ||
144 | <name>name</name> | ||
145 | <cstring>informationServiceButton</cstring> | ||
146 | </property> | ||
147 | <property stdset="1"> | ||
148 | <name>text</name> | ||
149 | <string>&Information</string> | ||
150 | </property> | ||
151 | </widget> | ||
152 | <widget row="0" column="1" > | ||
153 | <class>QPushButton</class> | ||
154 | <property stdset="1"> | ||
155 | <name>name</name> | ||
156 | <cstring>configureServiceButton</cstring> | ||
157 | </property> | ||
158 | <property stdset="1"> | ||
159 | <name>text</name> | ||
160 | <string>&Configure</string> | ||
161 | </property> | ||
162 | </widget> | ||
163 | <widget row="1" column="1" > | ||
164 | <class>QPushButton</class> | ||
165 | <property stdset="1"> | ||
166 | <name>name</name> | ||
167 | <cstring>removeServiceButton</cstring> | ||
168 | </property> | ||
169 | <property stdset="1"> | ||
170 | <name>text</name> | ||
171 | <string>&Remove</string> | ||
172 | </property> | ||
173 | </widget> | ||
174 | </grid> | ||
175 | </widget> | ||
176 | </vbox> | ||
177 | </widget> | ||
178 | <widget> | ||
179 | <class>QWidget</class> | ||
180 | <property stdset="1"> | ||
181 | <name>name</name> | ||
182 | <cstring>tab</cstring> | ||
183 | </property> | ||
184 | <attribute> | ||
185 | <name>title</name> | ||
186 | <string>Profiles</string> | ||
187 | </attribute> | ||
188 | <grid> | ||
189 | <property stdset="1"> | ||
190 | <name>margin</name> | ||
191 | <number>11</number> | ||
192 | </property> | ||
193 | <property stdset="1"> | ||
194 | <name>spacing</name> | ||
195 | <number>6</number> | ||
196 | </property> | ||
197 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
198 | <class>QLabel</class> | ||
199 | <property stdset="1"> | ||
200 | <name>name</name> | ||
201 | <cstring>TextLabel3</cstring> | ||
202 | </property> | ||
203 | <property stdset="1"> | ||
204 | <name>text</name> | ||
205 | <string>Change Profile To</string> | ||
206 | </property> | ||
207 | </widget> | ||
208 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
209 | <class>QLabel</class> | ||
210 | <property stdset="1"> | ||
211 | <name>name</name> | ||
212 | <cstring>TextLabel1</cstring> | ||
213 | </property> | ||
214 | <property stdset="1"> | ||
215 | <name>text</name> | ||
216 | <string>Current Profile</string> | ||
217 | </property> | ||
218 | </widget> | ||
219 | <widget row="0" column="2" > | ||
220 | <class>QLabel</class> | ||
221 | <property stdset="1"> | ||
222 | <name>name</name> | ||
223 | <cstring>TextLabel2</cstring> | ||
224 | </property> | ||
225 | <property stdset="1"> | ||
226 | <name>frameShape</name> | ||
227 | <enum>Panel</enum> | ||
228 | </property> | ||
229 | <property stdset="1"> | ||
230 | <name>frameShadow</name> | ||
231 | <enum>Sunken</enum> | ||
232 | </property> | ||
233 | <property stdset="1"> | ||
234 | <name>text</name> | ||
235 | <string>All</string> | ||
236 | </property> | ||
237 | </widget> | ||
238 | <widget row="1" column="2" > | ||
239 | <class>QComboBox</class> | ||
240 | <item> | ||
241 | <property> | ||
242 | <name>text</name> | ||
243 | <string>All</string> | ||
244 | </property> | ||
245 | </item> | ||
246 | <property stdset="1"> | ||
247 | <name>name</name> | ||
248 | <cstring>ComboBox10</cstring> | ||
249 | </property> | ||
250 | </widget> | ||
251 | <widget row="2" column="1" rowspan="1" colspan="2" > | ||
252 | <class>QPushButton</class> | ||
253 | <property stdset="1"> | ||
254 | <name>name</name> | ||
255 | <cstring>removeProfileButton</cstring> | ||
256 | </property> | ||
257 | <property stdset="1"> | ||
258 | <name>text</name> | ||
259 | <string>&Remove</string> | ||
260 | </property> | ||
261 | </widget> | ||
262 | <widget row="2" column="0" > | ||
263 | <class>QPushButton</class> | ||
264 | <property stdset="1"> | ||
265 | <name>name</name> | ||
266 | <cstring>newProfileButton</cstring> | ||
267 | </property> | ||
268 | <property stdset="1"> | ||
269 | <name>text</name> | ||
270 | <string>&New</string> | ||
271 | </property> | ||
272 | </widget> | ||
273 | <spacer row="3" column="2" > | ||
274 | <property> | ||
275 | <name>name</name> | ||
276 | <cstring>Spacer16</cstring> | ||
277 | </property> | ||
278 | <property stdset="1"> | ||
279 | <name>orientation</name> | ||
280 | <enum>Vertical</enum> | ||
281 | </property> | ||
282 | <property stdset="1"> | ||
283 | <name>sizeType</name> | ||
284 | <enum>Expanding</enum> | ||
285 | </property> | ||
286 | <property> | ||
287 | <name>sizeHint</name> | ||
288 | <size> | ||
289 | <width>20</width> | ||
290 | <height>20</height> | ||
291 | </size> | ||
292 | </property> | ||
293 | </spacer> | ||
294 | </grid> | ||
295 | </widget> | ||
296 | </widget> | ||
297 | </vbox> | ||
298 | </widget> | ||
299 | <customwidgets> | ||
300 | <customwidget> | ||
301 | <class>QWidget</class> | ||
302 | <header location="local">qwidget.h</header> | ||
303 | <sizehint> | ||
304 | <width>100</width> | ||
305 | <height>100</height> | ||
306 | </sizehint> | ||
307 | <container>0</container> | ||
308 | <sizepolicy> | ||
309 | <hordata>7</hordata> | ||
310 | <verdata>7</verdata> | ||
311 | </sizepolicy> | ||
312 | <pixmap>image0</pixmap> | ||
313 | </customwidget> | ||
314 | </customwidgets> | ||
315 | <images> | ||
316 | <image> | ||
317 | <name>image0</name> | ||
318 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
319 | </image> | ||
320 | </images> | ||
321 | </UI> | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp new file mode 100644 index 0000000..3c13143 --- a/dev/null +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -0,0 +1,308 @@ | |||
1 | #include "mainwindowimp.h" | ||
2 | #include "addserviceimp.h" | ||
3 | #include "interfaceinformationimp.h" | ||
4 | #include "interfacesetupimp.h" | ||
5 | |||
6 | #include <qpushbutton.h> | ||
7 | #include <qdir.h> | ||
8 | #include <qtabwidget.h> | ||
9 | #include <qmainwindow.h> | ||
10 | #include <qmessagebox.h> | ||
11 | #include <qlistbox.h> | ||
12 | #include <qpe/config.h> | ||
13 | #include <qpe/qlibrary.h> | ||
14 | #include <qpe/resource.h> | ||
15 | #include <qlist.h> | ||
16 | |||
17 | #include <qfile.h> | ||
18 | #include <qtextstream.h> | ||
19 | #include <qlistview.h> | ||
20 | #include <qheader.h> | ||
21 | // For library loading. | ||
22 | #include <dlfcn.h> | ||
23 | |||
24 | #define TEMP_ALL "/tmp/ifconfig-a" | ||
25 | #define TEMP_UP "/tmp/ifconfig" | ||
26 | |||
27 | #define NO_SELECT_ERROR_AND_RETURN { \ | ||
28 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); \ | ||
29 | return; \ | ||
30 | } | ||
31 | |||
32 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) { | ||
33 | connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked())); | ||
34 | connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | ||
35 | connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | ||
36 | connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | ||
37 | // Make sure we have a plugin directory to scan. | ||
38 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | ||
39 | QDir pluginDir( DirStr ); | ||
40 | pluginDir.mkdir( DirStr ); | ||
41 | pluginDir.mkdir( ( DirStr + "plugins/" ) ); | ||
42 | QString path = DirStr + "plugins"; | ||
43 | pluginDir.setPath(path); | ||
44 | if(!pluginDir.exists()){ | ||
45 | qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1()); | ||
46 | return; | ||
47 | } | ||
48 | |||
49 | // Load any saved services. | ||
50 | loadModules(path); | ||
51 | getInterfaceList(); | ||
52 | serviceList->header()->hide(); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Deconstructor. Unload libraries and save. | ||
57 | */ | ||
58 | MainWindowImp::~MainWindowImp(){ | ||
59 | } | ||
60 | |||
61 | void MainWindowImp::loadModules(QString path){ | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Attempt to load a function and resolve a function. | ||
66 | * @param pluginFileName - the name of the file in which to attempt to load | ||
67 | * @param resolveString - function pointer to resolve | ||
68 | * @return pointer to the function with name resolveString or NULL | ||
69 | */ | ||
70 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | ||
71 | //qDebug(pluginFileName.latin1()); | ||
72 | QLibrary *lib = new QLibrary(pluginFileName); | ||
73 | void *functionPointer = lib->resolve(resolveString); | ||
74 | if( !functionPointer ){ | ||
75 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | ||
76 | delete lib; | ||
77 | return NULL; | ||
78 | } | ||
79 | |||
80 | // Try to get an object. | ||
81 | Module *object = ((Module* (*)()) functionPointer)(); | ||
82 | if(object == NULL){ | ||
83 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | ||
84 | delete lib; | ||
85 | return NULL; | ||
86 | } | ||
87 | |||
88 | // Store for reference | ||
89 | libraries.insert(object, lib); | ||
90 | return object; | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | QList<QString> MainWindowImp::retrieveUnloadedPluginList(){ | ||
95 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | ||
96 | QString path = DirStr + "plugins"; | ||
97 | QDir d(path); | ||
98 | d.setFilter( QDir::Files | QDir::Hidden ); | ||
99 | |||
100 | QMap<QObject*, QLibrary*>::Iterator libraryIt; | ||
101 | QList<QString> rlist; | ||
102 | rlist.setAutoDelete(false); | ||
103 | |||
104 | const QFileInfoList *list = d.entryInfoList(); | ||
105 | QFileInfoListIterator it( *list ); | ||
106 | QFileInfo *fi; | ||
107 | while ( (fi=it.current()) ) { | ||
108 | if(fi->fileName().contains(".so")){ | ||
109 | for( libraryIt = libraries.begin(); libraryIt != libraries.end(); ++libraryIt ) | ||
110 | if((path + "/" + fi->fileName()) != (libraryIt.data())->library()){ | ||
111 | QString *s = new QString(path + "/" + fi->fileName()); | ||
112 | rlist.append(s); | ||
113 | } | ||
114 | } | ||
115 | ++it; | ||
116 | } | ||
117 | return rlist; | ||
118 | } | ||
119 | */ | ||
120 | |||
121 | /** | ||
122 | * The Add button was clicked. Bring up the add dialog and if OK is hit | ||
123 | * load the plugin and append it to the list | ||
124 | */ | ||
125 | void MainWindowImp::addClicked(){ | ||
126 | // Now that we have a list of all of the protocals, list them. | ||
127 | { | ||
128 | QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok"); | ||
129 | return; | ||
130 | } | ||
131 | AddServiceImp service(this, "AddService", true); | ||
132 | service.showMaximized(); | ||
133 | service.exec(); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Prompt the user to see if they really want to do this. | ||
138 | * If they do then remove from the list and unload. | ||
139 | */ | ||
140 | void MainWindowImp::removeClicked(){ | ||
141 | QListViewItem *item = serviceList->currentItem(); | ||
142 | if(item == NULL) NO_SELECT_ERROR_AND_RETURN | ||
143 | |||
144 | if(modules.find(interfaceItems[item]) == modules.end()){ | ||
145 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | ||
146 | } | ||
147 | else{ | ||
148 | // Try to remove. | ||
149 | } | ||
150 | |||
151 | } | ||
152 | |||
153 | /** | ||
154 | * See if there is a configuration for the selected protocal. | ||
155 | * Prompt with errors. | ||
156 | */ | ||
157 | void MainWindowImp::configureClicked(){ | ||
158 | QListViewItem *item = serviceList->currentItem(); | ||
159 | if(item == NULL) NO_SELECT_ERROR_AND_RETURN | ||
160 | |||
161 | if(modules.find(interfaceItems[item]) == modules.end()){ | ||
162 | InterfaceSetupImp *conf = new InterfaceSetupImp(0, "InterfaceConfiguration", interfaceItems[item]); | ||
163 | conf->showMaximized(); | ||
164 | conf->show(); | ||
165 | } | ||
166 | else{ | ||
167 | InterfaceSetupImp *conf = new InterfaceSetupImp(this, "InterfaceConfiguration"); | ||
168 | conf->show(); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * Pull up the information about the selected interface | ||
174 | * Report an error | ||
175 | */ | ||
176 | void MainWindowImp::informationClicked(){ | ||
177 | QListViewItem *item = serviceList->currentItem(); | ||
178 | if(item == NULL)NO_SELECT_ERROR_AND_RETURN | ||
179 | |||
180 | if(modules.find(interfaceItems[item]) == modules.end()){ | ||
181 | InterfaceInformationImp *i = new InterfaceInformationImp(0, "InterfaceInformationImp", interfaceItems[item]); | ||
182 | i->showMaximized(); | ||
183 | i->show(); | ||
184 | } | ||
185 | else{ | ||
186 | QTabWidget *t = new QTabWidget(this, "InterfaceInformationTAB"); | ||
187 | InterfaceInformationImp *i = new InterfaceInformationImp(t, "TCPIPInformation", interfaceItems[item], true); | ||
188 | t->insertTab(i, "TCP/IP"); | ||
189 | t->show(); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Aquire the list of active interfaces from ifconfig | ||
195 | * Call ifconfig and ifconfig -a | ||
196 | */ | ||
197 | void MainWindowImp::getInterfaceList(){ | ||
198 | KShellProcess *processAll = new KShellProcess(); | ||
199 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | ||
200 | connect(processAll, SIGNAL(processExited(KProcess *)), | ||
201 | this, SLOT(jobDone(KProcess *))); | ||
202 | threads.insert(processAll, TEMP_ALL); | ||
203 | processAll->start(KShellProcess::NotifyOnExit); | ||
204 | |||
205 | KShellProcess *process = new KShellProcess(); | ||
206 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | ||
207 | connect(process, SIGNAL(processExited(KProcess *)), | ||
208 | this, SLOT(jobDone(KProcess *))); | ||
209 | threads.insert(process, TEMP_UP); | ||
210 | process->start(KShellProcess::NotifyOnExit); | ||
211 | } | ||
212 | |||
213 | void MainWindowImp::jobDone(KProcess *process){ | ||
214 | QString fileName = threads[process]; | ||
215 | threads.remove(process); | ||
216 | delete process; | ||
217 | |||
218 | QFile file(fileName); | ||
219 | if (!file.open(IO_ReadOnly)){ | ||
220 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | ||
221 | return; | ||
222 | } | ||
223 | |||
224 | QTextStream stream( &file ); | ||
225 | QString line; | ||
226 | while ( !stream.eof() ) { | ||
227 | line = stream.readLine(); | ||
228 | int space = line.find(" "); | ||
229 | if(space > 1){ | ||
230 | // We have found an interface | ||
231 | QString interfaceName = line.mid(0, space); | ||
232 | Interface *i; | ||
233 | // See if we already have it | ||
234 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | ||
235 | if(fileName == TEMP_ALL) | ||
236 | i = new Interface(interfaceName, false); | ||
237 | else | ||
238 | i = new Interface(interfaceName, true); | ||
239 | } | ||
240 | else{ | ||
241 | i = interfaceNames[interfaceName]; | ||
242 | if(fileName != TEMP_ALL) | ||
243 | i->setStatus(true); | ||
244 | } | ||
245 | |||
246 | i->setAttached(true); | ||
247 | i->setInterfaceName(interfaceName); | ||
248 | |||
249 | QString hardName = "Ethernet"; | ||
250 | int hardwareName = line.find("Link encap:"); | ||
251 | int macAddress = line.find("HWaddr"); | ||
252 | if(macAddress == -1) | ||
253 | macAddress = line.length(); | ||
254 | if(hardwareName != -1) | ||
255 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11))); | ||
256 | // We have found an interface | ||
257 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
258 | interfaceNames.insert(i->getInterfaceName(), i); | ||
259 | updateInterface(i); | ||
260 | } | ||
261 | } | ||
262 | file.close(); | ||
263 | QFile::remove(fileName); | ||
264 | } | ||
265 | |||
266 | void MainWindowImp::updateInterface(Interface *i){ | ||
267 | QListViewItem *item = NULL; | ||
268 | |||
269 | // See if we already have it | ||
270 | if(items.find(i) == items.end()){ | ||
271 | item = new QListViewItem(serviceList, "", "", ""); | ||
272 | // See if you can't find a module owner for this interface | ||
273 | //EmployeeMap::Iterator it; | ||
274 | //for( it = map.begin(); it != map.end(); ++it ) | ||
275 | // printf( "%s, %s earns %d\n", it.key().latin1(), it.data().name().latin1(), it.data().salary() ); | ||
276 | |||
277 | items.insert(i, item); | ||
278 | interfaceItems.insert(item, i); | ||
279 | } | ||
280 | else | ||
281 | item = items[i]; | ||
282 | |||
283 | QString statusImage = "down"; | ||
284 | if(i->getStatus()) | ||
285 | statusImage = "up"; | ||
286 | QPixmap status = (Resource::loadPixmap(statusImage)); | ||
287 | item->setPixmap(0, status); | ||
288 | |||
289 | QString typeName = "lan"; | ||
290 | if(i->getHardwareName().contains("Local Loopback")) | ||
291 | typeName = "lo"; | ||
292 | QPixmap type = (Resource::loadPixmap(typeName)); | ||
293 | item->setPixmap(1, type); | ||
294 | |||
295 | item->setText(2, i->getHardwareName()); | ||
296 | |||
297 | } | ||
298 | |||
299 | void MainWindowImp::addProfile(){ | ||
300 | |||
301 | } | ||
302 | |||
303 | void MainWindowImp::removeProfile(){ | ||
304 | |||
305 | } | ||
306 | |||
307 | // mainwindowimp.cpp | ||
308 | |||
diff --git a/noncore/settings/networksettings/mainwindowimp.h b/noncore/settings/networksettings/mainwindowimp.h new file mode 100644 index 0000000..95ec2a1 --- a/dev/null +++ b/noncore/settings/networksettings/mainwindowimp.h | |||
@@ -0,0 +1,53 @@ | |||
1 | #ifndef MAINWINOWIMP_H | ||
2 | #define MAINWINOWIMP_H | ||
3 | |||
4 | #include "mainwindow.h" | ||
5 | #include "module.h" | ||
6 | #include "interface.h" | ||
7 | #include "kprocess.h" | ||
8 | #include <qmap.h> | ||
9 | |||
10 | class QLibrary; | ||
11 | |||
12 | class MainWindowImp : public MainWindow { | ||
13 | Q_OBJECT | ||
14 | |||
15 | public: | ||
16 | MainWindowImp(QWidget *parent=0, const char *name=0); | ||
17 | ~MainWindowImp(); | ||
18 | |||
19 | private slots: | ||
20 | void addClicked(); | ||
21 | void removeClicked(); | ||
22 | void configureClicked(); | ||
23 | void informationClicked(); | ||
24 | |||
25 | void jobDone(KProcess *process); | ||
26 | void getInterfaceList(); | ||
27 | |||
28 | void addProfile(); | ||
29 | void removeProfile(); | ||
30 | |||
31 | void updateInterface(Interface *i); | ||
32 | |||
33 | private: | ||
34 | void loadModules(QString path); | ||
35 | |||
36 | Module* loadPlugin(QString pluginFileName, | ||
37 | QString resolveString = "create_plugin"); | ||
38 | |||
39 | // For our local list of names | ||
40 | QMap<QString, Interface*> interfaceNames; | ||
41 | |||
42 | QMap<Module*, QLibrary*> libraries; | ||
43 | QMap<Interface*, Module*> modules; | ||
44 | QMap<Interface*, QListViewItem*> items; | ||
45 | QMap<QListViewItem*, Interface*> interfaceItems; | ||
46 | |||
47 | QMap<KProcess*, QString> threads; | ||
48 | }; | ||
49 | |||
50 | #endif | ||
51 | |||
52 | // mainwindowimp.h | ||
53 | |||
diff --git a/noncore/settings/networksettings/module.h b/noncore/settings/networksettings/module.h new file mode 100644 index 0000000..f146d8c --- a/dev/null +++ b/noncore/settings/networksettings/module.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef MODULE_H | ||
2 | #define MODULE_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qlist.h> | ||
6 | #include <qmap.h> | ||
7 | #include "interface.h" | ||
8 | |||
9 | class QWidget; | ||
10 | |||
11 | class Module : QObject{ | ||
12 | |||
13 | signals: | ||
14 | void updateInterface(Interface *i); | ||
15 | |||
16 | public: | ||
17 | Module(){}; | ||
18 | |||
19 | virtual bool isOwner(Interface *){ return false; }; | ||
20 | virtual QWidget *configure(){ return NULL; } ; | ||
21 | virtual QWidget *information(){ return NULL; }; | ||
22 | virtual QList<Interface> getInterfaces() = 0; | ||
23 | virtual QMap<QString, QString> possibleNewInterfaces() = 0; | ||
24 | virtual Interface *addNewInterface(QString name) = 0; | ||
25 | virtual bool remove(Interface* i) = 0; | ||
26 | |||
27 | |||
28 | }; | ||
29 | |||
30 | #endif | ||
31 | |||
32 | // module.h | ||
33 | |||
diff --git a/noncore/settings/networksettings/networksetup.pro b/noncore/settings/networksettings/networksetup.pro new file mode 100644 index 0000000..7d9918b --- a/dev/null +++ b/noncore/settings/networksettings/networksetup.pro | |||
@@ -0,0 +1,10 @@ | |||
1 | TEMPLATE= app | ||
2 | CONFIG = qt warn_on debug | ||
3 | #CONFIG = qt warn_on release | ||
4 | HEADERS = mainwindowimp.h addserviceimp.h interface.h interfaceinformationimp.h interfacesetupimp.h interfaces.h defaultmodule.h kprocctrl.h module.h kprocess.h | ||
5 | SOURCES = main.cpp mainwindowimp.cpp addserviceimp.cpp interface.cpp interfaceinformationimp.cpp interfacesetupimp.cpp kprocctrl.cpp kprocess.cpp interfaces.cpp | ||
6 | INCLUDEPATH+= $(QPEDIR)/include | ||
7 | DEPENDPATH+= $(QPEDIR)/include | ||
8 | LIBS += -lqpe | ||
9 | INTERFACES= mainwindow.ui addservice.ui interfaceinformation.ui interfaceadvanced.ui interfacesetup.ui | ||
10 | TARGET = networksetup | ||
diff --git a/noncore/settings/networksettings/systemadvanced.ui b/noncore/settings/networksettings/systemadvanced.ui new file mode 100644 index 0000000..6ea192c --- a/dev/null +++ b/noncore/settings/networksettings/systemadvanced.ui | |||
@@ -0,0 +1,443 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>SystemNetworking</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>SystemNetworking</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>222</width> | ||
15 | <height>289</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>System Networking</string> | ||
21 | </property> | ||
22 | <vbox> | ||
23 | <property stdset="1"> | ||
24 | <name>margin</name> | ||
25 | <number>0</number> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>spacing</name> | ||
29 | <number>6</number> | ||
30 | </property> | ||
31 | <widget> | ||
32 | <class>QTabWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>tabWidget</cstring> | ||
36 | </property> | ||
37 | <property> | ||
38 | <name>layoutMargin</name> | ||
39 | </property> | ||
40 | <widget> | ||
41 | <class>QWidget</class> | ||
42 | <property stdset="1"> | ||
43 | <name>name</name> | ||
44 | <cstring>tab</cstring> | ||
45 | </property> | ||
46 | <attribute> | ||
47 | <name>title</name> | ||
48 | <string>DNS</string> | ||
49 | </attribute> | ||
50 | <grid> | ||
51 | <property stdset="1"> | ||
52 | <name>margin</name> | ||
53 | <number>11</number> | ||
54 | </property> | ||
55 | <property stdset="1"> | ||
56 | <name>spacing</name> | ||
57 | <number>6</number> | ||
58 | </property> | ||
59 | <widget row="0" column="0" > | ||
60 | <class>QLabel</class> | ||
61 | <property stdset="1"> | ||
62 | <name>name</name> | ||
63 | <cstring>TextLabel6</cstring> | ||
64 | </property> | ||
65 | <property stdset="1"> | ||
66 | <name>text</name> | ||
67 | <string>Hostname</string> | ||
68 | </property> | ||
69 | </widget> | ||
70 | <widget row="1" column="0" > | ||
71 | <class>QLabel</class> | ||
72 | <property stdset="1"> | ||
73 | <name>name</name> | ||
74 | <cstring>TextLabel5</cstring> | ||
75 | </property> | ||
76 | <property stdset="1"> | ||
77 | <name>text</name> | ||
78 | <string>DNS</string> | ||
79 | </property> | ||
80 | <property stdset="1"> | ||
81 | <name>alignment</name> | ||
82 | <set>AlignTop|AlignLeft</set> | ||
83 | </property> | ||
84 | <property> | ||
85 | <name>vAlign</name> | ||
86 | </property> | ||
87 | </widget> | ||
88 | <widget row="1" column="1" > | ||
89 | <class>QListBox</class> | ||
90 | <property stdset="1"> | ||
91 | <name>name</name> | ||
92 | <cstring>ListBox5</cstring> | ||
93 | </property> | ||
94 | </widget> | ||
95 | <widget row="0" column="1" > | ||
96 | <class>QLineEdit</class> | ||
97 | <property stdset="1"> | ||
98 | <name>name</name> | ||
99 | <cstring>LineEdit7</cstring> | ||
100 | </property> | ||
101 | </widget> | ||
102 | <widget row="3" column="0" > | ||
103 | <class>QLabel</class> | ||
104 | <property stdset="1"> | ||
105 | <name>name</name> | ||
106 | <cstring>TextLabel7</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>text</name> | ||
110 | <string>Hosts</string> | ||
111 | </property> | ||
112 | </widget> | ||
113 | <widget row="3" column="1" > | ||
114 | <class>QLabel</class> | ||
115 | <property stdset="1"> | ||
116 | <name>name</name> | ||
117 | <cstring>TextLabel9</cstring> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>text</name> | ||
121 | <string>List here....</string> | ||
122 | </property> | ||
123 | </widget> | ||
124 | <widget row="2" column="0" > | ||
125 | <class>QPushButton</class> | ||
126 | <property stdset="1"> | ||
127 | <name>name</name> | ||
128 | <cstring>PushButton15</cstring> | ||
129 | </property> | ||
130 | <property stdset="1"> | ||
131 | <name>text</name> | ||
132 | <string>&Add</string> | ||
133 | </property> | ||
134 | </widget> | ||
135 | <widget row="2" column="1" > | ||
136 | <class>QPushButton</class> | ||
137 | <property stdset="1"> | ||
138 | <name>name</name> | ||
139 | <cstring>PushButton16</cstring> | ||
140 | </property> | ||
141 | <property stdset="1"> | ||
142 | <name>text</name> | ||
143 | <string>&Delete</string> | ||
144 | </property> | ||
145 | </widget> | ||
146 | <spacer row="4" column="1" > | ||
147 | <property> | ||
148 | <name>name</name> | ||
149 | <cstring>Spacer14</cstring> | ||
150 | </property> | ||
151 | <property stdset="1"> | ||
152 | <name>orientation</name> | ||
153 | <enum>Vertical</enum> | ||
154 | </property> | ||
155 | <property stdset="1"> | ||
156 | <name>sizeType</name> | ||
157 | <enum>Expanding</enum> | ||
158 | </property> | ||
159 | <property> | ||
160 | <name>sizeHint</name> | ||
161 | <size> | ||
162 | <width>20</width> | ||
163 | <height>20</height> | ||
164 | </size> | ||
165 | </property> | ||
166 | </spacer> | ||
167 | </grid> | ||
168 | </widget> | ||
169 | <widget> | ||
170 | <class>QWidget</class> | ||
171 | <property stdset="1"> | ||
172 | <name>name</name> | ||
173 | <cstring>tab</cstring> | ||
174 | </property> | ||
175 | <attribute> | ||
176 | <name>title</name> | ||
177 | <string>Routing</string> | ||
178 | </attribute> | ||
179 | <grid> | ||
180 | <property stdset="1"> | ||
181 | <name>margin</name> | ||
182 | <number>11</number> | ||
183 | </property> | ||
184 | <property stdset="1"> | ||
185 | <name>spacing</name> | ||
186 | <number>6</number> | ||
187 | </property> | ||
188 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
189 | <class>QListView</class> | ||
190 | <column> | ||
191 | <property> | ||
192 | <name>text</name> | ||
193 | <string>Destination</string> | ||
194 | </property> | ||
195 | <property> | ||
196 | <name>clickable</name> | ||
197 | <bool>true</bool> | ||
198 | </property> | ||
199 | <property> | ||
200 | <name>resizeable</name> | ||
201 | <bool>true</bool> | ||
202 | </property> | ||
203 | </column> | ||
204 | <column> | ||
205 | <property> | ||
206 | <name>text</name> | ||
207 | <string>Gateway</string> | ||
208 | </property> | ||
209 | <property> | ||
210 | <name>clickable</name> | ||
211 | <bool>true</bool> | ||
212 | </property> | ||
213 | <property> | ||
214 | <name>resizeable</name> | ||
215 | <bool>true</bool> | ||
216 | </property> | ||
217 | </column> | ||
218 | <column> | ||
219 | <property> | ||
220 | <name>text</name> | ||
221 | <string>Genmask</string> | ||
222 | </property> | ||
223 | <property> | ||
224 | <name>clickable</name> | ||
225 | <bool>true</bool> | ||
226 | </property> | ||
227 | <property> | ||
228 | <name>resizeable</name> | ||
229 | <bool>true</bool> | ||
230 | </property> | ||
231 | </column> | ||
232 | <column> | ||
233 | <property> | ||
234 | <name>text</name> | ||
235 | <string>Flags</string> | ||
236 | </property> | ||
237 | <property> | ||
238 | <name>clickable</name> | ||
239 | <bool>true</bool> | ||
240 | </property> | ||
241 | <property> | ||
242 | <name>resizeable</name> | ||
243 | <bool>true</bool> | ||
244 | </property> | ||
245 | </column> | ||
246 | <column> | ||
247 | <property> | ||
248 | <name>text</name> | ||
249 | <string>Metric</string> | ||
250 | </property> | ||
251 | <property> | ||
252 | <name>clickable</name> | ||
253 | <bool>true</bool> | ||
254 | </property> | ||
255 | <property> | ||
256 | <name>resizeable</name> | ||
257 | <bool>true</bool> | ||
258 | </property> | ||
259 | </column> | ||
260 | <column> | ||
261 | <property> | ||
262 | <name>text</name> | ||
263 | <string>Ref</string> | ||
264 | </property> | ||
265 | <property> | ||
266 | <name>clickable</name> | ||
267 | <bool>true</bool> | ||
268 | </property> | ||
269 | <property> | ||
270 | <name>resizeable</name> | ||
271 | <bool>true</bool> | ||
272 | </property> | ||
273 | </column> | ||
274 | <column> | ||
275 | <property> | ||
276 | <name>text</name> | ||
277 | <string>Use</string> | ||
278 | </property> | ||
279 | <property> | ||
280 | <name>clickable</name> | ||
281 | <bool>true</bool> | ||
282 | </property> | ||
283 | <property> | ||
284 | <name>resizeable</name> | ||
285 | <bool>true</bool> | ||
286 | </property> | ||
287 | </column> | ||
288 | <column> | ||
289 | <property> | ||
290 | <name>text</name> | ||
291 | <string>Iface</string> | ||
292 | </property> | ||
293 | <property> | ||
294 | <name>clickable</name> | ||
295 | <bool>true</bool> | ||
296 | </property> | ||
297 | <property> | ||
298 | <name>resizeable</name> | ||
299 | <bool>true</bool> | ||
300 | </property> | ||
301 | </column> | ||
302 | <item> | ||
303 | <property> | ||
304 | <name>text</name> | ||
305 | <string>192.168.1.0</string> | ||
306 | </property> | ||
307 | <property> | ||
308 | <name>text</name> | ||
309 | <string>*</string> | ||
310 | </property> | ||
311 | <property> | ||
312 | <name>text</name> | ||
313 | <string>255.255.255.0</string> | ||
314 | </property> | ||
315 | <property> | ||
316 | <name>text</name> | ||
317 | <string>U</string> | ||
318 | </property> | ||
319 | <property> | ||
320 | <name>text</name> | ||
321 | <string>0</string> | ||
322 | </property> | ||
323 | <property> | ||
324 | <name>text</name> | ||
325 | <string>0</string> | ||
326 | </property> | ||
327 | <property> | ||
328 | <name>text</name> | ||
329 | <string>0</string> | ||
330 | </property> | ||
331 | <property> | ||
332 | <name>text</name> | ||
333 | <string>eth0</string> | ||
334 | </property> | ||
335 | <property> | ||
336 | <name>pixmap</name> | ||
337 | <pixmap></pixmap> | ||
338 | </property> | ||
339 | <property> | ||
340 | <name>pixmap</name> | ||
341 | <pixmap></pixmap> | ||
342 | </property> | ||
343 | <property> | ||
344 | <name>pixmap</name> | ||
345 | <pixmap></pixmap> | ||
346 | </property> | ||
347 | <property> | ||
348 | <name>pixmap</name> | ||
349 | <pixmap></pixmap> | ||
350 | </property> | ||
351 | <property> | ||
352 | <name>pixmap</name> | ||
353 | <pixmap></pixmap> | ||
354 | </property> | ||
355 | <property> | ||
356 | <name>pixmap</name> | ||
357 | <pixmap></pixmap> | ||
358 | </property> | ||
359 | <property> | ||
360 | <name>pixmap</name> | ||
361 | <pixmap></pixmap> | ||
362 | </property> | ||
363 | <property> | ||
364 | <name>pixmap</name> | ||
365 | <pixmap></pixmap> | ||
366 | </property> | ||
367 | </item> | ||
368 | <property stdset="1"> | ||
369 | <name>name</name> | ||
370 | <cstring>ListView4</cstring> | ||
371 | </property> | ||
372 | </widget> | ||
373 | <widget row="1" column="0" > | ||
374 | <class>QPushButton</class> | ||
375 | <property stdset="1"> | ||
376 | <name>name</name> | ||
377 | <cstring>PushButton17</cstring> | ||
378 | </property> | ||
379 | <property stdset="1"> | ||
380 | <name>text</name> | ||
381 | <string>&Add</string> | ||
382 | </property> | ||
383 | </widget> | ||
384 | <widget row="1" column="1" > | ||
385 | <class>QPushButton</class> | ||
386 | <property stdset="1"> | ||
387 | <name>name</name> | ||
388 | <cstring>PushButton18</cstring> | ||
389 | </property> | ||
390 | <property stdset="1"> | ||
391 | <name>text</name> | ||
392 | <string>Remove</string> | ||
393 | </property> | ||
394 | </widget> | ||
395 | <spacer row="2" column="1" > | ||
396 | <property> | ||
397 | <name>name</name> | ||
398 | <cstring>Spacer15</cstring> | ||
399 | </property> | ||
400 | <property stdset="1"> | ||
401 | <name>orientation</name> | ||
402 | <enum>Vertical</enum> | ||
403 | </property> | ||
404 | <property stdset="1"> | ||
405 | <name>sizeType</name> | ||
406 | <enum>Expanding</enum> | ||
407 | </property> | ||
408 | <property> | ||
409 | <name>sizeHint</name> | ||
410 | <size> | ||
411 | <width>20</width> | ||
412 | <height>20</height> | ||
413 | </size> | ||
414 | </property> | ||
415 | </spacer> | ||
416 | </grid> | ||
417 | </widget> | ||
418 | </widget> | ||
419 | </vbox> | ||
420 | </widget> | ||
421 | <customwidgets> | ||
422 | <customwidget> | ||
423 | <class>QWidget</class> | ||
424 | <header location="local">qwidget.h</header> | ||
425 | <sizehint> | ||
426 | <width>100</width> | ||
427 | <height>100</height> | ||
428 | </sizehint> | ||
429 | <container>0</container> | ||
430 | <sizepolicy> | ||
431 | <hordata>7</hordata> | ||
432 | <verdata>7</verdata> | ||
433 | </sizepolicy> | ||
434 | <pixmap>image0</pixmap> | ||
435 | </customwidget> | ||
436 | </customwidgets> | ||
437 | <images> | ||
438 | <image> | ||
439 | <name>image0</name> | ||
440 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
441 | </image> | ||
442 | </images> | ||
443 | </UI> | ||