/*! * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * \copyright * 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 VDateTime.cpp * \author (last) Peter Lucia * \date (last) 16-Apr-2021 * \author (original) Peter Lucia * \date (original) 16-Apr-2021 * */ #include "VDateTime.h" // Qt #include // Project #include "GuiController.h" using namespace View; VIEW_DEF_CLASS(VDateTime) void VDateTime::initConnections() { startTimer(_timerInterval); ACTION_VIEW_CONNECTION(AdjustHDDateTimeResponseData); ACTION_VIEW_CONNECTION(AdjustDGDateTimeResponseData); ADJUST_VIEW_CONNECTION( AdjustHDDateTimeRequestData); ADJUST_VIEW_CONNECTION( AdjustDGDateTimeRequestData); connect(&_process, SIGNAL( finished(int)), this, SLOT(onSetDateUIFinished(int))); } /*! * \brief VDateTime::doCurrentTime * Reads and displays the current date and time */ void VDateTime::doInit() { _acceptHD = NOT_SET; _acceptDG = NOT_SET; _acceptUI = NOT_SET; QDateTime _currentTime = QDateTime::currentDateTime(); hour (_currentTime.toString("HH" )); minute(_currentTime.toString("mm" )); second(_currentTime.toString("ss" )); day (_currentTime.toString("dd" )); month (_currentTime.toString("MM" )); year (_currentTime.toString("yyyy" )); status(""); } /*! * \brief doConfirm * \details Issues request to save the current date and time to UI, HD and DG */ void VDateTime::doConfirm( const QString &vYear , const QString &vMonth , const QString &vDay , const QString &vHour , const QString &vMinute ) { year ( vYear ); month ( vMonth ); day ( vDay ); hour ( vHour ); minute ( vMinute ); quint32 epoch = QDateTime( QDate(_year .toInt() , _month .toInt() , _day .toInt()), QTime(_hour .toInt() , _minute .toInt()) ).toSecsSinceEpoch(); // the accepted format of the Linux data command: // example: 2021-03-16 16:24:00 QString mDateTime = QString("%1-%2-%3 %4:%5:%6") .arg(_year ) .arg(_month ) .arg(_day ) .arg(_hour ) .arg(_minute) .arg(_second); LOG_DEBUG(tr("SetDateTime %1").arg(mDateTime)); status("Setting date and time ..."); dateTimeUI(mDateTime); dateTimeHD(epoch ); dateTimeDG(epoch ); } /*! * \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(); } /*! * \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 */ void VDateTime::onActionReceive(const AdjustHDDateTimeResponseData &vData) { _acceptHD = vData.mAccepted ? SUCCEED : FAILED; _reasonHD = 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 */ void VDateTime::onActionReceive(const AdjustDGDateTimeResponseData &vData) { _acceptDG = vData.mAccepted ? SUCCEED : FAILED; _reasonDG = vData.mReason ; updateStatus(); } /*! * \brief VDateTime::dateTimeHD * \details Requests HD to set the date/time * \param epoch - the epoch parameter which FW understands to set date/time */ void VDateTime::dateTimeHD(quint32 epoch) { AdjustHDDateTimeRequestData data; data.mEpoch = epoch; emit didAdjustment(data); } /*! * \brief VDateTime::dateTimeDG * \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) { AdjustDGDateTimeRequestData 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 * \param vReason - the reason if the adjustment has been rejected. * \return the status string */ QString VDateTime::status(VDateTime::DateTimeSetStatus vStatus, quint8 vReason) { QString mNotSet = tr("Not Set"); QString mSucceed = tr("Succeed"); QString mFailed = tr("Failed" ) + " [%1]"; switch (vStatus) { case SUCCEED: return mSucceed; break; case FAILED: return mFailed.arg(vReason); break; default: return mNotSet; break; } } /*! * \brief VDateTime::updateStatus * Update the notification bar's status */ void VDateTime::updateStatus() { status(QString("HD: %1, DG: %2, UI: %3") .arg(status(_acceptHD, _reasonHD)) .arg(status(_acceptDG, _reasonDG)) .arg(status(_acceptUI, _reasonUI)) ); } /*! * \brief VDateTime::greeting * \details sets the greeting property string to be used on the standby/home screen regarding the device's current time of the day. * \param vMilitaryTime */ void VDateTime::greeting(quint16 vMilitaryTime) { if ( eMorningMin <= vMilitaryTime && vMilitaryTime < eMorningMax ) { greeting(tr("Good Morning" )); return; } if ( eAfternoonMin <= vMilitaryTime && vMilitaryTime < eAfternoonMax ) { greeting(tr("Good Afternoon")); return; } greeting(tr("Good Evening")); } /*! * \brief VDateTime::timerEvent * \details The overloaded member function of the QObject to send the current date/time to the UI. * \note The interval has been set in _timerInterval as 1000 ms (1sec). */ void VDateTime::timerEvent(QTimerEvent *) { QDateTime datetime = QDateTime::currentDateTime(); current(datetime.toString("MM/dd/yyyy HH:mm:ss")); quint16 military = datetime.time().hour() * 100 + datetime.time().minute(); greeting(military); }