author | mickeyl <mickeyl> | 2002-08-31 10:43:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2002-08-31 10:43:26 (UTC) |
commit | cd33eed8d5eccebdc37dcd0e30d7917b91765222 (patch) (unidiff) | |
tree | cec3d088b58501bcc660686f468c4a968dc2d729 /noncore/applets/wirelessapplet/wireless.cpp | |
parent | 3b720187b21a3b9b3d17fc2b26489723febdaec2 (diff) | |
download | opie-cd33eed8d5eccebdc37dcd0e30d7917b91765222.zip opie-cd33eed8d5eccebdc37dcd0e30d7917b91765222.tar.gz opie-cd33eed8d5eccebdc37dcd0e30d7917b91765222.tar.bz2 |
- debug output is now #ifdef'd
- wireless applet icon shows on demand (like cardmon
- applet has an advanced configuration dialog
- applet features experimental dhcp renew on change of essid/freq/ap/mode
Diffstat (limited to 'noncore/applets/wirelessapplet/wireless.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/wirelessapplet/wireless.cpp | 149 |
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 | |||
@@ -18,37 +18,45 @@ | |||
18 | #include <qapplication.h> | 18 | #include <qapplication.h> |
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/config.h> | 20 | #include <qpe/config.h> |
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> |
28 | #include <qbuttongroup.h> | 28 | #include <qbuttongroup.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qframe.h> | 30 | #include <qframe.h> |
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" |
41 | #include "connect3.xpm" | 47 | #include "connect3.xpm" |
42 | #include "connect4.xpm" | 48 | #include "connect4.xpm" |
43 | #include "connect5.xpm" | 49 | #include "connect5.xpm" |
44 | #include "nowireless.xpm" | 50 | #include "nowireless.xpm" |
45 | 51 | ||
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 | |||
49 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) | 57 | WirelessControl::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 | { |
52 | 60 | ||
53 | readConfig(); | 61 | readConfig(); |
54 | writeConfigEntry( "UpdateFrequency", updateFrequency ); | 62 | writeConfigEntry( "UpdateFrequency", updateFrequency ); |
@@ -91,18 +99,19 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const | |||
91 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 99 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
92 | mgraph->setMin( 0 ); | 100 | mgraph->setMin( 0 ); |
93 | mgraph->setMax( 92 ); | 101 | mgraph->setMax( 92 ); |
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 | ||
106 | updateLabel = new QLabel( this ); | 115 | updateLabel = new QLabel( this ); |
107 | text.sprintf( "Update every %d s", updateFrequency ); | 116 | text.sprintf( "Update every %d s", updateFrequency ); |
108 | updateLabel->setText( text ); | 117 | updateLabel->setText( text ); |
@@ -125,13 +134,28 @@ WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const | |||
125 | setFocusPolicy( QWidget::NoFocus ); | 134 | setFocusPolicy( QWidget::NoFocus ); |
126 | 135 | ||
127 | applet->displayStyleChange( displayStyle ); | 136 | applet->displayStyleChange( displayStyle ); |
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 | |||
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 | } |
133 | 157 | ||
134 | void WirelessControl::updateDelayChange( int delay ) | 158 | void WirelessControl::updateDelayChange( int delay ) |
135 | { | 159 | { |
136 | QString text; | 160 | QString text; |
137 | text.sprintf( "Update every %d s", delay ); | 161 | text.sprintf( "Update every %d s", delay ); |
@@ -163,13 +187,17 @@ void WirelessControl::show ( bool ) | |||
163 | void WirelessControl::readConfig() | 187 | void WirelessControl::readConfig() |
164 | { | 188 | { |
165 | Config cfg( "qpe" ); | 189 | Config cfg( "qpe" ); |
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 | ||
172 | void WirelessControl::writeConfigEntry( const char *entry, int val ) | 200 | void WirelessControl::writeConfigEntry( const char *entry, int val ) |
173 | { | 201 | { |
174 | Config cfg( "qpe" ); | 202 | Config cfg( "qpe" ); |
175 | cfg.setGroup( "Wireless" ); | 203 | cfg.setGroup( "Wireless" ); |
@@ -177,34 +205,75 @@ void WirelessControl::writeConfigEntry( const char *entry, int val ) | |||
177 | } | 205 | } |
178 | 206 | ||
179 | //=========================================================================== | 207 | //=========================================================================== |
180 | 208 | ||
181 | WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) | 209 | 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 | { |
185 | setFixedHeight( 18 ); | 214 | setFixedHeight( 18 ); |
186 | setFixedWidth( 14 ); | 215 | setFixedWidth( 14 ); |
187 | network = new MWirelessNetwork(); | 216 | network = new MWirelessNetwork(); |
188 | status = new WirelessControl( this, 0, "wireless status" ); | 217 | status = new WirelessControl( this, 0, "wireless status" ); |
189 | } | 218 | } |
190 | 219 | ||
191 | void WirelessApplet::checkInterface() | 220 | void WirelessApplet::checkInterface() |
192 | { | 221 | { |
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 | ||
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 | |||
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; | ||
272 | } | ||
273 | |||
205 | void WirelessApplet::updateDelayChange( int delay ) | 274 | void WirelessApplet::updateDelayChange( int delay ) |
206 | { | 275 | { |
207 | if ( timer ) | 276 | if ( timer ) |
208 | killTimer( timer ); | 277 | killTimer( timer ); |
209 | delay *= 1000; | 278 | delay *= 1000; |
210 | if ( delay == 0 ) | 279 | if ( delay == 0 ) |
@@ -225,13 +294,19 @@ WirelessApplet::~WirelessApplet() | |||
225 | void WirelessApplet::timerEvent( QTimerEvent* ) | 294 | void WirelessApplet::timerEvent( QTimerEvent* ) |
226 | { | 295 | { |
227 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 296 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
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." ); |
235 | repaint(); | 310 | repaint(); |
236 | } | 311 | } |
237 | 312 | ||
@@ -255,14 +330,28 @@ bool WirelessApplet::mustRepaint() | |||
255 | // check if there are enough changes to justify a (flickering) repaint | 330 | // check if there are enough changes to justify a (flickering) repaint |
256 | 331 | ||
257 | // has the interface changed? | 332 | // has the interface changed? |
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(); |
266 | 355 | ||
267 | if ( pixmap && ( pixmap != oldpixmap ) ) | 356 | if ( pixmap && ( pixmap != oldpixmap ) ) |
268 | { | 357 | { |
@@ -280,12 +369,46 @@ bool WirelessApplet::mustRepaint() | |||
280 | { | 369 | { |
281 | oldnoiseH = noiseH; | 370 | oldnoiseH = noiseH; |
282 | oldsignalH = signalH; | 371 | oldsignalH = signalH; |
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 | } |
289 | 412 | ||
290 | void WirelessApplet::updatePopupWindow() | 413 | void WirelessApplet::updatePopupWindow() |
291 | { | 414 | { |
@@ -331,13 +454,13 @@ void WirelessApplet::paintEvent( QPaintEvent* ) | |||
331 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 454 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
332 | 455 | ||
333 | QPainter p(this); | 456 | QPainter p(this); |
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 |
341 | { | 464 | { |
342 | 465 | ||
343 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; | 466 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; |