Index: sources/gui/qml/pages/settings/SettingsDateTime.qml =================================================================== diff -u -r86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f -r36c82a88dbd6b4fb71528465684d51c6fbff584f --- sources/gui/qml/pages/settings/SettingsDateTime.qml (.../SettingsDateTime.qml) (revision 86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f) +++ sources/gui/qml/pages/settings/SettingsDateTime.qml (.../SettingsDateTime.qml) (revision 36c82a88dbd6b4fb71528465684d51c6fbff584f) @@ -55,14 +55,20 @@ _ntpSwitch.checked ) } - onVisibleChanged: { // it seems entering in the TextInput by keyboard breaks the binding + onVisibleChanged: refreshDateTime() // it seems entering in the TextInput by keyboard breaks the binding + + function refreshDateTime() { _year .textInput.text = vDateTime.year _month .textInput.text = vDateTime.month _day .textInput.text = vDateTime.day _hours .textInput.text = vDateTime.hour _minutes.textInput.text = vDateTime.minute } + Connections { target: vDateTime + function onDidRefreshUIFields ( ) { refreshDateTime() } + } + contentItem: Column { id: _container spacing : 25 Index: sources/view/settings/VDateTime.cpp =================================================================== diff -u -r7d9128b49d1f7d6f36fd35286adda8c95441c552 -r36c82a88dbd6b4fb71528465684d51c6fbff584f --- sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 7d9128b49d1f7d6f36fd35286adda8c95441c552) +++ sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 36c82a88dbd6b4fb71528465684d51c6fbff584f) @@ -16,6 +16,7 @@ // Qt #include +#include // Project #include "GuiController.h" @@ -97,6 +98,10 @@ minute ( vMinute ); ntp ( vNTP ); + _acceptTD = NOT_SET; + _acceptDD = NOT_SET; + _acceptUI = NOT_SET; + const QDateTime currentDateTimeLocal ( QDate(_year .toInt() , _month .toInt() , _day .toInt()) , @@ -105,15 +110,19 @@ const QString dateTimeLocalStr = currentDateTimeLocal.toString(_updateFormat); // sudo date -s requires this format // 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, vNTP ); - dateTimeTD(epochUTC_sec ); - dateTimeDD(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 ); + } } /*! @@ -132,9 +141,40 @@ LOG_DEBUG("SetDateTime Succeed"); } updateStatus(); + + // If UI date time is set using ntp then update UI fields + // Need a short delay to wait for system clock to update first + if ( _ntp ) { + QTimer::singleShot(2000, [this]() { + // Get the current UTC datetime + QDateTime currentDateTime = QDateTime::currentDateTime(); + const quint32 epochUTC_sec = getEpochUTC(currentDateTime); + + dateTimeTD(epochUTC_sec ); + dateTimeDD(epochUTC_sec ); + year ( currentDateTime.toString("yyyy") ); + month ( currentDateTime.toString("MM") ); + day ( currentDateTime.toString("dd") ); + hour ( currentDateTime.toString("HH") ); + minute ( currentDateTime.toString("mm") ); + + emit didRefreshUIFields(); + }); + } } /*! + * \brief VDateTime::getEpochUTC + * Get Epoch from given data time + * \param vExitCode - (QDateTime) the date time to get epoch from + */ +quint32 VDateTime::getEpochUTC(QDateTime vDateTime) +{ + 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 Index: sources/view/settings/VDateTime.h =================================================================== diff -u -r7d9128b49d1f7d6f36fd35286adda8c95441c552 -r36c82a88dbd6b4fb71528465684d51c6fbff584f --- sources/view/settings/VDateTime.h (.../VDateTime.h) (revision 7d9128b49d1f7d6f36fd35286adda8c95441c552) +++ sources/view/settings/VDateTime.h (.../VDateTime.h) (revision 36c82a88dbd6b4fb71528465684d51c6fbff584f) @@ -83,6 +83,7 @@ QString status(DateTimeSetStatus vStatus, quint8 vReason); void updateStatus(); + quint32 getEpochUTC(QDateTime vDateTime); TRIGGER (QString, year , "0000") TRIGGER (QString, month , "00" ) @@ -128,5 +129,6 @@ signals: void didAdjustment(const AdjustTDDateTimeRequestData); void didAdjustment(const AdjustDDDateTimeRequestData); + void didRefreshUIFields(); }; }