MythTV  master
guidegrid.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 #ifndef GUIDEGRID_H_
3 #define GUIDEGRID_H_
4 
5 // c++
6 #include <utility>
7 #include <vector>
8 using namespace std;
9 
10 // qt
11 #include <QString>
12 #include <QDateTime>
13 #include <QEvent>
14 #include <QLinkedList>
15 
16 // myth
17 #include "mythscreentype.h"
18 #include "programinfo.h"
19 #include "channelgroup.h"
20 #include "channelutil.h"
21 #include "mythuiguidegrid.h"
22 #include "mthreadpool.h"
23 #include "tv_play.h"
24 
25 // mythfrontend
26 #include "schedulecommon.h"
27 
28 using namespace std;
29 
30 class ProgramInfo;
31 class QTimer;
32 class MythUIButtonList;
33 class MythUIGuideGrid;
34 
35 using db_chan_list_t = vector<ChannelInfo> ;
36 using db_chan_list_list_t = vector<db_chan_list_t>;
38 
39 class JumpToChannel;
41 {
42  public:
43  virtual ~JumpToChannelListener() = default;
44  virtual void GoTo(int start, int cur_row) = 0;
45  virtual void SetJumpToChannel(JumpToChannel *ptr) = 0;
46  virtual int FindChannel(uint chanid, const QString &channum,
47  bool exact = true) const = 0;
48 };
49 
50 class JumpToChannel : public QObject
51 {
52  Q_OBJECT
53 
54  public:
56  JumpToChannelListener *parent, QString start_entry,
57  int start_chan_idx, int cur_chan_idx, uint rows_disp);
58 
59  bool ProcessEntry(const QStringList &actions, const QKeyEvent *e);
60 
61  QString GetEntry(void) const { return m_entry; }
62 
63  public slots:
64  virtual void deleteLater(void);
65 
66  private:
67  ~JumpToChannel() override = default;
68  bool Update(void);
69 
70  private:
71  JumpToChannelListener *m_listener {nullptr};
72  QString m_entry;
76  QTimer *m_timer {nullptr}; // audited ref #5318
77 
78  static const uint kJumpToChannelTimeout = 3500; // ms
79 };
80 
81 // GuideUIElement encapsulates the arguments to
82 // MythUIGuideGrid::SetProgramInfo(). The elements are prepared in a
83 // background thread and then sent via an event to the UI thread for
84 // rendering.
86 public:
87  GuideUIElement(int row, int col, const QRect &area,
88  QString title, QString category,
89  int arrow, int recType, int recStat, bool selected)
90  : m_row(row), m_col(col), m_area(area), m_title(std::move(title)),
91  m_category(std::move(category)), m_arrow(arrow), m_recType(recType),
92  m_recStat(recStat), m_selected(selected) {}
93  const int m_row;
94  const int m_col;
95  const QRect m_area;
96  const QString m_title;
97  const QString m_category;
98  const int m_arrow;
99  const int m_recType;
100  const int m_recStat;
101  const bool m_selected;
102 };
103 
105 {
106  Q_OBJECT;
107 
108  public:
109  // Use this function to instantiate a guidegrid instance.
110  static void RunProgramGuide(uint startChanId,
111  const QString &startChanNum,
112  const QDateTime &startTime,
113  TV *player = nullptr,
114  bool embedVideo = false,
115  bool allowFinder = true,
116  int changrpid = -1);
117 
118  ChannelInfoList GetSelection(void) const;
119 
120  void GoTo(int start, int cur_row) override; // JumpToChannelListener
121  void SetJumpToChannel(JumpToChannel *ptr) override; // JumpToChannelListener
122 
123  bool Create(void) override; // MythScreenType
124  void Load(void) override; // MythScreenType
125  void Init(void) override; // MythScreenType
126  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
127  bool gestureEvent(MythGestureEvent *event) override; // MythScreenType
128 
129  void aboutToShow() override; // MythScreenType
130  void aboutToHide() override; // MythScreenType
131  // Allow class GuideUpdateProgramRow to figure out whether the
132  // current start time/channel coordinates are the same, so that it can
133  // skip the work if not.
134  uint GetCurrentStartChannel(void) const { return m_currentStartChannel; }
135  QDateTime GetCurrentStartTime(void) const { return m_currentStartTime; }
136 
137  protected slots:
138  void cursorLeft();
139  void cursorRight();
140  void cursorDown();
141  void cursorUp();
142 
143  void toggleGuideListing();
144  void toggleChannelFavorite(int grpid = -1);
145  void ChannelGroupMenu(int mode = 0);
146  void generateListings();
147 
148  void enter();
149 
150  void showProgFinder();
151  void channelUpdate();
152  void volumeUpdate(bool up);
153  void toggleMute(bool muteIndividualChannels = false);
154 
155  void deleteRule();
156 
157  void Close() override; // MythScreenType
158  void customEvent(QEvent *event) override; // ScheduleCommon
159 
160  protected:
161  GuideGrid(MythScreenStack *parentStack,
162  uint chanid, QString channum,
163  const QDateTime &startTime,
164  TV *player = nullptr,
165  bool embedVideo = false,
166  bool allowFinder = true,
167  int changrpid = -1);
168  ~GuideGrid() override;
169  ProgramInfo *GetCurrentProgram(void) const override // ScheduleCommon
170  { return m_programInfos[m_currentRow][m_currentCol]; };
171 
172  private slots:
173  void updateTimeout(void);
174  void refreshVideo(void);
175  void updateInfo(void);
176  void updateChannels(void);
177  void updateJumpToChannel(void);
178 
179  private:
180 
181  Q_DISABLE_COPY(GuideGrid);
182 
183  enum MoveVector {
194  };
195 
196  void moveLeftRight(MoveVector movement);
197  void moveUpDown(MoveVector movement);
198  void moveToTime(const QDateTime& datetime);
199 
200  void ShowMenu(void) override; // MythScreenType
201  void ShowRecordingMenu(void);
202  void ShowJumpToTime(void);
203 
204  int FindChannel(uint chanid, const QString &channum,
205  bool exact = true) const override; // JumpToChannelListener
206 
207  void fillChannelInfos(bool gotostartchannel = true);
208  void fillTimeInfos(void);
209  void fillProgramInfos(bool useExistingData = false);
210  // Set row=-1 to fill all rows.
211  void fillProgramRowInfos(int row, bool useExistingData);
212 public:
213  // These need to be public so that the helper classes can operate.
214  ProgramList *getProgramListFromProgram(int chanNum);
215  void updateProgramsUI(unsigned int firstRow, unsigned int numRows,
216  int progPast,
217  const QVector<ProgramList*> &proglists,
218  const ProgInfoGuideArray &programInfos,
219  const QLinkedList<GuideUIElement> &elements);
220  void updateChannelsNonUI(QVector<ChannelInfo *> &chinfos,
221  QVector<bool> &unavailables);
222  void updateChannelsUI(const QVector<ChannelInfo *> &chinfos,
223  const QVector<bool> &unavailables);
224 private:
225 
226  void setStartChannel(int newStartChannel);
227 
228  ChannelInfo *GetChannelInfo(uint chan_idx, int sel = -1);
229  const ChannelInfo *GetChannelInfo(uint chan_idx, int sel = -1) const;
230  uint GetChannelCount(void) const;
231  int GetStartChannelOffset(int row = -1) const;
232 
233  ProgramList GetProgramList(uint chanid) const;
234  uint GetAlternateChannelIndex(uint chan_idx, bool with_same_channum) const;
235  void updateDateText(void);
236 
237  private:
238  int m_selectRecThreshold {16};
239 
240  bool m_allowFinder {false};
242  QMap<uint,uint> m_channelInfoIdx;
243 
244  vector<ProgramList*> m_programs;
245  ProgInfoGuideArray m_programInfos {};
247 
250  QDateTime m_currentEndTime;
251  uint m_currentStartChannel {0};
253  QString m_startChanNum;
254 
255  int m_currentRow {0};
256  int m_currentCol {0};
257 
258  bool m_sortReverse {false};
259 
260  int m_channelCount {5};
261  int m_timeCount {30};
262  bool m_verticalLayout {false};
263 
264  QDateTime m_firstTime;
265  QDateTime m_lastTime;
266 
267  TV *m_player {nullptr};
268  bool m_usingNullVideo {false};
269  bool m_embedVideo {false};
270  QTimer *m_previewVideoRefreshTimer {nullptr}; // audited ref #5318
271  void EmbedTVWindow(void);
272  static void HideTVWindow(void);
273  QRect m_videoRect;
274 
276 
277  QTimer *m_updateTimer {nullptr}; // audited ref #5318
278 
280 
281  int m_changrpid {-1};
283 
284  QMutex m_jumpToChannelLock {QMutex::Recursive};
285  JumpToChannel *m_jumpToChannel {nullptr};
286 
287  MythUIButtonList *m_timeList {nullptr};
288  MythUIButtonList *m_channelList {nullptr};
289  MythUIGuideGrid *m_guideGrid {nullptr};
290  MythUIText *m_dateText {nullptr};
291  MythUIText *m_longdateText {nullptr};
292  MythUIText *m_jumpToText {nullptr};
293  MythUIText *m_changroupname {nullptr};
294  MythUIImage *m_channelImage {nullptr};
295 };
296 
297 #endif
QDateTime GetCurrentStartTime(void) const
Definition: guidegrid.h:135
uint m_startChanID
Definition: guidegrid.h:252
const QString m_category
Definition: guidegrid.h:97
A narrow purpose widget used to show television programs and the timeslots they occupy on channels.
QString m_startChanNum
Definition: guidegrid.h:253
unsigned int slots[4]
Definition: element.c:38
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
ProgramInfo * GetCurrentProgram(void) const override
Definition: guidegrid.h:169
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
QString m_entry
Definition: guidegrid.h:72
QDateTime m_lastTime
Definition: guidegrid.h:265
const QRect m_area
Definition: guidegrid.h:95
const int m_arrow
Definition: guidegrid.h:98
QDateTime m_currentStartTime
Definition: guidegrid.h:249
const QString m_title
Definition: guidegrid.h:96
uint m_rowsDisplayed
Definition: guidegrid.h:75
vector< db_chan_list_t > db_chan_list_list_t
Definition: guidegrid.h:36
ProgramInfo *[MAX_DISPLAY_CHANS][MAX_DISPLAY_TIMES] ProgInfoGuideArray
Definition: guidegrid.h:37
Holds information on recordings and videos.
Definition: programinfo.h:67
QDateTime m_currentEndTime
Definition: guidegrid.h:250
QString GetEntry(void) const
Definition: guidegrid.h:61
int m_previousStartChannelIndex
Definition: guidegrid.h:73
QDateTime m_originalStartTime
Definition: guidegrid.h:248
const int m_row
Definition: guidegrid.h:93
QDateTime m_firstTime
Definition: guidegrid.h:264
Control TV playback.
Definition: tv_play.h:279
ProgramList m_recList
Definition: guidegrid.h:246
unsigned int uint
Definition: compat.h:140
MThreadPool m_threadPool
Definition: guidegrid.h:279
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
vector< ChannelGroupItem > ChannelGroupList
Definition: channelgroup.h:32
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
db_chan_list_list_t m_channelInfos
Definition: guidegrid.h:241
const int m_recType
Definition: guidegrid.h:99
QRect m_videoRect
Definition: guidegrid.h:273
QMap< uint, uint > m_channelInfoIdx
Definition: guidegrid.h:242
int m_previousCurrentChannelIndex
Definition: guidegrid.h:74
const bool m_selected
Definition: guidegrid.h:101
const int m_recStat
Definition: guidegrid.h:100
#define MAX_DISPLAY_TIMES
vector< ProgramList * > m_programs
Definition: guidegrid.h:244
vector< ChannelInfo > db_chan_list_t
Definition: guidegrid.h:35
uint GetCurrentStartChannel(void) const
Definition: guidegrid.h:134
#define MAX_DISPLAY_CHANS
ChannelGroupList m_changrplist
Definition: guidegrid.h:282
const int m_col
Definition: guidegrid.h:94
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:133
QString m_channelOrdering
Definition: guidegrid.h:275
GuideUIElement(int row, int col, const QRect &area, QString title, QString category, int arrow, int recType, int recStat, bool selected)
Definition: guidegrid.h:87