|
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 |
|
62 TInt CMpxTNLoader::LoadThumbnail( TAny* aSelf ) |
|
63 { |
|
64 CMpxTNLoader* self = (CMpxTNLoader*)aSelf; |
|
65 self->LoadNextTN(); |
|
66 return KErrNone; |
|
67 } |
|
68 |
|
69 void CMpxTNLoader::LoadNextTN() |
|
70 { |
|
71 if( iLoading.Count() > 0 ) |
|
72 { |
|
73 TInt index = iLoading[0]->iIndex; |
|
74 if( index >= 0 && iLoading[0]->iId == 0) |
|
75 { |
|
76 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(iLoading[0]->iFileName, KMPXAlbumMimeType); |
|
77 TRAPD(err, iLoading[0]->iId = iTnEngine->GetThumbnailL( *source, NULL, 0 ); ) |
|
78 MPX_DEBUG4( "GetThumbnailL: %d [%d,%d]", err, index, iLoading[0]->iId); |
|
79 CleanupStack::PopAndDestroy(source); |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CMpxTNLoader::ThumbnailPreviewReady() |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CMpxTNLoader::ThumbnailPreviewReady (MThumbnailData& /*aThumbnail*/, |
|
89 TThumbnailRequestId /*aId*/ ) |
|
90 { |
|
91 // Previews not currently used |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CMpxTNLoader::ThumbnailReady() |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CMpxTNLoader::ThumbnailReady (TInt aError, |
|
99 MThumbnailData& aThumbnail, TThumbnailRequestId aId ) |
|
100 { |
|
101 TInt index = FindLoadingById(aId, ETrue); |
|
102 MPX_DEBUG4( "ThumbnailReady: %d [%d,%d]", aError, index, aId ); |
|
103 |
|
104 if( index != KErrNotFound ) |
|
105 { |
|
106 CFbsBitmap* bitmap = (aError == KErrNone ? aThumbnail.DetachBitmap() : NULL); |
|
107 |
|
108 TRAP_IGNORE(iObserver.TNReadyL(aError, bitmap, NULL, index)); |
|
109 |
|
110 if( iLoading.Count() > 0 ) |
|
111 { |
|
112 if(!iAsyncCallBack->IsActive()) |
|
113 iAsyncCallBack->CallBack(); |
|
114 } |
|
115 } |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CMpxTNLoader::CMpxTNLoader() |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CMpxTNLoader::CMpxTNLoader (MMpxTNLoaderObserver& aObserver, TThumbnailSize aSize ) |
|
123 : iObserver( aObserver ), iSize(aSize) |
|
124 { |
|
125 |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CMpxTNLoader::ConstructL() |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CMpxTNLoader::ConstructL () |
|
133 { |
|
134 iTnEngine = CThumbnailManager::NewL( *this ); |
|
135 iTnEngine->SetFlagsL( CThumbnailManager::EDefaultFlags ); |
|
136 iTnEngine->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality ); |
|
137 iTnEngine->SetThumbnailSizeL( iSize ); |
|
138 TCallBack callback(CMpxTNLoader::LoadThumbnail, this); |
|
139 iAsyncCallBack = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard ); |
|
140 iAsyncCallBack->Set(callback); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CMpxTNLoader::FindLoading() |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TInt CMpxTNLoader::FindLoadingById(TThumbnailRequestId aId, TBool aRemove) |
|
148 { |
|
149 TInt index = KErrNotFound; |
|
150 for(TInt i = 0; i < iLoading.Count(); ++i) |
|
151 { |
|
152 if(iLoading[i]->iId == aId) |
|
153 { |
|
154 index = iLoading[i]->iIndex; |
|
155 if(aRemove) |
|
156 { |
|
157 delete iLoading[i]; |
|
158 iLoading.Remove(i); |
|
159 } |
|
160 break; |
|
161 } |
|
162 } |
|
163 return index; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CMpxTNLoader::FindLoading() |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CMpxTNLoader::FindLoadingByIndex(TInt aIndex, TBool aRemove) |
|
171 { |
|
172 TInt index = KErrNotFound; |
|
173 for(TInt i = 0; i < iLoading.Count(); ++i) |
|
174 { |
|
175 if(iLoading[i]->iIndex == aIndex) |
|
176 { |
|
177 index = i; |
|
178 if(aRemove) |
|
179 { |
|
180 delete iLoading[i]; |
|
181 iLoading.Remove(i); |
|
182 } |
|
183 break; |
|
184 } |
|
185 } |
|
186 return index; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CMpxTNLoader::LoadThumbL() |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CMpxTNLoader::LoadThumbL( TInt aIndex, const TDesC& aFileName ) |
|
194 { |
|
195 if( FindLoadingByIndex(aIndex) == KErrNotFound ) |
|
196 { |
|
197 iLoading.Append( new (ELeave) TLoadingTN( 0, aIndex, aFileName ) ); |
|
198 if( !iAsyncCallBack->IsActive() ) |
|
199 iAsyncCallBack->CallBack(); |
|
200 } |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CMpxTNLoader::CancelThumb() |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CMpxTNLoader::CancelThumb( TInt aIndex ) |
|
208 { |
|
209 TInt loadingIndex = FindLoadingByIndex( aIndex ); |
|
210 if(loadingIndex != KErrNotFound) |
|
211 { |
|
212 // Current thumbnail manager has bugs in thumbnail request cancelation. |
|
213 // There is a fix coming in near future but until that we cannot cancel requests |
|
214 // since after that we dont get any thumbnails from server. |
|
215 // if( iLoading[loadingIndex]->iId != 0 ) |
|
216 // { |
|
217 // RDebug::Print(_L("!!CANCEL REQUEST!!")); |
|
218 // iTnEngine->CancelRequest( iLoading[loadingIndex]->iId ); |
|
219 // } |
|
220 delete iLoading[loadingIndex]; |
|
221 iLoading.Remove(loadingIndex); |
|
222 } |
|
223 } |
|
224 |
|
225 void CMpxTNLoader::CancelAll() |
|
226 { |
|
227 iLoading.ResetAndDestroy(); |
|
228 return; |
|
229 // Current thumbnail manager has bugs in thumbnail request cancelation. |
|
230 // There is a fix coming in near future but until that we cannot cancel requests |
|
231 // since after that we dont get any thumbnails from server. |
|
232 while ( iLoading.Count() > 0 ) |
|
233 { |
|
234 if( iLoading[0]->iId != 0 ) |
|
235 iTnEngine->CancelRequest( iLoading[0]->iId ); |
|
236 delete iLoading[0]; |
|
237 iLoading.Remove(0); |
|
238 } |
|
239 } |
|
240 |
|
241 void CMpxTNLoader::SetSizeL( TThumbnailSize aSize ) |
|
242 { |
|
243 iTnEngine->SetThumbnailSizeL( aSize ); |
|
244 } |