/*! * * Copyright (c) 2020-2024 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 MainTimer.cpp * \author (last) Behrouz NematiPour * \date (last) 18-Jul-2023 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #include "MainTimer.h" //Qt #include //Project #include "Logger.h" #include "ApplicationController.h" /*! * \brief MainTimer::MainTimer * \details Constructor * \param parent - QObject parent owner object. * Qt handles the children destruction by their parent objects life-cycle. */ MainTimer::MainTimer(QObject *parent) : QObject(parent) { } /*! * \brief MainTimer::init * \details starts the timer ans sets the timer interval * \return */ bool MainTimer::init() { if (gFakeInterval) { startTimer(gFakeInterval); } initConnections(); LOG_DEBUG(QString("%1 Initialized").arg(metaObject()->className())); return true; } /*! * \brief ApplicationController::initConnections * \details Initializes the required signal/slot connection between this class and other objects * to be able to communicate. */ void MainTimer::initConnections() { connect(&_ApplicationController , SIGNAL(didCheckInBegin()), this , SLOT( onCheckInBegin())); } /*! * \brief MainTimer::quit * \details Does nothing for now */ void MainTimer::quit() { } /*! * \brief MainTimer::isDateChanged * \details Checks the date has been changed * \return true if date changed. */ bool MainTimer::isDateChanged(bool vIncludeTime) { // old date // current date static int oy,om,od; int cy,cm,cd; // old time // current time static int oH,oM,oS; int cH,cM,cS; QDateTime::currentDateTime().date().getDate(&cy, &cm, &cd); if (vIncludeTime) { QTime currentTime = QDateTime::currentDateTime().time(); cH = currentTime.hour(); cM = currentTime.minute(); cS = currentTime.second(); } if (oy == cy && om == cm && od == cd) { if (vIncludeTime) { if (oH == cH && oM == cM && oS == cS) { return false; } else { // date oy = cy; om = cm; od = cd; // time oH = cH; oM = cM; oS = cS; } } else return false; } else { oy = cy; om = cm; od = cd; } return true; } /*! * \brief MainTimer::onCheckInBegin * \details the handler for the signal didCheckInBegin * emiited from ApplicationController */ void MainTimer::onCheckInBegin() { if ( ! gFakeInterval ) { startTimer(_interval); } } /*! * \brief MainTimer::timerEvent * \details This event handler has been re-implemented in here * to receive timer events for the object * for the timer which has been set to _checkInterval * Emits the didTimeout signal on each interval. */ void MainTimer::timerEvent(QTimerEvent *) { #ifndef DISABLE_KEEP_ALIVE emit didTimeout(); #endif // I'm not sure how often we need to check for this. // if it needs to be checked each second pass true // if it needs to be checked each day pass false if (isDateChanged(false)) { emit didDateChange(); } }