Solid

solid-power.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "solid-power.h"
8
9#include <solid/acpluggedjob.h>
10#include <solid/power.h>
11
12#include <QTextStream>
13
14using namespace Solid;
15using namespace std;
16
17static QTextStream sCout(stdout);
18
19SolidPower::SolidPower(QObject *parent)
20 : QObject(parent)
21{
22}
23
24void SolidPower::show()
25{
26 auto job = Solid::Power::isAcPlugged(this);
27 job->exec();
28
29 QString status = job->isPlugged() ? "yes" : "no";
30
31 sCout << "is AC plugged:\t" << status << Qt::endl;
32}
33
34void SolidPower::listen()
35{
36 auto power = Power::self();
37
38 connect(power, &Power::acPluggedChanged, [](bool plugged) {
39 QTextStream lOut(stdout);
40 QString status = plugged ? "yes" : "no";
41 lOut << "\tAC plugged changed:\t" << status << Qt::endl;
42 });
43
44 connect(power, &Power::aboutToSuspend, []() {
45 QTextStream lOut(stdout);
46 lOut << "\tAbout to suspend" << Qt::endl;
47 });
48
49 connect(power, &Power::resumeFromSuspend, []() {
50 QTextStream lOut(stdout);
51 lOut << "\tResume from suspend" << Qt::endl;
52 });
53}
54
55#include "moc_solid-power.cpp"
Q_SCRIPTABLE CaptureState status()
The single responsibility of this class is to create arguments valid for logind Inhibit call.
Definition fakebattery.h:16
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QTextStream & endl(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:56:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.