meetingrequest/mrservices/src/cesmrconflictchecker.cpp
branchRCL_3
changeset 80 726fba06891a
parent 64 3533d4323edc
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 *  Description : ESMR conflict checker implementation
    14 *  Description : ESMR conflict checker implementation
    15 *  Version     : %version: e002sa33#9 %
    15 *  Version     : %version: e002sa33#10.1.2 %
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include "emailtrace.h"
    19 #include "emailtrace.h"
    20 #include "cesmrconflictchecker.h"
    20 #include "cesmrconflictchecker.h"
    21 #include "cesmrcaldbmgr.h"
    21 #include "cesmrcaldbmgr.h"
    22 #include "esmrhelper.h"
    22 #include "esmrhelper.h"
    23 #include "esmrentryhelper.h"
    23 #include "esmrentryhelper.h"
    24 #include "esmrinternaluid.h"
    24 #include "esmrinternaluid.h"
       
    25 #include "cesmrcaluserutil.h"
    25 
    26 
    26 #include <calcommon.h>
    27 #include <calcommon.h>
    27 #include <calinstance.h>
    28 #include <calinstance.h>
    28 #include <calentryview.h>
    29 #include <calentryview.h>
    29 #include <calinstanceview.h>
    30 #include <calinstanceview.h>
    94         TTime aEnd,
    95         TTime aEnd,
    95         CCalInstanceView* aInstanceView )
    96         CCalInstanceView* aInstanceView )
    96     {
    97     {
    97     FUNC_LOG;
    98     FUNC_LOG;
    98     const CalCommon::TCalViewFilter instanceFilter =
    99     const CalCommon::TCalViewFilter instanceFilter =
    99             CalCommon::EIncludeAppts;
   100             CalCommon::EIncludeAppts | CalCommon::EIncludeEvents;
   100 
   101 
   101     TDateTime start = aStart.DateTime();
   102     TDateTime start = aStart.DateTime();
   102     TDateTime end   = aEnd.DateTime();
   103     TDateTime end   = aEnd.DateTime();
   103 
   104 
   104     start.SetHour( KZero );
   105     start.SetHour( KZero );
   293                                     aEntry.EndTimeL().TimeUtcL(),
   294                                     aEntry.EndTimeL().TimeUtcL(),
   294                                     allCalenInstanceView[i] );
   295                                     allCalenInstanceView[i] );
   295 
   296 
   296         allCalenInstanceView[i]->FindInstanceL(
   297         allCalenInstanceView[i]->FindInstanceL(
   297                 aInstances,
   298                 aInstances,
   298                 CalCommon::EIncludeAppts,
   299                 CalCommon::EIncludeAppts |
       
   300                 CalCommon::EIncludeEvents ,
   299                 timeRange );
   301                 timeRange );
   300         }
   302         }
   301 
   303 
   302     RemoveAndDeleteNonConflictingInstancesL(
   304     RemoveAndDeleteNonConflictingInstancesL(
   303             aInstances,
   305             aInstances,
   365             if ( tmpInstanceArray.Count() )
   367             if ( tmpInstanceArray.Count() )
   366                 {
   368                 {
   367                 MoveInstancesL( tmpInstanceArray, aInstances );
   369                 MoveInstancesL( tmpInstanceArray, aInstances );
   368                 if ( !aFindAllConflicts )
   370                 if ( !aFindAllConflicts )
   369                     {
   371                     {
   370                     break;
   372                     //break;
   371                     }
   373                     }
   372                 }
   374                 }
   373             }
   375             }
   374         }
   376         }
   375     else if ( rRule.Until().TimeUtcL() != Time::NullTTime() )
   377     else if ( rRule.Until().TimeUtcL() != Time::NullTTime() )
   397             if ( tmpInstanceArray.Count() )
   399             if ( tmpInstanceArray.Count() )
   398                 {
   400                 {
   399                 MoveInstancesL( tmpInstanceArray, aInstances );
   401                 MoveInstancesL( tmpInstanceArray, aInstances );
   400                 if ( !aFindAllConflicts )
   402                 if ( !aFindAllConflicts )
   401                     {
   403                     {
   402                     break;
   404                     //break;
   403                     }
   405                     }
   404                 }
   406                 }
   405 
   407 
   406             // Move to next occurence
   408             // Move to next occurence
   407             start += interval;
   409             start += interval;
   477                     if ( tmpInstanceArray.Count() )
   479                     if ( tmpInstanceArray.Count() )
   478                         {
   480                         {
   479                         MoveInstancesL( tmpInstanceArray, aInstances );
   481                         MoveInstancesL( tmpInstanceArray, aInstances );
   480                         if ( !aFindAllConflicts )
   482                         if ( !aFindAllConflicts )
   481                             {
   483                             {
   482                             break;
   484                             //break;
   483                             }
   485                             }
   484                         }
   486                         }
   485                     }
   487                     }
   486                 }
   488                 }
   487 
   489 
   521                     if ( tmpInstanceArray.Count() )
   523                     if ( tmpInstanceArray.Count() )
   522                         {
   524                         {
   523                         MoveInstancesL( tmpInstanceArray, aInstances );
   525                         MoveInstancesL( tmpInstanceArray, aInstances );
   524                         if ( !aFindAllConflicts )
   526                         if ( !aFindAllConflicts )
   525                             {
   527                             {
   526                             break;
   528                            // break;
   527                             }
   529                             }
   528                         }
   530                         }
   529                     }
   531                     }
   530                 }
   532                 }
   531 
   533 
   543     CleanupStack::PopAndDestroy( &days );
   545     CleanupStack::PopAndDestroy( &days );
   544     CleanupStack::PopAndDestroy( &tmpInstanceArray );
   546     CleanupStack::PopAndDestroy( &tmpInstanceArray );
   545     }
   547     }
   546 
   548 
   547 /**
   549 /**
       
   550  * Judge is one CCalEntry is a all day event
       
   551  * @param aEntry the entry be checked
       
   552  * @return ETure if it is a all day event
       
   553  */
       
   554 TBool IsAllDayEventL( const CCalEntry& aEntry )
       
   555     {
       
   556     FUNC_LOG;
       
   557     // for judge all day event
       
   558     CCalEntry* tmpEntry = ESMRHelper::CopyEntryLC(
       
   559 						aEntry,
       
   560 						aEntry.MethodL(),
       
   561                         ESMRHelper::ECopyFull );
       
   562     
       
   563     CESMRCalUserUtil* entryUtil = CESMRCalUserUtil::NewLC( *tmpEntry );
       
   564     TBool allDayEvent( entryUtil->IsAlldayEventL() );
       
   565     CleanupStack::PopAndDestroy( entryUtil );
       
   566     CleanupStack::PopAndDestroy( tmpEntry );
       
   567     
       
   568     return allDayEvent;
       
   569     }
       
   570 /**
       
   571  * Get the first visible instance from the iterater.
       
   572  * @param aIterater the handler of the iterater.
       
   573  * @return the first instance
       
   574  */
       
   575 CCalInstance* FirstInstanceL ( CCalInstanceIterator* aIterater)
       
   576 	{
       
   577 	FUNC_LOG;
       
   578 	CCalInstance* previous = aIterater->PreviousL();
       
   579 	while( previous )
       
   580 		{
       
   581 		CleanupStack::PushL( previous );
       
   582 		CleanupStack::PopAndDestroy( previous );
       
   583 		previous = aIterater->PreviousL();
       
   584 		}
       
   585 	
       
   586 	CCalInstance* next = aIterater->NextL();
       
   587 	CleanupStack::PushL( next );
       
   588 	CleanupStack::PopAndDestroy( next );
       
   589 	previous = aIterater->PreviousL();
       
   590 	return previous;
       
   591 	}
       
   592 
       
   593 /**
   548  * Finds conflict for recurrent entry
   594  * Finds conflict for recurrent entry
   549  */
   595  */
   550 void FindConflictsForRepeatingMeetingL(
   596 void FindConflictsForRepeatingMeetingL(
   551         const CCalEntry& aEntry,
   597         const CCalEntry& aEntry,
   552         RPointerArray< CCalInstance >& aInstances,
   598         RPointerArray< CCalInstance >& aInstances,
   560     if ( instance ) // Instance is stored
   606     if ( instance ) // Instance is stored
   561         {
   607         {
   562         CleanupStack::PushL( instance );
   608         CleanupStack::PushL( instance );
   563         RCPointerArray< CCalInstance > tmpInstanceArray;
   609         RCPointerArray< CCalInstance > tmpInstanceArray;
   564         CleanupClosePushL( tmpInstanceArray );
   610         CleanupClosePushL( tmpInstanceArray );
   565 
       
   566         CCalEntry& parent = instance->Entry();
   611         CCalEntry& parent = instance->Entry();
   567         CCalInstanceView* instanceView = aDb.InstanceViewL( parent );
   612         CCalInstanceView* instanceView = aDb.InstanceViewL( aEntry );
       
   613 
       
   614         // create the iterator for instances by current entry
   568         CCalInstanceIterator* iterator = instanceView->FindInstanceByUidL(
   615         CCalInstanceIterator* iterator = instanceView->FindInstanceByUidL(
   569                         parent.UidL(),
   616         		aEntry.UidL(),
   570                         parent.StartTimeL() );
   617         		aEntry.StartTimeL() );
       
   618         
   571         CleanupStack::PushL( iterator );
   619         CleanupStack::PushL( iterator );
   572         CCalEntry* entry = ESMRHelper::CopyEntryLC(
   620         CCalEntry* entry = ESMRHelper::CopyEntryLC(
   573                             parent,
   621                             parent,
   574                             parent.MethodL(),
   622                             parent.MethodL(),
   575                             ESMRHelper::ECopyFull );
   623                             ESMRHelper::ECopyFull );
   576 
   624         // For CCalInstanceIterator class don't have any function on how to get current instance, 
   577         while ( iterator->HasMore() )
   625         // handle the special situation for it.
   578             {
   626         if( iterator ->Count() == 1 )
   579             CCalInstance* next = iterator->NextL();
   627         	{
   580             CleanupStack::PushL( next );
   628 			entry->SetStartAndEndTimeL( aEntry.StartTimeL(), aEntry.EndTimeL() );
   581             entry->SetStartAndEndTimeL( next->StartTimeL(), next->EndTimeL() );
   629 			
   582             CleanupStack::PopAndDestroy( next );
   630 			FindConflictsForEntryL( *entry,
   583             FindConflictsForEntryL( *entry,
   631 									tmpInstanceArray,
   584                                     tmpInstanceArray,
   632 									aDb );
   585                                     aDb );
   633 			
   586 
   634 			if ( tmpInstanceArray.Count() )
   587             if ( tmpInstanceArray.Count() )
   635 				{
   588                 {
   636 			    MoveInstancesL( tmpInstanceArray, aInstances );
   589                 MoveInstancesL( tmpInstanceArray, aInstances );
   637 				}
   590 
   638         	}
   591                 if ( !aFindAllConflicts )
   639         else
   592                     {
   640         	{
   593                     break;
   641 			 // For CCalInstanceIterator class don't have any function on how to get current instance,
   594                     }
   642 			 // handle the first instance action when find conflict.
   595                 }
   643 			 CCalInstance* previous = FirstInstanceL( iterator );
   596             }
   644 			 CleanupStack::PushL( previous );
       
   645 			 entry->SetStartAndEndTimeL( previous->StartTimeL(), previous->EndTimeL() );
       
   646 			 CleanupStack::PopAndDestroy( previous );
       
   647 			 FindConflictsForEntryL( *entry, tmpInstanceArray, aDb );
       
   648 			 
       
   649 			 if ( tmpInstanceArray.Count() )
       
   650 				{
       
   651 				MoveInstancesL( tmpInstanceArray, aInstances );
       
   652 				}
       
   653 			 // does the normal find conflict action. From the second to the end.
       
   654 			 while ( iterator->HasMore() )
       
   655 				{
       
   656 				CCalInstance* next = iterator->NextL();
       
   657 				CleanupStack::PushL( next );
       
   658 				entry->SetStartAndEndTimeL( next->StartTimeL(), next->EndTimeL() );
       
   659 	
       
   660 				CleanupStack::PopAndDestroy( next );
       
   661 	
       
   662 				FindConflictsForEntryL( *entry,
       
   663 										tmpInstanceArray,
       
   664 										aDb );
       
   665 	
       
   666 				if ( tmpInstanceArray.Count() )
       
   667 					{
       
   668 					MoveInstancesL( tmpInstanceArray, aInstances );
       
   669 					}
       
   670 				}
       
   671         	}
   597 
   672 
   598         CleanupStack::PopAndDestroy( entry );
   673         CleanupStack::PopAndDestroy( entry );
   599 
   674 
   600         CleanupStack::PopAndDestroy( iterator );
   675         CleanupStack::PopAndDestroy( iterator );
   601 
   676