|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : LandmarksAppUi.cpp 00004 * Part of : Landmark Reference Application 00005 * Interface : - 00006 * Description : Implements the CLandmarksAppUi class 00007 * Version : 1.0 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <barsread2.h> 00018 00019 #include <eikprogi.h> 00020 #include <aknprogressdialog.h> 00021 #include <akntabgrp.h> 00022 #include <aknnavide.h> 00023 00024 #include "LmRefApp.hrh" 00025 #include <LmRefApp.rsg> 00026 #include "LandmarksAppUi.h" 00027 #include "LandmarksView.h" 00028 #include "LandmarksCategoriesView.h" 00029 #include "LandmarksInfoView.h" 00030 #include "LandmarksApplicationEngine.h" 00031 00032 // ============================ MEMBER FUNCTIONS =============================== 00033 00034 // ----------------------------------------------------------------------------- 00035 // CLandmarksAppUi::CLandmarksAppUi 00036 // C++ default constructor can NOT contain any code, that 00037 // might leave. 00038 // ----------------------------------------------------------------------------- 00039 // 00040 CLandmarksAppUi::CLandmarksAppUi() 00041 { 00042 } 00043 00044 // ----------------------------------------------------------------------------- 00045 // CLandmarksAppUi::ConstructL 00046 // Symbian 2nd phase constructor can leave. 00047 // ----------------------------------------------------------------------------- 00048 // 00049 void CLandmarksAppUi::ConstructL() 00050 { 00051 BaseConstructL(EAknEnableSkin); 00052 00053 // Fetch pointer to the status pane. 00054 CEikStatusPane* statusPane = StatusPane(); 00055 00056 // Fetch pointer to the default navi pane control. 00057 CAknNavigationControlContainer* naviPane = 00058 (CAknNavigationControlContainer*) statusPane->ControlL( 00059 TUid::Uid(EEikStatusPaneUidNavi)); 00060 00061 // Initialise the nave decorator that visualizes the tabs and navi arrows. 00062 iNaviDecorator = naviPane->ResourceDecorator(); 00063 CAknTabGroup* tabGroup = 00064 static_cast<CAknTabGroup*>(iNaviDecorator->DecoratedControl()); 00065 tabGroup->SetObserver(this); 00066 00067 // Create and init the application engine. 00068 iEngine = CLandmarksApplicationEngine::NewL(); 00069 00070 // Initialize the default landmark database if necessary. 00071 if (iEngine->StartInitializeDbIfNecessaryL(this)) 00072 { 00073 LaunchProgressDialogL(); 00074 } 00075 else 00076 { 00077 // Db is already initialized - OK to construct views. 00078 PostConstructL(); 00079 } 00080 } 00081 00082 // Destructor 00083 CLandmarksAppUi::~CLandmarksAppUi() 00084 { 00085 delete iNaviDecorator; 00086 00087 // Cannot delete iEngine here since it is needed when deactivating views. 00088 iEngine = NULL; 00089 } 00090 00091 // ----------------------------------------------------------------------------- 00092 // CLandmarksAppUi::HandleCommandL 00093 // 00094 // (other items were commented in a header). 00095 // ----------------------------------------------------------------------------- 00096 // 00097 void CLandmarksAppUi::HandleCommandL(TInt aCommand) 00098 { 00099 switch(aCommand) 00100 { 00101 case EEikCmdExit: 00102 case EAknSoftkeyExit: 00103 if (iProgressDialog) 00104 { 00105 // The progress dialog has been dismissed but not yet deleted. 00106 // iProgressDialog->ProcessFinishedL() deletes the progress 00107 // dialog asynchronously. If the app is exited before the 00108 // dialog is deleted, a Cone 8 panic will occur. 00109 // Thus, iProgressDialog must be deleted explicitely here. 00110 delete iProgressDialog; 00111 iProgressDialog = NULL; 00112 } 00113 Exit(); 00114 break; 00115 default: 00116 break; 00117 } 00118 } 00119 00120 // ----------------------------------------------------------------------------- 00121 // CLandmarksAppUi::HandleKeyEventL 00122 // 00123 // (other items were commented in a header). 00124 // ----------------------------------------------------------------------------- 00125 // 00126 TKeyResponse CLandmarksAppUi::HandleKeyEventL( 00127 const TKeyEvent& aKeyEvent,TEventCode aType) 00128 { 00129 // Offer arrow keys to CAknTabGroup, it then calculates new active tab 00130 // and later calls our TabChangedL() -method with correct new tab index. 00131 00132 CAknTabGroup* tabGroup = 00133 static_cast <CAknTabGroup*> (iNaviDecorator->DecoratedControl()); 00134 00135 if (tabGroup && 00136 (aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow)) 00137 { 00138 return tabGroup->OfferKeyEventL(aKeyEvent, aType); 00139 } 00140 00141 return EKeyWasNotConsumed; 00142 } 00143 00144 void CLandmarksAppUi::TabChangedL(TInt aIndex) 00145 { 00146 switch (aIndex) 00147 { 00148 case 0: 00149 ActivateLocalViewL(TUid::Uid(ELandmarksViewId)); 00150 break; 00151 case 1: 00152 ActivateLocalViewL(TUid::Uid(ELandmarksCategoriesViewId)); 00153 break; 00154 default: 00155 break; 00156 } 00157 } 00158 00159 // ----------------------------------------------------------------------------- 00160 // CLandmarksAppUi::NotifyOperationProgressL 00161 // 00162 // (other items were commented in a header). 00163 // ----------------------------------------------------------------------------- 00164 // 00165 void CLandmarksAppUi::NotifyOperationProgressL( 00166 TOperation aOperation, 00167 TInt aProgress, 00168 TInt aErrorCode) 00169 { 00170 if (aOperation == EInitializeDb) 00171 { 00172 // Update Progressbar 00173 CEikProgressInfo* progressBar = iProgressDialog->GetProgressInfoL(); 00174 progressBar->SetAndDraw(aProgress); 00175 00176 if (aErrorCode == KErrNone) // Db initialization ready. 00177 { 00178 // Dismiss dialog. 00179 iProgressDialog->ProcessFinishedL(); 00180 00181 // Continue with construction 00182 PostConstructL(); 00183 } 00184 } 00185 } 00186 00187 // ----------------------------------------------------------------------------- 00188 // CLandmarksAppUi::PostConstructL 00189 // 00190 // (other items were commented in a header). 00191 // ----------------------------------------------------------------------------- 00192 // 00193 void CLandmarksAppUi::PostConstructL() 00194 { 00195 // Create landmarks view 00196 CLandmarksView* landmarksView = 00197 CLandmarksView::NewLC(iNaviDecorator, *iEngine); 00198 AddViewL(landmarksView); // Transfer ownership to base class 00199 CleanupStack::Pop(landmarksView); 00200 00201 // Create categories view 00202 CLandmarksCategoriesView* categoriesView = 00203 CLandmarksCategoriesView::NewLC(iEngine); // ownership is transferred 00204 AddViewL(categoriesView); // Transfer ownership to base class 00205 CleanupStack::Pop(categoriesView); 00206 00207 // Create landmark info view 00208 CLandmarksInfoView* infoView = 00209 CLandmarksInfoView::NewLC(iNaviDecorator, *iEngine); 00210 AddViewL(infoView); // Transfer ownership to base class 00211 CleanupStack::Pop(infoView); 00212 00213 // Activate landmarks view 00214 landmarksView->ActivateViewL(landmarksView->ViewId()); 00215 } 00216 00217 // ----------------------------------------------------------------------------- 00218 // CLandmarksAppUi::DialogDismissedL 00219 // 00220 // (other items were commented in a header). 00221 // ----------------------------------------------------------------------------- 00222 // 00223 void CLandmarksAppUi::DialogDismissedL(TInt /*aButtonId*/) 00224 { 00225 iProgressDialog = NULL; 00226 } 00227 00228 // ----------------------------------------------------------------------------- 00229 // CLandmarksAppUi::LaunchProgressDialogL 00230 // 00231 // (other items were commented in a header). 00232 // ----------------------------------------------------------------------------- 00233 // 00234 void CLandmarksAppUi::LaunchProgressDialogL() 00235 { 00236 // Initialize dialog 00237 TBool showImmediately(ETrue); 00238 iProgressDialog = new (ELeave) CAknProgressDialog( 00239 reinterpret_cast <CEikDialog**> (&iProgressDialog), showImmediately); 00240 iProgressDialog->PrepareLC(R_LMREFAPP_INIT_DB_PROGRESS_DIALOG); 00241 iProgressDialog->SetCallback(this); 00242 00243 // Initialize progress bar. 00244 CEikProgressInfo* progressBar = iProgressDialog->GetProgressInfoL(); 00245 const TInt KFinalProgressValue = 100; // 100% done when ready 00246 progressBar->SetFinalValue(KFinalProgressValue); 00247 00248 // Launch the prepared dialog. 00249 iProgressDialog->RunLD(); 00250 00251 // Draw the progress bar 00252 progressBar->IncrementAndDraw(0); 00253 } 00254 00255 // End of File 00256
|
© Nokia 2006 |