idlefw/plugins/sapidataplugin/src/sapidataplugin.cpp
branchRCL_3
changeset 8 d0529222e3f0
parent 1 844b978f8d5e
child 11 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 8:d0529222e3f0
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Profile plug-in publisher
    14 * Description:  SAPI data plug-in publisher
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 // System includes
    19 #include <ecom/ecom.h>
    19 #include <ecom/ecom.h>
    20 #include <ecom/implementationproxy.h>
    20 #include <ecom/implementationproxy.h>
    21 #include <aicontentobserver.h>
       
    22 #include <aiutility.h>
       
    23 #include <aipspropertyobserver.h>
       
    24 #include <PUAcodes.hrh>
    21 #include <PUAcodes.hrh>
    25 #include <aipluginsettings.h>
       
    26 #include <badesca.h>
    22 #include <badesca.h>
    27 #include <fbs.h>
    23 #include <fbs.h>
    28 #include <gulicon.h>
    24 #include <gulicon.h>
    29 #include <AknsSkinInstance.h> 
    25 #include <AknsSkinInstance.h> 
    30 #include <AknsUtils.h> 
    26 #include <AknsUtils.h> 
    31 #include <AknsConstants.h>
    27 #include <AknsConstants.h>
    32 #include <e32property.h>
    28 #include <e32property.h>
       
    29 
       
    30 // User includes
       
    31 #include <hspublisherinfo.h>
       
    32 #include <aicontentobserver.h>
       
    33 #include <aiutility.h>
       
    34 #include <aipspropertyobserver.h>
       
    35 #include <aipluginsettings.h>
    33 #include <activeidle2domainpskeys.h>
    36 #include <activeidle2domainpskeys.h>
    34 
    37 
    35 #include "sapidatapluginconst.h"
    38 #include "sapidatapluginconst.h"
    36 #include "sapidatapluginuids.hrh"
    39 #include "sapidatapluginuids.hrh"
    37 #include "sapidataplugin.h"
    40 #include "sapidataplugin.h"
    38 #include "sapidata.h"
    41 #include "sapidata.h"
    39 
    42 
    40 // CONST CLASS VARIABLES
    43 // Constants
    41 const TImplementationProxy KImplementationTable[] =
    44 const TImplementationProxy KImplementationTable[] =
    42     {
    45     {
    43     IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CSapiDataPlugin::NewL ) 
    46     IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CSapiDataPlugin::NewL ) 
    44     };
    47     };
    45 
    48 
    73 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    74 // Default constructor
    77 // Default constructor
    75 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    76 //
    79 //
    77 CSapiDataPlugin::CSapiDataPlugin()
    80 CSapiDataPlugin::CSapiDataPlugin()
       
    81     : iNetworkStatus( EUnknown ), iPluginState( ENone ) 
    78     {
    82     {
    79     }
    83     }
    80     
    84     
    81 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
    82 // Symbian 2nd phase constructor can leave
    86 // Symbian 2nd phase constructor can leave
    83 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    84 //
    88 //
    85 void CSapiDataPlugin::ConstructL()
    89 void CSapiDataPlugin::ConstructL()
    86     { 
    90     {     
    87     iInfo.iUid.iUid = SAPIDP_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DATAPLUGIN; 
    91     User::LeaveIfError( iRfs.Connect() );
    88     iPluginState = ENone;
    92     
    89     iHSForeGround = EFalse;
    93     iData = CSapiData::NewL( this );   
    90     iKeyLockOn = EFalse;
       
    91     iNetworkStatus = EUnknown;
       
    92     iData = CSapiData::NewL(this);
       
    93 
       
    94     }
    94     }
    95     
    95     
    96 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
    97 // Destructor
    97 // Destructor
    98 // Deletes all data created to heap
    98 // Deletes all data created to heap
    99 // ---------------------------------------------------------------------------
    99 // ---------------------------------------------------------------------------
   100 //
   100 //
   101 CSapiDataPlugin::~CSapiDataPlugin()
   101 CSapiDataPlugin::~CSapiDataPlugin()
   102     {
   102     {
   103     // deactivate the publishers
   103     // deactivate the publishers
   104     if( iData )
   104     if ( iData )
   105         {
   105         {
   106         TRAP_IGNORE(iData->DeActivateL());
   106         TRAP_IGNORE( iData->ChangePublisherStatusL( KDeActive ));
       
   107         
   107         delete iData;
   108         delete iData;
   108         }
   109         }
       
   110     
   109     iObservers.Close();
   111     iObservers.Close();
   110     Release( iContent );
   112     Release( iContent );
       
   113 
   111     iDataArray.ResetAndDestroy();
   114     iDataArray.ResetAndDestroy();
   112 
   115 
   113     if( iContentModel)
   116     if ( iContentModel )
   114         {
   117         {
   115         for( TInt i = iDataCount-1;i>=0  ; i-- )
   118         for ( TInt i = iDataCount - 1; i >= 0  ; i-- )
   116             {
   119             {
   117             User::Free((TAny*)iContentModel[i].cid);   
   120             User::Free((TAny*)iContentModel[i].cid);   
   118             }
   121             }
   119         delete []iContentModel;
   122         
   120         }
   123         delete [] iContentModel;
       
   124         }
       
   125     
   121     iIconArray.Reset();
   126     iIconArray.Reset();
   122     }
   127     
   123 
   128     iRfs.Close();
   124 // ---------------------------------------------------------------------------
   129     }
   125 // From class CAiContentPublisher
   130 
   126 // Plug-ins take ownership of the settings array, so it must either
       
   127 // store it in a member or free it.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CSapiDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
       
   131     {
       
   132     if( iDataCount > 0 )
       
   133         {
       
   134         // We own the array so destroy it
       
   135          aSettings.ResetAndDestroy();
       
   136          return;
       
   137         }
       
   138     
       
   139     RAiSettingsItemArray contentItemsArr;
       
   140     RAiSettingsItemArray configurationItemsArr;
       
   141     
       
   142     TInt count = aSettings.Count();
       
   143     for(TInt i = 0; i < count; i++ )
       
   144         {
       
   145         MAiPluginSettings* pluginSetting = aSettings[i];
       
   146         if( pluginSetting->AiPluginItemType() == EAiPluginContentItem )
       
   147             {
       
   148             contentItemsArr.Append(pluginSetting);
       
   149             }
       
   150         else if( pluginSetting->AiPluginItemType() == EAiPluginConfigurationItem )
       
   151             {
       
   152             configurationItemsArr.Append(pluginSetting);
       
   153             }
       
   154         }
       
   155     iDataCount = contentItemsArr.Count();
       
   156     if(iDataCount > 0 )
       
   157         {
       
   158         // Create the content Model
       
   159         HBufC* contentId = HBufC::NewLC( KAiContentIdMaxLength + KAiPluginNameMaxLength );
       
   160         iContentModel = new TAiContentItem[iDataCount];
       
   161         for(TInt i = 0; i < iDataCount; i++)
       
   162             {
       
   163             MAiPluginContentItem& contentItem = (contentItemsArr[i])->AiPluginContentItem();
       
   164             iContentModel[i].id = i;
       
   165             if( contentItem.Type() == KText() || contentItem.Type() == KNewsTicker() )
       
   166                 {
       
   167                 // text
       
   168                 iContentModel[i].type = KAiContentTypeText;
       
   169                 }
       
   170             if( contentItem.Type() == KImage() )
       
   171                 {
       
   172                 // image
       
   173                 iContentModel[i].type = KAiContentTypeBitmap;
       
   174                 }
       
   175             
       
   176             contentId->Des().Copy(contentItem.Name());
       
   177             contentId->Des().Delete(0, contentId->Des().LocateReverse(KPluginNameSeprator) +1);
       
   178   
       
   179             TInt sizeOfContentId = contentId->Des().Size()+sizeof(wchar_t);
       
   180             iContentModel[i].cid = static_cast<const wchar_t*>( User::Alloc( sizeOfContentId ) );
       
   181             Mem::Copy((TAny*)iContentModel[i].cid, contentId->Des().PtrZ(), sizeOfContentId);
       
   182             
       
   183             contentId->Des().Delete( 0, contentId->Des().Length());
       
   184             }    
       
   185         
       
   186         CleanupStack::PopAndDestroy( contentId );
       
   187         iContent = AiUtility::CreateContentItemArrayIteratorL( iContentModel, iDataCount );
       
   188         // Configurations 
       
   189         iData->ConfigureL(configurationItemsArr);
       
   190         
       
   191         // Activate the publisher
       
   192         iData->ActivateL();
       
   193                 
       
   194         // Register for notifications
       
   195         iData->RegisterPublisherObserverL();
       
   196       
       
   197         PublishL();
       
   198         
       
   199         iPluginState = ESuspend;
       
   200         iData->RegisterContentObserverL();
       
   201         }
       
   202     contentItemsArr.Reset();
       
   203     configurationItemsArr.Reset();
       
   204        // We own the array so destroy it
       
   205     aSettings.ResetAndDestroy();
       
   206     // publish the initial data
       
   207     }
       
   208 
   131 
   209 // ---------------------------------------------------------------------------
   132 // ---------------------------------------------------------------------------
   210 // Publishes widget's texts and images
   133 // Publishes widget's texts and images
   211 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   212 //
   135 //
   213 void CSapiDataPlugin::PublishL()
   136 void CSapiDataPlugin::PublishL()
   214     {
   137     {    
   215     User::LeaveIfError( iRfs.Connect() );
       
   216 
       
   217     TInt observers( iObservers.Count() );        
   138     TInt observers( iObservers.Count() );        
   218     TInt transactionId = reinterpret_cast<TInt>( this );
   139     TInt transactionId = reinterpret_cast<TInt>( this );
   219 
   140 
   220     for ( int i = 0; i < observers; i++ )
   141     for ( TInt i = 0; i < observers; i++ )
   221         {
   142         {
   222         MAiContentObserver* observer = iObservers[i];
   143         MAiContentObserver* observer = iObservers[i];
   223         
   144         
   224 		if ( observer->StartTransaction( transactionId ) == KErrNone ) 				
   145 		if ( observer->StartTransaction( transactionId ) == KErrNone ) 				
   225             {
   146             {
   231 		// Release memory of the published text
   152 		// Release memory of the published text
   232         iDataArray.ResetAndDestroy();
   153         iDataArray.ResetAndDestroy();
   233         // Release memory of the published icons
   154         // Release memory of the published icons
   234         iIconArray.Reset();
   155         iIconArray.Reset();
   235         
   156         
   236         }
   157         }    
   237     iRfs.Close();
       
   238     }
   158     }
   239 
   159 
   240 // ---------------------------------------------------------------------------
   160 // ---------------------------------------------------------------------------
   241 // Publish a specific text of the widget  
   161 // Publish a specific text of the widget  
   242 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   338               aObserver->Clean( *this, aContentId, aContentId );
   258               aObserver->Clean( *this, aContentId, aContentId );
   339               }
   259               }
   340           }
   260           }
   341       else  // Interpret as File path
   261       else  // Interpret as File path
   342           {
   262           {
   343           RFile* iconFile = new (ELeave) RFile();
   263           RFile iconFile;
   344           err = iconFile->Open( iRfs, aPath, EFileShareReadersOnly |  EFileRead );
   264           
       
   265           err = iconFile.Open( iRfs, aPath, EFileShareReadersOnly |  EFileRead );
       
   266 
   345           if( err == KErrNone )
   267           if( err == KErrNone )
   346             {
   268             {
   347              aObserver->Publish( *this, aContentId, *iconFile, aContentId );
   269              aObserver->Publish( *this, aContentId, iconFile, aContentId );
   348             }
   270             }
   349           else
   271           else
   350               {
   272               {
   351               aObserver->Clean( *this, aContentId, aContentId );
   273               aObserver->Clean( *this, aContentId, aContentId );
   352               }
   274               }
   353           iconFile->Close();
   275           
   354           delete iconFile;
   276           iconFile.Close();
   355           iconFile = NULL;
       
   356           }
   277           }
   357         }
   278         }
   358     }
   279     }
   359 
   280 
   360 // ---------------------------------------------------------------------------
   281 // ---------------------------------------------------------------------------
   440 // ---------------------------------------------------------------------------
   361 // ---------------------------------------------------------------------------
   441 //Refresh a specific image of text in the widget
   362 //Refresh a specific image of text in the widget
   442 // ---------------------------------------------------------------------------
   363 // ---------------------------------------------------------------------------
   443 //
   364 //
   444 void CSapiDataPlugin::RefreshL(TDesC& aContentType, TDesC& aOperation)
   365 void CSapiDataPlugin::RefreshL(TDesC& aContentType, TDesC& aOperation)
   445     {
   366     {     
   446      User::LeaveIfError( iRfs.Connect() );
       
   447 	 TInt observers( iObservers.Count() );        
   367 	 TInt observers( iObservers.Count() );        
   448 	 TInt transactionId = reinterpret_cast<TInt>( this );
   368 	 TInt transactionId = reinterpret_cast<TInt>( this );
   449 	 
   369 	 
   450 	 for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
   370 	 for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
   451 		{
   371 		{
   466 			}
   386 			}
   467 		
   387 		
   468 		 // Relese memory of the published text
   388 		 // Relese memory of the published text
   469          iDataArray.ResetAndDestroy();
   389          iDataArray.ResetAndDestroy();
   470 		 iIconArray.Reset();
   390 		 iIconArray.Reset();
   471 		}
   391 		}	 
   472 	 iRfs.Close();
       
   473     }
   392     }
   474 
   393 
   475 // ---------------------------------------------------------------------------
   394 // ---------------------------------------------------------------------------
   476 // Cleans a data from the widget
   395 // Cleans a data from the widget
   477 // ---------------------------------------------------------------------------
   396 // ---------------------------------------------------------------------------
   481 	{
   400 	{
   482 	 if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
   401 	 if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
   483 		{
   402 		{
   484 		aObserver->Clean( *this, aContentId, aContentId );		
   403 		aObserver->Clean( *this, aContentId, aContentId );		
   485 		}
   404 		}
   486 
       
   487 	}
   405 	}
   488 // ---------------------------------------------------------------------------
   406 
   489 // From class CAiContentPublisher
   407 // ----------------------------------------------------------------------------
   490 // Plug-in is requested to unload its engines due backup operation
   408 // CSapiDataPlugin::Start
   491 // ---------------------------------------------------------------------------
   409 //
   492 //
   410 // ----------------------------------------------------------------------------
   493 void CSapiDataPlugin::Stop( TAiTransitionReason aReason )
   411 //
   494     {
   412 void CSapiDataPlugin::Start( TStartReason aReason )
   495     if( iPluginState == EResume )
   413     {
   496         {
   414     if( aReason == ESystemStartup )
   497         Suspend( aReason );
   415         {
   498         }
   416         TRAP_IGNORE( iData->SetStartupReasonL( KSystemStartup ));
   499     }
   417         }
   500 
   418     else if( aReason == EPageStartup )
   501 // ---------------------------------------------------------------------------
   419         {
   502 // From class CAiContentPublisher
   420         TRAP_IGNORE( iData->SetStartupReasonL( KPageStartup ));
   503 // Plug-in is instructed that it is allowed to consume CPU resources
   421         }
   504 // ---------------------------------------------------------------------------
   422     else if( aReason == EPluginStartup )
   505 //
   423         {
   506 void CSapiDataPlugin::Resume( TAiTransitionReason aReason )
   424         TRAP_IGNORE( iData->SetStartupReasonL( KPluginStartup));
   507     {
   425         }
   508     TRAP_IGNORE( DoResumeL( aReason ) ); 
   426     }
   509     }
   427 
   510     
   428 // ----------------------------------------------------------------------------
   511 // ---------------------------------------------------------------------------
   429 // CSapiDataPlugin::Stop
   512 // From class CAiContentPublisher
   430 //
   513 // Plug-in is instructed that it is not allowed to consume CPU resources
   431 // ----------------------------------------------------------------------------
   514 // ---------------------------------------------------------------------------
   432 //
   515 //
   433 void CSapiDataPlugin::Stop( TStopReason aReason )
   516 void CSapiDataPlugin::Suspend( TAiTransitionReason aReason )
   434     {
   517     {
   435     if( aReason == ESystemShutdown )
   518     switch( aReason )
   436         {
   519 		{
   437         TRAP_IGNORE( iData->ChangePublisherStatusL( KSystemShutdown ));
   520 		case EAiKeylockDisabled:
   438         }
   521         case EAiKeylockEnabled:
   439     else if( aReason == EPageShutdown )
   522         	{
   440         {
   523         	// handled in resume 
   441         TRAP_IGNORE( iData->ChangePublisherStatusL( KPageShutdown ));
   524         	TRAP_IGNORE( DoResumeL( aReason ) ); 
   442         }
   525         	break;
   443     else if( aReason == EPluginShutdown )
   526         	}
   444         {
   527         default :
   445         TRAP_IGNORE( iData->ChangePublisherStatusL( KPluginShutdown ));
   528         	{
   446         }
   529         	iPluginState = ESuspend;
   447     }
   530         	TRAP_IGNORE ( iData->SuspendL() );
   448 
   531         	}
   449 // ----------------------------------------------------------------------------
   532 		}
   450 // CSapiDataPlugin::Resume
   533     }
   451 //
   534 
   452 // ----------------------------------------------------------------------------
   535 // ---------------------------------------------------------------------------
   453 //
   536 // From class CAiContentPublisher
   454 void CSapiDataPlugin::Resume( TResumeReason aReason )
   537 // The plug-in MUST maintain a registry of subscribers and send 
   455     {
   538 // notification to all of them whenever the state changes or new content
   456     if ( aReason == EForeground )
   539 // is available
   457         {
   540 // ---------------------------------------------------------------------------
   458         iPluginState = EResume;
       
   459         TRAP_IGNORE( iData->ChangePublisherStatusL( KResume ));
       
   460         }
       
   461     }
       
   462 
       
   463 // ----------------------------------------------------------------------------
       
   464 // CSapiDataPlugin::Suspend
       
   465 //
       
   466 // ----------------------------------------------------------------------------
       
   467 //
       
   468 void CSapiDataPlugin::Suspend( TSuspendReason aReason )
       
   469     {
       
   470     if ( aReason == EBackground )
       
   471         {
       
   472         iPluginState = ESuspend;
       
   473         TRAP_IGNORE( iData->ChangePublisherStatusL( KSuspend ));
       
   474         }    
       
   475     }
       
   476 
       
   477 // ----------------------------------------------------------------------------
       
   478 // CSapiDataPlugin::SetOnline
       
   479 //
       
   480 // ----------------------------------------------------------------------------
       
   481 //
       
   482 void CSapiDataPlugin::SetOnline()
       
   483     {
       
   484     if ( iNetworkStatus != EOnline )
       
   485         {
       
   486         iNetworkStatus = EOnline;
       
   487         TRAP_IGNORE( iData->ChangePublisherStatusL( KOnLine ));
       
   488         }
       
   489     }
       
   490 
       
   491 // ----------------------------------------------------------------------------
       
   492 // CSapiDataPlugin::SetOffline
       
   493 //
       
   494 // ----------------------------------------------------------------------------
       
   495 //
       
   496 void CSapiDataPlugin::SetOffline()
       
   497     {
       
   498     if ( iNetworkStatus != EOffline )
       
   499         {
       
   500         iNetworkStatus = EOffline;
       
   501         TRAP_IGNORE( iData->ChangePublisherStatusL( KOffLine ));
       
   502         }
       
   503     }
       
   504 
       
   505 // ----------------------------------------------------------------------------
       
   506 // CSapiDataPlugin::SubscribeL
       
   507 //
       
   508 // ----------------------------------------------------------------------------
   541 //
   509 //
   542 void CSapiDataPlugin::SubscribeL( MAiContentObserver& aObserver )
   510 void CSapiDataPlugin::SubscribeL( MAiContentObserver& aObserver )
   543     { 
   511     {
   544     iObservers.AppendL( &aObserver );
   512     iObservers.AppendL( &aObserver );
   545     }
   513     }
   546  
   514 
   547 
   515 // ----------------------------------------------------------------------------
   548 // ---------------------------------------------------------------------------
   516 // CSapiDataPlugin::ConfigureL
   549 // From class CAiContentPublisher
   517 //
   550 // Returns the extension interface. Actual type depends on the passed 
   518 // ----------------------------------------------------------------------------
   551 // aUid argument.
   519 //
   552 // ---------------------------------------------------------------------------
   520 void CSapiDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
   553 //
   521     {
   554 TAny* CSapiDataPlugin::Extension( TUid aUid )
   522     if ( iDataCount > 0 )
       
   523         {
       
   524         // We own the array so destroy it
       
   525         aSettings.ResetAndDestroy();
       
   526         return;
       
   527         }
       
   528     
       
   529     RAiSettingsItemArray contentItemsArr;    
       
   530     RAiSettingsItemArray configurationItemsArr;
       
   531     
       
   532     TInt count( aSettings.Count() );
       
   533     
       
   534     for ( TInt i = 0; i < count; i++ )
       
   535         {
       
   536         MAiPluginSettings* setting( aSettings[i] );
       
   537         
       
   538         if ( setting->AiPluginItemType() == EAiPluginContentItem )
       
   539             {
       
   540             contentItemsArr.Append( setting );
       
   541             }
       
   542         else if ( setting->AiPluginItemType() == EAiPluginConfigurationItem )
       
   543             {
       
   544             configurationItemsArr.Append( setting );
       
   545             }
       
   546         }
       
   547     
       
   548     iDataCount = contentItemsArr.Count();
       
   549     
       
   550     if ( iDataCount > 0 )
       
   551         {
       
   552         // Create the content Model
       
   553         HBufC* contentId = HBufC::NewLC( 
       
   554             KAiContentIdMaxLength + KAiPluginNameMaxLength );
       
   555         
       
   556         iContentModel = new TAiContentItem[iDataCount];
       
   557         
       
   558         for ( TInt i = 0; i < iDataCount; i++ )
       
   559             {
       
   560             MAiPluginContentItem& contentItem( 
       
   561                 contentItemsArr[i]->AiPluginContentItem() );
       
   562             
       
   563             iContentModel[i].id = i;
       
   564             
       
   565             if( contentItem.Type() == KText() || 
       
   566                 contentItem.Type() == KNewsTicker() ||
       
   567                 contentItem.Type() == KTextEditor() )            
       
   568                 {
       
   569                 // text
       
   570                 iContentModel[i].type = KAiContentTypeText;
       
   571                 }
       
   572             if( contentItem.Type() == KImage() )
       
   573                 {
       
   574                 // image
       
   575                 iContentModel[i].type = KAiContentTypeBitmap;
       
   576                 }
       
   577             
       
   578             contentId->Des().Copy( contentItem.Name() );
       
   579             contentId->Des().Delete( 0, 
       
   580                 contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 );
       
   581   
       
   582             TInt sizeOfContentId( contentId->Des().Size() + sizeof( wchar_t ) );
       
   583             
       
   584             iContentModel[i].cid = 
       
   585                 static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) );
       
   586                 
       
   587             Mem::Copy( ( TAny* )iContentModel[i].cid, 
       
   588                 contentId->Des().PtrZ(), sizeOfContentId );
       
   589             
       
   590             contentId->Des().Delete( 0, contentId->Des().Length() );
       
   591             }    
       
   592         
       
   593         CleanupStack::PopAndDestroy( contentId );
       
   594 
       
   595         iContent = AiUtility::CreateContentItemArrayIteratorL( 
       
   596             iContentModel, iDataCount );
       
   597     
       
   598         iData->SetContentIdL( PublisherInfo().Namespace() );
       
   599         
       
   600         // Configurations 
       
   601         iData->ConfigureL( configurationItemsArr );
       
   602         
       
   603         // Activate the publisher
       
   604         iData->ChangePublisherStatusL( KActive );
       
   605                 
       
   606         // Register for notifications
       
   607         iData->RegisterPublisherObserverL();
       
   608       
       
   609         PublishL();
       
   610         
       
   611         iPluginState = ESuspend;
       
   612         
       
   613         iData->RegisterContentObserverL();
       
   614         }
       
   615     
       
   616     contentItemsArr.Reset();
       
   617     configurationItemsArr.Reset();
       
   618    
       
   619     // We own the array so destroy it
       
   620     aSettings.ResetAndDestroy();    
       
   621     }
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // CSapiDataPlugin::GetProperty
       
   625 //
       
   626 // ----------------------------------------------------------------------------
       
   627 //
       
   628 TAny* CSapiDataPlugin::GetProperty( TProperty aProperty )
   555     {    
   629     {    
   556     if ( aUid == KExtensionUidProperty )
   630     if ( aProperty == EPublisherContent )
   557    		{
   631         {
   558         return static_cast<MAiPropertyExtension*>( this );
   632         return static_cast< MAiContentItemIterator* >( iContent );
   559     	}
   633         }
   560     else if (aUid == KExtensionUidEventHandler)
   634     
   561     	{
   635     return NULL;
   562         return static_cast<MAiEventHandlerExtension*>( this );
   636     }
   563     	}
   637 
   564     else
   638 // ----------------------------------------------------------------------------
   565     	{	
   639 // CSapiDataPlugin::HandleEvent
   566         return NULL;
   640 //
   567     	}
   641 // ----------------------------------------------------------------------------
   568     }
       
   569 
       
   570 // ---------------------------------------------------------------------------
       
   571 // From class MAiPropertyExtension
       
   572 // Read property of publisher plug-in.
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 TAny* CSapiDataPlugin::GetPropertyL( TInt aProperty )
       
   576     {
       
   577     TAny* property = NULL;
       
   578     
       
   579     switch ( aProperty )
       
   580         {
       
   581     case EAiPublisherInfo:
       
   582         {
       
   583          property = static_cast<TAiPublisherInfo*>( &iInfo );
       
   584         break;  
       
   585         }       
       
   586 
       
   587     case EAiPublisherContent:
       
   588         {
       
   589         property = static_cast<MAiContentItemIterator*>( iContent );
       
   590         break;    
       
   591         }        
       
   592     default:
       
   593         break;
       
   594         }
       
   595 
       
   596     return property;
       
   597     }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // From class MAiPropertyExtension
       
   601 // Write property value to optimize the content model.
       
   602 // ---------------------------------------------------------------------------
       
   603 //
       
   604 void CSapiDataPlugin::SetPropertyL( TInt aProperty, TAny* aValue )
       
   605     {  
       
   606     if( aProperty == EAiPublisherInfo )
       
   607         {
       
   608         ASSERT( aValue );
       
   609         
       
   610         const TAiPublisherInfo* info( 
       
   611                 static_cast<const TAiPublisherInfo*>( aValue ) );
       
   612         
       
   613         iInfo = *info;
       
   614         
       
   615         iData->SetContentIdL( info->iNamespace );
       
   616         }
       
   617     }
       
   618  
       
   619 // ---------------------------------------------------------------------------
       
   620 // From class MAiEventHandlerExtension.
       
   621 // Handles an event sent by the AI framework.
       
   622 // ---------------------------------------------------------------------------
       
   623 //
       
   624 void CSapiDataPlugin::HandleEvent( TInt /*aEvent*/, const TDesC& /*aParam*/ )
       
   625 	{
       
   626     // This is not as there is no event id to retrieve in this dynamic plugin. 
       
   627 	} 
       
   628     
       
   629 // ---------------------------------------------------------------------------
       
   630 // From class MAiEventHandlerExtension.
       
   631 // Handles an event sent by the AI framework.
       
   632 // ---------------------------------------------------------------------------
       
   633 //
   642 //
   634 void CSapiDataPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam )
   643 void CSapiDataPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam )
   635     {
   644     {
   636     // We have no way of reporting errors to framework so just ignore them.
   645     TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) );    
   637     TRAP_IGNORE(iData->ExecuteActionL( aEventName , aParam ) );
   646     }
   638     }
   647 
   639 
   648 // ----------------------------------------------------------------------------
   640 // ---------------------------------------------------------------------------
   649 // CSapiDataPlugin::HasMenuItem
   641 // From class MAiEventHandlerExtension.
   650 //
   642 // Invoked by the framework for querying if plugin has menu item
   651 // ----------------------------------------------------------------------------
   643 // ---------------------------------------------------------------------------
   652 //
   644 //
   653 TBool CSapiDataPlugin::HasMenuItem( const TDesC16& aMenuItem )
   645 TBool CSapiDataPlugin::HasMenuItem( const TDesC& aMenuItem )
   654     {
   646 	{ 
   655     return iData->HasMenuItem ( aMenuItem );    
   647 	return iData->HasMenuItem ( aMenuItem );  
   656     }
   648 	}
   657 
   649 
   658 // ----------------------------------------------------------------------------
   650 // ---------------------------------------------------------------------------
   659 // CSapiDataPlugin::IsActive
   651 // From class CAiContentPublisher
   660 //
   652 // framework instructs plug-in that it is allowed to consume CPU resources
   661 // ----------------------------------------------------------------------------
   653 // ---------------------------------------------------------------------------
   662 //
   654 //
   663 TBool CSapiDataPlugin::IsActive() const
   655 void CSapiDataPlugin::DoResumeL( TAiTransitionReason aReason )
   664     {
   656     {
   665     return iPluginState == EResume;
   657 	//update in startup phase and idle is on foreground.
   666     }
   658     switch ( aReason )
   667 
   659     	{
   668 // ----------------------------------------------------------------------------
   660         case EAiIdleOnLine:
   669 // CSapiDataPlugin::Data
   661         	{
   670 //
   662         	iNetworkStatus = EOnline;
   671 // ----------------------------------------------------------------------------
   663 			iData->OnLineL();
   672 //
   664 			break;
   673 CSapiData* CSapiDataPlugin::Data() const
   665         	}
   674     {
   666         case EAiIdleOffLine:
   675     return iData;
   667         	{
   676     }
   668 			iNetworkStatus = EOffline;
   677 
   669 			iData->OffLineL();
   678 // ----------------------------------------------------------------------------
   670 			break;
   679 // CSapiDataPlugin::NetworkStatus
   671 			}
   680 //
   672         case EAiIdlePageSwitch:
   681 // ----------------------------------------------------------------------------
   673         	{
   682 //
   674         	if ( iPluginState == EResume )
   683 CSapiDataPlugin::TPluginNetworkStatus CSapiDataPlugin::NetworkStatus() const
   675 				{
   684     {
   676 				iData->SuspendL();
   685     return iNetworkStatus;
   677 				}
   686     }
   678         	iPluginState = EInActive;
   687 
   679         	iData->InActiveL();
   688 // End of file
   680         	}
       
   681         	break;
       
   682         case EAiSystemStartup:
       
   683     	case EAiIdleForeground:
       
   684     		{
       
   685 			iHSForeGround = ETrue;
       
   686     		}
       
   687     	case EAiBacklightOn:    		
       
   688     		{
       
   689     		if ( iPluginState == ESuspend  && !iKeyLockOn )
       
   690 				{
       
   691 				iPluginState = EResume;
       
   692 				iData->ResumeL();
       
   693 				}
       
   694     		break;
       
   695 			}
       
   696     	case EAiKeylockDisabled:
       
   697         	{
       
   698         	iKeyLockOn = EFalse;
       
   699         	// Key lock events considered only if HS is in foreground  
       
   700         	if ( iHSForeGround && iPluginState == ESuspend )
       
   701         		{
       
   702         		iPluginState = EResume;
       
   703 				iData->ResumeL();
       
   704         		}
       
   705         	break;
       
   706         	}
       
   707     	case EAiKeylockEnabled:
       
   708         	{
       
   709         	iKeyLockOn = ETrue;
       
   710         	// Key lock events considered only if HS is in foreground
       
   711         	if ( iHSForeGround && iPluginState == EResume )
       
   712         		{
       
   713 				iPluginState = ESuspend ;
       
   714 				iData->SuspendL();
       
   715         		}
       
   716         	break;
       
   717         	}
       
   718     	case EAiScreenLayoutChanged:
       
   719         	{
       
   720         	// ignore events
       
   721         	break;
       
   722         	}
       
   723       case EAiGeneralThemeChanged:
       
   724           {
       
   725           // ignore event
       
   726           break;
       
   727           }
       
   728     	case EAiIdleBackground: 
       
   729         	{
       
   730 			iHSForeGround = EFalse;
       
   731         	}
       
   732         default :
       
   733         	{
       
   734 			if ( iPluginState == EResume )
       
   735 				{
       
   736 				iPluginState = ESuspend;
       
   737 				iData->SuspendL();
       
   738 				}
       
   739         	break;
       
   740         	}
       
   741     	}
       
   742     }
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // Is plugin active to publish the data 
       
   746 // ---------------------------------------------------------------------------
       
   747 //
       
   748 TBool CSapiDataPlugin::IsActive()
       
   749     {
       
   750     return (iPluginState == EResume );
       
   751     }