|
1 // Copyright (c) 2004-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 "agmgsentry.h" |
|
17 #include "agmpanic.h" |
|
18 |
|
19 #include <s32stor.h> |
|
20 |
|
21 // TGsChildRefData |
|
22 EXPORT_C TGsChildRefData::TGsChildRefData(TCalLocalUid aChildId, const TAgnCalendarTime& aRecurId) |
|
23 : iChildId(aChildId), iRecurrenceId(aRecurId) |
|
24 { |
|
25 } |
|
26 |
|
27 EXPORT_C TCalLocalUid TGsChildRefData::ChildId() const |
|
28 { |
|
29 return iChildId; |
|
30 } |
|
31 |
|
32 EXPORT_C const TAgnCalendarTime& TGsChildRefData::RecurrenceId() const |
|
33 { |
|
34 return iRecurrenceId; |
|
35 } |
|
36 |
|
37 |
|
38 // CGsData |
|
39 CGsData::CGsData() |
|
40 { |
|
41 } |
|
42 |
|
43 CGsData::CGsData(TInt aSeq, CCalEntry::TMethod aMethod) |
|
44 { |
|
45 iSeqNum = aSeq; |
|
46 iMethod = aMethod; |
|
47 } |
|
48 |
|
49 CGsData::~CGsData() |
|
50 { |
|
51 delete iGuid; |
|
52 } |
|
53 |
|
54 void CGsData::SetSequenceNumber(TInt aNum) |
|
55 { |
|
56 iSeqNum = aNum; |
|
57 } |
|
58 |
|
59 TInt CGsData::SequenceNumber() const |
|
60 { |
|
61 return iSeqNum; |
|
62 } |
|
63 |
|
64 void CGsData::SetMethod(CCalEntry::TMethod aMethod) |
|
65 { |
|
66 iMethod = aMethod; |
|
67 } |
|
68 |
|
69 CCalEntry::TMethod CGsData::Method() const |
|
70 { |
|
71 return iMethod; |
|
72 } |
|
73 |
|
74 const TDesC8& CGsData::Guid() const |
|
75 { |
|
76 if(iGuid) |
|
77 { |
|
78 return *iGuid; |
|
79 } |
|
80 return KNullDesC8; |
|
81 } |
|
82 |
|
83 void CGsData::SetGuid(HBufC8* aGuid) |
|
84 { |
|
85 delete iGuid; |
|
86 iGuid = aGuid; |
|
87 } |
|
88 |
|
89 void CGsData::ExternalizeL(RWriteStream& aStream) const |
|
90 { |
|
91 aStream.WriteInt32L(iSeqNum); |
|
92 aStream.WriteInt8L(iMethod); |
|
93 ExternalizeTypeSpecificDataL(aStream, EFalse); |
|
94 } |
|
95 |
|
96 void CGsData::ExternalizeToBufferL(RWriteStream& aStream) const |
|
97 { |
|
98 aStream.WriteInt32L(iSeqNum); |
|
99 aStream.WriteInt8L(iMethod); |
|
100 ExternalizeTypeSpecificDataL(aStream, ETrue); |
|
101 } |
|
102 |
|
103 void CGsData::InternalizeL(RReadStream& aStream) |
|
104 { |
|
105 iSeqNum = aStream.ReadInt32L(); |
|
106 iMethod = static_cast<CCalEntry::TMethod> (aStream.ReadInt8L()); |
|
107 InternalizeTypeSpecificDataL(aStream, EFalse); |
|
108 } |
|
109 |
|
110 void CGsData::InternalizeFromBufferL(RReadStream& aStream) |
|
111 { |
|
112 iSeqNum = aStream.ReadInt32L(); |
|
113 iMethod = static_cast<CCalEntry::TMethod> (aStream.ReadInt8L()); |
|
114 InternalizeTypeSpecificDataL(aStream, ETrue); |
|
115 } |
|
116 |
|
117 // CGsParentEntryData |
|
118 void CGsParentData::RemoveChildId(TCalLocalUid aId) |
|
119 { |
|
120 TInt pos = FindChildId(aId); |
|
121 if (pos != KErrNotFound) |
|
122 { |
|
123 iChildIds->Remove(pos); |
|
124 } |
|
125 } |
|
126 |
|
127 void CGsParentData::AddChildIdL(const TGsChildRefData& aChildData) |
|
128 { |
|
129 TInt pos = FindChildId(aChildData.ChildId()); |
|
130 if (pos == KErrNotFound) |
|
131 { |
|
132 User::LeaveIfError(iChildIds->Append(aChildData)); |
|
133 } |
|
134 } |
|
135 |
|
136 CGsParentData::~CGsParentData() |
|
137 { |
|
138 if (iChildIds) |
|
139 { |
|
140 iChildIds->Close(); |
|
141 } |
|
142 delete iChildIds; |
|
143 } |
|
144 |
|
145 CGsParentData* CGsParentData::NewL() |
|
146 { |
|
147 return new (ELeave) CGsParentData(); |
|
148 } |
|
149 |
|
150 CGsParentData* CGsParentData::NewL(HBufC8* aUid, TInt aSeqNum, CCalEntry::TMethod aMethod) |
|
151 { |
|
152 CGsParentData* self = new (ELeave) CGsParentData(aSeqNum, aMethod); |
|
153 CleanupStack::PushL(self); |
|
154 self->ConstructL(); |
|
155 self->SetGuid(aUid); // set GUID last because ownership taken |
|
156 CleanupStack::Pop(self); |
|
157 return self; |
|
158 } |
|
159 |
|
160 CGsParentData::CGsParentData(TInt aSeqNum, CCalEntry::TMethod aMethod) |
|
161 :CGsData(aSeqNum, aMethod) |
|
162 { |
|
163 } |
|
164 |
|
165 void CGsParentData::ConstructL() |
|
166 { |
|
167 iChildIds = new (ELeave) RArray<TGsChildRefData>(); |
|
168 } |
|
169 |
|
170 CGsParentData::CGsParentData() |
|
171 { |
|
172 } |
|
173 |
|
174 void CGsParentData::ExternalizeTypeSpecificDataL(RWriteStream& aStream, TBool /*aToBuffer*/) const |
|
175 { |
|
176 aStream.WriteUint16L(Guid().Length()); |
|
177 aStream << Guid(); |
|
178 |
|
179 const TInt KCount = iChildIds->Count(); |
|
180 aStream.WriteInt32L(KCount); |
|
181 |
|
182 for (TInt i = 0; i < KCount; ++i) |
|
183 { |
|
184 aStream << (*iChildIds)[i].ChildId(); |
|
185 aStream << (*iChildIds)[i].RecurrenceId(); |
|
186 } |
|
187 } |
|
188 |
|
189 void CGsParentData::InternalizeTypeSpecificDataL(RReadStream& aStream, TBool /*aFromBuffer*/) |
|
190 { |
|
191 TUint16 length = aStream.ReadUint16L(); |
|
192 HBufC8* guid = HBufC8::NewL(aStream,length); |
|
193 SetGuid(guid); |
|
194 |
|
195 iChildIds = new (ELeave) RArray<TGsChildRefData>(); |
|
196 |
|
197 TAgnCalendarTime recurId; |
|
198 const TInt KCount = aStream.ReadInt32L(); |
|
199 |
|
200 for (TInt i = 0; i < KCount; ++i) |
|
201 { |
|
202 TCalLocalUid childId = aStream.ReadUint32L(); |
|
203 aStream >> recurId; |
|
204 |
|
205 TGsChildRefData childData(childId, recurId); |
|
206 iChildIds->AppendL(childData); |
|
207 } |
|
208 } |
|
209 |
|
210 TInt CGsParentData::FindChildId(TCalLocalUid aChildId) const |
|
211 { |
|
212 const TInt KCount = iChildIds->Count(); |
|
213 for (TInt i = 0; i < KCount; ++i) |
|
214 { |
|
215 if ((*iChildIds)[i].ChildId() == aChildId) |
|
216 { |
|
217 return i; |
|
218 } |
|
219 } |
|
220 return KErrNotFound; |
|
221 } |
|
222 |
|
223 const RArray<TGsChildRefData>& CGsParentData::ChildIds() const |
|
224 { |
|
225 return *iChildIds; |
|
226 } |
|
227 |
|
228 CGsData::TGsDataType CGsParentData::GsDataType() const |
|
229 { |
|
230 return CGsData::EParent; |
|
231 } |
|
232 |
|
233 void CGsParentData::CopyDataL(const CGsData& aSource) |
|
234 { |
|
235 if (aSource.GsDataType() == CGsData::EParent) |
|
236 { |
|
237 iChildIds->Reset(); |
|
238 |
|
239 const RArray<TGsChildRefData>& sourceChild = static_cast <const CGsParentData&> (aSource).ChildIds(); |
|
240 |
|
241 const TInt KCount = sourceChild.Count(); |
|
242 for (TInt ii = 0; ii<KCount; ++ii) |
|
243 { |
|
244 iChildIds->AppendL((sourceChild)[ii]); |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 TAgnCalendarTime CGsParentData::RecurrenceId() const |
|
250 { |
|
251 return TAgnCalendarTime(); |
|
252 } |
|
253 |
|
254 CalCommon::TRecurrenceRange CGsParentData::RecurrenceRange() const |
|
255 { |
|
256 return CalCommon::EThisOnly; |
|
257 } |
|
258 |
|
259 // CGsChildEntryData |
|
260 CGsData::TGsDataType CGsChildData::GsDataType() const |
|
261 { |
|
262 return CGsData::EChild; |
|
263 } |
|
264 |
|
265 void CGsChildData::CopyDataL(const CGsData& aSource) |
|
266 { |
|
267 if (aSource.GsDataType() == CGsData::EChild) |
|
268 { |
|
269 iParentId = static_cast <const CGsChildData&>(aSource).ParentId(); |
|
270 } |
|
271 } |
|
272 |
|
273 void CGsChildData::ExternalizeTypeSpecificDataL(RWriteStream& aStream, TBool aToBuffer) const |
|
274 { |
|
275 aStream << iParentId; |
|
276 if(aToBuffer) |
|
277 { |
|
278 if (Guid().Length() > 0) |
|
279 { |
|
280 aStream.WriteUint16L(Guid().Length()); |
|
281 aStream << Guid(); |
|
282 } |
|
283 else |
|
284 { |
|
285 aStream.WriteUint16L(0); |
|
286 } |
|
287 aStream << iRecurrenceId; |
|
288 aStream.WriteUint8L(iRecurrenceRange); |
|
289 } |
|
290 |
|
291 } |
|
292 |
|
293 void CGsChildData::InternalizeTypeSpecificDataL(RReadStream& aStream, TBool aFromBuffer) |
|
294 { |
|
295 aStream >> iParentId; |
|
296 if(aFromBuffer) |
|
297 { |
|
298 TUint16 length = aStream.ReadUint16L(); |
|
299 HBufC8* guid = NULL; |
|
300 if(length>0) |
|
301 { |
|
302 guid = HBufC8::NewL(aStream,length); |
|
303 } |
|
304 SetGuid(guid); |
|
305 aStream >> iRecurrenceId; |
|
306 iRecurrenceRange = static_cast<CalCommon::TRecurrenceRange>(aStream.ReadUint8L()); |
|
307 } |
|
308 } |
|
309 |
|
310 CGsChildData* CGsChildData::NewL() |
|
311 { |
|
312 return new (ELeave) CGsChildData();; |
|
313 } |
|
314 |
|
315 CGsChildData* CGsChildData::NewL(HBufC8* aUid, TInt aSeq, CCalEntry::TMethod aMethod, const TAgnCalendarTime& aRecurrenceId, CalCommon::TRecurrenceRange aRecurrenceRange) |
|
316 { |
|
317 CGsChildData* self = new (ELeave) CGsChildData(aSeq, aMethod, aRecurrenceId, aRecurrenceRange ); |
|
318 self->SetGuid(aUid); // set GUID last because ownership taken |
|
319 return self; |
|
320 } |
|
321 |
|
322 CGsChildData::CGsChildData(TInt aSeq, CCalEntry::TMethod aMethod, const TAgnCalendarTime& aRecurrenceId, CalCommon::TRecurrenceRange aRecurrenceRange) |
|
323 :CGsData(aSeq, aMethod) |
|
324 { |
|
325 iRecurrenceId = aRecurrenceId; |
|
326 iRecurrenceRange = aRecurrenceRange; |
|
327 } |
|
328 |
|
329 CGsChildData::CGsChildData() |
|
330 { |
|
331 } |
|
332 |
|
333 void CGsChildData::SetParentId(TCalLocalUid aParentId) |
|
334 { |
|
335 iParentId = aParentId; |
|
336 } |
|
337 |
|
338 TCalLocalUid CGsChildData::ParentId() const |
|
339 { |
|
340 return iParentId; |
|
341 } |
|
342 |
|
343 TAgnCalendarTime CGsChildData::RecurrenceId() const |
|
344 { |
|
345 return iRecurrenceId; |
|
346 } |
|
347 |
|
348 void CGsChildData::SetRecurrenceId(const TAgnCalendarTime& aRecurrenceId) |
|
349 { |
|
350 iRecurrenceId = aRecurrenceId; |
|
351 } |
|
352 |
|
353 CalCommon::TRecurrenceRange CGsChildData::RecurrenceRange() const |
|
354 { |
|
355 return iRecurrenceRange; |
|
356 } |
|
357 |
|
358 void CGsChildData::SetRecurrenceRange(CalCommon::TRecurrenceRange aRecurrenceRange) |
|
359 { |
|
360 iRecurrenceRange = aRecurrenceRange; |
|
361 } |
|
362 |