m_filter(),
m_filteredItems(),
m_requestRole(),
- m_minimumUpdateIntervalTimer(0),
m_maximumUpdateIntervalTimer(0),
m_resortAllItemsTimer(0),
m_pendingItemsToInsert(),
- m_pendingEmitLoadingCompleted(false),
m_groups(),
m_expandedParentsCountRoot(UninitializedExpandedParentsCountRoot),
m_expandedUrls(),
connect(dirLister, SIGNAL(clear()), this, SLOT(slotClear()));
connect(dirLister, SIGNAL(clear(KUrl)), this, SLOT(slotClear(KUrl)));
- // Although the layout engine of KItemListView is fast it is very inefficient to e.g.
- // emit 50 itemsInserted()-signals each 100 ms. m_minimumUpdateIntervalTimer assures that updates
- // are done in 1 second intervals for equal operations.
- m_minimumUpdateIntervalTimer = new QTimer(this);
- m_minimumUpdateIntervalTimer->setInterval(1000);
- m_minimumUpdateIntervalTimer->setSingleShot(true);
- connect(m_minimumUpdateIntervalTimer, SIGNAL(timeout()), this, SLOT(dispatchPendingItemsToInsert()));
-
// For slow KIO-slaves like used for searching it makes sense to show results periodically even
// before the completed() or canceled() signal has been emitted.
m_maximumUpdateIntervalTimer = new QTimer(this);
m_resortAllItemsTimer->setSingleShot(true);
connect(m_resortAllItemsTimer, SIGNAL(timeout()), this, SLOT(resortAllItems()));
- Q_ASSERT(m_minimumUpdateIntervalTimer->interval() <= m_maximumUpdateIntervalTimer->interval());
-
connect(KGlobalSettings::self(), SIGNAL(naturalSortingChanged()), this, SLOT(slotNaturalSortingChanged()));
}
void KFileItemModel::slotCompleted()
{
- if (m_urlsToExpand.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) {
- // dispatchPendingItems() will be called when the timer
- // has been expired.
- m_pendingEmitLoadingCompleted = true;
- return;
- }
-
- m_pendingEmitLoadingCompleted = false;
dispatchPendingItemsToInsert();
if (!m_urlsToExpand.isEmpty()) {
}
emit loadingCompleted();
- m_minimumUpdateIntervalTimer->start();
}
void KFileItemModel::slotCanceled()
{
- m_minimumUpdateIntervalTimer->stop();
m_maximumUpdateIntervalTimer->stop();
dispatchPendingItemsToInsert();
}
m_filteredItems.clear();
m_groups.clear();
- m_minimumUpdateIntervalTimer->stop();
m_maximumUpdateIntervalTimer->stop();
m_resortAllItemsTimer->stop();
m_pendingItemsToInsert.clear();
insertItems(m_pendingItemsToInsert);
m_pendingItemsToInsert.clear();
}
-
- if (m_pendingEmitLoadingCompleted) {
- emit loadingCompleted();
- }
}
void KFileItemModel::insertItems(const KFileItemList& items)
bool m_requestRole[RolesCount];
- QTimer* m_minimumUpdateIntervalTimer;
QTimer* m_maximumUpdateIntervalTimer;
QTimer* m_resortAllItemsTimer;
KFileItemList m_pendingItemsToInsert;
- bool m_pendingEmitLoadingCompleted;
// Cache for KFileItemModel::groups()
mutable QList<QPair<int, QVariant> > m_groups;
void testDefaultGroupedSorting();
void testNewItems();
void testRemoveItems();
+ void testLoadingCompleted();
void testSetData();
void testSetDataWithModifiedSortRole_data();
void testSetDataWithModifiedSortRole();
m_testDir = new TestDir();
m_dirLister = new KDirLister();
+ m_dirLister->setAutoUpdate(false);
m_model = new KFileItemModel(m_dirLister);
}
QVERIFY(isModelConsistent());
}
+void KFileItemModelTest::testLoadingCompleted()
+{
+ QSignalSpy loadingCompletedSpy(m_model, SIGNAL(loadingCompleted()));
+ QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+
+ m_testDir->createFiles(QStringList() << "a.txt" << "b.txt" << "c.txt");
+
+ m_dirLister->openUrl(m_testDir->url());
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+ QCOMPARE(loadingCompletedSpy.count(), 1);
+ QCOMPARE(itemsInsertedSpy.count(), 1);
+ QCOMPARE(itemsRemovedSpy.count(), 0);
+ QCOMPARE(m_model->count(), 3);
+
+ m_testDir->createFiles(QStringList() << "d.txt" << "e.txt");
+ m_dirLister->updateDirectory(m_testDir->url());
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+ QCOMPARE(loadingCompletedSpy.count(), 2);
+ QCOMPARE(itemsInsertedSpy.count(), 2);
+ QCOMPARE(itemsRemovedSpy.count(), 0);
+ QCOMPARE(m_model->count(), 5);
+
+ m_testDir->removeFile("a.txt");
+ m_testDir->createFile("f.txt");
+ m_dirLister->updateDirectory(m_testDir->url());
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
+ QCOMPARE(loadingCompletedSpy.count(), 3);
+ QCOMPARE(itemsInsertedSpy.count(), 3);
+ QCOMPARE(itemsRemovedSpy.count(), 1);
+ QCOMPARE(m_model->count(), 5);
+
+ m_testDir->removeFile("b.txt");
+ m_dirLister->updateDirectory(m_testDir->url());
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout));
+ QCOMPARE(loadingCompletedSpy.count(), 4);
+ QCOMPARE(itemsInsertedSpy.count(), 3);
+ QCOMPARE(itemsRemovedSpy.count(), 2);
+ QCOMPARE(m_model->count(), 4);
+
+ QVERIFY(isModelConsistent());
+}
+
void KFileItemModelTest::testSetData()
{
m_testDir->createFile("a.txt");
// one itemsInserted()-signal. However in this test we want to stress
// KFileItemModel to do a lot of insert operation and hence decrease
// the timeout to 1 millisecond.
- m_model->m_minimumUpdateIntervalTimer->setInterval(1);
-
m_testDir->createFile("1");
m_dirLister->openUrl(m_testDir->url());
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
void DolphinView::slotLoadingCompleted()
{
// Update the view-state. This has to be done using a Qt::QueuedConnection
- // because the view might not be in its final state yet (the view also
- // listens to the completed()-signal from KDirLister and the order of
- // of slots is undefined).
+ // because the view might not be in its final state yet.
QTimer::singleShot(0, this, SLOT(updateViewState()));
emit finishedPathLoading(url());