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 /core/launcher/desktop.cpp | |
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 |
1 files changed, 37 insertions, 280 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 | { |