pimappservices/calendar/client/src/caliteratorimpl.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2005-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 "caliteratorimpl.h"
       
    17 
       
    18 #include "calclient.h"
       
    19 #include "agmentry.h"
       
    20 #include "calsessionimpl.h"
       
    21 
       
    22 CCalIteratorImpl::CCalIteratorImpl(CCalSessionImpl& aSessionImpl)
       
    23 	:iCalSessionImpl(aSessionImpl), iServer(aSessionImpl.Server())
       
    24 	{
       
    25 	iCalSessionImpl.IncrementReferenceCount();
       
    26 	}
       
    27 
       
    28 CCalIteratorImpl::~CCalIteratorImpl()
       
    29 	{
       
    30 	iCalSessionImpl.DecrementReferenceCount();
       
    31 	delete iGuid;
       
    32 	}
       
    33 
       
    34 const TDesC8& CCalIteratorImpl::FirstL()
       
    35 	{
       
    36 	if (iServer.CreateEntryIteratorL(iCalSessionImpl.FileId()))
       
    37 		{
       
    38 		iFileEntry = ETrue; //file contains an entry
       
    39 		FindUidL();
       
    40 		if(iGuid)
       
    41 			{
       
    42 			return *iGuid;
       
    43 			}
       
    44 		else
       
    45 			{
       
    46 			NextL();
       
    47 			}
       
    48 		__ASSERT_ALWAYS(iGuid, User::Leave(KErrCorrupt));// At least there should be one entry which holds the guid
       
    49 		return *iGuid;
       
    50 		}
       
    51 	else
       
    52 		{//There is no entries - the file is empty -
       
    53 		iFileEntry = EFalse;
       
    54 		return KNullDesC8();
       
    55 		} 
       
    56 	}
       
    57 /** 
       
    58 Moves the entry iterator to the next entry which is a parent (parent and its children have the same Uid) and retrive its Uid. . 
       
    59 
       
    60 @capability None
       
    61 @return a descriptor which contains the Uid of the current entry. The return value can be a KNullDesC8 if there is no more parent entry in the file. 
       
    62 */
       
    63 const TDesC8& CCalIteratorImpl::NextL()
       
    64 	{
       
    65 	if (!iFileEntry)
       
    66 		{
       
    67 		User::Leave(KErrCorrupt);
       
    68 		}
       
    69 		
       
    70 	TBool available = iServer.EntryIteratorNextL(iCalSessionImpl.FileId());
       
    71 	while (available)
       
    72 		{
       
    73 		FindUidL();
       
    74 		if(iGuid)
       
    75 			{
       
    76 			return *iGuid;
       
    77 			}
       
    78 		
       
    79 		available = iServer.EntryIteratorNextL(iCalSessionImpl.FileId());
       
    80 		}
       
    81 	return KNullDesC8();
       
    82 	}
       
    83 
       
    84 
       
    85 void CCalIteratorImpl::FindUidL()
       
    86 	{/*
       
    87 	 Update the iGuid which hols the guid of the current entry.
       
    88 	 
       
    89 	 The descriptor HBufC* iGid may be one of the following values:
       
    90 
       
    91 	 1. Contains the guid of a GS parent entry.
       
    92 	 2. Null if it is a GS child entry
       
    93 	 3. Unique id (converted into descriptor) if it is not a GS entry.
       
    94 	 */
       
    95 	delete iGuid;
       
    96 	iGuid = NULL;
       
    97 
       
    98 	CAgnEntry* entry = iServer.FetchEntryByIteratorL(iCalSessionImpl.FileId());
       
    99 	
       
   100 	// sanity check: if NULL something went wrong with the indexes
       
   101 	
       
   102 	__ASSERT_ALWAYS(entry, User::Leave(KErrGeneral));
       
   103 
       
   104 	CleanupStack::PushL(entry);
       
   105 	 
       
   106 	if(entry->GsDataType()==CGsData::EParent)
       
   107 		{
       
   108 		iGuid = entry->Guid().AllocL();
       
   109 		}
       
   110 
       
   111 	CleanupStack::PopAndDestroy(entry);
       
   112 	}
       
   113