File indexing completed on 2025-02-09 04:31:51
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 "power.h" 0008 #include "acpluggedjob.h" 0009 #include "inhibition.h" 0010 #include "inhibitionjob.h" 0011 #include "powerbackendloader.h" 0012 #include "requeststatejob.h" 0013 #include "statesjob.h" 0014 0015 #include "backends/powernotifier.h" 0016 0017 Q_GLOBAL_STATIC(Solid::Power, globalPowerObject) 0018 0019 using namespace Solid; 0020 0021 class Power::Private 0022 { 0023 public: 0024 PowerNotifier *notifier; 0025 }; 0026 0027 Power *Power::self() 0028 { 0029 return globalPowerObject; 0030 } 0031 0032 Power::Power(QObject *parent) 0033 : QObject(parent) 0034 , d(new Private) 0035 { 0036 qRegisterMetaType<Solid::Inhibition::State>("Inhibition::State"); 0037 d->notifier = PowerBackendLoader::notifier(); 0038 connect(d->notifier, &PowerNotifier::acPluggedChanged, this, &Power::acPluggedChanged); 0039 connect(d->notifier, &PowerNotifier::aboutToSuspend, this, &Power::aboutToSuspend); 0040 connect(d->notifier, &PowerNotifier::resumeFromSuspend, this, &Power::resumeFromSuspend); 0041 } 0042 0043 AcPluggedJob *Power::isAcPlugged(QObject *parent) 0044 { 0045 return new AcPluggedJob(parent); 0046 } 0047 0048 InhibitionJob *Power::inhibit(Power::InhibitionTypes states, const QString &description, QObject *parent) 0049 { 0050 InhibitionJob *job = new InhibitionJob(parent); 0051 job->setInhibitions(states); 0052 job->setDescription(description); 0053 0054 return job; 0055 } 0056 0057 StatesJob *Power::supportedStates(QObject *parent) 0058 { 0059 return new StatesJob(parent); 0060 } 0061 0062 RequestStateJob *Power::requestState(Power::InhibitionType state, QObject *parent) 0063 { 0064 auto job = new RequestStateJob(parent); 0065 job->setState(state); 0066 0067 return job; 0068 } 0069 0070 #include "moc_power.cpp"