Index: mythvideo/mythvideo/videodlg.cpp
===================================================================
--- mythvideo/mythvideo/videodlg.cpp	(Revision 24737)
+++ mythvideo/mythvideo/videodlg.cpp	(Arbeitskopie)
@@ -1310,6 +1310,8 @@
 
         if (m_rememberPosition && m_lastTreeNodePath.length())
         {
+            VERBOSE(VB_GENERAL, QString("Exiting, saving video tree position: '%1'").
+                    arg(m_lastTreeNodePath));
             gCoreContext->SaveSetting("mythvideo.VideoTreeLastActive",
                     m_lastTreeNodePath);
         }
@@ -1674,10 +1676,16 @@
 
             if (m_d->m_rememberPosition)
             {
-                QStringList route =
-                        gCoreContext->GetSetting("mythvideo.VideoTreeLastActive",
-                                "").split("\n");
-                m_videoButtonTree->SetNodeByString(route);
+                // get the last saved path from the database
+                m_d->m_lastTreeNodePath = gCoreContext->GetSetting("mythvideo.VideoTreeLastActive", "");
+
+                // remove first element of the route since
+                // it is the name of the root 'Video Home' element
+                QStringList route = m_d->m_lastTreeNodePath.split("\n");
+                route.removeFirst();
+
+                if (m_videoButtonTree->SetNodeByString(route))
+                    m_videoButtonTree->SetCurrentDepth(route.length());
             }
         }
     }
@@ -1694,8 +1702,54 @@
         if (!m_d->m_currentNode)
             return;
 
+        // the currenty selected node. this will be
+        // overwritten by the last entry in the saved tree node entry
         MythGenericTree *selectedNode = m_d->m_currentNode->getSelectedChild();
 
+        // restore the last saved position in the video tree if this is the first
+        // time this method is called and the option is set in the database
+        if (m_d->m_firstLoadPass && m_d->m_rememberPosition)
+        {
+            QStringList lastTreeNodePath = gCoreContext->GetSetting("mythvideo.VideoTreeLastActive", "").split("\n");
+
+            if (m_d->m_type == DLG_GALLERY)
+            {
+                if (lastTreeNodePath.size() > 0)
+                {
+                    MythGenericTree *node;
+
+                    // go through the path list and set the current node
+                    for (int i = 0; i < lastTreeNodePath.size(); i++)
+                    {
+                        node = m_d->m_currentNode->getChildByName(lastTreeNodePath.at(i));
+                        if (node != NULL)
+                        {
+                            // check if the node name is the same as the currently selected
+                            // one in the saved tree list. if yes then we are on the right
+                            // way down the video tree to find the last saved position
+                            if (node->getString().compare(lastTreeNodePath.at(i)) == 0)
+                            { 
+                                // set the folder as the new node so we can travel further down
+                                // dont do this if its the last part of the saved video path tree
+                                if (node->getInt() == kSubFolder &&
+                                    node->childCount() > 1 &&
+                                    i < lastTreeNodePath.size()-1)
+                                {
+                                    SetCurrentNode(node);
+                                }
+                                // in the last run the selectedNode will be the last
+                                // entry of the saved tree node.
+                                if (lastTreeNodePath.at(i) == lastTreeNodePath.last())
+                                    selectedNode = node;
+                            }
+                        }
+                    }
+
+                    m_d->m_firstLoadPass = false;
+                }
+            }
+        }
+        				
         typedef QList<MythGenericTree *> MGTreeChildList;
         MGTreeChildList *lchildren = m_d->m_currentNode->getAllChildren();
 
@@ -2810,6 +2864,16 @@
 
     if (node)
         node->becomeSelectedChild();
+
+    // save the path and the item name only if we have already
+    // loaded the previously saved tree node path from the database.
+    if (!m_d->m_firstLoadPass)
+    {
+        m_d->m_lastTreeNodePath = m_d->m_currentNode->getRouteByString().join("\n");
+        m_d->m_lastTreeNodePath.append("\n").append( m_d->m_currentNode->getSelectedChild()->getString() );
+
+        VERBOSE(VB_IMPORTANT, QString("Saved m_lastTreeNodePath '%1'").arg(m_d->m_lastTreeNodePath));
+    }
 }
 
 /** \fn VideoDialog::VideoMenu()

