4 #include <QCoreApplication> 15 #define LOC QString("BH: ") 17 #define GetPlayer(X,Y) GetPlayerHaveLock(X, Y, __FILE__ , __LINE__) 18 #define GetOSDLock(X) GetOSDL(X, __FILE__, __LINE__) 20 static void format_time(
int seconds, QString &tMin, QString &tHrsMin)
22 int minutes = seconds / 60;
23 int hours = minutes / 60;
24 int min = minutes % 60;
26 tMin = TV::tr(
"%n minute(s)",
"", minutes);
27 tHrsMin = QString(
"%1:%2").arg(hours).arg(min, 2, 10, QChar(
'0'));
32 uint browse_max_forward,
33 bool browse_all_tuners,
34 bool use_channel_groups,
35 const QString& db_channel_ordering) :
38 m_dbBrowseMaxForward(browse_max_forward),
39 m_dbBrowseAllTuners(browse_all_tuners),
40 m_dbUseChannelGroups(use_channel_groups)
43 0,
true,
"channum, callsign");
56 0,
true,
"channum, callsign");
71 QMutexLocker locker(&
m_lock);
110 QMutexLocker locker(&
m_lock);
112 if (ctx &&
m_ctx != ctx)
130 OSD *osd =
m_tv->GetOSDLock(ctx);
159 QMutexLocker locker(&
m_lock);
192 QMutexLocker locker(&
m_lock);
194 if (
m_ctx !=
nullptr)
211 return m_ctx !=
nullptr;
222 const QString &channum,
uint pref_cardid,
uint pref_sourceid)
const 229 if ((*it).m_sourceid == pref_sourceid && (*it).m_channum == channum)
230 return (*it).m_chanid;
239 if ((*it).GetInputIds().contains(pref_cardid) &&
240 (*it).m_channum == channum)
241 return (*it).m_chanid;
250 if ((*it).m_channum == channum)
251 return (*it).m_chanid;
279 QString starttime = infoMap[
"dbstarttime"];
280 QString chanid = infoMap[
"chanid"];
281 QString channum = infoMap[
"channum"];
282 QString seriesid = infoMap[
"seriesid"];
283 QString programid = infoMap[
"programid"];
287 title, subtitle, desc, category,
288 starttime, endtime, callsign, iconpath,
289 channum, chanid, seriesid, programid);
291 if (!starttime.isEmpty())
300 infoMap[
"endtime"] = infoMap[
"enddate"] =
"";
301 if (!endtime.isEmpty())
309 infoMap[
"lenmins"] = TV::tr(
"%n minute(s)",
"", 0);
310 infoMap[
"lentime"] =
"0:00";
311 if (begts.isValid() && endts.isValid())
316 infoMap[
"lenmins"] = lenM;
317 infoMap[
"lentime"] = lenHM;
320 infoMap[
"dbstarttime"] = starttime;
321 infoMap[
"dbendtime"] = endtime;
322 infoMap[
"title"] = title;
323 infoMap[
"subtitle"] = subtitle;
324 infoMap[
"description"] = desc;
325 infoMap[
"category"] = category;
326 infoMap[
"callsign"] = callsign;
327 infoMap[
"channum"] = channum;
328 infoMap[
"chanid"] = chanid;
329 infoMap[
"iconpath"] = iconpath;
330 infoMap[
"seriesid"] = seriesid;
331 infoMap[
"programid"] = programid;
337 uint chanid = infoMap[
"chanid"].toUInt();
340 LOG(VB_GENERAL, LOG_ERR,
LOC +
"GetNextProgramDB() requires a chanid");
361 static_cast<ChannelChangeDirection>(chandir),
365 infoMap[
"chanid"] = QString::number(chanid);
369 QDateTime latesttime = nowtime.addSecs(6*60*60);
373 bindings[
":CHANID"] = chanid;
374 bindings[
":NOWTS"] = nowtime;
375 bindings[
":LATESTTS"] = latesttime;
376 bindings[
":BROWSETS"] = browsetime;
377 bindings[
":BROWSETS2"] = browsetime;
379 QString querystr =
" WHERE program.chanid = :CHANID ";
383 querystr +=
" AND program.endtime <= :BROWSETS " 384 " AND program.endtime > :NOWTS ";
388 querystr +=
" AND program.starttime > :BROWSETS " 389 " AND program.starttime < :LATESTTS ";
393 querystr +=
" AND program.starttime <= :BROWSETS " 394 " AND program.endtime > :BROWSETS2 ";
401 if (progList.
empty())
403 infoMap[
"dbstarttime"] =
"";
408 progList[progList.
size() - 1] : progList[0];
416 QMutexLocker locker(&
m_lock);
430 vector<uint> chanids;
435 vector<uint> chanids_extra;
437 QMultiMap<QString,uint>::iterator it;
443 chanids.push_back(*it);
445 chanids_extra.push_back(*it);
447 chanids.insert(chanids.end(),
448 chanids_extra.begin(),
449 chanids_extra.end());
460 if (lasttime < curtime)
464 if ((lasttime > maxtime) && (direction ==
BROWSE_RIGHT))
508 infoMap[
"chanid"] = QString::number(
m_chanid);
511 bool still_there =
false;
522 if (!chanids.empty())
524 for (
size_t i = 0; i < chanids.size(); i++)
528 infoMap[
"chanid"] = QString::number(chanids[i]);
536 uint orig_chanid = infoMap[
"chanid"].toUInt();
539 (infoMap[
"chanid"].toUInt() != orig_chanid))
549 if (!
m_ctx && !still_there)
553 m_chanid = infoMap[
"chanid"].toUInt();
556 !infoMap[
"dbstarttime"].isEmpty())
564 QCoreApplication::postEvent(
574 infoMap[
"channelgroup"] = QObject::tr(
"All channels");
578 recinfo.
ToMap(infoMap);
584 QCoreApplication::postEvent(
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
void start(QThread::Priority=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
QHash< uint, QString > m_dbChanidToChannum
void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi)
uint m_dbBrowseMaxForward
This is a wrapper around QThread that does several additional things.
QHash< uint, uint > m_dbChanidToSourceid
Fetch browse information on current channel and time.
void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const
virtual void ToMap(InfoMap &progMap, bool showrerecord=false, uint star_range=10) const
Converts ProgramInfo into QString QHash containing each field in ProgramInfo converted into localized...
ChannelChangeDirection
ChannelChangeDirection is an enumeration of possible channel changing directions.
static bool IsTunable(uint chanid)
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...
vector< PlayerContext * > m_player
void ReturnPlayerLock(PlayerContext *&)
QHash< QString, QString > InfoMap
Fetch information on current channel in the past.
void UnlockPlayingInfo(const char *file, int line) const
void GetNextProgram(BrowseDirection direction, InfoMap &infoMap) const
Fetches information on the desired program from the backend.
Holds information on a TV Program one might wish to record.
PlayerContext * GetPlayerReadLock(int which, const char *file, int location)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
QMutex m_channelGroupLock
Lock necessary when modifying channel group variables.
Do Today/Yesterday/Tomorrow transform.
QString GetChanNum(void) const
This is the channel "number", in the form 1, 1_2, 1-2, 1#1, etc.
static void SortChannels(ChannelInfoList &list, const QString &order, bool eliminate_duplicates=false)
void ReturnOSDLock(const PlayerContext *, OSD *&)
bool IsBrowsing(void) const
QDateTime GetScheduledStartTime(void) const
The scheduled start time of program.
ChannelInfoList m_channelGroupChannelList
ProgramInfo * m_playingInfo
Currently playing info.
Holds information on recordings and videos.
bool m_dbUseChannelGroups
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
QMultiMap< QString, uint > m_dbChannumToChanids
void HideWindow(const QString &Window)
bool BrowseStart(PlayerContext *ctx, bool skip_browse=false)
Begins channel browsing.
BrowseInfo GetBrowsedInfo(void) const
static void format_time(int seconds, QString &tMin, QString &tHrsMin)
static const uint kBrowseTimeout
Timeout for browse mode exit in msec.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
void LockPlayingInfo(const char *file, int line) const
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
int m_lastCardid
CardID of current/last recorder.
static QString GetIcon(uint chanid)
void BrowseChannel(PlayerContext *ctx, const QString &channum)
static QString GetChannelGroupName(int grpid)
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
ChannelInfoList m_dbAllVisibleChannels
RemoteEncoder * m_recorder
void BrowseEnd(PlayerContext *ctx, bool change_channel)
Ends channel browsing.
volatile int m_channelGroupId
BrowseDirection
Used to request ProgramInfo for channel browsing.
Fetch information on the next favorite channel.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Fetch information on next channel.
volatile int m_browseTimerId
TVBrowseHelper(TV *tv, uint browse_max_forward, bool browse_all_tuners, bool use_channel_groups, const QString &db_channel_ordering)
bool LoadFromProgram(ProgramList &destination, const QString &where, const QString &groupBy, const QString &orderBy, const MSqlBindings &bindings, const ProgramList &schedList)
Fetch information on previous channel.
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
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.
static uint GetSourceID(uint inputid)
void ChangeChannel(const PlayerContext *, const ChannelInfoList &options)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
int StartTimer(int interval, int line)
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Fetch information on current channel in the future.
bool ClearOSD(const PlayerContext *)
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)