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

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 "acpluggedjob.h"
0008 #include "acpluggedjob_p.h"
0009 #include "backends/abstractacpluggedjob.h"
0010 #include "powerbackendloader.h"
0011 
0012 #include <QDebug>
0013 
0014 using namespace Solid;
0015 
0016 AcPluggedJobPrivate::AcPluggedJobPrivate()
0017 {
0018     backendJob = nullptr;
0019     plugged = false;
0020     backendJobFinished = false;
0021 }
0022 
0023 AcPluggedJob::AcPluggedJob(QObject *parent)
0024     : Job(*new AcPluggedJobPrivate(), parent)
0025 {
0026 }
0027 
0028 void AcPluggedJob::doStart()
0029 {
0030     Q_D(AcPluggedJob);
0031     d->backendJob = PowerBackendLoader::AcPluggedJob();
0032     connect(d->backendJob, &AbstractAcPluggedJob::result, [this, d]() {
0033         d->backendJobFinished = true;
0034         d->plugged = d->backendJob->isPlugged();
0035         emitResult();
0036     });
0037 
0038     d->backendJob->start();
0039 }
0040 
0041 bool AcPluggedJob::isPlugged() const
0042 {
0043     if (d_func()->backendJobFinished) {
0044         return d_func()->plugged;
0045     }
0046     qWarning() << "isPlugged called without having called start";
0047     return false;
0048 }
0049 
0050 #include "moc_acpluggedjob.cpp"