videofeeds/mrssplugin/src/CIptvRssDownload.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <sysutil.h>
       
    23 #include "IptvDebug.h"
       
    24 #include <bautils.h>
       
    25 #include "CIptvTimer.h"
       
    26 #include "CIptvRssDownload.h"
       
    27 #include "CIptvRssPlugin.h"
       
    28 #include "CIptvEpgService.h"
       
    29 #include "CIptv3XmlContentHandler.h"
       
    30 #include "ciptvxmldatetime.h"
       
    31 
       
    32 // 0x10281F1E is the uid of the IptvUtil dll. This is taken
       
    33 // into use by reason following:
       
    34 // There can be two simultaneous RSS downloads ongoing at the
       
    35 // same time; one for search and one for vod. Download manager
       
    36 // prevents simultaneous downloads if uid given during Connect
       
    37 // is already active. That's why we take another uid into use
       
    38 // to allow search operations to run simultaneously with the
       
    39 // normal vod update.
       
    40 const TUid KIptvSearchUid = { 0x10281F1E };
       
    41 
       
    42 const TInt KIptvMaxTimeoutInSeconds( 60 );
       
    43 const TInt KIptvMaxPauseInSeconds( 10 );
       
    44 
       
    45 const TInt KIptvTime_1_second( 1000000 );
       
    46 const TInt KIptvTime_200_microsecond( 200 );
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 void CIptvRssDownload::ConstructL()
       
    55     {
       
    56     iTimer = CIptvTimer::NewL( CActive::EPriorityUserInput, *this );
       
    57     }
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // Two-phased constructor.
       
    61 // Create instance of concrete interface implementation
       
    62 // --------------------------------------------------------------------------
       
    63 //
       
    64 CIptvRssDownload* CIptvRssDownload::NewL(
       
    65     CIptvRssPlugin& aPlugin,
       
    66     RFs& aFs,
       
    67     CIptvXmlContentHandler& aXmlContentHandler )
       
    68     {
       
    69     CIptvRssDownload* self = new( ELeave ) CIptvRssDownload(
       
    70         aPlugin,
       
    71         aFs,
       
    72         aXmlContentHandler );
       
    73     CleanupStack::PushL( self );
       
    74 
       
    75     self->ConstructL();
       
    76 
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // Destructor
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CIptvRssDownload::~CIptvRssDownload()
       
    86     {
       
    87     IPTVLOGSTRING_LOW_LEVEL(
       
    88         "RSS Plugin --- CIptvRssDownload::~CIptvRssDownload" );
       
    89 
       
    90     if ( iTimer )
       
    91         {
       
    92         if ( iTimer->IsActive() )
       
    93             {
       
    94             iTimer->Cancel();
       
    95             }
       
    96         delete iTimer;
       
    97         iTimer = NULL;
       
    98         }
       
    99 
       
   100     Disconnect();
       
   101 
       
   102     iService = NULL;
       
   103 
       
   104     delete iDlDeleteTimer;
       
   105     delete iFileName;
       
   106     delete iUri;
       
   107     delete iETag;
       
   108 
       
   109     IPTVLOGSTRING_LOW_LEVEL(
       
   110         "RSS Plugin --- CIptvRssDownload::~CIptvRssDownload exit" );
       
   111     }
       
   112 
       
   113 // --------------------------------------------------------------------------
       
   114 // C++ default constructor
       
   115 // --------------------------------------------------------------------------
       
   116 //
       
   117 CIptvRssDownload::CIptvRssDownload(
       
   118     CIptvRssPlugin& aPlugin,
       
   119     RFs& aFs,
       
   120     CIptvXmlContentHandler& aXmlContentHandler ) :
       
   121     iService( NULL ),
       
   122     iPlugin( aPlugin ),
       
   123     iThumbnail( EFalse ),
       
   124     iDownloadId( 0 ),
       
   125     iTimer( NULL ),
       
   126     iConnected( EFalse ),
       
   127     iState( ENormal ),
       
   128     iPauseCounter( 0 ),
       
   129     iFs( aFs ),
       
   130     iXmlContentHandler( aXmlContentHandler )
       
   131     {
       
   132     }
       
   133 
       
   134 // --------------------------------------------------------------------------
       
   135 // Start download.
       
   136 // --------------------------------------------------------------------------
       
   137 //
       
   138 void CIptvRssDownload::DownloadL(
       
   139     const TDesC8& aUri,
       
   140     const TDesC& aFileName,
       
   141     TBool aThumbnail,
       
   142     const TDesC& aETag,
       
   143     const TTime& aLastUpdated )
       
   144     {
       
   145     if ( iState != ENormal && iState != EFinished )
       
   146         {
       
   147         IPTVLOGSTRING_LOW_LEVEL(
       
   148             "RSS Plugin --- CIptvRssDownload::DownloadL Busy Leave" );
       
   149         User::Leave( KErrAlreadyExists );
       
   150         }
       
   151     if ( ( 0 == aFileName.Length() ) || ( 0 == aUri.Length() ) )
       
   152         {
       
   153         IPTVLOGSTRING_LOW_LEVEL(
       
   154             "RSS Plugin --- CIptvRssDownload::DownloadL Argument Leave" );
       
   155         User::Leave( KErrArgument );
       
   156         }
       
   157     ChangeState( ENormal );
       
   158 
       
   159 #ifdef _DEBUG
       
   160 
       
   161     // Debug print filename.
       
   162     TBuf<KIptvMaxPath> debugFileName;
       
   163     debugFileName.Copy( aFileName );
       
   164     IPTVLOGSTRING2_LOW_LEVEL(
       
   165         "RSS Plugin --- CIptvRssDownload::DownloadL aFileName :         %S",
       
   166         &debugFileName );
       
   167 
       
   168     // Debug print Uri.
       
   169     TBuf<KIptvUrlMaxLength> debugUri;
       
   170     debugUri.Copy( aUri );
       
   171     IPTVLOGSTRING2_LOW_LEVEL(
       
   172         "RSS Plugin --- CIptvRssDownload::DownloadL aUri :              %S",
       
   173         &debugUri );
       
   174 
       
   175 #endif
       
   176 
       
   177     // When header information is given, fist dowload will fetch these values
       
   178     // for check. Thumbnail file must also exist to enable check.
       
   179     iWaitingContentTypeCheck =
       
   180         ( ( 0 != aETag.CompareC( KIptvEmptyDes ) ) ||
       
   181           ( TTime( 0LL ) != aLastUpdated ) )  &&
       
   182         !iDisableLastModifiedCheck &&
       
   183         ( !aThumbnail || BaflUtils::FileExists( iFs, aFileName ) );
       
   184     IPTVLOGSTRING2_LOW_LEVEL(
       
   185         "RSS Plugin --- CIptvRssDownload::DownloadL Content type check: %d",
       
   186         iWaitingContentTypeCheck );
       
   187 
       
   188     // Store argument data for further use.
       
   189     if ( iUri )
       
   190         {
       
   191         delete iUri;
       
   192         iUri = NULL;
       
   193         }
       
   194     iUri = HBufC8::NewL( aUri.Length() );
       
   195     iUri->Des().Copy( aUri );
       
   196 
       
   197     if ( iFileName )
       
   198         {
       
   199         delete iFileName;
       
   200         iFileName = NULL;
       
   201         }
       
   202     iFileName = HBufC::NewL( aFileName.Length() );
       
   203     iFileName->Des().Copy( aFileName );
       
   204 
       
   205     if ( iETag )
       
   206         {
       
   207         delete iETag;
       
   208         iETag = NULL;
       
   209         }
       
   210     if ( 0 < aETag.Length() )
       
   211         {
       
   212         iETag = HBufC::NewL( aETag.Length() );
       
   213         iETag->Des().Copy( aETag );
       
   214         }
       
   215 
       
   216     iLastUpdated = aLastUpdated;
       
   217     iThumbnail = aThumbnail;
       
   218 
       
   219     // When no check, old thumbnail can be removed at once.
       
   220     if ( iThumbnail && iFileName && !iWaitingContentTypeCheck )
       
   221         {
       
   222         iPlugin.RemoveIconFromList( iFileName, ETrue );
       
   223         }
       
   224 
       
   225     // Create new download.
       
   226     RHttpDownload& download =
       
   227         iDownloadManager.CreateDownloadL( aUri );
       
   228 
       
   229     // Set download attributes.
       
   230     download.SetBoolAttribute( EDlAttrNoContentTypeCheck, !iWaitingContentTypeCheck );
       
   231     SetAuthenticationInformationL( download );
       
   232     if ( !iWaitingContentTypeCheck )
       
   233         {
       
   234         // Content check will not require filename and DownloadManager would anyway
       
   235         // delete it.
       
   236         download.SetStringAttribute( EDlAttrDestFilename, aFileName );
       
   237         }
       
   238 
       
   239     IPTVLOGSTRING2_LOW_LEVEL(
       
   240         "RSS Plugin --- CIptvRssDownload::DownloadL Using IAP: %d",
       
   241         iService->iIap );
       
   242     User::LeaveIfError(
       
   243         iDownloadManager.SetIntAttribute( EDlMgrIap, iService->iIap ) );
       
   244 
       
   245     // Start download.
       
   246     User::LeaveIfError( download.Start() );
       
   247     download.GetIntAttribute( EDlAttrId, iDownloadId );
       
   248     iDownloadIdValid = ETrue;
       
   249     }
       
   250 
       
   251 // --------------------------------------------------------------------------
       
   252 // Restart download.
       
   253 // --------------------------------------------------------------------------
       
   254 //
       
   255 void CIptvRssDownload::DownloadL()
       
   256     {
       
   257     if ( iState != ENormal && iState != EFinished )
       
   258         {
       
   259         IPTVLOGSTRING_LOW_LEVEL(
       
   260             "RSS Plugin --- CIptvRssDownload::DownloadL Busy Leave" );
       
   261         User::Leave( KErrAlreadyExists );
       
   262         }
       
   263     if ( !iFileName || !iUri )
       
   264         {
       
   265         IPTVLOGSTRING_LOW_LEVEL(
       
   266             "RSS Plugin --- CIptvRssDownload::DownloadL Argument Leave" );
       
   267         User::Leave( KErrArgument );
       
   268         }
       
   269     ChangeState( ENormal );
       
   270 
       
   271 #ifdef _DEBUG
       
   272 
       
   273     // Debug print filename.
       
   274     TBuf<KIptvMaxPath> debugFileName;
       
   275     debugFileName.Copy( iFileName->Des() );
       
   276     IPTVLOGSTRING2_LOW_LEVEL(
       
   277         "RSS Plugin --- CIptvRssDownload::DownloadL aFileName :         %S",
       
   278         &debugFileName );
       
   279 
       
   280 #endif
       
   281 
       
   282     iWaitingContentTypeCheck = EFalse;
       
   283 
       
   284     // Create new download.
       
   285     RHttpDownload& download =
       
   286         iDownloadManager.CreateDownloadL( iUri->Des() );
       
   287 
       
   288     // Set download attributes.
       
   289     download.SetBoolAttribute( EDlAttrNoContentTypeCheck, ETrue );
       
   290     SetAuthenticationInformationL( download );
       
   291     download.SetStringAttribute( EDlAttrDestFilename, iFileName->Des() );
       
   292     IPTVLOGSTRING2_LOW_LEVEL(
       
   293         "RSS Plugin --- CIptvRssDownload::DownloadL Using IAP: %d",
       
   294         iService->iIap );
       
   295     User::LeaveIfError(
       
   296         iDownloadManager.SetIntAttribute( EDlMgrIap, iService->iIap ) );
       
   297 
       
   298     // Start download.
       
   299     User::LeaveIfError( download.Start() );
       
   300     download.GetIntAttribute( EDlAttrId, iDownloadId );
       
   301     iDownloadIdValid = ETrue;
       
   302     }
       
   303 
       
   304 // --------------------------------------------------------------------------
       
   305 // From MHttpDownloadMgrObserver.
       
   306 // --------------------------------------------------------------------------
       
   307 //
       
   308 void CIptvRssDownload::HandleDMgrEventL(
       
   309     RHttpDownload& aDownload,
       
   310     THttpDownloadEvent aEvent )
       
   311     {
       
   312     IPTVLOGSTRING_LOW_LEVEL(
       
   313         "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL" );
       
   314 
       
   315     // In EThumbnail and ENoDiskSpace states we do not need to do anything
       
   316     // for new events. We are just waiting for our timer to step in.
       
   317     // When iTimer is NULL, we are shutting down.
       
   318     if ( ( iState == EThumbnail ) || ( iState == ENoDiskSpace ) || !iTimer || iDlDeleteTimer )
       
   319         {
       
   320         return;
       
   321         }
       
   322 
       
   323     //lint -e{961} Else block not needed, default is no operation.
       
   324     if ( iState == EPause )
       
   325         {
       
   326         iTimer->Cancel();
       
   327         ChangeState( ENormal );
       
   328         IPTVLOGSTRING2_LOW_LEVEL(
       
   329             "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL PAUSED %d SECONDS, NOW CONTINUING!",
       
   330             iPauseCounter );
       
   331         iPauseCounter = 0;
       
   332         }
       
   333     else if ( iState == EWaiting )
       
   334         {
       
   335         iTimer->Cancel();
       
   336         ChangeState( ENormal );
       
   337         IPTVLOGSTRING2_LOW_LEVEL(
       
   338             "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL WAITED EVENTS FROM DL-MANAGER %d SECONDS",
       
   339             iPauseCounter );
       
   340         iPauseCounter = 0;
       
   341         }
       
   342     else if ( iState == ETimeout )
       
   343         {
       
   344         if ( aEvent.iDownloadState == EHttpDlCreated )
       
   345             {
       
   346             IPTVLOGSTRING_LOW_LEVEL(
       
   347                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL download state was EHttpDlCreated." );
       
   348             ChangeState( ENormal );
       
   349             iPauseCounter = 0;
       
   350             }
       
   351         else
       
   352             {
       
   353             IPTVLOGSTRING_LOW_LEVEL(
       
   354                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL iState == ETimeout -> return" );
       
   355             return;
       
   356             }
       
   357         }
       
   358 
       
   359     TInt32 fileSizeReported = 0;
       
   360     aDownload.GetIntAttribute( EDlAttrUserData, fileSizeReported );
       
   361 
       
   362     // We keep checking file size until it is available in EDlAttrLength.
       
   363     if ( fileSizeReported == 0 )
       
   364         {
       
   365         TInt32 fullSize = 0;
       
   366 
       
   367         aDownload.GetIntAttribute( EDlAttrLength, fullSize );
       
   368         IPTVLOGSTRING2_LOW_LEVEL(
       
   369             "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL  Full size: %d", fullSize );
       
   370 
       
   371         if ( fullSize > 0 )
       
   372             {
       
   373             aDownload.SetIntAttribute( EDlAttrUserData, ETrue );
       
   374 
       
   375             // For thumbnails, we check if size of file exceeds the maximum
       
   376             // allowed. If it does, the file is not downloaded at all.
       
   377             if ( iThumbnail && fullSize > KIptvRssMaxThumbnailSize )
       
   378                 {
       
   379                 IPTVLOGSTRING3_LOW_LEVEL(
       
   380                     "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL Thumbnail too big %d, max size %d, download cancelled!!!",
       
   381                     fullSize,
       
   382                     KIptvRssMaxThumbnailSize );
       
   383 
       
   384 #ifdef _DEBUG
       
   385 
       
   386                     switch ( iState )
       
   387                         {
       
   388                         case ENormal:
       
   389                             IPTVLOGSTRING_LOW_LEVEL(
       
   390                                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL iState changed from ENormal -> EThumbnail" );
       
   391                             break;
       
   392 
       
   393                         case EThumbnail:
       
   394                             IPTVLOGSTRING_LOW_LEVEL(
       
   395                                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL iState changed from EThumbnail -> EThumbnail" );
       
   396                             break;
       
   397 
       
   398                         case EFinished:
       
   399                             IPTVLOGSTRING_LOW_LEVEL(
       
   400                                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL iState changed from EFinished -> EThumbnail" );
       
   401                             break;
       
   402 
       
   403                         default:
       
   404                             IPTVLOGSTRING_LOW_LEVEL(
       
   405                                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL iState changed from ? -> EThumbnail" );
       
   406                             break;
       
   407                         }
       
   408 
       
   409 #endif // _DEBUG
       
   410 
       
   411                 iState = EThumbnail;
       
   412 
       
   413                 if ( iTimer )
       
   414                     {
       
   415                     iTimer->Cancel();
       
   416                     iTimer->After( KIptvTime_200_microsecond );
       
   417                     return;
       
   418                     }
       
   419                 }
       
   420             // For all other files, those that will be actually downloaded,
       
   421             // we check that we don't exceed critical disk space levels.
       
   422             else
       
   423                 {
       
   424                 TBool checkResult = EFalse;
       
   425                 TRAPD( checkError, checkResult =
       
   426                     SysUtil::DiskSpaceBelowCriticalLevelL(
       
   427                         &iFs, static_cast<TInt64>(fullSize), EDriveC ) );
       
   428                 if ( checkError != KErrNone || checkResult )
       
   429                     {
       
   430                     IPTVLOGSTRING_LOW_LEVEL(
       
   431                         "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL Disk space under critical level!!!" );
       
   432 
       
   433                     ChangeState( ENoDiskSpace );
       
   434 
       
   435                     if ( iTimer )
       
   436                         {
       
   437                         iTimer->Cancel();
       
   438                         iTimer->After( KIptvTime_200_microsecond );
       
   439                         return;
       
   440                         }
       
   441                     }
       
   442 
       
   443 #ifdef _DEBUG
       
   444 
       
   445                 else
       
   446                     {
       
   447                     IPTVLOGSTRING_LOW_LEVEL(
       
   448                         "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL Disk space ok." );
       
   449                     }
       
   450 
       
   451 #endif // _DEBUG
       
   452 
       
   453                 }
       
   454             }
       
   455         }
       
   456 
       
   457     switch ( aEvent.iProgressState )
       
   458         {
       
   459         case EHttpContentTypeReceived:
       
   460             {
       
   461             IPTVLOGSTRING_LOW_LEVEL(
       
   462                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpContentTypeReceived" );
       
   463 
       
   464             // Fetch header info to find out whether item has bee updated.
       
   465             TBuf<KMaxGeneralHeaderFieldLength> responseETag;
       
   466             TBuf<KMaxGeneralHeaderFieldLength> responseModifiedSince;
       
   467             aDownload.GetStringAttribute( EDlAttrResponseETag, responseETag );
       
   468             aDownload.GetStringAttribute( EDlAttrEntityLastModified, responseModifiedSince );
       
   469             iWaitingContentTypeCheck = EFalse;
       
   470 
       
   471             // Compare header info.
       
   472             TBool eTagMatch( EFalse );
       
   473             if ( iETag )
       
   474                 {
       
   475                 if ( responseETag.Length() > 0 )
       
   476                     {
       
   477                     eTagMatch = ( responseETag.Compare( iETag->Des() ) == 0 );
       
   478 
       
   479                     IPTVLOGSTRING2_LOW_LEVEL( "EDlAttrResponseETag :            %S",
       
   480                         &responseETag );
       
   481                     IPTVLOGSTRING2_LOW_LEVEL( "Local eTag valid :               %d",
       
   482                         eTagMatch );
       
   483                     }
       
   484 
       
   485                 delete iETag;
       
   486                 iETag = NULL;
       
   487                 iETag = HBufC::NewL( responseETag.Length() );
       
   488                 iETag->Des().Copy( responseETag );
       
   489                 }
       
   490 
       
   491             TBool modifiedSinceMatch( EFalse );
       
   492             if ( responseModifiedSince.Length() > 0 )
       
   493                 {
       
   494                 TTime lastUpdated( static_cast<TUint64>( 0 ) );
       
   495 
       
   496                 // Parse time string to TTime
       
   497                 HBufC* lastUpdatedStr = HBufC::NewLC( responseModifiedSince.Length() );
       
   498                 lastUpdatedStr->Des().Copy( responseModifiedSince );
       
   499                 CIptvXmlDateTime::ParseGmtL( lastUpdatedStr, lastUpdated );
       
   500                 CleanupStack::PopAndDestroy( lastUpdatedStr );
       
   501 
       
   502                 modifiedSinceMatch = lastUpdated <= iLastUpdated;
       
   503 
       
   504 #ifdef _DEBUG
       
   505 
       
   506                 // Debug print last updated info.
       
   507                 TBuf<KIptvEpgDbLastModifiedMaxLength> ecgDatePrint;
       
   508                 TBuf<KIptvEpgDbLastModifiedMaxLength> itemDatePrint;
       
   509                 _LIT( KIptvDatePrint, "%D%M%Y%/0%1%/1%2%/2%3%/3" );
       
   510                 iLastUpdated.FormatL( ecgDatePrint, KIptvDatePrint );
       
   511                 lastUpdated.FormatL( itemDatePrint, KIptvDatePrint );
       
   512 
       
   513                 TBuf<KIptvEpgDbLastModifiedMaxLength> ecgTimePrint;
       
   514                 TBuf<KIptvEpgDbLastModifiedMaxLength> itemTimePrint;
       
   515                 _LIT( KIptvTimePrint, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B" );
       
   516                 iLastUpdated.FormatL( ecgTimePrint, KIptvTimePrint );
       
   517                 lastUpdated.FormatL( itemTimePrint, KIptvTimePrint );
       
   518 
       
   519                 IPTVLOGSTRING2_LOW_LEVEL( "EDlAttrEntityLastModified :      %S",
       
   520                     &responseModifiedSince );
       
   521                 IPTVLOGSTRING3_LOW_LEVEL( "Local entity was last updated :  %S %S",
       
   522                     &ecgDatePrint,
       
   523                     &ecgTimePrint );
       
   524                 IPTVLOGSTRING3_LOW_LEVEL( "Server entity was last updated : %S %S",
       
   525                     &itemDatePrint,
       
   526                     &itemTimePrint );
       
   527                 IPTVLOGSTRING2_LOW_LEVEL( "Local entity valid :             %d",
       
   528                     modifiedSinceMatch );
       
   529 
       
   530 #endif
       
   531 
       
   532                 iLastUpdated = lastUpdated;
       
   533 
       
   534                 }
       
   535             else
       
   536                 {
       
   537                 iLastUpdated = TTime( static_cast<TUint64>( 0 ) );
       
   538                 }
       
   539 
       
   540 
       
   541             if ( eTagMatch || modifiedSinceMatch )
       
   542                 {
       
   543                 // Download headers match, no download required.
       
   544                 IPTVLOGSTRING_LOW_LEVEL(
       
   545                     "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL: Headers match to previous." );
       
   546                 iDlStatus = EDownloadNoNeed;
       
   547                 iDlError  = EIptvDlNoError;
       
   548 
       
   549                 DeleteDownloadAsyncL();
       
   550 
       
   551                 // Retain old Thumbnail and remove it from list.
       
   552                 if ( iThumbnail && iFileName )
       
   553                     {
       
   554                     iPlugin.RemoveIconFromList( iFileName, EFalse );
       
   555                     }
       
   556                 }
       
   557             else
       
   558                 {
       
   559                 // Download headers do not match.
       
   560                 IPTVLOGSTRING_LOW_LEVEL(
       
   561                     "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL: Headers do not match." );
       
   562                 iDlStatus = EDownloadNeeded;
       
   563                 iDlError  = EIptvDlNoError;
       
   564                 ChangeState( ENormal );
       
   565                 iRestartDownload = ETrue;
       
   566 
       
   567                 // When service will not support header info, do not request it further.
       
   568                 if ( ( 0 ==  responseETag.Length() ) &&
       
   569                      ( 0 == responseModifiedSince.Length() ) )
       
   570                     {
       
   571                     IPTVLOGSTRING_LOW_LEVEL(
       
   572                         "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL: Further header check disabled." );
       
   573                     iDisableLastModifiedCheck = ETrue; // Suppress further check
       
   574                     }
       
   575 
       
   576                 DeleteDownloadAsyncL();
       
   577 
       
   578                 if ( iFileName )
       
   579                     {
       
   580                     // Delete old Thumbnail if exists and remove it from list.
       
   581                     if ( iThumbnail )
       
   582                         {
       
   583                         iPlugin.RemoveIconFromList( iFileName, ETrue );
       
   584                         }
       
   585                     else
       
   586                         {
       
   587                         // Delete old file if exist.
       
   588                         if ( BaflUtils::FileExists( iFs, iFileName->Des() ) )
       
   589                             {
       
   590                             iFs.Delete( iFileName->Des() );
       
   591                             }
       
   592                         }
       
   593                     }
       
   594                 }
       
   595             }
       
   596             break;
       
   597 
       
   598         case EHttpProgNone:
       
   599             {
       
   600             IPTVLOGSTRING_LOW_LEVEL(
       
   601                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgNone" );
       
   602             }
       
   603             break;
       
   604 
       
   605         case EHttpStarted:
       
   606             {
       
   607             IPTVLOGSTRING_LOW_LEVEL(
       
   608                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpStarted" );
       
   609             }
       
   610             break;
       
   611 
       
   612         case EHttpProgCreatingConnection:
       
   613             {
       
   614             IPTVLOGSTRING_LOW_LEVEL(
       
   615                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgCreatingConnection" );
       
   616             }
       
   617             break;
       
   618 
       
   619         case EHttpProgConnectionNeeded:
       
   620             {
       
   621             IPTVLOGSTRING_LOW_LEVEL(
       
   622                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgConnectionNeeded" );
       
   623             }
       
   624             break;
       
   625 
       
   626         case EHttpProgConnected:
       
   627             {
       
   628             IPTVLOGSTRING_LOW_LEVEL(
       
   629                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgConnected" );
       
   630             }
       
   631             break;
       
   632 
       
   633         case EHttpProgConnectionSuspended:
       
   634             {
       
   635             IPTVLOGSTRING_LOW_LEVEL(
       
   636                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgConnectionSuspended" );
       
   637             }
       
   638             break;
       
   639 
       
   640         case EHttpProgDisconnected:
       
   641             {
       
   642             IPTVLOGSTRING_LOW_LEVEL(
       
   643                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgDisconnected" );
       
   644             }
       
   645             break;
       
   646 
       
   647         case EHttpProgDownloadStarted:
       
   648             {
       
   649             IPTVLOGSTRING_LOW_LEVEL(
       
   650                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgDownloadStarted" );
       
   651             }
       
   652             break;
       
   653 
       
   654         case EHttpContentTypeRequested:
       
   655             {
       
   656             IPTVLOGSTRING_LOW_LEVEL(
       
   657                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpContentTypeRequested" );
       
   658             }
       
   659             break;
       
   660 
       
   661         case EHttpProgSubmitIssued:
       
   662             {
       
   663             IPTVLOGSTRING_LOW_LEVEL(
       
   664                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgSubmitIssued" );
       
   665             }
       
   666             break;
       
   667 
       
   668         case EHttpProgResponseHeaderReceived:
       
   669             {
       
   670             IPTVLOGSTRING_LOW_LEVEL(
       
   671                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgResponseHeaderReceived" );
       
   672             }
       
   673             break;
       
   674 
       
   675         case EHttpProgResponseBodyReceived:
       
   676             {
       
   677             IPTVLOGSTRING_LOW_LEVEL(
       
   678                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgResponseBodyReceived" );
       
   679             }
       
   680             break;
       
   681 
       
   682         case EHttpProgRedirectedPermanently:
       
   683             {
       
   684             IPTVLOGSTRING_LOW_LEVEL(
       
   685                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgRedirectedPermanently" );
       
   686             }
       
   687             break;
       
   688 
       
   689         case EHttpProgRedirectedTemporarily:
       
   690             {
       
   691             IPTVLOGSTRING_LOW_LEVEL(
       
   692                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgRedirectedTemporarily" );
       
   693             }
       
   694             break;
       
   695 
       
   696         case EHttpProgDlNameChanged:
       
   697             {
       
   698             IPTVLOGSTRING_LOW_LEVEL(
       
   699                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgDlNameChanged" );
       
   700             }
       
   701             break;
       
   702 
       
   703         case EHttpProgContentTypeChanged:
       
   704             {
       
   705             IPTVLOGSTRING_LOW_LEVEL(
       
   706                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgContentTypeChanged" );
       
   707             }
       
   708             break;
       
   709 
       
   710         case EHttpProgCodDescriptorDownloaded:
       
   711             {
       
   712             IPTVLOGSTRING_LOW_LEVEL(
       
   713                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgCodDescriptorDownloaded" );
       
   714             }
       
   715             break;
       
   716 
       
   717         case EHttpProgCodDownloadStarted:
       
   718             {
       
   719             IPTVLOGSTRING_LOW_LEVEL(
       
   720                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgCodDownloadStarted" );
       
   721             }
       
   722             break;
       
   723 
       
   724         case EHttpProgCodDescriptorAccepted:
       
   725             {
       
   726             IPTVLOGSTRING_LOW_LEVEL(
       
   727                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgCodDescriptorAccepted" );
       
   728             }
       
   729             break;
       
   730 
       
   731         case EHttpProgCodLoadEnd:
       
   732             {
       
   733             IPTVLOGSTRING_LOW_LEVEL(
       
   734                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgCodLoadEnd" );
       
   735             }
       
   736             break;
       
   737 
       
   738         case EHttpProgSupportedMultiPart:
       
   739             {
       
   740             IPTVLOGSTRING_LOW_LEVEL(
       
   741                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL HttpProgSupportedMultiPart" );
       
   742             }
       
   743             break;
       
   744 
       
   745         case EHttpProgMovingContentFile:
       
   746             {
       
   747             IPTVLOGSTRING_LOW_LEVEL(
       
   748                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgMovingContentFilep" );
       
   749             }
       
   750             break;
       
   751 
       
   752         case EHttpProgContentFileMoved:
       
   753             {
       
   754             IPTVLOGSTRING_LOW_LEVEL(
       
   755                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpProgContentFileMoved" );
       
   756             }
       
   757             break;
       
   758 
       
   759         default:
       
   760             {
       
   761             IPTVLOGSTRING_LOW_LEVEL(
       
   762                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL Unknown state" );
       
   763             break;
       
   764             }
       
   765         }
       
   766 
       
   767     switch ( aEvent.iDownloadState )
       
   768         {
       
   769         case EHttpDlCompleted:
       
   770             {
       
   771             IPTVLOGSTRING_LOW_LEVEL(
       
   772                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlCompleted" );
       
   773             iDlStatus = EDownloadSucceeded;
       
   774             iDlError  = EIptvDlNoError;
       
   775             DeleteDownloadAsyncL();
       
   776             }
       
   777             break;
       
   778 
       
   779         case EHttpDlFailed:
       
   780             {
       
   781             IPTVLOGSTRING_LOW_LEVEL(
       
   782                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlFailed" );
       
   783             // When header download failed, we can still retry actual download.
       
   784             if ( iWaitingContentTypeCheck )
       
   785                 {
       
   786                 iDlStatus = EDownloadNeeded;
       
   787                 iDlError  = EIptvDlNoError;
       
   788                 ChangeState( ENormal );
       
   789 
       
   790                 // Delete old Thumbnail and remove it from list.
       
   791                 if ( iThumbnail && iFileName )
       
   792                     {
       
   793                     iPlugin.RemoveIconFromList( iFileName, ETrue );
       
   794                     }
       
   795 
       
   796                 iRestartDownload = ETrue;
       
   797                 IPTVLOGSTRING_LOW_LEVEL(
       
   798                     "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL Further header check disabled." );
       
   799                 iDisableLastModifiedCheck = ETrue; // Suppress further check
       
   800                 iWaitingContentTypeCheck = EFalse;
       
   801                 DeleteDownloadAsyncL();
       
   802                 }
       
   803             else
       
   804                 {
       
   805                 GetDownloadErrorCode( aDownload, iDlError );
       
   806                 // No state change, when only progress information.
       
   807                 if ( EIptvDlNoError != iDlError )
       
   808                     {
       
   809                     iDlStatus = EDownloadFailed;
       
   810                     DeleteDownloadAsyncL();
       
   811                     }
       
   812                 }
       
   813             }
       
   814             break;
       
   815 
       
   816         case EHttpDlCreated:
       
   817             IPTVLOGSTRING_LOW_LEVEL(
       
   818                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlCreated" );
       
   819             break;
       
   820 
       
   821         case EHttpDlInprogress:
       
   822             IPTVLOGSTRING_LOW_LEVEL(
       
   823                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlInprogress" );
       
   824             break;
       
   825 
       
   826         case EHttpDlPaused:
       
   827             {
       
   828             // Ignore paused state when content type is received because download is finished earlier.
       
   829             if ( aEvent.iProgressState != EHttpContentTypeReceived )
       
   830                 {
       
   831                 IPTVLOGSTRING_LOW_LEVEL(
       
   832                     "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlPaused" );
       
   833 
       
   834                 ChangeState( EPause );
       
   835 
       
   836                 if ( iTimer )
       
   837                     {
       
   838                     if ( !iTimer->IsActive() )
       
   839                         {
       
   840                         iTimer->After( KIptvTime_1_second );
       
   841                         }
       
   842                     }
       
   843                 }
       
   844             }
       
   845             break;
       
   846 
       
   847         case EHttpDlMoved:
       
   848             IPTVLOGSTRING_LOW_LEVEL(
       
   849                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlMoved" );
       
   850             break;
       
   851 
       
   852         case EHttpDlMediaRemoved:
       
   853             IPTVLOGSTRING_LOW_LEVEL(
       
   854                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlMediaRemoved" );
       
   855             break;
       
   856 
       
   857         case EHttpDlMediaInserted:
       
   858             IPTVLOGSTRING_LOW_LEVEL(
       
   859                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlMediaInserted" );
       
   860             break;
       
   861 
       
   862         case EHttpDlPausable:
       
   863             IPTVLOGSTRING_LOW_LEVEL(
       
   864                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlPausable" );
       
   865             break;
       
   866 
       
   867         case EHttpDlNonPausable:
       
   868             IPTVLOGSTRING_LOW_LEVEL(
       
   869                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlNonPausable" );
       
   870             break;
       
   871 
       
   872         case EHttpDlDeleted:
       
   873             IPTVLOGSTRING_LOW_LEVEL(
       
   874                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlDeleted" );
       
   875             break;
       
   876 
       
   877         case EHttpDlAlreadyRunning:
       
   878             IPTVLOGSTRING_LOW_LEVEL(
       
   879                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlAlreadyRunning" );
       
   880             break;
       
   881 
       
   882         case EHttpDlDeleting:
       
   883             IPTVLOGSTRING_LOW_LEVEL(
       
   884                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlDeleting" );
       
   885             break;
       
   886 
       
   887         case EHttpDlCancelTransaction:
       
   888             IPTVLOGSTRING_LOW_LEVEL(
       
   889                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL EHttpDlCancelTransaction" );
       
   890             break;
       
   891 
       
   892         default:
       
   893             IPTVLOGSTRING_LOW_LEVEL(
       
   894                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL Unknown state" );
       
   895             break;
       
   896         }
       
   897 
       
   898     if ( iState == ENormal )
       
   899         {
       
   900         ChangeState( EWaiting );
       
   901         if ( iTimer )
       
   902             {
       
   903             if ( !iTimer->IsActive() )
       
   904                 {
       
   905                 iTimer->After( KIptvTime_1_second );
       
   906                 }
       
   907             }
       
   908         }
       
   909     }
       
   910 
       
   911 // --------------------------------------------------------------------------
       
   912 // Set authentication information.
       
   913 // --------------------------------------------------------------------------
       
   914 //
       
   915 void CIptvRssDownload::SetAuthenticationInformationL(
       
   916     RHttpDownload& aDownload ) const
       
   917     {
       
   918     IPTVLOGSTRING_LOW_LEVEL(
       
   919         "RSS Plugin --- CIptvRssDownload::SetAuthenticationInformation" );
       
   920 
       
   921     User::LeaveIfError(
       
   922         aDownload.SetStringAttribute( EDlAttrUsername, iUserName ) );
       
   923     User::LeaveIfError(
       
   924         aDownload.SetStringAttribute( EDlAttrPassword, iPassword ) );
       
   925     }
       
   926 
       
   927 // --------------------------------------------------------------------------
       
   928 // Set service information.
       
   929 // --------------------------------------------------------------------------
       
   930 //
       
   931 void CIptvRssDownload::SetServiceInformation( CIptvEpgService* aService )
       
   932     {
       
   933     IPTVLOGSTRING_LOW_LEVEL(
       
   934         "RSS Plugin --- CIptvRssDownload::SetServiceInformation" );
       
   935 
       
   936     iService = aService;
       
   937 
       
   938     if ( aService )
       
   939         {
       
   940         iUserName.Copy( aService->iUserName );
       
   941         iPassword.Copy( aService->iPassword );
       
   942         }
       
   943     }
       
   944 
       
   945 // --------------------------------------------------------------------------
       
   946 // Initialize plugin.
       
   947 // --------------------------------------------------------------------------
       
   948 //
       
   949 void CIptvRssDownload::InitializeL()
       
   950     {
       
   951     IPTVLOGSTRING_LOW_LEVEL(
       
   952         "RSS Plugin  --- CIptvRssDownload::InitializeL" );
       
   953 
       
   954     if ( !iConnected )
       
   955         {
       
   956         if ( iPlugin.IsSearchOperation() )
       
   957             {
       
   958             iDownloadManager.ConnectL( KIptvSearchUid, *this, ETrue );
       
   959             }
       
   960         else
       
   961             {
       
   962             iDownloadManager.ConnectL( iService->iUid, *this, ETrue );
       
   963             }
       
   964         iConnected = ETrue;
       
   965         }
       
   966 
       
   967     iDownloadManager.DeleteAll();
       
   968     }
       
   969 
       
   970 // --------------------------------------------------------------------------
       
   971 // Disconnect download manager session.
       
   972 // --------------------------------------------------------------------------
       
   973 //
       
   974 void CIptvRssDownload::Disconnect()
       
   975     {
       
   976     IPTVLOGSTRING_LOW_LEVEL( "RSS Plugin  --- CIptvRssDownload::Disconnect" );
       
   977 
       
   978     if ( iConnected )
       
   979         {
       
   980         iDownloadManager.DeleteAll();
       
   981         iDownloadManager.RemoveObserver( *this );
       
   982         iDownloadManager.Close();
       
   983 
       
   984         iConnected = EFalse;
       
   985         }
       
   986     }
       
   987 
       
   988 // --------------------------------------------------------------------------
       
   989 // Get download error code.
       
   990 // --------------------------------------------------------------------------
       
   991 //
       
   992 void CIptvRssDownload::GetDownloadErrorCode(
       
   993     RHttpDownload& aDownload, TIptvDlError& aError ) const
       
   994     {
       
   995     IPTVLOGSTRING_LOW_LEVEL(
       
   996         "RSS Plugin  --- CIptvRssDownload::GetDownloadErrorCode" );
       
   997 
       
   998     TInt32 errorId;
       
   999     TInt32 globalErrorId;
       
  1000     aDownload.GetIntAttribute( EDlAttrErrorId, errorId );
       
  1001     aDownload.GetIntAttribute( EDlAttrGlobalErrorId, globalErrorId );
       
  1002     IPTVLOGSTRING2_LOW_LEVEL(
       
  1003         "RSS Plugin --- CIptvRssDownload::GetDownloadErrorCode:: DL error ID: %d",
       
  1004         errorId );
       
  1005     IPTVLOGSTRING2_LOW_LEVEL(
       
  1006         "RSS Plugin --- CIptvRssDownload::GetDownloadErrorCode:: DL global error ID: %d",
       
  1007         globalErrorId );
       
  1008 
       
  1009     switch ( errorId )
       
  1010         {
       
  1011         case EConnectionFailed:
       
  1012             {
       
  1013             aError = EIptvDlConnectionFailed;
       
  1014             }
       
  1015             break;
       
  1016 
       
  1017         case EHttpAuthenticationFailed:
       
  1018             {
       
  1019             aError = EIptvDlAuthFailed;
       
  1020             }
       
  1021             break;
       
  1022 
       
  1023         case EProxyAuthenticationFailed:
       
  1024             {
       
  1025             aError = EIptvDlProxyAuthFailed;
       
  1026             }
       
  1027             break;
       
  1028 
       
  1029         case EDestFileInUse:
       
  1030             {
       
  1031             aError = EIptvDlDestFileInUse;
       
  1032             }
       
  1033             break;
       
  1034 
       
  1035         case EBadUrl:
       
  1036             {
       
  1037             aError = EIptvDlBadUrl;
       
  1038             }
       
  1039             break;
       
  1040 
       
  1041         case EMMCRemoved:
       
  1042             {
       
  1043             aError = EIptvDlMmcRemoved;
       
  1044             }
       
  1045             break;
       
  1046 
       
  1047         case EDiskFull:
       
  1048             {
       
  1049             aError = EIptvDlDiskFull;
       
  1050             }
       
  1051             break;
       
  1052 
       
  1053         case EObjectNotFound:
       
  1054         case ETransactionFailed:
       
  1055             {
       
  1056             aError = EIptvDlContentNotFound;
       
  1057             }
       
  1058             break;
       
  1059 
       
  1060         default:
       
  1061             {
       
  1062             aError = EIptvDlGeneral;
       
  1063             }
       
  1064             break;
       
  1065         }
       
  1066 
       
  1067     switch ( globalErrorId )
       
  1068         {
       
  1069         case EHttpResponsePaymentRequired:
       
  1070             {
       
  1071             aError = EIptvDlContentNotFound;
       
  1072             }
       
  1073             break;
       
  1074 
       
  1075         case EHttpResponseContinue:
       
  1076         case EHttpResponseSwitchingProtocols:
       
  1077             {
       
  1078             aError = EIptvDlNoError;
       
  1079             }
       
  1080             break;
       
  1081 
       
  1082         default:
       
  1083             // Default should not affect aError, due only special cases
       
  1084             // are handled here.
       
  1085             break;
       
  1086         }
       
  1087     }
       
  1088 
       
  1089 // --------------------------------------------------------------------------
       
  1090 // Timer expired.
       
  1091 // --------------------------------------------------------------------------
       
  1092 //
       
  1093 void CIptvRssDownload::TimerExpired( CIptvTimer* aTimer )
       
  1094     {
       
  1095     IPTVLOGSTRING_LOW_LEVEL(
       
  1096         "RSS Plugin --- CIptvRssDownload::TimerExpired" );
       
  1097 
       
  1098     if ( aTimer == iDlDeleteTimer )
       
  1099         {
       
  1100         delete iDlDeleteTimer;
       
  1101         iDlDeleteTimer = NULL;
       
  1102         if ( iDownloadIdValid )
       
  1103             {
       
  1104             DeleteCurrentDownload();
       
  1105             }
       
  1106 
       
  1107         if ( iRestartDownload )
       
  1108             {
       
  1109             // Create new download.
       
  1110             iRestartDownload = EFalse;
       
  1111             if ( iFileName )
       
  1112                 {
       
  1113                 TRAP_IGNORE( DownloadL() )
       
  1114                 }
       
  1115         }
       
  1116         else if ( iState == EThumbnail )
       
  1117             {
       
  1118             TRAP_IGNORE( iPlugin.DownloadThumbnailsL() )
       
  1119             }
       
  1120         else
       
  1121             {
       
  1122             TRAP_IGNORE( iPlugin.DownloadFinishedL( iDlStatus, iDlError ) )
       
  1123             }
       
  1124 
       
  1125         return;
       
  1126         }
       
  1127 
       
  1128     //lint -e{961} Else block not needed, default is no operation.
       
  1129     if ( iState == EPause )
       
  1130         {
       
  1131         iPauseCounter++;
       
  1132         IPTVLOGSTRING2_LOW_LEVEL(
       
  1133             "RSS Plugin --- CIptvRssDownload::TimerExpired PAUSED %d SECONDS",
       
  1134             iPauseCounter );
       
  1135 
       
  1136         if ( iPauseCounter > KIptvMaxPauseInSeconds )
       
  1137             {
       
  1138             IPTVLOGSTRING_LOW_LEVEL(
       
  1139                 "RSS Plugin --- CIptvRssDownload::TimerExpired PAUSED TOO LONG, PLUGIN FAILED, PROBABLY WLAN CONNECTION LOST" );
       
  1140             iDlStatus = EDownloadFailed;
       
  1141             iDlError  = EIptvDlConnectionFailed;
       
  1142             TRAP_IGNORE( DeleteDownloadAsyncL() )
       
  1143             }
       
  1144         else
       
  1145             {
       
  1146             if ( iTimer && !iTimer->IsActive() )
       
  1147                 {
       
  1148                 iTimer->After( KIptvTime_1_second );
       
  1149                 }
       
  1150             }
       
  1151         }
       
  1152     else if ( iState == EWaiting )
       
  1153         {
       
  1154         iPauseCounter++;
       
  1155         IPTVLOGSTRING2_LOW_LEVEL(
       
  1156             "RSS Plugin --- CIptvRssDownload::TimerExpired WAITING EVENTS FROM DL-MANAGER %d SECONDS",
       
  1157             iPauseCounter );
       
  1158 
       
  1159         if ( iPauseCounter > KIptvMaxTimeoutInSeconds )
       
  1160             {
       
  1161             IPTVLOGSTRING2_LOW_LEVEL(
       
  1162                 "RSS Plugin --- CIptvRssDownload::TimerExpired TIMEOUT %d REACHED!",
       
  1163                 KIptvMaxTimeoutInSeconds );
       
  1164             iDlStatus = EDownloadFailed;
       
  1165             iDlError  = EIptvDlNoError;
       
  1166             TRAP_IGNORE( DeleteDownloadAsyncL() )
       
  1167             }
       
  1168         else
       
  1169             {
       
  1170             if ( iTimer && !iTimer->IsActive() )
       
  1171                 {
       
  1172                 iTimer->After( KIptvTime_1_second );
       
  1173                 }
       
  1174             }
       
  1175         }
       
  1176     else if ( iState == EThumbnail )
       
  1177         {
       
  1178         TRAP_IGNORE( DeleteDownloadAsyncL() )
       
  1179         }
       
  1180     else if ( iState == ENoDiskSpace )
       
  1181         {
       
  1182         IPTVLOGSTRING_LOW_LEVEL(
       
  1183             "RSS Plugin --- CIptvRssDownload::TimerExpired No disk space, deleting download." );
       
  1184         iDlStatus = EDownloadFailed;
       
  1185         iDlError  = EIptvDlDiskFull;
       
  1186         TRAP_IGNORE( DeleteDownloadAsyncL() )
       
  1187         }
       
  1188     }
       
  1189 
       
  1190 // --------------------------------------------------------------------------
       
  1191 // Finish and delete current download.
       
  1192 // --------------------------------------------------------------------------
       
  1193 //
       
  1194 void CIptvRssDownload::DeleteCurrentDownload()
       
  1195     {
       
  1196     IPTVLOGSTRING_LOW_LEVEL(
       
  1197         "RSS Plugin --- CIptvRssDownload::DeleteCurrentDownload" );
       
  1198 
       
  1199     ChangeState( EFinished );
       
  1200 
       
  1201     TInt count = iDownloadManager.CurrentDownloads().Count();
       
  1202     TInt32 downloadId;
       
  1203     for ( TInt i = 0; i < count; i++ )
       
  1204         {
       
  1205         iDownloadManager.CurrentDownloads()[i]->GetIntAttribute(
       
  1206             EDlAttrId, downloadId );
       
  1207         if ( downloadId == iDownloadId )
       
  1208             {
       
  1209             RHttpDownload* dl = iDownloadManager.CurrentDownloads()[i];
       
  1210             if ( dl )
       
  1211                 {
       
  1212                 dl->Delete();
       
  1213                 iDownloadIdValid = EFalse;
       
  1214                 }
       
  1215             }
       
  1216         }
       
  1217     }
       
  1218 
       
  1219 // --------------------------------------------------------------------------
       
  1220 // Change the state of the download.
       
  1221 // --------------------------------------------------------------------------
       
  1222 //
       
  1223 void CIptvRssDownload::ChangeState( TInt aState )
       
  1224     {
       
  1225     switch ( iState )
       
  1226         {
       
  1227         case ENormal:
       
  1228             {
       
  1229             IPTVLOGSTRING2_LOW_LEVEL(
       
  1230                 "RSS Plugin --- CIptvRssDownload:: iState changed -> ENormal, was: %d", iState );
       
  1231             break;
       
  1232             }
       
  1233 
       
  1234         case EPause:
       
  1235             {
       
  1236             IPTVLOGSTRING2_LOW_LEVEL(
       
  1237                 "RSS Plugin --- CIptvRssDownload:: iState changed -> EPause, was: %d", iState );
       
  1238             break;
       
  1239             }
       
  1240 
       
  1241         case EThumbnail:
       
  1242             {
       
  1243             IPTVLOGSTRING2_LOW_LEVEL(
       
  1244                 "RSS Plugin --- CIptvRssDownload:: iState changed -> EThumbnail, was: %d", iState );
       
  1245             break;
       
  1246             }
       
  1247 
       
  1248         case EWaiting:
       
  1249             {
       
  1250             IPTVLOGSTRING2_LOW_LEVEL(
       
  1251                 "RSS Plugin --- CIptvRssDownload:: iState changed -> EWaiting, was: %d", iState );
       
  1252             break;
       
  1253             }
       
  1254 
       
  1255         case EFinished:
       
  1256             {
       
  1257             IPTVLOGSTRING2_LOW_LEVEL(
       
  1258                 "RSS Plugin --- CIptvRssDownload:: iState changed -> EFinished, was: %d", iState );
       
  1259             break;
       
  1260             }
       
  1261 
       
  1262         case ETimeout:
       
  1263             {
       
  1264             IPTVLOGSTRING2_LOW_LEVEL(
       
  1265                 "RSS Plugin --- CIptvRssDownload:: iState changed -> ETimeout, was: %d", iState );
       
  1266             break;
       
  1267             }
       
  1268 
       
  1269         case ENoDiskSpace:
       
  1270             {
       
  1271             IPTVLOGSTRING2_LOW_LEVEL(
       
  1272                 "RSS Plugin --- CIptvRssDownload::HandleDMgrEventL iState changed -> ENoDiskSpace, was: %d", iState );
       
  1273             break;
       
  1274             }
       
  1275 
       
  1276         default:
       
  1277             {
       
  1278             break;
       
  1279             }
       
  1280         }
       
  1281 
       
  1282     iState = aState;
       
  1283     }
       
  1284 
       
  1285 // --------------------------------------------------------------------------
       
  1286 // CIptvRssDownload::SkipCurrentDownloadAsyncL
       
  1287 // --------------------------------------------------------------------------
       
  1288 //
       
  1289 void CIptvRssDownload::SkipCurrentDownloadAsyncL()
       
  1290     {
       
  1291     IPTVLOGSTRING_LOW_LEVEL(
       
  1292         "RSS Plugin --- CIptvRssDownload::SkipCurrentDownloadAsyncL" );
       
  1293 
       
  1294     iDlStatus = EDownloadAlreadyDownloaded;
       
  1295     iDlError  = EIptvDlNoError;
       
  1296 
       
  1297     DeleteDownloadAsyncL();
       
  1298     }
       
  1299 
       
  1300 // --------------------------------------------------------------------------
       
  1301 // CIptvRssDownload::DeleteDownloadAsyncL
       
  1302 // --------------------------------------------------------------------------
       
  1303 //
       
  1304 void CIptvRssDownload::DeleteDownloadAsyncL()
       
  1305     {
       
  1306     delete iDlDeleteTimer;
       
  1307     iDlDeleteTimer = NULL;
       
  1308     iDlDeleteTimer = CIptvTimer::NewL( 0, *this );
       
  1309     iDlDeleteTimer->After( 1 ); //just to make it async
       
  1310     }
       
  1311 
       
  1312 // --------------------------------------------------------------------------
       
  1313 // Getter for ETag
       
  1314 // --------------------------------------------------------------------------
       
  1315 //
       
  1316 void CIptvRssDownload::GetETag( TDes& aETag ) const
       
  1317     {
       
  1318     if ( iETag )
       
  1319         {
       
  1320         aETag.Copy( iETag->Des() );
       
  1321         }
       
  1322     else
       
  1323         {
       
  1324         aETag.Copy( KIptvEmptyDes );
       
  1325         }
       
  1326     }
       
  1327 
       
  1328 // --------------------------------------------------------------------------
       
  1329 // Getter for LastModifiedSince
       
  1330 // --------------------------------------------------------------------------
       
  1331 //
       
  1332 void CIptvRssDownload::GetLastModifiedSince( TTime& aLastUpdated ) const
       
  1333     {
       
  1334     aLastUpdated = iLastUpdated;
       
  1335     }