Let Dolphin act as Konqueror on KDE3 does when sorting. Folders have more priority than hidden items. So now items are shown: 1. Hidden Folders 2. Visible Folders 3.

Hidden Files 4. Visible Files

CCMAIL: aseigo@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=677173
This commit is contained in:
Rafael Fernández López 2007-06-18 16:11:11 +00:00
parent 54f6ab585b
commit ec5c086bc8

View file

@ -122,9 +122,18 @@ bool DolphinSortFilterProxyModel::lessThanGeneralPurpose(const QModelIndex &left
const KFileItem *rightFileItem = dirModel->itemForIndex(right);
if (sortRole() == DolphinView::SortByName) { // If we are sorting by name
QString leftFileName = leftFileItem->name();
QString rightFileName = rightFileItem->name();
leftFileName = leftFileName.at(0) == '.' ? leftFileName.mid(1) :
leftFileName;
rightFileName = rightFileName.at(0) == '.' ? rightFileName.mid(1) :
rightFileName;
// We don't care about case for building categories. We also don't
// want here to compare by a natural comparation
return QString::compare(leftFileItem->name(), rightFileItem->name(), Qt::CaseInsensitive) < 0;
return QString::compare(leftFileName, rightFileName, Qt::CaseInsensitive) < 0;
}
else if (sortRole() == DolphinView::SortBySize) { // If we are sorting by size
// If we are sorting by size, show folders first. We will sort them
@ -181,16 +190,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
if (sortRole() == DolphinView::SortByName) { // If we are sorting by name
if ((leftData.type() == QVariant::String) && (rightData.type() ==
QVariant::String)) {
// 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;
@ -199,6 +198,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
return false;
}
// So we are in the same priority, what counts now is their names
const QString leftStr = leftData.toString();
const QString rightStr = rightData.toString();
@ -208,15 +216,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
}
}
else if (sortRole() == DolphinView::SortBySize) { // If we are sorting by size
// 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;
@ -225,6 +224,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
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()) {
@ -258,15 +266,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return leftFileItem->size() < rightFileItem->size();
}
else if (sortRole() == DolphinView::SortByDate) {
// 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;
@ -275,6 +274,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
return false;
}
KDateTime leftTime;
leftTime.setTime_t(leftFileItem->time(KIO::UDS_MODIFICATION_TIME));
KDateTime rightTime;
@ -289,15 +297,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return leftTime > rightTime;
}
else if (sortRole() == DolphinView::SortByPermissions) {
// 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;
@ -306,6 +305,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
return false;
}
const QString leftPermissions = leftFileItem->permissionsString();
const QString rightPermissions = rightFileItem->permissionsString();
@ -319,15 +327,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
rightPermissions) < 0;
}
else if (sortRole() == DolphinView::SortByOwner) {
// 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;
@ -336,6 +335,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
return false;
}
const QString leftOwner = leftFileItem->user();
const QString rightOwner = rightFileItem->user();
@ -349,15 +357,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
rightOwner.toLower()) < 0;
}
else if (sortRole() == DolphinView::SortByGroup) {
// 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;
@ -366,6 +365,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
return false;
}
const QString leftGroup = leftFileItem->group();
const QString rightGroup = rightFileItem->group();
@ -379,15 +387,6 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
rightGroup.toLower()) < 0;
}
else if (sortRole() == DolphinView::SortByType) {
// 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;
@ -396,6 +395,15 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
return false;
}
// Hidden elements go before visible ones, if they both are
// folders or files
if (leftFileItem->isHidden() && !rightFileItem->isHidden()) {
return true;
}
else if (!leftFileItem->isHidden() && rightFileItem->isHidden()) {
return false;
}
if (leftFileItem->mimetype() == rightFileItem->mimetype())
{
return sortCaseSensitivity() ? (naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :