Index: sources/gui/guicontroller.cpp =================================================================== diff -u -re1605219ac2baf49ef21d0889f845ac53d59c3c1 -r56d00a82669a7a2c00ab90109a89dbec8db27527 --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 56d00a82669a7a2c00ab90109a89dbec8db27527) @@ -14,11 +14,12 @@ #include "guicontroller.h" // Qt -#include +#include +#include // Project -#include "applicationcontroller.h" #include "logger.h" +#include "applicationcontroller.h" // namespace using namespace Gui; @@ -30,8 +31,35 @@ 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 */ +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 @@ -46,12 +74,49 @@ } /*! + * \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() { + if ( _init ) return false; + _init = true; + initConnections(); - LOG_EVENT(QObject::tr("Gui Controller Initialized")); + + LOG_EVENT(QObject::tr("%1 Initialized").arg(metaObject()->className())); + + return true; } /*! @@ -70,29 +135,41 @@ } } -bool GuiController::handleTransmit(GuiActionType, const QVariantList &) +/*! + * \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. // It can be processed in GuiController take action and notify GuiView switch (vAction) { case GuiActionType::PowerOff: + //qApp->quit(); + // GUI Controller decides (loop back) - if (vData == GuiActionData::NoData){ - // PowerOff noData is a request - emit didActionReceive (vAction, GuiActionData::Accepted); - return true; - } + //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; } @@ -109,22 +186,43 @@ emit didActionReceive (vAction, vData); } +/*! + * \brief GuiController::onUSBDriveMount + * \details emits didUSBDriveMount signal to notify other classes (GuiView) + * , the USB drive has been mounted. + */ void GuiController::onUSBDriveMount() { emit didUSBDriveMount(); } +/*! + * \brief GuiController::doUSBDriveUmount + * \details emits didUSBDriveUmount signal to notify other classes (GuiView) + * , the USB drive has been unmounted. + */ void GuiController::doUSBDriveUmount() { emit didUSBDriveUmount(); } -void GuiController::doExportLog() +/*! + * \brief GuiController::onUSBDriveRemove + * \details emits didUSBDriveRemove signal to notify other classes (GuiView) + * , the USB drive has been removed. + */ +void GuiController::onUSBDriveRemove() { - emit didExportLog(); + emit didUSBDriveRemove(); } -void GuiController::onUSBDriveRemove() +/*! + * \brief GuiController::doExportLog + * \details emits didExportLog signal to notify other classes (ApplicationController) + * , the User requested to export the log. + */ +void GuiController::doExportLog() { - emit didUSBDriveRemove(); + emit didExportLog(); } +