pimappservices/calendar/shared/src/agmtzrules.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 <vtzrules.h>
       
    17 #include "agmtzrules.h"
       
    18 #include "agmtlsproxy.h"
       
    19 
       
    20 CAgnTzRules* CAgnTzRules::NewL()
       
    21 	{
       
    22 	CAgnTzRules* self = new (ELeave) CAgnTzRules();
       
    23 	CleanupStack::PushL(self);
       
    24 	self->ConstructL();
       
    25 	CleanupStack::Pop(self);
       
    26 	return self;
       
    27 	}
       
    28 
       
    29 CAgnTzRules* CAgnTzRules::NewL(const CTzRules& aTzRules)
       
    30 	{
       
    31 	CAgnTzRules* self = new (ELeave) CAgnTzRules();
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL(aTzRules);
       
    34 	CleanupStack::Pop(self);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 CAgnTzRules* CAgnTzRules::NewL(RReadStream& aStream, TBool aFromBuffer)
       
    39 	{
       
    40 	CAgnTzRules* self = new (ELeave) CAgnTzRules();
       
    41 	CleanupStack::PushL(self);
       
    42 	if(aFromBuffer)
       
    43 		{
       
    44 		self->ReadBufferL(aStream);
       
    45 		}
       
    46 	else
       
    47 		{
       
    48 		self->DoInternalizeL(aStream);
       
    49 		}
       
    50 	CleanupStack::Pop(self);
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 CAgnTzRules::~CAgnTzRules()
       
    55 	{
       
    56 	if(iTzRules && !SharedWithTzIndex())
       
    57 		{
       
    58 		CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
    59 		tlsProxy->ReferenceRemoved(iTzRules);
       
    60 		}
       
    61 	}
       
    62 
       
    63 CAgnTzRules::CAgnTzRules()
       
    64 	: iTzRules(NULL), iTzZoneStreamId(KNullStreamId), iSharedInTzIndex(EFalse), iUseCurSysTzZone(EFalse)
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CAgnTzRules::ConstructL()
       
    69 	{
       
    70 	CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
    71 	iTzRules = tlsProxy->GetCurrentSystemTzRulesL();
       
    72 	SetUseCurrentSystemTzRules(ETrue);
       
    73 	}
       
    74 
       
    75 void CAgnTzRules::ConstructL(const CTzRules& aTzRules)
       
    76 	{
       
    77 	CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
    78 	iTzRules = tlsProxy->GetZoneForRulesL(aTzRules);
       
    79 	}
       
    80 
       
    81 void CAgnTzRules::ExternalizeL(RWriteStream& aStream) const
       
    82 	{
       
    83 	aStream.WriteUint8L(iTzZoneIsSystemRule);
       
    84 	aStream << iTzZoneStreamId;
       
    85 	}
       
    86 
       
    87 void CAgnTzRules::InternalizeL(RReadStream& aStream)
       
    88 	{
       
    89 	Reset();
       
    90 	DoInternalizeL(aStream);
       
    91 	}
       
    92 
       
    93 void CAgnTzRules::DoInternalizeL(RReadStream& aStream)
       
    94 	{
       
    95  	iTzZoneIsSystemRule = aStream.ReadUint8L();
       
    96   	aStream >> iTzZoneStreamId;
       
    97 	}
       
    98 
       
    99 void CAgnTzRules::Reset()
       
   100 	{
       
   101 	if(iTzRules && !SharedWithTzIndex())
       
   102 		{
       
   103 		CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
   104 		tlsProxy->ReferenceRemoved(iTzRules);
       
   105 		}
       
   106 	
       
   107 	iTzRules = NULL;
       
   108 	SetTzZoneStreamId(KNullStreamId);
       
   109 	SetSystemTzRule(EFalse);
       
   110 	SetSharedWithTzIndex(EFalse);
       
   111 	SetUseCurrentSystemTzRules(EFalse);
       
   112 	}
       
   113 
       
   114 //Externalize to buffer used by client to server requests.
       
   115 void CAgnTzRules::WriteToBufferL(RWriteStream& aStream)
       
   116 	{
       
   117 	if(iTzRules == NULL || UseCurrentSystemTzRules())
       
   118 		{
       
   119 	   	aStream.WriteUint8L(ETrue);
       
   120 	   	if(iTzRules == NULL)
       
   121 	   		{
       
   122 			CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
   123 			iTzRules = tlsProxy->GetCurrentSystemTzRulesL();
       
   124 			SetUseCurrentSystemTzRules(ETrue);
       
   125 	   		}
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 	   	aStream.WriteUint8L(EFalse);
       
   130 	  	aStream << *iTzRules;;
       
   131 		}
       
   132 		
       
   133 	aStream.WriteUint8L(iTzZoneIsSystemRule);
       
   134   	aStream << iTzZoneStreamId;
       
   135 	}
       
   136 	
       
   137 //Internalize from buffer used by client to server requests.
       
   138 void CAgnTzRules::ReadBufferL(RReadStream& aStream)
       
   139 	{
       
   140 	Reset();
       
   141 	iUseCurSysTzZone = aStream.ReadUint8L();
       
   142   	
       
   143 	CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
   144   	if(UseCurrentSystemTzRules())
       
   145   		{
       
   146 		iTzRules = tlsProxy->GetCurrentSystemTzRulesL();
       
   147   		}
       
   148   	else
       
   149   		{
       
   150   		CTzRules* tzRules = CTzRules::NewL(aStream);
       
   151   		CleanupStack::PushL(tzRules);
       
   152   		iTzRules = tlsProxy->GetZoneForRulesL(*tzRules); // not owned
       
   153   		CleanupStack::PopAndDestroy(tzRules);
       
   154 		}
       
   155   	
       
   156  	iTzZoneIsSystemRule = aStream.ReadUint8L();
       
   157 	aStream >> iTzZoneStreamId;
       
   158 	}
       
   159 	
       
   160 EXPORT_C const CTzRules* CAgnTzRules::TzRules() const
       
   161 	{
       
   162 	return iTzRules;
       
   163 	}
       
   164 
       
   165 EXPORT_C void CAgnTzRules::SetTzRules(CTzRules* aTzRules)
       
   166 	{
       
   167 	if(iTzRules && !SharedWithTzIndex())
       
   168 		{
       
   169 		CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
   170 		tlsProxy->ReferenceRemoved(iTzRules);
       
   171 		}
       
   172 	
       
   173 	iTzRules = aTzRules;
       
   174 	SetSharedWithTzIndex(ETrue);
       
   175 	}
       
   176 
       
   177 CAgnTzRules* CAgnTzRules::CloneL() const
       
   178 	{
       
   179 	CAgnTzRules* tzZone = new (ELeave) CAgnTzRules();
       
   180 	CleanupStack::PushL(tzZone);
       
   181 	tzZone->CopyL(*this);
       
   182 	CleanupStack::Pop(tzZone);
       
   183 	return tzZone;
       
   184 	}
       
   185 
       
   186 CTzRules* CAgnTzRules::CloneTzRulesL() const
       
   187 	{
       
   188 	if(iTzRules)
       
   189 		{
       
   190 		return iTzRules->CloneL();
       
   191 		}
       
   192 	return NULL;
       
   193 	}
       
   194 
       
   195 void CAgnTzRules::CopyL(const CAgnTzRules& aAgnTzRules)
       
   196 	{
       
   197 	Reset();
       
   198 	if(aAgnTzRules.iTzRules) 
       
   199 		{
       
   200 		if(!aAgnTzRules.SharedWithTzIndex())
       
   201 			{
       
   202 			CAgnTlsProxy* tlsProxy = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
   203 			iTzRules = tlsProxy->GetZoneForRulesL(*aAgnTzRules.iTzRules);
       
   204 			}
       
   205 		else
       
   206 			{
       
   207 			iTzRules = aAgnTzRules.iTzRules;
       
   208 			SetSharedWithTzIndex(ETrue);
       
   209 			}
       
   210 		}
       
   211 	
       
   212 	SetSystemTzRule(aAgnTzRules.SystemTzRule());
       
   213 	SetUseCurrentSystemTzRules(aAgnTzRules.UseCurrentSystemTzRules());
       
   214 	SetTzZoneStreamId(aAgnTzRules.TzZoneStreamId());
       
   215 	}
       
   216 
       
   217 EXPORT_C TStreamId CAgnTzRules::TzZoneStreamId() const
       
   218 	{
       
   219 	return (iTzZoneStreamId);
       
   220 	}
       
   221 
       
   222 EXPORT_C TBool CAgnTzRules::HasValidTzZoneStreamId() const
       
   223 	{
       
   224 	return (iTzZoneStreamId != KNullStreamId);
       
   225 	}
       
   226 
       
   227 EXPORT_C void CAgnTzRules::SetTzZoneStreamId(TStreamId aStreamId)
       
   228 	{
       
   229 	(iTzZoneStreamId = aStreamId);
       
   230 	}
       
   231 
       
   232 EXPORT_C TBool CAgnTzRules::SystemTzRule() const
       
   233 	{
       
   234 	return (iTzZoneIsSystemRule);
       
   235 	}
       
   236 
       
   237 EXPORT_C void CAgnTzRules::SetSystemTzRule(TBool aIsSystemRule)
       
   238 	{
       
   239 	(iTzZoneIsSystemRule = aIsSystemRule);
       
   240 	}
       
   241 
       
   242 TBool CAgnTzRules::SharedWithTzIndex() const
       
   243 	{
       
   244 	return (iSharedInTzIndex);
       
   245 	}
       
   246 
       
   247 void CAgnTzRules::SetSharedWithTzIndex(TBool aSharedWithTzIndex)
       
   248 	{
       
   249 	(iSharedInTzIndex = aSharedWithTzIndex);
       
   250 	}
       
   251 
       
   252 EXPORT_C TBool CAgnTzRules::UseCurrentSystemTzRules() const
       
   253 	{
       
   254 	return (iUseCurSysTzZone);
       
   255 	}
       
   256 
       
   257 EXPORT_C void CAgnTzRules::SetUseCurrentSystemTzRules(TBool aUseCurrentSystemTzRules)
       
   258 	{
       
   259 	(iUseCurSysTzZone = aUseCurrentSystemTzRules);
       
   260 	}