messagingapp/msgappfw/server/src/ccscontactsresolver.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    14  * Description: QT contact resolver interface
    14  * Description: QT contact resolver interface
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // SYSTEM INCLUDES
    18 // SYSTEM INCLUDES
    19 #include "qtcontacts.h" 
    19 #include "qtcontacts.h"
    20 #include "qcontactdetailfilter.h"
    20 #include "qcontactdetailfilter.h"
    21 #include <QList>
    21 #include <QList>
    22 
    22 
    23 // USER INCLUDES
    23 // USER INCLUDES
    24 #include "ccscontactsresolver.h"
    24 #include "ccscontactsresolver.h"
    48 // ----------------------------------------------------------------------------
    48 // ----------------------------------------------------------------------------
    49 bool CCsContactsResolver::resolveContact(
    49 bool CCsContactsResolver::resolveContact(
    50         const QString &address,
    50         const QString &address,
    51         CCsContactDetail &contactDetail)
    51         CCsContactDetail &contactDetail)
    52     {
    52     {
       
    53     // apply filter on phone number field
    53     QContactDetailFilter phoneFilter;
    54     QContactDetailFilter phoneFilter;
    54     phoneFilter.setDetailDefinitionName(
    55     phoneFilter.setDetailDefinitionName(
    55             QContactPhoneNumber::DefinitionName, 
    56             QContactPhoneNumber::DefinitionName,
    56             QContactPhoneNumber::FieldNumber);
    57             QContactPhoneNumber::FieldNumber);
    57     
    58 
    58     phoneFilter.setValue(address);
    59     phoneFilter.setValue(address);
    59     phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
    60     phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
       
    61     QList<QContact> matchingContacts = mPhonebookManager->contacts(phoneFilter);
       
    62     if ( matchingContacts.count() > 0 ) {
       
    63         QContact match = matchingContacts.at(0);
       
    64         // Fill the contact details
       
    65         contactDetail.contactId = match.localId();
       
    66         contactDetail.displayName = match.displayLabel();
       
    67         return true;
       
    68     }
    60 
    69 
    61     QList<QContactSortOrder> sortOrder;
    70     // apply filter on email address field
    62     QList<QContact> matchingContacts = mPhonebookManager->contacts(
    71     QContactDetailFilter emailFilter;
    63                                                 phoneFilter,
    72     emailFilter.setDetailDefinitionName(
    64                                                 sortOrder,
    73             QContactEmailAddress::DefinitionName,
    65                                                 QStringList());
    74             QContactEmailAddress::FieldEmailAddress);
    66 
    75 
    67     if ( matchingContacts.count() > 0 ) {	        
    76     emailFilter.setValue(address);
       
    77     emailFilter.setMatchFlags(QContactFilter::MatchExactly);
       
    78     matchingContacts = mPhonebookManager->contacts(emailFilter);
       
    79     if ( matchingContacts.count() > 0 ) {
    68         QContact match = matchingContacts.at(0);
    80         QContact match = matchingContacts.at(0);
    69         // Fill the contact details        
    81         // Fill the contact details
    70         contactDetail.contactId = match.localId();
    82         contactDetail.contactId = match.localId();
    71         contactDetail.displayName = match.displayLabel();   
    83         contactDetail.displayName = match.displayLabel();
    72         return true;
    84         return true;
    73     }
    85     }
    74     return false;
    86     return false;
    75     }
    87     }
    76 
    88 
    78 // CCsContactsResolver::resolveContactId
    90 // CCsContactsResolver::resolveContactId
    79 // @see contactsresolver.h
    91 // @see contactsresolver.h
    80 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
    81 void CCsContactsResolver::resolveContactId(
    93 void CCsContactsResolver::resolveContactId(
    82         const quint32 &contactId,
    94         const quint32 &contactId,
    83         CCsContactDetail &contactDetail)	
    95         CCsContactDetail &contactDetail)
    84     {
    96     {
    85     // Fetch back the persisted contact
    97     // Fetch back the persisted contact
    86     QContact contact = mPhonebookManager->contact(contactId);
    98     QContact contact = mPhonebookManager->contact(contactId);
    87     contactDetail.contactId = contact.localId(); 
    99     contactDetail.contactId = contact.localId();
    88     
   100 
    89     contactDetail.displayName = contact.displayLabel();
   101     contactDetail.displayName = contact.displayLabel();
    90         
   102 
    91     QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>();
   103     QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>();
    92     int numberCount = numbers.count();
   104     int numberCount = numbers.count();
    93 
   105 
    94     for ( int a=0; a<numberCount ;++a)
   106     for ( int a=0; a<numberCount ;++a)
    95         {
   107         {
    96         QString phoneNumber= numbers.at(a).number();
   108         QString phoneNumber= numbers.at(a).number();
    97         contactDetail.addressList.append(phoneNumber);
   109         contactDetail.addressList.append(phoneNumber);
    98         }    
   110         }
       
   111 
       
   112     QList<QContactEmailAddress> emailAddresses = contact.details<QContactEmailAddress>();
       
   113     int emailCount = emailAddresses.count();
       
   114 
       
   115     for ( int a=0; a<emailCount ;++a)
       
   116         {
       
   117         QString emailAddr= emailAddresses.at(a).emailAddress();
       
   118         contactDetail.addressList.append(emailAddr);
       
   119         }
    99     }
   120     }
   100 
   121 
   101 // EOF
   122 // EOF