Ticket #8962: 8962_v1.patch

File 8962_v1.patch, 5.3 KB (added by Jim Stichnoth, 4 years ago)
  • mythtv/programs/mythfrontend/playbackbox.cpp

    diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp
    index 360d457..49f617d 100644
    a b static QString extract_main_state(const ProgramInfo &pginfo, const TV *player) 
    288288    return state;
    289289}
    290290
    291 static QString extract_job_state(const ProgramInfo &pginfo)
     291QString PlaybackBox::extract_job_state(const ProgramInfo &pginfo)
    292292{
    293293    QString job = "default";
    294294
    295295    if (pginfo.GetRecordingStatus() == RecStatus::Recording ||
    296296        pginfo.GetRecordingStatus() == RecStatus::Failing)
    297297        job = "recording";
    298     else if (JobQueue::IsJobQueuedOrRunning(
     298    else if (m_jobQueue.IsJobQueuedOrRunning(
    299299                 JOB_TRANSCODE, pginfo.GetChanID(),
    300300                 pginfo.GetRecordingStartTime()))
    301301        job = "transcoding";
    302     else if (JobQueue::IsJobQueuedOrRunning(
     302    else if (m_jobQueue.IsJobQueuedOrRunning(
    303303                 JOB_COMMFLAG,  pginfo.GetChanID(),
    304304                 pginfo.GetRecordingStartTime()))
    305305        job = "commflagging";
    static QString extract_job_state(const ProgramInfo &pginfo) 
    307307    return job;
    308308}
    309309
    310 static QString extract_commflag_state(const ProgramInfo &pginfo)
     310QString PlaybackBox::extract_commflag_state(const ProgramInfo &pginfo)
    311311{
    312312    QString job = "default";
    313313
    314314    // commflagged can be yes, no or processing
    315     if (JobQueue::IsJobRunning(JOB_COMMFLAG, pginfo))
     315    if (m_jobQueue.IsJobRunning(JOB_COMMFLAG, pginfo.GetChanID(),
     316                                pginfo.GetRecordingStartTime()))
    316317        return "running";
    317     if (JobQueue::IsJobQueued(JOB_COMMFLAG, pginfo.GetChanID(),
    318                               pginfo.GetRecordingStartTime()))
     318    if (m_jobQueue.IsJobQueued(JOB_COMMFLAG, pginfo.GetChanID(),
     319                               pginfo.GetRecordingStartTime()))
    319320        return "queued";
    320321
    321322    return ((pginfo.GetProgramFlags() & FL_COMMFLAG) ? "yes" : "no");
    void HelpPopup::addItem(const QString &state, const QString &text) 
    55445545    item->DisplayState(state, "icons");
    55455546}
    55465547
     5548void PlaybackBox::PbbJobQueue::Update()
     5549{
     5550    QDateTime now = QDateTime::currentDateTime();
     5551    if (!m_lastUpdated.isValid() ||
     5552        m_lastUpdated.msecsTo(now) >= kInvalidateTimeMs)
     5553    {
     5554        JobQueue::GetJobsInQueue(m_jobs, JOB_LIST_ALL);
     5555        m_lastUpdated = now;
     5556    }
     5557}
     5558
     5559bool PlaybackBox::PbbJobQueue::IsJobQueued(int jobType, uint chanid,
     5560                                           const QDateTime &recstartts)
     5561{
     5562    Update();
     5563    for (int i = 0; i < m_jobs.size(); ++i)
     5564    {
     5565        const JobQueueEntry &entry = m_jobs[i];
     5566        if (entry.type == jobType && entry.chanid == chanid &&
     5567            entry.recstartts == recstartts)
     5568        {
     5569            return entry.status & JOB_QUEUED;
     5570        }
     5571    }
     5572    return false;
     5573}
     5574
     5575bool PlaybackBox::PbbJobQueue::IsJobRunning(int jobType, uint chanid,
     5576                                            const QDateTime &recstartts)
     5577{
     5578    Update();
     5579    for (int i = 0; i < m_jobs.size(); ++i)
     5580    {
     5581        const JobQueueEntry &entry = m_jobs[i];
     5582        if (entry.type == jobType && entry.chanid == chanid &&
     5583            entry.recstartts == recstartts)
     5584        {
     5585            return entry.status & JOB_QUEUED;
     5586        }
     5587    }
     5588    return false;
     5589}
     5590
     5591bool PlaybackBox::PbbJobQueue::IsJobQueuedOrRunning(int jobType, uint chanid,
     5592                                                    const QDateTime &recstartts)
     5593{
     5594    return IsJobQueued(jobType, chanid, recstartts) ||
     5595        IsJobRunning(jobType, chanid, recstartts);
     5596}
     5597
    55475598/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythtv/programs/mythfrontend/playbackbox.h

    diff --git a/mythtv/programs/mythfrontend/playbackbox.h b/mythtv/programs/mythfrontend/playbackbox.h
    index 44a41e2..efed460 100644
    a b class PlaybackBox : public ScheduleCommon 
    333333
    334334    QString CreateProgramInfoString(const ProgramInfo &program) const;
    335335
     336    QString extract_job_state(const ProgramInfo &pginfo);
     337    QString extract_commflag_state(const ProgramInfo &pginfo);
     338
    336339
    337340    QRegExp m_prefixes;   ///< prefixes to be ignored when sorting
    338341    QRegExp m_titleChaff; ///< stuff to remove for search rules
    class PlaybackBox : public ScheduleCommon 
    442445    bool                m_usingGroupSelector;
    443446    bool                m_groupSelected;
    444447    bool                m_passwordEntered;
     448
     449    // This class caches the contents of the jobqueue table to avoid excessive
     450    // DB queries each time the PBB selection changes (currently 4 queries per
     451    // displayed item).  The cache remains valid for at most 5 seconds
     452    // (kInvalidateTimeMs).
     453    class PbbJobQueue
     454    {
     455    public:
     456        PbbJobQueue() {}
     457        bool IsJobQueued(int jobType, uint chanid,
     458                         const QDateTime &recstartts);
     459        bool IsJobRunning(int jobType, uint chanid,
     460                          const QDateTime &recstartts);
     461        bool IsJobQueuedOrRunning(int jobType, uint chanid,
     462                                  const QDateTime &recstartts);
     463    private:
     464        static const qint64 kInvalidateTimeMs = 5000;
     465        void Update();
     466        QDateTime m_lastUpdated;
     467        QMap<int, JobQueueEntry> m_jobs;
     468    } m_jobQueue;
    445469};
    446470
    447471class GroupSelector : public MythScreenType