Index: sources/gui/guicontroller.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -rc933552983a659ca4cc351ff4d43d07319adab1e --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision c933552983a659ca4cc351ff4d43d07319adab1e) @@ -14,73 +14,92 @@ #include "guicontroller.h" // Qt +#include // Project -#include "guiview.h" -#include "maintimer.h" +#include "applicationcontroller.h" +// namespace using namespace Gui; -GuiController *GuiController::_instance = nullptr; -void GuiController::registerView() -{ - qRegisterMetaType("GuiAction"); - qmlRegisterType ("Gui.View", 0, 1, "GuiView"); - qmlRegisterUncreatableType ("Gui.Actions", 0, 1, "GuiActions",QStringLiteral("Used only for enums no need to have an object")); -} +// Singleton +SINGLETON_INIT(GuiController) -GuiController::GuiController(QObject *parent) : QObject(parent) -{ - registerView(); - connect(this ,&GuiController::actionRequested, this, &GuiController::actionEvaluation); -} +/*! + * \brief GuiController Constructor + * \param parent + */ +GuiController::GuiController(QObject *parent) : QObject(parent) {} -GuiController *GuiController::I() +/*! + * \brief GuiController connections definition + */ +void GuiController::initConnections() { - if (!_instance) { - _instance = new GuiController(); - } - return _instance; + // From HD/DG + connect(_ApplicationController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); } +/*! + * \brief GuiController initializer + */ void GuiController::init() { - connect(&_viewer, &QQuickView::statusChanged, this, &GuiController::onUiStatusChanged); - const QUrl url(QML("main")); - _viewer.setSource(url); + initConnections(); } -void GuiController::onUiStatusChanged(QQuickView::Status vStatus) -{ - bool ok = vStatus == QQuickView::Ready; - if (ok) { - _viewer.show(); - } - emit initialized(ok); -} - /*! - * \brief GuiController::actionEvaluation - * This method evaluated that if the action is accepted or not,\n - * Regarding to the current state and the action.\n + * \brief An Action has been requested + * \details This method Confirmed that if the action is accepted or not,\n + * Regarding the current state and the action.\n * These actions are only user actions and there is only one user interaction,\n * So no need to capture from which screen this action comes since we have the current state.\n * Sometimes GuiController requires to investigate with the ApplicationController to get approval from HD device.\n * \param vAction - User requested Action */ -void GuiController::actionEvaluation(GuiAction vAction) +void GuiController::doActionTransmit(GuiActionType vAction, const QVariantList &vData) { - //static bool requested = false; - qDebug() << "actionRequested : " << vAction; + if (! handleTransmit(vAction, vData)) { + emit didActionTransmit(vAction, vData); + } +} - // TEST : check state and evaluate. - // if (!requested) { - // requested = true; - // qDebug() << "Ask again: " << vAction; - // actionEvaluated(vAction, false); - // return; - // } - // requested = false; - qDebug() << "Got it: " << vAction; - actionEvaluated(vAction, true); +bool GuiController::handleTransmit(GuiActionType, const QVariantList &) +{ + // This is an example implementation of how to handle + // which does not require HD approval in GuiController + /* + // Process the GuiView Request. + // It can be processed in GuiController take action and notify GuiView + switch (vAction) { + case GuiActionType::PowerOff: + // GUI Controller decides (loop back) + if (vData == GuiActionData::NoData){ + // PowerOff noData is a request + emit didActionReceive (vAction, GuiActionData::Accepted); + return true; + } + break; + //case Another_Command_Which_Doesn't_Require_HD_Approval: + //return true; + //break; + default: + break; + } + */ + return false; } + +/*! + * \brief Action commanded by HD + * \details An action has been commanded by HD, + * Gui requires to be notified to perform the action. + * \param vAction + */ +void GuiController::onActionReceive (GuiActionType vAction, const QVariantList &vData) +{ + // Process the command and notify GuiView + // Process ... + emit didActionReceive (vAction, vData); +}