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