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 CPVRChannelNumberInputHandler();
33 ~CPVRChannelNumberInputHandler() override
= default;
36 * @brief Get the events available for CEventStream.
39 CEventStream
<PVRChannelNumberInputChangedEvent
>& Events() { return m_events
; }
41 // implementation of ITimerCallback
42 void OnTimeout() override
;
45 * @brief Get the currently available channel numbers.
46 * @param channelNumbers The list to fill with the channel numbers.
48 virtual void GetChannelNumbers(std::vector
<std::string
>& channelNumbers
) = 0;
51 * @brief This method gets called after the channel number input timer has expired.
53 virtual void OnInputDone() = 0;
56 * @brief Appends a channel number character.
57 * @param cCharacter The character to append. value must be CPVRChannelNumber::SEPARATOR ('.') or any char in the range from '0' to '9'.
59 virtual void AppendChannelNumberCharacter(char cCharacter
);
62 * @brief Check whether a channel number was entered.
63 * @return True if the handler currently holds a channel number, false otherwise.
65 bool HasChannelNumber() const;
68 * @brief Get the currently entered channel number as a formatted string.
69 * @return the channel number string.
71 std::string
GetChannelNumberLabel() const;
74 * @brief If a number was entered, execute the associated action.
75 * @return True, if the action was executed, false otherwise.
77 bool CheckInputAndExecuteAction();
81 * @brief Get the currently entered channel number.
82 * @return the channel number.
84 CPVRChannelNumber
GetChannelNumber() const;
87 * @brief Get the currently entered number of digits.
88 * @return the number of digits.
90 size_t GetCurrentDigitCount() const { return m_inputBuffer
.size(); }
92 mutable CCriticalSection m_mutex
;
97 void SetLabel(const std::string
& label
);
99 std::vector
<std::string
> m_sortedChannelNumbers
;
100 const uint32_t m_delay
;
101 std::string m_inputBuffer
;
104 CEventSource
<PVRChannelNumberInputChangedEvent
> m_events
;