|
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: Homescreen Data plug-in publisher |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <ecom/ecom.h> |
|
19 #include <LiwServiceHandler.h> |
|
20 #include <aipluginsettings.h> |
|
21 #include <utf.h> |
|
22 |
|
23 #include "sapidata.h" |
|
24 #include "sapidatapluginconst.h" |
|
25 #include "sapidataobserver.h" |
|
26 #include "sapidataplugin.h" |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Symbian 2nd phase constructor can leave |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CContentItem* CContentItem::NewL() |
|
34 { |
|
35 CContentItem* self = new (ELeave) CContentItem(); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Default constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CContentItem::CContentItem() |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Symbian 2nd phase constructor can leave |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CContentItem::ConstructL() |
|
55 { |
|
56 iId = KErrNotFound; |
|
57 iName = NULL; |
|
58 iContentType = NULL; |
|
59 iType = NULL; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Destructor |
|
64 // Deletes all data created to heap |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CContentItem::~CContentItem() |
|
68 { |
|
69 delete iName; |
|
70 delete iContentType; |
|
71 delete iType; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // Symbian 2nd phase constructor can leave |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CSapiData* CSapiData::NewL(CSapiDataPlugin* aPlugin) |
|
79 { |
|
80 CSapiData* self = new (ELeave) CSapiData(); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(aPlugin); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Default constructor |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CSapiData::CSapiData() |
|
92 { |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // Symbian 2nd phase constructor can leave |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CSapiData::ConstructL(CSapiDataPlugin* aPlugin) |
|
100 { |
|
101 iPlugin = aPlugin; |
|
102 iCommandName = NULL; |
|
103 iContentId = NULL; |
|
104 iContentType = NULL; |
|
105 iUpdateNeeded = EFalse; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Destructor |
|
110 // Deletes all data created to heap |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 CSapiData::~CSapiData() |
|
114 { |
|
115 delete iCommandName; |
|
116 delete iPublisher; |
|
117 delete iContentType; |
|
118 delete iContentId; |
|
119 |
|
120 |
|
121 if(iPubObserver) |
|
122 { |
|
123 TRAP_IGNORE(iPubObserver->ReleaseL() ); |
|
124 delete iPubObserver; |
|
125 iPubObserver = NULL; |
|
126 } |
|
127 if(iContentObserver) |
|
128 { |
|
129 TRAP_IGNORE(iContentObserver->ReleaseL() ); |
|
130 delete iContentObserver; |
|
131 iContentObserver = NULL; |
|
132 } |
|
133 if( iInterface ) |
|
134 { |
|
135 iInterface->Close(); |
|
136 iInterface = NULL; |
|
137 } |
|
138 if( iServiceHandler ) |
|
139 { |
|
140 iServiceHandler->Reset(); |
|
141 delete iServiceHandler; |
|
142 iServiceHandler = NULL; |
|
143 } |
|
144 iMenuItems.ResetAndDestroy(); |
|
145 iMenuTriggers.ResetAndDestroy(); |
|
146 iItemList.ResetAndDestroy(); |
|
147 // not owned |
|
148 iPlugin = NULL; |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // ConfigureL |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CSapiData::ConfigureL(RAiSettingsItemArray& aConfigurations ) |
|
156 { |
|
157 HBufC8* serviceName = NULL; |
|
158 HBufC8* interfaceName = NULL; |
|
159 |
|
160 TInt count = aConfigurations.Count(); |
|
161 |
|
162 for(TInt i = 0;i<count;i++) |
|
163 { |
|
164 MAiPluginConfigurationItem& confItem = ( aConfigurations[i] )->AiPluginConfigurationItem(); |
|
165 // if owner is plugin then it (key,value) is for plugin configurations items |
|
166 if(confItem.Owner() == KPlugin()) |
|
167 { |
|
168 if(confItem.Name() == KService()) |
|
169 { |
|
170 serviceName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(confItem.Value()); |
|
171 } |
|
172 else if( confItem.Name() == KInterface() ) |
|
173 { |
|
174 interfaceName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(confItem.Value()); |
|
175 } |
|
176 else if( confItem.Name() == KCommand() ) |
|
177 { |
|
178 iCommandName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(confItem.Value()); |
|
179 } |
|
180 else if( confItem.Name() == KPublisher16() ) |
|
181 { |
|
182 iPublisher = confItem.Value().AllocL(); |
|
183 } |
|
184 } |
|
185 else if ( confItem.Name() == KContentType16() ) |
|
186 { |
|
187 HBufC* objectId = confItem.Owner().AllocLC(); |
|
188 objectId->Des().Delete(0, objectId->LocateReverse(KPluginNameSeprator) + 1); |
|
189 |
|
190 CContentItem *conItem = CContentItem::NewL(); |
|
191 conItem->iName = objectId->AllocL(); |
|
192 conItem->iContentType = confItem.Value().AllocL(); |
|
193 conItem->iType = iPlugin->GetTypeL( *objectId ).AllocL(); |
|
194 conItem->iId = iPlugin->GetIdL(*objectId ); |
|
195 iItemList.AppendL( conItem ); |
|
196 |
|
197 CleanupStack::PopAndDestroy(objectId); |
|
198 } |
|
199 } |
|
200 |
|
201 iItemCount = iItemList.Count(); |
|
202 |
|
203 if( !serviceName || !interfaceName || !iCommandName |
|
204 || !iContentId || !iPublisher || !iItemCount ) |
|
205 { |
|
206 // No service to offer without plugin configurations |
|
207 User::Leave( KErrNotSupported ); |
|
208 } |
|
209 iServiceHandler = CLiwServiceHandler::NewL(); |
|
210 |
|
211 // for convenience keep pointers to Service Handler param lists |
|
212 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
213 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
214 |
|
215 CLiwCriteriaItem* criteriaItem = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, *interfaceName , *serviceName ); |
|
216 criteriaItem->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
217 // Interface name |
|
218 RCriteriaArray criteriaArray; |
|
219 criteriaArray.AppendL( criteriaItem ); |
|
220 // attach Liw criteria |
|
221 iServiceHandler->AttachL( criteriaArray ); |
|
222 iServiceHandler->ExecuteServiceCmdL( *criteriaItem, *inParamList, *outParamList ); |
|
223 |
|
224 CleanupStack::PopAndDestroy(criteriaItem); |
|
225 criteriaArray.Reset(); |
|
226 |
|
227 // extract CPS interface from output params |
|
228 TInt pos( 0 ); |
|
229 outParamList->FindFirst( pos, *interfaceName ); |
|
230 if( pos != KErrNotFound ) |
|
231 { |
|
232 //iInterface is MLiwInterface* |
|
233 iInterface = (*outParamList)[pos].Value().AsInterface(); |
|
234 User::LeaveIfNull( iInterface ); |
|
235 } |
|
236 else |
|
237 { |
|
238 User::Leave( KErrNotFound ); |
|
239 } |
|
240 inParamList->Reset(); |
|
241 outParamList->Reset(); |
|
242 delete interfaceName; |
|
243 delete serviceName; |
|
244 |
|
245 //Gets the menu items from the publisher registry |
|
246 GetMenuItemsL(); |
|
247 |
|
248 iContentObserver = CSapiDataObserver::NewL( iInterface, this ); |
|
249 iPubObserver = CSapiDataObserver::NewL( iInterface, this ); |
|
250 } |
|
251 |
|
252 void CSapiData::SetContentIdL(const TDesC8& aId) |
|
253 { |
|
254 iContentId = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aId); |
|
255 } |
|
256 // --------------------------------------------------------------------------- |
|
257 // GetMenuItemsL |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 void CSapiData::GetMenuItemsL() |
|
261 { |
|
262 if(iInterface && iItemCount > 0) |
|
263 { |
|
264 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
265 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
266 filter->InsertL( KPublisherId, TLiwVariant(iPublisher )); |
|
267 //append filter to input param |
|
268 ExecuteCommandL( KPubData, filter, outParamList ); |
|
269 CleanupStack::PopAndDestroy( filter ); |
|
270 //extracts data map |
|
271 TInt pos = 0; |
|
272 outParamList->FindFirst( pos, KResults ); |
|
273 if( pos != KErrNotFound ) |
|
274 // results present |
|
275 { |
|
276 //extract iterator on results list |
|
277 TLiwVariant variant = (*outParamList)[pos].Value(); |
|
278 variant.PushL(); |
|
279 CLiwIterable* iterable = variant.AsIterable(); |
|
280 iterable->Reset(); |
|
281 |
|
282 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
283 //considering publisher is unique reading only first entry |
|
284 if( iterable->NextL( variant ) ) |
|
285 { |
|
286 //extract content map |
|
287 variant.Get( *map ); |
|
288 if( map->FindL( KDataMap, variant) ) |
|
289 { |
|
290 variant.Get( *map ); |
|
291 } |
|
292 } |
|
293 iterable->Reset(); |
|
294 variant.Reset(); |
|
295 if ( map->FindL( KMenuItems, variant ) ) |
|
296 { |
|
297 CLiwDefaultMap *menuMap = CLiwDefaultMap::NewLC(); |
|
298 variant.Get( *menuMap ); |
|
299 for ( TInt i = 0; i < menuMap->Count(); i++) |
|
300 { |
|
301 menuMap->FindL(menuMap->AtL(i), variant ); |
|
302 HBufC8* menuItem = variant.AsData().AllocLC(); |
|
303 if ( menuItem->Length()> 0 ) |
|
304 { |
|
305 iMenuTriggers.AppendL( menuItem ); |
|
306 CleanupStack::Pop( menuItem ); |
|
307 HBufC* triggerName = CnvUtfConverter::ConvertToUnicodeFromUtf8L(menuMap->AtL(i)); |
|
308 CleanupStack::PushL( triggerName ); |
|
309 iMenuItems.AppendL( triggerName ); |
|
310 CleanupStack::Pop( triggerName ); |
|
311 } |
|
312 else |
|
313 { |
|
314 CleanupStack::PopAndDestroy( menuItem ); |
|
315 } |
|
316 variant.Reset(); |
|
317 } |
|
318 CleanupStack::PopAndDestroy( menuMap ); |
|
319 } |
|
320 CleanupStack::PopAndDestroy( map ); |
|
321 CleanupStack::PopAndDestroy( &variant ); |
|
322 } |
|
323 outParamList->Reset(); |
|
324 } |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // CreateFilterL |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 CLiwDefaultMap* CSapiData::CreateFilterLC(const TDesC& aContentType, |
|
332 const TDesC& aContentId) |
|
333 { |
|
334 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
335 filter->InsertL( KPublisherId, TLiwVariant(iPublisher )); |
|
336 filter->InsertL( KContentId, TLiwVariant(aContentId )); |
|
337 filter->InsertL( KContentType, TLiwVariant(aContentType )); |
|
338 return filter; |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // CreateFilterL |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 CLiwDefaultMap* CSapiData::CreateFilterLC(const TDesC& aContentType) |
|
346 { |
|
347 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
348 filter->InsertL( KPublisherId, TLiwVariant(iPublisher )); |
|
349 filter->InsertL( KContentId, TLiwVariant(iContentId )); |
|
350 filter->InsertL( KContentType, TLiwVariant(aContentType )); |
|
351 return filter; |
|
352 } |
|
353 |
|
354 // --------------------------------------------------------------------------- |
|
355 // CreateFilterL |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 CLiwDefaultMap* CSapiData::CreateFilterLC() |
|
359 { |
|
360 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
361 filter->InsertL( KPublisherId, TLiwVariant(iPublisher )); |
|
362 filter->InsertL( KContentId, TLiwVariant(iContentId )); |
|
363 filter->InsertL( KContentType, TLiwVariant(KAll)); |
|
364 return filter; |
|
365 } |
|
366 |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // Update |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 TBool CSapiData::CanUpdate( TDesC& aPublisher, TDesC& aContentType, |
|
373 TDesC& aContentId) |
|
374 { |
|
375 TBool res = EFalse; |
|
376 if( aPublisher == *iPublisher |
|
377 && aContentId == *iContentId ) |
|
378 { |
|
379 if ( aContentType != KAll ) |
|
380 { |
|
381 for (TInt i = 0; i < iItemCount ; i++) |
|
382 { |
|
383 if ( aContentType == iItemList[i]->iContentType ) |
|
384 { |
|
385 res = ETrue; |
|
386 break; |
|
387 } |
|
388 } |
|
389 } |
|
390 else |
|
391 { |
|
392 res = ETrue; |
|
393 } |
|
394 } |
|
395 else |
|
396 { |
|
397 res = EFalse; |
|
398 } |
|
399 return res; |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // RemoveL |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CSapiData::RemoveL( MAiContentObserver* aObserver, TDesC& aContentType ) |
|
407 { |
|
408 for(TInt index = 0; index < iItemCount; index++) |
|
409 { |
|
410 if ( aContentType == iItemList[index]->iContentType ) |
|
411 { |
|
412 iPlugin->Clean( aObserver, iItemList[index]->iId ); |
|
413 } |
|
414 } |
|
415 } |
|
416 |
|
417 |
|
418 // --------------------------------------------------------------------------- |
|
419 // HasMenuItem |
|
420 // --------------------------------------------------------------------------- |
|
421 // |
|
422 TBool CSapiData::HasMenuItem(const TDesC& aMenuItem ) |
|
423 { |
|
424 TBool found = EFalse; |
|
425 for (TInt i = 0; i < iMenuItems.Count(); i++ ) |
|
426 { |
|
427 if( aMenuItem == iMenuItems[i] ) |
|
428 { |
|
429 found = ETrue; |
|
430 break; |
|
431 } |
|
432 } |
|
433 return found; |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // PublishL |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 void CSapiData::PublishL( MAiContentObserver* aObserver, const TDesC& aContentType ) |
|
441 { |
|
442 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
443 //Create filter criteria for requested entries in form of LIW map: |
|
444 CLiwDefaultMap* filter = CreateFilterLC( aContentType ); |
|
445 ExecuteCommandL( KCpData, filter, outParamList ); |
|
446 CleanupStack::PopAndDestroy( filter ); |
|
447 |
|
448 TInt pos = 0; |
|
449 outParamList->FindFirst( pos, KResults ); |
|
450 if( pos != KErrNotFound ) |
|
451 // results present |
|
452 { |
|
453 //extract iterator on results list |
|
454 TLiwVariant variant = (*outParamList)[pos].Value(); |
|
455 variant.PushL(); |
|
456 CLiwIterable* iterable = variant.AsIterable(); |
|
457 iterable->Reset(); |
|
458 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
459 |
|
460 while( iterable->NextL( variant ) ) |
|
461 { |
|
462 //extract content map |
|
463 if( variant.Get( *map ) && |
|
464 // Find the data map |
|
465 map->FindL( KDataMap, variant) ) |
|
466 { |
|
467 CLiwDefaultMap *datamap = CLiwDefaultMap::NewLC(); |
|
468 if ( variant.Get( *datamap ) ) |
|
469 { |
|
470 PublishDataL(aObserver, datamap); |
|
471 } |
|
472 CleanupStack::PopAndDestroy( datamap ); |
|
473 } |
|
474 } |
|
475 CleanupStack::PopAndDestroy( map ); |
|
476 CleanupStack::PopAndDestroy( &variant ); |
|
477 } |
|
478 outParamList->Reset(); |
|
479 } |
|
480 |
|
481 void CSapiData::PublishDataL(MAiContentObserver* aObserver, CLiwDefaultMap* aDataMap ) |
|
482 { |
|
483 for(TInt pIndex = 0; pIndex < iItemCount; pIndex++) |
|
484 { |
|
485 // result name to find |
|
486 TLiwVariant variant; |
|
487 HBufC8* itemName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*iItemList[pIndex]->iName); |
|
488 CleanupStack::PushL( itemName ); |
|
489 if ( aDataMap->FindL( *itemName, variant ) ) |
|
490 { |
|
491 TPtrC valPtr; |
|
492 if( iItemList[pIndex]->iType->Des() == KText ) |
|
493 { |
|
494 valPtr.Set( variant.AsDes() ); |
|
495 iPlugin->PublishTextL( aObserver, iItemList[pIndex]->iId, valPtr ); |
|
496 } |
|
497 else if( iItemList[pIndex]->iType->Des() == KImage ) |
|
498 { |
|
499 TInt handle = KErrBadHandle; |
|
500 // read as a image handle |
|
501 if( ! variant.Get( handle ) ) |
|
502 { |
|
503 // no handle, so read as image path |
|
504 variant.Get( valPtr ); |
|
505 iPlugin->PublishImageL(aObserver, iItemList[pIndex]->iId, valPtr ); |
|
506 } |
|
507 else |
|
508 { |
|
509 TInt maskHandle = KErrBadHandle; |
|
510 //Look for image mask |
|
511 HBufC8* maskKey = HBufC8::NewLC( itemName->Length() + KMask().Length() ); |
|
512 TPtr8 maskKeyPtr = maskKey->Des(); |
|
513 maskKeyPtr.Append( *itemName ); |
|
514 maskKeyPtr.Append( KMask ); |
|
515 if ( aDataMap->FindL( maskKeyPtr, variant ) ) |
|
516 { |
|
517 variant.Get( maskHandle ); |
|
518 } |
|
519 CleanupStack::PopAndDestroy( maskKey ); |
|
520 iPlugin->PublishImageL(aObserver, iItemList[pIndex]->iId, handle, maskHandle ); |
|
521 } |
|
522 } |
|
523 } |
|
524 variant.Reset(); |
|
525 CleanupStack::PopAndDestroy( itemName ); |
|
526 } |
|
527 } |
|
528 // --------------------------------------------------------------------------- |
|
529 // ExecuteCommandL |
|
530 // --------------------------------------------------------------------------- |
|
531 // |
|
532 void CSapiData::ExecuteCommandL(const TDesC& aRegistry, CLiwDefaultMap* aInFilter, |
|
533 CLiwGenericParamList* aOutParamList) |
|
534 { |
|
535 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
536 |
|
537 TLiwGenericParam type( KType, TLiwVariant( aRegistry ) ); |
|
538 inParamList->AppendL( type ); |
|
539 |
|
540 //append filter to input param |
|
541 TLiwGenericParam item( KFilter, TLiwVariant( aInFilter )); |
|
542 inParamList->AppendL( item ); |
|
543 |
|
544 // execute service.It is assumed that iInterface is already initiated |
|
545 if(iInterface) |
|
546 { |
|
547 iInterface->ExecuteCmdL( *iCommandName, *inParamList, *aOutParamList); |
|
548 } |
|
549 else |
|
550 { |
|
551 User::Leave( KErrNotSupported ); |
|
552 } |
|
553 type.Reset(); |
|
554 item.Reset(); |
|
555 inParamList->Reset(); |
|
556 } |
|
557 |
|
558 // --------------------------------------------------------------------------- |
|
559 // ExecuteActionL |
|
560 // --------------------------------------------------------------------------- |
|
561 // |
|
562 void CSapiData::ExecuteActionL(const TDesC& aObjectId, const TDesC& aTrigger ) |
|
563 { |
|
564 HBufC8* triggerName = HBufC8::NewLC( KSAPIContentNameMaxLength ); |
|
565 |
|
566 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
567 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
568 CLiwDefaultMap* filter = NULL; |
|
569 |
|
570 triggerName->Des().Copy(aTrigger); |
|
571 if ( aObjectId == KPubData ) |
|
572 { |
|
573 // this trigger belongs to publisher registery. |
|
574 // in such case it is assumed that all the items in the widgets |
|
575 // belongs to same publisher, type and id. |
|
576 TLiwGenericParam cptype( KType, TLiwVariant( KPubData ) ); |
|
577 inParamList->AppendL( cptype ); |
|
578 cptype.Reset(); |
|
579 // use the first item configuration to create the filter |
|
580 filter = CreateFilterLC( KWidget() ); |
|
581 } |
|
582 else |
|
583 { |
|
584 if ( aObjectId == KMenuItem16 ) |
|
585 { |
|
586 TInt pos = KErrNotFound; |
|
587 for (TInt i = 0; i < iMenuItems.Count(); i++) |
|
588 { |
|
589 if ( aTrigger == iMenuItems[i] ) |
|
590 { |
|
591 pos = i; |
|
592 break; |
|
593 } |
|
594 } |
|
595 if( pos == KErrNotFound ) |
|
596 { |
|
597 // No such menu items |
|
598 CleanupStack::PopAndDestroy( triggerName ); |
|
599 return; |
|
600 } |
|
601 triggerName->Des().Copy( iMenuTriggers[pos]->Des() ); |
|
602 filter = CreateFilterLC( KWidget() ); |
|
603 } |
|
604 else |
|
605 { |
|
606 //Create filter criteria for requested entries in form of LIW map: |
|
607 filter = CreateFilterLC( aObjectId ); |
|
608 } |
|
609 //append type to inparam list |
|
610 TLiwGenericParam cptype( KType, TLiwVariant( KCpData ) ); |
|
611 inParamList->AppendL( cptype ); |
|
612 cptype.Reset(); |
|
613 } |
|
614 |
|
615 filter->InsertL( KActionTrigger, TLiwVariant( triggerName->Des() ) ); |
|
616 //append filter to input param |
|
617 TLiwGenericParam item( KFilter, TLiwVariant( filter ) ); |
|
618 inParamList->AppendL( item ); |
|
619 iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList ); |
|
620 |
|
621 CleanupStack::PopAndDestroy( filter ); |
|
622 CleanupStack::PopAndDestroy( triggerName ); |
|
623 item.Reset(); |
|
624 |
|
625 inParamList->Reset(); |
|
626 outParamList->Reset(); |
|
627 |
|
628 } |
|
629 |
|
630 // --------------------------------------------------------------------------- |
|
631 // RegisterPublisherObserverL |
|
632 // --------------------------------------------------------------------------- |
|
633 // |
|
634 void CSapiData::RegisterPublisherObserverL() |
|
635 { |
|
636 if ( iItemCount > 0) |
|
637 { |
|
638 CLiwDefaultMap* pubRegFilter = CreateFilterLC( KAll(), KAll() ); |
|
639 pubRegFilter->InsertL( KOperation, TLiwVariant( KUpdate ) ); |
|
640 iPubObserver->RegisterL( pubRegFilter, KPubData() ); |
|
641 CleanupStack::PopAndDestroy( pubRegFilter ); |
|
642 } |
|
643 } |
|
644 |
|
645 // --------------------------------------------------------------------------- |
|
646 // RegisterContentObserverL |
|
647 // --------------------------------------------------------------------------- |
|
648 // |
|
649 void CSapiData::RegisterContentObserverL() |
|
650 { |
|
651 if ( iItemCount > 0) |
|
652 { |
|
653 CLiwDefaultMap* conRegFilter = CreateFilterLC(); |
|
654 conRegFilter->InsertL( KOperation, TLiwVariant( KAddUpdateDelete ) ); |
|
655 iContentObserver->RegisterL( conRegFilter, KCpData() ); |
|
656 CleanupStack::PopAndDestroy( conRegFilter ); |
|
657 } |
|
658 } |
|
659 |
|
660 // --------------------------------------------------------------------------- |
|
661 // RefreshL |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 void CSapiData::RefreshL( TDesC& aPublisher, TDesC& aContentType, |
|
665 TDesC& aContentId, TDesC& aOperation ) |
|
666 { |
|
667 if ( CanUpdate( aPublisher, aContentType, aContentId ) ) |
|
668 { |
|
669 iPlugin->RefreshL( aContentType, aOperation); |
|
670 } |
|
671 } |
|
672 |
|
673 // --------------------------------------------------------------------------- |
|
674 // IsPluginActive |
|
675 // --------------------------------------------------------------------------- |
|
676 // |
|
677 TBool CSapiData::IsPluginActive() |
|
678 { |
|
679 return iPlugin->IsActive(); |
|
680 } |
|
681 |
|
682 // --------------------------------------------------------------------------- |
|
683 // PublisherStatusL |
|
684 // --------------------------------------------------------------------------- |
|
685 // |
|
686 void CSapiData::ChangePublisherStatusL(const TDesC& aStatus) |
|
687 { |
|
688 CLiwGenericParamList* inParamList = &iServiceHandler->InParamListL(); |
|
689 CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL(); |
|
690 HBufC8* triggerName = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aStatus); |
|
691 CleanupStack::PushL( triggerName ); |
|
692 |
|
693 TLiwGenericParam type( KType, TLiwVariant( KPubData ) ); |
|
694 inParamList->AppendL( type ); |
|
695 |
|
696 CLiwDefaultMap* filter = CreateFilterLC( KWidget() ); |
|
697 filter->InsertL(KActionTrigger, TLiwVariant(triggerName->Des()) ); |
|
698 |
|
699 TLiwGenericParam item( KFilter, TLiwVariant( filter )); |
|
700 inParamList->AppendL( item ); |
|
701 |
|
702 if(iInterface) |
|
703 { |
|
704 iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList); |
|
705 } |
|
706 else |
|
707 { |
|
708 User::Leave( KErrNotSupported ); |
|
709 } |
|
710 |
|
711 CleanupStack::PopAndDestroy( filter ); |
|
712 CleanupStack::PopAndDestroy( triggerName ); |
|
713 inParamList->Reset(); |
|
714 outParamList->Reset(); |
|
715 } |
|
716 |
|
717 // --------------------------------------------------------------------------- |
|
718 // ResumeL |
|
719 // --------------------------------------------------------------------------- |
|
720 // |
|
721 void CSapiData::ResumeL() |
|
722 { |
|
723 if ( iUpdateNeeded ) |
|
724 { |
|
725 iPlugin->PublishL(); |
|
726 iUpdateNeeded = EFalse; |
|
727 } |
|
728 ChangePublisherStatusL( KResume ); |
|
729 } |
|
730 |
|
731 // --------------------------------------------------------------------------- |
|
732 // SuspendL |
|
733 // --------------------------------------------------------------------------- |
|
734 // |
|
735 void CSapiData::SuspendL() |
|
736 { |
|
737 ChangePublisherStatusL( KSuspend ); |
|
738 } |
|
739 |
|
740 // --------------------------------------------------------------------------- |
|
741 // ActivateL |
|
742 // --------------------------------------------------------------------------- |
|
743 // |
|
744 void CSapiData::ActivateL() |
|
745 { |
|
746 ChangePublisherStatusL( KActive ); |
|
747 } |
|
748 |
|
749 // --------------------------------------------------------------------------- |
|
750 // DeActivateL |
|
751 // --------------------------------------------------------------------------- |
|
752 // |
|
753 void CSapiData::DeActivateL() |
|
754 { |
|
755 ChangePublisherStatusL( KDeActive ); |
|
756 } |
|
757 |
|
758 // --------------------------------------------------------------------------- |
|
759 // OnLineL |
|
760 // --------------------------------------------------------------------------- |
|
761 // |
|
762 void CSapiData::OnLineL() |
|
763 { |
|
764 ChangePublisherStatusL( KOnLine ); |
|
765 } |
|
766 |
|
767 // --------------------------------------------------------------------------- |
|
768 // offLineL |
|
769 // --------------------------------------------------------------------------- |
|
770 // |
|
771 void CSapiData::OffLineL() |
|
772 { |
|
773 ChangePublisherStatusL( KOffLine ); |
|
774 } |
|
775 |
|
776 // --------------------------------------------------------------------------- |
|
777 // InActiveL |
|
778 // --------------------------------------------------------------------------- |
|
779 // |
|
780 void CSapiData::InActiveL() |
|
781 { |
|
782 ChangePublisherStatusL( KInActive ); |
|
783 } |
|
784 |
|
785 // --------------------------------------------------------------------------- |
|
786 // UpdatePublisherStatusL |
|
787 // --------------------------------------------------------------------------- |
|
788 // |
|
789 void CSapiData::UpdatePublisherStatusL( TDesC& aPublisher ) |
|
790 { |
|
791 if ( aPublisher == iPublisher ) |
|
792 { |
|
793 // Resend the plugin status to publisher |
|
794 ActivateL(); |
|
795 if ( iPlugin->IsActive() ) |
|
796 { |
|
797 ResumeL(); |
|
798 } |
|
799 else |
|
800 { |
|
801 SuspendL(); |
|
802 } |
|
803 // forward the network status if it uses. |
|
804 if ( iPlugin->NetworkStatus() == CSapiDataPlugin::EOnline ) |
|
805 { |
|
806 OnLineL(); |
|
807 } |
|
808 else if ( iPlugin->NetworkStatus() == CSapiDataPlugin::EOffline ) |
|
809 { |
|
810 OffLineL(); |
|
811 } |
|
812 } |
|
813 } |
|
814 |
|
815 // --------------------------------------------------------------------------- |
|
816 // ResolveSkinItemId |
|
817 // --------------------------------------------------------------------------- |
|
818 // |
|
819 TBool CSapiData::ResolveSkinIdAndMifId( const TDesC& aPath, TAknsItemID& aItemId, |
|
820 TInt& abitmapId, TInt& aMaskId, TDes& aFilename ) |
|
821 { |
|
822 // Syntax: skin( <major> <minor> ):mif(filename bimapId maskId) |
|
823 TInt error = KErrNotFound; |
|
824 TInt pos = aPath.FindF( KSkin ); |
|
825 if( pos != KErrNotFound ) |
|
826 { |
|
827 // Skip skin token |
|
828 pos += KSkin().Length(); |
|
829 |
|
830 // Initialize lexer |
|
831 TLex lex( aPath.Mid( pos ) ); |
|
832 lex.SkipSpace(); |
|
833 |
|
834 // Check left parenthesis |
|
835 if (lex.Get() == KLeftParenthesis ) |
|
836 { |
|
837 //lex.SkipSpace(); |
|
838 |
|
839 TInt majorId( 0 ); |
|
840 TInt minorId( 0 ); |
|
841 |
|
842 // Resolve major id |
|
843 error = lex.Val( majorId ); |
|
844 |
|
845 // Resolve minor id |
|
846 lex.SkipSpace(); |
|
847 error |= lex.Val( minorId ); |
|
848 |
|
849 // initilize skin item id object |
|
850 aItemId.Set( majorId, minorId ); |
|
851 } |
|
852 } |
|
853 |
|
854 if( (error == KErrNone && aPath.FindF( KColon ) != KErrNotFound ) |
|
855 || ( error == KErrNotFound ) ) |
|
856 { |
|
857 error = KErrNotFound; |
|
858 pos = aPath.FindF( KMif ); |
|
859 if ( pos != KErrNotFound ) |
|
860 { |
|
861 pos += KMif().Length(); |
|
862 // Initialize lexer |
|
863 TLex lex( aPath.Mid( pos ) ); |
|
864 lex.SkipSpace(); |
|
865 |
|
866 // Check left parenthesis |
|
867 if (lex.Get() == KLeftParenthesis ) |
|
868 { |
|
869 lex.SkipSpaceAndMark(); |
|
870 lex.SkipCharacters(); |
|
871 // Resolve MifFile name |
|
872 aFilename.Copy(lex.MarkedToken()); |
|
873 if( aFilename.Length()!= 0) |
|
874 { |
|
875 // Resolve major id |
|
876 lex.SkipSpace(); |
|
877 error = lex.Val( abitmapId ); |
|
878 |
|
879 // Resolve minor id |
|
880 lex.SkipSpace(); |
|
881 error |= lex.Val( aMaskId ); |
|
882 } |
|
883 else |
|
884 { |
|
885 error = KErrNotFound; |
|
886 } |
|
887 } |
|
888 } |
|
889 } |
|
890 return (error == KErrNone ); |
|
891 } |
|
892 |
|
893 // --------------------------------------------------------------------------- |
|
894 // SetUpdateNeeded |
|
895 // --------------------------------------------------------------------------- |
|
896 // |
|
897 void CSapiData::SetUpdateNeeded(TBool aStatus) |
|
898 { |
|
899 iUpdateNeeded = aStatus; |
|
900 } |