phoneengine/PhoneCntFinder/ContactService/src/cphcntspeeddialcontactlinkfetch.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 09:54:27 +0300
branchRCL_3
changeset 58 40a3f856b14d
parent 0 5f000ab63145
permissions -rw-r--r--
Revision: 201031 Kit: 201033

/*
* Copyright (c)  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:  Implementation of CPhCntSpeedDialContactL class.
*
*/


#include "cphcntspeeddialcontactlinkfetch.h"
#include "MPhCntContactManager.h"
#include "MVPbkContactLinkArray.h"
#include "MVPbkContactOperationBase.h"



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

// ---------------------------------------------------------------------------
// ?description_if_needed
// ---------------------------------------------------------------------------
//
CPhCntSpeedDialContactLinkFetch::CPhCntSpeedDialContactLinkFetch(
    MPhCntContactManager& aContactManager ) :
    iContactManager( aContactManager )
    {
    }


// ---------------------------------------------------------------------------
// ?description_if_needed
// ---------------------------------------------------------------------------
//
void CPhCntSpeedDialContactLinkFetch::ConstructL()
    {
    CPhCntContactLinkArrayFetch::BaseConstructL();
    }


// ---------------------------------------------------------------------------
// ?description_if_needed
// ---------------------------------------------------------------------------
//
CPhCntSpeedDialContactLinkFetch* CPhCntSpeedDialContactLinkFetch::NewL(
    MPhCntContactManager& aContactManager )
    {
    CPhCntSpeedDialContactLinkFetch* self = 
        CPhCntSpeedDialContactLinkFetch::NewLC( aContactManager );
    CleanupStack::Pop( self );
    return self;
    }


// ---------------------------------------------------------------------------
// ?description_if_needed
// ---------------------------------------------------------------------------
//
CPhCntSpeedDialContactLinkFetch* CPhCntSpeedDialContactLinkFetch::NewLC(
    MPhCntContactManager& aContactManager )
    {
    CPhCntSpeedDialContactLinkFetch* self = 
        new( ELeave ) CPhCntSpeedDialContactLinkFetch( aContactManager );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }


// ---------------------------------------------------------------------------
// ?description_if_needed
// ---------------------------------------------------------------------------
//
CPhCntSpeedDialContactLinkFetch::~CPhCntSpeedDialContactLinkFetch()
    {
    }

// ---------------------------------------------------------------------------
// ?implementation_description
// ---------------------------------------------------------------------------
//
const MVPbkContactLink& CPhCntSpeedDialContactLinkFetch::FetchSpeedDialLinkL( 
    TInt aSpeedDialPosition )
    {
    iSpeedDialPosition = aSpeedDialPosition;
    TInt error( MakeAsyncRequest() );
    
    delete iOperation; 
    iOperation = NULL;
    
    const MVPbkContactLink* contactLink = NULL;
    if( !error ) 
        {
        if( iFetchedContactLinks && iFetchedContactLinks->Count() == 1 )
            {
            contactLink = &iFetchedContactLinks->At( 0 );
            }
        else
            {
            delete iFetchedContactLinks;
            iFetchedContactLinks = NULL;
            error = KErrNotFound;
            }
        }
    User::LeaveIfError( error );
    
    return *contactLink;
    }

// ---------------------------------------------------------------------------
// From CPhCntAsyncToSync
// ?implementation_description
// ---------------------------------------------------------------------------
//
void CPhCntSpeedDialContactLinkFetch::DoMakeAsyncRequestL()
    {
    if( !IsActive() )
        {
        iOperation = iContactManager.RetrieveSpeedDialContactLinkL( 
            iSpeedDialPosition, *this );
        }
    else
        {
        User::Leave( KErrInUse );
        }
    }