Version: (using KDE KDE 3.5.3) Installed from: Gentoo Packages OS: Linux When autocompleting recipients in the composer, the standard/preferred address is consistently shown after other addresses, such that if I use autocomplete, it completes to the wrong address. As an example, let's say I create a contact with two email addresses: My.Contact@yahoo.com, and My.Contact@google.com. If I set the yahoo address as the preferred address, autocomplete shows the google one first; if I set the google address as preferred, the yahoo one shows up first.
Created attachment 19525 [details] place preferred email before others
SVN commit 630959 by schaarsc: list preferred email first CCBUG: 131176 M +22 -8 branches/work/kdepim-3.5.5+/libkdepim/addresseelineedit.cpp --- branches/work/kdepim-3.5.5+/libkdepim/addresseelineedit.cpp #630958:630959 @@ -575,36 +575,38 @@ //m_contactMap.insert( addr.realName(), addr ); const QStringList emails = addr.emails(); QStringList::ConstIterator it; + const int prefEmailWeight = 1; //increment weight by prefEmailWeight + int isPrefEmail = prefEmailWeight; //first in list is preferredEmail for ( it = emails.begin(); it != emails.end(); ++it ) { //TODO: highlight preferredEmail const QString email( (*it) ); const QString givenName = addr.givenName(); const QString familyName= addr.familyName(); const QString nickName = addr.nickName(); - const QString fullEmail = addr.fullEmail( email ); const QString domain = email.mid( email.find( '@' ) + 1 ); + QString fullEmail = addr.fullEmail( email ); //TODO: let user decide what fields to use in lookup, e.g. company, city, ... //for CompletionAuto if ( givenName.isEmpty() && familyName.isEmpty() ) { - addCompletionItem( fullEmail, weight, source ); // use whatever is there + addCompletionItem( fullEmail, weight + isPrefEmail, source ); // use whatever is there } else { const QString byFirstName= "\"" + givenName + " " + familyName + "\" <" + email + ">"; const QString byLastName = "\"" + familyName + ", " + givenName + "\" <" + email + ">"; - addCompletionItem( byFirstName, weight, source ); - addCompletionItem( byLastName, weight, source ); + addCompletionItem( byFirstName, weight + isPrefEmail, source ); + addCompletionItem( byLastName, weight + isPrefEmail, source ); } - addCompletionItem( email, weight, source ); + addCompletionItem( email, weight + isPrefEmail, source ); if ( !nickName.isEmpty() ){ const QString byNick = "\"" + nickName + "\" <" + email + ">"; - addCompletionItem( byNick, weight, source ); + addCompletionItem( byNick, weight + isPrefEmail, source ); } if ( !domain.isEmpty() ){ const QString byDomain = "\"" + domain + " " + familyName + " " + givenName + "\" <" + email + ">"; - addCompletionItem( byDomain, weight, source ); + addCompletionItem( byDomain, weight + isPrefEmail, source ); } //for CompletionShell, CompletionPopup @@ -631,8 +633,18 @@ keyWords.append( email ); - addCompletionItem( fullEmail, weight, source, &keyWords ); + /* KMailCompletion does not have knowlege about identities, it stores emails and + * keywords for each email. KMailCompletion::allMatches does a lookup on the + * keywords and returns an ordered list of emails. In order to get the preferred + * email before others for each identity we use this little trick. + * We remove the <blank> in getAdjustedCompletionItems. + */ + if ( isPrefEmail == prefEmailWeight ) + fullEmail.replace( " <", " <" ); + addCompletionItem( fullEmail, weight + isPrefEmail, source, &keyWords ); + isPrefEmail = 0; + #if 0 int len = (*it).length(); if ( len == 0 ) continue; @@ -1009,6 +1021,8 @@ lastSourceIndex = idx; } (*it) = (*it).prepend( s_completionItemIndentString ); + // remove preferred email sort <blank> added in addContact() + (*it).replace( " <", " <" ); } sections[idx].append( *it );
This is a duplicate of Bug 129116, which also suggests that the preferred address be marked somehow (either by listing it first, or putting it in bold, or some other way). Can someone please mark the bug as a duplicate?
I'll mark that one as dupe of this, since this one has some record of what's already been done.
*** Bug 129116 has been marked as a duplicate of this bug. ***
SVN commit 647586 by schaarsc: list preferred email first BUG: 131176 M +22 -8 addresseelineedit.cpp --- branches/KDE/3.5/kdepim/libkdepim/addresseelineedit.cpp #647585:647586 @@ -575,36 +575,38 @@ //m_contactMap.insert( addr.realName(), addr ); const QStringList emails = addr.emails(); QStringList::ConstIterator it; + const int prefEmailWeight = 1; //increment weight by prefEmailWeight + int isPrefEmail = prefEmailWeight; //first in list is preferredEmail for ( it = emails.begin(); it != emails.end(); ++it ) { //TODO: highlight preferredEmail const QString email( (*it) ); const QString givenName = addr.givenName(); const QString familyName= addr.familyName(); const QString nickName = addr.nickName(); - const QString fullEmail = addr.fullEmail( email ); const QString domain = email.mid( email.find( '@' ) + 1 ); + QString fullEmail = addr.fullEmail( email ); //TODO: let user decide what fields to use in lookup, e.g. company, city, ... //for CompletionAuto if ( givenName.isEmpty() && familyName.isEmpty() ) { - addCompletionItem( fullEmail, weight, source ); // use whatever is there + addCompletionItem( fullEmail, weight + isPrefEmail, source ); // use whatever is there } else { const QString byFirstName= "\"" + givenName + " " + familyName + "\" <" + email + ">"; const QString byLastName = "\"" + familyName + ", " + givenName + "\" <" + email + ">"; - addCompletionItem( byFirstName, weight, source ); - addCompletionItem( byLastName, weight, source ); + addCompletionItem( byFirstName, weight + isPrefEmail, source ); + addCompletionItem( byLastName, weight + isPrefEmail, source ); } - addCompletionItem( email, weight, source ); + addCompletionItem( email, weight + isPrefEmail, source ); if ( !nickName.isEmpty() ){ const QString byNick = "\"" + nickName + "\" <" + email + ">"; - addCompletionItem( byNick, weight, source ); + addCompletionItem( byNick, weight + isPrefEmail, source ); } if ( !domain.isEmpty() ){ const QString byDomain = "\"" + domain + " " + familyName + " " + givenName + "\" <" + email + ">"; - addCompletionItem( byDomain, weight, source ); + addCompletionItem( byDomain, weight + isPrefEmail, source ); } //for CompletionShell, CompletionPopup @@ -631,8 +633,18 @@ keyWords.append( email ); - addCompletionItem( fullEmail, weight, source, &keyWords ); + /* KMailCompletion does not have knowledge about identities, it stores emails and + * keywords for each email. KMailCompletion::allMatches does a lookup on the + * keywords and returns an ordered list of emails. In order to get the preferred + * email before others for each identity we use this little trick. + * We remove the <blank> in getAdjustedCompletionItems. + */ + if ( isPrefEmail == prefEmailWeight ) + fullEmail.replace( " <", " <" ); + addCompletionItem( fullEmail, weight + isPrefEmail, source, &keyWords ); + isPrefEmail = 0; + #if 0 int len = (*it).length(); if ( len == 0 ) continue; @@ -1009,6 +1021,8 @@ lastSourceIndex = idx; } (*it) = (*it).prepend( s_completionItemIndentString ); + // remove preferred email sort <blank> added in addContact() + (*it).replace( " <", " <" ); } sections[idx].append( *it );