Index: sources/ApplicationController.cpp =================================================================== diff -u -ra3030123e885fb9f22dea5839c4e988896a257e4 -r6581def57942b1c1ef56a2f2feb74559946517b9 --- sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision a3030123e885fb9f22dea5839c4e988896a257e4) +++ sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision 6581def57942b1c1ef56a2f2feb74559946517b9) @@ -5,16 +5,17 @@ * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * - * \file ApplicationController.cpp - * \author (last) Peter Lucia - * \date (last) 15-Oct-2020 - * \author (original) Behrouz NematiPour - * \date (original) 26-Aug-2020 + * \file ApplicationController.cpp + * \author (last) Behrouz NematiPour + * \date (last) 29-Mar-2021 + * \author (original) Behrouz NematiPour + * \date (original) 29-Mar-2021 * */ #include "ApplicationController.h" // Qt +#include // Project #include "MainTimer.h" @@ -23,7 +24,10 @@ #include "DriveWatcher.h" #include "FileHandler.h" #include "GuiController.h" +#include "Settings.h" +#include "MSettings.h" + /*! * \brief ApplicationController::ApplicationController * \details Constructor @@ -119,8 +123,15 @@ this , SLOT( onExportLog())); connect(&_Logger , SIGNAL(didExportLogs()), - this , SLOT( onExport())); + this , SLOT( onExport ())); + // Settings - move to application thread + connect(this, SIGNAL(didSettingsInit()), + this, SLOT( onSettingsInit())); + + connect(&_settingsWatcher, SIGNAL(finished ()), + this , SLOT(onSettingsUpdate())); + // ---- Signal/Slots ADJUST_TRANSMT_MODEL_BRIDGE_CONNECTIONS(_GuiController ) ACTION_RECEIVE_MODEL_BRIDGE_CONNECTIONS(_MessageDispatcher) @@ -430,7 +441,6 @@ data += (char)(0); } break; - } Types::safeIncrement(txCount); } @@ -441,3 +451,52 @@ } } // coco end + +/*! + * \brief ApplicationController::initSettings + * \details The external method available to request for initializing the settings + * To start the task in Application Tread, emits a signal which will call a slot to take care of the execution. + */ +void ApplicationController::initSettings() +{ + // this emit guaranties that the slot will be called in the application thread + // also the signal is private so it will be used internally only. + emit didSettingsInit({}); +} + +/*! + * \brief ApplicationController::onSettingsInit + * \details The slot which will be called to start the settings initialization in Application thread. + * This method also initializes the Settings model singleton object to let it live in the Application thread. + * To start the setting initialization QConcurrent is used with QFuture to signal the Application when it's done. + */ +void ApplicationController::onSettingsInit() +{ + // That is enough to call to the I function here to create the object in the thread that Settings is leaving in, + // which currently is Application_Thread, since the Settings is created in that thread. + _SettingModel; + + QFuture mFuture = QtConcurrent::run(this, &ApplicationController::settingsInit); + _settingsWatcher.setFuture(mFuture); +} + +/*! + * \brief onSettingsUpdate + * \details when the Settings reads the .conf files and fills the MSettings emits this finished signal + * then this slot is called to notify the GuiController about the settings that being ready. + */ +void ApplicationController::onSettingsUpdate() +{ + onActionReceive(SettingsData()); +} + +/*! + * \brief ApplicationController::settingsInit + * \details The Settings read function is called in this method. + * This callback function for the QCuncurrnent run. + */ +void ApplicationController::settingsInit() +{ + Storage::Settings settings; + settings.read(); +}