|
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: Holds information about a feed. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //#ifdef _DEBUG |
|
20 #include <f32file.h> |
|
21 //#endif |
|
22 |
|
23 #include "FeedAttributes.h" |
|
24 #include "FeedsServerFeed.h" |
|
25 #include "Logger.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CFeed::NewL |
|
29 // |
|
30 // Two-phased constructor. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CFeed* CFeed::NewL(CFeedsEntity* aFeedsEntity) |
|
34 { |
|
35 CFeed* self = new (ELeave) CFeed(aFeedsEntity); |
|
36 |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop(); |
|
40 |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CFeed::CFeed |
|
46 // |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CFeed::CFeed(CFeedsEntity* aFeedsEntity): |
|
52 iLeakTracker(CLeakTracker::EFeed), iFeedsEntity(aFeedsEntity), iTitle(KNullDesC), |
|
53 iDescription(KNullDesC), iUrl(KNullDesC), iDate(0), iItems(5) |
|
54 { |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CFeed::ConstructL |
|
59 // |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CFeed::ConstructL() |
|
64 { |
|
65 CEnclosure* enclosure = NULL; |
|
66 TPtrC title; |
|
67 TPtrC description; |
|
68 TPtrC url; |
|
69 TInt feedId; |
|
70 TInt itemCount = iFeedsEntity->GetChildren().Count(); |
|
71 |
|
72 |
|
73 for(TInt i=0 ; i< itemCount ; i++) |
|
74 { |
|
75 CFeedsEntity *feedEntity = iFeedsEntity->GetChildren()[i]; |
|
76 CItem *newItem = CItem::NewL( feedEntity); |
|
77 CleanupStack::PushL( newItem); |
|
78 TInt enclosureCount = feedEntity->GetChildren().Count(); |
|
79 |
|
80 for(TInt j=0 ; j< enclosureCount ; j++) |
|
81 { |
|
82 enclosure = CEnclosure::NewL( feedEntity->GetChildren()[j]); |
|
83 CleanupStack::PushL( enclosure); |
|
84 newItem->AddEnclosureL( enclosure); |
|
85 CleanupStack::Pop( enclosure); |
|
86 } |
|
87 |
|
88 iItems.Append( newItem); |
|
89 CleanupStack::Pop( newItem); |
|
90 } |
|
91 |
|
92 iFeedsEntity->GetIntegerValue( EFeedAttributeFeedId, feedId); |
|
93 iFeedId = feedId; |
|
94 |
|
95 iFeedsEntity->GetStringValue( EFeedAttributeTitle, title); |
|
96 SetAttribute( EFeedAttributeTitle, title); |
|
97 |
|
98 iFeedsEntity->GetStringValue( EFeedAttributeDescription, description); |
|
99 SetAttribute( EFeedAttributeDescription, description); |
|
100 |
|
101 iFeedsEntity->GetStringValue( EFeedAttributeLink, url); |
|
102 SetAttribute( EFeedAttributeLink,url); |
|
103 |
|
104 iFeedsEntity->GetTimeValue( EFeedAttributeTimestamp, iDate); |
|
105 |
|
106 } |
|
107 |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CFeed::~CFeed |
|
111 // |
|
112 // Deconstructor. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 CFeed::~CFeed() |
|
116 { |
|
117 // Delete the items. |
|
118 iItems.ResetAndDestroy(); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CFeed::Id |
|
123 // |
|
124 // Returns the feed's unique id. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C TInt CFeed::Id() const |
|
128 { |
|
129 return iFeedId; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CFeed::Title |
|
134 // |
|
135 // Returns the feed's title. |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C const TDesC& CFeed::Title() const |
|
139 { |
|
140 return iTitle; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CFeed::Description |
|
145 // |
|
146 // Returns the feed's description. |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C const TDesC& CFeed::Description() const |
|
150 { |
|
151 return iDescription; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CFeed::Url |
|
156 // |
|
157 // Returns the feed's url. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C const TDesC& CFeed::Url() const |
|
161 { |
|
162 return iUrl; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CFeed::Date |
|
167 // |
|
168 // Returns the feed's date. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C const TTime& CFeed::Date() const |
|
172 { |
|
173 return iDate; |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CFeed::ItemCount |
|
178 // |
|
179 // Returns the number of items. |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 EXPORT_C TInt CFeed::ItemCount() const |
|
183 { |
|
184 return iItems.Count(); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CFeed::ItemAt |
|
189 // |
|
190 // Returns the item at the given index |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C const CItem& CFeed::ItemAt(TInt aIndex) const |
|
194 { |
|
195 return *(iItems[aIndex]); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CFeed::ItemStatusL |
|
200 // |
|
201 // Returns the INITIAL status of each of the items in the feed. |
|
202 // The caller can then modify the values and call RFeed::UpdateFeedItemStatusL |
|
203 // to request the feeds server to update the feed's item status. |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C void CFeed::ItemStatusL(RArray<TInt>& aItemIds, |
|
207 RArray<TItemStatus>& aItemStatus) const |
|
208 { |
|
209 aItemIds.Reset(); |
|
210 aItemStatus.Reset(); |
|
211 |
|
212 // Add the item attributes. |
|
213 for (TInt i = 0; i < iItems.Count(); i++) |
|
214 { |
|
215 User::LeaveIfError(aItemIds.Append(iItems[i]->Id())); |
|
216 User::LeaveIfError(aItemStatus.Append(iItems[i]->ItemStatus())); |
|
217 } |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CFeed::AddItemL |
|
222 // |
|
223 // Appends the new Item to the Feed. aItem is adopted by this method. |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 void CFeed::AddItemL(CItem* aItem) |
|
227 { |
|
228 User::LeaveIfError(iItems.Append(aItem)); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CFeed::SetAttribute |
|
233 // |
|
234 // Sets an attribute. |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CFeed::SetAttribute(TUint aAttribute, const TPtrC& aAttributeValue) |
|
238 { |
|
239 switch (aAttribute) |
|
240 { |
|
241 case EFeedAttributeFeedId: |
|
242 { |
|
243 TLex16 lex(aAttributeValue); |
|
244 |
|
245 lex.Val(iFeedId); |
|
246 } |
|
247 break; |
|
248 |
|
249 case EFeedAttributeTitle: |
|
250 iTitle.Set(aAttributeValue); |
|
251 break; |
|
252 |
|
253 case EFeedAttributeDescription: |
|
254 iDescription.Set(aAttributeValue); |
|
255 break; |
|
256 |
|
257 case EFeedAttributeLink: |
|
258 iUrl.Set(aAttributeValue); |
|
259 break; |
|
260 |
|
261 case EFeedAttributeTimestamp: |
|
262 { |
|
263 TLex16 lex(aAttributeValue); |
|
264 TInt64 val; |
|
265 lex.Val(val); |
|
266 iDate = val; |
|
267 } |
|
268 break; |
|
269 |
|
270 default: |
|
271 break; |
|
272 } |
|
273 } |
|
274 |
|
275 //#ifdef _DEBUG |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CFeed::Debug_Print |
|
278 // |
|
279 // Prints the item to the log file. |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 EXPORT_C void CFeed::Debug_Print(void) const |
|
283 { |
|
284 FEED_LOG(_L("Feeds"), _L("Feeds_Dump.log"), |
|
285 EFileLoggingModeAppend, _L("\tFeed:")); |
|
286 |
|
287 if (iTitle.Length() > 0) |
|
288 { |
|
289 FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), |
|
290 EFileLoggingModeAppend, _L("\t\tTitle: %S"), &iTitle); |
|
291 } |
|
292 |
|
293 if (iUrl.Length() > 0) |
|
294 { |
|
295 FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), |
|
296 EFileLoggingModeAppend, _L("\t\tLink: %S"), &iUrl); |
|
297 } |
|
298 |
|
299 if (iDescription.Length() > 0) |
|
300 { |
|
301 FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), |
|
302 EFileLoggingModeAppend, _L("\t\tDescription: %S"), &iDescription); |
|
303 } |
|
304 |
|
305 // Print the items. |
|
306 FEED_LOG(_L("Feeds"), _L("Feeds_Dump.log"), |
|
307 EFileLoggingModeAppend, _L("\tItems:")); |
|
308 |
|
309 for (TInt i = 0; i < iItems.Count(); i++) |
|
310 { |
|
311 iItems[i]->Debug_Print(); |
|
312 } |
|
313 |
|
314 FEED_LOG(_L("Feeds"), _L("Feeds_Dump.log"), |
|
315 EFileLoggingModeAppend, _L("")); |
|
316 FEED_LOG(_L("Feeds"), _L("Feeds_Dump.log"), |
|
317 EFileLoggingModeAppend, _L("")); |
|
318 } |
|
319 |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CFeed::Debug_PrintInfo |
|
323 // |
|
324 // Prints info about the feed. |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 EXPORT_C void CFeed::Debug_PrintInfo(const TDesC& aUrl, RFile& aFile) const |
|
328 { |
|
329 TInt channels = 1; |
|
330 TInt titles = 0; |
|
331 TInt descriptions = 0; |
|
332 TInt items = 0; |
|
333 TInt links = 0; |
|
334 |
|
335 // Count the "unimportant" attributes. |
|
336 titles = iOtherTitles; |
|
337 links = iOtherLinks; |
|
338 descriptions = iOtherDescriptions; |
|
339 |
|
340 // Add the Channel attributes |
|
341 if (iTitle.Length() > 0) |
|
342 { |
|
343 titles++; |
|
344 } |
|
345 if (iDescription.Length() > 0) |
|
346 { |
|
347 descriptions++; |
|
348 } |
|
349 if (iUrl.Length() > 0) |
|
350 { |
|
351 links++; |
|
352 } |
|
353 |
|
354 // Add the item attributes. |
|
355 for (TInt i = 0; i < iItems.Count(); i++) |
|
356 { |
|
357 CItem* item; |
|
358 |
|
359 item = iItems[i]; |
|
360 items++; |
|
361 |
|
362 if (item->Title().Length() > 0) |
|
363 { |
|
364 titles++; |
|
365 } |
|
366 if (item->Description().Length() > 0) |
|
367 { |
|
368 descriptions++; |
|
369 } |
|
370 if (item->Url().Length() > 0) |
|
371 { |
|
372 links++; |
|
373 } |
|
374 } |
|
375 |
|
376 // Write out the stats. |
|
377 TBuf8<100> buff; |
|
378 |
|
379 aFile.Write(_L8("Feed Overview:\n")); |
|
380 |
|
381 // Write out the url. |
|
382 TUint8* asciiBuf = new TUint8[aUrl.Length() + 1]; |
|
383 |
|
384 if (asciiBuf != NULL) |
|
385 { |
|
386 TPtr8 asciiPtr(asciiBuf, 0, aUrl.Length() + 1); |
|
387 TPtrC16 ucs2Ptr(aUrl); |
|
388 |
|
389 asciiPtr.Copy(ucs2Ptr); |
|
390 asciiPtr.ZeroTerminate(); |
|
391 |
|
392 aFile.Write(_L8("\tfile: ")); |
|
393 aFile.Write(asciiPtr); |
|
394 aFile.Write(_L8("\n")); |
|
395 |
|
396 delete asciiBuf; |
|
397 } |
|
398 |
|
399 buff.Format(_L8("\tchannel: %d\n"), channels); |
|
400 aFile.Write(buff); |
|
401 |
|
402 buff.Format(_L8("\tdescription: %d\n"), descriptions); |
|
403 aFile.Write(buff); |
|
404 |
|
405 buff.Format(_L8("\titem: %d\n"), items); |
|
406 aFile.Write(buff); |
|
407 |
|
408 buff.Format(_L8("\tlink: %d\n"), links); |
|
409 aFile.Write(buff); |
|
410 |
|
411 buff.Format(_L8("\ttitle: %d\n"), titles); |
|
412 aFile.Write(buff); |
|
413 |
|
414 buff.Format(_L8("\r\n")); |
|
415 aFile.Write(buff); |
|
416 } |
|
417 //#endif |