Index: sources/view/settings/VDateTime.cpp =================================================================== diff -u -r2ad0fc5c1215088ee0e4ea7f9b2bc367c4ed2fd9 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 2ad0fc5c1215088ee0e4ea7f9b2bc367c4ed2fd9) +++ sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -16,6 +16,7 @@ // Qt #include +#include // Project #include "GuiController.h" @@ -28,38 +29,21 @@ void VDateTime::initConnections() { startTimer(_timerInterval); - ACTION_VIEW_CONNECTION(AdjustHDDateTimeResponseData); - ACTION_VIEW_CONNECTION(AdjustDGDateTimeResponseData); + ACTION_VIEW_CONNECTION(AdjustTDDateTimeResponseData); + ACTION_VIEW_CONNECTION(AdjustDDDateTimeResponseData); ACTION_VIEW_CONNECTION(HDRTCEpochData); - ADJUST_VIEW_CONNECTION( AdjustHDDateTimeRequestData); - ADJUST_VIEW_CONNECTION( AdjustDGDateTimeRequestData); - - connect(&_process, SIGNAL( finished(int)), - this, SLOT(onSetDateUIFinished(int))); - - connect(&_process, SIGNAL( errorOccurred(QProcess::ProcessError)), - this, SLOT(onSetDateUIErrored(QProcess::ProcessError))); + ADJUST_VIEW_CONNECTION( AdjustTDDateTimeRequestData); + ADJUST_VIEW_CONNECTION( AdjustDDDateTimeRequestData); } /*! - * \brief VDateTime::onSetDateUIErrored - * The slot for when the set datetime script errors, log the error - */ -void VDateTime::onSetDateUIErrored(QProcess::ProcessError error){ - QString mScript = Storage::Scripts_Path_Name(); - mScript += Storage::Date_Time_Set_Sh; - LOG_DEBUG(QString("%1 errored. Error %2").arg(mScript).arg(error)); - //DEBUG: qDebug()<< QString("%1 errored. Error ").arg(mScript) << error; -} - -/*! * \brief VDateTime::doCurrentTime * Reads and displays the current date and time */ void VDateTime::doInit() { - _acceptHD = NOT_SET; - _acceptDG = NOT_SET; + _acceptTD = NOT_SET; + _acceptDD = NOT_SET; _acceptUI = NOT_SET; QDateTime _currentTime = QDateTime::currentDateTime(); hour (_currentTime.toString("HH" )); @@ -69,6 +53,9 @@ month (_currentTime.toString("MM" )); year (_currentTime.toString("yyyy" )); + timeFormat (_Settings.timeFormat()); + dateFormat (_Settings.dateFormat()); + timezone(QTimeZone::systemTimeZone().abbreviation(_currentTime)); status(""); @@ -83,120 +70,123 @@ const QString &vMonth , const QString &vDay , const QString &vHour , - const QString &vMinute ) + const QString &vMinute , + bool vNTP ) { year ( vYear ); month ( vMonth ); day ( vDay ); hour ( vHour ); minute ( vMinute ); + ntp ( vNTP ); + _acceptTD = NOT_SET; + _acceptDD = NOT_SET; + _acceptUI = SUCCEED; // will get here if UI script succeeds + updateStatus(); + const QDateTime currentDateTimeLocal ( QDate(_year .toInt() , _month .toInt() , _day .toInt()) , QTime(_hour .toInt() , _minute .toInt())); - const QString dateTimeLocalStr = currentDateTimeLocal.toString(_Settings.getDatetimeFormat()); // Get the current UTC datetime - const QDateTime currentDateTimeUTC = currentDateTimeLocal.toUTC(); - const quint32 epochUTC_sec = currentDateTimeUTC.toSecsSinceEpoch(); + const quint32 epochUTC_sec = getEpochUTC(currentDateTimeLocal); - LOG_DEBUG(tr("SetDateTime %1").arg(dateTimeLocalStr)); status("Setting date and time ..."); - dateTimeUI(dateTimeLocalStr ); - dateTimeHD(epochUTC_sec ); - dateTimeDG(epochUTC_sec ); + // only send here if NTP is not set and sending manual time. + // DateTime will be sent to FW on script response of current time + if ( ! vNTP ) { + dateTimeTD(epochUTC_sec ); + dateTimeDD(epochUTC_sec ); + } + else { + // If UI date time is set using ntp then update UI fields + // Need a short delay to wait for system clock to update first + QTimer::singleShot(2000, [this]() { + // Get the current UTC datetime + const quint32 epochUTC_sec = getEpochUTC(); - //DEBUG: QDateTime convertBack; - //DEBUG: convertBack.setSecsSinceEpoch(epochUTC_sec); - //DEBUG: qDebug()<<"Secs since Epoch" << convertBack.toSecsSinceEpoch() << " UTC: " << convertBack.toUTC().toString(_Settings.getDatetimeFormat()); + dateTimeTD(epochUTC_sec ); + dateTimeDD(epochUTC_sec ); - //DEBUG: qDebug() << "doConfirm RTC | epoch : " << epochUTC_sec << " | local: " << currentDateTimeLocal.toString(_Settings.getDatetimeFormat()) << " | current time zone: " << currentDateTimeLocal.timeZone() << " | UTC: " << currentDateTimeUTC.toString(_Settings.getDatetimeFormat()) ; + // TBD this will be updated and most likely removed in LDT-2909 when we start broadcasting the date/time + QDateTime currentDateTime = QDateTime::currentDateTime(); + year ( currentDateTime.toString("yyyy") ); + month ( currentDateTime.toString("MM") ); + day ( currentDateTime.toString("dd") ); + hour ( currentDateTime.toString("HH") ); + minute ( currentDateTime.toString("mm") ); + + emit didRefreshUIFields(); + }); + } } /*! - * \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 + * \brief VDateTime::getEpochUTC + * Get Epoch from given data time + * \param vExitCode - (QDateTime) the date time to get epoch from */ -void VDateTime::onSetDateUIFinished(const int &vExitCode) +quint32 VDateTime::getEpochUTC(QDateTime vDateTime) { - if ( vExitCode ) { - _acceptUI = FAILED; - LOG_DEBUG(QString("SetDataTime[%1]").arg(vExitCode)); - } - else { - _acceptUI = SUCCEED; - LOG_DEBUG("SetDateTime Succeed"); - } - updateStatus(); + const QDateTime currentDateTimeUTC = vDateTime.toUTC(); + return currentDateTimeUTC.toSecsSinceEpoch(); } /*! * \brief VDateTime::onActionReceive * Called when we receive a response back from the HD after requesting to * set the epoch - * \param vData (AdjustHDDateTimeResponseData) - the response data + * \param vData (AdjustTDDateTimeResponseData) - the response data */ -void VDateTime::onActionReceive(const AdjustHDDateTimeResponseData &vData) +void VDateTime::onActionReceive(const AdjustTDDateTimeResponseData &vData) { - _acceptHD = vData.mAccepted ? SUCCEED : FAILED; - _reasonHD = vData.mReason ; + _acceptTD = vData.mAccepted ? SUCCEED : FAILED; + _reasonTD = vData.mReason ; updateStatus(); } /*! * \brief VDateTime::onActionReceive * Called when we receive a response back from the DG after requesting to * set the epoch - * \param vResponse (AdjustDGDateTimeResponseData) - the response + * \param vResponse (AdjustDDDateTimeResponseData) - the response */ -void VDateTime::onActionReceive(const AdjustDGDateTimeResponseData &vData) +void VDateTime::onActionReceive(const AdjustDDDateTimeResponseData &vData) { - _acceptDG = vData.mAccepted ? SUCCEED : FAILED; - _reasonDG = vData.mReason ; + _acceptDD = vData.mAccepted ? SUCCEED : FAILED; + _reasonDD = vData.mReason ; updateStatus(); } /*! - * \brief VDateTime::dateTimeHD - * \details Requests HD to set the date/time + * \brief VDateTime::dateTimeTD + * \details Requests TD to set the date/time * \param epoch - the epoch parameter which FW understands to set date/time */ -void VDateTime::dateTimeHD(quint32 epoch) +void VDateTime::dateTimeTD(quint32 epoch) { - AdjustHDDateTimeRequestData data; + AdjustTDDateTimeRequestData data; data.mEpoch = epoch; emit didAdjustment(data); } /*! - * \brief VDateTime::dateTimeDG + * \brief VDateTime::dateTimeDD * \details Requests DG to set the date/time * \param epoch - the epoch parameter which FW understands to set date/time */ -void VDateTime::dateTimeDG(quint32 epoch) +void VDateTime::dateTimeDD(quint32 epoch) { - AdjustDGDateTimeRequestData data; + AdjustDDDateTimeRequestData data; data.mEpoch = epoch; emit didAdjustment(data); } /*! - * \brief VDateTime::dateTimeUI - * \details starts the shell script in a process defined in Storage::Date_Time_Set_Sh to update the device date/time - */ -void VDateTime::dateTimeUI(const QString &vDateTime) -{ - if ( _process.state() != QProcess::NotRunning ) { return; } - QString mScript = Storage::Scripts_Path_Name(); - mScript += Storage::Date_Time_Set_Sh; - _process.start(mScript, QStringList() << vDateTime); -} - -/*! * \brief VDateTime::status * \details Returns the appropriate string for the date/time adjustment status * \param vStatus - the status of the adjustment @@ -226,9 +216,9 @@ */ void VDateTime::updateStatus() { - status(QString("HD: %1, DG: %2, UI: %3") - .arg(status(_acceptHD, _reasonHD)) - .arg(status(_acceptDG, _reasonDG)) + status(QString("TD: %1, DD: %2, UI: %3") + .arg(status(_acceptTD, _reasonTD)) + .arg(status(_acceptDD, _reasonDD)) .arg(status(_acceptUI, _reasonUI)) ); } @@ -278,8 +268,7 @@ QDateTime hdRTCTime_localZone; // Default timespec is Qt::localTime / local time zoned hdRTCTime_localZone.setSecsSinceEpoch(vData.mEpoch); - const QString newDateTimeString = hdRTCTime_localZone.toString(_Settings.getDatetimeFormat()); - dateTimeUI(newDateTimeString); +// const QString newDateTimeString = hdRTCTime_localZone.toString(_Settings.getDatetimeFormat()); _hasDoneHDSyncRTC = true; // indicate HD-UI RTC sync'd