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