Version: 2.2.90 (using KDE 4.4.0) Installed from: openSUSE RPMs Sorting by date in file browser does not work correctly - files are sorted by smth else.
Could you please specify what you did exactly? A precise description would be helpful.
I went to file browser, set files to be listed as "Detailed view" and clicked on date's column. I expected the files to be sorted by date now, but they didn't. PS. Note that it's with version 2.2.90, 2.2.2 is OK.
Well, it definitely works here, you maybe just didn't click twice. A file browser does take the focus from the name column on first click and sets it to the other column on second click only. Mind you, this only sorts the file date which is only the date you added a file, and it will only display one folder. Sorting files by play date is usually done in the CollectionBrowser search field...
Are you sure you are talking about file browser? I'll upload an image to illustrate what I'm talking about..
Created attachment 40791 [details] incorrect sorting by date
Yes, this is definitely the file browser, there are no columns in the CollectionBrowser. Please do not reopen this bug
Did you look at the image? Does it look like OK?
Hm, I tried in another folder now, and you are right, the sorting is indeed wrong, it sorts only by day, months and years (and times) are completely wrong.
Changing status.
The issue seems to be that the dates are sorted as strings and not as dates. On my system it works, but that is because the date format is arranged in order of importance (for instance, "2010-01-23 16:34" ) which when sorted as a string gives the correct result. According to the specs, the QSortFilterProxyModel used _should_ know how to correctly sort dates, but apparently not...
So it's Qt's fault?
As far as I can tell, yes
Nikolaj, did you report this upstream already?
*** Bug 231384 has been marked as a duplicate of this bug. ***
confirmed in git master.
*** Bug 234125 has been marked as a duplicate of this bug. ***
*** Bug 236968 has been marked as a duplicate of this bug. ***
commit 0a6d4a465b3e13edc55450c110c1de23bca379db Author: Rick W. Chen <stuffcorpse@archlinux.us> Date: Mon May 17 03:19:29 2010 +1200 Fix file browser sorting using headers BUG:226941 diff --git a/ChangeLog b/ChangeLog index ce726c4..b80d003 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ VERSION 2.3.1 Amarok. Batch scan users can invoke it with the --idlepriority flag. BUGFIXES: + * File browser: fixed sorting files by date. (BR 226941) * Fixed issue with file browser bookmarks not working when the file browser was showing "places". * Fixed crash when right clicking in file browser while it is showing diff --git a/src/browsers/filebrowser/FileBrowser.cpp b/src/browsers/filebrowser/FileBrowser.cpp index 0a210e6..7a3b675 100644 --- a/src/browsers/filebrowser/FileBrowser.cpp +++ b/src/browsers/filebrowser/FileBrowser.cpp @@ -74,7 +74,7 @@ FileBrowser::FileBrowser( const char * name, QWidget *parent ) m_mimeFilterProxyModel->setSourceModel( m_kdirModel ); m_mimeFilterProxyModel->setSortCaseSensitivity( Qt::CaseInsensitive ); m_mimeFilterProxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive ); - m_mimeFilterProxyModel->sort( 0 ); + m_mimeFilterProxyModel->setDynamicSortFilter( true ); debug() << "home path: " << QDir::homePath(); diff --git a/src/browsers/filebrowser/MimeTypeFilterProxyModel.cpp b/src/browsers/filebrowser/MimeTypeFilterProxyModel.cpp index 92ae889..309d7d4 100644 --- a/src/browsers/filebrowser/MimeTypeFilterProxyModel.cpp +++ b/src/browsers/filebrowser/MimeTypeFilterProxyModel.cpp @@ -18,7 +18,7 @@ #include <KDirModel> #include <KFileItem> -#include <kfile.h> +#include <KFile> MimeTypeFilterProxyModel::MimeTypeFilterProxyModel( QStringList mimeList, QObject *parent ) : QSortFilterProxyModel( parent ) @@ -49,24 +49,39 @@ MimeTypeFilterProxyModel::filterAcceptsRow( int source_row, const QModelIndex& s bool MimeTypeFilterProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) const { - // get the KFileItems - QVariant qvarLeft = left.data( KDirModel::FileItemRole ); - QVariant qvarRight = right.data( KDirModel::FileItemRole ); + const QVariant qvarLeft = left.data( KDirModel::FileItemRole ); + const QVariant qvarRight = right.data( KDirModel::FileItemRole ); + const KFileItem itemLeft = qvarLeft.value<KFileItem>(); + const KFileItem itemRight = qvarRight.value<KFileItem>(); - KFileItem itemLeft = qvarLeft.value<KFileItem>(); - KFileItem itemRight = qvarRight.value<KFileItem>(); + switch( left.column() ) + { + case KDirModel::Name: + // if both items are directories or files, then compare (case insensitive) on name + if( itemLeft.isDir() == itemRight.isDir() ) + return itemLeft.name( true ) < itemRight.name( true ); + // directories come before files + if( itemLeft.isDir() ) + return true; + break; - // if both items are directories or files, then compare (case insensitive) on name - if( itemLeft.isDir() == itemRight.isDir()) { - return itemLeft.name(true) < itemRight.name(true); - } + case KDirModel::Size: + return itemLeft.size() < itemRight.size(); + break; - // directories come before files - if (itemLeft.isDir()) { - return true; - } else { - return false; + case KDirModel::ModifiedTime: + return itemLeft.time( KFileItem::ModificationTime ) < itemRight.time( KFileItem::ModificationTime ); + break; + + case KDirModel::Permissions: + case KDirModel::Owner: + case KDirModel::Group: + case KDirModel::Type: + default: + return QString::localeAwareCompare( itemLeft.text(), itemRight.text() ) < 0; + break; } + return false; }
According to the specs, the QSortFilterProxyModel used _should_ know how to correctly sort dates, but apparently not...(In reply to comment #10 / Nikolaj) It should. But from what I understand KDirModel provides all those data as QStrings, as opposed to burying their respectively registered metatypes in the QVariants themselves. So the only thing you can do is find out what column they came from and match what the types used by KDirModel before they were converted to QStrings. That's what my patch does.