xbmc
PVRChannelNumberInputHandler.h
1 /*
2  * Copyright (C) 2012-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 "pvr/channels/PVRChannelNumber.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Timer.h"
14 #include "utils/EventStream.h"
15 
16 #include <string>
17 #include <vector>
18 
19 namespace PVR
20 {
22 {
23  explicit PVRChannelNumberInputChangedEvent(const std::string& input) : m_input(input) {}
24  virtual ~PVRChannelNumberInputChangedEvent() = default;
25 
26  std::string m_input;
27 };
28 
30 {
31 public:
32  static const int CHANNEL_NUMBER_INPUT_MAX_DIGITS = 5;
33 
35 
41  CPVRChannelNumberInputHandler(int iDelay, int iMaxDigits = CHANNEL_NUMBER_INPUT_MAX_DIGITS);
42 
43  ~CPVRChannelNumberInputHandler() override = default;
44 
50 
51  // implementation of ITimerCallback
52  void OnTimeout() override;
53 
58  virtual void GetChannelNumbers(std::vector<std::string>& channelNumbers) = 0;
59 
63  virtual void OnInputDone() = 0;
64 
69  virtual void AppendChannelNumberCharacter(char cCharacter);
70 
75  bool HasChannelNumber() const;
76 
81  std::string GetChannelNumberLabel() const;
82 
87  bool CheckInputAndExecuteAction();
88 
89 protected:
94  CPVRChannelNumber GetChannelNumber() const;
95 
100  size_t GetCurrentDigitCount() const { return m_inputBuffer.size(); }
101 
102  mutable CCriticalSection m_mutex;
103 
104 private:
105  void ExecuteAction();
106 
107  void SetLabel(const std::string& label);
108 
109  std::vector<std::string> m_sortedChannelNumbers;
110  const int m_iDelay;
111  const int m_iMaxDigits;
112  std::string m_inputBuffer;
113  std::string m_label;
114  CTimer m_timer;
116 };
117 
118 } // namespace PVR
Definition: ContextMenuManager.h:24
Definition: EventStream.h:65
Definition: PVRChannelNumberInputHandler.h:29
Definition: Timer.h:25
CEventStream< PVRChannelNumberInputChangedEvent > & Events()
Get the events available for CEventStream.
Definition: PVRChannelNumberInputHandler.h:49
Definition: PVRChannelNumberInputHandler.h:21
Definition: PVRChannelNumber.h:15
size_t GetCurrentDigitCount() const
Get the currently entered number of digits.
Definition: PVRChannelNumberInputHandler.h:100
Definition: Timer.h:17
Definition: EventStream.h:22