add ServiceOperationStatus binding

this class is used to monitor the enabled status of service operations
This commit is contained in:
Marco Martin 2013-05-02 18:56:00 +02:00
parent 8f61ecbe49
commit 4692c941af
4 changed files with 183 additions and 0 deletions

View File

@ -20,6 +20,7 @@ set(corebindings_SRCS
dialog.cpp dialog.cpp
tooltip.cpp tooltip.cpp
tooltipdialog.cpp tooltipdialog.cpp
serviceoperationstatus.cpp
dataenginebindings.cpp dataenginebindings.cpp
iconitem.cpp iconitem.cpp
plasmanamespace.cpp plasmanamespace.cpp

View File

@ -40,6 +40,7 @@
#include "theme.h" #include "theme.h"
#include "dialog.h" #include "dialog.h"
#include "iconitem.h" #include "iconitem.h"
#include "serviceoperationstatus.h"
#include "tooltip.h" #include "tooltip.h"
@ -97,6 +98,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
qRegisterMetaType<Plasma::Service*>("Service"); qRegisterMetaType<Plasma::Service*>("Service");
qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob"); qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob");
qRegisterMetaType<Plasma::ServiceJob*>("ServiceJob"); qRegisterMetaType<Plasma::ServiceJob*>("ServiceJob");
qmlRegisterType<ServiceOperationStatus>(uri, 2, 0, "ServiceOperationStatus");
qmlRegisterType<QAbstractItemModel>(); qmlRegisterType<QAbstractItemModel>();
qmlRegisterType<RunnerModel>(uri, 2, 0, "RunnerModel"); qmlRegisterType<RunnerModel>(uri, 2, 0, "RunnerModel");

View File

@ -0,0 +1,103 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* 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"

View File

@ -0,0 +1,77 @@
/***************************************************************************
* Copyright 2013 Marco Martin <mart@kde.org> *
* *
* 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 <QObject>
#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<Plasma::Service> m_service;
QString m_operation;
bool m_enabled;
};
#endif