Go to the documentation of this file.
2 #include <QCoreApplication>
16 #define LOC QString("BrowseHelper: ")
18 static void format_time(
int seconds, QString& tMin, QString& tHrsMin)
20 int minutes = seconds / 60;
21 int hours = minutes / 60;
22 int min = minutes % 60;
24 tMin = TV::tr(
"%n minute(s)",
"", minutes);
25 tHrsMin = QString(
"%1:%2").arg(hours).arg(min, 2, 10, QChar(
'0'));
41 bool UseChannelGroups,
const QString &DBChannelOrdering)
219 {
return Chan.m_sourceId == PrefSourceid && Chan.m_chanNum ==
Channum; };
222 return chan->m_chanId;
228 {
return Chan.GetInputIds().contains(PrefCardid) && Chan.m_chanNum ==
Channum; };
231 return chan->m_chanId;
239 return chan->m_chanId;
270 QString starttime = Infomap[
"dbstarttime"];
271 QString chanid = Infomap[
"chanid"];
272 QString channum = Infomap[
"channum"];
273 QString seriesid = Infomap[
"seriesid"];
274 QString programid = Infomap[
"programid"];
277 starttime, endtime, callsign, iconpath,
278 channum, chanid, seriesid, programid);
281 if (!starttime.isEmpty())
289 Infomap[
"endtime"] = Infomap[
"enddate"] =
"";
290 if (!endtime.isEmpty())
297 Infomap[
"lenmins"] = TV::tr(
"%n minute(s)",
"", 0);
298 Infomap[
"lentime"] =
"0:00";
299 if (begts.isValid() && endts.isValid())
303 format_time(
static_cast<int>(begts.secsTo(endts)), lenM, lenHM);
304 Infomap[
"lenmins"] = lenM;
305 Infomap[
"lentime"] = lenHM;
308 Infomap[
"dbstarttime"] = starttime;
309 Infomap[
"dbendtime"] = endtime;
310 Infomap[
"title"] = title;
311 Infomap[
"subtitle"] = subtitle;
312 Infomap[
"description"] = desc;
313 Infomap[
"category"] = category;
314 Infomap[
"callsign"] = callsign;
315 Infomap[
"channum"] = channum;
316 Infomap[
"chanid"] = chanid;
317 Infomap[
"iconpath"] = iconpath;
318 Infomap[
"seriesid"] = seriesid;
319 Infomap[
"programid"] = programid;
324 uint chanid = Infomap[
"chanid"].toUInt();
327 LOG(VB_GENERAL, LOG_ERR,
LOC +
"GetNextProgramDB() requires a chanid");
355 Infomap[
"chanid"] = QString::number(chanid);
359 static constexpr int64_t kSixHours {6LL * 60 * 60};
360 QDateTime latesttime = nowtime.addSecs(kSixHours);
364 bindings[
":CHANID"] = chanid;
365 bindings[
":NOWTS"] = nowtime;
366 bindings[
":LATESTTS"] = latesttime;
367 bindings[
":BROWSETS"] = browsetime;
368 bindings[
":BROWSETS2"] = browsetime;
370 QString querystr =
" WHERE program.chanid = :CHANID ";
374 querystr +=
" AND program.endtime <= :BROWSETS AND program.endtime > :NOWTS ";
377 querystr +=
" AND program.starttime > :BROWSETS AND program.starttime < :LATESTTS ";
380 querystr +=
" AND program.starttime <= :BROWSETS AND program.endtime > :BROWSETS2 ";
387 if (progList.
empty())
389 Infomap[
"dbstarttime"] =
"";
394 progList[
static_cast<uint>(progList.
size() - 1)] : progList[0];
401 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
"Helper thread starting");
414 std::vector<uint> chanids;
419 std::vector<uint> chanids_extra;
421 QMultiMap<QString,uint>::iterator it;
427 chanids.push_back(*it);
429 chanids_extra.push_back(*it);
431 chanids.insert(chanids.end(),
432 chanids_extra.begin(),
433 chanids_extra.end());
444 if (lasttime < curtime)
448 if ((lasttime > maxtime) && (direction ==
BROWSE_RIGHT))
503 if (!chanids.empty())
506 auto it = std::find_if(chanids.cbegin(), chanids.cend(), tunable);
507 if (it != chanids.cend())
509 infoMap[
"chanid"] = QString::number(*it);
515 uint orig_chanid = infoMap[
"chanid"].toUInt();
518 (infoMap[
"chanid"].toUInt() != orig_chanid))
532 !infoMap[
"dbstarttime"].isEmpty())
549 infoMap[
"channelgroup"] = QObject::tr(
"All channels");
553 recinfo.
ToMap(infoMap);
559 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
"Helper thread exiting");
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
QMultiMap< QString, uint > m_dbChannumToChanids
@ BROWSE_LEFT
Fetch information on current channel in the past.
int m_lastCardid
CardID of current/last recorder.
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
static constexpr const char * OSD_WIN_BROWSE
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void BrowseEnd(bool ChangeChannel)
Ends channel browsing.
@ BROWSE_UP
Fetch information on previous channel.
void UnlockPlayingInfo(const char *file, int line) const
static QString GetChannelGroupName(int grpid)
~TVBrowseHelper() override
ChannelChangeDirection
ChannelChangeDirection is an enumeration of possible channel changing directions.
QString m_browseStartTime
TVBrowseHelper(TV *Parent)
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Holds information on a TV Program one might wish to record.
static const std::chrono::milliseconds kBrowseTimeout
QString GetChanNum(void) const
This is the channel "number", in the form 1, 1_2, 1-2, 1#1, etc.
void GetNextProgram(int direction, QString &title, QString &subtitle, QString &desc, QString &category, QString &starttime, QString &endtime, QString &callsign, QString &iconpath, QString &channelname, QString &chanid, QString &seriesid, QString &programid)
Returns information about the program that would be seen if we changed the channel using ChangeChanne...
QHash< uint, uint > m_dbChanidToSourceid
void ChangeChannel(const ChannelInfoList &Options)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
uint GetBrowseChanId(const QString &Channum, uint PrefCardid, uint PrefSourceid) const
Returns a chanid for the channum, or 0 if none is available.
static uint GetNextChannel(const ChannelInfoList &sorted, uint old_chanid, uint mplexid_restriction, uint chanid_restriction, ChannelChangeDirection direction, bool skip_non_visible=true, bool skip_same_channum_and_callsign=false, bool skip_other_sources=false)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
QHash< QString, QString > InfoMap
static void SortChannels(ChannelInfoList &list, const QString &order, bool eliminate_duplicates=false)
ChannelInfoList m_channelGroupChannelList
QDateTime GetScheduledStartTime(void) const
The scheduled start time of program.
void GetNextProgram(BrowseDirection Direction, InfoMap &Infomap) const
Fetches information on the desired program from the backend.
ProgramInfo * m_playingInfo
Currently playing info.
QHash< uint, QString > m_dbChanidToChannum
void LockPlayingInfo(const char *file, int line) const
int StartTimer(std::chrono::milliseconds Interval, int Line)
static HostCheckBoxSetting * BrowseAllTuners()
bool m_dbUseChannelGroups
void BrowseInit(std::chrono::seconds BrowseMaxForward, bool BrowseAllTuners, bool UseChannelGroups, const QString &DBChannelOrdering)
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
virtual void ToMap(InfoMap &progMap, bool showrerecord=false, uint star_range=10, uint date_format=0) const
Converts ProgramInfo into QString QHash containing each field in ProgramInfo converted into localized...
static bool IsTunable(uint ChanId)
void GetNextProgramDB(BrowseDirection Direction, InfoMap &Infomap) const
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
@ CHANNEL_DIRECTION_FAVORITE
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
@ BROWSE_DOWN
Fetch information on next channel.
void BrowseDispInfo(const BrowseInfo &Browseinfo)
@ BROWSE_RIGHT
Fetch information on current channel in the future.
BrowseInfo GetBrowsedInfo() const
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
@ BROWSE_FAVORITE
Fetch information on the next favorite channel.
void ReturnOSDLock() const
QWaitCondition m_browseWait
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
void ReturnPlayerLock() const
static void format_time(int seconds, QString &tMin, QString &tHrsMin)
static QString GetIcon(uint chanid)
Holds information on recordings and videos.
PlayerContext * GetPlayerContext()
Return a pointer to TV::m_playerContext.
ChannelInfoList m_dbAllVisibleChannels
volatile int m_channelGroupId
bool LoadFromProgram(ProgramList &destination, const QString &where, const QString &groupBy, const QString &orderBy, const MSqlBindings &bindings, const ProgramList &schedList)
@ BROWSE_SAME
Fetch browse information on current channel and time.
This is a wrapper around QThread that does several additional things.
static uint GetSourceID(uint inputid)
void HideWindow(const QString &Window) override
QMutex m_channelGroupLock
Lock necessary when modifying channel group variables.
void BrowseChannel(const QString &Channum)
@ kDateFull
Default local time.
QList< BrowseInfo > m_browseList
BrowseDirection
Used to request ProgramInfo for channel browsing.
void GetPlayerReadLock() const
RemoteEncoder * m_recorder
@ kTime
Default local time.
bool BrowseStart(bool SkipBrowse=false)
Begins channel browsing.
ChannelInfoList m_dbAllChannels
std::chrono::seconds m_dbBrowseMaxForward
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.