add ServiceOperationStatus binding
this class is used to monitor the enabled status of service operations
This commit is contained in:
parent
8f61ecbe49
commit
4692c941af
@ -20,6 +20,7 @@ set(corebindings_SRCS
|
||||
dialog.cpp
|
||||
tooltip.cpp
|
||||
tooltipdialog.cpp
|
||||
serviceoperationstatus.cpp
|
||||
dataenginebindings.cpp
|
||||
iconitem.cpp
|
||||
plasmanamespace.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<Plasma::Service*>("Service");
|
||||
qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob");
|
||||
qRegisterMetaType<Plasma::ServiceJob*>("ServiceJob");
|
||||
qmlRegisterType<ServiceOperationStatus>(uri, 2, 0, "ServiceOperationStatus");
|
||||
qmlRegisterType<QAbstractItemModel>();
|
||||
|
||||
qmlRegisterType<RunnerModel>(uri, 2, 0, "RunnerModel");
|
||||
|
103
src/declarativeimports/core/serviceoperationstatus.cpp
Normal file
103
src/declarativeimports/core/serviceoperationstatus.cpp
Normal 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"
|
77
src/declarativeimports/core/serviceoperationstatus.h
Normal file
77
src/declarativeimports/core/serviceoperationstatus.h
Normal 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
|
Loading…
Reference in New Issue
Block a user