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