summaryrefslogtreecommitdiff
path: root/noncore/applets/wirelessapplet/wireless.cpp
Unidiff
Diffstat (limited to 'noncore/applets/wirelessapplet/wireless.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index 9ce6618..6ef2e44 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -1,326 +1,326 @@
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#include "connect0.xpm" 17#include "connect0.xpm"
18#include "connect1.xpm" 18#include "connect1.xpm"
19#include "connect2.xpm" 19#include "connect2.xpm"
20#include "connect3.xpm" 20#include "connect3.xpm"
21#include "connect4.xpm" 21#include "connect4.xpm"
22#include "connect5.xpm" 22#include "connect5.xpm"
23#include "nowireless.xpm" 23#include "nowireless.xpm"
24 24
25/* OPIE */ 25/* OPIE */
26#include <opie2/onetwork.h> 26#include <opie2/onetwork.h>
27#include <opie2/otaskbarapplet.h> 27#include <opie2/otaskbarapplet.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29 29
30/* QT */ 30/* QT */
31#include <qradiobutton.h> 31#include <qradiobutton.h>
32#include <qpushbutton.h> 32#include <qpushbutton.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qlabel.h> 34#include <qlabel.h>
35#include <qslider.h> 35#include <qslider.h>
36#include <qbuttongroup.h> 36#include <qbuttongroup.h>
37#include <qlayout.h> 37#include <qlayout.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40 40
41/* STD */ 41/* STD */
42#include <sys/types.h> 42#include <sys/types.h>
43#include <signal.h> 43#include <signal.h>
44 44
45#define STYLE_BARS 0 45#define STYLE_BARS 0
46#define STYLE_ANTENNA 1 46#define STYLE_ANTENNA 1
47 47
48//#define MDEBUG 48//#define MDEBUG
49#undef MDEBUG 49#undef MDEBUG
50 50
51WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 51WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
52 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 52 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
53{ 53{
54 54
55 readConfig(); 55 readConfig();
56 writeConfigEntry( "UpdateFrequency", updateFrequency ); 56 writeConfigEntry( "UpdateFrequency", updateFrequency );
57 writeConfigEntry( "DisplayStyle", displayStyle ); 57 writeConfigEntry( "DisplayStyle", displayStyle );
58 58
59 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 59 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
60 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); 60 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
61 61
62 /* status label */ 62 /* status label */
63 63
64 statusLabel = new QLabel( this, "statuslabel" ); 64 statusLabel = new QLabel( this, "statuslabel" );
65 QString text( "Wireless Status:<br>" 65 QString text( "Wireless Status:<br>"
66 "*** Unknown ***<br>" 66 "*** Unknown ***<br>"
67 "Card not inserted ?<br>" 67 "Card not inserted ?<br>"
68 "Or Sharp ROM ?<br>" 68 "Or Sharp ROM ?<br>"
69 "CELL: 00:00:00:00:00:00" ); 69 "CELL: 00:00:00:00:00:00" );
70 /* QString text( "Station: Unknown<br>" 70 /* QString text( "Station: Unknown<br>"
71 "ESSID: Unknown<br>" 71 "ESSID: Unknown<br>"
72 "MODE: Unknown<br>" 72 "MODE: Unknown<br>"
73 "FREQ: Unknown<br>" 73 "FREQ: Unknown<br>"
74 "CELL: AA:BB:CC:DD:EE:FF" ); */ 74 "CELL: AA:BB:CC:DD:EE:FF" ); */
75 statusLabel->setText( text ); 75 statusLabel->setText( text );
76 statusLabel->setFixedSize( statusLabel->sizeHint() ); 76 statusLabel->setFixedSize( statusLabel->sizeHint() );
77 grid->addWidget( statusLabel, 0, 0 ); 77 grid->addWidget( statusLabel, 0, 0 );
78 78
79 /* visualization group box */ 79 /* visualization group box */
80 80
81 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); 81 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this );
82 QRadioButton* r1 = new QRadioButton( "Color Bars", group ); 82 QRadioButton* r1 = new QRadioButton( "Color Bars", group );
83 QRadioButton* r2 = new QRadioButton( "Antenna", group ); 83 QRadioButton* r2 = new QRadioButton( "Antenna", group );
84 r1->setFocusPolicy( QWidget::NoFocus ); 84 r1->setFocusPolicy( QWidget::NoFocus );
85 r2->setFocusPolicy( QWidget::NoFocus ); 85 r2->setFocusPolicy( QWidget::NoFocus );
86 group->setFocusPolicy( QWidget::NoFocus ); 86 group->setFocusPolicy( QWidget::NoFocus );
87 group->setButton( displayStyle ); 87 group->setButton( displayStyle );
88 grid->addWidget( group, 0, 1 ); 88 grid->addWidget( group, 0, 1 );
89 89
90 /* quality graph */ 90 /* quality graph */
91 91
92 mgraph = new MGraph( this ); 92 mgraph = new MGraph( this );
93 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 93 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
94 mgraph->setMin( 0 ); 94 mgraph->setMin( 0 );
95 mgraph->setMax( 92 ); 95 mgraph->setMax( 92 );
96 grid->addWidget( mgraph, 1, 0 ); 96 grid->addWidget( mgraph, 1, 0 );
97 mgraph->setFocusPolicy( QWidget::NoFocus ); 97 mgraph->setFocusPolicy( QWidget::NoFocus );
98 98
99 /* advanced configuration Button */ 99 /* advanced configuration Button */
100 100
101 QPushButton* advanced = new QPushButton( "Advanced...", this ); 101 QPushButton* advanced = new QPushButton( "Advanced...", this );
102 advanced->setFocusPolicy( QWidget::NoFocus ); 102 advanced->setFocusPolicy( QWidget::NoFocus );
103 grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); 103 grid->addWidget( advanced, 2, 0, Qt::AlignCenter );
104 connect( advanced, SIGNAL( clicked() ), 104 connect( advanced, SIGNAL( clicked() ),
105 this, SLOT( advancedConfigClicked() ) ); 105 this, SLOT( advancedConfigClicked() ) );
106 106
107 /* update Frequency Label */ 107 /* update Frequency Label */
108 108
109 updateLabel = new QLabel( this ); 109 updateLabel = new QLabel( this );
110 text.sprintf( "Update every %d s", updateFrequency ); 110 text.sprintf( "Update every %d s", updateFrequency );
111 updateLabel->setText( text ); 111 updateLabel->setText( text );
112 grid->addWidget( updateLabel, 2, 1 ); 112 grid->addWidget( updateLabel, 2, 1 );
113 113
114 /* update Frequency Slider */ 114 /* update Frequency Slider */
115 115
116 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); 116 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this );
117 updateSlider->setRange( 0, 9 ); 117 updateSlider->setRange( 0, 9 );
118 updateSlider->setValue( updateFrequency ); 118 updateSlider->setValue( updateFrequency );
119 updateSlider->setTickmarks( QSlider::Both ); 119 updateSlider->setTickmarks( QSlider::Both );
120 updateSlider->setTickInterval( 1 ); 120 updateSlider->setTickInterval( 1 );
121 updateSlider->setSteps( 1, 1 ); 121 updateSlider->setSteps( 1, 1 );
122 updateSlider->setFocusPolicy( QWidget::NoFocus ); 122 updateSlider->setFocusPolicy( QWidget::NoFocus );
123 grid->addWidget( updateSlider, 1, 1 ); 123 grid->addWidget( updateSlider, 1, 1 );
124 connect( updateSlider, SIGNAL( valueChanged( int ) ), 124 connect( updateSlider, SIGNAL( valueChanged(int) ),
125 this, SLOT( updateDelayChange( int ) ) ); 125 this, SLOT( updateDelayChange(int) ) );
126 126
127 setFixedSize( sizeHint() ); 127 setFixedSize( sizeHint() );
128 setFocusPolicy( QWidget::NoFocus ); 128 setFocusPolicy( QWidget::NoFocus );
129 129
130 applet->displayStyleChange( displayStyle ); 130 applet->displayStyleChange( displayStyle );
131 applet->updateDelayChange( updateFrequency ); 131 applet->updateDelayChange( updateFrequency );
132 132
133 connect( group, SIGNAL( clicked( int ) ), 133 connect( group, SIGNAL( clicked(int) ),
134 this, SLOT( displayStyleChange( int ) ) ); 134 this, SLOT( displayStyleChange(int) ) );
135 135
136 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 136 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
137} 137}
138 138
139void WirelessControl::advancedConfigClicked() 139void WirelessControl::advancedConfigClicked()
140{ 140{
141 AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE ); 141 AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE );
142 int result = a->exec(); 142 int result = a->exec();
143 a->hide(); 143 a->hide();
144 delete a; 144 delete a;
145 if ( result == QDialog::Accepted ) 145 if ( result == QDialog::Accepted )
146 { 146 {
147 readConfig(); 147 readConfig();
148 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 148 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
149 } 149 }
150} 150}
151 151
152void WirelessControl::updateDelayChange( int delay ) 152void WirelessControl::updateDelayChange( int delay )
153{ 153{
154 QString text; 154 QString text;
155 text.sprintf( "Update every %d s", delay ); 155 text.sprintf( "Update every %d s", delay );
156 updateLabel->setText( text ); 156 updateLabel->setText( text );
157 applet->updateDelayChange( delay ); 157 applet->updateDelayChange( delay );
158 writeConfigEntry( "UpdateFrequency", delay ); 158 writeConfigEntry( "UpdateFrequency", delay );
159} 159}
160 160
161void WirelessControl::displayStyleChange( int style ) 161void WirelessControl::displayStyleChange( int style )
162{ 162{
163 applet->displayStyleChange( style ); 163 applet->displayStyleChange( style );
164 writeConfigEntry( "DisplayStyle", style ); 164 writeConfigEntry( "DisplayStyle", style );
165} 165}
166 166
167void WirelessControl::show ( bool ) 167void WirelessControl::show ( bool )
168{ 168{
169 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); 169 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
170 170
171 int w = sizeHint().width(); 171 int w = sizeHint().width();
172 int x = curPos.x() - ( w / 2 ); 172 int x = curPos.x() - ( w / 2 );
173 173
174 if ( ( x + w ) > QPEApplication::desktop() ->width() ) 174 if ( ( x + w ) > QPEApplication::desktop() ->width() )
175 x = QPEApplication::desktop ( ) -> width ( ) - w; 175 x = QPEApplication::desktop ( ) -> width ( ) - w;
176 176
177 move( x, curPos.y () - sizeHint().height () ); 177 move( x, curPos.y () - sizeHint().height () );
178 QFrame::show(); 178 QFrame::show();
179} 179}
180 180
181void WirelessControl::readConfig() 181void WirelessControl::readConfig()
182{ 182{
183 Config cfg( "qpe" ); 183 Config cfg( "qpe" );
184 cfg.setGroup( "Wireless" ); 184 cfg.setGroup( "Wireless" );
185 185
186 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); 186 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 );
187 displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA ); 187 displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA );
188 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); 188 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false );
189 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); 189 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false );
190 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); 190 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false );
191 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); 191 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false );
192} 192}
193 193
194void WirelessControl::writeConfigEntry( const char *entry, int val ) 194void WirelessControl::writeConfigEntry( const char *entry, int val )
195{ 195{
196 Config cfg( "qpe" ); 196 Config cfg( "qpe" );
197 cfg.setGroup( "Wireless" ); 197 cfg.setGroup( "Wireless" );
198 cfg.writeEntry( entry, val ); 198 cfg.writeEntry( entry, val );
199} 199}
200 200
201//=========================================================================== 201//===========================================================================
202 202
203WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) 203WirelessApplet::WirelessApplet( QWidget *parent, const char *name )
204 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), 204 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ),
205 timer( 0 ), interface( 0 ), oldiface( 0 ), 205 timer( 0 ), interface( 0 ), oldiface( 0 ),
206 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) 206 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false )
207{ 207{
208 setFixedHeight( 18 ); 208 setFixedHeight( 18 );
209 setFixedWidth( 14 ); 209 setFixedWidth( 14 );
210 status = new WirelessControl( this, this, "wireless status" ); 210 status = new WirelessControl( this, this, "wireless status" );
211} 211}
212 212
213void WirelessApplet::checkInterface() 213void WirelessApplet::checkInterface()
214{ 214{
215 interface = 0L; 215 interface = 0L;
216 ONetwork* net = ONetwork::instance(); 216 ONetwork* net = ONetwork::instance();
217 net->synchronize(); 217 net->synchronize();
218 ONetwork::InterfaceIterator it = net->iterator(); 218 ONetwork::InterfaceIterator it = net->iterator();
219 219
220 while ( it.current() && !it.current()->isWireless() ) ++it; 220 while ( it.current() && !it.current()->isWireless() ) ++it;
221 221
222 if ( it.current() && it.current()->isWireless() ) 222 if ( it.current() && it.current()->isWireless() )
223 interface = static_cast<OWirelessNetworkInterface*>( it.current() ); 223 interface = static_cast<OWirelessNetworkInterface*>( it.current() );
224 224
225 if ( interface ) 225 if ( interface )
226 { 226 {
227#ifdef MDEBUG 227#ifdef MDEBUG
228 qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() ); 228 qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() );
229#endif 229#endif
230 230
231 } 231 }
232 else 232 else
233 { 233 {
234#ifdef MDEBUG 234#ifdef MDEBUG
235 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); 235 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" );
236#endif 236#endif
237 hide(); 237 hide();
238 } 238 }
239} 239}
240 240
241void WirelessApplet::renewDHCP() 241void WirelessApplet::renewDHCP()
242{ 242{
243#ifdef MDEBUG 243#ifdef MDEBUG
244 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); 244 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." );
245#endif 245#endif
246 246
247 QString pidfile; 247 QString pidfile;
248 if ( !interface ) 248 if ( !interface )
249 return ; 249 return ;
250 QString ifacename( interface->name() ); 250 QString ifacename( interface->name() );
251 251
252 // At first we are trying dhcpcd 252 // At first we are trying dhcpcd
253 253
254 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename ); 254 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename );
255#ifdef MDEBUG 255#ifdef MDEBUG
256 qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile ); 256 qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile );
257#endif 257#endif
258 int pid; 258 int pid;
259 QFile pfile( pidfile ); 259 QFile pfile( pidfile );
260 bool hasFile = pfile.open( IO_ReadOnly ); 260 bool hasFile = pfile.open( IO_ReadOnly );
261 QTextStream s( &pfile ); 261 QTextStream s( &pfile );
262 if ( hasFile ) 262 if ( hasFile )
263 { 263 {
264 s >> pid; 264 s >> pid;
265#ifdef MDEBUG 265#ifdef MDEBUG
266 qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid ); 266 qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid );
267#endif 267#endif
268 kill( pid, SIGALRM ); 268 kill( pid, SIGALRM );
269 return ; 269 return ;
270 } 270 }
271 271
272 // No dhcpcd, so we are trying udhcpc 272 // No dhcpcd, so we are trying udhcpc
273#ifdef MDEBUG 273#ifdef MDEBUG
274 qDebug( "WIFIAPPLET: dhcpcd not available." ); 274 qDebug( "WIFIAPPLET: dhcpcd not available." );
275#endif 275#endif
276 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename ); 276 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename );
277#ifdef MDEBUG 277#ifdef MDEBUG
278 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile ); 278 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile );
279#endif 279#endif
280 QFile pfile2( pidfile ); 280 QFile pfile2( pidfile );
281 hasFile = pfile2.open( IO_ReadOnly ); 281 hasFile = pfile2.open( IO_ReadOnly );
282 QTextStream s2( &pfile2 ); 282 QTextStream s2( &pfile2 );
283 if ( hasFile ) 283 if ( hasFile )
284 { 284 {
285 s2 >> pid; 285 s2 >> pid;
286#ifdef MDEBUG 286#ifdef MDEBUG
287 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); 287 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid );
288#endif 288#endif
289 kill( pid, SIGUSR1 ); 289 kill( pid, SIGUSR1 );
290 return ; 290 return ;
291 } 291 }
292} 292}
293 293
294void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) 294void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE )
295{ 295{
296 rocESSID = ESSID; 296 rocESSID = ESSID;
297 rocFREQ = FREQ; 297 rocFREQ = FREQ;
298 rocAP = AP; 298 rocAP = AP;
299 rocMODE = MODE; 299 rocMODE = MODE;
300} 300}
301 301
302void WirelessApplet::updateDelayChange( int delay ) 302void WirelessApplet::updateDelayChange( int delay )
303{ 303{
304 if ( timer ) 304 if ( timer )
305 killTimer( timer ); 305 killTimer( timer );
306 delay *= 1000; 306 delay *= 1000;
307 if ( delay == 0 ) 307 if ( delay == 0 )
308 delay = 50; 308 delay = 50;
309 timer = startTimer( delay ); 309 timer = startTimer( delay );
310} 310}
311 311
312void WirelessApplet::displayStyleChange( int style ) 312void WirelessApplet::displayStyleChange( int style )
313{ 313{
314 visualStyle = style; 314 visualStyle = style;
315 repaint(); 315 repaint();
316} 316}
317 317
318WirelessApplet::~WirelessApplet() 318WirelessApplet::~WirelessApplet()
319{} 319{}
320 320
321void WirelessApplet::timerEvent( QTimerEvent* ) 321void WirelessApplet::timerEvent( QTimerEvent* )
322{ 322{
323#ifdef MDEBUG 323#ifdef MDEBUG
324 qDebug( "WirelessApplet::timerEvent" ); 324 qDebug( "WirelessApplet::timerEvent" );
325#endif 325#endif
326 if ( interface ) 326 if ( interface )