author | harlekin <harlekin> | 2002-10-22 21:41:42 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-10-22 21:41:42 (UTC) |
commit | e4297ff151693e07313ea036de91ad3c788c5e26 (patch) (unidiff) | |
tree | 564bf451b6e6319944e3e793631f93d879031c74 /core | |
parent | 4381aaf653750f4a51a816ff419be70059b2857d (diff) | |
download | opie-e4297ff151693e07313ea036de91ad3c788c5e26.zip opie-e4297ff151693e07313ea036de91ad3c788c5e26.tar.gz opie-e4297ff151693e07313ea036de91ad3c788c5e26.tar.bz2 |
launcher side of the support for new light and power settings
-rw-r--r-- | core/launcher/desktop.cpp | 161 | ||||
-rw-r--r-- | core/launcher/desktop.h | 15 |
2 files changed, 129 insertions, 47 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index d2bd8ae..4926b97 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -166,7 +166,12 @@ public: | |||
166 | m_enable_onlylcdoff = false; | 166 | m_enable_onlylcdoff = false; |
167 | 167 | ||
168 | m_disable_suspend_ac = 100; | ||
169 | m_enable_dim_ac = false; | ||
170 | m_enable_lightoff_ac = false; | ||
171 | m_enable_onlylcdoff_ac = false; | ||
172 | |||
168 | m_lcd_status = true; | 173 | m_lcd_status = true; |
169 | 174 | ||
170 | m_backlight_normal = -1; | 175 | m_backlight_normal = -1; |
171 | m_backlight_current = -1; | 176 | m_backlight_current = -1; |
172 | m_backlight_forcedoff = false; | 177 | m_backlight_forcedoff = false; |
@@ -187,36 +192,52 @@ public: | |||
187 | bool save( int level ) | 192 | bool save( int level ) |
188 | { | 193 | { |
189 | switch ( level ) { | 194 | bool onAC = ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ); |
195 | |||
196 | switch ( level ) { | ||
190 | case 0: | 197 | case 0: |
191 | if ( m_disable_suspend > 0 && m_enable_dim ) { | 198 | |
192 | if ( m_backlight_current > 1 ) | 199 | if ( m_disable_suspend_ac > 0 && m_enable_dim_ac && onAC ) { |
193 | setBacklightInternal ( 1 ); // lowest non-off | 200 | if ( m_backlight_current > 1 ) |
194 | } | 201 | setBacklight( 1 ); // lowest non-off |
195 | return true; | 202 | } else if ( m_disable_suspend > 0 && m_enable_dim ) { |
196 | break; | 203 | if ( m_backlight_current > 1 ) |
204 | setBacklightInternal( 1 ); // lowest non-off | ||
205 | } | ||
206 | return true; | ||
207 | break; | ||
197 | case 1: | 208 | case 1: |
198 | if ( m_disable_suspend > 1 && m_enable_lightoff ) { | 209 | |
199 | setBacklightInternal ( 0 ); // off | 210 | if ( m_disable_suspend_ac > 1 && m_enable_lightoff_ac && onAC ) { |
200 | } | 211 | setBacklightInternal( 0 ); // off |
201 | return true; | 212 | } else if ( m_disable_suspend > 1 && m_enable_lightoff ) { |
202 | break; | 213 | setBacklightInternal( 0 ); // off |
203 | case 2: | 214 | } |
204 | if ( m_enable_onlylcdoff ) { | ||
205 | ODevice::inst ( )-> setDisplayStatus ( false ); | ||
206 | m_lcd_status = false; | ||
207 | return true; | 215 | return true; |
208 | } | 216 | break; |
209 | else // We're going to suspend the whole machine | 217 | case 2: |
210 | { | 218 | if ( m_enable_onlylcdoff_ac && onAC ) { |
211 | if ( ( m_disable_suspend > 2 ) && | 219 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
212 | ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && | 220 | m_lcd_status = false; |
213 | ( !Network::networkOnline ( ) ) ) { | 221 | return true; |
214 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | ||
215 | return true; | ||
216 | } | 222 | } |
217 | } | 223 | else if ( m_enable_onlylcdoff ) { |
218 | break; | 224 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
219 | } | 225 | m_lcd_status = false; |
220 | return false; | 226 | return true; |
227 | } | ||
228 | else // We're going to suspend the whole machine | ||
229 | { | ||
230 | if ( ( m_disable_suspend_ac > 2 && onAC ) && ( !Network::networkOnline ( ) ) ) { | ||
231 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | ||
232 | return true; | ||
233 | } | ||
234 | if ( ( m_disable_suspend > 2 ) && ( !Network::networkOnline ( ) ) ) { | ||
235 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | ||
236 | return true; | ||
237 | } | ||
238 | } | ||
239 | break; | ||
240 | } | ||
241 | return false; | ||
221 | } | 242 | } |
222 | 243 | ||
@@ -261,4 +282,30 @@ public: | |||
261 | } | 282 | } |
262 | 283 | ||
284 | void setIntervalsAC( int i1, int i2, int i3 ) | ||
285 | { | ||
286 | Config config( "qpe" ); | ||
287 | config.setGroup( "Screensaver" ); | ||
288 | |||
289 | int v[ 4 ]; | ||
290 | i1 = ssi( i1, config, "DimAC", "Interval_DimAC", 30 ); | ||
291 | i2 = ssi( i2, config, "LightOffAC", "Interval_LightOffAC", 20 ); | ||
292 | i3 = ssi( i3, config, "", "IntervalAC", 60 ); | ||
293 | |||
294 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | ||
295 | |||
296 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | ||
297 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | ||
298 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | ||
299 | v [ 3 ] = 0; | ||
300 | m_enable_dim_ac = ( ( i1 != 0 ) ? config.readNumEntry ( "DimAC", 1 ) : false ); | ||
301 | m_enable_lightoff_ac = ( ( i2 != 0 ) ? config.readNumEntry ( "LightOffAC", 1 ) : false ); | ||
302 | m_enable_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnlyAC", 0 ); | ||
303 | |||
304 | if ( !i1 && !i2 && !i3 ) | ||
305 | QWSServer::setScreenSaverInterval( 0 ); | ||
306 | else | ||
307 | QWSServer::setScreenSaverIntervals( v ); | ||
308 | } | ||
309 | |||
263 | void setInterval ( int interval ) | 310 | void setInterval ( int interval ) |
264 | { | 311 | { |
@@ -272,5 +319,5 @@ public: | |||
272 | m_disable_suspend = mode; | 319 | m_disable_suspend = mode; |
273 | } | 320 | } |
274 | 321 | ||
275 | void setBacklight ( int bright ) | 322 | void setBacklight ( int bright ) |
276 | { | 323 | { |
@@ -300,5 +347,5 @@ private: | |||
300 | if ( bright == -1 ) | 347 | if ( bright == -1 ) |
301 | bright = m_backlight_normal; | 348 | bright = m_backlight_normal; |
302 | 349 | ||
303 | if ( bright != m_backlight_current ) { | 350 | if ( bright != m_backlight_current ) { |
304 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 351 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
@@ -322,4 +369,9 @@ private: | |||
322 | bool m_enable_onlylcdoff; | 369 | bool m_enable_onlylcdoff; |
323 | 370 | ||
371 | int m_disable_suspend_ac; | ||
372 | bool m_enable_dim_ac; | ||
373 | bool m_enable_lightoff_ac; | ||
374 | bool m_enable_onlylcdoff_ac; | ||
375 | |||
324 | bool m_lcd_status; | 376 | bool m_lcd_status; |
325 | 377 | ||
@@ -336,5 +388,5 @@ void DesktopApplication::switchLCD ( bool on ) | |||
336 | if ( dapp-> m_screensaver ) { | 388 | if ( dapp-> m_screensaver ) { |
337 | if ( on ) { | 389 | if ( on ) { |
338 | dapp-> m_screensaver-> setDisplayState ( true ); | 390 | dapp-> m_screensaver-> setDisplayState ( true ); |
339 | dapp-> m_screensaver-> setBacklight ( -3 ); | 391 | dapp-> m_screensaver-> setBacklight ( -3 ); |
340 | } | 392 | } |
@@ -351,7 +403,12 @@ DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | |||
351 | { | 403 | { |
352 | 404 | ||
353 | QTimer * t = new QTimer( this ); | 405 | //FIXME, need also a method for setting different timer ( changed runtime ) |
354 | connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); | 406 | m_timer = new QTimer( this ); |
355 | t->start( 10000 ); | 407 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); |
408 | Config cfg( "qpe" ); | ||
409 | cfg.setGroup( "APM" ); | ||
410 | m_timer->start( cfg.readNumEntry( "check_interval", 10000 ) ); | ||
411 | m_powerVeryLow = cfg.readNumEntry( "power_verylow", 10 ); | ||
412 | m_powerCritical = cfg.readNumEntry( "power_critical", 5 ); | ||
356 | ps = new PowerStatus; | 413 | ps = new PowerStatus; |
357 | pa = new DesktopPowerAlerter( 0 ); | 414 | pa = new DesktopPowerAlerter( 0 ); |
@@ -408,4 +465,9 @@ void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & | |||
408 | m_screensaver-> setIntervals( t1, t2, t3 ); | 465 | m_screensaver-> setIntervals( t1, t2, t3 ); |
409 | } | 466 | } |
467 | else if ( msg == "setScreenSaverIntervalsAC(int,int,int)" ) { | ||
468 | int t1, t2, t3; | ||
469 | stream >> t1 >> t2 >> t3; | ||
470 | m_screensaver-> setIntervalsAC( t1, t2, t3 ); | ||
471 | } | ||
410 | else if ( msg == "setBacklight(int)" ) { | 472 | else if ( msg == "setBacklight(int)" ) { |
411 | int bright; | 473 | int bright; |
@@ -418,4 +480,7 @@ void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & | |||
418 | m_screensaver-> setMode ( mode ); | 480 | m_screensaver-> setMode ( mode ); |
419 | } | 481 | } |
482 | else if ( msg == "reloadPowerWarnSettings()" ) { | ||
483 | reloadPowerWarnSettings(); | ||
484 | } | ||
420 | else if ( msg == "setDisplayState(int)" ) { | 485 | else if ( msg == "setDisplayState(int)" ) { |
421 | int state; | 486 | int state; |
@@ -428,4 +493,14 @@ void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & | |||
428 | } | 493 | } |
429 | 494 | ||
495 | void DesktopApplication::reloadPowerWarnSettings() { | ||
496 | Config cfg( "apm" ); | ||
497 | cfg.setGroup( "Warnings" ); | ||
498 | |||
499 | m_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); | ||
500 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); | ||
501 | m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); | ||
502 | } | ||
503 | |||
504 | |||
430 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; | 505 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; |
431 | 506 | ||
@@ -480,10 +555,10 @@ bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | |||
480 | return TRUE; | 555 | return TRUE; |
481 | } | 556 | } |
482 | // menu key now opens application menu/toolbar | 557 | |
483 | // if ( ke->simpleData.keycode == Key_F11 ) { | 558 | // if ( ke->simpleData.keycode == Key_F11 ) { |
484 | // if ( press ) emit menu(); | 559 | // if ( press ) emit menu(); |
485 | // return TRUE; | 560 | // return TRUE; |
486 | // } | 561 | // } |
487 | 562 | ||
488 | if ( ke->simpleData.keycode == Key_F12 ) { | 563 | if ( ke->simpleData.keycode == Key_F12 ) { |
489 | while ( activePopupWidget() ) | 564 | while ( activePopupWidget() ) |
@@ -564,11 +639,13 @@ void DesktopApplication::psTimeout() | |||
564 | *ps = PowerStatusManager::readStatus(); | 639 | *ps = PowerStatusManager::readStatus(); |
565 | 640 | ||
566 | if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { | 641 | // if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { |
567 | pa->alert( tr( "Battery is running very low." ), 6 ); | 642 | if ( ( ps->batteryPercentRemaining() == m_powerVeryLow ) ) { |
643 | pa->alert( tr( "Battery is running very low." ), 6 ); | ||
568 | } | 644 | } |
569 | 645 | ||
570 | if ( ps->batteryStatus() == PowerStatus::Critical ) { | 646 | // if ( ps->batteryStatus() == PowerStatus::Critical ) { |
571 | pa->alert( tr( "Battery level is critical!\n" | 647 | if ( ps->batteryPercentRemaining() == m_powerCritical ) { |
572 | "Keep power off until power restored!" ), 1 ); | 648 | pa->alert( tr( "Battery level is critical!\n" |
649 | "Keep power off until power restored!" ), 1 ); | ||
573 | } | 650 | } |
574 | 651 | ||
diff --git a/core/launcher/desktop.h b/core/launcher/desktop.h index 04c2f61..15d8ef7 100644 --- a/core/launcher/desktop.h +++ b/core/launcher/desktop.h | |||
@@ -81,9 +81,14 @@ protected slots: | |||
81 | void sendCard(); | 81 | void sendCard(); |
82 | private: | 82 | private: |
83 | DesktopPowerAlerter *pa; | 83 | void reloadPowerWarnSettings(); |
84 | PowerStatus *ps; | 84 | DesktopPowerAlerter *pa; |
85 | QTimer *cardSendTimer; | 85 | PowerStatus *ps; |
86 | QCopChannel *channel; | 86 | QTimer *cardSendTimer; |
87 | QPEScreenSaver *m_screensaver; | 87 | QCopChannel *channel; |
88 | QPEScreenSaver *m_screensaver; | ||
89 | QTimer * m_timer; | ||
90 | int m_powerVeryLow; | ||
91 | int m_powerCritical; | ||
92 | |||
88 | }; | 93 | }; |
89 | 94 | ||