emailuis/nmailuiwidgets/src/nmrecipientlineedit.cpp
changeset 54 997a02608b3a
parent 30 759dc5235cdb
child 75 47d84de1c893
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    63 }
    63 }
    64 
    64 
    65 
    65 
    66 #ifdef Q_OS_SYMBIAN
    66 #ifdef Q_OS_SYMBIAN
    67 /*!
    67 /*!
    68    This Slot inserts the selected contacts from Contacts-picker into the lineedit cursor position.    
    68    This Slot appends the selected contacts to the end of the lineedit content.    
    69 */
    69 */
    70 void NmRecipientLineEdit::insertSelectedContacts(const QVariant &selectedContacts)
    70 void NmRecipientLineEdit::addSelectedContacts(const QVariant &selectedContacts)
    71 {
    71 {
    72     NM_FUNCTION;
    72     NM_FUNCTION;
    73     
    73     
    74     if (!selectedContacts.isNull()) {
    74     // If user selected contact
    75         CntServicesContactList contactList;
    75     if (!selectedContacts.isNull()) {        
    76         contactList = qVariantValue<CntServicesContactList>(selectedContacts);
    76 
       
    77         // If the lineedit is not empty and if there is no ";" or "; " at the end,
       
    78         // add a delimiter("; ") at the end.
       
    79         if (this->text().length() != 0 && !(this->text().endsWith(Semicolon)) && 
       
    80             !(this->text().endsWith(Delimiter))){
       
    81             
       
    82             // Move cursor to the end of the lineedit.
       
    83             this->setCursorPosition(this->text().length());       
       
    84             QTextCursor textCursor(this->textCursor());
       
    85             // Append delimiter("; ") to the end of the lineedit
       
    86             textCursor.insertText(Delimiter);
       
    87         }
       
    88         
       
    89         CntServicesContactList contactList = qVariantValue<CntServicesContactList>(selectedContacts);
    77 
    90 
    78         // Loop through all the selected contacts.
    91         // Loop through all the selected contacts.
    79         for (int i = 0; i < contactList.count(); ++i) {
    92         for (int i = 0; i < contactList.count(); ++i) {
       
    93             QString contactName = contactList[i].mDisplayName;
    80             QString contactEmailAddress = contactList[i].mEmailAddress;
    94             QString contactEmailAddress = contactList[i].mEmailAddress;
    81             QString contactName = contactList[i].mDisplayName;
    95             
    82 
    96             // If this contact has no name, use it's emailaddress as the display name
    83             // If this contact has no name.
    97             if(contactName.isEmpty()) {	
    84             if(contactName.isEmpty()) {				
    98                 // Move cursor to the end of the lineedit.
    85                 // Generate a custom keyevent for this contact's emailaddress.
    99                 this->setCursorPosition(this->text().length());       
    86                 QKeyEvent contactEmailAddressKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
   100                 QTextCursor textCursor(this->textCursor());
    87                 		                              Qt::NoModifier, contactEmailAddress);
   101                 // Append contactEmailAddress to the end of the lineedit
    88                 // Forward this contactEmailAddressKeyEvent to base class to handle.
   102                 textCursor.insertText(contactEmailAddress);
    89                 NmHtmlLineEdit::keyPressEvent(&contactEmailAddressKeyEvent);
   103             }
    90             }
   104             // If this contact has name, use the name as the display name
    91             else {
   105             else {
    92                 // Handle a rare case: there are contacts has same name but different emailaddress.
   106                 // Handle a rare case: there are contacts has same name but different emailaddress.
    93                 for (int i = 0; i != mRecipientsAddedFromContacts.count(); ++i) {
   107                 for (int i = 0; i != mRecipientsAddedFromContacts.count(); ++i) {
    94                     if (mRecipientsAddedFromContacts.at(i).displayName() == contactName &&
   108                     if (mRecipientsAddedFromContacts.at(i).displayName() == contactName &&
    95                   	    mRecipientsAddedFromContacts.at(i).address() != contactEmailAddress) {
   109                   	    mRecipientsAddedFromContacts.at(i).address() != contactEmailAddress) {
    98                         contactName.append(contactEmailAddress);
   112                         contactName.append(contactEmailAddress);
    99                         contactName.append(">");
   113                         contactName.append(">");
   100                     }
   114                     }
   101                 }
   115                 }
   102                 
   116                 
   103                 // Generate custom keyevent for this contact's name.
   117                 // Move cursor to the end of the lineedit.
   104                 QKeyEvent contactNameKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
   118                 this->setCursorPosition(this->text().length());       
   105                                               Qt::NoModifier, contactName);
   119                 QTextCursor textCursor(this->textCursor());
   106                 // Forward this contactNameKeyEvent to base class to handle.
   120                 // Append contactName to the end of the lineedit
   107                 NmHtmlLineEdit::keyPressEvent(&contactNameKeyEvent);
   121                 textCursor.insertText(contactName);
   108             }
   122             }
   109 
   123                 
   110             // Generate custom keyevent for Delimiter("; ").
   124             QTextCursor textCursor(this->textCursor());
   111             QKeyEvent delimiterKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
   125             // Append delimiter("; ")
   112                                         Qt::NoModifier, Delimiter);
   126             textCursor.insertText(Delimiter);
   113             // Forward the delimiterKeyEvent to base class to handle.
   127             
   114             NmHtmlLineEdit::keyPressEvent(&delimiterKeyEvent);
       
   115 			
       
   116             // Form the contact into Qmail NmAddress format.
   128             // Form the contact into Qmail NmAddress format.
   117             NmAddress contact;
   129             NmAddress contact;
   118             contact.setAddress(contactEmailAddress);
   130             contact.setAddress(contactEmailAddress);
   119             contact.setDisplayName(contactName);
   131             contact.setDisplayName(contactName);
   120             
   132             
   121             // Add this NmAddress formated contact into mRecipientsAddedFromContacts.
   133             // Add this NmAddress formated contact into mRecipientsAddedFromContacts.
   122             mRecipientsAddedFromContacts.append(contact);
   134             mRecipientsAddedFromContacts.append(contact);
   123         }
   135         } 
   124     }
   136     }
   125     else {
   137     else {
   126         //Request returned NULL 
   138         //Request returned NULL 
   127         NM_COMMENT("ContactsPicker request returned NULL.");
   139         NM_COMMENT("ContactsPicker request returned NULL.");
   128     }
   140     }