+
+ // So we are in the same priority, what counts now is their names
+ const QString leftStr = leftData.toString();
+ const QString rightStr = rightData.toString();
+
+ return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
+ (naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
+ }
+ }
+ else if (sortRole() == DolphinView::SortBySize) { // If we are sorting by size
+ // Priority: hidden > folders > regular files. If an item is
+ // hidden (doesn't matter if file or folder) will have higher
+ // preference than a non-hidden item
+ if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
+ return true;
+ }
+ else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
+ return false;
+ }
+
+ // On our priority, folders go above regular files
+ if (leftFileItem->isDir() && !rightFileItem->isDir()) {
+ return true;
+ }
+ else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
+ return false;
+ }
+
+ // 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;
+
+ const QVariant rightValue = dirModel->data(right, KDirModel::ChildCountRole);
+ const int 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) {
+ const QString leftStr = leftData.toString();
+ const QString rightStr = rightData.toString();
+
+ return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
+ (naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
+ }
+
+ // If they had different number of items, we sort them depending
+ // on how many items had each other
+ return leftCount < rightCount;