Baloo

powerstatemonitor.cpp
1/*
2 This file is part of the KDE Project
3 SPDX-FileCopyrightText: 2008 Sebastian Trueg <trueg@kde.org>
4 SPDX-FileCopyrightText: 2010-15 Vishesh Handa <vhanda@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "powerstatemonitor.h"
10
11#include <QDBusConnection>
12#include <QDBusMessage>
13#include <QDBusPendingCallWatcher>
14#include <QDBusPendingReply>
15
16using namespace Baloo;
17
18PowerStateMonitor::PowerStateMonitor(QObject* parent)
19 : QObject(parent)
20 , m_isOnBattery(true)
21{
22 // monitor the powermanagement to not drain the battery
23 QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.PowerManagement"),
24 QStringLiteral("/org/freedesktop/PowerManagement"),
25 QStringLiteral("org.freedesktop.PowerManagement"),
26 QStringLiteral("PowerSaveStatusChanged"),
27 this, SLOT(slotPowerManagementStatusChanged(bool)));
28
29 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.PowerManagement"),
30 QStringLiteral("/org/freedesktop/PowerManagement"),
31 QStringLiteral("org.freedesktop.PowerManagement"),
32 QStringLiteral("GetPowerSaveStatus"));
33
35 QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(call, this);
37 QDBusPendingReply<bool> reply = *watch;
38 if (!reply.isError()) {
39 bool onBattery = reply.argumentAt<0>();
40 slotPowerManagementStatusChanged(onBattery);
41 } else {
42 slotPowerManagementStatusChanged(false);
43 }
44 watch->deleteLater();
45 });
46}
47
48void PowerStateMonitor::slotPowerManagementStatusChanged(bool conserveResources)
49{
50 if (m_isOnBattery != conserveResources) {
51 m_isOnBattery = conserveResources;
52 Q_EMIT powerManagementStatusChanged(conserveResources);
53 }
54}
55
56#include "moc_powerstatemonitor.cpp"
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout) const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
void finished(QDBusPendingCallWatcher *self)
QVariant argumentAt(int index) const const
bool isError() const const
Q_EMITQ_EMIT
void deleteLater()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.