phonebookengines_old/contactsmodel/src/CNTITER.CPP
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <cntdb.h>
       
    17 
       
    18 EXPORT_C TContactIter::TContactIter(CContactDatabase &aDatabase) : iDatabase(aDatabase)
       
    19 /** Constructs the object with a contact database.
       
    20 
       
    21 @param aDatabase The contact database over which to iterate. */
       
    22 	{
       
    23 	Reset();
       
    24 	}
       
    25 
       
    26 EXPORT_C void TContactIter::Reset()
       
    27 /** Resets the iterator to its initialised state, so that a subsequent call to 
       
    28 NextL() goes to the first item. */
       
    29 	{
       
    30 	iCursorId=KNullContactId;
       
    31 	}
       
    32 
       
    33 EXPORT_C TContactItemId TContactIter::FirstL()
       
    34 /** Moves to the first contact item in the database.
       
    35 
       
    36 @return The ID of the first contact item. */
       
    37 	{
       
    38 	if (iDatabase.SortedItemsL()->Count()==0)
       
    39 		iCursorId=KNullContactId;
       
    40 	else
       
    41 		GotoIndexL(0);
       
    42 	return iCursorId;
       
    43 	}
       
    44 
       
    45 EXPORT_C TContactItemId TContactIter::NextL()
       
    46 /** Moves to the next contact item in the database. 
       
    47 
       
    48 On a newly initialised TContactIter, this function moves to the first item.
       
    49 
       
    50 @return The ID of the next contact item. Has a value of KNullContactId if 
       
    51 there are no more items. */
       
    52 	{
       
    53 	TInt pos=0;
       
    54 	if (iCursorId!=KNullContactId)
       
    55 		pos=iDatabase.ContactPosL(iCursorId)+1;
       
    56 	if (pos==iDatabase.SortedItemsL()->Count())
       
    57 		iCursorId=KNullContactId;
       
    58 	else
       
    59 		GotoIndexL(pos);
       
    60 	return iCursorId;
       
    61 	}
       
    62 
       
    63 EXPORT_C TContactItemId TContactIter::PreviousL()
       
    64 /** Moves to the previous contact item in the database.
       
    65 
       
    66 Note: you must not call this function on a newly initialised database, otherwise 
       
    67 the function raises a panic.
       
    68 
       
    69 @return The ID of the previous contact item. Has a value of KNullContactId 
       
    70 if there is no previous item. */
       
    71 	{
       
    72 	TInt pos=iDatabase.ContactPosL(iCursorId);
       
    73 	if (pos==0)
       
    74 		return KNullContactId;
       
    75 	GotoIndexL(--pos);
       
    76 	return iCursorId;
       
    77 	}
       
    78 
       
    79 EXPORT_C TContactItemId TContactIter::LastL()
       
    80 /** Moves to the last contact item in the database.
       
    81 
       
    82 @return The ID of the last contact item. */
       
    83 	{
       
    84 	GotoIndexL(iDatabase.SortedItemsL()->Count()-1);
       
    85 	return iCursorId;
       
    86 	}
       
    87 
       
    88 EXPORT_C void TContactIter::GotoL(TContactItemId aContactId)
       
    89 /** Moves to the specified contact item.
       
    90 
       
    91 @param aContactId A contact item ID. Must not have a value of KNullContactId, 
       
    92 or the function raises a panic. */
       
    93 	{
       
    94 	User::LeaveIfError(iDatabase.DoGotoL(aContactId));
       
    95 	iCursorId=aContactId;
       
    96 	}
       
    97 
       
    98 void TContactIter::GotoIndexL(TInt aPos)
       
    99 	{
       
   100 	GotoL((*iDatabase.SortedItemsL())[aPos]);
       
   101 	}