// Qt // Project #include "VDateTime.h" #include "Logger.h" using namespace View; using namespace Gui; VIEW_DEF_CLASS(VDateTime) /*! * \brief VDateTime::initConnections * Makes the necessary connections. Called inside VIEW_DEF_CLASS */ void VDateTime::initConnections() { // outgoing connect(this, SIGNAL(didAdjustment(const AdjustHDDateTimeRequestData)), &_GuiController, SLOT(doAdjustment(const AdjustHDDateTimeRequestData))); 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))); startTimer(_timerInterval); } /*! * \brief VDateTime::timerEvent * Reads and displays the current date and time * \param event (QTimerEvent*) the timer event */ void VDateTime::timerEvent(QTimerEvent *event) { Q_UNUSED(event); _currentTime = QDateTime::currentDateTime(); hour (_currentTime.toString("hh")); minute(_currentTime.toString("mm")); second(_currentTime.toString("ss")); month (_currentTime.toString("MM")); day (_currentTime.toString("dd")); year (_currentTime.toString("yyyy")); } /*! * \brief doSetHour * Sets the hour * \param vHour (int) - the hour */ void VDateTime::doSetHour(const int &vHour) { hour(QStringLiteral("%1").arg(vHour, 2, 10, QLatin1Char('0'))); } /*! * \brief doSetMinute * Sets the minute * \param vMinute (int) - the minute */ void VDateTime::doSetMinute(const int &vMinute) { minute(QStringLiteral("%1").arg(vMinute, 2, 10, QLatin1Char('0'))); } /*! * \brief doSetMonth * Sets the month * \param vMonth (int) - the month */ void VDateTime::doSetMonth(const int &vMonth) { month(QStringLiteral("%1").arg(vMonth, 2, 10, QLatin1Char('0'))); } /*! * \brief doSetday * Sets the day * \param vDay (int) - the day */ void VDateTime::doSetDay(const int &vDay) { day(QStringLiteral("%1").arg(vDay, 2, 10, QLatin1Char('0'))); } /*! * \brief doSetyear * Sets the year * \param vYear (int) - the year */ void VDateTime::doSetYear(const int &vYear) { year(QStringLiteral("%1").arg(vYear, 4, 10, QLatin1Char('0'))); } /*! * \brief doSave * Issues request to save the current date and time to UI, HD and DG */ void VDateTime::doSave() { quint32 epoch = QDateTime(QDate(year().toInt(), month().toInt(), day().toInt()), QTime(hour().toInt(), minute().toInt())).toSecsSinceEpoch(); AdjustHDDateTimeRequestData hdDateTimeReq; hdDateTimeReq.mEpoch = epoch; AdjustDGDateTimeRequestData dgDateTimeReq; dgDateTimeReq.mEpoch = epoch; emit didAdjustment(hdDateTimeReq); emit didAdjustment(dgDateTimeReq); } /*! * \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); } else { alert.title = tr("Failure"); alert.description = tr("The HD rejected the date and time setting."); didRequestShowAlert(alert); } } /*! * \brief VDateTime::doActionReceive * Called when we receive a response back from the DG after requesting to * set the epoch * \param vResponse (AdjustDGDateTimeResponseData) - the response */ 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); } else { alert.title = tr("Failure"); alert.description = tr("The DG rejected the date and time setting."); didRequestShowAlert(alert); } }