From kde-commits Thu May 31 22:24:27 2012 From: Harald Sitter Date: Thu, 31 May 2012 22:24:27 +0000 To: kde-commits Subject: [dragon] src/app: make sure power saving is resumed when quitting the app Message-Id: <20120531222427.DEC47A60A9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133850325211964 Git commit ac92ddb3c2fe7ecc4009d0f2f1ec33843949ea2e by Harald Sitter. Committed on 01/06/2012 at 00:24. Pushed by sitter into branch 'master'. make sure power saving is resumed when quitting the app BUG: 290587 M +26 -0 src/app/mainWindow.cpp M +3 -0 src/app/mainWindow.h M +2 -19 src/app/stateChange.cpp http://commits.kde.org/dragon/ac92ddb3c2fe7ecc4009d0f2f1ec33843949ea2e diff --git a/src/app/mainWindow.cpp b/src/app/mainWindow.cpp index 3197986..b0e92b9 100644 --- a/src/app/mainWindow.cpp +++ b/src/app/mainWindow.cpp @@ -255,6 +255,7 @@ MainWindow::init() MainWindow::~MainWindow() { hide(); //so we appear to have quit, and then sound fades out below + releasePowerSave(); delete videoWindow(); //fades out sound in dtor } = @@ -780,6 +781,31 @@ MainWindow::keyPressEvent( QKeyEvent *e ) #undef seek } = +void +MainWindow::inhibitPowerSave() +{ + m_stopSleepCookie =3D Solid::PowerManagement::beginSuppressingSleep(QL= atin1String( "watching a film" )); + m_stopScreenPowerMgmtCookie =3D Solid::PowerManagement::beginSuppressi= ngScreenPowerManagement(QLatin1String( "watching a film" )); + if (!m_stopScreenSaver) + m_stopScreenSaver =3D new KNotificationRestrictions(KNotificationR= estrictions::ScreenSaver); +} + +void +MainWindow::releasePowerSave() +{ + //stop supressing sleep + if (m_stopSleepCookie !=3D -1) + Solid::PowerManagement::stopSuppressingSleep(m_stopSleepCookie); + + //stop supressing screen power management + if (m_stopScreenPowerMgmtCookie !=3D -1) + Solid::PowerManagement::stopSuppressingScreenPowerManagement(m_stopS= creenPowerMgmtCookie); + + //stop disabling screensaver + delete m_stopScreenSaver; // It is always 0, I have been careful. + m_stopScreenSaver =3D 0; +} + QMenu* MainWindow::menu( const char *name ) { diff --git a/src/app/mainWindow.h b/src/app/mainWindow.h index f581374..502758d 100644 --- a/src/app/mainWindow.h +++ b/src/app/mainWindow.h @@ -111,6 +111,9 @@ namespace Dragon virtual void dropEvent( QDropEvent* ); virtual void keyPressEvent( QKeyEvent* ); = + void inhibitPowerSave(); + void releasePowerSave(); + // virtual void saveProperties( KConfig* ); // virtual void readProperties( KConfig* ); = diff --git a/src/app/stateChange.cpp b/src/app/stateChange.cpp index f54b75c..3593f86 100644 --- a/src/app/stateChange.cpp +++ b/src/app/stateChange.cpp @@ -118,26 +118,9 @@ MainWindow::engineStateChanged( Phonon::State state, P= honon::State oldstate ) = /// turn off screensaver if( state =3D=3D Phonon::PlayingState ) - { - m_stopSleepCookie =3D Solid::PowerManagement::beginSuppressingSleep(= QLatin1String( "watching a film" )); - m_stopScreenPowerMgmtCookie =3D Solid::PowerManagement::beginSuppres= singScreenPowerManagement(QLatin1String( "watching a film" )); - if (!m_stopScreenSaver) - m_stopScreenSaver =3D new KNotificationRestrictions(KNotificatio= nRestrictions::ScreenSaver); - } + inhibitPowerSave(); else if( Phonon::StoppedState || !TheStream::hasMedia() ) - { - //stop supressing sleep - if (m_stopSleepCookie !=3D -1) - Solid::PowerManagement::stopSuppressingSleep(m_stopSleepCookie); - - //stop supressing screen power management - if (m_stopScreenPowerMgmtCookie !=3D -1) - Solid::PowerManagement::stopSuppressingScreenPowerManagement(m_sto= pScreenPowerMgmtCookie); - - //stop disabling screensaver - delete m_stopScreenSaver; // It is always 0, I have been careful. - m_stopScreenSaver =3D 0; - } + releasePowerSave(); = updateTitleBarText(); =20