videofeeds/vcnsuiengine/src/vcxnsupdateprogresshandler.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 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:    Content update progress handling*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <centralrepository.h>
       
    22 #include "CIptvUtil.h"
       
    23 #include "CIptvTimer.h"
       
    24 #include "IptvDebug.h"
       
    25 #include "vcxnsupdateprogresshandler.h"
       
    26 #include "vcxnsserviceprovider.h"
       
    27 #include "vcxnsuiengine.h"
       
    28 
       
    29 //CONSTANTS 
       
    30 const TInt KVcxNsProgCompletedNoThumbnails = 10;
       
    31 const TInt KVcxNsProgStartedNoThumbnails = 5;
       
    32 const TInt KVcxNsProgStartedThumbnails = 3;
       
    33 const TInt KVcxNsThumbProgressPercentVal = 3; 
       
    34 const TInt KVcxNsProgressUpdateStarted = 5;
       
    35 const TInt KVcxNsProgressUpdateCompletedNoThumb = 70;
       
    36 const TInt KVcxNsProgressUpdateCompleted = 40;
       
    37 const TInt KVcxNsProgressUpdateSucceeded = 99;
       
    38 const TInt KVcxNsProgressTimerDefault = 200000;  // 0,2 sec
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CVcxNsUpdateProgressHandler::CVcxNsUpdateProgressHandler()
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CVcxNsUpdateProgressHandler::CVcxNsUpdateProgressHandler( 
       
    47     CVcxNsUiEngine& aUiEngine ) 
       
    48 :   iUiEngine( aUiEngine ),
       
    49     iThumbnails ( EFalse ),
       
    50     iPreviousProgress ( 0 ),
       
    51     iProgressPerThumbnail ( 0 ),
       
    52     iThumbnailsInPercent ( 0 )
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CVcxNsUpdateProgressHandler::NewL()
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CVcxNsUpdateProgressHandler* CVcxNsUpdateProgressHandler::NewL( 
       
    61     CVcxNsUiEngine& aUiEngine )
       
    62     {
       
    63     IPTVLOGSTRING_HIGH_LEVEL(
       
    64         "UI Engine ## CVcxNsUpdateProgressHandler::NewL()");
       
    65     return new (ELeave) CVcxNsUpdateProgressHandler( aUiEngine );
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVcxNsUpdateProgressHandler::~CVcxNsUpdateProgressHandler()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CVcxNsUpdateProgressHandler::~CVcxNsUpdateProgressHandler()
       
    73     {
       
    74     if ( iProgressTimer && iProgressTimer->IsActive() )
       
    75         {
       
    76         iProgressTimer->Cancel();
       
    77         }
       
    78     
       
    79     delete iProgressTimer;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CVcxNsUpdateProgressHandler::RegisterObserver()
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CVcxNsUpdateProgressHandler::RegisterObserver(
       
    87     MVcxNsUpdateProgressObserver* aObserver )
       
    88     {
       
    89     IPTVLOGSTRING_HIGH_LEVEL(
       
    90         "UI Engine ## CVcxNsUpdateProgressHandler::RegisterObserver()");
       
    91     iProgressObserver = aObserver;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CVcxNsUpdateProgressHandler::DeRegisterObserver()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CVcxNsUpdateProgressHandler::DeRegisterObserver(
       
    99     MVcxNsUpdateProgressObserver* aObserver )
       
   100     {
       
   101     IPTVLOGSTRING_HIGH_LEVEL(
       
   102         "UI Engine ## CVcxNsUpdateProgressHandler::DeRegisterObserver()");
       
   103 
       
   104     if ( aObserver == iProgressObserver )
       
   105         {
       
   106         iProgressObserver = NULL;
       
   107         }
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CVcxNsUpdateProgressHandler::GetProgress
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TInt CVcxNsUpdateProgressHandler::GetProgress( TUint32 aServiceId )
       
   115     {
       
   116     if ( aServiceId == iCurrentServiceId )
       
   117         {
       
   118         IPTVLOGSTRING2_HIGH_LEVEL(
       
   119             "UI Engine ## CVcxNsUpdateProgressHandler::GetProgress( %d )", 
       
   120             iPreviousProgress );
       
   121         return iPreviousProgress;
       
   122         }
       
   123    
       
   124     return KErrNotFound;
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // Handle service update status
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CVcxNsUpdateProgressHandler::HandleUpdateStatusChangeL( 
       
   132     TUint32 aServiceId,
       
   133     TInt aUpdateStatusMsg,
       
   134     TInt aInfo )
       
   135     {
       
   136     IPTVLOGSTRING_HIGH_LEVEL(
       
   137         "UI Engine ## CVcxNsUpdateProgressHandler::HandleUpdateStatusChangeL()");
       
   138 
       
   139     TInt progress( iPreviousProgress );
       
   140     iCurrentServiceId = aServiceId;
       
   141     iCurrentStatus = aUpdateStatusMsg; 
       
   142     
       
   143     if ( iProgressTimer && iProgressTimer->IsActive() )
       
   144         {
       
   145         iProgressTimer->Cancel();
       
   146         }
       
   147     
       
   148     switch ( aUpdateStatusMsg )
       
   149         {
       
   150         case KIptvVodUpdateStarted:
       
   151             {
       
   152             //Update started: progress 5% 
       
   153             progress = KVcxNsProgressUpdateStarted;
       
   154             TRAP_IGNORE( iThumbnails = ThumbnailsAllowedL() );
       
   155             StartProgressUpdateTimerL( );
       
   156             }
       
   157             break;
       
   158         case KIptvContentUpdateCompleted:
       
   159             {
       
   160             if ( iThumbnails )
       
   161                 {
       
   162                 //Update completed, thumbnails: progress 40%
       
   163                 if ( progress < KVcxNsProgressUpdateCompleted )
       
   164                     {
       
   165                     progress = KVcxNsProgressUpdateCompleted;
       
   166                     }
       
   167                 }
       
   168             else 
       
   169                 {
       
   170                 if ( progress < KVcxNsProgressUpdateCompletedNoThumb )
       
   171                     {
       
   172                     //Update completed, no thumbnails: progress 70%
       
   173                     progress = KVcxNsProgressUpdateCompletedNoThumb;
       
   174                     }
       
   175                 StartProgressUpdateTimerL();
       
   176                 }            
       
   177             }
       
   178             break;
       
   179         case KIptvThumbnailCount:
       
   180             {
       
   181             if ( aInfo > 0 && iThumbnails )
       
   182                 {
       
   183                 TInt thumbnailPercentage = 
       
   184                     ( KVcxNsProgressUpdateSucceeded - KVcxNsProgressUpdateCompleted ); 
       
   185                 
       
   186                 iProgressPerThumbnail = ( thumbnailPercentage / aInfo );
       
   187                 
       
   188                 //If there's more thumbnails than percents left:
       
   189                 if ( iProgressPerThumbnail == 0 )
       
   190                     {
       
   191                     iThumbnailsInPercent = ( aInfo / thumbnailPercentage );
       
   192                     }
       
   193                 }
       
   194             }
       
   195             break;
       
   196         case KIptvServiceThumbnailDownloaded:
       
   197         case KIptvContentThumbnailDownloaded:
       
   198             {
       
   199             if ( iProgressPerThumbnail > 0 )
       
   200                 {
       
   201                 progress += iProgressPerThumbnail;
       
   202                 }
       
   203             else
       
   204                 {
       
   205                 iThumbnailCounter++;
       
   206                 if ( iThumbnailCounter == 
       
   207                        ( iThumbnailsInPercent * KVcxNsThumbProgressPercentVal ) )
       
   208                     {
       
   209                     //When downloaded enough for increasing progress,
       
   210                     //zero thumbnail counter 
       
   211                     progress += KVcxNsThumbProgressPercentVal;
       
   212                     iThumbnailCounter = 0;
       
   213                     }
       
   214                 }
       
   215             }
       
   216             break;
       
   217         case KIptvErrorEpgUpdateSuccessed:
       
   218             //Update succeeded: progress 99%
       
   219             progress = KVcxNsProgressUpdateSucceeded;
       
   220             break;
       
   221         
       
   222         case KIptvErrorEpgUpdateFailed:
       
   223         case KIptvErrorEpgUpdateStopped:    
       
   224             {
       
   225             progress = 0;
       
   226             iPreviousProgress = 0;
       
   227             iProgressPerThumbnail = 0;
       
   228             iThumbnailsInPercent = 0;
       
   229             iThumbnailCounter = 0;
       
   230             }
       
   231             break;
       
   232         default:
       
   233             break;
       
   234         }
       
   235     
       
   236     if ( progress > 0 && progress > iPreviousProgress )
       
   237         {
       
   238         //Refresh only if any progress
       
   239         RefreshProgressL( progress );
       
   240         }
       
   241     }
       
   242 
       
   243 // --------------------------------------------------------------------------
       
   244 // Timer expired
       
   245 // --------------------------------------------------------------------------
       
   246 //
       
   247 void CVcxNsUpdateProgressHandler::TimerExpired( CIptvTimer* /*aTimer*/ )
       
   248     {
       
   249     TInt progress ( iPreviousProgress );
       
   250     TInt timeout ( KVcxNsProgressTimerDefault );
       
   251     
       
   252     if ( iThumbnails &&
       
   253             progress < KVcxNsProgressUpdateCompleted &&
       
   254             iCurrentStatus == KIptvVodUpdateStarted )
       
   255         {
       
   256         progress += KVcxNsProgStartedThumbnails; 
       
   257         }
       
   258     else if ( !iThumbnails && 
       
   259               progress < KVcxNsProgressUpdateCompletedNoThumb &&
       
   260               iCurrentStatus == KIptvVodUpdateStarted )
       
   261         {
       
   262         progress += KVcxNsProgStartedNoThumbnails;
       
   263         }
       
   264     else if ( !iThumbnails && 
       
   265               iCurrentStatus == KIptvContentUpdateCompleted )
       
   266         {
       
   267         progress += KVcxNsProgCompletedNoThumbnails;
       
   268         }
       
   269     
       
   270     if ( progress > iPreviousProgress )
       
   271         {
       
   272         TRAP_IGNORE( RefreshProgressL( progress ) );
       
   273         }
       
   274 
       
   275     if ( iProgressTimer )
       
   276         {
       
   277         if ( iProgressTimer ->IsActive() )
       
   278             {
       
   279             iProgressTimer->Cancel();
       
   280             }
       
   281         iProgressTimer->After( timeout );
       
   282         }
       
   283     }
       
   284 
       
   285 // --------------------------------------------------------------------------
       
   286 // Cancel progress handler timer
       
   287 // --------------------------------------------------------------------------
       
   288 //
       
   289 void CVcxNsUpdateProgressHandler::Cancel()
       
   290     {
       
   291     if ( iProgressTimer && iProgressTimer->IsActive() )
       
   292         {
       
   293         IPTVLOGSTRING_HIGH_LEVEL(
       
   294             "UI Engine ## CVcxNsUpdateProgressHandler::Cancel()");
       
   295         iProgressTimer->Cancel();
       
   296         }
       
   297     }
       
   298 
       
   299 // --------------------------------------------------------------------------
       
   300 // Check if thumbnails are allowed
       
   301 // --------------------------------------------------------------------------
       
   302 //
       
   303 TBool CVcxNsUpdateProgressHandler::ThumbnailsAllowedL() const
       
   304     {
       
   305     TBool thumbnails( EFalse );
       
   306     CRepository* cenRep = CRepository::NewL( KIptvCenRepUid );
       
   307     if ( cenRep )
       
   308         {
       
   309         TInt value;
       
   310         TInt error = cenRep->Get( KIptvCenRepVoDThumbnailsKey, value );
       
   311         if ( error == KErrNone && value == 1 )
       
   312             {
       
   313             thumbnails = ETrue;
       
   314             }
       
   315         }
       
   316     
       
   317     delete cenRep;
       
   318     return thumbnails;
       
   319     }
       
   320 
       
   321 // --------------------------------------------------------------------------
       
   322 // Check progress
       
   323 // --------------------------------------------------------------------------
       
   324 //
       
   325 void CVcxNsUpdateProgressHandler::StartProgressUpdateTimerL( )
       
   326     {
       
   327     IPTVLOGSTRING_HIGH_LEVEL(
       
   328         "UI Engine ## CVcxNsUpdateProgressHandler::StartProgressUpdateTimerL()");
       
   329     
       
   330     if ( iProgressTimer && iProgressTimer->IsActive())
       
   331         {
       
   332         iProgressTimer->Cancel();
       
   333         }
       
   334     
       
   335     if ( !iProgressTimer )
       
   336         {
       
   337         iProgressTimer = CIptvTimer::NewL( CActive::EPriorityUserInput, *this );
       
   338         }
       
   339 
       
   340     iProgressTimer->After( KVcxNsProgressTimerDefault );
       
   341     }
       
   342 
       
   343 // --------------------------------------------------------------------------
       
   344 // Refresh progress
       
   345 // --------------------------------------------------------------------------
       
   346 //
       
   347 void CVcxNsUpdateProgressHandler::RefreshProgressL( TInt aProgress )
       
   348     {
       
   349     IPTVLOGSTRING2_HIGH_LEVEL(
       
   350         "UI Engine ## CVcxNsUpdateProgressHandler::RefreshProgressL( %d )", 
       
   351         aProgress );
       
   352 
       
   353     if ( aProgress > KVcxNsProgressUpdateSucceeded )
       
   354         {
       
   355         aProgress = KVcxNsProgressUpdateSucceeded;
       
   356         }
       
   357 
       
   358     iPreviousProgress = aProgress;
       
   359 
       
   360     CVcxNsServiceProvider* serviceProvider = iUiEngine.ServiceProvider();
       
   361     if ( serviceProvider && aProgress > 0 )
       
   362         {
       
   363         TInt index = serviceProvider->ServiceIndex( iCurrentServiceId );
       
   364         if ( iProgressObserver )
       
   365             {
       
   366             iProgressObserver->HandleFeedUpdateProgressL( index, aProgress );
       
   367             }
       
   368         }
       
   369     }