generic: use Solid::PowerManagement for power management

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-07-09 18:24:04 +03:00
parent db8a6a3842
commit 698d7f49c7
4 changed files with 24 additions and 60 deletions

View file

@ -129,6 +129,7 @@ add_library(kgetcore SHARED ${kgetcore_SRCS})
target_link_libraries(kgetcore
KDE4::kio
KDE4::knetworkmanager
KDE4::solid
)
if (KDE4WORKSPACE_FOUND)

View file

@ -44,9 +44,10 @@
#include <KConfigDialog>
#include <KSaveFile>
#include <KWindowSystem>
#include <Solid/PowerManagement>
#include <QTextStream>
#include <QtXml/qdom.h>
#include <QDomElement>
#include <QApplication>
#include <QClipboard>
#include <QAbstractItemView>
@ -54,9 +55,6 @@
#ifdef HAVE_KWORKSPACE
# include <QDBusConnection>
# include <QDBusInterface>
# include <QDBusPendingCall>
# include <kworkspace/kworkspace.h>
#endif
@ -1426,13 +1424,13 @@ void GenericObserver::transfersChangedEvent(QMap<TransferHandler*, Transfer::Cha
case KGet::Shutdown:
notification = KGet::showNotification(KGet::m_mainWindow, "notification", i18n("The computer will now turn off, as all downloads have completed."), "system-shutdown", i18nc("Shutting down computer", "Shutdown"), KNotification::Persistent | KNotification::CloseWhenWidgetActivated);
break;
#endif
case KGet::Hibernate:
notification = KGet::showNotification(KGet::m_mainWindow, "notification", i18n("The computer will now suspend to disk, as all downloads have completed."), "system-suspend-hibernate", i18nc("Hibernating computer", "Hibernating"), KNotification::Persistent | KNotification::CloseWhenWidgetActivated);
break;
case KGet::Suspend:
notification = KGet::showNotification(KGet::m_mainWindow, "notification", i18n("The computer will now suspend to RAM, as all downloads have completed."), "system-suspend", i18nc("Suspending computer", "Suspending"), KNotification::Persistent | KNotification::CloseWhenWidgetActivated);
break;
#endif
default:
break;
}
@ -1529,38 +1527,28 @@ bool GenericObserver::allTransfersFinished()
void GenericObserver::slotAfterFinishAction()
{
switch (Settings::afterFinishAction()) {
case KGet::Quit:
case KGet::Quit: {
kDebug() << "Quit Kget.";
QTimer::singleShot(0, KGet::m_mainWindow, SLOT(slotQuit()));
break;
}
#ifdef HAVE_KWORKSPACE
case KGet::Shutdown:
case KGet::Shutdown: {
QTimer::singleShot(0, KGet::m_mainWindow, SLOT(slotQuit()));
KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
KWorkSpace::ShutdownTypeHalt,
KWorkSpace::ShutdownModeForceNow);
break;
}
#endif
case KGet::Hibernate: {
QDBusMessage call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement",
"org.freedesktop.PowerManagement",
"Hibernate"
);
QDBusConnection::sessionBus().asyncCall(call);
Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState);
break;
}
case KGet::Suspend: {
QDBusMessage call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement",
"org.freedesktop.PowerManagement",
"Suspend"
);
QDBusConnection::sessionBus().asyncCall(call);
Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState);
break;
}
#endif
default: {
break;
}

View file

@ -147,8 +147,9 @@ add_library(okularcore SHARED ${okularcore_SRCS})
target_link_libraries(okularcore
KDE4::kio
KDE4::karchive
${MATH_LIB}
KDE4::kmediaplayer
KDE4::solid
${MATH_LIB}
)
set_target_properties(okularcore PROPERTIES

View file

@ -9,12 +9,7 @@
#include "presentationwidget.h"
// qt/kde includes
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusReply>
// Katie/kde includes
#include <qevent.h>
#include <qfontmetrics.h>
#include <kicon.h>
@ -29,9 +24,9 @@
#include <qvalidator.h>
#include <qapplication.h>
#include <qdesktopwidget.h>
#include <qtoolbar.h>
#include <kcursor.h>
#include <krandom.h>
#include <qtoolbar.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <klineedit.h>
@ -41,6 +36,7 @@
#include <kselectaction.h>
#include <kshortcut.h>
#include <kdialog.h>
#include <solid/powermanagement.h>
// system includes
#include <stdlib.h>
@ -1541,43 +1537,21 @@ void PresentationWidget::inhibitPowerManagement()
// Inhibit screen and sleep
// Note: beginSuppressingScreenPowerManagement inhibits DPMS, automatic brightness change and screensaver
QDBusInterface screensaveriface(
"org.freedesktop.ScreenSaver",
"/ScreenSaver",
"org.freedesktop.ScreenSaver",
QDBusConnection::sessionBus()
);
QDBusReply<uint> reply = screensaveriface.call("Inhibit", QString::fromLatin1("okular"), reason);
m_screenInhibitCookie = reply.value();
m_screenInhibitCookie = Solid::PowerManagement::beginSuppressingScreenPowerManagement(reason);
QDBusInterface powermanageriface(
"org.freedesktop.PowerManagement.Inhibit",
"/org/freedesktop/PowerManagement/Inhibit",
"org.freedesktop.PowerManagement.Inhibit",
QDBusConnection::sessionBus()
);
reply = powermanageriface.call("Inhibit", QString::fromLatin1("okular"), reason);
m_sleepInhibitCookie = reply.value();
m_sleepInhibitCookie = Solid::PowerManagement::beginSuppressingSleep(reason);
}
void PresentationWidget::allowPowerManagement()
{
// Remove cookies
QDBusInterface screensaveriface(
"org.freedesktop.ScreenSaver",
"/ScreenSaver",
"org.freedesktop.ScreenSaver",
QDBusConnection::sessionBus()
);
screensaveriface.asyncCall("UnInhibit", m_screenInhibitCookie);
if (m_screenInhibitCookie) {
Solid::PowerManagement::stopSuppressingScreenPowerManagement(m_screenInhibitCookie);
}
QDBusInterface powermanageriface(
"org.freedesktop.PowerManagement.Inhibit",
"/org/freedesktop/PowerManagement/Inhibit",
"org.freedesktop.PowerManagement.Inhibit",
QDBusConnection::sessionBus()
);
powermanageriface.asyncCall("UnInhibit", m_sleepInhibitCookie);
if (m_sleepInhibitCookie) {
Solid::PowerManagement::stopSuppressingSleep(m_sleepInhibitCookie);
}
}
void PresentationWidget::showTopBar( bool show )