From 4692c941af499336ee080a438d63eab33b174e27 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 2 May 2013 18:56:00 +0200 Subject: [PATCH] add ServiceOperationStatus binding this class is used to monitor the enabled status of service operations --- src/declarativeimports/core/CMakeLists.txt | 1 + .../core/corebindingsplugin.cpp | 2 + .../core/serviceoperationstatus.cpp | 103 ++++++++++++++++++ .../core/serviceoperationstatus.h | 77 +++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 src/declarativeimports/core/serviceoperationstatus.cpp create mode 100644 src/declarativeimports/core/serviceoperationstatus.h diff --git a/src/declarativeimports/core/CMakeLists.txt b/src/declarativeimports/core/CMakeLists.txt index fa51558db..f25a0851c 100644 --- a/src/declarativeimports/core/CMakeLists.txt +++ b/src/declarativeimports/core/CMakeLists.txt @@ -20,6 +20,7 @@ set(corebindings_SRCS dialog.cpp tooltip.cpp tooltipdialog.cpp + serviceoperationstatus.cpp dataenginebindings.cpp iconitem.cpp plasmanamespace.cpp diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index 3a59ab9dd..a7e51642c 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -40,6 +40,7 @@ #include "theme.h" #include "dialog.h" #include "iconitem.h" +#include "serviceoperationstatus.h" #include "tooltip.h" @@ -97,6 +98,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qRegisterMetaType("Service"); qmlRegisterInterface("ServiceJob"); qRegisterMetaType("ServiceJob"); + qmlRegisterType(uri, 2, 0, "ServiceOperationStatus"); qmlRegisterType(); qmlRegisterType(uri, 2, 0, "RunnerModel"); diff --git a/src/declarativeimports/core/serviceoperationstatus.cpp b/src/declarativeimports/core/serviceoperationstatus.cpp new file mode 100644 index 000000000..aa9f76ccc --- /dev/null +++ b/src/declarativeimports/core/serviceoperationstatus.cpp @@ -0,0 +1,103 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "serviceoperationstatus.h" + + + +ServiceOperationStatus::ServiceOperationStatus(QObject *parent) + : QObject(parent), + m_enabled(false) +{ +} + +ServiceOperationStatus::~ServiceOperationStatus() +{ +} + +void ServiceOperationStatus::setService(Plasma::Service *service) +{ + if (m_service.data() == service) { + return; + } + + if (m_service) { + disconnect(m_service.data(), 0, this, 0); + } + if (service) { + connect(service, &Plasma::Service::operationEnabledChanged, + this, &ServiceOperationStatus::updateStatus); + } + + m_service = service; + updateStatus(); + emit serviceChanged(); +} + +Plasma::Service *ServiceOperationStatus::service() const +{ + return m_service.data(); +} + +void ServiceOperationStatus::setOperation(const QString &operation) +{ + if (m_operation == operation) { + return; + } + + m_operation = operation; + updateStatus(); + emit operationChanged(); +} + +QString ServiceOperationStatus::operation() const +{ + return m_operation; +} + +void ServiceOperationStatus::setEnabled(bool enabled) +{ + if (m_enabled == enabled) { + return; + } + + m_enabled = enabled; + updateStatus(); + emit enabledChanged(); +} + +bool ServiceOperationStatus::isEnabled() const +{ + return m_enabled; +} + +void ServiceOperationStatus::updateStatus() +{ + if (!m_service) { + return; + } + + bool enabled = m_service.data()->isOperationEnabled(m_operation); + if (enabled != m_enabled) { + m_enabled = enabled; + emit enabledChanged(); + } +} + +#include "serviceoperationstatus.moc" diff --git a/src/declarativeimports/core/serviceoperationstatus.h b/src/declarativeimports/core/serviceoperationstatus.h new file mode 100644 index 000000000..ce93132fe --- /dev/null +++ b/src/declarativeimports/core/serviceoperationstatus.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright 2013 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ +#ifndef SERVICEOPERATIONSTATUS_P +#define SERVICEOPERATIONSTATUS_P + +#include + +#include "plasma/service.h" + +namespace Plasma { + class Service; +} + +class ServiceOperationStatus : public QObject +{ + Q_OBJECT + + /** + * The service instance we want to monitor + */ + Q_PROPERTY(Plasma::Service *service READ service WRITE setService NOTIFY serviceChanged) + + /** + * the service operation we want to monitor for enabled or disabled status + */ + Q_PROPERTY(QString operation READ operation WRITE setOperation NOTIFY operationChanged) + + /** + * true if the service operation is enabled + */ + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + +public: + ServiceOperationStatus(QObject *parent=0); + ~ServiceOperationStatus(); + + void setService(Plasma::Service *service); + Plasma::Service *service() const; + + void setOperation(const QString &operation); + QString operation() const; + + void setEnabled(bool enabled); + bool isEnabled() const; + +Q_SIGNALS: + void serviceChanged(); + void operationChanged(); + void enabledChanged(); + +private Q_SLOTS: + void updateStatus(); + +private: + QWeakPointer m_service; + QString m_operation; + bool m_enabled; +}; + + +#endif