]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix restoring expanded URLs
authorFrank Reininghaus <frank78ac@googlemail.com>
Thu, 24 Nov 2011 22:38:36 +0000 (23:38 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Thu, 24 Nov 2011 22:38:36 +0000 (23:38 +0100)
When navigating back or forward in history, DolphinView tells the
KFileItemModel about the expanded URLs which should be restored before
the folder is entered. In this case, the algorithm in the new function
KFileItemModel::setExpanded(const QSet<KUrl>&) does not work. To fix
this, the old function
KFileItemModel::restoreExpandedUrls(const QSet<KUrl>&) is restored.

Unit test included.

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/tests/kfileitemmodeltest.cpp
src/views/dolphinview.cpp

index 363503b02d18c11dda4ad345840adfc29b11edc8..040309dc319b62bc7751dc16f2a6d9ef6628e531 100644 (file)
@@ -431,6 +431,11 @@ QSet<KUrl> KFileItemModel::expandedUrls() const
     return m_expandedUrls;
 }
 
+void KFileItemModel::restoreExpandedUrls(const QSet<KUrl>& urls)
+{
+    m_urlsToExpand = urls;
+}
+
 void KFileItemModel::setExpanded(const QSet<KUrl>& urls)
 {
 
index a049f6766efa713629a9e10c6b5f4c382de0a70f..17524b82a20dcb28cfe91eb9eece2d9c8e9db138 100644 (file)
@@ -121,6 +121,13 @@ public:
     bool isExpandable(int index) const;
     QSet<KUrl> expandedUrls() const;
 
+    /**
+     * Marks the URLs in \a urls as subfolders which were expanded previously.
+     * They are re-expanded one by one each time the KDirLister's completed() signal is received.
+     * Note that a manual triggering of the KDirLister is required.
+     */
+    void restoreExpandedUrls(const QSet<KUrl>& urls);
+
     /**
      * Expands all parent-items of each URL given by \a urls.
      */
index f2d62fbad573c3abfdf37536172994378cdc86a8..59e817fff7c6a701e0ad19dea2e3995c4faaa931 100644 (file)
@@ -451,7 +451,7 @@ void KFileItemModelTest::testExpandItems()
     QVERIFY(m_model->expandedUrls().empty());
 
     m_dirLister->openUrl(m_testDir->url());
-    m_model->setExpanded(allFolders);
+    m_model->restoreExpandedUrls(allFolders);
     QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
     QCOMPARE(m_model->count(), 5);  // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
     QVERIFY(m_model->isExpanded(0));
@@ -460,6 +460,17 @@ void KFileItemModelTest::testExpandItems()
     QVERIFY(m_model->isExpanded(3));
     QVERIFY(!m_model->isExpanded(4));
     QCOMPARE(m_model->expandedUrls(), allFolders);
+
+    // Move to a sub folder, then call restoreExpandedFolders() *before* going back.
+    // This is how DolphinView restores the expanded folders when navigating in history.
+    m_dirLister->openUrl(KUrl(m_testDir->name() + "a/a/"));
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+    QCOMPARE(m_model->count(), 1);  // 1 item: "1"
+    m_model->restoreExpandedUrls(allFolders);
+    m_dirLister->openUrl(m_testDir->url());
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+    QCOMPARE(m_model->count(), 5);  // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
+    QCOMPARE(m_model->expandedUrls(), allFolders);
 }
 
 void KFileItemModelTest::testSorting()
index 578b93a2b6b85e112fded8b7e401cfbe7c81ebeb..91d668e9d6bd8fa70d8e076f4d3b4bf9b77e5d1b 100644 (file)
@@ -943,7 +943,7 @@ void DolphinView::restoreState(QDataStream& stream)
     // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
     QSet<KUrl> urls;
     stream >> urls;
-    fileItemModel()->setExpanded(urls);
+    fileItemModel()->restoreExpandedUrls(urls);
 }
 
 void DolphinView::saveState(QDataStream& stream)