Bug 131176 - Autocompletion shows standard/preferred address after other addresses
Summary: Autocompletion shows standard/preferred address after other addresses
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
: 129116 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-21 18:40 UTC by Pedro DeRose
Modified: 2007-09-14 12:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
place preferred email before others (2.88 KB, patch)
2007-02-03 22:14 UTC, Christian Schaarschmidt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro DeRose 2006-07-21 18:40:47 UTC
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.
Comment 1 Christian Schaarschmidt 2007-02-03 22:14:11 UTC
Created attachment 19525 [details]
place preferred email before others
Comment 2 Christian Schaarschmidt 2007-02-06 22:40:19 UTC
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 );
 
Comment 3 Tristan Miller 2007-03-10 20:39:53 UTC
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?
Comment 4 Philip Rodrigues 2007-03-11 23:26:59 UTC
I'll mark that one as dupe of this, since this one has some record of what's already been done.
Comment 5 Philip Rodrigues 2007-03-11 23:27:18 UTC
*** Bug 129116 has been marked as a duplicate of this bug. ***
Comment 6 Christian Schaarschmidt 2007-03-28 21:50:52 UTC
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 );