voiceui/voiceuivoicerecognition/src/vuicprecheckstate.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 17 Dec 2009 08:46:30 +0200
changeset 0 bf1d17376201
child 7 f096c31e006a
permissions -rw-r--r--
Revision: 200949 Kit: 200951

/*
* 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:  
*
*/


// INCLUDE FILES

#include <coreapplicationuisdomainpskeys.h>
#include <ctsydomainpskeys.h>
#include <PSVariables.h>        // Property values

#include "vuicstate.h"
#include "vuicprecheckstate.h"
#include "vuiccontextcheckstate.h"
#include "vuicexitstate.h"
#include "vuicerrorstate.h"

#include "vuicdatastorage.h"

#include "vuicvoicerecogdialogimpl.h"

#include "rubydebug.h"
    
// -----------------------------------------------------------------------------
// CPrecheckState::NewL
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CPrecheckState* CPrecheckState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
    {
    CPrecheckState* self = new (ELeave) CPrecheckState( aDataStorage, aUiModel );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }       
    
// Destructor       
CPrecheckState::~CPrecheckState()
    {
    RUBY_DEBUG0( "CPrecheckState::~CPrecheckState START" );
    
    RUBY_DEBUG0( "CPrecheckState::~CPrecheckState EXIT" );
    }
    
// ---------------------------------------------------------
// CPrecheckState::HandleEventL
// ---------------------------------------------------------
//       
void CPrecheckState::HandleEventL( TInt aEvent )
    {
    RUBY_DEBUG_BLOCK( "CPrecheckState::HandleEventL" );

    CState* nextState = NULL;

    switch( aEvent )
        {
        case KErrNone:
        
            nextState = CContextCheckState::NewL( DataStorage(), UiModel() );
            break;
        
        case KErrGeneral:
        
            nextState = CExitState::NewL( DataStorage(), UiModel() );
            break;
        
        default:
        
            nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
            break;
        }

    DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
    }

// ---------------------------------------------------------
// CPrecheckState::ExecuteL
// ---------------------------------------------------------
//       
void CPrecheckState::ExecuteL()
    {
    RUBY_DEBUG_BLOCK( "CPrecheckState::ExecuteL" );
    
    TInt error = KErrNone;

    // Check if autolock is on
    if ( GetAutoLockValue() > EAutolockOff )
        {
        if ( !DataStorage().DeviceLockMode() )
            {
            error = KErrGeneral;
            }
        }
    else
        {
        DataStorage().SetDeviceLockMode( EFalse );
        }

    // Check if phone or video call is currently active
    TInt state = CheckCallState();
    if ( ( state != EPSCTsyCallStateNone &&
           state != EPSCTsyCallStateUninitialized &&
           state != KErrUnknown ) || IsVideoCall() )
        {
        error = KErrCallInProgress;
        }

    HandleEventL( error );
    }

// ---------------------------------------------------------
// CPrecheckState::CPrecheckState
// ---------------------------------------------------------
//              
CPrecheckState::CPrecheckState( CDataStorage& aDataStorage, CUiModel& aUiModel )
 : CState( aDataStorage, aUiModel )
    {
    }
   
// ---------------------------------------------------------
// CPrecheckState::GetAutoLockValue
// ---------------------------------------------------------
//
TInt CPrecheckState::GetAutoLockValue()
    {
    RUBY_DEBUG0( "CPrecheckState::GetAutoLockValue START" );
  
    TInt autoLockValue;
    TInt err = RProperty::Get( KPSUidCoreApplicationUIs,
                               KCoreAppUIsAutolockStatus,
                               autoLockValue );
    if ( err == KErrNotFound )
        {
        autoLockValue = KErrNotFound;
        }
        
    RUBY_DEBUG0( "CPrecheckState::GetAutoLockValue EXIT" );
    
    return autoLockValue;
    }
    
// ---------------------------------------------------------
// CPrecheckState::CheckCallState
// ---------------------------------------------------------
//
TInt CPrecheckState::CheckCallState()
    {
    RUBY_DEBUG0( "CPrecheckState::CheckCallState START" );
    
    TInt callState;
    TInt err = RProperty::Get( KPSUidCtsyCallInformation,
                               KCTsyCallState,
                               callState );
    if ( err == KErrNotFound )
        {
        callState = KErrNotFound;
        }
    
    RUBY_DEBUG0( "CPrecheckState::CheckCallState EXIT" );
    
    return callState;    
    }    
    
// -----------------------------------------------------------------------------
// CPrecheckState::IsVideoCall 
// -----------------------------------------------------------------------------
//
TBool CPrecheckState::IsVideoCall() 
    {
    RUBY_DEBUG0( "CPrecheckState::IsVideoCall START" );
    
    TInt callType;
    RProperty::Get( KPSUidCtsyCallInformation,
                    KCTsyCallType, 
                    callType );// Ignore errors  

    RUBY_DEBUG0( "CPrecheckState::IsVideoCall EXIT" );

    return callType == EPSCTsyCallTypeH324Multimedia;
    }    

    
// End of File