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.cpp149
1 files changed, 136 insertions, 13 deletions
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
@@ -21,7 +21,7 @@
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>
@@ -31,10 +31,16 @@
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"
@@ -46,6 +52,8 @@
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{
@@ -94,12 +102,13 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const
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
@@ -128,7 +137,22 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const
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 )
@@ -166,7 +190,11 @@ void WirelessControl::readConfig()
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 )
@@ -180,7 +208,8 @@ void WirelessControl::writeConfigEntry( const char *entry, int val )
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 );
@@ -193,15 +222,55 @@ void WirelessApplet::checkInterface()
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 )
@@ -228,7 +297,13 @@ void WirelessApplet::timerEvent( QTimerEvent* )
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." );
@@ -258,8 +333,22 @@ bool WirelessApplet::mustRepaint()
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();
@@ -283,6 +372,40 @@ bool WirelessApplet::mustRepaint()
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}
@@ -334,7 +457,7 @@ void WirelessApplet::paintEvent( QPaintEvent* )
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