idlefw/plugins/wrtdataplugin/src/wrtdata.cpp
branchRCL_3
changeset 17 cb506ec2d869
parent 16 b276298d5729
child 23 ace62b58f4b2
equal deleted inserted replaced
13:c2817bb2a55c 17:cb506ec2d869
    22 #include <liwservicehandler.h>
    22 #include <liwservicehandler.h>
    23 #include <aipluginsettings.h>
    23 #include <aipluginsettings.h>
    24 #include <apgcli.h>
    24 #include <apgcli.h>
    25 #include <apgicnfl.h> 
    25 #include <apgicnfl.h> 
    26 #include <bautils.h> 
    26 #include <bautils.h> 
       
    27 #include <aicpscommandbuffer.h>
    27 
    28 
    28 #include "wrtdata.h"
    29 #include "wrtdata.h"
    29 #include "wrtdatapluginconst.h"
    30 #include "wrtdatapluginconst.h"
    30 #include "wrtdataobserver.h"
    31 #include "wrtdataobserver.h"
    31 #include "wrtdataplugin.h"
    32 #include "wrtdataplugin.h"
    48 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    49 // Default constructor
    50 // Default constructor
    50 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
    51 //
    52 //
    52 CWrtData::CWrtData()
    53 CWrtData::CWrtData()
       
    54     : iAppUid( KNullUid )
    53     {
    55     {
    54     }
    56     }
    55     
    57     
    56 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    57 // Symbian 2nd phase constructor can leave
    59 // Symbian 2nd phase constructor can leave
    58 // ---------------------------------------------------------------------------
    60 // ---------------------------------------------------------------------------
    59 //
    61 //
    60 void CWrtData::ConstructL(CWrtDataPlugin* aPlugin)
    62 void CWrtData::ConstructL(CWrtDataPlugin* aPlugin)
    61     { 
    63     { 
    62      iPlugin = aPlugin;
    64      iPlugin = aPlugin;
    63      iCommandName = HBufC8::NewL( KWRTContentValueMaxLength );
       
    64     }
    65     }
    65     
    66     
    66 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    67 // Destructor
    68 // Destructor
    68 // Deletes all data created to heap
    69 // Deletes all data created to heap
    69 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    70 //
    71 //
    71 CWrtData::~CWrtData()
    72 CWrtData::~CWrtData()
    72     {
    73     {
    73     if( iCommandName )
       
    74     	{
       
    75     	delete iCommandName;
       
    76     	iCommandName = NULL;
       
    77     	}
       
    78     if(iObserver)
    74     if(iObserver)
    79         {
    75         {      
    80         TRAP_IGNORE(iObserver->ReleaseL() );
       
    81         delete iObserver;
    76         delete iObserver;
    82         iObserver = NULL;
    77         iObserver = NULL;
    83         }
    78         }
    84     if( iInterface )
       
    85          {
       
    86          iInterface->Close();
       
    87          iInterface = NULL;
       
    88          }
       
    89     if( iServiceHandler )
       
    90          {
       
    91          iServiceHandler->Reset();
       
    92          delete iServiceHandler;
       
    93          iServiceHandler = NULL;
       
    94          }
       
    95     if ( iContentId )
    79     if ( iContentId )
    96     	{
    80     	{
    97     	delete iContentId;
    81     	delete iContentId;
    98     	iContentId = NULL;
    82     	iContentId = NULL;
    99     	}
    83     	}
   100     iMenuItems.ResetAndDestroy();
       
   101     iMenuTriggers.ResetAndDestroy();
       
   102     // not owned
    84     // not owned
       
    85     iInterface = NULL;
       
    86     iServiceHandler = NULL;
       
    87     iCpsExecute = NULL;
   103     iPlugin = NULL;
    88     iPlugin = NULL;
   104     }
    89     }
   105 
    90 
   106 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
   107 // CWrtData::ConfigureL
    92 // CWrtData::ConfigureL
   108 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
   109 //
    94 //
   110 void CWrtData::ConfigureL(RAiSettingsItemArray& aConfigurations )
    95 void CWrtData::ConfigureL(RAiSettingsItemArray& aConfigurations )
   111     {
    96     {
   112     HBufC8* serviceName = HBufC8::NewLC( KWRTContentValueMaxLength );
       
   113     HBufC8* interfaceName = HBufC8::NewLC( KWRTContentValueMaxLength );
       
   114     
       
   115     // Interface name 
       
   116     RCriteriaArray criteriaArray;
       
   117     
       
   118     TInt count = aConfigurations.Count();
    97     TInt count = aConfigurations.Count();
   119    
    98     for(TInt i = 0; i<count; i++ )
   120     for(TInt i = 0;i<count;i++)
       
   121        {
    99        {
   122        MAiPluginConfigurationItem& confItem = ( aConfigurations[i] )->AiPluginConfigurationItem();
   100        MAiPluginConfigurationItem& confItem = ( aConfigurations[i] )->AiPluginConfigurationItem();
   123        // if owner is plugin then it (key,value) is for plugin configurations items
   101        // if owner is plugin then it (key,value) is for plugin configurations items
   124        if(confItem.Owner() == KPlugin())
   102        if(confItem.Owner() == KPlugin() && confItem.Name() == KPubData())
   125            {
   103            {
   126            if(confItem.Name() ==  KService())
   104            iContentId = confItem.Value().AllocL();
   127                {
   105 		   }
   128                serviceName->Des().Copy(confItem.Value());
       
   129                }
       
   130            else if( confItem.Name() == KInterface() )
       
   131                  {
       
   132                  interfaceName->Des().Copy(confItem.Value());
       
   133                  }
       
   134            else if( confItem.Name() == KCommand() )
       
   135                  {
       
   136                  iCommandName->Des().Copy(confItem.Value());
       
   137                  }
       
   138            else if( confItem.Name() == KMenuItem16() )
       
   139                  {
       
   140                  iMenuItems.AppendL( confItem.Value().AllocL() );
       
   141                  }
       
   142            else if( confItem.Name() == KPubData() )
       
   143 				  {
       
   144 				  iContentId = confItem.Value().AllocL();
       
   145 				  }
       
   146            }
       
   147        }
   106        }
   148     
   107     if( iContentId->Des().Length() == 0 ) 
   149     if( !( serviceName->Des().Length() >= 0 && interfaceName->Des().Length() >= 0  
       
   150             && iCommandName->Des().Length() >= 0 ) )
       
   151         {
   108         {
   152         // No service to offer without plugin configurations 
   109         // No service to offer without plugin configurations 
   153         User::Leave( KErrNotSupported );
   110         User::Leave( KErrNotSupported );
   154         }
   111         }
   155     
       
   156     iServiceHandler = CLiwServiceHandler::NewL(); 
       
   157 
       
   158     // for convenience keep pointers to Service Handler param lists 
       
   159     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   160     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   161 
       
   162     CLiwCriteriaItem* criteriaItem = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, *interfaceName , *serviceName );
       
   163     criteriaItem->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   164     criteriaArray.AppendL( criteriaItem );
       
   165 
       
   166 
       
   167     // attach Liw criteria
       
   168      iServiceHandler->AttachL( criteriaArray );
       
   169      iServiceHandler->ExecuteServiceCmdL( *criteriaItem, *inParamList, *outParamList );
       
   170 
       
   171      CleanupStack::PopAndDestroy(criteriaItem);
       
   172      criteriaArray.Reset();
       
   173 
       
   174     // extract CPS interface from output params
       
   175     TInt pos( 0 );
       
   176     outParamList->FindFirst( pos, *interfaceName );
       
   177     if( pos != KErrNotFound )
       
   178         {
       
   179         //iInterface is MLiwInterface*
       
   180         iInterface = (*outParamList)[pos].Value().AsInterface(); 
       
   181         User::LeaveIfNull( iInterface );
       
   182         }
       
   183     else
       
   184         {
       
   185         User::Leave( KErrNotFound );
       
   186         }
       
   187     inParamList->Reset();
       
   188     outParamList->Reset();
       
   189     CleanupStack::PopAndDestroy( interfaceName );
       
   190     CleanupStack::PopAndDestroy( serviceName );
       
   191 
       
   192 	//Gets the menu items from the publisher registry    
       
   193     GetMenuItemsL();
       
   194  
       
   195     iObserver = CWrtDataObserver::NewL( iInterface, this );   
   112     iObserver = CWrtDataObserver::NewL( iInterface, this );   
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   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     }
   113     }
   215 
   114 
   216 // ---------------------------------------------------------------------------
   115 // ---------------------------------------------------------------------------
   217 // CWrtData::RegisterL
   116 // CWrtData::RegisterL
   218 // ---------------------------------------------------------------------------
   117 // ---------------------------------------------------------------------------
   230 // ---------------------------------------------------------------------------
   129 // ---------------------------------------------------------------------------
   231 //
   130 //
   232 void CWrtData::UpdatePublisherStatusL()
   131 void CWrtData::UpdatePublisherStatusL()
   233     {
   132     {
   234      // Resent the plugin status to publisher
   133      // Resent the plugin status to publisher
   235      ActivateL();
   134     CLiwDefaultList* actions= CLiwDefaultList::NewLC();
       
   135     actions->AppendL( TLiwVariant( KActive ));
   236      if ( iPlugin->IsActive() )
   136      if ( iPlugin->IsActive() )
   237          {
   137          {
   238          ResumeL();
   138          actions->AppendL( TLiwVariant( KResume ) );
   239          }
   139          }
   240      else
   140      else
   241          {
   141          {
   242          SuspendL();
   142          actions->AppendL( TLiwVariant( KSuspend ));
   243          }
   143          }
   244       // forward the network status if it uses.
   144       // forward the network status if it uses.
   245     if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOnline )
   145     if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOnline )
   246         {
   146         {
   247         OnLineL();
   147         actions->AppendL( TLiwVariant( KOnLine ));
   248         }
   148         }
   249     else if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOffline )
   149     else if ( iPlugin->NetworkStatus() == CWrtDataPlugin::EOffline )
   250         {
   150         {
   251         OffLineL();
   151         actions->AppendL( TLiwVariant(  KOffLine));
       
   152         }
       
   153 
       
   154     ReSendNotificationL( actions );
       
   155     CleanupStack::PopAndDestroy( actions );
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CWrtData::PublishInitialDataL
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CWrtData::PublishInitialDataL( MAiContentObserver* aObserver )
       
   163     {
       
   164     // Show loading animation
       
   165     iPlugin->ShowLoadingIcon( aObserver );
       
   166 
       
   167     TBuf<KWRTContentValueMaxLength> appName;
       
   168     TBuf<KWRTAppUidLenth> appUidStr;
       
   169     GetWidgetNameAndUidL( appName, appUidStr );
       
   170 
       
   171     // Publish widget's name
       
   172     if ( appName.Length() > 0 )
       
   173        {
       
   174        iPlugin->PublishTextL( aObserver, CWrtDataPlugin::EDefaultText, appName );
       
   175        }
       
   176 
       
   177     // Publish widget's apparc image. This might fail if there is application
       
   178     // list population ongoing in AppFW and then we have to try again later
       
   179     if ( ResolveUid ( appUidStr, iAppUid ) )
       
   180         {
       
   181         TRAPD( err, PublishDefaultImageL( aObserver ) );
       
   182         if ( KErrNone != err )
       
   183             {
       
   184             iPlugin->StartTimer();
       
   185             }
   252         }
   186         }
   253     }
   187     }
   254 
   188 
   255 // ---------------------------------------------------------------------------
   189 // ---------------------------------------------------------------------------
   256 // CWrtData::PublishDefaultImageL
   190 // CWrtData::PublishDefaultImageL
   257 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   258 //
   192 //
   259 void CWrtData::PublishDefaultImageL( MAiContentObserver* aObserver )
   193 void CWrtData::PublishDefaultImageL( MAiContentObserver* aObserver )
   260     {
   194     {
   261     TBuf<KWRTAppUidLenth> appUidStr;
   195     // Publish widget's apparc image
   262     TBuf<KWRTContentValueMaxLength> appName;
   196     TInt handle = KErrNotFound;
   263     GetWidgetNameAndUidL( appName, appUidStr );
   197     TInt mask = KErrNotFound;
   264     
   198     // create icon from application UID
   265     TUid appUid;
   199     CreateIconFromUidL( handle, mask, iAppUid );
   266     if ( ResolveUid (appUidStr, appUid ) )
   200     // Publish apparc image 
   267         {
   201     iPlugin->PublishImageL( aObserver,
   268 #ifdef WRT_PREDEFINED_IMAGE         
   202                                 CWrtDataPlugin::EDefaultImage,
   269         RFs rfs;
   203                                 handle,
   270         User::LeaveIfError( rfs.Connect() );
   204                                 mask );
   271 
   205     }
   272         TFileName privatePath;
   206 
   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 
   207 
   320 // ---------------------------------------------------------------------------
   208 // ---------------------------------------------------------------------------
   321 // CWrtData::PublishL
   209 // CWrtData::PublishL
   322 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   323 //
   211 //
   380    {
   268    {
   381    HBufC8* triggerName = HBufC8::NewLC( KWRTContentNameMaxLength );
   269    HBufC8* triggerName = HBufC8::NewLC( KWRTContentNameMaxLength );
   382   
   270   
   383    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   271    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   384    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   272    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   385    CLiwDefaultMap* filter = NULL;
   273 
       
   274    // use the first item configuration to create the filter
       
   275    CLiwDefaultMap* filter  = CreateFilterLC();
   386 
   276 
   387    triggerName->Des().Copy(aTrigger);
   277    triggerName->Des().Copy(aTrigger);
   388    if ( aObjectId == KPubData )
   278    if ( aObjectId == KPubData )
   389        {
   279        {
   390        // this trigger belongs to publisher registery.
   280        // this trigger belongs to publisher registery.
   391        // in such case it is assumed that all the items in the widgets
   281        // in such case it is assumed that all the items in the widgets
   392        // belongs to same publisher, type and id.
   282        // belongs to same publisher, type and id.
   393        TLiwGenericParam cptype( KType, TLiwVariant( KPubData ) );
   283        TLiwGenericParam cptype( KType, TLiwVariant( KPubData ) );
   394        inParamList->AppendL( cptype );
   284        inParamList->AppendL( cptype );
   395        cptype.Reset();
   285        cptype.Reset();
   396        // use the first item configuration to create the filter
       
   397        filter = CreateFilterLC();
       
   398        }
   286        }
   399    else
   287    else
   400        {
   288        {
   401        if ( aObjectId == KMenuItem16 )
   289         //append type to inparam list
   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 ) );
   290        TLiwGenericParam cptype( KType, TLiwVariant( KCpData ) );
   428        inParamList->AppendL( cptype );
   291        inParamList->AppendL( cptype );
   429        cptype.Reset();
   292        cptype.Reset();
   430        }
   293        }
   431 
   294 
   433    //append filter to input param
   296    //append filter to input param
   434     TLiwGenericParam item( KFilter, TLiwVariant( filter ) );
   297     TLiwGenericParam item( KFilter, TLiwVariant( filter ) );
   435     inParamList->AppendL( item );
   298     inParamList->AppendL( item );
   436     iInterface->ExecuteCmdL( KExecuteAction,  *inParamList, *outParamList );
   299     iInterface->ExecuteCmdL( KExecuteAction,  *inParamList, *outParamList );
   437     
   300     
       
   301     item.Reset();
   438     CleanupStack::PopAndDestroy( filter );
   302     CleanupStack::PopAndDestroy( filter );
   439     CleanupStack::PopAndDestroy( triggerName );
   303     CleanupStack::PopAndDestroy( triggerName );
   440     item.Reset();
   304     outParamList->Reset();
   441 
       
   442     inParamList->Reset();
   305     inParamList->Reset();
   443     outParamList->Reset();  
       
   444     
       
   445     }
   306     }
   446 
   307 
   447 // ---------------------------------------------------------------------------
   308 // ---------------------------------------------------------------------------
   448 // CWrtData::IsPluginActive
   309 // CWrtData::IsPluginActive
   449 // ---------------------------------------------------------------------------
   310 // ---------------------------------------------------------------------------
   450 //
   311 //
   451 TBool CWrtData::IsPluginActive()
   312 TBool CWrtData::IsPluginActive()
   452     {
   313     {
   453     return iPlugin->IsActive();
   314     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::OnLineL
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CWrtData::OnLineL()
       
   497     {
       
   498     ChangePublisherStatusL( KOnLine );
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CWrtData::offLineL
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CWrtData::OffLineL()
       
   506     {
       
   507     ChangePublisherStatusL( KOffLine );
       
   508     }
   315     }
   509 
   316 
   510 // ---------------------------------------------------------------------------
   317 // ---------------------------------------------------------------------------
   511 // CWrtData::CreateFilterL
   318 // CWrtData::CreateFilterL
   512 // ---------------------------------------------------------------------------
   319 // ---------------------------------------------------------------------------
   537      inParamList->AppendL( item );
   344      inParamList->AppendL( item );
   538      
   345      
   539     // execute service.It is assumed that iInterface is already initiatedd
   346     // execute service.It is assumed that iInterface is already initiatedd
   540     if(iInterface)
   347     if(iInterface)
   541         {
   348         {
   542         iInterface->ExecuteCmdL( *iCommandName, *inParamList, *outParamList);
   349         iInterface->ExecuteCmdL( KGetList, *inParamList, *outParamList);
   543         }
   350         }
   544     else
   351     else
   545         {
   352         {
   546         User::Leave( KErrNotSupported );
   353         User::Leave( KErrNotSupported );
   547         }
   354         }
   577         }
   384         }
   578     outParamList->Reset();
   385     outParamList->Reset();
   579     }
   386     }
   580 
   387 
   581 // ---------------------------------------------------------------------------
   388 // ---------------------------------------------------------------------------
   582 // CWrtData::PublisherStatusL
   389 // NotifyPublisherL
   583 // ---------------------------------------------------------------------------
   390 // ---------------------------------------------------------------------------
   584 //
   391 //
   585 void CWrtData::ChangePublisherStatusL(const TDesC& aStatus)
   392 void CWrtData::NotifyPublisherL(const TDesC8& aStatus)
   586     {
   393     {
   587     if( iContentId == NULL )
   394     if( iCpsExecute == NULL )
   588        {
   395         {
   589        return;
   396         User::Leave( KErrNotSupported );
   590        }
   397         }
   591    HBufC8* triggerName = HBufC8::NewLC(KWRTContentNameMaxLength);
   398     
   592    triggerName->Des().Copy(aStatus);
   399     CLiwDefaultMap* filter = CreateFilterLC();
   593    
   400     // Add execute command triggers. Idle framework will execute 
   594    CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
   401     iCpsExecute->AddCommand( iPluginId, KPubData, filter, aStatus );
   595    CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
   402     CleanupStack::PopAndDestroy( filter );
   596        
   403     }
   597    TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
       
   598    inParamList->AppendL( type );
       
   599               
       
   600    CLiwDefaultMap* filter = CreateFilterLC();
       
   601    filter->InsertL(KActionTrigger, TLiwVariant(triggerName->Des()) );
       
   602    
       
   603    TLiwGenericParam item( KFilter, TLiwVariant( filter ));
       
   604    inParamList->AppendL( item );
       
   605    
       
   606    if(iInterface)
       
   607        {
       
   608        iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
       
   609        }
       
   610    else
       
   611        {
       
   612        User::Leave( KErrNotSupported );
       
   613        }
       
   614    CleanupStack::PopAndDestroy( filter );
       
   615    
       
   616    inParamList->Reset();
       
   617    outParamList->Reset();
       
   618    CleanupStack::PopAndDestroy( triggerName );
       
   619    }
       
   620 
       
   621 // ---------------------------------------------------------------------------
       
   622 // CWrtData::GetMenuItemsL
       
   623 // ---------------------------------------------------------------------------
       
   624 //
       
   625 void CWrtData::GetMenuItemsL()
       
   626 	{
       
   627 	if(iInterface)
       
   628 		{
       
   629 		CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC();
       
   630 		CLiwDefaultMap* filter = CreateFilterLC( );
       
   631 		//append filter to input param
       
   632         ExecuteCommandL( filter, outDataMap, KPubData  );
       
   633 		CleanupStack::PopAndDestroy( filter );
       
   634 		
       
   635 		TLiwVariant variant;
       
   636 		TInt pos = outDataMap->FindL( KMenuItems, variant ) ;
       
   637 		
       
   638 		if ( pos  )
       
   639 			{
       
   640 			CLiwDefaultMap *menuMap = CLiwDefaultMap::NewLC();
       
   641 			variant.Get( *menuMap );
       
   642 			for ( TInt i = 0; i < menuMap->Count(); i++)
       
   643 				{
       
   644 				menuMap->FindL(menuMap->AtL(i), variant );
       
   645 				HBufC8* value = HBufC8::NewL( KWRTContentValueMaxLength );
       
   646 				CleanupStack::PushL( value );
       
   647 				TPtr8 valPtr = value->Des();
       
   648 				variant.Get( valPtr);
       
   649 				if ( valPtr.Length() > 0 )
       
   650 					{
       
   651 					iMenuTriggers.AppendL( value );
       
   652 					CleanupStack::Pop( value );
       
   653 					HBufC16* triggerName = HBufC16::NewLC( KWRTContentNameMaxLength );
       
   654 				    triggerName->Des().Copy( menuMap->AtL(i) );
       
   655 					iMenuItems.AppendL( triggerName );
       
   656 					CleanupStack::Pop( triggerName );
       
   657 					}
       
   658 				else
       
   659 					{
       
   660 					CleanupStack::PopAndDestroy( value );	
       
   661 					}
       
   662 				variant.Reset();
       
   663 				}
       
   664 			CleanupStack::PopAndDestroy( menuMap );
       
   665 			}
       
   666 		variant.Reset();
       
   667 		CleanupStack::PopAndDestroy( outDataMap );
       
   668 		}
       
   669 	}
       
   670 
   404 
   671 // ---------------------------------------------------------------------------
   405 // ---------------------------------------------------------------------------
   672 // CWrtData::GetWidgetNameAndUidL
   406 // CWrtData::GetWidgetNameAndUidL
   673 // ---------------------------------------------------------------------------
   407 // ---------------------------------------------------------------------------
   674 //
   408 //
   739                 error = lex.Val( id );
   473                 error = lex.Val( id );
   740                 aUid.iUid = id;
   474                 aUid.iUid = id;
   741                 }
   475                 }
   742             }
   476             }
   743         }
   477         }
   744     return (error == KErrNone );
   478     return ( error == KErrNone );
   745     }
   479     }
   746 
   480 
   747 // ---------------------------------------------------------------------------
   481 // ---------------------------------------------------------------------------
   748 // CWrtData::CreateIconFromUidL
   482 // CWrtData::CreateIconFromUidL
   749 // ---------------------------------------------------------------------------
   483 // ---------------------------------------------------------------------------
   750 //
   484 //
   751 void CWrtData::CreateIconFromUidL(TInt& aHandle, TInt& aMaskHandle, const TUid& aAppUid ) 
   485 void CWrtData::CreateIconFromUidL( TInt& aHandle, TInt& aMaskHandle, const TUid& aAppUid ) 
   752     {
   486     {
   753     RApaLsSession lsSession;
   487     RApaLsSession lsSession;
   754     User::LeaveIfError( lsSession.Connect() );
   488     User::LeaveIfError( lsSession.Connect() );
   755     CleanupClosePushL( lsSession ); // lsSession (1)
   489     CleanupClosePushL( lsSession ); // lsSession (1)
   756     
   490     
   757     CArrayFixFlat<TSize>* sizeArray = new(ELeave) CArrayFixFlat<TSize>( 5 );
   491     CArrayFixFlat<TSize>* sizeArray = new(ELeave) CArrayFixFlat<TSize>( 5 );
   758     CleanupStack::PushL( sizeArray );
   492     CleanupStack::PushL( sizeArray );
   759     if ( KErrNone == lsSession.GetAppIconSizes(aAppUid, *sizeArray) )
   493 
   760         {
   494     User::LeaveIfError( lsSession.GetAppIconSizes( aAppUid, *sizeArray ) );
   761         if ( sizeArray->Count() ) 
   495 
   762             {
   496     if ( sizeArray->Count() ) 
   763             // There are other icon sizes
   497         {
   764             TInt idx = 0;
   498         // There are other icon sizes
   765             TInt size( sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight );
   499         TInt idx = 0;
   766             for ( TInt i = 1; i < sizeArray->Count(); i++ ) 
   500         TInt size( sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight );
       
   501         for ( TInt i = 1; i < sizeArray->Count(); i++ ) 
       
   502             {
       
   503             if ( ( sizeArray->At(i).iWidth * sizeArray->At(i).iHeight ) > size )
   767                 {
   504                 {
   768                 if ( ( sizeArray->At(i).iWidth * sizeArray->At(i).iHeight ) > size )
   505                 idx = i;
   769                     {
   506                 size =  sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight;
   770                     idx = i;
       
   771                     size =  sizeArray->At(idx).iWidth * sizeArray->At(idx).iHeight;
       
   772                     }
       
   773                 }
   507                 }
   774 
   508             }
   775             CApaMaskedBitmap* appBitMap = CApaMaskedBitmap::NewLC();
   509 
   776             if ( KErrNone == lsSession.GetAppIcon( aAppUid, sizeArray->At(idx),
   510         CApaMaskedBitmap* appBitMap = CApaMaskedBitmap::NewLC();
   777                     *appBitMap ) )
   511         User::LeaveIfError( lsSession.GetAppIcon( aAppUid, sizeArray->At(idx), *appBitMap ) );
   778                 {
   512         aHandle = appBitMap->Handle();
   779                 aHandle = appBitMap->Handle();
   513         aMaskHandle = appBitMap->Mask()->Handle();
   780                 aMaskHandle = appBitMap->Mask()->Handle();
   514         CleanupStack::PopAndDestroy( appBitMap );
   781                 }
   515         }
   782             CleanupStack::PopAndDestroy( appBitMap );
   516 
   783             }
       
   784         }
       
   785     CleanupStack::PopAndDestroy( sizeArray );
   517     CleanupStack::PopAndDestroy( sizeArray );
   786     CleanupStack::PopAndDestroy( &lsSession );
   518     CleanupStack::PopAndDestroy( &lsSession );
   787     }
   519     }
   788 
   520 
       
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // ReSendNotificationL
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 void CWrtData::ReSendNotificationL(CLiwDefaultList* aActionsList)
       
   527     {
       
   528     if( iInterface == NULL )
       
   529         {
       
   530         User::Leave( KErrNotSupported );
       
   531         }
       
   532     
       
   533     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   534     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   535 
       
   536     TLiwGenericParam type( KType, TLiwVariant( KPubData ) );
       
   537     inParamList->AppendL( type );
       
   538      
       
   539     CLiwDefaultMap* filter = CreateFilterLC();
       
   540     // add list of action triggers to execute
       
   541     filter->InsertL(KActionTrigger, TLiwVariant(aActionsList) );
       
   542     
       
   543     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
       
   544     inParamList->AppendL( item );
       
   545     iInterface->ExecuteCmdL( KExecuteAction, *inParamList, *outParamList);
       
   546     CleanupStack::PopAndDestroy( filter );
       
   547     outParamList->Reset();
       
   548     inParamList->Reset();
       
   549 
       
   550     }
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 // SetCommandBuffer
       
   554 // ---------------------------------------------------------------------------
       
   555 //
       
   556 void CWrtData::SetCommandBuffer(TAny* aAny, const TDesC8& aNameSpace )
       
   557     {
       
   558     iPluginId.Copy(aNameSpace);
       
   559     iCpsExecute = reinterpret_cast <MAiCpsCommandBuffer* > ( aAny );
       
   560     if ( iCpsExecute )
       
   561         {
       
   562         iInterface = iCpsExecute->CpsInterface();
       
   563         iServiceHandler = iCpsExecute->ServiceHandler();
       
   564         }
       
   565     }
       
   566 
       
   567 // End of file
       
   568