Ticket #10161: lazystrings_v4.patch

File lazystrings_v4.patch, 17.2 KB (added by Jim Stichnoth <stichnot@…>, 12 years ago)
  • mythtv/libs/libmythui/mythuibuttonlist.cpp

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.cpp b/mythtv/libs/libmythui/mythuibuttonlist.cpp
    index ed473e0..8e612fe 100644
    a b MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype, 
    28522852                                           const QString &text, const QString &image,
    28532853                                           bool checkable, CheckState state,
    28542854                                           bool showArrow, int listPosition)
     2855    : m_strings(this), m_states(this)
    28552856{
    28562857    if (!lbtype)
    28572858        LOG(VB_GENERAL, LOG_ERR, "Cannot add a button to a non-existent list!");
    MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype, 
    28752876MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype,
    28762877                                           const QString &text,
    28772878                                           QVariant data, int listPosition)
     2879    : m_strings(this), m_states(this)
    28782880{
    28792881    if (!lbtype)
    28802882        LOG(VB_GENERAL, LOG_ERR, "Cannot add a button to a non-existent list!");
    void MythUIButtonListItem::SetTextFromMap(QMap<QString, TextProperties> &stringM 
    29512953    m_strings = stringMap;
    29522954}
    29532955
    2954 QString MythUIButtonListItem::GetText(const QString &name) const
     2956QString MythUIButtonListItem::GetText(const QString &name)
    29552957{
    29562958    if (name.isEmpty())
    29572959        return m_text;
    QString MythUIButtonListItem::GetText(const QString &name) const 
    29622964}
    29632965
    29642966bool MythUIButtonListItem::FindText(const QString &searchStr, const QString &fieldList,
    2965                                     bool startsWith) const
     2967                                    bool startsWith)
    29662968{
    29672969    if (fieldList.isEmpty())
    29682970    {
    bool MythUIButtonListItem::FindText(const QString &searchStr, const QString &fie 
    29842986                return true;
    29852987        }
    29862988
    2987         QMap<QString, TextProperties>::const_iterator i = m_strings.constBegin();
     2989        QMap<QString, TextProperties>::const_iterator i = m_strings.begin();
    29882990
    2989         while (i != m_strings.constEnd())
     2991        while (i != m_strings.end())
    29902992        {
    29912993            if (startsWith)
    29922994            {
    void SearchButtonListDialog::prevClicked(void) 
    35033505    if (m_searchState)
    35043506        m_searchState->DisplayState(found ? "found" : "notfound");
    35053507}
     3508
     3509void TextPropertiesWrapper::FillIn(void)
     3510{
     3511    if (pbb)
     3512    {
     3513        PlaybackBox *oldPbb = pbb;
     3514        pbb = 0;
     3515        func(oldPbb, progInfo, str, parent);
     3516        progInfo = 0;
     3517        func = 0;
     3518    }
     3519}
     3520
     3521void QStringWrapper::FillIn(void)
     3522{
     3523    if (pbb)
     3524    {
     3525        PlaybackBox *oldPbb = pbb;
     3526        pbb = 0;
     3527        func(oldPbb, progInfo, parent);
     3528        progInfo = 0;
     3529        func = 0;
     3530    }
     3531}
  • mythtv/libs/libmythui/mythuibuttonlist.h

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.h b/mythtv/libs/libmythui/mythuibuttonlist.h
    index b6cbebd..fdd3dac 100644
    a b  
    1414
    1515class MythUIButtonList;
    1616class MythUIStateType;
     17class ProgramInfo;
     18class PlaybackBox;
    1719
    1820struct TextProperties {
    1921    QString text;
    2022    QString state;
    2123};
    2224
     25typedef void (*DeferredFillInStringsFunc)(PlaybackBox *, ProgramInfo *,
     26                                          QString &, MythUIButtonListItem *);
     27// TextPropertiesWrapper is a wrapper around a
     28// QMap<QString,TextProperties> object such that initialization of
     29// MythUIButtonListItem::m_strings can be deferred until the next
     30// access to the object.
     31class TextPropertiesWrapper {
     32public:
     33    TextPropertiesWrapper(MythUIButtonListItem *p)
     34        : parent(p), pbb(0), progInfo(0), func(0) {}
     35    void SetDeferredMap(PlaybackBox *pb, ProgramInfo *pi,
     36                        QString &s, DeferredFillInStringsFunc f) {
     37        pbb = pb;
     38        progInfo = pi;
     39        str = s;
     40        func = f;
     41    }
     42    QMap<QString, TextProperties>::iterator begin(void) {
     43        FillIn();
     44        return map.begin();
     45    }
     46    void clear(void) {
     47        FillIn();
     48        map.clear();
     49    }
     50    bool contains(const QString &key) {
     51        FillIn();
     52        return map.contains(key);
     53    }
     54    QMap<QString, TextProperties>::iterator end(void) {
     55        FillIn();
     56        return map.end();
     57    }
     58    QMap<QString, TextProperties>::iterator insert(const QString &key, const TextProperties &value) {
     59        FillIn();
     60        return map.insert(key, value);
     61    }
     62    const TextProperties value(const QString &key) {
     63        FillIn();
     64        return map.value(key);
     65    }
     66    TextProperties &operator[](const QString &key) {
     67        FillIn();
     68        return map[key];
     69    }
     70    TextPropertiesWrapper &operator=(const QMap<QString, TextProperties> &other) {
     71        FillIn();
     72        map = other;
     73        return *this;
     74    }
     75private:
     76    void FillIn(void);
     77    MythUIButtonListItem *parent;
     78    PlaybackBox *pbb;
     79    ProgramInfo *progInfo;
     80    QString str;
     81    DeferredFillInStringsFunc func;
     82    QMap<QString, TextProperties> map;
     83};
     84
     85typedef void (*DeferredFillInStatesFunc)(PlaybackBox *, ProgramInfo *, MythUIButtonListItem *);
     86class QStringWrapper {
     87public:
     88    QStringWrapper(MythUIButtonListItem *p)
     89        : parent(p), pbb(0), progInfo(0), func(0) {}
     90    void SetDeferredMap(PlaybackBox *pb, ProgramInfo *pi,
     91                        DeferredFillInStatesFunc f) {
     92        pbb = pb;
     93        progInfo = pi;
     94        func = f;
     95    }
     96    QMap<QString, QString>::iterator begin(void) {
     97        FillIn();
     98        return map.begin();
     99    }
     100    QMap<QString, QString>::iterator find(const QString &key) {
     101        FillIn();
     102        return map.find(key);
     103    }
     104    QMap<QString, QString>::iterator end(void) {
     105        FillIn();
     106        return map.end();
     107    }
     108    QMap<QString, QString>::iterator insert(const QString &key, const QString &value) {
     109        FillIn();
     110        return map.insert(key, value);
     111    }
     112private:
     113    void FillIn(void);
     114    MythUIButtonListItem *parent;
     115    PlaybackBox *pbb;
     116    ProgramInfo *progInfo;
     117    DeferredFillInStatesFunc func;
     118    QMap<QString, QString> map;
     119};
     120
    23121class MUI_PUBLIC MythUIButtonListItem
    24122{
    25123  public:
    class MUI_PUBLIC MythUIButtonListItem 
    44142                 const QString &state="");
    45143    void SetTextFromMap(InfoMap &infoMap, const QString &state="");
    46144    void SetTextFromMap(QMap<QString, TextProperties> &stringMap);
    47     QString GetText(const QString &name="") const;
     145    void SetStringsDeferred(PlaybackBox *pb, ProgramInfo *pi,
     146                            QString &s, DeferredFillInStringsFunc f) {
     147        m_strings.SetDeferredMap(pb, pi, s, f);
     148    }
     149    void SetStatesDeferred(PlaybackBox *pb, ProgramInfo *pi,
     150                           DeferredFillInStatesFunc f) {
     151        m_states.SetDeferredMap(pb, pi, f);
     152    }
     153    QString GetText(const QString &name="");
    48154
    49155    bool FindText(const QString &searchStr, const QString &fieldList = "**ALL**",
    50                   bool startsWith = false) const;
     156                  bool startsWith = false);
    51157
    52158    void SetFontState(const QString &state, const QString &name="");
    53159
    class MUI_PUBLIC MythUIButtonListItem 
    95201    QVariant        m_data;
    96202    bool            m_showArrow;
    97203
    98     QMap<QString, TextProperties> m_strings;
     204    TextPropertiesWrapper m_strings;
    99205    QMap<QString, MythImage*> m_images;
    100206    QMap<QString, QString> m_imageFilenames;
    101     QMap<QString, QString> m_states;
     207    QStringWrapper m_states;
    102208
    103209    friend class MythUIButtonList;
    104210    friend class MythGenericTree;
  • mythtv/programs/mythfrontend/main.cpp

    diff --git a/mythtv/programs/mythfrontend/main.cpp b/mythtv/programs/mythfrontend/main.cpp
    index 5a6967a..60d24a6 100644
    a b static void startCustomPriority(void) 
    467467
    468468static void startPlaybackWithGroup(QString recGroup = "")
    469469{
     470    LOG(VB_GENERAL, LOG_INFO, QString("LZY startPlaybackWithGroup begin"));
    470471    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
    471472
    472473    PlaybackBox *pbb = new PlaybackBox(
    static void startPlaybackWithGroup(QString recGroup = "") 
    481482    }
    482483    else
    483484        delete pbb;
     485    LOG(VB_GENERAL, LOG_INFO, QString("LZY startPlaybackWithGroup end"));
    484486}
    485487
    486488static void startPlayback(void)
  • mythtv/programs/mythfrontend/playbackbox.cpp

    diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp
    index dc76ecf..cbd9b28 100644
    a b PlaybackBox::~PlaybackBox(void) 
    499499
    500500bool PlaybackBox::Create()
    501501{
     502    LOG(VB_GENERAL, LOG_INFO, QString("LZY LoadWindowFromXML begin"));
    502503    if (m_type == kDeleteBox &&
    503504            LoadWindowFromXML("recordings-ui.xml", "deleterecordings", this))
    504505        LOG(VB_GENERAL, LOG_DEBUG,
    bool PlaybackBox::Create() 
    506507    else
    507508        if (!LoadWindowFromXML("recordings-ui.xml", "watchrecordings", this))
    508509            return false;
     510    LOG(VB_GENERAL, LOG_INFO, QString("LZY LoadWindowFromXML end"));
    509511
    510512    m_recgroupList  = dynamic_cast<MythUIButtonList *> (GetChild("recgroups"));
    511513    m_groupList     = dynamic_cast<MythUIButtonList *> (GetChild("groups"));
    void PlaybackBox::UpdateUIRecGroupList(void) 
    12101212
    12111213void PlaybackBox::UpdateUIGroupList(const QStringList &groupPreferences)
    12121214{
     1215    LOG(VB_GENERAL, LOG_INFO, QString("LZY UpdateUIGroupList begin"));
    12131216    m_groupList->Reset();
    12141217
    12151218    if (!m_titleList.isEmpty())
    void PlaybackBox::UpdateUIGroupList(const QStringList &groupPreferences) 
    12501253        if (!sel_idx)
    12511254            updateRecList(m_groupList->GetItemCurrent());
    12521255    }
     1256    LOG(VB_GENERAL, LOG_INFO, QString("LZY UpdateUIGroupList end"));
    12531257}
    12541258
    12551259void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item)
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    12591263
    12601264    QString groupname = sel_item->GetData().toString();
    12611265    QString grouplabel = sel_item->GetText();
     1266    LOG(VB_GENERAL, LOG_INFO, QString("LZY updateRecList begin groupname=%1").arg(groupname));
    12621267
    12631268    updateGroupInfo(groupname, grouplabel);
    12641269
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    12791284
    12801285    ProgramList &progList = *pmit;
    12811286
    1282     QMap<AudioProps, QString> audioFlags;
    1283     audioFlags[AUD_DOLBY] = "dolby";
    1284     audioFlags[AUD_SURROUND] = "surround";
    1285     audioFlags[AUD_STEREO] = "stereo";
    1286     audioFlags[AUD_MONO] = "mono";
    1287 
    1288     QMap<VideoProps, QString> videoFlags;
    1289     videoFlags[VID_1080] = "hd1080";
    1290     videoFlags[VID_720] = "hd720";
    1291     videoFlags[VID_HDTV] = "hdtv";
    1292     videoFlags[VID_WIDESCREEN] = "widescreen";
    1293 
    1294     QMap<SubtitleTypes, QString> subtitleFlags;
    1295     subtitleFlags[SUB_SIGNED] = "deafsigned";
    1296     subtitleFlags[SUB_ONSCREEN] = "onscreensub";
    1297     subtitleFlags[SUB_NORMAL] = "subtitles";
    1298     subtitleFlags[SUB_HARDHEAR] = "cc";
    1299 
    13001287    ProgramList::iterator it = progList.begin();
     1288    int itemcount = 0;
    13011289    for (; it != progList.end(); ++it)
    13021290    {
    13031291        if ((*it)->GetAvailableStatus() == asPendingDelete ||
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    13071295        MythUIButtonListItem *item =
    13081296            new PlaybackBoxListItem(this, m_recordingList, *it);
    13091297
    1310         QString state = extract_main_state(**it, m_player);
    1311 
    1312         item->SetFontState(state);
     1298        item->SetStringsDeferred(this, *it, groupname, DeferredFillInStrings);
     1299        item->SetStatesDeferred(this, *it, DeferredFillInStates);
    13131300
    1314         InfoMap infoMap;
    1315         (*it)->ToMap(infoMap);
    1316         item->SetTextFromMap(infoMap);
    1317 
    1318         QString tempSubTitle  = extract_subtitle(**it, groupname);
    1319 
    1320         if (groupname == (*it)->GetTitle().toLower())
    1321             item->SetText(tempSubTitle,       "titlesubtitle");
    1322 
    1323         item->DisplayState(state, "status");
    1324 
    1325         item->DisplayState(QString::number((*it)->GetStars(10)), "ratingstate");
    1326 
    1327         SetItemIcons(item, (*it));
    1328 
    1329         QMap<AudioProps, QString>::iterator ait;
    1330         for (ait = audioFlags.begin(); ait != audioFlags.end(); ++ait)
    1331         {
    1332             if ((*it)->GetAudioProperties() & ait.key())
    1333                 item->DisplayState(ait.value(), "audioprops");
    1334         }
    1335 
    1336         QMap<VideoProps, QString>::iterator vit;
    1337         for (vit = videoFlags.begin(); vit != videoFlags.end(); ++vit)
    1338         {
    1339             if ((*it)->GetVideoProperties() & vit.key())
    1340                 item->DisplayState(vit.value(), "videoprops");
    1341         }
    1342 
    1343         QMap<SubtitleTypes, QString>::iterator sit;
    1344         for (sit = subtitleFlags.begin(); sit != subtitleFlags.end(); ++sit)
    1345         {
    1346             if ((*it)->GetSubtitleType() & sit.key())
    1347                 item->DisplayState(sit.value(), "subtitletypes");
    1348         }
     1301        ++itemcount;
    13491302    }
     1303    LOG(VB_GENERAL, LOG_INFO, QString("LZY item creation count = %1").arg(itemcount));
    13501304
    13511305    if (m_noRecordingsText)
    13521306    {
    void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item) 
    13611315            m_noRecordingsText->SetVisible(true);
    13621316        }
    13631317    }
     1318    LOG(VB_GENERAL, LOG_INFO, QString("LZY updateRecList end"));
    13641319}
    13651320
    13661321static bool save_position(
    static void restore_position( 
    14991454
    15001455bool PlaybackBox::UpdateUILists(void)
    15011456{
     1457    LOG(VB_GENERAL, LOG_INFO, QString("LZY UpdateUILists() m_recGroup=%1 begin").arg(m_recGroup));
    15021458    m_isFilling = true;
    15031459
    15041460    // Save selection, including next few items & groups
    bool PlaybackBox::UpdateUILists(void) 
    15461502    QMap<int, QString> searchRule;
    15471503    QMap<int, int> recidEpisodes;
    15481504
     1505    LOG(VB_GENERAL, LOG_INFO, QString("LZY m_programInfoCache.Refresh() begin"));
    15491506    m_programInfoCache.Refresh();
     1507    LOG(VB_GENERAL, LOG_INFO, QString("LZY m_programInfoCache.Refresh() end"));
    15501508
    15511509    if (!m_programInfoCache.empty())
    15521510    {
    bool PlaybackBox::UpdateUILists(void) 
    20822040
    20832041    m_isFilling = false;
    20842042
     2043    LOG(VB_GENERAL, LOG_INFO, QString("LZY UpdateUILists() end"));
    20852044    return true;
    20862045}
    20872046
    void PlaybackBox::SetRecGroupPassword(const QString &newPassword) 
    48474806    m_recGroupPwCache[m_recGroup] = newPassword;
    48484807}
    48494808
     4809void PlaybackBox::DeferredFillInStrings(PlaybackBox *pbb, ProgramInfo *pi,
     4810                                        QString &groupname, MythUIButtonListItem *item)
     4811{
     4812    QString state = extract_main_state(*pi, pbb->m_player);
     4813
     4814    item->SetFontState(state);
     4815
     4816    InfoMap infoMap;
     4817    pi->ToMap(infoMap);
     4818    item->SetTextFromMap(infoMap);
     4819
     4820    QString tempSubTitle  = extract_subtitle(*pi, groupname);
     4821
     4822    if (groupname == pi->GetTitle().toLower())
     4823        item->SetText(tempSubTitle,       "titlesubtitle");
     4824}
     4825
     4826void PlaybackBox::DeferredFillInStates(PlaybackBox *pbb, ProgramInfo *pi,
     4827                                       MythUIButtonListItem *item)
     4828{
     4829    QMap<AudioProps, QString> audioFlags;
     4830    audioFlags[AUD_DOLBY] = "dolby";
     4831    audioFlags[AUD_SURROUND] = "surround";
     4832    audioFlags[AUD_STEREO] = "stereo";
     4833    audioFlags[AUD_MONO] = "mono";
     4834
     4835    QMap<VideoProps, QString> videoFlags;
     4836    videoFlags[VID_1080] = "hd1080";
     4837    videoFlags[VID_720] = "hd720";
     4838    videoFlags[VID_HDTV] = "hdtv";
     4839    videoFlags[VID_WIDESCREEN] = "widescreen";
     4840
     4841    QMap<SubtitleTypes, QString> subtitleFlags;
     4842    subtitleFlags[SUB_SIGNED] = "deafsigned";
     4843    subtitleFlags[SUB_ONSCREEN] = "onscreensub";
     4844    subtitleFlags[SUB_NORMAL] = "subtitles";
     4845    subtitleFlags[SUB_HARDHEAR] = "cc";
     4846
     4847        QString state = extract_main_state(*pi, pbb->m_player);
     4848
     4849        item->DisplayState(state, "status");
     4850
     4851        item->DisplayState(QString::number(pi->GetStars(10)), "ratingstate");
     4852
     4853        pbb->SetItemIcons(item, pi);
     4854
     4855        QMap<AudioProps, QString>::iterator ait;
     4856        for (ait = audioFlags.begin(); ait != audioFlags.end(); ++ait)
     4857        {
     4858            if (pi->GetAudioProperties() & ait.key())
     4859                item->DisplayState(ait.value(), "audioprops");
     4860        }
     4861
     4862        QMap<VideoProps, QString>::iterator vit;
     4863        for (vit = videoFlags.begin(); vit != videoFlags.end(); ++vit)
     4864        {
     4865            if (pi->GetVideoProperties() & vit.key())
     4866                item->DisplayState(vit.value(), "videoprops");
     4867        }
     4868
     4869        QMap<SubtitleTypes, QString>::iterator sit;
     4870        for (sit = subtitleFlags.begin(); sit != subtitleFlags.end(); ++sit)
     4871        {
     4872            if (pi->GetSubtitleType() & sit.key())
     4873                item->DisplayState(sit.value(), "subtitletypes");
     4874        }
     4875        item->DisplayState(state, "status");
     4876}
     4877
    48504878///////////////////////////////////////////////////
    48514879
    48524880GroupSelector::GroupSelector(MythScreenStack *lparent, const QString &label,
  • mythtv/programs/mythfrontend/playbackbox.h

    diff --git a/mythtv/programs/mythfrontend/playbackbox.h b/mythtv/programs/mythfrontend/playbackbox.h
    index e6f4ed9..8c6814a 100644
    a b class PlaybackBox : public ScheduleCommon 
    441441    PlaybackBoxHelper   m_helper;
    442442    /// Outstanding preview image requests
    443443    QSet<QString>       m_preview_tokens;
     444
     445    static void DeferredFillInStrings(PlaybackBox *pbb, ProgramInfo *pi,
     446                                      QString &groupname, MythUIButtonListItem *item);
     447    static void DeferredFillInStates(PlaybackBox *pbb, ProgramInfo *pi,
     448                                     MythUIButtonListItem *item);
    444449};
    445450
    446451class GroupSelector : public MythScreenType