| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "guilib/GUIAction.h" |
| 12 |
#include "interfaces/info/InfoExpression.h" |
| 13 |
#include "utils/Stopwatch.h" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <string> |
| 17 |
|
| 18 |
class TiXmlElement; |
| 19 |
|
| 20 |
/*! \brief Skin timers are skin objects that dependent on time and can be fully controlled from skins either using boolean |
| 21 |
* conditions or builtin functions. This class represents the Skin Timer object. |
| 22 |
* \sa Skin_Timers |
| 23 |
*/ |
| 24 |
class CSkinTimer : public CStopWatch |
| 25 |
{ |
| 26 |
public: |
| 27 |
/*! \brief Skin timer constructor |
| 28 |
* \param name - the name of the timer |
| 29 |
* \param startCondition - the boolean info expression to start the timer (may be null) |
| 30 |
* \param resetCondition - the boolean info expression to reset the timer (may be null) |
| 31 |
* \param stopCondition - the boolean info expression to stop the timer (may be null) |
| 32 |
* \param startActions - the builtin functions to execute on timer start (actions may be empty) |
| 33 |
* \param stopActions - the builtin functions to execute on timer stop (actions may be empty) |
| 34 |
* \param resetOnStart - if the timer should be reset when started (i.e. start from zero if true or resumed if false) |
| 35 |
*/ |
| 36 |
CSkinTimer(const std::string& name, |
| 37 |
const INFO::InfoPtr& startCondition, |
| 38 |
const INFO::InfoPtr& resetCondition, |
| 39 |
const INFO::InfoPtr& stopCondition, |
| 40 |
const CGUIAction& startActions, |
| 41 |
const CGUIAction& stopActions, |
| 42 |
bool resetOnStart); |
| 43 |
|
| 44 |
/*! \brief Default skin timer destructor */ |
| 45 |
virtual ~CSkinTimer() = default; |
| 46 |
|
| 47 |
/*! \brief Start the skin timer */ |
| 48 |
void Start(); |
| 49 |
|
| 50 |
/*! \brief Resets the skin timer so that the elapsed time of the timer is 0 */ |
| 51 |
void Reset(); |
| 52 |
|
| 53 |
/*! \brief stops the skin timer */ |
| 54 |
void Stop(); |
| 55 |
|
| 56 |
/*! \brief Getter for the timer name |
| 57 |
* \return the timer name |
| 58 |
*/ |
| 59 |
const std::string& GetName() const; |
| 60 |
|
| 61 |
/*! \brief Getter for the timer start boolean condition/expression |
| 62 |
* \return the start boolean condition/expression (may be null) |
| 63 |
*/ |
| 64 |
INFO::InfoPtr GetStartCondition() const; |
| 65 |
|
| 66 |
/*! \brief Getter for the timer reset boolean condition/expression |
| 67 |
* \return the reset boolean condition/expression (may be null) |
| 68 |
*/ |
| 69 |
INFO::InfoPtr GetResetCondition() const; |
| 70 |
|
| 71 |
/*! \brief Getter for the timer start boolean condition/expression |
| 72 |
* \return the start boolean condition/expression (may be null) |
| 73 |
*/ |
| 74 |
INFO::InfoPtr GetStopCondition() const; |
| 75 |
|
| 76 |
/*! \brief Checks if a given timer is configured to reset every time it starts |
| 77 |
* \return true if the timer is configured to reset on start, false otherwise |
| 78 |
*/ |
| 79 |
bool ResetsOnStart() const; |
| 80 |
|
| 81 |
/*! \brief Gets the start actions of this skin timer |
| 82 |
* \return the actions configured to start when the timer is started |
| 83 |
*/ |
| 84 |
const CGUIAction& GetStartActions() const; |
| 85 |
|
| 86 |
/*! \brief Gets the stop actions of this skin timer |
| 87 |
* \return the actions configured to start when the timer is stopped |
| 88 |
*/ |
| 89 |
const CGUIAction& GetStopActions() const; |
| 90 |
|
| 91 |
/*! \brief Evaluates the timer start boolean info expression returning the respective result. |
| 92 |
* \details Called from the skin timer manager to check if the timer should be started |
| 93 |
* \return true if the condition is true, false otherwise |
| 94 |
*/ |
| 95 |
bool VerifyStartCondition() const; |
| 96 |
|
| 97 |
/*! \brief Evaluates the timer reset boolean info expression returning the respective result. |
| 98 |
* \details Called from the skin timer manager to check if the timer should be reset to 0 |
| 99 |
* \return true if the condition is true, false otherwise |
| 100 |
*/ |
| 101 |
bool VerifyResetCondition() const; |
| 102 |
|
| 103 |
/*! \brief Evaluates the timer stop boolean info expression returning the respective result. |
| 104 |
* \details Called from the skin timer manager to check if the timer should be stopped |
| 105 |
* \return true if the condition is true, false otherwise |
| 106 |
*/ |
| 107 |
bool VerifyStopCondition() const; |
| 108 |
|
| 109 |
private: |
| 110 |
/*! \brief Called when this timer is started */ |
| 111 |
void OnStart(); |
| 112 |
|
| 113 |
/*! \brief Called when this timer is stopped */ |
| 114 |
void OnStop(); |
| 115 |
|
| 116 |
/*! The name of the skin timer */ |
| 117 |
std::string m_name; |
| 118 |
/*! The info boolean expression that automatically starts the timer if evaluated true */ |
| 119 |
INFO::InfoPtr m_startCondition; |
| 120 |
/*! The info boolean expression that automatically resets the timer if evaluated true */ |
| 121 |
INFO::InfoPtr m_resetCondition; |
| 122 |
/*! The info boolean expression that automatically stops the timer if evaluated true */ |
| 123 |
INFO::InfoPtr m_stopCondition; |
| 124 |
/*! The builtin functions to be executed when the timer is started */ |
| 125 |
CGUIAction m_startActions; |
| 126 |
/*! The builtin functions to be executed when the timer is stopped */ |
| 127 |
CGUIAction m_stopActions; |
| 128 |
/*! if the timer should be reset on start (or just resumed) */ |
| 129 |
bool m_resetOnStart{false}; |
| 130 |
}; |