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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QList> |
|
19 #include <QString> |
|
20 #include <QChar> |
|
21 #include <qcontact.h> |
|
22 #include <qcontactdetailfilter.h> |
|
23 #include <qcontactphonenumber.h> |
|
24 #include <qtcontactsglobal.h> |
|
25 #include <qcontactmanager.h> |
|
26 |
|
27 #include "cphcntmatcherimpl2.h" |
|
28 #include "cphcntmatch2.h" |
|
29 #include "qtphonelog.h" |
|
30 |
|
31 |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // Static constructor |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CPhCntMatcherImpl2* CPhCntMatcherImpl2::NewL(QContactManager* aContactManager) |
|
38 { |
|
39 __ASSERT_ALWAYS(aContactManager!=NULL, User::Leave(KErrArgument)); |
|
40 CPhCntMatcherImpl2* self = new( ELeave )CPhCntMatcherImpl2(aContactManager); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Destructor |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CPhCntMatcherImpl2::~CPhCntMatcherImpl2() |
|
52 { |
|
53 delete iMatch; |
|
54 delete iContactManager; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // From CPhCntMatcher |
|
59 // Tries to find a contact which has aTelNumber. |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 TInt CPhCntMatcherImpl2::MatchNumber( |
|
63 MPhCntMatch*& aMatch, |
|
64 const TDesC& aTelNumber) |
|
65 { |
|
66 TInt err = KErrNone; |
|
67 QString telnumber((QChar*)aTelNumber.Ptr(),aTelNumber.Length()); |
|
68 QContactDetailFilter filter; |
|
69 filter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); |
|
70 filter.setValue(telnumber); |
|
71 QList<QContactLocalId> contacts; |
|
72 contacts = iContactManager->contactIds(filter); |
|
73 PHONE_DEBUG2("CPhCntMatcherImpl2::MatchNumber(): matched contacts count is:", contacts.count()); |
|
74 //only 1 exact match returns a contact to be used |
|
75 if (contacts.isEmpty() || contacts.count() > 1 ) |
|
76 { |
|
77 return KErrNotFound; |
|
78 } |
|
79 else |
|
80 { |
|
81 delete iMatch; |
|
82 iMatch = NULL; |
|
83 TRAP(err, iMatch = CPhCntMatch2::NewL(iContactManager->contact(contacts.at(0)))); |
|
84 if (!err) |
|
85 { |
|
86 aMatch = iMatch; |
|
87 PHONE_DEBUG("CPhCntMatcherImpl2::MatchNumber() -- matched contact is ready"); |
|
88 } |
|
89 return err; |
|
90 } |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // From CPhCntMatcher |
|
95 // Tries to find a contact which has aTelNumber. |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CPhCntMatcherImpl2::MatchNumber( |
|
99 MPhCntMatch*& /*aMatch*/, |
|
100 const TDesC& /*aTelNumber*/, |
|
101 const CPhCntContactId& /*aContactId*/ ) |
|
102 { |
|
103 return KErrNone; |
|
104 } |
|
105 // --------------------------------------------------------------------------- |
|
106 // From CPhCntMatcher |
|
107 // Tries to find a contact which has aTelNumber, contactId and fieldId |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 TInt CPhCntMatcherImpl2::MatchNumber( |
|
111 MPhCntMatch*& /*aMatch*/, |
|
112 const TDesC& /*aTelNumber*/, |
|
113 const CPhCntContactId& /*aContactId*/, |
|
114 const TFieldId /*aFieldId*/ ) |
|
115 { |
|
116 return KErrNone; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // From CPhCntMatcher |
|
121 // Empty implementation. |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CPhCntMatcherImpl2::MatchVoipNumber( |
|
125 MPhCntMatch*& /*aMatch*/, |
|
126 const TDesC& /*aMatchString*/, |
|
127 TBool /*aAllowUserNameMatch*/, |
|
128 TInt /*aCharsForMatching*/ ) |
|
129 { |
|
130 return KErrNotFound; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // From CPhCntMatcher |
|
135 // Empty implementation. |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 TInt CPhCntMatcherImpl2::MatchVoipNumber( |
|
139 MPhCntMatch*& /*aMatch*/, |
|
140 const CPhCntContactId& /*aContactId*/ ) |
|
141 { |
|
142 return KErrNotFound; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // From CPhCntMatcher |
|
147 // Empty implementation. Implemented in CPhCntMatcherVoIPImpl. |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 TBool CPhCntMatcherImpl2::HasCSNumbers( const CPhCntContactId& /*aContactId*/ ) |
|
151 { |
|
152 return EFalse; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // From CPhCntMatcher |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CPhCntMatcherImpl2::MatchNumber( |
|
160 MPhCntMatch*& aMatch, |
|
161 const TDesC& aTelNumber, |
|
162 TInt aContactId ) |
|
163 { |
|
164 TInt err = KErrNone; |
|
165 //now there's no way to check if the contact is valid or not |
|
166 QContact contact; |
|
167 contact = iContactManager->contact(aContactId); |
|
168 //should check if valid or not |
|
169 delete iMatch; |
|
170 iMatch = NULL; |
|
171 TRAP(err, iMatch = CPhCntMatch2::NewL(contact)); |
|
172 if (!err) |
|
173 { |
|
174 TRAP(err, iMatch->SetNumberL(aTelNumber)); |
|
175 } |
|
176 if (!err) |
|
177 { |
|
178 aMatch = iMatch; |
|
179 PHONE_DEBUG("CPhCntMatcherImpl2::MatchNumber(ContactId) -- matched contact is ready"); |
|
180 } |
|
181 return err; |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // Constructor |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 CPhCntMatcherImpl2::CPhCntMatcherImpl2(QContactManager* aContactManager) |
|
190 :iContactManager(aContactManager) |
|
191 { |
|
192 iMatch = NULL; |
|
193 } |
|
194 |
|
195 |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // Second phase constructor |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void CPhCntMatcherImpl2::ConstructL() |
|
202 { |
|
203 |
|
204 } |
|
205 |
|