Bug 255398 - KAddressbook shows names in wrong order
Summary: KAddressbook shows names in wrong order
Status: RESOLVED UPSTREAM
Alias: None
Product: kaddressbook
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-27 13:57 UTC by nebuchadnezzar_2069
Modified: 2011-01-04 15:02 UTC (History)
2 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 nebuchadnezzar_2069 2010-10-27 13:57:56 UTC
Version:           unspecified (using KDE 4.5.1) 
OS:                Linux

If you have Contacts in your Addressbook with similar surnames, where one name is longer then the other, e.g. "Peters" and "Peterson", then these will not be sorted correctly. Simple Example, of how it would look like:

Peters, Andrew
Peters, Henry
Peterson, Julia
Peterson, Mike
Peters, Sonya
Peters, Stan

See, how the Petersons and the Peters are mixed up? If you delete the commas and spaces between the names, you will see why:

PetersAndrew
PetersHenry
PetersonJulia
PetersonMike
PetersSonya
PetersStan

Seems like the sort algorithm does exectly that: Delete the commas and spaces and then take the whole string and sort it. In this case, it produces a wrong result.

Instead of this, it should rather first sort by surename, then by forename. Would be even better, if one could choose, by which fields to sort in what order. That way you could sort your contacts by location first, then by name. Or one could sort by organisation, then by department and then by name etc.

Reproducible: Always

Steps to Reproduce:
Create Contacts with the names shown in the description and show them as "surname, forename" or "surename forename" (with or without comma).

Actual Results:  
These Contacts will be shown in wrong order.

Expected Results:  
They should be shown in correct order (sorted by surname first, then by given name).

OS: Linux (x86_64) release 2.6.35-22-generic
Compiler: cc
Comment 1 Hans-Rudi Denzler 2010-10-27 14:28:11 UTC
Have you clicked the name header twice ?
In my case at startup the names are unsorted.
Comment 2 nebuchadnezzar_2069 2010-10-27 15:33:12 UTC
Sure. Have you tried to reproduce with the names i wrote above?

As I said, it must be in the sort-algorithm, that doesn't care about commas and spaces.
Comment 3 Tobias Koenig 2010-12-23 00:19:53 UTC
Hej,

we use the QString::compareLocaleAware() here. If you have the feeling that this sorting is wrong, please file a bug on the Qt bug tracker.

Ciao,
Tobias
Comment 4 nebuchadnezzar_2069 2011-01-03 22:54:06 UTC
I did that. It is now listed under: http://bugreports.qt.nokia.com/browse/QTBUG-16398

Btw: The function is called localeAwareCompare() not compareLocaleAware().
Comment 5 nebuchadnezzar_2069 2011-01-04 15:02:18 UTC
OK, now I have tested out the localeAwareCompare(). If you compare "Smithers, Eve" with "Smith, Eve" and "Smithers, Eve" with "Smith, Adam" like this:

[code]
#include <iostream>
#include <QString>

int main(int argc, char* argv[]) 
{	
	if ( QString::localeAwareCompare("Smithers, Eve", "Smith, Eve") < 0 )
		std::cout << "1. Smithers, Eve\n2. Smith, Eve" << std::endl;
	else
		std::cout << "1. Smith, Eve\n2. Smithers, Eve" << std::endl;
	
	std::cout << "---" << std::endl;
	
	if ( QString::localeAwareCompare("Smithers, Eve", "Smith, Adam") < 0 )
		std::cout << "1. Smithers, Eve\n2. Smith, Adam" << std::endl;
	else
		std::cout << "1. Smith, Adam\n2. Smithers, Eve" << std::endl;
}
[/code]

it outputs:

1. Smith, Eve
2. Smithers, Eve
---
1. Smith, Adam
2. Smithers, Eve

So both Smith's come before Mrs. Smithers.

Use the same names in KAddressbook and and it will sorted like this:

1. Smith, Adam
2. Smithers, Eve
3. Smith, Eve

So the issue cannot be in localeAwareCompare().