idlefw/plugins/sapidataplugin/src/sapidataplugin.cpp
branchRCL_3
changeset 23 ace62b58f4b2
parent 19 edd621764147
equal deleted inserted replaced
22:1b207dd38b72 23:ace62b58f4b2
   147         iIconArray.Reset();        
   147         iIconArray.Reset();        
   148         }        
   148         }        
   149     }
   149     }
   150 
   150 
   151 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   152 // Publish a specific text of the widget  
   152 // Publish a specific text to the widget  
   153 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   154 //
   154 //
   155 void CSapiDataPlugin::PublishTextL(MAiContentObserver* aObserver, 
   155 void CSapiDataPlugin::PublishTextL(MAiContentObserver* aObserver, 
   156         TInt& aContentId, TDesC& aContentValue)
   156         TInt& aContentId, TDesC& aContentValue)
   157     {
   157     {
   172             }
   172             }
   173         }
   173         }
   174     }
   174     }
   175 
   175 
   176 // ---------------------------------------------------------------------------
   176 // ---------------------------------------------------------------------------
   177 // Publish a specific image of the widget  
   177 // Publish a specific image to the widget  
   178 // ---------------------------------------------------------------------------
   178 // ---------------------------------------------------------------------------
   179 //
   179 //
   180 void CSapiDataPlugin::PublishImageL(MAiContentObserver* aObserver,
   180 void CSapiDataPlugin::PublishImageL(MAiContentObserver* aObserver,
   181         TInt aContentId, TDesC& aPath )
   181         TInt aContentId, TDesC& aPath )
   182     {
   182     {
   268           }
   268           }
   269         }
   269         }
   270     }
   270     }
   271 
   271 
   272 // ---------------------------------------------------------------------------
   272 // ---------------------------------------------------------------------------
   273 // Publish a image of the widget  
   273 // Publish a image to the widget  
   274 // ---------------------------------------------------------------------------
   274 // ---------------------------------------------------------------------------
   275 //
   275 //
   276 void CSapiDataPlugin::PublishImageL(MAiContentObserver* aObserver, 
   276 void CSapiDataPlugin::PublishImageL(MAiContentObserver* aObserver, 
   277         TInt& aContentId, TInt aHandle, TInt aMaskHandle )
   277     TInt& aContentId, TInt aHandle, TInt aMaskHandle )
   278     {
   278     {
   279     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
   279     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
   280         {
   280         {
   281         if( aHandle != KErrBadHandle  )
   281         if( aHandle != KErrBadHandle  )
   282             {
   282             {
   301                 delete bitmap;
   301                 delete bitmap;
   302                 bitmap = NULL;
   302                 bitmap = NULL;
   303                 aObserver->Clean( *this, aContentId, aContentId );
   303                 aObserver->Clean( *this, aContentId, aContentId );
   304                 }
   304                 }
   305             }
   305             }
   306           }
   306         }
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // Publish a data to the widget  
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 void CSapiDataPlugin::PublishData( MAiContentObserver* aObserver, 
       
   314     TInt& aContentId, const TDesC8& aData )
       
   315     {
       
   316     if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
       
   317         {                
       
   318         aObserver->Publish( *this, aContentId, aData, aContentId );
       
   319         }    
   307     }
   320     }
   308 
   321 
   309 // ---------------------------------------------------------------------------
   322 // ---------------------------------------------------------------------------
   310 // Gets the id of a content  
   323 // Gets the id of a content  
   311 // ---------------------------------------------------------------------------
   324 // ---------------------------------------------------------------------------
   340 				 }
   353 				 }
   341 			 else if( iContentModel[i].type == KAiContentTypeBitmap)
   354 			 else if( iContentModel[i].type == KAiContentTypeBitmap)
   342 				 {
   355 				 {
   343 				 return KImage();
   356 				 return KImage();
   344 				 }
   357 				 }
       
   358 			 else if ( iContentModel[i].type == KAiContentTypeData )
       
   359 			     {
       
   360                  return KData();
       
   361 			     }
   345 			 }
   362 			 }
   346 		}
   363 		}
   347 	
   364 	
   348 	return KNullDesC();
   365 	return KNullDesC();
   349 	}
   366 	}
   568 //
   585 //
   569 // ----------------------------------------------------------------------------
   586 // ----------------------------------------------------------------------------
   570 //
   587 //
   571 void CSapiDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
   588 void CSapiDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
   572     {
   589     {
   573     if ( iDataCount > 0 )
       
   574         {
       
   575         // We own the array so destroy it
       
   576         aSettings.ResetAndDestroy();
       
   577         return;
       
   578         }
       
   579     
       
   580     RAiSettingsItemArray contentItemsArr;    
   590     RAiSettingsItemArray contentItemsArr;    
       
   591     CleanupClosePushL( contentItemsArr );
       
   592     
   581     RAiSettingsItemArray configurationItemsArr;
   593     RAiSettingsItemArray configurationItemsArr;
       
   594     CleanupClosePushL( configurationItemsArr );
   582     
   595     
   583     TInt count( aSettings.Count() );
   596     TInt count( aSettings.Count() );
   584     
   597     
   585     for ( TInt i = 0; i < count; i++ )
   598     for ( TInt i = 0; i < count; i++ )
   586         {
   599         {
   596             }
   609             }
   597         }
   610         }
   598     
   611     
   599     iDataCount = contentItemsArr.Count();
   612     iDataCount = contentItemsArr.Count();
   600     
   613     
   601     if ( iDataCount > 0 )
   614     // Create the content Model
   602         {
   615     HBufC* contentId = HBufC::NewLC( 
   603         // Create the content Model
   616         KAiContentIdMaxLength + KAiPluginNameMaxLength );
   604         HBufC* contentId = HBufC::NewLC( 
   617     
   605             KAiContentIdMaxLength + KAiPluginNameMaxLength );
   618     iContentModel = new TAiContentItem[iDataCount];
   606         
   619     
   607         iContentModel = new TAiContentItem[iDataCount];
   620     for ( TInt i = 0; i < iDataCount; i++ )
   608         
   621         {
   609         for ( TInt i = 0; i < iDataCount; i++ )
   622         MAiPluginContentItem& contentItem( 
   610             {
   623             contentItemsArr[i]->AiPluginContentItem() );
   611             MAiPluginContentItem& contentItem( 
   624         
   612                 contentItemsArr[i]->AiPluginContentItem() );
   625         iContentModel[i].id = i;
       
   626         
       
   627         const TDesC& type( contentItem.Type() );
       
   628         
       
   629         if ( type == KText() || type == KNewsTicker() ||                 
       
   630             type == KTextEditor() )            
       
   631             {
       
   632             // text
       
   633             iContentModel[i].type = KAiContentTypeText;
       
   634             }
       
   635         else if ( type == KImage() )
       
   636             {
       
   637             // image
       
   638             iContentModel[i].type = KAiContentTypeBitmap;
       
   639             }
       
   640         else if ( type == KData() )
       
   641             {
       
   642             // data stream 
       
   643             iContentModel[i].type = KAiContentTypeData;
       
   644             }
       
   645         
       
   646         contentId->Des().Copy( contentItem.Name() );
       
   647         contentId->Des().Delete( 0, 
       
   648             contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 );
       
   649 
       
   650         TInt sizeOfContentId( contentId->Des().Size() + sizeof( wchar_t ) );
       
   651         
       
   652         iContentModel[i].cid = 
       
   653             static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) );
   613             
   654             
   614             iContentModel[i].id = i;
   655         Mem::Copy( ( TAny* )iContentModel[i].cid, 
   615             
   656             contentId->Des().PtrZ(), sizeOfContentId );
   616             if( contentItem.Type() == KText() || 
   657         
   617                 contentItem.Type() == KNewsTicker() ||
   658         contentId->Des().Delete( 0, contentId->Des().Length() );
   618                 contentItem.Type() == KTextEditor() )            
   659         }    
   619                 {
   660     
   620                 // text
   661     CleanupStack::PopAndDestroy( contentId );
   621                 iContentModel[i].type = KAiContentTypeText;
   662 
   622                 }
   663     iContent = AiUtility::CreateContentItemArrayIteratorL( 
   623             if( contentItem.Type() == KImage() )
   664         iContentModel, iDataCount );
   624                 {
   665 
   625                 // image
   666     iData->SetContentIdL( PublisherInfo().Namespace() );
   626                 iContentModel[i].type = KAiContentTypeBitmap;
   667     
   627                 }
   668     // Configurations 
   628             
   669     iData->ConfigureL( configurationItemsArr );
   629             contentId->Des().Copy( contentItem.Name() );
   670 
   630             contentId->Des().Delete( 0, 
   671     // Listen the publisher content update
   631                 contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 );
   672     iData->RegisterContentObserverL();              
   632   
   673 
   633             TInt sizeOfContentId( contentId->Des().Size() + sizeof( wchar_t ) );
   674     CleanupStack::PopAndDestroy( 2, &contentItemsArr ); // configurationItemsArr
   634             
       
   635             iContentModel[i].cid = 
       
   636                 static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) );
       
   637                 
       
   638             Mem::Copy( ( TAny* )iContentModel[i].cid, 
       
   639                 contentId->Des().PtrZ(), sizeOfContentId );
       
   640             
       
   641             contentId->Des().Delete( 0, contentId->Des().Length() );
       
   642             }    
       
   643         
       
   644         CleanupStack::PopAndDestroy( contentId );
       
   645 
       
   646         iContent = AiUtility::CreateContentItemArrayIteratorL( 
       
   647             iContentModel, iDataCount );
       
   648     
       
   649         iData->SetContentIdL( PublisherInfo().Namespace() );
       
   650         
       
   651         // Configurations 
       
   652         iData->ConfigureL( configurationItemsArr );
       
   653 
       
   654         // Listen the publisher content update
       
   655         iData->RegisterContentObserverL();              
       
   656         }
       
   657     
       
   658     contentItemsArr.Reset();
       
   659     configurationItemsArr.Reset();
       
   660    
       
   661     // We own the array so destroy it
       
   662     aSettings.ResetAndDestroy();    
       
   663     }
   675     }
   664 
   676 
   665 // ----------------------------------------------------------------------------
   677 // ----------------------------------------------------------------------------
   666 // CSapiDataPlugin::SetProperty
   678 // CSapiDataPlugin::SetProperty
   667 //
   679 //
   718     {
   730     {
   719     return iPluginState == EResume;
   731     return iPluginState == EResume;
   720     }
   732     }
   721 
   733 
   722 // ----------------------------------------------------------------------------
   734 // ----------------------------------------------------------------------------
       
   735 // CSapiDataPlugin::IsStopped
       
   736 //
       
   737 // ----------------------------------------------------------------------------
       
   738 //
       
   739 TBool CSapiDataPlugin::IsStopped() const
       
   740     {
       
   741     return iPluginState == EStopped;
       
   742     }
       
   743 
       
   744 // ----------------------------------------------------------------------------
   723 // CSapiDataPlugin::Data
   745 // CSapiDataPlugin::Data
   724 //
   746 //
   725 // ----------------------------------------------------------------------------
   747 // ----------------------------------------------------------------------------
   726 //
   748 //
   727 CSapiData* CSapiDataPlugin::Data() const
   749 CSapiData* CSapiDataPlugin::Data() const
   738     {
   760     {
   739     return iNetworkStatus;
   761     return iNetworkStatus;
   740     }
   762     }
   741 
   763 
   742 // End of file
   764 // End of file
       
   765