videofeeds/livetvutils/src/CIptvLiveUIImageHandler.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:    Offers interface for loading and converting images.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <gulicon.h>					// CGulIcon
       
    22 #include <imageconversion.h>			// CImageDecoder
       
    23 #include <AknIconArray.h>				// CAknIconArray
       
    24 #include "IptvLiveLogger.h"				// Live TV logging macros
       
    25 #include <AknIconUtils.h>				// AknIconUtils
       
    26 #include <AknsUtils.h>
       
    27 
       
    28 #include "CIptvLiveUIImageHandler.h"	// CIptvLiveUIImageHandler
       
    29 #include "MIptvLiveUIImageObserver.h"	// MIptvLiveUIImageObserver
       
    30 
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CIptvLiveUIImageHandler::NewL
       
    38 // Two-phased constructor.
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CIptvLiveUIImageHandler* CIptvLiveUIImageHandler::NewL( 
       
    42 										MIptvLiveUIImageObserver& aObserver )
       
    43     {
       
    44     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::NewL() in"));
       
    45     CIptvLiveUIImageHandler* self = 
       
    46 						new ( ELeave ) CIptvLiveUIImageHandler( aObserver );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CIptvLiveUIImageHandler::ConstructL()
       
    55 // Symbian 2nd phase constructor can leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CIptvLiveUIImageHandler::ConstructL()
       
    59     {
       
    60     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::ConstructL() in"));
       
    61 	User::LeaveIfError( iFs.Connect() );
       
    62     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::ConstructL() out"));
       
    63     }
       
    64     
       
    65 // -----------------------------------------------------------------------------
       
    66 // CIptvLiveUIImageHandler::CIptvLiveUIImageHandler()
       
    67 // C++ default constructor can NOT contain any code, that might leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CIptvLiveUIImageHandler::CIptvLiveUIImageHandler( 
       
    71 										MIptvLiveUIImageObserver& aObserver ) 
       
    72 	: CActive( EPriorityNormal ), iObserver( &aObserver ), 
       
    73 	iImageDecoder( NULL ), iBitmap( NULL )
       
    74     {
       
    75     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::CIptvLiveUIImageHandler() in"));
       
    76     CActiveScheduler::Add( this );
       
    77     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::CIptvLiveUIImageHandler() out"));
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CIptvLiveUIImageHandler::~CIptvLiveUIImageHandler()
       
    82 // Destructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CIptvLiveUIImageHandler::~CIptvLiveUIImageHandler()
       
    86     {
       
    87     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::~CIptvLiveUIImageHandler() in"));
       
    88     Cancel();
       
    89     iObserver = NULL;
       
    90 	delete iImageDecoder;
       
    91 	delete iBitmap;
       
    92 	iFs.Close();
       
    93     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::~CIptvLiveUIImageHandler() out"));    	
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CIptvLiveUIImageHandler::LoadImageL(). Asynchronous, 
       
    98 // MIptvLiveUIImageObserver::ImageReadyL() when loading and converting is complete.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CIptvLiveUIImageHandler::LoadImageL( const TDesC& aFilePath )
       
   102     {
       
   103     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadImageL() in"));
       
   104 	if ( IsActive() ) 
       
   105 		{
       
   106 		LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadImageL() IS ACTIVE, leave with KErrInUse"));
       
   107 		User::Leave( KErrInUse );
       
   108 		}
       
   109 	if ( iImageDecoder ) 
       
   110 		{
       
   111 		iImageDecoder->Cancel();
       
   112 		delete iImageDecoder;
       
   113 		iImageDecoder = NULL;
       
   114 		}
       
   115 	// Create new image decoder 
       
   116 	iImageDecoder = CImageDecoder::FileNewL( iFs, aFilePath );
       
   117 
       
   118 	// Create bitmap
       
   119 	if ( iBitmap ) 
       
   120 		{
       
   121 		delete iBitmap;
       
   122 		iBitmap = NULL;
       
   123 		}
       
   124 	TFrameInfo info = iImageDecoder->FrameInfo();
       
   125 	iBitmap = new ( ELeave ) CFbsBitmap;
       
   126 	TInt err = iBitmap->Create( info.iOverallSizeInPixels, 
       
   127 										 info.iFrameDisplayMode );
       
   128 	if ( err == KErrNone )
       
   129 		{
       
   130 		// Start converting the image
       
   131 		iImageDecoder->Convert( &iStatus, *iBitmap );
       
   132 		SetActive();	
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		delete iImageDecoder;
       
   137 		iImageDecoder = NULL;
       
   138 		delete iBitmap;
       
   139 		iBitmap = NULL;
       
   140 		User::Leave( err );
       
   141 		}
       
   142 	
       
   143     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadImageL() out"));
       
   144    	}
       
   145     
       
   146 // -----------------------------------------------------------------------------
       
   147 // CIptvImageLoader::LoadIconL
       
   148 // Loads icon to the given array.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C void CIptvLiveUIImageHandler::LoadIconL( CAknIconArray* aIcons, 
       
   152 									const TInt aIconIndex, 
       
   153                                     const TInt aMaskIndex, const TSize& aIconSize,
       
   154                                     const TDesC& aMifFileName, TBool aInsert )
       
   155     {
       
   156 	LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadIconL() in") );
       
   157     CFbsBitmap* bitmap = NULL;
       
   158     CFbsBitmap* mask = NULL;
       
   159         
       
   160     AknIconUtils::CreateIconLC( bitmap, mask, aMifFileName, 
       
   161                                 aIconIndex, aMaskIndex );
       
   162 
       
   163     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   164     CleanupStack::PushL( icon );
       
   165 
       
   166     // ownership of bitmap and mask transferred to icon
       
   167     icon->SetBitmapsOwnedExternally( EFalse );
       
   168 
       
   169     TInt err = AknIconUtils::SetSize( bitmap, aIconSize );
       
   170 	if ( err != KErrNone ) 
       
   171 		{
       
   172 		LIVE_TV_TRACE2(_L("CIptvLiveUIImageHandler::LoadIconL() AknIconUtils::SetSize() FAILED: %d"), err);
       
   173 		}
       
   174 
       
   175     if ( aInsert && aIcons )
       
   176         {
       
   177         aIcons->InsertL( 0, icon );
       
   178         }
       
   179     else 
       
   180         {
       
   181 		if ( aIcons ) 
       
   182 			{
       
   183 			aIcons->AppendL( icon );	
       
   184 			}
       
   185         }
       
   186 
       
   187     CleanupStack::Pop( icon );  
       
   188     CleanupStack::Pop( mask );
       
   189     CleanupStack::Pop( bitmap );
       
   190 	LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadIconL() out") );
       
   191     }   
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // Loads color-customized icon to the given array.
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 EXPORT_C void CIptvLiveUIImageHandler::LoadIconL( CAknIconArray* aIcons, 
       
   198                                     const TAknsItemID aItemId, 
       
   199 									const TInt aIconIndex, 
       
   200                                     const TInt aMaskIndex, 
       
   201                                     const TSize& aIconSize,
       
   202                                     const TDesC& aMifFileName, 
       
   203                                     TBool aInsert
       
   204                                     )
       
   205     {
       
   206 	LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadIconL() in") );
       
   207         
       
   208     MAknsSkinInstance* skin = AknsUtils::SkinInstance();    
       
   209             
       
   210     CFbsBitmap* bitmap = NULL;
       
   211     CFbsBitmap* mask = NULL;
       
   212     TRgb defaultColour( KRgbWhite );
       
   213     // Color is not updated if it not found from the skin
       
   214     AknsUtils::GetCachedColor( skin,
       
   215               defaultColour,
       
   216               KAknsIIDQsnIconColors,
       
   217               EAknsCIQsnIconColorsCG13 );
       
   218     
       
   219     AknsUtils::CreateColorIconLC( skin,
       
   220               aItemId,
       
   221               KAknsIIDQsnIconColors,
       
   222               EAknsCIQsnIconColorsCG13,
       
   223               bitmap,
       
   224               mask,
       
   225               aMifFileName,
       
   226               aIconIndex,
       
   227               aMaskIndex,
       
   228               defaultColour,
       
   229               aIconSize,
       
   230               EAspectRatioPreserved );
       
   231         
       
   232     CGulIcon* icon = NULL;
       
   233     icon = CGulIcon::NewL( bitmap, mask );
       
   234     
       
   235     CleanupStack::Pop( 2 ); // mask, bitmap        
       
   236     // ownership of bitmap and mask transferred to icon
       
   237     icon->SetBitmapsOwnedExternally( EFalse );         
       
   238     
       
   239     CleanupStack::PushL( icon );    
       
   240 
       
   241     if ( aInsert && aIcons )
       
   242         {
       
   243         aIcons->InsertL( 0, icon );
       
   244         }
       
   245     else 
       
   246         {
       
   247 		if ( aIcons ) 
       
   248 			{
       
   249 			aIcons->AppendL( icon );	
       
   250 			}
       
   251         }
       
   252 
       
   253     CleanupStack::Pop( icon );  
       
   254 	LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::LoadIconL() out") );
       
   255     }   
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CIptvLiveUIImageHandler::RunL()
       
   259 // From CActive
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CIptvLiveUIImageHandler::RunL()
       
   263     {
       
   264     LIVE_TV_TRACE2(_L("CIptvLiveUIImageHandler::RunL() in, iStatus.Int() = %d"), iStatus.Int());
       
   265 	if ( iStatus.Int() == KErrNone ) 
       
   266 		{
       
   267 		// Image conversion ok
       
   268 		iObserver->ImageReadyL( KErrNone, *iBitmap );
       
   269 		}
       
   270 	else 
       
   271 		{
       
   272 		// There was some error, notify observer
       
   273 		iObserver->ImageReadyL( iStatus.Int(), *iBitmap );
       
   274 		}
       
   275 	// free image file and bitmap
       
   276 	delete iImageDecoder;
       
   277 	iImageDecoder = NULL;
       
   278 	delete iBitmap;
       
   279 	iBitmap = NULL;
       
   280 	LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::RunL() out"));
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CIptvLiveUIImageHandler::RunError()
       
   285 // From CActive
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 TInt CIptvLiveUIImageHandler::RunError( TInt /*aError*/ )
       
   289     {
       
   290     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::RunError() in"));
       
   291 	// free image file and bitmap
       
   292 	delete iImageDecoder;
       
   293 	iImageDecoder = NULL;
       
   294 	delete iBitmap;
       
   295 	iBitmap = NULL;
       
   296 	LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::RunError() out"));
       
   297     return KErrNone;
       
   298     }
       
   299     
       
   300 // -----------------------------------------------------------------------------
       
   301 // CIptvLiveUIImageHandler::DoCancel()
       
   302 // From CActive
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CIptvLiveUIImageHandler::DoCancel()
       
   306     {
       
   307     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::DoCancel() in"));
       
   308 	if ( iImageDecoder ) 
       
   309 		{
       
   310 		iImageDecoder->Cancel();	
       
   311 		}
       
   312 	delete iImageDecoder;
       
   313 	iImageDecoder = NULL;
       
   314     LIVE_TV_TRACE1(_L("CIptvLiveUIImageHandler::DoCancel() out"));
       
   315     }
       
   316 
       
   317 // End of File