|
1 /* |
|
2 * Copyright (c) 2005-2007 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 2 server app contact fetch phase. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2ContactFetchPhase.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "MPbk2ServicePhaseObserver.h" |
|
23 #include "CPbk2ServerAppAppUi.h" |
|
24 #include "CPbk2ServerAppStoreManager.h" |
|
25 #include <CPbk2FetchDlg.h> |
|
26 #include <MPbk2ApplicationServices.h> |
|
27 #include <CPbk2ContactViewBuilder.h> |
|
28 |
|
29 // Virtual Phonebook |
|
30 #include <MVPbkContactLink.h> |
|
31 #include <MVPbkContactOperationBase.h> |
|
32 #include <MVPbkContactViewBase.h> |
|
33 #include <CVPbkContactManager.h> |
|
34 #include <MVPbkStoreContactField.h> |
|
35 #include <MVPbkFieldType.h> |
|
36 #include <CVPbkFieldTypeSelector.h> |
|
37 #include <MVPbkStoreContact.h> |
|
38 #include <MVPbkStoreContactFieldCollection.h> |
|
39 |
|
40 /// Unnamed namespace for local definitions |
|
41 namespace { |
|
42 |
|
43 const TInt KFirstElement = 0; |
|
44 |
|
45 } /// namespace |
|
46 |
|
47 // -------------------------------------------------------------------------- |
|
48 // CPbk2ContactFetchPhase::CPbk2ContactFetchPhase |
|
49 // -------------------------------------------------------------------------- |
|
50 // |
|
51 CPbk2ContactFetchPhase::CPbk2ContactFetchPhase |
|
52 ( MPbk2ServicePhaseObserver& aObserver, |
|
53 CPbk2ServerAppStoreManager& aStoreManager, |
|
54 CPbk2FetchDlg::TParams aFetchParams, |
|
55 TBool aFetchOkToExit, |
|
56 MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection |
|
57 aFetchAcceptPolicy, |
|
58 CVPbkFieldTypeSelector* aViewFilter, |
|
59 TBool aUsingDefaultConfig, |
|
60 const CVPbkContactStoreUriArray* aStoreUris ) : |
|
61 iObserver( aObserver ), |
|
62 iServerAppStoreManager( aStoreManager ), |
|
63 iFetchParams( aFetchParams ), |
|
64 iFetchOkToExit( aFetchOkToExit ), |
|
65 iFetchAcceptPolicy( aFetchAcceptPolicy ), |
|
66 iViewFilter( aViewFilter ), |
|
67 iUsingDefaultConfig( aUsingDefaultConfig ), |
|
68 iStoreUris( aStoreUris ) |
|
69 { |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // CPbk2ContactFetchPhase::~CPbk2ContactFetchPhase |
|
74 // -------------------------------------------------------------------------- |
|
75 // |
|
76 CPbk2ContactFetchPhase::~CPbk2ContactFetchPhase() |
|
77 { |
|
78 if ( iFetchDialogEliminator ) |
|
79 { |
|
80 iFetchDialogEliminator->ForceExit(); |
|
81 } |
|
82 delete iFetchNamesListView; |
|
83 delete iFetchGroupsListView; |
|
84 delete iFetchResults; |
|
85 delete iContactLinks; |
|
86 delete iRetrieveOperation; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2ContactFetchPhase::NewL |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 CPbk2ContactFetchPhase* CPbk2ContactFetchPhase::NewL |
|
94 ( MPbk2ServicePhaseObserver& aObserver, |
|
95 CPbk2ServerAppStoreManager& aStoreManager, |
|
96 CPbk2FetchDlg::TParams aFetchParams, |
|
97 TBool aFetchOkToExit, |
|
98 MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection |
|
99 aFetchAcceptPolicy, |
|
100 CVPbkFieldTypeSelector* aViewFilter, |
|
101 TBool aUsingDefaultConfig, |
|
102 const CVPbkContactStoreUriArray* aStoreUris ) |
|
103 { |
|
104 CPbk2ContactFetchPhase* self = |
|
105 new ( ELeave ) CPbk2ContactFetchPhase |
|
106 ( aObserver, aStoreManager, aFetchParams, aFetchOkToExit, |
|
107 aFetchAcceptPolicy, aViewFilter, aUsingDefaultConfig, |
|
108 aStoreUris ); |
|
109 return self; |
|
110 } |
|
111 |
|
112 // -------------------------------------------------------------------------- |
|
113 // CPbk2ContactFetchPhase::LaunchServicePhaseL |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 void CPbk2ContactFetchPhase::LaunchServicePhaseL() |
|
117 { |
|
118 CPbk2ServerAppAppUi* appUi = static_cast<CPbk2ServerAppAppUi*> |
|
119 ( CEikonEnv::Static()->EikAppUi() ); |
|
120 |
|
121 TUint32 flags = EVPbkContactViewFlagsNone; |
|
122 // Because the filter needs to have the contact store open, |
|
123 // we can't build the view earlier |
|
124 delete iFetchNamesListView; |
|
125 iFetchNamesListView = NULL; |
|
126 iFetchNamesListView = iServerAppStoreManager.BuildFetchViewL |
|
127 ( EVPbkContactsView, *iStoreUris, iViewFilter, |
|
128 appUi->ApplicationServices().StoreProperties(), |
|
129 appUi->ApplicationServices().SortOrderManager(), |
|
130 flags ); |
|
131 |
|
132 flags = EVPbkExcludeEmptyGroups; |
|
133 delete iFetchGroupsListView; |
|
134 iFetchGroupsListView = NULL; |
|
135 iFetchGroupsListView = iServerAppStoreManager.BuildFetchViewL |
|
136 ( EVPbkGroupsView, *iStoreUris, iViewFilter, |
|
137 appUi->ApplicationServices().StoreProperties(), |
|
138 appUi->ApplicationServices().SortOrderManager(), |
|
139 flags ); |
|
140 |
|
141 // Launch the fetch dialog |
|
142 iFetchParams.iExitCallback = this; |
|
143 iFetchParams.iNamesListView = iFetchNamesListView; |
|
144 iFetchParams.iGroupsListView = iFetchGroupsListView; |
|
145 iFetchDlg = CPbk2FetchDlg::NewL( iFetchParams, *this ); |
|
146 iFetchDialogEliminator = iFetchDlg; |
|
147 iFetchDialogEliminator->ResetWhenDestroyed( &iFetchDialogEliminator ); |
|
148 iFetchDlg->ExecuteLD(); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CPbk2ContactFetchPhase::CancelServicePhase |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 void CPbk2ContactFetchPhase::CancelServicePhase() |
|
156 { |
|
157 if ( iFetchDialogEliminator ) |
|
158 { |
|
159 iFetchDialogEliminator->ForceExit(); |
|
160 } |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // CPbk2ContactFetchPhase::RequestCancelL |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 void CPbk2ContactFetchPhase::RequestCancelL( TInt aExitCommandId ) |
|
168 { |
|
169 if ( iFetchDialogEliminator ) |
|
170 { |
|
171 iFetchDialogEliminator->RequestExitL( aExitCommandId ); |
|
172 } |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // CPbk2ContactFetchPhase::AcceptDelayed |
|
177 // -------------------------------------------------------------------------- |
|
178 // |
|
179 void CPbk2ContactFetchPhase::AcceptDelayedL |
|
180 ( const TDesC8& aContactLinkBuffer ) |
|
181 { |
|
182 if ( iFetchDlg ) |
|
183 { |
|
184 iFetchDlg->AcceptDelayedFetchL( aContactLinkBuffer ); |
|
185 } |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CPbk2ContactFetchPhase::Results |
|
190 // -------------------------------------------------------------------------- |
|
191 // |
|
192 MVPbkContactLinkArray* CPbk2ContactFetchPhase::Results() const |
|
193 { |
|
194 return iFetchResults; |
|
195 } |
|
196 |
|
197 // -------------------------------------------------------------------------- |
|
198 // CPbk2ContactFetchPhase::ExtraResultData |
|
199 // -------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CPbk2ContactFetchPhase::ExtraResultData() const |
|
202 { |
|
203 return KErrNotSupported; |
|
204 } |
|
205 |
|
206 // -------------------------------------------------------------------------- |
|
207 // CPbk2ContactFetchPhase::TakeStoreContact |
|
208 // -------------------------------------------------------------------------- |
|
209 // |
|
210 MVPbkStoreContact* CPbk2ContactFetchPhase::TakeStoreContact() |
|
211 { |
|
212 // No store contact concept in fetch |
|
213 return NULL; |
|
214 } |
|
215 |
|
216 // -------------------------------------------------------------------------- |
|
217 // CPbk2ContactFetchPhase::FieldContent |
|
218 // -------------------------------------------------------------------------- |
|
219 // |
|
220 HBufC* CPbk2ContactFetchPhase::FieldContent() const |
|
221 { |
|
222 return NULL; |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CPbk2ContactFetchPhase::Pbk2AcceptFetchSelectionL |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection |
|
230 CPbk2ContactFetchPhase::AcceptFetchSelectionL |
|
231 ( TInt aNumMarkedEntries, MVPbkContactLink& aLastSelection ) |
|
232 { |
|
233 MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection result = |
|
234 iFetchAcceptPolicy; |
|
235 |
|
236 if ( result == MPbk2FetchDlgObserver::EFetchDelayed ) |
|
237 { |
|
238 HBufC8* linkData = aLastSelection.PackLC(); |
|
239 TPckg<TInt> buffer(aNumMarkedEntries); |
|
240 iObserver.PhaseAccept( *this, buffer, *linkData ); |
|
241 CleanupStack::PopAndDestroy(); // linkData |
|
242 } |
|
243 |
|
244 return result; |
|
245 } |
|
246 |
|
247 // -------------------------------------------------------------------------- |
|
248 // CPbk2ContactFetchPhase::FetchCompletedL |
|
249 // -------------------------------------------------------------------------- |
|
250 // |
|
251 void CPbk2ContactFetchPhase::FetchCompletedL |
|
252 ( MVPbkContactLinkArray* aMarkedEntries ) |
|
253 { |
|
254 delete iFetchResults; |
|
255 iFetchResults = NULL; |
|
256 iFetchResults = CVPbkContactLinkArray::NewL(); |
|
257 |
|
258 CVPbkContactLinkArray* linkArray = iFetchResults; |
|
259 |
|
260 // View filter can not guarentee that returned contacts match the filter. |
|
261 // If user selects a group all the contacts of the group are returned |
|
262 // by fetch and we must manually filter them here. |
|
263 if ( iViewFilter ) |
|
264 { |
|
265 delete iContactLinks; |
|
266 iContactLinks = NULL; |
|
267 iContactLinks = CVPbkContactLinkArray::NewL(); |
|
268 linkArray = iContactLinks; |
|
269 } |
|
270 |
|
271 const TInt count = aMarkedEntries->Count(); |
|
272 for (TInt i = 0; i < count; ++i) |
|
273 { |
|
274 linkArray->AppendL( aMarkedEntries->At(i).CloneLC() ); |
|
275 CleanupStack::Pop(); // aMarkedEntries->At(i).CloneLC() |
|
276 } |
|
277 |
|
278 if ( iViewFilter ) |
|
279 { |
|
280 // Go through contacts one by one |
|
281 RetrieveContactL(); |
|
282 } |
|
283 else |
|
284 { |
|
285 // Finished |
|
286 iObserver.NextPhase( *this ); |
|
287 } |
|
288 } |
|
289 |
|
290 // -------------------------------------------------------------------------- |
|
291 // CPbk2ContactFetchPhase::FetchCanceled |
|
292 // -------------------------------------------------------------------------- |
|
293 // |
|
294 void CPbk2ContactFetchPhase::FetchCanceled() |
|
295 { |
|
296 delete iFetchResults; |
|
297 iFetchResults = NULL; |
|
298 delete iRetrieveOperation; |
|
299 iRetrieveOperation = NULL; |
|
300 |
|
301 iObserver.PhaseCanceled( *this ); |
|
302 } |
|
303 |
|
304 // -------------------------------------------------------------------------- |
|
305 // CPbk2ContactFetchPhase::FetchAborted |
|
306 // -------------------------------------------------------------------------- |
|
307 // |
|
308 void CPbk2ContactFetchPhase::FetchAborted() |
|
309 { |
|
310 delete iFetchResults; |
|
311 iFetchResults = NULL; |
|
312 |
|
313 iObserver.PhaseAborted( *this ); |
|
314 } |
|
315 |
|
316 // -------------------------------------------------------------------------- |
|
317 // CPbk2ContactFetchPhase::FetchOkToExit |
|
318 // -------------------------------------------------------------------------- |
|
319 // |
|
320 TInt CPbk2ContactFetchPhase::FetchOkToExit() |
|
321 { |
|
322 return iFetchOkToExit; |
|
323 } |
|
324 |
|
325 // -------------------------------------------------------------------------- |
|
326 // CPbk2ContactFetchPhase::OkToExitL |
|
327 // -------------------------------------------------------------------------- |
|
328 // |
|
329 TBool CPbk2ContactFetchPhase::OkToExitL( TInt aCommandId ) |
|
330 { |
|
331 return iObserver.PhaseOkToExit( *this, aCommandId ); |
|
332 } |
|
333 |
|
334 // -------------------------------------------------------------------------- |
|
335 // CPbk2ContactFetchPhase::VPbkSingleContactOperationComplete |
|
336 // -------------------------------------------------------------------------- |
|
337 // |
|
338 void CPbk2ContactFetchPhase::VPbkSingleContactOperationComplete |
|
339 ( MVPbkContactOperationBase& /*aOperation*/, |
|
340 MVPbkStoreContact* aContact ) |
|
341 { |
|
342 TRAPD( err, HandleContactOperationCompleteL( aContact ) ); |
|
343 if ( err != KErrNone ) |
|
344 { |
|
345 iObserver.PhaseError( *this, err ); |
|
346 } |
|
347 } |
|
348 |
|
349 // -------------------------------------------------------------------------- |
|
350 // CPbk2ContactFetchPhase::VPbkSingleContactOperationFailed |
|
351 // -------------------------------------------------------------------------- |
|
352 // |
|
353 void CPbk2ContactFetchPhase::VPbkSingleContactOperationFailed |
|
354 ( MVPbkContactOperationBase& /*aOperation*/, TInt aError ) |
|
355 { |
|
356 iObserver.PhaseError( *this, aError ); |
|
357 } |
|
358 |
|
359 // -------------------------------------------------------------------------- |
|
360 // CPbk2ContactFetchPhase::HandleContactOperationCompleteL |
|
361 // -------------------------------------------------------------------------- |
|
362 // |
|
363 void CPbk2ContactFetchPhase::HandleContactOperationCompleteL |
|
364 ( MVPbkStoreContact* aContact ) |
|
365 { |
|
366 // Verify current contact |
|
367 VerifyContactL( aContact ); |
|
368 |
|
369 // Retrieve next contact |
|
370 RetrieveContactL(); |
|
371 } |
|
372 |
|
373 // -------------------------------------------------------------------------- |
|
374 // CPbk2ContactFetchPhase::RetrieveContactL |
|
375 // -------------------------------------------------------------------------- |
|
376 // |
|
377 void CPbk2ContactFetchPhase::RetrieveContactL() |
|
378 { |
|
379 CPbk2ServerAppAppUi* appUi = static_cast<CPbk2ServerAppAppUi*> |
|
380 ( CEikonEnv::Static()->EikAppUi() ); |
|
381 |
|
382 // Fetch one contact at a time if service cancellation is not |
|
383 // commanded. |
|
384 if ( iContactLinks && iContactLinks->Count() > 0 ) |
|
385 { |
|
386 delete iRetrieveOperation; |
|
387 iRetrieveOperation = NULL; |
|
388 iRetrieveOperation = appUi->ApplicationServices().ContactManager(). |
|
389 RetrieveContactL( iContactLinks->At( KFirstElement ), *this ); |
|
390 iContactLinks->Delete( KFirstElement ); |
|
391 } |
|
392 else |
|
393 { |
|
394 iObserver.NextPhase( *this ); |
|
395 } |
|
396 } |
|
397 |
|
398 // -------------------------------------------------------------------------- |
|
399 // CPbk2ContactFetchPhase::VerifyContactL |
|
400 // -------------------------------------------------------------------------- |
|
401 // |
|
402 void CPbk2ContactFetchPhase::VerifyContactL( MVPbkStoreContact* aContact ) |
|
403 { |
|
404 CleanupDeletePushL( aContact ); |
|
405 |
|
406 MVPbkStoreContactFieldCollection& fields = aContact->Fields(); |
|
407 TInt fieldCount = fields.FieldCount(); |
|
408 |
|
409 for ( TInt i = 0; i < fieldCount; ++i ) |
|
410 { |
|
411 const MVPbkStoreContactField& field = fields.FieldAt( i ); |
|
412 const MVPbkFieldType* fieldType = field.BestMatchingFieldType(); |
|
413 if ( fieldType && iViewFilter->IsFieldTypeIncluded( *fieldType ) ) |
|
414 { |
|
415 MVPbkContactLink* link = aContact->CreateLinkLC(); |
|
416 CleanupStack::Pop(); // link |
|
417 iFetchResults->AppendL( link ); |
|
418 break; |
|
419 } |
|
420 } |
|
421 |
|
422 CleanupStack::PopAndDestroy(); // aContact |
|
423 } |
|
424 |
|
425 // End of File |