┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2011-11-24 23:38:36 +0100
committerFrank Reininghaus <[email protected]>2011-11-24 23:38:36 +0100
commit3950eccaf08374862ba848eac5319645d6a0f0d9 (patch)
tree6f1a2355b2a7751fd44dfe3dd8cb3ac223f88290
parentc0feb043e099620f50d3698c15219131973ed4f0 (diff)
Fix restoring expanded URLs
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.
-rw-r--r--src/kitemviews/kfileitemmodel.cpp5
-rw-r--r--src/kitemviews/kfileitemmodel.h7
-rw-r--r--src/tests/kfileitemmodeltest.cpp13
-rw-r--r--src/views/dolphinview.cpp2
4 files changed, 25 insertions, 2 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 363503b02..040309dc3 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -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)
{
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index a049f6766..17524b82a 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -122,6 +122,13 @@ public:
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.
*/
void setExpanded(const QSet<KUrl>& urls);
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index f2d62fbad..59e817fff 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -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()
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 578b93a2b..91d668e9d 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -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)