idlefw/plugins/wrtdataplugin/src/wrtdataplugin.cpp
changeset 0 79c6a41cd166
child 1 844b978f8d5e
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Profile plug-in publisher
       
    16 *
       
    17 */
       
    18 
       
    19 #include <ecom/ecom.h>
       
    20 #include <ecom/implementationproxy.h>
       
    21 #include <aicontentobserver.h>
       
    22 #include <aiutility.h>
       
    23 #include <aipspropertyobserver.h>
       
    24 #include <PUAcodes.hrh>
       
    25 #include <aipluginsettings.h>
       
    26 #include <badesca.h>
       
    27 #include <fbs.h>
       
    28 #include <gulicon.h>
       
    29 #include <AknsSkinInstance.h> 
       
    30 #include <AknsUtils.h> 
       
    31 #include <AknsConstants.h>
       
    32 #include <e32property.h>
       
    33 #include <activeidle2domainpskeys.h>
       
    34 
       
    35 #include "wrtdatapluginconst.h"
       
    36 #include "wrtdatapluginuids.hrh"
       
    37 #include "wrtdataplugin.h"
       
    38 #include "wrtdata.h"
       
    39 
       
    40 // CONST CLASS VARIABLES
       
    41 const TImplementationProxy KImplementationTable[] =
       
    42     {
       
    43     IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CWrtDataPlugin::NewL ) 
       
    44     };
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 // ---------------------------------------------------------------------------
       
    48 // Constructs and returns an application object.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount )
       
    52     {
       
    53     aTableCount = sizeof( KImplementationTable ) /
       
    54         sizeof( TImplementationProxy );
       
    55     return KImplementationTable;
       
    56     }
       
    57 
       
    58 // ======== MEMBER FUNCTIONS ========
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // Symbian 2nd phase constructor can leave
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CWrtDataPlugin* CWrtDataPlugin::NewL()
       
    65     {
       
    66     CWrtDataPlugin* self = new (ELeave) CWrtDataPlugin;
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72     
       
    73 // ---------------------------------------------------------------------------
       
    74 // Default constructor
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CWrtDataPlugin::CWrtDataPlugin()
       
    78     {
       
    79     }
       
    80     
       
    81 // ---------------------------------------------------------------------------
       
    82 // Symbian 2nd phase constructor can leave
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CWrtDataPlugin::ConstructL()
       
    86     { 
       
    87     iInfo.iUid.iUid = WRTDP_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DATAPLUGIN; 
       
    88     iPluginState = ENone;
       
    89     iHSForeGround = EFalse;
       
    90     iNetworkStatus = EUnknown;
       
    91     iData = CWrtData::NewL(this);
       
    92 
       
    93     }
       
    94     
       
    95 // ---------------------------------------------------------------------------
       
    96 // Destructor
       
    97 // Deletes all data created to heap
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CWrtDataPlugin::~CWrtDataPlugin()
       
   101     {
       
   102     // deactivate the publishers
       
   103     if( iData )
       
   104         {
       
   105         if ( iPluginState != EInActive )
       
   106         	{
       
   107         	TRAP_IGNORE(iData->DeActivateL());
       
   108         	}
       
   109         delete iData;
       
   110         }
       
   111     iObservers.Close();
       
   112     Release( iContent );
       
   113     iDataArray.ResetAndDestroy();
       
   114 
       
   115     if( iContentModel)
       
   116         {
       
   117         for( TInt i = iDataCount-1;i>=0  ; i-- )
       
   118             {
       
   119             User::Free((TAny*)iContentModel[i].cid);   
       
   120             }
       
   121         delete []iContentModel;
       
   122         }
       
   123     iIconArray.Reset();
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Publishes widget's texts and images
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CWrtDataPlugin::PublishL()
       
   131     {
       
   132     TInt err( KErrNone );
       
   133     User::LeaveIfError( iRfs.Connect() );
       
   134 
       
   135     TInt observers( iObservers.Count() );        
       
   136     TInt transactionId = reinterpret_cast<TInt>( this );
       
   137 
       
   138     for ( int i = 0; i < observers; i++ )
       
   139         {
       
   140         MAiContentObserver* observer = iObservers[i];
       
   141                 
       
   142         if ( observer->StartTransaction( transactionId ) == KErrNone )        	 
       
   143         	{// Publish all the data
       
   144             iData->PublishAllL(observer);
       
   145             observer->Commit( transactionId );
       
   146             }
       
   147 
       
   148         // Release memory of the published text
       
   149         iDataArray.ResetAndDestroy();
       
   150         // Release memory of the published icons
       
   151         iIconArray.Reset();
       
   152         }
       
   153     iRfs.Close();
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Publish a specific text of the widget  
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 /*
       
   161 void CWrtDataPlugin::PublishTextL(MAiContentObserver* aObserver, 
       
   162         TInt& aContentId, TDesC16& aContentValue)
       
   163     {
       
   164     if ( aObserver->CanPublish( *this,  aContentId  ,  aContentId  ) )
       
   165         {
       
   166         if( aContentValue.Length() > 0 )
       
   167             {
       
   168             HBufC* contentText = HBufC::NewLC(aContentValue.Size());
       
   169             TPtr16 cDes = contentText->Des();
       
   170             cDes.Copy(aContentValue);
       
   171             aObserver->Publish( *this, aContentId, cDes, aContentId );  
       
   172             iDataArray.AppendL( contentText );
       
   173             CleanupStack::Pop( contentText );
       
   174             }
       
   175         else
       
   176             {
       
   177             aObserver->Clean( *this, aContentId, aContentId );
       
   178             }
       
   179         }
       
   180     }*/
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Publish a specific image of the widget  
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CWrtDataPlugin::PublishImageL(MAiContentObserver* aObserver,
       
   187 		TContentItem aContentId, TDesC16& aPath )
       
   188     {
       
   189     TInt err = KErrNone;
       
   190     TAknsItemID iconId;
       
   191     iconId.iMajor=0;
       
   192     iconId.iMinor=0;
       
   193     TInt bitmapId(0);
       
   194     TInt maskId(0);
       
   195     TFileName fileName;
       
   196     CGulIcon* icon = NULL;
       
   197     CFbsBitmap* bitmap = NULL;
       
   198     CFbsBitmap* mask = NULL;
       
   199     
       
   200     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
       
   201       {
       
   202       TBool inSkin = iData->ResolveSkinIdAndMifId( aPath, iconId, bitmapId, maskId, fileName  );
       
   203       if ( inSkin )
       
   204           {
       
   205           // Load from skin 
       
   206           MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   207           if ( iconId.iMajor != 0 && iconId.iMajor!=0 )
       
   208               {
       
   209               // Create icon with fall back 
       
   210               TRAP_IGNORE(AknsUtils::CreateIconL(
       
   211                       skin,
       
   212                       iconId,
       
   213                       bitmap,
       
   214                       mask,
       
   215                       fileName,  /* backup filename */
       
   216                       bitmapId,  /* backup bit map id */
       
   217                       maskId));   /* backup mask id */
       
   218               }
       
   219           else if( bitmapId !=0 )
       
   220               {
       
   221               if ( maskId!=0 )
       
   222                   {
       
   223                   // Create icon from Mif filename , bitmap id and mask id
       
   224                   TRAP_IGNORE(icon = AknsUtils::CreateGulIconL(
       
   225                           skin,
       
   226                           iconId,
       
   227                           fileName,
       
   228                           bitmapId,
       
   229                           maskId) );
       
   230                   }
       
   231               else
       
   232                   {
       
   233                   TRAP_IGNORE(AknsUtils::CreateIconL(
       
   234                           skin,
       
   235                           iconId,
       
   236                           bitmap,
       
   237                           fileName,  /* backup filename */
       
   238                           bitmapId)); /* backup bit map id */
       
   239                   }
       
   240               }
       
   241           
       
   242           if ( icon == NULL && bitmap !=  NULL )
       
   243               {
       
   244               icon = CGulIcon::NewL( bitmap, mask );
       
   245               }
       
   246 
       
   247           if ( icon != NULL ) // Syntax correct but icon not found
       
   248               {
       
   249               aObserver->PublishPtr( *this, aContentId, icon , aContentId );
       
   250               iIconArray.Append(icon);
       
   251               } 
       
   252           else
       
   253               {
       
   254               err = KErrNotFound;   
       
   255               aObserver->Clean( *this, aContentId, aContentId );
       
   256               }
       
   257           }
       
   258       else  // Interpret as File path
       
   259           {
       
   260           RFile* iconFile = new (ELeave) RFile();
       
   261           err = iconFile->Open( iRfs, aPath, EFileShareReadersOnly |  EFileRead );
       
   262           if( err == KErrNone )
       
   263             {
       
   264              aObserver->Publish( *this, aContentId, *iconFile, aContentId );
       
   265             }
       
   266           else
       
   267               {
       
   268               aObserver->Clean( *this, aContentId, aContentId );
       
   269               }
       
   270           iconFile->Close();
       
   271           delete iconFile;
       
   272           iconFile = NULL;
       
   273           }
       
   274         }
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // Publish a image of the widget  
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CWrtDataPlugin::PublishImageL(MAiContentObserver* aObserver, 
       
   282 		TContentItem aContentId, TInt aHandle, TInt aMaskHandle )
       
   283     {
       
   284     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
       
   285         {
       
   286         if( aHandle != KErrBadHandle  )
       
   287             {
       
   288             CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
       
   289             if( KErrNone == bitmap->Duplicate( aHandle) )
       
   290                 {
       
   291                 // Take the ownership
       
   292                 CGulIcon* icon = CGulIcon::NewL(bitmap);
       
   293                 if( aMaskHandle != KErrBadHandle )
       
   294                     {
       
   295                     CFbsBitmap* mask = new (ELeave) CFbsBitmap();
       
   296                     if (KErrNone == mask->Duplicate( aMaskHandle) )
       
   297                         {
       
   298                         icon->SetMask( mask );            
       
   299                         }
       
   300                     }
       
   301                 aObserver->PublishPtr( *this, aContentId, icon , aContentId );
       
   302                 iIconArray.Append(icon);
       
   303                 }
       
   304             else
       
   305                 {
       
   306                 delete bitmap;
       
   307                 bitmap = NULL;
       
   308                 aObserver->Clean( *this, aContentId, aContentId );
       
   309                 }
       
   310             }
       
   311           }
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // Gets the id of a content  
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 TInt CWrtDataPlugin::GetIdL( TDesC16& aObjectId)
       
   319 	{
       
   320     TInt id = KErrNotFound;
       
   321     HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
       
   322 	for( TInt i = 0;i<  iDataCount; i++ )
       
   323 		{
       
   324 		 objectId->Des().Copy((TUint16*)iContentModel[i].cid);
       
   325 		 if( aObjectId == objectId->Des() )
       
   326 			 {
       
   327 			 id = iContentModel[i].id;
       
   328 			 break;
       
   329 			 }
       
   330 		}
       
   331 	CleanupStack::PopAndDestroy( objectId );
       
   332 	return id;
       
   333 	}
       
   334  
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // Gets type of a content
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CWrtDataPlugin::GetTypeL(TDesC16& aObjectId, TDes16& aType )
       
   341 	{
       
   342 	HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
       
   343 	for( TInt i = 0;i<  iDataCount; i++ )
       
   344 		{
       
   345 		objectId->Des().Copy((TUint16*)iContentModel[i].cid);
       
   346 		 if( aObjectId == objectId->Des() )
       
   347 			 {
       
   348 			 if( iContentModel[i].type ==  KAiContentTypeText)
       
   349 				 {
       
   350 				 aType.Copy( KText );
       
   351 				 }
       
   352 			 else if( iContentModel[i].type == KAiContentTypeBitmap)
       
   353 				 {
       
   354 				 aType.Copy( KImage );
       
   355 				 }
       
   356 			 break;
       
   357 			 }
       
   358 		}
       
   359 	CleanupStack::PopAndDestroy( objectId );
       
   360 	}
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 //Refresh a specific image of text in the widget
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void CWrtDataPlugin::RefreshL(TDesC16& aOperation)
       
   367     {
       
   368     TInt err( KErrNone );
       
   369     User::LeaveIfError( iRfs.Connect() );
       
   370     TInt observers( iObservers.Count() );        
       
   371     TInt transactionId = reinterpret_cast<TInt>( this );
       
   372    
       
   373     for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
       
   374         {
       
   375         MAiContentObserver* observer = iObservers[obsIndex];
       
   376     
       
   377         if ( observer->StartTransaction( transactionId ) == KErrNone )    	 
       
   378             {
       
   379             if( aOperation != KOperationDelete)
       
   380                 {
       
   381                 iData->PublishL( observer );
       
   382                 }
       
   383             else
       
   384                 {
       
   385                 Clean( observer , EImage1 ) ;
       
   386                 }
       
   387             
       
   388             observer->Commit( transactionId );
       
   389             }
       
   390      
       
   391         // Relese memory of the published text
       
   392         iDataArray.ResetAndDestroy();
       
   393         // Release memory of the published icons
       
   394         iIconArray.Reset();
       
   395         }
       
   396     
       
   397     iRfs.Close();
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // Cleans a data from the widget
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 void CWrtDataPlugin::Clean(MAiContentObserver* aObserver, 
       
   405         TInt aContentId )
       
   406 	{
       
   407 	 if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
       
   408 		{
       
   409 		aObserver->Clean( *this, aContentId, aContentId );		
       
   410 		}
       
   411 
       
   412 	}
       
   413 // ---------------------------------------------------------------------------
       
   414 // From class CAiContentPublisher
       
   415 // Plug-in is requested to unload its engines due backup operation
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 void CWrtDataPlugin::Stop( TAiTransitionReason aReason )
       
   419     {
       
   420     if( iPluginState == EResume )
       
   421         {
       
   422         Suspend( aReason );
       
   423         }
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // From class CAiContentPublisher
       
   428 // Plug-in is instructed that it is allowed to consume CPU resources
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CWrtDataPlugin::Resume( TAiTransitionReason aReason )
       
   432     {
       
   433     TRAP_IGNORE( DoResumeL( aReason ) ); 
       
   434     }
       
   435     
       
   436 // ---------------------------------------------------------------------------
       
   437 // From class CAiContentPublisher
       
   438 // Plug-in is instructed that it is not allowed to consume CPU resources
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CWrtDataPlugin::Suspend( TAiTransitionReason aReason )
       
   442     {
       
   443     switch( aReason )
       
   444 		{
       
   445 		case EAiKeylockDisabled:
       
   446         case EAiKeylockEnabled:
       
   447         	{
       
   448         	// handled in resume 
       
   449         	break;
       
   450         	}
       
   451         default :
       
   452         	{
       
   453         	iPluginState = ESuspend;
       
   454         	TRAP_IGNORE ( iData->SuspendL() );
       
   455         	}
       
   456 		}
       
   457     }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // From class CAiContentPublisher
       
   461 // The plug-in MUST maintain a registry of subscribers and send 
       
   462 // notification to all of them whenever the state changes or new content
       
   463 // is available
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CWrtDataPlugin::SubscribeL( MAiContentObserver& aObserver )
       
   467     { 
       
   468     iObservers.AppendL( &aObserver );
       
   469     }
       
   470  
       
   471 // ---------------------------------------------------------------------------
       
   472 // From class CAiContentPublisher
       
   473 // Plug-ins take ownership of the settings array, so it must either
       
   474 // store it in a member or free it.
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 void CWrtDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
       
   478     {
       
   479     if( iDataCount > 0 )
       
   480         {
       
   481         // We own the array so destroy it
       
   482          aSettings.ResetAndDestroy();
       
   483          return;
       
   484         }
       
   485     
       
   486     RAiSettingsItemArray contentItemsArr;
       
   487     RAiSettingsItemArray configurationItemsArr;
       
   488     RAiSettingsItemArray settingItemsArr;
       
   489     
       
   490     TInt count = aSettings.Count();
       
   491     for(TInt i = 0; i < count; i++ )
       
   492         {
       
   493         MAiPluginSettings* pluginSetting = aSettings[i];
       
   494         if( pluginSetting->AiPluginItemType() == EAiPluginContentItem )
       
   495             {
       
   496             contentItemsArr.Append(pluginSetting);
       
   497             }
       
   498         else if( pluginSetting->AiPluginItemType() == EAiPluginConfigurationItem )
       
   499             {
       
   500             configurationItemsArr.Append(pluginSetting);
       
   501             }
       
   502         else 
       
   503             {
       
   504             settingItemsArr.Append(pluginSetting);
       
   505             }
       
   506         }
       
   507     
       
   508     iDataCount = contentItemsArr.Count();
       
   509     if(iDataCount > 0 )
       
   510         {
       
   511         // Create the content Model
       
   512         HBufC16* contentId = HBufC16::NewLC( KAiContentIdMaxLength + KAiPluginNameMaxLength );
       
   513         iContentModel = new TAiContentItem[iDataCount];
       
   514         for(TInt i = 0; i < iDataCount; i++)
       
   515             {
       
   516             MAiPluginContentItem& contentItem = (contentItemsArr[i])->AiPluginContentItem();
       
   517             iContentModel[i].id = i;
       
   518             /*if( contentItem.Type() == KText() || contentItem.Type() == KNewsTicker() )
       
   519                 {
       
   520                 // text
       
   521                 iContentModel[i].type = KAiContentTypeText;
       
   522                 }*/
       
   523             if( contentItem.Type() == KImage() )
       
   524                 {
       
   525                 // image
       
   526                 iContentModel[i].type = KAiContentTypeBitmap;
       
   527                 }
       
   528             
       
   529             contentId->Des().Copy(contentItem.Name());
       
   530             contentId->Des().Delete(0, contentId->Des().LocateReverse(KPluginNameSeprator) +1);
       
   531   
       
   532             TInt sizeOfContentId = contentId->Des().Size()+sizeof(wchar_t);
       
   533             iContentModel[i].cid = static_cast<const wchar_t*>( User::Alloc( sizeOfContentId ) );
       
   534             Mem::Copy((TAny*)iContentModel[i].cid, contentId->Des().PtrZ(), sizeOfContentId);
       
   535             
       
   536             contentId->Des().Delete( 0, contentId->Des().Length());
       
   537             }    
       
   538         
       
   539         CleanupStack::PopAndDestroy( contentId );
       
   540         iContent = AiUtility::CreateContentItemArrayIteratorL( iContentModel, iDataCount );
       
   541         // Configurations 
       
   542         iData->ConfigureL(configurationItemsArr);
       
   543 
       
   544         iPluginState = ESuspend;
       
   545         // Register for notifications
       
   546         iData->RegisterL();
       
   547         
       
   548         // Activate the publisher 
       
   549         iData->ActivateL();
       
   550         }
       
   551     
       
   552     settingItemsArr.Reset();
       
   553     contentItemsArr.Reset();
       
   554     configurationItemsArr.Reset();
       
   555        // We own the array so destroy it
       
   556     aSettings.ResetAndDestroy();
       
   557     // publish the initial data
       
   558     PublishL();
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // From class CAiContentPublisher
       
   563 // Returns the extension interface. Actual type depends on the passed 
       
   564 // aUid argument.
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 TAny* CWrtDataPlugin::Extension( TUid aUid )
       
   568     {    
       
   569     if ( aUid == KExtensionUidProperty )
       
   570    		{
       
   571         return static_cast<MAiPropertyExtension*>( this );
       
   572     	}
       
   573     else if (aUid == KExtensionUidEventHandler)
       
   574     	{
       
   575         return static_cast<MAiEventHandlerExtension*>( this );
       
   576     	}
       
   577     else
       
   578     	{	
       
   579         return NULL;
       
   580     	}
       
   581     }
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // From class MAiPropertyExtension
       
   585 // Read property of publisher plug-in.
       
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 TAny* CWrtDataPlugin::GetPropertyL( TInt aProperty )
       
   589     {
       
   590     TAny* property = NULL;
       
   591     
       
   592     switch ( aProperty )
       
   593         {
       
   594     case EAiPublisherInfo:
       
   595         {
       
   596          property = static_cast<TAiPublisherInfo*>( &iInfo );
       
   597         break;  
       
   598         }       
       
   599 
       
   600     case EAiPublisherContent:
       
   601         {
       
   602         property = static_cast<MAiContentItemIterator*>( iContent );
       
   603         break;    
       
   604         }        
       
   605     default:
       
   606         break;
       
   607         }
       
   608 
       
   609     return property;
       
   610     }
       
   611 
       
   612 // ---------------------------------------------------------------------------
       
   613 // From class MAiPropertyExtension
       
   614 // Write property value to optimize the content model.
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 void CWrtDataPlugin::SetPropertyL( TInt aProperty, TAny* aValue )
       
   618     {  
       
   619     switch ( aProperty )
       
   620         {
       
   621 		case EAiPublisherInfo:
       
   622 			{
       
   623 			if( aValue )
       
   624 			    {
       
   625     		    const TAiPublisherInfo* info = static_cast<const TAiPublisherInfo*>( aValue );
       
   626 	    	    iInfo.iName.Copy( info->iName );
       
   627 	    	    iInfo.iNamespace.Copy( info->iNamespace );
       
   628 			    }
       
   629 		    break;
       
   630 		    }
       
   631 		default:
       
   632 		    break;         
       
   633         }
       
   634     }
       
   635  
       
   636 // ---------------------------------------------------------------------------
       
   637 // From class MAiEventHandlerExtension.
       
   638 // Handles an event sent by the AI framework.
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 void CWrtDataPlugin::HandleEvent( TInt /*aEvent*/, const TDesC& /*aParam*/ )
       
   642 	{
       
   643     // This is not as there is no event id to retrieve in this dynamic plugin. 
       
   644 	} 
       
   645     
       
   646 // ---------------------------------------------------------------------------
       
   647 // From class MAiEventHandlerExtension.
       
   648 // Handles an event sent by the AI framework.
       
   649 // ---------------------------------------------------------------------------
       
   650 //
       
   651 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam )
       
   652     {
       
   653     // We have no way of reporting errors to framework so just ignore them.
       
   654     TRAP_IGNORE(iData->ExecuteActionL( aEventName , aParam ) );
       
   655     }
       
   656 
       
   657 // ---------------------------------------------------------------------------
       
   658 // From class MAiEventHandlerExtension.
       
   659 // Invoked by the framework for querying if plugin has menu item
       
   660 // ---------------------------------------------------------------------------
       
   661 //
       
   662 TBool CWrtDataPlugin::HasMenuItem( const TDesC16& aMenuItem )
       
   663 	{ 
       
   664 	return iData->HasMenuItem ( aMenuItem );  
       
   665 	}
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // From class CAiContentPublisher
       
   669 // framework instructs plug-in that it is allowed to consume CPU resources
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 void CWrtDataPlugin::DoResumeL( TAiTransitionReason aReason )
       
   673     {
       
   674 	//update in startup phase and idle is on foreground.
       
   675     switch ( aReason )
       
   676     	{
       
   677         case EAiIdleOnLine:
       
   678         	{
       
   679         	iNetworkStatus = EOnline;
       
   680 			iData->OnLineL();
       
   681 			break;
       
   682         	}
       
   683         case EAiIdleOffLine:
       
   684         	{
       
   685 			iNetworkStatus = EOffline;
       
   686 			iData->OffLineL();
       
   687 			break;
       
   688 			}
       
   689         case EAiIdlePageSwitch:
       
   690         	{
       
   691         	if ( iPluginState == EResume )
       
   692 				{
       
   693 				iData->SuspendL();
       
   694 				}
       
   695         	iPluginState = EInActive;
       
   696         	iData->InActiveL();
       
   697         	}
       
   698         	break;
       
   699         case EAiSystemStartup:
       
   700     	case EAiIdleForeground:
       
   701     		{
       
   702 			iHSForeGround = ETrue;
       
   703     		}
       
   704     	case EAiBacklightOn:    		
       
   705     		{
       
   706     		if ( iPluginState == ESuspend )
       
   707 				{
       
   708 				iPluginState = EResume;
       
   709 				iData->ResumeL();
       
   710 				}
       
   711     		break;
       
   712 			}
       
   713     	case EAiKeylockDisabled:
       
   714         	{
       
   715         	// Key lock events considered only if HS is in foreground  
       
   716         	if ( iHSForeGround && iPluginState == ESuspend )
       
   717         		{
       
   718         		iPluginState = EResume;
       
   719 				iData->ResumeL();
       
   720         		}
       
   721         	break;
       
   722         	}
       
   723     	case EAiKeylockEnabled:
       
   724         	{
       
   725         	// Key lock events considered only if HS is in foreground
       
   726         	if ( iHSForeGround && iPluginState == EResume )
       
   727         		{
       
   728 				iPluginState = ESuspend ;
       
   729 				iData->SuspendL();
       
   730         		}
       
   731         	break;
       
   732         	}
       
   733     	case EAiScreenLayoutChanged:
       
   734         	{
       
   735         	// ignore events
       
   736         	break;
       
   737         	}
       
   738       case EAiGeneralThemeChanged:
       
   739           {
       
   740           // ignore event
       
   741           break;
       
   742           }
       
   743     	case EAiIdleBackground: 
       
   744         	{
       
   745 			iHSForeGround = EFalse;
       
   746         	}
       
   747         default :
       
   748         	{
       
   749 			if ( iPluginState == EResume )
       
   750 				{
       
   751 				iPluginState = ESuspend;
       
   752 				iData->SuspendL();
       
   753 				}
       
   754         	break;
       
   755         	}
       
   756     	}
       
   757     }
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // Is plugin active to publish the data 
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 TBool CWrtDataPlugin::IsActive()
       
   764     {
       
   765     return (iPluginState == EResume );
       
   766     }