summaryrefslogtreecommitdiff
path: root/noncore/applets/wirelessapplet/wireless.cpp
Unidiff
Diffstat (limited to 'noncore/applets/wirelessapplet/wireless.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp131
1 files changed, 39 insertions, 92 deletions
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index f244426..711d0dd 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -14,13 +14,6 @@
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#include "connect0.xpm"
18#include "connect1.xpm"
19#include "connect2.xpm"
20#include "connect3.xpm"
21#include "connect4.xpm"
22#include "connect5.xpm"
23#include "nowireless.xpm"
24 17
25/* OPIE */ 18/* OPIE */
26#include <opie2/onetwork.h> 19#include <opie2/onetwork.h>
@@ -40,12 +33,10 @@
40#include <qtextstream.h> 33#include <qtextstream.h>
41 34
42/* STD */ 35/* STD */
36#include <math.h>
43#include <sys/types.h> 37#include <sys/types.h>
44#include <signal.h> 38#include <signal.h>
45 39
46#define STYLE_BARS 0
47#define STYLE_ANTENNA 1
48
49//#define MDEBUG 40//#define MDEBUG
50#undef MDEBUG 41#undef MDEBUG
51 42
@@ -57,7 +48,6 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const
57 48
58 readConfig(); 49 readConfig();
59 writeConfigEntry( "UpdateFrequency", updateFrequency ); 50 writeConfigEntry( "UpdateFrequency", updateFrequency );
60 writeConfigEntry( "DisplayStyle", displayStyle );
61 51
62 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 52 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
63 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); 53 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
@@ -81,15 +71,6 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const
81 71
82 /* visualization group box */ 72 /* visualization group box */
83 73
84 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this );
85 QRadioButton* r1 = new QRadioButton( "Color Bars", group );
86 QRadioButton* r2 = new QRadioButton( "Antenna", group );
87 r1->setFocusPolicy( QWidget::NoFocus );
88 r2->setFocusPolicy( QWidget::NoFocus );
89 group->setFocusPolicy( QWidget::NoFocus );
90 group->setButton( displayStyle );
91 grid->addWidget( group, 0, 1 );
92
93 /* quality graph */ 74 /* quality graph */
94 75
95 mgraph = new MGraph( this ); 76 mgraph = new MGraph( this );
@@ -130,12 +111,8 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const
130 setFixedSize( sizeHint() ); 111 setFixedSize( sizeHint() );
131 setFocusPolicy( QWidget::NoFocus ); 112 setFocusPolicy( QWidget::NoFocus );
132 113
133 applet->displayStyleChange( displayStyle );
134 applet->updateDelayChange( updateFrequency ); 114 applet->updateDelayChange( updateFrequency );
135 115
136 connect( group, SIGNAL( clicked(int) ),
137 this, SLOT( displayStyleChange(int) ) );
138
139 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 116 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
140} 117}
141 118
@@ -187,7 +164,6 @@ void WirelessControl::readConfig()
187 cfg.setGroup( "Wireless" ); 164 cfg.setGroup( "Wireless" );
188 165
189 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); 166 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 );
190 displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA );
191 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); 167 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false );
192 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); 168 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false );
193 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); 169 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false );
@@ -204,7 +180,7 @@ void WirelessControl::writeConfigEntry( const char *entry, int val )
204//=========================================================================== 180//===========================================================================
205 181
206WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) 182WirelessApplet::WirelessApplet( QWidget *parent, const char *name )
207 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), 183 : QWidget( parent, name ),
208 timer( 0 ), interface( 0 ), oldiface( 0 ), 184 timer( 0 ), interface( 0 ), oldiface( 0 ),
209 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) 185 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false )
210{ 186{
@@ -391,11 +367,11 @@ bool WirelessApplet::mustRepaint()
391 } 367 }
392 } 368 }
393 369
394 const char** pixmap = getQualityPixmap(); 370 int rings = numberOfRings();
395 371
396 if ( pixmap && ( pixmap != oldpixmap ) ) 372 if ( rings != oldrings )
397 { 373 {
398 oldpixmap = pixmap; 374 oldrings = rings;
399 return true; 375 return true;
400 } 376 }
401 377
@@ -467,84 +443,55 @@ void WirelessApplet::updatePopupWindow()
467 cell + " " + interface->associatedAP().toString() ); 443 cell + " " + interface->associatedAP().toString() );
468} 444}
469 445
470const char** WirelessApplet::getQualityPixmap() 446int WirelessApplet::numberOfRings()
471{ 447{
472 if ( !interface ) return ( const char** ) nowireless_xpm; 448 if ( !interface ) return -1;
473 int qualityH = interface->signalStrength(); 449 int qualityH = interface->signalStrength();
474 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; 450 qDebug( "quality = %d", qualityH );
475 451 if ( qualityH < 1 ) return -1;
476 if ( visualStyle == STYLE_ANTENNA ) 452 if ( qualityH < 20 ) return 0;
477 { 453 if ( qualityH < 40 ) return 1;
478 if ( qualityH < 1 ) return ( const char** ) connect0_xpm; 454 if ( qualityH < 60 ) return 2;
479 if ( qualityH < 17 ) return ( const char** ) connect1_xpm; 455 if ( qualityH < 65 ) return 3;
480 if ( qualityH < 34 ) return ( const char** ) connect2_xpm; 456 return 4;
481 if ( qualityH < 50 ) return ( const char** ) connect3_xpm;
482 if ( qualityH < 65 ) return ( const char** ) connect4_xpm;
483 return ( const char** ) connect5_xpm;
484 }
485
486 return 0; // please draw your bars
487} 457}
488 458
489void WirelessApplet::paintEvent( QPaintEvent* ) 459void WirelessApplet::paintEvent( QPaintEvent* )
490{ 460{
491 QPainter p( this ); 461 QPainter p( this );
492 QColor color; 462 int h = height();
493 463 int w = width();
494 const char** pixmap = getQualityPixmap(); 464 int m = 2;
495 465
496 if ( pixmap ) 466 p.drawLine( m, h-m-1, round( w/2.0 ), round( 0+h/3.0 ) );
497 p.drawPixmap( 0, 1, pixmap ); 467 p.drawLine( round( w/2.0 ), round( 0+h/3.0 ), w-m, h-m-1 );
498 else 468 p.setPen( QColor( 150, 150, 150 ) );
499 { 469 p.drawLine( w-m, h-m-1, m, h-m-1 );
500 470
501 int noiseH = 30; // iface->noisePercent() * ( height() - 3 ) / 100; 471 int rings = numberOfRings();
502 int signalH = 50; // iface->signalPercent() * ( height() - 3 ) / 100;
503 int qualityH = interface->signalStrength(); // iface->qualityPercent() * ( height() - 3 ) / 100;
504 472
505 double intensity; 473 if ( rings == -1 )
506 int pixelHeight;
507 int pixelWidth = 2;
508 int Hue;
509 int barSpace = 3;
510 int leftoffset = 0;
511 int bottomoffset = 2;
512
513 // draw noise indicator
514 pixelHeight = noiseH;
515 Hue = 50;
516 for ( int i = 0; i < pixelHeight; ++i )
517 { 474 {
518 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; 475 p.setPen( QPen( QColor( 200, 20, 20 ), 2 ) );
519 color.setHsv( Hue, 255, intensity ); 476 p.drawLine( w/2-m-m, h/2-m-m, w/2+m+m, h/2+m+m );
520 p.setPen ( color ); 477 p.drawLine( w/2+m+m, h/2-m-m, w/2-m-m, h/2+m+m );
521 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); 478 return;
522 } 479 }
523 480
524 // draw signal indicator 481 qDebug( "WirelessApplet: painting %d rings", rings );
525 pixelHeight = signalH; 482 int radius = 2;
526 Hue = 100; 483 int rstep = 4;
527 leftoffset += pixelWidth + barSpace; 484 int maxrings = w/rstep;
528 for ( int i = 0; i < pixelHeight; ++i )
529 {
530 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205;
531 color.setHsv( Hue, 255, intensity );
532 p.setPen ( color );
533 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i );
534 }
535 485
536 // draw quality indicator 486 p.setPen( QColor( 200, 20, 20 ) );
537 pixelHeight = qualityH; 487 for ( int i = 0; i < rings; ++i )
538 Hue = 250;
539 leftoffset += pixelWidth + barSpace;
540 for ( int i = 0; i < pixelHeight; ++i )
541 { 488 {
542 intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; 489 p.drawEllipse( w/2 - radius/2, h/3 - radius/2, radius, radius );
543 color.setHsv( Hue, 255, intensity ); 490 radius += rstep;
544 p.setPen ( color ); 491 };
545 p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); 492
546 } 493
547 } 494
548} 495}
549 496
550 497