idlehomescreen/xmluirendering/uiengine/src/xnviewdata.cpp
branchRCL_3
changeset 23 7be2816dbabd
parent 17 b8fae6b8a148
child 28 d721605b30d0
equal deleted inserted replaced
19:79311d856354 23:7be2816dbabd
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
       
     9 * Initial Contributors:
     8 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
     9 * Nokia Corporation - initial contribution.
    11 *
    10 *
    12 * Contributors:
    11 * Contributors:
    13 *
    12 *
    15 *
    14 *
    16 */
    15 */
    17 
    16 
    18 // System includes
    17 // System includes
    19 #include <babitflags.h>
    18 #include <babitflags.h>
       
    19 
       
    20 // User includes
    20 #include <aifwdefs.h>
    21 #include <aifwdefs.h>
    21 
       
    22 // User includes
       
    23 #include "xnappuiadapter.h"
    22 #include "xnappuiadapter.h"
    24 #include "xncomposer.h"
    23 #include "xncomposer.h"
    25 #include "xnodtparser.h"
    24 #include "xnodtparser.h"
    26 #include "xnviewmanager.h"
    25 #include "xnviewmanager.h"
    27 #include "xnviewdata.h"
    26 #include "xnviewdata.h"
       
    27 #include "xnpublisherdata.h"
    28 #include "xncontroladapter.h"
    28 #include "xncontroladapter.h"
    29 #include "xndomnode.h"
    29 #include "xndomnode.h"
    30 #include "xnnode.h"
    30 #include "xnnode.h"
    31 #include "xnoomsyshandler.h"
    31 #include "xnoomsyshandler.h"
    32 #include "xnpanic.h"
    32 #include "xnpanic.h"
    33 
    33 
    34 #include "debug.h"
    34 #include "debug.h"
    35 
    35 
    36 // Constants
    36 // Constants
    37 const TInt KLoadDelay( 10000 );
       
    38 const TInt KInterval( 10000 );
       
    39 
    37 
    40 // ============================ LOCAL FUNCTIONS ================================
    38 // ============================ LOCAL FUNCTIONS ================================
    41 
    39 
    42 // ============================ MEMBER FUNCTIONS ===============================
    40 // ============================ MEMBER FUNCTIONS ===============================
    43 // -----------------------------------------------------------------------------
    41 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
    98 // -----------------------------------------------------------------------------
   101 // CXnViewData::SetActive()
    99 // CXnViewData::SetActive()
   102 // 
   100 // 
   103 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   104 //
   102 //
   105 void CXnViewData::SetActive( TBool aActive )
   103 TInt CXnViewData::SetActive( TBool aActive )
   106     {    
   104     {    
   107     TBool active( Active() );
   105     TBool active( Active() );
   108     
   106     
   109     if ( active == aActive || !Occupied() )
   107     TInt err( KErrNone );
   110         {
   108     
   111         return;
   109     if ( !Occupied() )
   112         }
   110         {
   113        
   111         err = KErrGeneral;
   114     if ( aActive )
   112         }    
   115         {
   113     else if ( active == aActive )
   116         iFlags.Set( EIsActive );
   114         {
   117         iFlags.Clear( EIsInitial );
   115         err = KErrNone;
   118         
       
   119         LoadPublishers();                             
       
   120         }
   116         }
   121     else
   117     else
   122         {                              
   118         {
   123         DestroyPublishers( EAiFwPageShutdown );
   119         if ( aActive )
   124 
   120             {
   125         iFlags.Clear( EIsActive );
   121             iFlags.Set( EIsActive );
   126         }
   122             iFlags.Clear( EIsInitial );
       
   123             
       
   124             LoadPublishers( EAiFwPageStartup );
       
   125             
       
   126             err = iLoadError;
       
   127             
       
   128             iLoadError = KErrNone;
       
   129             }
       
   130         else
       
   131             {                              
       
   132             DestroyPublishers( EAiFwPageShutdown );
       
   133     
       
   134             iFlags.Clear( EIsActive );
       
   135             }    
       
   136         }       
       
   137     
       
   138     return err;
   127     }
   139     }
   128 
   140 
   129 // -----------------------------------------------------------------------------
   141 // -----------------------------------------------------------------------------
   130 // CXnViewData::Load()
   142 // CXnViewData::Load()
   131 
   143 
   132 // -----------------------------------------------------------------------------
   144 // -----------------------------------------------------------------------------
   133 //
   145 //
   134 TInt CXnViewData::Load()
   146 TInt CXnViewData::Load()
   135     {               
   147     {   
       
   148     iLoadError = KErrNone;
       
   149     
   136     if ( Occupied() )
   150     if ( Occupied() )
   137         {
   151         {
   138         return KErrInUse;
   152         iLoadError = KErrInUse;
   139         }
   153         }      
   140        
   154     else if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) )
   141     if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) )
       
   142         {                                
   155         {                                
   143         return KErrNoMemory;
   156         iLoadError = KErrNoMemory;
   144         }
   157         }
   145                    
   158     else
   146     TInt err( KErrNone );
   159         {
   147     
   160         TInt err( KErrNone );
   148     TRAP( err, err = iManager.Composer().ComposeViewL( *this ) );
   161         
   149 
   162         TRAP( err, err = iManager.Composer().ComposeViewL( *this ) );
   150     if ( err == KErrNone )
   163     
   151         {
   164         if ( err == KErrNone )
   152         TRAP( err, iManager.Parser().LoadViewL( *this ) );
   165             {
   153         }
   166             TRAP( err, iManager.Parser().LoadViewL( *this ) );
   154         
   167             }
   155     if ( err == KErrNone )
   168                            
   156         {    
   169         if ( err == KErrNone )
   157         iVirginPublishers = ETrue;
   170             {                  
   158         
   171             // Load view's initial widgets
   159         // Load view's initial widgets
   172             for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   160         for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   173                 {
   161             {
   174                 if ( iPluginsData[i]->PluginId() != KNullDesC8 )
   162             if ( iPluginsData[i]->PluginId() != KNullDesC8 )
   175                     {                    
   163                 {                    
   176                     TInt err2( iPluginsData[i]->Load() );
   164                 TInt err2( iPluginsData[i]->Load() );
   177                     
   165                 
   178                     if ( err2 == KXnErrPluginFailure )
   166                 if ( err2 == KXnErrPluginFailure )
   179                         {
   167                     {
   180                         err = err2;                                        
   168                     // Content removed error note must be   
   181                         }          
   169                     // displayed once when this view is activated
   182                     else if ( err2 == KErrNoMemory )
   170                     iShowContentRemoved = ETrue;
   183                         {                                          
   171                                         
   184                         err = err2;                                                                  
   172                     err = err2;                                        
   185                         break;
   173                     }          
   186                         }
   174                 else if ( err2 == KErrNoMemory )
       
   175                     {                                          
       
   176                     err = err2;                                                                  
       
   177                     break;
       
   178                     }
   187                     }
   179                 }
   188                 }
   180             }
   189                            
       
   190             // Succesfully enough composed, publishers 
       
   191             // will be loaded when view is activated
       
   192             }    
       
   193         
       
   194         iLoadError = err;
       
   195         }
   181                        
   196                        
   182         // Succesfully enough composed, publishers 
   197     return iLoadError;
   183         // will be loaded when view is activated
       
   184         }
       
   185     
       
   186     return err;
       
   187     }
   198     }
   188 
   199 
   189 // -----------------------------------------------------------------------------
   200 // -----------------------------------------------------------------------------
   190 // CXnViewData::Destroy()
   201 // CXnViewData::Destroy()
   191 
   202 
   204     delete iBgImage;
   215     delete iBgImage;
   205     iBgImage = NULL;
   216     iBgImage = NULL;
   206     
   217     
   207     delete iBgImagePath;
   218     delete iBgImagePath;
   208     iBgImagePath = NULL;
   219     iBgImagePath = NULL;
   209               
   220     
       
   221     iLoadError = KErrNone;
       
   222     
   210     Flush();      
   223     Flush();      
   211     }
   224     }
   212 
   225 
   213 // -----------------------------------------------------------------------------
   226 // -----------------------------------------------------------------------------
   214 // CXnViewData::Plugin()
   227 // CXnViewData::Plugin()
   313     return iBgImage;
   326     return iBgImage;
   314     }
   327     }
   315 
   328 
   316 // -----------------------------------------------------------------------------
   329 // -----------------------------------------------------------------------------
   317 // CXnViewData::SetWallpaperImagePathL
   330 // CXnViewData::SetWallpaperImagePathL
       
   331 //
   318 // -----------------------------------------------------------------------------
   332 // -----------------------------------------------------------------------------
   319 //
   333 //
   320 void CXnViewData::SetWallpaperImagePathL( const TDesC& aFileName )
   334 void CXnViewData::SetWallpaperImagePathL( const TDesC& aFileName )
   321     {
   335     {
   322     if( !iBgImagePath || iBgImagePath->Des() != aFileName )
   336     if( !iBgImagePath || iBgImagePath->Des() != aFileName )
   327         }
   341         }
   328     }
   342     }
   329 
   343 
   330 // -----------------------------------------------------------------------------
   344 // -----------------------------------------------------------------------------
   331 // CXnViewData::WallpaperImagePath
   345 // CXnViewData::WallpaperImagePath
       
   346 //
   332 // -----------------------------------------------------------------------------
   347 // -----------------------------------------------------------------------------
   333 //
   348 //
   334 const TDesC& CXnViewData::WallpaperImagePath() const
   349 const TDesC& CXnViewData::WallpaperImagePath() const
   335     {
   350     {
   336     if( iBgImagePath )
   351     if( iBgImagePath )
   460 // -----------------------------------------------------------------------------
   475 // -----------------------------------------------------------------------------
   461 // CXnViewData::LoadPublishers
   476 // CXnViewData::LoadPublishers
   462 // Loads data plugins associated to the plugin
   477 // Loads data plugins associated to the plugin
   463 // -----------------------------------------------------------------------------
   478 // -----------------------------------------------------------------------------
   464 //
   479 //
   465 void CXnViewData::LoadPublishers()
   480 void CXnViewData::LoadPublishers( TInt aReason )
   466     {
   481     {
       
   482     __PRINTS( "*** CXnViewData::LoadPublishers" );
       
   483     
   467     if( !Active() || !Occupied() )
   484     if( !Active() || !Occupied() )
   468         {               
   485         {               
       
   486         __PRINTS( "*** CXnViewData::LoadPublishers - done, !Active() || !Occupied()" );
       
   487         
   469         return;
   488         return;
   470         }
   489         }
   471     
   490     
   472     iLoader->Cancel();
   491     for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   473     
   492         {
   474     iLoadIndex = 0;
   493         CXnPluginData* plugin( iPluginsData[i] );
   475                                 
   494         
   476     iLoader->Start( TTimeIntervalMicroSeconds32( KLoadDelay ),
   495         if ( plugin->Occupied() )
   477                     TTimeIntervalMicroSeconds32( KInterval ),
   496             {            
   478                     TCallBack( DoLoadPublishersL, this ) );           
   497             plugin->LoadPublishers( aReason );
   479     }
   498             }
   480 
   499         }
   481 // -----------------------------------------------------------------------------
   500         
   482 // CXnViewData::DoLoadPublishersL()
   501     CXnPluginData::LoadPublishers( aReason );
   483 // 
   502 
   484 // -----------------------------------------------------------------------------
   503     __PRINTS( "*** CXnViewData::LoadPublishers - done" );
   485 //
   504     }
   486 /* static */ TInt CXnViewData::DoLoadPublishersL( TAny* aAny )
   505 
   487     {
   506 // -----------------------------------------------------------------------------
   488     __PRINTS( "*** CXnViewData::DoLoadPublishersL" );
   507 // CXnViewData::NotifyPublisherReadyL
   489     
   508 // Notifies a publisher is ready
   490     CXnViewData* self = static_cast< CXnViewData* >( aAny );
   509 // -----------------------------------------------------------------------------
   491     
   510 //
   492     CXnAppUiAdapter* appui = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );         
   511 void CXnViewData::NotifyPublisherReadyL()
   493     
   512     {       
   494     RPointerArray< CXnPluginData >& plugins( self->PluginData() );
   513     if ( !Active() )
   495     
   514         {
   496     for ( TInt i = self->iLoadIndex; i < plugins.Count(); i++ )
   515         return;
   497         {        
   516         }
   498         if ( !plugins[i]->Occupied() )
   517      
   499             {
   518     TBool allready( ETrue );
   500             self->iLoadIndex++;
   519     
   501             }
   520     RPointerArray< CXnPublisherData > list;
   502         else
   521     CleanupClosePushL( list );
   503             {
   522     
       
   523     for ( TInt i = 0; i < iPluginsData.Count(); i++ )
       
   524         {
       
   525         CXnPluginData* plugin( iPluginsData[i] );
       
   526         
       
   527         if ( plugin->Occupied() )
       
   528             {
       
   529             plugin->PublishersL( list );
       
   530             }
       
   531         }
       
   532     
       
   533     CXnPluginData::PublishersL( list );
       
   534 
       
   535     for ( TInt i = 0; i < list.Count(); i++ )
       
   536         {
       
   537         CXnPublisherData* publisher( list[i] );
       
   538         
       
   539         if ( publisher->IsLoading() )
       
   540             {
       
   541             allready = EFalse;
   504             break;
   542             break;
   505             }
   543             }
   506         }
   544         }
   507         
   545 
   508     if ( self->iLoadIndex < plugins.Count() )
   546     if ( allready && Active() )
   509         {
   547         {
   510         CXnPluginData* plugin( plugins[self->iLoadIndex] );
   548         TInt result( KErrNone );
   511              
   549         
   512         self->iLoadIndex++;
   550         for ( TInt i = 0; i < list.Count(); i++ )
   513         
   551             {
   514         TInt reason( plugin->VirginPublishers() ? 
   552             CXnPublisherData* publisher( list[i] );
   515             EAiFwSystemStartup : EAiFwPageStartup );         
   553             
   516         
   554             if ( publisher->IsFailed() )
   517         TInt ret( plugin->LoadPublishers( reason ) );
   555                 {
   518         
   556                 CXnPluginData* plugin( publisher->Owner() );
   519         if ( ret == KErrAlreadyExists )
   557                 
   520             {
   558                 if ( plugin != this && plugin->Removable() )
   521             ret = KErrNone;
   559                     {
   522             }
   560                     iManager.UnloadWidgetFromPluginL( *plugin, ETrue );
   523         
       
   524         if( ret != KErrNone )
       
   525             {
       
   526             self->iManager.UnloadWidgetFromPluginL( *plugin, ETrue );            
       
   527             self->iShowContentRemoved = ETrue;
       
   528             }        
       
   529         }
       
   530     else
       
   531         {                
       
   532         TInt reason( self->VirginPublishers() ? 
       
   533             EAiFwSystemStartup : EAiFwPageStartup ); 
       
   534         
       
   535         self->iVirginPublishers = EFalse;
       
   536         
       
   537         self->iLoader->Cancel();
       
   538         
       
   539         self->iLoadIndex = 0;
       
   540         
       
   541         for ( TInt i = 0; i < self->iContentSourceNodes.Count(); i++ )
       
   542             {            
       
   543             CXnNodeAppIf& plugin( self->iContentSourceNodes[i]->AppIfL() ); 
       
   544                     
   561                     
   545             appui->LoadPublisher( plugin, reason );                          
   562                     result = KXnErrPluginFailure;
   546             }                
   563                     }                              
   547                              
   564                 }
   548         if ( self->iShowContentRemoved )
   565             }
   549             {
   566         
   550             self->ShowContentRemovedError();
   567         TRAP_IGNORE( iManager.PublishersReadyL( *this, result ) );        
   551             self->iShowContentRemoved = EFalse;
   568         }
   552             }      
   569         
   553                 
   570     CleanupStack::PopAndDestroy( &list );
   554         // Fire UI ready blindly here, it will be handled in AiFw if needed
       
   555         appui->HandleUiReadyEventL();
       
   556         }                  
       
   557             
       
   558     __PRINTS( "*** CXnViewData::DoLoadPublishersL - done" );
       
   559     
       
   560     return KErrNone;       
       
   561     }
   571     }
   562 
   572 
   563 // -----------------------------------------------------------------------------
   573 // -----------------------------------------------------------------------------
   564 // CXnViewData::DestroyPublishers
   574 // CXnViewData::DestroyPublishers
   565 // Remove data plugins associated to the plugin
   575 // Destroys data plugins associated to the plugin
   566 // -----------------------------------------------------------------------------
   576 // -----------------------------------------------------------------------------
   567 //
   577 //
   568 void CXnViewData::DestroyPublishers( TInt aReason )
   578 void CXnViewData::DestroyPublishers( TInt aReason )
   569     {
   579     {
   570     __PRINTS( "*** CXnViewData::DestroyPublishers" );
   580     __PRINTS( "*** CXnViewData::DestroyPublishers" );
   571     
   581     
   572     if ( Occupied() )
   582     if ( !Occupied() )
   573         {
   583         {
   574         // If not all plugins loaded yet               
   584         __PRINTS( "*** CXnViewData::DestroyPublishers - done, !Occupied()" );
   575         iLoader->Cancel();                                  
   585         
   576         
   586         return;
   577         TRAP_IGNORE( DoDestroyPublishersL( aReason ) );
   587         }
   578         
   588     
   579         User::Heap().Compress();        
   589     for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   580         }
   590         {
       
   591         CXnPluginData* plugin( iPluginsData[i] );
       
   592         
       
   593         if ( plugin->Occupied() )
       
   594             {
       
   595             plugin->DestroyPublishers( aReason );
       
   596             }
       
   597         }
       
   598     
       
   599     CXnPluginData::DestroyPublishers( aReason );
   581     
   600     
   582     __PRINTS( "*** CXnViewData::DestroyPublishers - done" );
   601     __PRINTS( "*** CXnViewData::DestroyPublishers - done" );
   583     }
   602     }
   584 
   603 
   585 // -----------------------------------------------------------------------------
       
   586 // CXnPluginData::DoDestroyPublishersL
       
   587 // Remove data plugins associated to the plugin
       
   588 // -----------------------------------------------------------------------------
       
   589 //
       
   590 void CXnViewData::DoDestroyPublishersL( TInt aReason )
       
   591     {
       
   592     __TIME_MARK( time );
       
   593     
       
   594     // Create list of data plugins to be removed    
       
   595     RPointerArray< CXnNode > publishers;
       
   596     CleanupClosePushL( publishers );
       
   597     
       
   598     TRAP_IGNORE( ContentSourceNodesL( publishers ) );
       
   599     
       
   600     for ( TInt i = 0; i < publishers.Count(); i++ )
       
   601         {
       
   602         // Destruction is synchronous
       
   603         iManager.AppUiAdapter().DestroyPublisher( 
       
   604             publishers[i]->AppIfL(), aReason );        
       
   605         }
       
   606         
       
   607     CleanupStack::PopAndDestroy( &publishers );
       
   608     
       
   609     __TIME_ENDMARK( "CXnViewData::DoDestroyPublishersL, done", time );
       
   610     }
       
   611 
       
   612 // End of file
   604 // End of file