diff --git a/autotests/kfileitemtest.cpp b/autotests/kfileitemtest.cpp --- a/autotests/kfileitemtest.cpp +++ b/autotests/kfileitemtest.cpp @@ -448,21 +448,22 @@ QTest::addColumn("expectedDeleting"); QTest::addColumn("expectedIsLocal"); QTest::addColumn("expectedIsDirectory"); + QTest::addColumn("expectedIsFile"); QTest::addColumn("expectedMimeType"); QTest::addColumn("expectedMimeGroup"); - QTest::newRow("one file") << "f" << true << true << true << false << "text/plain" << "text"; - QTest::newRow("one dir") << "d" << true << true << true << true << "inode/directory" << "inode"; - QTest::newRow("root dir") << "/" << true << false << true << true << "inode/directory" << "inode"; - QTest::newRow("file+dir") << "fd" << true << true << true << false << "" << ""; - QTest::newRow("two dirs") << "dd" << true << true << true << true << "inode/directory" << "inode"; - QTest::newRow("dir+root dir") << "d/" << true << false << true << true << "inode/directory" << "inode"; - QTest::newRow("two (text+html) files") << "ff" << true << true << true << false << "" << "text"; - QTest::newRow("three (text+html+empty) files") << "fff" << true << true << true << false << "" << ""; + QTest::newRow("one file") << "f" << true << true << true << false << true << "text/plain" << "text"; + QTest::newRow("one dir") << "d" << true << true << true << true << false << "inode/directory" << "inode"; + QTest::newRow("root dir") << "/" << true << false << true << true << false << "inode/directory" << "inode"; + QTest::newRow("file+dir") << "fd" << true << true << true << false << false << "" << ""; + QTest::newRow("two dirs") << "dd" << true << true << true << true << false << "inode/directory" << "inode"; + QTest::newRow("dir+root dir") << "d/" << true << false << true << true << false << "inode/directory" << "inode"; + QTest::newRow("two (text+html) files") << "ff" << true << true << true << false << true << "" << "text"; + QTest::newRow("three (text+html+empty) files") << "fff" << true << true << true << false << true << "" << ""; QTest::newRow("http url") << "h" << true << true /*says kio_http...*/ - << false << false << "application/octet-stream" << "application"; + << false << false << true << "application/octet-stream" << "application"; QTest::newRow("2 http urls") << "hh" << true << true /*says kio_http...*/ - << false << false << "application/octet-stream" << "application"; + << false << false << true << "application/octet-stream" << "application"; } void KFileItemTest::testListProperties() @@ -472,6 +473,7 @@ QFETCH(bool, expectedDeleting); QFETCH(bool, expectedIsLocal); QFETCH(bool, expectedIsDirectory); + QFETCH(bool, expectedIsFile); QFETCH(QString, expectedMimeType); QFETCH(QString, expectedMimeGroup); @@ -512,6 +514,7 @@ QCOMPARE(props.supportsDeleting(), expectedDeleting); QCOMPARE(props.isLocal(), expectedIsLocal); QCOMPARE(props.isDirectory(), expectedIsDirectory); + QCOMPARE(props.isFile(), expectedIsFile); QCOMPARE(props.mimeType(), expectedMimeType); QCOMPARE(props.mimeGroup(), expectedMimeGroup); } diff --git a/src/core/kfileitemlistproperties.h b/src/core/kfileitemlistproperties.h --- a/src/core/kfileitemlistproperties.h +++ b/src/core/kfileitemlistproperties.h @@ -123,6 +123,12 @@ */ bool isDirectory() const; + /** + * @return Whether all items are files, as reported by KFileItem::isFile(). + * @since 5.47 + */ + bool isFile() const; + /** * @return the mimetype of all items, if they all have the same, otherwise empty */ diff --git a/src/core/kfileitemlistproperties.cpp b/src/core/kfileitemlistproperties.cpp --- a/src/core/kfileitemlistproperties.cpp +++ b/src/core/kfileitemlistproperties.cpp @@ -32,6 +32,7 @@ public: KFileItemListPropertiesPrivate() : m_isDirectory(false), + m_isFile(false), m_supportsReading(false), m_supportsDeleting(false), m_supportsWriting(false), @@ -46,6 +47,7 @@ mutable QString m_mimeType; mutable QString m_mimeGroup; bool m_isDirectory : 1; + bool m_isFile : 1; bool m_supportsReading : 1; bool m_supportsDeleting : 1; bool m_supportsWriting : 1; @@ -78,6 +80,7 @@ m_supportsWriting = initialValue; m_supportsMoving = initialValue; m_isDirectory = initialValue; + m_isFile = initialValue; m_isLocal = true; m_mimeType.clear(); m_mimeGroup.clear(); @@ -113,6 +116,10 @@ if (m_isDirectory && !item.isDir()) { m_isDirectory = false; } + + if (m_isFile && !item.isFile()) { + m_isFile = false; + } } } @@ -170,6 +177,11 @@ return d->m_isDirectory; } +bool KFileItemListProperties::isFile() const +{ + return d->m_isFile; +} + QString KFileItemListProperties::mimeType() const { if (d->m_mimeType.isEmpty()) {