File indexing completed on 2024-04-28 04:00:50

0001 /*
0002     SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "solid-power.h"
0008 
0009 #include <solid/acpluggedjob.h>
0010 #include <solid/power.h>
0011 
0012 #include <QTextStream>
0013 
0014 using namespace Solid;
0015 using namespace std;
0016 
0017 static QTextStream sCout(stdout);
0018 
0019 SolidPower::SolidPower(QObject *parent)
0020     : QObject(parent)
0021 {
0022 }
0023 
0024 void SolidPower::show()
0025 {
0026     auto job = Solid::Power::isAcPlugged(this);
0027     job->exec();
0028 
0029     QString status = job->isPlugged() ? "yes" : "no";
0030 
0031     sCout << "is AC plugged:\t" << status << Qt::endl;
0032 }
0033 
0034 void SolidPower::listen()
0035 {
0036     auto power = Power::self();
0037 
0038     connect(power, &Power::acPluggedChanged, [](bool plugged) {
0039         QTextStream lOut(stdout);
0040         QString status = plugged ? "yes" : "no";
0041         lOut << "\tAC plugged changed:\t" << status << Qt::endl;
0042     });
0043 
0044     connect(power, &Power::aboutToSuspend, []() {
0045         QTextStream lOut(stdout);
0046         lOut << "\tAbout to suspend" << Qt::endl;
0047     });
0048 
0049     connect(power, &Power::resumeFromSuspend, []() {
0050         QTextStream lOut(stdout);
0051         lOut << "\tResume from suspend" << Qt::endl;
0052     });
0053 }
0054 
0055 #include "moc_solid-power.cpp"