Index: sources/ApplicationController.cpp =================================================================== diff -u -ra3030123e885fb9f22dea5839c4e988896a257e4 -r821bf955d0ba7e028bccfee7c04ca77cf80a0bd4 --- sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision a3030123e885fb9f22dea5839c4e988896a257e4) +++ sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision 821bf955d0ba7e028bccfee7c04ca77cf80a0bd4) @@ -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,14 @@ 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 , SIGNAL(didSettingsUpdate())); + // ---- Signal/Slots ADJUST_TRANSMT_MODEL_BRIDGE_CONNECTIONS(_GuiController ) ACTION_RECEIVE_MODEL_BRIDGE_CONNECTIONS(_MessageDispatcher) @@ -441,3 +451,46 @@ } } // 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() +{ + PRINT_THREAD_NAME // Main Thread + + // 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() +{ + PRINT_THREAD_NAME + + // has been used 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. + Q_UNUSED(_SettingModel) + + QFuture mFuture = QtConcurrent::run(this, &ApplicationController::settingsInit); + _settingsWatcher.setFuture(mFuture); +} + +/*! + * \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(); +}