|
1 /* |
|
2 * Copyright (c) 2002-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 store manager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2ContactViewSupplier.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "CPbk2CompressPolicyManager.h" |
|
24 #include <CPbk2StoreConfiguration.h> |
|
25 #include <CPbk2SortOrderManager.h> |
|
26 #include <CPbk2ContactViewBuilder.h> |
|
27 #include <RPbk2LocalizedResourceFile.h> |
|
28 #include <Pbk2CommonUi.rsg> |
|
29 #include <Pbk2DataCaging.hrh> |
|
30 #include <CPbk2GroupFeaturePlugin.h> |
|
31 #include <Pbk2ViewId.hrh> |
|
32 #include "CPbk2NonTopContactSelector.h" |
|
33 #include "Pbk2ContactView.hrh" |
|
34 |
|
35 // Virtual Phonebook |
|
36 #include <CVPbkContactManager.h> |
|
37 #include <MVPbkContactStoreList.h> |
|
38 #include <MVPbkContactStore.h> |
|
39 #include <MVPbkContactViewBase.h> |
|
40 #include <CVPbkContactViewDefinition.h> |
|
41 #include <CVPbkContactStoreUriArray.h> |
|
42 #include <TVPbkContactStoreUriPtr.h> |
|
43 #include <CVPbkSortOrder.h> |
|
44 #include <MVPbkFieldType.h> |
|
45 #include <CVPbkSortOrderAcquirer.h> |
|
46 #include <VPbkSortOrderAcquirerUid.h> |
|
47 #include <MVPbkContactViewBaseChildAccessExtension.h> |
|
48 |
|
49 // System includes |
|
50 #include <barsread.h> |
|
51 #include <coemain.h> |
|
52 |
|
53 // Debugging headers |
|
54 #include <Pbk2Debug.h> |
|
55 |
|
56 /// Unnamed namespace for local definitions |
|
57 namespace { |
|
58 |
|
59 _LIT( KGroupSortOrderDisplayName, "AllGroups" ); |
|
60 |
|
61 /** |
|
62 * Custom cleanup function. |
|
63 * |
|
64 * @param aObj Object to clean. |
|
65 */ |
|
66 void CleanupResetAndDestroy( TAny* aObj ) |
|
67 { |
|
68 if ( aObj ) |
|
69 { |
|
70 static_cast<RImplInfoPtrArray*>( aObj )->ResetAndDestroy(); |
|
71 } |
|
72 } |
|
73 |
|
74 } /// namespace |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CPbk2ContactViewSupplier::CPbk2ContactViewSupplier |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 inline CPbk2ContactViewSupplier::CPbk2ContactViewSupplier |
|
81 ( CVPbkContactManager& aContactManager, |
|
82 CPbk2SortOrderManager& aSortOrderManager, |
|
83 CPbk2StoreConfiguration& aStoreConfiguration, |
|
84 CPbk2StorePropertyArray& aStoreProperties ) : |
|
85 iContactManager( aContactManager ), |
|
86 iSortOrderManager( aSortOrderManager ), |
|
87 iStoreConfiguration( aStoreConfiguration ), |
|
88 iStoreProperties( aStoreProperties ) |
|
89 { |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CPbk2ContactViewSupplier::~CPbk2ContactViewSupplier |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 CPbk2ContactViewSupplier::~CPbk2ContactViewSupplier() |
|
97 { |
|
98 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
99 ("CPbk2ContactViewSupplier::~CPbk2ContactViewSupplier(0x%x)"), this); |
|
100 |
|
101 if ( iAllContactsView ) |
|
102 { |
|
103 iAllContactsView->RemoveObserver( *this ); |
|
104 } |
|
105 delete iAllContactsView; |
|
106 |
|
107 if ( iAllGroupsView ) |
|
108 { |
|
109 iAllGroupsView->RemoveObserver( *this ); |
|
110 } |
|
111 delete iAllGroupsView; |
|
112 |
|
113 delete iOldContactsView; |
|
114 delete iOldGroupsView; |
|
115 delete iSortOrderAcquirer; |
|
116 delete iNonTopContactSelector; |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------- |
|
120 // CPbk2ContactViewSupplier::ConstructL |
|
121 // -------------------------------------------------------------------------- |
|
122 // |
|
123 inline void CPbk2ContactViewSupplier::ConstructL |
|
124 ( TBool aActOnConfigurationEvents ) |
|
125 { |
|
126 if ( aActOnConfigurationEvents ) |
|
127 { |
|
128 // We must be the first observer for the store configuration |
|
129 // in Phonebook 2 framework. That is because all other observers |
|
130 // might ask for a new contact view after the configuration has |
|
131 // changed and since we are the first observer we get the event |
|
132 // last and can control contact views better. |
|
133 iStoreConfiguration.AddObserverL( *this ); |
|
134 } |
|
135 } |
|
136 |
|
137 // -------------------------------------------------------------------------- |
|
138 // CPbk2ContactViewSupplier::NewL |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C CPbk2ContactViewSupplier* CPbk2ContactViewSupplier::NewL |
|
142 ( CVPbkContactManager& aContactManager, |
|
143 CPbk2SortOrderManager& aSortOrderManager, |
|
144 CPbk2StoreConfiguration& aStoreConfiguration, |
|
145 CPbk2StorePropertyArray& aStoreProperties, |
|
146 TBool aActOnConfigurationEvents ) |
|
147 { |
|
148 CPbk2ContactViewSupplier* self = new (ELeave) CPbk2ContactViewSupplier |
|
149 ( aContactManager, aSortOrderManager, aStoreConfiguration, |
|
150 aStoreProperties ); |
|
151 CleanupStack::PushL( self ); |
|
152 self->ConstructL( aActOnConfigurationEvents ); |
|
153 CleanupStack::Pop( self ); |
|
154 return self; |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------- |
|
158 // CPbk2ContactViewSupplier::AllContactsViewL |
|
159 // -------------------------------------------------------------------------- |
|
160 // |
|
161 MVPbkContactViewBase* CPbk2ContactViewSupplier::AllContactsViewL() |
|
162 { |
|
163 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
164 ("CPbk2ContactViewSupplier::AllContactsViewL")); |
|
165 |
|
166 // Creates the view lazyly when the first client needs it |
|
167 if ( !iAllContactsView ) |
|
168 { |
|
169 iAllContactsView = CreateAllContactsViewL(); |
|
170 |
|
171 // Give the view to the sort order manager |
|
172 iSortOrderManager.SetContactViewL( *iAllContactsView ); |
|
173 } |
|
174 |
|
175 return iAllContactsView; |
|
176 } |
|
177 |
|
178 // -------------------------------------------------------------------------- |
|
179 // CPbk2ContactViewSupplier::TopContactsViewL |
|
180 // -------------------------------------------------------------------------- |
|
181 // |
|
182 MVPbkContactViewBase* CPbk2ContactViewSupplier::TopContactsViewL() |
|
183 { |
|
184 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
185 ("CPbk2ContactViewSupplier::TopContactsViewL")); |
|
186 |
|
187 MVPbkContactViewBase* topContactsView = NULL; |
|
188 MVPbkContactViewBase* allContactsView = AllContactsViewL(); |
|
189 TAny* extAny = allContactsView->ContactViewBaseExtension( |
|
190 TUid::Uid( KVPbkViewBaseExtChildAccess ) ); |
|
191 if ( extAny ) |
|
192 { |
|
193 MVPbkContactViewBaseChildAccessExtension* ext = |
|
194 static_cast<MVPbkContactViewBaseChildAccessExtension*>(extAny); |
|
195 topContactsView = ext->GetChildViewById( |
|
196 EPbk2MergedTopContactsListPlaceHolder ); // not owned here |
|
197 } |
|
198 return topContactsView; |
|
199 } |
|
200 |
|
201 // -------------------------------------------------------------------------- |
|
202 // CPbk2ContactViewSupplier::AllGroupsViewL |
|
203 // -------------------------------------------------------------------------- |
|
204 // |
|
205 MVPbkContactViewBase* CPbk2ContactViewSupplier::AllGroupsViewL() |
|
206 { |
|
207 // Creates the view lazyly when the first client needs it |
|
208 if ( !iAllGroupsView ) |
|
209 { |
|
210 iAllGroupsView = CreateAllGroupsViewL(); |
|
211 } |
|
212 |
|
213 return iAllGroupsView; |
|
214 } |
|
215 |
|
216 // -------------------------------------------------------------------------- |
|
217 // CPbk2ContactViewSupplier::MPbk2ContactViewSupplierExtension |
|
218 // -------------------------------------------------------------------------- |
|
219 // |
|
220 TAny* CPbk2ContactViewSupplier::MPbk2ContactViewSupplierExtension( |
|
221 TUid aExtensionUid ) |
|
222 { |
|
223 if ( aExtensionUid == KMPbk2ContactViewSupplierExtension2Uid ) |
|
224 { |
|
225 return static_cast<MPbk2ContactViewSupplier2*>( this ); |
|
226 } |
|
227 return NULL; |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------- |
|
231 // CPbk2ContactViewSupplier::ContactViewReady |
|
232 // -------------------------------------------------------------------------- |
|
233 // |
|
234 void CPbk2ContactViewSupplier::ContactViewReady |
|
235 ( MVPbkContactViewBase& aView ) |
|
236 { |
|
237 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
238 ("CPbk2ContactViewSupplier::ContactViewReady(0x%x)"), &aView); |
|
239 } |
|
240 |
|
241 // -------------------------------------------------------------------------- |
|
242 // CPbk2ContactViewSupplier::ContactViewUnavailable |
|
243 // -------------------------------------------------------------------------- |
|
244 // |
|
245 void CPbk2ContactViewSupplier::ContactViewUnavailable |
|
246 ( MVPbkContactViewBase& aView ) |
|
247 { |
|
248 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
249 ("CPbk2ContactViewSupplier::ContactViewUnavailable(0x%x)"), &aView); |
|
250 } |
|
251 |
|
252 // -------------------------------------------------------------------------- |
|
253 // CPbk2ContactViewSupplier::ContactAddedToView |
|
254 // -------------------------------------------------------------------------- |
|
255 // |
|
256 void CPbk2ContactViewSupplier::ContactAddedToView |
|
257 ( MVPbkContactViewBase& aView, TInt aIndex, |
|
258 const MVPbkContactLink& aContactLink ) |
|
259 { |
|
260 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
261 ("CPbk2ContactViewSupplier::ContactAddedToView(0x%x,%d,0x%x)"), |
|
262 &aView, aIndex, &aContactLink); |
|
263 } |
|
264 |
|
265 // -------------------------------------------------------------------------- |
|
266 // CPbk2ContactViewSupplier::ContactRemovedFromView |
|
267 // -------------------------------------------------------------------------- |
|
268 // |
|
269 void CPbk2ContactViewSupplier::ContactRemovedFromView |
|
270 ( MVPbkContactViewBase& aView, TInt aIndex, |
|
271 const MVPbkContactLink& aContactLink ) |
|
272 { |
|
273 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
274 ("CPbk2ContactViewSupplier::ContactRemovedFromView(0x%x,%d,0x%x)"), |
|
275 &aView, aIndex, &aContactLink); |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // CPbk2ContactViewSupplier::ContactViewError |
|
280 // -------------------------------------------------------------------------- |
|
281 // |
|
282 void CPbk2ContactViewSupplier::ContactViewError |
|
283 ( MVPbkContactViewBase& aView, |
|
284 TInt aError, TBool /*aErrorNotified*/ ) |
|
285 { |
|
286 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
287 ("CPbk2ContactViewSupplier::ContactViewError(0x%x,%d)"), |
|
288 &aView, aError); |
|
289 } |
|
290 |
|
291 // -------------------------------------------------------------------------- |
|
292 // CPbk2ContactViewSupplier::ConfigurationChanged |
|
293 // -------------------------------------------------------------------------- |
|
294 // |
|
295 void CPbk2ContactViewSupplier::ConfigurationChanged() |
|
296 { |
|
297 TRAPD( err, HandleConfigurationChangedL() ); |
|
298 if ( err != KErrNone ) |
|
299 { |
|
300 CCoeEnv::Static()->HandleError( err ); |
|
301 } |
|
302 } |
|
303 |
|
304 // -------------------------------------------------------------------------- |
|
305 // CPbk2ContactViewSupplier::ConfigurationChangedComplete |
|
306 // -------------------------------------------------------------------------- |
|
307 // |
|
308 void CPbk2ContactViewSupplier::ConfigurationChangedComplete() |
|
309 { |
|
310 delete iOldContactsView; |
|
311 iOldContactsView = NULL; |
|
312 delete iOldGroupsView; |
|
313 iOldGroupsView = NULL; |
|
314 } |
|
315 |
|
316 // -------------------------------------------------------------------------- |
|
317 // CPbk2ContactViewSupplier::HandleConfigurationChangedL |
|
318 // -------------------------------------------------------------------------- |
|
319 // |
|
320 void CPbk2ContactViewSupplier::HandleConfigurationChangedL() |
|
321 { |
|
322 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
323 ("CPbk2ContactViewSupplier::HandleConfigurationChangedL(0x%x)"), |
|
324 this); |
|
325 |
|
326 MVPbkContactViewBase* allContactsView = CreateAllContactsViewL(); |
|
327 CleanupDeletePushL( allContactsView ); |
|
328 iSortOrderManager.SetContactViewL( *allContactsView ); |
|
329 |
|
330 MVPbkContactViewBase* allGroupsView = NULL; |
|
331 if ( iAllGroupsView ) |
|
332 { |
|
333 allGroupsView = CreateAllGroupsViewL(); |
|
334 } |
|
335 |
|
336 CleanupStack::Pop(); // allContactsView |
|
337 |
|
338 // All leaving stuff done, switch the views |
|
339 |
|
340 if ( iAllContactsView ) |
|
341 { |
|
342 iAllContactsView->RemoveObserver( *this ); |
|
343 delete iOldContactsView; |
|
344 iOldContactsView = iAllContactsView; |
|
345 } |
|
346 iAllContactsView = allContactsView; |
|
347 |
|
348 if ( iAllGroupsView ) |
|
349 { |
|
350 iAllGroupsView->RemoveObserver( *this ); |
|
351 delete iOldGroupsView; |
|
352 iOldGroupsView = iAllGroupsView; |
|
353 } |
|
354 iAllGroupsView = allGroupsView; |
|
355 |
|
356 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
357 ( "CPbk2ContactViewSupplier::HandleConfigurationChangedL(0x%x) end" ), |
|
358 this ); |
|
359 } |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // CPbk2ContactViewSupplier::CreateAllContactsViewL |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 MVPbkContactViewBase* CPbk2ContactViewSupplier::CreateAllContactsViewL() |
|
366 { |
|
367 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
368 ("CPbk2ContactViewSupplier::CreateAllContactsViewL(0x%x)"), this); |
|
369 |
|
370 CPbk2ContactViewBuilder* viewBuilder = CPbk2ContactViewBuilder::NewLC |
|
371 ( iContactManager, iStoreProperties ); |
|
372 |
|
373 CVPbkContactStoreUriArray* currentConfig = |
|
374 iStoreConfiguration.CurrentConfigurationL(); |
|
375 |
|
376 CleanupStack::PushL( currentConfig ); |
|
377 |
|
378 |
|
379 if ( !iNonTopContactSelector ) |
|
380 { |
|
381 iNonTopContactSelector = CPbk2NonTopContactSelector::NewL(); |
|
382 } |
|
383 MVPbkContactViewBase* result = viewBuilder->CreateTopNonTopContactViewForStoresLC |
|
384 ( *currentConfig, *this, iSortOrderManager.SortOrder(), NULL, EVPbkContactViewFlagsNone, *iNonTopContactSelector ); |
|
385 CleanupStack::Pop(); // result |
|
386 CleanupStack::PopAndDestroy( 2 ); // currentConfig, viewBuilder |
|
387 |
|
388 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
389 ("CPbk2ContactViewSupplier::CreateAllContactsViewL(0x%x) end"), this); |
|
390 return result; |
|
391 } |
|
392 |
|
393 // -------------------------------------------------------------------------- |
|
394 // CPbk2ContactViewSupplier::CreateAllGroupsViewL |
|
395 // -------------------------------------------------------------------------- |
|
396 // |
|
397 MVPbkContactViewBase* CPbk2ContactViewSupplier::CreateAllGroupsViewL() |
|
398 { |
|
399 MVPbkContactViewBase* result = NULL; |
|
400 const MVPbkFieldTypeList* sortOrder = NULL; |
|
401 |
|
402 // Acquire group sort order |
|
403 RImplInfoPtrArray implementations; |
|
404 REComSession::ListImplementationsL |
|
405 ( TUid::Uid( KVPbkSortOrderAcquirerInterfaceUID ), implementations ); |
|
406 CleanupStack::PushL( TCleanupItem |
|
407 ( CleanupResetAndDestroy, &implementations ) ); |
|
408 |
|
409 TBool found = EFalse; |
|
410 const TInt count = implementations.Count(); |
|
411 for ( TInt i = count - 1; i >= 0 && !found ; --i ) |
|
412 { |
|
413 CImplementationInformation* implInfo = implementations[i]; |
|
414 |
|
415 if ( implInfo->DisplayName(). |
|
416 CompareC( KGroupSortOrderDisplayName ) == 0 ) |
|
417 { |
|
418 TUid implUid = implInfo->ImplementationUid(); |
|
419 |
|
420 CVPbkSortOrderAcquirer::TSortOrderAcquirerParam param |
|
421 ( iContactManager.FieldTypes() ); |
|
422 |
|
423 delete iSortOrderAcquirer; |
|
424 iSortOrderAcquirer = NULL; |
|
425 iSortOrderAcquirer = CVPbkSortOrderAcquirer::NewL |
|
426 ( implUid, param ); |
|
427 sortOrder = &iSortOrderAcquirer->SortOrder(); |
|
428 found = ETrue; |
|
429 } |
|
430 |
|
431 } |
|
432 CleanupStack::PopAndDestroy(); // implementations |
|
433 |
|
434 if ( sortOrder ) |
|
435 { |
|
436 CPbk2ContactViewBuilder* viewBuilder = CPbk2ContactViewBuilder::NewLC |
|
437 ( iContactManager, iStoreProperties ); |
|
438 |
|
439 CVPbkContactStoreUriArray* currentConfig = |
|
440 iStoreConfiguration.CurrentConfigurationL(); |
|
441 CleanupStack::PushL( currentConfig ); |
|
442 |
|
443 result = viewBuilder->CreateGroupViewForStoresLC |
|
444 ( *currentConfig, *this, *sortOrder, NULL, |
|
445 EVPbkContactViewFlagsNone ); |
|
446 |
|
447 CleanupStack::Pop(); // result |
|
448 CleanupStack::PopAndDestroy( 2 ); // currentConfig, viewBuilder |
|
449 } |
|
450 |
|
451 return result; |
|
452 } |
|
453 |
|
454 // End of File |