Index: sources/view/VDateTime.cpp =================================================================== diff -u -rb5a7852d2637f7969680fbd3d2c821a6a74a8ccd -r079aae9751fe0d234adaa470bc7d23980d5e7692 --- sources/view/VDateTime.cpp (.../VDateTime.cpp) (revision b5a7852d2637f7969680fbd3d2c821a6a74a8ccd) +++ sources/view/VDateTime.cpp (.../VDateTime.cpp) (revision 079aae9751fe0d234adaa470bc7d23980d5e7692) @@ -1,12 +1,14 @@ // Qt +#include // Project #include "VDateTime.h" #include "Logger.h" using namespace View; using namespace Gui; +using namespace Storage; VIEW_DEF_CLASS(VDateTime) @@ -23,27 +25,29 @@ connect(this, SIGNAL(didAdjustment(const AdjustDGDateTimeRequestData)), &_GuiController, SLOT(doAdjustment(const AdjustDGDateTimeRequestData))); - connect(this, SIGNAL(didRequestShowAlert(const GuiAlertRequestData)), - &_GuiController, SLOT(doAlertRequest(const GuiAlertRequestData))); - // incoming connect(&_GuiController, SIGNAL(didActionReceive(const AdjustHDDateTimeResponseData)), this, SLOT(doActionReceive(const AdjustHDDateTimeResponseData))); connect(&_GuiController, SIGNAL(didActionReceive(const AdjustDGDateTimeResponseData)), this, SLOT(doActionReceive(const AdjustDGDateTimeResponseData))); + connect(&_process, SIGNAL(finished(int)), + this, SLOT(onFinishedSetDateUI(const int))); + startTimer(_timerInterval); } /*! - * \brief VDateTime::timerEvent + * \brief VDateTime::doGetCurrentTime * Reads and displays the current date and time - * \param event (QTimerEvent*) the timer event */ -void VDateTime::timerEvent(QTimerEvent *event) +void VDateTime::doGetCurrentTime() { - Q_UNUSED(event); + _setDateTimeHD = NOT_SET; + _setDateTimeDG = NOT_SET; + _setDateTimeUI = NOT_SET; + status(""); _currentTime = QDateTime::currentDateTime(); hour (_currentTime.toString("hh")); minute(_currentTime.toString("mm")); @@ -120,31 +124,48 @@ dgDateTimeReq.mEpoch = epoch; emit didAdjustment(hdDateTimeReq); emit didAdjustment(dgDateTimeReq); + + status("Setting date and time..."); + + // 2021-03-16 16:24:00 + QString setTime = QString("%1-%2-%3 %4:%5:%6").arg(year()).arg(month()).arg(day()).arg(hour()).arg(minute()).arg(second()); + _process.start(Date_Time_Set, QStringList() << setTime); } /*! + * \brief VDateTime::onFinishedSetDateUI + * Called when the process that sets the UI date and time has finished. + * \param vExitCode - (int) the exit code of the process + */ +void VDateTime::onFinishedSetDateUI(const int &vExitCode) +{ + LOG_DEBUG(QString("%1 - exit code %2").arg(__FUNCTION__).arg(vExitCode)); + if (vExitCode == 0) + { + _setDateTimeUI = SUCCESS; + } else { + _setDateTimeUI = FAILURE; + } + updateStatus(); +} + +/*! * \brief VDateTime::doActionReceive * Called when we receive a response back from the HD after requesting to * set the epoch * \param vResponse (AdjustHDDateTimeResponseData) - the response */ void VDateTime::doActionReceive(const AdjustHDDateTimeResponseData &vResponse) { - GuiAlertRequestData alert; - alert.acknowledgeOnly = true; - alert.id = GuiAlertID::ID_Alert_Set_DG_RTC_Response; + if (vResponse.mAccepted == 1) { - // alert the user that the request was successful. - alert.title = tr("Success"); - alert.description = tr("Successfully set the HD date and time."); - didRequestShowAlert(alert); + _setDateTimeHD = SUCCESS; } else { - alert.title = tr("Failure"); - alert.description = tr("The HD rejected the date and time setting."); - didRequestShowAlert(alert); + _setDateTimeHD = FAILURE; } + updateStatus(); } /*! @@ -155,19 +176,40 @@ */ void VDateTime::doActionReceive(const AdjustDGDateTimeResponseData &vResponse) { - GuiAlertRequestData alert; - alert.acknowledgeOnly = true; - alert.id = GuiAlertID::ID_Alert_Set_DG_RTC_Response; if (vResponse.mAccepted == 1) { - alert.title = tr("Success"); - alert.description = tr("Successfully set the DG date and time."); - didRequestShowAlert(alert); + _setDateTimeDG = SUCCESS; } else { - alert.title = tr("Failure"); - alert.description = tr("The DG rejected the date and time setting."); - didRequestShowAlert(alert); + _setDateTimeDG = FAILURE; } + updateStatus(); +} +/*! + * \brief VDateTime::updateStatus + * Update the notification bar's status + */ +void VDateTime::updateStatus() +{ + status(QString("HD: %1 DG: %2 UI: %3").arg(enumToString(_setDateTimeHD)) + .arg(enumToString(_setDateTimeDG)) + .arg(enumToString(_setDateTimeUI))); } + +/** + * \brief VDateTime::enumToString + * Convenience functiont to convert an enum to a string + * \param vEnum - the enum value + * \return QString - the enum name + */ +QString VDateTime::enumToString(DateTimeSetStatus vEnum) +{ + const QMetaObject *mo = qt_getEnumMetaObject(vEnum); + int enumIdx = mo->indexOfEnumerator(qt_getEnumName(vEnum)); + QString text = mo->enumerator(enumIdx).valueToKey(vEnum); + if (!text.isEmpty() ) { + return text; + } + return QString("[%1] Unknown DateTime Status").arg(vEnum); +}