phonebookengines/contactsmodel/cntsrv/src/CViewSubSessions.cpp
changeset 24 0ba2181d7c28
parent 0 e686773b3f54
--- a/phonebookengines/contactsmodel/cntsrv/src/CViewSubSessions.cpp	Tue Feb 02 10:12:17 2010 +0200
+++ b/phonebookengines/contactsmodel/cntsrv/src/CViewSubSessions.cpp	Fri Mar 19 09:27:18 2010 +0200
@@ -1,17 +1,20 @@
-// Copyright (c) 2005-2009 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:
-//
+/*
+* Copyright (c) 2005-2009 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: 
+*
+*/
+
 
 /**
  @file
@@ -21,13 +24,13 @@
 
 
 #include "cntviewprivate.h"
-#include "CViewSubSessions.h"
-#include "CCntIpcCodes.h"
-#include "CCntDbManager.h"
-#include "CCntServer.h"
+#include "cviewsubsessions.h"
+#include "ccntipccodes.h"
+#include "ccntdbmanager.h"
+#include "ccntserver.h"
 #include <cntviewstore.h>
-#include "CCntLogger.h"
-#include "CCntStateMachine.h"
+#include "ccntlogger.h"
+#include "ccntstatemachine.h"
 
 
 extern void DebugLogViewNotification(const TDesC& aMethod, const TContactViewEvent& aEvent);
@@ -127,10 +130,7 @@
 						if(iEvents[pos].iInt >= aEvent.iInt && 
 								iEvents[pos].iContactId != aEvent.iContactId)
 							{
-							if( iEvents[pos].iEventType == TContactViewEvent::EItemRemoved || iEvents[pos].iEventType == TContactViewEvent::EItemAdded)  
-								{
-								iEvents[pos].iInt++;
-								}
+							iEvents[pos].iInt++;
 							}
 						}
 					iQueueError = iEvents.Insert(aEvent, lastItemRemovedPosition);		
@@ -153,10 +153,7 @@
 							eventsCount=iEvents.Count();
 							for(TUint loop=pos+1; loop<eventsCount; ++loop)
 								{
-								if( iEvents[pos].iEventType == TContactViewEvent::EItemRemoved || iEvents[pos].iEventType == TContactViewEvent::EItemAdded)
-									{
-									iEvents[loop].iInt++;
-									}
+								iEvents[loop].iInt++;
 								}						
 							haveToAppendEvent = EFalse;										
 							break;
@@ -171,7 +168,52 @@
 			}
 		else 
 			{
-			iQueueError = iEvents.Append(event);	
+			if(event.iEventType == TContactViewEvent::EItemRemoved)
+				{
+				TBool anyEventWithSameInt = EFalse;												
+				for( pos=0; pos<eventsCount; ++pos ) 
+					{
+					if(iEvents[pos].iEventType == TContactViewEvent::EItemAdded)
+						{								
+						if(iEvents[pos].iInt == event.iInt)
+							{
+							iEvents.Remove(pos);
+							eventsCount=iEvents.Count();
+							for(TUint loop=pos; loop<eventsCount; ++loop)
+								{
+								iEvents[loop].iInt--;
+								}						
+							anyEventWithSameInt=ETrue;	
+							break;									
+							}					
+						}
+					}						
+				pos=0;	
+				if(!anyEventWithSameInt) 
+					{
+					while(pos < eventsCount && iEvents[pos].iInt <= event.iInt)
+						{
+						pos++;
+						}
+					if(pos!=eventsCount)
+						{	
+						iQueueError = iEvents.Insert(event, pos);
+						eventsCount=iEvents.Count();
+						for(TUint loop=pos+1; loop<eventsCount; ++loop)
+							{
+							iEvents[loop].iInt--;
+							}	
+						}
+					else
+						{
+						iQueueError = iEvents.Append(event);
+						}
+					}
+				}
+			else
+				{
+				iQueueError = iEvents.Append(event);	
+				}
 			}
 		DEBUG_PRINTVN2(__VERBOSE_DEBUG__,_L("[CNTMODEL] CViewSubSessionQueue::QueueEvent(): ->Q:"), event);
 		}