messagingapp/msgappfw/server/src/ccscontactsresolver.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 44 36f374c67aa8
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
    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<QContact> matchingContacts = mPhonebookManager->contacts(phoneFilter);
    70     // apply filter on email address field
       
    71     QContactDetailFilter emailFilter;
       
    72     emailFilter.setDetailDefinitionName(
       
    73             QContactEmailAddress::DefinitionName,
       
    74             QContactEmailAddress::FieldEmailAddress);
    62 
    75 
    63     if ( matchingContacts.count() > 0 ) {	        
    76     emailFilter.setValue(address);
       
    77     emailFilter.setMatchFlags(QContactFilter::MatchExactly);
       
    78     matchingContacts = mPhonebookManager->contacts(emailFilter);
       
    79     if ( matchingContacts.count() > 0 ) {
    64         QContact match = matchingContacts.at(0);
    80         QContact match = matchingContacts.at(0);
    65         // Fill the contact details        
    81         // Fill the contact details
    66         contactDetail.contactId = match.localId();
    82         contactDetail.contactId = match.localId();
    67         contactDetail.displayName = match.displayLabel();   
    83         contactDetail.displayName = match.displayLabel();
    68         return true;
    84         return true;
    69     }
    85     }
    70     return false;
    86     return false;
    71     }
    87     }
    72 
    88 
    74 // CCsContactsResolver::resolveContactId
    90 // CCsContactsResolver::resolveContactId
    75 // @see contactsresolver.h
    91 // @see contactsresolver.h
    76 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
    77 void CCsContactsResolver::resolveContactId(
    93 void CCsContactsResolver::resolveContactId(
    78         const quint32 &contactId,
    94         const quint32 &contactId,
    79         CCsContactDetail &contactDetail)	
    95         CCsContactDetail &contactDetail)
    80     {
    96     {
    81     // Fetch back the persisted contact
    97     // Fetch back the persisted contact
    82     QContact contact = mPhonebookManager->contact(contactId);
    98     QContact contact = mPhonebookManager->contact(contactId);
    83     contactDetail.contactId = contact.localId(); 
    99     contactDetail.contactId = contact.localId();
    84     
   100 
    85     contactDetail.displayName = contact.displayLabel();
   101     contactDetail.displayName = contact.displayLabel();
    86         
   102 
    87     QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>();
   103     QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>();
    88     int numberCount = numbers.count();
   104     int numberCount = numbers.count();
    89 
   105 
    90     for ( int a=0; a<numberCount ;++a)
   106     for ( int a=0; a<numberCount ;++a)
    91         {
   107         {
    92         QString phoneNumber= numbers.at(a).number();
   108         QString phoneNumber= numbers.at(a).number();
    93         contactDetail.addressList.append(phoneNumber);
   109         contactDetail.addressList.append(phoneNumber);
    94         }    
   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         }
    95     }
   120     }
    96 
   121 
    97 // EOF
   122 // EOF