|
1 /* |
|
2 * Copyright (c) 2005-2007 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 * Profile plug-in publisher |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <ecom/ecom.h> |
|
22 #include <liwservicehandler.h> |
|
23 #include <aipluginsettings.h> |
|
24 #include <apgcli.h> |
|
25 #include <apgicnfl.h> |
|
26 #include <bautils.h> |
|
27 #include <aicpscommandbuffer.h> |
|
28 |
|
29 #include "wrtdata.h" |
|
30 #include "wrtdatapluginconst.h" |
|
31 #include "wrtdataobserver.h" |
|
32 #include "wrtdataplugin.h" |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Symbian 2nd phase constructor can leave |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CWrtData* CWrtData::NewL(CWrtDataPlugin* aPlugin) |
|
41 { |
|
42 CWrtData* self = new (ELeave) CWrtData(); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(aPlugin); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // Default constructor |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CWrtData::CWrtData() |
|
54 : iAppUid( KNullUid ) |
|
55 { |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // Symbian 2nd phase constructor can leave |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 void CWrtData::ConstructL(CWrtDataPlugin* aPlugin) |
|
63 { |
|
64 iPlugin = aPlugin; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Destructor |
|
69 // Deletes all data created to heap |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CWrtData::~CWrtData() |
|
73 { |
|
74 if(iObserver) |
|
75 { |
|
76 delete iObserver; |
|
77 iObserver = NULL; |
|
78 } |
|
79 if ( iContentId ) |
|
80 { |
|
81 delete iContentId; |
|
82 iContentId = NULL; |
|
83 } |
|
84 // not owned |
|
85 iInterface = NULL; |
|
86 iServiceHandler = NULL; |
|
87 iCpsExecute = NULL; |
|
88 iPlugin = NULL; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CWrtData::ConfigureL |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CWrtData::ConfigureL(RAiSettingsItemArray& aConfigurations ) |
|
96 { |
|
97 TInt count = aConfigurations.Count(); |
|
98 for(TInt i = 0; i<count; i++ ) |
|
99 { |
|
100 MAiPluginConfigurationItem& confItem = ( aConfigurations[i] )->AiPluginConfigurationItem(); |
|
101 // if owner is plugin then it (key,value) is for plugin configurations items |
|
102 if(confItem.Owner() == KPlugin() && confItem.Name() == KPubData()) |
|
103 { |
|
104 iContentId = confItem.Value().AllocL(); |
|
105 } |
|
106 } |
|
107 if( iContentId->Des().Length() == 0 ) |
|
108 { |
|
109 // No service to offer without plugin configurations |
|
110 User::Leave( KErrNotSupported ); |
|
111 } |
|
112 iObserver = CWrtDataObserver::NewL( iInterface, this ); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CWrtData::RegisterL |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CWrtData::RegisterL() |
|
120 { |
|
121 CLiwDefaultMap* filter = CreateFilterLC(); |
|
122 filter->InsertL( KOperation, TLiwVariant( KAddUpdateDelete ) ); |
|
123 iObserver->RegisterL(filter); |
|
124 CleanupStack::PopAndDestroy( filter ); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CWrtData::UpdatePublisherStatusL |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CWrtData::UpdatePublisherStatusL() |
|
132 { |
|
133 if ( !iPlugin->IsStopped() ) |
|
134 { |
|
135 // Resent the plugin status to publisher |
|
136 CLiwDefaultList* actions= CLiwDefaultList::NewLC(); |
|
137 actions->AppendL( TLiwVariant( KActive )); |
|
138 if ( iPlugin->IsActive() ) |
|
139 { |
|
140 actions->AppendL( TLiwVariant( KResume ) ); |
|
141 } |
|
142 else |
|
143 { |
|
144 actions->AppendL( TLiwVariant( KSuspend )); |
|
145 } |
|
146 // forward the network status if it uses. |
|
147 if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOnline ) |
|
148 { |
|
149 actions->AppendL( TLiwVariant( KOnLine )); |
|
150 } |
|
151 else if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOffline ) |
|
152 { |
|
153 actions->AppendL( TLiwVariant( KOffLine)); |
|
154 } |
|
155 |
|
156 ReSendNotificationL( actions ); |
|
157 CleanupStack::PopAndDestroy( actions ); |
|
158 } |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CWrtData::PublishInitialDataL |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CWrtData::PublishInitialDataL( MAiContentObserver* aObserver ) |
|
166 { |
|
167 // Show loading animation |
|
168 iPlugin->ShowLoadingIcon( aObserver ); |
|
169 |
|
170 TBuf<KWRTContentValueMaxLength> appName; |
|
171 TBuf<KWRTAppUidLenth> appUidStr; |
|
172 GetWidgetNameAndUidL( appName, appUidStr ); |
|
173 |
|
174 // Publish widget's name |
|
175 if ( appName.Length() > 0 ) |
|
176 { |
|
177 iPlugin->PublishTextL( aObserver, CWrtDataPlugin::EDefaultText, appName ); |
|
178 } |
|
179 |
|
180 // Publish widget's apparc image. This might fail if there is application |
|
181 // list population ongoing in AppFW and then we have to try again later |
|
182 if ( ResolveUid ( appUidStr, iAppUid ) ) |
|
183 { |
|
184 TRAPD( err, PublishDefaultImageL( aObserver ) ); |
|
185 if ( KErrNone != err ) |
|
186 { |
|
187 iPlugin->StartTimer(); |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CWrtData::PublishDefaultImageL |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CWrtData::PublishDefaultImageL( MAiContentObserver* aObserver ) |
|
197 { |
|
198 // Publish widget's apparc image |
|
199 TInt handle = KErrNotFound; |
|
200 TInt mask = KErrNotFound; |
|
201 // create icon from application UID |
|
202 CreateIconFromUidL( handle, mask, iAppUid ); |
|
203 // Publish apparc image |
|
204 iPlugin->PublishImageL( aObserver, |
|
205 CWrtDataPlugin::EDefaultImage, |
|
206 handle, |
|
207 mask ); |
|
208 } |
|
209 |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CWrtData::PublishL |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CWrtData::PublishL( MAiContentObserver* aObserver, CLiwDefaultMap* aDataMap ) |
|
216 { |
|
217 TLiwVariant variant; |
|
218 iPlugin->HideLoadingIcon(aObserver); |
|
219 if ( aDataMap->FindL( KImage1, variant ) ) |
|
220 { |
|
221 TInt handle = KErrBadHandle; |
|
222 TUint uintHandle = 0; |
|
223 TPtrC16 valPtr; |
|
224 if ( variant.Get( uintHandle ) ) |
|
225 { |
|
226 handle = uintHandle; |
|
227 } |
|
228 else if ( !variant.Get( handle ) ) |
|
229 { |
|
230 handle = KErrBadHandle; |
|
231 } |
|
232 // read as a image handle |
|
233 if( handle == KErrBadHandle ) |
|
234 { |
|
235 // no handle, so read as image path |
|
236 variant.Get( valPtr ); |
|
237 iPlugin->PublishImageL(aObserver, CWrtDataPlugin::EImage1, valPtr ); |
|
238 } |
|
239 else |
|
240 { |
|
241 TInt maskHandle = KErrBadHandle; |
|
242 //Look for image mask |
|
243 if ( aDataMap->FindL( KImageMask, variant ) ) |
|
244 { |
|
245 variant.Get( maskHandle ); |
|
246 } |
|
247 iPlugin->PublishImageL(aObserver, CWrtDataPlugin::EImage1, handle, maskHandle ); |
|
248 } |
|
249 } |
|
250 variant.Reset(); |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // CWrtData::RefreshL |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 void CWrtData::RefreshL( TDesC& aContentId, TDesC& aOperation, |
|
258 CLiwDefaultMap* aDataMap ) |
|
259 { |
|
260 if ( aContentId == iContentId ) |
|
261 { |
|
262 iPlugin->RefreshL( aOperation, aDataMap); |
|
263 } |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CWrtData::ExecuteActionL |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void CWrtData::ExecuteActionL(const TDesC& aObjectId, const TDesC& aTrigger ) |
|
271 { |
|
272 HBufC8* triggerName = HBufC8::NewLC( KWRTContentNameMaxLength ); |
|
273 |
|
274 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
275 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
276 |
|
277 // use the first item configuration to create the filter |
|
278 CLiwDefaultMap* filter = CreateFilterLC(); |
|
279 |
|
280 triggerName->Des().Copy(aTrigger); |
|
281 if ( aObjectId == KPubData ) |
|
282 { |
|
283 // this trigger belongs to publisher registery. |
|
284 // in such case it is assumed that all the items in the widgets |
|
285 // belongs to same publisher, type and id. |
|
286 TLiwGenericParam cptype( KType, TLiwVariant( KPubData ) ); |
|
287 inParamList->AppendL( cptype ); |
|
288 cptype.Reset(); |
|
289 } |
|
290 else |
|
291 { |
|
292 //append type to inparam list |
|
293 TLiwGenericParam cptype( KType, TLiwVariant( KCpData ) ); |
|
294 inParamList->AppendL( cptype ); |
|
295 cptype.Reset(); |
|
296 } |
|
297 |
|
298 filter->InsertL( KActionTrigger, TLiwVariant( triggerName->Des() ) ); |
|
299 //append filter to input param |
|
300 TLiwGenericParam item( KFilter, TLiwVariant( filter ) ); |
|
301 inParamList->AppendL( item ); |
|
302 iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList ); |
|
303 |
|
304 item.Reset(); |
|
305 CleanupStack::PopAndDestroy( filter ); |
|
306 CleanupStack::PopAndDestroy( triggerName ); |
|
307 outParamList->Reset(); |
|
308 inParamList->Reset(); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CWrtData::IsPluginActive |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 TBool CWrtData::IsPluginActive() |
|
316 { |
|
317 return iPlugin->IsActive(); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CWrtData::CreateFilterL |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 CLiwDefaultMap* CWrtData::CreateFilterLC() |
|
325 { |
|
326 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
327 filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher )); |
|
328 filter->InsertL( KContentType, TLiwVariant( KTemplateWidget )); |
|
329 filter->InsertL( KContentId, TLiwVariant( iContentId )); |
|
330 return filter; |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // CWrtData::ExecuteCommandL |
|
335 // --------------------------------------------------------------------------- |
|
336 // |
|
337 void CWrtData::ExecuteCommandL(CLiwDefaultMap* aInFilter, CLiwDefaultMap* aOutDataMap, const TDesC16& aRegistry ) |
|
338 { |
|
339 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
340 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
341 |
|
342 TLiwGenericParam type( KType, TLiwVariant( aRegistry ) ); |
|
343 inParamList->AppendL( type ); |
|
344 |
|
345 //append filter to input param |
|
346 TLiwGenericParam item( KFilter, TLiwVariant( aInFilter )); |
|
347 inParamList->AppendL( item ); |
|
348 |
|
349 // execute service.It is assumed that iInterface is already initiatedd |
|
350 if(iInterface) |
|
351 { |
|
352 iInterface->ExecuteCmdL( KGetList, *inParamList, *outParamList); |
|
353 } |
|
354 else |
|
355 { |
|
356 User::Leave( KErrNotSupported ); |
|
357 } |
|
358 type.Reset(); |
|
359 item.Reset(); |
|
360 inParamList->Reset(); |
|
361 |
|
362 //extracts data map |
|
363 TInt pos = 0; |
|
364 outParamList->FindFirst( pos, KResults ); |
|
365 if( pos != KErrNotFound ) |
|
366 // results present |
|
367 { |
|
368 //extract iterator on results list |
|
369 TLiwVariant variant = (*outParamList)[pos].Value(); |
|
370 CLiwIterable* iterable = variant.AsIterable(); |
|
371 iterable->Reset(); |
|
372 |
|
373 //get next result |
|
374 if( iterable->NextL( variant ) ) |
|
375 { |
|
376 //extract content map |
|
377 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
378 variant.Get( *map ); |
|
379 if( map->FindL( KDataMap, variant) ) |
|
380 { |
|
381 variant.Get( *aOutDataMap ); |
|
382 } |
|
383 CleanupStack::PopAndDestroy( map ); |
|
384 } |
|
385 iterable->Reset(); |
|
386 variant.Reset(); |
|
387 } |
|
388 outParamList->Reset(); |
|
389 } |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // NotifyPublisherL |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 void CWrtData::NotifyPublisherL(const TDesC8& aStatus) |
|
396 { |
|
397 if( iCpsExecute == NULL ) |
|
398 { |
|
399 User::Leave( KErrNotSupported ); |
|
400 } |
|
401 |
|
402 CLiwDefaultMap* filter = CreateFilterLC(); |
|
403 // Add execute command triggers. Idle framework will execute |
|
404 iCpsExecute->AddCommand( iPluginId, KPubData, filter, aStatus ); |
|
405 CleanupStack::PopAndDestroy( filter ); |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // CWrtData::GetWidgetNameAndUidL |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 void CWrtData::GetWidgetNameAndUidL(TDes& aName, TDes& aAppUID ) |
|
413 { |
|
414 CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC(); |
|
415 //Create filter criteria for requested entries in form of LIW map: |
|
416 CLiwDefaultMap* filter = CreateFilterLC(); |
|
417 ExecuteCommandL( filter, outDataMap, KPubData ); |
|
418 CleanupStack::PopAndDestroy( filter ); |
|
419 |
|
420 TLiwVariant variant; |
|
421 if ( outDataMap->FindL(KWidgetInfo, variant) ) |
|
422 { |
|
423 CLiwDefaultMap* widgetInfoMap = CLiwDefaultMap::NewLC(); |
|
424 variant.Get( *widgetInfoMap ); |
|
425 variant.Reset(); |
|
426 if ( widgetInfoMap->FindL( KWidgetName, variant ) ) |
|
427 { |
|
428 aName.Copy(variant.AsDes()); |
|
429 variant.Reset(); |
|
430 if ( widgetInfoMap->FindL( KWidgetIcon, variant ) ) |
|
431 { |
|
432 aAppUID.Copy(variant.AsDes()); |
|
433 } |
|
434 } |
|
435 CleanupStack::PopAndDestroy( widgetInfoMap ); |
|
436 } |
|
437 variant.Reset(); |
|
438 CleanupStack::PopAndDestroy( outDataMap ); |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CWrtData::ResolveUid |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 TBool CWrtData::ResolveUid(const TDesC& aUidDes, TUid& aUid ) |
|
446 { |
|
447 // Syntax: uid(0x12345678) |
|
448 TInt error = KErrNotFound; |
|
449 TInt pos = aUidDes.FindF( KUid ); |
|
450 if( pos == 0 ) |
|
451 { |
|
452 // Skip skin token |
|
453 pos += KUid().Length(); |
|
454 |
|
455 // Initialize lexer |
|
456 TLex lex( aUidDes.Mid( pos ) ); |
|
457 |
|
458 // Check left parenthesis |
|
459 if ( lex.Get() == KLeftParenthesis ) |
|
460 { |
|
461 lex.SkipSpaceAndMark(); |
|
462 lex.SkipCharacters(); |
|
463 |
|
464 TPtrC mtoken = lex.MarkedToken(); |
|
465 pos = mtoken.FindF( KHexPrefix ); |
|
466 if ( pos == 0 ) |
|
467 { |
|
468 TLex lex( mtoken.Mid( KHexPrefix().Length() ) ); |
|
469 TUint id = 0; |
|
470 error = lex.Val( id, EHex ); |
|
471 aUid = TUid::Uid( (TInt)id ); |
|
472 } |
|
473 else |
|
474 { |
|
475 TInt id( 0 ); |
|
476 error = lex.Val( id ); |
|
477 aUid.iUid = id; |
|
478 } |
|
479 } |
|
480 } |
|
481 return ( error == KErrNone ); |
|
482 } |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // CWrtData::CreateIconFromUidL |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 void CWrtData::CreateIconFromUidL( TInt& aHandle, TInt& aMaskHandle, const TUid& aAppUid ) |
|
489 { |
|
490 RApaLsSession lsSession; |
|
491 User::LeaveIfError( lsSession.Connect() ); |
|
492 CleanupClosePushL( lsSession ); // lsSession (1) |
|
493 |
|
494 CArrayFixFlat<TSize>* sizeArray = new(ELeave) CArrayFixFlat<TSize>( 5 ); |
|
495 CleanupStack::PushL( sizeArray ); |
|
496 |
|
497 User::LeaveIfError( lsSession.GetAppIconSizes( aAppUid, *sizeArray ) ); |
|
498 |
|
499 if ( sizeArray->Count() ) |
|
500 { |
|
501 // There are other icon sizes |
|
502 TInt idx = 0; |
|
503 TInt size( sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight ); |
|
504 for ( TInt i = 1; i < sizeArray->Count(); i++ ) |
|
505 { |
|
506 if ( ( sizeArray->At(i).iWidth * sizeArray->At(i).iHeight ) > size ) |
|
507 { |
|
508 idx = i; |
|
509 size = sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight; |
|
510 } |
|
511 } |
|
512 |
|
513 CApaMaskedBitmap* appBitMap = CApaMaskedBitmap::NewLC(); |
|
514 User::LeaveIfError( lsSession.GetAppIcon( aAppUid, sizeArray->At(idx), *appBitMap ) ); |
|
515 aHandle = appBitMap->Handle(); |
|
516 aMaskHandle = appBitMap->Mask()->Handle(); |
|
517 CleanupStack::PopAndDestroy( appBitMap ); |
|
518 } |
|
519 |
|
520 CleanupStack::PopAndDestroy( sizeArray ); |
|
521 CleanupStack::PopAndDestroy( &lsSession ); |
|
522 } |
|
523 |
|
524 |
|
525 // --------------------------------------------------------------------------- |
|
526 // ReSendNotificationL |
|
527 // --------------------------------------------------------------------------- |
|
528 // |
|
529 void CWrtData::ReSendNotificationL(CLiwDefaultList* aActionsList) |
|
530 { |
|
531 if( iInterface == NULL ) |
|
532 { |
|
533 User::Leave( KErrNotSupported ); |
|
534 } |
|
535 |
|
536 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
537 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
538 |
|
539 TLiwGenericParam type( KType, TLiwVariant( KPubData ) ); |
|
540 inParamList->AppendL( type ); |
|
541 |
|
542 CLiwDefaultMap* filter = CreateFilterLC(); |
|
543 // add list of action triggers to execute |
|
544 filter->InsertL(KActionTrigger, TLiwVariant(aActionsList) ); |
|
545 |
|
546 TLiwGenericParam item( KFilter, TLiwVariant( filter )); |
|
547 inParamList->AppendL( item ); |
|
548 iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList); |
|
549 CleanupStack::PopAndDestroy( filter ); |
|
550 outParamList->Reset(); |
|
551 inParamList->Reset(); |
|
552 |
|
553 } |
|
554 |
|
555 // --------------------------------------------------------------------------- |
|
556 // SetCommandBuffer |
|
557 // --------------------------------------------------------------------------- |
|
558 // |
|
559 void CWrtData::SetCommandBuffer(TAny* aAny, const TDesC8& aNameSpace ) |
|
560 { |
|
561 iPluginId.Copy(aNameSpace); |
|
562 iCpsExecute = reinterpret_cast <MAiCpsCommandBuffer* > ( aAny ); |
|
563 if ( iCpsExecute ) |
|
564 { |
|
565 iInterface = iCpsExecute->CpsInterface(); |
|
566 iServiceHandler = iCpsExecute->ServiceHandler(); |
|
567 } |
|
568 } |
|
569 |
|
570 // End of file |
|
571 |