svgtviewer/SvgtViewerPlugin/UIControlSrc/SvgtController.cpp
branchRCL_3
changeset 20 5fd161fa28b6
parent 0 632761c941a7
equal deleted inserted replaced
17:e52958d06c29 20:5fd161fa28b6
       
     1 /*
       
     2 * Copyright (c) 2005 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:  This file implements the active objects used for progressive 
       
    15 *                rendering 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "SvgtController.h"
       
    21 #include <eikenv.h>
       
    22 #include <aknnavi.h>
       
    23 #include <aknnavide.h>
       
    24 #include <eikspane.h>
       
    25 #include "SVGTCustControl.h"
       
    26 
       
    27 const TInt KAnimationInerval = 100000;
       
    28 
       
    29 _LIT(KDot, ". ");
       
    30 
       
    31 /*
       
    32 *************************************************************************************
       
    33 *   ThreadController Implemetation
       
    34 *
       
    35 ***************************************************************************************
       
    36 */
       
    37 // -----------------------------------------------------------------------------
       
    38 // CSvgtThreadController::NewL
       
    39 // Two phase constructor
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSvgtThreadController* CSvgtThreadController::NewL(CSVGTCustControl* aCustControl)
       
    43     {
       
    44     CSvgtThreadController* self = CSvgtThreadController::NewLC(aCustControl);
       
    45     CleanupStack::Pop(self);    //self
       
    46     return self;
       
    47     }
       
    48     
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSvgtThreadController::NewLC
       
    51 // Two phase constructor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CSvgtThreadController* CSvgtThreadController::NewLC(CSVGTCustControl* aCustControl)
       
    55     {
       
    56     CSvgtThreadController* self = new (ELeave) CSvgtThreadController(aCustControl);
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CSvgtThreadController::~CSvgtThreadController
       
    64 // Destructor
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CSvgtThreadController::~CSvgtThreadController()
       
    68     {
       
    69     Cancel();
       
    70     if(iLoadAnimator)
       
    71         {
       
    72         iLoadAnimator->Cancel();
       
    73         }
       
    74         
       
    75     delete iLoadAnimator;
       
    76     ClearNaviPaneDecorator();
       
    77     // Reset eikon env pointer
       
    78     iEikEnv = NULL;
       
    79     // Reset the custom control pointer
       
    80     iCustControl = NULL;
       
    81     }
       
    82     
       
    83 // -----------------------------------------------------------------------------
       
    84 // CSvgtThreadController::DoCancel
       
    85 // Cancels all the pending request
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CSvgtThreadController::DoCancel()
       
    89     {
       
    90     }
       
    91     
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSvgtThreadController::RunL
       
    94 // Handles an active object's request completion event.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CSvgtThreadController::RunL()
       
    98     {
       
    99     iCustControl->SetThreadRunning(EFalse);
       
   100     iLoadAnimator->Cancel();
       
   101     iCount = KAnimationLength;
       
   102     DoLoadAnimationL();
       
   103     TInt lLoadError = iCustControl->DoHandleLoadingThreadError();
       
   104     TInt lPostLoadError = KErrNone;
       
   105     
       
   106     // Stop displaying progressive-render indicator
       
   107     ClearNaviPaneDecorator();
       
   108     //iCustControl->StopEventHandler();
       
   109     if( lLoadError == KErrNone )
       
   110         {
       
   111         // No Load error, Do the post load functionality
       
   112         TRAP( lPostLoadError, iCustControl->DoPostLoadFuncL() );    
       
   113         }
       
   114     
       
   115     // If there were any errors then ask parent to exit
       
   116     if ( ( lLoadError!= KErrNone ) || ( lPostLoadError != KErrNone ) )
       
   117         {
       
   118         // Error has occurred, commence cleanup 
       
   119         // Request Observer to Exit
       
   120    	    iCustControl->DoExitFromDialogL();
       
   121         }
       
   122     }
       
   123     
       
   124 // -----------------------------------------------------------------------------
       
   125 // CSvgtThreadController::CSvgtThreadController
       
   126 // Parameterized constructor
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 CSvgtThreadController::CSvgtThreadController(CSVGTCustControl* aCustControl):
       
   130                                                 CActive(EPriorityStandard),
       
   131                                                 iCustControl(aCustControl)
       
   132     {
       
   133     CActiveScheduler::Add(this);
       
   134     }
       
   135     
       
   136 // -----------------------------------------------------------------------------
       
   137 // CSvgtThreadController::ConstructL
       
   138 // Two phase constructor
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CSvgtThreadController::ConstructL()
       
   142     {
       
   143     iLoadAnimator = CPeriodic::NewL(CActive::EPriorityStandard);
       
   144     
       
   145     // Store the environment pointer to avoid slow static access
       
   146     iEikEnv = CEikonEnv::Static();
       
   147     User::LeaveIfNull( iEikEnv );
       
   148     }
       
   149     
       
   150 // -----------------------------------------------------------------------------
       
   151 // CSvgtThreadController::IssueThreadMonitorRequest
       
   152 // Makes it active to get notify on thread death
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CSvgtThreadController::IssueThreadMonitorRequest(const RThread& aThread)
       
   156     {
       
   157     aThread.Logon(iStatus);
       
   158     iMainThread = aThread.Id();
       
   159     SetActive();
       
   160 
       
   161     TCallBack callBack(LoadAnimationCallBack, this);
       
   162     iCount  = 0;
       
   163     iLoadAnimator->Start(0, KAnimationInerval, callBack);
       
   164     }
       
   165     
       
   166 // -----------------------------------------------------------------------------
       
   167 // CSvgtThreadController::StopThreadExecution
       
   168 // Stops the thread execution
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CSvgtThreadController::StopThreadExecution(const RThread& aThread)
       
   172     {
       
   173     aThread.LogonCancel(iStatus);
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CSvgtThreadController::DoLoadAnimationL
       
   178 // This fuction does the loading animation
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CSvgtThreadController::DoLoadAnimationL()
       
   182     {
       
   183     CEikStatusPane* sp = iEikEnv->AppUiFactory()->StatusPane();
       
   184     CAknNavigationControlContainer* np = 
       
   185         static_cast<CAknNavigationControlContainer*>
       
   186             ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   187 
       
   188     if(iCount >= KAnimationLength)
       
   189         {
       
   190         iCount = 0;
       
   191         iAnimationText.Zero();
       
   192         }
       
   193     else
       
   194         {
       
   195         iCount++;
       
   196         iAnimationText.Append(KDot);
       
   197         }
       
   198 
       
   199     CAknNavigationDecorator* lOldNaviDecorator = iNaviDecorator;
       
   200     iNaviDecorator = NULL;
       
   201     if ( lOldNaviDecorator )
       
   202         {
       
   203         delete lOldNaviDecorator ;
       
   204         lOldNaviDecorator = NULL;
       
   205         }
       
   206 
       
   207     // Clear the old Navi-Pane Decorator
       
   208     // Create the navi pane label            
       
   209     iNaviDecorator = np->CreateNavigationLabelL( iAnimationText );
       
   210 
       
   211     // Save the old Navi Decorator so that it can be deleted after 
       
   212     // creating the new navi decorator 
       
   213     // Push the new Navi decorator in the Navigation Pane
       
   214     np->PushL( *iNaviDecorator );
       
   215     
       
   216     }
       
   217     
       
   218 // -----------------------------------------------------------------------------
       
   219 // CSvgtThreadController::LoadAnimationCallBack
       
   220 // Callback fuction for loading animation
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TInt CSvgtThreadController::LoadAnimationCallBack(TAny* aThreadController)
       
   224     {
       
   225     CSvgtThreadController* threadController = 
       
   226         static_cast< CSvgtThreadController* >( aThreadController );
       
   227     if ( threadController )
       
   228         {
       
   229         TRAPD( ignore, threadController->DoLoadAnimationL() );
       
   230         if ( ignore != KErrNone )
       
   231             {
       
   232             // No error handling done.
       
   233             }
       
   234         }
       
   235     return 0;
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CSvgtThreadController::ClearNaviPaneDecorator
       
   240 // Clears the navi pane indicator when the loading animation gets over
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CSvgtThreadController::ClearNaviPaneDecorator()
       
   244     {
       
   245     // Clear the Navi-Pane Decorator    
       
   246     if ( iNaviDecorator )
       
   247         {
       
   248         // Restore the old navi-pane
       
   249         CEikStatusPane* sp = iEikEnv->AppUiFactory()->StatusPane();
       
   250         
       
   251         CAknNavigationControlContainer* np = NULL;
       
   252         TRAPD( errGetNaviControl, 
       
   253             np = static_cast< CAknNavigationControlContainer* >
       
   254             ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ) );
       
   255         if ( errGetNaviControl == KErrNone && np )
       
   256             {
       
   257             TRAPD( errPushDefNaviControl, 
       
   258                 np->PushDefaultL ()); // Set default.    
       
   259             if ( errPushDefNaviControl != KErrNone )
       
   260                 {
       
   261                 // No error handling here.
       
   262                 }
       
   263             }
       
   264         delete iNaviDecorator;
       
   265         iNaviDecorator = NULL;
       
   266         }
       
   267     }
       
   268 // End of file
       
   269