]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Exit the deleted directory when it is removed
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index 23afb087a31a29d09730529f8f7cbd50db37b694..c08f8e964b3cd9e34532d6f92df1d2aeba9f2f8e 100644 (file)
@@ -15,8 +15,8 @@
 
 #include <KDirLister>
 #include <KIO/Job>
+#include <kio_version.h>
 #include <KLocalizedString>
-#include <KLazyLocalizedString>
 #include <KUrlMimeData>
 
 #include <QElapsedTimer>
@@ -238,7 +238,11 @@ bool KFileItemModel::sortHiddenLast() const
 
 void KFileItemModel::setShowHiddenFiles(bool show)
 {
+#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0)
     m_dirLister->setShowingDotFiles(show);
+#else
+    m_dirLister->setShowHiddenFiles(show);
+#endif
     m_dirLister->emitChanges();
     if (show) {
         dispatchPendingItemsToInsert();
@@ -247,7 +251,11 @@ 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)
@@ -575,6 +583,9 @@ 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();
@@ -590,6 +601,9 @@ 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;
@@ -1136,7 +1150,14 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
     indexesToRemove.reserve(items.count());
     KFileItemList dirsChanged;
 
+    const auto currentDir = directory();
+
     for (const KFileItem& item : items) {
+        if (item.url() == currentDir) {
+            Q_EMIT currentDirectoryRemoved();
+            return;
+        }
+
         const int indexForItem = index(item);
         if (indexForItem >= 0) {
             indexesToRemove.append(indexForItem);
@@ -1573,6 +1594,7 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl&
 void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
 {
     switch (m_sortRole) {
+    case ExtensionRole:
     case PermissionsRole:
     case OwnerRole:
     case GroupRole:
@@ -1794,6 +1816,10 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
         data.insert(sharedValue("text"), item.text());
     }
 
+    if (m_requestRole[ExtensionRole] && !isDir) {
+        data.insert(sharedValue("extension"), QFileInfo(item.name()).suffix());
+    }
+
     if (m_requestRole[SizeRole] && !isDir) {
         data.insert(sharedValue("size"), item.size());
     }
@@ -2056,6 +2082,17 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
         break;
     }
 
+    case AccessTimeRole: {
+        const long long dateTimeA = itemA.entry().numberValue(KIO::UDSEntry::UDS_ACCESS_TIME, -1);
+        const long long dateTimeB = itemB.entry().numberValue(KIO::UDSEntry::UDS_ACCESS_TIME, -1);
+        if (dateTimeA < dateTimeB) {
+            return -1;
+        } else if (dateTimeA > dateTimeB) {
+            return +1;
+        }
+        break;
+    }
+
     case CreationTimeRole: {
         const long long dateTimeA = itemA.entry().numberValue(KIO::UDSEntry::UDS_CREATION_TIME, -1);
         const long long dateTimeB = itemB.entry().numberValue(KIO::UDSEntry::UDS_CREATION_TIME, -1);
@@ -2606,6 +2643,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
         { "tags",                TagsRole,                kli18nc("@label", "Tags"),                 KLazyLocalizedString(),                            true,            false },
         { "comment",             CommentRole,             kli18nc("@label", "Comment"),              KLazyLocalizedString(),                            true,            false },
         { "title",               TitleRole,               kli18nc("@label", "Title"),                kli18nc("@label", "Document"),                     true,            true  },
+        { "author",              AuthorRole,              kli18nc("@label", "Author"),               kli18nc("@label", "Document"),                     true,            true  },
         { "wordCount",           WordCountRole,           kli18nc("@label", "Word Count"),           kli18nc("@label", "Document"),                     true,            true  },
         { "lineCount",           LineCountRole,           kli18nc("@label", "Line Count"),           kli18nc("@label", "Document"),                     true,            true  },
         { "imageDateTime",       ImageDateTimeRole,       kli18nc("@label", "Date Photographed"),    kli18nc("@label", "Image"),                        true,            true  },
@@ -2623,6 +2661,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
         { "aspectRatio",         AspectRatioRole,         kli18nc("@label", "Aspect Ratio"),         kli18nc("@label", "Video"),                        true,            true  },
         { "frameRate",           FrameRateRole,           kli18nc("@label", "Frame Rate"),           kli18nc("@label", "Video"),                        true,            true  },
         { "path",                PathRole,                kli18nc("@label", "Path"),                 kli18nc("@label", "Other"),                        false,           false },
+        { "extension",           ExtensionRole,           kli18nc("@label", "File Extension"),       kli18nc("@label", "Other"),                        false,           false },
         { "deletiontime",        DeletionTimeRole,        kli18nc("@label", "Deletion Time"),        kli18nc("@label", "Other"),                        false,           false },
         { "destination",         DestinationRole,         kli18nc("@label", "Link Destination"),     kli18nc("@label", "Other"),                        false,           false },
         { "originUrl",           OriginUrlRole,           kli18nc("@label", "Downloaded From"),      kli18nc("@label", "Other"),                        true,            false },