summaryrefslogtreecommitdiff
authorbrad <brad>2004-04-03 07:01:25 (UTC)
committer brad <brad>2004-04-03 07:01:25 (UTC)
commita2fa6f99b2a9c9f6d7e3b49847dfad619c606ac1 (patch) (unidiff)
tree4f9fa6de2199494e69d57d65b76333c41b5eeda6
parentff531aabe98565e041301f5f5b796cbf61b84fa1 (diff)
downloadopie-a2fa6f99b2a9c9f6d7e3b49847dfad619c606ac1.zip
opie-a2fa6f99b2a9c9f6d7e3b49847dfad619c606ac1.tar.gz
opie-a2fa6f99b2a9c9f6d7e3b49847dfad619c606ac1.tar.bz2
Fix for building on gcc-2.95.3
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index 711d0dd..0491a86 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -1,504 +1,507 @@
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 "mgraph.h" 15#include "mgraph.h"
16#include "advancedconfig.h" 16#include "advancedconfig.h"
17 17
18/* OPIE */ 18/* OPIE */
19#include <opie2/onetwork.h> 19#include <opie2/onetwork.h>
20#include <opie2/otaskbarapplet.h> 20#include <opie2/otaskbarapplet.h>
21#include <qpe/config.h> 21#include <qpe/config.h>
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23 23
24/* QT */ 24/* QT */
25#include <qradiobutton.h> 25#include <qradiobutton.h>
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qpainter.h> 27#include <qpainter.h>
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qslider.h> 29#include <qslider.h>
30#include <qbuttongroup.h> 30#include <qbuttongroup.h>
31#include <qlayout.h> 31#include <qlayout.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34 34
35/* STD */ 35/* STD */
36#include <math.h> 36#include <math.h>
37#include <sys/types.h> 37#include <sys/types.h>
38#include <signal.h> 38#include <signal.h>
39#if defined (__GNUC__) && (__GNUC__ < 3)
40#define round qRound
41#endif
39 42
40//#define MDEBUG 43//#define MDEBUG
41#undef MDEBUG 44#undef MDEBUG
42 45
43using namespace Opie::Ui; 46using namespace Opie::Ui;
44using namespace Opie::Net; 47using namespace Opie::Net;
45WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 48WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
46 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 49 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
47{ 50{
48 51
49 readConfig(); 52 readConfig();
50 writeConfigEntry( "UpdateFrequency", updateFrequency ); 53 writeConfigEntry( "UpdateFrequency", updateFrequency );
51 54
52 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 55 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
53 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); 56 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
54 57
55 /* status label */ 58 /* status label */
56 59
57 statusLabel = new QLabel( this, "statuslabel" ); 60 statusLabel = new QLabel( this, "statuslabel" );
58 QString text( "Wireless Status:<br>" 61 QString text( "Wireless Status:<br>"
59 "*** Unknown ***<br>" 62 "*** Unknown ***<br>"
60 "Card not inserted ?<br>" 63 "Card not inserted ?<br>"
61 "Or Sharp ROM ?<br>" 64 "Or Sharp ROM ?<br>"
62 "CELL: 00:00:00:00:00:00" ); 65 "CELL: 00:00:00:00:00:00" );
63 /* QString text( "Station: Unknown<br>" 66 /* QString text( "Station: Unknown<br>"
64 "ESSID: Unknown<br>" 67 "ESSID: Unknown<br>"
65 "MODE: Unknown<br>" 68 "MODE: Unknown<br>"
66 "FREQ: Unknown<br>" 69 "FREQ: Unknown<br>"
67 "CELL: AA:BB:CC:DD:EE:FF" ); */ 70 "CELL: AA:BB:CC:DD:EE:FF" ); */
68 statusLabel->setText( text ); 71 statusLabel->setText( text );
69 statusLabel->setFixedSize( statusLabel->sizeHint() ); 72 statusLabel->setFixedSize( statusLabel->sizeHint() );
70 grid->addWidget( statusLabel, 0, 0 ); 73 grid->addWidget( statusLabel, 0, 0 );
71 74
72 /* visualization group box */ 75 /* visualization group box */
73 76
74 /* quality graph */ 77 /* quality graph */
75 78
76 mgraph = new MGraph( this ); 79 mgraph = new MGraph( this );
77 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 80 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
78 mgraph->setMin( 0 ); 81 mgraph->setMin( 0 );
79 mgraph->setMax( 92 ); 82 mgraph->setMax( 92 );
80 grid->addWidget( mgraph, 1, 0 ); 83 grid->addWidget( mgraph, 1, 0 );
81 mgraph->setFocusPolicy( QWidget::NoFocus ); 84 mgraph->setFocusPolicy( QWidget::NoFocus );
82 85
83 /* advanced configuration Button */ 86 /* advanced configuration Button */
84 87
85 QPushButton* advanced = new QPushButton( "Advanced...", this ); 88 QPushButton* advanced = new QPushButton( "Advanced...", this );
86 advanced->setFocusPolicy( QWidget::NoFocus ); 89 advanced->setFocusPolicy( QWidget::NoFocus );
87 grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); 90 grid->addWidget( advanced, 2, 0, Qt::AlignCenter );
88 connect( advanced, SIGNAL( clicked() ), 91 connect( advanced, SIGNAL( clicked() ),
89 this, SLOT( advancedConfigClicked() ) ); 92 this, SLOT( advancedConfigClicked() ) );
90 93
91 /* update Frequency Label */ 94 /* update Frequency Label */
92 95
93 updateLabel = new QLabel( this ); 96 updateLabel = new QLabel( this );
94 text.sprintf( "Update every %d s", updateFrequency ); 97 text.sprintf( "Update every %d s", updateFrequency );
95 updateLabel->setText( text ); 98 updateLabel->setText( text );
96 grid->addWidget( updateLabel, 2, 1 ); 99 grid->addWidget( updateLabel, 2, 1 );
97 100
98 /* update Frequency Slider */ 101 /* update Frequency Slider */
99 102
100 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); 103 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this );
101 updateSlider->setRange( 0, 9 ); 104 updateSlider->setRange( 0, 9 );
102 updateSlider->setValue( updateFrequency ); 105 updateSlider->setValue( updateFrequency );
103 updateSlider->setTickmarks( QSlider::Both ); 106 updateSlider->setTickmarks( QSlider::Both );
104 updateSlider->setTickInterval( 1 ); 107 updateSlider->setTickInterval( 1 );
105 updateSlider->setSteps( 1, 1 ); 108 updateSlider->setSteps( 1, 1 );
106 updateSlider->setFocusPolicy( QWidget::NoFocus ); 109 updateSlider->setFocusPolicy( QWidget::NoFocus );
107 grid->addWidget( updateSlider, 1, 1 ); 110 grid->addWidget( updateSlider, 1, 1 );
108 connect( updateSlider, SIGNAL( valueChanged(int) ), 111 connect( updateSlider, SIGNAL( valueChanged(int) ),
109 this, SLOT( updateDelayChange(int) ) ); 112 this, SLOT( updateDelayChange(int) ) );
110 113
111 setFixedSize( sizeHint() ); 114 setFixedSize( sizeHint() );
112 setFocusPolicy( QWidget::NoFocus ); 115 setFocusPolicy( QWidget::NoFocus );
113 116
114 applet->updateDelayChange( updateFrequency ); 117 applet->updateDelayChange( updateFrequency );
115 118
116 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 119 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
117} 120}
118 121
119void WirelessControl::advancedConfigClicked() 122void WirelessControl::advancedConfigClicked()
120{ 123{
121 AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE ); 124 AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE );
122 int result = a->exec(); 125 int result = a->exec();
123 a->hide(); 126 a->hide();
124 delete a; 127 delete a;
125 if ( result == QDialog::Accepted ) 128 if ( result == QDialog::Accepted )
126 { 129 {
127 readConfig(); 130 readConfig();
128 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 131 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
129 } 132 }
130} 133}
131 134
132void WirelessControl::updateDelayChange( int delay ) 135void WirelessControl::updateDelayChange( int delay )
133{ 136{
134 QString text; 137 QString text;
135 text.sprintf( "Update every %d s", delay ); 138 text.sprintf( "Update every %d s", delay );
136 updateLabel->setText( text ); 139 updateLabel->setText( text );
137 applet->updateDelayChange( delay ); 140 applet->updateDelayChange( delay );
138 writeConfigEntry( "UpdateFrequency", delay ); 141 writeConfigEntry( "UpdateFrequency", delay );
139} 142}
140 143
141void WirelessControl::displayStyleChange( int style ) 144void WirelessControl::displayStyleChange( int style )
142{ 145{
143 applet->displayStyleChange( style ); 146 applet->displayStyleChange( style );
144 writeConfigEntry( "DisplayStyle", style ); 147 writeConfigEntry( "DisplayStyle", style );
145} 148}
146 149
147void WirelessControl::show ( bool ) 150void WirelessControl::show ( bool )
148{ 151{
149 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); 152 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
150 153
151 int w = sizeHint().width(); 154 int w = sizeHint().width();
152 int x = curPos.x() - ( w / 2 ); 155 int x = curPos.x() - ( w / 2 );
153 156
154 if ( ( x + w ) > QPEApplication::desktop() ->width() ) 157 if ( ( x + w ) > QPEApplication::desktop() ->width() )
155 x = QPEApplication::desktop ( ) -> width ( ) - w; 158 x = QPEApplication::desktop ( ) -> width ( ) - w;
156 159
157 move( x, curPos.y () - sizeHint().height () ); 160 move( x, curPos.y () - sizeHint().height () );
158 QFrame::show(); 161 QFrame::show();
159} 162}
160 163
161void WirelessControl::readConfig() 164void WirelessControl::readConfig()
162{ 165{
163 Config cfg( "qpe" ); 166 Config cfg( "qpe" );
164 cfg.setGroup( "Wireless" ); 167 cfg.setGroup( "Wireless" );
165 168
166 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); 169 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 );
167 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); 170 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false );
168 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); 171 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false );
169 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); 172 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false );
170 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); 173 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false );
171} 174}
172 175
173void WirelessControl::writeConfigEntry( const char *entry, int val ) 176void WirelessControl::writeConfigEntry( const char *entry, int val )
174{ 177{
175 Config cfg( "qpe" ); 178 Config cfg( "qpe" );
176 cfg.setGroup( "Wireless" ); 179 cfg.setGroup( "Wireless" );
177 cfg.writeEntry( entry, val ); 180 cfg.writeEntry( entry, val );
178} 181}
179 182
180//=========================================================================== 183//===========================================================================
181 184
182WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) 185WirelessApplet::WirelessApplet( QWidget *parent, const char *name )
183 : QWidget( parent, name ), 186 : QWidget( parent, name ),
184 timer( 0 ), interface( 0 ), oldiface( 0 ), 187 timer( 0 ), interface( 0 ), oldiface( 0 ),
185 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) 188 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false )
186{ 189{
187 setFixedHeight( 18 ); 190 setFixedHeight( 18 );
188 setFixedWidth( 14 ); 191 setFixedWidth( 14 );
189 status = new WirelessControl( this, this, "wireless status" ); 192 status = new WirelessControl( this, this, "wireless status" );
190} 193}
191 194
192void WirelessApplet::checkInterface() 195void WirelessApplet::checkInterface()
193{ 196{
194 interface = 0L; 197 interface = 0L;
195 ONetwork* net = ONetwork::instance(); 198 ONetwork* net = ONetwork::instance();
196 net->synchronize(); 199 net->synchronize();
197 ONetwork::InterfaceIterator it = net->iterator(); 200 ONetwork::InterfaceIterator it = net->iterator();
198 201
199 while ( it.current() && !it.current()->isWireless() ) ++it; 202 while ( it.current() && !it.current()->isWireless() ) ++it;
200 203
201 if ( it.current() && it.current()->isWireless() ) 204 if ( it.current() && it.current()->isWireless() )
202 interface = static_cast<OWirelessNetworkInterface*>( it.current() ); 205 interface = static_cast<OWirelessNetworkInterface*>( it.current() );
203 206
204 if ( interface ) 207 if ( interface )
205 { 208 {
206#ifdef MDEBUG 209#ifdef MDEBUG
207 qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() ); 210 qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() );
208#endif 211#endif
209 212
210 } 213 }
211 else 214 else
212 { 215 {
213#ifdef MDEBUG 216#ifdef MDEBUG
214 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); 217 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" );
215#endif 218#endif
216 hide(); 219 hide();
217 } 220 }
218} 221}
219 222
220void WirelessApplet::renewDHCP() 223void WirelessApplet::renewDHCP()
221{ 224{
222#ifdef MDEBUG 225#ifdef MDEBUG
223 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); 226 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." );
224#endif 227#endif
225 228
226 QString pidfile; 229 QString pidfile;
227 if ( !interface ) 230 if ( !interface )
228 return ; 231 return ;
229 QString ifacename( interface->name() ); 232 QString ifacename( interface->name() );
230 233
231 // At first we are trying dhcpcd 234 // At first we are trying dhcpcd
232 235
233 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename ); 236 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename );
234#ifdef MDEBUG 237#ifdef MDEBUG
235 qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile ); 238 qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile );
236#endif 239#endif
237 int pid; 240 int pid;
238 QFile pfile( pidfile ); 241 QFile pfile( pidfile );
239 bool hasFile = pfile.open( IO_ReadOnly ); 242 bool hasFile = pfile.open( IO_ReadOnly );
240 QTextStream s( &pfile ); 243 QTextStream s( &pfile );
241 if ( hasFile ) 244 if ( hasFile )
242 { 245 {
243 s >> pid; 246 s >> pid;
244#ifdef MDEBUG 247#ifdef MDEBUG
245 qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid ); 248 qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid );
246#endif 249#endif
247 kill( pid, SIGALRM ); 250 kill( pid, SIGALRM );
248 return ; 251 return ;
249 } 252 }
250 253
251 // No dhcpcd, so we are trying udhcpc 254 // No dhcpcd, so we are trying udhcpc
252#ifdef MDEBUG 255#ifdef MDEBUG
253 qDebug( "WIFIAPPLET: dhcpcd not available." ); 256 qDebug( "WIFIAPPLET: dhcpcd not available." );
254#endif 257#endif
255 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename ); 258 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename );
256#ifdef MDEBUG 259#ifdef MDEBUG
257 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile ); 260 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile );
258#endif 261#endif
259 QFile pfile2( pidfile ); 262 QFile pfile2( pidfile );
260 hasFile = pfile2.open( IO_ReadOnly ); 263 hasFile = pfile2.open( IO_ReadOnly );
261 QTextStream s2( &pfile2 ); 264 QTextStream s2( &pfile2 );
262 if ( hasFile ) 265 if ( hasFile )
263 { 266 {
264 s2 >> pid; 267 s2 >> pid;
265#ifdef MDEBUG 268#ifdef MDEBUG
266 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); 269 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid );
267#endif 270#endif
268 kill( pid, SIGUSR1 ); 271 kill( pid, SIGUSR1 );
269 return ; 272 return ;
270 } 273 }
271} 274}
272 275
273void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) 276void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE )
274{ 277{
275 rocESSID = ESSID; 278 rocESSID = ESSID;
276 rocFREQ = FREQ; 279 rocFREQ = FREQ;
277 rocAP = AP; 280 rocAP = AP;
278 rocMODE = MODE; 281 rocMODE = MODE;
279} 282}
280 283
281void WirelessApplet::updateDelayChange( int delay ) 284void WirelessApplet::updateDelayChange( int delay )
282{ 285{
283 if ( timer ) 286 if ( timer )
284 killTimer( timer ); 287 killTimer( timer );
285 delay *= 1000; 288 delay *= 1000;
286 if ( delay == 0 ) 289 if ( delay == 0 )
287 delay = 50; 290 delay = 50;
288 timer = startTimer( delay ); 291 timer = startTimer( delay );
289} 292}
290 293
291void WirelessApplet::displayStyleChange( int style ) 294void WirelessApplet::displayStyleChange( int style )
292{ 295{
293 visualStyle = style; 296 visualStyle = style;
294 repaint(); 297 repaint();
295} 298}
296 299
297WirelessApplet::~WirelessApplet() 300WirelessApplet::~WirelessApplet()
298{} 301{}
299 302
300void WirelessApplet::timerEvent( QTimerEvent* ) 303void WirelessApplet::timerEvent( QTimerEvent* )
301{ 304{
302#ifdef MDEBUG 305#ifdef MDEBUG
303 qDebug( "WirelessApplet::timerEvent" ); 306 qDebug( "WirelessApplet::timerEvent" );
304#endif 307#endif
305 if ( interface ) 308 if ( interface )
306 { 309 {
307 if ( !ONetwork::instance()->isPresent( (const char*) interface->name() ) ) 310 if ( !ONetwork::instance()->isPresent( (const char*) interface->name() ) )
308 { 311 {
309#ifdef MDEBUG 312#ifdef MDEBUG
310 qDebug( "WIFIAPPLET: Interface no longer present." ); 313 qDebug( "WIFIAPPLET: Interface no longer present." );
311#endif 314#endif
312 interface = 0L; 315 interface = 0L;
313 mustRepaint(); 316 mustRepaint();
314 return; 317 return;
315 } 318 }
316 319
317 if ( mustRepaint() ) 320 if ( mustRepaint() )
318 { 321 {
319#ifdef MDEBUG 322#ifdef MDEBUG
320 qDebug( "WIFIAPPLET: A value has changed -> repainting." ); 323 qDebug( "WIFIAPPLET: A value has changed -> repainting." );
321#endif 324#endif
322 repaint(); 325 repaint();
323 } 326 }
324 327
325 if ( status->isVisible() ) 328 if ( status->isVisible() )
326 { 329 {
327 updatePopupWindow(); 330 updatePopupWindow();
328 } 331 }
329 } 332 }
330 else 333 else
331 { 334 {
332 checkInterface(); 335 checkInterface();
333 } 336 }
334} 337}
335 338
336void WirelessApplet::mousePressEvent( QMouseEvent * ) 339void WirelessApplet::mousePressEvent( QMouseEvent * )
337{ 340{
338 if ( status->isVisible() ) 341 if ( status->isVisible() )
339 status->hide(); 342 status->hide();
340 else 343 else
341 status->show( true ); 344 status->show( true );
342} 345}
343 346
344bool WirelessApplet::mustRepaint() 347bool WirelessApplet::mustRepaint()
345{ 348{
346 // check if there are enough changes to justify a (flickering) repaint 349 // check if there are enough changes to justify a (flickering) repaint
347 350
348 // has the interface changed? 351 // has the interface changed?
349 352
350 if ( interface != oldiface ) 353 if ( interface != oldiface )
351 { 354 {
352 oldiface = interface; 355 oldiface = interface;
353 if ( interface ) 356 if ( interface )
354 { 357 {
355#ifdef MDEBUG 358#ifdef MDEBUG
356 qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" ); 359 qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" );
357#endif 360#endif
358 show(); 361 show();
359 } 362 }
360 else 363 else
361 { 364 {
362#ifdef MDEBUG 365#ifdef MDEBUG
363 qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" ); 366 qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" );
364#endif 367#endif
365 hide(); 368 hide();
366 return true; 369 return true;
367 } 370 }
368 } 371 }
369 372
370 int rings = numberOfRings(); 373 int rings = numberOfRings();
371 374
372 if ( rings != oldrings ) 375 if ( rings != oldrings )
373 { 376 {
374 oldrings = rings; 377 oldrings = rings;
375 return true; 378 return true;
376 } 379 }
377 380
378 int noiseH = 50; // iface->noisePercent() * ( height() - 3 ) / 100; 381 int noiseH = 50; // iface->noisePercent() * ( height() - 3 ) / 100;
379 int signalH = interface->signalStrength() * ( height() - 3 ) / 100; 382 int signalH = interface->signalStrength() * ( height() - 3 ) / 100;
380 int qualityH = 50; // iface->qualityPercent() * ( height() - 3 ) / 100; 383 int qualityH = 50; // iface->qualityPercent() * ( height() - 3 ) / 100;
381 384
382 if ( ( noiseH != oldnoiseH ) 385 if ( ( noiseH != oldnoiseH )
383 || ( signalH != oldsignalH ) 386 || ( signalH != oldsignalH )
384 || ( qualityH != oldqualityH ) ) 387 || ( qualityH != oldqualityH ) )
385 { 388 {
386 oldnoiseH = noiseH; 389 oldnoiseH = noiseH;
387 oldsignalH = signalH; 390 oldsignalH = signalH;
388 oldqualityH = qualityH; 391 oldqualityH = qualityH;
389 return true; 392 return true;
390 } 393 }
391 394
392 if ( rocESSID && ( oldESSID != interface->SSID() ) ) 395 if ( rocESSID && ( oldESSID != interface->SSID() ) )
393 { 396 {
394#ifdef MDEBUG 397#ifdef MDEBUG
395 qDebug( "WIFIAPPLET: ESSID has changed." ); 398 qDebug( "WIFIAPPLET: ESSID has changed." );
396#endif 399#endif
397 renewDHCP(); 400 renewDHCP();
398 } 401 }
399 else if ( rocFREQ && ( oldFREQ != interface->frequency() ) ) 402 else if ( rocFREQ && ( oldFREQ != interface->frequency() ) )
400 { 403 {
401#ifdef MDEBUG 404#ifdef MDEBUG
402 qDebug( "WIFIAPPLET: FREQ has changed." ); 405 qDebug( "WIFIAPPLET: FREQ has changed." );
403#endif 406#endif
404 renewDHCP(); 407 renewDHCP();
405 } 408 }
406 else if ( rocAP && ( oldAP != interface->associatedAP().toString() ) ) 409 else if ( rocAP && ( oldAP != interface->associatedAP().toString() ) )
407 { 410 {
408#ifdef MDEBUG 411#ifdef MDEBUG
409 qDebug( "WIFIAPPLET: AP has changed." ); 412 qDebug( "WIFIAPPLET: AP has changed." );
410#endif 413#endif
411 renewDHCP(); 414 renewDHCP();
412 } 415 }
413 else if ( rocMODE && ( oldMODE != interface->mode() ) ) 416 else if ( rocMODE && ( oldMODE != interface->mode() ) )
414 { 417 {
415#ifdef MDEBUG 418#ifdef MDEBUG
416 qDebug( "WIFIAPPLET: MODE has changed." ); 419 qDebug( "WIFIAPPLET: MODE has changed." );
417#endif 420#endif
418 renewDHCP(); 421 renewDHCP();
419 } 422 }
420 423
421 oldESSID = interface->SSID(); 424 oldESSID = interface->SSID();
422 oldMODE = interface->mode(); 425 oldMODE = interface->mode();
423 oldFREQ = interface->frequency(); 426 oldFREQ = interface->frequency();
424 oldAP = interface->associatedAP().toString(); 427 oldAP = interface->associatedAP().toString();
425 428
426 return false; 429 return false;
427} 430}
428 431
429void WirelessApplet::updatePopupWindow() 432void WirelessApplet::updatePopupWindow()
430{ 433{
431 int qualityH = interface->signalStrength(); 434 int qualityH = interface->signalStrength();
432 435
433 if ( status->mgraph ) 436 if ( status->mgraph )
434 status->mgraph->addValue( qualityH, false ); 437 status->mgraph->addValue( qualityH, false );
435 438
436 QString freqString; 439 QString freqString;
437 QString cell = ( interface->mode() == "Managed" ) ? "AP: " : "Cell: "; 440 QString cell = ( interface->mode() == "Managed" ) ? "AP: " : "Cell: ";
438 freqString.sprintf( "%.3f GHz", interface->frequency() ); 441 freqString.sprintf( "%.3f GHz", interface->frequency() );
439 status->statusLabel->setText( "Station: " + interface->nickName() + "<br>" + 442 status->statusLabel->setText( "Station: " + interface->nickName() + "<br>" +
440 "ESSID: " + interface->SSID() + "<br>" + 443 "ESSID: " + interface->SSID() + "<br>" +
441 "MODE: " + interface->mode() + "<br>" + 444 "MODE: " + interface->mode() + "<br>" +
442 "FREQ: " + freqString + "<br>" + 445 "FREQ: " + freqString + "<br>" +
443 cell + " " + interface->associatedAP().toString() ); 446 cell + " " + interface->associatedAP().toString() );
444} 447}
445 448
446int WirelessApplet::numberOfRings() 449int WirelessApplet::numberOfRings()
447{ 450{
448 if ( !interface ) return -1; 451 if ( !interface ) return -1;
449 int qualityH = interface->signalStrength(); 452 int qualityH = interface->signalStrength();
450 qDebug( "quality = %d", qualityH ); 453 qDebug( "quality = %d", qualityH );
451 if ( qualityH < 1 ) return -1; 454 if ( qualityH < 1 ) return -1;
452 if ( qualityH < 20 ) return 0; 455 if ( qualityH < 20 ) return 0;
453 if ( qualityH < 40 ) return 1; 456 if ( qualityH < 40 ) return 1;
454 if ( qualityH < 60 ) return 2; 457 if ( qualityH < 60 ) return 2;
455 if ( qualityH < 65 ) return 3; 458 if ( qualityH < 65 ) return 3;
456 return 4; 459 return 4;
457} 460}
458 461
459void WirelessApplet::paintEvent( QPaintEvent* ) 462void WirelessApplet::paintEvent( QPaintEvent* )
460{ 463{
461 QPainter p( this ); 464 QPainter p( this );
462 int h = height(); 465 int h = height();
463 int w = width(); 466 int w = width();
464 int m = 2; 467 int m = 2;
465 468
466 p.drawLine( m, h-m-1, round( w/2.0 ), round( 0+h/3.0 ) ); 469 p.drawLine( m, h-m-1, round( w/2.0 ), round( 0+h/3.0 ) );
467 p.drawLine( round( w/2.0 ), round( 0+h/3.0 ), w-m, h-m-1 ); 470 p.drawLine( round( w/2.0 ), round( 0+h/3.0 ), w-m, h-m-1 );
468 p.setPen( QColor( 150, 150, 150 ) ); 471 p.setPen( QColor( 150, 150, 150 ) );
469 p.drawLine( w-m, h-m-1, m, h-m-1 ); 472 p.drawLine( w-m, h-m-1, m, h-m-1 );
470 473
471 int rings = numberOfRings(); 474 int rings = numberOfRings();
472 475
473 if ( rings == -1 ) 476 if ( rings == -1 )
474 { 477 {
475 p.setPen( QPen( QColor( 200, 20, 20 ), 2 ) ); 478 p.setPen( QPen( QColor( 200, 20, 20 ), 2 ) );
476 p.drawLine( w/2-m-m, h/2-m-m, w/2+m+m, h/2+m+m ); 479 p.drawLine( w/2-m-m, h/2-m-m, w/2+m+m, h/2+m+m );
477 p.drawLine( w/2+m+m, h/2-m-m, w/2-m-m, h/2+m+m ); 480 p.drawLine( w/2+m+m, h/2-m-m, w/2-m-m, h/2+m+m );
478 return; 481 return;
479 } 482 }
480 483
481 qDebug( "WirelessApplet: painting %d rings", rings ); 484 qDebug( "WirelessApplet: painting %d rings", rings );
482 int radius = 2; 485 int radius = 2;
483 int rstep = 4; 486 int rstep = 4;
484 int maxrings = w/rstep; 487 int maxrings = w/rstep;
485 488
486 p.setPen( QColor( 200, 20, 20 ) ); 489 p.setPen( QColor( 200, 20, 20 ) );
487 for ( int i = 0; i < rings; ++i ) 490 for ( int i = 0; i < rings; ++i )
488 { 491 {
489 p.drawEllipse( w/2 - radius/2, h/3 - radius/2, radius, radius ); 492 p.drawEllipse( w/2 - radius/2, h/3 - radius/2, radius, radius );
490 radius += rstep; 493 radius += rstep;
491 }; 494 };
492 495
493 496
494 497
495} 498}
496 499
497 500
498int WirelessApplet::position() 501int WirelessApplet::position()
499{ 502{
500 return 6; 503 return 6;
501} 504}
502 505
503EXPORT_OPIE_APPLET_v1( WirelessApplet ) 506EXPORT_OPIE_APPLET_v1( WirelessApplet )
504 507