|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================ 00003 * Name : LmUiRefAppView.cpp 00004 * Part of : Landmarks UI Reference Application 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2005-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 // INCLUDE FILES 00016 #include <E32def.h> 00017 #include <avkon.hrh> 00018 #include <AknViewAppUi.h> 00019 #include <AknsUtils.h> 00020 #include <stringloader.h> 00021 #include <aknnotewrappers.h> 00022 #include <eikmenup.h> 00023 #include <EPos_CPosLandmarkDatabase.h> 00024 #include <lmuirefapp.rsg> 00025 #include "lmuirefapp.hrh" 00026 #include "CLmkLandmarkSelectorDlg.h" 00027 #include "CLmkCategorySelectorDlg.h" 00028 #include "LmUiRefAppDocument.h" 00029 #include "LmUiRefAppContainer.h" 00030 #include "LmUiRefAppUi.h" 00031 #include "LmUiRefAppView.h" 00032 #include "CLmkEditorDlg.h" 00033 #include "TLmkItemIdDbCombiInfo.h" //For multi db support, combiinfo struct 00034 00035 #define LMK_PARAMS (CLmkEditorDlg::ELmkOnlyName | CLmkEditorDlg::ELmkCategory | CLmkEditorDlg::ELmkStreet | CLmkEditorDlg::ELmkCity | CLmkEditorDlg::ELmkLatitude| CLmkEditorDlg::ELmkLongitude) 00036 00037 #define LMK_PARAMS_DEFAULT CLmkEditorDlg::ELmkAll 00038 00039 // ================= MEMBER FUNCTIONS ======================= 00040 //------------------------------------------------------------------------- 00041 // CLmUiRefAppView::NewLC 00042 // Two-phased constructor. 00043 //------------------------------------------------------------------------- 00044 // 00045 CLmUiRefAppView* CLmUiRefAppView::NewLC() 00046 { 00047 CLmUiRefAppView* self = 00048 new( ELeave ) CLmUiRefAppView(); 00049 CleanupStack::PushL( self ); 00050 self->ConstructL(); 00051 return self; 00052 } 00053 00054 //--------------------------------------------------------------------------- 00055 // CLmUiRefAppView::CLmUiRefAppView 00056 // C++ default constructor can NOT contain any code, that 00057 // might leave. 00058 //--------------------------------------------------------------------------- 00059 // 00060 CLmUiRefAppView::CLmUiRefAppView() 00061 { 00062 } 00063 00064 // -------------------------------------------------------------------------- 00065 // CLmUiRefAppView::ConstructL 00066 // Symbian 2nd phase constructor can leave. 00067 // -------------------------------------------------------------------------- 00068 // 00069 void CLmUiRefAppView::ConstructL() 00070 { 00071 BaseConstructL(R_LMUIREFAPP_VIEW); 00072 } 00073 00074 // -------------------------------------------------------------------------- 00075 // CLmUiRefAppView::~CLmUiRefAppView 00076 // ------------------------------------------------------------------------ 00077 // 00078 CLmUiRefAppView::~CLmUiRefAppView() 00079 { 00080 if ( iContainer ) 00081 { 00082 AppUi()->RemoveFromViewStack( *this, iContainer ); 00083 } 00084 delete iContainer; 00085 } 00086 00087 // -------------------------------------------------------------------------- 00088 // TUid CLmUiRefAppView::Id 00089 // -------------------------------------------------------------------------- 00090 // 00091 TUid CLmUiRefAppView::Id() const 00092 { 00093 return TUid::Uid(ELmUiRefAppView); 00094 } 00095 00096 // -------------------------------------------------------------------------- 00097 // CLmUiRefAppView::HandleCommandL 00098 // -------------------------------------------------------------------------- 00099 // 00100 void CLmUiRefAppView::HandleCommandL( TInt aCommand ) 00101 { 00102 switch ( aCommand ) 00103 { 00104 // these all are same: exit 00105 case EAknSoftkeyExit: 00106 case EAknSoftkeyBack: 00107 { 00108 AppUi()->HandleCommandL(EEikCmdExit); 00109 break; 00110 } 00111 case ELmUiRefAppCmdDeleteLm: 00112 { 00113 if (IsLmDbEmptyL()) 00114 { 00115 // Display some Error Note here 00116 iContainer->DrawNow(); 00117 return; 00118 } 00119 if (LaunchLandmarksDialogL() == 0) 00120 { 00121 // If Selector is cancelled, return to MAIN view 00122 iContainer->DrawNow(); 00123 return; 00124 } 00125 00126 // Display Note 00127 CEikonEnv* env = CEikonEnv::Static(); 00128 HBufC* noteText = NULL; 00129 noteText 00130 = StringLoader::LoadLC( R_LMUIREFAPP_DELETE_LANDMARK, env ); 00131 CAknQueryDialog* query = 00132 new( ELeave ) CAknQueryDialog( *noteText ); 00133 TInt ret = query->ExecuteLD( R_LMUIREFAPP_QUERY); 00134 if (!(ret)) 00135 { 00136 CleanupStack::PopAndDestroy(noteText); //noteText 00137 iContainer->DrawNow(); 00138 return; 00139 } 00140 TPosLmItemId delLmItem = SelectedItem(); 00141 ilDb->RemoveLandmarkL(delLmItem); 00142 delete ilDb; 00143 CleanupStack::PopAndDestroy(noteText); //noteText 00144 break; 00145 } 00146 00147 case ELmUiRefAppCmdNewLm : 00148 { 00149 //if to be used later on or commented because of an Error. 00150 NewLmCmdL(); 00151 break; 00152 } 00153 00154 case ELmUiRefAppCmdViewLm: 00155 { 00156 /* Launch LM Selector only when Landmarks 00157 * Database has any entries 00158 */ 00159 if (IsLmDbEmptyL()) 00160 { 00161 // Display some Error Note here 00162 iContainer->DrawNow(); 00163 return; 00164 } 00165 if (LaunchLandmarksDialogL() == 0) 00166 { 00167 // If Selector is cancelled, return to MAIN view 00168 iContainer->DrawNow(); 00169 return; 00170 } 00171 00172 CLmkEditorDlg::TLmkEditorParams editParams; 00173 editParams.iAttributes = CLmkEditorDlg::ELmkAll; 00174 editParams.iEditorMode = CLmkEditorDlg::ELmkViewer; 00175 TPosLmItemId lmItem = SelectedItem(); 00176 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(*ilDb, 00177 lmItem, 00178 editParams); 00179 dlg->ExecuteLD(); 00180 iContainer->DrawNow(); 00181 delete ilDb; 00182 break; 00183 } 00184 00185 case ELmUiRefAppCmdEditLm: 00186 { 00187 if (IsLmDbEmptyL()) 00188 { 00189 // Display some Error Note here 00190 iContainer->DrawNow(); 00191 return; 00192 } 00193 if (LaunchLandmarksDialogL() == 0) 00194 { 00195 // If Selector is cancelled, return to MAIN view 00196 iContainer->DrawNow(); 00197 return; 00198 } 00199 CPosLandmark* landmarkedi = NULL; 00200 ExecuteLmEditorL(landmarkedi, *ilDb); 00201 // Refresh 00202 iContainer->DrawNow(); 00203 delete ilDb; 00204 break; 00205 } 00206 case ELmUiRefAppCmdMultiLmSelector: 00207 { 00208 if ( IsLmDbEmptyL() ) 00209 { 00210 // Display some Error Note here 00211 iContainer->DrawNow(); 00212 return; 00213 } 00214 00215 if ( LaunchMultiLandmarkSelectorDialogL() == 0 ) 00216 { 00217 // If Selector is cancelled, return to MAIN view 00218 iContainer->DrawNow(); 00219 return; 00220 } 00221 break; 00222 } 00223 case ELmUiRefAppCmdMultiCatSelector: 00224 { 00225 if ( IsLmDbEmptyL() ) 00226 { 00227 // Display some Error Note here 00228 iContainer->DrawNow(); 00229 return; 00230 } 00231 00232 if ( LaunchMultiCategorySelectorDialogL() == 0 ) 00233 { 00234 // If Selector is cancelled, return to MAIN view 00235 iContainer->DrawNow(); 00236 return; 00237 } 00238 break; 00239 } 00240 case ELmUiRefAppCmdSingleCatSelector: 00241 { 00242 if ( IsLmDbEmptyL() ) 00243 { 00244 // Display some Error Note here 00245 iContainer->DrawNow(); 00246 return; 00247 } 00248 00249 if ( LaunchSingleCategoeyDialogL() == 0 ) 00250 { 00251 // If Selector is cancelled, return to MAIN view 00252 iContainer->DrawNow(); 00253 return; 00254 } 00255 // Refresh view if needed 00256 iContainer->DrawNow(); 00257 delete ilDb; 00258 break; 00259 } 00260 default: 00261 break; 00262 } 00263 } 00264 00265 // -------------------------------------------------------------------------- 00266 // CLmUiRefAppView::NewLmCmdL() 00267 // -------------------------------------------------------------------------- 00268 // 00269 void CLmUiRefAppView::NewLmCmdL() 00270 { 00271 CPosLandmark* landmark = CPosLandmark::NewL(); 00272 CleanupStack::PushL( landmark ); 00273 CLmUiRefAppUi* lmUiAppUi = static_cast<CLmUiRefAppUi*>( ViewAppUi() ); 00274 CPosLandmarkDatabase& iaDb = (lmUiAppUi->Document().LmDb()); 00275 ExecuteLmEditorL( landmark, iaDb ); 00276 CleanupStack::PopAndDestroy( landmark ); 00277 } 00278 00279 // ----------------------------------------------------------------------------- 00280 // CLmUiRefAppView::ExecuteLmEditorL() 00281 // ----------------------------------------------------------------------------- 00282 void CLmUiRefAppView::ExecuteLmEditorL( 00283 CPosLandmark* aLandmark, CPosLandmarkDatabase& aDb) 00284 { 00285 CLmkEditorDlg::TLmkEditorParams editParams; 00286 editParams.iAttributes = LMK_PARAMS_DEFAULT; 00287 editParams.iEditorMode = CLmkEditorDlg::ELmkEditor; 00288 TPosLmItemId lmItem = SelectedItem(); 00289 if (aLandmark) 00290 { 00291 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(aDb, *aLandmark, editParams); 00292 dlg->ExecuteLD(); 00293 } 00294 else 00295 { 00296 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(aDb, lmItem, editParams); 00297 dlg->ExecuteLD(); 00298 } 00299 } 00300 00301 // -------------------------------------------------------------------------- 00302 // CLmUiRefAppView::DoActivateL 00303 // -------------------------------------------------------------------------- 00304 // 00305 void CLmUiRefAppView::DoActivateL( 00306 const TVwsViewId& /*aPrevViewId*/, 00307 TUid /*aCustomMessageId*/, 00308 const TDesC8& /*aCustomMessage*/ ) 00309 { 00310 if ( !iContainer ) 00311 { 00312 iContainer = CLmUiRefAppContainer::NewL(this, ClientRect() ); 00313 AppUi()->AddToStackL( *this, iContainer ); 00314 } 00315 } 00316 00317 // -------------------------------------------------------------------------- 00318 // CLmUiRefAppView::DoDeactivate 00319 // -------------------------------------------------------------------------- 00320 // 00321 void CLmUiRefAppView::DoDeactivate() 00322 { 00323 if ( iContainer ) 00324 { 00325 AppUi()->RemoveFromViewStack( *this, iContainer ); 00326 } 00327 delete iContainer; 00328 iContainer = NULL; 00329 } 00330 00331 // -------------------------------------------------------------------------- 00332 // CLmUiRefAppView::LaunchLandmarksDialogL() 00333 // -------------------------------------------------------------------------- 00334 // 00335 TInt CLmUiRefAppView::LaunchLandmarksDialogL() 00336 { 00337 // Launch LMK Selector 00338 iLmkSelectDlg = CLmkLandmarkSelectorDlg::NewL(); 00339 iLmkSelectDlg->SetMopParent(this); 00340 TLmkItemIdDbCombiInfo selItem; 00341 TInt retVal = iLmkSelectDlg->ExecuteLD( selItem ); 00342 if (retVal !=0) 00343 { 00344 iSelectedItem = selItem.GetItemId(); 00345 ilDb = selItem.GetLmDb(); 00346 } 00347 return retVal; 00348 } 00349 00350 // -------------------------------------------------------------------------- 00351 // CLmUiRefAppView::ViewAppUi() 00352 // -------------------------------------------------------------------------- 00353 // 00354 CAknViewAppUi* CLmUiRefAppView::ViewAppUi() 00355 { 00356 return static_cast<CAknViewAppUi*>( iAvkonAppUi ); 00357 } 00358 00359 // -------------------------------------------------------------------------- 00360 // CLmUiRefAppView::SelectedItem() 00361 // -------------------------------------------------------------------------- 00362 // 00363 TPosLmItemId CLmUiRefAppView::SelectedItem() const 00364 { 00365 return iSelectedItem; 00366 } 00367 00368 // -------------------------------------------------------------------------- 00369 // CLmUiRefAppView::IsLmDbEmptyL() 00370 // -------------------------------------------------------------------------- 00371 // 00372 TBool CLmUiRefAppView::IsLmDbEmptyL() 00373 { 00374 CPosLmItemIterator* itemIterator = NULL;CLmUiRefAppUi* lmUiAppUi = static_cast<CLmUiRefAppUi*>( ViewAppUi() ); 00375 CPosLandmarkDatabase& iaDb = lmUiAppUi->Document().LmDb(); 00376 00377 itemIterator = iaDb.LandmarkIteratorL(); 00378 00379 CleanupStack::PushL(itemIterator); 00380 itemIterator->Reset(); 00381 TUint nrOfItems = itemIterator->NumOfItemsL(); 00382 CleanupStack::PopAndDestroy(itemIterator); 00383 if (nrOfItems == 0) 00384 { 00385 return ETrue; 00386 } 00387 return EFalse; 00388 } 00389 00390 // --------------------------------------------------------- 00391 // CLmkByLmView::DynInitMenuPaneL 00392 // --------------------------------------------------------- 00393 // 00394 void CLmUiRefAppView::DynInitMenuPaneL( 00395 TInt aResourceId, 00396 CEikMenuPane* aMenuPane ) 00397 { 00398 switch ( aResourceId ) 00399 { 00400 case R_LMUIREFAPP_MENU1: 00401 { 00402 if (IsLmDbEmptyL()) 00403 { 00404 // Show NEW LM Menu Item 00405 aMenuPane->SetItemDimmed( ELmUiRefAppCmdEditLm, ETrue ); 00406 aMenuPane->SetItemDimmed( ELmUiRefAppCmdViewLm, ETrue ); 00407 aMenuPane->SetItemDimmed( ELmUiRefAppCmdDeleteLm, ETrue ); 00408 } 00409 break; 00410 } 00411 default: 00412 { 00413 break; 00414 } 00415 } 00416 } 00417 // -------------------------------------------------------------------------- 00418 // CLmUiRefAppView::LaunchMultiLandmarkSelectorDialogL() 00419 // -------------------------------------------------------------------------- 00420 // 00421 TInt CLmUiRefAppView::LaunchMultiLandmarkSelectorDialogL() 00422 { 00423 // Launch LMK Selector 00424 iLmkSelectDlg = CLmkLandmarkSelectorDlg::NewL(); 00425 iLmkSelectDlg->SetMopParent(this); 00426 RArray<TLmkItemIdDbCombiInfo> selItemArray; 00427 TInt retVal = iLmkSelectDlg->ExecuteLD( selItemArray ); 00428 TInt count = selItemArray.Count(); 00429 if ( count > 0 ) 00430 { 00431 CPosLandmarkDatabase* pDb = selItemArray[0].GetLmDb(); 00432 delete( pDb ); 00433 } 00434 selItemArray.Close(); 00435 return retVal; 00436 } 00437 00438 //-------------------------------------------------------------------------- 00439 // CLmUiRefAppView::LaunchLandmarksDialogL() 00440 // -------------------------------------------------------------------------- 00441 // 00442 TInt CLmUiRefAppView::LaunchMultiCategorySelectorDialogL() 00443 { 00444 // Launch multiple Category Selector 00445 iCategorySelectDlg = CLmkCategorySelectorDlg::NewL(); 00446 iCategorySelectDlg->SetMopParent(this); 00447 RArray<TLmkItemIdDbCombiInfo> selItemArray; 00448 TInt retVal = iCategorySelectDlg->ExecuteLD( selItemArray ); 00449 TInt count = selItemArray.Count(); 00450 if ( count > 0 ) 00451 { 00452 CPosLandmarkDatabase* pDb = selItemArray[0].GetLmDb(); 00453 delete( pDb ); 00454 } 00455 selItemArray.Close(); 00456 return retVal; 00457 } 00458 00459 // -------------------------------------------------------------------------- 00460 // CLmUiRefAppView::LaunchSingleCategoeyDialogL() 00461 // -------------------------------------------------------------------------- 00462 // 00463 TInt CLmUiRefAppView::LaunchSingleCategoeyDialogL() 00464 { 00465 // Launch single category selector 00466 iCategorySelectDlg = CLmkCategorySelectorDlg::NewL(); 00467 iCategorySelectDlg->SetMopParent(this); 00468 TLmkItemIdDbCombiInfo selItem; 00469 TInt retVal = iCategorySelectDlg->ExecuteLD( selItem ); 00470 if (retVal !=0) 00471 { 00472 iSelectedItem = selItem.GetItemId(); 00473 ilDb = selItem.GetLmDb(); 00474 } 00475 return retVal; 00476 } 00477 00478 00479 // End of File
|
© Nokia 2009 |