idlefw/plugins/wrtdataplugin/src/wrtdataplugin.cpp
branchRCL_3
changeset 23 ace62b58f4b2
parent 19 edd621764147
equal deleted inserted replaced
22:1b207dd38b72 23:ace62b58f4b2
    82 // CWrtDataPlugin::CWrtDataPlugin()
    82 // CWrtDataPlugin::CWrtDataPlugin()
    83 //
    83 //
    84 // ----------------------------------------------------------------------------
    84 // ----------------------------------------------------------------------------
    85 //
    85 //
    86 CWrtDataPlugin::CWrtDataPlugin()
    86 CWrtDataPlugin::CWrtDataPlugin()
    87     : iNetworkStatus( EUnknown ), iPluginState( ENone ) 
    87     : iNetworkStatus( EUnknown ), iPluginState( EStopped ) 
    88     {
    88     {
    89     }
    89     }
    90     
    90     
    91 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
    92 // CWrtDataPlugin::ConstructL()
    92 // CWrtDataPlugin::ConstructL()
   136 //
   136 //
   137 // ----------------------------------------------------------------------------
   137 // ----------------------------------------------------------------------------
   138 //
   138 //
   139 void CWrtDataPlugin::Start( TStartReason aReason )
   139 void CWrtDataPlugin::Start( TStartReason aReason )
   140     {
   140     {
   141     iStopped = EFalse;
   141     iPluginState = EStarted;
   142     
   142     
   143     if( aReason == ESystemStartup || 
   143     if( aReason == ESystemStartup || 
   144         aReason == EPluginStartup )
   144         aReason == EPluginStartup )
   145         {
   145         {
   146         // Publish the initial data
   146         // Publish the initial data
   153 //
   153 //
   154 // ----------------------------------------------------------------------------
   154 // ----------------------------------------------------------------------------
   155 //
   155 //
   156 void CWrtDataPlugin::Stop( TStopReason aReason )
   156 void CWrtDataPlugin::Stop( TStopReason aReason )
   157     {
   157     {
       
   158     iPluginState = EStopped;
       
   159     
   158     if( aReason == EPluginShutdown ||
   160     if( aReason == EPluginShutdown ||
   159         aReason == ESystemShutdown )
   161         aReason == ESystemShutdown )
   160         {
   162         {
   161         TRAP_IGNORE(iData->NotifyPublisherL( KDeActive ));
   163         TRAP_IGNORE(iData->NotifyPublisherL( KDeActive ));
   162         }
   164         }
   163     
       
   164     iStopped = ETrue;
       
   165     }
   165     }
   166 
   166 
   167 // ----------------------------------------------------------------------------
   167 // ----------------------------------------------------------------------------
   168 // CWrtDataPlugin::Resume
   168 // CWrtDataPlugin::Resume
   169 //
   169 //
   170 // ----------------------------------------------------------------------------
   170 // ----------------------------------------------------------------------------
   171 //
   171 //
   172 void CWrtDataPlugin::Resume( TResumeReason aReason )
   172 void CWrtDataPlugin::Resume( TResumeReason aReason )
   173     {
   173     {
   174     if ( aReason == EForeground && !iStopped )
   174     if ( aReason == EForeground && iPluginState != EStopped )
   175         {
   175         {
   176         iPluginState = EResume;
   176         iPluginState = EResume;
   177 
   177 
   178         TRAP_IGNORE( iData->NotifyPublisherL( KResume ));        
   178         TRAP_IGNORE( iData->NotifyPublisherL( KResume ));        
   179         }    
   179         }    
   184 //
   184 //
   185 // ----------------------------------------------------------------------------
   185 // ----------------------------------------------------------------------------
   186 //
   186 //
   187 void CWrtDataPlugin::Suspend( TSuspendReason aReason )
   187 void CWrtDataPlugin::Suspend( TSuspendReason aReason )
   188     {    
   188     {    
   189     if ( aReason == EBackground && !iStopped )
   189     if ( aReason == EBackground && iPluginState != EStopped )
   190         {
   190         {
   191         iPluginState = ESuspend;
   191         iPluginState = ESuspend;
   192         
   192         
   193         TRAP_IGNORE ( iData->NotifyPublisherL( KSuspend ));        
   193         TRAP_IGNORE ( iData->NotifyPublisherL( KSuspend ));        
   194         }        
   194         }        
   199 //
   199 //
   200 // ----------------------------------------------------------------------------
   200 // ----------------------------------------------------------------------------
   201 //
   201 //
   202 void CWrtDataPlugin::SetOnline()
   202 void CWrtDataPlugin::SetOnline()
   203     {    
   203     {    
   204     if ( !iStopped )
   204     if ( iPluginState != EStopped )
   205         {
   205         {
   206         iNetworkStatus = EOnline;
   206         iNetworkStatus = EOnline;
   207         TRAP_IGNORE( iData->NotifyPublisherL( KOnLine ));                
   207         TRAP_IGNORE( iData->NotifyPublisherL( KOnLine ));                
   208         }
   208         }
   209     }
   209     }
   213 //
   213 //
   214 // ----------------------------------------------------------------------------
   214 // ----------------------------------------------------------------------------
   215 //
   215 //
   216 void CWrtDataPlugin::SetOffline()
   216 void CWrtDataPlugin::SetOffline()
   217     {
   217     {
   218     if ( !iStopped )
   218     if ( iPluginState != EStopped )
   219         {   
   219         {   
   220         iNetworkStatus = EOffline;
   220         iNetworkStatus = EOffline;
   221         TRAP_IGNORE( iData->NotifyPublisherL( KOffLine ));
   221         TRAP_IGNORE( iData->NotifyPublisherL( KOffLine ));
   222         }
   222         }
   223     }
   223     }
   237 //
   237 //
   238 // ----------------------------------------------------------------------------
   238 // ----------------------------------------------------------------------------
   239 //
   239 //
   240 void CWrtDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
   240 void CWrtDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
   241     {
   241     {
   242     if( iDataCount > 0 )
       
   243         {
       
   244         // We own the array so destroy it
       
   245          aSettings.ResetAndDestroy();
       
   246          return;
       
   247         }
       
   248     
       
   249     RAiSettingsItemArray contentItemsArr;
   242     RAiSettingsItemArray contentItemsArr;
   250     RAiSettingsItemArray configurationItemsArr;
   243     RAiSettingsItemArray configurationItemsArr;
   251     TInt count( aSettings.Count() );
   244     TInt count( aSettings.Count() );
   252     
   245     
   253     for ( TInt i = 0; i < count; i++ )
   246     for ( TInt i = 0; i < count; i++ )
   263             configurationItemsArr.Append( setting );
   256             configurationItemsArr.Append( setting );
   264             }
   257             }
   265         }
   258         }
   266     
   259     
   267     iDataCount = contentItemsArr.Count();
   260     iDataCount = contentItemsArr.Count();
   268     
   261  
   269     if ( iDataCount > 0 )
   262     // Create the content Model
   270         {
   263     HBufC16* contentId = HBufC16::NewLC( 
   271         // Create the content Model
   264         KAiContentIdMaxLength + KAiPluginNameMaxLength );
   272         HBufC16* contentId = HBufC16::NewLC( 
   265     
   273             KAiContentIdMaxLength + KAiPluginNameMaxLength );
   266     iContentModel = new TAiContentItem[iDataCount];
       
   267     
       
   268     for( TInt i = 0; i < iDataCount; i++ )
       
   269         {
       
   270         MAiPluginContentItem& contentItem( 
       
   271             contentItemsArr[i]->AiPluginContentItem() );
   274         
   272         
   275         iContentModel = new TAiContentItem[iDataCount];
   273         iContentModel[i].id = i;
       
   274         if( contentItem.Type() == KText() )
       
   275             {
       
   276             // text
       
   277             iContentModel[i].type = KAiContentTypeText;
       
   278             }
       
   279         if( contentItem.Type() == KImage() || 
       
   280             contentItem.Type() == KAnimation() )
       
   281             {
       
   282             // image
       
   283             iContentModel[i].type = KAiContentTypeBitmap;
       
   284             }
   276         
   285         
   277         for( TInt i = 0; i < iDataCount; i++ )
   286         contentId->Des().Copy( contentItem.Name() );
   278             {
   287         contentId->Des().Delete( 0, 
   279             MAiPluginContentItem& contentItem( 
   288             contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 );
   280                 contentItemsArr[i]->AiPluginContentItem() );
   289 
       
   290         TInt sizeOfContentId( contentId->Des().Size()+sizeof( wchar_t ) );
       
   291         
       
   292         iContentModel[i].cid = 
       
   293             static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) );
   281             
   294             
   282             iContentModel[i].id = i;
   295         Mem::Copy( ( TAny* )iContentModel[i].cid, 
   283             if( contentItem.Type() == KText() )
   296             contentId->Des().PtrZ(), sizeOfContentId );
   284                 {
       
   285                 // text
       
   286                 iContentModel[i].type = KAiContentTypeText;
       
   287                 }
       
   288             if( contentItem.Type() == KImage() || 
       
   289         		contentItem.Type() == KAnimation() )
       
   290                 {
       
   291                 // image
       
   292                 iContentModel[i].type = KAiContentTypeBitmap;
       
   293                 }
       
   294             
       
   295             contentId->Des().Copy( contentItem.Name() );
       
   296             contentId->Des().Delete( 0, 
       
   297                 contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 );
       
   298   
       
   299             TInt sizeOfContentId( contentId->Des().Size()+sizeof( wchar_t ) );
       
   300             
       
   301             iContentModel[i].cid = 
       
   302                 static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) );
       
   303                 
       
   304             Mem::Copy( ( TAny* )iContentModel[i].cid, 
       
   305                 contentId->Des().PtrZ(), sizeOfContentId );
       
   306             
       
   307             contentId->Des().Delete( 0, contentId->Des().Length() );
       
   308             }    
       
   309         
   297         
   310         CleanupStack::PopAndDestroy( contentId );
   298         contentId->Des().Delete( 0, contentId->Des().Length() );
   311         iContent = AiUtility::CreateContentItemArrayIteratorL( 
   299         }    
   312                 iContentModel, iDataCount );
   300     
   313                        
   301     CleanupStack::PopAndDestroy( contentId );
   314         // Configurations 
   302     iContent = AiUtility::CreateContentItemArrayIteratorL( 
   315         iData->ConfigureL( configurationItemsArr );
   303             iContentModel, iDataCount );
   316 
   304                    
   317         iPluginState = ESuspend;
   305     // Configurations 
   318 
   306     iData->ConfigureL( configurationItemsArr );
   319         // Register for notifications
   307 
   320         iData->RegisterL();
   308     // Register for notifications
   321         
   309     iData->RegisterL();
   322         // Activate the publisher 
   310     
   323         iData->NotifyPublisherL( KActive );
   311     // Activate the publisher 
   324         }
   312     iData->NotifyPublisherL( KActive );
   325     
   313     
   326     contentItemsArr.Reset();
   314     contentItemsArr.Reset();
   327     configurationItemsArr.Reset();
   315     configurationItemsArr.Reset();
   328     // We own the array so destroy it
   316     // We own the array so destroy it
   329     aSettings.ResetAndDestroy();
   317     aSettings.ResetAndDestroy();
   373 //
   361 //
   374 // ----------------------------------------------------------------------------
   362 // ----------------------------------------------------------------------------
   375 //
   363 //
   376 TBool CWrtDataPlugin::IsActive() const
   364 TBool CWrtDataPlugin::IsActive() const
   377     {
   365     {
   378     return iPluginState == EResume && !iStopped;
   366     return iPluginState == EResume;
       
   367     }
       
   368 
       
   369 // ----------------------------------------------------------------------------
       
   370 // CWrtDataPlugin::IsStopped
       
   371 //
       
   372 // ----------------------------------------------------------------------------
       
   373 //
       
   374 TBool CWrtDataPlugin::IsStopped() const
       
   375     {
       
   376     return iPluginState == EStopped;
   379     }
   377     }
   380 
   378 
   381 // ----------------------------------------------------------------------------
   379 // ----------------------------------------------------------------------------
   382 // CWrtDataPlugin::Data
   380 // CWrtDataPlugin::Data
   383 //
   381 //