emailuis/nmailuiwidgets/src/nmrecipientlineedit.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    71 {
    71 {
    72     if (!selectedContacts.isNull()) {
    72     if (!selectedContacts.isNull()) {
    73         CntServicesContactList contactList;
    73         CntServicesContactList contactList;
    74         contactList = qVariantValue<CntServicesContactList>(selectedContacts);
    74         contactList = qVariantValue<CntServicesContactList>(selectedContacts);
    75 
    75 
    76         if (contactList.count() == 0) {	
    76         // Loop through all the selected contacts.
    77             // String "No contact returned" will be replaced by a hbTrId.
    77         for (int i = 0; i < contactList.count(); ++i) {
    78             HbMessageBox note(tr("No contact returned"), HbMessageBox::MessageTypeInformation);
    78             QString contactEmailAddress = contactList[i].mEmailAddress;
    79             note.setTimeout(HbMessageBox::NoTimeout);
    79             QString contactName = contactList[i].mDisplayName;
    80             note.exec();
       
    81         }
       
    82         else {
       
    83             // Loop through all the contacts selected from Contacts application.
       
    84             for (int i = 0; i < contactList.count(); ++i) {
       
    85                 QString contactEmailAddress = contactList[i].mEmailAddress;
       
    86                 QString contactName = contactList[i].mDisplayName;
       
    87 
    80 
    88             // If this contact has no name.
    81             // If this contact has no name.
    89             if(contactName.isEmpty()) {				
    82             if(contactName.isEmpty()) {				
    90                 // Generate custom keyevent for this contact's emailaddress.
    83                 // Generate a custom keyevent for this contact's emailaddress.
    91                 QKeyEvent contactEmailAddressKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
    84                 QKeyEvent contactEmailAddressKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
    92                 		                              Qt::NoModifier, contactEmailAddress);
    85                 		                              Qt::NoModifier, contactEmailAddress);
    93                 // Forward this contactEmailAddressKeyEventt to base class to handle.
    86                 // Forward this contactEmailAddressKeyEvent to base class to handle.
    94                 NmHtmlLineEdit::keyPressEvent(&contactEmailAddressKeyEvent);
    87                 NmHtmlLineEdit::keyPressEvent(&contactEmailAddressKeyEvent);
    95             }
    88             }
    96             else {
    89             else {
    97                 // Handle a rare case: there's another contact has same name 
    90                 // Handle a rare case: there's another contact has same name but has different emailaddress.
    98                 // but has different emailaddress.
       
    99                 for (int i = 0; i != mContactsSelectedFromPhoneBook.count(); ++i) {
    91                 for (int i = 0; i != mContactsSelectedFromPhoneBook.count(); ++i) {
   100                     if (mContactsSelectedFromPhoneBook.at(i).displayName() == contactName &&
    92                     if (mContactsSelectedFromPhoneBook.at(i).displayName() == contactName &&
   101                     	mContactsSelectedFromPhoneBook.at(i).address() != contactEmailAddress) {
    93                   	    mContactsSelectedFromPhoneBook.at(i).address() != contactEmailAddress) {
   102                         // Differentiate this contact's name by adding a * mark
    94                         // Differentiate this contact's name by adding a * mark
   103                         contactName.append("*");
    95                         contactName.append("*");
   104                     }
    96                     }
   105                 }
    97                 }
   106                 
    98                 
   107                 // Generate custom keyevent for this contact's name.
    99                 // Generate custom keyevent for this contact's name.
   108                 QKeyEvent contactNameKeyEvent(QEvent::KeyPress, Qt::Key_unknown, Qt::NoModifier,
   100                 QKeyEvent contactNameKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
   109                                               contactName);
   101                                               Qt::NoModifier, contactName);
   110                 // Forward this contactNameKeyEvent to base class to handle.
   102                 // Forward this contactNameKeyEvent to base class to handle.
   111                 NmHtmlLineEdit::keyPressEvent(&contactNameKeyEvent);
   103                 NmHtmlLineEdit::keyPressEvent(&contactNameKeyEvent);
   112             }
   104             }
   113 
   105 
   114             // Generate custom keyevent for Delimiter("; ").
   106             // Generate custom keyevent for Delimiter("; ").
   115             QKeyEvent delimiterKeyEvent(QEvent::KeyPress, Qt::Key_unknown, Qt::NoModifier, Delimiter);
   107             QKeyEvent delimiterKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
       
   108                                         Qt::NoModifier, Delimiter);
   116             // Forward the delimiterKeyEvent to base class to handle.
   109             // Forward the delimiterKeyEvent to base class to handle.
   117             NmHtmlLineEdit::keyPressEvent(&delimiterKeyEvent);
   110             NmHtmlLineEdit::keyPressEvent(&delimiterKeyEvent);
   118 			
   111 			
   119             // Form the contact into Qmail NmAddress format.
   112             // Form the contact into Qmail NmAddress format.
   120             NmAddress contact;
   113             NmAddress contact;
   121             contact.setAddress(contactEmailAddress);
   114             contact.setAddress(contactEmailAddress);
   122             contact.setDisplayName(contactName);
   115             contact.setDisplayName(contactName);
   123             
   116             
   124             // Add this NmAddress formated contact into mContactsSelectedFromPhoneBook.
   117             // Add this NmAddress formated contact into mContactsSelectedFromPhoneBook.
   125             mContactsSelectedFromPhoneBook.append(contact);
   118             mContactsSelectedFromPhoneBook.append(contact);
   126             }
       
   127         }
   119         }
   128     }
   120     }
   129     else {
   121     else {
   130         //Request returned NULL 
   122         //Request returned NULL 
   131         NMLOG("Request returned NULL.");
   123         NMLOG("ContactsPicker request returned NULL.");
   132     }
   124     }
   133         
   125         
   134 }
   126 }
   135 
   127 
   136 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   128 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)