|
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 "tzlocalizedtimezonerecord.h" |
|
17 #include "tzid.h" |
|
18 #include "tzidinternal.h" |
|
19 |
|
20 |
|
21 EXPORT_C CTzLocalizedTimeZoneRecord* CTzLocalizedTimeZoneRecord::NewL(TInt aTimeZoneId, const TDesC& aStandardName, |
|
22 const TDesC& aDaylightName, const TDesC& aShortStandardName, const TDesC& aShortDaylightName, |
|
23 TUint aResourceId) |
|
24 { |
|
25 CTzLocalizedTimeZoneRecord* self = CTzLocalizedTimeZoneRecord::NewLC(aTimeZoneId, aStandardName, |
|
26 aDaylightName, aShortStandardName, aShortDaylightName, aResourceId); |
|
27 CleanupStack::Pop(self); |
|
28 return self; |
|
29 } |
|
30 |
|
31 EXPORT_C CTzLocalizedTimeZoneRecord* CTzLocalizedTimeZoneRecord::NewLC(TInt aTimeZoneId, const TDesC& aStandardName, |
|
32 const TDesC& aDaylightName, const TDesC& aShortStandardName, const TDesC& aShortDaylightName, |
|
33 TUint aResourceId) |
|
34 { |
|
35 CTzLocalizedTimeZoneRecord* self = new(ELeave) CTzLocalizedTimeZoneRecord(aResourceId); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(aTimeZoneId, aStandardName, aDaylightName, aShortStandardName, aShortDaylightName); |
|
38 return self; |
|
39 } |
|
40 |
|
41 EXPORT_C CTzLocalizedTimeZoneRecord* CTzLocalizedTimeZoneRecord::NewL(RReadStream& aStream) |
|
42 { |
|
43 CTzLocalizedTimeZoneRecord* self = CTzLocalizedTimeZoneRecord::NewLC(aStream); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 EXPORT_C CTzLocalizedTimeZoneRecord* CTzLocalizedTimeZoneRecord::NewLC(RReadStream& aStream) |
|
49 { |
|
50 CTzLocalizedTimeZoneRecord* self = new(ELeave) CTzLocalizedTimeZoneRecord(); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aStream); |
|
53 return self; |
|
54 } |
|
55 |
|
56 EXPORT_C CTzLocalizedTimeZoneRecord::~CTzLocalizedTimeZoneRecord() |
|
57 { |
|
58 delete iStandardName; |
|
59 delete iDaylightName; |
|
60 delete iShortStandardName; |
|
61 delete iShortDaylightName; |
|
62 } |
|
63 |
|
64 EXPORT_C void CTzLocalizedTimeZoneRecord::CleanupArray(TAny* aArray) |
|
65 { |
|
66 RPointerArray<CTzLocalizedTimeZoneRecord>* array = static_cast<RPointerArray<CTzLocalizedTimeZoneRecord>* >(aArray); |
|
67 if (array) |
|
68 { |
|
69 array->ResetAndDestroy(); |
|
70 array->Close(); |
|
71 } |
|
72 } |
|
73 |
|
74 CTzLocalizedTimeZoneRecord::CTzLocalizedTimeZoneRecord() |
|
75 { |
|
76 } |
|
77 |
|
78 CTzLocalizedTimeZoneRecord::CTzLocalizedTimeZoneRecord(TUint aResourceId) |
|
79 : iResourceId(aResourceId) |
|
80 { |
|
81 } |
|
82 |
|
83 void CTzLocalizedTimeZoneRecord::ConstructL(TInt aTzId, const TDesC& aStandardName, |
|
84 const TDesC& aDaylightName, const TDesC& aShortStandardName, const TDesC& aShortDaylightName) |
|
85 { |
|
86 if (aTzId > KTzIdMax) |
|
87 { |
|
88 // This is a mess, although most of the API allows for 32 bit tz ids some of them |
|
89 // only allow for 16 bit tz ids so we accept a TInt but do check that it can fit in |
|
90 // 16 bits |
|
91 User::Leave(KErrArgument); |
|
92 } |
|
93 iId = aTzId; |
|
94 iStandardName = aStandardName.AllocL(); |
|
95 iDaylightName = aDaylightName.AllocL(); |
|
96 iShortStandardName = aShortStandardName.AllocL(); |
|
97 iShortDaylightName = aShortDaylightName.AllocL(); |
|
98 } |
|
99 |
|
100 void CTzLocalizedTimeZoneRecord::ConstructL(RReadStream& aStream) |
|
101 { |
|
102 iId = aStream.ReadUint16L(); |
|
103 iStandardName = ConstructNameL(aStream); |
|
104 iDaylightName = ConstructNameL(aStream); |
|
105 iShortStandardName = ConstructNameL(aStream); |
|
106 iShortDaylightName = ConstructNameL(aStream); |
|
107 iResourceId = aStream.ReadUint32L(); |
|
108 } |
|
109 |
|
110 HBufC* CTzLocalizedTimeZoneRecord::ConstructNameL(RReadStream& aStream) |
|
111 { |
|
112 TInt nameLength = aStream.ReadInt32L(); |
|
113 HBufC* name = HBufC::NewLC(nameLength); |
|
114 TPtr16 namePtr = name->Des(); |
|
115 aStream.ReadL(namePtr, nameLength); |
|
116 CleanupStack::Pop(name); |
|
117 return name; |
|
118 } |
|
119 |
|
120 EXPORT_C TInt CTzLocalizedTimeZoneRecord::ExternalizeSize() const |
|
121 { |
|
122 return sizeof(TUint16) + sizeof(TInt32) + iStandardName->Size() + |
|
123 sizeof(TInt32) + iDaylightName->Size() + sizeof(TInt32) + iShortStandardName->Size() + |
|
124 sizeof(TInt32) + iShortDaylightName->Size() + sizeof(TUint32); |
|
125 } |
|
126 |
|
127 EXPORT_C void CTzLocalizedTimeZoneRecord::ExternalizeL(RWriteStream& aStream) const |
|
128 { |
|
129 aStream.WriteUint16L(iId); |
|
130 aStream.WriteInt32L(iStandardName->Length()); |
|
131 aStream.WriteL(*iStandardName); |
|
132 aStream.WriteInt32L(iDaylightName->Length()); |
|
133 aStream.WriteL(*iDaylightName); |
|
134 aStream.WriteInt32L(iShortStandardName->Length()); |
|
135 aStream.WriteL(*iShortStandardName); |
|
136 aStream.WriteInt32L(iShortDaylightName->Length()); |
|
137 aStream.WriteL(*iShortDaylightName); |
|
138 aStream.WriteUint32L(iResourceId); |
|
139 } |
|
140 |
|
141 EXPORT_C TInt CTzLocalizedTimeZoneRecord::ExternalizeSize(const RPointerArray<CTzLocalizedTimeZoneRecord>& aTimeZones) |
|
142 { |
|
143 TInt bufferSize = sizeof(TInt32); |
|
144 TInt i = 0; |
|
145 TInt end = aTimeZones.Count(); |
|
146 while (i < end) |
|
147 { |
|
148 bufferSize += aTimeZones[i]->ExternalizeSize(); |
|
149 ++i; |
|
150 } |
|
151 return bufferSize; |
|
152 } |
|
153 |
|
154 EXPORT_C void CTzLocalizedTimeZoneRecord::ExternalizeL(const RPointerArray<CTzLocalizedTimeZoneRecord>& aTimeZones, |
|
155 RWriteStream& aStream) |
|
156 { |
|
157 TInt i = 0; |
|
158 TInt end = aTimeZones.Count(); |
|
159 aStream.WriteInt32L(end); |
|
160 while (i < end) |
|
161 { |
|
162 aTimeZones[i]->ExternalizeL(aStream); |
|
163 ++i; |
|
164 } |
|
165 } |
|
166 |
|
167 EXPORT_C void CTzLocalizedTimeZoneRecord::InternalizeL(RReadStream& aStream, |
|
168 RPointerArray<CTzLocalizedTimeZoneRecord>& aTimeZones) |
|
169 { |
|
170 TInt count = aStream.ReadInt32L(); |
|
171 TInt i = 0; |
|
172 aTimeZones.ReserveL(aTimeZones.Count() + count); |
|
173 while (i < count) |
|
174 { |
|
175 CTzLocalizedTimeZoneRecord* newRecord = CTzLocalizedTimeZoneRecord::NewL(aStream); |
|
176 aTimeZones.Append(newRecord); |
|
177 ++i; |
|
178 } |
|
179 } |