author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 00:13:15 +0300 | |
changeset 72 | 6f657153cbc5 |
parent 44 | 36f374c67aa8 |
child 47 | 5b14749788d7 |
permissions | -rw-r--r-- |
31 | 1 |
/* |
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: QT contact resolver interface |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// SYSTEM INCLUDES |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
19 |
#include "qtcontacts.h" |
31 | 20 |
#include "qcontactdetailfilter.h" |
21 |
#include <QList> |
|
22 |
||
23 |
// USER INCLUDES |
|
24 |
#include "ccscontactsresolver.h" |
|
25 |
// ======================== Member Functions ==================== |
|
26 |
||
27 |
// ---------------------------------------------------------------------------- |
|
28 |
// CCsContactsResolver::ContactsResolver |
|
29 |
// @see contactsresolver.h |
|
30 |
// ---------------------------------------------------------------------------- |
|
31 |
CCsContactsResolver::CCsContactsResolver(QContactManager* manager): |
|
32 |
mPhonebookManager(manager) |
|
33 |
{ |
|
34 |
// do nothing |
|
35 |
} |
|
36 |
// ---------------------------------------------------------------------------- |
|
37 |
// CCsContactsResolver::~ContactsResolver |
|
38 |
// @see contactsresolver.h |
|
39 |
// ---------------------------------------------------------------------------- |
|
40 |
CCsContactsResolver::~CCsContactsResolver() |
|
41 |
{ |
|
42 |
// do nothing |
|
43 |
} |
|
44 |
||
45 |
// ---------------------------------------------------------------------------- |
|
46 |
// CCsContactsResolver::resolveContact |
|
47 |
// @see contactsresolver.h |
|
48 |
// ---------------------------------------------------------------------------- |
|
49 |
bool CCsContactsResolver::resolveContact( |
|
50 |
const QString &address, |
|
51 |
CCsContactDetail &contactDetail) |
|
52 |
{ |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
53 |
// apply filter on phone number field |
31 | 54 |
QContactDetailFilter phoneFilter; |
55 |
phoneFilter.setDetailDefinitionName( |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
56 |
QContactPhoneNumber::DefinitionName, |
31 | 57 |
QContactPhoneNumber::FieldNumber); |
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
58 |
|
31 | 59 |
phoneFilter.setValue(address); |
60 |
phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
|
61 |
QList<QContact> matchingContacts = mPhonebookManager->contacts(phoneFilter); |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
62 |
if ( matchingContacts.count() > 0 ) { |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
63 |
QContact match = matchingContacts.at(0); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
64 |
// Fill the contact details |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
65 |
contactDetail.contactId = match.localId(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
66 |
contactDetail.displayName = match.displayLabel(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
67 |
return true; |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
68 |
} |
31 | 69 |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
70 |
// apply filter on email address field |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
71 |
QContactDetailFilter emailFilter; |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
72 |
emailFilter.setDetailDefinitionName( |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
73 |
QContactEmailAddress::DefinitionName, |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
74 |
QContactEmailAddress::FieldEmailAddress); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
75 |
|
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
76 |
emailFilter.setValue(address); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
77 |
emailFilter.setMatchFlags(QContactFilter::MatchExactly); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
78 |
matchingContacts = mPhonebookManager->contacts(emailFilter); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
79 |
if ( matchingContacts.count() > 0 ) { |
31 | 80 |
QContact match = matchingContacts.at(0); |
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
81 |
// Fill the contact details |
31 | 82 |
contactDetail.contactId = match.localId(); |
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
83 |
contactDetail.displayName = match.displayLabel(); |
31 | 84 |
return true; |
85 |
} |
|
86 |
return false; |
|
87 |
} |
|
88 |
||
89 |
// ---------------------------------------------------------------------------- |
|
90 |
// CCsContactsResolver::resolveContactId |
|
91 |
// @see contactsresolver.h |
|
92 |
// ---------------------------------------------------------------------------- |
|
93 |
void CCsContactsResolver::resolveContactId( |
|
94 |
const quint32 &contactId, |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
95 |
CCsContactDetail &contactDetail) |
31 | 96 |
{ |
97 |
// Fetch back the persisted contact |
|
98 |
QContact contact = mPhonebookManager->contact(contactId); |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
99 |
contactDetail.contactId = contact.localId(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
100 |
|
31 | 101 |
contactDetail.displayName = contact.displayLabel(); |
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
102 |
|
31 | 103 |
QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>(); |
104 |
int numberCount = numbers.count(); |
|
105 |
||
106 |
for ( int a=0; a<numberCount ;++a) |
|
107 |
{ |
|
108 |
QString phoneNumber= numbers.at(a).number(); |
|
109 |
contactDetail.addressList.append(phoneNumber); |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
110 |
} |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
111 |
|
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
112 |
QList<QContactEmailAddress> emailAddresses = contact.details<QContactEmailAddress>(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
113 |
int emailCount = emailAddresses.count(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
114 |
|
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
115 |
for ( int a=0; a<emailCount ;++a) |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
116 |
{ |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
117 |
QString emailAddr= emailAddresses.at(a).emailAddress(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
118 |
contactDetail.addressList.append(emailAddr); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
119 |
} |
31 | 120 |
} |
121 |
||
122 |
// EOF |