Index: sources/device/DeviceController.cpp =================================================================== diff -u -r94c7a571dc12f24aa072ac2b14199432ce9f3821 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 94c7a571dc12f24aa072ac2b14199432ce9f3821) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -1390,3 +1390,70 @@ model._data.clear(); } } + +////////////////////////////////////////////////////////////////////////////////////////////////// DeviceDateTime +void DeviceController::onAttributeRequest(const DeviceDateTimeRequestData &vData) +{ + dateTimeRequest(vData); +} + +void DeviceController::dateTimeRequest(const DeviceDateTimeRequestData &vData) +{ + DeviceError::Scripts_Error_Enum error = DeviceError::eDevice_OK; + + // ----- initializing the member variable models + _deviceDateTimeRequest._data = vData; + + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, Date_Time_Set_Sh), _deviceDateTimeResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processDateTime.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceDateTimeResponse); + return; + } + + QStringList params; + params << vData.mDateTime << (vData.mNTP ? "true" : "false"); + + if ( error ) { + checkError(error, _deviceDateTimeResponse); + return; + } + + // ----- run the process + int timeout_ms = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processDateTime, script, timeout_ms, params); + timedProcess->start(); + + MDeviceDateTimeResponse model; + model._data.mCompleted = false; + model._data.mAccepted = false; + model._data.mMessage = tr("Date Time started."); + emit didAttributeResponse(model.data()); +} + +/*! + * \brief DeviceController::processDateTimeResponse + * \param vExitCode + * \param vStatus + */ +void DeviceController::processDateTimeResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel vChannel) +{ + static MDeviceDateTimeResponse model; + if ( vExitCode < 0 ) { + emit didAttributeResponse(model.data()); + switch (vChannel) { + case QProcess::StandardOutput : processDateTimeReadyOut(model); break; + case QProcess::StandardError : processDateTimeReadyErr(model); break; + } + } + else { + processDateTimeComplete(model, vExitCode, vStatus); + emit didAttributeResponse(model.data()); + model._data.clear(); + } +} + Index: sources/device/DeviceController.h =================================================================== diff -u -r94c7a571dc12f24aa072ac2b14199432ce9f3821 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceController.h (.../DeviceController.h) (revision 94c7a571dc12f24aa072ac2b14199432ce9f3821) +++ sources/device/DeviceController.h (.../DeviceController.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -471,6 +471,9 @@ // ----- RootSSHAccess void rootSSHAccessRequest(const DeviceRootSSHAccessRequestData &vData); + // ----- DateTime + void dateTimeRequest(const DeviceDateTimeRequestData &vData); + SAFE_CALL_EX2(doAddWatch, const QString &, bool) }; } Index: sources/device/DeviceError.cpp =================================================================== diff -u -r86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceError.cpp (.../DeviceError.cpp) (revision 86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f) +++ sources/device/DeviceError.cpp (.../DeviceError.cpp) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -59,6 +59,7 @@ QT_TR_NOOP("The WiFi info failed." ), // eDevice_WifiInfo_Error QT_TR_NOOP("The WiFi Connect failed." ), // eDevice_WifiConnect_Error QT_TR_NOOP("The WiFi Disconnect failed." ), // eDevice_WifiDisconnect_Error + QT_TR_NOOP("The Date/ Time failed." ), // eDevice_DateTime_Error QT_TR_NOOP("The USB Mount failed." ), // eDevice_USBMount_Error }; Index: sources/device/DeviceError.h =================================================================== diff -u -r86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceError.h (.../DeviceError.h) (revision 86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f) +++ sources/device/DeviceError.h (.../DeviceError.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -77,6 +77,7 @@ eDevice_WifiInfo_Error , eDevice_WifiConnect_Error , eDevice_WifiDisconnect_Error , + eDevice_DateTime_Error , eDevice_USBMount_Error , eDevice_Error_End Index: sources/device/DeviceGlobals.h =================================================================== diff -u -r86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 86df7ff03ea32f9cd8a18bbbc7b2e01de64c783f) +++ sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -209,6 +209,7 @@ DEVICE_DEV_PARENT ( FactoryReset ) \ DEVICE_DEV_PARENT ( RootSSHAccess ) \ DEVICE_DEV_PARENT ( Decommission ) \ + DEVICE_DEV_PARENT ( DateTime ) \ /* DEVICE_DEV_PARENT ( BluetoothPairedReset ) \ DEVICE_DEV_PARENT ( BluetoothPairedQuery ) \ @@ -226,6 +227,7 @@ DEVICE_DEV_INIT_CONNECTIONS ( FactoryReset ) \ DEVICE_DEV_INIT_CONNECTIONS ( RootSSHAccess ) \ DEVICE_DEV_INIT_CONNECTIONS ( Decommission ) \ + DEVICE_DEV_INIT_CONNECTIONS ( DateTime ) \ /* DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedReset ) \ DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ @@ -243,6 +245,7 @@ DEVICE_DEV_DEFINITION ( FactoryReset ) \ DEVICE_DEV_DEFINITION ( RootSSHAccess ) \ DEVICE_DEV_DEFINITION ( Decommission ) \ + DEVICE_DEV_DEFINITION ( DateTime ) \ /* DEVICE_DEV_DEFINITION ( BluetoothPairedReset ) \ DEVICE_DEV_DEFINITION ( BluetoothPairedQuery ) \ @@ -259,6 +262,7 @@ DEVICE_DEV_DECLARATION ( FactoryReset ) \ DEVICE_DEV_DECLARATION ( RootSSHAccess ) \ DEVICE_DEV_DECLARATION ( Decommission ) \ + DEVICE_DEV_DECLARATION ( DateTime ) \ /* DEVICE_DEV_DECLARATION ( BluetoothPairedReset ) \ DEVICE_DEV_DECLARATION ( BluetoothPairedQuery ) \ @@ -276,6 +280,7 @@ DEVICE_APP_INIT_CONNECTIONS ( FactoryReset ) \ DEVICE_APP_INIT_CONNECTIONS ( RootSSHAccess ) \ DEVICE_APP_INIT_CONNECTIONS ( Decommission ) \ + DEVICE_APP_INIT_CONNECTIONS ( DateTime ) \ /* DEVICE_APP_INIT_CONNECTIONS ( BluetoothPairedReset ) \ DEVICE_APP_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ @@ -291,6 +296,7 @@ DEVICE_APP_BRIDGE_DEFINITION( FactoryReset ) \ DEVICE_APP_BRIDGE_DEFINITION( RootSSHAccess ) \ DEVICE_APP_BRIDGE_DEFINITION( Decommission ) \ + DEVICE_APP_BRIDGE_DEFINITION( DateTime ) \ /* DEVICE_APP_BRIDGE_DEFINITION( BluetoothPairedReset ) \ DEVICE_APP_BRIDGE_DEFINITION( BluetoothPairedQuery ) \ @@ -308,6 +314,7 @@ DEVICE_GUI_INIT_CONNECTIONS ( FactoryReset ) \ DEVICE_GUI_INIT_CONNECTIONS ( RootSSHAccess ) \ DEVICE_GUI_INIT_CONNECTIONS ( Decommission ) \ + DEVICE_GUI_INIT_CONNECTIONS ( DateTime ) \ /* DEVICE_GUI_INIT_CONNECTIONS ( BluetoothPairedReset ) \ DEVICE_GUI_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ @@ -322,6 +329,7 @@ DEVICE_GUI_BRIDGE_DEFINITION( FactoryReset ) \ DEVICE_GUI_BRIDGE_DEFINITION( RootSSHAccess ) \ DEVICE_GUI_BRIDGE_DEFINITION( Decommission ) \ + DEVICE_GUI_BRIDGE_DEFINITION( DateTime ) \ /* DEVICE_GUI_BRIDGE_DEFINITION( BluetoothPairedReset ) \ DEVICE_GUI_BRIDGE_DEFINITION( BluetoothPairedQuery ) \ @@ -339,6 +347,7 @@ DEVICE_VIEW_INIT_CONNECTIONS( FactoryReset ) \ DEVICE_VIEW_INIT_CONNECTIONS( RootSSHAccess ) \ DEVICE_VIEW_INIT_CONNECTIONS( Decommission ) \ + DEVICE_VIEW_INIT_CONNECTIONS( DateTime ) \ /* DEVICE_VIEW_INIT_CONNECTIONS( BluetoothPairedReset ) \ DEVICE_VIEW_INIT_CONNECTIONS( BluetoothPairedQuery ) \ Index: sources/device/DeviceModels.cpp =================================================================== diff -u -r0836610a587b1e4986c08afe0711ef336e5b07ff -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 0836610a587b1e4986c08afe0711ef336e5b07ff) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -495,3 +495,42 @@ if ( vError && error ) *vError = error; return ""; } + +/*! + * \brief MDeviceDateTimeResponse::fromByteArray + * \details Checks the response and sets up the model data. + * \param vExitCode - Passed script exit code + * \return true if passed. + */ +bool MDeviceDateTimeResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) +{ + // initialize data + bool ok = false; + int error = 0; + _data.mCompleted = true; + _data.mAccepted = false; + _data.mReason = Device::DeviceError::eDevice_OK; + + ok = true; + + // check if the vExitCode passed and it has a value other than zero + if ( ! ok ){ _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp_Type ; goto lError; } // there is not a valid value + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_DateTime_Error ; goto lApply; } // there still a valid value + + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mMessage = QObject::tr("The Date Time is complete.") ; goto lOut ; // normal return + +// apply returned value in case the passed value is valid (type, range) +// regardless of the exit code (success, fail) +lApply: + goto lOut; + +// immediate exit on fail exitcode and invalid returned value. +lError: + if ( vExitCode ) error = *vExitCode; + _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; + +lOut: + return _data.mAccepted; +} Index: sources/device/DeviceModels.h =================================================================== diff -u -r0836610a587b1e4986c08afe0711ef336e5b07ff -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceModels.h (.../DeviceModels.h) (revision 0836610a587b1e4986c08afe0711ef336e5b07ff) +++ sources/device/DeviceModels.h (.../DeviceModels.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -470,8 +470,42 @@ bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; }; +// ================================================= MDeviceDateTime +/*! + * \brief The MDeviceDateTimeRequest class + * \details The model for the Date Time script call. + */ +class MDeviceDateTimeRequest : public MDeviceRequestBase { +public: + struct Data { + QString mDateTime = "" ; + bool mNTP = false ; + } _data; + + QString toString() { + return MDeviceRequestBase::toString("DateTime", { _data.mDateTime, _data.mNTP}); + } + + QByteArray toByteArray(Device::DeviceError::Scripts_Error_Enum * = nullptr) override { return ""; } +}; + +/*! + * \brief The MDeviceDateTimeResponse class + * \details The model for the Date Time script call returned value / response. + */ +class MDeviceDateTimeResponse : public MDeviceResponseBase { +public: + struct Data : MDeviceResponseBase::Data { + } _data; + QVariantList parameters ( ) const override { return { }; } + QString infoText ( ) const override { return QString("DateTime"); } + Data data ( ) const { return _data; } + bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; +}; + } + typedef Model::MDeviceResponseBase ::Data DeviceResponseBaseData; typedef Model::MDeviceBrightnessRequest ::Data DeviceBrightnessRequestData ; @@ -506,3 +540,6 @@ typedef Model::MDeviceWifiConnectRequest ::Data DeviceWifiConnectRequestData ; typedef Model::MDeviceWifiConnectResponse ::Data DeviceWifiConnectResponseData; + +typedef Model::MDeviceDateTimeRequest ::Data DeviceDateTimeRequestData ; +typedef Model::MDeviceDateTimeResponse ::Data DeviceDateTimeResponseData; Index: sources/device/DeviceView.cpp =================================================================== diff -u -r46c55a9eeb75ac84fbcd6160a2318c459672936a -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 46c55a9eeb75ac84fbcd6160a2318c459672936a) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -15,6 +15,7 @@ #include "DeviceView.h" // Qt +#include // Project #include "ApplicationController.h" @@ -626,5 +627,50 @@ ipAddress(vData); } +// ================================================= Date/Time +void VDevice::doInitDateTime() { + // Nothing for now. +} +void VDevice::dateTimeRequest( const QString &) { + // Nothing for now. +} +void VDevice::doDateTime(const QString &vYear, const QString &vMonth, const QString &vDay, + const QString &vHour, const QString &vMinute, bool vNTP) { + + const QDateTime currentDateTimeLocal ( QDate( vYear .toInt() , + vMonth .toInt() , + vDay .toInt()) , + QTime( vHour .toInt() , + vMinute .toInt())); + const QString dateTimeLocalStr = currentDateTimeLocal.toString(_Settings.getUpdateFormat()); // sudo date -s requires this format + + DeviceDateTimeRequestData data; + data.mDateTime = dateTimeLocalStr; + data.mNTP = vNTP; + + LOG_DEBUG(tr("SetDateTime %1").arg(dateTimeLocalStr)); + + emit didAttributeRequest(data); +} + +void VDevice::onAttributeResponse(const DeviceDateTimeResponseData &vData) { + + if ( vData.mCompleted ) { + if ( vData.mAccepted ) { + emit dateTimeChanged(""); + status(""); + } + else { + status(vData.mMessage); + } + } + + accepted(vData.mAccepted); + reason (vData.mReason ); + + // has to be the last one + response(true); +} + Index: sources/device/DeviceView.h =================================================================== diff -u -r46c55a9eeb75ac84fbcd6160a2318c459672936a -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/device/DeviceView.h (.../DeviceView.h) (revision 46c55a9eeb75ac84fbcd6160a2318c459672936a) +++ sources/device/DeviceView.h (.../DeviceView.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -118,6 +118,8 @@ ATTRIBUTE ( QString , decommission , "", Decommission ) READONLY ( bool , decommissionEnabled , true ) + ATTRIBUTE ( QString , dateTime , "", DateTime ) + ATTRIBUTE ( QStringList , wifiList , {}, WifiList ) ATTRIBUTE ( QStringList , wifiInfo , {}, WifiInfo ) ATTRIBUTE ( bool , wifiConnect , false, WifiConnect ) @@ -132,6 +134,8 @@ public slots: void doWifiConnect(bool vConnect, const QString &vSsid, const QString &vPassword); + void doDateTime ( const QString &vYear, const QString &vMonth, const QString &vDay, + const QString &vHour, const QString &vMinute, bool vNTP); private slots: void onPOSTOSVersionData (const QString &vOSVersion); Index: sources/gui/qml/components/HeaderBar.qml =================================================================== diff -u -r3d5bd682a4dc4bd36e26ca17067bafd489fa970b -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/components/HeaderBar.qml (.../HeaderBar.qml) (revision 3d5bd682a4dc4bd36e26ca17067bafd489fa970b) +++ sources/gui/qml/components/HeaderBar.qml (.../HeaderBar.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -44,15 +44,15 @@ anchors.horizontalCenter: parent.horizontalCenter horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter - font.pixelSize : 18 + font.pixelSize : Fonts.fontHeaderbarUser } Text { id: _title color : Colors.textMain anchors.centerIn : parent horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter - font.pixelSize : 35 + font.pixelSize : Fonts.fontHeaderbarTitle font.weight : Font.DemiBold } @@ -75,7 +75,7 @@ horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter text : vDateTime.time - font.pixelSize : 40 + font.pixelSize : Fonts.fontHeaderbarTime font.weight : Font.DemiBold } @@ -87,7 +87,7 @@ horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter text : vDateTime.date - font.pixelSize: 22 + font.pixelSize: Fonts.fontHeaderbarDate } } } @@ -105,7 +105,7 @@ height : 15 width : _root.width / 5 text : vDateTime.timezone - font.pixelSize: 14 + font.pixelSize: Fonts.fontHeaderbarTimezone } MainMenu { id: _headerMenu Index: sources/gui/qml/compounds/LabelUnitContainer.qml =================================================================== diff -u -r33f808e5b8d9134231fc0d016bfb16605c2de812 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/compounds/LabelUnitContainer.qml (.../LabelUnitContainer.qml) (revision 33f808e5b8d9134231fc0d016bfb16605c2de812) +++ sources/gui/qml/compounds/LabelUnitContainer.qml (.../LabelUnitContainer.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -61,7 +61,7 @@ anchors.bottom : _title.bottom text : ("(%1)").arg(_root.unitText) color : Colors.offWhite - font.pixelSize : 18 + font.pixelSize : Fonts.fontUnit font.weight : Font.Thin visible : _root.showUnit } Index: sources/gui/qml/dialogs/ConfirmDialog.qml =================================================================== diff -u -r3d5bd682a4dc4bd36e26ca17067bafd489fa970b -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/dialogs/ConfirmDialog.qml (.../ConfirmDialog.qml) (revision 3d5bd682a4dc4bd36e26ca17067bafd489fa970b) +++ sources/gui/qml/dialogs/ConfirmDialog.qml (.../ConfirmDialog.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -53,7 +53,7 @@ TitleText { id: _messageText anchors.centerIn : parent - anchors.verticalCenterOffset: Variables.defaultMargin * -3 + anchors.verticalCenterOffset: Variables.defaultMargin * -3 // adjust text up to add more space from bottom buttons width : parent.width height : Variables.mainMenuHeight * 4 // title + reason + 2*Gap clip : true Index: sources/gui/qml/globals/Fonts.qml =================================================================== diff -u -rcb9c48c7c307690dcafcfd16ef412fe660291692 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/globals/Fonts.qml (.../Fonts.qml) (revision cb9c48c7c307690dcafcfd16ef412fe660291692) +++ sources/gui/qml/globals/Fonts.qml (.../Fonts.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -57,6 +57,14 @@ readonly property int fontPixelFluidUnit : 22 readonly property int fontPixelFluidVolume : 16 + readonly property int fontHeaderbarUser : 18 + readonly property int fontHeaderbarTitle : 35 + readonly property int fontHeaderbarTime : 40 + readonly property int fontHeaderbarDate : 22 + readonly property int fontHeaderbarTimezone : 14 + + readonly property int fontUnit : 18 + readonly property int fontPixelConfirm : 21 readonly property int fontPixelBack : 17 Index: sources/gui/qml/pages/settings/SettingsBase.qml =================================================================== diff -u -re7adb742d7dd362b2deb795259694b223eea3bc0 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/pages/settings/SettingsBase.qml (.../SettingsBase.qml) (revision e7adb742d7dd362b2deb795259694b223eea3bc0) +++ sources/gui/qml/pages/settings/SettingsBase.qml (.../SettingsBase.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -85,7 +85,7 @@ Text { id: _titleText anchors { top : _root.top - topMargin : Variables.defaultMargin * 3 + topMargin : Variables.defaultMargin * 3 // add margins to match design horizontalCenter: parent.horizontalCenter } horizontalAlignment : Text.AlignHCenter @@ -96,7 +96,7 @@ ContentArea { id : _contentArea anchors { fill : _root - topMargin : Variables.defaultMargin * 6 + topMargin : Variables.defaultMargin * 6 // add margins for content in each settings page to match design leftMargin : Variables.defaultMargin * 2 rightMargin : Variables.defaultMargin * 2 bottomMargin: Variables.settingsContentBottomMargin Index: sources/gui/qml/pages/settings/SettingsDateTime.qml =================================================================== diff -u -r36c82a88dbd6b4fb71528465684d51c6fbff584f -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/pages/settings/SettingsDateTime.qml (.../SettingsDateTime.qml) (revision 36c82a88dbd6b4fb71528465684d51c6fbff584f) +++ sources/gui/qml/pages/settings/SettingsDateTime.qml (.../SettingsDateTime.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -46,7 +46,7 @@ confirmEnabled : isValid notificationText: vDateTime.status onConfirmClicked: { - vDateTime.doConfirm( + vDevice.doDateTime( _year .textInput.text , _month .textInput.text , _day .textInput.text , @@ -55,7 +55,9 @@ _ntpSwitch.checked ) } - onVisibleChanged: refreshDateTime() // it seems entering in the TextInput by keyboard breaks the binding + onVisibleChanged: { // it seems entering in the TextInput by keyboard breaks the binding + refreshDateTime() + } function refreshDateTime() { _year .textInput.text = vDateTime.year @@ -65,8 +67,21 @@ _minutes.textInput.text = vDateTime.minute } + Connections { target: vDevice + // ... WILL BE UPDATE IN LDT-2909 + // send fw date/time after succesfully settings it in shell script + function onDateTimeChanged ( vValue ) { vDateTime.doConfirm( + _year .textInput.text , + _month .textInput.text , + _day .textInput.text , + _hours .textInput.text , + _minutes.textInput.text , + _ntpSwitch.checked ) } + } + Connections { target: vDateTime function onDidRefreshUIFields ( ) { refreshDateTime() } + } contentItem: Column { id: _container Index: sources/gui/qml/pages/settings/SettingsHome.qml =================================================================== diff -u -redb8ee3edc41b1d324cd8a53e8e27a2a58289563 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/gui/qml/pages/settings/SettingsHome.qml (.../SettingsHome.qml) (revision edb8ee3edc41b1d324cd8a53e8e27a2a58289563) +++ sources/gui/qml/pages/settings/SettingsHome.qml (.../SettingsHome.qml) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -31,7 +31,7 @@ property alias itemsText : _settingItems.itemsText property alias itemsVisible : _settingItems.itemsVisible - readonly property real rowCount : Math.ceil(_settingItems.itemsVisible.filter(value => value).length / 2) + readonly property int rowCount : Math.ceil(_settingItems.itemsVisible.filter(value => value).length / 2) readonly property int colCount : 2 readonly property int delegateWidth : parent.width / 2.5 Index: sources/model/MModel.h =================================================================== diff -u -r08ffb068817ab0bb1c7f2fe2705986142ac68601 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/model/MModel.h (.../MModel.h) (revision 08ffb068817ab0bb1c7f2fe2705986142ac68601) +++ sources/model/MModel.h (.../MModel.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -334,6 +334,8 @@ REGISTER_METATYPE( DeviceWifiInfoResponseData ) \ REGISTER_METATYPE( DeviceWifiConnectRequestData ) \ REGISTER_METATYPE( DeviceWifiConnectResponseData ) \ + REGISTER_METATYPE( DeviceDateTimeRequestData ) \ + REGISTER_METATYPE( DeviceDateTimeResponseData ) \ /* Settings */ \ REGISTER_METATYPE( SettingsData ) \ REGISTER_METATYPE( BluetoothData ) \ Index: sources/model/settings/MSettings.h =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/model/settings/MSettings.h (.../MSettings.h) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/model/settings/MSettings.h (.../MSettings.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -91,10 +91,13 @@ private : QString _datetimeFormat = "MM/dd/yyyy HH:mm:ss"; private : QString _dateFormat = "MM/dd/yyyy"; private : QString _timeFormat = "HH:mm:ss"; +private : QString _updateFormat = "yyyy-MM-dd HH:mm:ss"; // format only used for changing system date/ time + public : void datetimeFormat(); public : QString getDatetimeFormat() { return _datetimeFormat;} public : QString timeFormat() { return _timeFormat;} public : QString dateFormat() { return _dateFormat;} +public : QString getUpdateFormat() { return _updateFormat;} }; } Index: sources/view/settings/VDateTime.cpp =================================================================== diff -u -r36c82a88dbd6b4fb71528465684d51c6fbff584f -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 36c82a88dbd6b4fb71528465684d51c6fbff584f) +++ sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -34,27 +34,9 @@ ACTION_VIEW_CONNECTION(HDRTCEpochData); ADJUST_VIEW_CONNECTION( AdjustTDDateTimeRequestData); ADJUST_VIEW_CONNECTION( AdjustDDDateTimeRequestData); - - connect(&_process, SIGNAL( finished(int)), - this, SLOT(onSetDateUIFinished(int))); - - connect(&_process, SIGNAL( errorOccurred(QProcess::ProcessError)), - this, SLOT(onSetDateUIErrored(QProcess::ProcessError))); } /*! - * \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; - QString errorString = QString("%1 errored. Error %2").arg(mScript).arg(error); - LOG_DEBUG(errorString); - status(errorString); -} - -/*! * \brief VDateTime::doCurrentTime * Reads and displays the current date and time */ @@ -89,7 +71,7 @@ const QString &vDay , const QString &vHour , const QString &vMinute , - const bool &vNTP ) + bool vNTP ) { year ( vYear ); month ( vMonth ); @@ -100,58 +82,38 @@ _acceptTD = NOT_SET; _acceptDD = NOT_SET; - _acceptUI = 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(_updateFormat); // sudo date -s requires this format // Get the current UTC datetime const quint32 epochUTC_sec = getEpochUTC(currentDateTimeLocal); - LOG_DEBUG(tr("SetDateTime %1").arg(dateTimeLocalStr)); status("Setting date and time ..."); - dateTimeUI(dateTimeLocalStr, vNTP ); - // 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 ); } -} - -/*! - * \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::onSetDateUIFinished(const int &vExitCode) -{ - if ( vExitCode ) { - _acceptUI = FAILED; - LOG_DEBUG(QString("SetDataTime[%1]").arg(vExitCode)); - } else { - _acceptUI = SUCCEED; - 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 ) { + // 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 - QDateTime currentDateTime = QDateTime::currentDateTime(); - const quint32 epochUTC_sec = getEpochUTC(currentDateTime); + const quint32 epochUTC_sec = getEpochUTC(); dateTimeTD(epochUTC_sec ); dateTimeDD(epochUTC_sec ); + + // 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") ); @@ -225,20 +187,6 @@ } /*! - * \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, const bool &vNTP) -{ - if ( _process.state() != QProcess::NotRunning ) { return; } - QString mScript = Storage::Scripts_Path_Name(); - mScript += Storage::Date_Time_Set_Sh; - QStringList arguments; - arguments << vDateTime << (vNTP ? "true" : "false"); - _process.start(mScript, arguments); -} - -/*! * \brief VDateTime::status * \details Returns the appropriate string for the date/time adjustment status * \param vStatus - the status of the adjustment @@ -320,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, false); +// const QString newDateTimeString = hdRTCTime_localZone.toString(_Settings.getDatetimeFormat()); _hasDoneHDSyncRTC = true; // indicate HD-UI RTC sync'd Index: sources/view/settings/VDateTime.h =================================================================== diff -u -r36c82a88dbd6b4fb71528465684d51c6fbff584f -r6e18f1d24b8cc3d84d26f46f36f73deb34e54371 --- sources/view/settings/VDateTime.h (.../VDateTime.h) (revision 36c82a88dbd6b4fb71528465684d51c6fbff584f) +++ sources/view/settings/VDateTime.h (.../VDateTime.h) (revision 6e18f1d24b8cc3d84d26f46f36f73deb34e54371) @@ -65,9 +65,7 @@ private: QDateTime _currentDateTime ; - int _timerInterval = 1000; // ms - QProcess _process ; - QString _updateFormat = "yyyy-MM-dd HH:mm:ss"; // format only used for changing system date/ time + int _timerInterval = 1000; // ms DateTimeSetStatus _acceptTD = NOT_SET; DateTimeSetStatus _acceptDD = NOT_SET; @@ -78,12 +76,10 @@ void dateTimeTD(quint32 epoch); void dateTimeDD(quint32 epoch); - void dateTimeUI(const QString &vDateTime, - const bool &vNTP ); QString status(DateTimeSetStatus vStatus, quint8 vReason); void updateStatus(); - quint32 getEpochUTC(QDateTime vDateTime); + quint32 getEpochUTC(QDateTime vDateTime = QDateTime::currentDateTime()); TRIGGER (QString, year , "0000") TRIGGER (QString, month , "00" ) @@ -113,19 +109,15 @@ void greeting(quint16 vMilitaryTime); -private slots: - void onSetDateUIFinished(const int &vExitCode); - public slots: void doInit (); void doConfirm (const QString &vYear , const QString &vMonth , const QString &vDay , const QString &vHour , const QString &vMinute, - const bool &vNTP ); + bool vNTP ); - void onSetDateUIErrored(QProcess::ProcessError error); signals: void didAdjustment(const AdjustTDDateTimeRequestData); void didAdjustment(const AdjustDDDateTimeRequestData);