Ticket #10161: lazystrings_v13a.patch

File lazystrings_v13a.patch, 15.6 KB (added by Jim Stichnoth, 12 years ago)

Here's a version of the v13 patch that refactors the event structure into the MythUIButtonList class.

  • mythtv/libs/libmythui/mythuibuttonlist.cpp

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.cpp b/mythtv/libs/libmythui/mythuibuttonlist.cpp
    index 8d4de31..dbef0f7 100644
    a b void MythUIButtonList::Const(void) 
    8686
    8787    m_buttontemplate = NULL;
    8888
     89    m_nextItemInited = 0;
     90
    8991    SetCanTakeFocus(true);
    9092
    9193    connect(this, SIGNAL(TakingFocus()), this, SLOT(Select()));
    void MythUIButtonList::Reset() 
    153155    m_topPosition = 0;
    154156    m_itemCount   = 0;
    155157
     158    StopInit();
    156159    Update();
    157160    MythUIType::Reset();
    158161}
    bool MythUIButtonList::gestureEvent(MythGestureEvent *event) 
    24762479    return handled;
    24772480}
    24782481
     2482class NextButtonListPageEvent : public QEvent
     2483{
     2484  public:
     2485    NextButtonListPageEvent(int start, int pageSize) :
     2486        QEvent(kEventType), m_start(start), m_pageSize(pageSize) {}
     2487    const int m_start;
     2488    const int m_pageSize;
     2489    static Type kEventType;
     2490};
     2491
     2492QEvent::Type NextButtonListPageEvent::kEventType =
     2493    (QEvent::Type) QEvent::registerEventType();
     2494
     2495void MythUIButtonList::customEvent(QEvent *event)
     2496{
     2497    if (event->type() == NextButtonListPageEvent::kEventType)
     2498    {
     2499        NextButtonListPageEvent *npe =
     2500            dynamic_cast<NextButtonListPageEvent*>(event);
     2501        int cur = npe->m_start;
     2502        for (; cur < npe->m_start + npe->m_pageSize && cur < GetCount(); ++cur)
     2503        {
     2504            const int loginterval = (cur < 1000 ? 100 : 500);
     2505            if (cur % loginterval == 0)
     2506                LOG(VB_GENERAL, LOG_INFO,
     2507                    QString("Build background buttonlist item %1").arg(cur));
     2508            emit itemInited(GetItemAt(cur));
     2509        }
     2510        m_nextItemInited = cur;
     2511        if (cur < GetCount())
     2512            StartInit(cur, npe->m_pageSize);
     2513    }
     2514}
     2515
     2516void MythUIButtonList::StartInit(int start, int pageSize)
     2517{
     2518    m_nextItemInited = start;
     2519    QCoreApplication::
     2520        postEvent(this, new NextButtonListPageEvent(start, pageSize));
     2521}
     2522
     2523int MythUIButtonList::StopInit(void)
     2524{
     2525    QCoreApplication::
     2526        removePostedEvents(this, NextButtonListPageEvent::kEventType);
     2527    return m_nextItemInited;
     2528}
     2529
    24792530QPoint MythUIButtonList::GetButtonPosition(int column, int row) const
    24802531{
    24812532    int x = m_contentsRect.x() +
  • mythtv/libs/libmythui/mythuibuttonlist.h

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.h b/mythtv/libs/libmythui/mythuibuttonlist.h
    index d42a204..8b731ef 100644
    a b class MUI_PUBLIC MythUIButtonList : public MythUIType 
    128128
    129129    virtual bool keyPressEvent(QKeyEvent *);
    130130    virtual bool gestureEvent(MythGestureEvent *event);
     131    virtual void customEvent(QEvent *);
    131132
    132133    enum MovementUnit { MoveItem, MoveColumn, MoveRow, MovePage, MoveMax,
    133134                        MoveMid, MoveByAmount };
    class MUI_PUBLIC MythUIButtonList : public MythUIType 
    184185    bool FindNext(void);
    185186    bool FindPrev(void);
    186187
     188    void StartInit(int start = 0, int pageSize = 20);
     189    int  StopInit(void);
     190
    187191  public slots:
    188192    void Select();
    189193    void Deselect();
    class MUI_PUBLIC MythUIButtonList : public MythUIType 
    192196    void itemSelected(MythUIButtonListItem* item);
    193197    void itemClicked(MythUIButtonListItem* item);
    194198    void itemVisible(MythUIButtonListItem* item);
     199    void itemInited(MythUIButtonListItem* item);
    195200
    196201  protected:
    197202    enum ScrollStyle { ScrollFree, ScrollCenter, ScrollGroupCenter };
    class MUI_PUBLIC MythUIButtonList : public MythUIType 
    302307    bool m_keepSelAtBottom;
    303308
    304309    QList<MythUIButtonListItem*> m_itemList;
     310    int m_nextItemInited;
    305311
    306312    bool m_drawFromBottom;
    307313
  • mythtv/programs/mythfrontend/playbackbox.cpp

    diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp
    index 2e65654..82c36a5 100644
    a b bool PlaybackBox::Create() 
    542542            SLOT(PlayFromBookmark(MythUIButtonListItem*)));
    543543    connect(m_recordingList, SIGNAL(itemVisible(MythUIButtonListItem*)),
    544544            SLOT(ItemVisible(MythUIButtonListItem*)));
     545    connect(m_recordingList, SIGNAL(itemInited(MythUIButtonListItem*)),
     546            SLOT(ItemInited(MythUIButtonListItem*)));
    545547
    546548    // connect up timers...
    547549    connect(m_artTimer[kArtworkFanart],   SIGNAL(timeout()), SLOT(fanartLoad()));
    void PlaybackBox::UpdateUIListItem(MythUIButtonListItem *item, 
    890892    }
    891893}
    892894
     895void PlaybackBox::ItemInited(MythUIButtonListItem *item)
     896{
     897    ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData());
     898    if (item->GetText("is_item_initialized").isNull())
     899    {
     900        QMap<AudioProps, QString> audioFlags;
     901        audioFlags[AUD_DOLBY] = "dolby";
     902        audioFlags[AUD_SURROUND] = "surround";
     903        audioFlags[AUD_STEREO] = "stereo";
     904        audioFlags[AUD_MONO] = "mono";
     905
     906        QMap<VideoProps, QString> videoFlags;
     907        videoFlags[VID_1080] = "hd1080";
     908        videoFlags[VID_720] = "hd720";
     909        videoFlags[VID_HDTV] = "hdtv";
     910        videoFlags[VID_WIDESCREEN] = "widescreen";
     911
     912        QMap<SubtitleTypes, QString> subtitleFlags;
     913        subtitleFlags[SUB_SIGNED] = "deafsigned";
     914        subtitleFlags[SUB_ONSCREEN] = "onscreensub";
     915        subtitleFlags[SUB_NORMAL] = "subtitles";
     916        subtitleFlags[SUB_HARDHEAR] = "cc";
     917
     918        QString groupname =
     919            m_groupList->GetItemCurrent()->GetData().toString();
     920
     921        QString state = extract_main_state(*pginfo, m_player);
     922
     923        item->SetFontState(state);
     924
     925        InfoMap infoMap;
     926        pginfo->ToMap(infoMap);
     927        item->SetTextFromMap(infoMap);
     928
     929        QString tempSubTitle  = extract_subtitle(*pginfo, groupname);
     930
     931        if (groupname == pginfo->GetTitle().toLower())
     932            item->SetText(tempSubTitle, "titlesubtitle");
     933
     934        item->DisplayState(state, "status");
     935
     936        item->DisplayState(QString::number(pginfo->GetStars(10)),
     937                           "ratingstate");
     938
     939        SetItemIcons(item, pginfo);
     940
     941        QMap<AudioProps, QString>::iterator ait;
     942        for (ait = audioFlags.begin(); ait != audioFlags.end(); ++ait)
     943        {
     944            if (pginfo->GetAudioProperties() & ait.key())
     945                item->DisplayState(ait.value(), "audioprops");
     946        }
     947
     948        QMap<VideoProps, QString>::iterator vit;
     949        for (vit = videoFlags.begin(); vit != videoFlags.end(); ++vit)
     950        {
     951            if (pginfo->GetVideoProperties() & vit.key())
     952                item->DisplayState(vit.value(), "videoprops");
     953        }
     954
     955        QMap<SubtitleTypes, QString>::iterator sit;
     956        for (sit = subtitleFlags.begin(); sit != subtitleFlags.end(); ++sit)
     957        {
     958            if (pginfo->GetSubtitleType() & sit.key())
     959                item->DisplayState(sit.value(), "subtitletypes");
     960        }
     961
     962        item->DisplayState(pginfo->GetCategoryType(), "categorytype");
     963
     964        // Mark this button list item as initialized.
     965        item->SetText("yes", "is_item_initialized");
     966    }
     967
     968}
     969
    893970void PlaybackBox::ItemVisible(MythUIButtonListItem *item)
    894971{
    895972    ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData());
    896973
     974    ItemInited(item);
    897975    // Job status (recording, transcoding, flagging)
    898976    QString job = extract_job_state(*pginfo);
    899977    item->DisplayState(job, "jobstate");
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    13161394
    13171395    ProgramList &progList = *pmit;
    13181396
    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 
    13371397    ProgramList::iterator it = progList.begin();
    13381398    for (; it != progList.end(); ++it)
    13391399    {
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    13411401            (*it)->GetAvailableStatus() == asDeleted)
    13421402            continue;
    13431403
    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");
     1404        new PlaybackBoxListItem(this, m_recordingList, *it);
    13881405    }
     1406    m_recordingList->StartInit();
    13891407
    13901408    if (m_noRecordingsText)
    13911409    {
    bool PlaybackBox::Play( 
    24182436    ProgramInfo tvrec(rec);
    24192437
    24202438    m_playingSomething = true;
     2439    int initIndex = m_recordingList->StopInit();
    24212440
    24222441    uint flags =
    24232442        (inPlaylist          ? kStartTVInPlayList       : kStartTVNoFlags) |
    bool PlaybackBox::Play( 
    24272446    playCompleted = TV::StartTV(&tvrec, flags);
    24282447
    24292448    m_playingSomething = false;
     2449    m_recordingList->StartInit(initIndex);
    24302450
    24312451    if (inPlaylist && !m_playListPlay.empty())
    24322452    {
  • mythtv/programs/mythfrontend/playbackbox.h

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

    diff --git a/mythtv/programs/mythfrontend/proglist.cpp b/mythtv/programs/mythfrontend/proglist.cpp
    index ddda2af..b4b855a 100644
    a b ProgLister::ProgLister(MythScreenStack *parent, ProgListType pltype, 
    4444    m_viewTextList(),
    4545
    4646    m_itemList(),
     47    m_itemListSave(),
    4748    m_schedList(),
    4849
    4950    m_typeList(),
    ProgLister::ProgLister( 
    9394    m_viewTextList(),
    9495
    9596    m_itemList(),
     97    m_itemListSave(),
    9698    m_schedList(),
    9799
    98100    m_typeList(),
    ProgLister::ProgLister( 
    115117ProgLister::~ProgLister()
    116118{
    117119    m_itemList.clear();
     120    m_itemListSave.clear();
    118121    gCoreContext->removeListener(this);
    119122}
    120123
    bool ProgLister::Create() 
    139142    connect(m_progList, SIGNAL(itemSelected(MythUIButtonListItem*)),
    140143            this,       SLOT(  HandleSelected(  MythUIButtonListItem*)));
    141144
     145    connect(m_progList, SIGNAL(itemVisible(MythUIButtonListItem*)),
     146            this,       SLOT(  HandleVisible(  MythUIButtonListItem*)));
     147
     148    connect(m_progList, SIGNAL(itemInited(MythUIButtonListItem*)),
     149            this,       SLOT(  HandleVisible(  MythUIButtonListItem*)));
     150
    142151    connect(m_progList, SIGNAL(itemClicked(MythUIButtonListItem*)),
    143152            this,       SLOT(  HandleClicked()));
    144153
    void ProgLister::FillItemList(bool restorePosition, bool updateDisp) 
    13421351        selectedP = &selected;
    13431352    }
    13441353
     1354    // Save a copy of m_itemList so that deletion of the ProgramInfo
     1355    // objects can be deferred until background processing of old
     1356    // ProgramInfo objects has completed.
     1357    m_itemListSave.clear();
     1358    m_itemListSave = m_itemList;
     1359    m_itemList.setAutoDelete(false);
    13451360    m_itemList.clear();
     1361    m_itemList.setAutoDelete(true);
    13461362
    13471363    if (m_type == plPreviouslyRecorded)
    13481364    {
    void ProgLister::RestoreSelection(const ProgramInfo *selected, 
    14891505    m_progList->SetItemCurrent(i + 1, i + 1 - selectedOffset);
    14901506}
    14911507
    1492 void ProgLister::UpdateButtonList(void)
     1508void ProgLister::HandleVisible(MythUIButtonListItem *item)
    14931509{
    1494     ProgramList::const_iterator it = m_itemList.begin();
    1495     for (; it != m_itemList.end(); ++it)
    1496     {
    1497         MythUIButtonListItem *item =
    1498             new MythUIButtonListItem(
    1499                 m_progList, "", qVariantFromValue(*it));
     1510    ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData());
    15001511
     1512    if (item->GetText("is_item_initialized").isNull())
     1513    {
    15011514        InfoMap infoMap;
    1502         (**it).ToMap(infoMap);
     1515        pginfo->ToMap(infoMap);
    15031516
    1504         QString state = toUIState((**it).GetRecordingStatus());
     1517        QString state = toUIState(pginfo->GetRecordingStatus());
    15051518        if ((state == "warning") && (plPreviouslyRecorded == m_type))
    15061519            state = "disabled";
    15071520
    void ProgLister::UpdateButtonList(void) 
    15091522
    15101523        if (m_type == plTitle)
    15111524        {
    1512             QString tempSubTitle = (**it).GetSubtitle();
     1525            QString tempSubTitle = pginfo->GetSubtitle();
    15131526            if (tempSubTitle.trimmed().isEmpty())
    1514                 tempSubTitle = (**it).GetTitle();
     1527                tempSubTitle = pginfo->GetTitle();
    15151528            item->SetText(tempSubTitle, "titlesubtitle", state);
    15161529        }
    15171530
    1518         item->DisplayState(
    1519             QString::number((**it).GetStars(10)), "ratingstate");
     1531        item->DisplayState(QString::number(pginfo->GetStars(10)),
     1532                          "ratingstate");
    15201533
    15211534        item->DisplayState(state, "status");
     1535
     1536        // Mark this button list item as initialized.
     1537        item->SetText("yes", "is_item_initialized");
    15221538    }
     1539}
     1540
     1541void ProgLister::UpdateButtonList(void)
     1542{
     1543    ProgramList::const_iterator it = m_itemList.begin();
     1544    for (; it != m_itemList.end(); ++it)
     1545        new MythUIButtonListItem(m_progList, "", qVariantFromValue(*it));
     1546    m_progList->StartInit();
    15231547
    15241548    if (m_positionText)
    15251549    {
  • mythtv/programs/mythfrontend/proglist.h

    diff --git a/mythtv/programs/mythfrontend/proglist.h b/mythtv/programs/mythfrontend/proglist.h
    index 1fc9020..5ecc84c 100644
    a b class ProgLister : public ScheduleCommon 
    5050
    5151  protected slots:
    5252    void HandleSelected(MythUIButtonListItem *item);
     53    void HandleVisible(MythUIButtonListItem *item);
    5354    void HandleClicked(void);
    5455
    5556    void DeleteOldEpisode(bool ok);
    class ProgLister : public ScheduleCommon 
    115116    QStringList       m_viewTextList;
    116117
    117118    ProgramList       m_itemList;
     119    ProgramList       m_itemListSave;
    118120    ProgramList       m_schedList;
    119121
    120122    QStringList       m_typeList;