videocollection/mpxmyvideoscollection/tsrc/mpxmvcolltest/src/VCXMyVideosTestDlWatcher.cpp
branchRCL_3
changeset 57 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
56:839377eedc2b 57:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2002 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:   ?Description*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32svr.h>
       
    20 #include "VCXMyVideosTestDlWatcher.h"
       
    21 #include "MVCXMyVideosCollectionPluginTesterObserver.h"
       
    22 #include "VCXMyVideosTestCommon.h"
       
    23 #include "VCXTestStatsKeeper.h"
       
    24 
       
    25 #include <BAUTILS.H>
       
    26 #include <HttpDownloadMgrCommon.h>
       
    27 
       
    28 #include "VCXTestLog.h"
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT(KEVcxMyVideosDlStateNone, "EVcxMyVideosDlStateNone");
       
    32 _LIT(KEVcxMyVideosDlStateDownloading, "EVcxMyVideosDlStateDownloading");
       
    33 _LIT(KEVcxMyVideosDlStateFailed, "EVcxMyVideosDlStateFailed");
       
    34 _LIT(KEVcxMyVideosDlStatePaused, "EVcxMyVideosDlStatePaused");
       
    35 _LIT(KEVcxMyVideosDlStateDownloaded, "EVcxMyVideosDlStateDownloaded");
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CVCXMyVideosTestDlWatcher::NewL
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CVCXMyVideosTestDownload* CVCXMyVideosTestDownload::NewL()
       
    45     {
       
    46     VCXLOGLO1(">>>CVCXMyVideosTestDownload::NewL");
       
    47     CVCXMyVideosTestDownload* self = new (ELeave) CVCXMyVideosTestDownload();
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL( );
       
    50     CleanupStack::Pop(self);
       
    51     VCXLOGLO1("<<<CVCXMyVideosTestDownload::NewL");
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CVCXMyVideosTestDownload::CVCXMyVideosTestDownload
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CVCXMyVideosTestDownload::CVCXMyVideosTestDownload()
       
    60     {
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CVCXMyVideosTestDownload::~CVCXMyVideosTestDownload
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CVCXMyVideosTestDownload::~CVCXMyVideosTestDownload( )
       
    68     {
       
    69     delete iTitle;
       
    70     iTitle = NULL;
       
    71     delete iUrl;
       
    72     iUrl = NULL;
       
    73     delete iPath;
       
    74     iPath = NULL;
       
    75     delete iUserName;
       
    76     iUserName = NULL;
       
    77     delete iPassword;
       
    78     iPassword = NULL;
       
    79     delete iPath;
       
    80     iPath = NULL;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CVCXMyVideosTestDlWatcher::ConstructL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CVCXMyVideosTestDownload::ConstructL( )
       
    88     {
       
    89     VCXLOGLO1(">>>CVCXMyVideosTestDownload::ConstructL");
       
    90     VCXLOGLO1("<<<CVCXMyVideosTestDownload::ConstructL");
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CVCXMyVideosTestDlWatcher::NewL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CVCXMyVideosTestDlWatcher* CVCXMyVideosTestDlWatcher::NewL(
       
    98             MVCXMyVideosCollectionPluginTesterObserver* aObserver, CVCXTestStatsKeeper* aStatsKeeper )
       
    99     {
       
   100     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::NewL");
       
   101     CVCXMyVideosTestDlWatcher* self = new (ELeave) CVCXMyVideosTestDlWatcher( aStatsKeeper );
       
   102     CleanupStack::PushL(self);
       
   103     self->ConstructL( aObserver );
       
   104     CleanupStack::Pop(self);
       
   105     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::NewL");
       
   106     return self;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CVCXMyVideosTestDlWatcher::CVCXMyVideosTestDlWatcher
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CVCXMyVideosTestDlWatcher::CVCXMyVideosTestDlWatcher( CVCXTestStatsKeeper* aStatsKeeper )
       
   114   : iStats( aStatsKeeper )
       
   115     {
       
   116 
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CVCXMyVideosTestDlWatcher::~CVCXMyVideosTestDlWatcher
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 CVCXMyVideosTestDlWatcher::~CVCXMyVideosTestDlWatcher( )
       
   124     {
       
   125     iDownloads.ResetAndDestroy();
       
   126     iFs.Close();
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CVCXMyVideosTestDlWatcher::ConstructL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CVCXMyVideosTestDlWatcher::ConstructL( MVCXMyVideosCollectionPluginTesterObserver* aObserver )
       
   134     {
       
   135     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::ConstructL");
       
   136     iObserver = aObserver;
       
   137     User::LeaveIfError( iFs.Connect() );
       
   138     iDlCheckDisabled = ETrue;
       
   139     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::ConstructL");
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CVCXMyVideosTestDlWatcher::CreateDownloadL
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CVCXMyVideosTestDlWatcher::CreateDownloadL( TInt aIapId, TInt aServiceId, TInt aContentId, const TDesC& aUrl, TBool aSync, const TDesC& aUserName, const TDesC& aPassword )
       
   147     {
       
   148     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::CreateDownloadL");
       
   149 
       
   150     VCXLOGLO3("CVCXMyVideosTestDlWatcher:: aServiceId: %d, aContentId: %d", aServiceId, aContentId);
       
   151     PrintUrl( _L("CVCXMyVideosTestDlWatcher:: aUrl:"), aUrl );
       
   152 
       
   153     CVCXMyVideosTestDownload* dl = CVCXMyVideosTestDownload::NewL();
       
   154     iDownloads.Append( dl );
       
   155 
       
   156     CleanupDownloadsL( aServiceId, aContentId, aUrl );
       
   157     
       
   158     dl->iState = EVcxMyVideosDlStateNone;
       
   159     dl->iSyncCall = aSync;
       
   160     dl->iUrl = aUrl.AllocL();
       
   161     dl->iIapId = aIapId;
       
   162     dl->iUserName = aUserName.AllocL();
       
   163     dl->iPassword = aPassword.AllocL();
       
   164     dl->iServiceId = aServiceId;
       
   165     dl->iContentId = aContentId;
       
   166 
       
   167     iDlCheckDisabled = EFalse;
       
   168     
       
   169     TRAP_IGNORE( iStats->ActionStartL( aUrl, _L("Download "), ETrue ) );
       
   170 
       
   171     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::CreateDownloadL");
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CVCXMyVideosTestDlWatcher::StartDownloadL
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CVCXMyVideosTestDlWatcher::StartDownloadL( const TDesC& aUrl, const TDesC& aPath, TInt aDownloadId, TInt aMpxId,
       
   179         const TDesC& aTitle, TVcxMyVideosDownloadState aState, TInt aProgress )
       
   180     {
       
   181     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::StartDownloadL");
       
   182 
       
   183     VCXLOGLO3("CVCXMyVideosTestDlWatcher:: aMpxId: %d, aDownloadId: %d", aMpxId, aDownloadId);
       
   184     PrintUrl( _L("aUrl:"), aUrl );
       
   185 
       
   186     CVCXMyVideosTestDownload* dl = GetDownload( aUrl );
       
   187     if( !dl )
       
   188         {
       
   189         CreateDownloadL( -1, -1, -1, aUrl, ETrue, _L(""), _L("") );
       
   190         dl = GetDownload( aUrl );
       
   191         if( !dl )
       
   192             {
       
   193             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestErrorDownloadNotFound, KVCXMYVideosTestErrorDownloadNotFound );
       
   194             VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::StartDownloadL");
       
   195             return;
       
   196             }
       
   197         }
       
   198 
       
   199     dl->iMpxId = aMpxId;
       
   200     if( dl->iTitle )
       
   201         {
       
   202         delete dl->iTitle;
       
   203         dl->iTitle = NULL;
       
   204         }
       
   205     dl->iTitle = aTitle.AllocL();
       
   206     
       
   207     if( dl->iPath )
       
   208         {
       
   209         delete dl->iPath;
       
   210         }    
       
   211     dl->iPath = aPath.AllocL();
       
   212     
       
   213     dl->iMpxId = aMpxId;
       
   214 
       
   215     UpdateDownloadStateL( aMpxId, aDownloadId, aState, aProgress, KErrNone, KErrNone );
       
   216     
       
   217     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::StartDownloadL");
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CVCXMyVideosTestDlWatcher::UpdateDownloadStateL
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CVCXMyVideosTestDlWatcher::UpdateDownloadStateL( TInt aMpxId, TInt aDownloadId,
       
   225         TVcxMyVideosDownloadState aState, TInt aProgress, TInt aDownloadError, TInt aGlobalError )
       
   226     {
       
   227     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::UpdateDownloadStateL");
       
   228     
       
   229     CVCXMyVideosTestDownload* dl = GetDownloadByMpxId( aMpxId );
       
   230     if( !dl )
       
   231         {
       
   232         iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestErrorDownloadNotFound, KVCXMYVideosTestErrorDownloadNotFound );
       
   233         VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::UpdateDownloadStateL");
       
   234         return;
       
   235         }
       
   236     
       
   237     TBool finishedDownload = dl && aState == EVcxMyVideosDlStateDownloaded && aDownloadId != 0
       
   238                             && dl->iProgress >= 100 && dl->iState == EVcxMyVideosDlStateDownloaded;
       
   239     
       
   240     if( finishedDownload )
       
   241         {
       
   242         VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::UpdateDownloadStateL");
       
   243         return;
       
   244         }
       
   245     
       
   246     VCXLOGLO3("CVCXMyVideosTestDlWatcher:: aDownloadError: %d, aGlobalError: %d", aDownloadError, aGlobalError);
       
   247     VCXLOGLO4("CVCXMyVideosTestDlWatcher:: aMpxId: %d, aState: %d, aProgress: %d", aMpxId, aState, aProgress);
       
   248 
       
   249     // This is main error and will be informed to client always.
       
   250     TInt error ( aGlobalError );
       
   251 
       
   252     // For other download manager related errors the global error code should be better
       
   253     if( aDownloadError == EInternal
       
   254             | aDownloadError == EContentFileIntegrity
       
   255             | aDownloadError == EDiskFull
       
   256             | aDownloadError == EConnectionFailed
       
   257             | aDownloadError == EMoveFailed
       
   258             | aDownloadError == EDestFileWriteFailed
       
   259             | aDownloadError == EMMCRemoved
       
   260             | aDownloadError == EBadUrl
       
   261             | aDownloadError == EWrongDestFilename
       
   262             | aDownloadError == EDestFileInUse
       
   263             | aDownloadError == EHttpUnhandled
       
   264             | aDownloadError == EHttpAuthenticationFailed
       
   265             | aDownloadError == EProxyAuthenticationFailed
       
   266             | aDownloadError == EObjectNotFound
       
   267             | aDownloadError == EPartialContentModified
       
   268             | aDownloadError == EContentExpired
       
   269             | aDownloadError == EHttpRestartFailed )
       
   270         {
       
   271         error = aDownloadError;
       
   272         }
       
   273 
       
   274     // Check for DL existance
       
   275     dl->iExists = ETrue;
       
   276 
       
   277     // Download was failed at previous update, inform client now.
       
   278     if( dl->iGlobalError == KVCXMYVideosTestMessageDlFailed && !dl->iInformed )
       
   279         {
       
   280         if( error != KErrNone )
       
   281             {
       
   282             VCXLOGLO1("CVCXMyVideosTestDlWatcher::UpdateDownloadStateL - DL failed at last update, we have error now.");
       
   283             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlFailed, error );
       
   284             dl->iInformed = ETrue;
       
   285             TRAPD( actionErr, iStats->ActionEndL( *dl->iUrl, error ) );
       
   286             if( actionErr == KErrAbort )
       
   287                 iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   288             }
       
   289         else
       
   290             {
       
   291             VCXLOGLO1("CVCXMyVideosTestDlWatcher::UpdateDownloadStateL - DL failed at last update, still no error.");
       
   292             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlFailed, dl->iGlobalError );
       
   293             dl->iInformed = ETrue;
       
   294             TRAPD( actionErr, iStats->ActionEndL( *dl->iUrl, dl->iGlobalError ) );
       
   295             if( actionErr == KErrAbort )
       
   296                 iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   297             }
       
   298         }
       
   299 
       
   300     // Inform the new state
       
   301     if( dl->iState != aState )
       
   302         {
       
   303         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: New state: %d", aState);
       
   304         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: Old state: %d", dl->iState);
       
   305 
       
   306         // Unusual case, signal error to script.
       
   307         if( dl->iState != EVcxMyVideosDlStateNone && aState == EVcxMyVideosDlStateNone && !dl->iCanceled )
       
   308             {
       
   309             VCXLOGLO1("CVCXMyVideosTestDlWatcher:: DL state changed to EVcxMyVideosDlStateNone, reporting as error.");
       
   310             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlGeneral, KVCXMYVideosTestMessageDlGeneral );
       
   311             }
       
   312 
       
   313         if( dl->iState == EVcxMyVideosDlStatePaused && dl->iWaitingResume )
       
   314             {
       
   315             dl->iWaitingResume = EFalse;
       
   316             }
       
   317 
       
   318         dl->iInformed = EFalse;
       
   319         dl->iState = aState;
       
   320         dl->iDownloadError = aDownloadError;
       
   321         dl->iGlobalError = aGlobalError;
       
   322         
       
   323         TBuf<50> stateBuff;
       
   324         TPtrC stateStr = GetStateDesc( static_cast<TVcxMyVideosDownloadState>( dl->iState ) );
       
   325         stateBuff.Format( _L("State: %S"), &stateStr );
       
   326         TRAP_IGNORE( iStats->ActionProgressL( *dl->iUrl, stateBuff ) );
       
   327         }
       
   328 
       
   329     UpdateDownloadProgressL( aMpxId, aDownloadId, aProgress );
       
   330 
       
   331     dl->iDownloadId = aDownloadId;
       
   332 
       
   333     // Handle states which are informed to observer.
       
   334     if( !dl ->iInformed )
       
   335     switch( dl->iState )
       
   336         {
       
   337         case EVcxMyVideosDlStateNone:
       
   338             {
       
   339 
       
   340             }
       
   341             break;
       
   342 
       
   343         case EVcxMyVideosDlStateDownloading:
       
   344             {
       
   345             dl->iInformed = ETrue;
       
   346             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlRunning, error );
       
   347             }
       
   348             break;
       
   349 
       
   350         case EVcxMyVideosDlStateFailed:
       
   351             {
       
   352             if( error != KErrNone )
       
   353                 {
       
   354                 VCXLOGLO1("CVCXMyVideosTestDlWatcher::UpdateDownloadStateL - DL failed, we have error.");
       
   355                 iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlFailed, error );
       
   356                 TRAPD( actionErr, iStats->ActionEndL( *dl->iUrl, error ) );
       
   357                 if( actionErr == KErrAbort )
       
   358                     iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   359                 
       
   360                 dl->iInformed = ETrue;
       
   361                 }
       
   362             else
       
   363                 {
       
   364                 VCXLOGLO1("CVCXMyVideosTestDlWatcher::UpdateDownloadStateL - DL failed, no error yet.");
       
   365                 //iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlFailed, KVCXMYVideosTestMessageDlFailed );
       
   366                 // This will be informed at next update to client.
       
   367                 dl->iGlobalError = KVCXMYVideosTestMessageDlFailed;
       
   368                 }
       
   369             }
       
   370             break;
       
   371 
       
   372         case EVcxMyVideosDlStatePaused:
       
   373             {
       
   374             dl->iInformed = ETrue;
       
   375             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlPaused, error );
       
   376             // Unexpected pause state, stop action.
       
   377             if( !dl->iWaitingPause )
       
   378                 {
       
   379                 TRAPD( actionErr, iStats->ActionEndL( *dl->iUrl, KErrGeneral ) );
       
   380                 if( actionErr == KErrAbort )
       
   381                     iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   382                 }
       
   383             dl->iWaitingPause = EFalse;
       
   384             }
       
   385             break;
       
   386 
       
   387         case EVcxMyVideosDlStateDownloaded:
       
   388             {
       
   389             if( !BaflUtils::FileExists( iFs, *dl->iPath ) )
       
   390                 {
       
   391                 VCXLOGLO1("CVCXMyVideosTestDlWatcher:: DL finished without errors but file doesn't exist!");
       
   392                 iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestErrorFileNotFound, KVCXMYVideosTestErrorFileNotFound );
       
   393                 TRAPD( actionErr, iStats->ActionEndL( *dl->iUrl, KVCXMYVideosTestErrorFileNotFound ) );
       
   394                 if( actionErr == KErrAbort )
       
   395                     iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   396                 dl->iInformed = ETrue;
       
   397                 }
       
   398             else
       
   399                 {
       
   400                 dl->iInformed = ETrue;
       
   401                 iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlSucceeded, error );
       
   402                 TRAPD( actionErr, iStats->ActionEndL( *dl->iUrl, error ) );
       
   403                 if( actionErr == KErrAbort )
       
   404                     iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   405                 }
       
   406             }
       
   407             break;
       
   408 
       
   409         default:
       
   410             break;
       
   411         }
       
   412 
       
   413     if( error != KErrNone && !dl->iInformed )
       
   414         {
       
   415         dl->iInformed = ETrue;
       
   416         iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlGeneral, error );
       
   417         }
       
   418 
       
   419     VCXLOGLO1("<<<<CVCXMyVideosTestDlWatcher::UpdateDownloadStateL");
       
   420     }
       
   421 
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CVCXMyVideosTestDlWatcher::UpdateDownloadProgressL
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 void CVCXMyVideosTestDlWatcher::UpdateDownloadProgressL( TInt aMpxId, TInt aDownloadId, TInt aProgress )
       
   428     {
       
   429     CVCXMyVideosTestDownload* dl = GetDownloadByMpxId( aMpxId );
       
   430     if( dl )
       
   431         {
       
   432         if( ( aProgress > dl->iProgress + KVCXTestProgressUpdateInterval ) || ( aProgress == 100 && dl->iProgress != 100 ) )
       
   433             {
       
   434             dl->iProgress = aProgress;
       
   435             iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlProgressed, KErrNone );
       
   436             TBuf<50> progressBuff;
       
   437             progressBuff.Format( _L("Progress: %d"), aProgress );
       
   438             TRAP_IGNORE( iStats->ActionProgressL( *dl->iUrl, progressBuff ) );
       
   439             }
       
   440         }
       
   441     }
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // CVCXMyVideosTestDlWatcher::CancelDownloadL
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void CVCXMyVideosTestDlWatcher::CancelDownloadL( TInt aServiceId, TInt aContentId, const TDesC& aUrl )
       
   448     {
       
   449     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::CancelDownloadL");
       
   450     CVCXMyVideosTestDownload* dl = GetDownload( aServiceId, aContentId, aUrl );
       
   451     if( dl )
       
   452         {
       
   453         dl->iCanceled = ETrue;
       
   454         }
       
   455     else
       
   456         {
       
   457         iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestErrorDownloadNotFound, KVCXMYVideosTestErrorDownloadNotFound );
       
   458         }
       
   459     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::CancelDownloadL");
       
   460     }
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CVCXMyVideosTestDlWatcher::SetDownloadResumedFlagL
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 void CVCXMyVideosTestDlWatcher::SetDownloadResumedFlagL( TInt aMpxId, TInt /* aDownloadId */ )
       
   467     {
       
   468     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::SetDownloadResumedFlagL");
       
   469 
       
   470     CVCXMyVideosTestDownload* dl = GetDownloadByMpxId( aMpxId );
       
   471     if( dl )
       
   472         {
       
   473         dl->iWaitingResume = ETrue;
       
   474         dl->iWaitingPause = EFalse;
       
   475         dl->iInformed = EFalse;
       
   476         dl->iDownloadError = KErrNone;
       
   477         dl->iGlobalError = KErrNone;
       
   478         }
       
   479 
       
   480     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::SetDownloadResumedFlagL");
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CVCXMyVideosTestDlWatcher::SetDownloadPausedFlagL
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 void CVCXMyVideosTestDlWatcher::SetDownloadPausedFlagL( TInt aMpxId, TInt /* aDownloadId */ )
       
   488     {
       
   489     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::SetDownloadPausedFlagL");
       
   490 
       
   491     CVCXMyVideosTestDownload* dl = GetDownloadByMpxId( aMpxId );
       
   492     if( dl )
       
   493         {
       
   494         dl->iWaitingResume = EFalse;
       
   495         dl->iWaitingPause = ETrue;
       
   496         dl->iInformed = EFalse;
       
   497         dl->iDownloadError = KErrNone;
       
   498         dl->iGlobalError = KErrNone;
       
   499         }
       
   500 
       
   501     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::SetDownloadPausedFlagL");
       
   502     }
       
   503 // -----------------------------------------------------------------------------
       
   504 // CVCXMyVideosTestDlWatcher::GetDownloadByMpxId
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 CVCXMyVideosTestDownload* CVCXMyVideosTestDlWatcher::GetDownloadByMpxId( TInt aMpxId )
       
   508     {
       
   509     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   510         {
       
   511         if( iDownloads[i]->iMpxId == aMpxId )
       
   512             {
       
   513             return iDownloads[i];
       
   514             }
       
   515         }
       
   516     return NULL;
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CVCXMyVideosTestDlWatcher::GetDownloadByDownloadId
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 CVCXMyVideosTestDownload* CVCXMyVideosTestDlWatcher::GetDownloadByDownloadId( TInt aDownloadId )
       
   524     {
       
   525     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   526         {
       
   527         if( iDownloads[i]->iDownloadId == aDownloadId )
       
   528             {
       
   529             return iDownloads[i];
       
   530             }
       
   531         }
       
   532     return NULL;
       
   533     }
       
   534 
       
   535 // -----------------------------------------------------------------------------
       
   536 // CVCXMyVideosTestDlWatcher::GetDownload
       
   537 // -----------------------------------------------------------------------------
       
   538 //
       
   539 CVCXMyVideosTestDownload* CVCXMyVideosTestDlWatcher::GetDownload( TInt aServiceId, TInt aContentId, const TDesC& aUrl )
       
   540     {
       
   541     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   542         {
       
   543         if( iDownloads[i]->iServiceId == aServiceId &&
       
   544             iDownloads[i]->iContentId == aContentId &&
       
   545             iDownloads[i]->iUrl->Des() == aUrl )
       
   546             {
       
   547             return iDownloads[i];
       
   548             }
       
   549         }
       
   550     return NULL;
       
   551     }
       
   552 
       
   553 // -----------------------------------------------------------------------------
       
   554 // CVCXMyVideosTestDlWatcher::GetDownloadByIndex
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 CVCXMyVideosTestDownload* CVCXMyVideosTestDlWatcher::GetDownloadByIndex( TInt aIndex )
       
   558     {
       
   559     if( aIndex >= iDownloads.Count() ) return NULL;
       
   560     return iDownloads[aIndex];
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CVCXMyVideosTestDlWatcher::GetDownloadCount
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 TInt CVCXMyVideosTestDlWatcher::GetDownloadCount()
       
   568     {
       
   569     return iDownloads.Count();
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CVCXMyVideosTestDlWatcher::GetFailedDownloadCount
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 TInt CVCXMyVideosTestDlWatcher::GetFailedDownloadCount()
       
   577     {
       
   578     TInt count( 0 );
       
   579 
       
   580     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   581         {
       
   582         if( iDownloads[i]->iState == EVcxMyVideosDlStateFailed )
       
   583             {
       
   584             count++;
       
   585             }
       
   586         }
       
   587 
       
   588     return count;
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // CVCXMyVideosTestDlWatcher::CleanupDownloadsL
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 void CVCXMyVideosTestDlWatcher::CleanupDownloadsL( TInt aServiceId, TInt aContentId, const TDesC& aUrl )
       
   596     {
       
   597     if( aUrl.Length() <= 0 ) return;
       
   598 
       
   599     // Remove duplicates which are finished.
       
   600     for( TInt i=iDownloads.Count()-1; i>=0; i-- )
       
   601         {
       
   602         if( iDownloads[i]->iUrl &&
       
   603             iDownloads[i]->iServiceId == aServiceId &&
       
   604             iDownloads[i]->iContentId == aContentId &&
       
   605             iDownloads[i]->iUrl->Des() == aUrl &&
       
   606             ( iDownloads[i]->iState == EVcxMyVideosDlStateDownloaded ||
       
   607               iDownloads[i]->iState == EVcxMyVideosDlStateFailed ) )
       
   608             {
       
   609             CVCXMyVideosTestDownload* dl = iDownloads[i];
       
   610             iDownloads.Remove( i );
       
   611             delete dl;
       
   612             }
       
   613         }
       
   614     
       
   615     // Keep only 10 newest downloads.
       
   616     if( iDownloads.Count() > 10 )
       
   617         {
       
   618         TInt tooMany = iDownloads.Count() - 10;
       
   619         for( TInt i = tooMany - 1; i >= 0; i-- )
       
   620             {
       
   621             CVCXMyVideosTestDownload* dl = iDownloads[i];
       
   622             iDownloads.Remove( i );
       
   623             delete dl;
       
   624             }
       
   625         }
       
   626     
       
   627     }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // CVCXMyVideosTestDlWatcher::GetDownload
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 CVCXMyVideosTestDownload* CVCXMyVideosTestDlWatcher::GetDownload( const TDesC& aUrl )
       
   634     {
       
   635     CVCXMyVideosTestDownload* dl( NULL );
       
   636 
       
   637     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   638         {
       
   639         if( iDownloads[i]->iUrl->Des() == aUrl )
       
   640             {
       
   641             // Take first with same URL.
       
   642             if( dl == NULL )
       
   643                 {
       
   644                 dl = iDownloads[i];
       
   645                 }
       
   646             else
       
   647                 {
       
   648                 // If there's more dl items with same URL then prefer one with dl state none.
       
   649                 if( iDownloads[i]->iState == EVcxMyVideosDlStateNone )
       
   650                     {
       
   651                     dl = iDownloads[i];
       
   652                     }
       
   653                 }
       
   654             }
       
   655         }
       
   656     return dl;
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CVCXMyVideosTestDlWatcher::PrintDownloads
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 void CVCXMyVideosTestDlWatcher::PrintDownloads( )
       
   664     {
       
   665     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::PrintDownloads");
       
   666 
       
   667     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   668         {
       
   669         CVCXMyVideosTestDownload* dl = iDownloads[i];
       
   670         VCXLOGLO1("--------------------------------------------------------------------------------");
       
   671 
       
   672         if( dl->iTitle )
       
   673             {
       
   674             TPtr titlePtr = dl->iTitle->Des();
       
   675             VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iTitle: %S", &titlePtr);
       
   676             }
       
   677         if( dl->iPath )
       
   678             {
       
   679             TPtr pathPtr = dl->iPath->Des();
       
   680             VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iPath: %S", &pathPtr);
       
   681             }
       
   682         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iMpxId: %d", dl->iMpxId);
       
   683         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iDownloadId: %d", dl->iDownloadId);
       
   684         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iContentId: %d", dl->iContentId);
       
   685         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iServiceId: %d", dl->iServiceId);
       
   686         PrintUrl( _L("CVCXMyVideosTestDlWatcher:: iUrl:"), *dl->iUrl );
       
   687         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iProgress: %d", dl->iProgress);
       
   688         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iDownloadError: %d", dl->iDownloadError);
       
   689         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iGlobalError: %d", dl->iGlobalError);
       
   690         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iInformed: %d", dl->iInformed);
       
   691         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: iWaitingResume: %d", dl->iWaitingResume);
       
   692 
       
   693         TPtrC stateDesc = GetStateDesc( static_cast<TVcxMyVideosDownloadState>( dl->iState ) );
       
   694         
       
   695         VCXLOGLO2("CVCXMyVideosTestDlWatcher:: State: %S", &stateDesc);
       
   696         }
       
   697     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::PrintDownloads");
       
   698     }
       
   699 
       
   700 // -----------------------------------------------------------------------------
       
   701 // CVCXMyVideosTestDlWatcher::PrintUrl
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 void CVCXMyVideosTestDlWatcher::PrintUrl( const TDesC& aPre, const TDesC& aUrl )
       
   705     {
       
   706     if( aUrl.Length() > 80 )
       
   707         {
       
   708         TPtrC left( aUrl.Left( 38 ) );
       
   709         TPtrC right( aUrl.Right( 38 ) );
       
   710         VCXLOGLO4("%S %S..%S", &aPre, &left, &right );
       
   711         }
       
   712     else
       
   713         {
       
   714         VCXLOGLO3("%S %S", &aPre, &aUrl );
       
   715         }
       
   716     }
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CVCXMyVideosTestDlWatcher::PrepareCheck
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void CVCXMyVideosTestDlWatcher::PrepareCheck( )
       
   723     {
       
   724     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::PrepareCheck");
       
   725 
       
   726     for( TInt i=0; i<iDownloads.Count(); i++ )
       
   727         {
       
   728         iDownloads[i]->iExists = EFalse;
       
   729         }
       
   730 
       
   731     iDlCheckActive = ETrue;
       
   732     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::PrepareCheck");
       
   733     }
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // CVCXMyVideosTestDlWatcher::FinishCheckL
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 void CVCXMyVideosTestDlWatcher::FinishCheckL( )
       
   740     {
       
   741     if( iDownloads.Count() <= 0) return;
       
   742 
       
   743     VCXLOGLO1(">>>CVCXMyVideosTestDlWatcher::FinishCheckL");
       
   744 
       
   745     // Check that all downloads exist.
       
   746     for( TInt i = iDownloads.Count()-1; i>=0; i-- )
       
   747         {
       
   748         if( !iDownloads[i]->iExists )
       
   749             {
       
   750             if( iDownloads[i]->iCanceled )
       
   751                 {
       
   752                 TRAPD( actionErr, iStats->ActionEndL( *iDownloads[i]->iUrl, KErrNone ) );
       
   753                 if( actionErr == KErrAbort )
       
   754                     iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   755                 VCXLOGLO2("CVCXMyVideosTestDlWatcher:: Dl is canceled, mpxId: %d.", iDownloads[i]->iMpxId);
       
   756                 CVCXMyVideosTestDownload* dl = iDownloads[i];
       
   757                 iDownloads.Remove( i );
       
   758                 delete dl;
       
   759                 iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlCanceled, KErrNone );
       
   760                 }
       
   761             else
       
   762                 {
       
   763                 if( iDownloads[i]->iState != EVcxMyVideosDlStateNone &&
       
   764                     iDownloads[i]->iState != EVcxMyVideosDlStateDownloaded &&
       
   765                     !iDlCheckDisabled )
       
   766                     {
       
   767                     TRAP_IGNORE( iStats->ActionTraceL( _L("Download item was not found.") ) );
       
   768                     TRAPD( actionErr, iStats->ActionEndL( *iDownloads[i]->iUrl, KErrNone ) );
       
   769                     if( actionErr == KErrAbort )
       
   770                         iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageCollectionGeneral, actionErr );
       
   771                     
       
   772                     VCXLOGLO2("CVCXMyVideosTestDlWatcher:: Dl doesn't exist anymore, mpxId: %d. Error!", iDownloads[i]->iMpxId);
       
   773                     iObserver->HandleVcxMvTesterMessageL( KVCXMYVideosTestMessageDlFailed, KErrCorrupt );
       
   774                     CVCXMyVideosTestDownload* dl = iDownloads[i];
       
   775                     iDownloads.Remove( i );
       
   776                     delete dl;                    
       
   777                     }
       
   778                 }
       
   779             }
       
   780         }
       
   781 
       
   782     iDlCheckActive = EFalse;
       
   783     VCXLOGLO1("<<<CVCXMyVideosTestDlWatcher::FinishCheckL");
       
   784     }
       
   785 // -----------------------------------------------------------------------------
       
   786 // CVCXMyVideosTestDlWatcher::DisableDownloadCheck
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 void CVCXMyVideosTestDlWatcher::DisableDownloadCheck( )
       
   790     {
       
   791     iDlCheckDisabled = ETrue;
       
   792     }
       
   793 
       
   794 // -----------------------------------------------------------------------------
       
   795 // CVCXMyVideosTestDlWatcher::Reset
       
   796 // -----------------------------------------------------------------------------
       
   797 //
       
   798 void CVCXMyVideosTestDlWatcher::Reset( )
       
   799     {
       
   800     iDownloads.ResetAndDestroy();
       
   801     }
       
   802 
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // CVCXMyVideosTestDlWatcher::GetStateDesc
       
   806 // -----------------------------------------------------------------------------
       
   807 //
       
   808 const TDesC& CVCXMyVideosTestDlWatcher::GetStateDesc( TVcxMyVideosDownloadState aState )
       
   809     {
       
   810     switch( aState )
       
   811         {
       
   812         default:
       
   813         case EVcxMyVideosDlStateNone:
       
   814             {
       
   815             return KEVcxMyVideosDlStateNone;
       
   816             }
       
   817 
       
   818         case EVcxMyVideosDlStateDownloading:
       
   819             {
       
   820             return KEVcxMyVideosDlStateDownloading;
       
   821             }
       
   822 
       
   823         case EVcxMyVideosDlStateFailed:
       
   824             {
       
   825             return KEVcxMyVideosDlStateFailed;
       
   826             }
       
   827 
       
   828         case EVcxMyVideosDlStatePaused:
       
   829             {
       
   830             return KEVcxMyVideosDlStatePaused;
       
   831             }
       
   832 
       
   833         case EVcxMyVideosDlStateDownloaded:
       
   834             {
       
   835             return KEVcxMyVideosDlStateDownloaded;
       
   836             }
       
   837         }
       
   838     }
       
   839 
       
   840 //  End of File