phonebookui/Phonebook2/UIControls/src/CPbk2ContactViewIterator.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 09:41:07 +0300
branchRCL_3
changeset 58 d4f567ce2e7c
parent 0 e686773b3f54
permissions -rw-r--r--
Revision: 201031 Kit: 201033

/*
* Copyright (c) 2005-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:  Phonebook 2 contact link iterator.
*
*/


#include "CPbk2ContactViewIterator.h"

// Virtual Phonebook
#include <MVPbkContactViewBase.h>
#include <MVPbkViewContact.h>

/// Unnamed namespace for local definitions
namespace {
    const TInt KAtFirstElement( 0 );

} /// namespace
   
// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::CPbk2ContactViewIterator
// --------------------------------------------------------------------------
//    
inline CPbk2ContactViewIterator::CPbk2ContactViewIterator
        ( MVPbkContactViewBase& aView, TArray<TInt> aSelectedIndexes )  :
            iView( aView ), 
            iSelectedIndexes( aSelectedIndexes ), 
            iCursor( KAtFirstElement )
    {
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::~CPbk2ContactViewIterator
// --------------------------------------------------------------------------
//     
CPbk2ContactViewIterator::~CPbk2ContactViewIterator()    
    {
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::NewLC
// --------------------------------------------------------------------------
//     
CPbk2ContactViewIterator* CPbk2ContactViewIterator::NewLC
        ( MVPbkContactViewBase& aView,
          TArray<TInt> aSelectedIndexes )
    {
    CPbk2ContactViewIterator* self = 
        new (ELeave) CPbk2ContactViewIterator( aView, aSelectedIndexes );
    CleanupStack::PushL( self );
    return self;
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::HasNext
// --------------------------------------------------------------------------
//     
TBool CPbk2ContactViewIterator::HasNext() const
    {
    TBool ret = EFalse;

    if ( iCursor < iSelectedIndexes.Count() )
        {
        ret = ETrue;
        }

    return ret;
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::HasPrevious
// --------------------------------------------------------------------------
//     
TBool CPbk2ContactViewIterator::HasPrevious() const
    {
    TBool ret = EFalse;
    if ( iCursor > KAtFirstElement )
        {
        ret = ETrue;
        }

    return ret;
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::NextL
// --------------------------------------------------------------------------
// 
MVPbkContactLink* CPbk2ContactViewIterator::NextL()
    {
    MVPbkContactLink* link = NULL;
    if ( HasNext() )
        {
        link = iView.ContactAtL
            ( iSelectedIndexes[ iCursor ] ).CreateLinkLC();
        CleanupStack::Pop(); // link
        ++iCursor;
        }
    return link;
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::PreviousL
// --------------------------------------------------------------------------
//     
MVPbkContactLink* CPbk2ContactViewIterator::PreviousL()
    {
    MVPbkContactLink* link = NULL;
    if ( HasPrevious() )
        {
        --iCursor;
        link = iView.ContactAtL
            ( iSelectedIndexes[ iCursor ] ).CreateLinkLC();
        CleanupStack::Pop(); // link    
        }
    return link;    
    }
    
// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::SetToFirst
// --------------------------------------------------------------------------
//     
void CPbk2ContactViewIterator::SetToFirst()
    {
    iCursor = KAtFirstElement;
    }

// --------------------------------------------------------------------------
// CPbk2ContactViewIterator::SetToLast
// --------------------------------------------------------------------------
//     
void CPbk2ContactViewIterator::SetToLast()
    {
    iCursor = iSelectedIndexes.Count();
    }    
    
// End of File