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 #include <e32base.h>
00031 #include <badesca.h>
00032
00033 #include "TZLocalizerEngine.h"
00034 const TInt KBufSize=30;
00035
00036 _LIT( KTab, "\t");
00037 _LIT( KEmpty, " ");
00038 _LIT(KDateTimeString, "%*E%*D%X%*N%*Y %1 %2 '%3 %H%:1%T%:2%S");
00039
00040
00041
00042
00043
00044 CTZLocalizerEngine* CTZLocalizerEngine::NewL()
00045 {
00046 CTZLocalizerEngine* self = CTZLocalizerEngine::NewLC();
00047 CleanupStack::Pop( self );
00048 return self;
00049 }
00050
00051
00052
00053
00054
00055 CTZLocalizerEngine* CTZLocalizerEngine::NewLC()
00056 {
00057 CTZLocalizerEngine* self = new( ELeave ) CTZLocalizerEngine();
00058 CleanupStack::PushL( self );
00059
00060 self->ConstructL();
00061 return self;
00062 }
00063
00064
00065
00066
00067
00068 CTZLocalizerEngine::~CTZLocalizerEngine()
00069 {
00070 }
00071
00072
00073
00074
00075
00076 CTZLocalizerEngine::CTZLocalizerEngine()
00077 {
00078 }
00079
00080
00081
00082
00083
00084 void CTZLocalizerEngine::ConstructL()
00085 {
00086 }
00087
00088
00089
00090
00091
00092 TPtrC CTZLocalizerEngine::GetCityName(CTzLocalizedCity *aLocalizedCity)
00093 {
00094 return aLocalizedCity->Name();
00095 }
00096
00097
00098
00099
00100
00101 TUint16 CTZLocalizerEngine::GetCityTimeZoneId(CTzLocalizedCity *aLocalizedCity)
00102 {
00103 return aLocalizedCity->TimeZoneId();
00104 }
00105
00106
00107
00108
00109
00110 TUint8 CTZLocalizerEngine::GetCityGroupId(CTzLocalizedCity *aLocalizedCity)
00111 {
00112 return aLocalizedCity->GroupId();
00113 }
00114
00115
00116
00117
00118
00119 HBufC* CTZLocalizerEngine::GetCityLocalTimeL(CTzLocalizedCity *aLocalizedCity)
00120 {
00121 RTz tzServer;
00122 User::LeaveIfError(tzServer.Connect());
00123 CleanupClosePushL(tzServer);
00124
00125 TBuf<KBufSize> dateTimeString;
00126 TTime time;
00127 time.HomeTime();
00128 time.FormatL(dateTimeString, KDateTimeString);
00129
00130
00131
00132 TInt results=tzServer.ConvertToUniversalTime(time);
00133
00134
00135 CTzId* timezoneId = CTzId::NewL(GetCityTimeZoneId(aLocalizedCity));
00136 CleanupStack::PushL(timezoneId);
00137
00138 results=tzServer.ConvertToLocalTime(time,*timezoneId);
00139
00140 TBuf<KBufSize> timeZoneString;
00141 timeZoneString.Copy(timezoneId->TimeZoneNameID());
00142 time.FormatL(dateTimeString, KDateTimeString);
00143
00144 CleanupStack::PopAndDestroy(timezoneId);
00145
00146 HBufC* temp = HBufC::NewL(dateTimeString.Size());
00147 (*temp)= dateTimeString;
00148
00149 CleanupStack::PopAndDestroy(1);
00150
00151 return temp;
00152 }
00153
00154
00155
00156
00157
00158
00159 CTzLocalizedCity* CTZLocalizerEngine::FindCityL(const TDesC& aCityName )
00160 {
00161 CTzLocalizer* loc = CTzLocalizer::NewL();
00162 CleanupStack::PushL(loc);
00163
00164 CTzLocalizedCity* localizedCity = loc->FindCityByNameL(aCityName);
00165
00166 CleanupStack::PopAndDestroy(loc);
00167
00168 return localizedCity;
00169 }
00170
00171
00172
00173
00174
00175 CDesC16ArrayFlat* CTZLocalizerEngine::GetAllTimeZonesL()
00176 {
00177 CTzLocalizer* loc = CTzLocalizer::NewL();
00178 CleanupStack::PushL(loc);
00179
00180 CTzLocalizedCityArray* locCityArray =
00181 loc->GetCitiesL(loc->ETzUTCAscending);
00182 CleanupStack::PushL(locCityArray);
00183
00184 CDesC16ArrayFlat* timeZones =
00185 new (ELeave)CDesC16ArrayFlat( locCityArray->Count() );
00186
00187 TBuf<KBufSize> temp;
00188 TInt result;
00189 TInt k = 0;
00190 for(TInt i=0; i<locCityArray->Count();i++)
00191 {
00192 result = 0;
00193
00194 temp.Num((locCityArray->At(i)).TimeZoneId());
00195 result = timeZones->Find(temp, k);
00196
00197 if(result!=0)
00198 {
00199 timeZones->AppendL(temp);
00200 }
00201 }
00202
00203 timeZones->Sort();
00204
00205 CleanupStack::PopAndDestroy(2);
00206 return timeZones;
00207 }
00208
00209
00210
00211
00212
00213 CDesC16ArrayFlat* CTZLocalizerEngine::GetAllGroupIDL()
00214 {
00215 CTzLocalizer* loc = CTzLocalizer::NewL();
00216 CleanupStack::PushL(loc);
00217
00218 CTzLocalizedCityArray* locCityArray =
00219 loc->GetCitiesL(loc->ETzUTCAscending);
00220 CleanupStack::PushL(locCityArray);
00221
00222 CDesC16ArrayFlat* groupIDs =
00223 new (ELeave)CDesC16ArrayFlat( locCityArray->Count() );
00224
00225 TBuf<KBufSize> temp;
00226 TInt result;
00227 TInt k = 0;
00228 for(TInt i=0; i<locCityArray->Count();i++)
00229 {
00230 result = 0;
00231
00232 temp.Num((locCityArray->At(i)).GroupId());
00233 result = groupIDs->Find(temp, k);
00234
00235 if(result!=0)
00236 {
00237 groupIDs->AppendL(temp);
00238 }
00239 }
00240
00241 groupIDs->Sort();
00242
00243 CleanupStack::PopAndDestroy(2);
00244 return groupIDs;
00245 }
00246
00247
00248
00249
00250
00251 CDesC16ArrayFlat* CTZLocalizerEngine::GetAllCitiesL()
00252 {
00253 CTzLocalizer* loc = CTzLocalizer::NewL();
00254 CleanupStack::PushL(loc);
00255
00256 CTzLocalizedCityArray* locCityArray =
00257 loc->GetCitiesL(loc->ETzAlphaNameAscending);
00258 CleanupStack::PushL(locCityArray);
00259
00260 CDesC16ArrayFlat* locCity =
00261 new (ELeave)CDesC16ArrayFlat( locCityArray->Count() );
00262
00263 for(TInt i=0; i<locCityArray->Count();i++)
00264 {
00265 locCity->AppendL((locCityArray->At(i)).Name());
00266 }
00267
00268 CleanupStack::PopAndDestroy(2);
00269
00270 return locCity;
00271 }
00272
00273
00274
00275
00276
00277
00278
00279 CTzLocalizedCity* CTZLocalizerEngine::AddCityL(TInt aTimeZoneId,
00280 const TDesC &aCityName, TInt aGroupId)
00281 {
00282 CTzLocalizer* loc = CTzLocalizer::NewL();
00283 CleanupStack::PushL(loc);
00284 CTzLocalizedCity* localizedCity = NULL;
00285 TRAPD(error,localizedCity = loc->AddCityL(aTimeZoneId, aCityName, aGroupId));
00286
00287 if(error!=KErrNone)
00288 {
00289 localizedCity = NULL;
00290 }
00291 CleanupStack::PopAndDestroy(loc);
00292
00293 return localizedCity;
00294 }
00295
00296
00297
00298
00299
00300
00301 CDesC16ArrayFlat* CTZLocalizerEngine::FindCitiesInGroupL( TInt aGroupID )
00302 {
00303 CTzLocalizer* loc = CTzLocalizer::NewL();
00304 CleanupStack::PushL(loc);
00305
00306 CTzLocalizedCityArray* locCityArray
00307 = loc->GetCitiesInGroupL(aGroupID, loc->ETzAlphaNameAscending);
00308 CleanupStack::PushL(locCityArray);
00309
00310 CDesC16ArrayFlat* locCity =
00311 new (ELeave)CDesC16ArrayFlat( locCityArray->Count() );
00312
00313 TBuf<KBufSize> temp;
00314
00315 for(TInt i=0; i<locCityArray->Count();i++)
00316 {
00317 temp.Copy( KTab );
00318 temp.Append((locCityArray->At(i)).Name());
00319 temp.Append( KTab );
00320 temp.Append( KEmpty );
00321 locCity->AppendL(temp);
00322 }
00323
00324 CleanupStack::PopAndDestroy(2);
00325
00326 return locCity;
00327 }
00328
00329
00330
00331
00332
00333 void CTZLocalizerEngine::RemoveCityL(const TDesC& aCityName )
00334 {
00335 CTzLocalizer* loc = CTzLocalizer::NewL();
00336 CleanupStack::PushL(loc);
00337 CTzLocalizedCity* localizedCity = FindCityL(aCityName);
00338
00339 loc->RemoveCityL(localizedCity);
00340 CleanupStack::PopAndDestroy(loc);
00341 }
00342
00343