1 /* |
|
2 * Copyright (c) 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 * CWmWidgetData implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <fbs.h> |
|
22 #include <bautils.h> |
|
23 #include <s32file.h> |
|
24 #include <hscontentinfo.h> |
|
25 #include <WidgetRegistryClient.h> // widgetreqistry |
|
26 #include "wmwidgetdata.h" |
|
27 #include "wmwidgetdataobserver.h" |
|
28 #include "wmpersistentwidgetorder.h" |
|
29 #include "wmcommon.h" |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CWmWidgetData::NewL |
|
33 // --------------------------------------------------------- |
|
34 // |
|
35 CWmWidgetData* CWmWidgetData::NewL( |
|
36 CHsContentInfo& aHsContentInfo, |
|
37 RWidgetRegistryClientSession* aRegistryClientSession ) |
|
38 { |
|
39 CWmWidgetData* self = CWmWidgetData::NewLC( |
|
40 aHsContentInfo, aRegistryClientSession ); |
|
41 CleanupStack::Pop(); // self; |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CWmWidgetData::NewLC |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 CWmWidgetData* CWmWidgetData::NewLC( |
|
50 CHsContentInfo& aHsContentInfo, |
|
51 RWidgetRegistryClientSession* aRegistryClientSession ) |
|
52 { |
|
53 CWmWidgetData* self = new ( ELeave ) CWmWidgetData(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL( aHsContentInfo, aRegistryClientSession ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CWmWidgetData::CWmWidgetData |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 CWmWidgetData::CWmWidgetData() |
|
64 { |
|
65 iIdle = NULL; |
|
66 iLogoImage = NULL; |
|
67 iLogoImageMask = NULL; |
|
68 iHsContentInfo = NULL; |
|
69 iWidgetType = CWmWidgetData::EUnknown; |
|
70 iInstallAnimationIndex = KErrNotFound; |
|
71 iPublisherUid = KNullUid; |
|
72 iLogoSize = TSize( 0, 0 ); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CWmWidgetData::ConstructL |
|
77 // --------------------------------------------------------- |
|
78 // |
|
79 void CWmWidgetData::ConstructL( |
|
80 CHsContentInfo& aHsContentInfo, |
|
81 RWidgetRegistryClientSession* aRegistryClientSession ) |
|
82 { |
|
83 // analyse the widget type |
|
84 if ( aHsContentInfo.Type() == KContentTemplate ) |
|
85 { |
|
86 iWidgetType = CWmWidgetData::ECps; // wrt widgets included in this gategory |
|
87 } |
|
88 else if ( aHsContentInfo.Type() == KContentWidget ) |
|
89 { |
|
90 iWidgetType = CWmWidgetData::ENative; |
|
91 } |
|
92 |
|
93 // duplicate the content info locally |
|
94 iHsContentInfo = aHsContentInfo.CloneL(); |
|
95 |
|
96 iImageConverter = CWmImageConverter::NewL( this ); |
|
97 |
|
98 FetchPublisherUidL( aRegistryClientSession ); |
|
99 |
|
100 // start decoding the icon |
|
101 iIdle = CIdle::NewL( CActive::EPriorityLow ); |
|
102 iIdle->Start( TCallBack( HandleAsyncIconString, this ) ); |
|
103 } |
|
104 |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CWmWidgetData::~CWmWidgetData |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 CWmWidgetData::~CWmWidgetData() |
|
111 { |
|
112 if ( iIdle && iIdle->IsActive() ) |
|
113 { |
|
114 iIdle->Cancel(); |
|
115 } |
|
116 delete iIdle; |
|
117 SetObserver( NULL ); |
|
118 delete iLogoImage; |
|
119 delete iLogoImageMask; |
|
120 delete iImageConverter; |
|
121 delete iHsContentInfo; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CWmWidgetData::SetObserver |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 void CWmWidgetData::SetObserver( MWmWidgetDataObserver* aObserver ) |
|
129 { |
|
130 iObserver = aObserver; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // CWmWidgetData::SetObserver |
|
135 // --------------------------------------------------------- |
|
136 // |
|
137 void CWmWidgetData::SetPersistentWidgetOrder( |
|
138 const CWmPersistentWidgetOrder* aPersistentWidgetOrder ) |
|
139 { |
|
140 iPersistentWidgetOrder = aPersistentWidgetOrder; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // CWmWidgetData::EqualsTo |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 TBool CWmWidgetData::EqualsTo( CHsContentInfo& aContentInfo ) |
|
148 { |
|
149 return ( |
|
150 HsContentInfo().Uid() == aContentInfo.Uid() && |
|
151 HsContentInfo().PublisherId() == aContentInfo.PublisherId() ); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CWmWidgetData::CompareByName |
|
156 // --------------------------------------------------------- |
|
157 // |
|
158 TInt CWmWidgetData::CompareByName( |
|
159 const CWmWidgetData& aDataOne, const CWmWidgetData& aDataTwo ) |
|
160 { |
|
161 // negate the result for ascending alphabetical order |
|
162 TInt result = aDataOne.Name().CompareC( aDataTwo.Name() ); |
|
163 return result; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------- |
|
167 // CWmWidgetData::CompareByPersistentWidgetOrder |
|
168 // --------------------------------------------------------- |
|
169 // |
|
170 TInt CWmWidgetData::CompareByPersistentWidgetOrder( |
|
171 const CWmWidgetData& aDataOne, const CWmWidgetData& aDataTwo ) |
|
172 { |
|
173 TInt result; |
|
174 const CWmPersistentWidgetOrder* order = aDataOne.iPersistentWidgetOrder; |
|
175 if ( order && !order->IsEmpty() ) |
|
176 { |
|
177 result = order->IndexOf( aDataOne ) - order->IndexOf( aDataTwo ); |
|
178 } |
|
179 else |
|
180 { |
|
181 // fallback: if persistent widget order is not available |
|
182 // or it is empty (this is the case on first start, or if the persistent |
|
183 // file is corrupted or deleted) -> order widgets by name. |
|
184 result = CompareByName( aDataOne, aDataTwo ); |
|
185 } |
|
186 return result; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CWmWidgetData::NotifyCompletion |
|
191 // --------------------------------------------------------- |
|
192 // |
|
193 void CWmWidgetData::NotifyCompletion( TInt aError ) |
|
194 { |
|
195 delete iLogoImage; |
|
196 iLogoImage = NULL; |
|
197 delete iLogoImageMask; |
|
198 iLogoImageMask = NULL; |
|
199 if ( KErrNone != aError ) |
|
200 { |
|
201 // no image available. Do nothing. |
|
202 } |
|
203 else |
|
204 { |
|
205 iLogoImage = iImageConverter->Bitmap(); |
|
206 iLogoImageMask = iImageConverter->Mask(); |
|
207 FireDataChanged(); |
|
208 } |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CWmWidgetData::HandleIconStringL |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 void CWmWidgetData::HandleIconStringL( const TDesC& aIconStr ) |
|
216 { |
|
217 HBufC* iconStr = NULL; |
|
218 if ( aIconStr.Length() == 0 && |
|
219 iPublisherUid != KNullUid ) |
|
220 { |
|
221 // workaround for wrt widgets icon |
|
222 _LIT( KUidTag, "uid(0x%x)" ); |
|
223 const TInt KLength = 32; |
|
224 iconStr = HBufC::NewLC( KLength ); |
|
225 iconStr->Des().Format( KUidTag, iPublisherUid.iUid ); |
|
226 } |
|
227 else |
|
228 { |
|
229 iconStr = aIconStr.AllocLC(); |
|
230 } |
|
231 |
|
232 TSize size( iLogoSize ); |
|
233 if ( iLogoImage ) { size = iLogoImage->SizeInPixels(); } |
|
234 if ( size != iLogoSize && |
|
235 iLogoSize.iWidth > 0 && iLogoSize.iHeight > 0 ) |
|
236 { |
|
237 size = iLogoSize; |
|
238 } |
|
239 iImageConverter->HandleIconStringL( |
|
240 size.iWidth, size.iHeight, *iconStr ); |
|
241 |
|
242 CleanupStack::PopAndDestroy( iconStr ); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CWmWidgetData::FireDataChanged |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 void CWmWidgetData::FireDataChanged() |
|
250 { |
|
251 if ( iObserver ) |
|
252 { |
|
253 iObserver->HandleWidgetDataChanged( this ); |
|
254 } |
|
255 } |
|
256 |
|
257 // ---------------------------------------------------- |
|
258 // CWmWidgetData::UidFromString |
|
259 // ---------------------------------------------------- |
|
260 // |
|
261 TUid CWmWidgetData::UidFromString( const TDesC8& aUidString ) const |
|
262 { |
|
263 TUid uid( TUid::Null() ); |
|
264 const TInt KHexPrefixLength = 2; |
|
265 if ( aUidString.Length() > KHexPrefixLength ) |
|
266 { |
|
267 TUint id = 0; |
|
268 TLex8 lex( aUidString.Mid( KHexPrefixLength ) ); |
|
269 if ( lex.Val( id, EHex ) == KErrNone ) |
|
270 { |
|
271 uid.iUid = (TInt32)id; |
|
272 } |
|
273 } |
|
274 return uid; |
|
275 } |
|
276 |
|
277 // ---------------------------------------------------- |
|
278 // CWmWidgetData::PublisherUid |
|
279 // ---------------------------------------------------- |
|
280 // |
|
281 TUid CWmWidgetData::PublisherUid() |
|
282 { |
|
283 return iPublisherUid; |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------- |
|
287 // CWmWidgetData::FetchPublisherUidL |
|
288 // ---------------------------------------------------- |
|
289 // |
|
290 void CWmWidgetData::FetchPublisherUidL( |
|
291 RWidgetRegistryClientSession* aRegistryClientSession ) |
|
292 { |
|
293 if ( iPublisherUid == KNullUid && |
|
294 PublisherId() != KNullDesC && |
|
295 iWidgetType != CWmWidgetData::ENative && |
|
296 aRegistryClientSession ) |
|
297 { |
|
298 TInt widgetUid = aRegistryClientSession->GetWidgetUidL( PublisherId() ); |
|
299 iPublisherUid = ( widgetUid != 0 ? TUid::Uid(widgetUid) : KNullUid ); |
|
300 } |
|
301 } |
|
302 // ---------------------------------------------------- |
|
303 // CWmWidgetData::SetLogoSize |
|
304 // ---------------------------------------------------- |
|
305 // |
|
306 void CWmWidgetData::SetLogoSize( const TSize& aSize ) |
|
307 { |
|
308 iLogoSize = aSize; |
|
309 if ( iImageConverter ) |
|
310 { |
|
311 iImageConverter->SetLogoSize( aSize ); |
|
312 } |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------- |
|
316 // CWmWidgetData::HandleAsyncIconString |
|
317 // --------------------------------------------------------- |
|
318 // |
|
319 TInt CWmWidgetData::HandleAsyncIconString( TAny* aPtr ) |
|
320 { |
|
321 CWmWidgetData* self = static_cast< CWmWidgetData* >( aPtr ); |
|
322 if ( self->iIdle->IsActive() ) |
|
323 { |
|
324 self->iIdle->Cancel(); |
|
325 } |
|
326 TRAP_IGNORE( self->HandleIconStringL( |
|
327 self->HsContentInfo().IconPath() ); ); |
|
328 return KErrNone; |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------- |
|
332 // CWmWidgetData::ReCreateLogo |
|
333 // --------------------------------------------------------- |
|
334 // |
|
335 void CWmWidgetData::ReCreateLogo( const TSize& aSize ) |
|
336 { |
|
337 TSize imageSize( iLogoSize ); |
|
338 if ( iLogoImage ) { imageSize = iLogoImage->SizeInPixels(); } |
|
339 if ( (aSize != iLogoSize) || (imageSize != iLogoSize) ) |
|
340 { |
|
341 iLogoSize = aSize; |
|
342 |
|
343 delete iLogoImage; |
|
344 iLogoImage = NULL; |
|
345 delete iLogoImageMask; |
|
346 iLogoImageMask = NULL; |
|
347 |
|
348 if ( iIdle && !iIdle->IsActive() ) |
|
349 { |
|
350 // start decoding the icon |
|
351 iIdle->Start( TCallBack( HandleAsyncIconString, this ) ); |
|
352 } |
|
353 } |
|
354 } |
|
355 |
|
356 // End of file |
|
357 |
|