OSDN Git Service

generic: use Solid::PowerManagement for power management
authorIvailo Monev <xakepa10@gmail.com>
Sun, 9 Jul 2023 15:24:04 +0000 (18:24 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 9 Jul 2023 15:24:04 +0000 (18:24 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kget/CMakeLists.txt
kget/core/kget.cpp
okular/CMakeLists.txt
okular/ui/presentationwidget.cpp

index 2371d02..2923102 100644 (file)
@@ -129,6 +129,7 @@ add_library(kgetcore SHARED ${kgetcore_SRCS})
 target_link_libraries(kgetcore
     KDE4::kio
     KDE4::knetworkmanager
+    KDE4::solid
 )
 
 if (KDE4WORKSPACE_FOUND)
index fbe7c5e..3059cf8 100644 (file)
 #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;
         }
index 3ffb875..00c2860 100644 (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
index e0a7ea5..6f09b54 100644 (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();
-
-    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_screenInhibitCookie = Solid::PowerManagement::beginSuppressingScreenPowerManagement(reason);
+
+    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);
-
-    QDBusInterface powermanageriface(
-        "org.freedesktop.PowerManagement.Inhibit",
-        "/org/freedesktop/PowerManagement/Inhibit",
-        "org.freedesktop.PowerManagement.Inhibit",
-        QDBusConnection::sessionBus()
-    );
-    powermanageriface.asyncCall("UnInhibit", m_sleepInhibitCookie);
+    if (m_screenInhibitCookie) {
+        Solid::PowerManagement::stopSuppressingScreenPowerManagement(m_screenInhibitCookie);
+    }
+
+    if (m_sleepInhibitCookie) {
+        Solid::PowerManagement::stopSuppressingSleep(m_sleepInhibitCookie);
+    }
 }
 
 void PresentationWidget::showTopBar( bool show )