Plasma5Support

keyservice.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "keyservice.h"
8
9#include <kmodifierkeyinfo.h>
10
11KeyService::KeyService(QObject *parent, KModifierKeyInfo *keyInfo, Qt::Key key)
12 : Plasma5Support::Service(parent)
13 , m_keyInfo(keyInfo)
14 , m_key(key)
15{
16 setName(QStringLiteral("modifierkeystate"));
17 setDestination(QStringLiteral("keys"));
18}
19
20Plasma5Support::ServiceJob *KeyService::createJob(const QString &operation, QMap<QString, QVariant> &parameters)
21{
22 if (operation == QLatin1String("Lock")) {
23 return new LockKeyJob(this, parameters);
24 } else if (operation == QLatin1String("Latch")) {
25 return new LatchKeyJob(this, parameters);
26 }
27
28 return nullptr;
29}
30
31void KeyService::lock(bool lock)
32{
33 m_keyInfo->setKeyLocked(m_key, lock);
34}
35
36void KeyService::latch(bool lock)
37{
38 m_keyInfo->setKeyLatched(m_key, lock);
39}
40
41LockKeyJob::LockKeyJob(KeyService *service, const QMap<QString, QVariant> &parameters)
42 : Plasma5Support::ServiceJob(service->destination(), QStringLiteral("Lock"), parameters, service)
43 , m_service(service)
44{
45}
46
47void LockKeyJob::start()
48{
49 m_service->lock(parameters().value(QStringLiteral("Lock")).toBool());
50 setResult(true);
51}
52
53LatchKeyJob::LatchKeyJob(KeyService *service, const QMap<QString, QVariant> &parameters)
54 : Plasma5Support::ServiceJob(service->destination(), QStringLiteral("Lock"), parameters, service)
55 , m_service(service)
56{
57}
58
59void LatchKeyJob::start()
60{
61 m_service->latch(parameters().value(QStringLiteral("Lock")).toBool());
62 setResult(true);
63}
64
65// vim: sw=4 sts=4 et tw=100
bool setKeyLocked(Qt::Key key, bool locked)
bool setKeyLatched(Qt::Key key, bool latched)
This class provides jobs for use with Plasma5Support::Service.
Definition servicejob.h:39
QVariantMap parameters() const
void setResult(const QVariant &result)
Sets the result for an operation.
Namespace for everything in libplasma.
Definition datamodel.cpp:15
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.