- case DolphinView::SortByName: {
- // So we are in the same priority, what counts now is their names.
- const QVariant leftData = dirModel->data(left, KDirModel::Name);
- const QVariant rightData = dirModel->data(right, KDirModel::Name);
- const QString leftValueString(leftData.toString());
- const QString 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()) {
- QVariant leftValue = dirModel->data(left, KDirModel::ChildCountRole);
- int leftCount = leftValue.type() == QVariant::Int ? leftValue.toInt() : KDirModel::ChildCountUnknown;
-
- QVariant rightValue = dirModel->data(right, KDirModel::ChildCountRole);
- 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) {
- return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- // If they had different number of items, we sort them depending
- // on how many items had each other.
- return leftCount < rightCount;
- }
-
- // If what we are measuring is two files and they have the same size,
- // sort them by their file names.
- if (leftFileItem->size() == rightFileItem->size()) {
- return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- // If their sizes are different, sort them by their sizes, as expected.
- return leftFileItem->size() < rightFileItem->size();
- }
-
- case DolphinView::SortByDate: {
- KDateTime leftTime, rightTime;
- leftTime.setTime_t(leftFileItem->time(KIO::UDS_MODIFICATION_TIME));
- rightTime.setTime_t(rightFileItem->time(KIO::UDS_MODIFICATION_TIME));
-
- if (leftTime == rightTime) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return leftTime > rightTime;
- }
-
- case DolphinView::SortByPermissions: {
- if (leftFileItem->permissionsString() == rightFileItem->permissionsString()) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return naturalCompare(leftFileItem->permissionsString(),
- rightFileItem->permissionsString()) < 0;
- }
-
- case DolphinView::SortByOwner: {
- if (leftFileItem->user() == rightFileItem->user()) {
- return sortCaseSensitivity() ?
- (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
- (naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
- }
-
- return naturalCompare(leftFileItem->user(), rightFileItem->user()) < 0;
- }
+ case DolphinView::SortByRating: {
+ const quint32 leftRating = ratingForIndex(left);
+ const quint32 rightRating = ratingForIndex(right);
+
+ if (leftRating == rightRating) {
+ // On our priority, folders go above regular files.
+ // This checks are needed (don't think it's the same doing it here
+ // than above). Here we make dirs citizens of first class because
+ // we know we are on the same category. On the check we do on the
+ // top of the method we don't know, so we remove that check when we
+ // are sorting by rating. (ereslibre)
+ if (leftFileItem->isDir() && !rightFileItem->isDir()) {
+ return true;
+ } else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
+ return false;
+ }