|
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 application services. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2ApplicationServices.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <CPbk2StoreManager.h> |
|
24 #include <CPbk2SortOrderManager.h> |
|
25 #include <MPbk2ContactNameFormatter.h> |
|
26 #include <CPbk2CommandHandler.h> |
|
27 #include <MPbk2ViewExplorer.h> |
|
28 #include <Pbk2ContactNameFormatterFactory.h> |
|
29 #include <Pbk2CommonUi.rsg> |
|
30 #include <CPbk2StorePropertyArray.h> |
|
31 #include <CPbk2FieldPropertyArray.h> |
|
32 #include <Pbk2MenuFilteringFlags.hrh> |
|
33 #include <Phonebook2PrivateCRKeys.h> |
|
34 #include <CPbk2ContactViewSupplier.h> |
|
35 #include <CPbk2StoreConfiguration.h> |
|
36 #include <CPbk2ServiceManager.h> |
|
37 |
|
38 // Virtual Phonebook |
|
39 #include <CVPbkContactManager.h> |
|
40 #include <CVPbkContactStoreUriArray.h> |
|
41 |
|
42 // System includes |
|
43 #include <StringLoader.h> |
|
44 #include <sendui.h> |
|
45 #include <centralrepository.h> |
|
46 |
|
47 // Debugging headers |
|
48 #include <Pbk2Config.hrh> |
|
49 #include <Pbk2Debug.h> |
|
50 #include <Pbk2Profile.h> |
|
51 |
|
52 /// Unnamed namespace for local definitions |
|
53 namespace { |
|
54 |
|
55 /** |
|
56 * Returns the global instance of CPbk2ApplicationServices. |
|
57 * |
|
58 * @return Instance of CPbk2ApplicationServices. |
|
59 */ |
|
60 inline CPbk2ApplicationServices* Instance() |
|
61 { |
|
62 return static_cast<CPbk2ApplicationServices*>( Dll::Tls() ); |
|
63 } |
|
64 |
|
65 } /// namespace |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // CPbk2ApplicationServices::CPbk2ApplicationServices |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 CPbk2ApplicationServices::CPbk2ApplicationServices() |
|
72 : iLocalVariationFlags(KErrNotFound) |
|
73 { |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CPbk2ApplicationServices::~CPbk2ApplicationServices |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 CPbk2ApplicationServices::~CPbk2ApplicationServices() |
|
81 { |
|
82 // Command handler is calling iStoreConfiguration's RemoveObserver |
|
83 // in its destructor. So delete command handler before store |
|
84 // configuration. |
|
85 delete iServiceManager; |
|
86 delete iSortOrderManager; |
|
87 delete iNameFormatter; |
|
88 delete iFieldProperties; |
|
89 delete iViewSupplier; |
|
90 delete iStoreManager; |
|
91 delete iStoreConfiguration; |
|
92 delete iStoreProperties; |
|
93 delete iContactManager; |
|
94 } |
|
95 |
|
96 // -------------------------------------------------------------------------- |
|
97 // CPbk2ApplicationServices::ConstructL |
|
98 // -------------------------------------------------------------------------- |
|
99 // |
|
100 inline void CPbk2ApplicationServices::ConstructL() |
|
101 { |
|
102 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
103 ( "CPbk2ApplicationServices::ConstructL(0x%x)"), this ); |
|
104 |
|
105 // Create Virtual Phonebook contact manager for Phonebook 2 |
|
106 CreateManagerL(); |
|
107 |
|
108 CreateSortOrderManagerL(); |
|
109 CreateStorePropertyArrayL(); |
|
110 CreateStoreConfigurationL(); |
|
111 CreateViewSupplierL(); |
|
112 |
|
113 PBK2_PROFILE_START(Pbk2Profile::EAppServicesCreateStoreManager); |
|
114 iStoreManager = CPbk2StoreManager::NewL |
|
115 ( *iContactManager, *iStoreConfiguration, ETrue ); |
|
116 PBK2_PROFILE_END(Pbk2Profile::EAppServicesCreateStoreManager); |
|
117 |
|
118 // Set core Phonebook 2 stores |
|
119 iStoreManager->EnsureDefaultSavingStoreIncludedL(); |
|
120 iStoreManager->EnsureCurrentConfigurationStoresIncludedL(); |
|
121 |
|
122 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
123 ( "CPbk2ApplicationServices::ConstructL(0x%x) Store manager created"), |
|
124 this ); |
|
125 |
|
126 iServiceManager = CPbk2ServiceManager::NewL(iContactManager->FsSession()); |
|
127 |
|
128 CreateFieldPropertyArrayL(); |
|
129 CreateNameFormatterL(); |
|
130 |
|
131 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
132 ("CPbk2ApplicationServices::ConstructL(0x%x) end"), this); |
|
133 } |
|
134 |
|
135 // -------------------------------------------------------------------------- |
|
136 // CPbk2ApplicationServices::NewL |
|
137 // -------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C CPbk2ApplicationServices* CPbk2ApplicationServices::InstanceL() |
|
140 { |
|
141 CPbk2ApplicationServices* instance = Instance(); |
|
142 |
|
143 if ( !instance ) |
|
144 { |
|
145 instance = new ( ELeave ) CPbk2ApplicationServices; |
|
146 CleanupStack::PushL( instance ); |
|
147 User::LeaveIfError( Dll::SetTls( instance ) ); |
|
148 TRAPD( error, instance->ConstructL(); ); |
|
149 if( error != KErrNone ) |
|
150 { |
|
151 Dll::SetTls( NULL ); |
|
152 User::Leave( error ); |
|
153 } |
|
154 |
|
155 CleanupStack::Pop( instance ); |
|
156 } |
|
157 |
|
158 instance->IncRef(); |
|
159 |
|
160 return instance; |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // CPbk2ApplicationServices::InstanceLC |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C CPbk2ApplicationServices* CPbk2ApplicationServices::InstanceLC() |
|
168 { |
|
169 CPbk2ApplicationServices* appServices = InstanceL(); |
|
170 appServices->PushL(); |
|
171 return appServices; |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CPbk2ApplicationServices::ContactManager |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 CVPbkContactManager& CPbk2ApplicationServices::ContactManager() const |
|
179 { |
|
180 return *iContactManager; |
|
181 } |
|
182 |
|
183 // -------------------------------------------------------------------------- |
|
184 // CPbk2ApplicationServices::CommandHandlerL |
|
185 // -------------------------------------------------------------------------- |
|
186 // |
|
187 MPbk2CommandHandler* CPbk2ApplicationServices::CommandHandlerL() |
|
188 { |
|
189 // Not supported in Base Application Services |
|
190 return NULL; |
|
191 } |
|
192 |
|
193 // -------------------------------------------------------------------------- |
|
194 // CPbk2ApplicationServices::NameFormatter |
|
195 // -------------------------------------------------------------------------- |
|
196 // |
|
197 MPbk2ContactNameFormatter& CPbk2ApplicationServices::NameFormatter() const |
|
198 { |
|
199 return *iNameFormatter; |
|
200 } |
|
201 |
|
202 // -------------------------------------------------------------------------- |
|
203 // CPbk2ApplicationServices::SortOrderManager |
|
204 // -------------------------------------------------------------------------- |
|
205 // |
|
206 CPbk2SortOrderManager& CPbk2ApplicationServices::SortOrderManager() const |
|
207 { |
|
208 return *iSortOrderManager; |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CPbk2ApplicationServices::SendUiL |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 CSendUi* CPbk2ApplicationServices::SendUiL() |
|
216 { |
|
217 // Not supported in Base Application Services |
|
218 return NULL; |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CPbk2ApplicationServices::StoreProperties |
|
223 // -------------------------------------------------------------------------- |
|
224 // |
|
225 CPbk2StorePropertyArray& CPbk2ApplicationServices::StoreProperties() const |
|
226 { |
|
227 return *iStoreProperties; |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------- |
|
231 // CPbk2ApplicationServices::FieldProperties |
|
232 // -------------------------------------------------------------------------- |
|
233 // |
|
234 CPbk2FieldPropertyArray& CPbk2ApplicationServices::FieldProperties() const |
|
235 { |
|
236 return *iFieldProperties; |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // CPbk2ApplicationServices::StoreConfiguration |
|
241 // -------------------------------------------------------------------------- |
|
242 // |
|
243 CPbk2StoreConfiguration& CPbk2ApplicationServices::StoreConfiguration() const |
|
244 { |
|
245 return *iStoreConfiguration; |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPbk2ApplicationServices::StoreObservationRegister |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 MPbk2StoreObservationRegister& |
|
253 CPbk2ApplicationServices::StoreObservationRegister() const |
|
254 { |
|
255 return *iStoreManager; |
|
256 } |
|
257 |
|
258 // -------------------------------------------------------------------------- |
|
259 // CPbk2ApplicationServices::StoreValidityInformer |
|
260 // -------------------------------------------------------------------------- |
|
261 // |
|
262 MPbk2StoreValidityInformer& |
|
263 CPbk2ApplicationServices::StoreValidityInformer() const |
|
264 { |
|
265 return *iStoreManager; |
|
266 } |
|
267 |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // CPbk2ApplicationServices::ViewSupplier |
|
271 // -------------------------------------------------------------------------- |
|
272 // |
|
273 MPbk2ContactViewSupplier& CPbk2ApplicationServices::ViewSupplier() const |
|
274 { |
|
275 return *iViewSupplier; |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // CPbk2ApplicationServices::GlobalMenuFilteringFlagsL |
|
280 // -------------------------------------------------------------------------- |
|
281 // |
|
282 TInt CPbk2ApplicationServices::GlobalMenuFilteringFlagsL() const |
|
283 { |
|
284 return KPbk2MenuFilteringFlagsNone; |
|
285 } |
|
286 |
|
287 // -------------------------------------------------------------------------- |
|
288 // CPbk2ApplicationServices::LocallyVariatedFeatureEnabled |
|
289 // -------------------------------------------------------------------------- |
|
290 // |
|
291 TBool CPbk2ApplicationServices::LocallyVariatedFeatureEnabled( |
|
292 TVPbkLocalVariantFlags aFeatureFlag) |
|
293 { |
|
294 TBool ret = EFalse; |
|
295 |
|
296 if ( iLocalVariationFlags == KErrNotFound ) |
|
297 { |
|
298 GetLocalVariationFlags(); |
|
299 } |
|
300 |
|
301 if ( iLocalVariationFlags != KErrNotFound ) |
|
302 { |
|
303 ret = (iLocalVariationFlags & aFeatureFlag); |
|
304 } |
|
305 |
|
306 return ret; |
|
307 } |
|
308 |
|
309 // -------------------------------------------------------------------------- |
|
310 // CPbk2ApplicationServices::MPbk2ApplicationServicesExtension |
|
311 // -------------------------------------------------------------------------- |
|
312 // |
|
313 TAny* CPbk2ApplicationServices::MPbk2ApplicationServicesExtension( |
|
314 TUid aExtensionUid ) |
|
315 { |
|
316 if ( aExtensionUid == KMPbk2ApplicationServicesExtension2Uid ) |
|
317 { |
|
318 return static_cast<MPbk2ApplicationServices2*>( this ); |
|
319 } |
|
320 return NULL; |
|
321 } |
|
322 |
|
323 // -------------------------------------------------------------------------- |
|
324 // CPbk2ApplicationServices::StoreManager |
|
325 // -------------------------------------------------------------------------- |
|
326 // |
|
327 CPbk2StoreManager& CPbk2ApplicationServices::StoreManager() const |
|
328 { |
|
329 return *iStoreManager; |
|
330 } |
|
331 |
|
332 // -------------------------------------------------------------------------- |
|
333 // CPbk2ApplicationServices::ServicesManager |
|
334 // -------------------------------------------------------------------------- |
|
335 // |
|
336 CPbk2ServiceManager& CPbk2ApplicationServices::ServiceManager() const |
|
337 { |
|
338 return *iServiceManager; |
|
339 } |
|
340 |
|
341 // -------------------------------------------------------------------------- |
|
342 // CPbk2ApplicationServices::CreateManagerL |
|
343 // -------------------------------------------------------------------------- |
|
344 // |
|
345 inline void CPbk2ApplicationServices::CreateManagerL() |
|
346 { |
|
347 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
348 ( "CPbk2ApplicationServices:CreateManagerL(0x%x)" ), this ); |
|
349 |
|
350 // Initialize contact manager with empty URI array |
|
351 CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewL(); |
|
352 CleanupStack::PushL( uriArray ); |
|
353 |
|
354 TSecurityInfo secInfo; |
|
355 |
|
356 // Using the security info of the current process to create contact manager |
|
357 secInfo.SetToCurrentInfo(); |
|
358 |
|
359 iContactManager = CVPbkContactManager::NewL( secInfo, *uriArray ); |
|
360 //iContactManager = CVPbkContactManager::NewL( *uriArray ); |
|
361 |
|
362 CleanupStack::PopAndDestroy(); // uriArray |
|
363 |
|
364 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
365 ("CPbk2ApplicationServices::CreateManagerL(0x%x) end"), this); |
|
366 } |
|
367 |
|
368 // -------------------------------------------------------------------------- |
|
369 // CPbk2ApplicationServices::CreateSortOrderManagerL |
|
370 // -------------------------------------------------------------------------- |
|
371 // |
|
372 inline void CPbk2ApplicationServices::CreateSortOrderManagerL() |
|
373 { |
|
374 PBK2_PROFILE_START( Pbk2Profile::EAppServicesCreateSortOrderManager ); |
|
375 |
|
376 iSortOrderManager = CPbk2SortOrderManager::NewL |
|
377 ( iContactManager->FieldTypes() ); |
|
378 |
|
379 PBK2_PROFILE_END( Pbk2Profile::EAppServicesCreateSortOrderManager ); |
|
380 } |
|
381 |
|
382 // -------------------------------------------------------------------------- |
|
383 // CPbk2ApplicationServices::CreateStorePropertyArrayL |
|
384 // -------------------------------------------------------------------------- |
|
385 // |
|
386 inline void CPbk2ApplicationServices::CreateStorePropertyArrayL() |
|
387 { |
|
388 PBK2_PROFILE_START( Pbk2Profile::EAppServicesCreateStorePropertyArray ); |
|
389 iStoreProperties = CPbk2StorePropertyArray::NewL(); |
|
390 PBK2_PROFILE_END( Pbk2Profile::EAppServicesCreateStorePropertyArray ); |
|
391 |
|
392 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
393 ( "CPbk2ApplicationServices::CreateStorePropertyArrayL() done ") ); |
|
394 } |
|
395 |
|
396 // -------------------------------------------------------------------------- |
|
397 // CPbk2ApplicationServices::CreateFieldPropertyArrayL |
|
398 // -------------------------------------------------------------------------- |
|
399 // |
|
400 inline void CPbk2ApplicationServices::CreateFieldPropertyArrayL() |
|
401 { |
|
402 PBK2_PROFILE_START( Pbk2Profile::EAppServicesCreateFieldPropertyArray ); |
|
403 iFieldProperties = CPbk2FieldPropertyArray::NewL |
|
404 ( iContactManager->FieldTypes(), iContactManager->FsSession(), |
|
405 iServiceManager ); |
|
406 PBK2_PROFILE_END( Pbk2Profile::EAppServicesCreateFieldPropertyArray ); |
|
407 } |
|
408 |
|
409 // -------------------------------------------------------------------------- |
|
410 // CPbk2ApplicationServices::CreateNameFormatterL |
|
411 // -------------------------------------------------------------------------- |
|
412 // |
|
413 inline void CPbk2ApplicationServices::CreateNameFormatterL() |
|
414 { |
|
415 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
416 ( "CPbk2ApplicationServices::CreateNameFormatterL(0x%x)" ), this ); |
|
417 |
|
418 HBufC* unnamedBuf = StringLoader::LoadLC( R_QTN_PHOB_UNNAMED ); |
|
419 TPtr unnamed = unnamedBuf->Des(); |
|
420 MPbk2ContactNameFormatter* nameFormatter = |
|
421 Pbk2ContactNameFormatterFactory::CreateL |
|
422 ( unnamed, iContactManager->FieldTypes(), *iSortOrderManager, |
|
423 &CCoeEnv::Static()->FsSession() ); |
|
424 CleanupStack::PopAndDestroy( unnamedBuf ); |
|
425 |
|
426 delete iNameFormatter; |
|
427 iNameFormatter = nameFormatter; |
|
428 |
|
429 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
430 ( "CPbk2ApplicationServices::CreateNameFormatterL(0x%x) end" ), |
|
431 this ); |
|
432 } |
|
433 |
|
434 // -------------------------------------------------------------------------- |
|
435 // CPbk2ApplicationServices::CreateViewSupplierL |
|
436 // -------------------------------------------------------------------------- |
|
437 // |
|
438 inline void CPbk2ApplicationServices::CreateViewSupplierL() |
|
439 { |
|
440 iViewSupplier = CPbk2ContactViewSupplier::NewL |
|
441 ( *iContactManager, *iSortOrderManager, *iStoreConfiguration, |
|
442 *iStoreProperties, ETrue ); |
|
443 } |
|
444 |
|
445 // -------------------------------------------------------------------------- |
|
446 // CPbk2ApplicationServices::CreateStoreConfigurationL |
|
447 // -------------------------------------------------------------------------- |
|
448 // |
|
449 inline void CPbk2ApplicationServices::CreateStoreConfigurationL() |
|
450 { |
|
451 iStoreConfiguration = CPbk2StoreConfiguration::NewL(); |
|
452 } |
|
453 |
|
454 // -------------------------------------------------------------------------- |
|
455 // CPbk2ApplicationServices::GetLocalVariationFlags |
|
456 // -------------------------------------------------------------------------- |
|
457 // |
|
458 void CPbk2ApplicationServices::GetLocalVariationFlags() |
|
459 { |
|
460 CRepository* key = NULL; |
|
461 |
|
462 // Read local variation flags |
|
463 TRAPD( err, key = |
|
464 CRepository::NewL( TUid::Uid( KCRUidPhonebook ) ) ); |
|
465 |
|
466 // If NewL fails do not set iLocalVariationFlags, new query is made next time |
|
467 if ( err == KErrNone ) |
|
468 { |
|
469 err = key->Get( KPhonebookLocalVariationFlags, iLocalVariationFlags ); |
|
470 if ( err != KErrNone ) |
|
471 { |
|
472 // If there were problems reading the flags, |
|
473 // assume everything is off |
|
474 iLocalVariationFlags = 0; |
|
475 } |
|
476 delete key; |
|
477 } |
|
478 } |
|
479 |
|
480 // -------------------------------------------------------------------------- |
|
481 // CPbk2ApplicationServices::DoRelease |
|
482 // -------------------------------------------------------------------------- |
|
483 // |
|
484 void CPbk2ApplicationServices::DoRelease() |
|
485 { |
|
486 if (DecRef() == 0) |
|
487 { |
|
488 Dll::SetTls(NULL); |
|
489 delete this; |
|
490 } |
|
491 } |
|
492 |
|
493 // -------------------------------------------------------------------------- |
|
494 // CPbk2ApplicationServices::IncRef |
|
495 // -------------------------------------------------------------------------- |
|
496 // |
|
497 void CPbk2ApplicationServices::IncRef() |
|
498 { |
|
499 ++iRefCount; |
|
500 } |
|
501 |
|
502 // -------------------------------------------------------------------------- |
|
503 // CPbk2ApplicationServices::DecRef |
|
504 // -------------------------------------------------------------------------- |
|
505 // |
|
506 TInt CPbk2ApplicationServices::DecRef() |
|
507 { |
|
508 return --iRefCount; |
|
509 } |
|
510 |
|
511 // End of File |