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