|
1 /* |
|
2 * Copyright (c) 2006 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 loader implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <thumbnaildata.h> |
|
20 #include <AknIconUtils.h> |
|
21 #include "mpxcollectionviewhgtnloader.h" |
|
22 #include "mpxlog.h" |
|
23 |
|
24 _LIT( KMPXAlbumMimeType, "audio/mpeg3" ); |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CODEScrollerTNLoader::NewL() |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CMpxTNLoader* CMpxTNLoader::NewL ( |
|
32 MMpxTNLoaderObserver& aObserver, TThumbnailSize aSize ) |
|
33 { |
|
34 CMpxTNLoader* self = new (ELeave) CMpxTNLoader(aObserver, aSize ); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CMpxTNLoader:~CMpxTNLoader() |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CMpxTNLoader::~CMpxTNLoader ( ) |
|
46 { |
|
47 // cancel outstanding requests |
|
48 if(iTnEngine) |
|
49 { |
|
50 // CancelAll(); |
|
51 } |
|
52 |
|
53 iLoading.ResetAndDestroy(); |
|
54 delete iTnEngine; |
|
55 |
|
56 if( iAsyncCallBack ) |
|
57 iAsyncCallBack->Cancel(); |
|
58 |
|
59 delete iAsyncCallBack; |
|
60 |
|
61 if( iPauseTimer ) |
|
62 iPauseTimer->Cancel(); |
|
63 |
|
64 delete iPauseTimer; |
|
65 } |
|
66 |
|
67 TInt CMpxTNLoader::LoadThumbnail( TAny* aSelf ) |
|
68 { |
|
69 CMpxTNLoader* self = (CMpxTNLoader*)aSelf; |
|
70 MPX_TRAPD( err, self->LoadNextTNL() ); |
|
71 return err; |
|
72 } |
|
73 |
|
74 void CMpxTNLoader::LoadNextTNL() |
|
75 { |
|
76 if( iPaused ) |
|
77 return; |
|
78 |
|
79 if( iLoading.Count() > 0 ) |
|
80 { |
|
81 TInt index = iLoading[0]->iIndex; |
|
82 if( index >= 0 && iLoading[0]->iId == 0) |
|
83 { |
|
84 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(iLoading[0]->iFileName, KMPXAlbumMimeType); |
|
85 TRAPD(err, iLoading[0]->iId = iTnEngine->GetThumbnailL( *source, NULL, 1 ); ) |
|
86 MPX_DEBUG4( "GetThumbnailL: %d [%d,%d]", err, index, iLoading[0]->iId); |
|
87 CleanupStack::PopAndDestroy(source); |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CMpxTNLoader::ThumbnailPreviewReady() |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 void CMpxTNLoader::ThumbnailPreviewReady (MThumbnailData& /*aThumbnail*/, |
|
97 TThumbnailRequestId /*aId*/ ) |
|
98 { |
|
99 // Previews not currently used |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CMpxTNLoader::ThumbnailReady() |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CMpxTNLoader::ThumbnailReady (TInt aError, |
|
107 MThumbnailData& aThumbnail, TThumbnailRequestId aId ) |
|
108 { |
|
109 TInt index = FindLoadingById(aId, ETrue); |
|
110 MPX_DEBUG4( "ThumbnailReady: %d [%d,%d]", aError, index, aId ); |
|
111 |
|
112 if( index != KErrNotFound ) |
|
113 { |
|
114 CFbsBitmap* bitmap = (aError == KErrNone ? aThumbnail.DetachBitmap() : NULL); |
|
115 |
|
116 TRAP_IGNORE(iObserver.TNReadyL(aError, bitmap, NULL, index)); |
|
117 |
|
118 if( iLoading.Count() > 0 ) |
|
119 { |
|
120 if(!iAsyncCallBack->IsActive()) |
|
121 iAsyncCallBack->CallBack(); |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CMpxTNLoader::CMpxTNLoader() |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 CMpxTNLoader::CMpxTNLoader (MMpxTNLoaderObserver& aObserver, TThumbnailSize aSize ) |
|
131 : iObserver( aObserver ), iSize(aSize) |
|
132 { |
|
133 |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CMpxTNLoader::ConstructL() |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CMpxTNLoader::ConstructL () |
|
141 { |
|
142 iTnEngine = CThumbnailManager::NewL( *this ); |
|
143 iTnEngine->SetFlagsL( CThumbnailManager::EDefaultFlags ); |
|
144 iTnEngine->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality ); |
|
145 iTnEngine->SetThumbnailSizeL( iSize ); |
|
146 TCallBack callback(CMpxTNLoader::LoadThumbnail, this); |
|
147 iAsyncCallBack = new (ELeave) CAsyncCallBack( CActive::EPriorityHigh ); |
|
148 iAsyncCallBack->Set(callback); |
|
149 iPauseTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CMpxTNLoader::FindLoading() |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TInt CMpxTNLoader::FindLoadingById(TThumbnailRequestId aId, TBool aRemove) |
|
157 { |
|
158 TInt index = KErrNotFound; |
|
159 for(TInt i = 0; i < iLoading.Count(); ++i) |
|
160 { |
|
161 if(iLoading[i]->iId == aId) |
|
162 { |
|
163 index = iLoading[i]->iIndex; |
|
164 if(aRemove) |
|
165 { |
|
166 delete iLoading[i]; |
|
167 iLoading.Remove(i); |
|
168 } |
|
169 break; |
|
170 } |
|
171 } |
|
172 return index; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CMpxTNLoader::FindLoading() |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 TInt CMpxTNLoader::FindLoadingByIndex(TInt aIndex, TBool aRemove) |
|
180 { |
|
181 TInt index = KErrNotFound; |
|
182 for(TInt i = 0; i < iLoading.Count(); ++i) |
|
183 { |
|
184 if(iLoading[i]->iIndex == aIndex) |
|
185 { |
|
186 index = i; |
|
187 if(aRemove) |
|
188 { |
|
189 delete iLoading[i]; |
|
190 iLoading.Remove(i); |
|
191 } |
|
192 break; |
|
193 } |
|
194 } |
|
195 return index; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CMpxTNLoader::LoadThumbL() |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CMpxTNLoader::LoadThumbL( TInt aIndex, const TDesC& aFileName ) |
|
203 { |
|
204 if( FindLoadingByIndex(aIndex) == KErrNotFound ) |
|
205 { |
|
206 iLoading.Append( new (ELeave) TLoadingTN( 0, aIndex, aFileName ) ); |
|
207 if( !iAsyncCallBack->IsActive() ) |
|
208 iAsyncCallBack->CallBack(); |
|
209 } |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CMpxTNLoader::CancelThumb() |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CMpxTNLoader::CancelThumb( TInt aIndex ) |
|
217 { |
|
218 TInt loadingIndex = FindLoadingByIndex( aIndex ); |
|
219 if(loadingIndex != KErrNotFound) |
|
220 { |
|
221 if( iLoading[loadingIndex]->iId != 0 ) |
|
222 { |
|
223 MPX_DEBUG2( "Cancel Thumb Request: %d", aIndex ); |
|
224 iTnEngine->CancelRequest( iLoading[loadingIndex]->iId ); |
|
225 } |
|
226 delete iLoading[loadingIndex]; |
|
227 iLoading.Remove(loadingIndex); |
|
228 } |
|
229 } |
|
230 |
|
231 void CMpxTNLoader::CancelAll() |
|
232 { |
|
233 while ( iLoading.Count() > 0 ) |
|
234 { |
|
235 if( iLoading[0]->iId != 0 ) |
|
236 iTnEngine->CancelRequest( iLoading[0]->iId ); |
|
237 delete iLoading[0]; |
|
238 iLoading.Remove(0); |
|
239 } |
|
240 } |
|
241 |
|
242 void CMpxTNLoader::SetSizeL( TThumbnailSize aSize ) |
|
243 { |
|
244 iTnEngine->SetThumbnailSizeL( aSize ); |
|
245 } |
|
246 |
|
247 void CMpxTNLoader::Pause(TTimeIntervalMicroSeconds32 aDelay) |
|
248 { |
|
249 iAsyncCallBack->Cancel(); |
|
250 iPaused = ETrue; |
|
251 iPauseTimer->Cancel(); |
|
252 iPauseTimer->Start( |
|
253 aDelay, aDelay, |
|
254 TCallBack(ResumeCallback, this)); |
|
255 } |
|
256 |
|
257 void CMpxTNLoader::Resume() |
|
258 { |
|
259 iPaused = EFalse; |
|
260 if( !iAsyncCallBack->IsActive() ) |
|
261 iAsyncCallBack->CallBack(); |
|
262 iPauseTimer->Cancel(); |
|
263 } |
|
264 |
|
265 TInt CMpxTNLoader::ResumeCallback(TAny* aPtr) |
|
266 { |
|
267 CMpxTNLoader* self = (CMpxTNLoader*)aPtr; |
|
268 if( self ) |
|
269 { |
|
270 self->Resume(); |
|
271 } |
|
272 return KErrNone; |
|
273 } |