emailuis/nmailuiwidgets/src/nmrecipientlineedit.cpp
changeset 43 99bcbff212ad
parent 23 2dc6caa42ec3
child 47 f83bd4ae1fe3
child 54 997a02608b3a
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    27 */
    27 */
    28 NmRecipientLineEdit::NmRecipientLineEdit(QGraphicsItem *parent) 
    28 NmRecipientLineEdit::NmRecipientLineEdit(QGraphicsItem *parent) 
    29     : NmHtmlLineEdit(parent),
    29     : NmHtmlLineEdit(parent),
    30     mNeedToGenerateEmailAddressList(true)
    30     mNeedToGenerateEmailAddressList(true)
    31 {
    31 {
       
    32     NM_FUNCTION;
       
    33     
    32     connect(this, SIGNAL(textChanged(QString)), this, SLOT(handleTextChanged(QString)));
    34     connect(this, SIGNAL(textChanged(QString)), this, SLOT(handleTextChanged(QString)));
    33 }
    35 }
    34 
    36 
    35 
    37 
    36 /*!
    38 /*!
    37    Destructor
    39    Destructor
    38 */
    40 */
    39 NmRecipientLineEdit::~NmRecipientLineEdit()
    41 NmRecipientLineEdit::~NmRecipientLineEdit()
    40 {
    42 {
       
    43     NM_FUNCTION;
    41 }
    44 }
    42 
    45 
    43 
    46 
    44 /*!
    47 /*!
    45    Get the emailaddress list generated from the content of the lineedit.
    48    Get the emailaddress list generated from the content of the lineedit.
    46 */
    49 */
    47 QList<NmAddress> NmRecipientLineEdit::emailAddressList()
    50 QList<NmAddress> NmRecipientLineEdit::emailAddressList()
    48 {
    51 {
       
    52     NM_FUNCTION;
       
    53     
    49     if (mNeedToGenerateEmailAddressList) {
    54     if (mNeedToGenerateEmailAddressList) {
    50         // Empty mEmailAddressList.
    55         // Empty mEmailAddressList.
    51         mEmailAddressList.clear();
    56         mEmailAddressList.clear();
    52         // Generate mEmailAddressList from the lineedit content.
    57         // Generate mEmailAddressList from the lineedit content.
    53         generateEmailAddressList();					
    58         generateEmailAddressList();					
    59 
    64 
    60 
    65 
    61 #ifdef Q_OS_SYMBIAN
    66 #ifdef Q_OS_SYMBIAN
    62 /*!
    67 /*!
    63    This Slot inserts the selected contacts from Contacts-picker into the lineedit cursor position.    
    68    This Slot inserts the selected contacts from Contacts-picker into the lineedit cursor position.    
    64    "You shouldn't be able to convert the parameter selectedContacts into a QStringlist or QString,
       
    65    you need to convert selectedContacts into a CntServicesContactList." -- Comments from 
       
    66    Contacts-picker author Erkinheimo Joonas (Nokia-D/Espoo)
       
    67    Contacts-Picker should be working in TB 10.1 MCL wk16 release, 
       
    68    Custom metatypes problem will be fixed in wk16 by QtHighway.
       
    69 */
    69 */
    70 void NmRecipientLineEdit::insertSelectedContacts(const QVariant &selectedContacts)
    70 void NmRecipientLineEdit::insertSelectedContacts(const QVariant &selectedContacts)
    71 {
    71 {
       
    72     NM_FUNCTION;
       
    73     
    72     if (!selectedContacts.isNull()) {
    74     if (!selectedContacts.isNull()) {
    73         CntServicesContactList contactList;
    75         CntServicesContactList contactList;
    74         contactList = qVariantValue<CntServicesContactList>(selectedContacts);
    76         contactList = qVariantValue<CntServicesContactList>(selectedContacts);
    75 
    77 
    76         // Loop through all the selected contacts.
    78         // Loop through all the selected contacts.
    85                 		                              Qt::NoModifier, contactEmailAddress);
    87                 		                              Qt::NoModifier, contactEmailAddress);
    86                 // Forward this contactEmailAddressKeyEvent to base class to handle.
    88                 // Forward this contactEmailAddressKeyEvent to base class to handle.
    87                 NmHtmlLineEdit::keyPressEvent(&contactEmailAddressKeyEvent);
    89                 NmHtmlLineEdit::keyPressEvent(&contactEmailAddressKeyEvent);
    88             }
    90             }
    89             else {
    91             else {
    90                 // Handle a rare case: there's another contact has same name but has different emailaddress.
    92                 // Handle a rare case: there are contacts has same name but different emailaddress.
    91                 for (int i = 0; i != mContactsSelectedFromPhoneBook.count(); ++i) {
    93                 for (int i = 0; i != mRecipientsAddedFromContacts.count(); ++i) {
    92                     if (mContactsSelectedFromPhoneBook.at(i).displayName() == contactName &&
    94                     if (mRecipientsAddedFromContacts.at(i).displayName() == contactName &&
    93                   	    mContactsSelectedFromPhoneBook.at(i).address() != contactEmailAddress) {
    95                   	    mRecipientsAddedFromContacts.at(i).address() != contactEmailAddress) {
    94                         // Differentiate this contact's name by adding a * mark
    96                         // Differentiate this contact by supplying it's emailaddress
    95                         contactName.append("*");
    97                         contactName.append("<");
       
    98                         contactName.append(contactEmailAddress);
       
    99                         contactName.append(">");
    96                     }
   100                     }
    97                 }
   101                 }
    98                 
   102                 
    99                 // Generate custom keyevent for this contact's name.
   103                 // Generate custom keyevent for this contact's name.
   100                 QKeyEvent contactNameKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
   104                 QKeyEvent contactNameKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 
   112             // Form the contact into Qmail NmAddress format.
   116             // Form the contact into Qmail NmAddress format.
   113             NmAddress contact;
   117             NmAddress contact;
   114             contact.setAddress(contactEmailAddress);
   118             contact.setAddress(contactEmailAddress);
   115             contact.setDisplayName(contactName);
   119             contact.setDisplayName(contactName);
   116             
   120             
   117             // Add this NmAddress formated contact into mContactsSelectedFromPhoneBook.
   121             // Add this NmAddress formated contact into mRecipientsAddedFromContacts.
   118             mContactsSelectedFromPhoneBook.append(contact);
   122             mRecipientsAddedFromContacts.append(contact);
   119         }
   123         }
   120     }
   124     }
   121     else {
   125     else {
   122         //Request returned NULL 
   126         //Request returned NULL 
   123         NMLOG("ContactsPicker request returned NULL.");
   127         NM_COMMENT("ContactsPicker request returned NULL.");
   124     }
   128     }
   125         
   129         
   126 }
   130 }
   127 
   131 
   128 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   132 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   135    P.S. keyPressEvent can only catch QKeyEvent "," or ";" typed from physical keyboard,
   139    P.S. keyPressEvent can only catch QKeyEvent "," or ";" typed from physical keyboard,
   136    inputMethodEvent method handles user inputs "," or ";" from virtual keyboard.
   140    inputMethodEvent method handles user inputs "," or ";" from virtual keyboard.
   137 */
   141 */
   138 void NmRecipientLineEdit::keyPressEvent(QKeyEvent *keyEvent)
   142 void NmRecipientLineEdit::keyPressEvent(QKeyEvent *keyEvent)
   139 {
   143 {
       
   144     NM_FUNCTION;
       
   145     
   140 	bool eventHandled = false;
   146 	bool eventHandled = false;
   141 	
   147 	
   142     if (keyEvent) {
   148     if (keyEvent) {
   143         switch (keyEvent->key()) {    
   149         switch (keyEvent->key()) {    
   144         case Qt::Key_Comma:
   150         case Qt::Key_Comma:
   182    inputMethodEvent handles replacing user inputs "," or ";" from virtual keyboard with "; ".
   188    inputMethodEvent handles replacing user inputs "," or ";" from virtual keyboard with "; ".
   183    P.S. keyPressEvent can only catch QKeyEvent "," or ";" typed from physical keyboard
   189    P.S. keyPressEvent can only catch QKeyEvent "," or ";" typed from physical keyboard
   184 */
   190 */
   185 void NmRecipientLineEdit::inputMethodEvent(QInputMethodEvent *event)
   191 void NmRecipientLineEdit::inputMethodEvent(QInputMethodEvent *event)
   186 {
   192 {
       
   193     NM_FUNCTION;
       
   194     
   187 	bool eventHandled = false;
   195 	bool eventHandled = false;
   188 	
   196 	
   189     if (event) {
   197     if (event) {
   190         QString eventText = event->commitString();
   198         QString eventText = event->commitString();
   191 
   199 
   218     }
   226     }
   219 }
   227 }
   220 
   228 
   221  
   229  
   222 /*!
   230 /*!
   223    Generate emailaddress list from the content of the lineedit.
   231    Generate a list of all the email addresses from the content of the lineedit.
   224 */
   232 */
   225 void NmRecipientLineEdit::generateEmailAddressList()
   233 void NmRecipientLineEdit::generateEmailAddressList()
   226 {   
   234 {   
       
   235     NM_FUNCTION;
       
   236     
   227     // Remove whitespace from the start and the end of the lineedit content. 
   237     // Remove whitespace from the start and the end of the lineedit content. 
   228     QString contentOfLineedit = (this->text()).trimmed();
   238     QString contentOfLineedit = (this->text()).trimmed();
   229     
   239     
   230     // Split the lineedit content into individual items wherever a Semicolon(";") occurs, 
   240     // Split the lineedit content by semicolon(";").
   231     // empty entries don't appear in the result.
       
   232     QStringList itemsOfLineeditContent = contentOfLineedit.split(Semicolon, QString::SkipEmptyParts);
   241     QStringList itemsOfLineeditContent = contentOfLineedit.split(Semicolon, QString::SkipEmptyParts);
   233         
   242         
   234     // Loop through all the items in the itemsOfLineeditContent list.
   243     // Loop through all the items of the lineedit content.
   235     for (int i = 0; i != itemsOfLineeditContent.count(); ++i) {
   244     for (int i = 0; i != itemsOfLineeditContent.count(); ++i) {
   236         // Remove whitespace from the start and the end of the item.
   245         // Remove whitespace from the start and the end of the item.
   237         QString itemInLineedit = itemsOfLineeditContent.at(i).trimmed();
   246         QString itemInLineedit = itemsOfLineeditContent.at(i).trimmed();
   238 
   247 
   239         if (mContactsSelectedFromPhoneBook.count() > 0) {
   248         // Get the count of the recipients added from Contacts.
   240             // Loop through all the elements in the mContactsSelectedFromPhoneBook list.
   249         int countOfRecipientsAddedFromContacts = mRecipientsAddedFromContacts.count();
   241             for (int j = 0; j != mContactsSelectedFromPhoneBook.count(); ++j) {
   250         
   242                 NmAddress contact = mContactsSelectedFromPhoneBook.at(j);		
   251         // If there is recipient added from Contacts.
   243                 // If the item matches either the name or the emailaddress of this contact.
   252         if (countOfRecipientsAddedFromContacts > 0) {
   244                 if (itemInLineedit == contact.displayName() || itemInLineedit == contact.address()) {
   253             QStringList listOfAddedContactsName;
   245                     // Add the contact into mEmailAddressList.
   254             QStringList listOfAddedContactsAddress;
   246                     mEmailAddressList.append(contact);  
   255             
   247                 }
   256             // Loop through all the recipients added from Contacts.
   248                 else {
   257             for (int j = 0; j != countOfRecipientsAddedFromContacts; ++j) {
   249                     // Form the item into Qmail NmAddress format.
   258                 NmAddress contact = mRecipientsAddedFromContacts.at(j);          
   250                     NmAddress recipient;
   259                 listOfAddedContactsName.append(contact.displayName());
   251                     recipient.setAddress(itemInLineedit);
   260                 listOfAddedContactsAddress.append(contact.address());
   252                     // no display name info available, so don't us it
   261             }
   253                     recipient.setDisplayName(QString()); 
   262                 
   254                     // Add this NmAddress formated lineedit item into mEmailAddressList.
   263             int indexInAddedContactsName = listOfAddedContactsName.indexOf(itemInLineedit);
   255                     mEmailAddressList.append(recipient);  
   264             int indexInAddedContactsAddress = listOfAddedContactsAddress.indexOf(itemInLineedit);
   256                 }
   265             
   257             }
   266             // If this itemInLineedit matches the name of one added contact.
   258         }
   267             if (indexInAddedContactsName >= 0) {
   259         else {
   268                 // Add the recipient into mEmailAddressList.
   260             // Form the item into Qmail NmAddress format.
   269                 mEmailAddressList.append(mRecipientsAddedFromContacts.at(indexInAddedContactsName));  
       
   270             }
       
   271             // If this itemInLineedit matches the emailaddress of one added contact.
       
   272             else if (indexInAddedContactsAddress >= 0) { 
       
   273                 // Add the recipient into mEmailAddressList.
       
   274                 mEmailAddressList.append(mRecipientsAddedFromContacts.at(indexInAddedContactsAddress));  
       
   275             }
       
   276             // This itemInLineedit is not added from Contacts
       
   277             else { 
       
   278                 // Form the item into NmAddress format.
       
   279                 NmAddress recipient;
       
   280                 recipient.setAddress(itemInLineedit);
       
   281                 // There is no display name info available, so leave display name empty.
       
   282                 recipient.setDisplayName(QString()); 
       
   283                 // Add this NmAddress formated lineedit item into mEmailAddressList.
       
   284                 mEmailAddressList.append(recipient);  
       
   285             }
       
   286         }
       
   287         else { // There is no recipient is added from Contacts
       
   288             // Form the item into NmAddress format.
   261             NmAddress recipient;
   289             NmAddress recipient;
   262             recipient.setAddress(itemInLineedit);
   290             recipient.setAddress(itemInLineedit);
   263             // no display name info available, so don't us it
   291             // There is no display name info available, so leave display name emapty.
   264             recipient.setDisplayName(QString()); 
   292             recipient.setDisplayName(QString()); 
   265             // Add this NmAddress formated lineedit item into mEmailAddressList.
   293             // Add this NmAddress formated lineedit item into mEmailAddressList.
   266             mEmailAddressList.append(recipient);  
   294             mEmailAddressList.append(recipient);  
   267         }
   295         }
   268     }
   296     }
   272 /*!
   300 /*!
   273    This Slot is called when the lineedit text changes.
   301    This Slot is called when the lineedit text changes.
   274 */
   302 */
   275 void NmRecipientLineEdit::handleTextChanged(const QString &text)
   303 void NmRecipientLineEdit::handleTextChanged(const QString &text)
   276 {
   304 {
       
   305     NM_FUNCTION;
       
   306     
   277     Q_UNUSED(text);
   307     Q_UNUSED(text);
   278     mNeedToGenerateEmailAddressList = true;
   308     mNeedToGenerateEmailAddressList = true;
   279 }
   309 }