Ticket #10161: lazystrings_v11.patch

File lazystrings_v11.patch, 11.5 KB (added by stichnot, 15 months ago)

Use the PlaybackBox? helper thread to initialize the button list items in the background.

  • mythtv/programs/mythfrontend/playbackbox.cpp

    diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp
    index 2e65654..e2e4b19 100644
    a b void PlaybackBox::UpdateUIListItem(MythUIButtonListItem *item, 
    890890    } 
    891891} 
    892892 
     893void PlaybackBox::ItemVisibleCore(MythUIButtonListItem *item) 
     894{ 
     895    ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData()); 
     896    if (item->GetText("is_item_initialized").isNull()) 
     897    { 
     898        QMap<AudioProps, QString> audioFlags; 
     899        audioFlags[AUD_DOLBY] = "dolby"; 
     900        audioFlags[AUD_SURROUND] = "surround"; 
     901        audioFlags[AUD_STEREO] = "stereo"; 
     902        audioFlags[AUD_MONO] = "mono"; 
     903 
     904        QMap<VideoProps, QString> videoFlags; 
     905        videoFlags[VID_1080] = "hd1080"; 
     906        videoFlags[VID_720] = "hd720"; 
     907        videoFlags[VID_HDTV] = "hdtv"; 
     908        videoFlags[VID_WIDESCREEN] = "widescreen"; 
     909 
     910        QMap<SubtitleTypes, QString> subtitleFlags; 
     911        subtitleFlags[SUB_SIGNED] = "deafsigned"; 
     912        subtitleFlags[SUB_ONSCREEN] = "onscreensub"; 
     913        subtitleFlags[SUB_NORMAL] = "subtitles"; 
     914        subtitleFlags[SUB_HARDHEAR] = "cc"; 
     915 
     916        QString groupname = m_groupList->GetItemCurrent()->GetData().toString(); 
     917 
     918        QString state = extract_main_state(*pginfo, m_player); 
     919 
     920        item->SetFontState(state); 
     921 
     922        InfoMap infoMap; 
     923        pginfo->ToMap(infoMap); 
     924        item->SetTextFromMap(infoMap); 
     925 
     926        QString tempSubTitle  = extract_subtitle(*pginfo, groupname); 
     927 
     928        if (groupname == pginfo->GetTitle().toLower()) 
     929            item->SetText(tempSubTitle, "titlesubtitle"); 
     930 
     931        item->DisplayState(state, "status"); 
     932 
     933        item->DisplayState(QString::number(pginfo->GetStars(10)), "ratingstate"); 
     934 
     935        SetItemIcons(item, pginfo); 
     936 
     937        QMap<AudioProps, QString>::iterator ait; 
     938        for (ait = audioFlags.begin(); ait != audioFlags.end(); ++ait) 
     939        { 
     940            if (pginfo->GetAudioProperties() & ait.key()) 
     941                item->DisplayState(ait.value(), "audioprops"); 
     942        } 
     943 
     944        QMap<VideoProps, QString>::iterator vit; 
     945        for (vit = videoFlags.begin(); vit != videoFlags.end(); ++vit) 
     946        { 
     947            if (pginfo->GetVideoProperties() & vit.key()) 
     948                item->DisplayState(vit.value(), "videoprops"); 
     949        } 
     950 
     951        QMap<SubtitleTypes, QString>::iterator sit; 
     952        for (sit = subtitleFlags.begin(); sit != subtitleFlags.end(); ++sit) 
     953        { 
     954            if (pginfo->GetSubtitleType() & sit.key()) 
     955                item->DisplayState(sit.value(), "subtitletypes"); 
     956        } 
     957 
     958        item->DisplayState(pginfo->GetCategoryType(), "categorytype"); 
     959 
     960        // Mark this button list item as initialized. 
     961        item->SetText("yes", "is_item_initialized"); 
     962    } 
     963 
     964} 
     965 
    893966void PlaybackBox::ItemVisible(MythUIButtonListItem *item) 
    894967{ 
    895968    ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData()); 
    896969 
     970    ItemVisibleCore(item); 
    897971    // Job status (recording, transcoding, flagging) 
    898972    QString job = extract_job_state(*pginfo); 
    899973    item->DisplayState(job, "jobstate"); 
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    13161390 
    13171391    ProgramList &progList = *pmit; 
    13181392 
    1319     QMap<AudioProps, QString> audioFlags; 
    1320     audioFlags[AUD_DOLBY] = "dolby"; 
    1321     audioFlags[AUD_SURROUND] = "surround"; 
    1322     audioFlags[AUD_STEREO] = "stereo"; 
    1323     audioFlags[AUD_MONO] = "mono"; 
    1324  
    1325     QMap<VideoProps, QString> videoFlags; 
    1326     videoFlags[VID_1080] = "hd1080"; 
    1327     videoFlags[VID_720] = "hd720"; 
    1328     videoFlags[VID_HDTV] = "hdtv"; 
    1329     videoFlags[VID_WIDESCREEN] = "widescreen"; 
    1330  
    1331     QMap<SubtitleTypes, QString> subtitleFlags; 
    1332     subtitleFlags[SUB_SIGNED] = "deafsigned"; 
    1333     subtitleFlags[SUB_ONSCREEN] = "onscreensub"; 
    1334     subtitleFlags[SUB_NORMAL] = "subtitles"; 
    1335     subtitleFlags[SUB_HARDHEAR] = "cc"; 
    1336  
    13371393    ProgramList::iterator it = progList.begin(); 
    13381394    for (; it != progList.end(); ++it) 
    13391395    { 
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    13411397            (*it)->GetAvailableStatus() == asDeleted) 
    13421398            continue; 
    13431399 
    1344         MythUIButtonListItem *item = 
    1345             new PlaybackBoxListItem(this, m_recordingList, *it); 
    1346  
    1347         QString state = extract_main_state(**it, m_player); 
    1348  
    1349         item->SetFontState(state); 
    1350  
    1351         InfoMap infoMap; 
    1352         (*it)->ToMap(infoMap); 
    1353         item->SetTextFromMap(infoMap); 
    1354  
    1355         QString tempSubTitle  = extract_subtitle(**it, groupname); 
    1356  
    1357         if (groupname == (*it)->GetTitle().toLower()) 
    1358             item->SetText(tempSubTitle,       "titlesubtitle"); 
    1359  
    1360         item->DisplayState(state, "status"); 
    1361  
    1362         item->DisplayState(QString::number((*it)->GetStars(10)), "ratingstate"); 
    1363  
    1364         SetItemIcons(item, (*it)); 
    1365  
    1366         QMap<AudioProps, QString>::iterator ait; 
    1367         for (ait = audioFlags.begin(); ait != audioFlags.end(); ++ait) 
    1368         { 
    1369             if ((*it)->GetAudioProperties() & ait.key()) 
    1370                 item->DisplayState(ait.value(), "audioprops"); 
    1371         } 
    1372  
    1373         QMap<VideoProps, QString>::iterator vit; 
    1374         for (vit = videoFlags.begin(); vit != videoFlags.end(); ++vit) 
    1375         { 
    1376             if ((*it)->GetVideoProperties() & vit.key()) 
    1377                 item->DisplayState(vit.value(), "videoprops"); 
    1378         } 
    1379  
    1380         QMap<SubtitleTypes, QString>::iterator sit; 
    1381         for (sit = subtitleFlags.begin(); sit != subtitleFlags.end(); ++sit) 
    1382         { 
    1383             if ((*it)->GetSubtitleType() & sit.key()) 
    1384                 item->DisplayState(sit.value(), "subtitletypes"); 
    1385         } 
    1386  
    1387         item->DisplayState((*it)->GetCategoryType(), "categorytype"); 
     1400        new PlaybackBoxListItem(this, m_recordingList, *it); 
    13881401    } 
     1402    m_helper.ComputeButtonListPage(0); 
    13891403 
    13901404    if (m_noRecordingsText) 
    13911405    { 
    void PlaybackBox::customEvent(QEvent *event) 
    38453859        if (resultid == "transcode" && dce->GetResult() >= 0) 
    38463860            changeProfileAndTranscode(dce->GetData().toInt()); 
    38473861    } 
     3862    else if (event->type() == NextButtonListPageEvent::kEventType) 
     3863    { 
     3864        // Lazily compute a "page" of the next 20 button list items 
     3865        // before the next screen refresh.  The value 20 is chosen to 
     3866        // be large enough that the background computation finishes 
     3867        // reasonably quickly, while small enough that it doesn't 
     3868        // noticeably affect scrolling/paging UI responsiveness. 
     3869        const int pageSize = 20; 
     3870        NextButtonListPageEvent *pue = 
     3871            dynamic_cast<NextButtonListPageEvent*>(event); 
     3872        if (m_recordingList) 
     3873        { 
     3874            int start = pue->getStart(); 
     3875            while (start < pue->getStart() + pageSize && 
     3876                   start < m_recordingList->GetCount()) 
     3877            { 
     3878                ItemVisibleCore(m_recordingList->GetItemAt(start)); 
     3879                ++start; 
     3880            } 
     3881            if (start < m_recordingList->GetCount()) 
     3882                m_helper.ComputeButtonListPage(start, pue->getGeneration()); 
     3883        } 
     3884    } 
    38483885    else if ((MythEvent::Type)(event->type()) == MythEvent::MythEventMessage) 
    38493886    { 
    38503887        MythEvent *me = (MythEvent *)event; 
  • mythtv/programs/mythfrontend/playbackbox.h

    diff --git a/mythtv/programs/mythfrontend/playbackbox.h b/mythtv/programs/mythfrontend/playbackbox.h
    index c6a9a2d..f7135fd 100644
    a b class PlaybackBox : public ScheduleCommon 
    142142    void ItemSelected(MythUIButtonListItem *item) 
    143143        { UpdateUIListItem(item, true); } 
    144144    void ItemVisible(MythUIButtonListItem *item); 
     145    void ItemVisibleCore(MythUIButtonListItem *item); 
    145146    void selected(MythUIButtonListItem *item); 
    146147    void PlayFromBookmark(MythUIButtonListItem *item = NULL); 
    147148    void PlayFromBeginning(MythUIButtonListItem *item = NULL); 
  • mythtv/programs/mythfrontend/playbackboxhelper.cpp

    diff --git a/mythtv/programs/mythfrontend/playbackboxhelper.cpp b/mythtv/programs/mythfrontend/playbackboxhelper.cpp
    index 06950e4..3d1d13d 100644
    a b AvailableStatusType PBHEventHandler::CheckAvailability(const QStringList &slist) 
    126126    return availableStatus; 
    127127} 
    128128 
     129QEvent::Type NextButtonListPageEvent::kEventType = 
     130    (QEvent::Type) QEvent::registerEventType(); 
     131 
    129132bool PBHEventHandler::event(QEvent *e) 
    130133{ 
    131134    if (e->type() == QEvent::Timer) 
    bool PBHEventHandler::event(QEvent *e) 
    301304 
    302305            return true; 
    303306        } 
     307        else if (me->Message() == "BUTTONLIST_NEXT_PAGE") 
     308        { 
     309            int current = me->ExtraData(0).toInt(); 
     310            int generation = me->ExtraData(1).toInt(); 
     311            QCoreApplication::postEvent( 
     312                m_pbh.m_listener, 
     313                new NextButtonListPageEvent(current, generation)); 
     314        } 
    304315    } 
    305316 
    306317    return QObject::event(e); 
    PlaybackBoxHelper::PlaybackBoxHelper(QObject *listener) : 
    320331    MThread("PlaybackBoxHelper"), 
    321332    m_listener(listener), m_eventHandler(new PBHEventHandler(*this)), 
    322333    // Free Space Tracking Variables 
    323     m_freeSpaceTotalMB(0ULL), m_freeSpaceUsedMB(0ULL) 
     334    m_freeSpaceTotalMB(0ULL), m_freeSpaceUsedMB(0ULL), 
     335    m_buttonListItemCurrent(0), m_buttonListGeneration(0) 
    324336{ 
    325337    start(); 
    326338    m_eventHandler->moveToThread(qthread()); 
    QString PlaybackBoxHelper::GetPreviewImage( 
    479491 
    480492    return token; 
    481493} 
     494 
     495void PlaybackBoxHelper::ComputeButtonListPage(int start, int generation) 
     496{ 
     497    // If a specific generation is requested, only honor it if someone 
     498    // else hasn't already reset the search and updated the current 
     499    // generation. 
     500    { 
     501        QMutexLocker locker(&m_lock); 
     502        if (generation >= 0 && generation != m_buttonListGeneration) 
     503            return; 
     504        // Restart any work in progress 
     505        if (start == 0) 
     506            generation = ++m_buttonListGeneration; 
     507    } 
     508    LOG(VB_GENERAL, LOG_INFO, 
     509        QString("Background buttonlist building: start=%1 gen=%2") 
     510        .arg(start).arg(generation)); 
     511    QStringList extraData; 
     512    extraData += QString::number(start); 
     513    extraData += QString::number(generation); 
     514    QCoreApplication::postEvent(m_eventHandler, 
     515                                new MythEvent("BUTTONLIST_NEXT_PAGE", 
     516                                              extraData)); 
     517} 
  • mythtv/programs/mythfrontend/playbackboxhelper.h

    diff --git a/mythtv/programs/mythfrontend/playbackboxhelper.h b/mythtv/programs/mythfrontend/playbackboxhelper.h
    index a288b8b..a7ad37d 100644
    a b class PlaybackBoxHelper : public MThread 
    5353    uint64_t GetFreeSpaceTotalMB(void) const; 
    5454    uint64_t GetFreeSpaceUsedMB(void) const; 
    5555 
     56    void ComputeButtonListPage(int start, int generation = -1); 
     57 
    5658  private: 
    5759    void UpdateFreeSpace(void); 
    5860 
    class PlaybackBoxHelper : public MThread 
    6769 
    6870    // Artwork Variables ////////////////////////////////////////////////////// 
    6971    QHash<QString, QString>    m_artworkFilenameCache; 
     72 
     73    // Background button list loading 
     74    int m_buttonListItemCurrent; 
     75    int m_buttonListGeneration; 
     76}; 
     77 
     78class NextButtonListPageEvent : public QEvent 
     79{ 
     80  public: 
     81    NextButtonListPageEvent(int start, int generation) : 
     82        QEvent(kEventType), m_start(start), m_generation(generation) {} 
     83 
     84    int getStart()      { return m_start; } 
     85    int getGeneration() { return m_generation; } 
     86 
     87    static Type kEventType; 
     88 
     89  private: 
     90    int m_start; 
     91    int m_generation; 
    7092}; 
    7193 
    7294#endif // _FREE_SPACE_H_