]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Do not rely on KIO source-code compat code
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index 629332703685f561b75dd18261fcf95ab19f5570..4463b37ae3f747fc54673c6c6ae9608a6b7e38fc 100644 (file)
@@ -15,9 +15,9 @@
 
 #include <KDirLister>
 #include <KIO/Job>
+#include <KIO/ListJob>
 #include <KLocalizedString>
 #include <KUrlMimeData>
-#include <kio_version.h>
 
 #include <QElapsedTimer>
 #include <QIcon>
@@ -26,7 +26,6 @@
 #include <QRecursiveMutex>
 #include <QTimer>
 #include <QWidget>
-#include <algorithm>
 #include <klazylocalizedstring.h>
 
 Q_GLOBAL_STATIC(QRecursiveMutex, s_collatorMutex)
@@ -100,7 +99,7 @@ KFileItemModel::KFileItemModel(QObject *parent)
     // for a lot of items within a quite small timeslot. To prevent expensive resortings the
     // resorting is postponed until the timer has been exceeded.
     m_resortAllItemsTimer = new QTimer(this);
-    m_resortAllItemsTimer->setInterval(500);
+    m_resortAllItemsTimer->setInterval(50);
     m_resortAllItemsTimer->setSingleShot(true);
     connect(m_resortAllItemsTimer, &QTimer::timeout, this, &KFileItemModel::resortAllItems);
 
@@ -261,13 +260,16 @@ void KFileItemModel::setShowTrashMime(bool show)
     }
 }
 
+void KFileItemModel::scheduleResortAllItems()
+{
+    if (!m_resortAllItemsTimer->isActive()) {
+        m_resortAllItemsTimer->start();
+    }
+}
+
 void KFileItemModel::setShowHiddenFiles(bool show)
 {
-#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0)
-    m_dirLister->setShowingDotFiles(show);
-#else
     m_dirLister->setShowHiddenFiles(show);
-#endif
     setShowTrashMime(show);
     m_dirLister->emitChanges();
     if (show) {
@@ -277,11 +279,7 @@ void KFileItemModel::setShowHiddenFiles(bool show)
 
 bool KFileItemModel::showHiddenFiles() const
 {
-#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0)
-    return m_dirLister->showingDotFiles();
-#else
     return m_dirLister->showHiddenFiles();
-#endif
 }
 
 void KFileItemModel::setShowDirectoriesOnly(bool enabled)
@@ -624,9 +622,7 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
 
         m_expandedDirs.remove(targetUrl);
         m_dirLister->stop(url);
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0)
         m_dirLister->forgetDirs(url);
-#endif
 
         const int parentLevel = expandedParentsCount(index);
         const int itemCount = m_itemData.count();
@@ -642,9 +638,7 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
                 const QUrl url = itemData->item.url();
                 m_expandedDirs.remove(targetUrl);
                 m_dirLister->stop(url); // TODO: try to unit-test this, see https://bugs.kde.org/show_bug.cgi?id=332102#c11
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0)
                 m_dirLister->forgetDirs(url);
-#endif
                 expandedChildren.append(targetUrl);
             }
             ++childIndex;
@@ -994,7 +988,7 @@ void KFileItemModel::resortAllItems()
     // been moved because of the resorting.
     QList<QUrl> oldUrls;
     oldUrls.reserve(itemCount);
-    for (const ItemData *itemData : qAsConst(m_itemData)) {
+    for (const ItemData *itemData : std::as_const(m_itemData)) {
         oldUrls.append(itemData->item.url());
     }
 
@@ -1209,7 +1203,12 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items)
 
     for (const KFileItem &item : items) {
         if (item.url() == currentDir) {
-            Q_EMIT currentDirectoryRemoved();
+            // #473377: Delay emitting currentDirectoryRemoved() to avoid modifying KCoreDirLister
+            // before KCoreDirListerCache::deleteDir() returns.
+            QTimer::singleShot(0, this, [this] {
+                Q_EMIT currentDirectoryRemoved();
+            });
+
             return;
         }
 
@@ -1239,7 +1238,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items)
         indexesToRemoveWithChildren.reserve(m_itemData.count());
 
         const int itemCount = m_itemData.count();
-        for (int index : qAsConst(indexesToRemove)) {
+        for (int index : std::as_const(indexesToRemove)) {
             indexesToRemoveWithChildren.append(index);
 
             const int parentLevel = expandedParentsCount(index);
@@ -1657,7 +1656,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData *> &itemDataList)
     case DeletionTimeRole:
         // These roles can be determined with retrieveData, and they have to be stored
         // in the QHash "values" for the sorting.
-        for (ItemData *itemData : qAsConst(itemDataList)) {
+        for (ItemData *itemData : std::as_const(itemDataList)) {
             if (itemData->values.isEmpty()) {
                 itemData->values = retrieveData(itemData->item, itemData->parent);
             }
@@ -1666,7 +1665,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData *> &itemDataList)
 
     case TypeRole:
         // At least store the data including the file type for items with known MIME type.
-        for (ItemData *itemData : qAsConst(itemDataList)) {
+        for (ItemData *itemData : std::as_const(itemDataList)) {
             if (itemData->values.isEmpty()) {
                 const KFileItem item = itemData->item;
                 if (item.isDir() || item.isMimeTypeKnown()) {
@@ -2606,7 +2605,7 @@ QList<QPair<int, QVariant>> KFileItemModel::permissionRoleGroups() const
         if (info.permission(QFile::ExeUser)) {
             user += i18nc("@item:intext Access permission, concatenated", "Execute, ");
         }
-        user = user.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : user.mid(0, user.count() - 2);
+        user = user.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : user.mid(0, user.length() - 2);
 
         // Set group string
         QString group;
@@ -2619,7 +2618,7 @@ QList<QPair<int, QVariant>> KFileItemModel::permissionRoleGroups() const
         if (info.permission(QFile::ExeGroup)) {
             group += i18nc("@item:intext Access permission, concatenated", "Execute, ");
         }
-        group = group.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : group.mid(0, group.count() - 2);
+        group = group.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : group.mid(0, group.length() - 2);
 
         // Set others string
         QString others;
@@ -2632,7 +2631,7 @@ QList<QPair<int, QVariant>> KFileItemModel::permissionRoleGroups() const
         if (info.permission(QFile::ExeOther)) {
             others += i18nc("@item:intext Access permission, concatenated", "Execute, ");
         }
-        others = others.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : others.mid(0, others.count() - 2);
+        others = others.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : others.mid(0, others.length() - 2);
 
         const QString newGroupValue = i18nc("@title:group Files and folders by permissions", "User: %1 | Group: %2 | Others: %3", user, group, others);
         if (newGroupValue != groupValue) {
@@ -2863,3 +2862,5 @@ void KFileItemModel::slotListerError(KIO::Job *job)
         Q_EMIT errorMessage(!errorString.isEmpty() ? errorString : i18nc("@info:status", "Unknown error."));
     }
 }
+
+#include "moc_kfileitemmodel.cpp"