Merge pull request #26244 from Hitcher/media_flag_border_fix
[xbmc.git] / xbmc / pvr / PVRChannelNumberInputHandler.h
blob77810d4e994d61a7cc46cbcdcc6fd67b4fd4efd4
1 /*
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.
7 */
9 #pragma once
11 #include "pvr/channels/PVRChannelNumber.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Timer.h"
14 #include "utils/EventStream.h"
16 #include <string>
17 #include <vector>
19 namespace PVR
21 struct PVRChannelNumberInputChangedEvent
23 explicit PVRChannelNumberInputChangedEvent(const std::string& input) : m_input(input) {}
24 virtual ~PVRChannelNumberInputChangedEvent() = default;
26 std::string m_input;
29 class CPVRChannelNumberInputHandler : private ITimerCallback
31 public:
32 CPVRChannelNumberInputHandler();
33 ~CPVRChannelNumberInputHandler() override = default;
35 /*!
36 * @brief Get the events available for CEventStream.
37 * @return The events.
39 CEventStream<PVRChannelNumberInputChangedEvent>& Events() { return m_events; }
41 // implementation of ITimerCallback
42 void OnTimeout() override;
44 /*!
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;
50 /*!
51 * @brief This method gets called after the channel number input timer has expired.
53 virtual void OnInputDone() = 0;
55 /*!
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);
61 /*!
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;
67 /*!
68 * @brief Get the currently entered channel number as a formatted string.
69 * @return the channel number string.
71 std::string GetChannelNumberLabel() const;
73 /*!
74 * @brief If a number was entered, execute the associated action.
75 * @return True, if the action was executed, false otherwise.
77 bool CheckInputAndExecuteAction();
79 protected:
80 /*!
81 * @brief Get the currently entered channel number.
82 * @return the channel number.
84 CPVRChannelNumber GetChannelNumber() const;
86 /*!
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;
94 private:
95 void ExecuteAction();
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;
102 std::string m_label;
103 CTimer m_timer;
104 CEventSource<PVRChannelNumberInputChangedEvent> m_events;
107 } // namespace PVR