Index: sources/gui/guicontroller.cpp =================================================================== diff -u -rde2f87e15fa05b1c45581cfedd8f1af0c47c2b48 -rb9c5b0b3afc3b34d4980ecc4f023f498f80dafbc --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision de2f87e15fa05b1c45581cfedd8f1af0c47c2b48) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision b9c5b0b3afc3b34d4980ecc4f023f498f80dafbc) @@ -1,6 +1,6 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. * \copyright \n * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n * IN PART OR IN WHOLE, \n @@ -14,114 +14,229 @@ #include "guicontroller.h" // Qt -#include +#include +#include // Project +#include "logger.h" #include "applicationcontroller.h" // namespace using namespace Gui; -// Singleton -SINGLETON_INIT(GuiController) - /*! * \brief GuiController Constructor * \param parent */ GuiController::GuiController(QObject *parent) : QObject(parent) {} /*! - * \brief GuiController connections definition + * \brief GuiController::init + * \details Initialized the Class by calling the init() method first + * And initializes the thread vThread by calling initThread + * on success init(). + * \param vThread - the thread + * \return returns the return value of the init() method */ -void GuiController::connection() +bool GuiController::init(QThread &vThread) { + if ( ! init() ) return false; + initThread(vThread); + return true; +} + +/*! + * \brief GuiController::quit + * \details quits the class + * Calls quitThread + */ +void GuiController::quit() +{ + quitThread(); +} + +/*! + * \brief GuiController::initConnections + * \details Initializes the required signal/slot connection between this class and other objects + * to be able to communicate. + */ +void GuiController::initConnections() +{ // 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))); + connect(&_ApplicationController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + // From OS : USB Drive has been removed physically. + connect(&_ApplicationController, SIGNAL(didUSBDriveMount ()), + this , SLOT( onUSBDriveMount ())); + connect(&_ApplicationController, SIGNAL(didUSBDriveRemove()), + this , SLOT( onUSBDriveRemove())); + + connect(&_ApplicationController, SIGNAL(didExport()), + this , SLOT( onExport())); + } +/*! + * \brief ApplicationController::initThread + * \details Moves this object into the thread vThread. + * And checks that this method is called from main thread. + * Also connects quitThread to application aboutToQuit. + * \param vThread - the thread + */ +void GuiController::initThread(QThread &vThread) +{ + // runs in main thread + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , __func__, "The Class initialization must be done in Main Thread" ); + _thread = &vThread; + _thread->setObjectName(QString("%1_Thread").arg(metaObject()->className())); + connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(quit())); + _thread->start(); + moveToThread(_thread); +} /*! + * \brief GuiController::quitThread + * \details Moves this object to main thread to be handled by QApplicaiton + * And to be destroyed there. + */ +void GuiController::quitThread() +{ + if ( ! _thread ) return; + + // runs in thread + moveToThread(qApp->thread()); +} + +/*! * \brief GuiController initializer */ -void GuiController::init() +bool GuiController::init() { - connection(); + if ( _init ) return false; + _init = true; + + initConnections(); + + LOG_EVENT(QObject::tr("%1 Initialized").arg(metaObject()->className())); + + return true; } /*! - * \brief GuiController::onActionRequest - * This method Confirmed that if the action is accepted or not,\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::doActionRequest(GuiActionType vAction) +void GuiController::doActionTransmit(GuiActionType vAction, const QVariantList &vData) { + if (! handleTransmit(vAction, vData)) { + emit didActionTransmit(vAction, vData); + } +} + +/*! + * \brief GuiController::handleTransmit + * \details If an action request from Gui can be handled in Gui Controller + * without passing to HD, then can be handled here. + * \param vAction - the Requested action + * \param vData - Data of the action + * \return if handled returns true to not to pass to the lower level (Application Controller) + * to not to send to HD then. + */ +bool GuiController::handleTransmit(GuiActionType vAction, const QVariantList &vData) +{ + Q_UNUSED(vAction) + Q_UNUSED(vData) + + // This is an example implementation of how to handle + // which does not require HD approval in 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) + // It can be processed in GuiController take action and notify GuiView switch (vAction) { - // TODO : Test Code case GuiActionType::PowerOff: - emit didActionConfirm(vAction, mInfo); + //qApp->quit(); + + // 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: - // If it requires to be Confirmed by HD/DG send the request to ApplicationController - emit didActionRequest(vAction); break; } + return false; } /*! - * \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 + * \brief Action commanded by HD + * \details An action has been commanded by HD, + * Gui requires to be notified to perform the action. * \param vAction - * \param vInfo */ -void GuiController::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +void GuiController::onActionReceive (GuiActionType vAction, const QVariantList &vData) { - // qDebug() << "GuiController.actionPerformed : " << vAction << vInfo; - // Process the performed action by Gui + // Process the command and notify GuiView // Process ... - emit didActionPerform(vAction, vInfo); + emit didActionReceive (vAction, vData); } /*! - * \brief Action commanded by HD - * \details An action has been commanded by HD, - * Gui requires to be notified to perform the action. - * \param vAction + * \brief GuiController::onUSBDriveMount + * \details emits didUSBDriveMount signal to notify other classes (GuiView) + * , the USB drive has been mounted. */ -void GuiController::onActionCommand(GuiActionType vAction) +void GuiController::onUSBDriveMount() { - // qDebug() << "GuiController.actionCommanded : " << vAction; - // Process the command and notify GuiView - // Process ... - emit didActionCommand(vAction); + emit didUSBDriveMount(); } /*! - * \brief An action has been confirmed - * \details Gui requested an action. - * In response HD confirmed the action. - * \param vAction - * \param vInfo + * \brief GuiController::doUSBDriveUmount + * \details emits didUSBDriveUmount signal to notify other classes (GuiView) + * , the USB drive has been unmounted. */ -void GuiController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) +void GuiController::doUSBDriveUmount() { - // qDebug() << "GuiController.actionConfirmed : " << vAction; - // Process the command and notify GuiView - // Process ... - emit didActionConfirm(vAction, vInfo); + emit didUSBDriveUmount(); } + +/*! + * \brief GuiController::onUSBDriveRemove + * \details emits didUSBDriveRemove signal to notify other classes (GuiView) + * , the USB drive has been removed. + */ +void GuiController::onUSBDriveRemove() +{ + emit didUSBDriveRemove(); +} + +/*! + * \brief GuiController::onExport + * \details The slot which will be called to notify the export is done + * by emitting the didExport signal. + */ +void GuiController::onExport() +{ + emit didExport(); +} + +/*! + * \brief GuiController::doExportLog + * \details emits didExportLog signal to notify other classes (ApplicationController) + * , the User requested to export the log. + */ +void GuiController::doExportLog() +{ + emit didExportLog(); +} +