author | sandman <sandman> | 2002-10-28 04:48:35 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-28 04:48:35 (UTC) |
commit | cb687974f9e97c0ce6117b0ac4551ad4d4342b6a (patch) (unidiff) | |
tree | 3128de5e3647a786bcc47a5fb14af06ba65f2a09 | |
parent | f3c9e44d9d694a0a803fb6a7d79cfa8d173b9864 (diff) | |
download | opie-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)
-rw-r--r-- | core/launcher/desktop.cpp | 317 | ||||
-rw-r--r-- | core/launcher/desktop.h | 7 | ||||
-rw-r--r-- | core/launcher/launcher.pro | 2 | ||||
-rw-r--r-- | core/launcher/screensaver.cpp | 237 | ||||
-rw-r--r-- | core/launcher/screensaver.h | 61 |
5 files changed, 340 insertions, 284 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 | |||
@@ -28,6 +28,7 @@ | |||
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> |
@@ -151,241 +152,6 @@ void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | |||
151 | currentPriority = INT_MAX; | 152 | currentPriority = INT_MAX; |
152 | } | 153 | } |
153 | 154 | ||
154 | class QPEScreenSaver : public QWSScreenSaver | ||
155 | { | ||
156 | private: | ||
157 | int LcdOn; | ||
158 | |||
159 | public: | ||
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 | |||
248 | private: | ||
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 | |||
261 | public: | ||
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 | |||
338 | private: | ||
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 | |||
362 | public: | ||
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 | |||
371 | private: | ||
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 | ||
390 | void DesktopApplication::switchLCD ( bool on ) | 156 | void DesktopApplication::switchLCD ( bool on ) |
391 | { | 157 | { |
@@ -409,17 +175,20 @@ DesktopApplication::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 ); | ||
413 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); | ||
414 | Config cfg( "apm" ); | 178 | Config cfg( "apm" ); |
415 | cfg.setGroup( "Warnings" ); | 179 | 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 | |
184 | m_ps = new PowerStatus; | ||
185 | m_ps_last = new PowerStatus; | ||
421 | pa = new DesktopPowerAlerter( 0 ); | 186 | pa = new DesktopPowerAlerter( 0 ); |
422 | 187 | ||
188 | m_timer = new QTimer( this ); | ||
189 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); | ||
190 | m_timer->start( 5000 ); | ||
191 | |||
423 | channel = new QCopChannel( "QPE/Desktop", this ); | 192 | channel = new QCopChannel( "QPE/Desktop", this ); |
424 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
425 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); | 194 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); |
@@ -428,19 +197,45 @@ DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | |||
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 | |||
433 | m_screensaver-> setInterval ( -1 ); | 201 | m_screensaver-> setInterval ( -1 ); |
434 | QWSServer::setScreenSaver( m_screensaver ); | 202 | QWSServer::setScreenSaver( m_screensaver ); |
203 | |||
204 | apmTimeout ( ); | ||
435 | } | 205 | } |
436 | 206 | ||
437 | 207 | ||
438 | DesktopApplication::~DesktopApplication() | 208 | DesktopApplication::~DesktopApplication() |
439 | { | 209 | { |
440 | delete ps; | 210 | delete m_ps; |
211 | delete m_ps_last; | ||
441 | delete pa; | 212 | delete pa; |
442 | } | 213 | } |
443 | 214 | ||
215 | void 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 | } | ||
237 | } | ||
238 | |||
444 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) | 239 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) |
445 | { | 240 | { |
446 | QDataStream stream( data, IO_ReadOnly ); | 241 | QDataStream stream( data, IO_ReadOnly ); |
@@ -471,11 +266,6 @@ void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & | |||
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; |
@@ -639,39 +429,6 @@ bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | |||
639 | } | 429 | } |
640 | #endif | 430 | #endif |
641 | 431 | ||
642 | void 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 | |||
663 | void 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 | ||
676 | void DesktopApplication::sendCard() | 433 | void DesktopApplication::sendCard() |
677 | { | 434 | { |
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 | |||
@@ -37,7 +37,7 @@ class QCopBridge; | |||
37 | class TransferServer; | 37 | class TransferServer; |
38 | class DesktopPowerAlerter; | 38 | class DesktopPowerAlerter; |
39 | class PackageSlave; | 39 | class PackageSlave; |
40 | class QPEScreenSaver; | 40 | class OpieScreenSaver; |
41 | 41 | ||
42 | class DesktopApplication : public QPEApplication | 42 | class DesktopApplication : public QPEApplication |
43 | { | 43 | { |
@@ -77,16 +77,15 @@ public slots: | |||
77 | 77 | ||
78 | protected slots: | 78 | protected 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(); |
83 | private: | 82 | private: |
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; |
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 | |||
@@ -3,6 +3,7 @@ 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 \ |
@@ -44,6 +45,7 @@ HEADERS = background.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 \ |
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 | |||
11 | using namespace Opie; | ||
12 | |||
13 | |||
14 | OpieScreenSaver::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 | |||
47 | void 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 | |||
60 | bool 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 | |||
109 | void 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 | |||
149 | void OpieScreenSaver::setInterval ( int interval ) | ||
150 | { | ||
151 | setIntervals ( -1, -1, interval ); | ||
152 | } | ||
153 | |||
154 | |||
155 | void OpieScreenSaver::setMode ( int mode ) | ||
156 | { | ||
157 | if ( mode > m_disable_suspend ) | ||
158 | setInterval ( -1 ); | ||
159 | m_disable_suspend = mode; | ||
160 | } | ||
161 | |||
162 | |||
163 | void 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 | |||
184 | void 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 | |||
208 | void 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 | |||
217 | void 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 | |||
226 | void 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 | |||
9 | class OpieScreenSaver : public QObject, public QWSScreenSaver | ||
10 | { | ||
11 | public: | ||
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 | |||
29 | private: | ||
30 | void setBacklightInternal ( int bright ); | ||
31 | |||
32 | protected: | ||
33 | virtual void timerEvent ( QTimerEvent * ); | ||
34 | |||
35 | private: | ||
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 | ||