Index: sources/applicationcontroller.cpp =================================================================== diff -u -re1605219ac2baf49ef21d0889f845ac53d59c3c1 -r56d00a82669a7a2c00ab90109a89dbec8db27527 --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 56d00a82669a7a2c00ab90109a89dbec8db27527) @@ -38,14 +38,47 @@ */ bool ApplicationController::init() { - if (!_applicationPost->init()) return false; + if ( _init ) return false; + _init = true; + initConnections(); + if (!_applicationPost->init()) return false; + + LOG_EVENT(QObject::tr("%1 Initialized").arg(metaObject()->className())); + return true; } /*! - * \brief GUI Controller connections definition + * \brief ApplicationController::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 ApplicationController::init(QThread &vThread) +{ + if ( init() ) return false; + initThread(vThread); + return true; +} + +/*! + * \brief ApplicationController::quit + * \details quits the class + * Calls quitThread + */ +void ApplicationController::quit() +{ + quitThread(); +} + +/*! + * \brief ApplicationController::initConnections + * \details Initializes the required signal/slot connection between this class and other objects + * to be able to communicate. + */ void ApplicationController::initConnections() { @@ -72,6 +105,37 @@ } /*! + * \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 ApplicationController::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 ApplicationController::quitThread + * \details Moves this object to main thread to be handled by QApplicaiton + * And to be destroyed there. + */ +void ApplicationController::quitThread() +{ + if ( ! _thread ) return; + + // runs in thread + moveToThread(qApp->thread()); +} + +/*! * \brief Process the requested action * \details Processes the requested action * \param vAction - User requested Action @@ -103,25 +167,46 @@ keepAlive(); } +/*! + * \brief ApplicationController::onUSBDriveMount + * \details This is the slot which connects to the _USBWatcher didUSBDriveMount signal + * and notifies the other classes (GuiController) by emitting its signal didUSBDriveMount + */ void ApplicationController::onUSBDriveMount () { emit didUSBDriveMount(); } +/*! + * \brief ApplicationController::onUSBDriveRemove + * \details This is the slot which connects to the _GuiController didUSBDriveUmount signal + * and notifies the other classes (USBWatcher) by emitting its signal didUSBDriveUmount + */ void ApplicationController::onUSBDriveUmount() { emit didUSBDriveUmount(); } +/*! + * \brief ApplicationController::onUSBDriveRemove + * \details This is the slot which connects to the _USBWatcher didUSBDriveRemove signal + * and notifies the other classes (GuiController) by emitting its signal didUSBDriveRemove + */ void ApplicationController::onUSBDriveRemove() { emit didUSBDriveRemove(); } +/*! + * \brief ApplicationController::onExportLog + * \details the slot which will be called by UI to so the log export. + */ void ApplicationController::onExportLog() { Storage::FileHandler fh; - fh.exportLog(); + fh.concurrentExportLog(); + //TODO : it needs to change in a way that we can have an actual export finish time and then emit signal. + // this is not accurate. emit didExportLog(); }