From 021dde561b5ce86820013c681ff554b07590b052 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 4 Jan 2016 23:24:43 +0100 Subject: Prototype of the action system --- framework/actions/actionhandler.cpp | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 framework/actions/actionhandler.cpp (limited to 'framework/actions/actionhandler.cpp') diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp new file mode 100644 index 00000000..748c2303 --- /dev/null +++ b/framework/actions/actionhandler.cpp @@ -0,0 +1,70 @@ +/* + Copyright (c) 2016 Christian Mollekopf + + This library 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 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "actionhandler.h" + +#include "context.h" +#include "actionbroker.h" +#include + +using namespace Kube; + +ActionHandler::ActionHandler(QObject *parent) + : QObject(parent) +{ + +} + +bool ActionHandler::isActionReady(Context *context) +{ + if (context) { + QVariant returnedValue; + QMetaObject::invokeMethod(this, "isReady", + Q_RETURN_ARG(QVariant, returnedValue), + Q_ARG(QVariant, QVariant::fromValue(context))); + return returnedValue.toBool(); + } else { + qWarning() << "The handler didn't get a context"; + } + return false; +} + +void ActionHandler::execute(Context *context) +{ + QVariant returnedValue; + qWarning() << "Executing the handler"; + if (context) { + QMetaObject::invokeMethod(this, "handler", + Q_RETURN_ARG(QVariant, returnedValue), + Q_ARG(QVariant, QVariant::fromValue(context))); + } else { + qWarning() << "The handler didn't get a context"; + } +} + +void ActionHandler::setActionId(const QByteArray &actionId) +{ + mActionId = actionId; + ActionBroker::instance().registerHandler(actionId, this); +} + +QByteArray ActionHandler::actionId() const +{ + return mActionId; +} -- cgit v1.2.3