MythTV  master
tvbrowsehelper.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef _TV_BROWSE_HELPER_H_
4 #define _TV_BROWSE_HELPER_H_
5 
6 #include <utility>
7 
8 // Qt headers
9 #include <QHash>
10 #include <QMultiMap>
11 #include <QString>
12 #include <QWaitCondition>
13 
14 // MythTV headers
15 #include "channelinfo.h" // for ChannelInfoList
16 #include "programtypes.h" // for InfoMap
17 #include "mthread.h"
18 #include "tv.h" // for BrowseDirection
19 
20 class PlayerContext;
21 class RemoteEncoder;
22 class TV;
23 
25 {
26  public:
27  explicit BrowseInfo(BrowseDirection dir) :
28  m_dir(dir)
29  {
30  }
32  QString channum,
33  uint chanid,
34  QString starttime) :
35  m_dir(dir), m_chanNum(std::move(channum)),
36  m_chanId(chanid), m_startTime(std::move(starttime))
37  {
38  }
39  BrowseInfo(QString channum,
40  uint sourceid) :
41  m_chanNum(std::move(channum)),
42  m_sourceId(sourceid)
43  {
44  }
45 
46  QString toString() const
47  {
48  return QString("%1;%2;%3;%4;%5")
49  .arg(BROWSE_SAME==m_dir?"SAME":
50  BROWSE_UP ==m_dir?"UP":
51  BROWSE_DOWN==m_dir?"DOWN":
52  QString::number(m_dir))
53  .arg(m_chanNum)
54  .arg(m_chanId)
55  .arg(m_startTime)
56  .arg(m_sourceId);
57  }
58 
60  QString m_chanNum;
62  QString m_startTime;
64 };
65 
66 
67 class TVBrowseHelper : public MThread
68 {
69  public:
70  TVBrowseHelper(TV *tv,
71  uint browse_max_forward,
72  bool browse_all_tuners,
73  bool use_channel_groups,
74  const QString& db_channel_ordering);
75 
76  ~TVBrowseHelper() override
77  {
78  Stop();
79  Wait();
80  }
81 
82  void Stop()
83  {
84  QMutexLocker locker(&m_lock);
85  m_list.clear();
86  m_run = false;
87  m_wait.wakeAll();
88  }
89 
90  void Wait() { MThread::wait(); }
91 
92  bool BrowseStart(PlayerContext *ctx, bool skip_browse = false);
93  void BrowseEnd(PlayerContext *ctx, bool change_channel);
94  void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi);
95 
97  {
98  BrowseInfo bi(direction);
99  if (BROWSE_SAME != direction)
100  BrowseDispInfo(ctx, bi);
101  }
102 
103  void BrowseChannel(PlayerContext *ctx, const QString &channum);
104 
105  BrowseInfo GetBrowsedInfo(void) const;
106  bool IsBrowsing(void) const;
107  uint GetChanId(const QString &channum,
108  uint pref_cardid, uint pref_sourceid) const;
109 
110  protected:
111  void GetNextProgram(BrowseDirection direction, InfoMap &infoMap) const;
112  void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const;
113 
114  void run() override; // MThread
115 
116  TV *m_tv {nullptr};
122  QHash<uint,QString> m_dbChanidToChannum;
123  QHash<uint,uint> m_dbChanidToSourceid;
124  QMultiMap<QString,uint> m_dbChannumToChanids;
125 
126  mutable QMutex m_lock; // protects variables below
127  PlayerContext *m_ctx {nullptr};
128  QString m_chanNum;
130  QString m_startTime;
131  bool m_run {true};
132  QWaitCondition m_wait;
133  QList<BrowseInfo> m_list;
134 };
135 
136 #endif // _TV_BROWSE_HELPER_H_
QString toString() const
QHash< uint, QString > m_dbChanidToChannum
void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi)
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
QHash< uint, uint > m_dbChanidToSourceid
Fetch browse information on current channel and time.
Definition: tv.h:40
void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
BrowseInfo(BrowseDirection dir)
BrowseDirection m_dir
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:311
void BrowseDispInfo(PlayerContext *ctx, BrowseDirection direction)
void GetNextProgram(BrowseDirection direction, InfoMap &infoMap) const
Fetches information on the desired program from the backend.
~TVBrowseHelper() override
bool IsBrowsing(void) const
QMultiMap< QString, uint > m_dbChannumToChanids
bool BrowseStart(PlayerContext *ctx, bool skip_browse=false)
Begins channel browsing.
BrowseInfo GetBrowsedInfo(void) const
BrowseInfo(BrowseDirection dir, QString channum, uint chanid, QString starttime)
BrowseInfo(QString channum, uint sourceid)
Control TV playback.
Definition: tv_play.h:279
unsigned int uint
Definition: compat.h:140
void BrowseChannel(PlayerContext *ctx, const QString &channum)
QWaitCondition m_wait
ChannelInfoList m_dbAllVisibleChannels
QString m_startTime
void BrowseEnd(PlayerContext *ctx, bool change_channel)
Ends channel browsing.
BrowseDirection
Used to request ProgramInfo for channel browsing.
Definition: tv.h:37
Fetch information on next channel.
Definition: tv.h:42
QString m_chanNum
TVBrowseHelper(TV *tv, uint browse_max_forward, bool browse_all_tuners, bool use_channel_groups, const QString &db_channel_ordering)
Fetch information on previous channel.
Definition: tv.h:41
ChannelInfoList m_dbAllChannels
QList< BrowseInfo > m_list
uint GetChanId(const QString &channum, uint pref_cardid, uint pref_sourceid) const
Returns a chanid for the channum, or 0 if none is available.
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:133
PlayerContext * m_ctx