|
1 /* |
|
2 * Copyright (c) 2007-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 : Implementation of the class CESMRCasPluginImpl. |
|
15 * Version : %version: tr1sido#7 % << Don't touch! Updated by Synergy at check-out. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include "cesmrcasplugincontactretriever.h" |
|
22 #include "esmrinternaluid.h" |
|
23 #include "esmrhelper.h" |
|
24 #include "mesmrcasplugincontactretrieverobserver.h" |
|
25 |
|
26 #include <esmrcasplugindata.rsg> |
|
27 #include <esmrcasplugin.mbg> |
|
28 #include <caluser.h> |
|
29 |
|
30 #include <MVPbkStoreContact.h> |
|
31 #include <data_caging_path_literals.hrh> |
|
32 #include <badesca.h> |
|
33 |
|
34 #include <utf.h> |
|
35 #include <bautils.h> |
|
36 //<cmail> |
|
37 #include "mfscactionutils.h" |
|
38 #include "mfsccontactset.h" |
|
39 #include "mfsccontactsetobserver.h" |
|
40 #include "tfsccontactactionpluginparams.h" |
|
41 //</cmail> |
|
42 #include <MVPbkStoreContactField.h> |
|
43 #include <MVPbkFieldType.h> |
|
44 #include <TVPbkFieldVersitProperty.h> |
|
45 #include <VPbkFieldType.hrh> |
|
46 |
|
47 // Unnamed namespace for local definitions |
|
48 namespace { // codescanner::namespace |
|
49 |
|
50 const TInt KEmailTextLength( 255 ); |
|
51 |
|
52 }//namespace |
|
53 |
|
54 // ======== MEMBER FUNCTIONS ======== |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CESMRCasPluginContactRetriever::CESMRCasPluginContactRetriever |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CESMRCasPluginContactRetriever::CESMRCasPluginContactRetriever( |
|
61 const TFscContactActionPluginParams& aParams ) |
|
62 : iParams( aParams ) |
|
63 { |
|
64 FUNC_LOG; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CESMRCasPluginImpl::~CESMRCasPluginImpl |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CESMRCasPluginContactRetriever::~CESMRCasPluginContactRetriever( ) |
|
72 { |
|
73 FUNC_LOG; |
|
74 |
|
75 iAttendees.ResetAndDestroy(); |
|
76 |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CESMRCasPluginContactRetriever::NewL |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 CESMRCasPluginContactRetriever* CESMRCasPluginContactRetriever::NewL( |
|
84 const TFscContactActionPluginParams& aParams ) |
|
85 { |
|
86 FUNC_LOG; |
|
87 |
|
88 CESMRCasPluginContactRetriever* self = |
|
89 new (ELeave) CESMRCasPluginContactRetriever( aParams ); |
|
90 CleanupStack::PushL ( self ); |
|
91 self->ConstructL ( ); |
|
92 CleanupStack::Pop ( self ); |
|
93 |
|
94 |
|
95 return self; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CESMRCasPluginContactRetriever::ConstructL |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CESMRCasPluginContactRetriever::ConstructL() |
|
103 { |
|
104 FUNC_LOG; |
|
105 |
|
106 // Nothing to do. |
|
107 |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CESMRCasPluginContactRetriever::CanExecuteL |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CESMRCasPluginContactRetriever::CanExecuteL( |
|
115 MFscContactSet& aContactSet, |
|
116 MESMRCasPluginContactRetrieverObserver& aObserver ) |
|
117 { |
|
118 FUNC_LOG; |
|
119 |
|
120 iOperation = EOperationCanExecute; |
|
121 iContactSet = &aContactSet; |
|
122 iObserver = &aObserver; |
|
123 |
|
124 StartIterationL(); |
|
125 |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CESMRCasPluginContactRetriever::GetAttendeesL |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CESMRCasPluginContactRetriever::GetAttendeesL( |
|
134 MFscContactSet& aContactSet, |
|
135 MESMRCasPluginContactRetrieverObserver& aObserver ) |
|
136 { |
|
137 FUNC_LOG; |
|
138 |
|
139 iOperation = EOperationGetAttendees; |
|
140 iContactSet = &aContactSet; |
|
141 iObserver = &aObserver; |
|
142 |
|
143 StartIterationL(); |
|
144 |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CESMRCasPluginContactRetriever::Cancel |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void CESMRCasPluginContactRetriever::Cancel() |
|
152 { |
|
153 FUNC_LOG; |
|
154 |
|
155 if ( iContactSet ) |
|
156 { |
|
157 // We need to cancel both operations. |
|
158 TRAP_IGNORE( iContactSet->CancelNextContactL() ); |
|
159 TRAP_IGNORE( iContactSet->CancelNextGroupL() ); |
|
160 } |
|
161 |
|
162 iContactSet = NULL; |
|
163 iAttendees.ResetAndDestroy(); |
|
164 |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CESMRCasPluginContactRetriever::StartIterationL |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CESMRCasPluginContactRetriever::StartIterationL() |
|
172 { |
|
173 FUNC_LOG; |
|
174 |
|
175 // Initialize member variables for iteration |
|
176 iContactSet->SetToFirstContact(); |
|
177 iContactSet->SetToFirstGroup(); |
|
178 iContactSet->CancelNextContactL(); |
|
179 iContactSet->CancelNextGroupL(); |
|
180 |
|
181 iContactCount = 0; |
|
182 iContactCountWithEmail = 0; |
|
183 iAttendees.ResetAndDestroy(); |
|
184 |
|
185 if ( iContactSet->HasNextContact() ) |
|
186 { |
|
187 iLastEvent = EActionEventNextContact; |
|
188 iContactSet->NextContactL( this ); |
|
189 } |
|
190 else if ( iContactSet->HasNextGroup() ) |
|
191 { |
|
192 iLastEvent = EActionEventNextGroup; |
|
193 iContactSet->NextGroupL( this ); |
|
194 } |
|
195 else |
|
196 { |
|
197 NotifyFinished(); |
|
198 } |
|
199 |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CESMRCasPluginContactRetriever::NextContactComplete |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CESMRCasPluginContactRetriever::NextContactComplete( |
|
207 MVPbkStoreContact* aContact ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 |
|
211 TRAPD( err, HandleNextContactCompleteL( *aContact ) ); |
|
212 if ( KErrNone != err ) |
|
213 { |
|
214 NotifyError( err ); |
|
215 } |
|
216 |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CESMRCasPluginContactRetriever::NextContactFailed |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CESMRCasPluginContactRetriever::NextContactFailed( |
|
224 TInt aError ) |
|
225 { |
|
226 FUNC_LOG; |
|
227 |
|
228 NotifyError( aError ); |
|
229 |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // CESMRCasPluginContactRetriever::NextGroupComplete |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 void CESMRCasPluginContactRetriever::NextGroupComplete( |
|
237 MVPbkStoreContact* aContact ) |
|
238 { |
|
239 FUNC_LOG; |
|
240 |
|
241 TRAPD( err, HandleNextGroupCompleteL( aContact ) ); |
|
242 if ( KErrNone != err ) |
|
243 { |
|
244 NotifyError( err ); |
|
245 } |
|
246 |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CESMRCasPluginContactRetriever::NextGroupFailed |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CESMRCasPluginContactRetriever::NextGroupFailed( |
|
254 TInt aError ) |
|
255 { |
|
256 FUNC_LOG; |
|
257 |
|
258 NotifyError( aError ); |
|
259 |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CESMRCasPluginContactRetriever::GetGroupContactComplete |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CESMRCasPluginContactRetriever::GetGroupContactComplete( |
|
267 MVPbkStoreContact* aContact ) |
|
268 { |
|
269 FUNC_LOG; |
|
270 |
|
271 TRAPD( err, HandleNextContactCompleteL( *aContact ) ); |
|
272 if ( KErrNone != err ) |
|
273 { |
|
274 NotifyError( err ); |
|
275 } |
|
276 delete aContact; |
|
277 |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // CESMRCasPluginContactRetriever::GetGroupContactFailed |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void CESMRCasPluginContactRetriever::GetGroupContactFailed( |
|
285 TInt aError ) |
|
286 { |
|
287 FUNC_LOG; |
|
288 |
|
289 NotifyError( aError ); |
|
290 |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // CESMRCasPluginContactRetriever::HandleNextContactCompleteL |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CESMRCasPluginContactRetriever::HandleNextContactCompleteL( |
|
298 MVPbkStoreContact& aContact ) |
|
299 { |
|
300 FUNC_LOG; |
|
301 |
|
302 TBool stopIteration = EFalse; |
|
303 TInt error = KErrNone; |
|
304 iContactCount++; |
|
305 |
|
306 if ( EOperationCanExecute == iOperation ) |
|
307 { |
|
308 if ( iParams.iUtils->IsContactNumberAvailableL( aContact, ETypeEmailAddress ) ) |
|
309 { |
|
310 // Stop iteration as soon as first contact with email is found. |
|
311 iContactCountWithEmail++; |
|
312 stopIteration = ETrue; |
|
313 } |
|
314 } |
|
315 else if ( EOperationGetAttendees == iOperation ) |
|
316 { |
|
317 TBuf<KEmailTextLength> eMailAddress; |
|
318 TInt retVal = iParams.iUtils->GetEmailAddressL( aContact, eMailAddress ); |
|
319 |
|
320 // User selected an email address for contact or |
|
321 // contact had only 1 email address. |
|
322 if ( retVal == KErrNone ) |
|
323 { |
|
324 // Add attendee with selected email to attendees list. |
|
325 CCalUser* attendee = CCalUser::NewL( eMailAddress ); |
|
326 CleanupStack::PushL( attendee ); |
|
327 |
|
328 HBufC* contactName = iParams.iUtils->GetContactNameL( aContact ); |
|
329 CleanupStack::PushL( contactName ); |
|
330 |
|
331 attendee->SetCommonNameL( *contactName ); |
|
332 CleanupStack::PopAndDestroy( contactName ); |
|
333 contactName = NULL; |
|
334 |
|
335 // Ownership transferred |
|
336 iAttendees.AppendL( attendee ); |
|
337 CleanupStack::Pop( attendee ); |
|
338 } |
|
339 // User selected cancel (KErrCancel) or some other error was returned. |
|
340 // If retVal = KErrNotFound contact had no email address, |
|
341 // in that case continue iteration. |
|
342 else if ( KErrNotFound != retVal ) |
|
343 { |
|
344 // Stop iteration and notify error to observer. |
|
345 error = retVal; |
|
346 stopIteration = ETrue; |
|
347 } |
|
348 } |
|
349 |
|
350 // If iteration should be stopped |
|
351 if ( stopIteration ) |
|
352 { |
|
353 if ( error != KErrNone ) |
|
354 { |
|
355 NotifyError( error ); |
|
356 } |
|
357 else |
|
358 { |
|
359 NotifyFinished(); |
|
360 } |
|
361 } |
|
362 // First iterate contacts |
|
363 else if ( iLastEvent == EActionEventNextContact && |
|
364 iContactSet->HasNextContact() ) |
|
365 { |
|
366 iContactSet->NextContactL( this ); |
|
367 } |
|
368 // If there are more contacts in current group |
|
369 else if ( iLastEvent == EActionEventGetGroupContact && |
|
370 iCurrentGroupContactIndex < iCurrentGroupContactCount ) |
|
371 { |
|
372 iContactSet->GetGroupContactL( |
|
373 *iCurrentGroup, |
|
374 iCurrentGroupContactIndex, |
|
375 this); |
|
376 ++iCurrentGroupContactIndex; |
|
377 } |
|
378 // If there are more groups |
|
379 else if ( iContactSet->HasNextGroup() ) |
|
380 { |
|
381 iLastEvent = EActionEventNextGroup; |
|
382 iContactSet->NextGroupL( this ); |
|
383 } |
|
384 // Iteration complete |
|
385 else |
|
386 { |
|
387 NotifyFinished(); |
|
388 } |
|
389 |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // CESMRCasPluginContactRetriever::HandleNextGroupCompleteL |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 void CESMRCasPluginContactRetriever::HandleNextGroupCompleteL( |
|
397 MVPbkStoreContact* aGroup ) |
|
398 { |
|
399 FUNC_LOG; |
|
400 |
|
401 iCurrentGroupContactCount = iContactSet->GroupContactCountL( *aGroup ); |
|
402 iCurrentGroup = NULL; |
|
403 |
|
404 // If group contains contacts |
|
405 if ( iCurrentGroupContactCount ) |
|
406 { |
|
407 iCurrentGroup = aGroup; |
|
408 iCurrentGroupContactIndex = 0; |
|
409 iLastEvent = EActionEventGetGroupContact; |
|
410 iContactSet->GetGroupContactL( |
|
411 *iCurrentGroup, |
|
412 iCurrentGroupContactIndex, |
|
413 this ); |
|
414 |
|
415 ++iCurrentGroupContactIndex; |
|
416 } |
|
417 // If there are more groups |
|
418 else if ( iContactSet->HasNextGroup() ) |
|
419 { |
|
420 iLastEvent = EActionEventNextGroup; |
|
421 iContactSet->NextGroupL( this ); |
|
422 } |
|
423 // Group iteration complete |
|
424 else |
|
425 { |
|
426 NotifyFinished(); |
|
427 } |
|
428 |
|
429 } |
|
430 |
|
431 // --------------------------------------------------------------------------- |
|
432 // CESMRCasPluginContactRetriever::NotifyFinished |
|
433 // --------------------------------------------------------------------------- |
|
434 // |
|
435 void CESMRCasPluginContactRetriever::NotifyFinished() |
|
436 { |
|
437 FUNC_LOG; |
|
438 |
|
439 iContactSet = NULL; |
|
440 |
|
441 if ( iObserver ) |
|
442 { |
|
443 if ( EOperationCanExecute == iOperation ) |
|
444 { |
|
445 iObserver->MRCanExecuteComplete( iContactCountWithEmail > 0 ); |
|
446 } |
|
447 else if ( EOperationGetAttendees == iOperation ) |
|
448 { |
|
449 iObserver->MRGetAttendeesComplete( iContactCount, iAttendees ); |
|
450 } |
|
451 } |
|
452 |
|
453 iAttendees.ResetAndDestroy(); |
|
454 |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // CESMRCasPluginContactRetriever::NotifyError |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 void CESMRCasPluginContactRetriever::NotifyError( TInt aError ) |
|
462 { |
|
463 FUNC_LOG; |
|
464 |
|
465 iContactSet = NULL; |
|
466 |
|
467 if ( iObserver ) |
|
468 { |
|
469 if ( EOperationCanExecute == iOperation ) |
|
470 { |
|
471 iObserver->MRCanExecuteError( aError ); |
|
472 } |
|
473 else if ( EOperationGetAttendees == iOperation ) |
|
474 { |
|
475 iObserver->MRGetAttendeesError( aError ); |
|
476 } |
|
477 } |
|
478 |
|
479 iAttendees.ResetAndDestroy(); |
|
480 |
|
481 } |
|
482 |
|
483 // EOF |
|
484 |