cellular/telephonysettings/src/PsetCallDiverting.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Mar 2010 09:40:14 +0200
changeset 12 ae8abd0db65c
parent 0 ff3b6d0fd310
child 13 e32024264ebb
permissions -rw-r--r--
Revision: 201007 Kit: 201011

/*
* Copyright (c) 2002-2004 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:  Call diverting class. Sets and gets call diverting status. 
*
*
*/


//  Include Files
#include <etelmm.h>           
#include <e32math.h>
#include <e32svr.h>
#include <badesca.h>
// <-- QT PHONE START -->
//#include <vmnumber.h>
// <-- QT PHONE END-->
#include <centralrepository.h>
#include <settingsinternalcrkeys.h> 

#include "psetcalldiverting.h" 
#include "psetcontainer.h" 
#include "mpsetdivertobs.h" 
#include "PsetTelephony.h" 
#include "PSetPanic.h" 
#include "PhoneSettingsLogger.h" 

#include "PSetCallDivertingCreator.h" 
#include "MCallDiverting.h" 

//  MEMBER FUNCTIONS
// ---------------------------------------------------------------------------
// First phase constructor
// ---------------------------------------------------------------------------       
EXPORT_C CPsetCallDiverting* CPsetCallDiverting::NewL( MPsetDivertObserver& aObserver,
                  RMobilePhone& aPhone )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::NewL");
    CPsetCallDiverting* self = new ( ELeave ) CPsetCallDiverting( aPhone );
    CleanupStack::PushL( self );
    self->ConstructL( aObserver );
    CleanupStack::Pop( self );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::NewL");
    return self;
    }

// ---------------------------------------------------------------------------
// Destructor.
// ---------------------------------------------------------------------------
EXPORT_C CPsetCallDiverting::~CPsetCallDiverting()
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::~CPsetCallDiverting");
    iReqObserver = NULL;

    delete iRepository;
    
    delete iDivert;
    iDivert = NULL;
    __PHSLOGSTRING("[PHS]<-- CPsetCallDiverting::~CPsetCallDiverting");
    } 

// ---------------------------------------------------------------------------
// Symbian OS constructor
// ---------------------------------------------------------------------------
void CPsetCallDiverting::ConstructL( MPsetDivertObserver& aObserver )
    {
    __PHSLOGSTRING("[PHS] -->CPsetCallDiverting::ConstructL" );
    iDivert= CPSetCallDivertingCreator::CreateCallDivertingL( aObserver, iPhone, this );
    iRepository = CRepository::NewL( KCRUidCallForwarding );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::ConstructL" );
    }

// ---------------------------------------------------------------------------
// C++ constructor
// ---------------------------------------------------------------------------
//
CPsetCallDiverting::CPsetCallDiverting( RMobilePhone& aPhone ) :
                    iPhone ( aPhone )
    {
    }

// ---------------------------------------------------------------------------
// Sets diverting. 
// ---------------------------------------------------------------------------
EXPORT_C void CPsetCallDiverting::SetDivertingL( 
    const TCallDivertSetting& aDivert, 
    TBasicServiceGroups aBsc, TBool /*aVmbx*/ )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::SetDivertingL");    
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetDivertingL: aDivert.iCondition: %d", aDivert.iCondition );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetDivertingL: aDivert.iStatus: %d", aDivert.iStatus );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetDivertingL: aDivert.iServiceGroup: %d", aDivert.iServiceGroup );
    iDivert->SetDivertingL( aDivert, aBsc );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::SetDivertingL" );
    }

// --------------------------------------------------------------------------- 
// Request diverting status from network asynhronously.
// ---------------------------------------------------------------------------
EXPORT_C void CPsetCallDiverting::GetDivertingStatusL( 
    const TServiceGroup aServiceGroup,
    const TCallDivertingCondition aCondition, 
    TBasicServiceGroups aBsc ) 
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::GetDivertingStatusL" );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::GetDivertingStatusL: aServiceGroup: %d", aServiceGroup );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::GetDivertingStatusL: aCondition: %d", aCondition );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::GetDivertingStatusL: aBsc: %d", aBsc );
    iDivert->GetDivertingStatusL( aServiceGroup, aCondition, aBsc );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::GetDivertingStatusL" );
    }

// ---------------------------------------------------------------------------
// Cancels pending request.
// ---------------------------------------------------------------------------
EXPORT_C TInt CPsetCallDiverting::CancelCurrentRequest()
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::CancelCurrentRequest" );
    TInt err(KErrNone);
    err = iDivert->CancelCurrentRequest();
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::CancelCurrentRequest" );
    return err; 
    }

// ---------------------------------------------------------------------------
// The default (last forwarded-to) numbers can be retrieved through this method.
// The amount of available numbers is returned.
// Relies on default numbers having right order in shared data.
// ---------------------------------------------------------------------------
EXPORT_C TInt CPsetCallDiverting::GetDefaultNumbersL( 
    CDesC16ArrayFlat& aDefNumbers )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::GetDefaultNumbersL" );
    return iDivert->GetNumbersFromSharedDataL( NULL, aDefNumbers );
    }

// ---------------------------------------------------------------------------
// Sets new default number the the default numbers list, erases the oldest one.
// ---------------------------------------------------------------------------
EXPORT_C TInt CPsetCallDiverting::SetNewDefaultNumberL( TDes& aNumber )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::SetNewDefaultNumberL" );
    TInt retValue(KErrNone);
    retValue = iDivert->SetNewDefaultNumberL( aNumber );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::SetNewDefaultNumberL" );
    return retValue; //return value is not used
    }

// ---------------------------------------------------------------------------
// Gets the timer value index related to "cfnry" from shared data
// In error cases, return default value (30).
// ---------------------------------------------------------------------------
//
EXPORT_C TInt CPsetCallDiverting::GetTimerValueL()
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::GetTimerValueL" );
    TInt timerValue(0);
    timerValue = iDivert->GetTimerValueL();
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::GetTimerValueL" );
    return timerValue;
    }

// ---------------------------------------------------------------------------
// Sets the default time for "divert when not answered" to .ini file
// ---------------------------------------------------------------------------
EXPORT_C TInt CPsetCallDiverting::SetTimerValueL( const TInt& aValue )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::SetTimerValueL" );
    TInt retValue(KErrNone);
    retValue = iDivert->SetTimerValueL( aValue );
    __PHSLOGSTRING1("[PHS] <--CPsetCallDiverting::SetTimerValueL: retValue: %d", retValue );
    return retValue; 
    }

// ---------------------------------------------------------------------------
// Swaps the most recently used number to first in the shared data file.
// ---------------------------------------------------------------------------
EXPORT_C void CPsetCallDiverting::SwapDefaultNumberL( const TInt& aLocation )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::SwapDefaultNumberL" );
    iDivert->SwapDefaultNumberL( aLocation );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::SwapDefaultNumberL" );
    }

// ---------------------------------------------------------------------------
// Saves fax call diverting number to shareddata.
// ---------------------------------------------------------------------------
EXPORT_C TInt CPsetCallDiverting::SetUsedDataNumberL(  TTelNumber& aNumber ) 
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::SetUsedDataNumberL" );
    TInt retValue = KErrNone;
    retValue = iDivert->SaveKey( KSettingsCFUsedDataNumber, aNumber );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetUsedDataNumberL: aNumber: %S", &aNumber );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetUsedDataNumberL: retValue: %d", retValue );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::SetUsedDataNumberL" );
    return retValue;
    }

// ---------------------------------------------------------------------------
// Returns used number for data call forwardings.
// ---------------------------------------------------------------------------
EXPORT_C HBufC* CPsetCallDiverting::GetUsedDataNumberLC( ) 
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::GetUsedDataNumberLC" );
    TTelNumber readNumber;

    iRepository->Get( KSettingsCFUsedDataNumber, readNumber );

    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::GetUsedDataNumberLC: readNumber: %S", &readNumber );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::GetUsedDataNumberLC" );
    
    return readNumber.AllocLC();
    }

// ---------------------------------------------------------------------------
// Saves fax call diverting number to shareddata.
// ---------------------------------------------------------------------------
EXPORT_C TInt CPsetCallDiverting::SetUsedFaxNumberL(  TTelNumber& aNumber ) 
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::SetUsedFaxNumberL" );
    TInt retValue = KErrNone;

    retValue =  iDivert->SaveKey( KSettingsCFUsedFaxNumber, aNumber );

    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetUsedFaxNumberL: aNumber: %S", &aNumber );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::SetUsedFaxNumberL: retValue: %d", retValue );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::SetUsedFaxNumberL" );

    return retValue;
    }

// ---------------------------------------------------------------------------
// Returns used number for fax call forwardings.
// ---------------------------------------------------------------------------
EXPORT_C HBufC* CPsetCallDiverting::GetUsedFaxNumberLC() 
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::GetUsedFaxNumberLC" );
    TTelNumber readNumber;

    iRepository->Get( KSettingsCFUsedFaxNumber, readNumber );

    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::GetUsedFaxNumberLC: readNumber: %S", &readNumber );
    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::GetUsedFaxNumberLC" );

    return readNumber.AllocLC();
    }

// ---------------------------------------------------------------------------
// Sets request observer.
// ---------------------------------------------------------------------------
//
EXPORT_C void CPsetCallDiverting::SetRequestObserver( MPsetRequestObserver* aObs )
    {
    iReqObserver = aObs;
// <-- QT PHONE START -->
    iDivert->SetRequestObserver(aObs);
// <-- QT PHONE END -->
    }

// ---------------------------------------------------------------------------
// Queries for voice mail box number
// ---------------------------------------------------------------------------
//
EXPORT_C void CPsetCallDiverting::VoiceMailQueryL( TDes& /*aTelNumber*/ )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::VoiceMailQueryL" );
// <-- QT PHONE START -->
/*
    RVmbxNumber vmbxConnection;
    TBool vmbxNrChanged = ETrue;
    TInt retValue = iDivert->OpenVmbxLC( aTelNumber, vmbxConnection );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::VoiceMailQueryL: aTelNumber = %S", &aTelNumber );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::VoiceMailQueryL: retValue = %d", retValue );

    if ( retValue == KErrNotFound )
        {
        vmbxNrChanged = vmbxConnection.QueryNumberL( EVmbxNotDefinedQuery, aTelNumber );
        }
    else if ( retValue != KErrNone )
        {
        //Problem with vmbx application, better leave.
        User::Leave( retValue );
        }
    if ( !vmbxNrChanged )
        {
        User::Leave( KErrCancel );
        }
    CleanupStack::PopAndDestroy(); // vmbxConnection
    */
// <-- QT PHONE END-->

    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::VoiceMailQueryL" );
    }

// ---------------------------------------------------------------------------
// Queries for voice mail box number
// ---------------------------------------------------------------------------
//
EXPORT_C void CPsetCallDiverting::VideoMailQueryL( TDes& /*aTelNumber*/ )
    {
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::VideoMailQueryL" );
    // <-- QT PHONE START -->
    /*
    RVmbxNumber vmbxConnection;
    TBool vmbxNrChanged = ETrue;
    TInt retValue = OpenVideoMailboxLC( aTelNumber, vmbxConnection );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::VideoMailQueryL: aTelNumber = %S", &aTelNumber );
    __PHSLOGSTRING1("[PHS]    CPsetCallDiverting::VideoMailQueryL: retValue = %d", retValue );

    if ( retValue == KErrNotFound )
        {
        vmbxNrChanged = vmbxConnection.QueryVideoMbxNumberL( EVmbxNotDefinedQuery, aTelNumber );
        }
    else if ( retValue != KErrNone )
        {
        //Problem with vmbx application, better leave.
        User::Leave( retValue );
        }
    if ( !vmbxNrChanged )
        {
        User::Leave( KErrCancel );
        }
    CleanupStack::PopAndDestroy(); // vmbxConnection
    */
    // <-- QT PHONE END-->

    __PHSLOGSTRING("[PHS] <--CPsetCallDiverting::VideoMailQueryL" );
    }    
    
// ---------------------------------------------------------------------------
// Opens Vmbx. Leaves vmbx to the stack. 
// ---------------------------------------------------------------------------
//
// <-- QT PHONE START -->
TInt CPsetCallDiverting::OpenVideoMailboxLC( TDes& /*aTelNumber*/, RVmbxNumber& /*aVmbx*/ )
    {
/*
    __PHSLOGSTRING("[PHS]--> CPsetCallDiverting::OpenVideoMailboxLC" );
    User::LeaveIfError( aVmbx.Open( iPhone ) );
    CleanupClosePushL( aVmbx );         
    __PHSLOGSTRING("[PHS]<-- CPsetCallDiverting::OpenVideoMailboxLC" );
    return aVmbx.GetVideoMbxNumber( aTelNumber );
*/
    return 0;
// <-- QT PHONE END -->
    }
    
// End of File