/*
* Copyright (c) 2006-2007 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: Idle integration
*
*/
// System includes
#include <coeaui.h>
#include <eikenv.h>
#include <AknIncallBubbleNotify.h>
#include <aknsoundsystem.h>
#include <AknDef.h>
#include <ctsydomainpskeys.h>
// User includes
#include <aisystemuids.hrh>
#include <aiutility.h>
#include <aipspropertyobserver.h>
#include "activeidle2domainpskeys.h"
#include "aiuiidleintegrationimpl.h"
#include "aifweventhandler.h"
#include "aistate.h"
#include "aifwpanic.h"
#include "debug.h"
// ======== MEMBER FUNCTIONS ========
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::NewL()
// ----------------------------------------------------------------------------
//
CAiUiIdleIntegrationImpl* CAiUiIdleIntegrationImpl::NewL( CEikonEnv& aEikEnv,
const TAiIdleKeySoundConfig& aKeySoundConfig,
MAiFwEventHandler* aAiFwEventHandler )
{
CAiUiIdleIntegrationImpl* self =
new ( ELeave ) CAiUiIdleIntegrationImpl( aEikEnv, aAiFwEventHandler );
CleanupStack::PushL( self );
self->ConstructL( aKeySoundConfig );
CleanupStack::Pop( self );
return self;
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::~CAiUiIdleIntegrationImpl()
// ----------------------------------------------------------------------------
//
CAiUiIdleIntegrationImpl::~CAiUiIdleIntegrationImpl()
{
delete iActiveIdleState;
delete iIncallBubble;
Release( iCallStatusObserver );
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::CAiUiIdleIntegrationImpl()
// ----------------------------------------------------------------------------
//
CAiUiIdleIntegrationImpl::CAiUiIdleIntegrationImpl( CEikonEnv& aEikEnv,
MAiFwEventHandler* aAiFwEventHandler )
: iEikEnv( aEikEnv ),
iAiFwEventHandler( aAiFwEventHandler )
{
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::ConstructL()
// ----------------------------------------------------------------------------
//
void CAiUiIdleIntegrationImpl::ConstructL(
const TAiIdleKeySoundConfig& aKeySoundConfig )
{
__PRINTS( "*** CAiUiIdleIntegrationImpl::ConstructL" );
__TIME_MARK( time );
iIncallBubble = CAknIncallBubble::NewL();
iActiveIdleState = CActiveIdleState::NewL();
// Set up keysounds
if( aKeySoundConfig.iKeySounds )
{
aKeySoundConfig.iKeySounds->PushContextL(
aKeySoundConfig.iContextResId );
}
iEikEnv.SetSystem( ETrue );
TInt wgId( iEikEnv.RootWin().Identifier() );
TInt focusWgId( iEikEnv.WsSession().GetFocusWindowGroup() );
if ( focusWgId == wgId )
{
__PRINTS( "*** CAiUiIdleIntegrationImpl::ConstructL - iForeground: 1" );
iForeground = ETrue;
}
iActiveIdleState->SetIsIdleForeground( iForeground );
iCallStatusObserver = AiUtility::CreatePSPropertyObserverL(
TCallBack( HandleCallEvent, this ),
KPSUidCtsyCallInformation,
KCTsyCallState );
ActivateUI();
__TIME_ENDMARK( "CAiUiIdleIntegrationImpl::ConstructL, done", time );
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::ActivateUI()
// ----------------------------------------------------------------------------
//
void CAiUiIdleIntegrationImpl::ActivateUI()
{
__TICK( "CAiUiIdleIntegrationImpl::ActivateUI - HandleActivateUI" );
iAiFwEventHandler->HandleActivateUI();
__PRINTS( "CAiUiIdleIntegrationImpl::ActivateUI - HandleActivateUI done" );
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::HandleWsEventL()
// ----------------------------------------------------------------------------
//
void CAiUiIdleIntegrationImpl::HandleWsEventL( const TWsEvent& aEvent,
CCoeControl* /*aDestination*/ )
{
TInt type( aEvent.Type() );
if ( type == KAknFullOrPartialForegroundGained )
{
if ( !iForeground )
{
iForeground = ETrue;
iActiveIdleState->SetIsIdleForeground( ETrue );
SetCallBubbleIfNeededL();
}
}
else if ( type == KAknFullOrPartialForegroundLost )
{
if ( iForeground )
{
iForeground = EFalse;
iActiveIdleState->SetIsIdleForeground( EFalse );
ClearCallBubbleL();
}
}
else if ( type == EEventKeyDown )
{
if( aEvent.Key()->iScanCode == EStdKeyDevice0 )
{
TBool isDialog( iEikEnv.AppUi()->IsDisplayingMenuOrDialog() );
if( isDialog || iAiFwEventHandler->QueryIsMenuOpen() )
{
RProperty::Set(
KPSUidAiInformation,
KActiveIdlePopupState,
EPSAiDisplayingMenuOrDialog );
}
else
{
RProperty::Set(
KPSUidAiInformation,
KActiveIdlePopupState,
EPSAiNotDisplayingMenuOrDialog );
}
}
}
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::SetCallBubbleIfNeededL()
// ----------------------------------------------------------------------------
//
void CAiUiIdleIntegrationImpl::SetCallBubbleIfNeededL()
{
if( !iIncallBubbleAllowed )
{
TInt callStatus( 0 );
TInt err( RProperty::Get( KPSUidCtsyCallInformation,
KCTsyCallState,
callStatus ) );
// Call ongoing => show bubble
if( err == KErrNone && callStatus > EPSCTsyCallStateNone )
{
iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );
iIncallBubbleAllowed = ETrue;
}
}
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::ClearCallBubbleL()
// ----------------------------------------------------------------------------
//
void CAiUiIdleIntegrationImpl::ClearCallBubbleL()
{
if( iIncallBubbleAllowed )
{
iIncallBubble->SetIncallBubbleAllowedInIdleL( EFalse );
iIncallBubbleAllowed = EFalse;
}
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegration::NewL()
// ----------------------------------------------------------------------------
//
EXPORT_C CAiUiIdleIntegration* CAiUiIdleIntegration::NewL( CEikonEnv& aEikEnv,
const TAiIdleKeySoundConfig& aKeySoundConfig,
MAiFwEventHandler* aAiFwEventHandler )
{
return CAiUiIdleIntegrationImpl::NewL( aEikEnv, aKeySoundConfig,
aAiFwEventHandler );
}
// ----------------------------------------------------------------------------
// CAiUiIdleIntegrationImpl::HandleCallEvent()
// ----------------------------------------------------------------------------
//
TInt CAiUiIdleIntegrationImpl::HandleCallEvent( TAny* aPtr )
{
__ASSERT_DEBUG( aPtr,
AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
CAiUiIdleIntegrationImpl* self =
static_cast<CAiUiIdleIntegrationImpl*>( aPtr );
TInt callStatus( EPSCTsyCallStateNone );
TInt err( self->iCallStatusObserver->Get( callStatus ) );
if( err == KErrNone )
{
// Call ongoing => show bubble if not showing already
TBool allowed = EFalse;
if( !self->iIncallBubbleAllowed &&
self->iForeground &&
( callStatus > EPSCTsyCallStateNone ) )
{
allowed = ETrue;
TRAP( err,
self->iIncallBubble->SetIncallBubbleAllowedInIdleL( allowed ) );
if( err == KErrNone )
{
self->iIncallBubbleAllowed = allowed;
}
}
// No call ongoing => hide if bubble is visible
else if( self->iIncallBubbleAllowed && callStatus <= EPSCTsyCallStateNone )
{
allowed = EFalse;
TRAP( err,
self->iIncallBubble->SetIncallBubbleAllowedInIdleL( allowed ) );
if( err == KErrNone )
{
self->iIncallBubbleAllowed = allowed;
}
}
}
return err;
}
// End of file.