mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
kmediaplayer: supress screen power management while playing
feels like adding cherry on top, I want to release soon tho.. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
de6f7c87f0
commit
bd0e1a7688
3 changed files with 45 additions and 2 deletions
|
@ -9,6 +9,7 @@ target_link_libraries(kmediaplayer
|
|||
KDE4::kfile
|
||||
KDE4::kcmutils
|
||||
KDE4::kmediaplayer
|
||||
KDE4::solid
|
||||
)
|
||||
|
||||
# part
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <KStatusBar>
|
||||
#include <KMessageBox>
|
||||
#include <KConfigGroup>
|
||||
#include <Solid/PowerManagement>
|
||||
#include <QApplication>
|
||||
#include <QMenuBar>
|
||||
|
||||
|
@ -42,12 +43,16 @@ KMediaWindow::KMediaWindow(QWidget *parent, Qt::WindowFlags flags)
|
|||
m_recentfiles(nullptr),
|
||||
m_menu(nullptr),
|
||||
m_currenttime(float(0.0)),
|
||||
m_playing(true)
|
||||
m_playing(true),
|
||||
m_inhibition(0)
|
||||
{
|
||||
m_config = new KConfig("kmediaplayerrc", KConfig::SimpleConfig);
|
||||
|
||||
m_player = new KMediaWidget(this, KMediaWidget::AllOptions);
|
||||
m_player->player()->setPlayerID("kmediaplayer");
|
||||
connect(m_player->player(), SIGNAL(loaded()), this, SLOT(slotInhibit()));
|
||||
connect(m_player->player(), SIGNAL(paused(bool)), this, SLOT(slotMaybeInhibit(bool)));
|
||||
connect(m_player->player(), SIGNAL(finished()), this, SLOT(slotUninhibit()));
|
||||
|
||||
setCentralWidget(m_player);
|
||||
|
||||
|
@ -115,7 +120,7 @@ KMediaWindow::~KMediaWindow()
|
|||
KConfigGroup firstrungroup(m_config, "KMediaPlayer");
|
||||
firstrungroup.writeEntry("firstrun", false);
|
||||
|
||||
m_player->deleteLater();
|
||||
delete m_player;
|
||||
m_recentfiles->deleteLater();
|
||||
m_menu->deleteLater();
|
||||
delete m_config;
|
||||
|
@ -193,10 +198,43 @@ void KMediaWindow::slotMenu(QPoint position)
|
|||
|
||||
void KMediaWindow::slotQuit()
|
||||
{
|
||||
slotUninhibit();
|
||||
|
||||
KMediaWindow::close();
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void KMediaWindow::slotInhibit()
|
||||
{
|
||||
if (!m_inhibition) {
|
||||
m_inhibition = Solid::PowerManagement::beginSuppressingScreenPowerManagement(QString::fromLatin1("KMediaPlayer playing"));
|
||||
if (!m_inhibition) {
|
||||
kWarning() << "Could not inhibit";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWindow::slotMaybeInhibit(bool paused)
|
||||
{
|
||||
if (paused) {
|
||||
slotUninhibit();
|
||||
} else {
|
||||
slotInhibit();
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWindow::slotUninhibit()
|
||||
{
|
||||
if (m_inhibition) {
|
||||
const bool diduninhibit = Solid::PowerManagement::stopSuppressingScreenPowerManagement(m_inhibition);
|
||||
if (diduninhibit) {
|
||||
m_inhibition = 0;
|
||||
} else {
|
||||
kWarning() << "Could not uninhibit";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWindow::slotDelayedRestore()
|
||||
{
|
||||
disconnect(m_player->player(), SIGNAL(loaded()), this, SLOT(slotDelayedRestore()));
|
||||
|
|
|
@ -43,6 +43,9 @@ public slots:
|
|||
void slotQuit();
|
||||
|
||||
private slots:
|
||||
void slotInhibit();
|
||||
void slotMaybeInhibit(bool paused);
|
||||
void slotUninhibit();
|
||||
void slotDelayedRestore();
|
||||
|
||||
protected:
|
||||
|
@ -57,6 +60,7 @@ private:
|
|||
QMenu *m_menu;
|
||||
float m_currenttime;
|
||||
bool m_playing;
|
||||
int m_inhibition;
|
||||
};
|
||||
|
||||
#endif // KMEDIAWINDOW_H
|
||||
|
|
Loading…
Add table
Reference in a new issue