www.pudn.com > SystemSounds_Example_v1_0.zip > SystemSoundsView.cpp


/*
* ============================================================================
* Name : CSystemSoundsView from SystemSoundsView.h
* Part of : SystemSounds
* Created : 06/12/2003 by Forum Nokia
* Implementation notes:
* Initial content was generated by Nokia Series 60 AppWizard.
* Version : 1.0
* Copyright: Nokia
* ============================================================================
*/

// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>
#include <SystemSounds.rsg>
#include "SystemSoundsView.h"
#include "SystemSoundsContainer.h"
#include "SystemSounds.hrh"

// Definitions
#define KWavSoundId 2

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CSystemSoundsView::ConstructL(const TRect&amt; aRect)
// EPOC two-phased constructor
// ---------------------------------------------------------
//
void CSystemSoundsView::ConstructL()
{
BaseConstructL( R_SYSTEMSOUNDS_VIEW1 );

// Create player
iSoundPlayer = (STATIC_CAST(CAknAppUi*,
CEikonEnv::Static()->AppUi()))->KeySounds();

// Add system wav to soundlist
TRAPD(error, iSoundPlayer->AddAppSoundInfoListL( R_SYSTEM_WAV_SOUND ));
if ( ( error != KErrAlreadyExists ) &amt;&amt; ( error != KErrNone) )
User::LeaveIfError(error);

}

// ---------------------------------------------------------
// CSystemSoundsView::~CSystemSoundsView()
// ?implementation_description
// ---------------------------------------------------------
//
CSystemSoundsView::~CSystemSoundsView()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}

delete iContainer;
}

// ---------------------------------------------------------
// TUid CSystemSoundsView::Id()
// ?implementation_description
// ---------------------------------------------------------
//
TUid CSystemSoundsView::Id() const
{
return KViewId;
}

// ---------------------------------------------------------
// CSystemSoundsView::HandleCommandL(TInt aCommand)
// ?implementation_description
// ---------------------------------------------------------
//
void CSystemSoundsView::HandleCommandL(TInt aCommand)
{
if (aCommand>=EAvkonSIDNoSound &amt;&amt; aCommand<=EAvkonSIDRingGoing)
{
TInt soundNumber=aCommand;
// Play system sounds
// Note that some of the sounds are played in the loudspeaker,
// some in the earpiece (speaker)
// These sounds follow the profiles. However, those system sounds
// involving phone speaker, not loudspeaker will be played even in the silent mode.
// You need to have the phone on the ear to hear it.
if (iSoundPlayer)iSoundPlayer->PlaySound(soundNumber);
}

switch ( aCommand )
{
case EAknSoftkeyBack:
{
AppUi()->HandleCommandL(EEikCmdExit);
break;
}

case ESystemSoundsView1Cmd1:
{
TInt soundNumber=KWavSoundId;
// Play system wav sound
if (iSoundPlayer)iSoundPlayer->PlaySound(soundNumber);
break;
}


default:
{
AppUi()->HandleCommandL( aCommand );
break;
}
}
}

// ---------------------------------------------------------
// CSystemSoundsView::HandleClientRectChange()
// ---------------------------------------------------------
//
void CSystemSoundsView::HandleClientRectChange()
{
if ( iContainer )
{
iContainer->SetRect( ClientRect() );
}
}

// ---------------------------------------------------------
// CSystemSoundsView::DoActivateL(...)
// ---------------------------------------------------------
//
void CSystemSoundsView::DoActivateL(
const TVwsViewId&amt; /*aPrevViewId*/,TUid /*aCustomMessageId*/,
const TDesC8&amt; /*aCustomMessage*/)
{
if (!iContainer)
{
iContainer = new (ELeave) CSystemSoundsContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
}
}

// ---------------------------------------------------------
// CSystemSoundsView::HandleCommandL(TInt aCommand)
// ---------------------------------------------------------
//
void CSystemSoundsView::DoDeactivate()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}

delete iContainer;
iContainer = NULL;
}

// End of File