startupservices/Startup/src/startupanimationwrapper.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007,2008 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:  Implementation of CStartupAnimationWrapper class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <apgtask.h>
       
    20 #include <e32debug.h>
       
    21 #include <e32property.h>
       
    22 #include <startupdomainpskeys.h>
       
    23 
       
    24 #include "startupanimationwrapper.h"
       
    25 #include "startup.hrh"
       
    26 #include "StartupDefines.h"
       
    27 #include "startupview.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CStartupAnimationWrapper::NewL
       
    33 //
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CStartupAnimationWrapper* CStartupAnimationWrapper::NewL( CStartupView& aView )
       
    37     {
       
    38     TRACES("CStartupAnimationWrapper::NewL()");
       
    39 
       
    40     CStartupAnimationWrapper* self =
       
    41         new( ELeave ) CStartupAnimationWrapper( aView );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45 
       
    46     TRACES("CStartupAnimationWrapper::NewL(): End");
       
    47     return self;
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CStartupAnimationWrapper::~CStartupAnimationWrapper
       
    53 //
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CStartupAnimationWrapper::~CStartupAnimationWrapper()
       
    57     {
       
    58     TRACES("CStartupAnimationWrapper::~CStartupAnimationWrapper()");
       
    59 
       
    60     Cancel();
       
    61     if ( iCallBackCaller )
       
    62         {
       
    63         iCallBackCaller->Cancel();
       
    64         }
       
    65     delete iCallBackCaller;
       
    66     delete iCtrl;
       
    67 
       
    68     TRACES("CStartupAnimationWrapper::~CStartupAnimationWrapper(): end");
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CStartupAnimationWrapper::PreLoad
       
    74 //
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CStartupAnimationWrapper::PreLoad(
       
    78     const TRect& aRect,
       
    79     const CCoeControl& aContainer,
       
    80     const CSAnimStartupCtrl::TAnimationParams& aParams,
       
    81     const TBool aPlayDefaultBeep,
       
    82     const TInt aSyncCommand )
       
    83     {
       
    84     TRACES1("CStartupAnimationWrapper::PreLoad(), iState = %d", iState);
       
    85 
       
    86     if ( iState == EIdle ) // This component will not be re-used if first animation is cancelled
       
    87         {
       
    88         TRAPD( errorCode,
       
    89             LoadL( aRect, aContainer, aParams, aPlayDefaultBeep, aSyncCommand ) );
       
    90         if ( errorCode != KErrNone )
       
    91             {
       
    92             TRACES1("CStartupAnimationWrapper::LoadL() leave code = %d", errorCode);
       
    93 
       
    94             DestroyCtrl();
       
    95             }
       
    96         }
       
    97 
       
    98     TRACES("CStartupAnimationWrapper::PreLoad(): End");
       
    99     }
       
   100 
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CStartupAnimationWrapper::Play
       
   104 //
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CStartupAnimationWrapper::Play(
       
   108     const TRect& aRect,
       
   109     const CCoeControl& aContainer,
       
   110     const CSAnimStartupCtrl::TAnimationParams& aParams,
       
   111     const TBool aPlayDefaultBeep,
       
   112     const TInt aSyncCommand,
       
   113     const TCallBack& aCallBack )
       
   114     {
       
   115     TRACES("CStartupAnimationWrapper::Play()");
       
   116 
       
   117     iCallBackCaller->Set( aCallBack );
       
   118 
       
   119     if ( iState == ELoading )
       
   120         {
       
   121         iPlayImmediately = ETrue;
       
   122         }
       
   123     else if ( iState == EReady )
       
   124         {
       
   125         StartPlaying();
       
   126         }
       
   127     else if ( iState == EIdle )
       
   128         {
       
   129         iPlayImmediately = ETrue;
       
   130 
       
   131         TRAPD( errorCode,
       
   132             LoadL( aRect, aContainer, aParams, aPlayDefaultBeep, aSyncCommand ) );
       
   133         if ( errorCode != KErrNone )
       
   134             {
       
   135             TRACES1("CStartupAnimationWrapper::LoadL() leave code = %d", errorCode);
       
   136 
       
   137             DestroyCtrl();
       
   138             iCallBackCaller->CallBack();
       
   139             }
       
   140         }
       
   141 
       
   142     TRACES("CStartupAnimationWrapper::Play(): End");
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CStartupAnimationWrapper::WasCancelled
       
   148 //
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TBool CStartupAnimationWrapper::WasCancelled() const
       
   152     {
       
   153     return ( iState == ECancelled );
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CStartupAnimationWrapper::DoCancel
       
   159 //
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CStartupAnimationWrapper::DoCancel()
       
   163     {
       
   164     TRACES("CStartupAnimationWrapper::DoCancel()");
       
   165 
       
   166     iState = ECancelled;
       
   167     DestroyCtrl();
       
   168     iCallBackCaller->CallBack();
       
   169 
       
   170     TRACES("CStartupAnimationWrapper::DoCancel(): End");
       
   171     }
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CStartupAnimationWrapper::RunL
       
   176 //
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CStartupAnimationWrapper::RunL()
       
   180     {
       
   181     TRACES1("CStartupAnimationWrapper::RunL(): iStatus = %d", iStatus.Int());
       
   182 
       
   183     if ( iState == ELoading && iStatus.Int() == KErrNone )
       
   184         {
       
   185         iState = EReady;
       
   186 
       
   187         if ( iPlayImmediately )
       
   188             {
       
   189             StartPlaying();
       
   190             }
       
   191         }
       
   192     else
       
   193         {
       
   194         iState = ( iStatus.Int() == KErrCancel ? ECancelled : EIdle );
       
   195         DestroyCtrl();
       
   196         iCallBackCaller->CallBack();
       
   197         }
       
   198 
       
   199     TRACES("CStartupAnimationWrapper::RunL(): End");
       
   200     }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CStartupAnimationWrapper::CStartupAnimationWrapper
       
   205 //
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 CStartupAnimationWrapper::CStartupAnimationWrapper( CStartupView& aView )
       
   209   : CActive( EPriorityStandard ),
       
   210     iView( aView ),
       
   211     iState( EIdle ),
       
   212     iHasContent( EFalse )
       
   213     {
       
   214     TRACES("CStartupAnimationWrapper::CStartupAnimationWrapper()");
       
   215 
       
   216     CActiveScheduler::Add( this );
       
   217 
       
   218     TRACES("CStartupAnimationWrapper::CStartupAnimationWrapper(): End");
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CStartupAnimationWrapper::ConstructL
       
   224 //
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CStartupAnimationWrapper::ConstructL()
       
   228     {
       
   229     TRACES("CStartupAnimationWrapper::ConstructL()");
       
   230     TRACES("CStartupAnimationWrapper::ConstructL(): End");
       
   231 
       
   232     iCallBackCaller = new ( ELeave ) CAsyncCallBack( EPriorityStandard );
       
   233     }
       
   234 
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CStartupAnimationWrapper::LoadL
       
   238 //
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CStartupAnimationWrapper::LoadL(
       
   242     const TRect& /*aRect*/,
       
   243     const CCoeControl& aContainer,
       
   244     const CSAnimStartupCtrl::TAnimationParams& aParams,
       
   245     const TBool aPlayDefaultBeep,
       
   246     const TInt aSyncCommand )
       
   247     {
       
   248     TRACES("CStartupAnimationWrapper::LoadL()");
       
   249     __ASSERT_DEBUG( !iCtrl, PANIC( EStartupPanicClassMemberVariableIsNotNull ) );
       
   250     __ASSERT_DEBUG( iState == EIdle, PANIC( EStartupInvalidInternalState ) );
       
   251 
       
   252     iCtrl = CSAnimStartupCtrl::NewL( iView.Rect(), aContainer );
       
   253     iView.SetComponent( *iCtrl );
       
   254     iState = ELoading;
       
   255     iCtrl->Load( aParams, aPlayDefaultBeep, aSyncCommand, iStatus );
       
   256     iHasContent = iCtrl->HasContent();
       
   257     SetActive();
       
   258 
       
   259     TRACES("CStartupAnimationWrapper::LoadL(): End");
       
   260     }
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CStartupAnimationWrapper::StartPlaying
       
   265 //
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CStartupAnimationWrapper::StartPlaying()
       
   269     {
       
   270     TRACES("CStartupAnimationWrapper::StartPlaying()");
       
   271 
       
   272     iState = EPlaying;
       
   273     RProperty::Set( KPSUidStartup, KPSSplashShutdown, ESplashShutdown );
       
   274 
       
   275     BringToForeground();
       
   276 
       
   277     iCtrl->Start( iStatus );
       
   278     SetActive();
       
   279 
       
   280     TRACES("CStartupAnimationWrapper::StartPlaying(): End");
       
   281     }
       
   282 
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CStartupAnimationWrapper::DestroyCtrl
       
   286 //
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CStartupAnimationWrapper::DestroyCtrl()
       
   290     {
       
   291     TRACES("CStartupAnimationWrapper::DestroyCtrl()");
       
   292 
       
   293     if ( iCtrl )
       
   294         {
       
   295         iCtrl->Cancel();
       
   296         iView.RemoveComponent();
       
   297         delete iCtrl;
       
   298         iCtrl = NULL;
       
   299         }
       
   300 
       
   301     TRACES("CStartupAnimationWrapper::DestroyCtrl(): End");
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CStartupAnimationWrapper::HasContent
       
   306 //
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 TBool CStartupAnimationWrapper::HasContent() const
       
   310     {
       
   311     return iHasContent;
       
   312     }
       
   313 
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CStartupAnimationWrapper::BringToForeground
       
   317 //
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CStartupAnimationWrapper::BringToForeground()
       
   321     {
       
   322     TRACES("CStartupAnimationWrapper::BringToForeground()");
       
   323 
       
   324     TApaTask self( CCoeEnv::Static()->WsSession() );
       
   325     self.SetWgId( CCoeEnv::Static()->RootWin().Identifier() );
       
   326     self.BringToForeground();
       
   327 
       
   328     TRACES("CStartupAnimationWrapper::BringToForeground(): End");
       
   329     }