Index: sources/gui/guicontroller.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -14,73 +14,110 @@ #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() +// Singleton +SINGLETON_INIT(GuiController) + +GuiController::GuiController(QObject *parent) : QObject(parent) {} + +/*! + * \brief GuiController connections definition + */ +void GuiController::connection() { - 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")); + // From HD/DG + connect(_ApplicationController, SIGNAL(didActionCommand(GuiActionType)), + this , SLOT( onActionCommand(GuiActionType))); + // From HD/DG + connect(_ApplicationController, SIGNAL(didActionConfirm(GuiActionType, GuiActionInfo)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); + } -GuiController::GuiController(QObject *parent) : QObject(parent) + +/*! + * \brief GuiController initializer + */ +void GuiController::init() { - registerView(); - connect(this ,&GuiController::actionRequested, this, &GuiController::actionEvaluation); + connection(); } -GuiController *GuiController::I() +/*! + * \brief GuiController::onActionRequest + * 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::doActionRequest(GuiActionType vAction) { - if (!_instance) { - _instance = new GuiController(); + // Process the GuiView Request. + // If can be processed in GuiController take action and notify GuiView + qDebug() << "GuiController.actionRequested : " << vAction; + GuiActionInfo mInfo = GuiActionInfo::Accepted; + Q_UNUSED(mInfo) + switch (vAction) { + // TODO : Test Code + case GuiActionType::PowerOff: + emit didActionConfirm(vAction, mInfo); + break; + default: + // If it requires to be Confirmed by HD/DG send the request to ApplicationController + emit didActionRequest(vAction); + break; } - return _instance; } -void GuiController::init() +/*! + * \brief Process the performed action + * \details An action which has been commanded by HD has been performed by Gui.\n + * Gui notifies that the action has been performed + * \param vAction + * \param vInfo + */ +void GuiController::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) { - connect(&_viewer, &QQuickView::statusChanged, this, &GuiController::onUiStatusChanged); - const QUrl url(QML("main")); - _viewer.setSource(url); + qDebug() << "GuiController.actionPerformed : " << vAction << vInfo; + // Process the performed action by Gui + // Process ... + emit didActionPerform(vAction, vInfo); } -void GuiController::onUiStatusChanged(QQuickView::Status vStatus) +/*! + * \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::onActionCommand(GuiActionType vAction) { - bool ok = vStatus == QQuickView::Ready; - if (ok) { - _viewer.show(); - } - emit initialized(ok); + qDebug() << "GuiController.actionCommanded : " << vAction; + // Process the command and notify GuiView + // Process ... + emit didActionCommand(vAction); } /*! - * \brief GuiController::actionEvaluation - * This method evaluated that if the action is accepted or not,\n - * Regarding to 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 + * \brief An action has been confirmed + * \details Gui requested an action. + * In response HD confirmed the action. + * \param vAction + * \param vInfo */ -void GuiController::actionEvaluation(GuiAction vAction) +void GuiController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) { - //static bool requested = false; - qDebug() << "actionRequested : " << vAction; - - // 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); + qDebug() << "GuiController.actionConfirmed : " << vAction; + // Process the command and notify GuiView + // Process ... + emit didActionConfirm(vAction, vInfo); }