-rw-r--r-- | core/launcher/desktop.cpp | 20 | ||||
-rw-r--r-- | core/launcher/screensaver.cpp | 14 |
2 files changed, 17 insertions, 17 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index bc43475..f2e00d8 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp @@ -161,140 +161,140 @@ void DesktopApplication::switchLCD ( bool on ) if ( dapp-> m_screensaver ) { if ( on ) { dapp-> m_screensaver-> setDisplayState ( true ); dapp-> m_screensaver-> setBacklight ( -3 ); } else { dapp-> m_screensaver-> setDisplayState ( false ); } } } } DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) : QPEApplication( argc, argv, appType ) { Config cfg( "apm" ); cfg.setGroup( "Warnings" ); //cfg.readNumEntry( "checkinterval", 10000 ) m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); m_ps = new PowerStatus; m_ps_last = new PowerStatus; pa = new DesktopPowerAlerter( 0 ); m_timer = new QTimer( this ); connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); m_timer->start( 5000 ); channel = new QCopChannel( "QPE/Desktop", this ); connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); channel = new QCopChannel( "QPE/System", this ); connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); m_screensaver = new OpieScreenSaver ( ); m_screensaver-> setInterval ( -1 ); QWSServer::setScreenSaver( m_screensaver ); apmTimeout ( ); } DesktopApplication::~DesktopApplication() { delete m_ps; delete m_ps_last; delete pa; } void DesktopApplication::apmTimeout() { qpedesktop->checkMemory(); // in case no events are being generated *m_ps_last = *m_ps; *m_ps = PowerStatusManager::readStatus(); if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) m_screensaver-> powerStatusChanged ( *m_ps ); - int bat = m_ps-> batteryPercentRemaining ( ); - - if ( m_ps_last-> batteryPercentRemaining ( ) != bat ) { - if ( bat <= m_powerCritical ) - pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); - else if ( bat <= m_powerVeryLow ) - pa->alert( tr( "Battery is running very low." ), 2 ); - - + if ( m_ps-> acStatus ( ) != PowerStatus::Online ) { + int bat = m_ps-> batteryPercentRemaining ( ); + + if ( bat < m_ps_last-> batteryPercentRemaining ( )) { + if ( bat <= m_powerCritical ) + pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); + else if ( bat <= m_powerVeryLow ) + pa->alert( tr( "Battery is running very low." ), 2 ); + } if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); - } + } } void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "keyRegister(int key, QString channel, QString message)" ) { int k; QString c, m; stream >> k; stream >> c; stream >> m; qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); keyRegisterList.append( QCopKeyRegister( k, c, m ) ); } } void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) { QDataStream stream ( data, IO_ReadOnly ); if ( msg == "setScreenSaverInterval(int)" ) { int time; stream >> time; m_screensaver-> setInterval( time ); } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { int t1, t2, t3; stream >> t1 >> t2 >> t3; m_screensaver-> setIntervals( t1, t2, t3 ); } else if ( msg == "setBacklight(int)" ) { int bright; stream >> bright; m_screensaver-> setBacklight( bright ); } else if ( msg == "setScreenSaverMode(int)" ) { int mode; stream >> mode; m_screensaver-> setMode ( mode ); } else if ( msg == "reloadPowerWarnSettings()" ) { reloadPowerWarnSettings(); } else if ( msg == "setDisplayState(int)" ) { int state; stream >> state; m_screensaver-> setDisplayState ( state != 0 ); } else if ( msg == "suspend()" ) { emit power(); } } void DesktopApplication::reloadPowerWarnSettings() { Config cfg( "apm" ); cfg.setGroup( "Warnings" ); // m_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); } diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 741591e..45da9ed 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp @@ -54,185 +54,185 @@ void OpieScreenSaver::restore() ODevice::inst ( ) -> setDisplayStatus ( true ); m_lcd_status = true; } setBacklightInternal ( -1 ); } bool OpieScreenSaver::save( int level ) { m_level = level; switch ( level ) { case 0: if (( m_on_ac && m_enable_dim_ac ) || ( !m_on_ac && m_enable_dim )) { if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) setBacklightInternal ( 1 ); // lowest non-off } return true; break; case 1: if (( m_on_ac && m_enable_lightoff_ac ) || ( !m_on_ac && m_enable_lightoff )) { if ( m_disable_suspend > 1 ) setBacklightInternal ( 0 ); // off } return true; break; case 2: if (( m_on_ac && !m_enable_suspend_ac ) || ( !m_on_ac && !m_enable_suspend )) { return true; } if (( m_on_ac && m_onlylcdoff_ac ) || ( !m_on_ac && m_onlylcdoff )) { ODevice::inst ( ) -> setDisplayStatus ( false ); m_lcd_status = false; return true; } // We're going to suspend the whole machine if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); return true; } break; } return false; } void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) { Config config ( "apm" ); config. setGroup ( m_on_ac ? "AC" : "Battery" ); int v[ 4 ]; if ( i1 < 0 ) - i1 = config. readNumEntry ( "Dim", 30 ); + i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); if ( i2 < 0 ) - i2 = config. readNumEntry ( "LightOff", 20 ); + i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); if ( i3 < 0 ) - i3 = config. readNumEntry ( "Suspend", 60 ); + i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); if ( m_on_ac ) { m_enable_dim_ac = ( i1 > 0 ); m_enable_lightoff_ac = ( i2 > 0 ); m_enable_suspend_ac = ( i3 > 0 ); - m_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnly", 0 ); + m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); } else { m_enable_dim = ( i1 > 0 ); m_enable_lightoff = ( i2 > 0 ); m_enable_suspend = ( i3 > 0 ); - m_onlylcdoff = config.readNumEntry ( "LcdOffOnly", 0 ); + m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); } qDebug("screen saver intervals: %d %d %d", i1, i2, i3); v [ 0 ] = QMAX( 1000 * i1, 100 ); v [ 1 ] = QMAX( 1000 * i2, 100 ); v [ 2 ] = QMAX( 1000 * i3, 100 ); v [ 3 ] = 0; if ( !i1 && !i2 && !i3 ) QWSServer::setScreenSaverInterval( 0 ); else QWSServer::setScreenSaverIntervals( v ); } void OpieScreenSaver::setInterval ( int interval ) { setIntervals ( -1, -1, interval ); } void OpieScreenSaver::setMode ( int mode ) { if ( mode > m_disable_suspend ) setInterval ( -1 ); m_disable_suspend = mode; } void OpieScreenSaver::setBacklight ( int bright ) { // Read from config Config config ( "apm" ); config. setGroup ( m_on_ac ? "AC" : "Battery" ); - m_backlight_normal = config. readNumEntry ( "Brightness", 255 ); + m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); - qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); +// qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); killTimers ( ); if ( m_use_light_sensor ) { QStringList sl = config. readListEntry ( "LightSensorData", ';' ); m_sensordata [LS_SensorMin] = 40; m_sensordata [LS_SensorMax] = 215; m_sensordata [LS_LightMin] = 1; m_sensordata [LS_LightMax] = 255; m_sensordata [LS_Steps] = 12; m_sensordata [LS_Interval] = 2000; for ( uint i = 0; i < LS_Count; i++ ) { if ( i < sl. count ( )) m_sensordata [i] = sl [i]. toInt ( ); } timerEvent ( 0 ); startTimer ( m_sensordata [LS_Interval] ); } setBacklightInternal ( bright ); } void OpieScreenSaver::setBacklightInternal ( int bright ) { if ( bright == -3 ) { // Forced on m_backlight_forcedoff = false; bright = -1; } if ( m_backlight_forcedoff && bright != -2 ) return ; if ( bright == -2 ) { // Toggle between off and on bright = m_backlight_current ? 0 : -1; m_backlight_forcedoff = !bright; } if ( bright == -1 ) bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; if ( bright != m_backlight_current ) { ODevice::inst ( )-> setDisplayBrightness ( bright ); m_backlight_current = bright; } } void OpieScreenSaver::timerEvent ( QTimerEvent * ) { int s = ODevice::inst ( )-> readLightSensor ( ); if ( s < m_sensordata [LS_SensorMin] ) m_backlight_sensor = m_sensordata [LS_LightMax]; else if ( s >= m_sensordata [LS_SensorMax] ) m_backlight_sensor = m_sensordata [LS_LightMin]; else { int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |