1 /* |
|
2 * Copyright (c) 2004-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: Implements the CLandmarksAppUi class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <barsread2.h> |
|
21 |
|
22 #include <eikprogi.h> |
|
23 #include <AknProgressDialog.h> |
|
24 #include <akntabgrp.h> |
|
25 #include <aknnavide.h> |
|
26 |
|
27 #include "LmRefApp.hrh" |
|
28 #include <LmRefApp.rsg> |
|
29 #include "LandmarksAppUi.h" |
|
30 #include "LandmarksView.h" |
|
31 #include "LandmarksCategoriesView.h" |
|
32 #include "LandmarksInfoView.h" |
|
33 #include "LandmarksApplicationEngine.h" |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CLandmarksAppUi::CLandmarksAppUi() |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CLandmarksAppUi::ConstructL() |
|
48 { |
|
49 BaseConstructL(EAknEnableSkin); |
|
50 |
|
51 // Fetch pointer to the status pane. |
|
52 CEikStatusPane* statusPane = StatusPane(); |
|
53 |
|
54 // Fetch pointer to the default navi pane control. |
|
55 CAknNavigationControlContainer* naviPane = |
|
56 (CAknNavigationControlContainer*) statusPane->ControlL( |
|
57 TUid::Uid(EEikStatusPaneUidNavi)); |
|
58 |
|
59 // Initialise the nave decorator that visualizes the tabs and navi arrows. |
|
60 iNaviDecorator = naviPane->ResourceDecorator(); |
|
61 CAknTabGroup* tabGroup = |
|
62 static_cast<CAknTabGroup*>(iNaviDecorator->DecoratedControl()); |
|
63 tabGroup->SetObserver(this); |
|
64 |
|
65 // Create and init the application engine. |
|
66 iEngine = CLandmarksApplicationEngine::NewL(); |
|
67 |
|
68 // Initialize the default landmark database if necessary. |
|
69 if (iEngine->StartInitializeDbIfNecessaryL(this)) |
|
70 { |
|
71 LaunchProgressDialogL(); |
|
72 } |
|
73 else |
|
74 { |
|
75 // Db is already initialized - OK to construct views. |
|
76 PostConstructL(); |
|
77 } |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CLandmarksAppUi::~CLandmarksAppUi() |
|
84 { |
|
85 delete iNaviDecorator; |
|
86 |
|
87 // Cannot delete iEngine here since it is needed when deactivating views. |
|
88 iEngine = NULL; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CLandmarksAppUi::HandleCommandL(TInt aCommand) |
|
95 { |
|
96 switch(aCommand) |
|
97 { |
|
98 case EEikCmdExit: |
|
99 case EAknSoftkeyExit: |
|
100 if (iProgressDialog) |
|
101 { |
|
102 // The progress dialog has been dismissed but not yet deleted. |
|
103 // iProgressDialog->ProcessFinishedL() deletes the progress |
|
104 // dialog asynchronously. If the app is exited before the |
|
105 // dialog is deleted, a Cone 8 panic will occur. |
|
106 // Thus, iProgressDialog must be deleted explicitely here. |
|
107 delete iProgressDialog; |
|
108 iProgressDialog = NULL; |
|
109 } |
|
110 Exit(); |
|
111 break; |
|
112 default: |
|
113 break; |
|
114 } |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TKeyResponse CLandmarksAppUi::HandleKeyEventL( |
|
121 const TKeyEvent& aKeyEvent,TEventCode aType) |
|
122 { |
|
123 // Offer arrow keys to CAknTabGroup, it then calculates new active tab |
|
124 // and later calls our TabChangedL() -method with correct new tab index. |
|
125 |
|
126 CAknTabGroup* tabGroup = |
|
127 static_cast <CAknTabGroup*> (iNaviDecorator->DecoratedControl()); |
|
128 |
|
129 if (tabGroup && |
|
130 (aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow)) |
|
131 { |
|
132 return tabGroup->OfferKeyEventL(aKeyEvent, aType); |
|
133 } |
|
134 |
|
135 return EKeyWasNotConsumed; |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // ---------------------------------------------------------------------------- |
|
140 // |
|
141 void CLandmarksAppUi::HandleResourceChangeL( TInt aType ) |
|
142 { |
|
143 CAknAppUi::HandleResourceChangeL( aType ); |
|
144 |
|
145 CLandmarksView* lmView = ( CLandmarksView* ) View( TUid::Uid( ELandmarksViewId ) ); |
|
146 if ( lmView ) |
|
147 { |
|
148 lmView->HandleResourceChange( aType ); |
|
149 } |
|
150 |
|
151 CLandmarksCategoriesView* catView = ( CLandmarksCategoriesView* ) View( TUid::Uid( ELandmarksCategoriesViewId ) ); |
|
152 if ( catView ) |
|
153 { |
|
154 catView->HandleResourceChange( aType ); |
|
155 } |
|
156 |
|
157 CLandmarksInfoView* infoView = ( CLandmarksInfoView* ) View( TUid::Uid( ELandmarksInfoViewId ) ); |
|
158 if ( infoView ) |
|
159 { |
|
160 infoView->HandleResourceChange( aType ); |
|
161 } |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CLandmarksAppUi::TabChangedL(TInt aIndex) |
|
168 { |
|
169 switch (aIndex) |
|
170 { |
|
171 case 0: |
|
172 ActivateLocalViewL(TUid::Uid(ELandmarksViewId)); |
|
173 break; |
|
174 case 1: |
|
175 ActivateLocalViewL(TUid::Uid(ELandmarksCategoriesViewId)); |
|
176 break; |
|
177 default: |
|
178 break; |
|
179 } |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CLandmarksAppUi::NotifyOperationProgressL( |
|
186 TOperation aOperation, |
|
187 TInt aProgress, |
|
188 TInt aErrorCode) |
|
189 { |
|
190 if (aOperation == EInitializeDb) |
|
191 { |
|
192 // Update Progressbar |
|
193 CEikProgressInfo* progressBar = iProgressDialog->GetProgressInfoL(); |
|
194 progressBar->SetAndDraw(aProgress); |
|
195 |
|
196 if (aErrorCode == KErrNone) // Db initialization ready. |
|
197 { |
|
198 // Dismiss dialog. |
|
199 iProgressDialog->ProcessFinishedL(); |
|
200 |
|
201 // Continue with construction |
|
202 PostConstructL(); |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CLandmarksAppUi::PostConstructL() |
|
211 { |
|
212 // Create landmarks view |
|
213 CLandmarksView* landmarksView = |
|
214 CLandmarksView::NewLC(iNaviDecorator, *iEngine); |
|
215 AddViewL(landmarksView); // Transfer ownership to base class |
|
216 CleanupStack::Pop(landmarksView); |
|
217 |
|
218 // Create categories view |
|
219 CLandmarksCategoriesView* categoriesView = |
|
220 CLandmarksCategoriesView::NewLC(iEngine); // ownership is transferred |
|
221 AddViewL(categoriesView); // Transfer ownership to base class |
|
222 CleanupStack::Pop(categoriesView); |
|
223 |
|
224 // Create landmark info view |
|
225 CLandmarksInfoView* infoView = |
|
226 CLandmarksInfoView::NewLC(iNaviDecorator, *iEngine); |
|
227 AddViewL(infoView); // Transfer ownership to base class |
|
228 CleanupStack::Pop(infoView); |
|
229 |
|
230 // Activate landmarks view |
|
231 landmarksView->ActivateViewL(landmarksView->ViewId()); |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CLandmarksAppUi::DialogDismissedL(TInt /*aButtonId*/) |
|
238 { |
|
239 iProgressDialog = NULL; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CLandmarksAppUi::LaunchProgressDialogL() |
|
246 { |
|
247 // Initialize dialog |
|
248 TBool showImmediately(ETrue); |
|
249 iProgressDialog = new (ELeave) CAknProgressDialog( |
|
250 reinterpret_cast <CEikDialog**> (&iProgressDialog), showImmediately); |
|
251 iProgressDialog->PrepareLC(R_LMREFAPP_INIT_DB_PROGRESS_DIALOG); |
|
252 iProgressDialog->SetCallback(this); |
|
253 |
|
254 // Initialize progress bar. |
|
255 CEikProgressInfo* progressBar = iProgressDialog->GetProgressInfoL(); |
|
256 const TInt KFinalProgressValue = 100; // 100% done when ready |
|
257 progressBar->SetFinalValue(KFinalProgressValue); |
|
258 |
|
259 // Launch the prepared dialog. |
|
260 iProgressDialog->RunLD(); |
|
261 |
|
262 // Draw the progress bar |
|
263 progressBar->IncrementAndDraw(0); |
|
264 } |
|
265 |
|