tzservices/tzserver/Client/Source/timezoneuserdata.cpp
changeset 0 2e3d3ce01487
child 7 fc3225a0ab43
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <tz.h>
       
    17 #include <vtzrules.h>
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <tzusernames.h>
       
    20 #include <tzuserdefineddata.h>
       
    21 #endif
       
    22 
       
    23 
       
    24 const TInt KMaxYear = 9999;
       
    25 const TInt KMaxStandardName = 255;
       
    26 const TInt KMaxShortName = 10;
       
    27 
       
    28 
       
    29 CTzUserNames::CTzUserNames()
       
    30 	{
       
    31 	}
       
    32 
       
    33 
       
    34 /**
       
    35 Destroys this CTzUserNames object.
       
    36 */
       
    37 EXPORT_C CTzUserNames::~CTzUserNames()
       
    38 	{
       
    39 	delete iStandardName;
       
    40 	delete iShortStandardName;
       
    41 	delete iDaylightName;
       
    42 	delete iShortDaylightName;	
       
    43 	delete iCityName;
       
    44 	delete iRegionName;
       
    45 	}
       
    46 
       
    47 
       
    48 void CTzUserNames::ConstructL(const TDesC& aStandardName, const TDesC& aShortStandardName, const TDesC& aDaylightName, const TDesC& aShortDaylightName, const TDesC& aCityName, const TDesC& aRegionName)
       
    49 	{
       
    50 	if(aStandardName.Length() > KMaxStandardName ||
       
    51 	   aDaylightName.Length() > KMaxStandardName ||
       
    52 	   	   aCityName.Length() > KMaxStandardName ||
       
    53 	   	 aRegionName.Length() > KMaxStandardName ||
       
    54   aShortStandardName.Length() > KMaxShortName ||
       
    55   aShortDaylightName.Length() > KMaxShortName
       
    56 			)
       
    57 		{
       
    58 		User::Leave(KErrArgument);
       
    59 		}
       
    60 	
       
    61 	iStandardName  = aStandardName.AllocL();
       
    62 	iShortStandardName = aShortStandardName.AllocL();
       
    63 	iDaylightName = aDaylightName.AllocL();
       
    64     iShortDaylightName = aShortDaylightName.AllocL();
       
    65     iCityName = aCityName.AllocL();
       
    66     iRegionName = aRegionName.AllocL();
       
    67     }
       
    68 
       
    69 
       
    70 /**
       
    71 Creates a user-defined time zone names object from the given names.
       
    72 
       
    73 @param aStandardName The standard time name.
       
    74 @param aShortStandardName The short standard time name.
       
    75 @param aDaylightName The daylight saving time name.
       
    76 @param aShortDaylightName The short daylight saving time name.
       
    77 @param aCityName The city name.
       
    78 @param aRegionName The region name.
       
    79 
       
    80 @return Pointer to a fully initialised instance of the CTzUserNames class.  The
       
    81 caller takes ownership of this object.
       
    82 */	
       
    83 EXPORT_C CTzUserNames* CTzUserNames::NewL(const TDesC& aStandardName, const TDesC& aShortStandardName, const TDesC& aDaylightName, const TDesC& aShortDaylightName, const TDesC& aCityName, const TDesC& aRegionName)
       
    84 	{
       
    85 	CTzUserNames* self = NewLC(aStandardName, aShortStandardName, aDaylightName, aShortDaylightName, aCityName, aRegionName);
       
    86 	CleanupStack::Pop(self);
       
    87 	return self;
       
    88 	}
       
    89 
       
    90 
       
    91 /**
       
    92 Creates a user-defined time zone names object from the given names leaving the
       
    93 newly created object on the cleanup stack.
       
    94 
       
    95 @param aStandardName The standard time name.
       
    96 @param aShortStandardName The short standard time name.
       
    97 @param aDaylightName The daylight saving time name.
       
    98 @param aShortDaylightName The short daylight saving time name.
       
    99 @param aCityName The city name.
       
   100 @param aRegionName The region name.
       
   101 
       
   102 @return Pointer to a fully initialised instance of the CTzUserNames class.  The
       
   103 caller takes ownership of this object.
       
   104 */	
       
   105 
       
   106 EXPORT_C CTzUserNames* CTzUserNames::NewLC(const TDesC& aStandardName, const TDesC& aShortStandardName, const TDesC& aDaylightName, const TDesC& aShortDaylightName, const TDesC& aCityName, const TDesC& aRegionName)
       
   107 	{
       
   108 	CTzUserNames* self = new(ELeave) CTzUserNames();
       
   109 	CleanupStack::PushL(self);
       
   110 	self->ConstructL(aStandardName, aShortStandardName, aDaylightName, aShortDaylightName, aCityName, aRegionName);
       
   111 	return self;
       
   112 	}
       
   113 
       
   114 
       
   115 /**
       
   116 Returns the standard time name for this object.
       
   117 
       
   118 @return The standard time name for this object
       
   119 */	
       
   120 EXPORT_C const TDesC& CTzUserNames::StandardName() const
       
   121 	{
       
   122 	return *iStandardName;		
       
   123 	}
       
   124 
       
   125 
       
   126 /**
       
   127 Returns the short standard time name for this object.
       
   128 
       
   129 @return The short standard time name for this object.
       
   130 */		
       
   131 EXPORT_C const TDesC& CTzUserNames::ShortStandardName() const
       
   132 	{
       
   133 	return *iShortStandardName;	
       
   134 	}
       
   135 
       
   136 
       
   137 /**
       
   138 Returns the daylight saving time name for this object.
       
   139 
       
   140 @return The daylight saving time name for this object.
       
   141 */	
       
   142 EXPORT_C const TDesC& CTzUserNames::DaylightSaveName() const
       
   143 	{
       
   144 	return *iDaylightName;	
       
   145 	}
       
   146 
       
   147 
       
   148 /**
       
   149 Returns the short daylight saving time name for this object.
       
   150 
       
   151 @return The short daylight saving time name for this object.
       
   152 */		
       
   153 EXPORT_C const TDesC& CTzUserNames::ShortDaylightSaveName() const
       
   154 	{
       
   155 	return *iShortDaylightName;	
       
   156 	}
       
   157 
       
   158 
       
   159 /**
       
   160 Returns the city name for this object.
       
   161 
       
   162 @return The city name for this object.
       
   163 */	
       
   164 EXPORT_C const TDesC& CTzUserNames::CityName() const
       
   165 	{
       
   166 	return *iCityName;	
       
   167 	}
       
   168 
       
   169 
       
   170 /**
       
   171 Returns the region name for this object.
       
   172 
       
   173 @return The region name for this object.
       
   174 */		
       
   175 EXPORT_C const TDesC& CTzUserNames::RegionName() const
       
   176 	{
       
   177 	return *iRegionName;	
       
   178 	}
       
   179 
       
   180 
       
   181 /**
       
   182 Externalises user-defined time zone names to the given stream.
       
   183 
       
   184 @param aStream Stream to which the object should be externalised. 
       
   185 
       
   186 @internalComponent
       
   187 */	
       
   188 EXPORT_C void CTzUserNames::ExternalizeL(RWriteStream& aStream) const
       
   189 	{
       
   190 	TInt count = iStandardName->Length();
       
   191 	aStream.WriteInt32L(count); 
       
   192 	if(count>0)	
       
   193 		{
       
   194 		aStream << *iStandardName;
       
   195 		}		
       
   196 
       
   197 	count = iShortStandardName->Length();
       
   198 	aStream.WriteInt32L(count); 
       
   199 	if(count>0)
       
   200 		{
       
   201 		aStream << *iShortStandardName;
       
   202 		}		
       
   203 	
       
   204 	count = iDaylightName->Length();
       
   205 	aStream.WriteInt32L(count); 
       
   206 	if(count>0)	
       
   207 		{
       
   208 		aStream << *iDaylightName;
       
   209 		}
       
   210 	
       
   211 	count = iShortDaylightName->Length();
       
   212 	aStream.WriteInt32L(count); 
       
   213 	if(count>0)	
       
   214 		{
       
   215 		aStream << *iShortDaylightName;
       
   216 		}
       
   217 	
       
   218 	count = iCityName->Length();
       
   219 	aStream.WriteInt32L(count); 
       
   220 	if(count>0)
       
   221 		{
       
   222 		aStream <<*iCityName;
       
   223 		}
       
   224 	
       
   225 	count = iRegionName->Length();
       
   226 	aStream.WriteInt32L(count); 
       
   227 	if(count>0)
       
   228 		{
       
   229 		aStream << *iRegionName;
       
   230 		}
       
   231 	}
       
   232 
       
   233 
       
   234 /**
       
   235 Internalizes user-defined time zone names from the given read stream.
       
   236 
       
   237 @param aStream Stream from which the object should be internalised. 
       
   238 
       
   239 @internalComponent
       
   240 */ 
       
   241 EXPORT_C void CTzUserNames::InternalizeL(RReadStream& aStream)
       
   242 	{
       
   243 	__ASSERT_DEBUG(!iStandardName && !iDaylightName && !iShortDaylightName &&
       
   244 			!iCityName && !iRegionName, User::Invariant());
       
   245 	
       
   246 	TInt count = aStream.ReadInt32L();
       
   247 	if(count)
       
   248 		{
       
   249 		iStandardName = HBufC::NewL(aStream, KMaxTInt);	
       
   250 		}
       
   251 	else
       
   252 		{
       
   253 		iStandardName = KNullDesC().AllocL();
       
   254 		}	
       
   255 			
       
   256 	count = aStream.ReadInt32L();
       
   257 	if(count)
       
   258 		{
       
   259 		iShortStandardName = HBufC::NewL(aStream, KMaxTInt);	
       
   260 		}
       
   261 	else
       
   262 		{
       
   263 		iShortStandardName = KNullDesC().AllocL();
       
   264 		}	
       
   265 
       
   266 	count = aStream.ReadInt32L();
       
   267 	if(count)
       
   268 		{
       
   269 		iDaylightName = HBufC::NewL(aStream, KMaxTInt);
       
   270 		}
       
   271 	else
       
   272 		{
       
   273 		iDaylightName = KNullDesC().AllocL();
       
   274 		}
       
   275 			
       
   276 	count = aStream.ReadInt32L();
       
   277 	if(count)
       
   278 		{
       
   279 		iShortDaylightName = HBufC::NewL(aStream, KMaxTInt);
       
   280 		}
       
   281 	else
       
   282 		{
       
   283 		iShortDaylightName = KNullDesC().AllocL();
       
   284 		}
       
   285 			
       
   286 	count = aStream.ReadInt32L();
       
   287 	if(count)
       
   288 		{
       
   289 		iCityName = HBufC::NewL(aStream, KMaxTInt);;
       
   290 		}
       
   291 	else
       
   292 		{
       
   293 		iCityName = KNullDesC().AllocL();
       
   294 		}	
       
   295 	
       
   296 	count = aStream.ReadInt32L();
       
   297 	if(count)
       
   298 		{
       
   299 		iRegionName = HBufC::NewL(aStream, KMaxTInt);;
       
   300 		}
       
   301 	else
       
   302 		{
       
   303 		iRegionName = KNullDesC().AllocL();
       
   304 		}
       
   305 	
       
   306 	__ASSERT_DEBUG(iStandardName->Length() <= KMaxStandardName &&
       
   307 				   iDaylightName->Length() <= KMaxStandardName &&
       
   308 					   iCityName->Length() <= KMaxStandardName &&
       
   309 					 iRegionName->Length() <= KMaxStandardName &&
       
   310 			  iShortStandardName->Length() <= KMaxShortName &&
       
   311 	   	      iShortDaylightName->Length() <= KMaxShortName, User::Invariant()); 
       
   312 	}
       
   313 
       
   314 
       
   315 /**
       
   316 Creates a new user-defined time zone names object from the given stream.
       
   317 
       
   318 @param aStream Stream with the time zone rules to be used to create a CTzRules
       
   319 object.
       
   320 
       
   321 @return Pointer to a fully initialised instance of the CTzUserNames class.  The
       
   322 caller takes ownership of this object.
       
   323 
       
   324 @internalComponent
       
   325 */
       
   326 EXPORT_C CTzUserNames* CTzUserNames::NewL(RReadStream& aStream)
       
   327 	{
       
   328 	CTzUserNames* self = new(ELeave) CTzUserNames();
       
   329 	CleanupStack::PushL(self);
       
   330 	self->InternalizeL(aStream);
       
   331 	CleanupStack::Pop(self);
       
   332 	return self;
       
   333 	}
       
   334 
       
   335 
       
   336 /**
       
   337 Determines the size of this object. 
       
   338 
       
   339 @return The size of CTzUserNames object.
       
   340 
       
   341 @internalComponent
       
   342 */	
       
   343 EXPORT_C TInt CTzUserNames::SizeOfObject() const
       
   344 	{
       
   345 	return 6*sizeof(TInt) + iStandardName->Size() + iShortStandardName->Size() +
       
   346 		iDaylightName->Size() + iShortDaylightName->Size() + iCityName->Size() +
       
   347 		iRegionName->Size();	
       
   348 	}
       
   349 	
       
   350 
       
   351 /**
       
   352 Creates a new CTzUserData object.
       
   353 
       
   354 @param aTzServer A connection to the time zone server.
       
   355 
       
   356 @return A fully initialised instance of the CTzUserData class.  The caller takes
       
   357 ownership of this object.
       
   358 
       
   359 @leave KErrNotReady The given connection to the time zone server is not
       
   360 connected.
       
   361 */	
       
   362 EXPORT_C CTzUserData* CTzUserData::NewL(RTz& aTzServer)
       
   363     {
       
   364 	__ASSERT_ALWAYS(aTzServer.Handle()!= 0, User::Leave(KErrNotReady));
       
   365 
       
   366   	CTzUserData* self = new(ELeave) CTzUserData(aTzServer);
       
   367 	return self;		
       
   368     };
       
   369 
       
   370 
       
   371 /**
       
   372 Destroys this CTzUserData object
       
   373 */  
       
   374 EXPORT_C CTzUserData::~CTzUserData()
       
   375 	{
       
   376 	}
       
   377 
       
   378 
       
   379 CTzUserData::CTzUserData(RTz& aTzServer)
       
   380 	:iTzServer(aTzServer)
       
   381 	{
       
   382 	}
       
   383 
       
   384 
       
   385 /**
       
   386 Creates a new user-defined time zone from the given time zone rules and time
       
   387 zone names.
       
   388 
       
   389 @param aTzUserRules The time zone rules to use for the newly created
       
   390 user-defined time zone.
       
   391 @param aTzUserNames The time zone names to use for the newly created
       
   392 user-defined time zone.
       
   393 
       
   394 @return A time zone identifier that identifies the newly created user-defined
       
   395 time zone.  The caller takes ownership of this object.
       
   396 
       
   397 @leave KErrLocked The time zone Server Backup or Restore are in progress.
       
   398 @leave KErrOverflow All the time zone user IDs have been used.
       
   399 To resolve this the user must delete one or more user defined time zones.
       
   400 
       
   401 
       
   402 @capability WriteDeviceData
       
   403 */			
       
   404 EXPORT_C CTzId* CTzUserData::CreateL(const CTzRules& aTzUserRules,
       
   405 	const CTzUserNames& aTzUserNames)
       
   406 	{
       
   407 	return iTzServer.CreateUserTimeZoneL(aTzUserRules, aTzUserNames);
       
   408 	}
       
   409 
       
   410 
       
   411 /**
       
   412 Reads the time zone rules for the given time zone identifier.
       
   413 
       
   414 @param aTzId The time zone identifier that identifies the user-defined time zone
       
   415 that is to be read.
       
   416 
       
   417 @return The time zone rules for the given time zone identifier.  The caller
       
   418 takes ownership of this object.
       
   419 
       
   420 @leave KErrNotFound The time zone names is not found for given time zone
       
   421 identifier.
       
   422 @leave KErrArgument The given time zone identifier does not identify a
       
   423 user-defined time zone.
       
   424 */				
       
   425 EXPORT_C CTzRules* CTzUserData::ReadRulesL(const CTzId& aTzId) const
       
   426 	{
       
   427 	if (!aTzId.IsUserTzId())
       
   428 		{
       
   429 		User::Leave(KErrArgument);	
       
   430 		}
       
   431 		
       
   432 	return iTzServer.GetTimeZoneRulesL(aTzId, 0, KMaxYear, ETzUtcTimeReference);
       
   433 	}
       
   434 
       
   435 
       
   436 /**
       
   437 Reads the time zone names for the given time zone identifier.
       
   438 
       
   439 @param aTzId The time zone identifier that identifies the user-defined time zone
       
   440 that is to be read.
       
   441 
       
   442 @return The time zone names for the given time zone identifier.  The caller
       
   443 takes ownership of this object.
       
   444 
       
   445 @leave KErrArgument The given time zone identifier does not identify a
       
   446 user-defined time zone.
       
   447 @leave KErrNotFound The time zone names is not found for given time zone
       
   448 identifier.
       
   449 */		
       
   450 EXPORT_C CTzUserNames* CTzUserData::ReadNamesL(const CTzId& aTzId) const
       
   451 	{
       
   452 	if (!aTzId.IsUserTzId())
       
   453 		{
       
   454 		User::Leave(KErrArgument);	
       
   455 		}
       
   456 
       
   457 	return iTzServer.GetUserTimeZoneNamesL(aTzId);
       
   458 	}
       
   459 
       
   460 
       
   461 /**
       
   462 Updates a user-defined time zone using the given time zone rules and time zone
       
   463 names.  The user-defined time zone to be updated is identified by the given time
       
   464 zone identifier.
       
   465 
       
   466 @param aTzId The time zone identifier that identifies the user-defined time zone
       
   467 that is to be read.
       
   468 @param aTzUserRules The time zone rules which are used to update the
       
   469 user-defined time zone.  The user-defined time zone is identified by the given
       
   470 time zone identifier.
       
   471 @param aTzUserNames The time zone names which are used to update the
       
   472 user-defined time zone.  The user-defined time zone is identified by the given
       
   473 time zone identifier. 
       
   474  
       
   475 @leave KErrArgument The given time zone identifier does not identify a
       
   476 user-defined time zone.
       
   477 
       
   478 @capability WriteDeviceData
       
   479 */			
       
   480 EXPORT_C void CTzUserData::UpdateL(const CTzId& aTzId, const CTzRules& aTzUserRules, const CTzUserNames& aTzUserNames)
       
   481 	{
       
   482 	if (!aTzId.IsUserTzId())
       
   483 		{
       
   484 		User::Leave(KErrArgument);	
       
   485 		}
       
   486 
       
   487     iTzServer.UpdateUserTimeZoneL(aTzId, aTzUserRules, aTzUserNames);
       
   488 	}
       
   489 
       
   490 
       
   491 /**
       
   492 Deletes the user-defined time zone identified by the given time zone identifier.
       
   493 
       
   494 The current time zone is maintained through the CTzLocalizer class.  If the
       
   495 given time zone identifier is referred to by the current time zone then the
       
   496 current time zone will revert to the default time zone specified by the system
       
   497 TZ rules database.
       
   498 
       
   499 Frequently used time zones are maintained through the CTzLocalizer class.  If
       
   500 the given time zone identifier is referred to by a frequently used time zone
       
   501 then the frequently used time zone will revert to the default time zone
       
   502 specified by the system TZ rules database.
       
   503 
       
   504 If any Calendar entries are associated with the deleted user-defined time zone
       
   505 then they will not be affected.  The Calendar entries maintain a copy of the
       
   506 associated time zone rules.
       
   507 
       
   508 @param aTzId The time zone identifier that identifies the user-defined time zone
       
   509 that is to be deleted.
       
   510  
       
   511 @leave KErrArgument The given time zone identifier does not identify a
       
   512 user-defined time zone.
       
   513 
       
   514 @capability WriteDeviceData
       
   515 */			
       
   516 EXPORT_C void CTzUserData::DeleteL(const CTzId& aTzId)
       
   517 	{
       
   518 	if (!aTzId.IsUserTzId())
       
   519 		{
       
   520 		User::Leave(KErrArgument);	
       
   521 		}
       
   522 
       
   523 	iTzServer.DeleteUserTimeZoneL(aTzId);
       
   524 	}
       
   525 
       
   526 
       
   527 /**
       
   528 Returns the time zone identifiers for all existing user-defined time zones.
       
   529 
       
   530 @param aTzIds On return the array will be populated with the time zone
       
   531 identifiers for all existing user-defined time zones.  If no user-defined time
       
   532 zones exist the array will be empty.
       
   533 */	
       
   534 EXPORT_C void CTzUserData::GetTzIdsL(RPointerArray<CTzId>& aTzIds) const
       
   535 	{
       
   536 	iTzServer.GetUserTimeZoneIdsL(aTzIds);
       
   537 	}