|
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 USIM UI Extension view manager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPsu2ViewManager.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "Pbk2USimUIError.h" |
|
24 #include "CPsu2SecUi.h" |
|
25 #include "MPsu2ViewLaunchCallback.h" |
|
26 #include <MPbk2ViewExplorer.h> |
|
27 #include <CPbk2SortOrderManager.h> |
|
28 #include <Pbk2USimUIRes.rsg> |
|
29 #include <CPbk2StoreProperty.h> |
|
30 #include <CPbk2StorePropertyArray.h> |
|
31 #include <MPbk2AppUi.h> |
|
32 #include <Pbk2UIControls.rsg> |
|
33 #include <CPbk2ApplicationServices.h> |
|
34 |
|
35 // Virtual Phonebook |
|
36 #include <CVPbkContactManager.h> |
|
37 #include <TVPbkContactStoreUriPtr.h> |
|
38 #include <MVPbkContactViewBase.h> |
|
39 #include <MVPbkContactStoreList.h> |
|
40 #include <MVPbkContactStore.h> |
|
41 #include <MVPbkContactStoreObserver.h> |
|
42 #include <MVPbkContactViewObserver.h> |
|
43 #include <CVPbkContactViewDefinition.h> |
|
44 #include <CVPbkContactStoreUriArray.h> |
|
45 #include <VPbkSimStoreFactory.h> |
|
46 #include <MVPbkSimPhone.h> |
|
47 #include <VPbkContactStoreUris.h> |
|
48 #include <MVPbkContactStoreProperties.h> |
|
49 |
|
50 // System includes |
|
51 #include <barsread.h> |
|
52 #include <coemain.h> |
|
53 #include <CVPbkSortOrder.h> |
|
54 #include <StringLoader.h> |
|
55 #include <aknnotewrappers.h> |
|
56 |
|
57 // Debugging headers |
|
58 #include <Pbk2Debug.h> |
|
59 |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CPsu2ViewManager::CPsu2ViewManager |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 CPsu2ViewManager::CPsu2ViewManager() |
|
66 { |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CPsu2ViewManager::~CPsu2ViewManager |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 CPsu2ViewManager::~CPsu2ViewManager() |
|
74 { |
|
75 delete iCurrentSimView; |
|
76 delete iSecUi; |
|
77 delete iPhone; |
|
78 delete iFdnSortOrder; |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CPsu2ViewManager::ConstructL |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 inline void CPsu2ViewManager::ConstructL() |
|
86 { |
|
87 CPbk2ApplicationServices* appServices = CPbk2ApplicationServices::InstanceLC(); |
|
88 |
|
89 iContactManager = &(appServices->ContactManager()); |
|
90 |
|
91 CleanupStack::PopAndDestroy(); // appServices |
|
92 |
|
93 iContactStores = &iContactManager->ContactStoresL(); |
|
94 |
|
95 iPhone = VPbkSimStoreFactory::CreatePhoneL(); |
|
96 iSecUi = CPsu2SecUi::NewL(*iPhone); |
|
97 |
|
98 TResourceReader reader; |
|
99 CCoeEnv::Static()->CreateResourceReaderLC( |
|
100 reader, R_PSU2_FDN_NAME_DISPLAY_ORDER ); |
|
101 iFdnSortOrder = CVPbkSortOrder::NewL |
|
102 (reader, iContactManager->FieldTypes() ); |
|
103 CleanupStack::PopAndDestroy(); // reader |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CPsu2ViewManager::NewL |
|
108 // -------------------------------------------------------------------------- |
|
109 // |
|
110 CPsu2ViewManager* CPsu2ViewManager::NewL() |
|
111 { |
|
112 CPsu2ViewManager* self = new ( ELeave ) CPsu2ViewManager; |
|
113 CleanupStack::PushL( self ); |
|
114 self->ConstructL(); |
|
115 CleanupStack::Pop( self ); |
|
116 return self; |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------- |
|
120 // CPsu2ViewManager::ResetAndInitiateStoreAndViewL |
|
121 // -------------------------------------------------------------------------- |
|
122 // |
|
123 void CPsu2ViewManager::ResetAndInitiateStoreAndViewL |
|
124 ( const TVPbkContactStoreUriPtr& aURI, TPsu2ViewId aViewId, |
|
125 MPsu2ViewLaunchCallback& aViewLaunchCallback ) |
|
126 { |
|
127 // Reset |
|
128 iRefCount = 0; |
|
129 delete iCurrentSimView; |
|
130 iCurrentSimView = NULL; |
|
131 if ( iContactStore ) |
|
132 { |
|
133 iContactStore->Close( *this ); |
|
134 } |
|
135 |
|
136 // Initiate |
|
137 iViewId = aViewId; |
|
138 iViewLaunchCallback = &aViewLaunchCallback; |
|
139 |
|
140 // Retrieve store list from the contact manager |
|
141 MVPbkContactStoreList& storeList = iContactManager->ContactStoresL(); |
|
142 // Check whether the plugin is loaded, does not mean that the store is open |
|
143 MVPbkContactStore* store = storeList.Find(aURI); |
|
144 if ( !store ) |
|
145 { |
|
146 iContactManager->LoadContactStoreL( aURI ); |
|
147 } |
|
148 |
|
149 // Plugin is now loaded and store exists |
|
150 iContactStore = storeList.Find( aURI ); |
|
151 |
|
152 __ASSERT_DEBUG(iContactStore, Pbk2USimUI::Panic( |
|
153 Pbk2USimUI::EPostCond_OpenAndActivateViewL ) ); |
|
154 |
|
155 iContactStore->OpenL( *this ); |
|
156 } |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CPsu2ViewManager::RemoveViewLaunchCallBack |
|
160 // -------------------------------------------------------------------------- |
|
161 // |
|
162 void CPsu2ViewManager::RemoveViewLaunchCallBack() |
|
163 { |
|
164 iViewLaunchCallback = NULL; |
|
165 } |
|
166 // -------------------------------------------------------------------------- |
|
167 // CPsu2ViewManager::RegisterStoreAndView |
|
168 // -------------------------------------------------------------------------- |
|
169 // |
|
170 void CPsu2ViewManager::RegisterStoreAndView() |
|
171 { |
|
172 ++iRefCount; |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // CPsu2ViewManager::DeregisterStoreAndView |
|
177 // -------------------------------------------------------------------------- |
|
178 // |
|
179 void CPsu2ViewManager::DeregisterStoreAndView() |
|
180 { |
|
181 --iRefCount; |
|
182 |
|
183 if ( iRefCount <= 0 ) |
|
184 { |
|
185 // No clients left, close view and then close store |
|
186 delete iCurrentSimView; |
|
187 iCurrentSimView = NULL; |
|
188 iContactStore->Close( *this ); |
|
189 } |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CPsu2ViewManager::ContactStore |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 MVPbkContactStore& CPsu2ViewManager::ContactStore() |
|
197 { |
|
198 return *iContactStore; |
|
199 } |
|
200 |
|
201 // -------------------------------------------------------------------------- |
|
202 // CPsu2ViewManager::StoreReady |
|
203 // -------------------------------------------------------------------------- |
|
204 // |
|
205 void CPsu2ViewManager::StoreReady( MVPbkContactStore& aContactStore ) |
|
206 { |
|
207 if ( iContactStore == &aContactStore ) |
|
208 { |
|
209 iStoreAvailable = ETrue; |
|
210 |
|
211 // Not need to create new view if we already have one. |
|
212 if ( !iCurrentSimView ) |
|
213 { |
|
214 TRAPD( err, DoOpenContactViewL() ); |
|
215 if ( err != KErrNone ) |
|
216 { |
|
217 if ( iViewLaunchCallback ) |
|
218 { |
|
219 iViewLaunchCallback->HandleError( err ); |
|
220 } |
|
221 } |
|
222 } |
|
223 } |
|
224 } |
|
225 |
|
226 // -------------------------------------------------------------------------- |
|
227 // CPsu2ViewManager::StoreUnavailable |
|
228 // -------------------------------------------------------------------------- |
|
229 // |
|
230 void CPsu2ViewManager::StoreUnavailable |
|
231 ( MVPbkContactStore& aContactStore, TInt aReason ) |
|
232 { |
|
233 if ( iContactStore == &aContactStore ) |
|
234 { |
|
235 iStoreAvailable = EFalse; |
|
236 if ( iViewLaunchCallback ) |
|
237 { |
|
238 iViewLaunchCallback->HandleError( aReason ); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 // -------------------------------------------------------------------------- |
|
244 // CPsu2ViewManager::HandleStoreEventL |
|
245 // -------------------------------------------------------------------------- |
|
246 // |
|
247 void CPsu2ViewManager::HandleStoreEventL |
|
248 ( MVPbkContactStore& /*aContactStore*/, |
|
249 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
250 { |
|
251 // No action |
|
252 } |
|
253 |
|
254 // -------------------------------------------------------------------------- |
|
255 // CPsu2ViewManager::ContactViewReady |
|
256 // -------------------------------------------------------------------------- |
|
257 // |
|
258 void CPsu2ViewManager::ContactViewReady( MVPbkContactViewBase& aView ) |
|
259 { |
|
260 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
261 ("CPsu2ViewManager::ContactViewReady(0x%x)"), &aView); |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // CPsu2ViewManager::ContactViewUnavailable |
|
266 // -------------------------------------------------------------------------- |
|
267 // |
|
268 void CPsu2ViewManager::ContactViewUnavailable |
|
269 ( MVPbkContactViewBase& aView ) |
|
270 { |
|
271 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
272 ("CPsu2ViewManager::ContactViewUnavailable(0x%x)"), &aView); |
|
273 } |
|
274 |
|
275 // -------------------------------------------------------------------------- |
|
276 // CPsu2ViewManager::ContactAddedToView |
|
277 // -------------------------------------------------------------------------- |
|
278 // |
|
279 void CPsu2ViewManager::ContactAddedToView |
|
280 ( MVPbkContactViewBase& aView, TInt aIndex, |
|
281 const MVPbkContactLink& aContactLink ) |
|
282 { |
|
283 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
284 ("CPsu2ViewManager::ContactAddedToView(0x%x,%d,0x%x)"), |
|
285 &aView, aIndex, &aContactLink); |
|
286 } |
|
287 |
|
288 // -------------------------------------------------------------------------- |
|
289 // CPsu2ViewManager::ContactRemovedFromView |
|
290 // -------------------------------------------------------------------------- |
|
291 // |
|
292 void CPsu2ViewManager::ContactRemovedFromView |
|
293 ( MVPbkContactViewBase& aView, TInt aIndex, |
|
294 const MVPbkContactLink& aContactLink ) |
|
295 { |
|
296 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
297 ("CPsu2ViewManager::ContactRemovedFromView(0x%x,%d,0x%x)"), |
|
298 &aView, aIndex, &aContactLink); |
|
299 } |
|
300 |
|
301 // -------------------------------------------------------------------------- |
|
302 // CPsu2ViewManager::ContactViewError |
|
303 // -------------------------------------------------------------------------- |
|
304 // |
|
305 void CPsu2ViewManager::ContactViewError |
|
306 ( MVPbkContactViewBase& aView, |
|
307 TInt aError, TBool /*aErrorNotified*/ ) |
|
308 { |
|
309 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
310 ("CPsu2ViewManager::ContactViewError(0x%x,%d)"), |
|
311 &aView, aError); |
|
312 } |
|
313 |
|
314 // -------------------------------------------------------------------------- |
|
315 // CPsu2ViewManager::CreateViewL |
|
316 // -------------------------------------------------------------------------- |
|
317 // |
|
318 MVPbkContactViewBase* CPsu2ViewManager::CreateViewL |
|
319 ( TInt aViewDefResourceId ) |
|
320 { |
|
321 MVPbkContactViewBase* view = NULL; |
|
322 |
|
323 TResourceReader reader; |
|
324 CCoeEnv::Static()->CreateResourceReaderLC( reader, aViewDefResourceId ); |
|
325 |
|
326 CVPbkContactViewDefinition* def = |
|
327 CVPbkContactViewDefinition::NewL( reader ); |
|
328 CleanupStack::PushL( def ); |
|
329 |
|
330 if ( aViewDefResourceId == R_PSU2_FDN_CONTACTS_VIEW ) |
|
331 { |
|
332 view = iContactManager->CreateContactViewLC |
|
333 ( *this, *def, *iFdnSortOrder ); |
|
334 } |
|
335 else |
|
336 { |
|
337 view = iContactManager->CreateContactViewLC |
|
338 ( *this, *def, Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
339 SortOrderManager().SortOrder() ); |
|
340 } |
|
341 |
|
342 CleanupStack::Pop(); // view |
|
343 CleanupStack::PopAndDestroy( 2 ); // def, reader |
|
344 return view; |
|
345 } |
|
346 |
|
347 // -------------------------------------------------------------------------- |
|
348 // CPsu2ViewManager::OpenViewL |
|
349 // -------------------------------------------------------------------------- |
|
350 // |
|
351 MVPbkContactViewBase* CPsu2ViewManager::OpenViewL(TPsu2ViewId aViewId) |
|
352 { |
|
353 MVPbkContactViewBase* view = NULL; |
|
354 switch (aViewId) |
|
355 { |
|
356 case EPsu2OwnNumberViewId: |
|
357 { |
|
358 view = CreateViewL(R_PSU2_OWN_NUMBER_CONTACTS_VIEW ); |
|
359 break; |
|
360 } |
|
361 case EPsu2ServiceDialingViewId: |
|
362 { |
|
363 view = CreateViewL(R_PSU2_SDN_CONTACTS_VIEW ); |
|
364 break; |
|
365 } |
|
366 case EPsu2FixedDialingViewId: |
|
367 { |
|
368 view = CreateViewL(R_PSU2_FDN_CONTACTS_VIEW ); |
|
369 break; |
|
370 } |
|
371 default: |
|
372 { |
|
373 // Do nothing |
|
374 break; |
|
375 } |
|
376 } |
|
377 |
|
378 __ASSERT_DEBUG( view, Pbk2USimUI::Panic |
|
379 ( Pbk2USimUI::EPostCond_OpenAndActivateViewL ) ); |
|
380 |
|
381 return view; |
|
382 } |
|
383 |
|
384 // -------------------------------------------------------------------------- |
|
385 // CPsu2ViewManager::DoOpenContactViewL |
|
386 // -------------------------------------------------------------------------- |
|
387 // |
|
388 void CPsu2ViewManager::DoOpenContactViewL() |
|
389 { |
|
390 // Open contact view |
|
391 delete iCurrentSimView; |
|
392 iCurrentSimView = NULL; |
|
393 iCurrentSimView = OpenViewL( iViewId ); |
|
394 |
|
395 if ( iViewLaunchCallback ) |
|
396 { |
|
397 iViewLaunchCallback->SetContactViewL( *iCurrentSimView ); |
|
398 } |
|
399 } |
|
400 |
|
401 // -------------------------------------------------------------------------- |
|
402 // CPsu2ViewManager::StoreAvailable |
|
403 // -------------------------------------------------------------------------- |
|
404 // |
|
405 TBool CPsu2ViewManager::StoreAvailableL() |
|
406 { |
|
407 if ( !iStoreAvailable ) |
|
408 { |
|
409 // Show unavailable note |
|
410 const CPbk2StoreProperty* prop = Phonebook2::Pbk2AppUi()-> |
|
411 ApplicationServices().StoreProperties().FindProperty |
|
412 ( iContactStore->StoreProperties().Uri() ); |
|
413 HBufC* text = NULL; |
|
414 if ( prop ) |
|
415 { |
|
416 if ( prop->StoreName().Length() > 0 ) |
|
417 { |
|
418 text = StringLoader::LoadLC |
|
419 ( R_QTN_PHOB_STORE_NOT_AVAILABLE, prop->StoreName() ); |
|
420 } |
|
421 } |
|
422 if ( !text ) |
|
423 { |
|
424 text = StringLoader::LoadLC |
|
425 ( R_QTN_PHOB_STORE_NOT_AVAILABLE, |
|
426 iContactStore->StoreProperties().Uri().UriDes() ); |
|
427 } |
|
428 CAknInformationNote* note = |
|
429 new ( ELeave ) CAknInformationNote( ETrue ); |
|
430 // Show "not available" note |
|
431 note->ExecuteLD(*text); |
|
432 CleanupStack::PopAndDestroy(text); |
|
433 } |
|
434 return iStoreAvailable; |
|
435 } |
|
436 |
|
437 // End of File |