|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Is a serialized version of CFolderItem suitable for transfer between |
|
15 * client and server. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "PackedAttributes.h" |
|
20 #include "FeedAttributes.h" |
|
21 #include "FolderAttributes.h" |
|
22 #include "PackedFolder.h" |
|
23 #include "Logger.h" |
|
24 |
|
25 |
|
26 const TInt KTokenArrayIncrementSize = 100; |
|
27 const TInt KStringTableIncrementSize = 1024; |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CPackedFolder::NewL |
|
32 // |
|
33 // Two-phased constructor. Used on both the client and server. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CPackedFolder* CPackedFolder::NewL() |
|
37 { |
|
38 CPackedFolder* self = new (ELeave) CPackedFolder(KTokenArrayIncrementSize, |
|
39 KStringTableIncrementSize); |
|
40 |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(); |
|
44 |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CPackedFolder::CPackedFolder |
|
51 // |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. Used on both the client and server. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CPackedFolder::CPackedFolder(TInt aTokenArrayInc, TInt aStringTableInc): |
|
57 CPacked(aTokenArrayInc, aStringTableInc), iLeakTracker(CLeakTracker::EPackedFolder) |
|
58 { |
|
59 } |
|
60 |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CPackedFolder::ConstructL |
|
64 // |
|
65 // Symbian 2nd phase constructor can leave. Used on both the client and server. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CPackedFolder::ConstructL() |
|
69 { |
|
70 BaseConstructL(); |
|
71 } |
|
72 |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CPackedFolder::~CPackedFolder |
|
76 // |
|
77 // Deconstructor. Used on both the client and server. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CPackedFolder::~CPackedFolder() |
|
81 { |
|
82 } |
|
83 |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CPackedFolder::FolderBeginsL |
|
87 // |
|
88 // Insert the begining of a folder. Used only on the server. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CPackedFolder::FolderBeginsL(const TDesC& aTitle, TInt aEntryId, TInt aStatus) |
|
92 { |
|
93 TBuf16<25> buf; |
|
94 |
|
95 InsertTokenL(EFolderTokenFolderBegin); |
|
96 AddAttributeL(EFolderAttributeTitle, aTitle); |
|
97 |
|
98 buf.AppendNum(aEntryId); |
|
99 AddAttributeL(EFolderAttributeEntryId, buf); |
|
100 |
|
101 buf.Zero(); |
|
102 buf.AppendNum(aStatus); |
|
103 AddAttributeL(EFolderAttributeStatus, buf); |
|
104 |
|
105 InsertTokenL(EFolderAttributeEnd); |
|
106 } |
|
107 |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CPackedFolder::FolderEndsL |
|
111 // |
|
112 // Insert the ending of a folder. Used only on the server. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CPackedFolder::FolderEndsL() |
|
116 { |
|
117 InsertTokenL(EFolderTokenFolderEnd); |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CPackedFolder::AddFeedL |
|
123 // |
|
124 // Insert a feed. Used only on the server. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CPackedFolder::AddFeedL( const TDesC& aTitle, const TDesC& aFeedUrl, |
|
128 const TTime& aLastUpdate, TInt aFreq, TInt aStatus,TInt aUnreadCount, TInt aEntryId, TInt aFeedId) |
|
129 { |
|
130 TBuf16<25> buf; |
|
131 |
|
132 InsertTokenL(EFolderTokenFeed); |
|
133 AddAttributeL(EFolderAttributeTitle, aTitle); |
|
134 AddAttributeL(EFolderAttributeUrl, aFeedUrl); |
|
135 |
|
136 buf.Zero(); |
|
137 buf.Format(_L("%Ld"), aLastUpdate.Int64()); |
|
138 AddAttributeL(EFolderAttributeTimestamp, buf); |
|
139 |
|
140 buf.Zero(); |
|
141 buf.AppendNum(aUnreadCount); |
|
142 AddAttributeL(EFolderAttributeUnreadCount, buf); |
|
143 |
|
144 buf.Zero(); |
|
145 buf.AppendNum(aEntryId); |
|
146 AddAttributeL(EFolderAttributeEntryId, buf); |
|
147 |
|
148 buf.Zero(); |
|
149 buf.AppendNum(aFeedId); |
|
150 AddAttributeL(EFolderAttributeFeedId, buf); |
|
151 |
|
152 buf.Zero(); |
|
153 buf.AppendNum(aStatus); |
|
154 AddAttributeL(EFolderAttributeStatus, buf); |
|
155 |
|
156 buf.Zero(); |
|
157 buf.AppendNum(aFreq); |
|
158 AddAttributeL(EFolderAttributeFreq, buf); |
|
159 |
|
160 InsertTokenL(EFolderAttributeEnd); |
|
161 } |
|
162 |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CPackedFolder::ItemBeginsL |
|
166 // |
|
167 // Insert the begining of a item. Used only on the server. |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CPackedFolder::ItemBeginsL() |
|
171 { |
|
172 InsertTokenL(EFolderTokenItemBegin); |
|
173 } |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CPackedFolder::ItemEndsL |
|
178 // |
|
179 // Insert the ending of a item. Used only on the server. |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CPackedFolder::ItemEndsL() |
|
183 { |
|
184 InsertTokenL(EFolderTokenItemEnd); |
|
185 } |
|
186 |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CPackedFolder::DoneL |
|
190 // |
|
191 // Called when when packing is done. Used only on the server. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CPackedFolder::DoneL() |
|
195 { |
|
196 iTokenArrayAsDes.Set((const TUint8*) iTokenArray, iTokenArrayLength * sizeof(TUint)); |
|
197 } |
|
198 |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CPackedFolder::ExtractAttributes |
|
202 // |
|
203 // Extract the folder item's attributes |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CPackedFolder::ExtractAttributes( TPtrC& aTitle, TPtrC& aUrl, |
|
207 TInt& aEntryId, TInt& aFeedId, TTime& aTimestamp, TInt& aUnreadCount, TInt &aStatus, TInt& aFreq) const |
|
208 { |
|
209 TBool done = EFalse; |
|
210 TUint attributeToken; |
|
211 TPtrC attributeValue; |
|
212 |
|
213 // Set the default values. |
|
214 aTitle.Set(KNullDesC); |
|
215 aUrl.Set(KNullDesC); |
|
216 aEntryId = -1; |
|
217 aFeedId = 0; |
|
218 aTimestamp.UniversalTime(); |
|
219 |
|
220 // Extract the attribute tokens. |
|
221 while (!done) |
|
222 { |
|
223 TUint token; |
|
224 |
|
225 token = NextToken(); |
|
226 |
|
227 // Extract the next attribute. |
|
228 if (token != EFolderAttributeEnd) |
|
229 { |
|
230 // Get the attribute. |
|
231 ExtractAttributeValue(attributeToken, attributeValue); |
|
232 |
|
233 switch (attributeToken) |
|
234 { |
|
235 case EFolderAttributeTitle: |
|
236 aTitle.Set(attributeValue); |
|
237 break; |
|
238 |
|
239 case EFolderAttributeUrl: |
|
240 aUrl.Set(attributeValue); |
|
241 break; |
|
242 |
|
243 case EFolderAttributeEntryId: |
|
244 { |
|
245 TLex16 lex(attributeValue); |
|
246 |
|
247 lex.Val(aEntryId); |
|
248 } |
|
249 break; |
|
250 |
|
251 case EFolderAttributeFeedId: |
|
252 { |
|
253 TLex16 lex(attributeValue); |
|
254 |
|
255 lex.Val(aFeedId); |
|
256 } |
|
257 break; |
|
258 |
|
259 case EFolderAttributeTimestamp: |
|
260 { |
|
261 TLex16 lex(attributeValue); |
|
262 TInt64 ts; |
|
263 |
|
264 lex.Val(ts); |
|
265 aTimestamp = ts; |
|
266 } |
|
267 break; |
|
268 |
|
269 case EFolderAttributeUnreadCount: |
|
270 { |
|
271 TLex16 lex(attributeValue); |
|
272 TInt unreadCount; |
|
273 |
|
274 lex.Val(unreadCount); |
|
275 aUnreadCount = unreadCount; |
|
276 } |
|
277 break; |
|
278 case EFolderAttributeStatus: |
|
279 { |
|
280 TLex16 lex(attributeValue); |
|
281 |
|
282 lex.Val(aStatus); |
|
283 } |
|
284 break; |
|
285 case EFolderAttributeFreq: |
|
286 { |
|
287 TLex16 lex(attributeValue); |
|
288 TInt freq; |
|
289 |
|
290 lex.Val(freq); |
|
291 aFreq = freq; |
|
292 } |
|
293 break; |
|
294 } |
|
295 } |
|
296 |
|
297 // Otherwise there are no more attributes. |
|
298 else |
|
299 { |
|
300 done = ETrue; |
|
301 } |
|
302 } |
|
303 } |
|
304 |
|
305 |
|
306 |