|
1 /* |
|
2 * Copyright (c) 2002-2009 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 |
|
19 #include <barsread.h> |
|
20 #include <AknUtils.h> |
|
21 #include <aknlayoutscalable_avkon.cdl.h> |
|
22 |
|
23 #include <centralrepository.h> |
|
24 #include <AvkonInternalCRKeys.h> |
|
25 |
|
26 #include <smiley.rsg> |
|
27 #include <smiley.mbg> |
|
28 |
|
29 #include "AknSmileyModel.h" |
|
30 #include "AknSmileyImage.h" |
|
31 |
|
32 |
|
33 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 // TSmileyIconInfo |
|
35 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
37 TSmileyIconInfo::TSmileyIconInfo() |
|
38 { |
|
39 Reset(); |
|
40 } |
|
41 |
|
42 TSmileyIconInfo::TSmileyIconInfo(const TSmileyIconInfo& aInfo) : |
|
43 iName(aInfo.iName), |
|
44 iId(aInfo.iId), |
|
45 iSkinItemID(aInfo.iSkinItemID), |
|
46 iDefaultThumbnailID(aInfo.iDefaultThumbnailID), |
|
47 iDefaultAnimationID(aInfo.iDefaultAnimationID) |
|
48 { |
|
49 } |
|
50 |
|
51 void TSmileyIconInfo::Reset() |
|
52 { |
|
53 iName.Zero(); |
|
54 iId = 0; |
|
55 iSkinItemID.Set(0, 0); |
|
56 iDefaultThumbnailID = 0; |
|
57 iDefaultAnimationID = 0; |
|
58 } |
|
59 |
|
60 |
|
61 |
|
62 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 // CSmileyIcon |
|
64 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
66 CSmileyIcon* CSmileyIcon::NewL(const TSmileyIconInfo& aInfo, MSmileyIconObserver* aObserver) |
|
67 { |
|
68 CSmileyIcon* self = new (ELeave) CSmileyIcon(aInfo, aObserver); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(); // self; |
|
72 return self; |
|
73 } |
|
74 |
|
75 void CSmileyIcon::ConstructL() |
|
76 { |
|
77 iThumbnailImage = CSmileyImage::NewL(iInfo.iSkinItemID, iInfo.iDefaultThumbnailID, FALSE, this); |
|
78 |
|
79 if(iInfo.iSkinItemID.iMinor==0 && iInfo.iDefaultAnimationID>0) |
|
80 { |
|
81 iAnimationImage = CSmileyImage::NewL(iInfo.iSkinItemID, iInfo.iDefaultAnimationID, TRUE, this); |
|
82 } |
|
83 } |
|
84 |
|
85 CSmileyIcon::CSmileyIcon(const TSmileyIconInfo& aInfo, MSmileyIconObserver* aObserver) : |
|
86 iInfo(aInfo), iSmileyIconObserver(aObserver) |
|
87 { |
|
88 } |
|
89 |
|
90 CSmileyIcon::~CSmileyIcon() |
|
91 { |
|
92 delete iThumbnailImage; |
|
93 delete iAnimationImage; |
|
94 } |
|
95 |
|
96 TBool CSmileyIcon::ReadyToDraw() const |
|
97 { |
|
98 TBool thumbnailCanDraw = iThumbnailImage->ReadyToDraw(); |
|
99 TBool animationCanDraw = iAnimationImage ? iAnimationImage->ReadyToDraw() : FALSE; |
|
100 |
|
101 return (thumbnailCanDraw || animationCanDraw); |
|
102 } |
|
103 |
|
104 const CFbsBitmap* CSmileyIcon::Image() const |
|
105 { |
|
106 if(ShouldShowAnimation()) |
|
107 { |
|
108 return iAnimationImage->Image(); |
|
109 } |
|
110 else |
|
111 { |
|
112 return iThumbnailImage->Image(); |
|
113 } |
|
114 } |
|
115 |
|
116 const CFbsBitmap* CSmileyIcon::Mask() const |
|
117 { |
|
118 if(ShouldShowAnimation()) |
|
119 { |
|
120 return iAnimationImage->Mask(); |
|
121 } |
|
122 else |
|
123 { |
|
124 return iThumbnailImage->Mask(); |
|
125 } |
|
126 } |
|
127 |
|
128 void CSmileyIcon::LoadThumbnailL() |
|
129 { |
|
130 iThumbnailImage->LoadL(); |
|
131 } |
|
132 |
|
133 TBool CSmileyIcon::ThumbnailReady() const |
|
134 { |
|
135 return iThumbnailImage->ReadyToDraw(); |
|
136 } |
|
137 |
|
138 void CSmileyIcon::PlayAnimationL(TInt aRepeat, TInt aDelay) |
|
139 { |
|
140 if(iAnimationImage) |
|
141 { |
|
142 iAnimationImage->LoadL(aRepeat, aDelay); |
|
143 } |
|
144 } |
|
145 |
|
146 void CSmileyIcon::StopAnimation() |
|
147 { |
|
148 if(iAnimationImage) |
|
149 { |
|
150 iAnimationImage->Release(); |
|
151 } |
|
152 } |
|
153 |
|
154 void CSmileyIcon::SetSize(const TSize& aSize) |
|
155 { |
|
156 iThumbnailImage->SetSize(aSize); |
|
157 |
|
158 if(iAnimationImage) |
|
159 { |
|
160 iAnimationImage->SetSize(aSize); |
|
161 } |
|
162 } |
|
163 |
|
164 const TSize& CSmileyIcon::Size() const |
|
165 { |
|
166 return iThumbnailImage->Size(); |
|
167 } |
|
168 |
|
169 void CSmileyIcon::BitmapChanged(CSmileyImage* aSmileyImage, CFbsBitmap* /*aBitmap*/) |
|
170 { |
|
171 if(aSmileyImage == iThumbnailImage) |
|
172 { |
|
173 if(iSmileyIconObserver) iSmileyIconObserver->ThumbnailLoaded(this); |
|
174 } |
|
175 else |
|
176 { |
|
177 if(iSmileyIconObserver) iSmileyIconObserver->AnimationChanged(this); |
|
178 } |
|
179 } |
|
180 |
|
181 TBool CSmileyIcon::ShouldShowAnimation() const |
|
182 { |
|
183 return (iAnimationImage && iAnimationImage->ReadyToDraw()); |
|
184 } |
|
185 |
|
186 |
|
187 |
|
188 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
189 // CSmileyTnumbnailAsynLoader |
|
190 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
192 CSmileyTnumbnailAsynLoader::CSmileyTnumbnailAsynLoader() |
|
193 { |
|
194 |
|
195 } |
|
196 |
|
197 CSmileyTnumbnailAsynLoader::~CSmileyTnumbnailAsynLoader() |
|
198 { |
|
199 iTaskArray.Close(); |
|
200 } |
|
201 |
|
202 void CSmileyTnumbnailAsynLoader::AddTaskL(CSmileyIcon* aSmileyIcon) |
|
203 { |
|
204 if(aSmileyIcon) |
|
205 { |
|
206 iTaskArray.Append(aSmileyIcon); |
|
207 if(!iIsLoading) |
|
208 { |
|
209 DoNextTaskL(); |
|
210 } |
|
211 } |
|
212 } |
|
213 |
|
214 void CSmileyTnumbnailAsynLoader::DiscardAll() |
|
215 { |
|
216 iTaskArray.Reset(); |
|
217 } |
|
218 |
|
219 TInt CSmileyTnumbnailAsynLoader::TaskCount() const |
|
220 { |
|
221 return iTaskArray.Count(); |
|
222 } |
|
223 |
|
224 void CSmileyTnumbnailAsynLoader::DoNextTaskL() |
|
225 { |
|
226 TInt count = TaskCount(); |
|
227 if(count > 0) |
|
228 { |
|
229 CSmileyIcon* icon = iTaskArray[0]; |
|
230 iTaskArray.Remove(0); |
|
231 |
|
232 if(icon->ThumbnailReady()) |
|
233 { |
|
234 DoNextTaskL(); |
|
235 } |
|
236 else |
|
237 { |
|
238 icon->LoadThumbnailL(); |
|
239 iIsLoading = TRUE; |
|
240 } |
|
241 } |
|
242 else |
|
243 { |
|
244 iIsLoading = FALSE; |
|
245 } |
|
246 } |
|
247 |
|
248 |
|
249 |
|
250 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 // CSmileyModel |
|
252 /////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
254 CSmileyModel::CSmileyModel(MSmileyIconObserver* aObserver) : iSmileyIconObserver(aObserver) |
|
255 { |
|
256 } |
|
257 |
|
258 CSmileyModel::~CSmileyModel() |
|
259 { |
|
260 ReleaseResource(); |
|
261 |
|
262 iSmileyIconArray.Close(); |
|
263 } |
|
264 |
|
265 void CSmileyModel::LoadResourceL() |
|
266 { |
|
267 if(Count() > 0) return; |
|
268 |
|
269 // append sct & smiley switch icon |
|
270 { |
|
271 TSmileyIconInfo info; |
|
272 info.iSkinItemID = KAknsIIDQgnIndiSwitchSmiley2; |
|
273 info.iDefaultThumbnailID = EMbmSmileyQgn_indi_switch_smiley2; |
|
274 iSmileyIconArray.Append(CSmileyIcon::NewL(info, this)); |
|
275 |
|
276 info.iSkinItemID = KAknsIIDQgnIndiSwitchSct2; |
|
277 info.iDefaultThumbnailID = EMbmSmileyQgn_indi_switch_sct2; |
|
278 iSmileyIconArray.Append(CSmileyIcon::NewL(info, this)); |
|
279 } |
|
280 |
|
281 // append image resourece |
|
282 TResourceReader reader; |
|
283 TFileName smileyRscName; |
|
284 SmileyUtils::GetCustomizableResPath(smileyRscName, KSmileyRsc); |
|
285 TInt offset = CCoeEnv::Static()->AddResourceFileL(smileyRscName); |
|
286 CCoeEnv::Static()->CreateResourceReaderLC(reader, R_SMILEY_ICONS_INFO); |
|
287 |
|
288 TInt count(reader.ReadInt16()); |
|
289 for(TInt id(1); id<=count; id++) |
|
290 { |
|
291 TSmileyIconInfo info; |
|
292 |
|
293 info.iId = id; // id |
|
294 |
|
295 TBool isAnimation = (reader.ReadInt16() == 1); |
|
296 TInt16 code = reader.ReadInt16(); |
|
297 TInt bmpId1 = reader.ReadInt32(); |
|
298 TInt maskId1 = reader.ReadInt32(); |
|
299 TInt bmpId2 = reader.ReadInt32(); |
|
300 TInt maskId2 = reader.ReadInt32(); |
|
301 |
|
302 if(bmpId2 > 0) |
|
303 { |
|
304 info.iDefaultThumbnailID = bmpId2; |
|
305 info.iDefaultAnimationID = bmpId1; |
|
306 } |
|
307 else |
|
308 { |
|
309 info.iDefaultThumbnailID = bmpId1; |
|
310 info.iDefaultAnimationID = 0; |
|
311 } |
|
312 |
|
313 TBuf<64> smileyName = reader.ReadTPtrC(); // strings |
|
314 TInt pos = smileyName.Find(_L(" ")); |
|
315 if(pos > 0) smileyName.SetLength(pos); |
|
316 info.iName = smileyName; |
|
317 |
|
318 iSmileyIconArray.Append(CSmileyIcon::NewL(info, this)); |
|
319 } |
|
320 |
|
321 CCoeEnv::Static()->DeleteResourceFile(offset); |
|
322 CleanupStack::PopAndDestroy(); // reader |
|
323 |
|
324 } |
|
325 |
|
326 void CSmileyModel::ReleaseResource() |
|
327 { |
|
328 // reset array |
|
329 for(TInt i(0); i<Count(); i++) |
|
330 { |
|
331 delete iSmileyIconArray[i]; |
|
332 iSmileyIconArray[i] = NULL; |
|
333 } |
|
334 iSmileyIconArray.Reset(); |
|
335 |
|
336 // reset task loader |
|
337 iSmileyThumbnailLoader.DiscardAll(); |
|
338 } |
|
339 |
|
340 void CSmileyModel::LoadThumbnailAsyn(TInt aIndex) |
|
341 { |
|
342 TRAP_IGNORE(iSmileyThumbnailLoader.AddTaskL((*this)[aIndex])); |
|
343 } |
|
344 |
|
345 void CSmileyModel::SetSize(const TSize& aSize) |
|
346 { |
|
347 for(TInt i(0); i<Count(); i++) |
|
348 { |
|
349 iSmileyIconArray[i]->SetSize(aSize); |
|
350 } |
|
351 } |
|
352 |
|
353 CSmileyIcon* CSmileyModel::operator[](TInt aIndex) const |
|
354 { |
|
355 if(aIndex>=0 && aIndex<Count()) |
|
356 { |
|
357 return iSmileyIconArray[aIndex]; |
|
358 } |
|
359 else |
|
360 { |
|
361 return NULL; |
|
362 } |
|
363 } |
|
364 |
|
365 TInt CSmileyModel::Count() const |
|
366 { |
|
367 return iSmileyIconArray.Count(); |
|
368 } |
|
369 |
|
370 void CSmileyModel::ThumbnailLoaded(CSmileyIcon* aSmileyIcon) |
|
371 { |
|
372 TRAP_IGNORE(iSmileyThumbnailLoader.DoNextTaskL()); |
|
373 |
|
374 if(iSmileyIconObserver) iSmileyIconObserver->ThumbnailLoaded(aSmileyIcon); |
|
375 } |
|
376 |
|
377 void CSmileyModel::AnimationChanged(CSmileyIcon* aSmileyIcon) |
|
378 { |
|
379 if(iSmileyIconObserver) iSmileyIconObserver->AnimationChanged(aSmileyIcon); |
|
380 } |
|
381 |
|
382 |
|
383 // end of file |
|
384 |