|
1 /* |
|
2 * Copyright (c) 2008 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 the License "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: Internal class definition for WidgetUI application. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cpspublisher.h" |
|
20 |
|
21 #include <LiwServiceHandler.h> |
|
22 #include <LiwVariant.h> |
|
23 #include <LiwGenericParam.h> |
|
24 #include <Liwcommon.h> |
|
25 |
|
26 #include <AknsFrameBackgroundControlContext.h> |
|
27 #include <fbs.h> |
|
28 #include <aknsdrawutils.h> |
|
29 |
|
30 |
|
31 // TODO use global definitions! |
|
32 |
|
33 _LIT8( KCPService, "Service.ContentPublishing" ); |
|
34 _LIT8( KCPInterface, "IDataSource" ); |
|
35 |
|
36 _LIT8( KType, "type" ); |
|
37 _LIT( KCpData, "cp_data" ); |
|
38 |
|
39 _LIT8( KPublisherId, "publisher" ); |
|
40 _LIT8( KContentType, "content_type" ); |
|
41 _LIT8( KContentId, "content_id" ); |
|
42 |
|
43 |
|
44 _LIT8( KDataMap, "data_map" ); |
|
45 |
|
46 _LIT8( KItem, "item" ); |
|
47 _LIT8( KAdd, "Add" ); |
|
48 |
|
49 _LIT(KP,"ai3templatedwidget"); |
|
50 _LIT(KCT,"wideimage"); |
|
51 _LIT8( KImageKey, "image1"); |
|
52 |
|
53 _LIT8( KMask, "_mask"); |
|
54 |
|
55 _LIT(KP1,"ai3homescreen"); |
|
56 _LIT(KCT1,"wideimage"); |
|
57 _LIT( KImageContainer, "image_container" ); |
|
58 _LIT8( KWidth, "width"); |
|
59 _LIT8( KHeight, "height"); |
|
60 _LIT8( KFilter, "filter" ); |
|
61 _LIT8( KResults, "results"); |
|
62 _LIT8( KOperation, "operation" ); |
|
63 _LIT8( KRequestNotification, "RequestNotification" ); |
|
64 _LIT( KUpdate, "update" ); |
|
65 _LIT8( KChangeInfo, "change_info" ); |
|
66 const TInt KSkinGfxInnerRectShrink = 5; |
|
67 |
|
68 static void DoResetAndDestroy( TAny* aPtr ) |
|
69 { |
|
70 __ASSERT_DEBUG( aPtr, User::Invariant() ); |
|
71 reinterpret_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // InvertBitmap |
|
76 // Sets white pixels black and other ones white. |
|
77 // ----------------------------------------------------------------------------- |
|
78 static void InvertBitmap( CFbsBitmap*& aBitmap ) |
|
79 { |
|
80 TSize inSize = aBitmap->SizeInPixels(); |
|
81 TBitmapUtil bitmapUtil( aBitmap ); |
|
82 bitmapUtil.Begin( TPoint(0,0) ); |
|
83 TInt xPos; |
|
84 for ( TInt yPos = 0; yPos < inSize.iHeight; yPos++ ) |
|
85 { |
|
86 bitmapUtil.SetPos( TPoint( 0,yPos )); |
|
87 for ( xPos = 0; xPos < inSize.iWidth; xPos++ ) |
|
88 { |
|
89 //Inverts the pixel colors. |
|
90 TInt pix = bitmapUtil.GetPixel(); |
|
91 if( pix == 0xff ) |
|
92 { |
|
93 bitmapUtil.SetPixel( 0x00 ); |
|
94 } |
|
95 else |
|
96 { |
|
97 bitmapUtil.SetPixel( 0xff ); |
|
98 } |
|
99 bitmapUtil.IncXPos(); |
|
100 } |
|
101 } |
|
102 bitmapUtil.End(); |
|
103 } |
|
104 // ----------------------------------------------------------------------------- |
|
105 // LoadMaskBitmapL |
|
106 // Loads a mask bitmap from the skin. |
|
107 // ----------------------------------------------------------------------------- |
|
108 static void LoadMaskBitmapL( |
|
109 CFbsBitmap*& aBitmap, |
|
110 TSize aSize) |
|
111 { |
|
112 const TRect rect( 0, 0, aSize.iWidth, aSize.iHeight ); |
|
113 TRect shrunkRect( rect ); |
|
114 shrunkRect.Shrink( KSkinGfxInnerRectShrink, KSkinGfxInnerRectShrink ); |
|
115 |
|
116 CAknsFrameBackgroundControlContext* skinContext = |
|
117 CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnHomeBgWidget, rect, shrunkRect, EFalse ); |
|
118 CleanupStack::PushL( skinContext ); |
|
119 |
|
120 // Create an off-screen bitmap and context (CFbsBitGc) |
|
121 // Also remember to take care of destruction / cleanup during leaves |
|
122 aBitmap = new (ELeave) CFbsBitmap(); |
|
123 CleanupStack::PushL( aBitmap ); |
|
124 User::LeaveIfError( aBitmap->Create( aSize, EGray256 ) ); |
|
125 |
|
126 CFbsBitGc* bitGc = NULL; |
|
127 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( aBitmap ); |
|
128 CleanupStack::PushL( bitmapDevice ); |
|
129 User::LeaveIfError( bitmapDevice->CreateContext( bitGc ) ); |
|
130 |
|
131 // Draw the content on the off-screen bitmap |
|
132 AknsDrawUtils::DrawBackground( AknsUtils::SkinInstance(), skinContext, |
|
133 NULL, *bitGc, TPoint(0,0), rect, KAknsDrawParamNoClearUnderImage ); |
|
134 |
|
135 CleanupStack::PopAndDestroy( bitmapDevice ); |
|
136 CleanupStack::Pop( aBitmap ); |
|
137 CleanupStack::PopAndDestroy( skinContext ); |
|
138 } |
|
139 |
|
140 |
|
141 CCpsPublisher* CCpsPublisher::NewL() |
|
142 { |
|
143 CCpsPublisher* self = new (ELeave) CCpsPublisher(); |
|
144 CleanupStack::PushL( self ); |
|
145 self->ConstructL(); |
|
146 CleanupStack::Pop(); |
|
147 return self; |
|
148 } |
|
149 |
|
150 CCpsPublisher::~CCpsPublisher() |
|
151 { |
|
152 if( iCpsInterface ) |
|
153 { |
|
154 iCpsInterface->Close(); |
|
155 iCpsInterface = NULL; |
|
156 } |
|
157 if( iServiceHandler ) |
|
158 { |
|
159 iServiceHandler->Reset(); |
|
160 delete iServiceHandler; |
|
161 iServiceHandler = NULL; |
|
162 } |
|
163 delete iMaskBitmap; |
|
164 } |
|
165 |
|
166 CLiwDefaultMap* ElementSizeFilterLC() |
|
167 { |
|
168 //Create filter criteria for requested entries in form of LIW map: |
|
169 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
170 filter->InsertL( KPublisherId, TLiwVariant( KP1 )); |
|
171 filter->InsertL( KContentType, TLiwVariant( KCT1 )); |
|
172 filter->InsertL( KContentId, TLiwVariant( KImageContainer )); |
|
173 return filter; |
|
174 } |
|
175 |
|
176 void UpdateElementSizeL( CLiwDefaultMap *outDataMap, TSize& aSize ) |
|
177 { |
|
178 TLiwVariant variant; |
|
179 variant.PushL(); |
|
180 if ( outDataMap->FindL( KWidth, variant ) ) |
|
181 { |
|
182 variant.Get( aSize.iWidth ); |
|
183 } |
|
184 variant.Reset(); |
|
185 if ( outDataMap->FindL( KHeight, variant ) ) |
|
186 { |
|
187 variant.Get( aSize.iHeight ); |
|
188 } |
|
189 CleanupStack::PopAndDestroy( &variant ); |
|
190 } |
|
191 |
|
192 CCpsPublisher::CCpsPublisher() |
|
193 { |
|
194 |
|
195 } |
|
196 |
|
197 void CCpsPublisher::ConstructL() |
|
198 { |
|
199 RDebug::Printf("CCpsPublisher::InitCPS"); |
|
200 InitCpsInterfaceL(); |
|
201 RDebug::Printf("CCpsPublisher::Register"); |
|
202 ExecuteRegistrationCommandL( 0 ); |
|
203 RDebug::Printf("CCpsPublisher::GetBitmapSize"); |
|
204 GetBitmapSizeL(); |
|
205 RDebug::Printf("CCpsPublisher::EndConstructL"); |
|
206 } |
|
207 |
|
208 TSize CCpsPublisher::BitmapSize() |
|
209 { |
|
210 return iSize; |
|
211 } |
|
212 |
|
213 void CCpsPublisher::PublishBitmapL( CFbsBitmap& aBitmap, const TDesC& aBundleName ) |
|
214 { |
|
215 // Load the mask bitmap from skin |
|
216 if( !iMaskBitmap || |
|
217 aBitmap.SizeInPixels() != iMaskBitmap->SizeInPixels()) |
|
218 { |
|
219 RDebug::Printf("CCpsPublisher::LoadMaskBitmapL"); |
|
220 delete iMaskBitmap; |
|
221 iMaskBitmap = NULL; |
|
222 LoadMaskBitmapL( iMaskBitmap, aBitmap.SizeInPixels() ); |
|
223 InvertBitmap( iMaskBitmap ); |
|
224 } |
|
225 |
|
226 TInt handle = aBitmap.Handle(); |
|
227 TInt maskHandle = KErrBadHandle; |
|
228 if( iMaskBitmap ) |
|
229 { |
|
230 maskHandle = iMaskBitmap->Handle(); |
|
231 } |
|
232 RDebug::Printf("CCpsPublisher::PublishBitmapL"); |
|
233 AddImageHandleL( KP() ,KCT(), aBundleName, |
|
234 handle, maskHandle, KImageKey() ); |
|
235 } |
|
236 |
|
237 void CCpsPublisher::GetBitmapSizeL() |
|
238 { |
|
239 CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC(); |
|
240 CLiwDefaultMap* filter = ElementSizeFilterLC(); |
|
241 ExecuteCommandL( filter, outDataMap, KCpData ); |
|
242 CleanupStack::PopAndDestroy( filter ); |
|
243 |
|
244 UpdateElementSizeL( outDataMap, iSize ); |
|
245 |
|
246 CleanupStack::PopAndDestroy( outDataMap ); |
|
247 } |
|
248 |
|
249 void CCpsPublisher::ExecuteRegistrationCommandL( |
|
250 TUint aOption ) |
|
251 { |
|
252 __UHEAP_MARK; |
|
253 CLiwDefaultMap* filter = ElementSizeFilterLC(); |
|
254 filter->InsertL( KOperation, TLiwVariant( KUpdate )); |
|
255 |
|
256 CLiwGenericParamList& inParamList = iServiceHandler->InParamListL(); |
|
257 CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL(); |
|
258 |
|
259 // Fill in input list for RequestNotification command |
|
260 inParamList.AppendL( TLiwGenericParam( KType,TLiwVariant( KCpData ))); |
|
261 inParamList.AppendL( TLiwGenericParam( KFilter ,TLiwVariant( filter ))); |
|
262 |
|
263 iCpsInterface->ExecuteCmdL( |
|
264 KRequestNotification, |
|
265 inParamList, |
|
266 outParamList, |
|
267 aOption, |
|
268 this ); |
|
269 |
|
270 outParamList.Reset(); |
|
271 inParamList.Reset(); |
|
272 CleanupStack::PopAndDestroy( filter ); |
|
273 __UHEAP_MARKEND; |
|
274 } |
|
275 |
|
276 TInt CCpsPublisher::HandleNotifyL( |
|
277 TInt /*aCmdId*/, |
|
278 TInt /*aEventId*/, |
|
279 CLiwGenericParamList& aEventParamList, |
|
280 const CLiwGenericParamList& /*aInParamList*/ ) |
|
281 { |
|
282 __UHEAP_MARK; |
|
283 TInt pos(0); |
|
284 aEventParamList.FindFirst( pos, KChangeInfo ); |
|
285 if (pos != KErrNotFound) |
|
286 { |
|
287 // Get list of maps |
|
288 TLiwVariant variant = ( aEventParamList )[pos].Value(); |
|
289 variant.PushL(); |
|
290 const CLiwList* changeMapsList = variant.AsList(); |
|
291 |
|
292 TPtrC operation; |
|
293 |
|
294 // Iter through list content |
|
295 for (TInt i = 0; i < changeMapsList->Count(); ++i) |
|
296 { |
|
297 if ( changeMapsList->AtL( i, variant )) |
|
298 { |
|
299 const CLiwMap* map = variant.AsMap(); |
|
300 |
|
301 // Check what triggered a notification |
|
302 if ( map->FindL( KOperation, variant )) |
|
303 { |
|
304 operation.Set( variant.AsDes()); |
|
305 } |
|
306 if ( operation == KUpdate ) |
|
307 { |
|
308 GetBitmapSizeL(); |
|
309 } |
|
310 } |
|
311 } |
|
312 CleanupStack::PopAndDestroy( &variant ); |
|
313 } |
|
314 __UHEAP_MARKEND; |
|
315 return KErrNone; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CCpsPublisher::AddImageHandleL( |
|
323 const TDesC& aPublisherId, const TDesC& aContentType, |
|
324 const TDesC& aContentId, const TInt& aHandle, const TInt& aMaskHandle, |
|
325 const TDesC8& aImageKey ) |
|
326 { |
|
327 __UHEAP_MARK; |
|
328 CLiwGenericParamList& inparam = iServiceHandler->InParamListL(); |
|
329 CLiwGenericParamList& outparam = iServiceHandler->OutParamListL(); |
|
330 |
|
331 TLiwGenericParam cptype( KType, TLiwVariant( KCpData )); |
|
332 cptype.PushL(); |
|
333 |
|
334 inparam.AppendL( cptype ); |
|
335 |
|
336 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
337 CLiwDefaultMap* map = CLiwDefaultMap::NewLC(); |
|
338 |
|
339 // Add bitmap handle to data map |
|
340 map->InsertL( aImageKey, TLiwVariant( aHandle )); // key - aKey, value - map (stringsMap) |
|
341 |
|
342 HBufC8* maskKey = HBufC8::NewLC( aImageKey.Length() + KMask().Length() ); |
|
343 TPtr8 maskKeyPtr = maskKey->Des(); |
|
344 |
|
345 maskKeyPtr.Append(aImageKey); |
|
346 maskKeyPtr.Append(KMask); |
|
347 map->InsertL( maskKeyPtr, TLiwVariant( aMaskHandle )); |
|
348 CleanupStack::PopAndDestroy( maskKey ); |
|
349 |
|
350 // Create content data map |
|
351 cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
352 cpdatamap->InsertL( KContentType, TLiwVariant( aContentType )); |
|
353 cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
354 cpdatamap->InsertL( KDataMap, TLiwVariant(map) ); |
|
355 |
|
356 TLiwGenericParam item( KItem, TLiwVariant( cpdatamap )); |
|
357 item.PushL(); |
|
358 |
|
359 inparam.AppendL( item ); |
|
360 |
|
361 iCpsInterface->ExecuteCmdL( KAdd , inparam, outparam); |
|
362 |
|
363 |
|
364 CleanupStack::PopAndDestroy(); // item |
|
365 CleanupStack::PopAndDestroy( map ); |
|
366 CleanupStack::PopAndDestroy( cpdatamap ); |
|
367 CleanupStack::PopAndDestroy(); // cptype |
|
368 |
|
369 outparam.Reset(); |
|
370 inparam.Reset(); |
|
371 __UHEAP_MARKEND; |
|
372 } |
|
373 |
|
374 void CCpsPublisher::ExecuteCommandL(CLiwDefaultMap* aInFilter, CLiwDefaultMap* aOutDataMap, const TDesC16& aRegistry ) |
|
375 { |
|
376 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
377 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
378 |
|
379 TLiwGenericParam type( KType, TLiwVariant( aRegistry ) ); |
|
380 inParamList->AppendL( type ); |
|
381 |
|
382 //append filter to input param |
|
383 TLiwGenericParam item( KFilter, TLiwVariant( aInFilter )); |
|
384 inParamList->AppendL( item ); |
|
385 |
|
386 // It is assumed that interface is already initiated |
|
387 iCpsInterface->ExecuteCmdL( _L8("GetList"), *inParamList, *outParamList); |
|
388 |
|
389 type.Reset(); |
|
390 item.Reset(); |
|
391 inParamList->Reset(); |
|
392 |
|
393 //extracts data map |
|
394 TInt pos = 0; |
|
395 outParamList->FindFirst( pos, KResults ); |
|
396 if( pos != KErrNotFound ) |
|
397 // results present |
|
398 { |
|
399 //extract iterator on results list |
|
400 TLiwVariant variant = (*outParamList)[pos].Value(); |
|
401 CLiwIterable* iterable = variant.AsIterable(); |
|
402 iterable->Reset(); |
|
403 |
|
404 //get next result |
|
405 if( iterable->NextL( variant ) ) |
|
406 { |
|
407 //extract content map |
|
408 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
409 variant.Get( *map ); |
|
410 if( map->FindL( KDataMap, variant) ) |
|
411 { |
|
412 variant.Get( *aOutDataMap ); |
|
413 } |
|
414 variant.Reset(); |
|
415 CleanupStack::PopAndDestroy( map ); |
|
416 } |
|
417 iterable->Reset(); |
|
418 } |
|
419 outParamList->Reset(); |
|
420 } |
|
421 |
|
422 void CCpsPublisher::InitCpsInterfaceL() |
|
423 { |
|
424 if( !iServiceHandler ) |
|
425 { |
|
426 iServiceHandler = CLiwServiceHandler::NewL(); |
|
427 } |
|
428 |
|
429 CLiwGenericParamList& inParam = iServiceHandler->InParamListL(); |
|
430 CLiwGenericParamList& outParam = iServiceHandler->OutParamListL(); |
|
431 |
|
432 RCriteriaArray a; |
|
433 TCleanupItem item( DoResetAndDestroy, &a ); |
|
434 CleanupStack::PushL( item ); |
|
435 |
|
436 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, KCPInterface, |
|
437 KCPService ); |
|
438 crit->SetServiceClass( TUid::Uid(KLiwClassBase) ); |
|
439 |
|
440 a.AppendL(crit); |
|
441 |
|
442 CleanupStack::Pop( crit ); |
|
443 |
|
444 iServiceHandler->AttachL( a ); |
|
445 iServiceHandler->ExecuteServiceCmdL( *crit, inParam, outParam ); |
|
446 |
|
447 CleanupStack::PopAndDestroy(); // item; |
|
448 |
|
449 // find service interface |
|
450 TInt pos = 0; |
|
451 MLiwInterface* msgInterface = NULL; |
|
452 outParam.FindFirst( pos, KCPInterface ); |
|
453 if ( pos != KErrNotFound ) |
|
454 { |
|
455 msgInterface = (outParam)[pos].Value().AsInterface(); |
|
456 } |
|
457 |
|
458 outParam.Reset(); |
|
459 inParam.Reset(); |
|
460 iCpsInterface = msgInterface; |
|
461 } |
|
462 // END OF FILE |
|
463 |
|
464 |
|
465 |