videofeeds/hgvodui/src/vcxhgvodthumbnailmanager.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2009 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:    HG VOD class for handling thumbnail loading*
       
    15 */
       
    16 
       
    17 
       
    18 #include "vcxnsimageconverter.h"
       
    19 #include "vcxhgvodthumbnailmanager.h"
       
    20 #include "vcxhgvodthumbnailobserver.h"
       
    21 
       
    22 // Private data class.
       
    23 NONSHARABLE_CLASS( CVcxHgVodThumbnailRequest ) : public CBase
       
    24     {
       
    25 public:
       
    26 
       
    27     CVcxHgVodThumbnailRequest( MVcxHgVodThumbnailObserver& aObserver, 
       
    28             TSize aRequestedSize, TInt64 aClientId )
       
    29       : iObserver( aObserver ),
       
    30         iRequestedSize( aRequestedSize ),
       
    31         iClientId( aClientId )
       
    32         {
       
    33         }
       
    34     
       
    35     void ConstructL( const TDesC& aThumbnailPath )
       
    36         {
       
    37         iThumbnailPath = aThumbnailPath.AllocL();
       
    38         }
       
    39     
       
    40     ~CVcxHgVodThumbnailRequest()
       
    41         {
       
    42         delete iThumbnailPath;
       
    43         }
       
    44     
       
    45 public: // data
       
    46     
       
    47     MVcxHgVodThumbnailObserver& iObserver;
       
    48     HBufC* iThumbnailPath;
       
    49     TSize iRequestedSize;
       
    50     TInt64 iClientId;
       
    51     
       
    52     };
       
    53 
       
    54 TBool CompareRequests( const CVcxHgVodThumbnailRequest& aFirst, const CVcxHgVodThumbnailRequest& aSecond )
       
    55     {
       
    56     return aFirst.iClientId == aSecond.iClientId;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CVcxHgVodThumbnailManager::~CVcxHgVodThumbnailManager()
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CVcxHgVodThumbnailManager::~CVcxHgVodThumbnailManager()
       
    64     {
       
    65     delete iImageConverter;
       
    66     iRequestBuffer.ResetAndDestroy();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVcxHgVodThumbnailManager::NewL()
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CVcxHgVodThumbnailManager* CVcxHgVodThumbnailManager::NewL( RFs& aFsSession )
       
    74     {
       
    75     CVcxHgVodThumbnailManager* self = 
       
    76         CVcxHgVodThumbnailManager::NewLC( aFsSession );
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CVcxHgVodThumbnailManager::NewLC()
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CVcxHgVodThumbnailManager* CVcxHgVodThumbnailManager::NewLC( RFs& aFsSession )
       
    86     {
       
    87     CVcxHgVodThumbnailManager* self = 
       
    88         new (ELeave) CVcxHgVodThumbnailManager();
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL( aFsSession );
       
    91     return self;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CVcxHgVodThumbnailManager::CVcxHgVodThumbnailManager()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CVcxHgVodThumbnailManager::CVcxHgVodThumbnailManager()
       
    99     {
       
   100     
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CVcxHgVodThumbnailManager::ConstructL()
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CVcxHgVodThumbnailManager::ConstructL( RFs& aFsSession )
       
   108     {
       
   109     iImageConverter = CVcxNsImageConverter::NewL( *this, aFsSession );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CVcxHgVodThumbnailManager::Reset()
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CVcxHgVodThumbnailManager::Reset()
       
   117     {
       
   118     iRequestBuffer.ResetAndDestroy();
       
   119     iImageConverter->Cancel();
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CVcxHgVodThumbnailManager::AddThumbnailRequestL()
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CVcxHgVodThumbnailManager::AddThumbnailRequestL( 
       
   127     MVcxHgVodThumbnailObserver& aObserver,
       
   128     const TDesC& aThumbnailPath, 
       
   129     TSize aRequestedSize, 
       
   130     TInt64 aClientId )
       
   131     {
       
   132     CVcxHgVodThumbnailRequest* newReq = new (ELeave) CVcxHgVodThumbnailRequest(
       
   133             aObserver, aRequestedSize, aClientId );
       
   134     CleanupStack::PushL( newReq );
       
   135     newReq->ConstructL( aThumbnailPath );
       
   136     CleanupStack::Pop( newReq );
       
   137     
       
   138     TInt err( KErrAlreadyExists );
       
   139     
       
   140     TIdentityRelation<CVcxHgVodThumbnailRequest> relation( CompareRequests );
       
   141     
       
   142     if ( iRequestBuffer.Find( newReq, relation ) == KErrNotFound )
       
   143         {
       
   144         err = iRequestBuffer.Append( newReq );
       
   145         }
       
   146 
       
   147     if ( err != KErrNone )
       
   148         {
       
   149         delete newReq;
       
   150         }
       
   151     else
       
   152         {
       
   153         if ( !(iImageConverter->IsActive()) )
       
   154             {
       
   155             err = iImageConverter->StartConvertL( *(newReq->iThumbnailPath), 
       
   156                     newReq->iRequestedSize, ETrue );
       
   157             
       
   158             if ( err != KErrNone )
       
   159                 {
       
   160                 // image cannot be converted, remove from request list
       
   161                 iRequestBuffer.Remove( iRequestBuffer.Count() - 1 );
       
   162                 delete newReq;
       
   163                 }
       
   164             }
       
   165         }
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CVcxHgVodThumbnailManager::ImageConversionCompletedL()
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CVcxHgVodThumbnailManager::ImageConversionCompletedL( 
       
   173     TInt aError,
       
   174     CGulIcon* aIcon )
       
   175     {
       
   176     if ( iRequestBuffer.Count() > 0 )
       
   177         {
       
   178         CVcxHgVodThumbnailRequest* req = iRequestBuffer[0];
       
   179         iRequestBuffer.Remove( 0 );
       
   180         
       
   181         if ( aError == KErrNone )
       
   182             {    
       
   183             req->iObserver.MvtoThumbnailReady( aIcon, req->iClientId );
       
   184             }
       
   185         
       
   186         delete req;
       
   187         
       
   188         if ( iRequestBuffer.Count() > 0 )
       
   189             {
       
   190             req = iRequestBuffer[0];
       
   191             iImageConverter->StartConvertL( *(req->iThumbnailPath), req->iRequestedSize, ETrue );
       
   192             }
       
   193         }
       
   194     }