summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2002-08-31 10:43:26 (UTC)
committer mickeyl <mickeyl>2002-08-31 10:43:26 (UTC)
commitcd33eed8d5eccebdc37dcd0e30d7917b91765222 (patch) (unidiff)
treecec3d088b58501bcc660686f468c4a968dc2d729
parent3b720187b21a3b9b3d17fc2b26489723febdaec2 (diff)
downloadopie-cd33eed8d5eccebdc37dcd0e30d7917b91765222.zip
opie-cd33eed8d5eccebdc37dcd0e30d7917b91765222.tar.gz
opie-cd33eed8d5eccebdc37dcd0e30d7917b91765222.tar.bz2
- debug output is now #ifdef'd
- wireless applet icon shows on demand (like cardmon - applet has an advanced configuration dialog - applet features experimental dhcp renew on change of essid/freq/ap/mode
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/advancedconfig.cpp55
-rw-r--r--noncore/applets/wirelessapplet/advancedconfig.h36
-rw-r--r--noncore/applets/wirelessapplet/advancedconfigbase.ui159
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.cpp30
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.h4
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp149
-rw-r--r--noncore/applets/wirelessapplet/wireless.h18
-rw-r--r--noncore/applets/wirelessapplet/wirelessapplet.pro7
8 files changed, 432 insertions, 26 deletions
diff --git a/noncore/applets/wirelessapplet/advancedconfig.cpp b/noncore/applets/wirelessapplet/advancedconfig.cpp
new file mode 100644
index 0000000..97b008d
--- a/dev/null
+++ b/noncore/applets/wirelessapplet/advancedconfig.cpp
@@ -0,0 +1,55 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer
3** <mickey@tm.informatik.uni-frankfurt.de>
4** http://www.Vanille.de
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#include "advancedconfig.h"
17
18#include <qpe/config.h>
19#include <qwidget.h>
20#include <qcheckbox.h>
21
22AdvancedConfig::AdvancedConfig( QWidget* parent, const char* name, bool modal, WFlags fl )
23 : AdvancedConfigBase( parent, name, modal, fl )
24{
25 Config cfg( "qpe" );
26 cfg.setGroup( "Wireless" );
27
28 bool rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false );
29 bool rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false );
30 bool rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false );
31 bool rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false );
32
33 cbESSID->setChecked( rocESSID );
34 cbFrequency->setChecked( rocFREQ );
35 cbAccessPoint->setChecked( rocAP );
36 cbMODE->setChecked( rocMODE );
37}
38
39AdvancedConfig::~AdvancedConfig()
40{
41}
42
43void AdvancedConfig::accept()
44{
45
46 Config cfg( "qpe" );
47 cfg.setGroup( "Wireless" );
48 cfg.writeEntry( "renew_dhcp_on_essid_change", cbESSID->isChecked() );
49 cfg.writeEntry( "renew_dhcp_on_freq_change", cbFrequency->isChecked() );
50 cfg.writeEntry( "renew_dhcp_on_ap_change", cbAccessPoint->isChecked() );
51 cfg.writeEntry( "renew_dhcp_on_mode_change", cbMODE->isChecked() );
52
53 AdvancedConfigBase::accept();
54}
55
diff --git a/noncore/applets/wirelessapplet/advancedconfig.h b/noncore/applets/wirelessapplet/advancedconfig.h
new file mode 100644
index 0000000..17ba3c5
--- a/dev/null
+++ b/noncore/applets/wirelessapplet/advancedconfig.h
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer
3** <mickey@tm.informatik.uni-frankfurt.de>
4** http://www.Vanille.de
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#ifndef ADVANCED_CONFIG_H
17#define ADVANCED_CONFIG_H
18
19#include "advancedconfigbase.h"
20
21#include <qnamespace.h>
22
23class AdvancedConfig: public AdvancedConfigBase
24{
25 Q_OBJECT
26
27public:
28 AdvancedConfig( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
29 ~AdvancedConfig();
30
31protected:
32 virtual void accept();
33
34};
35
36#endif
diff --git a/noncore/applets/wirelessapplet/advancedconfigbase.ui b/noncore/applets/wirelessapplet/advancedconfigbase.ui
new file mode 100644
index 0000000..c7c4a10
--- a/dev/null
+++ b/noncore/applets/wirelessapplet/advancedconfigbase.ui
@@ -0,0 +1,159 @@
1<!DOCTYPE UI><UI>
2<class>AdvancedConfigBase</class>
3<comment>/**********************************************************************
4** Copyright (C) 2001 Trolltech AS. All rights reserved.
5**
6** This file is part of Qt Palmtop Environment.
7**
8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file.
12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17**
18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you.
20**
21** $Id$
22**
23**********************************************************************/</comment>
24<widget>
25 <class>QDialog</class>
26 <property stdset="1">
27 <name>name</name>
28 <cstring>AdvancedConfigBase</cstring>
29 </property>
30 <property stdset="1">
31 <name>geometry</name>
32 <rect>
33 <x>0</x>
34 <y>0</y>
35 <width>197</width>
36 <height>158</height>
37 </rect>
38 </property>
39 <property stdset="1">
40 <name>sizePolicy</name>
41 <sizepolicy>
42 <hsizetype>1</hsizetype>
43 <vsizetype>1</vsizetype>
44 </sizepolicy>
45 </property>
46 <property stdset="1">
47 <name>caption</name>
48 <string>Advanced Config</string>
49 </property>
50 <property>
51 <name>layoutMargin</name>
52 </property>
53 <property>
54 <name>layoutSpacing</name>
55 </property>
56 <widget>
57 <class>QGroupBox</class>
58 <property stdset="1">
59 <name>name</name>
60 <cstring>fraStart</cstring>
61 </property>
62 <property stdset="1">
63 <name>geometry</name>
64 <rect>
65 <x>11</x>
66 <y>11</y>
67 <width>175</width>
68 <height>136</height>
69 </rect>
70 </property>
71 <property stdset="1">
72 <name>frameShape</name>
73 <enum>Box</enum>
74 </property>
75 <property stdset="1">
76 <name>frameShadow</name>
77 <enum>Sunken</enum>
78 </property>
79 <property stdset="1">
80 <name>title</name>
81 <string>Renew DHCP on changing</string>
82 </property>
83 <widget>
84 <class>QLayoutWidget</class>
85 <property stdset="1">
86 <name>name</name>
87 <cstring>Layout5</cstring>
88 </property>
89 <property stdset="1">
90 <name>geometry</name>
91 <rect>
92 <x>10</x>
93 <y>21</y>
94 <width>98</width>
95 <height>96</height>
96 </rect>
97 </property>
98 <grid>
99 <property stdset="1">
100 <name>margin</name>
101 <number>0</number>
102 </property>
103 <property stdset="1">
104 <name>spacing</name>
105 <number>6</number>
106 </property>
107 <widget row="1" column="0" >
108 <class>QCheckBox</class>
109 <property stdset="1">
110 <name>name</name>
111 <cstring>cbFrequency</cstring>
112 </property>
113 <property stdset="1">
114 <name>text</name>
115 <string>Frequency</string>
116 </property>
117 </widget>
118 <widget row="3" column="0" >
119 <class>QCheckBox</class>
120 <property stdset="1">
121 <name>name</name>
122 <cstring>cbMODE</cstring>
123 </property>
124 <property stdset="1">
125 <name>text</name>
126 <string>MODE</string>
127 </property>
128 </widget>
129 <widget row="0" column="0" >
130 <class>QCheckBox</class>
131 <property stdset="1">
132 <name>name</name>
133 <cstring>cbESSID</cstring>
134 </property>
135 <property stdset="1">
136 <name>text</name>
137 <string>ESSID</string>
138 </property>
139 </widget>
140 <widget row="2" column="0" >
141 <class>QCheckBox</class>
142 <property stdset="1">
143 <name>name</name>
144 <cstring>cbAccessPoint</cstring>
145 </property>
146 <property stdset="1">
147 <name>text</name>
148 <string>AccessPoint</string>
149 </property>
150 </widget>
151 </grid>
152 </widget>
153 </widget>
154</widget>
155<connections>
156 <slot access="protected">itemUp()</slot>
157 <slot access="protected">itemDown()</slot>
158</connections>
159</UI>
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp
index 22d7d83..8531fd5 100644
--- a/noncore/applets/wirelessapplet/networkinfo.cpp
+++ b/noncore/applets/wirelessapplet/networkinfo.cpp
@@ -30,104 +30,109 @@
30#include <linux/wireless.h> 30#include <linux/wireless.h>
31 31
32#include <unistd.h> 32#include <unistd.h>
33#include <math.h> 33#include <math.h>
34#include <errno.h> 34#include <errno.h>
35#include <string.h> 35#include <string.h>
36 36
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39#include <qstring.h> 39#include <qstring.h>
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* estimated wireless signal strength and noise level values 43/* estimated wireless signal strength and noise level values
44 based on experimentation with Orinoco and Prism2 cards. 44 based on experimentation with Orinoco and Prism2 cards.
45 Seem to be correct, but please inform me, if you got values 45 Seem to be correct, but please inform me, if you got values
46 outside these boundaries. :Mickey: */ 46 outside these boundaries. :Mickey: */
47 47
48#define IW_UPPER 220 48#define IW_UPPER 220
49#define IW_LOWER 140 49#define IW_LOWER 140
50 50
51#define PROCNETDEV "/proc/net/dev" 51#define PROCNETDEV "/proc/net/dev"
52#define PROCNETWIRELESS "/proc/net/wireless" 52#define PROCNETWIRELESS "/proc/net/wireless"
53 53
54#define MDEBUG 0
55
54//--------------------------------------------------------------------------- 56//---------------------------------------------------------------------------
55// class MNetworkInterface 57// class MNetworkInterface
56// 58//
57 59
58MNetworkInterface::MNetworkInterface( const char* name ) 60MNetworkInterface::MNetworkInterface( const char* name )
59 :name( name ) 61 :name( name )
60{ 62{
61 struct ifreq ifr; 63 struct ifreq ifr;
62 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; 64 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
63 fd = socket( AF_INET, SOCK_DGRAM, 0 ); 65 fd = socket( AF_INET, SOCK_DGRAM, 0 );
64} 66}
65 67
66MNetworkInterface::~MNetworkInterface() 68MNetworkInterface::~MNetworkInterface()
67{ 69{
68 if ( fd != -1 ) 70 if ( fd != -1 )
69 close( fd ); 71 close( fd );
70} 72}
71 73
72void MNetworkInterface::updateStatistics() 74bool MNetworkInterface::updateStatistics()
73{ 75{
76 return true;
74} 77}
75 78
76//--------------------------------------------------------------------------- 79//---------------------------------------------------------------------------
77// class MWirelessNetworkInterface 80// class MWirelessNetworkInterface
78// 81//
79 82
80MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) 83MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n )
81 :MNetworkInterface( n ) 84 :MNetworkInterface( n )
82{ 85{
83 signal = 0; 86 signal = 0;
84 noise = 0; 87 noise = 0;
85 quality = 0; 88 quality = 0;
86} 89}
87 90
88MWirelessNetworkInterface::~MWirelessNetworkInterface() 91MWirelessNetworkInterface::~MWirelessNetworkInterface()
89{ 92{
90} 93}
91 94
92int MWirelessNetworkInterface::qualityPercent() 95int MWirelessNetworkInterface::qualityPercent()
93{ 96{
94 return ( quality*100 ) / 92; 97 return ( quality*100 ) / 92;
95} 98}
96 99
97int MWirelessNetworkInterface::signalPercent() 100int MWirelessNetworkInterface::signalPercent()
98{ 101{
99 return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; 102 return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER;
100} 103}
101 104
102int MWirelessNetworkInterface::noisePercent() 105int MWirelessNetworkInterface::noisePercent()
103{ 106{
104 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; 107 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
105} 108}
106 109
107void MWirelessNetworkInterface::updateStatistics() 110bool MWirelessNetworkInterface::updateStatistics()
108{ 111{
109 MNetworkInterface::updateStatistics(); 112 bool base = MNetworkInterface::updateStatistics();
113 if ( !base )
114 return false;
110 115
111 const char* buffer[200]; 116 const char* buffer[200];
112 117
113 struct iwreq iwr; 118 struct iwreq iwr;
114 memset( &iwr, 0, sizeof( iwr ) ); 119 memset( &iwr, 0, sizeof( iwr ) );
115 iwr.u.essid.pointer = (caddr_t) buffer; 120 iwr.u.essid.pointer = (caddr_t) buffer;
116 iwr.u.essid.length = IW_ESSID_MAX_SIZE; 121 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
117 iwr.u.essid.flags = 0; 122 iwr.u.essid.flags = 0;
118 123
119 // check if it is an IEEE 802.11 standard conform 124 // check if it is an IEEE 802.11 standard conform
120 // wireless device by sending SIOCGIWESSID 125 // wireless device by sending SIOCGIWESSID
121 // which also gives back the Extended Service Set ID 126 // which also gives back the Extended Service Set ID
122 // (see IEEE 802.11 for more information) 127 // (see IEEE 802.11 for more information)
123 128
124 strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); 129 strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name );
125 int result = ioctl( fd, SIOCGIWESSID, &iwr ); 130 int result = ioctl( fd, SIOCGIWESSID, &iwr );
126 if ( result == 0 ) 131 if ( result == 0 )
127 { 132 {
128 hasWirelessExtensions = true; 133 hasWirelessExtensions = true;
129 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; 134 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
130 essid = iwr.u.essid.pointer; 135 essid = iwr.u.essid.pointer;
131 } 136 }
132 else essid = "*** Unknown ***"; 137 else essid = "*** Unknown ***";
133 138
@@ -160,112 +165,121 @@ void MWirelessNetworkInterface::updateStatistics()
160 if ( result == 0 ) 165 if ( result == 0 )
161 mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; 166 mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed";
162 else mode = "*** Unknown ***"; 167 else mode = "*** Unknown ***";
163 168
164 result = ioctl( fd, SIOCGIWFREQ, &iwr ); 169 result = ioctl( fd, SIOCGIWFREQ, &iwr );
165 if ( result == 0 ) 170 if ( result == 0 )
166 freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; 171 freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000;
167 else freq = 0; 172 else freq = 0;
168 173
169 // gather link quality from /proc/net/wireless 174 // gather link quality from /proc/net/wireless
170 175
171 char c; 176 char c;
172 QString status; 177 QString status;
173 QString name; 178 QString name;
174 QFile wfile( PROCNETWIRELESS ); 179 QFile wfile( PROCNETWIRELESS );
175 bool hasFile = wfile.open( IO_ReadOnly ); 180 bool hasFile = wfile.open( IO_ReadOnly );
176 QTextStream wstream( &wfile ); 181 QTextStream wstream( &wfile );
177 if ( hasFile ) 182 if ( hasFile )
178 { 183 {
179 wstream.readLine(); // skip the first two lines 184 wstream.readLine(); // skip the first two lines
180 wstream.readLine(); // because they only contain headers 185 wstream.readLine(); // because they only contain headers
181 } 186 }
182 if ( ( !hasFile ) || ( wstream.atEnd() ) ) 187 if ( ( !hasFile ) || ( wstream.atEnd() ) )
183 { 188 {
189#ifdef MDEBUG
184 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); 190 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
191#endif
185 quality = -1; 192 quality = -1;
186 signal = IW_LOWER; 193 signal = IW_LOWER;
187 noise = IW_LOWER; 194 noise = IW_LOWER;
188 return; 195 return false;
189 } 196 }
190 197
191 wstream >> name >> status >> quality >> c >> signal >> c >> noise; 198 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
192 199
193 if ( quality > 92 ) 200 if ( quality > 92 )
201#ifdef MDEBUG
194 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); 202 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
203#endif
195 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) 204 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
205#ifdef MDEBUG
196 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); 206 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
207#endif
197 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) 208 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
209#ifdef MDEBUG
198 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); 210 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
211#endif
212
213 return true;
214
199} 215}
200 216
201//--------------------------------------------------------------------------- 217//---------------------------------------------------------------------------
202// class Network 218// class Network
203// 219//
204 220
205MNetwork::MNetwork() 221MNetwork::MNetwork()
206{ 222{
207 //qDebug( "MNetwork::MNetwork()" );
208 procfile = PROCNETDEV; 223 procfile = PROCNETDEV;
209} 224}
210 225
211MNetwork::~MNetwork() 226MNetwork::~MNetwork()
212{ 227{
213 //qDebug( "MNetwork::~MNetwork()" );
214} 228}
215 229
216//--------------------------------------------------------------------------- 230//---------------------------------------------------------------------------
217// class WirelessNetwork 231// class WirelessNetwork
218// 232//
219 233
220MWirelessNetwork::MWirelessNetwork() 234MWirelessNetwork::MWirelessNetwork()
221{ 235{
222 //qDebug( "MWirelessNetwork::MWirelessNetwork()" );
223 procfile = PROCNETWIRELESS; 236 procfile = PROCNETWIRELESS;
224} 237}
225 238
226MWirelessNetwork::~MWirelessNetwork() 239MWirelessNetwork::~MWirelessNetwork()
227{ 240{
228 //qDebug( "MWirelessNetwork::~MWirelessNetwork()" );
229} 241}
230 242
231MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const 243MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const
232{ 244{
233 return new MWirelessNetworkInterface( n ); 245 return new MWirelessNetworkInterface( n );
234} 246}
235 247
236//--------------------------------------------------------------------------- 248//---------------------------------------------------------------------------
237// class NetworkInterface 249// class NetworkInterface
238// 250//
239 251
240MNetworkInterface* MNetwork::getFirstInterface() 252MNetworkInterface* MNetwork::getFirstInterface()
241{ 253{
242 enumerateInterfaces(); 254 enumerateInterfaces();
243 InterfaceMapIterator it( interfaces ); 255 InterfaceMapIterator it( interfaces );
244 return ( it.count() > 0 ) ? it.toFirst() : 0; 256 return ( it.count() > 0 ) ? it.toFirst() : 0;
245} 257}
246 258
247void MNetwork::enumerateInterfaces() 259void MNetwork::enumerateInterfaces()
248{ 260{
249 interfaces.clear(); 261 interfaces.clear();
250 QString str; 262 QString str;
251 QFile f( procfile ); 263 QFile f( procfile );
252 bool hasFile = f.open( IO_ReadOnly ); 264 bool hasFile = f.open( IO_ReadOnly );
253 if ( !hasFile ) 265 if ( !hasFile )
254 return; 266 return;
255 QTextStream s( &f ); 267 QTextStream s( &f );
256 s.readLine(); 268 s.readLine();
257 s.readLine(); 269 s.readLine();
258 while ( !s.atEnd() ) 270 while ( !s.atEnd() )
259 { 271 {
260 s >> str; 272 s >> str;
261 str.truncate( str.find( ':' ) ); 273 str.truncate( str.find( ':' ) );
274#ifdef MDEBUG
262 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); 275 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str );
276#endif
263 interfaces.insert( str, createInterface( str ) ); 277 interfaces.insert( str, createInterface( str ) );
264 s.readLine(); 278 s.readLine();
265 } 279 }
266} 280}
267 281
268MNetworkInterface* MNetwork::createInterface( const char* n ) const 282MNetworkInterface* MNetwork::createInterface( const char* n ) const
269{ 283{
270 return new MNetworkInterface( n ); 284 return new MNetworkInterface( n );
271} 285}
diff --git a/noncore/applets/wirelessapplet/networkinfo.h b/noncore/applets/wirelessapplet/networkinfo.h
index c5eb743..7e50bc4 100644
--- a/noncore/applets/wirelessapplet/networkinfo.h
+++ b/noncore/applets/wirelessapplet/networkinfo.h
@@ -16,82 +16,82 @@
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17** 17**
18**********************************************************************/ 18**********************************************************************/
19 19
20#ifndef NETWORKINFO_H 20#ifndef NETWORKINFO_H
21#define NETWORKINFO_H 21#define NETWORKINFO_H
22 22
23#include <qstring.h> 23#include <qstring.h>
24#include <qdict.h> 24#include <qdict.h>
25 25
26//--------------------------------------------------------------------------- 26//---------------------------------------------------------------------------
27// class MNetworkInterface 27// class MNetworkInterface
28// 28//
29 29
30class MNetworkInterface 30class MNetworkInterface
31{ 31{
32public: 32public:
33 33
34 MNetworkInterface( const char* name = "eth0" ); 34 MNetworkInterface( const char* name = "eth0" );
35 virtual ~MNetworkInterface(); 35 virtual ~MNetworkInterface();
36 36
37 bool isLoopback() { return isLoopbackInterface; }; 37 bool isLoopback() { return isLoopbackInterface; };
38 const QString& getName() { return name; }; 38 const QString& getName() { return name; };
39 39
40 virtual void updateStatistics(); 40 virtual bool updateStatistics();
41 41
42protected: 42protected:
43 43
44 int fd; 44 int fd;
45 const QString name; 45 const QString name;
46 bool isLoopbackInterface; 46 bool isLoopbackInterface;
47 bool isIrda; 47 bool isIrda;
48 bool isTunnel; 48 bool isTunnel;
49}; 49};
50 50
51//--------------------------------------------------------------------------- 51//---------------------------------------------------------------------------
52// class MWirelessNetworkInterface 52// class MWirelessNetworkInterface
53// 53//
54 54
55class MWirelessNetworkInterface : public MNetworkInterface 55class MWirelessNetworkInterface : public MNetworkInterface
56{ 56{
57public: 57public:
58 MWirelessNetworkInterface( const char* name = "wlan0" ); 58 MWirelessNetworkInterface( const char* name = "wlan0" );
59 virtual ~MWirelessNetworkInterface(); 59 virtual ~MWirelessNetworkInterface();
60 60
61 int noisePercent(); 61 int noisePercent();
62 int qualityPercent(); 62 int qualityPercent();
63 int signalPercent(); 63 int signalPercent();
64 64
65 QString APAddr; 65 QString APAddr;
66 QString essid; 66 QString essid;
67 QString mode; 67 QString mode;
68 QString nick; 68 QString nick;
69 QString rate; 69 QString rate;
70 double freq; 70 double freq;
71 int channel; 71 int channel;
72 72
73 virtual void updateStatistics(); 73 virtual bool updateStatistics();
74 74
75private: 75private:
76 int quality; 76 int quality;
77 int signal; 77 int signal;
78 int noise; 78 int noise;
79 79
80 bool hasWirelessExtensions; 80 bool hasWirelessExtensions;
81}; 81};
82 82
83//--------------------------------------------------------------------------- 83//---------------------------------------------------------------------------
84// class MNetwork 84// class MNetwork
85// 85//
86 86
87class MNetwork 87class MNetwork
88{ 88{
89public: 89public:
90 MNetwork(); 90 MNetwork();
91 virtual ~MNetwork(); 91 virtual ~MNetwork();
92 92
93 typedef QDict<MNetworkInterface> InterfaceMap; 93 typedef QDict<MNetworkInterface> InterfaceMap;
94 typedef QDictIterator<MNetworkInterface> InterfaceMapIterator; 94 typedef QDictIterator<MNetworkInterface> InterfaceMapIterator;
95 95
96 bool hasInterfaces() const { return interfaces.isEmpty(); }; 96 bool hasInterfaces() const { return interfaces.isEmpty(); };
97 int numInterfaces() const { return interfaces.count(); }; 97 int numInterfaces() const { return interfaces.count(); };
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index 183aab8..a5aabb0 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -1,309 +1,432 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer 2** Copyright (C) 2002 Michael 'Mickey' Lauer
3** <mickey@tm.informatik.uni-frankfurt.de> 3** <mickey@tm.informatik.uni-frankfurt.de>
4** http://www.Vanille.de 4** http://www.Vanille.de
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "wireless.h" 16#include "wireless.h"
17 17
18#include <qapplication.h> 18#include <qapplication.h>
19#include <qpe/qpeapplication.h> 19#include <qpe/qpeapplication.h>
20#include <qpe/config.h> 20#include <qpe/config.h>
21 21
22#include <qpoint.h> 22#include <qpoint.h>
23#include <qradiobutton.h> 23#include <qradiobutton.h>
24#include <qcheckbox.h> 24#include <qpushbutton.h>
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qslider.h> 27#include <qslider.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qframe.h> 30#include <qframe.h>
31#include <qpixmap.h> 31#include <qpixmap.h>
32#include <qstring.h> 32#include <qstring.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qtextstream.h>
35
36#include <sys/types.h>
37#include <signal.h>
34 38
35#include "networkinfo.h" 39#include "networkinfo.h"
36#include "mgraph.h" 40#include "mgraph.h"
37 41
42#include "advancedconfig.h"
43
38#include "connect0.xpm" 44#include "connect0.xpm"
39#include "connect1.xpm" 45#include "connect1.xpm"
40#include "connect2.xpm" 46#include "connect2.xpm"
41#include "connect3.xpm" 47#include "connect3.xpm"
42#include "connect4.xpm" 48#include "connect4.xpm"
43#include "connect5.xpm" 49#include "connect5.xpm"
44#include "nowireless.xpm" 50#include "nowireless.xpm"
45 51
46#define STYLE_BARS 0 52#define STYLE_BARS 0
47#define STYLE_ANTENNA 1 53#define STYLE_ANTENNA 1
48 54
55#define MDEBUG 0
56
49WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 57WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
50 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 58 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
51{ 59{
52 60
53 readConfig(); 61 readConfig();
54 writeConfigEntry( "UpdateFrequency", updateFrequency ); 62 writeConfigEntry( "UpdateFrequency", updateFrequency );
55 writeConfigEntry( "DisplayStyle", displayStyle ); 63 writeConfigEntry( "DisplayStyle", displayStyle );
56 64
57 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 65 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
58 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); 66 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
59 67
60 /* status label */ 68 /* status label */
61 69
62 statusLabel = new QLabel( this, "statuslabel" ); 70 statusLabel = new QLabel( this, "statuslabel" );
63 QString text( "Wireless Status:<br>" 71 QString text( "Wireless Status:<br>"
64 "*** Unknown ***<br>" 72 "*** Unknown ***<br>"
65 "Card not inserted ?<br>" 73 "Card not inserted ?<br>"
66 "Or Sharp ROM ?<br>" 74 "Or Sharp ROM ?<br>"
67 "CELL: 00:00:00:00:00:00" ); 75 "CELL: 00:00:00:00:00:00" );
68/* QString text( "Station: Unknown<br>" 76/* QString text( "Station: Unknown<br>"
69 "ESSID: Unknown<br>" 77 "ESSID: Unknown<br>"
70 "MODE: Unknown<br>" 78 "MODE: Unknown<br>"
71 "FREQ: Unknown<br>" 79 "FREQ: Unknown<br>"
72 "CELL: AA:BB:CC:DD:EE:FF" ); */ 80 "CELL: AA:BB:CC:DD:EE:FF" ); */
73 statusLabel->setText( text ); 81 statusLabel->setText( text );
74 statusLabel->setFixedSize( statusLabel->sizeHint() ); 82 statusLabel->setFixedSize( statusLabel->sizeHint() );
75 grid->addWidget( statusLabel, 0, 0 ); 83 grid->addWidget( statusLabel, 0, 0 );
76 84
77 /* visualization group box */ 85 /* visualization group box */
78 86
79 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); 87 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this );
80 QRadioButton* r1 = new QRadioButton( "Color Bars", group ); 88 QRadioButton* r1 = new QRadioButton( "Color Bars", group );
81 QRadioButton* r2 = new QRadioButton( "Antenna", group ); 89 QRadioButton* r2 = new QRadioButton( "Antenna", group );
82 r1->setFocusPolicy( QWidget::NoFocus ); 90 r1->setFocusPolicy( QWidget::NoFocus );
83 r2->setFocusPolicy( QWidget::NoFocus ); 91 r2->setFocusPolicy( QWidget::NoFocus );
84 group->setFocusPolicy( QWidget::NoFocus ); 92 group->setFocusPolicy( QWidget::NoFocus );
85 group->setButton( displayStyle ); 93 group->setButton( displayStyle );
86 grid->addWidget( group, 0, 1 ); 94 grid->addWidget( group, 0, 1 );
87 95
88 /* quality graph */ 96 /* quality graph */
89 97
90 mgraph = new MGraph( this ); 98 mgraph = new MGraph( this );
91 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 99 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
92 mgraph->setMin( 0 ); 100 mgraph->setMin( 0 );
93 mgraph->setMax( 92 ); 101 mgraph->setMax( 92 );
94 grid->addWidget( mgraph, 1, 0 ); 102 grid->addWidget( mgraph, 1, 0 );
95 mgraph->setFocusPolicy( QWidget::NoFocus ); 103 mgraph->setFocusPolicy( QWidget::NoFocus );
96 104
97 /* dhcp renew CheckBox */ 105 /* advanced configuration Button */
98 106
99 //FIXME: under construction 107 QPushButton* advanced = new QPushButton( "Advanced...", this );
100 //QCheckBox* dhcpCheckBox = new QCheckBox( "DHCP renew", this ); 108 advanced->setFocusPolicy( QWidget::NoFocus );
101 //dhcpCheckBox->setFocusPolicy( QWidget::NoFocus ); 109 grid->addWidget( advanced, 2, 0, Qt::AlignCenter );
102 //grid->addWidget( dhcpCheckBox, 2, 0, Qt::AlignCenter ); 110 connect( advanced, SIGNAL( clicked() ),
111 this, SLOT( advancedConfigClicked() ) );
103 112
104 /* update Frequency Label */ 113 /* update Frequency Label */
105 114
106 updateLabel = new QLabel( this ); 115 updateLabel = new QLabel( this );
107 text.sprintf( "Update every %d s", updateFrequency ); 116 text.sprintf( "Update every %d s", updateFrequency );
108 updateLabel->setText( text ); 117 updateLabel->setText( text );
109 grid->addWidget( updateLabel, 2, 1 ); 118 grid->addWidget( updateLabel, 2, 1 );
110 119
111 /* update Frequency Slider */ 120 /* update Frequency Slider */
112 121
113 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); 122 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this );
114 updateSlider->setRange( 0, 9 ); 123 updateSlider->setRange( 0, 9 );
115 updateSlider->setValue( updateFrequency ); 124 updateSlider->setValue( updateFrequency );
116 updateSlider->setTickmarks( QSlider::Both ); 125 updateSlider->setTickmarks( QSlider::Both );
117 updateSlider->setTickInterval( 1 ); 126 updateSlider->setTickInterval( 1 );
118 updateSlider->setSteps( 1, 1 ); 127 updateSlider->setSteps( 1, 1 );
119 updateSlider->setFocusPolicy( QWidget::NoFocus ); 128 updateSlider->setFocusPolicy( QWidget::NoFocus );
120 grid->addWidget( updateSlider, 1, 1 ); 129 grid->addWidget( updateSlider, 1, 1 );
121 connect( updateSlider, SIGNAL( valueChanged( int ) ), 130 connect( updateSlider, SIGNAL( valueChanged( int ) ),
122 this, SLOT( updateDelayChange( int ) ) ); 131 this, SLOT( updateDelayChange( int ) ) );
123 132
124 setFixedSize( sizeHint() ); 133 setFixedSize( sizeHint() );
125 setFocusPolicy( QWidget::NoFocus ); 134 setFocusPolicy( QWidget::NoFocus );
126 135
127 applet->displayStyleChange( displayStyle ); 136 applet->displayStyleChange( displayStyle );
128 applet->updateDelayChange( updateFrequency ); 137 applet->updateDelayChange( updateFrequency );
129 138
130 connect( group, SIGNAL( clicked( int ) ), 139 connect( group, SIGNAL( clicked( int ) ),
131 this, SLOT( displayStyleChange( int ) ) ); 140 this, SLOT( displayStyleChange( int ) ) );
141
142 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
143}
144
145void WirelessControl::advancedConfigClicked()
146{
147 AdvancedConfig* a = new AdvancedConfig( this, "dialog", TRUE );
148 int result = a->exec();
149 a->hide();
150 delete a;
151 if ( result == QDialog::Accepted )
152 {
153 readConfig();
154 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
155 }
132} 156}
133 157
134void WirelessControl::updateDelayChange( int delay ) 158void WirelessControl::updateDelayChange( int delay )
135{ 159{
136 QString text; 160 QString text;
137 text.sprintf( "Update every %d s", delay ); 161 text.sprintf( "Update every %d s", delay );
138 updateLabel->setText( text ); 162 updateLabel->setText( text );
139 applet->updateDelayChange( delay ); 163 applet->updateDelayChange( delay );
140 writeConfigEntry( "UpdateFrequency", delay ); 164 writeConfigEntry( "UpdateFrequency", delay );
141} 165}
142 166
143void WirelessControl::displayStyleChange( int style ) 167void WirelessControl::displayStyleChange( int style )
144{ 168{
145 applet->displayStyleChange( style ); 169 applet->displayStyleChange( style );
146 writeConfigEntry( "DisplayStyle", style ); 170 writeConfigEntry( "DisplayStyle", style );
147} 171}
148 172
149void WirelessControl::show ( bool ) 173void WirelessControl::show ( bool )
150{ 174{
151 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); 175 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
152 176
153 int w = sizeHint().width(); 177 int w = sizeHint().width();
154 int x = curPos.x() - ( w / 2 ); 178 int x = curPos.x() - ( w / 2 );
155 179
156 if ( ( x + w ) > QPEApplication::desktop()->width() ) 180 if ( ( x + w ) > QPEApplication::desktop()->width() )
157 x = QPEApplication::desktop ( )-> width ( ) - w; 181 x = QPEApplication::desktop ( )-> width ( ) - w;
158 182
159 move( x, curPos.y () - sizeHint().height () ); 183 move( x, curPos.y () - sizeHint().height () );
160 QFrame::show(); 184 QFrame::show();
161} 185}
162 186
163void WirelessControl::readConfig() 187void WirelessControl::readConfig()
164{ 188{
165 Config cfg( "qpe" ); 189 Config cfg( "qpe" );
166 cfg.setGroup( "Wireless" ); 190 cfg.setGroup( "Wireless" );
167 191
168 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); 192 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 );
169 displayStyle = cfg. readNumEntry( "DisplayStyle", STYLE_ANTENNA ); 193 displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA );
194 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false );
195 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false );
196 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false );
197 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false );
170} 198}
171 199
172void WirelessControl::writeConfigEntry( const char *entry, int val ) 200void WirelessControl::writeConfigEntry( const char *entry, int val )
173{ 201{
174 Config cfg( "qpe" ); 202 Config cfg( "qpe" );
175 cfg.setGroup( "Wireless" ); 203 cfg.setGroup( "Wireless" );
176 cfg.writeEntry( entry, val ); 204 cfg.writeEntry( entry, val );
177} 205}
178 206
179//=========================================================================== 207//===========================================================================
180 208
181WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) 209WirelessApplet::WirelessApplet( QWidget *parent, const char *name )
182 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), 210 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ),
183 timer( 0 ), interface( 0 ) 211 timer( 0 ), interface( 0 ),
212 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false )
184{ 213{
185 setFixedHeight( 18 ); 214 setFixedHeight( 18 );
186 setFixedWidth( 14 ); 215 setFixedWidth( 14 );
187 network = new MWirelessNetwork(); 216 network = new MWirelessNetwork();
188 status = new WirelessControl( this, 0, "wireless status" ); 217 status = new WirelessControl( this, 0, "wireless status" );
189} 218}
190 219
191void WirelessApplet::checkInterface() 220void WirelessApplet::checkInterface()
192{ 221{
193 interface = network->getFirstInterface(); 222 interface = network->getFirstInterface();
194 if ( interface ) 223 if ( interface )
195 { 224 {
225#ifdef MDEBUG
196 qDebug( "WIFIAPPLET: using interface '%s'", (const char*) 226 qDebug( "WIFIAPPLET: using interface '%s'", (const char*)
227#endif
197 interface->getName() ); 228 interface->getName() );
198 } 229 }
199 else 230 else
200 { 231 {
232#ifdef MDEBUG
201 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); 233 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" );
234 hide();
235#endif
202 } 236 }
203} 237}
204 238
239void WirelessApplet::renewDHCP()
240{
241#ifdef MDEBUG
242 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." );
243#endif
244
245 QString pidfile;
246 if ( !interface )
247 return;
248 QString ifacename( interface->getName() );
249 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", (const char* ) ifacename );
250#ifdef MDEBUG
251 qDebug( "WIFIAPPLET: pidfile is '%s'", (const char*) pidfile );
252#endif
253 int pid;
254 QFile pfile( pidfile );
255 bool hasFile = pfile.open( IO_ReadOnly );
256 QTextStream s( &pfile );
257 if ( hasFile )
258 s >> pid;
259#ifdef MDEBUG
260 qDebug( "WIFIAPPLET: sent -14 to pid %d", pid );
261#endif
262 kill( pid, -14 );
263
264}
265
266void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE )
267{
268 rocESSID = ESSID;
269 rocFREQ = FREQ;
270 rocAP = AP;
271 rocMODE = MODE;
272}
273
205void WirelessApplet::updateDelayChange( int delay ) 274void WirelessApplet::updateDelayChange( int delay )
206{ 275{
207 if ( timer ) 276 if ( timer )
208 killTimer( timer ); 277 killTimer( timer );
209 delay *= 1000; 278 delay *= 1000;
210 if ( delay == 0 ) 279 if ( delay == 0 )
211 delay = 50; 280 delay = 50;
212 timer = startTimer( delay ); 281 timer = startTimer( delay );
213} 282}
214 283
215void WirelessApplet::displayStyleChange( int style ) 284void WirelessApplet::displayStyleChange( int style )
216{ 285{
217 visualStyle = style; 286 visualStyle = style;
218 repaint(); 287 repaint();
219} 288}
220 289
221WirelessApplet::~WirelessApplet() 290WirelessApplet::~WirelessApplet()
222{ 291{
223} 292}
224 293
225void WirelessApplet::timerEvent( QTimerEvent* ) 294void WirelessApplet::timerEvent( QTimerEvent* )
226{ 295{
227 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; 296 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface;
228 297
229 if ( iface ) 298 if ( iface )
230 { 299 {
231 iface->updateStatistics(); 300 bool statResult = iface->updateStatistics();
301 if ( !statResult )
302 {
303 interface = 0;
304 mustRepaint();
305 return;
306 } else
232 if ( mustRepaint() ) 307 if ( mustRepaint() )
233 { 308 {
234 //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); 309 //qDebug( "WIFIAPPLET: A value has changed -> repainting." );
235 repaint(); 310 repaint();
236 } 311 }
237 312
238 if ( status->isVisible() ) 313 if ( status->isVisible() )
239 updatePopupWindow(); 314 updatePopupWindow();
240 } else checkInterface(); 315 } else checkInterface();
241} 316}
242 317
243void WirelessApplet::mousePressEvent( QMouseEvent *) 318void WirelessApplet::mousePressEvent( QMouseEvent *)
244{ 319{
245 if ( status->isVisible() ) 320 if ( status->isVisible() )
246 status->hide(); 321 status->hide();
247 else 322 else
248 status->show( true ); 323 status->show( true );
249} 324}
250 325
251bool WirelessApplet::mustRepaint() 326bool WirelessApplet::mustRepaint()
252{ 327{
253 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; 328 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface;
254 329
255 // check if there are enough changes to justify a (flickering) repaint 330 // check if there are enough changes to justify a (flickering) repaint
256 331
257 // has the interface changed? 332 // has the interface changed?
258 333
259 if ( iface != oldiface ) 334 if ( iface != oldiface )
260 { 335 {
261 oldiface = iface; 336 oldiface = iface;
262 return true; 337 if ( iface )
338 {
339#ifdef MDEBUG
340 qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" );
341#endif
342 show();
343 }
344 else
345 {
346#ifdef MDEBUG
347 qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" );
348#endif
349 hide();
350 return true;
351 }
263 } 352 }
264 353
265 const char** pixmap = getQualityPixmap(); 354 const char** pixmap = getQualityPixmap();
266 355
267 if ( pixmap && ( pixmap != oldpixmap ) ) 356 if ( pixmap && ( pixmap != oldpixmap ) )
268 { 357 {
269 oldpixmap = pixmap; 358 oldpixmap = pixmap;
270 return true; 359 return true;
271 } 360 }
272 361
273 int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; 362 int noiseH = iface->noisePercent() * ( height() - 3 ) / 100;
274 int signalH = iface->signalPercent() * ( height() - 3 ) / 100; 363 int signalH = iface->signalPercent() * ( height() - 3 ) / 100;
275 int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; 364 int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100;
276 365
277 if ( ( noiseH != oldnoiseH ) 366 if ( ( noiseH != oldnoiseH )
278 || ( signalH != oldsignalH ) 367 || ( signalH != oldsignalH )
279 || ( qualityH != oldqualityH ) ) 368 || ( qualityH != oldqualityH ) )
280 { 369 {
281 oldnoiseH = noiseH; 370 oldnoiseH = noiseH;
282 oldsignalH = signalH; 371 oldsignalH = signalH;
283 oldqualityH = qualityH; 372 oldqualityH = qualityH;
284 return true; 373 return true;
285 } 374 }
375
376 if ( rocESSID && ( oldESSID != iface->essid ) )
377 {
378#ifdef MDEBUG
379 qDebug( "WIFIAPPLET: ESSID has changed.");
380#endif
381 renewDHCP();
382 }
383 else if ( rocFREQ && ( oldFREQ != iface->freq ) )
384 {
385#ifdef MDEBUG
386 qDebug( "WIFIAPPLET: FREQ has changed.");
387#endif
388 renewDHCP();
389 }
390 else if ( rocAP && ( oldAP != iface->APAddr ) )
391 {
392#ifdef MDEBUG
393 qDebug( "WIFIAPPLET: AP has changed.");
394#endif
395 renewDHCP();
396 }
397 else if ( rocMODE && ( oldMODE != iface->mode ) )
398 {
399#ifdef MDEBUG
400 qDebug( "WIFIAPPLET: MODE has changed.");
401#endif
402 renewDHCP();
403 }
404
405 oldESSID = iface->essid;
406 oldMODE = iface->mode;
407 oldFREQ = iface->freq;
408 oldAP = iface->APAddr;
286 409
287 return false; 410 return false;
288} 411}
289 412
290void WirelessApplet::updatePopupWindow() 413void WirelessApplet::updatePopupWindow()
291{ 414{
292 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; 415 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface;
293 int qualityH = iface->qualityPercent(); 416 int qualityH = iface->qualityPercent();
294 417
295 if ( status->mgraph ) 418 if ( status->mgraph )
296 status->mgraph->addValue( qualityH, false ); 419 status->mgraph->addValue( qualityH, false );
297 420
298 QString freqString; 421 QString freqString;
299 QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; 422 QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: ";
300 freqString.sprintf( "%.3f GHz", iface->freq ); 423 freqString.sprintf( "%.3f GHz", iface->freq );
301 status->statusLabel->setText( "Station: " + iface->nick + "<br>" + 424 status->statusLabel->setText( "Station: " + iface->nick + "<br>" +
302 "ESSID: " + iface->essid + "<br>" + 425 "ESSID: " + iface->essid + "<br>" +
303 "MODE: " + iface->mode + "<br>" + 426 "MODE: " + iface->mode + "<br>" +
304 "FREQ: " + freqString + "<br>" + 427 "FREQ: " + freqString + "<br>" +
305 cell + " " + iface->APAddr ); 428 cell + " " + iface->APAddr );
306} 429}
307 430
308const char** WirelessApplet::getQualityPixmap() 431const char** WirelessApplet::getQualityPixmap()
309{ 432{
@@ -313,49 +436,49 @@ const char** WirelessApplet::getQualityPixmap()
313 int qualityH = iface->qualityPercent(); 436 int qualityH = iface->qualityPercent();
314 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; 437 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm;
315 438
316 if ( visualStyle == STYLE_ANTENNA ) 439 if ( visualStyle == STYLE_ANTENNA )
317 { 440 {
318 if ( qualityH < 1 ) return ( const char** ) connect0_xpm; 441 if ( qualityH < 1 ) return ( const char** ) connect0_xpm;
319 if ( qualityH < 17 ) return ( const char** ) connect1_xpm; 442 if ( qualityH < 17 ) return ( const char** ) connect1_xpm;
320 if ( qualityH < 34 ) return ( const char** ) connect2_xpm; 443 if ( qualityH < 34 ) return ( const char** ) connect2_xpm;
321 if ( qualityH < 50 ) return ( const char** ) connect3_xpm; 444 if ( qualityH < 50 ) return ( const char** ) connect3_xpm;
322 if ( qualityH < 65 ) return ( const char** ) connect4_xpm; 445 if ( qualityH < 65 ) return ( const char** ) connect4_xpm;
323 return ( const char** ) connect5_xpm; 446 return ( const char** ) connect5_xpm;
324 } 447 }
325 448
326 return 0; // please draw your bars 449 return 0; // please draw your bars
327} 450}
328 451
329void WirelessApplet::paintEvent( QPaintEvent* ) 452void WirelessApplet::paintEvent( QPaintEvent* )
330{ 453{
331 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; 454 MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface;
332 455
333 QPainter p(this); 456 QPainter p(this);
334 QColor color; 457 QColor color;
335 458
336 const char** pixmap = getQualityPixmap(); 459 const char** pixmap = getQualityPixmap();
337 460
338 if ( pixmap ) 461 if ( pixmap )
339 p.drawPixmap( 0, 1, pixmap ); 462 p.drawPixmap( 0, 1, pixmap );
340 else 463 else
341 { 464 {
342 465
343 int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; 466 int noiseH = iface->noisePercent() * ( height() - 3 ) / 100;
344 int signalH = iface->signalPercent() * ( height() - 3 ) / 100; 467 int signalH = iface->signalPercent() * ( height() - 3 ) / 100;
345 int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; 468 int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100;
346 469
347 double intensity; 470 double intensity;
348 int pixelHeight; 471 int pixelHeight;
349 int pixelWidth = 2; 472 int pixelWidth = 2;
350 int Hue; 473 int Hue;
351 int barSpace = 3; 474 int barSpace = 3;
352 int leftoffset = 0; 475 int leftoffset = 0;
353 int bottomoffset = 2; 476 int bottomoffset = 2;
354 477
355 // draw noise indicator 478 // draw noise indicator
356 pixelHeight = noiseH; 479 pixelHeight = noiseH;
357 Hue = 50; 480 Hue = 50;
358 for ( int i = 0; i < pixelHeight; ++i ) 481 for ( int i = 0; i < pixelHeight; ++i )
359 { 482 {
360 intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; 483 intensity = 50 + ( (double) i / (double) pixelHeight ) * 205;
361 color.setHsv( Hue, 255, intensity ); 484 color.setHsv( Hue, 255, intensity );
diff --git a/noncore/applets/wirelessapplet/wireless.h b/noncore/applets/wirelessapplet/wireless.h
index 45c519d..51a3fab 100644
--- a/noncore/applets/wirelessapplet/wireless.h
+++ b/noncore/applets/wirelessapplet/wireless.h
@@ -24,72 +24,90 @@ class MWirelessNetwork;
24class MNetworkInterface; 24class MNetworkInterface;
25class MWirelessNetworkInterface; 25class MWirelessNetworkInterface;
26class Y; 26class Y;
27class QLabel; 27class QLabel;
28class WirelessApplet; 28class WirelessApplet;
29class MGraph; 29class MGraph;
30 30
31class WirelessControl : public QFrame 31class WirelessControl : public QFrame
32{ 32{
33 Q_OBJECT 33 Q_OBJECT
34public: 34public:
35 WirelessControl( WirelessApplet* icon, QWidget *parent=0, const char *name=0 ); 35 WirelessControl( WirelessApplet* icon, QWidget *parent=0, const char *name=0 );
36 void show( bool ); 36 void show( bool );
37 37
38 void readConfig(); 38 void readConfig();
39 void writeConfigEntry( const char* entry, int val ); 39 void writeConfigEntry( const char* entry, int val );
40 40
41 MGraph* mgraph; 41 MGraph* mgraph;
42 QLabel* statusLabel; 42 QLabel* statusLabel;
43 QLabel* updateLabel; 43 QLabel* updateLabel;
44 44
45public slots: 45public slots:
46 void updateDelayChange( int ); 46 void updateDelayChange( int );
47 void displayStyleChange( int ); 47 void displayStyleChange( int );
48 void advancedConfigClicked();
48 49
49private: 50private:
50 WirelessApplet* applet; 51 WirelessApplet* applet;
51 52
52 int displayStyle; 53 int displayStyle;
53 int updateFrequency; 54 int updateFrequency;
54 55
56 bool rocESSID;
57 bool rocFREQ;
58 bool rocAP;
59 bool rocMODE;
55}; 60};
56 61
57class WirelessApplet : public QWidget 62class WirelessApplet : public QWidget
58{ 63{
59 Q_OBJECT 64 Q_OBJECT
60public: 65public:
61 WirelessApplet( QWidget *parent = 0, const char *name=0 ); 66 WirelessApplet( QWidget *parent = 0, const char *name=0 );
62 ~WirelessApplet(); 67 ~WirelessApplet();
63 WirelessControl* status; 68 WirelessControl* status;
64 69
65 virtual void timerEvent( QTimerEvent* ); 70 virtual void timerEvent( QTimerEvent* );
66 void updateDelayChange( int delay ); 71 void updateDelayChange( int delay );
67 void displayStyleChange( int style ); 72 void displayStyleChange( int style );
73
74 void updateDHCPConfig( bool, bool, bool, bool );
68 75
69private: 76private:
70 void mousePressEvent( QMouseEvent * ); 77 void mousePressEvent( QMouseEvent * );
71 void paintEvent( QPaintEvent* ); 78 void paintEvent( QPaintEvent* );
72 void checkInterface(); 79 void checkInterface();
80 void renewDHCP();
73 81
74 bool mustRepaint(); 82 bool mustRepaint();
75 void updatePopupWindow(); 83 void updatePopupWindow();
76 const char** getQualityPixmap(); 84 const char** getQualityPixmap();
77 85
78private: 86private:
79 QPixmap snapshotPixmap; 87 QPixmap snapshotPixmap;
80 int visualStyle; 88 int visualStyle;
81 int timer; 89 int timer;
82 90
83 MWirelessNetwork* network; 91 MWirelessNetwork* network;
84 MNetworkInterface* interface; 92 MNetworkInterface* interface;
85 93
86private: 94private:
87 const char** oldpixmap; 95 const char** oldpixmap;
88 MWirelessNetworkInterface* oldiface; 96 MWirelessNetworkInterface* oldiface;
89 int oldqualityH; 97 int oldqualityH;
90 int oldsignalH; 98 int oldsignalH;
91 int oldnoiseH; 99 int oldnoiseH;
100
101 QString oldESSID;
102 QString oldAP;
103 QString oldMODE;
104 double oldFREQ;
105
106 bool rocESSID;
107 bool rocFREQ;
108 bool rocAP;
109 bool rocMODE;
92}; 110};
93 111
94#endif // __WIRELESS_APPLET_H__ 112#endif // __WIRELESS_APPLET_H__
95 113
diff --git a/noncore/applets/wirelessapplet/wirelessapplet.pro b/noncore/applets/wirelessapplet/wirelessapplet.pro
index b758d4f..390b271 100644
--- a/noncore/applets/wirelessapplet/wirelessapplet.pro
+++ b/noncore/applets/wirelessapplet/wirelessapplet.pro
@@ -1,25 +1,26 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3HEADERS = wireless.h wirelessappletimpl.h networkinfo.h mgraph.h 3HEADERS = wireless.h wirelessappletimpl.h networkinfo.h mgraph.h advancedconfig.h
4SOURCES = wireless.cpp wirelessappletimpl.cpp networkinfo.cpp mgraph.cpp 4SOURCES = wireless.cpp wirelessappletimpl.cpp networkinfo.cpp mgraph.cpp advancedconfig.cpp
5INTERFACES = advancedconfigbase.ui
5TARGET = wirelessapplet 6TARGET = wirelessapplet
6DESTDIR = $(OPIEDIR)/plugins/applets 7DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include 8INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += ../$(OPIEDIR)/include 9DEPENDPATH += ../$(OPIEDIR)/include
9LIBS += -lqpe 10LIBS += -lqpe
10VERSION = 0.0.3 11VERSION = 0.1.0
11 12
12TRANSLATIONS = ../../../i18n/de/libwirelessapplet.ts \ 13TRANSLATIONS = ../../../i18n/de/libwirelessapplet.ts \
13 ../../../i18n/en/libwirelessapplet.ts \ 14 ../../../i18n/en/libwirelessapplet.ts \
14 ../../../i18n/es/libwirelessapplet.ts \ 15 ../../../i18n/es/libwirelessapplet.ts \
15 ../../../i18n/fr/libwirelessapplet.ts \ 16 ../../../i18n/fr/libwirelessapplet.ts \
16 ../../../i18n/hu/libwirelessapplet.ts \ 17 ../../../i18n/hu/libwirelessapplet.ts \
17 ../../../i18n/ja/libwirelessapplet.ts \ 18 ../../../i18n/ja/libwirelessapplet.ts \
18 ../../../i18n/ko/libwirelessapplet.ts \ 19 ../../../i18n/ko/libwirelessapplet.ts \
19 ../../../i18n/no/libwirelessapplet.ts \ 20 ../../../i18n/no/libwirelessapplet.ts \
20 ../../../i18n/pl/libwirelessapplet.ts \ 21 ../../../i18n/pl/libwirelessapplet.ts \
21 ../../../i18n/pt/libwirelessapplet.ts \ 22 ../../../i18n/pt/libwirelessapplet.ts \
22 ../../../i18n/pt_BR/libwirelessapplet.ts \ 23 ../../../i18n/pt_BR/libwirelessapplet.ts \
23 ../../../i18n/sl/libwirelessapplet.ts \ 24 ../../../i18n/sl/libwirelessapplet.ts \
24 ../../../i18n/zh_CN/libwirelessapplet.ts \ 25 ../../../i18n/zh_CN/libwirelessapplet.ts \
25 ../../../i18n/zh_TW/libwirelessapplet.ts 26 ../../../i18n/zh_TW/libwirelessapplet.ts