]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Combine modificationtime, creationtime and accesstime roles into one group
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index d4d0be0e8b2332a124526941e1dc3df2d0111638..da9bcd0fee0c8483f70eb3b4aea17041c4dda276 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <KDirLister>
 #include <KIO/Job>
+#include <kio_version.h>
 #include <KLocalizedString>
 #include <KLazyLocalizedString>
 #include <KUrlMimeData>
@@ -575,6 +576,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 +594,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;
@@ -1573,6 +1580,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 +1802,10 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
         data.insert(sharedValue("text"), item.text());
     }
 
+    if (m_requestRole[ExtensionRole]) {
+        data.insert(sharedValue("extension"), QFileInfo(item.name()).suffix());
+    }
+
     if (m_requestRole[SizeRole] && !isDir) {
         data.insert(sharedValue("size"), item.size());
     }
@@ -2089,6 +2101,19 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
         break;
     }
 
+   case DimensionsRole: {
+        const QByteArray role = roleForType(m_sortRole);
+        const QSize dimensionsA = a->values.value(role).toSize();
+        const QSize dimensionsB = b->values.value(role).toSize();
+
+        if (dimensionsA.width() == dimensionsB.width()) {
+            result = dimensionsA.height() - dimensionsB.height();
+        } else {
+            result = dimensionsA.width() - dimensionsB.width();
+        }
+        break;
+    }
+
     default: {
         const QByteArray role = roleForType(m_sortRole);
         const QString roleValueA = a->values.value(role).toString();
@@ -2585,17 +2610,20 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
         { nullptr,               NoRole,                  KLazyLocalizedString(),                    KLazyLocalizedString(),                            false,           false },
         { "text",                NameRole,                kli18nc("@label", "Name"),                 KLazyLocalizedString(),                            false,           false },
         { "size",                SizeRole,                kli18nc("@label", "Size"),                 KLazyLocalizedString(),                            false,           false },
-        { "modificationtime",    ModificationTimeRole,    kli18nc("@label", "Modified"),             KLazyLocalizedString(),                            false,           false },
-        { "creationtime",        CreationTimeRole,        kli18nc("@label", "Created"),              KLazyLocalizedString(),                            false,           false },
-        { "accesstime",          AccessTimeRole,          kli18nc("@label", "Accessed"),             KLazyLocalizedString(),                            false,           false },
         { "type",                TypeRole,                kli18nc("@label", "Type"),                 KLazyLocalizedString(),                            false,           false },
+        { "extension",           ExtensionRole,           kli18nc("@label", "Extension"),            KLazyLocalizedString(),                            false,           false },
         { "rating",              RatingRole,              kli18nc("@label", "Rating"),               KLazyLocalizedString(),                            true,            false },
         { "tags",                TagsRole,                kli18nc("@label", "Tags"),                 KLazyLocalizedString(),                            true,            false },
         { "comment",             CommentRole,             kli18nc("@label", "Comment"),              KLazyLocalizedString(),                            true,            false },
+        { "modificationtime",    ModificationTimeRole,    kli18nc("@label", "Modified"),             kli18nc("@label", "Date"),                         false,           false },
+        { "creationtime",        CreationTimeRole,        kli18nc("@label", "Created"),              kli18nc("@label", "Date"),                         false,           false },
+        { "accesstime",          AccessTimeRole,          kli18nc("@label", "Accessed"),             kli18nc("@label", "Date"),                         false,           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  },
+        { "dimensions",          DimensionsRole,          kli18nc("@label width x height", "Dimensions"), kli18nc("@label", "Image"),                   true,            true  },
         { "width",               WidthRole,               kli18nc("@label", "Width"),                kli18nc("@label", "Image"),                        true,            true  },
         { "height",              HeightRole,              kli18nc("@label", "Height"),               kli18nc("@label", "Image"),                        true,            true  },
         { "orientation",         OrientationRole,         kli18nc("@label", "Orientation"),          kli18nc("@label", "Image"),                        true,            true  },