-rw-r--r-- | core/launcher/desktop.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index 4926b97..33bea36 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp @@ -381,56 +381,56 @@ private: }; void DesktopApplication::switchLCD ( bool on ) { if ( qApp ) { DesktopApplication *dapp = (DesktopApplication *) qApp; 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 ) { - //FIXME, need also a method for setting different timer ( changed runtime ) m_timer = new QTimer( this ); - connect( m_timer, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); - Config cfg( "qpe" ); - cfg.setGroup( "APM" ); - m_timer->start( cfg.readNumEntry( "check_interval", 10000 ) ); - m_powerVeryLow = cfg.readNumEntry( "power_verylow", 10 ); - m_powerCritical = cfg.readNumEntry( "power_critical", 5 ); + connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); + Config cfg( "apm" ); + cfg.setGroup( "Warnings" ); + m_timer->start( 5000 ); + //cfg.readNumEntry( "checkinterval", 10000 ) + m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); + m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); ps = new PowerStatus; pa = new DesktopPowerAlerter( 0 ); 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 QPEScreenSaver; m_screensaver-> setInterval ( -1 ); QWSServer::setScreenSaver( m_screensaver ); } DesktopApplication::~DesktopApplication() { delete ps; delete pa; } @@ -475,49 +475,49 @@ void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & 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_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); } enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; #ifdef Q_WS_QWS bool DesktopApplication::qwsEventFilter( QWSEvent *e ) { qpedesktop->checkMemory(); if ( e->type == QWSEvent::Key ) { QWSKeyEvent * ke = ( QWSKeyEvent * ) e; if ( !loggedin && ke->simpleData.keycode != Key_F34 ) return TRUE; bool press = ke->simpleData.is_press; bool autoRepeat = ke->simpleData.is_auto_repeat; /* app that registers key/message to be sent back to the app, when it doesn't have focus, when user presses key, unless keyboard has been requested from app. will not send multiple repeats if user holds key i.e. one shot @@ -611,70 +611,81 @@ bool DesktopApplication::qwsEventFilter( QWSEvent *e ) } if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) qpedesktop->keyClick(); } else { if ( e->type == QWSEvent::Mouse ) { QWSMouseEvent * me = ( QWSMouseEvent * ) e; static bool up = TRUE; if ( me->simpleData.state & LeftButton ) { if ( up ) { up = FALSE; qpedesktop->screenClick(); } } else { up = TRUE; } } } return QPEApplication::qwsEventFilter( e ); } #endif -void DesktopApplication::psTimeout() +void DesktopApplication::psTimeout( int batRemaining ) { - qpedesktop->checkMemory(); // in case no events are being generated - *ps = PowerStatusManager::readStatus(); + // maybe now since its triggered by apm change there might be to few warnings // if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { - if ( ( ps->batteryPercentRemaining() == m_powerVeryLow ) ) { + if ( ( batRemaining == m_powerVeryLow ) ) { pa->alert( tr( "Battery is running very low." ), 6 ); } // if ( ps->batteryStatus() == PowerStatus::Critical ) { - if ( ps->batteryPercentRemaining() == m_powerCritical ) { + if ( batRemaining == m_powerCritical ) { pa->alert( tr( "Battery level is critical!\n" "Keep power off until power restored!" ), 1 ); } if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); } } +void DesktopApplication::apmTimeout() +{ + qpedesktop->checkMemory(); // in case no events are being generated + + *ps = PowerStatusManager::readStatus(); + + if ( m_currentPowerLevel != ps->batteryPercentRemaining() ) { + // not very nice, since psTimeout parses the again + m_currentPowerLevel = ps->batteryPercentRemaining(); + psTimeout( m_currentPowerLevel ); + } +} void DesktopApplication::sendCard() { delete cardSendTimer; cardSendTimer = 0; QString card = getenv( "HOME" ); card += "/Applications/addressbook/businesscard.vcf"; if ( QFile::exists( card ) ) { QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); QString mimetype = "text/x-vCard"; e << tr( "business card" ) << card << mimetype; } } #if defined(QPE_HAVE_MEMALERTER) QPE_MEMALERTER_IMPL #endif //=========================================================================== Desktop::Desktop() : QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), qcopBridge( 0 ), |