2#include <QCoreApplication>
16#define LOC QString("BrowseHelper: ")
18static 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)
217 {
return Chan.m_sourceId == PrefSourceid && Chan.m_chanNum ==
Channum; };
220 return chan->m_chanId;
226 {
return Chan.GetInputIds().contains(PrefCardid) && Chan.m_chanNum ==
Channum; };
229 return chan->m_chanId;
237 return chan->m_chanId;
268 QString starttime = Infomap[
"dbstarttime"];
269 QString chanid = Infomap[
"chanid"];
270 QString channum = Infomap[
"channum"];
271 QString seriesid = Infomap[
"seriesid"];
272 QString programid = Infomap[
"programid"];
275 starttime, endtime, callsign, iconpath,
276 channum, chanid, seriesid, programid);
279 if (!starttime.isEmpty())
287 Infomap[
"endtime"] = Infomap[
"enddate"] =
"";
288 if (!endtime.isEmpty())
295 Infomap[
"lenmins"] = TV::tr(
"%n minute(s)",
"", 0);
296 Infomap[
"lentime"] =
"0:00";
297 if (begts.isValid() && endts.isValid())
301 format_time(
static_cast<int>(begts.secsTo(endts)), lenM, lenHM);
302 Infomap[
"lenmins"] = lenM;
303 Infomap[
"lentime"] = lenHM;
306 Infomap[
"dbstarttime"] = starttime;
307 Infomap[
"dbendtime"] = endtime;
308 Infomap[
"title"] = title;
309 Infomap[
"subtitle"] = subtitle;
310 Infomap[
"description"] = desc;
311 Infomap[
"category"] = category;
312 Infomap[
"callsign"] = callsign;
313 Infomap[
"channum"] = channum;
314 Infomap[
"chanid"] = chanid;
315 Infomap[
"iconpath"] = iconpath;
316 Infomap[
"seriesid"] = seriesid;
317 Infomap[
"programid"] = programid;
322 uint chanid = Infomap[
"chanid"].toUInt();
325 LOG(VB_GENERAL, LOG_ERR,
LOC +
"GetNextProgramDB() requires a chanid");
353 Infomap[
"chanid"] = QString::number(chanid);
357 static constexpr int64_t kSixHours {6LL * 60 * 60};
358 QDateTime latesttime = nowtime.addSecs(kSixHours);
362 bindings[
":CHANID"] = chanid;
363 bindings[
":NOWTS"] = nowtime;
364 bindings[
":LATESTTS"] = latesttime;
365 bindings[
":BROWSETS"] = browsetime;
366 bindings[
":BROWSETS2"] = browsetime;
368 QString querystr =
" WHERE program.chanid = :CHANID ";
372 querystr +=
" AND program.endtime <= :BROWSETS AND program.endtime > :NOWTS ";
375 querystr +=
" AND program.starttime > :BROWSETS AND program.starttime < :LATESTTS ";
378 querystr +=
" AND program.starttime <= :BROWSETS AND program.endtime > :BROWSETS2 ";
385 if (progList.
empty())
387 Infomap[
"dbstarttime"] =
"";
392 progList[
static_cast<uint>(progList.
size() - 1)] : progList[0];
399 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
"Helper thread starting");
412 std::vector<uint> chanids;
417 std::vector<uint> chanids_extra;
419 QMultiMap<QString,uint>::iterator it;
425 chanids.push_back(*it);
427 chanids_extra.push_back(*it);
429 chanids.insert(chanids.end(),
430 chanids_extra.begin(),
431 chanids_extra.end());
442 if (lasttime < curtime)
446 if ((lasttime > maxtime) && (direction ==
BROWSE_RIGHT))
501 if (!chanids.empty())
504 auto it = std::find_if(chanids.cbegin(), chanids.cend(), tunable);
505 if (it != chanids.cend())
507 infoMap[
"chanid"] = QString::number(*it);
513 uint orig_chanid = infoMap[
"chanid"].toUInt();
516 (infoMap[
"chanid"].toUInt() != orig_chanid))
530 !infoMap[
"dbstarttime"].isEmpty())
547 infoMap[
"channelgroup"] = QObject::tr(
"All channels");
551 recinfo.
ToMap(infoMap);
557 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
"Helper thread exiting");
static uint GetSourceID(uint inputid)
static QString GetChannelGroupName(int grpid)
static QString GetIcon(uint chanid)
static void SortChannels(ChannelInfoList &list, const QString &order, bool eliminate_duplicates=false)
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)
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
This is a wrapper around QThread that does several additional things.
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
void HideWindow(const QString &Window) override
void LockPlayingInfo(const char *file, int line) const
int m_lastCardid
CardID of current/last recorder.
RemoteEncoder * m_recorder
void UnlockPlayingInfo(const char *file, int line) const
ProgramInfo * m_playingInfo
Currently playing info.
Holds information on recordings and videos.
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
QDateTime GetScheduledStartTime(void) const
The scheduled start time of program.
QString GetChanNum(void) const
This is the channel "number", in the form 1, 1_2, 1-2, 1#1, etc.
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...
Holds information on a TV Program one might wish to record.
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...
void GetNextProgramDB(BrowseDirection Direction, InfoMap &Infomap) const
bool m_dbUseChannelGroups
void BrowseEnd(bool ChangeChannel)
Ends channel browsing.
BrowseInfo GetBrowsedInfo() const
ChannelInfoList m_dbAllChannels
QHash< uint, QString > m_dbChanidToChannum
void BrowseDispInfo(const BrowseInfo &Browseinfo)
void GetNextProgram(BrowseDirection Direction, InfoMap &Infomap) const
Fetches information on the desired program from the backend.
TVBrowseHelper(TV *Parent)
QWaitCondition m_browseWait
QString m_browseStartTime
void BrowseChannel(const QString &Channum)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
std::chrono::seconds m_dbBrowseMaxForward
~TVBrowseHelper() override
void BrowseInit(std::chrono::seconds BrowseMaxForward, bool BrowseAllTuners, bool UseChannelGroups, const QString &DBChannelOrdering)
QHash< uint, uint > m_dbChanidToSourceid
uint GetBrowseChanId(const QString &Channum, uint PrefCardid, uint PrefSourceid) const
Returns a chanid for the channum, or 0 if none is available.
QList< BrowseInfo > m_browseList
bool BrowseStart(bool SkipBrowse=false)
Begins channel browsing.
QMultiMap< QString, uint > m_dbChannumToChanids
int StartTimer(std::chrono::milliseconds Interval, int Line)
PlayerContext * GetPlayerContext()
Return a pointer to TV::m_playerContext.
void GetPlayerReadLock() const
volatile int m_channelGroupId
static bool IsTunable(uint ChanId)
QMutex m_channelGroupLock
Lock necessary when modifying channel group variables.
void ReturnPlayerLock() const
void ReturnOSDLock() const
static const std::chrono::milliseconds kBrowseTimeout
void ChangeChannel(const ChannelInfoList &Options)
ChannelInfoList m_channelGroupChannelList
static HostCheckBoxSetting * BrowseAllTuners()
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QHash< QString, QString > InfoMap
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
@ kDateFull
Default local time.
@ kTime
Default local time.
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
static constexpr const char * OSD_WIN_BROWSE
bool LoadFromProgram(ProgramList &destination, const QString &where, const QString &groupBy, const QString &orderBy, const MSqlBindings &bindings, const ProgramList &schedList)
BrowseDirection
Used to request ProgramInfo for channel browsing.
@ BROWSE_SAME
Fetch browse information on current channel and time.
@ BROWSE_RIGHT
Fetch information on current channel in the future.
@ BROWSE_LEFT
Fetch information on current channel in the past.
@ BROWSE_UP
Fetch information on previous channel.
@ BROWSE_FAVORITE
Fetch information on the next favorite channel.
@ BROWSE_DOWN
Fetch information on next channel.
ChannelChangeDirection
ChannelChangeDirection is an enumeration of possible channel changing directions.
@ CHANNEL_DIRECTION_FAVORITE
static void format_time(int seconds, QString &tMin, QString &tHrsMin)