summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-02-23 18:38:28 (UTC)
committer mickeyl <mickeyl>2004-02-23 18:38:28 (UTC)
commitd66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b (patch) (unidiff)
tree224c86eb4ab72154365ae450ce517c559b363bf0
parent19b274033fc05d5190cee2fa974c683892173c84 (diff)
downloadopie-d66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b.zip
opie-d66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b.tar.gz
opie-d66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b.tar.bz2
The wireless applet uses now libopie2net instead of its own routines.
Display mode "ANTENNA" is fixed, "BAR GRAPH" is still broken but will be removed anyway, since nearly everyone used "ANTENNA".
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.cpp284
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.h126
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp59
-rw-r--r--noncore/applets/wirelessapplet/wirelessapplet.pro4
4 files changed, 28 insertions, 445 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp
deleted file mode 100644
index e0c487b..0000000
--- a/noncore/applets/wirelessapplet/networkinfo.cpp
+++ b/dev/null
@@ -1,284 +0,0 @@
1/**********************************************************************
2** MNetwork* classes
3**
4** Encapsulate network information
5**
6** Copyright (C) 2002, Michael Lauer
7** mickey@tm.informatik.uni-frankfurt.de
8** http://www.Vanille.de
9**
10** Based on portions of the Wireless Extensions
11** Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com>
12**
13** This file may be distributed and/or modified under the terms of the
14** GNU General Public License version 2 as published by the Free Software
15** Foundation and appearing in the file LICENSE.GPL included in the
16** packaging of this file.
17**
18** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20**
21**********************************************************************/
22
23#include "networkinfo.h"
24
25#include <arpa/inet.h>
26#include <sys/socket.h>
27#include <linux/if_ether.h>
28#include <netinet/ip.h>
29#include <sys/ioctl.h>
30#include <linux/wireless.h>
31
32#include <unistd.h>
33#include <math.h>
34#include <errno.h>
35#include <string.h>
36
37#include <stdlib.h>
38
39#include <qstring.h>
40#include <qfile.h>
41#include <qtextstream.h>
42
43/* estimated wireless signal strength and noise level values
44 based on experimentation with Orinoco and Prism2 cards.
45 Seem to be correct, but please inform me, if you got values
46 outside these boundaries. :Mickey: */
47
48#define IW_UPPER 220
49#define IW_LOWER 140
50
51#define PROCNETDEV "/proc/net/dev"
52#define PROCNETWIRELESS "/proc/net/wireless"
53
54//#define MDEBUG 0
55#undef MDEBUG
56
57//---------------------------------------------------------------------------
58// class MNetworkInterface
59//
60
61MNetworkInterface::MNetworkInterface( const char* name )
62 :name( name )
63{
64 struct ifreq ifr;
65 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
66 fd = socket( AF_INET, SOCK_DGRAM, 0 );
67}
68
69MNetworkInterface::~MNetworkInterface()
70{
71 if ( fd != -1 )
72 close( fd );
73}
74
75bool MNetworkInterface::updateStatistics()
76{
77 return true;
78}
79
80//---------------------------------------------------------------------------
81// class MWirelessNetworkInterface
82//
83
84MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n )
85 :MNetworkInterface( n )
86{
87 signal = 0;
88 noise = 0;
89 quality = 0;
90}
91
92MWirelessNetworkInterface::~MWirelessNetworkInterface()
93{
94}
95
96int MWirelessNetworkInterface::qualityPercent()
97{
98 return ( quality*100 ) / 92;
99}
100
101int MWirelessNetworkInterface::signalPercent()
102{
103 return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER;
104}
105
106int MWirelessNetworkInterface::noisePercent()
107{
108 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
109}
110
111bool MWirelessNetworkInterface::updateStatistics()
112{
113 bool base = MNetworkInterface::updateStatistics();
114 if ( !base )
115 return false;
116
117 const char* buffer[200];
118
119 struct iwreq iwr;
120 memset( &iwr, 0, sizeof( iwr ) );
121 iwr.u.essid.pointer = (caddr_t) buffer;
122 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
123 iwr.u.essid.flags = 0;
124
125 // check if it is an IEEE 802.11 standard conform
126 // wireless device by sending SIOCGIWESSID
127 // which also gives back the Extended Service Set ID
128 // (see IEEE 802.11 for more information)
129
130 strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name );
131 int result = ioctl( fd, SIOCGIWESSID, &iwr );
132 if ( result == 0 )
133 {
134 hasWirelessExtensions = true;
135 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
136 essid = iwr.u.essid.pointer;
137 }
138 else essid = "*** Unknown ***";
139
140 // Address of associated access-point
141
142 result = ioctl( fd, SIOCGIWAP, &iwr );
143 if ( result == 0 )
144 {
145 APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
146 iwr.u.ap_addr.sa_data[0]&0xff,
147 iwr.u.ap_addr.sa_data[1]&0xff,
148 iwr.u.ap_addr.sa_data[2]&0xff,
149 iwr.u.ap_addr.sa_data[3]&0xff,
150 iwr.u.ap_addr.sa_data[4]&0xff,
151 iwr.u.ap_addr.sa_data[5]&0xff );
152 } else APAddr = "*** Unknown ***";
153
154 iwr.u.data.pointer = (caddr_t) buffer;
155 iwr.u.data.length = IW_ESSID_MAX_SIZE;
156 iwr.u.data.flags = 0;
157
158 result = ioctl( fd, SIOCGIWNICKN, &iwr );
159 if ( result == 0 )
160 {
161 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
162 nick = iwr.u.data.pointer;
163 } else nick = "*** Unknown ***";
164
165 result = ioctl( fd, SIOCGIWMODE, &iwr );
166 if ( result == 0 )
167 mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed";
168 else mode = "*** Unknown ***";
169
170 result = ioctl( fd, SIOCGIWFREQ, &iwr );
171 if ( result == 0 )
172 freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000;
173 else freq = 0;
174
175 // gather link quality from /proc/net/wireless
176
177 char c;
178 QString status;
179 QString name;
180 QFile wfile( PROCNETWIRELESS );
181 bool hasFile = wfile.open( IO_ReadOnly );
182 QTextStream wstream( &wfile );
183 if ( hasFile )
184 {
185 wstream.readLine(); // skip the first two lines
186 wstream.readLine(); // because they only contain headers
187 }
188 if ( ( !hasFile ) || ( wstream.atEnd() ) )
189 {
190#ifdef MDEBUG
191 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
192#endif
193 quality = -1;
194 signal = IW_LOWER;
195 noise = IW_LOWER;
196 return false;
197 }
198
199 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
200
201#ifdef MDEBUG
202 if ( quality > 92 )
203 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
204
205 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
206 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
207
208 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
209 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
210#endif
211
212 return true;
213
214}
215
216//---------------------------------------------------------------------------
217// class Network
218//
219
220MNetwork::MNetwork()
221{
222 procfile = PROCNETDEV;
223}
224
225MNetwork::~MNetwork()
226{
227}
228
229//---------------------------------------------------------------------------
230// class WirelessNetwork
231//
232
233MWirelessNetwork::MWirelessNetwork()
234{
235 procfile = PROCNETWIRELESS;
236}
237
238MWirelessNetwork::~MWirelessNetwork()
239{
240}
241
242MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const
243{
244 return new MWirelessNetworkInterface( n );
245}
246
247//---------------------------------------------------------------------------
248// class NetworkInterface
249//
250
251MNetworkInterface* MNetwork::getFirstInterface()
252{
253 enumerateInterfaces();
254 InterfaceMapIterator it( interfaces );
255 return ( it.count() > 0 ) ? it.toFirst() : 0;
256}
257
258void MNetwork::enumerateInterfaces()
259{
260 interfaces.clear();
261 QString str;
262 QFile f( procfile );
263 bool hasFile = f.open( IO_ReadOnly );
264 if ( !hasFile )
265 return;
266 QTextStream s( &f );
267 s.readLine();
268 s.readLine();
269 while ( !s.atEnd() )
270 {
271 s >> str;
272 str.truncate( str.find( ':' ) );
273#ifdef MDEBUG
274 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str );
275#endif
276 interfaces.insert( str, createInterface( str ) );
277 s.readLine();
278 }
279}
280
281MNetworkInterface* MNetwork::createInterface( const char* n ) const
282{
283 return new MNetworkInterface( n );
284}
diff --git a/noncore/applets/wirelessapplet/networkinfo.h b/noncore/applets/wirelessapplet/networkinfo.h
deleted file mode 100644
index 7e50bc4..0000000
--- a/noncore/applets/wirelessapplet/networkinfo.h
+++ b/dev/null
@@ -1,126 +0,0 @@
1/**********************************************************************
2** MNetwork* classes
3**
4** Encapsulates network information
5**
6** Copyright (C) 2002, Michael Lauer
7** mickey@tm.informatik.uni-frankfurt.de
8** http://www.Vanille.de
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#ifndef NETWORKINFO_H
21#define NETWORKINFO_H
22
23#include <qstring.h>
24#include <qdict.h>
25
26//---------------------------------------------------------------------------
27// class MNetworkInterface
28//
29
30class MNetworkInterface
31{
32public:
33
34 MNetworkInterface( const char* name = "eth0" );
35 virtual ~MNetworkInterface();
36
37 bool isLoopback() { return isLoopbackInterface; };
38 const QString& getName() { return name; };
39
40 virtual bool updateStatistics();
41
42protected:
43
44 int fd;
45 const QString name;
46 bool isLoopbackInterface;
47 bool isIrda;
48 bool isTunnel;
49};
50
51//---------------------------------------------------------------------------
52// class MWirelessNetworkInterface
53//
54
55class MWirelessNetworkInterface : public MNetworkInterface
56{
57public:
58 MWirelessNetworkInterface( const char* name = "wlan0" );
59 virtual ~MWirelessNetworkInterface();
60
61 int noisePercent();
62 int qualityPercent();
63 int signalPercent();
64
65 QString APAddr;
66 QString essid;
67 QString mode;
68 QString nick;
69 QString rate;
70 double freq;
71 int channel;
72
73 virtual bool updateStatistics();
74
75private:
76 int quality;
77 int signal;
78 int noise;
79
80 bool hasWirelessExtensions;
81};
82
83//---------------------------------------------------------------------------
84// class MNetwork
85//
86
87class MNetwork
88{
89public:
90 MNetwork();
91 virtual ~MNetwork();
92
93 typedef QDict<MNetworkInterface> InterfaceMap;
94 typedef QDictIterator<MNetworkInterface> InterfaceMapIterator;
95
96 bool hasInterfaces() const { return interfaces.isEmpty(); };
97 int numInterfaces() const { return interfaces.count(); };
98
99 MNetworkInterface* getFirstInterface();
100
101protected:
102 QString procfile;
103 InterfaceMap interfaces;
104
105 virtual MNetworkInterface* createInterface( const char* name ) const;
106
107private:
108 void enumerateInterfaces();
109};
110
111//---------------------------------------------------------------------------
112// class MWirelessNetwork
113//
114
115class MWirelessNetwork : public MNetwork
116{
117public:
118 MWirelessNetwork();
119 virtual ~MWirelessNetwork();
120
121protected:
122 virtual MNetworkInterface* createInterface( const char* name )
123 const;
124};
125
126#endif
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index dc9742a..72ac380 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -1,103 +1,102 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer <mickey@vanille.de> 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer <mickey@vanille.de>
3** 3**
4** This file may be distributed and/or modified under the terms of the 4** This file may be distributed and/or modified under the terms of the
5** GNU General Public License version 2 as published by the Free Software 5** GNU General Public License version 2 as published by the Free Software
6** Foundation and appearing in the file LICENSE.GPL included in the 6** Foundation and appearing in the file LICENSE.GPL included in the
7** packaging of this file. 7** packaging of this file.
8** 8**
9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11** 11**
12**********************************************************************/ 12**********************************************************************/
13 13
14#include "wireless.h" 14#include "wireless.h"
15#include "networkinfo.h"
16#include "mgraph.h" 15#include "mgraph.h"
17#include "advancedconfig.h" 16#include "advancedconfig.h"
18#include "connect0.xpm" 17#include "connect0.xpm"
19#include "connect1.xpm" 18#include "connect1.xpm"
20#include "connect2.xpm" 19#include "connect2.xpm"
21#include "connect3.xpm" 20#include "connect3.xpm"
22#include "connect4.xpm" 21#include "connect4.xpm"
23#include "connect5.xpm" 22#include "connect5.xpm"
24#include "nowireless.xpm" 23#include "nowireless.xpm"
25 24
26/* OPIE */ 25/* OPIE */
27#include <opie2/onetwork.h> 26#include <opie2/onetwork.h>
28#include <opie2/otaskbarapplet.h> 27#include <opie2/otaskbarapplet.h>
29#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
30#include <qpe/config.h> 29#include <qpe/config.h>
31 30
32/* QT */ 31/* QT */
33#include <qpoint.h> 32#include <qpoint.h>
34#include <qradiobutton.h> 33#include <qradiobutton.h>
35#include <qpushbutton.h> 34#include <qpushbutton.h>
36#include <qpainter.h> 35#include <qpainter.h>
37#include <qlabel.h> 36#include <qlabel.h>
38#include <qslider.h> 37#include <qslider.h>
39#include <qbuttongroup.h> 38#include <qbuttongroup.h>
40#include <qlayout.h> 39#include <qlayout.h>
41#include <qframe.h> 40#include <qframe.h>
42#include <qpixmap.h> 41#include <qpixmap.h>
43#include <qstring.h> 42#include <qstring.h>
44#include <qfile.h> 43#include <qfile.h>
45#include <qtextstream.h> 44#include <qtextstream.h>
46 45
47/* STD */ 46/* STD */
48#include <sys/types.h> 47#include <sys/types.h>
49#include <signal.h> 48#include <signal.h>
50 49
51#define STYLE_BARS 0 50#define STYLE_BARS 0
52#define STYLE_ANTENNA 1 51#define STYLE_ANTENNA 1
53 52
54//#define MDEBUG 53#define MDEBUG
55#undef MDEBUG 54//#undef MDEBUG
56 55
57WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 56WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
58 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 57 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
59{ 58{
60 59
61 readConfig(); 60 readConfig();
62 writeConfigEntry( "UpdateFrequency", updateFrequency ); 61 writeConfigEntry( "UpdateFrequency", updateFrequency );
63 writeConfigEntry( "DisplayStyle", displayStyle ); 62 writeConfigEntry( "DisplayStyle", displayStyle );
64 63
65 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 64 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
66 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); 65 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
67 66
68 /* status label */ 67 /* status label */
69 68
70 statusLabel = new QLabel( this, "statuslabel" ); 69 statusLabel = new QLabel( this, "statuslabel" );
71 QString text( "Wireless Status:<br>" 70 QString text( "Wireless Status:<br>"
72 "*** Unknown ***<br>" 71 "*** Unknown ***<br>"
73 "Card not inserted ?<br>" 72 "Card not inserted ?<br>"
74 "Or Sharp ROM ?<br>" 73 "Or Sharp ROM ?<br>"
75 "CELL: 00:00:00:00:00:00" ); 74 "CELL: 00:00:00:00:00:00" );
76 /* QString text( "Station: Unknown<br>" 75 /* QString text( "Station: Unknown<br>"
77 "ESSID: Unknown<br>" 76 "ESSID: Unknown<br>"
78 "MODE: Unknown<br>" 77 "MODE: Unknown<br>"
79 "FREQ: Unknown<br>" 78 "FREQ: Unknown<br>"
80 "CELL: AA:BB:CC:DD:EE:FF" ); */ 79 "CELL: AA:BB:CC:DD:EE:FF" ); */
81 statusLabel->setText( text ); 80 statusLabel->setText( text );
82 statusLabel->setFixedSize( statusLabel->sizeHint() ); 81 statusLabel->setFixedSize( statusLabel->sizeHint() );
83 grid->addWidget( statusLabel, 0, 0 ); 82 grid->addWidget( statusLabel, 0, 0 );
84 83
85 /* visualization group box */ 84 /* visualization group box */
86 85
87 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); 86 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this );
88 QRadioButton* r1 = new QRadioButton( "Color Bars", group ); 87 QRadioButton* r1 = new QRadioButton( "Color Bars", group );
89 QRadioButton* r2 = new QRadioButton( "Antenna", group ); 88 QRadioButton* r2 = new QRadioButton( "Antenna", group );
90 r1->setFocusPolicy( QWidget::NoFocus ); 89 r1->setFocusPolicy( QWidget::NoFocus );
91 r2->setFocusPolicy( QWidget::NoFocus ); 90 r2->setFocusPolicy( QWidget::NoFocus );
92 group->setFocusPolicy( QWidget::NoFocus ); 91 group->setFocusPolicy( QWidget::NoFocus );
93 group->setButton( displayStyle ); 92 group->setButton( displayStyle );
94 grid->addWidget( group, 0, 1 ); 93 grid->addWidget( group, 0, 1 );
95 94
96 /* quality graph */ 95 /* quality graph */
97 96
98 mgraph = new MGraph( this ); 97 mgraph = new MGraph( this );
99 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 98 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
100 mgraph->setMin( 0 ); 99 mgraph->setMin( 0 );
101 mgraph->setMax( 92 ); 100 mgraph->setMax( 92 );
102 grid->addWidget( mgraph, 1, 0 ); 101 grid->addWidget( mgraph, 1, 0 );
103 mgraph->setFocusPolicy( QWidget::NoFocus ); 102 mgraph->setFocusPolicy( QWidget::NoFocus );
@@ -280,122 +279,116 @@ void WirelessApplet::renewDHCP()
280#endif 279#endif
281 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename ); 280 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename );
282#ifdef MDEBUG 281#ifdef MDEBUG
283 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile ); 282 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile );
284#endif 283#endif
285 QFile pfile2( pidfile ); 284 QFile pfile2( pidfile );
286 hasFile = pfile2.open( IO_ReadOnly ); 285 hasFile = pfile2.open( IO_ReadOnly );
287 QTextStream s2( &pfile2 ); 286 QTextStream s2( &pfile2 );
288 if ( hasFile ) 287 if ( hasFile )
289 { 288 {
290 s2 >> pid; 289 s2 >> pid;
291#ifdef MDEBUG 290#ifdef MDEBUG
292 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); 291 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid );
293#endif 292#endif
294 kill( pid, SIGUSR1 ); 293 kill( pid, SIGUSR1 );
295 return ; 294 return ;
296 } 295 }
297} 296}
298 297
299void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) 298void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE )
300{ 299{
301 rocESSID = ESSID; 300 rocESSID = ESSID;
302 rocFREQ = FREQ; 301 rocFREQ = FREQ;
303 rocAP = AP; 302 rocAP = AP;
304 rocMODE = MODE; 303 rocMODE = MODE;
305} 304}
306 305
307void WirelessApplet::updateDelayChange( int delay ) 306void WirelessApplet::updateDelayChange( int delay )
308{ 307{
309 if ( timer ) 308 if ( timer )
310 killTimer( timer ); 309 killTimer( timer );
311 delay *= 1000; 310 delay *= 1000;
312 if ( delay == 0 ) 311 if ( delay == 0 )
313 delay = 50; 312 delay = 50;
314 timer = startTimer( delay ); 313 timer = startTimer( delay );
315} 314}
316 315
317void WirelessApplet::displayStyleChange( int style ) 316void WirelessApplet::displayStyleChange( int style )
318{ 317{
319 visualStyle = style; 318 visualStyle = style;
320 repaint(); 319 repaint();
321} 320}
322 321
323WirelessApplet::~WirelessApplet() 322WirelessApplet::~WirelessApplet()
324{} 323{}
325 324
326void WirelessApplet::timerEvent( QTimerEvent* ) 325void WirelessApplet::timerEvent( QTimerEvent* )
327{ 326{
328 /* 327 qDebug( "WirelessApplet::timerEvent" );
329
330 OWirelessNetworkInterface* iface = interface; 328 OWirelessNetworkInterface* iface = interface;
331 329
332 if ( iface ) 330 if ( iface )
333 { 331 {
334 bool statResult = iface->updateStatistics(); 332 if ( mustRepaint() )
335 if ( !statResult )
336 { 333 {
337 interface = 0; 334 qDebug( "WIFIAPPLET: A value has changed -> repainting." );
338 mustRepaint(); 335 repaint();
339 return ;
340 } 336 }
341 else
342 if ( mustRepaint() )
343 {
344 //qDebug( "WIFIAPPLET: A value has changed -> repainting." );
345 repaint();
346 }
347 337
348 if ( status->isVisible() ) 338 if ( status->isVisible() )
339 {
349 updatePopupWindow(); 340 updatePopupWindow();
341 }
342 }
343 else
344 {
345 checkInterface();
350 } 346 }
351 else checkInterface();
352
353 */
354} 347}
355 348
356void WirelessApplet::mousePressEvent( QMouseEvent * ) 349void WirelessApplet::mousePressEvent( QMouseEvent * )
357{ 350{
358 if ( status->isVisible() ) 351 if ( status->isVisible() )
359 status->hide(); 352 status->hide();
360 else 353 else
361 status->show( true ); 354 status->show( true );
362} 355}
363 356
364bool WirelessApplet::mustRepaint() 357bool WirelessApplet::mustRepaint()
365{ 358{
366 OWirelessNetworkInterface* iface = interface; 359 OWirelessNetworkInterface* iface = interface;
367 360
368 // check if there are enough changes to justify a (flickering) repaint 361 // check if there are enough changes to justify a (flickering) repaint
369 362
370 // has the interface changed? 363 // has the interface changed?
371 364
372 if ( iface != oldiface ) 365 if ( iface != oldiface )
373 { 366 {
374 oldiface = iface; 367 oldiface = iface;
375 if ( iface ) 368 if ( iface )
376 { 369 {
377#ifdef MDEBUG 370#ifdef MDEBUG
378 qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" ); 371 qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" );
379#endif 372#endif
380 show(); 373 show();
381 } 374 }
382 else 375 else
383 { 376 {
384#ifdef MDEBUG 377#ifdef MDEBUG
385 qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" ); 378 qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" );
386#endif 379#endif
387 hide(); 380 hide();
388 return true; 381 return true;
389 } 382 }
390 } 383 }
391 384
392 const char** pixmap = getQualityPixmap(); 385 const char** pixmap = getQualityPixmap();
393 386
394 if ( pixmap && ( pixmap != oldpixmap ) ) 387 if ( pixmap && ( pixmap != oldpixmap ) )
395 { 388 {
396 oldpixmap = pixmap; 389 oldpixmap = pixmap;
397 return true; 390 return true;
398 } 391 }
399 392
400 int noiseH = 50; // iface->noisePercent() * ( height() - 3 ) / 100; 393 int noiseH = 50; // iface->noisePercent() * ( height() - 3 ) / 100;
401 int signalH = iface->signalStrength() * ( height() - 3 ) / 100; 394 int signalH = iface->signalStrength() * ( height() - 3 ) / 100;
@@ -405,150 +398,150 @@ bool WirelessApplet::mustRepaint()
405 || ( signalH != oldsignalH ) 398 || ( signalH != oldsignalH )
406 || ( qualityH != oldqualityH ) ) 399 || ( qualityH != oldqualityH ) )
407 { 400 {
408 oldnoiseH = noiseH; 401 oldnoiseH = noiseH;
409 oldsignalH = signalH; 402 oldsignalH = signalH;
410 oldqualityH = qualityH; 403 oldqualityH = qualityH;
411 return true; 404 return true;
412 } 405 }
413 406
414 if ( rocESSID && ( oldESSID != iface->SSID() ) ) 407 if ( rocESSID && ( oldESSID != iface->SSID() ) )
415 { 408 {
416#ifdef MDEBUG 409#ifdef MDEBUG
417 qDebug( "WIFIAPPLET: ESSID has changed." ); 410 qDebug( "WIFIAPPLET: ESSID has changed." );
418#endif 411#endif
419 renewDHCP(); 412 renewDHCP();
420 } 413 }
421 else if ( rocFREQ && ( oldFREQ != iface->frequency() ) ) 414 else if ( rocFREQ && ( oldFREQ != iface->frequency() ) )
422 { 415 {
423#ifdef MDEBUG 416#ifdef MDEBUG
424 qDebug( "WIFIAPPLET: FREQ has changed." ); 417 qDebug( "WIFIAPPLET: FREQ has changed." );
425#endif 418#endif
426 renewDHCP(); 419 renewDHCP();
427 } 420 }
428 else if ( rocAP && ( oldAP != iface->associatedAP().toString() ) ) 421 else if ( rocAP && ( oldAP != iface->associatedAP().toString() ) )
429 { 422 {
430#ifdef MDEBUG 423#ifdef MDEBUG
431 qDebug( "WIFIAPPLET: AP has changed." ); 424 qDebug( "WIFIAPPLET: AP has changed." );
432#endif 425#endif
433 renewDHCP(); 426 renewDHCP();
434 } 427 }
435 else if ( rocMODE && ( oldMODE != iface->mode() ) ) 428 else if ( rocMODE && ( oldMODE != iface->mode() ) )
436 { 429 {
437#ifdef MDEBUG 430#ifdef MDEBUG
438 qDebug( "WIFIAPPLET: MODE has changed." ); 431 qDebug( "WIFIAPPLET: MODE has changed." );
439#endif 432#endif
440 renewDHCP(); 433 renewDHCP();
441 } 434 }
442 435
443 oldESSID = iface->SSID(); 436 oldESSID = iface->SSID();
444 oldMODE = iface->mode(); 437 oldMODE = iface->mode();
445 oldFREQ = iface->frequency(); 438 oldFREQ = iface->frequency();
446 oldAP = iface->associatedAP().toString(); 439 oldAP = iface->associatedAP().toString();
447 440
448 return false; 441 return false;
449} 442}
450 443
451void WirelessApplet::updatePopupWindow() 444void WirelessApplet::updatePopupWindow()
452{ 445{
453 MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; 446 OWirelessNetworkInterface* iface = interface;
454 int qualityH = iface->qualityPercent(); 447 int qualityH = iface->signalStrength();
455 448
456 if ( status->mgraph ) 449 if ( status->mgraph )
457 status->mgraph->addValue( qualityH, false ); 450 status->mgraph->addValue( qualityH, false );
458 451
459 QString freqString; 452 QString freqString;
460 QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; 453 QString cell = ( iface->mode() == "Managed" ) ? "AP: " : "Cell: ";
461 freqString.sprintf( "%.3f GHz", iface->freq ); 454 freqString.sprintf( "%.3f GHz", iface->frequency() );
462 status->statusLabel->setText( "Station: " + iface->nick + "<br>" + 455 status->statusLabel->setText( "Station: " + iface->nickName() + "<br>" +
463 "ESSID: " + iface->essid + "<br>" + 456 "ESSID: " + iface->SSID() + "<br>" +
464 "MODE: " + iface->mode + "<br>" + 457 "MODE: " + iface->mode() + "<br>" +
465 "FREQ: " + freqString + "<br>" + 458 "FREQ: " + freqString + "<br>" +
466 cell + " " + iface->APAddr ); 459 cell + " " + iface->associatedAP().toString() );
467} 460}
468 461
469const char** WirelessApplet::getQualityPixmap() 462const char** WirelessApplet::getQualityPixmap()
470{ 463{
471 MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; 464 OWirelessNetworkInterface* iface = interface;
472 465
473 if ( !iface ) return ( const char** ) nowireless_xpm; 466 if ( !iface ) return ( const char** ) nowireless_xpm;
474 int qualityH = iface->qualityPercent(); 467 int qualityH = iface->signalStrength();
475 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; 468 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm;
476 469
477 if ( visualStyle == STYLE_ANTENNA ) 470 if ( visualStyle == STYLE_ANTENNA )
478 { 471 {
479 if ( qualityH < 1 ) return ( const char** ) connect0_xpm; 472 if ( qualityH < 1 ) return ( const char** ) connect0_xpm;
480 if ( qualityH < 17 ) return ( const char** ) connect1_xpm; 473 if ( qualityH < 17 ) return ( const char** ) connect1_xpm;
481 if ( qualityH < 34 ) return ( const char** ) connect2_xpm; 474 if ( qualityH < 34 ) return ( const char** ) connect2_xpm;
482 if ( qualityH < 50 ) return ( const char** ) connect3_xpm; 475 if ( qualityH < 50 ) return ( const char** ) connect3_xpm;
483 if ( qualityH < 65 ) return ( const char** ) connect4_xpm; 476 if ( qualityH < 65 ) return ( const char** ) connect4_xpm;
484 return ( const char** ) connect5_xpm; 477 return ( const char** ) connect5_xpm;
485 } 478 }
486 479
487 return 0; // please draw your bars 480 return 0; // please draw your bars
488} 481}
489 482
490void WirelessApplet::paintEvent( QPaintEvent* ) 483void WirelessApplet::paintEvent( QPaintEvent* )
491{ 484{
492 MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; 485 OWirelessNetworkInterface* iface = interface;
493 486
494 QPainter p( this ); 487 QPainter p( this );
495 QColor color; 488 QColor color;
496 489
497 const char** pixmap = getQualityPixmap(); 490 const char** pixmap = getQualityPixmap();
498 491
499 if ( pixmap ) 492 if ( pixmap )
500 p.drawPixmap( 0, 1, pixmap ); 493 p.drawPixmap( 0, 1, pixmap );
501 else 494 else
502 { 495 {
503 496
504 int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; 497 int noiseH = 30; // iface->noisePercent() * ( height() - 3 ) / 100;
505 int signalH = iface->signalPercent() * ( height() - 3 ) / 100; 498 int signalH = 50; // iface->signalPercent() * ( height() - 3 ) / 100;
506 int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; 499 int qualityH = iface->signalStrength(); // iface->qualityPercent() * ( height() - 3 ) / 100;
507 500
508 double intensity; 501 double intensity;
509 int pixelHeight; 502 int pixelHeight;
510 int pixelWidth = 2; 503 int pixelWidth = 2;
511 int Hue; 504 int Hue;
512 int barSpace = 3; 505 int barSpace = 3;
513 int leftoffset = 0; 506 int leftoffset = 0;
514 int bottomoffset = 2; 507 int bottomoffset = 2;
515 508
516 // draw noise indicator 509 // draw noise indicator
517 pixelHeight = noiseH; 510 pixelHeight = noiseH;
518 Hue = 50; 511 Hue = 50;
519 for ( int i = 0; i < pixelHeight; ++i ) 512 for ( int i = 0; i < pixelHeight; ++i )
520 { 513 {
521 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; 514 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205;
522 color.setHsv( Hue, 255, intensity ); 515 color.setHsv( Hue, 255, intensity );
523 p.setPen ( color ); 516 p.setPen ( color );
524 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); 517 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i );
525 } 518 }
526 519
527 // draw signal indicator 520 // draw signal indicator
528 pixelHeight = signalH; 521 pixelHeight = signalH;
529 Hue = 100; 522 Hue = 100;
530 leftoffset += pixelWidth + barSpace; 523 leftoffset += pixelWidth + barSpace;
531 for ( int i = 0; i < pixelHeight; ++i ) 524 for ( int i = 0; i < pixelHeight; ++i )
532 { 525 {
533 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; 526 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205;
534 color.setHsv( Hue, 255, intensity ); 527 color.setHsv( Hue, 255, intensity );
535 p.setPen ( color ); 528 p.setPen ( color );
536 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); 529 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i );
537 } 530 }
538 531
539 // draw quality indicator 532 // draw quality indicator
540 pixelHeight = qualityH; 533 pixelHeight = qualityH;
541 Hue = 250; 534 Hue = 250;
542 leftoffset += pixelWidth + barSpace; 535 leftoffset += pixelWidth + barSpace;
543 for ( int i = 0; i < pixelHeight; ++i ) 536 for ( int i = 0; i < pixelHeight; ++i )
544 { 537 {
545 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; 538 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205;
546 color.setHsv( Hue, 255, intensity ); 539 color.setHsv( Hue, 255, intensity );
547 p.setPen ( color ); 540 p.setPen ( color );
548 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); 541 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i );
549 } 542 }
550 } 543 }
551} 544}
552 545
553 546
554int WirelessApplet::position() 547int WirelessApplet::position()
diff --git a/noncore/applets/wirelessapplet/wirelessapplet.pro b/noncore/applets/wirelessapplet/wirelessapplet.pro
index 7bd7380..636b2d3 100644
--- a/noncore/applets/wirelessapplet/wirelessapplet.pro
+++ b/noncore/applets/wirelessapplet/wirelessapplet.pro
@@ -1,13 +1,13 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt plugin warn_on release 2CONFIG += qt plugin warn_on release
3HEADERS = wireless.h networkinfo.h mgraph.h advancedconfig.h 3HEADERS = wireless.h mgraph.h advancedconfig.h
4SOURCES = wireless.cpp networkinfo.cpp mgraph.cpp advancedconfig.cpp 4SOURCES = wireless.cpp mgraph.cpp advancedconfig.cpp
5INTERFACES = advancedconfigbase.ui 5INTERFACES = advancedconfigbase.ui
6TARGET = wirelessapplet 6TARGET = wirelessapplet
7DESTDIR = $(OPIEDIR)/plugins/applets 7DESTDIR = $(OPIEDIR)/plugins/applets
8INCLUDEPATH += $(OPIEDIR)/include 8INCLUDEPATH += $(OPIEDIR)/include
9DEPENDPATH += $(OPIEDIR)/include 9DEPENDPATH += $(OPIEDIR)/include
10LIBS += -lqpe -lopiecore2 -lopienet2 10LIBS += -lqpe -lopiecore2 -lopienet2
11VERSION = 0.1.1 11VERSION = 0.1.1
12 12
13include ( $(OPIEDIR)/include.pro ) 13include ( $(OPIEDIR)/include.pro )