Bug 251161 - wrong date sort order in `find messages' window
Summary: wrong date sort order in `find messages' window
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Applications
Component: search (show other bugs)
Version: 1.13.5
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-13 23:40 UTC by tim blechmann
Modified: 2011-01-22 14:59 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tim blechmann 2010-09-13 23:40:37 UTC
Version:           1.13.5 (using KDE 4.5.1) 
OS:                Linux

in the `find messages' window, messages cannot correctly be sorted by date.

instead of being sorted by date, they are sorted by the date string

Reproducible: Always

Steps to Reproduce:
- find messages in folder
- hit `search'
- try to sort by date
Comment 1 Nicolas Morange 2010-10-09 10:42:57 UTC
I can confirm this bug.
KMail 1.13.5, KDE 4.5.2
Comment 2 CSights 2010-11-12 04:25:11 UTC
I can confirm this bug.
KMail 1.13.5, KDE 4.4.5
Comment 3 Thomas Fischer 2010-11-23 13:27:56 UTC
The problem is that the list widget uses a lexicographical comparison by default. To solve this issue, instead of using QTreeWidgetItem objects to represent search results, a new class has to derived here which re-implements the sorting function (more specifically, how two entries are compared).

My idea would be as follows (not compiled, not tested, may not work at all!):



const int ColumnDate=2;

class MatchListViewItem : public QTreeWidgetItem
{
	private:
		MatchListView *parent;
		
	public:
		
MatchListViewItem(MatchListView *p)
: QTreeWidgetItem(p), parent(p)
{
	// empty
};

bool operator<( const QTreeWidgetItem & other ) const
{
	switch(parent->sortColumn()) {
		case ColumnDate:
			return QDate::fromString(text(ColumnDate)).operator<(QDate::fromString(other.text(ColumnDate)));
		default:
	return QTreeWidgetItem::operator<(other);
	}
}
};


In function SearchWindow::slotAddMsg, use this class instead of QTreeWidgetItem when adding more results.
Maybe I'll test and refine this code later today...
Comment 4 Thomas Fischer 2010-11-23 21:33:53 UTC
(In reply to comment #3)
> The problem is that the list widget uses a lexicographical comparison by
> default. To solve this issue, instead of using QTreeWidgetItem objects to
> represent search results, a new class has to derived here which re-implements
> the sorting function (more specifically, how two entries are compared).
> [...]
> In function SearchWindow::slotAddMsg, use this class instead of QTreeWidgetItem
> when adding more results.
> Maybe I'll test and refine this code later today...

My simple code above would not work, as the date strings are localized and not easy to compare. A better implementation would be to use nice model/view approach which has already been implemented in trunk and 4.5beta1 (not tested myself, yet).

Therefore I propose to close this bug as soon as Kontact / KMail 4.5 becomes stable. Maybe mark this bug until then as WONTFIX?
Comment 5 Laurent Montel 2011-01-22 14:59:09 UTC
I fixed this bug yesterday
I close it