00001 /* 00002 * Copyright © 2008 Nokia Corporation. 00003 */ 00004 00005 // INCLUDE FILES 00006 #include <AknQueryDialog.h> 00007 #include <t32wld.h> 00008 #include <badesca.h> 00009 #include <aknlists.h> 00010 #include <eikmenup.h> 00011 #include <aknnotewrappers.h> 00012 #include "TZLocalizerAppUi.h" 00013 #include "TZLocalizerDialog.h" 00014 #include "TZLocalizerEngine.h" 00015 #include <TZLocalizer.rsg> 00016 #include "tzlocalizer.hrh" 00017 00018 00019 #include <avkon.hrh> 00020 00021 // constants 00022 00023 const TInt KBufSize = 30; 00024 const TInt KTextBufferLength = 128; 00025 const TInt KArrayGranularity = 5; 00026 const TInt KTimeNumWidth = 2; 00027 00028 // literals for the ui 00029 _LIT( KDeleteCity , "Delete city:" ); 00030 _LIT( KNoMatchingCity, "No matching city found!"); 00031 _LIT( KCityName , "City name:" ); 00032 _LIT( KErrorAddingCity, "Error while adding new city!"); 00033 _LIT( KCityAdded, "City added."); 00034 _LIT( KCityRemoved, "City removed."); 00035 _LIT( KNewCityName , "New city name:" ); 00036 _LIT( KChooseCityGroupID , "Choose city group ID"); 00037 _LIT( KChooseTimeZoneID,"Choose Time Zone ID"); 00038 _LIT( KCityLocalTime, "\tCity local time:\t" ); 00039 _LIT( KCityGroupID, "\tCity group ID:\t"); 00040 _LIT( KCityTimeZoneID, "\tCity time zone ID:\t"); 00041 _LIT( KCityName2,"\tCity name:\t" ); 00042 00043 00044 // --------------------------------------------------------- 00045 // CTZLocalizerAppUi::ConstructL() 00046 // 00047 // --------------------------------------------------------- 00048 void CTZLocalizerAppUi::ConstructL() 00049 { 00050 BaseConstructL(EAknEnableSkin); 00051 00052 // Create engine 00053 iTzEngine = CTZLocalizerEngine::NewL(); 00054 00055 // Start dialog 00056 iAppDialog = new (ELeave) CTZLocalizerDialog; 00057 iAppDialog->SetMopParent( this ); 00058 iAppDialog->ExecuteLD( R_TZLOCALIZER_DIALOG ); 00059 } 00060 00061 // ---------------------------------------------------- 00062 // CTZLocalizerAppUi::~CTZLocalizerAppUi() 00063 // Destructor 00064 // Frees reserved resources 00065 // ---------------------------------------------------- 00066 CTZLocalizerAppUi::~CTZLocalizerAppUi() 00067 { 00068 if (iAppDialog) 00069 { 00070 delete iAppDialog; 00071 } 00072 if(iTzEngine) 00073 { 00074 delete iTzEngine; 00075 } 00076 } 00077 // ---------------------------------------------------- 00078 // CTZLocalizerAppUi::DynInitMenuPaneL() 00079 // This function is called by the EIKON framework just before 00080 // it displays a menu pane. Its default implementation is empty, 00081 // and by overriding it, the application can set the state of menu 00082 // items dynamically according to the state of application data. 00083 // ---------------------------------------------------- 00084 void CTZLocalizerAppUi::DynInitMenuPaneL( TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/) 00085 { 00086 } 00087 00088 // ---------------------------------------------------- 00089 // CTZLocalizerAppUi::HandleKeyEventL() 00090 // Standard key press information forwasion. 00091 // ---------------------------------------------------- 00092 TKeyResponse CTZLocalizerAppUi::HandleKeyEventL( const TKeyEvent& aKeyEvent, 00093 TEventCode aType ) 00094 { 00095 if( aType!=EEventKey ) 00096 { 00097 return EKeyWasNotConsumed; 00098 } 00099 00100 switch( aKeyEvent.iCode ) 00101 { 00102 case EKeyUpArrow: 00103 case EKeyDownArrow: 00104 { 00105 if( iAppDialog != NULL ) 00106 { 00107 TKeyResponse result = iAppDialog->OfferKeyEventL( aKeyEvent, 00108 aType ); 00109 return result; 00110 } 00111 } 00112 break; 00113 00114 default: 00115 break; 00116 } 00117 return EKeyWasNotConsumed; 00118 } 00119 00120 // ---------------------------------------------------- 00121 // CTZLocalizerAppUi::ShowInfoL() 00122 // Briefly shows small information note which contain 00123 // aText as message. 00124 // ---------------------------------------------------- 00125 void CTZLocalizerAppUi::ShowInfoL( const TPtrC aText ) 00126 { 00127 CAknInformationNote* infoNote = new (ELeave) CAknInformationNote(); 00128 infoNote->ExecuteLD( aText ); 00129 } 00130 00131 // ---------------------------------------------------- 00132 // CTZLocalizerAppUi::AskPopupChoiseL() 00133 // Shows a popupmenu list containing aList information 00134 // On return to aReturn is copied the chosen text and 00135 // if aIndex != NULL the index # of the chosen item 00136 // is copied to. 00137 // ---------------------------------------------------- 00138 TBool CTZLocalizerAppUi::AskPopupChoiseL( const TPtrC aPrompt, 00139 CDesC16ArrayFlat* aList, TDes& aReturn ) 00140 { 00141 TBool rVal(EFalse); 00142 00143 CEikTextListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox; 00144 CleanupStack::PushL(list); 00145 00146 // Create popup list and PUSH it. 00147 CAknPopupList* popupList = CAknPopupList::NewL( 00148 list, R_AVKON_SOFTKEYS_OK_BACK, 00149 AknPopupLayouts::EMenuWindow); 00150 CleanupStack::PushL(popupList); 00151 00152 // initialize listbox. 00153 00154 list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect); 00155 list->CreateScrollBarFrameL(ETrue); 00156 list->ScrollBarFrame()->SetScrollBarVisibilityL( 00157 CEikScrollBarFrame::EOff, 00158 CEikScrollBarFrame::EAuto); 00159 00160 list->Model()->SetItemTextArray( aList ); 00161 popupList->SetTitleL(aPrompt); 00162 00163 //If the user enters ok on a selection 00164 if (popupList->ExecuteLD()) 00165 { 00166 aReturn.Copy( (*aList)[list->CurrentItemIndex()] ); 00167 00168 rVal = ETrue; 00169 } 00170 CleanupStack::Pop(popupList); 00171 CleanupStack::PopAndDestroy(list); 00172 00173 return rVal; 00174 } 00175 00176 // ---------------------------------------------------- 00177 // CTZLocalizerAppUi::QueryTextL() 00178 // Shows a dialog with aPrompt note and waits for text 00179 // input which is then copied to aReturn 00180 // ---------------------------------------------------- 00181 TBool CTZLocalizerAppUi::QueryTextL( const TPtrC aPrompt, TDes& aReturn ) 00182 { 00183 CAknTextQueryDialog* textQuery = CAknTextQueryDialog::NewL( aReturn ); 00184 CleanupStack::PushL( textQuery ); 00185 00186 textQuery->SetPromptL( aPrompt ); 00187 CleanupStack::Pop( textQuery ); 00188 00189 return textQuery->ExecuteLD( R_DATAQUERY_DATA_QUERY ); 00190 } 00191 00192 // ---------------------------------------------------- 00193 // CTZLocalizerAppUi::HandleCommandL() 00194 // Normal menu command handling 00195 // ---------------------------------------------------- 00196 void CTZLocalizerAppUi::HandleCommandL( TInt aCommand ) 00197 { 00198 switch ( aCommand ) 00199 { 00200 case EAknSoftkeyExit: 00201 case EEikCmdExit: 00202 { 00203 Exit(); 00204 break; 00205 } 00206 // ------------------------------------------------ 00207 // Ask for (partial) city name and show the city 00208 // information in the lisbox. 00209 case ETZLocalizerCmdSearchCities: 00210 SearchCitiesL(); 00211 break; 00212 00213 // ------------------------------------------------ 00214 // Add new city to world server database. 00215 case ETZLocalizerCmdAddCity: 00216 CreateNewCityL(); 00217 break; 00218 // ------------------------------------------------ 00219 // remove city from world server database 00220 case ETZLocalizerCmdRemoveCity: 00221 DeleteCityL(); 00222 break; 00223 00224 // Search Cities In Groups 00225 case ETZLocalizerCmdSearchCitiesInGroup: 00226 SearchCitiesInGroupsL(); 00227 break; 00228 // ------------------------------------------------ 00229 default: 00230 break; 00231 } 00232 } 00233 00234 // --------------------------------------------------------- 00235 // CTZLocalizerAppUi::FillListBoxL() 00236 // Fill main dialog listbox with city information 00237 // --------------------------------------------------------- 00238 void CTZLocalizerAppUi::FillListBoxL( CTzLocalizedCity* aLocalizedCity ) 00239 { 00240 TBuf<KTextBufferLength> formatBuffer; 00241 00242 CDesC16ArrayFlat* cityInfo = 00243 new (ELeave)CDesC16ArrayFlat( KArrayGranularity ); 00244 CleanupStack::PushL( cityInfo ); 00245 00246 cityInfo->Reset(); 00247 00248 formatBuffer.Copy( KCityName2 ); 00249 formatBuffer.Append( iTzEngine->GetCityName(aLocalizedCity) ); 00250 cityInfo->AppendL( formatBuffer ); 00251 00252 formatBuffer.Copy( KCityTimeZoneID ); 00253 TBuf<KBufSize> temp; 00254 temp.Num( iTzEngine->GetCityTimeZoneId(aLocalizedCity) ); 00255 formatBuffer.Append( temp ); 00256 cityInfo->AppendL( formatBuffer ); 00257 00258 formatBuffer.Copy( KCityGroupID ); 00259 temp.Num( iTzEngine->GetCityGroupId(aLocalizedCity) ); 00260 formatBuffer.Append( temp ); 00261 cityInfo->AppendL( formatBuffer ); 00262 00263 formatBuffer.Copy( KCityLocalTime ); 00264 HBufC* time; 00265 time = iTzEngine->GetCityLocalTimeL(aLocalizedCity); 00266 formatBuffer.Append( *time ); 00267 00268 cityInfo->AppendL( formatBuffer ); 00269 00270 if (iAppDialog) 00271 { 00272 iAppDialog->SetListBoxTextL( cityInfo ); 00273 } 00274 00275 delete time; 00276 CleanupStack::PopAndDestroy( cityInfo ); 00277 } 00278 // --------------------------------------------------------- 00279 // CTZLocalizerAppUi::FillListBoxL() 00280 // Fill main dialog listbox with city information 00281 // --------------------------------------------------------- 00282 void CTZLocalizerAppUi::FillListBoxL( CDesC16ArrayFlat* aArray ) 00283 { 00284 if (iAppDialog) 00285 { 00286 iAppDialog->SetListBoxTextL( aArray ); 00287 } 00288 } 00289 00290 // --------------------------------------------------------- 00291 // CTZLocalizerAppUi::ClearListBoxL() 00292 // Clear main dialog listbox 00293 // --------------------------------------------------------- 00294 void CTZLocalizerAppUi::ClearListBoxL() 00295 { 00296 CDesC16ArrayFlat* nothing = new (ELeave)CDesC16ArrayFlat(1); 00297 CleanupStack::PushL( nothing ); 00298 if (iAppDialog) 00299 { 00300 iAppDialog->SetListBoxTextL( nothing ); 00301 } 00302 CleanupStack::PopAndDestroy(); // nothing 00303 } 00304 00305 // --------------------------------------------------------- 00306 // CTZLocalizerAppUi::CreateCityUIL() 00307 // Ask all the information about new city and create it. 00308 // --------------------------------------------------------- 00309 void CTZLocalizerAppUi::CreateNewCityL() 00310 { 00311 TBuf<KBufSize> newCity; 00312 TBuf<KBufSize> timeZoneID; 00313 TBuf<KBufSize> groupID; 00314 TPtrC text; 00315 00316 // ask a new city name 00317 text.Set(KNewCityName); 00318 if( QueryTextL( text, newCity) == EFalse ) 00319 { 00320 return; 00321 } 00322 00323 CDesC16ArrayFlat* timeZones = iTzEngine->GetAllTimeZonesL(); 00324 00325 // choose time zone ID 00326 text.Set(KChooseTimeZoneID); 00327 if( AskPopupChoiseL( text, timeZones, timeZoneID ) == EFalse ) 00328 { 00329 return; 00330 } 00331 00332 CDesC16ArrayFlat* groupdIDs = iTzEngine->GetAllGroupIDL(); 00333 00334 // choose group zone ID 00335 text.Set(KChooseCityGroupID); 00336 if( AskPopupChoiseL( text, groupdIDs, groupID ) == EFalse ) 00337 { 00338 return; 00339 } 00340 00341 TInt tzID; 00342 TLex lexTimeZone(timeZoneID); 00343 lexTimeZone.Val(tzID); 00344 00345 TInt grID; 00346 TLex lexGroup(groupID); 00347 lexGroup.Val(grID); 00348 00349 CTzLocalizedCity* localizedCity = iTzEngine->AddCityL(tzID, newCity, grID); 00350 00351 if( !localizedCity ) 00352 { 00353 TPtrC msg(KErrorAddingCity); 00354 ShowInfoL( msg ); 00355 } 00356 else 00357 { 00358 TPtrC msg(KCityAdded); 00359 ShowInfoL( msg ); 00360 FillListBoxL( localizedCity ); 00361 } 00362 delete localizedCity; 00363 } 00364 00365 // --------------------------------------------------------- 00366 // CTZLocalizerAppUi::SearchCitiesL() 00367 // Search a city and show it in the listbox 00368 // --------------------------------------------------------- 00369 void CTZLocalizerAppUi::SearchCitiesL() 00370 { 00371 00372 TBuf<KTextBufferLength> placeName; 00373 00374 CTzLocalizedCity* localizedCity; 00375 // ask for the city name 00376 TPtrC msg(KCityName); 00377 if( QueryTextL( msg, placeName) == false ) 00378 { 00379 return; 00380 } 00381 00382 // get the city matching the search string 00383 localizedCity = iTzEngine->FindCityL( placeName ); 00384 00385 if( !localizedCity ) 00386 { 00387 TPtrC msg(KNoMatchingCity); 00388 ShowInfoL( msg ); 00389 } 00390 else 00391 { 00392 FillListBoxL( localizedCity ); 00393 } 00394 delete localizedCity; 00395 } 00396 00397 00398 // --------------------------------------------------------- 00399 // CTZLocalizerAppUi::DeleteCityL() 00400 // Delete city from world server database 00401 // --------------------------------------------------------- 00402 void CTZLocalizerAppUi::DeleteCityL() 00403 { 00404 CDesC16ArrayFlat* citiesList = iTzEngine->GetAllCitiesL(); 00405 TBuf<KTextBufferLength> cityName; 00406 00407 // ask for the city name with the list of all cities 00408 TPtrC msg(KDeleteCity); 00409 00410 if( AskPopupChoiseL( msg, citiesList, cityName ) == EFalse ) 00411 { 00412 return; 00413 } 00414 00415 iTzEngine->RemoveCityL(cityName); 00416 00417 // clear display and show "city removed" message 00418 ClearListBoxL(); 00419 TPtrC msgRemoved(KCityRemoved); 00420 ShowInfoL( msgRemoved ); 00421 } 00422 00423 // --------------------------------------------------------- 00424 // CTZLocalizerAppUi::SearchCitiesInGroupsL() 00425 // Search a city and show it in the listbox 00426 // --------------------------------------------------------- 00427 void CTZLocalizerAppUi::SearchCitiesInGroupsL() 00428 { 00429 TBuf<KBufSize> groupID; 00430 TPtrC text; 00431 00432 CDesC16ArrayFlat* groupIDs = iTzEngine->GetAllGroupIDL(); 00433 00434 // choose group zone ID 00435 text.Set(KChooseCityGroupID); 00436 if( AskPopupChoiseL( text, groupIDs, groupID ) == EFalse ) 00437 { 00438 return; 00439 } 00440 00441 TInt grID; 00442 TLex lexGroup(groupID); 00443 lexGroup.Val(grID); 00444 00445 CDesC16ArrayFlat* citiest = iTzEngine->FindCitiesInGroupL(grID); 00446 FillListBoxL(citiest); 00447 00448 citiest->Reset(); 00449 delete citiest; 00450 } 00451 00452 void CTZLocalizerAppUi::HandleResourceChangeL( TInt aType ) 00453 { 00454 CAknAppUi::HandleResourceChangeL(aType); 00455 00456 if ( aType==KEikDynamicLayoutVariantSwitch ) 00457 { 00458 if (iAppDialog) 00459 { 00460 TRect rect; 00461 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect); 00462 iAppDialog->SetRect(rect); 00463 // NOTE: Remember to send KEikDynamicLayoutVariantSwitch also to dialog 00464 iAppDialog->HandleResourceChange( aType ); 00465 } 00466 } 00467 } 00468 00469 // End of File
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.