gssettingsuis/Gs/GSFramework/src/GSShimmedView.cpp
branchRCL_3
changeset 54 7e0eff37aedb
parent 0 8c5d936e5675
equal deleted inserted replaced
53:8ee96d21d9bf 54:7e0eff37aedb
       
     1 /*
       
     2 * Copyright (c) 2006-1008 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:  Shim view
       
    15 *
       
    16 */
       
    17 
       
    18 #include "GSShimmedView.h"
       
    19 
       
    20 // System includes
       
    21 #include <eikenv.h>
       
    22 #include <aknViewAppUi.h>
       
    23 
       
    24 // User includes
       
    25 #include "GSPluginAndViewIdCache.h"
       
    26 #include <gsfwviewuids.h>
       
    27 #include <gspluginloader.h>
       
    28 #include <gsplugininterface.h>
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // CGSShimmedView::CGSShimmedView
       
    34 //
       
    35 //
       
    36 // ----------------------------------------------------------------------------
       
    37 //
       
    38 CGSShimmedView::CGSShimmedView( TUid aViewId, 
       
    39                                 CGSPluginAndViewIdCache& aCache, 
       
    40                                 CCoeAppUi& aAppUi )
       
    41 :   CActive( KMaxTInt ), iViewId( aViewId ), iCache( aCache ), iAppUi( aAppUi )
       
    42     {
       
    43     }
       
    44 
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // CGSShimmedView::~CGSShimmedView
       
    48 //
       
    49 //
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 CGSShimmedView::~CGSShimmedView()
       
    53     {
       
    54     Cancel();
       
    55     DeregisterView();
       
    56     iCache.HandleShimDestruction( iViewId );
       
    57     delete iCustomMessage;
       
    58     }
       
    59 
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CGSShimmedView::ConstructL
       
    63 //
       
    64 //
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 void CGSShimmedView::ConstructL()
       
    68     {
       
    69     RegisterViewL();
       
    70     }
       
    71 
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CGSShimmedView::NewLC
       
    75 //
       
    76 //
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 CGSShimmedView* CGSShimmedView::NewLC( TUid aViewId, 
       
    80                                        CGSPluginAndViewIdCache& aCache, 
       
    81                                        CCoeAppUi& aAppUi )
       
    82     {
       
    83     CGSShimmedView* self = new(ELeave) CGSShimmedView( aViewId, aCache, aAppUi );
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     return self;
       
    87     }
       
    88 
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // CGSShimmedView::ViewId
       
    92 //
       
    93 //
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 TVwsViewId CGSShimmedView::ViewId() const
       
    97     {
       
    98     const TVwsViewId ret( KUidGS, iViewId );
       
    99     return ret;
       
   100     }
       
   101 
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CGSShimmedView::ViewActivatedL
       
   105 //
       
   106 //
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 void CGSShimmedView::ViewActivatedL( const TVwsViewId& aPrevViewId, 
       
   110                                      TUid aCustomMessageId, 
       
   111                                      const TDesC8& aCustomMessage )
       
   112     {
       
   113     const TBool isLoaded = iCache.IsPluginLoaded( iViewId );
       
   114     if  ( isLoaded == EFalse )
       
   115         {
       
   116         HBufC8* customMessage = aCustomMessage.AllocL();
       
   117         delete iCustomMessage;
       
   118         iCustomMessage = customMessage;
       
   119 
       
   120         iCustomMessageId = aCustomMessageId;
       
   121 
       
   122         iCache.SetPriorToPlaceholderActiveViewId( aPrevViewId );
       
   123         SetState( EStateActivatingPlaceholderView );
       
   124         }
       
   125     }
       
   126 
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // CGSShimmedView::ViewDeactivated
       
   130 //
       
   131 //
       
   132 // ----------------------------------------------------------------------------
       
   133 //
       
   134 void CGSShimmedView::ViewDeactivated()
       
   135     {
       
   136     }
       
   137 
       
   138 
       
   139 // ----------------------------------------------------------------------------
       
   140 // CGSShimmedView::RunL
       
   141 //
       
   142 //
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 void CGSShimmedView::RunL()
       
   146     {
       
   147     // NB: At this point, we are the active view.
       
   148 
       
   149     switch( iState )
       
   150         {
       
   151     default:
       
   152     case EStateInactive:
       
   153         break;
       
   154 
       
   155     case EStateActivatingPlaceholderView:
       
   156         StateActivatePlaceholderViewL();
       
   157         break;
       
   158 
       
   159     case EStateLoadingPlugin:
       
   160         StateLoadPluginL();
       
   161         break;
       
   162 
       
   163     case EStateDeletingSelf:
       
   164         SetState( EStateInactive, EFalse );
       
   165         delete this;
       
   166         break;
       
   167         }
       
   168     }
       
   169 
       
   170 
       
   171 // ----------------------------------------------------------------------------
       
   172 // CGSShimmedView::RegisterViewL
       
   173 //
       
   174 //
       
   175 // ----------------------------------------------------------------------------
       
   176 //
       
   177 void CGSShimmedView::RegisterViewL()
       
   178     {
       
   179     iAppUi.RegisterViewL( *this );
       
   180     iIsRegistered = ETrue;
       
   181     }
       
   182 
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CGSShimmedView::DeregisterView
       
   186 //
       
   187 //
       
   188 // ----------------------------------------------------------------------------
       
   189 //
       
   190 void CGSShimmedView::DeregisterView()
       
   191     {
       
   192     if  ( iIsRegistered )
       
   193         {
       
   194         iAppUi.DeregisterView( *this );
       
   195         }
       
   196     iIsRegistered = EFalse;
       
   197     }
       
   198 
       
   199 
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // CGSShimmedView::DoCancel
       
   203 //
       
   204 //
       
   205 // ----------------------------------------------------------------------------
       
   206 //
       
   207 void CGSShimmedView::DoCancel()
       
   208     {
       
   209     // Nothing to do here - requests already completed
       
   210     }
       
   211 
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CGSShimmedView::SetState
       
   215 //
       
   216 //
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 void CGSShimmedView::SetState( TState aState, TBool aCompleteRequest )
       
   220     {
       
   221     Cancel();
       
   222     //
       
   223     iState = aState;
       
   224     //
       
   225     if  ( aCompleteRequest )
       
   226         {
       
   227         if  ( !IsAdded() )
       
   228             {
       
   229             // Add only on-demand to avoid cluttering the scheduler
       
   230             CActiveScheduler::Add( this );
       
   231             }
       
   232 
       
   233         // Complete ourselves to continue activation process asynchronously
       
   234         // via RunL().
       
   235         TRequestStatus* status = &iStatus;
       
   236         User::RequestComplete( status, KErrNone );
       
   237         SetActive();
       
   238         }
       
   239     }
       
   240 
       
   241 
       
   242 // ----------------------------------------------------------------------------
       
   243 // CGSShimmedView::StateActivatePlaceholderViewL
       
   244 //
       
   245 //
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 void CGSShimmedView::StateActivatePlaceholderViewL()
       
   249     {
       
   250     iCache.ActivatePlaceholderViewL();
       
   251     SetState( EStateLoadingPlugin );
       
   252     }
       
   253 
       
   254 
       
   255 //Disabling warning caused by err variable used inside macros
       
   256 #pragma diag_suppress 550
       
   257 // ----------------------------------------------------------------------------
       
   258 // CGSShimmedView::StateLoadPluginL
       
   259 //
       
   260 //
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 void CGSShimmedView::StateLoadPluginL()
       
   264     {
       
   265     CAknViewAppUi& appUi = static_cast< CAknViewAppUi& >( iAppUi );
       
   266 
       
   267     // As a fall back, we'll try to activate the view that was being
       
   268     // displayed prior to us attempting to load a plugin.
       
   269     TUid viewIdToActivate = iCache.PriorToPlaceholderActiveViewId().iViewUid;
       
   270 
       
   271     // Get the implementation uid that contains this view.
       
   272     const TUid impUid = iCache.PluginImplementationUidForView( iViewId );
       
   273 
       
   274     if  ( impUid != KNullUid )
       
   275         {
       
   276         CGSPluginLoader* loader = CGSPluginLoader::NewL( &appUi );
       
   277         CleanupStack::PushL( loader );
       
   278 
       
   279         // Now try to load the specific instance of the GS plugin that
       
   280         // implements the real view's concrete implementation.
       
   281         //
       
   282         // Since the act of loading a plugin will also attempt to register
       
   283         // that plugin with the app ui (since a GS plugin "is a" view) we
       
   284         // must first unregister the shim view. If there was an error
       
   285         // loading the plugin, then we'll re-register the shim.
       
   286         DeregisterView();
       
   287        
       
   288         CGSPluginInterface* plugin = NULL;
       
   289         TRAPD( loadError, plugin = &loader->LoadSyncL( KGSPluginInterfaceUid, impUid ) );
       
   290         CleanupStack::PopAndDestroy( loader );
       
   291 
       
   292         if  ( loadError == KErrNone )
       
   293             {
       
   294             // .. and set us up to activate the newly loaded plugin view.
       
   295             viewIdToActivate = iViewId;
       
   296 
       
   297             // Set ourselves up to be destroyed in the next RunL callback
       
   298             SetState( EStateDeletingSelf );
       
   299             }
       
   300         else
       
   301             {
       
   302             // Didn't manage to load plugin. Re-register the view
       
   303             // and bail out.
       
   304             SetState( EStateInactive, EFalse );
       
   305             RegisterViewL();
       
   306             }
       
   307         }
       
   308 
       
   309     appUi.ActivateLocalViewL( viewIdToActivate, iCustomMessageId, *iCustomMessage );
       
   310     }
       
   311 //Enabling warnings
       
   312 #pragma diag_default 550
       
   313 
       
   314 
       
   315 
       
   316 
       
   317 
       
   318 //  End of File