]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinitemcategorizer.cpp
don't use deprecated KGlobalSettings::xxxColor() methods anymore
[dolphin.git] / src / dolphinitemcategorizer.cpp
index 0f55881c43183e6e0725e69fca1919622b97b9f9..88e6733c9eaa3dff0c7886753f5130e8ae4de959 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <klocale.h>
 #include <kdirmodel.h>
+#include <kdatetime.h>
 
 #include <QtGui/QSortFilterProxyModel>
 
@@ -46,10 +47,39 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
         return retString;
     }
 
+    int column;
+
+    switch (sortRole)
+    {
+        case DolphinView::SortByName:        // KDirModel::Name
+            column = KDirModel::Name;
+            break;
+        case DolphinView::SortBySize:        // KDirModel::Size
+            column = KDirModel::Size;
+            break;
+        case DolphinView::SortByDate:        // KDirModel::ModifiedTime
+            column = KDirModel::ModifiedTime;
+            break;
+        case DolphinView::SortByPermissions: // KDirModel::Permissions
+            column = KDirModel::Permissions;
+            break;
+        case DolphinView::SortByOwner:       // KDirModel::Owner
+            column = KDirModel::Owner;
+            break;
+        case DolphinView::SortByGroup:       // KDirModel::Group
+            column = KDirModel::Group;
+            break;
+        case DolphinView::SortByType:         // KDirModel::Type
+            column = KDirModel::Type;
+            break;
+        default:
+            column = KDirModel::Name;
+    }
+
     // KDirModel checks columns to know to which role are
     // we talking about
     QModelIndex theIndex = index.model()->index(index.row(),
-                                                sortRole,
+                                                column,
                                                 index.parent());
 
     if (!theIndex.isValid()) {
@@ -60,11 +90,12 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
 
     const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model());
     KFileItem *item = dirModel->itemForIndex(index);
-    int fileSize;
 
+    int fileSize;
+    KDateTime modifiedTime;
     switch (sortRole)
     {
-        case KDirModel::Name:
+        case DolphinView::SortByName:
             if (data.toString().size())
             {
                 if (!item->isHidden() && data.toString().at(0).isLetter())
@@ -80,11 +111,58 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
                 else if (item->isHidden())
                     retString = data.toString().toUpper().at(0);
                 else
-                    retString = i18n("Others");
+                {
+                    bool validCategory = false;
+
+                    const QChar* currA = data.toString().toUpper().unicode(); // iterator over a
+                    while (!currA->isNull() && !validCategory) {
+                        if (currA->isLetter())
+                            validCategory = true;
+                        else if (currA->isDigit())
+                            return i18n("Others");
+                        else
+                            ++currA;
+                    }
+
+                    if (!validCategory)
+                        retString = i18n("Others");
+                    else
+                        retString = *currA;
+                }
             }
             break;
 
-        case KDirModel::Size:
+        case DolphinView::SortByDate:
+            modifiedTime.setTime_t(item->time(KIO::UDS_MODIFICATION_TIME));
+            modifiedTime = modifiedTime.toLocalZone();
+
+            if (modifiedTime.daysTo(KDateTime::currentLocalDateTime()) == 0)
+                retString = i18n("Today");
+            else if (modifiedTime.daysTo(KDateTime::currentLocalDateTime()) == 1)
+                retString = i18n("Yesterday");
+            else if (modifiedTime.daysTo(KDateTime::currentLocalDateTime()) < 7)
+                retString = i18n("Less than a week");
+            else if (modifiedTime.daysTo(KDateTime::currentLocalDateTime()) < 31)
+                retString = i18n("Less than a month");
+            else if (modifiedTime.daysTo(KDateTime::currentLocalDateTime()) < 365)
+                retString = i18n("Less than a year");
+            else
+                retString = i18n("More than a year");
+            break;
+
+        case DolphinView::SortByPermissions:
+            retString = item->permissionsString();
+            break;
+
+        case DolphinView::SortByOwner:
+            retString = item->user();
+            break;
+
+        case DolphinView::SortByGroup:
+            retString = item->group();
+            break;
+
+        case DolphinView::SortBySize:
             fileSize = (item) ? item->size() : -1;
             if (item && item->isDir()) {
                 retString = i18n("Folders");
@@ -97,7 +175,7 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
             }
             break;
 
-        case KDirModel::Type:
+        case DolphinView::SortByType:
             retString = item->mimeComment();
             break;
     }