phonebookui/Phonebook2/ccapplication/ccapp/src/ccaappview.cpp
changeset 0 e686773b3f54
child 7 b3431bff8c19
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  A class responsible handling the views
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "ccappheaders.h"
       
    21 #include <mccappviewpluginbase2.h>
       
    22 #include "ccappmycardpluginuids.hrh"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CCCAppView::CCCAppView
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CCCAppView::CCCAppView( CCCAAppAppUi& aAppUi )
       
    31     : iAppUi ( aAppUi ),
       
    32       iViewChangeInProgress ( EFalse )
       
    33     {
       
    34     CCA_DP( KCCAppLogFile, CCA_L("CCCAppView::CCCAppView"));
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CCCAppView::~CCCAppView
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CCCAppView::~CCCAppView()
       
    42     {
       
    43     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::~CCCAppView"));
       
    44     
       
    45     iPluginUidToBeSynchd.Close();
       
    46     
       
    47     if ( iCmsWrapper )
       
    48         {
       
    49         iCmsWrapper->RemoveObserver( *this );    
       
    50         iCmsWrapper->Release();
       
    51         }
       
    52     iObservers.Reset();
       
    53     iObservers.Close();
       
    54     delete iPaneHandler; 
       
    55     delete iPluginLoader;
       
    56     delete iViewResetter;
       
    57     delete iDelayedConstructor;
       
    58 
       
    59     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::~CCCAppView"));
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CCCAppView::NewL
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CCCAppView* CCCAppView::NewL( CCCAAppAppUi& aAppUi )
       
    67     {
       
    68     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::NewL"));
       
    69     
       
    70     CCCAppView* self = new( ELeave ) CCCAppView( aAppUi );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop( self );
       
    74 
       
    75     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::NewL"));
       
    76     return self;
       
    77 	}
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CCCAppView::ConstructL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CCCAppView::ConstructL()
       
    84     {
       
    85     //CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::ConstructL"));
       
    86 
       
    87     //CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ConstructL"));
       
    88 	} 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CCCAppView::StartView
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 TInt CCCAppView::StartView( const TUid aUid )
       
    95     {
       
    96     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::StartView"));
       
    97     TRAPD( err, StartViewL( aUid ))
       
    98     CCA_DP( KCCAppLogFile, CCA_L("::StartView - StartViewL returned err: %d"), err );
       
    99     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::StartView"));
       
   100     return err;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CCCAppView::StartViewL
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CCCAppView::StartViewL( const TUid aUid )
       
   108     {
       
   109     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::StartViewL"));
       
   110     iDelayedStarting = ETrue;
       
   111 
       
   112     // 1st start the contact fetching
       
   113     iCmsWrapper = CCCAppCmsContactFetcherWrapper::CreateInstanceL( 
       
   114          &iAppUi.Parameter(), CCCAppCmsContactFetcherWrapper::EFindContactFromOtherStores );
       
   115     iCmsWrapper->AddObserverL( *this );
       
   116 
       
   117     // TODO: replace hardcoded uid comparison with better sollution that
       
   118     // supports other mycard views too
       
   119     TBool isUidMyCard = ( aUid == 
       
   120             TUid::Uid( KCCAMyCardPluginImplmentationUid ) );
       
   121 
       
   122     
       
   123     //In this version support only contact type data (i.e. group data discarded)
       
   124     _LIT8( KCcaOpaqueTag_CNT,           "CNT" );    //Contact    
       
   125     _LIT8( KCcaOpaqueTag_MCD,           "MCD" );    //MyCard    
       
   126     _LIT8( KCcaPluginTypeMyCard,        "application/x-mycard" );    
       
   127     
       
   128     TPtrC8 properties( isUidMyCard ? KCcaOpaqueTag_MCD : KCcaOpaqueTag_CNT);
       
   129     TPtrC8 type( KNullDesC8 );
       
   130     if( isUidMyCard )
       
   131         {
       
   132         type.Set( KCcaPluginTypeMyCard );    
       
   133         }
       
   134     iPluginLoader = CCCAppPluginLoader::NewL( this, properties, type );
       
   135     CCA_DP( KCCAppLogFile, CCA_L("::ConstructL - iPluginLoader created"));
       
   136     iPaneHandler = CCCAppStatusPaneHandler::NewL( *this );
       
   137     CCA_DP( KCCAppLogFile, CCA_L("::ConstructL - iPaneHandler created"));    
       
   138     
       
   139     // 2nd start constructing the plugin view with preferred
       
   140     // plugin view (if provided)
       
   141     TInt pluginToFocus = iPluginLoader->SetPluginInFocus( aUid );
       
   142 
       
   143     if(pluginToFocus != KErrNotFound)
       
   144         {
       
   145         iPluginLoader->SetPluginVisibility(aUid, CCCAppPluginData::EPluginVisible); 
       
   146         }
       
   147     else
       
   148         {
       
   149         //Not found, try set the first plugin
       
   150         pluginToFocus = 0;
       
   151         if(iPluginLoader->PluginAt(pluginToFocus)) 
       
   152             {
       
   153             iPluginLoader->SetPluginVisibility(
       
   154                 iPluginLoader->PluginAt(pluginToFocus)->Plugin().Id(), CCCAppPluginData::EPluginVisible);  
       
   155             }
       
   156         }
       
   157 
       
   158     //Start plugin and construct CIdle object to call back to finalise 
       
   159     //time consuming construction    
       
   160     StartPluginL(pluginToFocus);
       
   161     iDelayedConstructor = CIdle::NewL( CActive::EPriorityIdle );
       
   162     iDelayedConstructor->Start( TCallBack( ConstructDelayedCallbackL, this) );            
       
   163     
       
   164     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::StartViewL"));
       
   165 	} 
       
   166 
       
   167 // ----------------------------------------------------------------------------
       
   168 // CCCAppView::ConstructDelayedCallbackL
       
   169 //
       
   170 // Called from CIdle to finish time consuming construction operations
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 TInt CCCAppView::ConstructDelayedCallbackL( TAny* aContainer )
       
   174     {
       
   175     CCCAppView* container = static_cast<CCCAppView*>( aContainer );
       
   176     container->DoConstructDelayedL();    
       
   177     return 0;
       
   178     }    
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CCCAppView::DoConstructDelayedL
       
   182 //
       
   183 // Perform time consuming construction operations
       
   184 // ----------------------------------------------------------------------------
       
   185 //
       
   186 void CCCAppView::DoConstructDelayedL()
       
   187     {
       
   188     if( iDelayState == EDelayedCreateTabs )
       
   189         {
       
   190         iPaneHandler->CreateTabsL();  
       
   191         iDelayedConstructor->Start( TCallBack( ConstructDelayedCallbackL, this) );
       
   192         iDelayState=EDelayedCheckVisibilities;
       
   193         }
       
   194     else if( iDelayState == EDelayedCheckVisibilities )
       
   195         {
       
   196         CheckOtherPluginVisibilitiesL();
       
   197         iDelayedConstructor->Start( TCallBack( ConstructDelayedCallbackL, this) );
       
   198         }
       
   199     else if( iDelayState == EDelayedCheckVisibilitiesOk )
       
   200         {
       
   201         TInt tabNbr = 0;
       
   202         CCCAppPluginData* currPluginData = iPluginLoader->PluginInFocus();    
       
   203         if( currPluginData )
       
   204             {
       
   205             TUid currentlyVisiblePluginId = currPluginData->Plugin().Id();
       
   206             iPluginLoader->PluginVisibility( currentlyVisiblePluginId, tabNbr );
       
   207             }
       
   208         
       
   209         iPaneHandler->ActivateTab( tabNbr );
       
   210         iDelayedConstructor->Start( TCallBack( ConstructDelayedCallbackL, this) );
       
   211         iDelayState=EDelayedFinish;
       
   212         }    
       
   213     else
       
   214         {
       
   215         delete iDelayedConstructor;
       
   216         iDelayedConstructor = NULL;
       
   217         iDelayedStarting = EFalse;        
       
   218         SynchPluginVisibilityWithTabAfterDelayedStartL();
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CCCAppView::CheckOtherPluginVisibilitiesL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CCCAppView::CheckOtherPluginVisibilitiesL()
       
   227     {
       
   228     TBool pluginVisibility(EFalse);
       
   229     
       
   230     if(iDelayedPluginVisibilityCheck < iPluginLoader->PluginsCount())
       
   231         {
       
   232         // prepare plugin parameter 
       
   233         CCCAppPluginParameter* pluginParam = CCCAppPluginParameter::NewL( *this );
       
   234         CleanupStack::PushL( pluginParam );
       
   235         TRAPD(err, pluginVisibility = iPluginLoader->
       
   236             PluginAt(iDelayedPluginVisibilityCheck)->Plugin().CheckVisibilityL(*pluginParam));
       
   237         CleanupStack::PopAndDestroy( pluginParam );
       
   238         if (KErrNone == err)
       
   239             {
       
   240             if(iPluginLoader->SetPluginVisibility(iPluginLoader->
       
   241                 PluginAt(iDelayedPluginVisibilityCheck)->Plugin().Id(), pluginVisibility))
       
   242                 {
       
   243                 iDelayedVisibilityChanged = ETrue;
       
   244                 }
       
   245             }
       
   246         else
       
   247             {
       
   248             CCA_DP( KCCAppLogFile, CCA_L( 
       
   249                 "CCCAppStatusPaneHandler::CreateTabsL: Plugin %d visibility check failed."), 
       
   250                 iDelayedPluginVisibilityCheck);
       
   251             //Remove plugin from plugin loader
       
   252             TUid pluginUid = iPluginLoader->PluginAt(iDelayedPluginVisibilityCheck)->Plugin().Id();
       
   253             CCA_DP( KCCAppLogFile, CCA_L("::visibility check - problem plugin uid: %d"), pluginUid.iUid );
       
   254             iPluginLoader->RemovePlugin( pluginUid );
       
   255             iDelayedVisibilityChanged = ETrue;
       
   256             }        
       
   257         }
       
   258     else 
       
   259         {
       
   260         //All checked. Reset if changes requested by plugins
       
   261         if(iDelayedVisibilityChanged) 
       
   262             {
       
   263             iPaneHandler->CreateTabsL();
       
   264             }
       
   265         iDelayState=EDelayedCheckVisibilitiesOk;
       
   266         }
       
   267     iDelayedPluginVisibilityCheck++;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CCCAppView::StartPluginL
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 void CCCAppView::StartPluginL(TInt aPluginToFocus)
       
   275     {
       
   276     /* 
       
   277      * Activating plugin is done in two TRAP-levels. The lower is activating
       
   278      * the plugin and if it fails, takes care of recovering from the
       
   279      * situation. The higher level takes care of exiting the application
       
   280      * if something leaves while recovering from the plugin activation.
       
   281      */
       
   282     CCCAppPluginData* pluginDataInFocus = iPluginLoader->PluginInFocus();  
       
   283     User::LeaveIfNull(pluginDataInFocus);
       
   284     
       
   285     TRAPD( err, ActivatePluginL( *pluginDataInFocus ));
       
   286     if ( KErrNone == err )
       
   287         {// view started successfully - activate correct tab
       
   288         // activate 1st view plugin in case preferred plugin uid not found
       
   289         iPaneHandler->ActivateTab( KErrNotFound != aPluginToFocus ? aPluginToFocus : 0  );
       
   290         }
       
   291     else
       
   292         {// problem in plugin activation - try to recover
       
   293         CCA_DP( KCCAppLogFile, CCA_L("::StartViewL - problem in plugin activation: err %d"), err );
       
   294         RecoverFromBadPluginL();            
       
   295         }
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // CCCAppView::ChangeView
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 TInt CCCAppView::ChangeView( TBool aForward )
       
   303     {
       
   304     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::ChangeView"));
       
   305     
       
   306     TInt err = KErrNone;
       
   307     
       
   308     //Forward the call to statusPane only if it is ready
       
   309     if ( iPaneHandler )
       
   310         {
       
   311         if ( iPaneHandler->IsTabAvailable() )
       
   312             {
       
   313             TRAP( err, ChangeViewL( aForward ));
       
   314             CCA_DP( KCCAppLogFile, CCA_L("::ChangeView - ChangeViewL returned err: %d"), err );
       
   315             }
       
   316         }   
       
   317     
       
   318     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ChangeView"));
       
   319     return err;
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CCCAppView::ChangeViewL
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 void CCCAppView::ChangeViewL( TBool aForward )
       
   327     {
       
   328     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::ChangeViewL"));
       
   329 
       
   330     const TInt visiblePluginCount = iPluginLoader->VisiblePluginCount();  
       
   331     if ( KCCAppMinPluginCountForTabs > visiblePluginCount // if only 1 plugin, we can stop handling here
       
   332         || iViewChangeInProgress ) // OR view change is in progress
       
   333         return;    
       
   334 
       
   335     __ASSERT_DEBUG ( iPaneHandler->TabCount() == visiblePluginCount, CCAppPanic( ECCAppPanicObjectCountMismatch ));
       
   336     
       
   337     iViewChangeInProgress = ETrue;    
       
   338     
       
   339     /* 
       
   340      * If ActivateTabL changes tab succesfully, it will call TabChangedL,
       
   341      * which then again will do activation the plugin.
       
   342      *  
       
   343      * Activating plugin is done in two TRAP-levels. The lower is activating
       
   344      * the plugin and if it fails, takes care of recovering from the
       
   345      * situation. The higher level takes care of exiting the application
       
   346      * if something leaves while recovering from the plugin activation.
       
   347      */
       
   348     TRAPD( err, iPaneHandler->ActivateTabL( aForward ));
       
   349     if ( KErrNone != err)
       
   350         {
       
   351         CCA_DP( KCCAppLogFile, CCA_L("::ChangeViewL - problem in plugin activation: err %d"), err );
       
   352         RecoverFromBadPluginL();            
       
   353         }
       
   354     
       
   355     iViewChangeInProgress = EFalse;    
       
   356 
       
   357     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ChangeViewL"));
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CCCAppView::TabChangedL
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CCCAppView::TabChangedL( TInt aIndex )
       
   365     {
       
   366     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::TabChangedL"));
       
   367     
       
   368     CCCAppPluginData* pluginDataInFocus = iPluginLoader->VisiblePlugin( aIndex, ETrue );// not owned
       
   369     ActivatePluginL( *pluginDataInFocus );
       
   370     
       
   371     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::TabChangedL"));
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CCCAppView::ActivatePluginL
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 void CCCAppView::ActivatePluginL( CCCAppPluginData& aPluginDataInFocus )
       
   379     {
       
   380     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::ActivatePluginL"));
       
   381 
       
   382     //PERFORMANCE LOGGING: 6. Plugin activation
       
   383     WriteToPerfLog();
       
   384         
       
   385     CCCAppViewPluginBase& plugin = aPluginDataInFocus.Plugin();
       
   386     
       
   387     if ( !aPluginDataInFocus.IsPluginPrepared() )
       
   388         {// 1st activation
       
   389         // prepare plugin parameter
       
   390         CCCAppPluginParameter* pluginParam = CCCAppPluginParameter::NewL( *this );
       
   391         CleanupStack::PushL( pluginParam );
       
   392         plugin.PreparePluginViewL( *pluginParam );
       
   393         CleanupStack::PopAndDestroy( pluginParam );
       
   394         iAppUi.AddViewL( &plugin );// transfers ownership to AppUi -framework
       
   395         aPluginDataInFocus.PluginIsPrepared();
       
   396         }
       
   397 
       
   398     // activate plugin
       
   399     iAppUi.ActivateLocalViewL( plugin.Id() );
       
   400 
       
   401     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ActivatePluginL"));
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CCCAppView::AppUi
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 CCCAAppAppUi& CCCAppView::AppUi()
       
   409     {
       
   410     CCA_DP( KCCAppLogFile, CCA_L("CCCAppView::AppUi"));
       
   411     return iAppUi;
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // CCCAppView::EikonEnv
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 CEikonEnv& CCCAppView::EikonEnv()
       
   419     {
       
   420     CCA_DP( KCCAppLogFile, CCA_L("CCCAppView::AlfEnv"));
       
   421     return iAppUi.EikonEnv();
       
   422     }
       
   423     
       
   424 // ---------------------------------------------------------------------------
       
   425 // CCCAppView::PluginLoader
       
   426 // ---------------------------------------------------------------------------
       
   427 //    
       
   428 CCCAppPluginLoader& CCCAppView::PluginLoader()
       
   429     {
       
   430     CCA_DP( KCCAppLogFile, CCA_L("CCCAppView::PluginLoader"));
       
   431     return *iPluginLoader;
       
   432     }
       
   433     
       
   434 // ---------------------------------------------------------------------------
       
   435 // CCCAppView::ContactFieldDataObserverNotifyL
       
   436 // ---------------------------------------------------------------------------
       
   437 //  
       
   438 void CCCAppView::ContactFieldDataObserverNotifyL( 
       
   439         MCCAppContactFieldDataObserver::TParameter& aParameter )
       
   440     {
       
   441     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::ContactFieldDataObserverNotifyL"));
       
   442 
       
   443     // not interested about other notifications
       
   444     if ( MCCAppContactFieldDataObserver::TParameter::EContactDataFieldAvailable 
       
   445         == aParameter.iType && NULL != aParameter.iContactField )
       
   446         {
       
   447         ContactFieldFetchedNotifyL( *aParameter.iContactField );
       
   448         }
       
   449     else if ( MCCAppContactFieldDataObserver::TParameter::EContactDeleted 
       
   450             == aParameter.iType )
       
   451         {
       
   452         // Quick fix for the urgent need
       
   453         //
       
   454         // To fix this such manner that CCApplication works as normal Avkon
       
   455         // applications do, let the leave with leave code KLeaveExit 
       
   456         // go up to CActive's RunL and return it also through RunError.
       
   457         // Then normal Avkon AppUi functionality AppUi().Exit() will work.
       
   458         AppUi().RunAppShutter();
       
   459         }
       
   460     
       
   461     
       
   462 
       
   463     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ContactFieldDataObserverNotifyL"));
       
   464     }
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // CCCAppView::ContactFieldDataObserverHandleErrorL
       
   468 // ---------------------------------------------------------------------------
       
   469 //  
       
   470 void CCCAppView::ContactFieldDataObserverHandleErrorL( 
       
   471     TInt aState, TInt aError )
       
   472     {
       
   473     CCA_DP( KCCAppLogFile, CCA_L("CCCAppView::ContactFieldDataObserverHandleErrorL"));
       
   474     CCA_DP( KCCAppLogFile, CCA_L("::ContactFieldDataObserverHandleErrorL - aState: %d, aError: %d"), aState, aError );
       
   475     //todo; what kind of behaviour is wanted in error case?
       
   476     // - exit the app if no cms connection/contact is not found?
       
   477     }
       
   478 
       
   479 // ---------------------------------------------------------------------------
       
   480 // CCCAppView::ContactFieldFetchedNotifyL
       
   481 // ---------------------------------------------------------------------------
       
   482 //    
       
   483 void CCCAppView::ContactFieldFetchedNotifyL( 
       
   484         CCmsContactField& aContactField )
       
   485     {
       
   486     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ContactFieldFetchedNotifyL"));
       
   487 
       
   488     if ( CCmsContactFieldItem::ECmsFullName == aContactField.Type() )
       
   489         {// update titlepane with the name
       
   490         CCA_DP( KCCAppLogFile, CCA_L("::ContactFieldFetchedNotifyL - changing title"));
       
   491         
       
   492         TPtrC newTxt = aContactField.ItemL( 0 ).Data();        
       
   493         iAppUi.SetTitleL( newTxt );          
       
   494         }    
       
   495 
       
   496     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ContactFieldFetchedNotifyL"));
       
   497     }
       
   498 
       
   499 // ---------------------------------------------------------------------------
       
   500 // CCCAppView::RecoverFromBadPluginL
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 void CCCAppView::RecoverFromBadPluginL()
       
   504     {
       
   505     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::RecoverFromBadPluginL"));
       
   506 
       
   507 #ifdef _DEBUG
       
   508     CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
       
   509     informationNote->ExecuteLD( _L("Problem in plugin! Check logs!"));         
       
   510 #endif
       
   511 
       
   512     //Remove plugin from plugin loader
       
   513     TUid pluginUid = iPluginLoader->PluginInFocus()->Plugin().Id();
       
   514     CCA_DP( KCCAppLogFile, CCA_L("::RecoverFromBadPluginL - problem plugin uid: %d"), pluginUid.iUid );
       
   515     iPluginLoader->RemovePlugin( pluginUid );
       
   516 
       
   517     if ( iPluginLoader->PluginsCount() )
       
   518         {// Plugins available
       
   519         CCA_DP( KCCAppLogFile, CCA_L("::RecoverFromBadPluginL - plugins found"));
       
   520         
       
   521         // Reset tabs
       
   522         delete iPaneHandler;
       
   523         iPaneHandler = NULL; 
       
   524         iPaneHandler = CCCAppStatusPaneHandler::NewL( *this );        
       
   525         iPaneHandler->CreateTabsL();
       
   526 
       
   527         // Needed to get the focus in most cases to 1st plugin in array
       
   528         delete iViewResetter;
       
   529         iViewResetter = NULL;
       
   530         iViewResetter = CIdle::NewL( CActive::EPriorityStandard );
       
   531         iViewResetter->Start( TCallBack( ResetViewL, this ));       
       
   532         }
       
   533     else
       
   534         {// no plugins left
       
   535         // (should basically never happen, since there should always be working internal plugins)
       
   536         User::Leave( KErrNotFound );
       
   537         }
       
   538     
       
   539     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::RecoverFromBadPluginL"));
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // CCCAppView::CurrentPluginBusy
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 TBool CCCAppView::CurrentPluginBusy()
       
   547     {
       
   548     TBool isBusy = EFalse;
       
   549     if(iPluginLoader)
       
   550         {
       
   551         CCCAppPluginData* pluginData = iPluginLoader->PluginInFocus(); //not owned
       
   552         if ( pluginData != NULL )
       
   553             {
       
   554             CCCAppViewPluginBase& plugin = pluginData->Plugin();
       
   555             MCCAppViewPluginBase2* pluginExtension =
       
   556                 reinterpret_cast<MCCAppViewPluginBase2*>(
       
   557                     plugin.CCCAppViewPluginBaseExtension( KMCCAppViewPluginBaseExtension2Uid ) );
       
   558             if ( pluginExtension != NULL )
       
   559                 {
       
   560                 isBusy = pluginExtension->PluginBusy();
       
   561                 }
       
   562             }
       
   563         }
       
   564 
       
   565     return isBusy;
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // CCCAppView::ResetViewL
       
   570 // ---------------------------------------------------------------------------
       
   571 //
       
   572 TInt CCCAppView::ResetViewL( TAny* aSelf )
       
   573     {
       
   574     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppView::ResetViewL"));
       
   575     
       
   576     CCCAppView* view = static_cast<CCCAppView*>(aSelf);//not owned
       
   577     
       
   578     // Change focus and activate 1st plugin in array
       
   579     CCCAppPluginData* pluginDataInFocus =
       
   580         view->iPluginLoader->PluginAt( 0, ETrue );
       
   581     view->ActivatePluginL( *pluginDataInFocus );
       
   582     view->iPaneHandler->ActivateTab( 0 );
       
   583 
       
   584     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppView::ResetViewL"));
       
   585     return KErrNone;
       
   586     }
       
   587 // ---------------------------------------------------------------------------
       
   588 // CCCAppView::ContactRelocationL
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 void CCCAppView::CCAppContactEventL()
       
   592     {    
       
   593     TInt count = iObservers.Count();
       
   594     for (TInt i = 0; i < count; i++)
       
   595         {
       
   596         // Inform observers of contact event
       
   597         TRAP_IGNORE(iObservers[i]->NotifyPluginOfContactEventL());
       
   598         }
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------------------------
       
   602 // CCCAppView::AddObserverL
       
   603 // ---------------------------------------------------------------------------
       
   604 //
       
   605 void CCCAppView::AddObserverL( MCCAppPluginsContactObserver& aObserver )
       
   606     {
       
   607     TInt index = iObservers.Find(&aObserver);
       
   608     if (index == KErrNotFound)
       
   609         {
       
   610         iObservers.AppendL(&aObserver);
       
   611         }
       
   612     }
       
   613 
       
   614 // ---------------------------------------------------------------------------
       
   615 // CCCAppView::RemoveObserver
       
   616 // ---------------------------------------------------------------------------
       
   617 //
       
   618 void CCCAppView::RemoveObserver( MCCAppPluginsContactObserver& aObserver )
       
   619     {
       
   620     TInt index = iObservers.Find(&aObserver);
       
   621     if (index != KErrNotFound)
       
   622         {
       
   623         iObservers.Remove(index);
       
   624         }
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 // CCCAppView::Parameter
       
   629 // ---------------------------------------------------------------------------
       
   630 //
       
   631 MCCAParameter& CCCAppView::Parameter()
       
   632     {
       
   633     return iAppUi.Parameter();
       
   634     }
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // CCCAppView::ShowPluginL
       
   638 // ---------------------------------------------------------------------------
       
   639 //  
       
   640 void CCCAppView::ShowPluginL( TUid aUid )
       
   641     {
       
   642     if(iDelayedStarting)
       
   643         {        
       
   644         iPluginLoader->SetPluginVisibility(aUid, CCCAppPluginData::EPluginVisible);
       
   645         iPluginUidToBeSynchd.Append(aUid);
       
   646         }
       
   647     else
       
   648         {                
       
   649         PerformShowPluginL( aUid ); 
       
   650         }
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // CCCAppView::PerformShowPluginL
       
   655 // ---------------------------------------------------------------------------
       
   656 //  
       
   657 void CCCAppView::PerformShowPluginL( TUid aUid )
       
   658     {
       
   659     TInt currentTab(KErrNotFound);    
       
   660     CCCAppPluginData* pluginData = iPluginLoader->PluginInFocus( );
       
   661     iPluginLoader->SetPluginVisibility(aUid, CCCAppPluginData::EPluginVisible);
       
   662     iPaneHandler->CreateTabsL();    
       
   663     
       
   664     if( pluginData )
       
   665         {
       
   666         iPluginLoader->PluginVisibility( pluginData->Plugin().Id(), currentTab );
       
   667         iPaneHandler->ActivateTab( currentTab ); 
       
   668         }
       
   669     else
       
   670         {
       
   671         iPaneHandler->ActivateTab( 0 );
       
   672         }
       
   673     }
       
   674 
       
   675 // ---------------------------------------------------------------------------
       
   676 // CCCAppView::HidePluginL
       
   677 // ---------------------------------------------------------------------------
       
   678 //  
       
   679 void CCCAppView::HidePluginL( TUid aUid )
       
   680     {
       
   681     if(iDelayedStarting)
       
   682         {        
       
   683         iPluginLoader->SetPluginVisibility(aUid, CCCAppPluginData::EPluginHidden);
       
   684         iPluginUidToBeSynchd.Append(aUid);
       
   685         }
       
   686     else
       
   687         {        
       
   688         PerformHidePluginL( aUid ); 
       
   689         }
       
   690     }
       
   691 
       
   692 // ---------------------------------------------------------------------------
       
   693 // CCCAppView::PerformHidePluginL
       
   694 // ---------------------------------------------------------------------------
       
   695 //  
       
   696 void CCCAppView::PerformHidePluginL( TUid aUid )
       
   697     {
       
   698     TInt newTab(KErrNotFound);    
       
   699 
       
   700     //Currently visible plugin
       
   701     TInt currentTab(KErrNotFound);
       
   702     CCCAppPluginData* currPluginData = iPluginLoader->PluginInFocus( );
       
   703     iPluginLoader->PluginVisibility( currPluginData->Plugin().Id(), currentTab );    
       
   704 
       
   705     //Hide plugin aUid
       
   706     iPluginLoader->SetPluginVisibility(aUid, CCCAppPluginData::EPluginHidden);
       
   707     iPaneHandler->CreateTabsL();  
       
   708     
       
   709     //Set new visible plugin
       
   710     if( currPluginData )
       
   711         {
       
   712         if(currPluginData->Plugin().Id() == aUid)
       
   713             {
       
   714             //Current will be hidden, bring previous or next to foreground 
       
   715             if( CCCAppPluginData* previousPlugin = iPluginLoader->PreviousPlugin( ETrue )) 
       
   716                 {
       
   717                 ActivatePluginL( *previousPlugin );
       
   718                 iPluginLoader->PluginVisibility( previousPlugin->Plugin().Id(), newTab );
       
   719                 iPaneHandler->ActivateTab( newTab );
       
   720                 return;
       
   721                 }
       
   722             else if( CCCAppPluginData* nextPlugin = iPluginLoader->NextPlugin( ETrue ))
       
   723                 {
       
   724                 ActivatePluginL( *nextPlugin );
       
   725                 iPluginLoader->PluginVisibility( nextPlugin->Plugin().Id(), newTab );
       
   726                 iPaneHandler->ActivateTab( newTab );
       
   727                 return;                
       
   728                 }
       
   729             else
       
   730                 {
       
   731                 //Nothing to activate properly
       
   732                 ResetViewL( this );                
       
   733                 return;                
       
   734                 }
       
   735             }
       
   736         else
       
   737             {
       
   738             //Retain current plugin in foreground            
       
   739             iPluginLoader->PluginVisibility( currPluginData->Plugin().Id(), newTab );
       
   740             iPaneHandler->ActivateTab( newTab );
       
   741             return;            
       
   742             }
       
   743         }
       
   744         //Nothing to activate properly
       
   745         ResetViewL( this ); 
       
   746         return;
       
   747     }
       
   748 
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // CCCAppView::SynchPluginVisibilityWithTabAfterDelayedStartL
       
   752 // ---------------------------------------------------------------------------
       
   753 // 
       
   754 void CCCAppView::SynchPluginVisibilityWithTabAfterDelayedStartL()
       
   755     {
       
   756     CCCAppPluginData* currPluginData = iPluginLoader->PluginInFocus();    
       
   757     TBool syncDone = EFalse;   
       
   758     TInt pluginsRequireSynch = iPluginUidToBeSynchd.Count();
       
   759     if( currPluginData && pluginsRequireSynch )
       
   760         {
       
   761         TUid currentlyVisiblePluginId = currPluginData->Plugin().Id();
       
   762         
       
   763         for ( TInt index=0; index<pluginsRequireSynch; index++ )
       
   764             {        
       
   765             if ( currentlyVisiblePluginId == iPluginUidToBeSynchd[index] )
       
   766                 {
       
   767                 //is there any change in the visibility of the current visible plugin 
       
   768                 //the only option could be is that it can become invisible
       
   769                 //only on the above case we willbe interested
       
   770                 TInt tabNbr = 0;
       
   771                 if ( !iPluginLoader->PluginVisibility( currentlyVisiblePluginId, tabNbr ) )
       
   772                     {
       
   773                     //This plugin is no more visible so its better to call just HidePluginL()
       
   774                     syncDone = ETrue;
       
   775                     HidePluginL( currentlyVisiblePluginId );                
       
   776                     }
       
   777                 break;
       
   778                 }
       
   779             }
       
   780         
       
   781         if ( !syncDone )
       
   782             {
       
   783             //Still synchronisation has not been done
       
   784             //Possible reason could be is that, this plugin is not the currently visible one
       
   785             //so now it becomes much more easy, so just go ahead and call CreateTabsL
       
   786             //only the tab will be reset and the current active plugin will stay active
       
   787             TInt tabNbr = 0;
       
   788             iPaneHandler->CreateTabsL();  
       
   789             //Current the repositioned active tab & activate the same
       
   790             iPluginLoader->PluginVisibility( currentlyVisiblePluginId, tabNbr );        
       
   791             iPaneHandler->ActivateTab( tabNbr );
       
   792             }    
       
   793         }
       
   794     }
       
   795 
       
   796 //  End of File