return retString;
}
- int indexColumn;
-
- switch (sortRole)
- {
- case DolphinView::SortByName:
- indexColumn = KDirModel::Name;
- break;
- case DolphinView::SortBySize:
- indexColumn = KDirModel::Size;
- break;
- default:
- return retString;
- }
-
// KDirModel checks columns to know to which role are
// we talking about
QModelIndex theIndex = index.model()->index(index.row(),
- indexColumn,
- index.parent());
+ sortRole,
+ index.parent());
if (!theIndex.isValid()) {
return retString;
QVariant data = theIndex.model()->data(theIndex, Qt::DisplayRole);
const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model());
- KFileItem* item = dirModel->itemForIndex(index);
+ KFileItem *item = dirModel->itemForIndex(index);
+ int fileSize;
switch (sortRole)
{
- case DolphinView::SortByName:
+ case KDirModel::Name:
if (data.toString().size())
{
if (!item->isHidden() && data.toString().at(0).isLetter())
else
retString = i18n("Others");
}
- break;
- case DolphinView::SortBySize:
- int fileSize = (item) ? item->size() : -1;
- if (item && item->isDir()) {
- retString = i18n("Folders");
- } else if (fileSize < 5242880) {
- retString = i18nc("Size", "Small");
- } else if (fileSize < 10485760) {
- retString = i18nc("Size", "Medium");
- } else {
- retString = i18nc("Size", "Big");
- }
- break;
+ break;
+
+ case KDirModel::Size:
+ fileSize = (item) ? item->size() : -1;
+ if (item && item->isDir()) {
+ retString = i18n("Folders");
+ } else if (fileSize < 5242880) {
+ retString = i18nc("Size", "Small");
+ } else if (fileSize < 10485760) {
+ retString = i18nc("Size", "Medium");
+ } else {
+ retString = i18nc("Size", "Big");
+ }
+ break;
+
+ case KDirModel::Type:
+ retString = item->mimeComment();
+ break;
}
return retString;
m_sorting = (column >= 0) && (column < dolphinMapSize) ?
dirModelColumnToDolphinView[column] :
DolphinView::SortByName;
- setSortRole(m_sorting);
+ setSortRole(dirModelColumnToDolphinView[column]);
KSortFilterProxyModel::sort(column, sortOrder);
}
KDirModel* dirModel = static_cast<KDirModel*>(sourceModel());
const KFileItem *leftFileItem = dirModel->itemForIndex(left);
- const KFileItem *rightFileItem = dirModel->itemForIndex(right);
+ const KFileItem *rightFileItem = dirModel->itemForIndex(right);
if (sortRole() == DolphinView::SortByName) // If we are sorting by name
{
// want here to compare by a natural comparation
return leftStr.toLower() < rightStr.toLower();
}
- else if (sortRole() == DolphinView::SortBySize) // If we are sorting by size
+ else if (sortRole() == KDirModel::Size) // If we are sorting by size
{
// If we are sorting by size, show folders first. We will sort them
// correctly later
return false;
}
+ else if (sortRole() == KDirModel::Type)
+ {
+ return naturalCompare(leftFileItem->mimetype().toLower(),
+ rightFileItem->mimetype().toLower()) < 0;
+ }
}
bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
const KFileItem *leftFileItem = dirModel->itemForIndex(left);
const KFileItem *rightFileItem = dirModel->itemForIndex(right);
- if (sortRole() == DolphinView::SortByName) { // If we are sorting by name
+ if (sortRole() == KDirModel::Name) { // If we are sorting by name
if ((leftData.type() == QVariant::String) && (rightData.type() ==
QVariant::String)) {
// Priority: hidden > folders > regular files. If an item is
(naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
}
}
- else if (sortRole() == DolphinView::SortBySize) { // If we are sorting by size
+ else if (sortRole() == KDirModel::Size) { // 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()) {
// 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 = dirModel->data(left, DolphinView::SortByName).toString();
- const QString rightStr = dirModel->data(right, DolphinView::SortByName).toString();
+ const QString leftStr = dirModel->data(left, KDirModel::Name).toString();
+ const QString rightStr = dirModel->data(right, KDirModel::Name).toString();
return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
(naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
// 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()) {
- const QString leftStr = dirModel->data(left, DolphinView::SortByName).toString();
- const QString rightStr = dirModel->data(right, DolphinView::SortByName).toString();
+ const QString leftStr = dirModel->data(left, KDirModel::Name).toString();
+ const QString rightStr = dirModel->data(right, KDirModel::Name).toString();
return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
(naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
// If their sizes are different, sort them by their sizes, as expected
return leftFileItem->size() < rightFileItem->size();
}
+ else if (sortRole() == KDirModel::Type)
+ {
+ if (leftFileItem->mimetype() == rightFileItem->mimetype())
+ {
+ const QString leftStr = dirModel->data(left, KDirModel::Name).toString();
+ const QString rightStr = dirModel->data(right, KDirModel::Name).toString();
+
+ return sortCaseSensitivity() ? (naturalCompare(leftStr, rightStr) < 0) :
+ (naturalCompare(leftStr.toLower(), rightStr.toLower()) < 0);
+ }
+
+ return naturalCompare(leftFileItem->mimeComment(),
+ rightFileItem->mimeComment()) < 0;
+ }
// We have set a SortRole and trust the ProxyModel to do
// the right thing for now.