|
S60 3rd Edition SDK for Symbian OS 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 "LmUiRefAppDocument.h" 00028 #include "LmUiRefAppContainer.h" 00029 #include "LmUiRefAppUi.h" 00030 #include "LmUiRefAppView.h" 00031 #include "CLmkEditorDlg.h" 00032 #include "TLmkItemIdDbCombiInfo.h" //For multi db support, combiinfo struct 00033 00034 #define LMK_PARAMS (CLmkEditorDlg::ELmkOnlyName | CLmkEditorDlg::ELmkCategory | CLmkEditorDlg::ELmkStreet | CLmkEditorDlg::ELmkCity | CLmkEditorDlg::ELmkLatitude| CLmkEditorDlg::ELmkLongitude) 00035 00036 #define LMK_PARAMS_DEFAULT CLmkEditorDlg::ELmkAll 00037 00038 // ================= MEMBER FUNCTIONS ======================= 00039 //------------------------------------------------------------------------- 00040 // CLmUiRefAppView::NewLC 00041 // Two-phased constructor. 00042 //------------------------------------------------------------------------- 00043 // 00044 CLmUiRefAppView* CLmUiRefAppView::NewLC() 00045 { 00046 CLmUiRefAppView* self = 00047 new( ELeave ) CLmUiRefAppView(); 00048 CleanupStack::PushL( self ); 00049 self->ConstructL(); 00050 return self; 00051 } 00052 00053 //--------------------------------------------------------------------------- 00054 // CLmUiRefAppView::CLmUiRefAppView 00055 // C++ default constructor can NOT contain any code, that 00056 // might leave. 00057 //--------------------------------------------------------------------------- 00058 // 00059 CLmUiRefAppView::CLmUiRefAppView() 00060 { 00061 } 00062 00063 // -------------------------------------------------------------------------- 00064 // CLmUiRefAppView::ConstructL 00065 // Symbian 2nd phase constructor can leave. 00066 // -------------------------------------------------------------------------- 00067 // 00068 void CLmUiRefAppView::ConstructL() 00069 { 00070 BaseConstructL(R_LMUIREFAPP_VIEW); 00071 } 00072 00073 // -------------------------------------------------------------------------- 00074 // CLmUiRefAppView::~CLmUiRefAppView 00075 // ------------------------------------------------------------------------ 00076 // 00077 CLmUiRefAppView::~CLmUiRefAppView() 00078 { 00079 if ( iContainer ) 00080 { 00081 AppUi()->RemoveFromViewStack( *this, iContainer ); 00082 } 00083 delete iContainer; 00084 } 00085 00086 // -------------------------------------------------------------------------- 00087 // TUid CLmUiRefAppView::Id 00088 // -------------------------------------------------------------------------- 00089 // 00090 TUid CLmUiRefAppView::Id() const 00091 { 00092 return TUid::Uid(ELmUiRefAppView); 00093 } 00094 00095 // -------------------------------------------------------------------------- 00096 // CLmUiRefAppView::HandleCommandL 00097 // -------------------------------------------------------------------------- 00098 // 00099 void CLmUiRefAppView::HandleCommandL( TInt aCommand ) 00100 { 00101 switch ( aCommand ) 00102 { 00103 // these all are same: exit 00104 case EAknSoftkeyExit: 00105 case EAknSoftkeyBack: 00106 { 00107 AppUi()->HandleCommandL(EEikCmdExit); 00108 break; 00109 } 00110 case ELmUiRefAppCmdDeleteLm: 00111 { 00112 if (IsLmDbEmptyL()) 00113 { 00114 // Display some Error Note here 00115 iContainer->DrawNow(); 00116 return; 00117 } 00118 if (LaunchLandmarksDialogL() == 0) 00119 { 00120 // If Selector is cancelled, return to MAIN view 00121 iContainer->DrawNow(); 00122 return; 00123 } 00124 00125 // Display Note 00126 CEikonEnv* env = CEikonEnv::Static(); 00127 HBufC* noteText = NULL; 00128 noteText 00129 = StringLoader::LoadLC( R_LMUIREFAPP_DELETE_LANDMARK, env ); 00130 CAknQueryDialog* query = 00131 new( ELeave ) CAknQueryDialog( *noteText ); 00132 TInt ret = query->ExecuteLD( R_LMUIREFAPP_QUERY); 00133 if (!(ret)) 00134 { 00135 CleanupStack::PopAndDestroy(noteText); //noteText 00136 iContainer->DrawNow(); 00137 return; 00138 } 00139 TPosLmItemId delLmItem = SelectedItem(); 00140 ilDb->RemoveLandmarkL(delLmItem); 00141 delete ilDb; 00142 CleanupStack::PopAndDestroy(noteText); //noteText 00143 break; 00144 } 00145 00146 case ELmUiRefAppCmdNewLm : 00147 { 00148 //if to be used later on or commented because of an Error. 00149 NewLmCmdL(); 00150 break; 00151 } 00152 00153 case ELmUiRefAppCmdViewLm: 00154 { 00155 /* Launch LM Selector only when Landmarks 00156 * Database has any entries 00157 */ 00158 if (IsLmDbEmptyL()) 00159 { 00160 // Display some Error Note here 00161 iContainer->DrawNow(); 00162 return; 00163 } 00164 if (LaunchLandmarksDialogL() == 0) 00165 { 00166 // If Selector is cancelled, return to MAIN view 00167 iContainer->DrawNow(); 00168 return; 00169 } 00170 00171 CLmkEditorDlg::TLmkEditorParams editParams; 00172 editParams.iAttributes = CLmkEditorDlg::ELmkAll; 00173 editParams.iEditorMode = CLmkEditorDlg::ELmkViewer; 00174 TPosLmItemId lmItem = SelectedItem(); 00175 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(*ilDb, 00176 lmItem, 00177 editParams); 00178 dlg->ExecuteLD(); 00179 iContainer->DrawNow(); 00180 delete ilDb; 00181 break; 00182 } 00183 00184 case ELmUiRefAppCmdEditLm: 00185 { 00186 if (IsLmDbEmptyL()) 00187 { 00188 // Display some Error Note here 00189 iContainer->DrawNow(); 00190 return; 00191 } 00192 if (LaunchLandmarksDialogL() == 0) 00193 { 00194 // If Selector is cancelled, return to MAIN view 00195 iContainer->DrawNow(); 00196 return; 00197 } 00198 CPosLandmark* landmarkedi = NULL; 00199 ExecuteLmEditorL(landmarkedi, *ilDb); 00200 // Refresh 00201 iContainer->DrawNow(); 00202 delete ilDb; 00203 break; 00204 } 00205 default: 00206 break; 00207 } 00208 } 00209 00210 // -------------------------------------------------------------------------- 00211 // CLmUiRefAppView::NewLmCmdL() 00212 // -------------------------------------------------------------------------- 00213 // 00214 void CLmUiRefAppView::NewLmCmdL() 00215 { 00216 CPosLandmark* landmark = CPosLandmark::NewL(); 00217 CleanupStack::PushL( landmark ); 00218 CLmUiRefAppUi* lmUiAppUi = static_cast<CLmUiRefAppUi*>( ViewAppUi() ); 00219 CPosLandmarkDatabase& iaDb = (lmUiAppUi->Document().LmDb()); 00220 ExecuteLmEditorL( landmark, iaDb ); 00221 CleanupStack::PopAndDestroy( landmark ); 00222 } 00223 00224 // ----------------------------------------------------------------------------- 00225 // CLmUiRefAppView::ExecuteLmEditorL() 00226 // ----------------------------------------------------------------------------- 00227 void CLmUiRefAppView::ExecuteLmEditorL( 00228 CPosLandmark* aLandmark, CPosLandmarkDatabase& aDb) 00229 { 00230 CLmkEditorDlg::TLmkEditorParams editParams; 00231 editParams.iAttributes = LMK_PARAMS_DEFAULT; 00232 editParams.iEditorMode = CLmkEditorDlg::ELmkEditor; 00233 TPosLmItemId lmItem = SelectedItem(); 00234 if (aLandmark) 00235 { 00236 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(aDb, *aLandmark, editParams); 00237 dlg->ExecuteLD(); 00238 } 00239 else 00240 { 00241 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(aDb, lmItem, editParams); 00242 dlg->ExecuteLD(); 00243 } 00244 } 00245 00246 // -------------------------------------------------------------------------- 00247 // CLmUiRefAppView::DoActivateL 00248 // -------------------------------------------------------------------------- 00249 // 00250 void CLmUiRefAppView::DoActivateL( 00251 const TVwsViewId& /*aPrevViewId*/, 00252 TUid /*aCustomMessageId*/, 00253 const TDesC8& /*aCustomMessage*/ ) 00254 { 00255 if ( !iContainer ) 00256 { 00257 iContainer = CLmUiRefAppContainer::NewL(this, ClientRect() ); 00258 AppUi()->AddToStackL( *this, iContainer ); 00259 } 00260 } 00261 00262 // -------------------------------------------------------------------------- 00263 // CLmUiRefAppView::DoDeactivate 00264 // -------------------------------------------------------------------------- 00265 // 00266 void CLmUiRefAppView::DoDeactivate() 00267 { 00268 if ( iContainer ) 00269 { 00270 AppUi()->RemoveFromViewStack( *this, iContainer ); 00271 } 00272 delete iContainer; 00273 iContainer = NULL; 00274 } 00275 00276 // -------------------------------------------------------------------------- 00277 // CLmUiRefAppView::LaunchLandmarksDialogL() 00278 // -------------------------------------------------------------------------- 00279 // 00280 TInt CLmUiRefAppView::LaunchLandmarksDialogL() 00281 { 00282 // Launch LMK Selector 00283 iLmkSelectDlg = CLmkLandmarkSelectorDlg::NewL(); 00284 iLmkSelectDlg->SetMopParent(this); 00285 TLmkItemIdDbCombiInfo selItem; 00286 TInt retVal = iLmkSelectDlg->ExecuteLD( selItem ); 00287 if (retVal !=0) 00288 { 00289 iSelectedItem = selItem.GetItemId(); 00290 ilDb = selItem.GetLmDb(); 00291 } 00292 return retVal; 00293 } 00294 00295 // -------------------------------------------------------------------------- 00296 // CLmUiRefAppView::ViewAppUi() 00297 // -------------------------------------------------------------------------- 00298 // 00299 CAknViewAppUi* CLmUiRefAppView::ViewAppUi() 00300 { 00301 return static_cast<CAknViewAppUi*>( iAvkonAppUi ); 00302 } 00303 00304 // -------------------------------------------------------------------------- 00305 // CLmUiRefAppView::SelectedItem() 00306 // -------------------------------------------------------------------------- 00307 // 00308 TPosLmItemId CLmUiRefAppView::SelectedItem() const 00309 { 00310 return iSelectedItem; 00311 } 00312 00313 // -------------------------------------------------------------------------- 00314 // CLmUiRefAppView::IsLmDbEmptyL() 00315 // -------------------------------------------------------------------------- 00316 // 00317 TBool CLmUiRefAppView::IsLmDbEmptyL() 00318 { 00319 CPosLmItemIterator* itemIterator = NULL;CLmUiRefAppUi* lmUiAppUi = static_cast<CLmUiRefAppUi*>( ViewAppUi() ); 00320 CPosLandmarkDatabase& iaDb = lmUiAppUi->Document().LmDb(); 00321 00322 itemIterator = iaDb.LandmarkIteratorL(); 00323 00324 CleanupStack::PushL(itemIterator); 00325 itemIterator->Reset(); 00326 TUint nrOfItems = itemIterator->NumOfItemsL(); 00327 CleanupStack::PopAndDestroy(itemIterator); 00328 if (nrOfItems == 0) 00329 { 00330 return ETrue; 00331 } 00332 return EFalse; 00333 } 00334 00335 // --------------------------------------------------------- 00336 // CLmkByLmView::DynInitMenuPaneL 00337 // --------------------------------------------------------- 00338 // 00339 void CLmUiRefAppView::DynInitMenuPaneL( 00340 TInt aResourceId, 00341 CEikMenuPane* aMenuPane ) 00342 { 00343 switch ( aResourceId ) 00344 { 00345 case R_LMUIREFAPP_MENU1: 00346 { 00347 if (IsLmDbEmptyL()) 00348 { 00349 // Show NEW LM Menu Item 00350 aMenuPane->SetItemDimmed( ELmUiRefAppCmdEditLm, ETrue ); 00351 aMenuPane->SetItemDimmed( ELmUiRefAppCmdViewLm, ETrue ); 00352 aMenuPane->SetItemDimmed( ELmUiRefAppCmdDeleteLm, ETrue ); 00353 } 00354 break; 00355 } 00356 default: 00357 { 00358 break; 00359 } 00360 } 00361 } 00362 // End of File 00363
|
© Nokia 2006 |