51 static int resolveContactDisplayName(const QString& contactNumber, |
51 static int resolveContactDisplayName(const QString& contactNumber, |
52 QString& displayName, |
52 QString& displayName, |
53 int& countPhoneNumber) |
53 int& countPhoneNumber) |
54 { |
54 { |
55 QContactManager phonebookManager; |
55 QContactManager phonebookManager; |
|
56 QVariant address(contactNumber); |
|
57 |
|
58 // apply filter on phone number field |
56 QContactDetailFilter phoneFilter; |
59 QContactDetailFilter phoneFilter; |
57 |
60 phoneFilter.setDetailDefinitionName( |
58 phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, |
61 QContactPhoneNumber::DefinitionName, |
59 QContactPhoneNumber::FieldNumber); |
62 QContactPhoneNumber::FieldNumber); |
60 |
63 |
61 QVariant address(contactNumber); |
|
62 phoneFilter.setValue(address); |
64 phoneFilter.setValue(address); |
63 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
65 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
64 |
|
65 QList<QContact> matchingContacts = |
66 QList<QContact> matchingContacts = |
66 phonebookManager.contacts(phoneFilter); |
67 phonebookManager.contacts(phoneFilter); |
67 |
|
68 if (matchingContacts.count() > 0) |
68 if (matchingContacts.count() > 0) |
69 { |
69 { |
70 // Fill the contact details |
70 // Fill the contact details |
71 QContact match = matchingContacts.at(0); |
71 QContact match = matchingContacts.at(0); |
72 |
72 |
73 displayName = match.displayLabel(); |
73 displayName = match.displayLabel(); |
74 QList<QContactPhoneNumber> numbers = |
74 QList<QContactPhoneNumber> numbers = |
75 match.details<QContactPhoneNumber> (); |
75 match.details<QContactPhoneNumber> (); |
76 countPhoneNumber = numbers.count(); |
76 countPhoneNumber = numbers.count(); |
77 return match.localId(); |
77 return match.localId(); |
78 } |
78 } |
79 else // no matching contacts |
79 |
80 { |
80 // apply filter on email address field |
81 displayName = contactNumber; |
81 QContactDetailFilter emailFilter; |
82 return -1; |
82 emailFilter.setDetailDefinitionName( |
83 } |
83 QContactEmailAddress::DefinitionName, |
84 } |
84 QContactEmailAddress::FieldEmailAddress); |
85 |
85 |
|
86 emailFilter.setValue(address); |
|
87 emailFilter.setMatchFlags(QContactFilter::MatchExactly); |
|
88 matchingContacts = phonebookManager.contacts(emailFilter); |
|
89 if ( matchingContacts.count() > 0 ) |
|
90 { |
|
91 // Fill the contact details |
|
92 QContact match = matchingContacts.at(0); |
|
93 |
|
94 displayName = match.displayLabel(); |
|
95 QList<QContactEmailAddress> numbers = |
|
96 match.details<QContactEmailAddress> (); |
|
97 countPhoneNumber = numbers.count(); |
|
98 return match.localId(); |
|
99 } |
|
100 |
|
101 // no matching contact |
|
102 displayName = contactNumber; |
|
103 return -1; |
|
104 } |
|
105 |
86 /** |
106 /** |
87 * This shall resolve contact number with display name |
107 * This shall resolve contact number with display name |
88 * @param contactNumber number to resolve |
108 * @param contactNumber number to resolve |
89 * @param fieldName specifies filter name |
109 * @param fieldName specifies filter name |
90 * @param fieldType specifies filter type |
110 * @param fieldType specifies filter type |