idlefw/plugins/wrtdataplugin/src/wrtdataplugin.cpp
changeset 3 ff572005ac23
parent 1 844b978f8d5e
child 9 d0529222e3f0
equal deleted inserted replaced
2:b7904b40483f 3:ff572005ac23
    14 * Description:
    14 * Description:
    15 * Profile plug-in publisher
    15 * Profile plug-in publisher
    16 *
    16 *
    17 */
    17 */
    18 
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
    19 #include <ecom/ecom.h>
    22 #include <ecom/ecom.h>
    20 #include <ecom/implementationproxy.h>
    23 #include <ecom/implementationproxy.h>
    21 #include <aicontentobserver.h>
    24 #include <aicontentobserver.h>
    22 #include <aiutility.h>
    25 #include <aiutility.h>
    23 #include <aipspropertyobserver.h>
    26 #include <aipspropertyobserver.h>
   123         }
   126         }
   124     iIconArray.Reset();
   127     iIconArray.Reset();
   125     }
   128     }
   126 
   129 
   127 // ---------------------------------------------------------------------------
   130 // ---------------------------------------------------------------------------
   128 // Publishes widget's texts and images
   131 // From class CAiContentPublisher
   129 // ---------------------------------------------------------------------------
   132 // Plug-in is requested to unload its engines due backup operation
   130 //
   133 // ---------------------------------------------------------------------------
   131 void CWrtDataPlugin::PublishL()
   134 //
   132     {
   135 void CWrtDataPlugin::Stop( TAiTransitionReason aReason )
   133     User::LeaveIfError( iRfs.Connect() );
   136     {
   134 
   137     if( iPluginState == EResume )
       
   138         {
       
   139         Suspend( aReason );
       
   140         }
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // From class CAiContentPublisher
       
   145 // Plug-in is instructed that it is allowed to consume CPU resources
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CWrtDataPlugin::Resume( TAiTransitionReason aReason )
       
   149     {
       
   150     TRAP_IGNORE( DoResumeL( aReason ) ); 
       
   151     }
       
   152     
       
   153 // ---------------------------------------------------------------------------
       
   154 // From class CAiContentPublisher
       
   155 // Plug-in is instructed that it is not allowed to consume CPU resources
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CWrtDataPlugin::Suspend( TAiTransitionReason aReason )
       
   159     {
       
   160     switch( aReason )
       
   161         {
       
   162         case EAiKeylockDisabled:
       
   163         case EAiKeylockEnabled:
       
   164             {
       
   165             // handled in resume 
       
   166             break;
       
   167             }
       
   168         default :
       
   169             {
       
   170             iPluginState = ESuspend;
       
   171             TRAP_IGNORE ( iData->SuspendL() );
       
   172             }
       
   173         }
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // From class CAiContentPublisher
       
   178 // The plug-in MUST maintain a registry of subscribers and send 
       
   179 // notification to all of them whenever the state changes or new content
       
   180 // is available
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CWrtDataPlugin::SubscribeL( MAiContentObserver& aObserver )
       
   184     { 
       
   185     iObservers.AppendL( &aObserver );
       
   186     }
       
   187  
       
   188 // ---------------------------------------------------------------------------
       
   189 // From class CAiContentPublisher
       
   190 // Plug-ins take ownership of the settings array, so it must either
       
   191 // store it in a member or free it.
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CWrtDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
       
   195     {
       
   196     if( iDataCount > 0 )
       
   197         {
       
   198         // We own the array so destroy it
       
   199          aSettings.ResetAndDestroy();
       
   200          return;
       
   201         }
       
   202     
       
   203     RAiSettingsItemArray contentItemsArr;
       
   204     RAiSettingsItemArray configurationItemsArr;
       
   205     RAiSettingsItemArray settingItemsArr;
       
   206     
       
   207     TInt count = aSettings.Count();
       
   208     for(TInt i = 0; i < count; i++ )
       
   209         {
       
   210         MAiPluginSettings* pluginSetting = aSettings[i];
       
   211         if( pluginSetting->AiPluginItemType() == EAiPluginContentItem )
       
   212             {
       
   213             contentItemsArr.Append(pluginSetting);
       
   214             }
       
   215         else if( pluginSetting->AiPluginItemType() == EAiPluginConfigurationItem )
       
   216             {
       
   217             configurationItemsArr.Append(pluginSetting);
       
   218             }
       
   219         else 
       
   220             {
       
   221             settingItemsArr.Append(pluginSetting);
       
   222             }
       
   223         }
       
   224     
       
   225     iDataCount = contentItemsArr.Count();
       
   226     if(iDataCount > 0 )
       
   227         {
       
   228         // Create the content Model
       
   229         HBufC16* contentId = HBufC16::NewLC( KAiContentIdMaxLength + KAiPluginNameMaxLength );
       
   230         iContentModel = new TAiContentItem[iDataCount];
       
   231         for(TInt i = 0; i < iDataCount; i++)
       
   232             {
       
   233             MAiPluginContentItem& contentItem = (contentItemsArr[i])->AiPluginContentItem();
       
   234             iContentModel[i].id = i;
       
   235             if( contentItem.Type() == KText() )
       
   236                 {
       
   237                 // text
       
   238                 iContentModel[i].type = KAiContentTypeText;
       
   239                 }
       
   240             if( contentItem.Type() == KImage() || 
       
   241                     contentItem.Type() == KAnimation() )
       
   242                 {
       
   243                 // image
       
   244                 iContentModel[i].type = KAiContentTypeBitmap;
       
   245                 }
       
   246             
       
   247             contentId->Des().Copy(contentItem.Name());
       
   248             contentId->Des().Delete(0, contentId->Des().LocateReverse(KPluginNameSeprator) +1);
       
   249   
       
   250             TInt sizeOfContentId = contentId->Des().Size()+sizeof(wchar_t);
       
   251             iContentModel[i].cid = static_cast<const wchar_t*>( User::Alloc( sizeOfContentId ) );
       
   252             Mem::Copy((TAny*)iContentModel[i].cid, contentId->Des().PtrZ(), sizeOfContentId);
       
   253             
       
   254             contentId->Des().Delete( 0, contentId->Des().Length());
       
   255             }    
       
   256         
       
   257         CleanupStack::PopAndDestroy( contentId );
       
   258         iContent = AiUtility::CreateContentItemArrayIteratorL( iContentModel, iDataCount );
       
   259         // Configurations 
       
   260         iData->ConfigureL(configurationItemsArr);
       
   261 
       
   262         iPluginState = ESuspend;
       
   263         // Register for notifications
       
   264         iData->RegisterL();
       
   265         
       
   266         // Activate the publisher 
       
   267         iData->ActivateL();
       
   268         }
       
   269     
       
   270     settingItemsArr.Reset();
       
   271     contentItemsArr.Reset();
       
   272     configurationItemsArr.Reset();
       
   273        // We own the array so destroy it
       
   274     aSettings.ResetAndDestroy();
       
   275     // publish the initial data
       
   276     PublishL();
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // From class CAiContentPublisher
       
   281 // Returns the extension interface. Actual type depends on the passed 
       
   282 // aUid argument.
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 TAny* CWrtDataPlugin::Extension( TUid aUid )
       
   286     {    
       
   287     if ( aUid == KExtensionUidProperty )
       
   288         {
       
   289         return static_cast<MAiPropertyExtension*>( this );
       
   290         }
       
   291     else if (aUid == KExtensionUidEventHandler)
       
   292         {
       
   293         return static_cast<MAiEventHandlerExtension*>( this );
       
   294         }
       
   295     else
       
   296         {   
       
   297         return NULL;
       
   298         }
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // From class MAiPropertyExtension
       
   303 // Read property of publisher plug-in.
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 TAny* CWrtDataPlugin::GetPropertyL( TInt aProperty )
       
   307     {
       
   308     TAny* property = NULL;
       
   309     
       
   310     switch ( aProperty )
       
   311         {
       
   312     case EAiPublisherInfo:
       
   313         {
       
   314          property = static_cast<TAiPublisherInfo*>( &iInfo );
       
   315         break;  
       
   316         }       
       
   317 
       
   318     case EAiPublisherContent:
       
   319         {
       
   320         property = static_cast<MAiContentItemIterator*>( iContent );
       
   321         break;    
       
   322         }        
       
   323     default:
       
   324         break;
       
   325         }
       
   326 
       
   327     return property;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // From class MAiPropertyExtension
       
   332 // Write property value to optimize the content model.
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 void CWrtDataPlugin::SetPropertyL( TInt aProperty, TAny* aValue )
       
   336     {  
       
   337     switch ( aProperty )
       
   338         {
       
   339         case EAiPublisherInfo:
       
   340             {
       
   341             if( aValue )
       
   342                 {
       
   343                 const TAiPublisherInfo* info = static_cast<const TAiPublisherInfo*>( aValue );
       
   344                 iInfo.iName.Copy( info->iName );
       
   345                 iInfo.iNamespace.Copy( info->iNamespace );
       
   346                 }
       
   347             break;
       
   348             }
       
   349         default:
       
   350             break;         
       
   351         }
       
   352     }
       
   353  
       
   354 // ---------------------------------------------------------------------------
       
   355 // From class MAiEventHandlerExtension.
       
   356 // Handles an event sent by the AI framework.
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CWrtDataPlugin::HandleEvent( TInt /*aEvent*/, const TDesC& /*aParam*/ )
       
   360     {
       
   361     // This is not as there is no event id to retrieve in this dynamic plugin. 
       
   362     } 
       
   363     
       
   364 // ---------------------------------------------------------------------------
       
   365 // From class MAiEventHandlerExtension.
       
   366 // Handles an event sent by the AI framework.
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam )
       
   370     {
       
   371     // We have no way of reporting errors to framework so just ignore them.
       
   372     TRAP_IGNORE(iData->ExecuteActionL( aEventName , aParam ) );
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // From class MAiEventHandlerExtension.
       
   377 // Invoked by the framework for querying if plugin has menu item
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 TBool CWrtDataPlugin::HasMenuItem( const TDesC16& aMenuItem )
       
   381     { 
       
   382     return iData->HasMenuItem ( aMenuItem );  
       
   383     }
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // Gets the id of a content  
       
   387 // ---------------------------------------------------------------------------
       
   388 //
       
   389 TInt CWrtDataPlugin::GetIdL( TDesC16& aObjectId)
       
   390     {
       
   391     TInt id = KErrNotFound;
       
   392     HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
       
   393     for( TInt i = 0;i<  iDataCount; i++ )
       
   394         {
       
   395          objectId->Des().Copy((TUint16*)iContentModel[i].cid);
       
   396          if( aObjectId == objectId->Des() )
       
   397              {
       
   398              id = iContentModel[i].id;
       
   399              break;
       
   400              }
       
   401         }
       
   402     CleanupStack::PopAndDestroy( objectId );
       
   403     return id;
       
   404     }
       
   405  
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // Gets type of a content
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void CWrtDataPlugin::GetTypeL(TDesC16& aObjectId, TDes16& aType )
       
   412     {
       
   413     HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
       
   414     for( TInt i = 0;i<  iDataCount; i++ )
       
   415         {
       
   416         objectId->Des().Copy((TUint16*)iContentModel[i].cid);
       
   417          if( aObjectId == objectId->Des() )
       
   418              {
       
   419              if( iContentModel[i].type ==  KAiContentTypeText)
       
   420                  {
       
   421                  aType.Copy( KText );
       
   422                  }
       
   423              else if( iContentModel[i].type == KAiContentTypeBitmap)
       
   424                  {
       
   425                  aType.Copy( KImage );
       
   426                  }
       
   427              break;
       
   428              }
       
   429         }
       
   430     CleanupStack::PopAndDestroy( objectId );
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 //Refresh a specific image of text in the widget
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CWrtDataPlugin::RefreshL( TDesC16& aOperation, CLiwDefaultMap* aDataMap )
       
   438     {
   135     TInt observers( iObservers.Count() );        
   439     TInt observers( iObservers.Count() );        
   136     TInt transactionId = reinterpret_cast<TInt>( this );
   440     TInt transactionId = reinterpret_cast<TInt>( this );
   137 
   441     
   138     for ( int i = 0; i < observers; i++ )
   442     for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
   139         {
   443         {
   140         MAiContentObserver* observer = iObservers[i];
   444         MAiContentObserver* observer = iObservers[obsIndex];
   141                 
   445  
   142         if ( observer->StartTransaction( transactionId ) == KErrNone )        	 
   446         if ( observer->StartTransaction( transactionId ) == KErrNone )       
   143         	{// Publish all the data
   447             {
   144             iData->PublishAllL(observer);
   448             if( ( aOperation == KOperationUpdate 
       
   449                   || aOperation == KOperationAdd )
       
   450                   && aDataMap )
       
   451                 {
       
   452                 iData->PublishL( observer, aDataMap );
       
   453                 }
       
   454             else if ( aOperation == KOperationDelete )
       
   455                 {
       
   456                 Clean( observer , EImage1 ) ;
       
   457                 }
       
   458             
   145             observer->Commit( transactionId );
   459             observer->Commit( transactionId );
   146             }
   460             }
   147 
   461      
   148         // Release memory of the published text
   462         // Relese memory of the published text
   149         iDataArray.ResetAndDestroy();
   463         iDataArray.ResetAndDestroy();
   150         // Release memory of the published icons
   464         // Release memory of the published icons
   151         iIconArray.Reset();
   465         iIconArray.Reset();
   152         }
   466         }
   153     iRfs.Close();
   467     }
       
   468 
       
   469 // ---------------------------------------------------------------------------
       
   470 // Is plugin active to publish the data 
       
   471 // ---------------------------------------------------------------------------
       
   472 //
       
   473 TBool CWrtDataPlugin::IsActive()
       
   474     {
       
   475     return (iPluginState == EResume );
   154     }
   476     }
   155 
   477 
   156 // ---------------------------------------------------------------------------
   478 // ---------------------------------------------------------------------------
   157 // Publish a specific text of the widget  
   479 // Publish a specific text of the widget  
   158 // ---------------------------------------------------------------------------
   480 // ---------------------------------------------------------------------------
   159 //
   481 //
   160 /*
       
   161 void CWrtDataPlugin::PublishTextL(MAiContentObserver* aObserver, 
   482 void CWrtDataPlugin::PublishTextL(MAiContentObserver* aObserver, 
   162         TInt& aContentId, TDesC16& aContentValue)
   483         TInt aContentId, const TDesC16& aContentValue)
   163     {
   484     {
   164     if ( aObserver->CanPublish( *this,  aContentId  ,  aContentId  ) )
   485     if ( aObserver->CanPublish( *this,  aContentId  ,  aContentId  ) )
   165         {
   486         {
   166         if( aContentValue.Length() > 0 )
   487         if( aContentValue.Length() > 0 )
   167             {
   488             {
   175         else
   496         else
   176             {
   497             {
   177             aObserver->Clean( *this, aContentId, aContentId );
   498             aObserver->Clean( *this, aContentId, aContentId );
   178             }
   499             }
   179         }
   500         }
   180     }*/
   501     }
   181 
   502 
   182 // ---------------------------------------------------------------------------
   503 // ---------------------------------------------------------------------------
   183 // Publish a specific image of the widget  
   504 // Publish a specific image of the widget  
   184 // ---------------------------------------------------------------------------
   505 // ---------------------------------------------------------------------------
   185 //
   506 //
   186 void CWrtDataPlugin::PublishImageL(MAiContentObserver* aObserver,
   507 void CWrtDataPlugin::PublishImageL(MAiContentObserver* aObserver,
   187 		TContentItem aContentId, TDesC16& aPath )
   508 		TContentItem aContentId, const TDesC16& aPath )
   188     {
   509     {
   189     TInt err = KErrNone;
   510     TInt err = KErrNone;
   190     TAknsItemID iconId;
   511     TAknsItemID iconId;
   191     iconId.iMajor=0;
   512     iconId.iMajor=0;
   192     iconId.iMinor=0;
   513     iconId.iMinor=0;
   197     CFbsBitmap* bitmap = NULL;
   518     CFbsBitmap* bitmap = NULL;
   198     CFbsBitmap* mask = NULL;
   519     CFbsBitmap* mask = NULL;
   199     
   520     
   200     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
   521     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
   201       {
   522       {
   202       TBool inSkin = iData->ResolveSkinIdAndMifId( aPath, iconId, bitmapId, maskId, fileName  );
   523       TBool inSkin = ResolveSkinIdAndMifId( aPath, iconId, bitmapId, maskId, fileName  );
   203       if ( inSkin )
   524       if ( inSkin )
   204           {
   525           {
   205           // Load from skin 
   526           // Load from skin 
   206           MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   527           MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   207           if ( iconId.iMajor != 0 && iconId.iMajor!=0 )
   528           if ( iconId.iMajor != 0 && iconId.iMajor!=0 )
   255               aObserver->Clean( *this, aContentId, aContentId );
   576               aObserver->Clean( *this, aContentId, aContentId );
   256               }
   577               }
   257           }
   578           }
   258       else  // Interpret as File path
   579       else  // Interpret as File path
   259           {
   580           {
       
   581           RFs rfs;
       
   582           User::LeaveIfError( rfs.Connect() );
   260           RFile* iconFile = new (ELeave) RFile();
   583           RFile* iconFile = new (ELeave) RFile();
   261           err = iconFile->Open( iRfs, aPath, EFileShareReadersOnly |  EFileRead );
   584           err = iconFile->Open( rfs, aPath, EFileShareReadersOnly |  EFileRead );
   262           if( err == KErrNone )
   585           if( err == KErrNone )
   263             {
   586             {
   264              aObserver->Publish( *this, aContentId, *iconFile, aContentId );
   587              aObserver->Publish( *this, aContentId, *iconFile, aContentId );
   265             }
   588             }
   266           else
   589           else
   268               aObserver->Clean( *this, aContentId, aContentId );
   591               aObserver->Clean( *this, aContentId, aContentId );
   269               }
   592               }
   270           iconFile->Close();
   593           iconFile->Close();
   271           delete iconFile;
   594           delete iconFile;
   272           iconFile = NULL;
   595           iconFile = NULL;
       
   596           rfs.Close();
   273           }
   597           }
   274         }
   598         }
   275     }
   599     }
   276 
   600 
   277 // ---------------------------------------------------------------------------
   601 // ---------------------------------------------------------------------------
   310             }
   634             }
   311           }
   635           }
   312     }
   636     }
   313 
   637 
   314 // ---------------------------------------------------------------------------
   638 // ---------------------------------------------------------------------------
   315 // Gets the id of a content  
   639 // Cleans a data from the widget
   316 // ---------------------------------------------------------------------------
   640 // ---------------------------------------------------------------------------
   317 //
   641 //
   318 TInt CWrtDataPlugin::GetIdL( TDesC16& aObjectId)
   642 void CWrtDataPlugin::Clean(MAiContentObserver* aObserver, 
   319 	{
   643         TInt aContentId )
   320     TInt id = KErrNotFound;
   644     {
   321     HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
   645      if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
   322 	for( TInt i = 0;i<  iDataCount; i++ )
   646         {
   323 		{
   647         aObserver->Clean( *this, aContentId, aContentId );      
   324 		 objectId->Des().Copy((TUint16*)iContentModel[i].cid);
   648         }
   325 		 if( aObjectId == objectId->Des() )
   649 
   326 			 {
   650     }
   327 			 id = iContentModel[i].id;
   651 
   328 			 break;
   652 // ---------------------------------------------------------------------------
   329 			 }
   653 // Show the loading icong animation 
   330 		}
   654 // ---------------------------------------------------------------------------
   331 	CleanupStack::PopAndDestroy( objectId );
   655 //
   332 	return id;
   656 void CWrtDataPlugin::ShowLoadingIcon(MAiContentObserver* aObserver)
   333 	}
   657     {
   334  
   658     aObserver->SetProperty( *this, KElement , KDisplay , KShow );
   335 
   659     }
   336 // ---------------------------------------------------------------------------
   660 
   337 // Gets type of a content
   661 // ---------------------------------------------------------------------------
   338 // ---------------------------------------------------------------------------
   662 // Hides the loading icon animation 
   339 //
   663 // ---------------------------------------------------------------------------
   340 void CWrtDataPlugin::GetTypeL(TDesC16& aObjectId, TDes16& aType )
   664 //
   341 	{
   665 void CWrtDataPlugin::HideLoadingIcon(MAiContentObserver* aObserver)
   342 	HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
   666     {
   343 	for( TInt i = 0;i<  iDataCount; i++ )
   667     aObserver->SetProperty( *this, KElement , KDisplay , KHide );
   344 		{
   668     }
   345 		objectId->Des().Copy((TUint16*)iContentModel[i].cid);
   669 
   346 		 if( aObjectId == objectId->Des() )
   670 // ---------------------------------------------------------------------------
   347 			 {
   671 // Publishes widget's texts and images
   348 			 if( iContentModel[i].type ==  KAiContentTypeText)
   672 // ---------------------------------------------------------------------------
   349 				 {
   673 //
   350 				 aType.Copy( KText );
   674 void CWrtDataPlugin::PublishL()
   351 				 }
   675     {
   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     User::LeaveIfError( iRfs.Connect() );
       
   369     TInt observers( iObservers.Count() );        
   676     TInt observers( iObservers.Count() );        
   370     TInt transactionId = reinterpret_cast<TInt>( this );
   677     TInt transactionId = reinterpret_cast<TInt>( this );
   371    
   678 
   372     for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
   679     for ( int i = 0; i < observers; i++ )
   373         {
   680         {
   374         MAiContentObserver* observer = iObservers[obsIndex];
   681         MAiContentObserver* observer = iObservers[i];
   375     
   682                 
   376         if ( observer->StartTransaction( transactionId ) == KErrNone )    	 
   683         if ( observer->StartTransaction( transactionId ) == KErrNone )           
   377             {
   684             {// Publish default data
   378             if( aOperation != KOperationDelete)
   685             iData->PublishDefaultImageL(observer);
   379                 {
       
   380                 iData->PublishL( observer );
       
   381                 }
       
   382             else
       
   383                 {
       
   384                 Clean( observer , EImage1 ) ;
       
   385                 }
       
   386             
       
   387             observer->Commit( transactionId );
   686             observer->Commit( transactionId );
   388             }
   687             }
   389      
   688 
   390         // Relese memory of the published text
   689         // Release memory of the published text
   391         iDataArray.ResetAndDestroy();
   690         iDataArray.ResetAndDestroy();
   392         // Release memory of the published icons
   691         // Release memory of the published icons
   393         iIconArray.Reset();
   692         iIconArray.Reset();
   394         }
   693         }
   395     
   694 
   396     iRfs.Close();
   695     }
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // Cleans a data from the widget
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 void CWrtDataPlugin::Clean(MAiContentObserver* aObserver, 
       
   404         TInt aContentId )
       
   405 	{
       
   406 	 if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
       
   407 		{
       
   408 		aObserver->Clean( *this, aContentId, aContentId );		
       
   409 		}
       
   410 
       
   411 	}
       
   412 // ---------------------------------------------------------------------------
       
   413 // From class CAiContentPublisher
       
   414 // Plug-in is requested to unload its engines due backup operation
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void CWrtDataPlugin::Stop( TAiTransitionReason aReason )
       
   418     {
       
   419     if( iPluginState == EResume )
       
   420         {
       
   421         Suspend( aReason );
       
   422         }
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // From class CAiContentPublisher
       
   427 // Plug-in is instructed that it is allowed to consume CPU resources
       
   428 // ---------------------------------------------------------------------------
       
   429 //
       
   430 void CWrtDataPlugin::Resume( TAiTransitionReason aReason )
       
   431     {
       
   432     TRAP_IGNORE( DoResumeL( aReason ) ); 
       
   433     }
       
   434     
       
   435 // ---------------------------------------------------------------------------
       
   436 // From class CAiContentPublisher
       
   437 // Plug-in is instructed that it is not allowed to consume CPU resources
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 void CWrtDataPlugin::Suspend( TAiTransitionReason aReason )
       
   441     {
       
   442     switch( aReason )
       
   443 		{
       
   444 		case EAiKeylockDisabled:
       
   445         case EAiKeylockEnabled:
       
   446         	{
       
   447         	// handled in resume 
       
   448         	break;
       
   449         	}
       
   450         default :
       
   451         	{
       
   452         	iPluginState = ESuspend;
       
   453         	TRAP_IGNORE ( iData->SuspendL() );
       
   454         	}
       
   455 		}
       
   456     }
       
   457 
       
   458 // ---------------------------------------------------------------------------
       
   459 // From class CAiContentPublisher
       
   460 // The plug-in MUST maintain a registry of subscribers and send 
       
   461 // notification to all of them whenever the state changes or new content
       
   462 // is available
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 void CWrtDataPlugin::SubscribeL( MAiContentObserver& aObserver )
       
   466     { 
       
   467     iObservers.AppendL( &aObserver );
       
   468     }
       
   469  
       
   470 // ---------------------------------------------------------------------------
       
   471 // From class CAiContentPublisher
       
   472 // Plug-ins take ownership of the settings array, so it must either
       
   473 // store it in a member or free it.
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 void CWrtDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
       
   477     {
       
   478     if( iDataCount > 0 )
       
   479         {
       
   480         // We own the array so destroy it
       
   481          aSettings.ResetAndDestroy();
       
   482          return;
       
   483         }
       
   484     
       
   485     RAiSettingsItemArray contentItemsArr;
       
   486     RAiSettingsItemArray configurationItemsArr;
       
   487     RAiSettingsItemArray settingItemsArr;
       
   488     
       
   489     TInt count = aSettings.Count();
       
   490     for(TInt i = 0; i < count; i++ )
       
   491         {
       
   492         MAiPluginSettings* pluginSetting = aSettings[i];
       
   493         if( pluginSetting->AiPluginItemType() == EAiPluginContentItem )
       
   494             {
       
   495             contentItemsArr.Append(pluginSetting);
       
   496             }
       
   497         else if( pluginSetting->AiPluginItemType() == EAiPluginConfigurationItem )
       
   498             {
       
   499             configurationItemsArr.Append(pluginSetting);
       
   500             }
       
   501         else 
       
   502             {
       
   503             settingItemsArr.Append(pluginSetting);
       
   504             }
       
   505         }
       
   506     
       
   507     iDataCount = contentItemsArr.Count();
       
   508     if(iDataCount > 0 )
       
   509         {
       
   510         // Create the content Model
       
   511         HBufC16* contentId = HBufC16::NewLC( KAiContentIdMaxLength + KAiPluginNameMaxLength );
       
   512         iContentModel = new TAiContentItem[iDataCount];
       
   513         for(TInt i = 0; i < iDataCount; i++)
       
   514             {
       
   515             MAiPluginContentItem& contentItem = (contentItemsArr[i])->AiPluginContentItem();
       
   516             iContentModel[i].id = i;
       
   517             /*if( contentItem.Type() == KText() || contentItem.Type() == KNewsTicker() )
       
   518                 {
       
   519                 // text
       
   520                 iContentModel[i].type = KAiContentTypeText;
       
   521                 }*/
       
   522             if( contentItem.Type() == KImage() )
       
   523                 {
       
   524                 // image
       
   525                 iContentModel[i].type = KAiContentTypeBitmap;
       
   526                 }
       
   527             
       
   528             contentId->Des().Copy(contentItem.Name());
       
   529             contentId->Des().Delete(0, contentId->Des().LocateReverse(KPluginNameSeprator) +1);
       
   530   
       
   531             TInt sizeOfContentId = contentId->Des().Size()+sizeof(wchar_t);
       
   532             iContentModel[i].cid = static_cast<const wchar_t*>( User::Alloc( sizeOfContentId ) );
       
   533             Mem::Copy((TAny*)iContentModel[i].cid, contentId->Des().PtrZ(), sizeOfContentId);
       
   534             
       
   535             contentId->Des().Delete( 0, contentId->Des().Length());
       
   536             }    
       
   537         
       
   538         CleanupStack::PopAndDestroy( contentId );
       
   539         iContent = AiUtility::CreateContentItemArrayIteratorL( iContentModel, iDataCount );
       
   540         // Configurations 
       
   541         iData->ConfigureL(configurationItemsArr);
       
   542 
       
   543         iPluginState = ESuspend;
       
   544         // Register for notifications
       
   545         iData->RegisterL();
       
   546         
       
   547         // Activate the publisher 
       
   548         iData->ActivateL();
       
   549         }
       
   550     
       
   551     settingItemsArr.Reset();
       
   552     contentItemsArr.Reset();
       
   553     configurationItemsArr.Reset();
       
   554        // We own the array so destroy it
       
   555     aSettings.ResetAndDestroy();
       
   556     // publish the initial data
       
   557     PublishL();
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // From class CAiContentPublisher
       
   562 // Returns the extension interface. Actual type depends on the passed 
       
   563 // aUid argument.
       
   564 // ---------------------------------------------------------------------------
       
   565 //
       
   566 TAny* CWrtDataPlugin::Extension( TUid aUid )
       
   567     {    
       
   568     if ( aUid == KExtensionUidProperty )
       
   569    		{
       
   570         return static_cast<MAiPropertyExtension*>( this );
       
   571     	}
       
   572     else if (aUid == KExtensionUidEventHandler)
       
   573     	{
       
   574         return static_cast<MAiEventHandlerExtension*>( this );
       
   575     	}
       
   576     else
       
   577     	{	
       
   578         return NULL;
       
   579     	}
       
   580     }
       
   581 
       
   582 // ---------------------------------------------------------------------------
       
   583 // From class MAiPropertyExtension
       
   584 // Read property of publisher plug-in.
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 TAny* CWrtDataPlugin::GetPropertyL( TInt aProperty )
       
   588     {
       
   589     TAny* property = NULL;
       
   590     
       
   591     switch ( aProperty )
       
   592         {
       
   593     case EAiPublisherInfo:
       
   594         {
       
   595          property = static_cast<TAiPublisherInfo*>( &iInfo );
       
   596         break;  
       
   597         }       
       
   598 
       
   599     case EAiPublisherContent:
       
   600         {
       
   601         property = static_cast<MAiContentItemIterator*>( iContent );
       
   602         break;    
       
   603         }        
       
   604     default:
       
   605         break;
       
   606         }
       
   607 
       
   608     return property;
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // From class MAiPropertyExtension
       
   613 // Write property value to optimize the content model.
       
   614 // ---------------------------------------------------------------------------
       
   615 //
       
   616 void CWrtDataPlugin::SetPropertyL( TInt aProperty, TAny* aValue )
       
   617     {  
       
   618     switch ( aProperty )
       
   619         {
       
   620 		case EAiPublisherInfo:
       
   621 			{
       
   622 			if( aValue )
       
   623 			    {
       
   624     		    const TAiPublisherInfo* info = static_cast<const TAiPublisherInfo*>( aValue );
       
   625 	    	    iInfo.iName.Copy( info->iName );
       
   626 	    	    iInfo.iNamespace.Copy( info->iNamespace );
       
   627 			    }
       
   628 		    break;
       
   629 		    }
       
   630 		default:
       
   631 		    break;         
       
   632         }
       
   633     }
       
   634  
       
   635 // ---------------------------------------------------------------------------
       
   636 // From class MAiEventHandlerExtension.
       
   637 // Handles an event sent by the AI framework.
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 void CWrtDataPlugin::HandleEvent( TInt /*aEvent*/, const TDesC& /*aParam*/ )
       
   641 	{
       
   642     // This is not as there is no event id to retrieve in this dynamic plugin. 
       
   643 	} 
       
   644     
       
   645 // ---------------------------------------------------------------------------
       
   646 // From class MAiEventHandlerExtension.
       
   647 // Handles an event sent by the AI framework.
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam )
       
   651     {
       
   652     // We have no way of reporting errors to framework so just ignore them.
       
   653     TRAP_IGNORE(iData->ExecuteActionL( aEventName , aParam ) );
       
   654     }
       
   655 
       
   656 // ---------------------------------------------------------------------------
       
   657 // From class MAiEventHandlerExtension.
       
   658 // Invoked by the framework for querying if plugin has menu item
       
   659 // ---------------------------------------------------------------------------
       
   660 //
       
   661 TBool CWrtDataPlugin::HasMenuItem( const TDesC16& aMenuItem )
       
   662 	{ 
       
   663 	return iData->HasMenuItem ( aMenuItem );  
       
   664 	}
       
   665 
   696 
   666 // ---------------------------------------------------------------------------
   697 // ---------------------------------------------------------------------------
   667 // From class CAiContentPublisher
   698 // From class CAiContentPublisher
   668 // framework instructs plug-in that it is allowed to consume CPU resources
   699 // framework instructs plug-in that it is allowed to consume CPU resources
   669 // ---------------------------------------------------------------------------
   700 // ---------------------------------------------------------------------------
   670 //
   701 //
   671 void CWrtDataPlugin::DoResumeL( TAiTransitionReason aReason )
   702 void CWrtDataPlugin::DoResumeL( TAiTransitionReason aReason )
   672     {
   703     {
   673 	//update in startup phase and idle is on foreground.
   704     //update in startup phase and idle is on foreground.
   674     switch ( aReason )
   705     switch ( aReason )
   675     	{
   706         {
   676         case EAiIdleOnLine:
   707         case EAiIdleOnLine:
   677         	{
   708             {
   678         	iNetworkStatus = EOnline;
   709             iNetworkStatus = EOnline;
   679 			iData->OnLineL();
   710             iData->OnLineL();
   680 			break;
   711             break;
   681         	}
   712             }
   682         case EAiIdleOffLine:
   713         case EAiIdleOffLine:
   683         	{
   714             {
   684 			iNetworkStatus = EOffline;
   715             iNetworkStatus = EOffline;
   685 			iData->OffLineL();
   716             iData->OffLineL();
   686 			break;
   717             break;
   687 			}
   718             }
   688         case EAiIdlePageSwitch:
   719         case EAiIdlePageSwitch:
   689         	{
   720             {
   690         	if ( iPluginState == EResume )
   721             if ( iPluginState == EResume )
   691 				{
   722                 {
   692 				iData->SuspendL();
   723                 iData->SuspendL();
   693 				}
   724                 }
   694         	iPluginState = EInActive;
   725             iPluginState = EInActive;
   695         	iData->InActiveL();
   726             iData->InActiveL();
   696         	}
   727             }
   697         	break;
   728             break;
   698         case EAiSystemStartup:
   729         case EAiSystemStartup:
   699     	case EAiIdleForeground:
   730         case EAiIdleForeground:
   700     		{
   731             {
   701 			iHSForeGround = ETrue;
   732             iHSForeGround = ETrue;
   702     		}
   733             }
   703     	case EAiBacklightOn:    		
   734         case EAiBacklightOn:            
   704     		{
   735             {
   705     		if ( iPluginState == ESuspend  && !iKeyLockOn )
   736             if ( iPluginState == ESuspend  && !iKeyLockOn )
   706 				{
   737                 {
   707 				iPluginState = EResume;
   738                 iPluginState = EResume;
   708 				iData->ResumeL();
   739                 iData->ResumeL();
   709 				}
   740                 }
   710     		break;
   741             break;
   711 			}
   742             }
   712     	case EAiKeylockDisabled:
   743         case EAiKeylockDisabled:
   713         	{
   744             {
   714         	iKeyLockOn = EFalse;
   745             iKeyLockOn = EFalse;
   715         	// Key lock events considered only if HS is in foreground  
   746             // Key lock events considered only if HS is in foreground  
   716         	if ( iHSForeGround && iPluginState == ESuspend )
   747             if ( iHSForeGround && iPluginState == ESuspend )
   717         		{
   748                 {
   718         		iPluginState = EResume;
   749                 iPluginState = EResume;
   719 				iData->ResumeL();
   750                 iData->ResumeL();
   720         		}
   751                 }
   721         	break;
   752             break;
   722         	}
   753             }
   723     	case EAiKeylockEnabled:
   754         case EAiKeylockEnabled:
   724         	{
   755             {
   725         	iKeyLockOn = ETrue;
   756             iKeyLockOn = ETrue;
   726         	// Key lock events considered only if HS is in foreground
   757             // Key lock events considered only if HS is in foreground
   727         	if ( iHSForeGround && iPluginState == EResume )
   758             if ( iHSForeGround && iPluginState == EResume )
   728         		{
   759                 {
   729 				iPluginState = ESuspend ;
   760                 iPluginState = ESuspend ;
   730 				iData->SuspendL();
   761                 iData->SuspendL();
   731         		}
   762                 }
   732         	break;
   763             break;
   733         	}
   764             }
   734     	case EAiScreenLayoutChanged:
   765         case EAiScreenLayoutChanged:
   735         	{
   766             {
   736         	// ignore events
   767             // ignore events
   737         	break;
   768             break;
   738         	}
   769             }
   739       case EAiGeneralThemeChanged:
   770       case EAiGeneralThemeChanged:
   740           {
   771           {
   741           // ignore event
   772           // ignore event
   742           break;
   773           break;
   743           }
   774           }
   744     	case EAiIdleBackground: 
   775         case EAiIdleBackground: 
   745         	{
   776             {
   746 			iHSForeGround = EFalse;
   777             iHSForeGround = EFalse;
   747         	}
   778             }
   748         default :
   779         default :
   749         	{
   780             {
   750 			if ( iPluginState == EResume )
   781             if ( iPluginState == EResume )
   751 				{
   782                 {
   752 				iPluginState = ESuspend;
   783                 iPluginState = ESuspend;
   753 				iData->SuspendL();
   784                 iData->SuspendL();
   754 				}
   785                 }
   755         	break;
   786             break;
   756         	}
   787             }
   757     	}
   788         }
   758     }
   789     }
   759 
   790 
   760 // ---------------------------------------------------------------------------
   791 // ---------------------------------------------------------------------------
   761 // Is plugin active to publish the data 
   792 // ResolveSkinItemId
   762 // ---------------------------------------------------------------------------
   793 // ---------------------------------------------------------------------------
   763 //
   794 //
   764 TBool CWrtDataPlugin::IsActive()
   795 TBool CWrtDataPlugin::ResolveSkinIdAndMifId( const TDesC& aPath, TAknsItemID& aItemId,
   765     {
   796         TInt& abitmapId, TInt& aMaskId, TDes& aFilename )
   766     return (iPluginState == EResume );
   797    {
   767     }
   798    // Syntax: skin( <major> <minor> ):mif(filename bimapId maskId) 
       
   799    TInt error = KErrNotFound;
       
   800    TInt pos = aPath.FindF( KSkin );
       
   801    if( pos != KErrNotFound )
       
   802        {
       
   803        // Skip skin token
       
   804        pos += KSkin().Length();
       
   805        
       
   806        // Initialize lexer
       
   807       TLex lex( aPath.Mid( pos ) );
       
   808       lex.SkipSpace();
       
   809        
       
   810        // Check left parenthesis
       
   811       if (lex.Get() == KLeftParenthesis )
       
   812            {
       
   813            //lex.SkipSpace();
       
   814            
       
   815            TInt majorId( 0 );        
       
   816            TInt minorId( 0 );
       
   817 
       
   818            // Resolve major id        
       
   819            error = lex.Val( majorId );
       
   820            
       
   821            // Resolve minor id
       
   822            lex.SkipSpace();
       
   823            error |= lex.Val( minorId );
       
   824            
       
   825            // initilize skin item id object
       
   826            aItemId.Set( majorId, minorId );
       
   827            }
       
   828        }
       
   829 
       
   830    if( (error == KErrNone && aPath.FindF( KColon ) != KErrNotFound ) 
       
   831          || ( error == KErrNotFound ) )
       
   832        {
       
   833        error = KErrNotFound;
       
   834        pos = aPath.FindF( KMif );
       
   835        if ( pos != KErrNotFound )
       
   836            {
       
   837            pos += KMif().Length();
       
   838            // Initialize lexer
       
   839            TLex lex( aPath.Mid( pos ) );
       
   840            lex.SkipSpace();
       
   841            
       
   842            // Check left parenthesis
       
   843            if (lex.Get() == KLeftParenthesis )
       
   844                {
       
   845                lex.SkipSpaceAndMark();
       
   846                lex.SkipCharacters();
       
   847                // Resolve MifFile name
       
   848                aFilename.Copy(lex.MarkedToken());
       
   849                if( aFilename.Length()!= 0)
       
   850                    {
       
   851                    // Resolve bitmap id  
       
   852                    lex.SkipSpace();
       
   853                    error = lex.Val( abitmapId );
       
   854                    
       
   855                    // Resolve mask id
       
   856                    // dont return error if it is not found, that is ok
       
   857                    lex.SkipSpace();
       
   858                    lex.Val( aMaskId );
       
   859                    }
       
   860                else
       
   861                    {
       
   862                    error = KErrNotFound;
       
   863                    }
       
   864                }
       
   865            }
       
   866        }
       
   867    return (error == KErrNone );
       
   868    }