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:
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
TVBrowseHelper::m_dbChannumToChanids
QMultiMap< QString, uint > m_dbChannumToChanids
Definition: tvbrowsehelper.h:124
TVBrowseHelper::m_list
QList< BrowseInfo > m_list
Definition: tvbrowsehelper.h:133
TVBrowseHelper::GetNextProgram
void GetNextProgram(BrowseDirection direction, InfoMap &infoMap) const
Fetches information on the desired program from the backend.
Definition: tvbrowsehelper.cpp:259
TVBrowseHelper::TVBrowseHelper
TVBrowseHelper(TV *tv, uint browse_max_forward, bool browse_all_tuners, bool use_channel_groups, const QString &db_channel_ordering)
Definition: tvbrowsehelper.cpp:30
tv.h
BROWSE_UP
@ BROWSE_UP
Fetch information on previous channel.
Definition: tv.h:41
BrowseInfo::m_chanNum
QString m_chanNum
Definition: tvbrowsehelper.h:60
TVBrowseHelper::~TVBrowseHelper
~TVBrowseHelper() override
Definition: tvbrowsehelper.h:76
TVBrowseHelper::BrowseDispInfo
void BrowseDispInfo(PlayerContext *ctx, BrowseDirection direction)
Definition: tvbrowsehelper.h:96
TVBrowseHelper::m_ctx
PlayerContext * m_ctx
Definition: tvbrowsehelper.h:127
TVBrowseHelper::BrowseStart
bool BrowseStart(PlayerContext *ctx, bool skip_browse=false)
Begins channel browsing.
Definition: tvbrowsehelper.cpp:65
BrowseInfo::m_chanId
uint m_chanId
Definition: tvbrowsehelper.h:61
BrowseInfo::BrowseInfo
BrowseInfo(BrowseDirection dir, QString channum, uint chanid, QString starttime)
Definition: tvbrowsehelper.h:31
TVBrowseHelper::m_dbChanidToSourceid
QHash< uint, uint > m_dbChanidToSourceid
Definition: tvbrowsehelper.h:123
TVBrowseHelper::m_chanNum
QString m_chanNum
Definition: tvbrowsehelper.h:128
TVBrowseHelper::m_chanId
uint m_chanId
Definition: tvbrowsehelper.h:129
TVBrowseHelper::m_lock
QMutex m_lock
Definition: tvbrowsehelper.h:126
RemoteEncoder
Definition: remoteencoder.h:25
TVBrowseHelper::Stop
void Stop()
Definition: tvbrowsehelper.h:82
programtypes.h
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
TVBrowseHelper::BrowseChannel
void BrowseChannel(PlayerContext *ctx, const QString &channum)
Definition: tvbrowsehelper.cpp:165
TVBrowseHelper::m_startTime
QString m_startTime
Definition: tvbrowsehelper.h:130
BrowseInfo::BrowseInfo
BrowseInfo(BrowseDirection dir)
Definition: tvbrowsehelper.h:27
TVBrowseHelper::m_dbChanidToChannum
QHash< uint, QString > m_dbChanidToChannum
Definition: tvbrowsehelper.h:122
TVBrowseHelper::Wait
void Wait()
Definition: tvbrowsehelper.h:90
TVBrowseHelper::m_dbUseChannelGroups
bool m_dbUseChannelGroups
Definition: tvbrowsehelper.h:121
TVBrowseHelper::BrowseEnd
void BrowseEnd(PlayerContext *ctx, bool change_channel)
Ends channel browsing.
Definition: tvbrowsehelper.cpp:104
TVBrowseHelper::m_dbBrowseAllTuners
bool m_dbBrowseAllTuners
Definition: tvbrowsehelper.h:120
TVBrowseHelper::GetChanId
uint GetChanId(const QString &channum, uint pref_cardid, uint pref_sourceid) const
Returns a chanid for the channum, or 0 if none is available.
Definition: tvbrowsehelper.cpp:220
TVBrowseHelper::GetBrowsedInfo
BrowseInfo GetBrowsedInfo(void) const
Definition: tvbrowsehelper.cpp:189
ChannelInfoList
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:133
TVBrowseHelper::m_run
bool m_run
Definition: tvbrowsehelper.h:131
uint
unsigned int uint
Definition: compat.h:140
TVBrowseHelper
Definition: tvbrowsehelper.h:67
BROWSE_DOWN
@ BROWSE_DOWN
Fetch information on next channel.
Definition: tv.h:42
TVBrowseHelper::BrowseDispInfo
void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi)
Definition: tvbrowsehelper.cpp:140
channelinfo.h
BrowseInfo
Definition: tvbrowsehelper.h:24
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1171
TVBrowseHelper::m_wait
QWaitCondition m_wait
Definition: tvbrowsehelper.h:132
TVBrowseHelper::m_dbAllVisibleChannels
ChannelInfoList m_dbAllVisibleChannels
Definition: tvbrowsehelper.h:118
BrowseInfo::m_sourceId
uint m_sourceId
Definition: tvbrowsehelper.h:63
BrowseInfo::toString
QString toString() const
Definition: tvbrowsehelper.h:46
BROWSE_SAME
@ BROWSE_SAME
Fetch browse information on current channel and time.
Definition: tv.h:40
TVBrowseHelper::IsBrowsing
bool IsBrowsing(void) const
Definition: tvbrowsehelper.cpp:205
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
BrowseInfo::BrowseInfo
BrowseInfo(QString channum, uint sourceid)
Definition: tvbrowsehelper.h:39
mthread.h
PlayerContext
Definition: playercontext.h:48
BrowseInfo::m_dir
BrowseDirection m_dir
Definition: tvbrowsehelper.h:59
TVBrowseHelper::m_tv
TV * m_tv
Definition: tvbrowsehelper.h:116
BrowseDirection
BrowseDirection
Used to request ProgramInfo for channel browsing.
Definition: tv.h:37
TVBrowseHelper::m_dbBrowseMaxForward
uint m_dbBrowseMaxForward
Definition: tvbrowsehelper.h:119
MThread::wait
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:309
TVBrowseHelper::m_dbAllChannels
ChannelInfoList m_dbAllChannels
Definition: tvbrowsehelper.h:117
TVBrowseHelper::run
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: tvbrowsehelper.cpp:409
BrowseInfo::m_startTime
QString m_startTime
Definition: tvbrowsehelper.h:62
TVBrowseHelper::GetNextProgramDB
void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const
Definition: tvbrowsehelper.cpp:330
TV
Control TV playback.
Definition: tv_play.h:280