File indexing completed on 2025-02-02 05:26:32

0001 /*
0002     SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "serviceoperationstatus.h"
0008 
0009 ServiceOperationStatus::ServiceOperationStatus(QObject *parent)
0010     : QObject(parent)
0011     , m_enabled(false)
0012 {
0013 }
0014 
0015 ServiceOperationStatus::~ServiceOperationStatus()
0016 {
0017 }
0018 
0019 void ServiceOperationStatus::setService(Plasma5Support::Service *service)
0020 {
0021     if (m_service.data() == service) {
0022         return;
0023     }
0024 
0025     if (m_service) {
0026         disconnect(m_service.data(), nullptr, this, nullptr);
0027     }
0028     if (service) {
0029         connect(service, &Plasma5Support::Service::operationEnabledChanged, this, &ServiceOperationStatus::updateStatus);
0030     }
0031 
0032     m_service = service;
0033     updateStatus();
0034     Q_EMIT serviceChanged();
0035 }
0036 
0037 Plasma5Support::Service *ServiceOperationStatus::service() const
0038 {
0039     return m_service.data();
0040 }
0041 
0042 void ServiceOperationStatus::setOperation(const QString &operation)
0043 {
0044     if (m_operation == operation) {
0045         return;
0046     }
0047 
0048     m_operation = operation;
0049     updateStatus();
0050     Q_EMIT operationChanged();
0051 }
0052 
0053 QString ServiceOperationStatus::operation() const
0054 {
0055     return m_operation;
0056 }
0057 
0058 void ServiceOperationStatus::setEnabled(bool enabled)
0059 {
0060     if (m_enabled == enabled) {
0061         return;
0062     }
0063 
0064     m_enabled = enabled;
0065     updateStatus();
0066     Q_EMIT enabledChanged();
0067 }
0068 
0069 bool ServiceOperationStatus::isEnabled() const
0070 {
0071     return m_enabled;
0072 }
0073 
0074 void ServiceOperationStatus::updateStatus()
0075 {
0076     if (!m_service) {
0077         return;
0078     }
0079 
0080     bool enabled = m_service.data()->isOperationEnabled(m_operation);
0081     if (enabled != m_enabled) {
0082         m_enabled = enabled;
0083         Q_EMIT enabledChanged();
0084     }
0085 }
0086 
0087 #include "moc_serviceoperationstatus.cpp"