emailuis/nmailuiwidgets/src/nmrecipientlineedit.cpp
changeset 47 f83bd4ae1fe3
parent 43 99bcbff212ad
child 48 10eaf342f539
--- a/emailuis/nmailuiwidgets/src/nmrecipientlineedit.cpp	Fri Jun 11 16:42:02 2010 +0300
+++ b/emailuis/nmailuiwidgets/src/nmrecipientlineedit.cpp	Thu Jun 24 14:32:18 2010 +0300
@@ -65,29 +65,43 @@
 
 #ifdef Q_OS_SYMBIAN
 /*!
-   This Slot inserts the selected contacts from Contacts-picker into the lineedit cursor position.    
+   This Slot appends the selected contacts to the end of the lineedit content.    
 */
-void NmRecipientLineEdit::insertSelectedContacts(const QVariant &selectedContacts)
+void NmRecipientLineEdit::addSelectedContacts(const QVariant &selectedContacts)
 {
     NM_FUNCTION;
     
-    if (!selectedContacts.isNull()) {
-        CntServicesContactList contactList;
-        contactList = qVariantValue<CntServicesContactList>(selectedContacts);
+    // If user selected contact
+    if (!selectedContacts.isNull()) {        
+
+        // If the lineedit is not empty and if there is no ";" or "; " at the end,
+        // add a delimiter("; ") at the end.
+        if (this->text().length() != 0 && !(this->text().endsWith(Semicolon)) && 
+            !(this->text().endsWith(Delimiter))){
+            
+            // Move cursor to the end of the lineedit.
+            this->setCursorPosition(this->text().length());       
+            QTextCursor textCursor(this->textCursor());
+            // Append delimiter("; ") to the end of the lineedit
+            textCursor.insertText(Delimiter);
+        }
+        
+        CntServicesContactList contactList = qVariantValue<CntServicesContactList>(selectedContacts);
 
         // Loop through all the selected contacts.
         for (int i = 0; i < contactList.count(); ++i) {
+            QString contactName = contactList[i].mDisplayName;
             QString contactEmailAddress = contactList[i].mEmailAddress;
-            QString contactName = contactList[i].mDisplayName;
-
-            // If this contact has no name.
-            if(contactName.isEmpty()) {				
-                // Generate a custom keyevent for this contact's emailaddress.
-                QKeyEvent contactEmailAddressKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
-                		                              Qt::NoModifier, contactEmailAddress);
-                // Forward this contactEmailAddressKeyEvent to base class to handle.
-                NmHtmlLineEdit::keyPressEvent(&contactEmailAddressKeyEvent);
+            
+            // If this contact has no name, use it's emailaddress as the display name
+            if(contactName.isEmpty()) {	
+                // Move cursor to the end of the lineedit.
+                this->setCursorPosition(this->text().length());       
+                QTextCursor textCursor(this->textCursor());
+                // Append contactEmailAddress to the end of the lineedit
+                textCursor.insertText(contactEmailAddress);
             }
+            // If this contact has name, use the name as the display name
             else {
                 // Handle a rare case: there are contacts has same name but different emailaddress.
                 for (int i = 0; i != mRecipientsAddedFromContacts.count(); ++i) {
@@ -100,19 +114,17 @@
                     }
                 }
                 
-                // Generate custom keyevent for this contact's name.
-                QKeyEvent contactNameKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
-                                              Qt::NoModifier, contactName);
-                // Forward this contactNameKeyEvent to base class to handle.
-                NmHtmlLineEdit::keyPressEvent(&contactNameKeyEvent);
+                // Move cursor to the end of the lineedit.
+                this->setCursorPosition(this->text().length());       
+                QTextCursor textCursor(this->textCursor());
+                // Append contactName to the end of the lineedit
+                textCursor.insertText(contactName);
             }
-
-            // Generate custom keyevent for Delimiter("; ").
-            QKeyEvent delimiterKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
-                                        Qt::NoModifier, Delimiter);
-            // Forward the delimiterKeyEvent to base class to handle.
-            NmHtmlLineEdit::keyPressEvent(&delimiterKeyEvent);
-			
+                
+            QTextCursor textCursor(this->textCursor());
+            // Append delimiter("; ")
+            textCursor.insertText(Delimiter);
+            
             // Form the contact into Qmail NmAddress format.
             NmAddress contact;
             contact.setAddress(contactEmailAddress);
@@ -120,7 +132,7 @@
             
             // Add this NmAddress formated contact into mRecipientsAddedFromContacts.
             mRecipientsAddedFromContacts.append(contact);
-        }
+        } // end of for (int i = 0; i < contactList.count(); ++i)  
     }
     else {
         //Request returned NULL