author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:15:33 +0300 | |
branch | RCL_3 |
changeset 85 | 38bb213f60ba |
parent 68 | 9da50d567e3c |
permissions | -rw-r--r-- |
63 | 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: . |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// class header |
|
19 |
#include "cpbk2mycard.h" |
|
20 |
||
21 |
// Pbk2 |
|
22 |
#include <MPbk2AppUi.h> |
|
23 |
#include <CPbk2ApplicationServices.h> |
|
24 |
#include "mpbk2mycardobserver.h" |
|
25 |
#include <MVPbkFieldType.h> |
|
26 |
#include <Pbk2InternalUID.h> |
|
27 |
#include "pbk2nameslistexiconid.hrh" |
|
28 |
#include "Pbk2NamesListExUID.h" |
|
29 |
||
30 |
// Virtual Phonebook |
|
31 |
#include <VPbkContactStoreUris.h> |
|
32 |
#include <TVPbkContactStoreUriPtr.h> |
|
33 |
#include <MVPbkContactStore.h> |
|
34 |
#include <MVPbkContactStore2.h> |
|
35 |
#include <CVPbkContactManager.h> |
|
36 |
#include <MVPbkContactStoreList.h> |
|
37 |
#include <MVPbkContactOperationBase.h> |
|
38 |
#include <MVPbkContactLink.h> |
|
39 |
#include <MVPbkStoreContact.h> |
|
40 |
||
41 |
// thumbnail loading |
|
42 |
#include <CPbk2ImageManager.h> |
|
43 |
#include <TPbk2ImageManagerParams.h> |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
44 |
#include <VPbkEng.rsg> |
63 | 45 |
#include <fbs.h> |
46 |
#include <AknUtils.h> |
|
47 |
#include <aknlayoutscalable_apps.cdl.h> |
|
48 |
||
49 |
TSize CalculateThumbnailSize() |
|
50 |
{ |
|
51 |
TAknWindowComponentLayout layout( |
|
52 |
TAknWindowComponentLayout::Compose( |
|
53 |
AknLayoutScalable_Apps::list_double_large_graphic_phob2_pane( 0 ), |
|
54 |
AknLayoutScalable_Apps::list_double_large_graphic_phob2_pane_g1( 0 ) ) ); |
|
55 |
||
56 |
TRect mainPane; |
|
57 |
AknLayoutUtils::LayoutMetricsRect( |
|
58 |
AknLayoutUtils::EMainPane, mainPane ); |
|
59 |
TAknLayoutRect layoutRect; |
|
60 |
layoutRect.LayoutRect( |
|
61 |
mainPane, |
|
62 |
layout.LayoutLine() ); |
|
63 |
return layoutRect.Rect().Size(); |
|
64 |
} |
|
65 |
||
66 |
// -------------------------------------------------------------------------- |
|
67 |
// CPbk2MyCard::NewL |
|
68 |
// -------------------------------------------------------------------------- |
|
69 |
// |
|
70 |
CPbk2MyCard* CPbk2MyCard::NewL( MVPbkContactStore& aPhoneStore ) |
|
71 |
{ |
|
72 |
CPbk2MyCard* self = new (ELeave) CPbk2MyCard( aPhoneStore ); |
|
73 |
CleanupStack::PushL( self ); |
|
74 |
self->ConstructL(); |
|
75 |
CleanupStack::Pop( self ); |
|
76 |
return self; |
|
77 |
} |
|
78 |
||
79 |
// -------------------------------------------------------------------------- |
|
80 |
// CPbk2MyCard::ConstructL |
|
81 |
// -------------------------------------------------------------------------- |
|
82 |
// |
|
83 |
void CPbk2MyCard::ConstructL() |
|
84 |
{ |
|
85 |
// first get application services and contact manager |
|
86 |
iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
87 |
iContactManager = &iAppServices->ContactManager(); |
|
88 |
||
89 |
// create image manager for fetching the thumbnail |
|
90 |
iImageManager = CPbk2ImageManager::NewL( *iContactManager ); |
|
91 |
iPhoneStore->OpenL(*this); |
|
92 |
} |
|
93 |
||
94 |
// -------------------------------------------------------------------------- |
|
95 |
// CPbk2MyCard::CPbk2MyCard |
|
96 |
// -------------------------------------------------------------------------- |
|
97 |
// |
|
98 |
CPbk2MyCard::CPbk2MyCard( MVPbkContactStore& aPhoneStore ) |
|
99 |
:iMyCardState( EUnkown ), |
|
100 |
iPhoneStore( &aPhoneStore ), |
|
101 |
iIconId( TUid::Uid( KPbk2ControlCmdItemExtensionUID ), 1 ), |
|
102 |
iEmptyId( TUid::Uid( KPbk2NamesListExtPluginUID2 ), |
|
103 |
EPbk2EceNoMyCardThumbnailIconId ) |
|
104 |
{ |
|
105 |
} |
|
106 |
||
107 |
// -------------------------------------------------------------------------- |
|
108 |
// CPbk2MyCard::~CPbk2MyCard |
|
109 |
// -------------------------------------------------------------------------- |
|
110 |
// |
|
111 |
CPbk2MyCard::~CPbk2MyCard() |
|
112 |
{ |
|
113 |
delete iThumbBitmap; |
|
114 |
delete iMyCardStoreContact; |
|
115 |
delete iImageManager; |
|
116 |
delete iMyCardLink; |
|
117 |
delete iOperation; |
|
118 |
Release( iAppServices ); |
|
119 |
iObserverArray.Reset(); |
|
120 |
if(iPhoneStore) |
|
121 |
{ |
|
122 |
iPhoneStore->Close(*this); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
// -------------------------------------------------------------------------- |
|
127 |
// CPbk2MyCard::SetObserverL |
|
128 |
// -------------------------------------------------------------------------- |
|
129 |
// |
|
130 |
void CPbk2MyCard::SetObserverL(MPbk2MyCardObserver& aObserver) |
|
131 |
{ |
|
132 |
iObserverArray.AppendL(&aObserver); |
|
133 |
} |
|
134 |
||
135 |
// -------------------------------------------------------------------------- |
|
136 |
// CPbk2MyCard::RemoveObserver |
|
137 |
// -------------------------------------------------------------------------- |
|
138 |
// |
|
139 |
void CPbk2MyCard::RemoveObserver(MPbk2MyCardObserver& aObserver) |
|
140 |
{ |
|
141 |
const TInt index(iObserverArray.Find(&aObserver)); |
|
142 |
if(index >= 0) |
|
143 |
{ |
|
144 |
iObserverArray.Remove(index); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
// -------------------------------------------------------------------------- |
|
149 |
// CPbk2MyCard::NotifyObservers |
|
150 |
// -------------------------------------------------------------------------- |
|
151 |
// |
|
152 |
void CPbk2MyCard::NotifyObservers( MPbk2MyCardObserver::TMyCardStatusEvent aEvent ) |
|
153 |
{ |
|
154 |
const TInt count(iObserverArray.Count()); |
|
155 |
for(TInt i = 0 ; i < count ; ++i) |
|
156 |
{ |
|
157 |
iObserverArray[i]->MyCardEvent( aEvent ); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
// -------------------------------------------------------------------------- |
|
162 |
// CPbk2MyCard::MyCardLink |
|
163 |
// -------------------------------------------------------------------------- |
|
164 |
// |
|
165 |
MVPbkContactLink* CPbk2MyCard::MyCardLink() const |
|
166 |
{ |
|
167 |
return iMyCardLink; |
|
168 |
} |
|
169 |
||
170 |
// -------------------------------------------------------------------------- |
|
171 |
// CPbk2MyCard::MyCardBitmap |
|
172 |
// -------------------------------------------------------------------------- |
|
173 |
// |
|
174 |
CFbsBitmap* CPbk2MyCard::MyCardBitmapL() const |
|
175 |
{ |
|
176 |
// if fetched |
|
177 |
if( iThumbBitmap ) |
|
178 |
{ |
|
179 |
// create duplicate bitmap |
|
180 |
CFbsBitmap* dstbitmap = new (ELeave) CFbsBitmap; |
|
181 |
CleanupStack::PushL( dstbitmap ); |
|
182 |
||
183 |
//Get the handle to source bitmap |
|
184 |
const TInt srchandle = iThumbBitmap->Handle(); |
|
185 |
||
186 |
//Duplicate the bitmap handle. Increases the RefCount of bitmap |
|
187 |
//managed but Fbs Server |
|
188 |
User::LeaveIfError( dstbitmap->Duplicate( srchandle ) ); |
|
189 |
CleanupStack::Pop( dstbitmap ); |
|
190 |
return dstbitmap; |
|
191 |
} |
|
192 |
return NULL; |
|
193 |
} |
|
194 |
||
195 |
// -------------------------------------------------------------------------- |
|
196 |
// CPbk2MyCard::MyCardIconId |
|
197 |
// -------------------------------------------------------------------------- |
|
198 |
// |
|
199 |
const TPbk2IconId& CPbk2MyCard::MyCardIconId() const |
|
200 |
{ |
|
201 |
// if my card thumbnail exists |
|
202 |
if( iThumbBitmap ) |
|
203 |
{ |
|
204 |
return iIconId; |
|
205 |
} |
|
206 |
return iEmptyId; |
|
207 |
} |
|
208 |
||
209 |
// -------------------------------------------------------------------------- |
|
210 |
// CPbk2MyCard::MyCardStoreContact |
|
211 |
// -------------------------------------------------------------------------- |
|
212 |
// |
|
213 |
MVPbkStoreContact* CPbk2MyCard::MyCardStoreContact() const |
|
214 |
{ |
|
215 |
return iMyCardStoreContact; |
|
216 |
} |
|
217 |
||
218 |
// -------------------------------------------------------------------------- |
|
219 |
// CPbk2MyCard::ContactManager |
|
220 |
// -------------------------------------------------------------------------- |
|
221 |
// |
|
222 |
CVPbkContactManager& CPbk2MyCard::ContactManager() |
|
223 |
{ |
|
224 |
return *iContactManager; |
|
225 |
} |
|
226 |
||
227 |
// -------------------------------------------------------------------------- |
|
228 |
// CPbk2MyCard::VPbkSingleContactLinkOperationComplete |
|
229 |
// -------------------------------------------------------------------------- |
|
230 |
// |
|
231 |
void CPbk2MyCard::VPbkSingleContactLinkOperationComplete( |
|
232 |
MVPbkContactOperationBase& /*aOperation*/, |
|
233 |
MVPbkContactLink* aLink ) |
|
234 |
{ |
|
235 |
// iOperation still owns the contact link until this method returns. |
|
236 |
// we can't delete iOperation here |
|
237 |
delete iMyCardLink; |
|
238 |
iMyCardLink = aLink; |
|
239 |
iMyCardState = EExisting; |
|
240 |
||
241 |
NotifyObservers( MPbk2MyCardObserver::EStateStatusResolved ); |
|
242 |
||
243 |
// fetch store contact |
|
244 |
TRAP_IGNORE( iRetrieveOperation = |
|
245 |
iContactManager->RetrieveContactL( *iMyCardLink, *this ) ); |
|
246 |
} |
|
247 |
||
248 |
// -------------------------------------------------------------------------- |
|
249 |
// CPbk2MyCard::VPbkSingleContactLinkOperationFailed |
|
250 |
// -------------------------------------------------------------------------- |
|
251 |
// |
|
252 |
void CPbk2MyCard::VPbkSingleContactLinkOperationFailed( |
|
253 |
MVPbkContactOperationBase& /*aOperation*/, |
|
254 |
TInt /*aError*/ ) |
|
255 |
{ |
|
256 |
delete iOperation; |
|
257 |
iOperation = NULL; |
|
258 |
delete iMyCardLink; |
|
259 |
iMyCardLink = NULL; |
|
260 |
iMyCardState = ENonExisting; |
|
261 |
||
262 |
NotifyObservers( MPbk2MyCardObserver::EStateStatusResolved ); |
|
263 |
} |
|
264 |
||
265 |
||
266 |
// --------------------------------------------------------------------------- |
|
267 |
// CPbk2MyCard::VPbkSingleContactOperationComplete |
|
268 |
// --------------------------------------------------------------------------- |
|
269 |
// |
|
270 |
void CPbk2MyCard::VPbkSingleContactOperationComplete( |
|
271 |
MVPbkContactOperationBase& /*aOperation*/, |
|
272 |
MVPbkStoreContact* aContact ) |
|
273 |
{ |
|
274 |
delete iRetrieveOperation; |
|
275 |
iRetrieveOperation = NULL; |
|
276 |
||
277 |
delete iMyCardStoreContact; |
|
278 |
iMyCardStoreContact = aContact; |
|
279 |
||
280 |
// load thumbnail |
|
281 |
TRAPD( error, LoadThumbnailL( *iMyCardStoreContact ) ); |
|
282 |
if( error ) |
|
283 |
{ |
|
284 |
delete iThumbBitmap; |
|
285 |
iThumbBitmap = NULL; |
|
286 |
// inform observers |
|
287 |
NotifyObservers( MPbk2MyCardObserver::EStateThumbnailNotFound ); |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
// --------------------------------------------------------------------------- |
|
292 |
// CPbk2MyCard::VPbkSingleContactOperationFailed |
|
293 |
// --------------------------------------------------------------------------- |
|
294 |
// |
|
295 |
void CPbk2MyCard::VPbkSingleContactOperationFailed( |
|
296 |
MVPbkContactOperationBase& /*aOperation*/, |
|
297 |
TInt /*aError*/ ) |
|
298 |
{ |
|
299 |
// cannot fetch store contact |
|
300 |
delete iRetrieveOperation; |
|
301 |
iRetrieveOperation = NULL; |
|
302 |
} |
|
303 |
||
304 |
// --------------------------------------------------------------------------- |
|
305 |
// CPbk2MyCard::Pbk2ImageGetComplete |
|
306 |
// --------------------------------------------------------------------------- |
|
307 |
// |
|
308 |
void CPbk2MyCard::Pbk2ImageGetComplete( |
|
309 |
MPbk2ImageOperation& /*aOperation*/, |
|
310 |
CFbsBitmap* aBitmap ) |
|
311 |
{ |
|
312 |
delete iImageOperation; |
|
313 |
iImageOperation = NULL; |
|
314 |
//delete existing |
|
315 |
delete iThumbBitmap; |
|
316 |
iThumbBitmap = aBitmap; |
|
317 |
||
318 |
// inform observers |
|
319 |
NotifyObservers( MPbk2MyCardObserver::EStateThumbnailLoaded ); |
|
320 |
} |
|
321 |
||
322 |
// --------------------------------------------------------------------------- |
|
323 |
// CPbk2MyCard::Pbk2ImageGetFailed |
|
324 |
// --------------------------------------------------------------------------- |
|
325 |
// |
|
326 |
void CPbk2MyCard::Pbk2ImageGetFailed( |
|
327 |
MPbk2ImageOperation& /*aOperation*/, |
|
328 |
TInt /*aError*/ ) |
|
329 |
{ |
|
330 |
// image fetching failed |
|
331 |
delete iImageOperation; |
|
332 |
iImageOperation = NULL; |
|
333 |
// inform observers |
|
334 |
NotifyObservers( MPbk2MyCardObserver::EStateThumbnailNotFound ); |
|
335 |
} |
|
336 |
||
337 |
// -------------------------------------------------------------------------- |
|
338 |
// CPbk2MyCard::LoadThumbnailL |
|
339 |
// -------------------------------------------------------------------------- |
|
340 |
// |
|
341 |
void CPbk2MyCard::LoadThumbnailL( MVPbkBaseContact& aContact ) |
|
342 |
{ |
|
343 |
// cancel previous operations |
|
344 |
delete iImageOperation; |
|
345 |
iImageOperation = NULL; |
|
346 |
||
347 |
const MVPbkFieldType* thumbType = iContactManager->FieldTypes().Find( |
|
348 |
R_VPBK_FIELD_TYPE_THUMBNAILPIC ); |
|
349 |
// if there's picture field |
|
350 |
if( thumbType ) |
|
351 |
{ |
|
352 |
if( iImageManager->HasImage( aContact, *thumbType ) ) |
|
353 |
{ |
|
354 |
TSize size( CalculateThumbnailSize() ); |
|
355 |
||
356 |
// Define parameters for thumbnail |
|
357 |
TPbk2ImageManagerParams params; |
|
358 |
// set params |
|
359 |
params.iSize = size; |
|
360 |
params.iFlags = TPbk2ImageManagerParams::EScaleImage | |
|
361 |
TPbk2ImageManagerParams::EUseSpeedOptimizedScaling | |
|
362 |
TPbk2ImageManagerParams::ECropImage ; |
|
363 |
params.iDisplayMode = EColor16MU; |
|
364 |
// contact has image. load it. |
|
365 |
iImageOperation = iImageManager->GetImageAsyncL( |
|
366 |
¶ms, aContact, *thumbType, *this ); |
|
367 |
} |
|
368 |
// no image |
|
369 |
else |
|
370 |
{ |
|
371 |
// reset thumbnail |
|
372 |
delete iThumbBitmap; |
|
373 |
iThumbBitmap = NULL; |
|
374 |
// inform observers |
|
375 |
NotifyObservers( MPbk2MyCardObserver::EStateThumbnailNotFound ); |
|
376 |
} |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
// -------------------------------------------------------------------------- |
|
381 |
// CPbk2MyCard::StoreReady |
|
382 |
// -------------------------------------------------------------------------- |
|
383 |
// |
|
384 |
void CPbk2MyCard::StoreReady( MVPbkContactStore& aContactStore ) |
|
385 |
{ |
|
386 |
delete iOperation; |
|
387 |
iOperation = NULL; |
|
388 |
||
389 |
MVPbkContactStore2* phoneStoreExtension = |
|
390 |
static_cast<MVPbkContactStore2*>(aContactStore.ContactStoreExtension( |
|
391 |
KMVPbkContactStoreExtension2Uid)); |
|
392 |
if ( phoneStoreExtension ) |
|
393 |
{ |
|
394 |
TRAP_IGNORE( iOperation = phoneStoreExtension->OwnContactLinkL(*this) ); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
// -------------------------------------------------------------------------- |
|
399 |
// CPbk2MyCard::StoreUnavailable |
|
400 |
// -------------------------------------------------------------------------- |
|
401 |
// |
|
402 |
void CPbk2MyCard::StoreUnavailable( |
|
403 |
MVPbkContactStore& /*aContactStore*/, |
|
404 |
TInt /*aReason*/ ) |
|
405 |
{ |
|
406 |
} |
|
407 |
||
408 |
// -------------------------------------------------------------------------- |
|
409 |
// CPbk2MyCard::HandleStoreEventL |
|
410 |
// -------------------------------------------------------------------------- |
|
411 |
// |
|
412 |
void CPbk2MyCard::HandleStoreEventL( |
|
413 |
MVPbkContactStore& /*aContactStore*/, |
|
414 |
TVPbkContactStoreEvent aStoreEvent ) |
|
415 |
{ |
|
416 |
// my card is not set yet |
|
417 |
if( !iMyCardLink && |
|
418 |
aStoreEvent.iContactLink && |
|
419 |
( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactAdded || |
|
420 |
aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ) ) |
|
421 |
{ |
|
422 |
// check is new or changed contact own contact |
|
423 |
delete iOperation; |
|
424 |
iOperation = NULL; |
|
425 |
||
426 |
MVPbkContactStore2* phoneStoreExtension = |
|
427 |
static_cast<MVPbkContactStore2*>(iPhoneStore->ContactStoreExtension( |
|
428 |
KMVPbkContactStoreExtension2Uid)); |
|
429 |
if ( phoneStoreExtension ) |
|
430 |
{ |
|
431 |
iOperation = phoneStoreExtension->OwnContactLinkL( *this ); |
|
432 |
} |
|
433 |
} |
|
434 |
else if( iMyCardLink && aStoreEvent.iContactLink ) |
|
435 |
{ |
|
436 |
if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactDeleted ) |
|
437 |
{ |
|
438 |
// Check is MyCard deleted |
|
439 |
if( iMyCardLink->IsSame( *aStoreEvent.iContactLink ) ) |
|
440 |
{ |
|
441 |
delete iMyCardLink; |
|
442 |
iMyCardLink = NULL; |
|
443 |
delete iMyCardStoreContact; |
|
444 |
iMyCardStoreContact = NULL; |
|
445 |
iMyCardState = ENonExisting; |
|
446 |
NotifyObservers( MPbk2MyCardObserver::EStateStatusResolved ); |
|
447 |
||
448 |
// remove thumbnail and inform |
|
449 |
delete iThumbBitmap; |
|
450 |
iThumbBitmap = NULL; |
|
451 |
// inform also that thumbnail is removed |
|
452 |
NotifyObservers( MPbk2MyCardObserver::EStateThumbnailNotFound ); |
|
453 |
} |
|
454 |
} |
|
455 |
// contact has changed, check the thumbnail |
|
456 |
else if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ) |
|
457 |
{ |
|
458 |
// Check is MyCard changed |
|
459 |
if( iMyCardLink->IsSame( *aStoreEvent.iContactLink ) ) |
|
460 |
{ |
|
461 |
// fetch store contact and check thumbnail |
|
462 |
iRetrieveOperation = |
|
463 |
iContactManager->RetrieveContactL( *iMyCardLink, *this ); |
|
464 |
} |
|
465 |
} |
|
466 |
}// else if |
|
467 |
} |
|
468 |
||
469 |
// end of file |