Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8b9b0d55 authored by James D. Smith's avatar James D. Smith

Inhibit power management when playing audio.

parent 5bcbd5fd
......@@ -17,6 +17,7 @@
#include "juk.h"
#include <kaboutdata.h>
#include <kmessagebox.h>
#include <kactioncollection.h>
#include <kstandardaction.h>
......@@ -39,6 +40,9 @@
#include <QTimer>
#include <QDesktopWidget>
#include <QStatusBar>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDBusInterface>
#include "slideraction.h"
#include "statuslabel.h"
......@@ -79,7 +83,8 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent) :
m_player(new PlayerManager),
m_scrobbler(nullptr),
m_filesToOpen(filesToOpen),
m_shuttingDown(false)
m_shuttingDown(false),
m_pmToken(0)
{
// Expect segfaults if you change this order.
......@@ -120,6 +125,38 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent) :
setupGlobalAccels();
activateScrobblerIfEnabled();
QDBusInterface *pmInterface = new QDBusInterface(QStringLiteral("org.kde.Solid.PowerManagement"),
QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"),
QStringLiteral("org.freedesktop.PowerManagement.Inhibit"),
QDBusConnection::sessionBus());
connect(m_player, &PlayerManager::signalPlay, [=] () {
QDBusReply<uint> reply;
if (pmInterface->isValid() && (m_pmToken == 0)) {
reply = pmInterface->call(QStringLiteral("Inhibit"),
KAboutData::applicationData().componentName(),
QStringLiteral("playing audio"));
if (reply.isValid()) {
m_pmToken = reply.value();
qCDebug(JUK_LOG) << "Inhibiting power management";
}
}
});
auto uninhibitPowerManagement = [=] () {
QDBusMessage reply;
if (pmInterface->isValid() && (m_pmToken != 0)) {
reply = pmInterface->call(QStringLiteral("UnInhibit"), m_pmToken);
if (reply.errorName().isEmpty()) {
m_pmToken = 0;
qCDebug(JUK_LOG) << "Uninhibiting power management";
}
}
};
connect(m_player, &PlayerManager::signalPause, uninhibitPowerManagement);
connect(m_player, &PlayerManager::signalStop, uninhibitPowerManagement);
// The system tray quit command will go straight to qApp->quit without calling
// our quit action, so make sure we save config changes no matter how quit is
// called.
......
......@@ -96,6 +96,7 @@ private:
QStringList m_filesToOpen;
bool m_startDocked;
bool m_shuttingDown;
uint m_pmToken;
static JuK* m_instance;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment