phonebookui/Phonebook/App/src/CPbkStartupView.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *       
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkStartupView.h"
       
    22 #include "CPbkAppUi.h"
       
    23 #include "CPbkDocument.h"
       
    24 #include <CPbkControlContainer.h>
       
    25 #include <Phonebook.hrh>
       
    26 
       
    27 // Debugging headers
       
    28 #include <pbkdebug.h>
       
    29 #include "PbkProfiling.h"
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KViewActivationTimeout = 5000000;
       
    34 
       
    35 inline CPbkStartupView::CPbkStartupView(MPbkAppUiExtension& aAppUiExtension) :
       
    36     iAppUiExtension(aAppUiExtension)
       
    37     {
       
    38     }
       
    39 
       
    40 inline void CPbkStartupView::ConstructL()
       
    41     {
       
    42     __PBK_PROFILE_START(PbkProfiling::EViewBaseConstruct);
       
    43     BaseConstructL();
       
    44     __PBK_PROFILE_END(PbkProfiling::EViewBaseConstruct);
       
    45     }
       
    46 
       
    47 CPbkStartupView* CPbkStartupView::NewLC(MPbkAppUiExtension& aAppUiExtension)
       
    48     {
       
    49 	CPbkStartupView* self = new(ELeave) CPbkStartupView(aAppUiExtension);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL();
       
    52 	return self;
       
    53     }
       
    54 
       
    55 CPbkStartupView* CPbkStartupView::NewL(MPbkAppUiExtension& aAppUiExtension)
       
    56     {
       
    57 	CPbkStartupView* self = CPbkStartupView::NewLC(aAppUiExtension);
       
    58 	CleanupStack::Pop(self);
       
    59 	return self;
       
    60     }
       
    61 
       
    62 CPbkStartupView::~CPbkStartupView()
       
    63     {
       
    64     if (iContainer)
       
    65         {
       
    66         AppUi()->RemoveFromViewStack(*this, iContainer);
       
    67         delete iContainer;
       
    68         }
       
    69     if (iTimer)
       
    70         {
       
    71         iTimer->Cancel();
       
    72         delete iTimer;
       
    73         }
       
    74     }
       
    75 
       
    76 void CPbkStartupView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, 
       
    77                                   TUid /*aCustomMessageId*/, 
       
    78                                   const TDesC8& /*aCustomMessage*/)
       
    79     {
       
    80     __PBK_PROFILE_END(PbkProfiling::EStartupViewActivation);
       
    81 
       
    82     __PBK_PROFILE_START(PbkProfiling::EStartupViewDoActivateL);
       
    83 
       
    84     if (!iContainer)
       
    85         {
       
    86         iContainer = CContainer::NewL(this, *this);
       
    87         CCoeControl* control = new(ELeave) CCoeControl;
       
    88         CleanupStack::PushL(control);
       
    89         control->SetContainerWindowL(*iContainer);
       
    90         CleanupStack::Pop(control);
       
    91         iContainer->SetControl(control, ClientRect());
       
    92         iContainer->ActivateL();
       
    93         AppUi()->AddToViewStackL(*this, iContainer);
       
    94         }
       
    95     iContainer->Control()->DrawNow();
       
    96 
       
    97     __PBK_PROFILE_END(PbkProfiling::EStartupViewDoActivateL);
       
    98 
       
    99     if (iAppUiExtension.StartupStatus() == MPbkAppUiExtension::EStartupNotStarted)
       
   100         {
       
   101         // we have to make this check to make sure that extension startup is not started multiple times
       
   102         // for example in case of screen saver popping up when startup is in progress or when user
       
   103         // visits some other application during startup
       
   104 
       
   105         // Ending this profile is in CPbkStartupView::HandleStartupComplete
       
   106         __PBK_PROFILE_START(PbkProfiling::EExtensionStartup);
       
   107         CPbkContactEngine* engine = Engine();    
       
   108         iAppUiExtension.ExtensionStartupL(*this, *engine);
       
   109         }
       
   110     }
       
   111 
       
   112 void CPbkStartupView::DoDeactivate()
       
   113     {
       
   114     if (iTimer)
       
   115         {
       
   116         // at this point the names list view is already activated
       
   117         // so we know that activation was successful and we can
       
   118         // cancel the timer
       
   119         iTimer->Cancel();
       
   120         delete iTimer;
       
   121         iTimer = NULL;
       
   122         }
       
   123 
       
   124     if (iContainer)
       
   125         {
       
   126         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   127         delete iContainer;
       
   128         iContainer = NULL;
       
   129         }
       
   130     }
       
   131 
       
   132 TUid CPbkStartupView::Id() const
       
   133     {
       
   134     return TUid::Uid(EPbkStartupViewId);
       
   135     }
       
   136 
       
   137 void CPbkStartupView::HandleStartupComplete()
       
   138     {
       
   139     __PBK_PROFILE_END(PbkProfiling::EExtensionStartup);
       
   140 
       
   141     __PBK_PROFILE_START(PbkProfiling::EHandleStartupComplete);
       
   142        
       
   143     TRAPD(error, 
       
   144         {
       
   145         PbkAppUi()->ActivatePhonebookViewL(TUid::Uid(EPbkNamesListViewId));
       
   146         if (!iTimer)
       
   147             {
       
   148             iTimer = CPeriodic::NewL(CPeriodic::EPriorityIdle);
       
   149             }
       
   150         });
       
   151 
       
   152     if (error != KErrNone)
       
   153         {
       
   154         // view activation failed - exit gracefully
       
   155         iCoeEnv->HandleError(error);
       
   156         PbkAppUi()->Exit();
       
   157         }
       
   158 
       
   159     if (iContainer)
       
   160         {
       
   161         // If the iContainer exists, it means that this view is still active, so
       
   162         // we have to start the timer to see if names list view was activated
       
   163 
       
   164         // Start timer for view activation. If view activation times
       
   165         // out, the application is closed.
       
   166         iTimer->Start(KViewActivationTimeout, 
       
   167                       1, // this is irrelevant because the event is not repeated
       
   168                       TCallBack(CPbkStartupView::ViewActivationTimeout, this));
       
   169         }
       
   170 
       
   171     __PBK_PROFILE_END(PbkProfiling::EHandleStartupComplete);
       
   172 
       
   173     // Ending this profile is in CPbkNamesListView::DoActivateL
       
   174     __PBK_PROFILE_START(PbkProfiling::ENamesListViewActivation);
       
   175     }
       
   176 
       
   177 void CPbkStartupView::HandleStartupFailedL(TInt aError)
       
   178     {
       
   179     // initialisation failed - exit gracefully
       
   180     iCoeEnv->HandleError(aError);
       
   181     PbkAppUi()->Exit();
       
   182     }
       
   183 
       
   184 TInt CPbkStartupView::ViewActivationTimeout(TAny* aThis)
       
   185     {
       
   186     return static_cast<CPbkStartupView*>(aThis)->ViewActivationTimeout();
       
   187     }
       
   188 
       
   189 TInt CPbkStartupView::ViewActivationTimeout()
       
   190     {
       
   191     PbkAppUi()->Exit();
       
   192     return 0;
       
   193     }
       
   194 
       
   195 // End of File