summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-28 04:48:35 (UTC)
committer sandman <sandman>2002-10-28 04:48:35 (UTC)
commitcb687974f9e97c0ce6117b0ac4551ad4d4342b6a (patch) (unidiff)
tree3128de5e3647a786bcc47a5fb14af06ba65f2a09
parentf3c9e44d9d694a0a803fb6a7d79cfa8d173b9864 (diff)
downloadopie-cb687974f9e97c0ce6117b0ac4551ad4d4342b6a.zip
opie-cb687974f9e97c0ce6117b0ac4551ad4d4342b6a.tar.gz
opie-cb687974f9e97c0ce6117b0ac4551ad4d4342b6a.tar.bz2
- moved the QPEScreenSaver to screensaver.cpp/.h and renamed the class to
OpieScreenSaver - (hopefully) fixed all outstanding bugs regarding the new on batt/on ac handling - first (primitive) version of light sensor control (but it works)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp345
-rw-r--r--core/launcher/desktop.h7
-rw-r--r--core/launcher/launcher.pro2
-rw-r--r--core/launcher/screensaver.cpp237
-rw-r--r--core/launcher/screensaver.h61
5 files changed, 354 insertions, 298 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 2ea6d27..bc43475 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -7,48 +7,49 @@
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#include "desktop.h"
22#include "info.h" 22#include "info.h"
23#include "launcher.h" 23#include "launcher.h"
24#include "qcopbridge.h" 24#include "qcopbridge.h"
25#include "shutdownimpl.h" 25#include "shutdownimpl.h"
26#include "startmenu.h" 26#include "startmenu.h"
27#include "taskbar.h" 27#include "taskbar.h"
28#include "transferserver.h" 28#include "transferserver.h"
29#include "irserver.h" 29#include "irserver.h"
30#include "packageslave.h" 30#include "packageslave.h"
31#include "screensaver.h"
31 32
32#include <qpe/applnk.h> 33#include <qpe/applnk.h>
33#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
34#include <qpe/password.h> 35#include <qpe/password.h>
35#include <qpe/config.h> 36#include <qpe/config.h>
36#include <qpe/power.h> 37#include <qpe/power.h>
37#include <qpe/timeconversion.h> 38#include <qpe/timeconversion.h>
38#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
39#include <qpe/network.h> 40#include <qpe/network.h>
40#include <qpe/global.h> 41#include <qpe/global.h>
41 42
42#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 43#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
43#include <qpe/custom.h> 44#include <qpe/custom.h>
44#endif 45#endif
45 46
46#include <opie/odevice.h> 47#include <opie/odevice.h>
47 48
48#include <qgfx_qws.h> 49#include <qgfx_qws.h>
49#include <qmainwindow.h> 50#include <qmainwindow.h>
50#include <qmessagebox.h> 51#include <qmessagebox.h>
51#include <qtimer.h> 52#include <qtimer.h>
52#include <qwindowsystem_qws.h> 53#include <qwindowsystem_qws.h>
53 54
54#include <qvaluelist.h> 55#include <qvaluelist.h>
@@ -130,373 +131,162 @@ private:
130 int currentPriority; 131 int currentPriority;
131 int alertCount; 132 int alertCount;
132}; 133};
133 134
134void DesktopPowerAlerter::alert( const QString &text, int priority ) 135void DesktopPowerAlerter::alert( const QString &text, int priority )
135{ 136{
136 alertCount++; 137 alertCount++;
137 if ( alertCount < priority ) 138 if ( alertCount < priority )
138 return ; 139 return ;
139 if ( priority > currentPriority ) 140 if ( priority > currentPriority )
140 return ; 141 return ;
141 currentPriority = priority; 142 currentPriority = priority;
142 setText( text ); 143 setText( text );
143 show(); 144 show();
144} 145}
145 146
146 147
147void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 148void DesktopPowerAlerter::hideEvent( QHideEvent *e )
148{ 149{
149 QMessageBox::hideEvent( e ); 150 QMessageBox::hideEvent( e );
150 alertCount = 0; 151 alertCount = 0;
151 currentPriority = INT_MAX; 152 currentPriority = INT_MAX;
152} 153}
153 154
154class QPEScreenSaver : public QWSScreenSaver
155{
156private:
157 int LcdOn;
158
159public:
160 QPEScreenSaver()
161 {
162 m_disable_suspend = 100;
163 m_enable_dim = false;
164 m_enable_lightoff = false;
165 m_enable_onlylcdoff = false;
166
167 m_disable_suspend_ac = 100;
168 m_enable_dim_ac = false;
169 m_enable_lightoff_ac = false;
170 m_enable_onlylcdoff_ac = false;
171 m_disable_apm_ac = false;
172
173 m_lcd_status = true;
174
175 m_backlight_normal = -1;
176 m_backlight_current = -1;
177 m_backlight_forcedoff = false;
178
179 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
180 ODevice::inst ( )-> setDisplayStatus ( true );
181 setBacklight ( -1 );
182 }
183 void restore()
184 {
185 if ( !m_lcd_status ) { // We must have turned it off
186 ODevice::inst ( ) -> setDisplayStatus ( true );
187 m_lcd_status = true;
188 }
189
190 setBacklightInternal ( -1 );
191 }
192 bool save( int level )
193 {
194 bool onAC = ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online );
195
196 switch ( level ) {
197 case 0:
198
199 if ( m_disable_suspend_ac > 0 && m_enable_dim_ac && onAC ) {
200 if ( m_backlight_current > 1 )
201 setBacklight( 1 ); // lowest non-off
202 } else if ( !onAC && m_disable_suspend > 0 && m_enable_dim ) {
203 if ( m_backlight_current > 1 )
204 setBacklightInternal( 1 ); // lowest non-off
205 }
206 return true;
207 break;
208 case 1:
209
210 if ( m_disable_suspend_ac > 1 && m_enable_lightoff_ac && onAC ) {
211 setBacklightInternal( 0 ); // off
212 } else if ( !onAC && m_disable_suspend > 1 && m_enable_lightoff ) {
213 setBacklightInternal( 0 ); // off
214 }
215 return true;
216 break;
217 case 2:
218 if ( m_disable_apm_ac && onAC ) {
219 return true;
220 }
221
222 if ( m_enable_onlylcdoff_ac && onAC ) {
223 ODevice::inst ( ) -> setDisplayStatus ( false );
224 m_lcd_status = false;
225 return true;
226 }
227 else if ( !onAC && m_enable_onlylcdoff ) {
228 ODevice::inst ( ) -> setDisplayStatus ( false );
229 m_lcd_status = false;
230 return true;
231 }
232 else // We're going to suspend the whole machine
233 {
234 if ( ( m_disable_suspend_ac > 2 && onAC ) && ( !Network::networkOnline ( ) ) ) {
235 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
236 return true;
237 }
238 if ( !onAC && ( m_disable_suspend > 2 ) && ( !Network::networkOnline ( ) ) ) {
239 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
240 return true;
241 }
242 }
243 break;
244 }
245 return false;
246 }
247
248private:
249 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def )
250 {
251 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 )
252 return 0;
253
254 if ( interval < 0 ) {
255 // Restore screen blanking and power saving state
256 interval = config.readNumEntry( value, def );
257 }
258 return interval;
259 }
260
261public:
262 void setIntervals( int i1, int i2, int i3 )
263 {
264 Config config( "qpe" );
265 config.setGroup( "Screensaver" );
266
267 int v[ 4 ];
268 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 );
269 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 );
270 i3 = ssi( i3, config, "", "Interval", 60 );
271
272 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
273
274 v [ 0 ] = QMAX( 1000 * i1, 100 );
275 v [ 1 ] = QMAX( 1000 * i2, 100 );
276 v [ 2 ] = QMAX( 1000 * i3, 100 );
277 v [ 3 ] = 0;
278 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false );
279 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false );
280 m_enable_onlylcdoff = config.readNumEntry ( "LcdOffOnly", 0 );
281
282 if ( !i1 && !i2 && !i3 )
283 QWSServer::setScreenSaverInterval( 0 );
284 else
285 QWSServer::setScreenSaverIntervals( v );
286 }
287
288 void setIntervalsAC( int i1, int i2, int i3 )
289 {
290 Config config( "qpe" );
291 config.setGroup( "Screensaver" );
292
293 int v[ 4 ];
294 i1 = ssi( i1, config, "DimAC", "Interval_DimAC", 30 );
295 i2 = ssi( i2, config, "LightOffAC", "Interval_LightOffAC", 20 );
296 i3 = ssi( i3, config, "", "IntervalAC", 60 );
297
298 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
299
300 v [ 0 ] = QMAX( 1000 * i1, 100 );
301 v [ 1 ] = QMAX( 1000 * i2, 100 );
302 v [ 2 ] = QMAX( 1000 * i3, 100 );
303 v [ 3 ] = 0;
304 m_enable_dim_ac = ( ( i1 != 0 ) ? config.readNumEntry ( "DimAC", 1 ) : false );
305 m_enable_lightoff_ac = ( ( i2 != 0 ) ? config.readNumEntry ( "LightOffAC", 1 ) : false );
306 m_enable_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnlyAC", 0 );
307 m_disable_apm_ac = config.readNumEntry ( "NoApmAC", 0 );
308
309 if ( !i1 && !i2 && !i3 )
310 QWSServer::setScreenSaverInterval( 0 );
311 else
312 QWSServer::setScreenSaverIntervals( v );
313 }
314
315 void setInterval ( int interval )
316 {
317 setIntervals ( -1, -1, interval );
318 setIntervalsAC ( -1, -1, interval );
319 }
320
321 void setMode ( int mode )
322 {
323 if ( mode > m_disable_suspend )
324 setInterval( -1 );
325 m_disable_suspend = mode;
326 }
327
328 void setBacklight ( int bright )
329 {
330 // Read from config
331 Config config ( "qpe" );
332 config. setGroup ( "Screensaver" );
333 m_backlight_normal = config. readNumEntry ( "Brightness", 255 );
334
335 setBacklightInternal ( bright );
336 }
337
338private:
339 void setBacklightInternal ( int bright )
340 {
341 if ( bright == -3 ) {
342 // Forced on
343 m_backlight_forcedoff = false;
344 bright = -1;
345 }
346 if ( m_backlight_forcedoff && bright != -2 )
347 return ;
348 if ( bright == -2 ) {
349 // Toggle between off and on
350 bright = m_backlight_current ? 0 : -1;
351 m_backlight_forcedoff = !bright;
352 }
353 if ( bright == -1 )
354 bright = m_backlight_normal;
355
356 if ( bright != m_backlight_current ) {
357 ODevice::inst ( )-> setDisplayBrightness ( bright );
358 m_backlight_current = bright;
359 }
360 }
361
362public:
363 void setDisplayState ( bool on )
364 {
365 if ( m_lcd_status != on ) {
366 ODevice::inst ( ) -> setDisplayStatus ( on );
367 m_lcd_status = on;
368 }
369 }
370
371private:
372 int m_disable_suspend;
373 bool m_enable_dim;
374 bool m_enable_lightoff;
375 bool m_enable_onlylcdoff;
376
377 int m_disable_suspend_ac;
378 bool m_enable_dim_ac;
379 bool m_enable_lightoff_ac;
380 bool m_enable_onlylcdoff_ac;
381 bool m_disable_apm_ac;
382
383 bool m_lcd_status;
384
385 int m_backlight_normal;
386 int m_backlight_current;
387 bool m_backlight_forcedoff;
388};
389 155
390void DesktopApplication::switchLCD ( bool on ) 156void DesktopApplication::switchLCD ( bool on )
391{ 157{
392 if ( qApp ) { 158 if ( qApp ) {
393 DesktopApplication *dapp = (DesktopApplication *) qApp; 159 DesktopApplication *dapp = (DesktopApplication *) qApp;
394 160
395 if ( dapp-> m_screensaver ) { 161 if ( dapp-> m_screensaver ) {
396 if ( on ) { 162 if ( on ) {
397 dapp-> m_screensaver-> setDisplayState ( true ); 163 dapp-> m_screensaver-> setDisplayState ( true );
398 dapp-> m_screensaver-> setBacklight ( -3 ); 164 dapp-> m_screensaver-> setBacklight ( -3 );
399 } 165 }
400 else { 166 else {
401 dapp-> m_screensaver-> setDisplayState ( false ); 167 dapp-> m_screensaver-> setDisplayState ( false );
402 } 168 }
403 } 169 }
404 } 170 }
405} 171}
406 172
407 173
408DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) 174DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
409 : QPEApplication( argc, argv, appType ) 175 : QPEApplication( argc, argv, appType )
410{ 176{
411 177
412 m_timer = new QTimer( this ); 178 Config cfg( "apm" );
413 connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); 179 cfg.setGroup( "Warnings" );
414 Config cfg( "apm" );
415 cfg.setGroup( "Warnings" );
416 m_timer->start( 5000 );
417 //cfg.readNumEntry( "checkinterval", 10000 ) 180 //cfg.readNumEntry( "checkinterval", 10000 )
418 m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); 181 m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 );
419 m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); 182 m_powerCritical = cfg.readNumEntry( "powercritical", 5 );
420 ps = new PowerStatus; 183
421 pa = new DesktopPowerAlerter( 0 ); 184 m_ps = new PowerStatus;
185 m_ps_last = new PowerStatus;
186 pa = new DesktopPowerAlerter( 0 );
422 187
423 channel = new QCopChannel( "QPE/Desktop", this ); 188 m_timer = new QTimer( this );
424 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 189 connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) );
425 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); 190 m_timer->start( 5000 );
191
192 channel = new QCopChannel( "QPE/Desktop", this );
193 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
194 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) );
426 195
427 channel = new QCopChannel( "QPE/System", this ); 196 channel = new QCopChannel( "QPE/System", this );
428 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 197 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
429 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); 198 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
430 199
431 m_screensaver = new QPEScreenSaver; 200 m_screensaver = new OpieScreenSaver ( );
432 201 m_screensaver-> setInterval ( -1 );
433 m_screensaver-> setInterval ( -1 ); 202 QWSServer::setScreenSaver( m_screensaver );
434 QWSServer::setScreenSaver( m_screensaver ); 203
204 apmTimeout ( );
435} 205}
436 206
437 207
438DesktopApplication::~DesktopApplication() 208DesktopApplication::~DesktopApplication()
439{ 209{
440 delete ps; 210 delete m_ps;
441 delete pa; 211 delete m_ps_last;
212 delete pa;
213}
214
215void DesktopApplication::apmTimeout()
216{
217 qpedesktop->checkMemory(); // in case no events are being generated
218
219 *m_ps_last = *m_ps;
220 *m_ps = PowerStatusManager::readStatus();
221
222 if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( ))
223 m_screensaver-> powerStatusChanged ( *m_ps );
224
225 int bat = m_ps-> batteryPercentRemaining ( );
226
227 if ( m_ps_last-> batteryPercentRemaining ( ) != bat ) {
228 if ( bat <= m_powerCritical )
229 pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 );
230 else if ( bat <= m_powerVeryLow )
231 pa->alert( tr( "Battery is running very low." ), 2 );
232
233
234 if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow )
235 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 );
236 }
442} 237}
443 238
444void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) 239void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data )
445{ 240{
446 QDataStream stream( data, IO_ReadOnly ); 241 QDataStream stream( data, IO_ReadOnly );
447 if ( msg == "keyRegister(int key, QString channel, QString message)" ) { 242 if ( msg == "keyRegister(int key, QString channel, QString message)" ) {
448 int k; 243 int k;
449 QString c, m; 244 QString c, m;
450 stream >> k; 245 stream >> k;
451 stream >> c; 246 stream >> c;
452 stream >> m; 247 stream >> m;
453 248
454 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); 249 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m );
455 keyRegisterList.append( QCopKeyRegister( k, c, m ) ); 250 keyRegisterList.append( QCopKeyRegister( k, c, m ) );
456 } 251 }
457} 252}
458 253
459 254
460void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) 255void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data )
461{ 256{
462 QDataStream stream ( data, IO_ReadOnly ); 257 QDataStream stream ( data, IO_ReadOnly );
463 258
464 if ( msg == "setScreenSaverInterval(int)" ) { 259 if ( msg == "setScreenSaverInterval(int)" ) {
465 int time; 260 int time;
466 stream >> time; 261 stream >> time;
467 m_screensaver-> setInterval( time ); 262 m_screensaver-> setInterval( time );
468 } 263 }
469 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 264 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
470 int t1, t2, t3; 265 int t1, t2, t3;
471 stream >> t1 >> t2 >> t3; 266 stream >> t1 >> t2 >> t3;
472 m_screensaver-> setIntervals( t1, t2, t3 ); 267 m_screensaver-> setIntervals( t1, t2, t3 );
473 } 268 }
474 else if ( msg == "setScreenSaverIntervalsAC(int,int,int)" ) {
475 int t1, t2, t3;
476 stream >> t1 >> t2 >> t3;
477 m_screensaver-> setIntervalsAC( t1, t2, t3 );
478 }
479 else if ( msg == "setBacklight(int)" ) { 269 else if ( msg == "setBacklight(int)" ) {
480 int bright; 270 int bright;
481 stream >> bright; 271 stream >> bright;
482 m_screensaver-> setBacklight( bright ); 272 m_screensaver-> setBacklight( bright );
483 } 273 }
484 else if ( msg == "setScreenSaverMode(int)" ) { 274 else if ( msg == "setScreenSaverMode(int)" ) {
485 int mode; 275 int mode;
486 stream >> mode; 276 stream >> mode;
487 m_screensaver-> setMode ( mode ); 277 m_screensaver-> setMode ( mode );
488 } 278 }
489 else if ( msg == "reloadPowerWarnSettings()" ) { 279 else if ( msg == "reloadPowerWarnSettings()" ) {
490 reloadPowerWarnSettings(); 280 reloadPowerWarnSettings();
491 } 281 }
492 else if ( msg == "setDisplayState(int)" ) { 282 else if ( msg == "setDisplayState(int)" ) {
493 int state; 283 int state;
494 stream >> state; 284 stream >> state;
495 m_screensaver-> setDisplayState ( state != 0 ); 285 m_screensaver-> setDisplayState ( state != 0 );
496 } 286 }
497 else if ( msg == "suspend()" ) { 287 else if ( msg == "suspend()" ) {
498 emit power(); 288 emit power();
499 } 289 }
500} 290}
501 291
502void DesktopApplication::reloadPowerWarnSettings() { 292void DesktopApplication::reloadPowerWarnSettings() {
@@ -618,81 +408,48 @@ bool DesktopApplication::qwsEventFilter( QWSEvent *e )
618 } 408 }
619 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) 409 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) )
620 qpedesktop->keyClick(); 410 qpedesktop->keyClick();
621 } 411 }
622 else { 412 else {
623 if ( e->type == QWSEvent::Mouse ) { 413 if ( e->type == QWSEvent::Mouse ) {
624 QWSMouseEvent * me = ( QWSMouseEvent * ) e; 414 QWSMouseEvent * me = ( QWSMouseEvent * ) e;
625 static bool up = TRUE; 415 static bool up = TRUE;
626 if ( me->simpleData.state & LeftButton ) { 416 if ( me->simpleData.state & LeftButton ) {
627 if ( up ) { 417 if ( up ) {
628 up = FALSE; 418 up = FALSE;
629 qpedesktop->screenClick(); 419 qpedesktop->screenClick();
630 } 420 }
631 } 421 }
632 else { 422 else {
633 up = TRUE; 423 up = TRUE;
634 } 424 }
635 } 425 }
636 } 426 }
637 427
638 return QPEApplication::qwsEventFilter( e ); 428 return QPEApplication::qwsEventFilter( e );
639} 429}
640#endif 430#endif
641 431
642void DesktopApplication::psTimeout( int batRemaining )
643{
644 *ps = PowerStatusManager::readStatus();
645
646 // maybe now since its triggered by apm change there might be to few warnings
647 // if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) {
648 if ( ( batRemaining == m_powerVeryLow ) ) {
649 pa->alert( tr( "Battery is running very low." ), 2 );
650 }
651
652 // if ( ps->batteryStatus() == PowerStatus::Critical ) {
653 if ( batRemaining == m_powerCritical ) {
654 pa->alert( tr( "Battery level is critical!\n"
655 "Keep power off until power restored!" ), 1 );
656 }
657
658 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
659 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 );
660 }
661}
662
663void DesktopApplication::apmTimeout()
664{
665 qpedesktop->checkMemory(); // in case no events are being generated
666
667 *ps = PowerStatusManager::readStatus();
668
669 if ( m_currentPowerLevel != ps->batteryPercentRemaining() ) {
670 // not very nice, since psTimeout parses the again
671 m_currentPowerLevel = ps->batteryPercentRemaining();
672 psTimeout( m_currentPowerLevel );
673 }
674}
675 432
676void DesktopApplication::sendCard() 433void DesktopApplication::sendCard()
677{ 434{
678 delete cardSendTimer; 435 delete cardSendTimer;
679 cardSendTimer = 0; 436 cardSendTimer = 0;
680 QString card = getenv( "HOME" ); 437 QString card = getenv( "HOME" );
681 card += "/Applications/addressbook/businesscard.vcf"; 438 card += "/Applications/addressbook/businesscard.vcf";
682 439
683 if ( QFile::exists( card ) ) { 440 if ( QFile::exists( card ) ) {
684 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); 441 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" );
685 QString mimetype = "text/x-vCard"; 442 QString mimetype = "text/x-vCard";
686 e << tr( "business card" ) << card << mimetype; 443 e << tr( "business card" ) << card << mimetype;
687 } 444 }
688} 445}
689 446
690#if defined(QPE_HAVE_MEMALERTER) 447#if defined(QPE_HAVE_MEMALERTER)
691QPE_MEMALERTER_IMPL 448QPE_MEMALERTER_IMPL
692#endif 449#endif
693 450
694//=========================================================================== 451//===========================================================================
695 452
696Desktop::Desktop() : 453Desktop::Desktop() :
697 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 454 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
698 qcopBridge( 0 ), 455 qcopBridge( 0 ),
diff --git a/core/launcher/desktop.h b/core/launcher/desktop.h
index 8308811..f6059b8 100644
--- a/core/launcher/desktop.h
+++ b/core/launcher/desktop.h
@@ -16,98 +16,97 @@
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef __DESKTOP_H__ 21#ifndef __DESKTOP_H__
22#define __DESKTOP_H__ 22#define __DESKTOP_H__
23 23
24 24
25#include "shutdownimpl.h" 25#include "shutdownimpl.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28 28
29#include <qwidget.h> 29#include <qwidget.h>
30#include <qdatetime.h> 30#include <qdatetime.h>
31 31
32class Background; 32class Background;
33class Launcher; 33class Launcher;
34class TaskBar; 34class TaskBar;
35class PowerStatus; 35class PowerStatus;
36class QCopBridge; 36class QCopBridge;
37class TransferServer; 37class TransferServer;
38class DesktopPowerAlerter; 38class DesktopPowerAlerter;
39class PackageSlave; 39class PackageSlave;
40class QPEScreenSaver; 40class OpieScreenSaver;
41 41
42class DesktopApplication : public QPEApplication 42class DesktopApplication : public QPEApplication
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45public: 45public:
46 DesktopApplication( int& argc, char **argv, Type t ); 46 DesktopApplication( int& argc, char **argv, Type t );
47 ~DesktopApplication(); 47 ~DesktopApplication();
48 48
49 static void switchLCD ( bool on ); // only for togglePower in Desktop 49 static void switchLCD ( bool on ); // only for togglePower in Desktop
50 50
51signals: 51signals:
52 void menu(); 52 void menu();
53 void home(); 53 void home();
54 void datebook(); 54 void datebook();
55 void contacts(); 55 void contacts();
56 void launch(); 56 void launch();
57 void email(); 57 void email();
58 void backlight(); 58 void backlight();
59 void power(); 59 void power();
60 void symbol(); 60 void symbol();
61 void numLockStateToggle(); 61 void numLockStateToggle();
62 void capsLockStateToggle(); 62 void capsLockStateToggle();
63 void prepareForRestart(); 63 void prepareForRestart();
64 64
65protected: 65protected:
66#ifdef Q_WS_QWS 66#ifdef Q_WS_QWS
67 67
68 bool qwsEventFilter( QWSEvent * ); 68 bool qwsEventFilter( QWSEvent * );
69#endif 69#endif
70 70
71 void shutdown(); 71 void shutdown();
72 void restart(); 72 void restart();
73 73
74public slots: 74public slots:
75 virtual void desktopMessage ( const QCString &msg, const QByteArray &data ); 75 virtual void desktopMessage ( const QCString &msg, const QByteArray &data );
76 virtual void systemMessage ( const QCString &msg, const QByteArray &data ); 76 virtual void systemMessage ( const QCString &msg, const QByteArray &data );
77 77
78protected slots: 78protected slots:
79 void shutdown( ShutdownImpl::Type ); 79 void shutdown( ShutdownImpl::Type );
80 void psTimeout( int );
81 void apmTimeout(); 80 void apmTimeout();
82 void sendCard(); 81 void sendCard();
83private: 82private:
84 void reloadPowerWarnSettings(); 83 void reloadPowerWarnSettings();
85 DesktopPowerAlerter *pa; 84 DesktopPowerAlerter *pa;
86 PowerStatus *ps; 85 PowerStatus *m_ps, *m_ps_last;
87 QTimer *cardSendTimer; 86 QTimer *cardSendTimer;
88 QCopChannel *channel; 87 QCopChannel *channel;
89 QPEScreenSaver *m_screensaver; 88 OpieScreenSaver *m_screensaver;
90 QTimer * m_timer; 89 QTimer * m_timer;
91 int m_powerVeryLow; 90 int m_powerVeryLow;
92 int m_powerCritical; 91 int m_powerCritical;
93 int m_currentPowerLevel; 92 int m_currentPowerLevel;
94}; 93};
95 94
96 95
97class Desktop : public QWidget 96class Desktop : public QWidget
98{ 97{
99 Q_OBJECT 98 Q_OBJECT
100public: 99public:
101 Desktop(); 100 Desktop();
102 ~Desktop(); 101 ~Desktop();
103 102
104 static bool screenLocked(); 103 static bool screenLocked();
105 104
106 void show(); 105 void show();
107 void checkMemory(); 106 void checkMemory();
108 107
109 void keyClick(); 108 void keyClick();
110 void screenClick(); 109 void screenClick();
111 static void soundAlarm(); 110 static void soundAlarm();
112 111
113public slots: 112public slots:
diff --git a/core/launcher/launcher.pro b/core/launcher/launcher.pro
index 95642af..83f8b5c 100644
--- a/core/launcher/launcher.pro
+++ b/core/launcher/launcher.pro
@@ -1,70 +1,72 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 DESTDIR = ../../bin 3 DESTDIR = ../../bin
4 HEADERS = background.h \ 4 HEADERS = background.h \
5 desktop.h \ 5 desktop.h \
6 screensaver.h \
6 qprocess.h \ 7 qprocess.h \
7 mediummountgui.h \ 8 mediummountgui.h \
8 info.h \ 9 info.h \
9 appicons.h \ 10 appicons.h \
10 taskbar.h \ 11 taskbar.h \
11 sidething.h \ 12 sidething.h \
12 runningappbar.h \ 13 runningappbar.h \
13 stabmon.h \ 14 stabmon.h \
14 inputmethods.h \ 15 inputmethods.h \
15 systray.h \ 16 systray.h \
16 wait.h \ 17 wait.h \
17 shutdownimpl.h \ 18 shutdownimpl.h \
18 launcher.h \ 19 launcher.h \
19 launcherview.h \ 20 launcherview.h \
20 ../../core/apps/calibrate/calibrate.h \ 21 ../../core/apps/calibrate/calibrate.h \
21 startmenu.h \ 22 startmenu.h \
22 transferserver.h \ 23 transferserver.h \
23 qcopbridge.h \ 24 qcopbridge.h \
24 packageslave.h \ 25 packageslave.h \
25 irserver.h \ 26 irserver.h \
26 ../../rsync/buf.h \ 27 ../../rsync/buf.h \
27 ../../rsync/checksum.h \ 28 ../../rsync/checksum.h \
28 ../../rsync/command.h \ 29 ../../rsync/command.h \
29 ../../rsync/emit.h \ 30 ../../rsync/emit.h \
30 ../../rsync/job.h \ 31 ../../rsync/job.h \
31 ../../rsync/netint.h \ 32 ../../rsync/netint.h \
32 ../../rsync/protocol.h \ 33 ../../rsync/protocol.h \
33 ../../rsync/prototab.h \ 34 ../../rsync/prototab.h \
34 ../../rsync/rsync.h \ 35 ../../rsync/rsync.h \
35 ../../rsync/search.h \ 36 ../../rsync/search.h \
36 ../../rsync/stream.h \ 37 ../../rsync/stream.h \
37 ../../rsync/sumset.h \ 38 ../../rsync/sumset.h \
38 ../../rsync/trace.h \ 39 ../../rsync/trace.h \
39 ../../rsync/types.h \ 40 ../../rsync/types.h \
40 ../../rsync/util.h \ 41 ../../rsync/util.h \
41 ../../rsync/whole.h \ 42 ../../rsync/whole.h \
42 ../../rsync/config_rsync.h \ 43 ../../rsync/config_rsync.h \
43 ../../rsync/qrsync.h \ 44 ../../rsync/qrsync.h \
44 quicklauncher.h 45 quicklauncher.h
45 SOURCES = background.cpp \ 46 SOURCES = background.cpp \
46 desktop.cpp \ 47 desktop.cpp \
48 screensaver.cpp \
47 mediummountgui.cpp \ 49 mediummountgui.cpp \
48 qprocess.cpp qprocess_unix.cpp \ 50 qprocess.cpp qprocess_unix.cpp \
49 info.cpp \ 51 info.cpp \
50 appicons.cpp \ 52 appicons.cpp \
51 taskbar.cpp \ 53 taskbar.cpp \
52 sidething.cpp \ 54 sidething.cpp \
53 runningappbar.cpp \ 55 runningappbar.cpp \
54 stabmon.cpp \ 56 stabmon.cpp \
55 inputmethods.cpp \ 57 inputmethods.cpp \
56 systray.cpp \ 58 systray.cpp \
57 wait.cpp \ 59 wait.cpp \
58 shutdownimpl.cpp \ 60 shutdownimpl.cpp \
59 launcher.cpp \ 61 launcher.cpp \
60 launcherview.cpp \ 62 launcherview.cpp \
61 ../../core/apps/calibrate/calibrate.cpp \ 63 ../../core/apps/calibrate/calibrate.cpp \
62 transferserver.cpp \ 64 transferserver.cpp \
63 packageslave.cpp \ 65 packageslave.cpp \
64 irserver.cpp \ 66 irserver.cpp \
65 qcopbridge.cpp \ 67 qcopbridge.cpp \
66 startmenu.cpp \ 68 startmenu.cpp \
67 main.cpp \ 69 main.cpp \
68 ../../rsync/base64.c \ 70 ../../rsync/base64.c \
69 ../../rsync/buf.c \ 71 ../../rsync/buf.c \
70 ../../rsync/checksum.c \ 72 ../../rsync/checksum.c \
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
new file mode 100644
index 0000000..9e823ff
--- a/dev/null
+++ b/core/launcher/screensaver.cpp
@@ -0,0 +1,237 @@
1
2#include "screensaver.h"
3
4#include <qpe/config.h>
5#include <qpe/power.h>
6#include <qpe/network.h>
7
8#include <opie/odevice.h>
9
10
11using namespace Opie;
12
13
14OpieScreenSaver::OpieScreenSaver ( )
15 : QObject ( 0, "screensaver" ), QWSScreenSaver ( )
16{
17 m_disable_suspend = 100;
18 m_enable_dim = false;
19 m_enable_lightoff = false;
20 m_enable_suspend = false;
21 m_onlylcdoff = false;
22
23 m_enable_dim_ac = false;
24 m_enable_lightoff_ac = false;
25 m_enable_suspend_ac = false;
26 m_onlylcdoff_ac = false;
27
28 m_use_light_sensor = false;
29 m_backlight_sensor = -1;
30
31 m_lcd_status = true;
32
33 m_backlight_normal = -1;
34 m_backlight_current = -1;
35 m_backlight_forcedoff = false;
36
37 m_on_ac = false;
38
39 m_level = -1;
40
41 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
42 ODevice::inst ( )-> setDisplayStatus ( true );
43 setBacklight ( -1 );
44}
45
46
47void OpieScreenSaver::restore()
48{
49 m_level = -1;
50
51 if ( !m_lcd_status ) { // We must have turned it off
52 ODevice::inst ( ) -> setDisplayStatus ( true );
53 m_lcd_status = true;
54 }
55
56 setBacklightInternal ( -1 );
57}
58
59
60bool OpieScreenSaver::save( int level )
61{
62 m_level = level;
63
64 switch ( level ) {
65 case 0:
66 if (( m_on_ac && m_enable_dim_ac ) ||
67 ( !m_on_ac && m_enable_dim )) {
68 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor )
69 setBacklightInternal ( 1 ); // lowest non-off
70 }
71 return true;
72 break;
73
74 case 1:
75 if (( m_on_ac && m_enable_lightoff_ac ) ||
76 ( !m_on_ac && m_enable_lightoff )) {
77 if ( m_disable_suspend > 1 )
78 setBacklightInternal ( 0 ); // off
79 }
80 return true;
81 break;
82
83 case 2:
84 if (( m_on_ac && !m_enable_suspend_ac ) ||
85 ( !m_on_ac && !m_enable_suspend )) {
86 return true;
87 }
88
89 if (( m_on_ac && m_onlylcdoff_ac ) ||
90 ( !m_on_ac && m_onlylcdoff )) {
91 ODevice::inst ( ) -> setDisplayStatus ( false );
92 m_lcd_status = false;
93 return true;
94 }
95
96 // We're going to suspend the whole machine
97
98 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) {
99 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
100 return true;
101 }
102
103 break;
104 }
105 return false;
106}
107
108
109void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 )
110{
111 Config config ( "apm" );
112 config. setGroup ( m_on_ac ? "AC" : "Battery" );
113
114 int v[ 4 ];
115 if ( i1 < 0 )
116 i1 = config. readNumEntry ( "Dim", 30 );
117 if ( i2 < 0 )
118 i2 = config. readNumEntry ( "LightOff", 20 );
119 if ( i3 < 0 )
120 i3 = config. readNumEntry ( "Suspend", 60 );
121
122 if ( m_on_ac ) {
123 m_enable_dim_ac = ( i1 > 0 );
124 m_enable_lightoff_ac = ( i2 > 0 );
125 m_enable_suspend_ac = ( i3 > 0 );
126 m_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnly", 0 );
127 }
128 else {
129 m_enable_dim = ( i1 > 0 );
130 m_enable_lightoff = ( i2 > 0 );
131 m_enable_suspend = ( i3 > 0 );
132 m_onlylcdoff = config.readNumEntry ( "LcdOffOnly", 0 );
133 }
134
135 qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
136
137 v [ 0 ] = QMAX( 1000 * i1, 100 );
138 v [ 1 ] = QMAX( 1000 * i2, 100 );
139 v [ 2 ] = QMAX( 1000 * i3, 100 );
140 v [ 3 ] = 0;
141
142 if ( !i1 && !i2 && !i3 )
143 QWSServer::setScreenSaverInterval( 0 );
144 else
145 QWSServer::setScreenSaverIntervals( v );
146}
147
148
149void OpieScreenSaver::setInterval ( int interval )
150{
151 setIntervals ( -1, -1, interval );
152}
153
154
155void OpieScreenSaver::setMode ( int mode )
156{
157 if ( mode > m_disable_suspend )
158 setInterval ( -1 );
159 m_disable_suspend = mode;
160}
161
162
163void OpieScreenSaver::setBacklight ( int bright )
164{
165 // Read from config
166 Config config ( "apm" );
167 config. setGroup ( m_on_ac ? "AC" : "Battery" );
168 m_backlight_normal = config. readNumEntry ( "Brightness", 255 );
169
170 m_use_light_sensor = config. readBoolEntry ( "LightSensor", false );
171
172 qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 );
173
174 killTimers ( );
175 if ( m_use_light_sensor ) {
176 timerEvent ( 0 );
177 startTimer ( 2000 );
178 }
179
180 setBacklightInternal ( bright );
181}
182
183
184void OpieScreenSaver::setBacklightInternal ( int bright )
185{
186 if ( bright == -3 ) {
187 // Forced on
188 m_backlight_forcedoff = false;
189 bright = -1;
190 }
191 if ( m_backlight_forcedoff && bright != -2 )
192 return ;
193 if ( bright == -2 ) {
194 // Toggle between off and on
195 bright = m_backlight_current ? 0 : -1;
196 m_backlight_forcedoff = !bright;
197 }
198 if ( bright == -1 )
199 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal;
200
201 if ( bright != m_backlight_current ) {
202 ODevice::inst ( )-> setDisplayBrightness ( bright );
203 m_backlight_current = bright;
204 }
205}
206
207
208void OpieScreenSaver::timerEvent ( QTimerEvent * )
209{
210 m_backlight_sensor = (( 255 - ODevice::inst ( )-> readLightSensor ( )) * m_backlight_normal ) / 255;
211
212 if ( m_level <= 0 )
213 setBacklightInternal ( -1 );
214}
215
216
217void OpieScreenSaver::setDisplayState ( bool on )
218{
219 if ( m_lcd_status != on ) {
220 ODevice::inst ( ) -> setDisplayStatus ( on );
221 m_lcd_status = on;
222 }
223}
224
225
226void OpieScreenSaver::powerStatusChanged ( PowerStatus ps )
227{
228 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online );
229
230 if ( newonac != m_on_ac ) {
231 m_on_ac = newonac;
232 setInterval ( -1 );
233 setBacklight ( -1 );
234 restore ( );
235 }
236}
237
diff --git a/core/launcher/screensaver.h b/core/launcher/screensaver.h
new file mode 100644
index 0000000..9126f33
--- a/dev/null
+++ b/core/launcher/screensaver.h
@@ -0,0 +1,61 @@
1#ifndef __LAUNCHER_SCREENSAVER_H__
2#define __LAUNCHER_SCREENSAVER_H__
3
4#include <qwindowsystem_qws.h>
5#include <qobject.h>
6
7#include <qpe/power.h>
8
9class OpieScreenSaver : public QObject, public QWSScreenSaver
10{
11public:
12 OpieScreenSaver ( );
13
14 void restore ( );
15 bool save ( int level );
16
17 void setIntervals( int i1, int i2, int i3 );
18 void setIntervalsAC( int i1, int i2, int i3 );
19
20 void setInterval ( int interval );
21
22 void setMode ( int mode );
23
24 void setBacklight ( int bright );
25 void setDisplayState ( bool on );
26
27 void powerStatusChanged ( PowerStatus ps );
28
29private:
30 void setBacklightInternal ( int bright );
31
32protected:
33 virtual void timerEvent ( QTimerEvent * );
34
35private:
36 int m_disable_suspend;
37 bool m_enable_dim;
38 bool m_enable_lightoff;
39 bool m_enable_suspend;
40 bool m_onlylcdoff;
41
42 bool m_enable_dim_ac;
43 bool m_enable_lightoff_ac;
44 bool m_enable_suspend_ac;
45 bool m_onlylcdoff_ac;
46
47 bool m_use_light_sensor;
48 int m_backlight_sensor;
49
50 bool m_lcd_status;
51
52 int m_backlight_normal;
53 int m_backlight_current;
54 bool m_backlight_forcedoff;
55
56 bool m_on_ac;
57
58 int m_level;
59};
60
61#endif