Ticket #7425: mythvideo-remember-tree-position.patch

File mythvideo-remember-tree-position.patch, 4.6 KB (added by Robert S, 2 years ago)

Improved patch against trunk 24740

  • mythvideo/mythvideo/videodlg.cpp

     
    13101310 
    13111311        if (m_rememberPosition && m_lastTreeNodePath.length()) 
    13121312        { 
     1313            VERBOSE(VB_GENERAL, QString("Exiting, saving video tree position: '%1'"). 
     1314                    arg(m_lastTreeNodePath)); 
    13131315            gCoreContext->SaveSetting("mythvideo.VideoTreeLastActive", 
    13141316                    m_lastTreeNodePath); 
    13151317        } 
     
    16741676 
    16751677            if (m_d->m_rememberPosition) 
    16761678            { 
    1677                 QStringList route = 
    1678                         gCoreContext->GetSetting("mythvideo.VideoTreeLastActive", 
    1679                                 "").split("\n"); 
    1680                 m_videoButtonTree->SetNodeByString(route); 
     1679                // get the last saved path from the database 
     1680                m_d->m_lastTreeNodePath = gCoreContext->GetSetting("mythvideo.VideoTreeLastActive", ""); 
     1681 
     1682                // remove first element of the route since 
     1683                // it is the name of the root 'Video Home' element 
     1684                QStringList route = m_d->m_lastTreeNodePath.split("\n"); 
     1685                route.removeFirst(); 
     1686 
     1687                if (m_videoButtonTree->SetNodeByString(route)) 
     1688                    m_videoButtonTree->SetCurrentDepth(route.length()); 
    16811689            } 
    16821690        } 
    16831691    } 
     
    16941702        if (!m_d->m_currentNode) 
    16951703            return; 
    16961704 
     1705        // the currenty selected node. this will be 
     1706        // overwritten by the last entry in the saved tree node entry 
    16971707        MythGenericTree *selectedNode = m_d->m_currentNode->getSelectedChild(); 
    16981708 
     1709        // restore the last saved position in the video tree if this is the first 
     1710        // time this method is called and the option is set in the database 
     1711        if (m_d->m_firstLoadPass && m_d->m_rememberPosition) 
     1712        { 
     1713            QStringList lastTreeNodePath = gCoreContext->GetSetting("mythvideo.VideoTreeLastActive", "").split("\n"); 
     1714 
     1715            if (m_d->m_type == DLG_GALLERY) 
     1716            { 
     1717                if (lastTreeNodePath.size() > 0) 
     1718                { 
     1719                    MythGenericTree *node; 
     1720 
     1721                    // go through the path list and set the current node 
     1722                    for (int i = 0; i < lastTreeNodePath.size(); i++) 
     1723                    { 
     1724                        node = m_d->m_currentNode->getChildByName(lastTreeNodePath.at(i)); 
     1725                        if (node != NULL) 
     1726                        { 
     1727                            // check if the node name is the same as the currently selected 
     1728                            // one in the saved tree list. if yes then we are on the right 
     1729                            // way down the video tree to find the last saved position 
     1730                            if (node->getString().compare(lastTreeNodePath.at(i)) == 0) 
     1731                            {  
     1732                                // set the folder as the new node so we can travel further down 
     1733                                // dont do this if its the last part of the saved video path tree 
     1734                                if (node->getInt() == kSubFolder && 
     1735                                    node->childCount() > 1 && 
     1736                                    i < lastTreeNodePath.size()-1) 
     1737                                { 
     1738                                    SetCurrentNode(node); 
     1739                                } 
     1740                                // in the last run the selectedNode will be the last 
     1741                                // entry of the saved tree node. 
     1742                                if (lastTreeNodePath.at(i) == lastTreeNodePath.last()) 
     1743                                    selectedNode = node; 
     1744                            } 
     1745                        } 
     1746                    } 
     1747 
     1748                    m_d->m_firstLoadPass = false; 
     1749                } 
     1750            } 
     1751        } 
     1752                                         
    16991753        typedef QList<MythGenericTree *> MGTreeChildList; 
    17001754        MGTreeChildList *lchildren = m_d->m_currentNode->getAllChildren(); 
    17011755 
     
    28102864 
    28112865    if (node) 
    28122866        node->becomeSelectedChild(); 
     2867 
     2868    // save the path and the item name only if we have already 
     2869    // loaded the previously saved tree node path from the database. 
     2870    if (!m_d->m_firstLoadPass) 
     2871    { 
     2872        m_d->m_lastTreeNodePath = m_d->m_currentNode->getRouteByString().join("\n"); 
     2873        m_d->m_lastTreeNodePath.append("\n").append( m_d->m_currentNode->getSelectedChild()->getString() ); 
     2874 
     2875        VERBOSE(VB_IMPORTANT, QString("Saved m_lastTreeNodePath '%1'").arg(m_d->m_lastTreeNodePath)); 
     2876    } 
    28132877} 
    28142878 
    28152879/** \fn VideoDialog::VideoMenu()