- // change the sort order by keeping the current column
- sort(dolphinViewToDirModelColumn[m_sorting], sortOrder);
+ KDirModel* dirModel = static_cast<KDirModel*>(sourceModel());
+
+ QVariant leftData = dirModel->data(left, sortRole());
+ QVariant rightData = dirModel->data(right, sortRole());
+
+ if ((leftData.type() == QVariant::String) && (rightData.type() == QVariant::String)) {
+ const QString leftStr = leftData.toString();
+ const QString rightStr = rightData.toString();
+
+ const bool leftIsDir = dirModel->itemForIndex(left)->isDir();
+ const bool rightIsDir = dirModel->itemForIndex(right)->isDir();
+
+ // assure that directories are always sorted before files
+ if (leftIsDir && !rightIsDir) {
+ return true;
+ }
+
+ if (!leftIsDir && rightIsDir) {
+ return false;
+ }
+
+ return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
+ (naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
+ }
+
+ // We have set a SortRole and trust the ProxyModel to do
+ // the right thing for now.
+ return QSortFilterProxyModel::lessThan(left, right);