idlefw/plugins/wrtdataplugin/src/wrtdata.cpp
changeset 3 ff572005ac23
parent 1 844b978f8d5e
child 9 d0529222e3f0
equal deleted inserted replaced
2:b7904b40483f 3:ff572005ac23
    14 * Description:
    14 * Description:
    15 * Profile plug-in publisher
    15 * Profile plug-in publisher
    16 *
    16 *
    17 */
    17 */
    18 
    18 
       
    19 
       
    20 // INCLUDE FILES
    19 #include <ecom/ecom.h>
    21 #include <ecom/ecom.h>
    20 #include <liwservicehandler.h>
    22 #include <liwservicehandler.h>
    21 #include <aipluginsettings.h>
    23 #include <aipluginsettings.h>
    22 
    24 #include <apgcli.h>
       
    25 #include <apgicnfl.h> 
       
    26 #include <bautils.H> 
    23 
    27 
    24 #include "wrtdata.h"
    28 #include "wrtdata.h"
    25 #include "wrtdatapluginconst.h"
    29 #include "wrtdatapluginconst.h"
    26 #include "wrtdataobserver.h"
    30 #include "wrtdataobserver.h"
    27 #include "wrtdataplugin.h"
    31 #include "wrtdataplugin.h"
       
    32 
    28 // ======== MEMBER FUNCTIONS ========
    33 // ======== MEMBER FUNCTIONS ========
    29 	
    34 	
    30 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
    31 // Symbian 2nd phase constructor can leave
    36 // Symbian 2nd phase constructor can leave
    32 // ---------------------------------------------------------------------------
    37 // ---------------------------------------------------------------------------
    97     // not owned
   102     // not owned
    98     iPlugin = NULL;
   103     iPlugin = NULL;
    99     }
   104     }
   100 
   105 
   101 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   102 // ConfigureL
   107 // CWrtData::ConfigureL
   103 // ---------------------------------------------------------------------------
   108 // ---------------------------------------------------------------------------
   104 //
   109 //
   105 void CWrtData::ConfigureL(RAiSettingsItemArray& aConfigurations )
   110 void CWrtData::ConfigureL(RAiSettingsItemArray& aConfigurations )
   106     {
   111     {
   107     HBufC8* serviceName = HBufC8::NewLC( KWRTContentValueMaxLength );
   112     HBufC8* serviceName = HBufC8::NewLC( KWRTContentValueMaxLength );
   189  
   194  
   190     iObserver = CWrtDataObserver::NewL( iInterface, this );   
   195     iObserver = CWrtDataObserver::NewL( iInterface, this );   
   191     }
   196     }
   192 
   197 
   193 // ---------------------------------------------------------------------------
   198 // ---------------------------------------------------------------------------
   194 // GetMenuItemsL
   199 // CWrtData::HasMenuItem
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TBool CWrtData::HasMenuItem(const TDesC16& aMenuItem )
       
   203     {
       
   204     TBool found = EFalse;
       
   205     for (TInt i = 0; i < iMenuItems.Count(); i++ )
       
   206         {
       
   207         if( aMenuItem == iMenuItems[i] )
       
   208             {
       
   209             found =  ETrue;
       
   210             break;
       
   211             }
       
   212         }
       
   213     return found;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CWrtData::RegisterL
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void CWrtData::RegisterL()
       
   221     {
       
   222     CLiwDefaultMap* filter = CreateFilterLC();
       
   223     filter->InsertL( KOperation, TLiwVariant( KAddUpdateDelete ) );
       
   224     iObserver->RegisterL(filter);
       
   225     CleanupStack::PopAndDestroy( filter );
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CWrtData::UpdatePublisherStatusL
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CWrtData::UpdatePublisherStatusL()
       
   233     {
       
   234      // Resent the plugin status to publisher
       
   235      ActivateL();
       
   236      if ( iPlugin->IsActive() )
       
   237          {
       
   238          ResumeL();
       
   239          }
       
   240      else
       
   241          {
       
   242          SuspendL();
       
   243          }
       
   244       // forward the network status if it uses.
       
   245     if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOnline )
       
   246         {
       
   247         OnLineL();
       
   248         }
       
   249     else if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOffline )
       
   250         {
       
   251         OffLineL();
       
   252         }
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CWrtData::PublishDefaultImageL
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CWrtData::PublishDefaultImageL( MAiContentObserver* aObserver )
       
   260     {
       
   261     TBuf<KWRTAppUidLenth> appUidStr;
       
   262     TBuf<KWRTContentValueMaxLength> appName;
       
   263     GetWidgetNameAndUidL( appName, appUidStr );
       
   264     
       
   265     TUid appUid;
       
   266     if ( ResolveUid (appUidStr, appUid ) )
       
   267         {
       
   268 #ifdef WRT_PREDEFINED_IMAGE         
       
   269         RFs rfs;
       
   270         User::LeaveIfError( rfs.Connect() );
       
   271 
       
   272         TFileName privatePath;
       
   273         rfs.PrivatePath(privatePath);
       
   274         privatePath.Insert(0,KDrive);
       
   275         privatePath.Append( KImgFolder );
       
   276       
       
   277         appUidStr.Copy( appUid.Name());
       
   278         appUidStr.Delete(0,1);
       
   279         appUidStr.Delete( appUidStr.Length() -1, 1);
       
   280         privatePath.Append (appUidStr );
       
   281         privatePath.Append ( KJPEG );
       
   282         if ( BaflUtils::FileExists(rfs,privatePath) )
       
   283             {
       
   284             // Publish predefined jpeg image
       
   285             iPlugin->PublishImageL( aObserver, CWrtDataPlugin::EImage1,privatePath);
       
   286             }
       
   287         else
       
   288             {
       
   289             privatePath.Delete( privatePath.Length() - 4 , 4);
       
   290             privatePath.Append( KPNG );
       
   291             if ( BaflUtils::FileExists(rfs,privatePath) )
       
   292                {
       
   293                // Publish predefined image
       
   294                iPlugin->PublishImageL( aObserver, CWrtDataPlugin::EImage1,privatePath);
       
   295                }
       
   296             else
       
   297                 {
       
   298 #endif                 
       
   299                 TInt handle = KErrNotFound;
       
   300                 TInt mask = KErrNotFound;
       
   301                 CreateIconFromUidL( handle, mask, appUid );
       
   302                 // Publish widget apparc image
       
   303                 iPlugin->PublishImageL( aObserver, CWrtDataPlugin::EDefaultImage,handle,mask);
       
   304                 if ( appName.Length() > 0)
       
   305                    {
       
   306                    // Publish Widget Name
       
   307                    iPlugin->PublishTextL( aObserver, CWrtDataPlugin::EDefaultText, appName);
       
   308                    }
       
   309 #ifdef WRT_PREDEFINED_IMAGE                
       
   310                 }
       
   311             }
       
   312         rfs.Close();
       
   313 #endif        
       
   314         }
       
   315     
       
   316     // Show loading animation
       
   317     iPlugin->ShowLoadingIcon(aObserver);
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CWrtData::PublishL
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CWrtData::PublishL( MAiContentObserver* aObserver, CLiwDefaultMap* aDataMap ) 
       
   325     {
       
   326     TLiwVariant variant;
       
   327     iPlugin->HideLoadingIcon(aObserver);
       
   328     if ( aDataMap->FindL( KImage1, variant ) )
       
   329         {
       
   330         TInt handle = KErrBadHandle;
       
   331         TUint uintHandle = 0;
       
   332         TPtrC16 valPtr;
       
   333         if ( variant.Get( uintHandle ) )
       
   334             {
       
   335             handle = uintHandle;
       
   336             }
       
   337         else if ( !variant.Get( handle ) )
       
   338             {
       
   339             handle = KErrBadHandle;
       
   340             }
       
   341         // read as a image handle
       
   342         if( handle == KErrBadHandle )
       
   343             {
       
   344             // no handle, so read as image path
       
   345             variant.Get( valPtr );
       
   346             iPlugin->PublishImageL(aObserver, CWrtDataPlugin::EImage1, valPtr );
       
   347             }
       
   348         else
       
   349             {
       
   350             TInt maskHandle = KErrBadHandle;
       
   351             //Look for image mask
       
   352             if ( aDataMap->FindL( KImageMask, variant ) )
       
   353                {
       
   354                variant.Get( maskHandle );                           
       
   355                }
       
   356             iPlugin->PublishImageL(aObserver, CWrtDataPlugin::EImage1, handle, maskHandle );
       
   357             }
       
   358         }
       
   359     variant.Reset();
       
   360     }
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 // CWrtData::RefreshL
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void CWrtData::RefreshL( TDesC& aContentId, TDesC& aOperation, 
       
   367         CLiwDefaultMap* aDataMap )
       
   368     {
       
   369      if ( aContentId == iContentId )
       
   370          {
       
   371          iPlugin->RefreshL( aOperation, aDataMap);
       
   372          }
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CWrtData::ExecuteActionL
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CWrtData::ExecuteActionL(const TDesC& aObjectId, const TDesC& aTrigger )
       
   380    {
       
   381    HBufC8* triggerName = HBufC8::NewLC( KWRTContentNameMaxLength );
       
   382   
       
   383    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   384    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   385    CLiwDefaultMap* filter = NULL;
       
   386 
       
   387    triggerName->Des().Copy(aTrigger);
       
   388    if ( aObjectId == KPubData )
       
   389        {
       
   390        // this trigger belongs to publisher registery.
       
   391        // in such case it is assumed that all the items in the widgets
       
   392        // belongs to same publisher, type and id.
       
   393        TLiwGenericParam cptype( KType, TLiwVariant( KPubData ) );
       
   394        inParamList->AppendL( cptype );
       
   395        cptype.Reset();
       
   396        // use the first item configuration to create the filter
       
   397        filter = CreateFilterLC();
       
   398        }
       
   399    else
       
   400        {
       
   401        if ( aObjectId == KMenuItem16 )
       
   402            {
       
   403            TInt pos = KErrNotFound;
       
   404            for (TInt i = 0; i < iMenuItems.Count(); i++)
       
   405                {
       
   406                if ( aTrigger == iMenuItems[i] )
       
   407                    {
       
   408                    pos = i;
       
   409                    break;
       
   410                    }
       
   411                }
       
   412            if( pos == KErrNotFound )
       
   413                {
       
   414                // No such menu items
       
   415                CleanupStack::PopAndDestroy( triggerName );
       
   416                return; 
       
   417                }
       
   418               triggerName->Des().Copy( iMenuTriggers[pos]->Des() );
       
   419               filter = CreateFilterLC();
       
   420            }
       
   421        else
       
   422            {
       
   423            //Create filter criteria for requested entries in form of LIW map:
       
   424            filter = CreateFilterLC();
       
   425            }
       
   426        //append type to inparam list
       
   427        TLiwGenericParam cptype( KType, TLiwVariant( KCpData ) );
       
   428        inParamList->AppendL( cptype );
       
   429        cptype.Reset();
       
   430        }
       
   431 
       
   432     filter->InsertL( KActionTrigger, TLiwVariant( triggerName->Des() ) );
       
   433    //append filter to input param
       
   434     TLiwGenericParam item( KFilter, TLiwVariant( filter ) );
       
   435     inParamList->AppendL( item );
       
   436     iInterface->ExecuteCmdL( KExecuteAction,  *inParamList, *outParamList );
       
   437     
       
   438     CleanupStack::PopAndDestroy( filter );
       
   439     CleanupStack::PopAndDestroy( triggerName );
       
   440     item.Reset();
       
   441 
       
   442     inParamList->Reset();
       
   443     outParamList->Reset();  
       
   444     
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CWrtData::IsPluginActive
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 TBool CWrtData::IsPluginActive()
       
   452     {
       
   453     return iPlugin->IsActive();
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // CWrtData::ActivateL
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 void CWrtData::ActivateL()
       
   461     {
       
   462     ChangePublisherStatusL( KActive );
       
   463     }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CWrtData::ResumeL
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CWrtData::ResumeL()
       
   470     {
       
   471     ChangePublisherStatusL( KResume );
       
   472     }
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // CWrtData::SuspendL
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 void CWrtData::SuspendL()
       
   479     {
       
   480     ChangePublisherStatusL( KSuspend );
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // CWrtData::DeActivateL
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CWrtData::DeActivateL()
       
   488     {
       
   489     ChangePublisherStatusL( KDeActive );
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 // CWrtData::InActiveL
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CWrtData::InActiveL()
       
   497     {
       
   498     ChangePublisherStatusL( KInActive );
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CWrtData::OnLineL
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CWrtData::OnLineL()
       
   506     {
       
   507     ChangePublisherStatusL( KOnLine );
       
   508     }
       
   509 
       
   510 // ---------------------------------------------------------------------------
       
   511 // CWrtData::offLineL
       
   512 // ---------------------------------------------------------------------------
       
   513 //
       
   514 void CWrtData::OffLineL()
       
   515     {
       
   516     ChangePublisherStatusL( KOffLine );
       
   517     }
       
   518 
       
   519 // ---------------------------------------------------------------------------
       
   520 // CWrtData::CreateFilterL
       
   521 // ---------------------------------------------------------------------------
       
   522 //
       
   523 CLiwDefaultMap* CWrtData::CreateFilterLC()
       
   524     {
       
   525     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   526     filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ));
       
   527     filter->InsertL( KContentType, TLiwVariant( KTemplateWidget ));
       
   528     filter->InsertL( KContentId, TLiwVariant( iContentId ));
       
   529     return filter;
       
   530     }
       
   531 
       
   532 // ---------------------------------------------------------------------------
       
   533 // CWrtData::ExecuteCommandL
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 void CWrtData::ExecuteCommandL(CLiwDefaultMap* aInFilter, CLiwDefaultMap* aOutDataMap, const TDesC16& aRegistry  )
       
   537     {
       
   538     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   539     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   540     
       
   541     TLiwGenericParam type( KType, TLiwVariant( aRegistry ) );
       
   542     inParamList->AppendL( type );
       
   543     
       
   544     //append filter to input param
       
   545      TLiwGenericParam item( KFilter, TLiwVariant( aInFilter ));
       
   546      inParamList->AppendL( item );
       
   547      
       
   548     // execute service.It is assumed that iInterface is already initiatedd
       
   549     if(iInterface)
       
   550         {
       
   551         iInterface->ExecuteCmdL( *iCommandName, *inParamList, *outParamList);
       
   552         }
       
   553     else
       
   554         {
       
   555         User::Leave( KErrNotSupported );
       
   556         }
       
   557     type.Reset();
       
   558     item.Reset();
       
   559     inParamList->Reset();
       
   560     
       
   561     //extracts data map
       
   562     TInt pos = 0;
       
   563     outParamList->FindFirst( pos, KResults );
       
   564     if( pos != KErrNotFound )
       
   565         // results present
       
   566         {
       
   567         //extract iterator on results list
       
   568         TLiwVariant variant = (*outParamList)[pos].Value();
       
   569         CLiwIterable* iterable = variant.AsIterable();
       
   570         iterable->Reset();
       
   571         
       
   572         //get next result
       
   573         if( iterable->NextL( variant ) )
       
   574             {
       
   575             //extract content map
       
   576             CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   577             variant.Get( *map );
       
   578             if( map->FindL( KDataMap, variant) )
       
   579                 {
       
   580                  variant.Get( *aOutDataMap );
       
   581                 }
       
   582             CleanupStack::PopAndDestroy( map );
       
   583             }
       
   584         iterable->Reset();
       
   585         variant.Reset();
       
   586         }
       
   587     outParamList->Reset();
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // CWrtData::PublisherStatusL
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 void CWrtData::ChangePublisherStatusL(const TDesC& aStatus)
       
   595     {
       
   596     if( iContentId == NULL )
       
   597        {
       
   598        return;
       
   599        }
       
   600    HBufC8* triggerName = HBufC8::NewLC(KWRTContentNameMaxLength);
       
   601    triggerName->Des().Copy(aStatus);
       
   602    
       
   603    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   604    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   605        
       
   606    TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
       
   607    inParamList->AppendL( type );
       
   608               
       
   609    CLiwDefaultMap* filter = CreateFilterLC();
       
   610    filter->InsertL(KActionTrigger, TLiwVariant(triggerName->Des()) );
       
   611    
       
   612    TLiwGenericParam item( KFilter, TLiwVariant( filter ));
       
   613    inParamList->AppendL( item );
       
   614    
       
   615    if(iInterface)
       
   616        {
       
   617        iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
       
   618        }
       
   619    else
       
   620        {
       
   621        User::Leave( KErrNotSupported );
       
   622        }
       
   623    CleanupStack::PopAndDestroy( filter );
       
   624    
       
   625    inParamList->Reset();
       
   626    outParamList->Reset();
       
   627    CleanupStack::PopAndDestroy( triggerName );
       
   628    }
       
   629 
       
   630 // ---------------------------------------------------------------------------
       
   631 // CWrtData::GetMenuItemsL
   195 // ---------------------------------------------------------------------------
   632 // ---------------------------------------------------------------------------
   196 //
   633 //
   197 void CWrtData::GetMenuItemsL()
   634 void CWrtData::GetMenuItemsL()
   198 	{
   635 	{
   199 	if(iInterface)
   636 	if(iInterface)
   239 		CleanupStack::PopAndDestroy( outDataMap );
   676 		CleanupStack::PopAndDestroy( outDataMap );
   240 		}
   677 		}
   241 	}
   678 	}
   242 
   679 
   243 // ---------------------------------------------------------------------------
   680 // ---------------------------------------------------------------------------
   244 // CreateFilterL
   681 // CWrtData::GetWidgetNameAndUidL
   245 // ---------------------------------------------------------------------------
   682 // ---------------------------------------------------------------------------
   246 //
   683 //
   247 CLiwDefaultMap* CWrtData::CreateFilterLC()
   684 void CWrtData::GetWidgetNameAndUidL(TDes& aName, TDes& aAppUID )
   248     {
   685     {
   249     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
   686     CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC();
   250 	filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ));
   687     //Create filter criteria for requested entries in form of LIW map:
   251 	filter->InsertL( KContentType, TLiwVariant( KTemplateWidget ));
   688     CLiwDefaultMap* filter = CreateFilterLC();
   252 	filter->InsertL( KContentId, TLiwVariant( iContentId ));
   689     ExecuteCommandL( filter, outDataMap, KPubData  );
   253 	return filter;
   690     CleanupStack::PopAndDestroy( filter );
   254     }
   691   
   255 
   692     TLiwVariant variant;
   256 // ---------------------------------------------------------------------------
   693     if ( outDataMap->FindL(KWidgetInfo, variant) )
   257 // HasMenuItem
   694         {
   258 // ---------------------------------------------------------------------------
   695         CLiwDefaultMap* widgetInfoMap = CLiwDefaultMap::NewLC();
   259 //
   696         variant.Get( *widgetInfoMap );
   260 TBool CWrtData::HasMenuItem(const TDesC16& aMenuItem )
   697         variant.Reset();
   261 	{
   698         if ( widgetInfoMap->FindL( KWidgetName, variant ) )
   262 	TBool found = EFalse;
   699             {
   263 	for (TInt i = 0; i < iMenuItems.Count(); i++ )
   700             aName.Copy(variant.AsDes());
   264 		{
   701             variant.Reset();
   265 		if( aMenuItem == iMenuItems[i] )
   702             if ( widgetInfoMap->FindL( KWidgetIcon, variant ) )
   266 			{
   703                {
   267 			found =  ETrue;
   704                aAppUID.Copy(variant.AsDes());
   268 			break;
   705                }
   269 			}
   706             }
   270 		}
   707         CleanupStack::PopAndDestroy( widgetInfoMap );
   271 	return found;
   708         }
   272 	}
   709     variant.Reset();
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // PublishAllL
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CWrtData::PublishAllL( MAiContentObserver* aObserver )
       
   279 	{
       
   280     PublishL( aObserver );
       
   281 	}
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // PublishL
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CWrtData::PublishL( MAiContentObserver* aObserver ) 
       
   288    {
       
   289    CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC();
       
   290    //Create filter criteria for requested entries in form of LIW map:
       
   291    CLiwDefaultMap* filter = CreateFilterLC();
       
   292    ExecuteCommandL( filter, outDataMap, KCpData  );
       
   293    CleanupStack::PopAndDestroy( filter );
       
   294    TLiwVariant variant;
       
   295 	if ( outDataMap->FindL( KImage1, variant ) )
       
   296 		{
       
   297 		TInt handle = KErrBadHandle;
       
   298 		TUint uintHandle = 0;
       
   299 		TPtrC16 valPtr;
       
   300 		if ( variant.Get( uintHandle ) )
       
   301 			{
       
   302 			handle = uintHandle;
       
   303 			}
       
   304 		else if ( !variant.Get( handle ) )
       
   305 			{
       
   306 			handle = KErrBadHandle;
       
   307 			}
       
   308 		// read as a image handle
       
   309 		if( handle == KErrBadHandle )
       
   310 			{
       
   311 			// no handle, so read as image path
       
   312 			variant.Get( valPtr );
       
   313 			iPlugin->PublishImageL(aObserver, EImage1, valPtr );
       
   314 			}
       
   315 		else
       
   316 			{
       
   317 			TInt maskHandle = KErrBadHandle;
       
   318 			//Look for image mask
       
   319 			if ( outDataMap->FindL( KImageMask, variant ) )
       
   320 			   {
       
   321 			   variant.Get( maskHandle );                           
       
   322 			   }
       
   323 			iPlugin->PublishImageL(aObserver, EImage1, handle, maskHandle );
       
   324 			}
       
   325 		}
       
   326 	
       
   327 	variant.Reset();
       
   328     CleanupStack::PopAndDestroy( outDataMap );
   710     CleanupStack::PopAndDestroy( outDataMap );
   329 	}
   711     }
   330 
   712 
   331 // ---------------------------------------------------------------------------
   713 // ---------------------------------------------------------------------------
   332 // ExecuteCommandL
   714 // CWrtData::ResolveUid
   333 // ---------------------------------------------------------------------------
   715 // ---------------------------------------------------------------------------
   334 //
   716 //
   335 void CWrtData::ExecuteCommandL(CLiwDefaultMap* aInFilter, CLiwDefaultMap* aOutDataMap, const TDesC16& aRegistry  )
   717 TBool CWrtData::ResolveUid(const TDesC& aUidDes, TUid& aUid )
   336 	{
   718     {
   337 	CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   719     // Syntax: uid(0x12345678)
   338 	CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   720     TInt error = KErrNotFound;
   339 	
   721     TInt pos = aUidDes.FindF( KUid );
   340 	TLiwGenericParam type( KType, TLiwVariant( aRegistry ) );
   722     if( pos == 0 )
   341 	inParamList->AppendL( type );
   723         {
   342 	
   724         // Skip skin token
   343 	//append filter to input param
   725         pos += KUid().Length();
   344 	 TLiwGenericParam item( KFilter, TLiwVariant( aInFilter ));
   726 
   345 	 inParamList->AppendL( item );
   727         // Initialize lexer
   346 	 
   728         TLex lex( aUidDes.Mid( pos ) );
   347 	// execute service.It is assumed that iInterface is already initiatedd
   729 
   348 	if(iInterface)
   730         // Check left parenthesis
   349 		{
   731         if ( lex.Get() == KLeftParenthesis )
   350 		iInterface->ExecuteCmdL( *iCommandName, *inParamList, *outParamList);
   732             {
   351 		}
   733             lex.SkipSpaceAndMark();
   352 	else
   734             lex.SkipCharacters();
   353 		{
   735             
   354 		User::Leave( KErrNotSupported );
   736             TPtrC mtoken = lex.MarkedToken();
   355 		}
   737             pos = mtoken.FindF( KHexPrefix );
   356 	type.Reset();
   738             if ( pos == 0 )
   357 	item.Reset();
   739                 {
   358 	inParamList->Reset();
   740                 TLex lex( mtoken.Mid( KHexPrefix().Length() ) );
   359 	
   741                 TUint id = 0;
   360 	//extracts data map
   742                 error = lex.Val( id, EHex );
   361 	TInt pos = 0;
   743                 aUid = TUid::Uid( (TInt)id );
   362 	outParamList->FindFirst( pos, KResults );
   744                 }
   363 	if( pos != KErrNotFound )
   745             else
   364 		// results present
   746                 {
   365 		{
   747                 TInt id( 0 );
   366 		//extract iterator on results list
   748                 error = lex.Val( id );
   367 		TLiwVariant variant = (*outParamList)[pos].Value();
   749                 aUid.iUid = id;
   368 		CLiwIterable* iterable = variant.AsIterable();
   750                 }
   369 		iterable->Reset();
   751             }
   370 		
   752         }
   371 		//get next result
   753     return (error == KErrNone );
   372 		if( iterable->NextL( variant ) )
   754     }
   373 			{
   755 
   374 			//extract content map
   756 // ---------------------------------------------------------------------------
   375 			CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
   757 // CWrtData::CreateIconFromUidL
   376 			variant.Get( *map );
   758 // ---------------------------------------------------------------------------
   377 			if( map->FindL( KDataMap, variant) )
   759 //
   378 				{
   760 void CWrtData::CreateIconFromUidL(TInt& aHandle, TInt& aMaskHandle, const TUid& aAppUid ) 
   379 				 variant.Get( *aOutDataMap );
   761     {
   380 				}
   762     RApaLsSession lsSession;
   381 			CleanupStack::PopAndDestroy( map );
   763     User::LeaveIfError( lsSession.Connect() );
   382 			}
   764     CleanupClosePushL( lsSession ); // lsSession (1)
   383 		iterable->Reset();
   765     
   384 		variant.Reset();
   766     CArrayFixFlat<TSize>* sizeArray = new(ELeave) CArrayFixFlat<TSize>( 5 );
   385 		}
   767     CleanupStack::PushL( sizeArray );
   386 	outParamList->Reset();
   768     if ( KErrNone == lsSession.GetAppIconSizes(aAppUid, *sizeArray) )
   387 	}
   769         {
   388 
   770         if ( sizeArray->Count() ) 
   389 // ---------------------------------------------------------------------------
   771             {
   390 // ExecuteActionL
   772             // There are other icon sizes
   391 // ---------------------------------------------------------------------------
   773             TInt idx = 0;
   392 //
   774             TInt size( sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight );
   393 void CWrtData::ExecuteActionL(const TDesC& aObjectId, const TDesC& aTrigger )
   775             for ( TInt i = 1; i < sizeArray->Count(); i++ ) 
   394    {
   776                 {
   395    HBufC8* triggerName = HBufC8::NewLC( KWRTContentNameMaxLength );
   777                 if ( ( sizeArray->At(i).iWidth * sizeArray->At(i).iHeight ) > size )
   396   
   778                     {
   397    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   779                     idx = i;
   398    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   780                     size =  sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight;
   399    CLiwDefaultMap* filter = NULL;
   781                     }
   400 
   782                 }
   401    triggerName->Des().Copy(aTrigger);
   783 
   402    if ( aObjectId == KPubData )
   784             CApaMaskedBitmap* appBitMap = CApaMaskedBitmap::NewLC();
   403 	   {
   785             if ( KErrNone == lsSession.GetAppIcon( aAppUid, sizeArray->At(idx),
   404 	   // this trigger belongs to publisher registery.
   786                     *appBitMap ) )
   405 	   // in such case it is assumed that all the items in the widgets
   787                 {
   406 	   // belongs to same publisher, type and id.
   788                 aHandle = appBitMap->Handle();
   407 	   TLiwGenericParam cptype( KType, TLiwVariant( KPubData ) );
   789                 aMaskHandle = appBitMap->Mask()->Handle();
   408 	   inParamList->AppendL( cptype );
   790                 }
   409 	   cptype.Reset();
   791             CleanupStack::PopAndDestroy( appBitMap );
   410 	   // use the first item configuration to create the filter
   792             }
   411 	   filter = CreateFilterLC();
   793         }
   412 	   }
   794     CleanupStack::PopAndDestroy( sizeArray );
   413    else
   795     CleanupStack::PopAndDestroy( &lsSession );
   414 	   {
   796     }
   415 	   if ( aObjectId == KMenuItem16 )
   797 
   416 		   {
       
   417 		   TInt pos = KErrNotFound;
       
   418 		   for (TInt i = 0; i < iMenuItems.Count(); i++)
       
   419 			   {
       
   420 			   if ( aTrigger == iMenuItems[i] )
       
   421 				   {
       
   422 				   pos = i;
       
   423 				   break;
       
   424 				   }
       
   425 			   }
       
   426 		   if( pos == KErrNotFound )
       
   427 			   {
       
   428 			   // No such menu items
       
   429 			   CleanupStack::PopAndDestroy( triggerName );
       
   430 			   return; 
       
   431 			   }
       
   432 			  triggerName->Des().Copy( iMenuTriggers[pos]->Des() );
       
   433 			  filter = CreateFilterLC();
       
   434 		   }
       
   435 	   else
       
   436 		   {
       
   437 		   //Create filter criteria for requested entries in form of LIW map:
       
   438 		   filter = CreateFilterLC();
       
   439 		   }
       
   440 	   //append type to inparam list
       
   441 	   TLiwGenericParam cptype( KType, TLiwVariant( KCpData ) );
       
   442 	   inParamList->AppendL( cptype );
       
   443 	   cptype.Reset();
       
   444 	   }
       
   445 
       
   446     filter->InsertL( KActionTrigger, TLiwVariant( triggerName->Des() ) );
       
   447    //append filter to input param
       
   448     TLiwGenericParam item( KFilter, TLiwVariant( filter ) );
       
   449     inParamList->AppendL( item );
       
   450     iInterface->ExecuteCmdL( KExecuteAction,  *inParamList, *outParamList );
       
   451     
       
   452     CleanupStack::PopAndDestroy( filter );
       
   453     CleanupStack::PopAndDestroy( triggerName );
       
   454     item.Reset();
       
   455 
       
   456     inParamList->Reset();
       
   457     outParamList->Reset();  
       
   458     
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // RegisterL
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 void CWrtData::RegisterL()
       
   466     {
       
   467 	CLiwDefaultMap* filter = CreateFilterLC();
       
   468 	filter->InsertL( KOperation, TLiwVariant( KAddUpdateDelete ) );
       
   469 	iObserver->RegisterL(filter);
       
   470 	CleanupStack::PopAndDestroy( filter );
       
   471     }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // RefreshL
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 void CWrtData::RefreshL( TDesC& aPublisher, TDesC& aContentType, 
       
   478                 TDesC& aContentId, TDesC& aOperation )
       
   479     {
       
   480      if ( aPublisher == KWRTPublisher() && aContentType == KTemplateWidget()
       
   481     	  && aContentId == iContentId )
       
   482     	 {
       
   483     	 iPlugin->RefreshL( aOperation);
       
   484     	 }
       
   485     }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // IsPluginActive
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 TBool CWrtData::IsPluginActive()
       
   492     {
       
   493     return iPlugin->IsActive();
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // PublisherStatusL
       
   498 // ---------------------------------------------------------------------------
       
   499 //
       
   500 void CWrtData::ChangePublisherStatusL(const TDesC& aStatus)
       
   501     {
       
   502     if( iContentId == NULL )
       
   503        {
       
   504        return;
       
   505        }
       
   506    HBufC8* triggerName = HBufC8::NewLC(KWRTContentNameMaxLength);
       
   507    triggerName->Des().Copy(aStatus);
       
   508    
       
   509    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   510    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   511        
       
   512    TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
       
   513    inParamList->AppendL( type );
       
   514 			  
       
   515    CLiwDefaultMap* filter = CreateFilterLC();
       
   516    filter->InsertL(KActionTrigger, TLiwVariant(triggerName->Des()) );
       
   517    
       
   518    TLiwGenericParam item( KFilter, TLiwVariant( filter ));
       
   519    inParamList->AppendL( item );
       
   520    
       
   521    if(iInterface)
       
   522 	   {
       
   523 	   iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
       
   524 	   }
       
   525    else
       
   526 	   {
       
   527 	   User::Leave( KErrNotSupported );
       
   528 	   }
       
   529    CleanupStack::PopAndDestroy( filter );
       
   530    
       
   531    inParamList->Reset();
       
   532    outParamList->Reset();
       
   533    CleanupStack::PopAndDestroy( triggerName );
       
   534    }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // ResumeL
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 void CWrtData::ResumeL()
       
   541     {
       
   542     ChangePublisherStatusL( KResume );
       
   543     }
       
   544 
       
   545 // ---------------------------------------------------------------------------
       
   546 // SuspendL
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 void CWrtData::SuspendL()
       
   550     {
       
   551     ChangePublisherStatusL( KSuspend );
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // ActivateL
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 void CWrtData::ActivateL()
       
   559     {
       
   560     ChangePublisherStatusL( KActive );
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // DeActivateL
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 void CWrtData::DeActivateL()
       
   568     {
       
   569     ChangePublisherStatusL( KDeActive );
       
   570     }
       
   571 
       
   572 // ---------------------------------------------------------------------------
       
   573 // OnLineL
       
   574 // ---------------------------------------------------------------------------
       
   575 //
       
   576 void CWrtData::OnLineL()
       
   577     {
       
   578     ChangePublisherStatusL( KOnLine );
       
   579     }
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // offLineL
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 void CWrtData::OffLineL()
       
   586     {
       
   587     ChangePublisherStatusL( KOffLine );
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // InActiveL
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 void CWrtData::InActiveL()
       
   595     {
       
   596     ChangePublisherStatusL( KInActive );
       
   597     }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // UpdatePublisherStatusL
       
   601 // ---------------------------------------------------------------------------
       
   602 //
       
   603 void CWrtData::UpdatePublisherStatusL()
       
   604 	{
       
   605 	 // Resent the plugin status to publisher
       
   606 	 ActivateL();
       
   607 	 if ( iPlugin->IsActive() )
       
   608 		 {
       
   609 		 ResumeL();
       
   610 		 }
       
   611 	 else
       
   612 		 {
       
   613 		 SuspendL();
       
   614 		 }
       
   615 	  // forward the network status if it uses.
       
   616 	if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOnline )
       
   617 		{
       
   618 		OnLineL();
       
   619 		}
       
   620 	else if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOffline )
       
   621 		{
       
   622 		OffLineL();
       
   623 		}
       
   624 	}
       
   625 
       
   626 // ---------------------------------------------------------------------------
       
   627 // ResolveSkinItemId
       
   628 // ---------------------------------------------------------------------------
       
   629 //
       
   630 TBool CWrtData::ResolveSkinIdAndMifId( const TDesC& aPath, TAknsItemID& aItemId,
       
   631 		TInt& abitmapId, TInt& aMaskId, TDes& aFilename )
       
   632    {
       
   633    // Syntax: skin( <major> <minor> ):mif(filename bimapId maskId) 
       
   634    TInt error = KErrNotFound;
       
   635    TInt pos = aPath.FindF( KSkin );
       
   636    if( pos != KErrNotFound )
       
   637 	   {
       
   638 	   // Skip skin token
       
   639 	   pos += KSkin().Length();
       
   640 	   
       
   641 	   // Initialize lexer
       
   642 	  TLex lex( aPath.Mid( pos ) );
       
   643 	  lex.SkipSpace();
       
   644 	   
       
   645 	   // Check left parenthesis
       
   646 	  if (lex.Get() == KLeftParenthesis )
       
   647 		   {
       
   648 		   //lex.SkipSpace();
       
   649 		   
       
   650 		   TInt majorId( 0 );        
       
   651 		   TInt minorId( 0 );
       
   652 
       
   653 		   // Resolve major id        
       
   654 		   error = lex.Val( majorId );
       
   655 		   
       
   656 		   // Resolve minor id
       
   657 		   lex.SkipSpace();
       
   658 		   error |= lex.Val( minorId );
       
   659 		   
       
   660 		   // initilize skin item id object
       
   661 		   aItemId.Set( majorId, minorId );
       
   662 		   }
       
   663 	   }
       
   664 
       
   665    if( (error == KErrNone && aPath.FindF( KColon ) != KErrNotFound ) 
       
   666 		 || ( error == KErrNotFound ) )
       
   667 	   {
       
   668 	   error = KErrNotFound;
       
   669 	   pos = aPath.FindF( KMif );
       
   670 	   if ( pos != KErrNotFound )
       
   671 		   {
       
   672 		   pos += KMif().Length();
       
   673 		   // Initialize lexer
       
   674 		   TLex lex( aPath.Mid( pos ) );
       
   675 		   lex.SkipSpace();
       
   676 		   
       
   677 		   // Check left parenthesis
       
   678 		   if (lex.Get() == KLeftParenthesis )
       
   679 			   {
       
   680 			   lex.SkipSpaceAndMark();
       
   681 			   lex.SkipCharacters();
       
   682 			   // Resolve MifFile name
       
   683 			   aFilename.Copy(lex.MarkedToken());
       
   684 			   if( aFilename.Length()!= 0)
       
   685 				   {
       
   686 				   // Resolve bitmap id  
       
   687 				   lex.SkipSpace();
       
   688 				   error = lex.Val( abitmapId );
       
   689 				   
       
   690 				   // Resolve mask id
       
   691 				   // dont return error if it is not found, that is ok
       
   692 				   lex.SkipSpace();
       
   693 				   lex.Val( aMaskId );
       
   694 				   }
       
   695 			   else
       
   696 				   {
       
   697 				   error = KErrNotFound;
       
   698 				   }
       
   699 			   }
       
   700 		   }
       
   701 	   }
       
   702    return (error == KErrNone );
       
   703    }