]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinitemcategorizer.cpp
Draw dragged items. Better conditions (more accurate to our behavior, hey ! we have...
[dolphin.git] / src / dolphinitemcategorizer.cpp
index 38d0e2c16433bee322c40bc3019faa75b118a4db..dfb3840624548550809b8a92a4bdc95043485e5f 100644 (file)
 #include "dolphinitemcategorizer.h"
 
 #include "dolphinview.h"
+#include "dolphinsortfilterproxymodel.h"
+
+#ifdef HAVE_NEPOMUK
+#include <config-nepomuk.h>
+#include <nepomuk/global.h>
+#include <nepomuk/resource.h>
+#endif
 
-#include <klocale.h>
-#include <kdirmodel.h>
 #include <kdatetime.h>
+#include <kdirmodel.h>
+#include <kfileitem.h>
+#include <klocale.h>
+#include <kurl.h>
 
-#include <QtGui/QSortFilterProxyModel>
+#include <QList>
+#include <QSortFilterProxyModel>
 
 DolphinItemCategorizer::DolphinItemCategorizer() :
     KItemCategorizer()
@@ -47,55 +57,24 @@ 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(),
-                                                column,
-                                                index.parent());
-
-    if (!theIndex.isValid()) {
-        return retString;
-    }
-
-    QVariant data = theIndex.model()->data(theIndex, Qt::DisplayRole);
-
     const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model());
     KFileItem *item = dirModel->itemForIndex(index);
 
-    int fileSize;
-    KDateTime modifiedTime;
     switch (sortRole)
     {
         case DolphinView::SortByName:
+        {
+            // KDirModel checks columns to know to which role are
+            // we talking about
+            QModelIndex theIndex = index.model()->index(index.row(),
+                                                        KDirModel::Name,
+                                                        index.parent());
+
+            if (!theIndex.isValid()) {
+                return retString;
+            }
+
+            QVariant data = theIndex.model()->data(theIndex, Qt::DisplayRole);
             if (data.toString().size())
             {
                 if (!item->isHidden() && data.toString().at(0).isLetter())
@@ -132,8 +111,11 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
                 }
             }
             break;
+        }
 
         case DolphinView::SortByDate:
+        {
+            KDateTime modifiedTime;
             modifiedTime.setTime_t(item->time(KIO::UDS_MODIFICATION_TIME));
             modifiedTime = modifiedTime.toLocalZone();
 
@@ -150,6 +132,7 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
             else
                 retString = i18n("More than a year");
             break;
+        }
 
         case DolphinView::SortByPermissions:
             retString = item->permissionsString();
@@ -163,8 +146,8 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
             retString = item->group();
             break;
 
-        case DolphinView::SortBySize:
-            fileSize = (item) ? item->size() : -1;
+        case DolphinView::SortBySize: {
+            const int fileSize = item ? item->size() : -1;
             if (item && item->isDir()) {
                 retString = i18n("Folders");
             } else if (fileSize < 5242880) {
@@ -175,10 +158,32 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
                 retString = i18nc("Size", "Big");
             }
             break;
+        }
 
         case DolphinView::SortByType:
             retString = item->mimeComment();
             break;
+
+#ifdef HAVE_NEPOMUK
+        case DolphinView::SortByRating: {
+            const quint32 rating = DolphinSortFilterProxyModel::ratingForIndex(index);
+            if (rating) {
+                retString = i18np("1 star", "%1 stars", rating);
+            } else {
+                retString = i18n("Not yet rated");
+            }
+            break;
+        }
+
+        case DolphinView::SortByTags: {
+            retString = DolphinSortFilterProxyModel::tagsForIndex(index);
+
+            if (retString.isEmpty())
+                retString = i18n("Not yet tagged");
+
+            break;
+        }
+#endif
     }
 
     return retString;