Plasma5Support

serviceoperationstatus.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "serviceoperationstatus.h"
8
9ServiceOperationStatus::ServiceOperationStatus(QObject *parent)
10 : QObject(parent)
11 , m_enabled(false)
12{
13}
14
15ServiceOperationStatus::~ServiceOperationStatus()
16{
17}
18
19void ServiceOperationStatus::setService(Plasma5Support::Service *service)
20{
21 if (m_service.data() == service) {
22 return;
23 }
24
25 if (m_service) {
26 disconnect(m_service.data(), nullptr, this, nullptr);
27 }
28 if (service) {
29 connect(service, &Plasma5Support::Service::operationEnabledChanged, this, &ServiceOperationStatus::updateStatus);
30 }
31
32 m_service = service;
33 updateStatus();
34 Q_EMIT serviceChanged();
35}
36
38{
39 return m_service.data();
40}
41
42void ServiceOperationStatus::setOperation(const QString &operation)
43{
44 if (m_operation == operation) {
45 return;
46 }
47
48 m_operation = operation;
49 updateStatus();
50 Q_EMIT operationChanged();
51}
52
54{
55 return m_operation;
56}
57
58void ServiceOperationStatus::setEnabled(bool enabled)
59{
60 if (m_enabled == enabled) {
61 return;
62 }
63
64 m_enabled = enabled;
65 updateStatus();
66 Q_EMIT enabledChanged();
67}
68
69bool ServiceOperationStatus::isEnabled() const
70{
71 return m_enabled;
72}
73
74void ServiceOperationStatus::updateStatus()
75{
76 if (!m_service) {
77 return;
78 }
79
80 bool enabled = m_service.data()->isOperationEnabled(m_operation);
81 if (enabled != m_enabled) {
82 m_enabled = enabled;
83 Q_EMIT enabledChanged();
84 }
85}
86
87#include "moc_serviceoperationstatus.cpp"
This class provides a generic API for write access to settings or services.
Definition service.h:78
void operationEnabledChanged(const QString &operation, bool enabled)
Emitted when an operation got enabled or disabled.
bool enabled
true if the service operation is enabled
QML_ELEMENTPlasma5Support::Service * service
The service instance we want to monitor.
QString operation
the service operation we want to monitor for enabled or disabled status
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
T * data() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.