File indexing completed on 2025-01-26 05:09:00

0001 /*
0002     SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include "keyservice.h"
0008 
0009 #include <kmodifierkeyinfo.h>
0010 
0011 KeyService::KeyService(QObject *parent, KModifierKeyInfo *keyInfo, Qt::Key key)
0012     : Plasma5Support::Service(parent)
0013     , m_keyInfo(keyInfo)
0014     , m_key(key)
0015 {
0016     setName(QStringLiteral("modifierkeystate"));
0017     setDestination(QStringLiteral("keys"));
0018 }
0019 
0020 Plasma5Support::ServiceJob *KeyService::createJob(const QString &operation, QMap<QString, QVariant> &parameters)
0021 {
0022     if (operation == QLatin1String("Lock")) {
0023         return new LockKeyJob(this, parameters);
0024     } else if (operation == QLatin1String("Latch")) {
0025         return new LatchKeyJob(this, parameters);
0026     }
0027 
0028     return nullptr;
0029 }
0030 
0031 void KeyService::lock(bool lock)
0032 {
0033     m_keyInfo->setKeyLocked(m_key, lock);
0034 }
0035 
0036 void KeyService::latch(bool lock)
0037 {
0038     m_keyInfo->setKeyLatched(m_key, lock);
0039 }
0040 
0041 LockKeyJob::LockKeyJob(KeyService *service, const QMap<QString, QVariant> &parameters)
0042     : Plasma5Support::ServiceJob(service->destination(), QStringLiteral("Lock"), parameters, service)
0043     , m_service(service)
0044 {
0045 }
0046 
0047 void LockKeyJob::start()
0048 {
0049     m_service->lock(parameters().value(QStringLiteral("Lock")).toBool());
0050     setResult(true);
0051 }
0052 
0053 LatchKeyJob::LatchKeyJob(KeyService *service, const QMap<QString, QVariant> &parameters)
0054     : Plasma5Support::ServiceJob(service->destination(), QStringLiteral("Lock"), parameters, service)
0055     , m_service(service)
0056 {
0057 }
0058 
0059 void LatchKeyJob::start()
0060 {
0061     m_service->latch(parameters().value(QStringLiteral("Lock")).toBool());
0062     setResult(true);
0063 }
0064 
0065 // vim: sw=4 sts=4 et tw=100