Commit 8141788c authored by David Faure's avatar David Faure

Fix KDirLister's rootItem not being updated when renaming the directory.

The root item kept having the old URL.

Thanks to Emmanuel for the bug investigation, and to Frank for the unittest!

BUG: 294445
FIXED-IN: 4.9.5
parent 52ee7642
......@@ -2709,8 +2709,11 @@ void KDirLister::setDelayedMimeTypes( bool delayedMimeTypes )
void KDirLister::Private::redirect(const KUrl& oldUrl, const KUrl& newUrl, bool keepItems)
{
if ( url.equals( oldUrl, KUrl::CompareWithoutTrailingSlash ) ) {
if (!keepItems)
if (!keepItems) {
rootFileItem = KFileItem();
} else {
rootFileItem.setUrl(newUrl);
}
url = newUrl;
}
......
......@@ -933,6 +933,33 @@ void KDirListerTest::testBug211472()
QVERIFY(QTest::kWaitForSignal(&dirLister, SIGNAL(clear()), 1000));
}
void KDirListerTest::testRenameCurrentDir() // #294445
{
m_items.clear();
const QString path = m_tempDir.name() + "newsubdir-1";
QVERIFY(QDir().mkdir(path));
MyDirLister secondDirLister;
connect(&secondDirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(slotNewItems(KFileItemList)));
secondDirLister.openUrl(KUrl(path));
QVERIFY(QTest::kWaitForSignal(&secondDirLister, SIGNAL(completed()), 1000));
QVERIFY(secondDirLister.isFinished());
QVERIFY(m_items.empty());
QCOMPARE(secondDirLister.rootItem().url().toLocalFile(), path);
const QString newPath = m_tempDir.name() + "newsubdir-2";
QVERIFY(QDir().rename(path, newPath));
org::kde::KDirNotify::emitFileRenamed(KUrl(path).url(), KUrl(newPath).url());
QVERIFY(QTest::kWaitForSignal(&secondDirLister, SIGNAL(redirection(KUrl,KUrl)), 1000));
// Check that the URL of the root item got updated
QCOMPARE(secondDirLister.rootItem().url().toLocalFile(), newPath);
disconnect(&secondDirLister, 0, this, 0);
QDir().remove(newPath);
}
void KDirListerTest::testRedirection()
{
m_items.clear();
......
......@@ -107,6 +107,7 @@ private Q_SLOTS:
void testOpenUrlTwiceWithKeep();
void testOpenAndStop();
void testBug211472();
void testRenameCurrentDir();
void testRedirection();
void testDeleteCurrentDir(); // must be last!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment