2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "pvr/channels/PVRChannelNumber.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Timer.h"
14 #include "utils/EventStream.h"
21 struct PVRChannelNumberInputChangedEvent
23 explicit PVRChannelNumberInputChangedEvent(const std::string
& input
) : m_input(input
) {}
24 virtual ~PVRChannelNumberInputChangedEvent() = default;
29 class CPVRChannelNumberInputHandler
: private ITimerCallback
32 static const int CHANNEL_NUMBER_INPUT_MAX_DIGITS
= 5;
34 CPVRChannelNumberInputHandler();
38 * @param iDelay timer delay in millisecods.
39 * @param iMaxDigits maximum number of display digits to use.
41 CPVRChannelNumberInputHandler(int iDelay
, int iMaxDigits
= CHANNEL_NUMBER_INPUT_MAX_DIGITS
);
43 ~CPVRChannelNumberInputHandler() override
= default;
46 * @brief Get the events available for CEventStream.
49 CEventStream
<PVRChannelNumberInputChangedEvent
>& Events() { return m_events
; }
51 // implementation of ITimerCallback
52 void OnTimeout() override
;
55 * @brief Get the currently available channel numbers.
56 * @param channelNumbers The list to fill with the channel numbers.
58 virtual void GetChannelNumbers(std::vector
<std::string
>& channelNumbers
) = 0;
61 * @brief This method gets called after the channel number input timer has expired.
63 virtual void OnInputDone() = 0;
66 * @brief Appends a channel number character.
67 * @param cCharacter The character to append. value must be CPVRChannelNumber::SEPARATOR ('.') or any char in the range from '0' to '9'.
69 virtual void AppendChannelNumberCharacter(char cCharacter
);
72 * @brief Check whether a channel number was entered.
73 * @return True if the handler currently holds a channel number, false otherwise.
75 bool HasChannelNumber() const;
78 * @brief Get the currently entered channel number as a formatted string.
79 * @return the channel number string.
81 std::string
GetChannelNumberLabel() const;
84 * @brief If a number was entered, execute the associated action.
85 * @return True, if the action was executed, false otherwise.
87 bool CheckInputAndExecuteAction();
91 * @brief Get the currently entered channel number.
92 * @return the channel number.
94 CPVRChannelNumber
GetChannelNumber() const;
97 * @brief Get the currently entered number of digits.
98 * @return the number of digits.
100 size_t GetCurrentDigitCount() const { return m_inputBuffer
.size(); }
102 mutable CCriticalSection m_mutex
;
105 void ExecuteAction();
107 void SetLabel(const std::string
& label
);
109 std::vector
<std::string
> m_sortedChannelNumbers
;
111 const int m_iMaxDigits
;
112 std::string m_inputBuffer
;
115 CEventSource
<PVRChannelNumberInputChangedEvent
> m_events
;