|
1 /* |
|
2 * Copyright (c) 2002 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: Thumbnail loading implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPhCntThumbnailLoaderImpl.h" |
|
21 #include "MPhoneCntPbkOwner.h" |
|
22 #include "MPhCntThumbnailLoaderObserver.h" |
|
23 #include "cphcntcontactid.h" |
|
24 #include "cphcntpbkcontactid.h" |
|
25 #include "cphcntpbkthumbnailloader.h" |
|
26 |
|
27 #include <CPbkContactItem.h> |
|
28 #include <CPbkContactEngine.h> |
|
29 #include <CPbkThumbnailManager.h> |
|
30 #include <fbs.h> |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // Granularity of thumbnail array. |
|
35 const TInt KPhoneThumbnailArrayGranularity = 5; |
|
36 |
|
37 // Maximum amount of thumbnails. |
|
38 const TInt KPhoneThumbnailMax = 20; |
|
39 |
|
40 // Panic literal for thumbnail related panics. |
|
41 _LIT( KPhCntThumbnailLoaderPanic, "PhCntThumb" ); |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CPhCntThumbnailLoaderImpl::NewL |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CPhCntThumbnailLoaderImpl* CPhCntThumbnailLoaderImpl::NewL( |
|
51 MPhCntThumbnailLoaderObserver& aObserver, |
|
52 MPhoneCntPbkOwner& aPbkOwner, |
|
53 MPhCntThumbnailLoader& aLoader ) |
|
54 { |
|
55 CPhCntThumbnailLoaderImpl* self = |
|
56 new ( ELeave ) CPhCntThumbnailLoaderImpl( |
|
57 aObserver, |
|
58 aPbkOwner, |
|
59 aLoader ); |
|
60 |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( aPbkOwner ); |
|
63 CleanupStack::Pop(); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPhCntThumbnailLoaderImpl::~CPhCntThumbnailLoaderImpl |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CPhCntThumbnailLoaderImpl::~CPhCntThumbnailLoaderImpl() |
|
73 { |
|
74 delete iBitmap; |
|
75 ClearThumbnailArray(); |
|
76 iArray.Close(); |
|
77 delete iLoader; |
|
78 delete iBridge; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CPhCntThumbnailLoaderImpl::Load |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 TInt CPhCntThumbnailLoaderImpl::Load( |
|
86 TThumbnailId& aId, |
|
87 const CPhCntContactId& aContactId ) |
|
88 { |
|
89 // If condition doesn't hold, then definitely something is badly |
|
90 // wrong. |
|
91 if ( iArray.Count() < KPhoneThumbnailMax ) |
|
92 { |
|
93 TRAPD( err, AttemptLoadL( aId, aContactId ) ); |
|
94 |
|
95 if ( err != KErrNone ) |
|
96 { |
|
97 aId = KPhCntThumbnailNullId; |
|
98 } |
|
99 |
|
100 return err; |
|
101 } |
|
102 else |
|
103 { |
|
104 aId = KPhCntThumbnailNullId; |
|
105 return KErrNotFound; |
|
106 } |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CPhCntThumbnailLoaderImpl::Cancel |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CPhCntThumbnailLoaderImpl::Cancel( |
|
114 TThumbnailId aId ) |
|
115 { |
|
116 TInt index = FindById( aId ); |
|
117 |
|
118 // If not found, then we can ignore the call. |
|
119 if ( index == KErrNotFound ) |
|
120 { |
|
121 return; |
|
122 } |
|
123 |
|
124 // Remove thumbnail loading information from array. |
|
125 RemoveThumbnailArrayEntry( index ); |
|
126 |
|
127 // If we are currently loading this, then cancel loading. |
|
128 if ( iCurrent != KPhCntThumbnailNullId && aId == iCurrent ) |
|
129 { |
|
130 CancelLoad(); |
|
131 } |
|
132 |
|
133 if ( iCurrent == KPhCntThumbnailNullId && iArray.Count() ) |
|
134 { |
|
135 Start( ELoadFromContact ); |
|
136 } |
|
137 } |
|
138 |
|
139 void CPhCntThumbnailLoaderImpl::LoadingCompleted( |
|
140 CFbsBitmap* aBitmap, |
|
141 TInt aResult ) |
|
142 { |
|
143 if( aResult == KErrNone ) |
|
144 { |
|
145 if ( iCurrent != KPhCntThumbnailNullId ) |
|
146 { |
|
147 |
|
148 iBitmap = aBitmap; |
|
149 Start( EProcessResult ); |
|
150 } |
|
151 else |
|
152 { |
|
153 delete aBitmap; |
|
154 } |
|
155 } |
|
156 else |
|
157 { |
|
158 if ( iCurrent != KPhCntThumbnailNullId ) |
|
159 { |
|
160 TThumbnailId old = iCurrent; |
|
161 |
|
162 Cancel( old ); |
|
163 Notify( old, aResult, NULL ); |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CPhCntThumbnailLoaderImpl::CPhCntThumbnailLoaderImpl |
|
170 // C++ constructor can NOT contain any code, that |
|
171 // might leave. |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 CPhCntThumbnailLoaderImpl::CPhCntThumbnailLoaderImpl( |
|
175 MPhCntThumbnailLoaderObserver& aObserver, |
|
176 MPhoneCntPbkOwner& /*aPbkOwner*/, |
|
177 MPhCntThumbnailLoader& aLoader ) |
|
178 : iObserver( aObserver ), |
|
179 iArray( KPhoneThumbnailArrayGranularity ), |
|
180 iCurrent( KPhCntThumbnailNullId ), |
|
181 iLoader( &aLoader ) |
|
182 { |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPhCntThumbnailLoaderImpl::ConstructL |
|
187 // Symbian 2nd phase constructor can leave. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CPhCntThumbnailLoaderImpl::ConstructL( |
|
191 MPhoneCntPbkOwner& /*aPbkOwner*/ ) |
|
192 { |
|
193 iBridge = |
|
194 CIdle::NewL( |
|
195 CActive::EPriorityStandard ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CPhCntThumbnailLoaderImpl::AttemptLoadL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CPhCntThumbnailLoaderImpl::AttemptLoadL( |
|
203 TThumbnailId aId, |
|
204 const CPhCntContactId& aContactId ) |
|
205 { |
|
206 // Create new thumbnail information. |
|
207 TThumbnailInfo info; |
|
208 info.iId = aId; |
|
209 info.iContactId = aContactId.CloneL(); |
|
210 User::LeaveIfError( iArray.Append( info ) ); |
|
211 |
|
212 // If there were no items, then we can start loading the first image. |
|
213 if ( iCurrent == KPhCntThumbnailNullId ) |
|
214 { |
|
215 Start( ELoadFromContact ); |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CPhCntThumbnailLoaderImpl::StartLoadL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CPhCntThumbnailLoaderImpl::StartLoadL() |
|
224 { |
|
225 if ( !iArray.Count() ) |
|
226 { |
|
227 return; |
|
228 } |
|
229 |
|
230 TThumbnailInfo& info = iArray[ 0 ]; // first |
|
231 iCurrent = info.iId; |
|
232 |
|
233 // Clear pbk |
|
234 ClearPbk( ETrue ); |
|
235 |
|
236 iLoader->LoadL( *info.iContactId, *this ); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CPhCntThumbnailLoaderImpl::CancelLoad |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CPhCntThumbnailLoaderImpl::CancelLoad() |
|
244 { |
|
245 iCurrent = KPhCntThumbnailNullId; |
|
246 |
|
247 delete iBitmap; |
|
248 iBitmap = NULL; |
|
249 |
|
250 ClearPbk( iArray.Count() ); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CPhCntThumbnailLoaderImpl::ProcessResultL |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CPhCntThumbnailLoaderImpl::ProcessResultL() |
|
258 { |
|
259 if ( iCurrent == KPhCntThumbnailNullId ) |
|
260 { |
|
261 return; |
|
262 } |
|
263 |
|
264 if ( !iBitmap ) |
|
265 { |
|
266 User::Leave( KErrNotFound ); |
|
267 } |
|
268 else |
|
269 { |
|
270 CFbsBitmap* bitmap = iBitmap; |
|
271 iBitmap = NULL; |
|
272 TThumbnailId old = iCurrent; |
|
273 Cancel( iCurrent ); |
|
274 Notify( old, KErrNone, bitmap ); |
|
275 } |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CPhCntThumbnailLoaderImpl::HandleStartL |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CPhCntThumbnailLoaderImpl::HandleStartL() |
|
283 { |
|
284 switch ( iState ) |
|
285 { |
|
286 case ELoadFromContact: |
|
287 StartLoadL(); |
|
288 break; |
|
289 |
|
290 case EProcessResult: |
|
291 ProcessResultL(); |
|
292 break; |
|
293 |
|
294 default: |
|
295 Panic( EPanicInvalidState ); |
|
296 break; |
|
297 } |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CPhCntThumbnailLoaderImpl::HandleStart |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 void CPhCntThumbnailLoaderImpl::HandleStart() |
|
305 { |
|
306 TRAPD( err, HandleStartL() ); |
|
307 |
|
308 if ( err != KErrNone && iCurrent != KPhCntThumbnailNullId ) |
|
309 { |
|
310 TThumbnailId old = iCurrent; |
|
311 Cancel( iCurrent ); |
|
312 Notify( old, err, NULL ); |
|
313 } |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CPhCntThumbnailLoaderImpl::Start |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 void CPhCntThumbnailLoaderImpl::Start( TState aState ) |
|
321 { |
|
322 iState = aState; |
|
323 iBridge->Cancel(); |
|
324 iBridge->Start( TCallBack( DoStart, this ) ); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CPhCntThumbnailLoaderImpl::DoStart |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CPhCntThumbnailLoaderImpl::DoStart( TAny* aAny ) |
|
332 { |
|
333 CPhCntThumbnailLoaderImpl* loader = |
|
334 static_cast< CPhCntThumbnailLoaderImpl* >( aAny ); |
|
335 |
|
336 loader->HandleStart(); |
|
337 |
|
338 return KErrNone; |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CPhCntThumbnailLoaderImpl::Notify |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CPhCntThumbnailLoaderImpl::Notify( |
|
346 TThumbnailId aId, |
|
347 TInt aResult, |
|
348 CFbsBitmap* aBitmap ) |
|
349 { |
|
350 iObserver.MpctloThumbnailLoaded( aId, aResult, aBitmap ); |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CPhCntThumbnailLoaderImpl::ClearPbk |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CPhCntThumbnailLoaderImpl::ClearPbk( TBool aMore ) |
|
358 { |
|
359 |
|
360 iLoader->Cancel(); |
|
361 |
|
362 if ( !aMore ) |
|
363 { |
|
364 iLoader->Release(); |
|
365 } |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CPhCntThumbnailLoaderImpl::FindById |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 TInt CPhCntThumbnailLoaderImpl::FindById( TThumbnailId aId ) |
|
373 { |
|
374 TThumbnailInfo info; |
|
375 info.iId = aId; |
|
376 // info.iContactId doesn't matter. |
|
377 |
|
378 return |
|
379 iArray.Find( |
|
380 info, |
|
381 TIdentityRelation<TThumbnailInfo>( CompareIds ) ); |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CPhCntThumbnailLoaderImpl::CompareIds |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 TBool CPhCntThumbnailLoaderImpl::CompareIds( |
|
389 const TThumbnailInfo& aFirst, |
|
390 const TThumbnailInfo& aSecond ) |
|
391 { |
|
392 return aFirst.iId == aSecond.iId; |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CPhCntThumbnailLoaderImpl::Panic |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 void CPhCntThumbnailLoaderImpl::Panic( |
|
400 TPanicReason aReason ) |
|
401 { |
|
402 User::Panic( KPhCntThumbnailLoaderPanic, aReason ); |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CPhCntThumbnailLoaderImpl::ClearThumbnailArray |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 void CPhCntThumbnailLoaderImpl::ClearThumbnailArray() |
|
410 { |
|
411 const TInt count( iArray.Count() ); |
|
412 for( TInt i = 0; i < count; i++ ) |
|
413 { |
|
414 RemoveThumbnailArrayEntry( i ); |
|
415 } |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // CPhCntThumbnailLoaderImpl::ClearThumbnailArrayEntry |
|
420 // ----------------------------------------------------------------------------- |
|
421 // |
|
422 void CPhCntThumbnailLoaderImpl::RemoveThumbnailArrayEntry( TInt aIndex ) |
|
423 { |
|
424 TThumbnailInfo info = iArray[aIndex]; |
|
425 delete info.iContactId; |
|
426 iArray.Remove( aIndex ); |
|
427 } |
|
428 |
|
429 // End of File |