|
1 /* |
|
2 * Copyright (c) 2006 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: Phonebook services wrapper. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <MVPbkContactLinkArray.h> |
|
20 #include <MVPbkContactLink.h> |
|
21 #include "MPhCntContactManager.h" |
|
22 #include "cphcntphonebookservices.h" |
|
23 #include "tphcntservicerequestparamfactory.h" |
|
24 #include "mphcntservicerequestparam.h" |
|
25 #include "CPhCntService.h" |
|
26 #include "tphcntcontactlinkresult.h" |
|
27 #include "cphcntfetchcontact.h" |
|
28 #include "CPhCntContact.h" |
|
29 #include "cphcntcontactid.h" |
|
30 #include "tphcntnullserviceresult.h" |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Static constructor |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CPhCntPhonebookServices* CPhCntPhonebookServices::NewL( |
|
39 MPhCntContactStores& aContactStores, |
|
40 MPhCntContactManager& aContactManager ) |
|
41 { |
|
42 CPhCntPhonebookServices* self = |
|
43 new( ELeave ) CPhCntPhonebookServices( aContactManager ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL( aContactStores ); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Destructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CPhCntPhonebookServices::~CPhCntPhonebookServices() |
|
55 { |
|
56 delete iService; |
|
57 delete iFetchContact; |
|
58 delete iParamFactory; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Gets user select phonenumber from phonebook. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 void CPhCntPhonebookServices::GetUserSelectedPhoneNumberL( |
|
66 CPhCntContactId*& aContactId, |
|
67 HBufC*& aPhoneNumber ) |
|
68 { |
|
69 GetUserSelectedNumberL( aContactId, aPhoneNumber, EFalse ); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Gets user select phonenumber from phonebook. |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CPhCntPhonebookServices::GetUserSelectedVoIPAddressL( |
|
77 CPhCntContactId*& aContactId, |
|
78 HBufC*& aVoIPAddress ) |
|
79 { |
|
80 GetUserSelectedAddressL( aContactId, aVoIPAddress ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // Gets user select dtmf number from phonebook. |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CPhCntPhonebookServices::GetUserSelectedDtmfNumberL( |
|
88 CPhCntContactId*& aContactId, |
|
89 HBufC*& aDtmfNumber ) |
|
90 { |
|
91 GetUserSelectedNumberL( aContactId, aDtmfNumber, ETrue ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // Cancels request. |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CPhCntPhonebookServices::CancelRequest() |
|
99 { |
|
100 delete iService; |
|
101 iService = NULL; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // Creates CPhCntService if needed. |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CPhCntPhonebookServices::CreateCntServiceL() |
|
109 { |
|
110 if ( !iService ) |
|
111 { |
|
112 iService = CPhCntService::NewL(); |
|
113 } |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Creates new contact to phonebook. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CPhCntPhonebookServices::CreateNewContactL( |
|
121 const TDesC& aPhoneNumber ) |
|
122 { |
|
123 CreateCntServiceL(); |
|
124 |
|
125 MPhCntServiceRequestParam* param = |
|
126 iParamFactory->CreateCreateNewContactRequestParamLC( aPhoneNumber ); |
|
127 |
|
128 TPhCntNullServiceResult noResult; |
|
129 iService->ExecuteRequestL( *param, noResult ); |
|
130 |
|
131 CleanupStack::PopAndDestroy( 1 ); // param |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // Updates existing contact from phonebook. |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CPhCntPhonebookServices::UpdateExistingContactL( |
|
139 const TDesC& aPhoneNumber ) |
|
140 { |
|
141 CreateCntServiceL(); |
|
142 MPhCntServiceRequestParam* param = |
|
143 iParamFactory->CreateUpdateContactRequestParamLC( aPhoneNumber ); |
|
144 |
|
145 TPhCntNullServiceResult noResult; |
|
146 iService->ExecuteRequestL( *param, noResult ); |
|
147 |
|
148 CleanupStack::PopAndDestroy( 1 ); // param |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // Constructor |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 CPhCntPhonebookServices::CPhCntPhonebookServices( |
|
156 MPhCntContactManager& aContactManager ) : |
|
157 iContactManager( aContactManager ) |
|
158 { |
|
159 } |
|
160 |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // Second phase constructor |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CPhCntPhonebookServices::ConstructL( |
|
167 MPhCntContactStores& aContactStores ) |
|
168 { |
|
169 iFetchContact = CPhCntFetchContact::NewL( aContactStores ); |
|
170 CreateCntServiceL(); |
|
171 iParamFactory = CPhCntServiceRequestParamFactory::NewL( iContactManager ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // Gets contact links |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 HBufC8* CPhCntPhonebookServices::GetContactLinksLC( |
|
179 MPhCntServiceRequestParam& aParam ) |
|
180 { |
|
181 CreateCntServiceL(); |
|
182 HBufC8* linkToContact = NULL; |
|
183 TPhCntContactLinkResult result( linkToContact ); |
|
184 iService->ExecuteRequestL( aParam, result ); |
|
185 CleanupStack::PushL( linkToContact ); |
|
186 return linkToContact; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // Gets contact links and fetches the contact pointed by link |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 CPhCntContact* CPhCntPhonebookServices::GetUserSelectedContactLC( |
|
194 MPhCntServiceRequestParam& aParam ) |
|
195 { |
|
196 CPhCntContact* contact = NULL; |
|
197 HBufC8* linkToContact = GetContactLinksLC( aParam ); |
|
198 if( linkToContact && linkToContact->Length() > 0 ) |
|
199 { |
|
200 User::LeaveIfError( |
|
201 iFetchContact->FetchContact( *linkToContact, contact ) ); |
|
202 } |
|
203 else |
|
204 { |
|
205 User::Leave( KErrNotFound ); |
|
206 } |
|
207 CleanupStack::PopAndDestroy( linkToContact ); |
|
208 CleanupStack::PushL( contact ); |
|
209 return contact; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // Sets result to client. |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CPhCntPhonebookServices::SetResultsL( |
|
217 const TDesC& aReceivedNumber, |
|
218 const CPhCntContactId* const aReceivedContactId, |
|
219 HBufC*& aClientResultNumber, |
|
220 CPhCntContactId*& aClientResultContactId ) const |
|
221 { |
|
222 if( aReceivedNumber.Length() > 0 && aReceivedContactId ) |
|
223 { |
|
224 HBufC* number = aReceivedNumber.AllocLC(); |
|
225 aClientResultContactId = aReceivedContactId->CloneL(); |
|
226 aClientResultNumber = number; |
|
227 CleanupStack::Pop( number ); |
|
228 } |
|
229 else |
|
230 { |
|
231 User::Leave( KErrNotFound ); |
|
232 } |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // Gets user selected number from phonebook. |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 void CPhCntPhonebookServices::GetUserSelectedNumberL( |
|
240 CPhCntContactId*& aContactId, |
|
241 HBufC*& aNumber, TBool aDTMFWanted ) |
|
242 { |
|
243 |
|
244 MPhCntServiceRequestParam* param = NULL; |
|
245 if( aDTMFWanted ) |
|
246 { |
|
247 param = |
|
248 iParamFactory->CreateGetUserSelectedDtmfNumberLinkLC( |
|
249 iContactManager ); |
|
250 } |
|
251 else |
|
252 { |
|
253 param = iParamFactory->CreateGetUserSelectedPhoneNumberLinkParamLC(); |
|
254 } |
|
255 |
|
256 CPhCntContact* contact = GetUserSelectedContactLC( *param ); |
|
257 |
|
258 if( contact ) |
|
259 { |
|
260 TPtrC number; |
|
261 if( aDTMFWanted ) |
|
262 { |
|
263 number.Set( contact->Dtmf() ); |
|
264 } |
|
265 // If dtmf not valid, then use phonenumber |
|
266 if( number.Length() == 0 ) |
|
267 { |
|
268 number.Set( contact->Number() ); |
|
269 } |
|
270 SetResultsL( |
|
271 number, |
|
272 contact->ContactId(), |
|
273 aNumber, |
|
274 aContactId ); |
|
275 CleanupStack::PopAndDestroy( contact ); |
|
276 } |
|
277 else |
|
278 { |
|
279 User::Leave( KErrNotFound ); |
|
280 } |
|
281 CleanupStack::PopAndDestroy( 1 ); // param |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // Gets user selected VoIP Address from phonebook. |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 void CPhCntPhonebookServices::GetUserSelectedAddressL( |
|
289 CPhCntContactId*& aContactId, |
|
290 HBufC*& aVoIPAddress ) |
|
291 { |
|
292 MPhCntServiceRequestParam* param = NULL; |
|
293 param = iParamFactory->CreateGetUserSelectedVoIPAddressLinkParamLC( |
|
294 iContactManager ); |
|
295 |
|
296 CPhCntContact* contact = GetUserSelectedContactLC( *param ); |
|
297 |
|
298 if( contact ) |
|
299 { |
|
300 TPtrC number; |
|
301 |
|
302 if( number.Length() == 0 ) |
|
303 { |
|
304 number.Set( contact->Number() ); |
|
305 } |
|
306 |
|
307 SetResultsL( |
|
308 number, |
|
309 contact->ContactId(), |
|
310 aVoIPAddress, |
|
311 aContactId ); |
|
312 CleanupStack::PopAndDestroy( contact ); |
|
313 } |
|
314 else |
|
315 { |
|
316 User::Leave( KErrNotFound ); |
|
317 } |
|
318 CleanupStack::PopAndDestroy( 1 ); // contact |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // Gets a phone number for a contact link. |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 void CPhCntPhonebookServices::GetPhoneNumberL( |
|
326 const TDesC8& aContactLink, |
|
327 const CPhCntSingleItemFetch::TCallType aCallType, |
|
328 HBufC*& aNumber, |
|
329 HBufC8*& aFieldLink ) |
|
330 { |
|
331 // Setup AIW parameters for a service request |
|
332 MPhCntServiceRequestParam* param = |
|
333 iParamFactory->CreateGetPhoneNumberFromContactParamLC( |
|
334 aContactLink, aCallType ); |
|
335 // Execute the service request |
|
336 CPhCntContact* contact = GetUserSelectedContactLC( *param ); |
|
337 |
|
338 // If a contact was found |
|
339 if( contact ) |
|
340 { |
|
341 if( contact->Number().Length() > 0 && |
|
342 contact->ContactLink() ) |
|
343 { |
|
344 aNumber = contact->Number().AllocLC(); |
|
345 aFieldLink = contact->ContactLink()->PackLC(); |
|
346 CleanupStack::Pop( 2, aNumber ); // aNumber & aFieldLink |
|
347 } |
|
348 CleanupStack::PopAndDestroy( contact ); |
|
349 } |
|
350 else |
|
351 { |
|
352 User::Leave( KErrNotFound ); |
|
353 } |
|
354 CleanupStack::PopAndDestroy( 1 ); // param. |
|
355 } |