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 <QWaitCondition>
7 #include <QMultiMap>
8 #include <QString>
9 #include <QHash>
10 
11 #include "channelinfo.h" // for ChannelInfoList
12 #include "programtypes.h" // for InfoMap
13 #include "mthread.h"
14 #include "tv.h" // for BrowseDirection
15 
16 class PlayerContext;
17 class RemoteEncoder;
18 class TV;
19 
21 {
22  public:
23  explicit BrowseInfo(BrowseDirection dir) :
24  m_dir(dir), m_chanid(0), m_sourceid(0)
25  {
26  }
28  const QString &channum,
29  uint chanid,
30  const QString &starttime) :
31  m_dir(dir), m_channum(channum),
32  m_chanid(chanid), m_starttime(starttime)
33  {
34  }
35  BrowseInfo(const QString &channum,
36  uint sourceid) :
37  m_channum(channum),
38  m_sourceid(sourceid)
39  {
40  }
41 
42  QString toString() const
43  {
44  return QString("%1;%2;%3;%4;%5")
45  .arg(BROWSE_SAME==m_dir?"SAME":
46  BROWSE_UP ==m_dir?"UP":
47  BROWSE_DOWN==m_dir?"DOWN":
48  QString::number(m_dir))
49  .arg(m_channum)
50  .arg(m_chanid)
51  .arg(m_starttime)
52  .arg(m_sourceid);
53  }
54 
56  QString m_channum;
58  QString m_starttime;
60 };
61 
62 
63 class TVBrowseHelper : public MThread
64 {
65  public:
66  TVBrowseHelper(TV *tv,
67  uint browse_max_forward,
68  bool browse_all_tuners,
69  bool use_channel_groups,
70  const QString& db_channel_ordering);
71 
72  virtual ~TVBrowseHelper()
73  {
74  Stop();
75  Wait();
76  }
77 
78  void Stop()
79  {
80  QMutexLocker locker(&m_lock);
81  m_list.clear();
82  m_run = false;
83  m_wait.wakeAll();
84  }
85 
86  void Wait() { MThread::wait(); }
87 
88  bool BrowseStart(PlayerContext *ctx, bool skip_browse = false);
89  void BrowseEnd(PlayerContext *ctx, bool change_channel);
90  void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi);
91 
93  {
94  BrowseInfo bi(direction);
95  if (BROWSE_SAME != direction)
96  BrowseDispInfo(ctx, bi);
97  }
98 
99  void BrowseChannel(PlayerContext *ctx, const QString &channum);
100 
101  BrowseInfo GetBrowsedInfo(void) const;
102  bool IsBrowsing(void) const;
103  uint GetChanId(const QString &channum,
104  uint pref_cardid, uint pref_sourceid) const;
105 
106  protected:
107  void GetNextProgram(BrowseDirection direction, InfoMap &infoMap) const;
108  void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const;
109 
110  void run() override; // MThread
111 
112  TV *m_tv {nullptr};
118  QHash<uint,QString> m_dbChanidToChannum;
119  QHash<uint,uint> m_dbChanidToSourceid;
120  QMultiMap<QString,uint> m_dbChannumToChanids;
121 
122  mutable QMutex m_lock; // protects variables below
123  PlayerContext *m_ctx {nullptr};
124  QString m_channum;
126  QString m_starttime;
127  bool m_run {true};
128  QWaitCondition m_wait;
129  QList<BrowseInfo> m_list;
130 };
131 
132 #endif // _TV_BROWSE_HELPER_H_
QString toString() const
QHash< uint, QString > m_dbChanidToChannum
void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi)
Fetch information on previous channel.
Definition: tv.h:41
QString m_channum
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
QHash< uint, uint > m_dbChanidToSourceid
void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const
BrowseInfo(BrowseDirection dir)
virtual ~TVBrowseHelper()
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.
BrowseInfo(BrowseDirection dir, const QString &channum, uint chanid, const QString &starttime)
Fetch browse information on current channel and time.
Definition: tv.h:40
unsigned int uint
Definition: compat.h:140
bool IsBrowsing(void) const
Fetch information on next channel.
Definition: tv.h:42
enum BrowseDirections BrowseDirection
Used to request ProgramInfo for channel browsing.
QMultiMap< QString, uint > m_dbChannumToChanids
bool BrowseStart(PlayerContext *ctx, bool skip_browse=false)
Begins channel browsing.
BrowseInfo GetBrowsedInfo(void) const
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QString m_starttime
Control TV playback.
Definition: tv_play.h:284
void BrowseChannel(PlayerContext *ctx, const QString &channum)
QWaitCondition m_wait
ChannelInfoList m_dbAllVisibleChannels
void BrowseEnd(PlayerContext *ctx, bool change_channel)
Ends channel browsing.
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:120
TVBrowseHelper(TV *tv, uint browse_max_forward, bool browse_all_tuners, bool use_channel_groups, const QString &db_channel_ordering)
ChannelInfoList m_dbAllChannels
BrowseInfo(const QString &channum, uint sourceid)
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.
PlayerContext * m_ctx