- // If we have two folders, what we have to measure is the number of
- // items that contains each other
- if (leftFileItem->isDir() && rightFileItem->isDir()) {
- const QVariant leftValue = dirModel->data(left, KDirModel::ChildCountRole);
- const int leftCount = leftValue.type() == QVariant::Int ? leftValue.toInt() : KDirModel::ChildCountUnknown;
+ QVariant leftValue, rightValue;
+ QString leftValueString, rightValueString;
+ KDateTime leftTime, rightTime;
+ int leftCount, rightCount;
+ switch (sortRole()) {
+ case DolphinView::SortByName:
+ // So we are in the same priority, what counts now is their names
+ leftValueString = leftData.toString();
+ rightValueString = rightData.toString();
+
+ return sortCaseSensitivity() ? (naturalCompare(leftValueString, rightValueString) < 0) :
+ (naturalCompare(leftValueString.toLower(), rightValueString.toLower()) < 0);
+
+ case DolphinView::SortBySize:
+ // If we have two folders, what we have to measure is the number of
+ // items that contains each other
+ if (leftFileItem->isDir() && rightFileItem->isDir()) {
+ leftValue = dirModel->data(left, KDirModel::ChildCountRole);
+ leftCount = leftValue.type() == QVariant::Int ? leftValue.toInt() : KDirModel::ChildCountUnknown;
+
+ rightValue = dirModel->data(right, KDirModel::ChildCountRole);
+ rightCount = rightValue.type() == QVariant::Int ? rightValue.toInt() : KDirModel::ChildCountUnknown;
+
+ // In the case they two have the same child items, we sort them by
+ // their names. So we have always everything ordered. We also check
+ // if we are taking in count their cases
+ if (leftCount == rightCount) {
+ return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
+ (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
+ }