Diffstat (limited to 'noncore/applets/wirelessapplet/wireless.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/applets/wirelessapplet/wireless.cpp | 139 |
1 files changed, 131 insertions, 8 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 | |||
@@ -23,3 +23,3 @@ | |||
23 | #include <qradiobutton.h> | 23 | #include <qradiobutton.h> |
24 | #include <qcheckbox.h> | 24 | #include <qpushbutton.h> |
25 | #include <qpainter.h> | 25 | #include <qpainter.h> |
@@ -33,2 +33,6 @@ | |||
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qtextstream.h> | ||
35 | |||
36 | #include <sys/types.h> | ||
37 | #include <signal.h> | ||
34 | 38 | ||
@@ -37,2 +41,4 @@ | |||
37 | 41 | ||
42 | #include "advancedconfig.h" | ||
43 | |||
38 | #include "connect0.xpm" | 44 | #include "connect0.xpm" |
@@ -48,2 +54,4 @@ | |||
48 | 54 | ||
55 | #define MDEBUG 0 | ||
56 | |||
49 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) | 57 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) |
@@ -96,8 +104,9 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const | |||
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 | ||
@@ -131,2 +140,17 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const | |||
131 | this, SLOT( displayStyleChange( int ) ) ); | 140 | this, SLOT( displayStyleChange( int ) ) ); |
141 | |||
142 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); | ||
143 | } | ||
144 | |||
145 | void 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 | } |
@@ -169,2 +193,6 @@ void WirelessControl::readConfig() | |||
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 | } |
@@ -182,3 +210,4 @@ WirelessApplet::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 | { |
@@ -195,3 +224,5 @@ void WirelessApplet::checkInterface() | |||
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() ); |
@@ -200,4 +231,42 @@ void WirelessApplet::checkInterface() | |||
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 | ||
236 | } | ||
237 | } | ||
238 | |||
239 | void 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 | |||
202 | } | 264 | } |
265 | |||
266 | void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) | ||
267 | { | ||
268 | rocESSID = ESSID; | ||
269 | rocFREQ = FREQ; | ||
270 | rocAP = AP; | ||
271 | rocMODE = MODE; | ||
203 | } | 272 | } |
@@ -230,3 +299,9 @@ void WirelessApplet::timerEvent( QTimerEvent* ) | |||
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() ) |
@@ -261,4 +336,18 @@ bool WirelessApplet::mustRepaint() | |||
261 | oldiface = iface; | 336 | oldiface = iface; |
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(); | ||
262 | return true; | 350 | return true; |
263 | } | 351 | } |
352 | } | ||
264 | 353 | ||
@@ -286,2 +375,36 @@ bool WirelessApplet::mustRepaint() | |||
286 | 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; | ||
409 | |||
287 | return false; | 410 | return false; |