idlehomescreen/xmluirendering/uiengine/src/xnviewdata.cpp
branchRCL_3
changeset 9 f966699dea19
parent 2 08c6ee43b396
child 15 ff572dfe6d86
equal deleted inserted replaced
5:c743ef5928ba 9:f966699dea19
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <babitflags.h>
    19 #include <babitflags.h>
       
    20 #include <aifwdefs.h>
    20 
    21 
    21 // User includes
    22 // User includes
       
    23 #include "xnappuiadapter.h"
    22 #include "xncomposer.h"
    24 #include "xncomposer.h"
    23 #include "xnodtparser.h"
    25 #include "xnodtparser.h"
    24 #include "xnviewmanager.h"
    26 #include "xnviewmanager.h"
    25 #include "xnviewdata.h"
    27 #include "xnviewdata.h"
    26 #include "xncontroladapter.h"
    28 #include "xncontroladapter.h"
    27 #include "xndomnode.h"
    29 #include "xndomnode.h"
    28 #include "xnnode.h"
    30 #include "xnnode.h"
    29 #include "xnoomsyshandler.h"
    31 #include "xnoomsyshandler.h"
       
    32 #include "xnpanic.h"
    30 
    33 
    31 // Constants
    34 // Constants
    32 _LIT8( KStateConfirmed, "Confirmed" );
       
    33 _LIT8( KStateError, "Error" );
       
    34 _LIT8( KLockingStatusLocked, "locked" );
    35 _LIT8( KLockingStatusLocked, "locked" );
    35 
    36 
    36 // ============================ LOCAL FUNCTIONS ================================
    37 // ============================ LOCAL FUNCTIONS ================================
    37 
    38 
    38 // ============================ MEMBER FUNCTIONS ===============================
    39 // ============================ MEMBER FUNCTIONS ===============================
    92     {
    93     {
    93     CXnPluginData::ConstructL();
    94     CXnPluginData::ConstructL();
    94     }
    95     }
    95 
    96 
    96 // -----------------------------------------------------------------------------
    97 // -----------------------------------------------------------------------------
    97 // CXnViewData::SetActiveL()
    98 // CXnViewData::SetActive()
    98 // 
    99 // 
    99 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   100 //
   101 //
   101 void CXnViewData::SetActiveL( TBool aActive )
   102 void CXnViewData::SetActive( TBool aActive )
   102     {    
   103     {    
   103     TBool active( Active() );
   104     TBool active( Active() );
   104     
   105     
   105     if ( active == aActive || !Occupied() )
   106     if ( active == aActive || !Occupied() )
   106         {
   107         {
   107         return;
   108         return;
   108         }
   109         }
   109 
   110        
   110     if ( aActive )
   111     if ( aActive )
   111         {     
   112         {     
   112         iFlags.Clear( EIsInitial );
   113         iFlags.Clear( EIsInitial );
   113 
   114 
   114         iFlags.Set( EIsActive );
   115         iFlags.Set( EIsActive );
   115 
   116 
   116         LoadDataPluginsL();
   117         LoadPublishers();       
   117         }
   118         }
   118     else
   119     else
   119         {                              
   120         {                              
   120         DestroyDataPluginsL();
   121         DestroyPublishers( EAiFwPageShutdown );
   121 
   122 
   122         iFlags.Clear( EIsActive );
   123         iFlags.Clear( EIsActive );
   123         }
   124         }
   124     }
   125     }
   125 
   126 
   126 // -----------------------------------------------------------------------------
   127 // -----------------------------------------------------------------------------
   127 // CXnViewData::LoadL()
   128 // CXnViewData::Load()
   128 
   129 
   129 // -----------------------------------------------------------------------------
   130 // -----------------------------------------------------------------------------
   130 //
   131 //
   131 void CXnViewData::LoadL()
   132 TInt CXnViewData::Load()
   132     {               
   133     {               
   133     if ( Occupied() || PluginState().CompareF( KStateError ) == 0 )
   134     if ( Occupied() )
   134         {
   135         {
   135         return;
   136         return KErrInUse;
   136         }
   137         }
   137        
   138        
   138     if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) )
   139     if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) )
   139         {
   140         {                                
   140         ViewManager().OomSysHandler().HandlePotentialOomL();        
   141         return KErrNoMemory;
   141         return;
   142         }
   142         }
   143                    
   143         
   144     TInt err( KErrNone );
   144     TRAPD( error,
   145     
   145                         
   146     TRAP( err, err = iManager.Composer().ComposeViewL( *this ) );
   146         if( iManager.Composer().ComposeViewL( *this ) == KErrNone )
   147 
   147             {
   148     if ( err == KErrNone )
   148             iManager.Parser().LoadViewL( *this );
   149         {
   149             }                  
   150         TRAP( err, iManager.Parser().LoadViewL( *this ) );
   150         );                              
   151         }
   151 
   152         
   152     if ( error || !Occupied() )
   153     if ( err == KErrNone )
   153         {                       
   154         {    
   154         if( error == KErrNoMemory )
   155         iVirginPublishers = ETrue;
   155             {
   156         
   156             ViewManager().OomSysHandler().HandlePotentialOomL();
   157         // Load view's initial widgets
   157             }        
       
   158         
       
   159         // Set error state
       
   160         iFlags.Clear( EIsInitial );
       
   161         
       
   162         SetPluginStateL( KStateError );               
       
   163         }    
       
   164     else
       
   165         {
       
   166         // Must confirm here, as widgets loading may fail, which  
       
   167         // then results his view to be doomed unnceccesarily
       
   168         SetPluginStateL( KStateConfirmed );
       
   169         
       
   170         // Load view initial widgets
       
   171         for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   158         for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   172             {
   159             {
   173             if ( iPluginsData[i]->PluginId() != KNullDesC8 )
   160             if ( iPluginsData[i]->PluginId() != KNullDesC8 )
   174                 {
   161                 {                    
   175                 iPluginsData[i]->LoadL();                        
   162                 TInt err2( iPluginsData[i]->Load() );
       
   163                 
       
   164                 if ( err2 == KXnErrPluginFailure )
       
   165                     {
       
   166                     // Content removed error note must be   
       
   167                     // displayed once when this view is activated
       
   168                     iShowContentRemoved = ETrue;
       
   169                                         
       
   170                     err = err2;                                        
       
   171                     }          
       
   172                 else if ( err2 == KErrNoMemory )
       
   173                     {                                          
       
   174                     err = err2;                                                                  
       
   175                     break;
       
   176                     }
   176                 }
   177                 }
   177             }  
   178             }
   178         
   179                        
   179         if ( Active() )
   180         // Succesfully enough composed, publishers 
   180             {
   181         // will be loaded when view is activated
   181             LoadDataPluginsL();
   182         }
   182             }
   183     
   183         }       
   184     return err;
   184     }
   185     }
   185 
   186 
   186 // -----------------------------------------------------------------------------
   187 // -----------------------------------------------------------------------------
   187 // CXnViewData::Destroy()
   188 // CXnViewData::Destroy()
   188 
   189 
   189 // -----------------------------------------------------------------------------
   190 // -----------------------------------------------------------------------------
   190 //
   191 //
   191 void CXnViewData::Destroy()
   192 void CXnViewData::Destroy()
   192     {
   193     {
   193     if ( Occupied() )
   194     if ( Occupied() )
   194         {
   195         {        
   195         TRAP_IGNORE( DestroyDataPluginsL() );
   196         // View is deleted, pretend plugin is removed from UI
       
   197         DestroyPublishers( EAiFwPluginShutdown );
   196         
   198         
   197         iManager.Parser().DestroyView( *this );
   199         iManager.Parser().DestroyView( *this );
   198         }
   200         }
       
   201         
   199     delete iBgImage;
   202     delete iBgImage;
   200     iBgImage = NULL;
   203     iBgImage = NULL;
   201     Flush();  
   204     
   202     delete iBgImagePath;
   205     delete iBgImagePath;
   203     iBgImagePath = NULL;
   206     iBgImagePath = NULL;
       
   207               
       
   208     Flush();      
   204     }
   209     }
   205 
   210 
   206 // -----------------------------------------------------------------------------
   211 // -----------------------------------------------------------------------------
   207 // CXnViewData::Plugin()
   212 // CXnViewData::Plugin()
   208 // Finds plugin or view data based on node
   213 // Finds plugin or view data based on node
   301 // CXnViewData::SetWallpaperImagePathL
   306 // CXnViewData::SetWallpaperImagePathL
   302 // -----------------------------------------------------------------------------
   307 // -----------------------------------------------------------------------------
   303 //
   308 //
   304 void CXnViewData::SetWallpaperImagePathL( const TDesC& aFileName )
   309 void CXnViewData::SetWallpaperImagePathL( const TDesC& aFileName )
   305     {
   310     {
   306     delete iBgImagePath;
   311     if( !iBgImagePath || iBgImagePath->Des() != aFileName )
   307     iBgImagePath = NULL;
   312         {
   308     iBgImagePath = aFileName.AllocL();
   313         delete iBgImagePath;
       
   314         iBgImagePath = NULL;
       
   315         iBgImagePath = aFileName.AllocL();
       
   316         }
   309     }
   317     }
   310 
   318 
   311 // -----------------------------------------------------------------------------
   319 // -----------------------------------------------------------------------------
   312 // CXnViewData::WallpaperImagePath
   320 // CXnViewData::WallpaperImagePath
   313 // -----------------------------------------------------------------------------
   321 // -----------------------------------------------------------------------------
   395 // Gets this view data's content source nodes
   403 // Gets this view data's content source nodes
   396 // -----------------------------------------------------------------------------
   404 // -----------------------------------------------------------------------------
   397 //
   405 //
   398 void CXnViewData::ContentSourceNodesL( RPointerArray< CXnNode >& aList ) const
   406 void CXnViewData::ContentSourceNodesL( RPointerArray< CXnNode >& aList ) const
   399     {
   407     {
   400     // Get my data provider nodes
   408     // Get my data publisher nodes
   401     CXnPluginData::ContentSourceNodesL( aList );
   409     CXnPluginData::ContentSourceNodesL( aList );
   402 
   410 
   403     for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   411     for ( TInt i = 0; i < iPluginsData.Count(); i++ )
   404         {
   412         {
   405         // And appearance nodes which my plugin holds
   413         // And publisher nodes which my plugin holds
   406         iPluginsData[i]->ContentSourceNodesL( aList );
   414         iPluginsData[i]->ContentSourceNodesL( aList );
   407         }
   415         }
   408     }
   416     }
   409 
   417 
   410 // -----------------------------------------------------------------------------
   418 // -----------------------------------------------------------------------------
   420         aList.AppendL( iPluginsData[i]->Owner()->LayoutNode() );
   428         aList.AppendL( iPluginsData[i]->Owner()->LayoutNode() );
   421         }
   429         }
   422     }
   430     }
   423 
   431 
   424 // -----------------------------------------------------------------------------
   432 // -----------------------------------------------------------------------------
   425 // CXnViewData::LoadDataPluginsL
   433 // CXnViewData::LoadPublishers
   426 // Loads data plugins associated to the plugin
   434 // Loads data plugins associated to the plugin
   427 // -----------------------------------------------------------------------------
   435 // -----------------------------------------------------------------------------
   428 //
   436 //
   429 void CXnViewData::LoadDataPluginsL()
   437 void CXnViewData::LoadPublishers()
   430     {
   438     {
   431     if( Occupied() && Active() )
   439     if( !Active() || !Occupied() )
   432         {               
   440         {               
   433         // Load own plugins first, and after that data plugins for widgets
   441         return;
   434         CXnPluginData::LoadDataPluginsL();
   442         }
   435         }
   443     
   436     }
   444     iLoader->Cancel();
   437 
   445     
   438 // -----------------------------------------------------------------------------
   446     iLoadIndex = 0;
   439 // CXnPluginData::DataPluginsLoadCompletedL
   447             
   440 // Indicates that all data plugins are loaded
   448     iLoader->Start( TTimeIntervalMicroSeconds32( 50 ),
   441 // -----------------------------------------------------------------------------
   449                     TTimeIntervalMicroSeconds32( 50 ),
   442 //
   450                     TCallBack( DoLoadPublishersL, this ) );           
   443 void CXnViewData::DataPluginsLoadCompletedL( TInt aStatus )
   451     }
   444     {       
   452 
   445     if ( aStatus == KErrNone )
   453 // -----------------------------------------------------------------------------
   446         {
   454 // CXnViewData::DoLoadPublishersL()
   447         for( TInt i = 0; i < iPluginsData.Count(); i++ )
   455 // 
   448             {
   456 // -----------------------------------------------------------------------------
   449             iPluginsData[i]->LoadDataPluginsL();
   457 //
       
   458 /* static */ TInt CXnViewData::DoLoadPublishersL( TAny* aAny )
       
   459     {
       
   460     CXnViewData* self = static_cast< CXnViewData* >( aAny );
       
   461     
       
   462     RPointerArray< CXnPluginData >& plugins( self->PluginData() );
       
   463     
       
   464     for ( TInt i = self->iLoadIndex; i < plugins.Count(); i++ )
       
   465         {        
       
   466         if ( !plugins[i]->Occupied() )
       
   467             {
       
   468             self->iLoadIndex++;
       
   469             }
       
   470         else
       
   471             {
       
   472             break;
       
   473             }
       
   474         }
       
   475         
       
   476     if ( self->iLoadIndex < plugins.Count() )
       
   477         {
       
   478         CXnPluginData* plugin( plugins[self->iLoadIndex] );
       
   479              
       
   480         self->iLoadIndex++;
       
   481         
       
   482         TInt reason( plugin->VirginPublishers() ? 
       
   483             EAiFwSystemStartup : EAiFwPageStartup );         
       
   484         
       
   485         if( plugin->LoadPublishers( reason ) != KErrNone )
       
   486             {
       
   487             self->iManager.UnloadWidgetFromPluginL( *plugin, ETrue );
       
   488             
       
   489             self->iShowContentRemoved = ETrue;
       
   490             }
       
   491         
       
   492         }
       
   493     else
       
   494         {                
       
   495         TInt reason( self->VirginPublishers() ? 
       
   496             EAiFwSystemStartup : EAiFwPageStartup ); 
       
   497         
       
   498         self->iVirginPublishers = EFalse;
       
   499         
       
   500         self->iLoader->Cancel();
       
   501         
       
   502         self->iLoadIndex = 0;
       
   503         
       
   504         for ( TInt i = 0; i < self->iContentSourceNodes.Count(); i++ )
       
   505             {            
       
   506             CXnNodeAppIf& plugin( self->iContentSourceNodes[i]->AppIfL() ); 
       
   507                     
       
   508             self->iManager.AppUiAdapter().LoadPublisher( plugin, reason );                          
   450             }                
   509             }                
   451         }
   510                              
   452     
   511         if ( self->iShowContentRemoved )
   453     CXnPluginData::DataPluginsLoadCompletedL( aStatus );
   512             {
   454     }
   513             self->ShowContentRemovedError();
   455 
   514             self->iShowContentRemoved = EFalse;
   456 // -----------------------------------------------------------------------------
   515             }              
   457 // CXnViewData::DestroyDataPluginsL
   516         }                  
       
   517             
       
   518     return KErrNone;       
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CXnViewData::DestroyPublishers
   458 // Remove data plugins associated to the plugin
   523 // Remove data plugins associated to the plugin
   459 // -----------------------------------------------------------------------------
   524 // -----------------------------------------------------------------------------
   460 //
   525 //
   461 void CXnViewData::DestroyDataPluginsL()
   526 void CXnViewData::DestroyPublishers( TInt aReason )
   462     {
   527     {
   463     CXnPluginData::DestroyDataPluginsL();
   528     if ( Occupied() )
   464     
   529         {
   465     for( TInt i = 0; i < iPluginsData.Count(); i++ )
   530         // If not all plugins loaded yet               
   466         {
   531         iLoader->Cancel();                                  
   467         iPluginsData[i]->DestroyDataPluginsL();
   532         
   468         }
   533         TRAP_IGNORE( DoDestroyPublishersL( aReason ) );
   469     }
   534         
   470 
   535         User::Heap().Compress();        
   471 // -----------------------------------------------------------------------------
   536         }
   472 // CXnPluginData::DataPluginsLoaded()
   537     }
   473 // -----------------------------------------------------------------------------
   538 
   474 //
   539 // -----------------------------------------------------------------------------
   475 TBool CXnViewData::DataPluginsLoaded() const
   540 // CXnPluginData::DoDestroyPublishersL
   476     {
   541 // Remove data plugins associated to the plugin
   477     TBool loaded( CXnPluginData::DataPluginsLoaded() );
   542 // -----------------------------------------------------------------------------
   478     
   543 //
   479     for( TInt i = 0; loaded && i < iPluginsData.Count(); i++ )
   544 void CXnViewData::DoDestroyPublishersL( TInt aReason )
   480         {
   545     {
   481         CXnPluginData* plugin( iPluginsData[i] );
   546     // Create list of data plugins to be removed    
   482         
   547     RPointerArray< CXnNode > publishers;
   483         if( plugin->Occupied() )
   548     CleanupClosePushL( publishers );
   484             {
   549     
   485             loaded = plugin->DataPluginsLoaded();
   550     TRAP_IGNORE( ContentSourceNodesL( publishers ) );
   486             }               
   551     
   487         }
   552     for ( TInt i = 0; i < publishers.Count(); i++ )
   488     
   553         {
   489     return loaded;    
   554         // Destruction is synchronous
   490     }
   555         iManager.AppUiAdapter().DestroyPublisher( 
   491 
   556             publishers[i]->AppIfL(), aReason );        
   492 // -----------------------------------------------------------------------------
   557         }
       
   558         
       
   559     CleanupStack::PopAndDestroy( &publishers );    
       
   560     }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CXnViewData::SetLockingStatus
   493 // Sets view's locking_status attribute ("locked"/"none")
   564 // Sets view's locking_status attribute ("locked"/"none")
   494 // -----------------------------------------------------------------------------
   565 // -----------------------------------------------------------------------------
   495 //
   566 //
   496 void CXnViewData::SetLockingStatus( const TDesC8& aLockingStatusString )
   567 void CXnViewData::SetLockingStatus( const TDesC8& aLockingStatusString )
   497     {
   568     {
   498     if( ( aLockingStatusString != KNullDesC8 ) && 
   569     if( ( aLockingStatusString != KNullDesC8 ) && 
   499             ( aLockingStatusString.Match( KLockingStatusLocked ) == 0 ) )
   570         ( aLockingStatusString.Match( KLockingStatusLocked ) == 0 ) )
   500         {
   571         {
   501         iFlags.Clear( EIsRemovable );
   572         iFlags.Clear( EIsRemovable );
   502         }
   573         }
   503     else
   574     else
   504         {
   575         {
   505         iFlags.Set( EIsRemovable );
   576         iFlags.Set( EIsRemovable );
   506         }
   577         }
   507     }
   578     }
       
   579 
   508 // End of file
   580 // End of file