|
1 /* |
|
2 * Copyright (c) 2004-2008 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: RSS plugin.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <sysutil.h> |
|
22 #include <centralrepository.h> |
|
23 #include <bautils.h> |
|
24 #include <xml/parser.h> |
|
25 |
|
26 #include "IptvDebug.h" |
|
27 #include "MIptvEpgVodCallback.h" |
|
28 #include "MIptvEpgLiveTvCallback.h" |
|
29 #include "CIptvTimer.h" |
|
30 #include <hash.h> |
|
31 |
|
32 #include "CIptvEpgService.h" |
|
33 #include "iptvlastwatcheddata.h" |
|
34 #include "iptvlastwatchedapi.h" |
|
35 |
|
36 #include "CIptvRssPlugin.h" |
|
37 #include "CIptvRssDownload.h" |
|
38 #include "CIptv3XmlContentHandler.h" |
|
39 |
|
40 _LIT8( KMimeType, "text/xml" ); |
|
41 |
|
42 _LIT( KIptvRssFileName, "rss." ); |
|
43 _LIT( KIptvThumbnailExtension, ".jpg" ); |
|
44 _LIT( KIptvVCFGExtension, ".vcfg" ); |
|
45 _LIT( KIptvRssSearchFileName, "rsssearch." ); |
|
46 _LIT( KIptvAllFiles, "*.*" ); |
|
47 _LIT8( KIptvHexByteFormatStr, "%02x" ); |
|
48 |
|
49 const TInt64 KIptvRssUpdateSuccesInterval( 60 ); |
|
50 const TInt64 KIptvRssUpdateFailedInterval( 0 ); |
|
51 const TInt KIptvExtensionMaxSize( 5 ); |
|
52 |
|
53 const TInt KIptvRssPluginFreeSpace( 512000 ); // 500 KB |
|
54 |
|
55 static const TInt KReadAtOnceLength( 1000 ); |
|
56 |
|
57 const TInt KIptvTime_200_microsecond( 200 ); |
|
58 |
|
59 const TInt KIptvHexCharInByte( 2 ); |
|
60 /** |
|
61 * Enable this flag to update feed from local XML file. The path |
|
62 * to XML file is defined with KIptvLocalTestFeed variable below. |
|
63 */ |
|
64 //#define IPTV_RSS_LOCAL_TEST |
|
65 |
|
66 #ifdef IPTV_RSS_LOCAL_TEST |
|
67 _LIT( KIptvLocalTestFeed, "C:\\videofeed.xml" ); |
|
68 #warning Local feed test flag IPTV_RSS_LOCAL_TEST has been defined!!! |
|
69 #endif |
|
70 |
|
71 // ======== MEMBER FUNCTIONS ======== |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 void CIptvRssPlugin::ConstructL() |
|
78 { |
|
79 IPTVLOGSTRING_LOW_LEVEL( "RSS Plugin --- CIptvRssPlugin::ConstructL" ); |
|
80 |
|
81 User::LeaveIfError( iFs.Connect() ); |
|
82 iDownload = CIptvRssDownload::NewL( *this, iFs, *iXmlContentHandler ); |
|
83 iThumbnailDlAllowed = ThumbnailDlAllowedL(); |
|
84 |
|
85 if ( iThumbnailDlAllowed ) |
|
86 { |
|
87 IPTVLOGSTRING_LOW_LEVEL( |
|
88 "RSS Plugin --- CIptvRssPlugin::ConstructL --- Thumbnail downloading is allowed!" ); |
|
89 } |
|
90 else |
|
91 { |
|
92 IPTVLOGSTRING_LOW_LEVEL( |
|
93 "RSS Plugin --- CIptvRssPlugin::ConstructL --- Thumbnail downloading is not allowed!" ); |
|
94 } |
|
95 |
|
96 iParserIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
97 iXmlContentHandler = CIptvXmlContentHandler::NewL( *this ); |
|
98 iParser = CParser::NewL( KMimeType, *iXmlContentHandler ); |
|
99 } |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // Two-phased constructor. |
|
103 // Create instance of concrete ECOM interface implementation |
|
104 // -------------------------------------------------------------------------- |
|
105 // |
|
106 CIptvRssPlugin* CIptvRssPlugin::NewL() |
|
107 { |
|
108 IPTVLOGSTRING_LOW_LEVEL( "RSS Plugin --- CIptvRssPlugin::NewL" ); |
|
109 |
|
110 CIptvRssPlugin* self = new( ELeave ) CIptvRssPlugin(); |
|
111 CleanupStack::PushL( self ); |
|
112 |
|
113 self->ConstructL(); |
|
114 |
|
115 CleanupStack::Pop( self ); |
|
116 return self; |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------- |
|
120 // Destructor |
|
121 // -------------------------------------------------------------------------- |
|
122 // |
|
123 CIptvRssPlugin::~CIptvRssPlugin() |
|
124 { |
|
125 IPTVLOGSTRING_LOW_LEVEL( |
|
126 "RSS Plugin --- CIptvRssPlugin::~CIptvRssPlugin" ); |
|
127 |
|
128 delete iItem; |
|
129 delete iParser; |
|
130 delete iDownload; |
|
131 delete iParserIdle; |
|
132 delete iXmlContentHandler; |
|
133 delete iXmlFileContent; |
|
134 delete iStartTimer; |
|
135 delete iMD5Calculator; |
|
136 iDlQueue.ResetAndDestroy(); |
|
137 iIconList.ResetAndDestroy(); |
|
138 iPreviouslyDownloadedAddresses.ResetAndDestroy(); |
|
139 iPreviouslyDownloadedPaths.ResetAndDestroy(); |
|
140 |
|
141 iFs.Close(); |
|
142 iVodCallback = NULL; |
|
143 } |
|
144 |
|
145 // -------------------------------------------------------------------------- |
|
146 // C++ default constructor |
|
147 // -------------------------------------------------------------------------- |
|
148 // |
|
149 CIptvRssPlugin::CIptvRssPlugin() : |
|
150 iXmlContentHandler( NULL ), |
|
151 iParser( NULL ), |
|
152 iParserIdle( NULL ), |
|
153 iDownload( NULL ), |
|
154 iVodCallback( NULL ), |
|
155 iXmlFileContent( NULL ), |
|
156 iStartTimer( NULL ), |
|
157 iServiceId( 0 ), |
|
158 iItem( NULL ), |
|
159 iDlThumbnail( EFalse ), |
|
160 iThumbnailDlAllowed( EFalse ), |
|
161 iParsingFailed( EFalse ) |
|
162 { |
|
163 IPTVLOGSTRING_LOW_LEVEL( |
|
164 "RSS Plugin --- CIptvRssPlugin::CIptvRssPlugin" ); |
|
165 } |
|
166 |
|
167 // -------------------------------------------------------------------------- |
|
168 // From CIptvEpgPluginInterface |
|
169 // -------------------------------------------------------------------------- |
|
170 // |
|
171 void CIptvRssPlugin::RunPlugin() |
|
172 { |
|
173 IPTVLOGSTRING_LOW_LEVEL( "RSS Plugin --- CIptvRssPlugin::RunPlugin" ); |
|
174 |
|
175 // Timer removes UI jamming in update sequence. |
|
176 if ( !iStartTimer ) |
|
177 { |
|
178 TRAP_IGNORE( iStartTimer = |
|
179 CIptvTimer::NewL( CActive::EPriorityUserInput, *this ) ); |
|
180 } |
|
181 |
|
182 if ( iStartTimer ) |
|
183 { |
|
184 if ( !iStartTimer->IsActive() ) |
|
185 { |
|
186 iStartTimer->After( KIptvTime_200_microsecond ); |
|
187 } |
|
188 } |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // Delayed plugin start. |
|
193 // -------------------------------------------------------------------------- |
|
194 // |
|
195 void CIptvRssPlugin::TimerExpired( CIptvTimer* /* aTimer */ ) |
|
196 { |
|
197 IPTVLOGSTRING_LOW_LEVEL( |
|
198 "CIptvRssPlugin --- CIptvRssPlugin::TimerExpired" ); |
|
199 |
|
200 TRAPD( error, DoTimerExpiredL() ); |
|
201 if ( error != KErrNone ) |
|
202 { |
|
203 IPTVLOGSTRING2_LOW_LEVEL( |
|
204 "RSS Plugin --- CIptvRssPlugin::TimerExpired --- Leave while DoTimerExpiredL() = %d", |
|
205 error ); |
|
206 TRAP( error, PluginFailedL( EIptvDlNoError ) ); |
|
207 if ( error != KErrNone ) |
|
208 { |
|
209 IPTVLOGSTRING2_LOW_LEVEL( |
|
210 "RSS Plugin --- CIptvRssPlugin::TimerExpired --- Leave while PluginFailedL() = %d", |
|
211 error ); |
|
212 } |
|
213 } |
|
214 } |
|
215 |
|
216 // -------------------------------------------------------------------------- |
|
217 // Delayed plugin start. |
|
218 // -------------------------------------------------------------------------- |
|
219 // |
|
220 void CIptvRssPlugin::DoTimerExpiredL() |
|
221 { |
|
222 IPTVLOGSTRING_LOW_LEVEL( |
|
223 "RSS Plugin --- CIptvRssPlugin::DoTimerExpiredL" ); |
|
224 |
|
225 iDownload->InitializeL(); |
|
226 RunPluginL(); |
|
227 } |
|
228 |
|
229 // -------------------------------------------------------------------------- |
|
230 // Start plugin. |
|
231 // -------------------------------------------------------------------------- |
|
232 // |
|
233 void CIptvRssPlugin::RunPluginL() |
|
234 { |
|
235 IPTVLOGSTRING_LOW_LEVEL( "RSS Plugin --- CIptvRssPlugin::RunPluginL" ); |
|
236 |
|
237 if ( ! iIsGroupOperation ) |
|
238 { |
|
239 // If exist, delete old rss file |
|
240 if ( BaflUtils::FileExists( iFs, iRssPath ) ) |
|
241 { |
|
242 BaflUtils::DeleteFile( iFs, iRssPath ); |
|
243 } |
|
244 } |
|
245 |
|
246 // Clear obsolete thumbnail list. |
|
247 iIconList.ResetAndDestroy(); |
|
248 |
|
249 // Clear already downloaded thumbnail list. |
|
250 iPreviouslyDownloadedAddresses.ResetAndDestroy(); |
|
251 iPreviouslyDownloadedPaths.ResetAndDestroy(); |
|
252 |
|
253 // Before we even start the download, we check that there is sensible |
|
254 // amount of free disk space for content guide and thumbnail files. |
|
255 TBool checkResult( EFalse ); |
|
256 TRAPD( |
|
257 checkError, |
|
258 checkResult = SysUtil::DiskSpaceBelowCriticalLevelL( |
|
259 &iFs, KIptvRssPluginFreeSpace, EDriveC ) ); |
|
260 if ( checkError != KErrNone || checkResult ) |
|
261 { |
|
262 // Not enough space on disk, return immediately without any downloading. |
|
263 if ( iIsSearchOperation ) |
|
264 { |
|
265 iVodCallback->ErrorL( KIptvErrorRssSearchFailed, EIptvDlDiskFull ); |
|
266 } |
|
267 else |
|
268 { |
|
269 iVodCallback->ErrorL( KIptvErrorEpgUpdateFailed, EIptvDlDiskFull ); |
|
270 } |
|
271 return; |
|
272 } |
|
273 |
|
274 // Callback EPG manager that plugin is started |
|
275 if ( iVodCallback ) |
|
276 { |
|
277 iVodCallback->StartedL(); |
|
278 } |
|
279 else |
|
280 { |
|
281 IPTVLOGSTRING_LOW_LEVEL( |
|
282 "RSS Plugin --- CIptvRssPlugin::RunPluginL --- iVodCallback is NULL" ); |
|
283 } |
|
284 |
|
285 #ifndef IPTV_RSS_LOCAL_TEST |
|
286 |
|
287 if ( ( EIptvRssAddServiceThumbnailToDlQueue == iAction ) || |
|
288 ( EIptvRssAddItemThumbnailToDlQueue == iAction ) ) |
|
289 { |
|
290 // Download only previously listed thumbnails. |
|
291 iParsingFailed = EFalse; |
|
292 DownloadThumbnailsL(); |
|
293 } |
|
294 else |
|
295 { |
|
296 // Download RSS-file. |
|
297 iDownload->DownloadL( |
|
298 iServiceAddress, |
|
299 iRssPath, |
|
300 EFalse, |
|
301 KIptvEmptyDes, |
|
302 iLastUpdated ); |
|
303 } |
|
304 |
|
305 #else |
|
306 |
|
307 IPTVLOGSTRING_LOW_LEVEL( |
|
308 "RSS Plugin --- CIptvRssPlugin::RunPluginL --- Parsing XML from local filesystem!" ); |
|
309 iRssPath.Copy( KIptvLocalTestFeed ); |
|
310 DownloadFinishedL( EDownloadSucceeded, EIptvDlNoError ); |
|
311 |
|
312 #endif |
|
313 } |
|
314 |
|
315 // -------------------------------------------------------------------------- |
|
316 // Set callback pointer to MIptvEpgVodCallback. Plugin uses |
|
317 // MIptvEpgVodCallback interface to supply Epg data to system. |
|
318 // -------------------------------------------------------------------------- |
|
319 // |
|
320 void CIptvRssPlugin::SetVodCallback( MIptvEpgVodCallback* aVodCallback ) |
|
321 { |
|
322 IPTVLOGSTRING_LOW_LEVEL( |
|
323 "RSS Plugin --- CIptvRssPlugin::SetVodCallback" ); |
|
324 |
|
325 iXmlContentHandler->SetVodCallback( aVodCallback ); |
|
326 iVodCallback = aVodCallback; |
|
327 } |
|
328 |
|
329 // -------------------------------------------------------------------------- |
|
330 // Set callback pointer to MIptvEpgLiveTvCallback. |
|
331 // -------------------------------------------------------------------------- |
|
332 // |
|
333 void CIptvRssPlugin::SetLiveTvCallback( |
|
334 MIptvEpgLiveTvCallback* /*aLiveTvCallback*/ ) |
|
335 { |
|
336 IPTVLOGSTRING_LOW_LEVEL( |
|
337 "RSS Plugin --- CIptvRssPlugin::SetLiveTvCallback" ); |
|
338 } |
|
339 |
|
340 // -------------------------------------------------------------------------- |
|
341 // From CIptvEpgPluginInterface interface |
|
342 // -------------------------------------------------------------------------- |
|
343 // |
|
344 void CIptvRssPlugin::SetServiceInformation( |
|
345 CIptvEpgService* aService, |
|
346 TBool aUseSearchAddress ) |
|
347 { |
|
348 IPTVLOGSTRING_LOW_LEVEL( |
|
349 "RSS Plugin --- CIptvRssPlugin::SetServiceInformation" ); |
|
350 |
|
351 TIptvRSSAction action( EIptvRssService ); |
|
352 if ( aUseSearchAddress ) |
|
353 { |
|
354 action = EIptvRssSearch; |
|
355 } |
|
356 |
|
357 TRAP_IGNORE( SetServiceInformationL( aService, action ) ); |
|
358 } |
|
359 |
|
360 // -------------------------------------------------------------------------- |
|
361 // From CIptvEpgPluginInterface interface |
|
362 // -------------------------------------------------------------------------- |
|
363 // |
|
364 void CIptvRssPlugin::SetServiceInformationL( |
|
365 CIptvEpgService* aService, |
|
366 TIptvRSSAction aAction ) |
|
367 { |
|
368 IPTVLOGSTRING_LOW_LEVEL( |
|
369 "RSS Plugin --- CIptvRssPlugin::SetServiceInformationL" ); |
|
370 |
|
371 if ( !aService ) |
|
372 { |
|
373 User::Leave( KErrArgument ); |
|
374 } |
|
375 |
|
376 iAction = aAction; |
|
377 iIsGroupOperation = |
|
378 ( ( EIptvRssServiceGroup == iAction ) || |
|
379 ( EIptvRssAddServiceThumbnailToDlQueue == iAction ) || |
|
380 ( EIptvRssAddItemThumbnailToDlQueue == iAction ) ); |
|
381 iIsSearchOperation = ( EIptvRssSearch == iAction ); |
|
382 |
|
383 if ( ( EIptvRssAddServiceThumbnailToDlQueue == iAction ) || |
|
384 ( EIptvRssAddItemThumbnailToDlQueue == iAction ) ) |
|
385 { |
|
386 CIptvDownloadItem* item = CIptvDownloadItem::NewL(); |
|
387 CleanupStack::PushL( item ); |
|
388 item->iThumbnailUrl.Copy( aService->iAddress ); |
|
389 item->iServiceThumbnail = ( EIptvRssAddServiceThumbnailToDlQueue == iAction ); |
|
390 item->iId = aService->iServiceId; |
|
391 AddToDlQueueL( item ); |
|
392 CleanupStack::Pop( item ); |
|
393 } |
|
394 else |
|
395 { |
|
396 IPTVLOGSTRING2_LOW_LEVEL( |
|
397 "RSS Plugin --- CIptvRssPlugin::SetServiceInformationL --- USERNAME %S", |
|
398 &aService->iUserName ); |
|
399 IPTVLOGSTRING2_LOW_LEVEL( |
|
400 "RSS Plugin --- CIptvRssPlugin::SetServiceInformationL --- PASSWORD %S", |
|
401 &aService->iPassword ); |
|
402 |
|
403 iServiceId = aService->iServiceId; |
|
404 if ( iIsSearchOperation ) |
|
405 { |
|
406 iServiceAddress.Copy( aService->SearchUrl() ); |
|
407 } |
|
408 else |
|
409 { |
|
410 iServiceAddress.Copy( aService->iAddress ); |
|
411 } |
|
412 |
|
413 iDownload->SetServiceInformation( aService ); |
|
414 |
|
415 if ( iIsGroupOperation ) |
|
416 { |
|
417 HBufC* path = HBufC::NewLC( KIptvMaxPath ); |
|
418 TPtr16 pathPtr = path->Des(); |
|
419 TBuf<KIptvCAContentUrlLength> url; |
|
420 url.Copy( iServiceAddress ); |
|
421 |
|
422 // Get pathname for vcfg file. |
|
423 BuildUniqueuPathNameL( |
|
424 url, |
|
425 EIptvPathTmp, |
|
426 KIptvVCFGExtension, |
|
427 ETrue, |
|
428 pathPtr ); |
|
429 |
|
430 iRssPath.Copy( *path ); |
|
431 CleanupStack::PopAndDestroy( path ); |
|
432 } |
|
433 else |
|
434 { |
|
435 // Get RSS temp file path |
|
436 TRAP_IGNORE( CIptvUtil::GetPathL( iFs, EIptvPathTmp, iRssPath ) ); |
|
437 |
|
438 if ( iIsSearchOperation ) |
|
439 { |
|
440 iRssPath.Append( KIptvRssSearchFileName ); |
|
441 } |
|
442 else |
|
443 { |
|
444 iRssPath.Append( KIptvRssFileName ); |
|
445 } |
|
446 |
|
447 TBuf<KIptvMaxPath> service; |
|
448 service.Num( TInt64( iServiceId ) ); |
|
449 iRssPath.Append( service ); |
|
450 } |
|
451 |
|
452 iLastUpdated = aService->iLastUpdated; |
|
453 |
|
454 IPTVLOGSTRING2_LOW_LEVEL( |
|
455 "RSS Plugin --- CIptvRssPlugin::SetServiceInformation --- RSS temp file : %S", |
|
456 &iRssPath ); |
|
457 } |
|
458 } |
|
459 |
|
460 // -------------------------------------------------------------------------- |
|
461 // Handles download finished. |
|
462 // -------------------------------------------------------------------------- |
|
463 // |
|
464 void CIptvRssPlugin::DownloadFinishedL( TInt aState, TIptvDlError aError ) |
|
465 { |
|
466 IPTVLOGSTRING_LOW_LEVEL( |
|
467 "RSS Plugin --- CIptvRssPlugin::DownloadFinishedL" ); |
|
468 |
|
469 TBuf<1> empty; |
|
470 |
|
471 if ( !iDlThumbnail ) |
|
472 { |
|
473 switch ( aState ) |
|
474 { |
|
475 case EDownloadFailed: |
|
476 { |
|
477 IPTVLOGSTRING_LOW_LEVEL( |
|
478 "RSS Plugin --- CIptvRssPlugin::DownloadFinishedL --- EDownloadFailed" ); |
|
479 PluginFailedL( aError ); |
|
480 } |
|
481 break; |
|
482 |
|
483 case EDownloadSucceeded: |
|
484 { |
|
485 IPTVLOGSTRING_LOW_LEVEL( |
|
486 "RSS Plugin --- CIptvRssPlugin::DownloadFinishedL --- EDownloadSucceeded" ); |
|
487 if ( iIsGroupOperation ) |
|
488 { |
|
489 // This is used for group VCFG file download indication. |
|
490 iVodCallback->UpdateServiceThumbnailL( iRssPath, ETrue ); |
|
491 } |
|
492 else |
|
493 { |
|
494 ParseL(); |
|
495 } |
|
496 } |
|
497 break; |
|
498 |
|
499 case EDownloadNoNeed: |
|
500 case EDownloadAlreadyDownloaded: |
|
501 { |
|
502 IPTVLOGSTRING_LOW_LEVEL( |
|
503 "RSS Plugin --- CIptvRssPlugin::DownloadFinishedL --- EDownloadNoNeed" ); |
|
504 // When rss file has not been changed, also thumnails are |
|
505 // assumed not having been changed. |
|
506 if ( iIsGroupOperation ) |
|
507 { |
|
508 iVodCallback->ErrorL( |
|
509 KIptvContentUpdateCompleted, |
|
510 EIptvDlNoErrorUpToDate ); |
|
511 iVodCallback->UpdateServiceThumbnailL( iRssPath, ETrue ); |
|
512 } |
|
513 else |
|
514 { |
|
515 PluginSucceededL(); |
|
516 } |
|
517 } |
|
518 break; |
|
519 |
|
520 default: |
|
521 break; |
|
522 } |
|
523 } |
|
524 else |
|
525 { |
|
526 if ( iItem ) |
|
527 { |
|
528 if ( iItem->iServiceThumbnail ) |
|
529 { |
|
530 switch ( aState ) |
|
531 { |
|
532 case EDownloadFailed: |
|
533 { |
|
534 IPTVLOGSTRING_LOW_LEVEL( |
|
535 "RSS Plugin --- CIptvRssPlugin::DownloadFinishedL --- Service thumbnail download finished --- EDownloadFailed" ); |
|
536 iVodCallback->UpdateServiceThumbnailL( empty, EFalse ); |
|
537 |
|
538 // Thumbnail file id is not used |
|
539 TUint32 iconFileId( 0 ); |
|
540 iVodCallback->UpdateCategoryIconL( |
|
541 iItem->iId, iconFileId, empty, EFalse ); |
|
542 } |
|
543 break; |
|
544 |
|
545 case EDownloadSucceeded: |
|
546 case EDownloadNoNeed: |
|
547 // Set as already downloaded only first time, |
|
548 // when really done it. |
|
549 SetAlreadyDownloadedPathL(); |
|
550 //lint -fallthrough intended here |
|
551 case EDownloadAlreadyDownloaded: |
|
552 { |
|
553 IPTVLOGSTRING2_LOW_LEVEL( |
|
554 "RSS Plugin --- CIptvRssPlugin::DownloadFinishedL --- Service thumbnail %S", |
|
555 &iDownloadPath ); |
|
556 iVodCallback->UpdateServiceThumbnailL( |
|
557 iDownloadPath, EFalse ); |
|
558 |
|
559 // Thumbnail file id is not used |
|
560 TUint32 iconFileId( 0 ); |
|
561 iVodCallback->UpdateCategoryIconL( |
|
562 iItem->iId, |
|
563 iconFileId, |
|
564 iDownloadPath, |
|
565 EFalse ); |
|
566 iVodCallback->ErrorL( |
|
567 KIptvServiceThumbnailDownloaded, |
|
568 iServiceId ); |
|
569 } |
|
570 break; |
|
571 |
|
572 default: |
|
573 break; |
|
574 } |
|
575 } |
|
576 else |
|
577 { |
|
578 switch ( aState ) |
|
579 { |
|
580 case EDownloadFailed: |
|
581 { |
|
582 IPTVLOGSTRING_LOW_LEVEL( |
|
583 "RSS Plugin:: --- CIptvRssPlugin::DownloadFinishedL --- Content thumbnail download finished --- EDownloadFailed" ); |
|
584 // Thumbnail file id is not used |
|
585 TUint32 iconFileId( 0 ); |
|
586 iVodCallback->UpdateContentIconL( |
|
587 iItem->iId, |
|
588 iconFileId, |
|
589 empty, |
|
590 EFalse ); |
|
591 } |
|
592 break; |
|
593 |
|
594 case EDownloadSucceeded: |
|
595 case EDownloadNoNeed: |
|
596 // Set as already downloaded only first time, |
|
597 // when really done it. |
|
598 SetAlreadyDownloadedPathL(); |
|
599 //lint -fallthrough intended here |
|
600 case EDownloadAlreadyDownloaded: |
|
601 { |
|
602 IPTVLOGSTRING2_LOW_LEVEL( |
|
603 "RSS Plugin:: --- CIptvRssPlugin::DownloadFinishedL --- Content thumbnail %S", |
|
604 &iDownloadPath ); |
|
605 // Thumbnail file id is not used |
|
606 TUint32 iconFileId( 0 ); |
|
607 iVodCallback->UpdateContentIconL( |
|
608 iItem->iId, |
|
609 iconFileId, |
|
610 iDownloadPath, |
|
611 EFalse ); |
|
612 if ( iIsSearchOperation ) |
|
613 { |
|
614 iVodCallback->ErrorL( |
|
615 KIptvRssSearchContentThumbnailDownloaded, |
|
616 iItem->iId ); |
|
617 } |
|
618 else |
|
619 { |
|
620 iVodCallback->ErrorL( |
|
621 KIptvContentThumbnailDownloaded, |
|
622 iItem->iId ); |
|
623 } |
|
624 } |
|
625 break; |
|
626 |
|
627 default: |
|
628 break; |
|
629 } |
|
630 } |
|
631 } |
|
632 |
|
633 iDlThumbnail = EFalse; |
|
634 DownloadThumbnailsL(); |
|
635 } |
|
636 } |
|
637 |
|
638 // -------------------------------------------------------------------------- |
|
639 // Set plugin failed. |
|
640 // -------------------------------------------------------------------------- |
|
641 // |
|
642 void CIptvRssPlugin::PluginFailedL( TIptvDlError aError ) |
|
643 { |
|
644 IPTVLOGSTRING_LOW_LEVEL( |
|
645 "RSS Plugin:: --- CIptvRssPlugin::PluginFailedL" ); |
|
646 |
|
647 TTime valid( KIptvRssUpdateFailedInterval ); |
|
648 |
|
649 if ( iParsingFailed ) |
|
650 { |
|
651 if ( iIsSearchOperation ) |
|
652 { |
|
653 iVodCallback->ErrorL( |
|
654 KIptvErrorRssSearchFailed, KIptvRssParserError ); |
|
655 } |
|
656 else |
|
657 { |
|
658 iVodCallback->ErrorL( |
|
659 KIptvErrorEpgUpdateFailed, KIptvRssParserError ); |
|
660 } |
|
661 } |
|
662 else |
|
663 { |
|
664 if ( iIsSearchOperation ) |
|
665 { |
|
666 iVodCallback->ErrorL( KIptvErrorRssSearchFailed, aError ); |
|
667 } |
|
668 else |
|
669 { |
|
670 iVodCallback->ErrorL( KIptvErrorEpgUpdateFailed, aError ); |
|
671 } |
|
672 } |
|
673 |
|
674 iVodCallback->FinishedL( valid ); |
|
675 } |
|
676 |
|
677 // -------------------------------------------------------------------------- |
|
678 // Set plugin succeeded. |
|
679 // -------------------------------------------------------------------------- |
|
680 // |
|
681 void CIptvRssPlugin::PluginSucceededL() |
|
682 { |
|
683 IPTVLOGSTRING_LOW_LEVEL( |
|
684 "RSS Plugin:: --- CIptvRssPlugin::PluginSucceededL" ); |
|
685 |
|
686 TInt64 ms; |
|
687 ms = KIptvMinuteAsMicrosecond * KIptvRssUpdateSuccesInterval; |
|
688 TTime valid( ms ); |
|
689 |
|
690 if ( iIsSearchOperation ) |
|
691 { |
|
692 iVodCallback->ErrorL( KIptvErrorRssSearchSucceed, 0 ); |
|
693 } |
|
694 else |
|
695 { |
|
696 iVodCallback->ErrorL( KIptvErrorEpgUpdateSuccessed, 0 ); |
|
697 } |
|
698 |
|
699 iVodCallback->FinishedL( valid ); |
|
700 } |
|
701 |
|
702 // -------------------------------------------------------------------------- |
|
703 // Parse EPG data. |
|
704 // -------------------------------------------------------------------------- |
|
705 // |
|
706 void CIptvRssPlugin::ParseL() |
|
707 { |
|
708 IPTVLOGSTRING_LOW_LEVEL( "RSS Plugin:: --- CIptvRssPlugin::ParseL" ); |
|
709 |
|
710 TRAPD( err, StartParsingXmlFileL( iRssPath ) ); |
|
711 if ( err != KErrNone ) |
|
712 { |
|
713 IPTVLOGSTRING2_LOW_LEVEL( |
|
714 "RSS Plugin --- CIptvRssPlugin::ParseL --- Leave while Parse() = %d", |
|
715 err ); |
|
716 PluginFailedL( EIptvDlNoError ); |
|
717 } |
|
718 |
|
719 #ifndef IPTV_RSS_LOCAL_TEST |
|
720 |
|
721 // If exist, delete downloaded rss file. |
|
722 if ( BaflUtils::FileExists( iFs, iRssPath ) ) |
|
723 { |
|
724 BaflUtils::DeleteFile( iFs, iRssPath ); |
|
725 } |
|
726 |
|
727 #endif |
|
728 |
|
729 } |
|
730 |
|
731 // -------------------------------------------------------------------------- |
|
732 // Parse EPG data. |
|
733 // -------------------------------------------------------------------------- |
|
734 // |
|
735 void CIptvRssPlugin::StartParsingXmlFileL( const TDesC& aFileName ) |
|
736 { |
|
737 IPTVLOGSTRING_LOW_LEVEL( |
|
738 "RSS Plugin --- CIptvRssPlugin::StartParsingXmlFileL" ); |
|
739 |
|
740 RFile phile; |
|
741 User::LeaveIfError( phile.Open( iFs, aFileName, EFileRead ) ); |
|
742 CleanupClosePushL( phile ); |
|
743 TInt size( 0 ); |
|
744 User::LeaveIfError( phile.Size( size ) ); |
|
745 delete iXmlFileContent; |
|
746 iXmlFileContent = NULL; |
|
747 if ( 0 < size ) |
|
748 { |
|
749 iXmlFileContent = HBufC8::NewL( size ); |
|
750 TPtr8 fileContentPtr = iXmlFileContent->Des(); |
|
751 User::LeaveIfError( phile.Read( fileContentPtr ) ); |
|
752 size = iXmlFileContent->Length(); |
|
753 } |
|
754 CleanupStack::PopAndDestroy( &phile ); |
|
755 |
|
756 // There was at least some content in the file |
|
757 if ( 0 < size ) |
|
758 { |
|
759 iCurrentParsePosition = 0; |
|
760 iParser->ParseBeginL(); |
|
761 if ( iParserIdle->IsActive() ) |
|
762 { |
|
763 iParserIdle->Cancel(); |
|
764 } |
|
765 TCallBack cb( ParseIdleCallback, this ); |
|
766 iParserIdle->Start( cb ); |
|
767 } |
|
768 else |
|
769 { |
|
770 iParsingFailed = ETrue; |
|
771 PluginFailedL( EIptvDlContentNotFound ); |
|
772 } |
|
773 } |
|
774 |
|
775 // -------------------------------------------------------------------------- |
|
776 // Static entry point for CIdle callback. |
|
777 // -------------------------------------------------------------------------- |
|
778 // |
|
779 TInt CIptvRssPlugin::ParseIdleCallback( TAny* aPluginImpl ) |
|
780 { |
|
781 IPTVLOGSTRING_LOW_LEVEL( |
|
782 "RSS Plugin --- CIptvRssPlugin::ParseIdleCallback" ); |
|
783 |
|
784 CIptvRssPlugin* self = static_cast<CIptvRssPlugin*> ( aPluginImpl ); |
|
785 if ( self ) |
|
786 { |
|
787 return self->HandleParseIdleCallback(); |
|
788 } |
|
789 else |
|
790 { |
|
791 return NULL; |
|
792 } |
|
793 } |
|
794 |
|
795 // -------------------------------------------------------------------------- |
|
796 // Add thumbnail to download queue. |
|
797 // -------------------------------------------------------------------------- |
|
798 // |
|
799 void CIptvRssPlugin::AddToDlQueueL( const CIptvDownloadItem* aItem ) |
|
800 { |
|
801 IPTVLOGSTRING_LOW_LEVEL( |
|
802 "RSS Plugin --- CIptvRssPlugin::AddToDlQueueL" ); |
|
803 |
|
804 iDlQueue.AppendL( aItem ); |
|
805 } |
|
806 |
|
807 // -------------------------------------------------------------------------- |
|
808 // Download thumbnails from download queue. |
|
809 // -------------------------------------------------------------------------- |
|
810 // |
|
811 void CIptvRssPlugin::DownloadThumbnailsL() |
|
812 { |
|
813 IPTVLOGSTRING_LOW_LEVEL( |
|
814 "RSS Plugin --- CIptvRssPlugin::DownloadThumbnailsL" ); |
|
815 |
|
816 if ( iParsingFailed ) |
|
817 { |
|
818 PluginFailedL( EIptvDlNoError ); |
|
819 return; |
|
820 } |
|
821 |
|
822 iDlThumbnail = ETrue; |
|
823 TBool download( EFalse ); |
|
824 TBool loop( ETrue ); |
|
825 while ( loop ) |
|
826 { |
|
827 download = EFalse; |
|
828 TInt count( iDlQueue.Count() ); |
|
829 if ( count > 0 ) |
|
830 { |
|
831 delete iItem; |
|
832 iItem = NULL; |
|
833 iItem = iDlQueue[0]; |
|
834 iDlQueue.Remove( 0 ); |
|
835 |
|
836 if ( iItem ) |
|
837 { |
|
838 iServiceAddress.Copy( iItem->iThumbnailUrl ); |
|
839 |
|
840 // Create variable for thumbnail path |
|
841 HBufC* path = HBufC::NewLC( KIptvMaxPath ); |
|
842 TPtr16 pathPtr = path->Des(); |
|
843 |
|
844 // If downloading service thumbnail |
|
845 if ( iItem->iServiceThumbnail ) |
|
846 { |
|
847 TBool doDownload( EFalse ); |
|
848 |
|
849 if ( ! iIsSearchOperation ) |
|
850 { |
|
851 doDownload = ETrue; |
|
852 } |
|
853 else |
|
854 { |
|
855 // we do nothing here. We dont want to download service |
|
856 // thumbnails for search results |
|
857 } |
|
858 |
|
859 // Download service thumbnail only for "normal" vod. |
|
860 // When doing search service thumbnail is not downloaded. |
|
861 if ( doDownload ) |
|
862 { |
|
863 // Get pathname for service thumbnail. |
|
864 BuildUniqueuPathNameL( |
|
865 iItem->iThumbnailUrl, |
|
866 EIptvPathService, |
|
867 KIptvThumbnailExtension, |
|
868 EFalse, |
|
869 pathPtr ); |
|
870 |
|
871 // If exists, add it to thumbnail list. |
|
872 if ( BaflUtils::FileExists( iFs, *path ) ) |
|
873 { |
|
874 HBufC* srvIcon = HBufC::NewLC( path->Length() ); |
|
875 TPtr16 srvIconPtr = srvIcon->Des(); |
|
876 srvIconPtr.Copy( *path ); |
|
877 iIconList.AppendL( srvIcon ); |
|
878 CleanupStack::Pop( srvIcon ); |
|
879 } |
|
880 |
|
881 loop = EFalse; |
|
882 download = ETrue; |
|
883 iDownloadPath.Copy( *path ); |
|
884 IPTVLOGSTRING2_LOW_LEVEL( |
|
885 "RSS Plugin --- CIptvRssPlugin::DownloadThumbnailsL --- Downloading service thumbnail -> %S", |
|
886 &iDownloadPath ); |
|
887 } |
|
888 else |
|
889 { |
|
890 loop = ETrue; |
|
891 download = EFalse; |
|
892 } |
|
893 } |
|
894 else |
|
895 { |
|
896 if ( iThumbnailDlAllowed ) |
|
897 { |
|
898 if ( iIsSearchOperation ) |
|
899 { |
|
900 // Get pathname for search thumbnail. |
|
901 BuildUniqueuPathNameL( |
|
902 iItem->iThumbnailUrl, |
|
903 EIptvPathRssSearchThumbnail, |
|
904 KIptvThumbnailExtension, |
|
905 ETrue, |
|
906 pathPtr ); |
|
907 } |
|
908 else if ( iIsGroupOperation ) |
|
909 { |
|
910 // Get pathname for item thumbnail. |
|
911 BuildUniqueuPathNameL( |
|
912 iItem->iThumbnailUrl, |
|
913 EIptvPathService, |
|
914 KIptvThumbnailExtension, |
|
915 ETrue, |
|
916 pathPtr ); |
|
917 } |
|
918 else |
|
919 { |
|
920 // Get pathname for item thumbnail. |
|
921 BuildUniqueuPathNameL( |
|
922 iItem->iThumbnailUrl, |
|
923 EIptvPathRssThumbnail, |
|
924 KIptvThumbnailExtension, |
|
925 ETrue, |
|
926 pathPtr ); |
|
927 } |
|
928 |
|
929 loop = EFalse; |
|
930 download = ETrue; |
|
931 iDownloadPath.Copy( *path ); |
|
932 IPTVLOGSTRING2_LOW_LEVEL( |
|
933 "RSS Plugin --- CIptvRssPlugin::DownloadThumbnailsL --- Downloading content thumbnail -> %S", |
|
934 &iDownloadPath ); |
|
935 } |
|
936 } |
|
937 CleanupStack::PopAndDestroy( path ); |
|
938 } |
|
939 } |
|
940 else |
|
941 { |
|
942 loop = EFalse; |
|
943 PluginSucceededL(); |
|
944 if ( EIptvRssService == iAction ) |
|
945 { |
|
946 RemoveObsoleteIconsL(); |
|
947 } |
|
948 |
|
949 // Clear already downloaded thumbnail list. |
|
950 iPreviouslyDownloadedAddresses.ResetAndDestroy(); |
|
951 iPreviouslyDownloadedPaths.ResetAndDestroy(); |
|
952 } |
|
953 } |
|
954 |
|
955 if ( download ) |
|
956 { |
|
957 // Get address from possible previously downloaded. |
|
958 HBufC* alreadyDownloaded = GetAlreadyDownloadedPath(); |
|
959 if ( NULL == alreadyDownloaded ) |
|
960 { |
|
961 TRAPD( |
|
962 dlError, |
|
963 iDownload->DownloadL( |
|
964 iServiceAddress, |
|
965 iDownloadPath, |
|
966 ETrue, |
|
967 KIptvEmptyDes, |
|
968 iLastUpdated ) ); |
|
969 |
|
970 // Starting of thumbnail download can fail for example because of |
|
971 // invalid URL. |
|
972 if ( dlError != KErrNone ) |
|
973 { |
|
974 DownloadFinishedL( EDownloadFailed, EIptvDlGeneral ); |
|
975 } |
|
976 } |
|
977 else |
|
978 { |
|
979 // When already downloaded, use it. |
|
980 if ( 0 != iDownloadPath.CompareF( *alreadyDownloaded ) ) |
|
981 { |
|
982 BaflUtils::CopyFile( iFs, *alreadyDownloaded, iDownloadPath ); |
|
983 } |
|
984 |
|
985 // Retain old Thumbnail and remove it from list. |
|
986 HBufC* fileName = HBufC::NewLC( iDownloadPath.Length() ); |
|
987 fileName->Des().Copy( iDownloadPath ); |
|
988 RemoveIconFromList( fileName, EFalse ); |
|
989 CleanupStack::PopAndDestroy( fileName ); |
|
990 |
|
991 // Signaling must be done async to avoid recursive looping. |
|
992 iDownload->SkipCurrentDownloadAsyncL(); |
|
993 } |
|
994 } |
|
995 } |
|
996 |
|
997 // -------------------------------------------------------------------------- |
|
998 // Keep track of already downloaded thumbnails to avoid to redownload. |
|
999 // -------------------------------------------------------------------------- |
|
1000 // |
|
1001 void CIptvRssPlugin::SetAlreadyDownloadedPathL() |
|
1002 { |
|
1003 |
|
1004 #ifdef _DEBUG |
|
1005 |
|
1006 // Debug print filename and url. |
|
1007 TBuf<KIptvMaxPath> debugFileName; |
|
1008 debugFileName.Copy( iDownloadPath ); |
|
1009 |
|
1010 TBuf<KIptvMaxPath> debugUrl; |
|
1011 debugUrl.Copy( iServiceAddress ); |
|
1012 |
|
1013 IPTVLOGSTRING3_LOW_LEVEL( |
|
1014 "RSS Plugin --- CIptvRssPlugin::SetAlreadyDownloadedPathL --- Set to already downloaded: %S From: %S", |
|
1015 &debugFileName, |
|
1016 &debugUrl ); |
|
1017 |
|
1018 #endif |
|
1019 |
|
1020 // Append new service address. |
|
1021 TInt len( iServiceAddress.Length() ); |
|
1022 HBufC8* addr = HBufC8::NewLC( len ); |
|
1023 TPtr8 addrPtr = addr->Des(); |
|
1024 addrPtr.Copy( iServiceAddress ); |
|
1025 iPreviouslyDownloadedAddresses.AppendL( addr ); |
|
1026 CleanupStack::Pop( addr ); |
|
1027 |
|
1028 // Append corresponding path. |
|
1029 len = iDownloadPath.Length(); |
|
1030 HBufC* path = HBufC::NewLC( len ); |
|
1031 TPtr16 pathPtr = path->Des(); |
|
1032 pathPtr.Copy( iDownloadPath ); |
|
1033 iPreviouslyDownloadedPaths.AppendL( path ); |
|
1034 CleanupStack::Pop( path ); |
|
1035 } |
|
1036 |
|
1037 // -------------------------------------------------------------------------- |
|
1038 // Keep track of already downloaded thumbnails to avoid to redownload. |
|
1039 // -------------------------------------------------------------------------- |
|
1040 // |
|
1041 HBufC* CIptvRssPlugin::GetAlreadyDownloadedPath() |
|
1042 { |
|
1043 HBufC* alreadyDownloaded( NULL ); |
|
1044 |
|
1045 TInt icon( -1 ); |
|
1046 |
|
1047 // Find address from list. |
|
1048 for ( TInt i = 0; |
|
1049 ( i < iPreviouslyDownloadedAddresses.Count() ) && ( -1 == icon ); |
|
1050 i++ ) |
|
1051 { |
|
1052 if ( 0 == iServiceAddress.CompareF( *iPreviouslyDownloadedAddresses[i] ) ) |
|
1053 { |
|
1054 icon = i; |
|
1055 } |
|
1056 } |
|
1057 |
|
1058 // When found, return it, otherwise append new one to the list. |
|
1059 if ( icon >= 0 ) |
|
1060 { |
|
1061 if ( iPreviouslyDownloadedPaths.Count() > icon ) |
|
1062 { |
|
1063 alreadyDownloaded = iPreviouslyDownloadedPaths[icon]; |
|
1064 |
|
1065 #ifdef _DEBUG |
|
1066 |
|
1067 // Debug print filename and url. |
|
1068 TBuf<KIptvMaxPath> debugFileName; |
|
1069 debugFileName.Copy( *alreadyDownloaded ); |
|
1070 |
|
1071 TBuf<KIptvMaxPath> debugUrl; |
|
1072 debugUrl.Copy( iServiceAddress ); |
|
1073 |
|
1074 IPTVLOGSTRING3_LOW_LEVEL( |
|
1075 "RSS Plugin --- CIptvRssPlugin::GetAlreadyDownloadedPathL --- Already downloaded: %S From: %S", |
|
1076 &debugFileName, |
|
1077 &debugUrl ); |
|
1078 |
|
1079 #endif |
|
1080 |
|
1081 } |
|
1082 } |
|
1083 |
|
1084 return alreadyDownloaded; |
|
1085 } |
|
1086 |
|
1087 // -------------------------------------------------------------------------- |
|
1088 // Handle idle callback functionality. |
|
1089 // -------------------------------------------------------------------------- |
|
1090 // |
|
1091 TInt CIptvRssPlugin::HandleParseIdleCallback() |
|
1092 { |
|
1093 IPTVLOGSTRING_LOW_LEVEL( |
|
1094 "RSS Plugin --- CIptvRssPlugin::HandleParseIdleCallback" ); |
|
1095 |
|
1096 // By default add KReadAtOnceLength to current parse position |
|
1097 TInt lengthToBeExtracted( KReadAtOnceLength ); |
|
1098 TBool isLastPart( EFalse ); |
|
1099 |
|
1100 // Dealing with last part of the data in the buffer |
|
1101 if ( ( iCurrentParsePosition + lengthToBeExtracted ) > |
|
1102 iXmlFileContent->Length() ) |
|
1103 { |
|
1104 lengthToBeExtracted = |
|
1105 iXmlFileContent->Length() - iCurrentParsePosition; |
|
1106 isLastPart = ETrue; |
|
1107 } |
|
1108 |
|
1109 // Get next data part to be parsed |
|
1110 TPtr8 midPtr = iXmlFileContent->Des().MidTPtr( |
|
1111 iCurrentParsePosition, lengthToBeExtracted ); |
|
1112 TInt err( KErrNone ); |
|
1113 |
|
1114 // Trap possible leave. If there was something, wrong, just stop parsing |
|
1115 TRAP( err, iParser->ParseL( midPtr ) ); |
|
1116 |
|
1117 TInt retVal( 0 ); |
|
1118 // ParseL went just fine |
|
1119 if ( err == KErrNone ) |
|
1120 { |
|
1121 // We are dealing with last part of the data -> let's not call this |
|
1122 // callback again |
|
1123 if ( isLastPart ) |
|
1124 { |
|
1125 // If some leave occured, just ignore it |
|
1126 TRAP( err, iParser->ParseEndL() ); |
|
1127 iCurrentParsePosition = 0; |
|
1128 |
|
1129 #ifndef IPTV_RSS_LOCAL_TEST |
|
1130 |
|
1131 if ( iThumbnailDlAllowed && ( EIptvRssService == iAction ) ) |
|
1132 { |
|
1133 // We will start thumbnail downloading. Lets list |
|
1134 // current icons for comparing them with new available. |
|
1135 TRAP_IGNORE( ListCurrentIconsL() ) |
|
1136 } |
|
1137 |
|
1138 TRAP( err, DownloadThumbnailsL() ); |
|
1139 |
|
1140 #else |
|
1141 |
|
1142 TRAP_IGNORE( PluginSucceededL() ); |
|
1143 |
|
1144 #endif // IPTV_RSS_LOCAL_TEST |
|
1145 |
|
1146 } |
|
1147 // There will still be more data to be parsed in the buffer |
|
1148 else |
|
1149 { |
|
1150 iCurrentParsePosition += KReadAtOnceLength; |
|
1151 retVal = 1; |
|
1152 } |
|
1153 } |
|
1154 // ParseL leaved. Tell manager, that we have finished our job |
|
1155 else |
|
1156 { |
|
1157 TRAP( err, PluginFailedL( EIptvDlNoError ) ); |
|
1158 retVal = 0; |
|
1159 } |
|
1160 |
|
1161 return retVal; |
|
1162 } |
|
1163 |
|
1164 // -------------------------------------------------------------------------- |
|
1165 // Check is thumbnail download allowed. |
|
1166 // -------------------------------------------------------------------------- |
|
1167 // |
|
1168 TBool CIptvRssPlugin::ThumbnailDlAllowedL() const |
|
1169 { |
|
1170 IPTVLOGSTRING_LOW_LEVEL( |
|
1171 "RSS Plugin --- CIptvRssPlugin::ThumbnailDlAllowedL" ); |
|
1172 |
|
1173 TBool allow( EFalse ); |
|
1174 CRepository* cenRep = CRepository::NewL( KIptvCenRepUid ); |
|
1175 if ( cenRep ) |
|
1176 { |
|
1177 CleanupStack::PushL( cenRep ); |
|
1178 TInt value; |
|
1179 TInt error = cenRep->Get( KIptvCenRepVoDThumbnailsKey, value ); |
|
1180 if ( error == KErrNone && value == 1 ) |
|
1181 { |
|
1182 allow = ETrue; |
|
1183 } |
|
1184 CleanupStack::PopAndDestroy( cenRep ); |
|
1185 } |
|
1186 |
|
1187 return allow; |
|
1188 } |
|
1189 |
|
1190 // -------------------------------------------------------------------------- |
|
1191 // XML parsing failed. |
|
1192 // -------------------------------------------------------------------------- |
|
1193 // |
|
1194 void CIptvRssPlugin::SetParsingFailed() |
|
1195 { |
|
1196 IPTVLOGSTRING_LOW_LEVEL( |
|
1197 "RSS Plugin --- CIptvRssPlugin::SetParsingFailed" ); |
|
1198 |
|
1199 iParsingFailed = ETrue; |
|
1200 } |
|
1201 |
|
1202 // -------------------------------------------------------------------------- |
|
1203 // Content update completed. |
|
1204 // -------------------------------------------------------------------------- |
|
1205 // |
|
1206 void CIptvRssPlugin::ContentUpdateCompletedL() |
|
1207 { |
|
1208 IPTVLOGSTRING_LOW_LEVEL( |
|
1209 "RSS Plugin --- CIptvRssPlugin::ContentUpdateCompletedL" ); |
|
1210 |
|
1211 iVodCallback->ContentUpdateCompletedL(); |
|
1212 |
|
1213 if ( EIptvRssService == iAction ) |
|
1214 { |
|
1215 iVodCallback->ErrorL( KIptvThumbnailCount, iDlQueue.Count() ); |
|
1216 } |
|
1217 else if ( EIptvRssSearch == iAction ) |
|
1218 { |
|
1219 iVodCallback->ErrorL( KIptvRssSearchThumbnailCount, iDlQueue.Count() ); |
|
1220 } |
|
1221 } |
|
1222 |
|
1223 // -------------------------------------------------------------------------- |
|
1224 // Set first update. |
|
1225 // -------------------------------------------------------------------------- |
|
1226 // |
|
1227 void CIptvRssPlugin::SetFirstUpdate( TBool /*aFirstUpdate*/ ) |
|
1228 { |
|
1229 IPTVLOGSTRING_LOW_LEVEL( |
|
1230 "RSS Plugin --- CIptvRssPlugin::SetFirstUpdate" ); |
|
1231 } |
|
1232 |
|
1233 // -------------------------------------------------------------------------- |
|
1234 // Build unique pathname for download object. |
|
1235 // -------------------------------------------------------------------------- |
|
1236 // |
|
1237 void CIptvRssPlugin::BuildUniqueuPathNameL( |
|
1238 const TDesC& aUrl, |
|
1239 const TIptvPathSelection aPathSelection, |
|
1240 const TDesC& aDefaultExtension, |
|
1241 const TBool aGenerateName, |
|
1242 TPtr aPathName ) |
|
1243 { |
|
1244 IPTVLOGSTRING_LOW_LEVEL( |
|
1245 "RSS Plugin --- CIptvRssPlugin::BuildUniqueuPathNameL" ); |
|
1246 |
|
1247 // Lets get files type extension ex. .jpg, vcgf, ... |
|
1248 TInt urlLength( aUrl.Length() ); |
|
1249 TInt index( aUrl.LocateReverse( '.' ) ); |
|
1250 TInt extensionLength( 0 ); |
|
1251 |
|
1252 if ( ( urlLength - index ) < KIptvExtensionMaxSize ) |
|
1253 { |
|
1254 extensionLength = urlLength - index; |
|
1255 } |
|
1256 |
|
1257 // Get path for download object. |
|
1258 if ( ( EIptvPathService == aPathSelection ) || |
|
1259 ( EIptvPathTmp == aPathSelection ) ) |
|
1260 { |
|
1261 CIptvUtil::GetPathL( iFs, aPathSelection, aPathName ); |
|
1262 } |
|
1263 // Item thumbnail must be hashed to keep track on it. |
|
1264 else |
|
1265 { |
|
1266 CIptvUtil::GetPathL( iFs, aPathSelection, iServiceId, aPathName ); |
|
1267 } |
|
1268 |
|
1269 if ( aGenerateName ) |
|
1270 { |
|
1271 // Check whether md5 calculator is already constructed. |
|
1272 if ( !iMD5Calculator ) |
|
1273 { |
|
1274 iMD5Calculator = CMD5::NewL(); |
|
1275 } |
|
1276 |
|
1277 // Calculate the 128 bit, 16 byte hash |
|
1278 iMD5Calculator->Reset(); |
|
1279 TBuf8<KIptvMaxPath> buffer; |
|
1280 buffer.Copy( aUrl ); |
|
1281 |
|
1282 TPtrC8 hash = iMD5Calculator->Hash( buffer ); |
|
1283 |
|
1284 // Now print it as a 32 byte hex number |
|
1285 TBuf8<KIptvHexCharInByte> hexNumber; |
|
1286 for ( TInt i = 0; i < hash.Length(); i++ ) |
|
1287 { |
|
1288 hexNumber.Zero(); |
|
1289 hexNumber.Format( KIptvHexByteFormatStr, hash[i] ); |
|
1290 aPathName.Append( hexNumber[0] ); |
|
1291 aPathName.Append( hexNumber[1] ); |
|
1292 } |
|
1293 } |
|
1294 else |
|
1295 { |
|
1296 // Service thumbnail can be with service identifier. |
|
1297 aPathName.AppendNum( static_cast<TUint64>( iServiceId ) ); |
|
1298 } |
|
1299 |
|
1300 // Add thumbnail file extension. |
|
1301 if ( extensionLength > 0 ) |
|
1302 { |
|
1303 // If there was a extension for thumbnail use it |
|
1304 aPathName.Append( aUrl.Right( extensionLength ) ); |
|
1305 } |
|
1306 else |
|
1307 { |
|
1308 // By default add .jpg extension |
|
1309 aPathName.Append( aDefaultExtension ); |
|
1310 } |
|
1311 |
|
1312 #ifdef _DEBUG |
|
1313 |
|
1314 // Debug print filename. |
|
1315 TBuf<KIptvMaxPath> debugFileName; |
|
1316 debugFileName.Copy( aPathName ); |
|
1317 |
|
1318 IPTVLOGSTRING2_LOW_LEVEL( |
|
1319 "RSS Plugin --- CIptvRssPlugin::BuildUniqueuPathNameL Generated path name: %S", |
|
1320 &debugFileName ); |
|
1321 |
|
1322 #endif |
|
1323 |
|
1324 } |
|
1325 |
|
1326 // -------------------------------------------------------------------------- |
|
1327 // List current icons. |
|
1328 // -------------------------------------------------------------------------- |
|
1329 // |
|
1330 void CIptvRssPlugin::ListCurrentIconsL() |
|
1331 { |
|
1332 IPTVLOGSTRING_LOW_LEVEL( |
|
1333 "RSS Plugin --- CIptvRssPlugin::ListCurrentIconsL" ); |
|
1334 |
|
1335 CDir* iconList( NULL ); |
|
1336 |
|
1337 // Create mask path for thumbnail search |
|
1338 HBufC* mask = HBufC::NewLC( KIptvMaxPath ); |
|
1339 TPtr16 maskPtr = mask->Des(); |
|
1340 |
|
1341 // list item icons. |
|
1342 CIptvUtil::GetPathL( iFs, EIptvPathRssThumbnail, iServiceId, maskPtr ); |
|
1343 TInt dirLen( mask->Length() ); |
|
1344 maskPtr.Append( KIptvAllFiles ); |
|
1345 |
|
1346 if ( iFs.GetDir( maskPtr, |
|
1347 KEntryAttNormal, |
|
1348 ESortNone, |
|
1349 iconList ) == KErrNone ) |
|
1350 { |
|
1351 CleanupStack::PushL( iconList ); |
|
1352 |
|
1353 for ( TInt i = 0; i < iconList->Count(); i++ ) |
|
1354 { |
|
1355 TInt len( ( *iconList )[i].iName.Length() ); |
|
1356 HBufC* icon = HBufC::NewLC( dirLen + len ); |
|
1357 TPtr16 iconPtr = icon->Des(); |
|
1358 iconPtr.Copy( maskPtr.Mid( 0, dirLen ) ); |
|
1359 iconPtr.Append( ( *iconList )[i].iName.Mid( 0, len ) ); |
|
1360 iIconList.AppendL( icon ); |
|
1361 |
|
1362 CleanupStack::Pop( icon ); |
|
1363 } |
|
1364 |
|
1365 IPTVLOGSTRING2_LOW_LEVEL( |
|
1366 "RSS Plugin --- CIptvRssPlugin::ListCurrentIconsL found: %d", |
|
1367 iIconList.Count() ); |
|
1368 |
|
1369 CleanupStack::PopAndDestroy( iconList ); |
|
1370 } |
|
1371 |
|
1372 CleanupStack::PopAndDestroy( mask ); |
|
1373 } |
|
1374 |
|
1375 // -------------------------------------------------------------------------- |
|
1376 // Remove icons stored to list. These icons are either from remove items or |
|
1377 // all icons are decided to be removed. |
|
1378 // -------------------------------------------------------------------------- |
|
1379 // |
|
1380 void CIptvRssPlugin::RemoveObsoleteIconsL() |
|
1381 { |
|
1382 IPTVLOGSTRING2_LOW_LEVEL( |
|
1383 "RSS Plugin --- CIptvRssPlugin::RemoveObsoleteIconsL Count : %d", |
|
1384 iIconList.Count() ); |
|
1385 |
|
1386 HBufC* iconPath( NULL ); |
|
1387 |
|
1388 // Fetch thumbnail of last watched clip, when any. |
|
1389 CIptvLastWatchedApi* lastWatchedApi = CIptvLastWatchedApi::NewL(); |
|
1390 CleanupStack::PushL( lastWatchedApi ); |
|
1391 |
|
1392 CIptvLastWatchedData* lwData = CIptvLastWatchedData::NewL(); |
|
1393 if ( lwData ) |
|
1394 { |
|
1395 CleanupStack::PushL( lwData ); |
|
1396 TInt err( KErrNone ); |
|
1397 TRAPD( leaveErr, err = lastWatchedApi->GetLastWatchedDataL( *lwData ) ); |
|
1398 |
|
1399 if ( KErrNone == leaveErr && KErrNone == err ) |
|
1400 { |
|
1401 // Fetch thumbnail, no need to put it to cleanup stack. |
|
1402 iconPath = HBufC::NewL( lwData->IconPath().Length() ); |
|
1403 iconPath->Des().Copy( lwData->IconPath() ); |
|
1404 } |
|
1405 CleanupStack::PopAndDestroy( lwData ); |
|
1406 } |
|
1407 CleanupStack::PopAndDestroy( lastWatchedApi ); |
|
1408 |
|
1409 for ( TInt icon = 0; icon < iIconList.Count(); icon++ ) |
|
1410 { |
|
1411 TBool wasLastWatched( EFalse ); |
|
1412 |
|
1413 // Check whether thumbnail belongs to last watched clip. |
|
1414 if ( iconPath ) |
|
1415 { |
|
1416 if ( 0 == iIconList[icon]->Des().CompareF( *iconPath ) ) |
|
1417 { |
|
1418 wasLastWatched = ETrue; |
|
1419 } |
|
1420 } |
|
1421 |
|
1422 #ifdef _DEBUG |
|
1423 |
|
1424 // Debug print filename. |
|
1425 TBuf<KIptvMaxPath> debugFileName; |
|
1426 debugFileName.Copy( iIconList[icon]->Des() ); |
|
1427 if ( wasLastWatched ) |
|
1428 { |
|
1429 IPTVLOGSTRING2_LOW_LEVEL( |
|
1430 "RSS Plugin --- CIptvRssPlugin::RemoveObsoleteIconsL Thumbnail of last watched clip saved: %S", |
|
1431 &debugFileName ); |
|
1432 } |
|
1433 else |
|
1434 { |
|
1435 IPTVLOGSTRING2_LOW_LEVEL( |
|
1436 "RSS Plugin --- CIptvRssPlugin::RemoveObsoleteIconsL Thumbnail deleted: %S", |
|
1437 &debugFileName ); |
|
1438 } |
|
1439 |
|
1440 #endif |
|
1441 |
|
1442 if ( !wasLastWatched ) |
|
1443 { |
|
1444 // Delete list thumbnail. |
|
1445 iFs.Delete( iIconList[icon]->Des() ); |
|
1446 } |
|
1447 } |
|
1448 |
|
1449 if ( iconPath ) |
|
1450 { |
|
1451 delete iconPath; |
|
1452 iconPath = NULL; |
|
1453 } |
|
1454 |
|
1455 // Remove all icons from list. |
|
1456 iIconList.ResetAndDestroy(); |
|
1457 } |
|
1458 |
|
1459 // -------------------------------------------------------------------------- |
|
1460 // Find thumbnail from list and delete it when found. |
|
1461 // -------------------------------------------------------------------------- |
|
1462 // |
|
1463 void CIptvRssPlugin::RemoveIconFromList( |
|
1464 const HBufC* aIconName, |
|
1465 TBool aDelete ) |
|
1466 { |
|
1467 IPTVLOGSTRING_LOW_LEVEL( |
|
1468 "RSS Plugin --- CIptvRssPlugin::RemoveIconFromList" ); |
|
1469 |
|
1470 if ( aIconName && ( EIptvRssService == iAction ) ) |
|
1471 { |
|
1472 TInt icon( -1 ); |
|
1473 |
|
1474 // Find icon from list. |
|
1475 for ( TInt i = 0; ( i < iIconList.Count() ) && ( -1 == icon ); i++ ) |
|
1476 { |
|
1477 if ( 0 == iIconList[i]->Des().CompareF( *aIconName ) ) |
|
1478 { |
|
1479 icon = i; |
|
1480 } |
|
1481 } |
|
1482 |
|
1483 // When found, remove it. |
|
1484 if ( icon >= 0 ) |
|
1485 { |
|
1486 if ( aDelete ) |
|
1487 { |
|
1488 |
|
1489 #ifdef _DEBUG |
|
1490 |
|
1491 // Debug print filename. |
|
1492 TBuf<KIptvMaxPath> debugFileName; |
|
1493 debugFileName.Copy( iIconList[icon]->Des() ); |
|
1494 IPTVLOGSTRING2_LOW_LEVEL( |
|
1495 "RSS Plugin --- CIptvRssPlugin::RemoveIconFromList --- Thumbnail deleted: %S", |
|
1496 &debugFileName ); |
|
1497 |
|
1498 #endif |
|
1499 |
|
1500 // Delete list thumbnail. |
|
1501 iFs.Delete( iIconList[icon]->Des() ); |
|
1502 } |
|
1503 |
|
1504 // Remove thumbnail from list. |
|
1505 delete iIconList[icon]; |
|
1506 iIconList.Remove( icon ); |
|
1507 } |
|
1508 } |
|
1509 } |