All pastes #1718735 Raw Edit

Miscellany

public text v1 · immutable
#1718735 ·published 2009-12-17 21:33 UTC
rendered paste body
Index: libs/libmyth/remoteutil.cpp
===================================================================
--- libs/libmyth/remoteutil.cpp	(revision 22974)
+++ libs/libmyth/remoteutil.cpp	(working copy)
@@ -258,6 +258,12 @@
 
 void RemoteSendMessage(const QString &message)
 {
+    if (gContext->IsBackend())
+    {
+        gContext->dispatch(MythEvent(message));
+        return;
+    }
+
     QStringList strlist( "MESSAGE" );
     strlist << message;
 
Index: libs/libmyth/programinfo.cpp
===================================================================
--- libs/libmyth/programinfo.cpp	(revision 22974)
+++ libs/libmyth/programinfo.cpp	(working copy)
@@ -1770,17 +1770,21 @@
     filesize = fsize;
 
     MSqlQuery query(MSqlQuery::InitCon());
-    query.prepare("UPDATE recorded SET filesize = :FILESIZE"
-                  " WHERE chanid = :CHANID"
-                  " AND starttime = :STARTTIME ;");
-    query.bindValue(":FILESIZE", longLongToString(fsize));
-    query.bindValue(":CHANID", chanid);
+    query.prepare(
+        "UPDATE recorded "
+        "SET filesize = :FILESIZE "
+        "WHERE chanid    = :CHANID AND "
+        "      starttime = :STARTTIME");
+    query.bindValue(":FILESIZE",  fsize);
+    query.bindValue(":CHANID",    chanid);
     query.bindValue(":STARTTIME", recstartts);
 
-    if (!query.exec() || !query.isActive())
+    if (!query.exec())
         MythDB::DBError("File size update", query);
 
-    SendUpdateEvent();
+    QString msg = QString("UPDATE_FILE_SIZE %1 %2 %3")
+        .arg(chanid).arg(recstartts.toString(Qt::ISODate)).arg(fsize);
+    RemoteSendMessage(msg);
 }
 
 /** \fn ProgramInfo::GetFilesize(void)
@@ -1880,7 +1884,7 @@
         // table send an update event..
         QStringList list;
         ToStringList(list);
-        RemoteSendEvent(MythEvent(QString("UPDATE_PROG_INFO"), list));
+        RemoteSendEvent(MythEvent(QString("MASTER_UPDATE_PROG_INFO"), list));
     }
 }
 
Index: programs/mythfrontend/playbackbox.cpp
===================================================================
--- programs/mythfrontend/playbackbox.cpp	(revision 22974)
+++ programs/mythfrontend/playbackbox.cpp	(working copy)
@@ -628,7 +628,30 @@
     updateIcons();
 }
 
-void PlaybackBox::UpdateProgramInfo(
+void PlaybackBox::UpdateUIListItem(ProgramInfo *pginfo)
+{
+    if (!pginfo)
+        return;
+
+    MythUIButtonListItem *item =
+        m_recordingList->GetItemByData(qVariantFromValue(pginfo));
+
+    if (item)
+    {
+        MythUIButtonListItem *sel_item =
+            m_recordingList->GetItemCurrent();
+        UpdateUIListItem(item, item == sel_item, true);
+    }
+    else
+    {
+        VERBOSE(VB_GENERAL, LOC +
+                QString("UpdateUIListItem called with a title unknown "
+                        "to us in m_recordingList\n %1:%2")
+                .arg(pginfo->title).arg(pginfo->subtitle));
+    }
+}
+
+void PlaybackBox::UpdateUIListItem(
     MythUIButtonListItem *item, bool is_sel, bool force_preview_reload)
 {
     if (!item)
@@ -652,6 +675,8 @@
 
     item->DisplayState(job, "jobstate");
 
+    VERBOSE(VB_IMPORTANT, QString("jobstate: %1").arg(job));
+
     QString rating = QString::number((int)((pginfo->stars * 10.0) + 0.5));
 
     item->DisplayState(rating, "ratingstate");
@@ -1666,7 +1691,7 @@
 
         it = randomList.begin() + i;
 
-        tmpItem = findMatchingProg(*it);
+        tmpItem = FindProgramInUILists(*it);
 
         if ((tmpItem->availableStatus == asAvailable) ||
             (tmpItem->availableStatus == asNotYetAvailable))
@@ -1970,8 +1995,11 @@
 bool PlaybackBox::doRemove(ProgramInfo *rec, bool forgetHistory,
                            bool forceMetadataDelete)
 {
-    ProgramInfo *delItem = findMatchingProg(rec);
+    if (!rec)
+        return false;
 
+    ProgramInfo *delItem = FindProgramInUILists(*rec);
+
     if (!delItem)
         return false;
 
@@ -2442,7 +2470,7 @@
 
     for(it = m_playList.begin(); it != m_playList.end(); ++it)
     {
-        tmpItem = findMatchingProg(*it);
+        tmpItem = FindProgramInUILists(*it);
         if (tmpItem)
         {
             if (!JobQueue::IsJobQueuedOrRunning(JOB_TRANSCODE,
@@ -2904,7 +2932,7 @@
     QStringList::Iterator it;
     for (it = m_playList.begin(); it != m_playList.end(); ++it)
     {
-        ProgramInfo *tmpItem = findMatchingProg(*it);
+        ProgramInfo *tmpItem = FindProgramInUILists(*it);
 
         if (!tmpItem)
             continue;
@@ -3003,7 +3031,7 @@
     if (!pginfo)
         return;
 
-    ProgramInfo *tmpItem = findMatchingProg(pginfo);
+    ProgramInfo *tmpItem = FindProgramInUILists(*pginfo);
 
     if (JobQueue::IsJobQueuedOrRunning(jobType, pginfo->chanid,
                                pginfo->recstartts))
@@ -3042,7 +3070,7 @@
     for (it = m_playList.begin(); it != m_playList.end(); ++it)
     {
         jobID = 0;
-        tmpItem = findMatchingProg(*it);
+        tmpItem = FindProgramInUILists(*it);
         if (tmpItem &&
             (!JobQueue::IsJobQueuedOrRunning(jobType, tmpItem->chanid,
                                     tmpItem->recstartts)))
@@ -3066,7 +3094,7 @@
     for (it = m_playList.begin(); it != m_playList.end(); ++it)
     {
         jobID = 0;
-        tmpItem = findMatchingProg(*it);
+        tmpItem = FindProgramInUILists(*it);
         if (tmpItem &&
             (JobQueue::IsJobQueuedOrRunning(jobType, tmpItem->chanid,
                                 tmpItem->recstartts)))
@@ -3112,7 +3140,7 @@
 
     for (it = m_playList.begin(); it != m_playList.end(); ++it )
     {
-        tmpItem = findMatchingProg(*it);
+        tmpItem = FindProgramInUILists(*it);
         if (tmpItem && (REC_CAN_BE_DELETED(tmpItem)))
             RemoteDeleteRecording(tmpItem, forgetHistory, false);
     }
@@ -3147,15 +3175,43 @@
     doRemove(m_delItem, true, false);
 }
 
-ProgramInfo *PlaybackBox::findMatchingProg(const ProgramInfo *pginfo)
+ProgramInfo *PlaybackBox::FindProgramInUILists(const ProgramInfo &pginfo)
 {
+    return FindProgramInUILists(
+        pginfo.chanid.toUInt(), pginfo.recstartts, pginfo.recgroup);
+}
+
+/// Extracts chanid and recstartts from a string constructed by
+/// ProgramInfo::MakeUniqueKey() returns the matching program info
+/// from the UI program info lists.
+ProgramInfo *PlaybackBox::FindProgramInUILists(const QString &key)
+{
+    if (!key.isEmpty())
+    {
+        QStringList keyParts = key.split('_');
+        if (keyParts.size() == 2)
+        {
+            uint      chanid     = keyParts[0].toUInt();
+            QDateTime recstartts = QDateTime::fromString(keyParts[1]);
+            if (chanid && recstartts.isValid())
+                return FindProgramInUILists(chanid, recstartts);
+        }
+    }
+
+    return NULL;
+}
+
+ProgramInfo *PlaybackBox::FindProgramInUILists(
+    uint chanid, const QDateTime &recstartts,
+    QString recgroup)
+{
     // LiveTV ProgramInfo's are not in the aggregated list
     ProgramList::iterator _it[2] = {
         m_progLists[tr("LiveTV").toLower()].begin(), m_progLists[""].begin() };
     ProgramList::iterator _end[2] = {
         m_progLists[tr("LiveTV").toLower()].end(),   m_progLists[""].end()   };
 
-    if (pginfo->recgroup != "LiveTV")
+    if (recgroup != "LiveTV")
     {
         swap( _it[0],  _it[1]);
         swap(_end[0], _end[1]);
@@ -3166,8 +3222,8 @@
         ProgramList::iterator it = _it[i], end = _end[i];
         for (; it != end; ++it)
         {
-            if ((*it)->recstartts == pginfo->recstartts &&
-                (*it)->chanid == pginfo->chanid)
+            if ((*it)->recstartts      == recstartts &&
+                (*it)->chanid.toUInt() == chanid)
             {
                 return *it;
             }
@@ -3223,52 +3279,44 @@
     }
 }
 
-ProgramInfo *PlaybackBox::findMatchingProg(const QString &key)
+void PlaybackBox::UpdateProgramInfo(
+    uint chanid, const QDateTime &recstartts, long long filesize)
 {
-    QStringList keyParts;
+    // LiveTV ProgramInfo's are not in the aggregated list
+    ProgramList::iterator _it[2] = {
+        m_progLists[tr("LiveTV").toLower()].begin(), m_progLists[""].begin() };
+    ProgramList::iterator _end[2] = {
+        m_progLists[tr("LiveTV").toLower()].end(),   m_progLists[""].end()   };
 
-    if ((key.isEmpty()) || (key.indexOf('_') < 0))
-        return NULL;
-
-    keyParts = key.split('_');
-
-    // ProgramInfo::MakeUniqueKey() has 2 parts separated by '_' characters
-    if (keyParts.size() == 2)
-        return findMatchingProg(keyParts[0], keyParts[1]);
-    else
-        return NULL;
-}
-
-ProgramInfo *PlaybackBox::findMatchingProg(const QString &chanid,
-                                           const QString &recstartts)
-{
-    ProgramList::iterator it = m_progLists[""].begin();
-    ProgramList::iterator end = m_progLists[""].end();
-    for (; it != end; ++it)
+    for (uint i = 0; i < 2; i++)
     {
-        if ((*it)->recstartts.toString(Qt::ISODate) == recstartts &&
-            (*it)->chanid == chanid)
+        ProgramList::iterator it = _it[i], end = _end[i];
+        for (; it != end; ++it)
         {
-            return *it;
+            if (chanid     == (*it)->chanid.toUInt() &&
+                recstartts == (*it)->recstartts)
+            {
+                (*it)->filesize = filesize;
+                break;
+            }
         }
     }
 
-    // LiveTV ProgramInfo's are not in the aggregated list
-    if (m_progLists.contains(tr("LiveTV").toLower()))
+    // now do the cache..
+    QMutexLocker locker(&m_progCacheLock);
+    if (m_progCache)
     {
-        it  = m_progLists[tr("LiveTV").toLower()].begin();
-        end = m_progLists[tr("LiveTV").toLower()].end();
-        for (; it != end; ++it)
+        vector<ProgramInfo *>::iterator it = m_progCache->begin();
+        for ( ; it != m_progCache->end(); ++it)
         {
-            if ((*it)->recstartts.toString(Qt::ISODate) == recstartts &&
-                (*it)->chanid == chanid)
+            if ((chanid     == (*it)->chanid.toUInt()) &&
+                (recstartts == (*it)->recstartts))
             {
-                return *it;
+                (*it)->filesize = filesize;
+                break;
             }
         }
     }
-
-    return NULL;
 }
 
 void PlaybackBox::toggleWatched(void)
@@ -3726,8 +3774,32 @@
         {
             ProgramInfo evinfo;
             if (evinfo.FromStringList(me->ExtraDataList(), 0))
+            {
+                VERBOSE(VB_IMPORTANT, QString("recstatus: %1:%2")
+                        .arg(evinfo.recstatus)
+                        .arg(evinfo.RecStatusChar()));
                 HandleUpdateProgramInfoEvent(evinfo);
+            }
         }
+        else if (message.left(17) == "UPDATE_FILE_SIZE")
+        {
+            QStringList tokens = message.simplified().split(" ");
+            bool ok = false;
+            uint chanid = 0;
+            QDateTime recstartts;
+            long long filesize = 0;
+            if (tokens.size() >= 4)
+            {
+                chanid     = tokens[1].toUInt();
+                recstartts = QDateTime::fromString(tokens[2]);
+                filesize   = tokens[3].toLongLong(&ok);
+            }
+            if (chanid && recstartts.isValid() && ok)
+            {
+                HandleUpdateProgramInfoFileSizeEvent(
+                    chanid, recstartts, filesize);
+            }
+        }
         else if (message == "RECONNECT_SUCCESS")
         {
             m_fillListFromCache = false;
@@ -3810,7 +3882,7 @@
 
 void PlaybackBox::HandleUpdateProgramInfoEvent(const ProgramInfo &evinfo)
 {
-    ProgramInfo *dst = findMatchingProg(&evinfo);
+    ProgramInfo *dst = FindProgramInUILists(evinfo);
     QString old_recgroup;
     if (dst)
         old_recgroup = dst->recgroup;
@@ -3837,22 +3909,17 @@
         return;
     }
 
-    MythUIButtonListItem *item =
-        m_recordingList->GetItemByData(qVariantFromValue(dst));
+    UpdateUIListItem(dst);
+}
 
-    if (item)
-    {
-        MythUIButtonListItem *sel_item =
-            m_recordingList->GetItemCurrent();
-        UpdateProgramInfo(item, item == sel_item, true);
-    }
-    else
-    {
-        VERBOSE(VB_GENERAL, LOC +
-                QString("Got UPDATE_PROG_INFO event about a title unknown "
-                        "to us only in m_recordingList\n %1:%2")
-                .arg(evinfo.title).arg(evinfo.subtitle));
-    }
+void PlaybackBox::HandleUpdateProgramInfoFileSizeEvent(
+    uint chanid, const QDateTime &recstartts, const long long filesize)
+{
+    UpdateProgramInfo(chanid, recstartts, filesize);
+
+    ProgramInfo *dst = FindProgramInUILists(chanid, recstartts);
+    if (dst)
+        UpdateUIListItem(dst);
 }
 
 void PlaybackBox::ScheduleFillList(void)
@@ -4032,7 +4099,7 @@
 
 void PlaybackBox::HandlePreviewEvent(const ProgramInfo &evinfo)
 {
-    ProgramInfo *info = findMatchingProg(&evinfo);
+    ProgramInfo *info = FindProgramInUILists(evinfo);
 
     if (!info)
         return;
@@ -4044,7 +4111,7 @@
         return;
 
     MythUIButtonListItem *sel_item = m_recordingList->GetItemCurrent();
-    UpdateProgramInfo(item, item == sel_item, true);
+    UpdateUIListItem(item, item == sel_item, true);
 }
 
 QString PlaybackBox::GetPreviewImage(ProgramInfo *pginfo)
@@ -4525,7 +4592,7 @@
 
     for (it = m_playList.begin(); it != m_playList.end(); ++it)
     {
-        if ((tmpItem = findMatchingProg(*it)))
+        if ((tmpItem = FindProgramInUILists(*it)))
         {
             tmpItem->SetAutoExpire(turnOn, true);
         }
@@ -4579,7 +4646,7 @@
         item->SetText(newTitle, "title");
         item->SetText(newSubtitle, "subtitle");
 
-        UpdateProgramInfo(item, true);
+        UpdateUIListItem(item, true);
     }
     else
         m_recordingList->RemoveItem(item);
@@ -4620,7 +4687,7 @@
 
         for (it = m_playList.begin(); it != m_playList.end(); ++it )
         {
-            tmpItem = findMatchingProg(*it);
+            tmpItem = FindProgramInUILists(*it);
             if (tmpItem)
             {
                 if ((tmpItem->recgroup == "LiveTV") && (newRecGroup != "LiveTV"))
@@ -4670,7 +4737,7 @@
 
         for (it = m_playList.begin(); it != m_playList.end(); ++it )
         {
-            tmpItem = findMatchingProg(*it);
+            tmpItem = FindProgramInUILists(*it);
             if (tmpItem)
             {
                 RecordingInfo ri(*tmpItem);
Index: programs/mythfrontend/playbackboxlistitem.cpp
===================================================================
--- programs/mythfrontend/playbackboxlistitem.cpp	(revision 22974)
+++ programs/mythfrontend/playbackboxlistitem.cpp	(working copy)
@@ -15,7 +15,7 @@
 {
     if (needs_update)
     {
-        pbbox->UpdateProgramInfo(this, selected);
+        pbbox->UpdateUIListItem(this, selected);
         needs_update = false;
     }
     MythUIButtonListItem::SetToRealButton(button, selected);
Index: programs/mythfrontend/playbackbox.h
===================================================================
--- programs/mythfrontend/playbackbox.h	(revision 22974)
+++ programs/mythfrontend/playbackbox.h	(working copy)
@@ -133,7 +133,7 @@
   protected slots:
     void updateRecList(MythUIButtonListItem *);
     void ItemSelected(MythUIButtonListItem *item)
-        { UpdateProgramInfo(item, true); }
+        { UpdateUIListItem(item, true); }
     void selected(MythUIButtonListItem *item);
     void playSelected(MythUIButtonListItem *item = NULL);
     void deleteSelected(MythUIButtonListItem *item);
@@ -293,10 +293,11 @@
     void processNetworkControlCommands(void);
     void processNetworkControlCommand(const QString &command);
 
-    ProgramInfo *findMatchingProg(const ProgramInfo *);
-    ProgramInfo *findMatchingProg(const QString &key);
-    ProgramInfo *findMatchingProg(const QString &chanid,
-                                  const QString &recstartts);
+    ProgramInfo *FindProgramInUILists(const ProgramInfo&);
+    ProgramInfo *FindProgramInUILists(const QString &key);
+    ProgramInfo *FindProgramInUILists(
+        uint chanid, const QDateTime &recstartts,
+        QString recgroup = "NotLiveTV");
 
     bool doRemove(ProgramInfo *, bool forgetHistory, bool forceMetadataDelete);
     void showDeletePopup(deletePopupType);
@@ -321,15 +322,22 @@
     void updateUsage();
     void updateGroupInfo(const QString &groupname, const QString &grouplabel);
     void UpdateProgramInfo(const ProgramInfo &pginfo);
-    void UpdateProgramInfo(MythUIButtonListItem *item, bool is_sel,
-                           bool force_preview_reload = false);
+    void UpdateProgramInfo(
+        uint chanid, const QDateTime &recstartts, long long filesize);
 
+    void UpdateUIListItem(
+        ProgramInfo *ProgramInfo_pointer_from_FindProgramInUILists);
+    void UpdateUIListItem(MythUIButtonListItem *item, bool is_sel,
+                          bool force_preview_reload = false);
+
     void clearProgramCache(void);
 
     void HandlePreviewEvent(const ProgramInfo &evinfo);
     void HandleRecordingRemoveEvent(uint chanid, const QDateTime &recstartts);
     void HandleRecordingAddEvent(const ProgramInfo &evinfo);
     void HandleUpdateProgramInfoEvent(const ProgramInfo &evinfo);
+    void HandleUpdateProgramInfoFileSizeEvent(
+        uint chanid, const QDateTime &recstartts,  long long filesize);
     void ScheduleFillList(void);
 
     void ShowMenu(void);
Index: programs/mythbackend/scheduler.h
===================================================================
--- programs/mythbackend/scheduler.h	(revision 22974)
+++ programs/mythbackend/scheduler.h	(working copy)
@@ -80,6 +80,8 @@
 
     bool WasStartedAutomatically();
 
+    RecStatusType GetRecStatus(const ProgramInfo &pginfo) const;
+
     int GetError(void) const { return error; }
 
   protected:
Index: programs/mythbackend/mainserver.cpp
===================================================================
--- programs/mythbackend/mainserver.cpp	(revision 22974)
+++ programs/mythbackend/mainserver.cpp	(working copy)
@@ -874,6 +874,37 @@
         if (me->Message().left(6) == "LOCAL_")
             return;
 
+        MythEvent mod_me("");
+        if (me->Message() == "MASTER_UPDATE_PROG_INFO" && m_sched)
+        {
+            ProgramInfo evinfo;
+            if (evinfo.FromStringList(me->ExtraDataList(), 0))
+            {
+                QDateTime rectime = QDateTime::currentDateTime().addSecs(
+                    -gContext->GetNumSetting("RecordOverTime"));
+
+                VERBOSE(VB_IMPORTANT, QString("recstatus for %1:%2 was: %3:%4")
+                        .arg(evinfo.title).arg(evinfo.subtitle)
+                        .arg(evinfo.recstatus)
+                        .arg(evinfo.RecStatusChar()));
+                if (evinfo.recendts > rectime)
+                    evinfo.recstatus = m_sched->GetRecStatus(evinfo);
+                VERBOSE(VB_IMPORTANT, QString("recstatus for %1:%2 now: %3:%4")
+                        .arg(evinfo.title).arg(evinfo.subtitle)
+                        .arg(evinfo.recstatus)
+                        .arg(evinfo.RecStatusChar()));
+
+                QStringList list;
+                evinfo.ToStringList(list);
+                mod_me = MythEvent("UPDATE_PROG_INFO", list);
+                me = &mod_me;
+            }
+            else
+            {
+                return;
+            }
+        }
+
         broadcast = QStringList( "BACKEND_MESSAGE" );
         broadcast << me->Message();
         broadcast += me->ExtraDataList();
Index: programs/mythbackend/scheduler.cpp
===================================================================
--- programs/mythbackend/scheduler.cpp	(revision 22974)
+++ programs/mythbackend/scheduler.cpp	(working copy)
@@ -1409,6 +1409,20 @@
     return hasconflicts;
 }
 
+RecStatusType Scheduler::GetRecStatus(const ProgramInfo &pginfo) const
+{
+    QMutexLocker lockit(reclist_lock);
+
+    for (RecConstIter it = reclist.begin(); it != reclist.end(); ++it)
+    {
+        const ProgramInfo &s = **it;
+        if (pginfo.chanid == s.chanid && pginfo.recstartts == s.recstartts)
+            return (rsRecording==s.recstatus) ? rsRecording : pginfo.recstatus;
+    }
+
+    return pginfo.recstatus;
+}
+
 void Scheduler::getAllPending(QStringList &strList)
 {
     RecList retlist;