Ticket #8988: 8988-v1.patch

File 8988-v1.patch, 7.5 KB (added by danielk, 10 years ago)
  • programs/mythfrontend/playbackbox.cpp

     
    784784
    785785    item->DisplayState(rating, "ratingstate");
    786786
    787     QString oldimgfile = item->GetImage("preview");
     787    // If there is no preview image, load it.
     788    QString oldimgfile = GetLoadedPreview(*pginfo);
    788789    if (oldimgfile.isEmpty() || force_preview_reload)
    789790        m_preview_tokens.insert(m_helper.GetPreviewImage(*pginfo));
     791    // Try to set preview image
     792    if (oldimgfile.isEmpty())
     793        oldimgfile = GetStalePreview(*pginfo);
     794    if (item->GetImage("preview").isEmpty())
     795    {
     796        if (!oldimgfile.isEmpty())
     797            item->SetImage(oldimgfile, "preview", false);
     798    }
    790799
    791800    if ((GetFocusWidget() == m_recordingList) && is_sel)
    792801    {
     
    810819        if (m_previewImage)
    811820        {
    812821            m_previewImage->SetFilename(oldimgfile);
    813             m_previewImage->Load(true, true);
     822            m_previewImage->Load(false, false);
    814823        }
    815824
    816825        // Handle artwork
     
    849858void PlaybackBox::ItemVisible(MythUIButtonListItem *item)
    850859{
    851860    ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData());
     861    if (!pginfo)
     862        return;
    852863
    853864    // Job status (recording, transcoding, flagging)
    854865    QString job = extract_job_state(*pginfo);
    855866    item->DisplayState(job, "jobstate");
    856867
    857868    MythUIButtonListItem *sel_item = item->parent()->GetItemCurrent();
    858     if ((item != sel_item) && pginfo && item->GetImage("preview").isEmpty() &&
    859         (asAvailable == pginfo->GetAvailableStatus()))
     869    if (item == sel_item)
     870        return;
     871
     872    if ((asAvailable == pginfo->GetAvailableStatus()) &&
     873        GetLoadedPreview(*pginfo).isEmpty())
    860874    {
    861875        QString token = m_helper.GetPreviewImage(*pginfo, true);
    862         if (token.isEmpty())
    863             return;
    864 
    865         m_preview_tokens.insert(token);
    866         // now make sure selected item is still at the top of the queue
    867         ProgramInfo *sel_pginfo =
    868             qVariantValue<ProgramInfo*>(sel_item->GetData());
    869         if (sel_pginfo && sel_item->GetImage("preview").isEmpty() &&
    870             (asAvailable == sel_pginfo->GetAvailableStatus()))
     876        if (!token.isEmpty())
    871877        {
    872             m_preview_tokens.insert(
    873                 m_helper.GetPreviewImage(*sel_pginfo, false));
     878            m_preview_tokens.insert(token);
     879            // now make sure selected item is still at the top of the queue
     880            ProgramInfo *sel_pginfo =
     881                qVariantValue<ProgramInfo*>(sel_item->GetData());
     882            if (sel_pginfo && GetLoadedPreview(*sel_pginfo).isEmpty() &&
     883                (asAvailable == sel_pginfo->GetAvailableStatus()))
     884            {
     885                m_preview_tokens.insert(
     886                    m_helper.GetPreviewImage(*sel_pginfo, false));
     887            }
    874888        }
    875889    }
     890
     891    if (item->GetImage("preview").isEmpty())
     892    {
     893        QString cachedPreview = GetStalePreview(*pginfo);
     894        if (!cachedPreview.isEmpty())
     895            item->SetImage(cachedPreview, "preview", true);
     896    }
    876897}
    877898
     899/** \brief Returns a relatively up to date preview file name if available.
     900 *  This will only be returned after the preview generator hands us this
     901 *  preview file as an up to date preview file. This returns an empty string
     902 *  when not available.
     903 *  \sa GetStalePreview()
     904 */
     905QString PlaybackBox::GetLoadedPreview(const ProgramInfo &pginfo) const
     906{
     907    PreviewCache::const_iterator it =
     908        m_previewCache.find(pginfo.MakeUniqueKey());
     909    return (it == m_previewCache.end()) ? QString() :
     910        ((*it).left(6) == "cache:") ? QString() : *it;
     911}
    878912
     913/** \brief Returns the most up to date preview we have in local storage.
     914 *  This image may be quite stale, as another frontent may have changed
     915 *  the file or the bookmarks since the last time it was shown on screen
     916 *  on this frontend. This is meant as a temporary placeholder image.
     917 *  \sa GetLoadedPreview()
     918 */
     919QString PlaybackBox::GetStalePreview(const ProgramInfo &pginfo) const
     920{
     921    QString key = pginfo.MakeUniqueKey();
     922    PreviewCache::const_iterator it = m_previewCache.find(key);
     923    QString ret;
     924    if (it != m_previewCache.end())
     925        ret = ((*it).left(6) == "cache:") ? (*it).mid(6) : *it;
     926    if (ret.left(12) == "<NOT_CACHED>")
     927        return QString();
     928    else if (ret.length())
     929    {
     930        VERBOSE(VB_IMPORTANT, QString("GetStalePreview() 1 -> '%1'")
     931                .arg(ret));
     932        return ret;
     933    }
     934
     935    QString preview;
     936    QString remotecachedirname = QString("%1/remotecache").arg(GetConfDir());
     937    QDir remotecachedir(remotecachedirname);
     938    if (remotecachedir.exists())
     939    {
     940        QString filename = QString("%1/%2")
     941            .arg(remotecachedirname)
     942            .arg(pginfo.GetBasename() + ".png");
     943        if (QFileInfo(filename).isReadable())
     944            preview = filename;
     945    }
     946
     947    ret = m_previewCache[key] = QString("cache:") +
     948        ((preview.isEmpty()) ? QString("<NOT_CACHED>") : preview);
     949    ret = (ret.left(6) == "cache:") ? (ret).mid(6) : ret;
     950
     951    if (ret.left(12) != "<NOT_CACHED>")
     952        VERBOSE(VB_IMPORTANT, QString("GetStalePreview() 2 -> '%1'")
     953                .arg(ret));
     954
     955    return (ret.left(12) == "<NOT_CACHED>") ? QString() : ret;
     956}
     957
    879958/** \brief Updates the UI properties for a new preview file.
    880959 *  This first update the image property of the MythUIButtonListItem
    881960 *  with the new preview file, then if it is selected and there is
     
    9461025                QString("Loading preview %1,\n\t\t\tmsg %2")
    9471026                .arg(previewFile).arg(message));
    9481027
     1028        m_previewCache[info->MakeUniqueKey()] = previewFile;
     1029
    9491030        item->SetImage(previewFile, "preview", true);
    9501031
    9511032        if ((GetFocusWidget() == m_recordingList) &&
  • programs/mythfrontend/playbackboxhelper.cpp

     
    602602QString PlaybackBoxHelper::GetPreviewImage(
    603603    const ProgramInfo &pginfo, bool check_availability)
    604604{
     605    VERBOSE(VB_IMPORTANT, QString("GetPreviewImage(%1)")
     606            .arg(pginfo.GetBasename()));
     607
    605608    if (!check_availability && pginfo.GetAvailableStatus() != asAvailable)
    606609        return QString();
    607610
  • programs/mythfrontend/playbackbox.h

     
    4545class MythDialogBox;
    4646
    4747typedef QMap<QString,ProgramList>       ProgramMap;
     48typedef QMap<QString,QString>           PreviewCache;
    4849typedef QMap<QString,QString>           Str2StrMap;
    4950
    5051enum {
     
    327328
    328329    QString CreateProgramInfoString(const ProgramInfo &program) const;
    329330
     331    QString GetLoadedPreview(const ProgramInfo &pginfo) const;
     332    QString GetStalePreview(const ProgramInfo &pginfo) const;
     333
    330334  private:
    331335    QRegExp m_prefixes;   ///< prefixes to be ignored when sorting
    332336    QRegExp m_titleChaff; ///< stuff to remove for search rules
     
    398402    // Main Recording List support
    399403    QStringList         m_titleList;  ///< list of pages
    400404    ProgramMap          m_progLists;  ///< lists of programs by page
     405    mutable PreviewCache m_previewCache;
    401406    int                 m_progsInDB;  ///< total number of recordings in DB
    402407    bool                m_isFilling;
    403408