internetradio2.0/uicontrolssrc/irstationlogodata.cpp
author Pat Downey <patd@symbian.org>
Tue, 18 May 2010 11:36:57 +0100
changeset 4 3f2d53f144fe
parent 0 09774dfdd46b
permissions -rw-r--r--
Merge docml changeset with recent Nokia delivery.

/*
* Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Data for single station logo
*
*/


#include <alf/alfenv.h>
#include <alf/alfevent.h>
#include <alf/alfimagevisual.h>
#include <alf/alftexture.h>
#include "irdebug.h"

#include "irstationlogodata.h"

// ---------------------------------------------------------------------------
// Default constructor
// ---------------------------------------------------------------------------
//
CIRStationLogoData::CIRStationLogoData( TInt aId, const TDesC8& aRawData ) : 
    iData( aRawData ),    
    iId( aId ), 
    iTextureId( KErrNotFound )
    {
    }

// ---------------------------------------------------------------------------
// Second phase constructor
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::ConstructL()
    {
 	//TO DO :: The line can be removed in future nad written to fix
	return;
    }

// ---------------------------------------------------------------------------
// Two-phased constructor
// ---------------------------------------------------------------------------
//
CIRStationLogoData* CIRStationLogoData::NewLC( TInt aId, const TDesC8& aRawData )
    {
    CIRStationLogoData* self = new( ELeave ) CIRStationLogoData( aId, aRawData );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

// ---------------------------------------------------------------------------
// Destructor
// ---------------------------------------------------------------------------
//
CIRStationLogoData::~CIRStationLogoData()
    {
    DestroyVisual();
    DestroyTexture();
    }

// ---------------------------------------------------------------------------
// Sets the raw data
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::SetRawData( const TDesC8& aRawData )
    {
    iData.Set( aRawData );
    }

// ---------------------------------------------------------------------------
// Provides the raw data
// ---------------------------------------------------------------------------
//
const TDesC8& CIRStationLogoData::RawData() const
    {
    return iData;
    }

// ---------------------------------------------------------------------------
// Updates the texture
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::UpdateTextureL( CFbsBitmap* aBitmap, CFbsBitmap* aMask )
    {
    IRLOG_DEBUG(" *** S60VisualRadio -- CIRStationLogoData::UpdateTextureL()");
    DestroyTexture();
    iBitmap = aBitmap;
    iMask = aMask;
    iTexture = &CAlfEnv::Static()->TextureManager().CreateTextureL( KAlfAutoGeneratedTextureId, 
    								this, EAlfTextureFlagRetainResolution );
    }

// ---------------------------------------------------------------------------
// Destroys the texture
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::DestroyTexture()
    {
    IRLOG_DEBUG(" *** S60VisualRadio -- CIRStationLogoData::DestroyTexture()");
    if( iTextureId != KErrNotFound )
        {
        CAlfEnv::Static()->TextureManager().UnloadTexture( iTextureId );
        }
    delete iTexture;
    iTexture = NULL;
    
    delete iBitmap;
    iBitmap = NULL;
    delete iMask;
    iMask = NULL;
    }

// ---------------------------------------------------------------------------
// Sets the visual for this logo data
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::SetVisual( CAlfImageVisual* aVisual )
    {
    DestroyVisual();
    iVisual = aVisual;
    }

// ---------------------------------------------------------------------------
// Provides the visual
// ---------------------------------------------------------------------------
//
CAlfImageVisual* CIRStationLogoData::Visual()
    {
    return iVisual;
    }

// ---------------------------------------------------------------------------
// Destroys the visual
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::DestroyVisual()
    {
    IRLOG_DEBUG(" *** S60VisualRadio -- CIRStationLogoData::DestroyVisual()");
    if( iVisual )
        {
        iVisual->RemoveAndDestroyAllD();
        }
    iVisual = NULL;
    }

// ---------------------------------------------------------------------------
// Provides the texture
// ---------------------------------------------------------------------------
//
CAlfTexture* CIRStationLogoData::Texture()
    {
    return iTexture;
    }

// ---------------------------------------------------------------------------
// Provides the ID
// ---------------------------------------------------------------------------
//
TInt CIRStationLogoData::Id() const 
    {
    return iId;
    }

// ---------------------------------------------------------------------------
// From class MAlfBitmapProvider.
// Provides the bitmap for the texture
// ---------------------------------------------------------------------------
//
void CIRStationLogoData::ProvideBitmapL(TInt aId, CFbsBitmap*& aBitmap, CFbsBitmap*& aMaskBitmap)
    {
    IRLOG_DEBUG2(" *** S60VisualRadio -- CIRStationLogoData::ProvideBitmapL(aId=%d)", aId);
    iTextureId = aId;
    // Ownership is transfered so the members are NULLED
    aBitmap = iBitmap;
    iBitmap = NULL;
    aMaskBitmap = iMask;
    iMask = NULL;

	return;
    }

// ---------------------------------------------------------------------------
// From class MAlfEventHandler.
// Handles the Alf events
// ---------------------------------------------------------------------------
//
TBool CIRStationLogoData::OfferEventL( const TAlfEvent& aEvent )
    {
    TBool eventHandled( EFalse );
    if( aEvent.IsCustomEvent() && aEvent.CustomParameter() == EIRCustomEventLogoFadeOutComplete )
        {
        IRLOG_DEBUG(" *** S60VisualRadio -- CIRStationLogoData::OfferEventL() -- deleting visual and texture");
        DestroyVisual();
        DestroyTexture();
        eventHandled = ETrue;
        }

    return eventHandled;
    }