agendainterface/agendautil/src/agendautil_p.cpp
changeset 49 5de72ea7a065
parent 37 360d55486d7f
child 50 579cc610882e
equal deleted inserted replaced
37:360d55486d7f 49:5de72ea7a065
    18 // System includes
    18 // System includes
    19 #include <hbextendedlocale.h>
    19 #include <hbextendedlocale.h>
    20 #include <calsession.h>
    20 #include <calsession.h>
    21 #include <calinstance.h>
    21 #include <calinstance.h>
    22 #include <CalenImporter>
    22 #include <CalenImporter>
       
    23 #include <CalenInterimUtils2>
    23 #include <calentry.h>
    24 #include <calentry.h>
    24 #include <calrrule.h>
    25 #include <calrrule.h>
    25 #include <e32math.h>
    26 #include <e32math.h>
    26 #include <caluser.h>
    27 #include <caluser.h>
    27 #include <caldataexchange.h>
    28 #include <caldataexchange.h>
    32 
    33 
    33 // User includes
    34 // User includes
    34 #include "agendautil_p.h"
    35 #include "agendautil_p.h"
    35 #include "agendaentry.h"
    36 #include "agendaentry.h"
    36 #include "agendaentry_p.h"
    37 #include "agendaentry_p.h"
       
    38 #include "CleanupResetAndDestroy.h"
    37 
    39 
    38 // Constants
    40 // Constants
    39 //recognition string for ical
    41 //recognition string for ical
    40 _LIT8(KVersionICal,		"VERSION:2.0");
    42 _LIT8(KVersionICal,		"VERSION:2.0");
    41 //recognition string for vcal
    43 //recognition string for vcal
   132 }
   134 }
   133 
   135 
   134 void AgendaUtilPrivate::Completed(TInt aError)
   136 void AgendaUtilPrivate::Completed(TInt aError)
   135 {
   137 {
   136 	iError = aError;
   138 	iError = aError;
       
   139 	static bool isInstanceViewDeleted = false;
       
   140 	static bool isEntryViewDeleted = false;
   137 
   141 
   138 	if (mIsDeleting) {
   142 	if (mIsDeleting) {
   139 		// If deletion was in progress, then it is completed now
   143 		// If deletion was in progress, then it is completed now
   140 		// emit the signal to the clients.
   144 		// emit the signal to the clients.
   141 		mIsDeleting = false;
   145 		mIsDeleting = false;
   142 		emit q->entriesDeleted(iError);
   146 		emit q->entriesDeleted(iError);
   143 	}
   147 	}
   144 
   148 
   145 	if (KErrNone != iError) {
   149 	if (KErrNone != iError) {
   146 		// Something has gone wrong, return
   150 		// Something has gone wrong, return
   147 		if (iCalEntryView) {
   151 		if (iCalEntryView && !isEntryViewDeleted) {
       
   152 		isEntryViewDeleted = true;
   148 		delete iCalEntryView;
   153 		delete iCalEntryView;
   149 		iCalEntryView = NULL;
   154 		iCalEntryView = NULL;
   150 		}
   155 		}
   151 		if (iCalInstanceView) {
   156 		if (iCalInstanceView && !isInstanceViewDeleted) {
       
   157 		isInstanceViewDeleted = true;
   152 		delete iCalInstanceView;
   158 		delete iCalInstanceView;
   153 		iCalInstanceView = NULL;
   159 		iCalInstanceView = NULL;
   154 		}
   160 		}
   155 		return;
   161 		return;
   156 	}
   162 	}
   204 	if (AgendaEntry::TypeNote == entry.type()) {
   210 	if (AgendaEntry::TypeNote == entry.type()) {
   205 		TRAP(
   211 		TRAP(
   206 				iError,
   212 				iError,
   207 
   213 
   208 				RPointerArray<CCalEntry> entryArray;
   214 				RPointerArray<CCalEntry> entryArray;
   209 				CleanupClosePushL(entryArray);
   215                 CleanupResetAndDestroyPushL(entryArray);
   210 
   216 
   211 				// Get the global uid.
   217 				// Get the global uid.
   212 				TTime homeTime;
   218 				CCalenInterimUtils2* calenInterimUtils2 = CCalenInterimUtils2::NewL();
   213 				homeTime.HomeTime();
   219 				HBufC8* globalUid = calenInterimUtils2->GlobalUidL();
   214 				TInt64 seed = homeTime.Int64();
   220 				CleanupStack::PushL(globalUid);
   215 				TInt randumNumber = Math::Rand(seed);
   221 				delete calenInterimUtils2;
   216 				HBufC8* globalUid = HBufC8::NewLC(KGuidLength);
       
   217 				globalUid->Des().Num(randumNumber);
       
   218 
   222 
   219 				// Construct a CCalEntry object and start filling the details.
   223 				// Construct a CCalEntry object and start filling the details.
   220 				CCalEntry* newEntry = 0;
   224 				CCalEntry* newEntry = 0;
   221 				newEntry = CCalEntry::NewL(
   225 				newEntry = CCalEntry::NewL(
   222 						static_cast<CCalEntry::TType>(entry.type()),
   226 						static_cast<CCalEntry::TType>(entry.type()),
   223 						globalUid,
   227 						globalUid,
   224 						static_cast<CCalEntry::TMethod>(entry.method()),
   228 						static_cast<CCalEntry::TMethod>(entry.method()),
   225 						0);
   229 						0);
   226 
   230 
   227 				CleanupStack::Pop(globalUid);
   231 				CleanupStack::Pop(globalUid);
   228 				CleanupStack::PushL(newEntry);
       
   229 
   232 
   230 				// Add description.
   233 				// Add description.
   231 				TPtrC description(reinterpret_cast<const TUint16*>(
   234 				TPtrC description(reinterpret_cast<const TUint16*>(
   232 						entry.description().utf16()));
   235 						entry.description().utf16()));
   233 				newEntry->SetDescriptionL(description);
   236 				newEntry->SetDescriptionL(description);
   263 				entryArray.AppendL(newEntry);
   266 				entryArray.AppendL(newEntry);
   264 				iCalEntryView->StoreL(entryArray, success);
   267 				iCalEntryView->StoreL(entryArray, success);
   265 				localUid = newEntry->LocalUidL();
   268 				localUid = newEntry->LocalUidL();
   266 
   269 
   267 				// Cleanup.
   270 				// Cleanup.
   268 				CleanupStack::PopAndDestroy(newEntry);
       
   269 				CleanupStack::PopAndDestroy(&entryArray);
   271 				CleanupStack::PopAndDestroy(&entryArray);
   270 		)
   272 		)
   271 	} else {
   273 	} else {
   272 		TRAP(
   274 		TRAP(
   273 				iError,
   275 				iError,
   274 
   276 
   275 				RPointerArray<CCalEntry> entryArray;
   277 				RPointerArray<CCalEntry> entryArray;
   276 				CleanupClosePushL(entryArray);
   278                 CleanupResetAndDestroyPushL(entryArray);
   277 
   279 
   278 				// Get the global uid.
   280 				// Get the global uid.
   279 				TTime homeTime;
   281 				TTime homeTime;
   280 				homeTime.HomeTime();
   282 				homeTime.HomeTime();
   281 				TInt64 seed = homeTime.Int64();
   283 				TInt64 seed = homeTime.Int64();
   290 						globalUid,
   292 						globalUid,
   291 						static_cast<CCalEntry::TMethod>(entry.method()),
   293 						static_cast<CCalEntry::TMethod>(entry.method()),
   292 						0);
   294 						0);
   293 
   295 
   294 				CleanupStack::Pop(globalUid);
   296 				CleanupStack::Pop(globalUid);
   295 				CleanupStack::PushL(newEntry);
       
   296 
   297 
   297 				// Add the summary.
   298 				// Add the summary.
   298 				if (!entry.summary().isNull()) {
   299 				if (!entry.summary().isNull()) {
   299 					TPtrC summary(reinterpret_cast<const TUint16*>(
   300 					TPtrC summary(reinterpret_cast<const TUint16*>(
   300 							entry.summary().utf16()));
   301 							entry.summary().utf16()));
   389 				entryArray.AppendL(newEntry);
   390 				entryArray.AppendL(newEntry);
   390 				iCalEntryView->StoreL(entryArray, success);
   391 				iCalEntryView->StoreL(entryArray, success);
   391 				localUid = newEntry->LocalUidL();
   392 				localUid = newEntry->LocalUidL();
   392 
   393 
   393 				// Cleanup.
   394 				// Cleanup.
   394 				CleanupStack::PopAndDestroy(newEntry);
       
   395 				CleanupStack::PopAndDestroy(&entryArray);
   395 				CleanupStack::PopAndDestroy(&entryArray);
   396 		)
   396 		)
   397 	}
   397 	}
   398 	// Emit signal upon successful creation of entry.
   398 	// Emit signal upon successful creation of entry.
   399 	if (0 < localUid && 1 == success) {
   399 	if (0 < localUid && 1 == success) {
   456 	if (AgendaEntry::TypeNote == type) {
   456 	if (AgendaEntry::TypeNote == type) {
   457 		TRAP(
   457 		TRAP(
   458 				iError,
   458 				iError,
   459 
   459 
   460 				RPointerArray<CCalEntry> entryArray;
   460 				RPointerArray<CCalEntry> entryArray;
   461 				CleanupClosePushL(entryArray);
   461                 CleanupResetAndDestroyPushL(entryArray);
   462 
   462 
   463 				// Construct a CCalEntry object and start filling the details.
   463 				// Construct a CCalEntry object and start filling the details.
   464 				CCalEntry* newEntry = 0;
   464 				CCalEntry* newEntry = 0;
   465 				newEntry = CCalEntry::NewL(
   465 				newEntry = CCalEntry::NewL(
   466 						static_cast<CCalEntry::TType>(type),
   466 						static_cast<CCalEntry::TType>(type),
   467 						globalUid,
   467 						globalUid,
   468 						static_cast<CCalEntry::TMethod>(entry.method()),
   468 						static_cast<CCalEntry::TMethod>(entry.method()),
   469 						0);
   469 						0);
   470 				CleanupStack::PushL(newEntry);
       
   471 
   470 
   472 				// Add description.
   471 				// Add description.
   473 				TPtrC description(reinterpret_cast<const TUint16*>(
   472 				TPtrC description(reinterpret_cast<const TUint16*>(
   474 						entry.description().utf16()));
   473 						entry.description().utf16()));
   475 				newEntry->SetDescriptionL(description);
   474 				newEntry->SetDescriptionL(description);
   481 				entryArray.AppendL(newEntry);
   480 				entryArray.AppendL(newEntry);
   482 				iCalEntryView->StoreL(entryArray, success);
   481 				iCalEntryView->StoreL(entryArray, success);
   483 				localUid = newEntry->LocalUidL();
   482 				localUid = newEntry->LocalUidL();
   484 
   483 
   485 				// Cleanup.
   484 				// Cleanup.
   486 				CleanupStack::PopAndDestroy(newEntry);
       
   487 				CleanupStack::PopAndDestroy(&entryArray);
   485 				CleanupStack::PopAndDestroy(&entryArray);
   488 		)
   486 		)
   489 	} else {
   487 	} else {
   490 		TRAP(
   488 		TRAP(
   491 				iError,
   489 				iError,
   492 
   490 
   493 				RPointerArray<CCalEntry> entryArray;
   491 				RPointerArray<CCalEntry> entryArray;
   494 				CleanupClosePushL(entryArray);
   492                 CleanupResetAndDestroyPushL(entryArray);
   495 
   493 
   496 				// Construct a CCalEntry object and start filling the details.
   494 				// Construct a CCalEntry object and start filling the details.
   497 				CCalEntry* newEntry = 0;
   495 				CCalEntry* newEntry = 0;
   498 				newEntry = CCalEntry::NewL(
   496 				newEntry = CCalEntry::NewL(
   499 						static_cast<CCalEntry::TType>(type),
   497 						static_cast<CCalEntry::TType>(type),
   500 						globalUid,
   498 						globalUid,
   501 						static_cast<CCalEntry::TMethod>(entry.method()),
   499 						static_cast<CCalEntry::TMethod>(entry.method()),
   502 						0);
   500 						0);
   503 				CleanupStack::PushL(newEntry);
       
   504 
   501 
   505 				// Add the summary.
   502 				// Add the summary.
   506 				if (!entry.summary().isNull()) {
   503 				if (!entry.summary().isNull()) {
   507 					TPtrC summary(reinterpret_cast<const TUint16*>(
   504 					TPtrC summary(reinterpret_cast<const TUint16*>(
   508 							entry.summary().utf16()));
   505 							entry.summary().utf16()));
   597 				entryArray.AppendL(newEntry);
   594 				entryArray.AppendL(newEntry);
   598 				iCalEntryView->StoreL(entryArray, success);
   595 				iCalEntryView->StoreL(entryArray, success);
   599 				localUid = newEntry->LocalUidL();
   596 				localUid = newEntry->LocalUidL();
   600 
   597 
   601 				// Cleanup.
   598 				// Cleanup.
   602 				CleanupStack::PopAndDestroy(newEntry);
       
   603 				CleanupStack::PopAndDestroy(&entryArray);
   599 				CleanupStack::PopAndDestroy(&entryArray);
   604 		)
   600 		)
   605 	}
   601 	}
   606 	// Emit signal upon successful creation of entry.
   602 	// Emit signal upon successful creation of entry.
   607 	if (0 < localUid && 1 == success) {
   603 	if (0 < localUid && 1 == success) {
   682 
   678 
   683 				// Fetch the entries based on the global uid of the entry, as
   679 				// Fetch the entries based on the global uid of the entry, as
   684 				// the exceptional entries share the global uid with the parent
   680 				// the exceptional entries share the global uid with the parent
   685 				// entry.
   681 				// entry.
   686 				RPointerArray<CCalEntry> entries;
   682 				RPointerArray<CCalEntry> entries;
   687 				CleanupClosePushL(entries);
   683 				CleanupResetAndDestroyPushL(entries);
   688 				iCalEntryView->FetchL(calEntry->UidL(), entries);
   684 				iCalEntryView->FetchL(calEntry->UidL(), entries);
   689 				if (entries.Count()) {
   685 				if (entries.Count()) {
   690 				    iCalEntryView->DeleteL(*entries[0]);
   686 				    iCalEntryView->DeleteL(*entries[0]);
   691 				}
   687 				}
   692 
   688 
   693 				// Cleanup.
       
   694 				int count = entries.Count();
       
   695 				for (int i = count - 1; i >= 0; --i) {
       
   696 					CCalEntry *entry = entries[i];
       
   697 					delete entry;
       
   698 				}
       
   699 				CleanupStack::PopAndDestroy(&entries);
   689 				CleanupStack::PopAndDestroy(&entries);
   700 				CleanupStack::PopAndDestroy();
   690 				CleanupStack::PopAndDestroy();
   701 			}
   691 			}
   702 	)
   692 	)
   703 	
   693 	
   731 				iError,
   721 				iError,
   732 
   722 
   733 				// Get the entry corresponding to the id.
   723 				// Get the entry corresponding to the id.
   734 				AgendaEntry storedEntry = fetchById(entry.id());
   724 				AgendaEntry storedEntry = fetchById(entry.id());
   735 				CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
   725 				CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
   736 				CleanupStack::PushL(calEntry);
       
   737 
   726 
   738 				// Update the description.
   727 				// Update the description.
   739 				if (storedEntry.description() != entry.description()
   728 				if (storedEntry.description() != entry.description()
   740 						&& !entry.description().isNull()) {
   729 						&& !entry.description().isNull()) {
   741 					calEntry->SetDescriptionL(
   730 					calEntry->SetDescriptionL(
   785 					calEntry->SetFavouriteL(entry.favourite());
   774 					calEntry->SetFavouriteL(entry.favourite());
   786 				}
   775 				}
   787 
   776 
   788 				// Update the entry using the CCalEntryView.
   777 				// Update the entry using the CCalEntryView.
   789 				RPointerArray<CCalEntry> entryArray;
   778 				RPointerArray<CCalEntry> entryArray;
   790 				CleanupClosePushL(entryArray);
   779 				CleanupResetAndDestroyPushL(entryArray);
   791 				entryArray.AppendL(calEntry);
   780 				entryArray.AppendL(calEntry);
   792 				iCalEntryView->UpdateL(entryArray, success);
   781 				iCalEntryView->UpdateL(entryArray, success);
   793 
   782 
   794 				// Cleanup.
   783 				// Cleanup.
   795 				CleanupStack::PopAndDestroy(2, calEntry);
   784 				CleanupStack::PopAndDestroy( &entryArray );
   796 		)
   785 		)
   797 	} else {
   786 	} else {
   798 		TRAP(
   787 		TRAP(
   799 				iError,
   788 				iError,
   800 
   789 
   801 				// Get the entry corresponding to the id.
   790 				// Get the entry corresponding to the id.
   802 				AgendaEntry storedEntry = fetchById(entry.id());
   791 				AgendaEntry storedEntry = fetchById(entry.id());
   803 				CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
   792 				CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
   804 				CleanupStack::PushL(calEntry);
       
   805 
   793 
   806 				// Update the attendees.
   794 				// Update the attendees.
   807 				if (!entry.isNull()
   795 				if (!entry.isNull()
   808 						&& (entry.d->m_attendees != storedEntry.attendees())) {
   796 						&& (entry.d->m_attendees != storedEntry.attendees())) {
   809 
   797 
   810 					RPointerArray<CCalAttendee> attendeesArray =
   798 					RPointerArray<CCalAttendee>& attendeesArray =
   811 							calEntry->AttendeesL();
   799 							calEntry->AttendeesL();
   812 					CleanupClosePushL(attendeesArray);
       
   813 					int iterator = 0;
   800 					int iterator = 0;
   814 					while (attendeesArray.Count() > iterator) {
   801 					while (attendeesArray.Count() > iterator) {
   815 						calEntry->DeleteAttendeeL(iterator);
   802 						calEntry->DeleteAttendeeL(iterator);
   816 						iterator++;
   803 						iterator++;
   817 					}
   804 					}
   818 					// Cleanup.
       
   819 					CleanupStack::PopAndDestroy(&attendeesArray);
       
   820 
   805 
   821 					addAttendeesToEntry(entry.d->m_attendees, *calEntry);
   806 					addAttendeesToEntry(entry.d->m_attendees, *calEntry);
   822 				}
   807 				}
   823 
   808 
   824 				// Update the categories.
   809 				// Update the categories.
   825 				if (entry.d->m_categories != storedEntry.categories()) {
   810 				if (entry.d->m_categories != storedEntry.categories()) {
   826 
   811 
   827 					RPointerArray<CCalCategory> categories =
   812 					RPointerArray<CCalCategory> categories =
   828 							calEntry->CategoryListL();
   813 							calEntry->CategoryListL();
   829 					CleanupClosePushL(categories);
       
   830 					int iterator = 0;
   814 					int iterator = 0;
   831 					while (categories.Count() > iterator) {
   815 					while (categories.Count() > iterator) {
   832 						calEntry->DeleteCategoryL(iterator);
   816 						calEntry->DeleteCategoryL(iterator);
   833 						iterator++;
   817 						iterator++;
   834 					}
   818 					}
   835 					// Cleanup.
       
   836 					CleanupStack::PopAndDestroy(&categories);
       
   837 
   819 
   838 					addCategoriesToEntry(entry.d->m_categories, *calEntry);
   820 					addCategoriesToEntry(entry.d->m_categories, *calEntry);
   839 				}
   821 				}
   840 
   822 
   841 				// Update the alarm.
   823 				// Update the alarm.
   940 				}
   922 				}
   941 				calEntry->SetLastModifiedDateL();
   923 				calEntry->SetLastModifiedDateL();
   942 				
   924 				
   943 				// Save the geo value if any
   925 				// Save the geo value if any
   944 				AgendaGeoValue entryGeoValue = entry.geoValue();
   926 				AgendaGeoValue entryGeoValue = entry.geoValue();
   945 				if (!entryGeoValue.isNull()) {
   927 				if (!entryGeoValue.isNull() && (entryGeoValue != storedEntry.geoValue())) {
   946 					CCalGeoValue* geoValue = CCalGeoValue::NewL();
   928 					CCalGeoValue* geoValue = CCalGeoValue::NewL();
   947 					double latitude;
   929 					double latitude;
   948 					double longitude;
   930 					double longitude;
   949 					entryGeoValue.getLatLong(latitude, longitude);
   931 					entryGeoValue.getLatLong(latitude, longitude);
   950 					
   932 					
   952 					geoValue->SetLatLongL(latitude, longitude);
   934 					geoValue->SetLatLongL(latitude, longitude);
   953 					
   935 					
   954 					// set it to CCalentry
   936 					// set it to CCalentry
   955 					calEntry->SetGeoValueL(*geoValue);
   937 					calEntry->SetGeoValueL(*geoValue);
   956 					delete geoValue;
   938 					delete geoValue;
       
   939 				} else if (entryGeoValue.isNull()) {
       
   940                     // Clear the geo values if any
       
   941                     calEntry->ClearGeoValueL();
   957 				}
   942 				}
   958 								
   943 								
   959 				// Update the entry using the calen entry view.
   944 				// Update the entry using the calen entry view.
   960 				RPointerArray<CCalEntry> entryArray;
   945 				RPointerArray<CCalEntry> entryArray;
   961 				CleanupClosePushL(entryArray);
   946 				CleanupResetAndDestroyPushL(entryArray);
   962 				entryArray.AppendL(calEntry);
   947 				entryArray.AppendL(calEntry);
   963 				if (!isChild) {
   948 				if (!isChild) {
   964 					iCalEntryView->UpdateL(entryArray, success);
   949 					iCalEntryView->UpdateL(entryArray, success);
   965 				} else {
   950 				} else {
   966 					iCalEntryView->StoreL(entryArray, success);
   951 					iCalEntryView->StoreL(entryArray, success);
   967 				}
   952 				}
   968 				// Cleanup.
   953 				// Cleanup.
   969 				CleanupStack::PopAndDestroy(2, calEntry);
   954 				CleanupStack::PopAndDestroy( &entryArray );
   970 		)
   955 		)
   971 	}
   956 	}
   972 
   957 
   973 	// Emit the signal to notify the clients.
   958 	// Emit the signal to notify the clients.
   974 	if (0 < success) {
   959 	if (0 < success) {
  1000 	
   985 	
  1001 	CCalEntry* calEntry;
   986 	CCalEntry* calEntry;
  1002 	if (instance) {
   987 	if (instance) {
  1003 		// Get all the entries with same global Uid.
   988 		// Get all the entries with same global Uid.
  1004 		RPointerArray<CCalEntry> entries;
   989 		RPointerArray<CCalEntry> entries;
  1005 		CleanupClosePushL(entries);
   990 		CleanupResetAndDestroyPushL(entries);
  1006 		iCalEntryView->FetchL(instance->UidL(), entries);
   991 		iCalEntryView->FetchL(instance->UidL(), entries);
  1007 		calEntry = entries[0];
   992 		calEntry = entries[0];
       
   993 		entries.Remove(0);
  1008 		CleanupStack::PopAndDestroy(&entries);
   994 		CleanupStack::PopAndDestroy(&entries);
  1009 	} else {
   995 	} else {
  1010 		CleanupStack::PopAndDestroy(instance);
   996 		CleanupStack::PopAndDestroy(instance);
  1011 		return false;
   997 		return false;
  1012 	}
   998 	}
  1038 	}
  1024 	}
  1039 
  1025 
  1040 	// Entry is not a child, but does it have any children?
  1026 	// Entry is not a child, but does it have any children?
  1041 	// Fetch array of entries associated with this UID.
  1027 	// Fetch array of entries associated with this UID.
  1042 	RPointerArray<CCalEntry> oldEntries;
  1028 	RPointerArray<CCalEntry> oldEntries;
  1043 	CleanupClosePushL(oldEntries);
  1029 	CleanupResetAndDestroyPushL(oldEntries);
  1044 	iCalEntryView->FetchL(calEntry->UidL(), oldEntries);
  1030 	iCalEntryView->FetchL(calEntry->UidL(), oldEntries);
  1045 	bool hasChildren = oldEntries.Count() > 0;
  1031 	bool hasChildren = oldEntries.Count() > 0;
  1046 	
  1032 	
  1047 	// Before we proceed further update calEntry with the latest modifications
  1033 	// Before we proceed further update calEntry with the latest modifications
  1048 	// Update only those fields that are required to copy to the children
  1034 	// Update only those fields that are required to copy to the children
  1068 		geoValue->SetLatLongL(latitude, longitude);
  1054 		geoValue->SetLatLongL(latitude, longitude);
  1069 		
  1055 		
  1070 		// set it to CCalentry
  1056 		// set it to CCalentry
  1071 		calEntry->SetGeoValueL(*geoValue);
  1057 		calEntry->SetGeoValueL(*geoValue);
  1072 		delete geoValue;
  1058 		delete geoValue;
       
  1059 	} else {
       
  1060         // Clear the geo values
       
  1061         calEntry->ClearGeoValueL();
  1073 	}
  1062 	}
  1074 	
  1063 	
  1075 	// set the description
  1064 	// set the description
  1076 	calEntry->SetDescriptionL(TPtrC(reinterpret_cast<const TUint16 *> (
  1065 	calEntry->SetDescriptionL(TPtrC(reinterpret_cast<const TUint16 *> (
  1077 										entry.description().utf16())));
  1066 										entry.description().utf16())));
  1145 	CleanupStack::PopAndDestroy( calEntry );
  1134 	CleanupStack::PopAndDestroy( calEntry );
  1146 
  1135 
  1147 	return success;    
  1136 	return success;    
  1148 }
  1137 }
  1149 
  1138 
  1150 bool AgendaUtilPrivate::createException(const AgendaEntry& entry)
  1139 bool AgendaUtilPrivate::createException(const AgendaEntry& entry, 
  1151 {
  1140 										QDateTime instanceOriginalDateTime)
  1152 
  1141 { 
  1153 	// First prepare the session with agenda server.
  1142 	// First prepare the session with agenda server.
  1154 	if (!mInstanceViewCreated) {
  1143 	if (!mInstanceViewCreated) {
  1155 		// Something went wrong.
  1144 		// Something went wrong.
  1156 		return false;
  1145 		return false;
  1157 	}
  1146 	}
  1172 				CleanupStack::PushL(calEntry);
  1161 				CleanupStack::PushL(calEntry);
  1173 				// We are creating an exception, hence get the global Uid
  1162 				// We are creating an exception, hence get the global Uid
  1174 				HBufC8* guid = calEntry->UidL().AllocLC();
  1163 				HBufC8* guid = calEntry->UidL().AllocLC();
  1175 				// create new (child) entry
  1164 				// create new (child) entry
  1176 				// Use original instance time for recurrenceID as this entry hasn't got one.
  1165 				// Use original instance time for recurrenceID as this entry hasn't got one.
  1177 				TCalTime originalCalTime = calEntry->StartTimeL();
  1166 				TCalTime originalCalTime;
       
  1167 				TDateTime originalDateTime(instanceOriginalDateTime.date().year(),
       
  1168 							TMonth(instanceOriginalDateTime.date().month() - 1),
       
  1169 							instanceOriginalDateTime.date().day() -1, 0, 0, 0, 0);
       
  1170 				TTime originalDateTimeTTime(originalDateTime);
       
  1171 				originalCalTime.SetTimeLocalL(originalDateTimeTTime);
  1178 				// create the new child now
  1172 				// create the new child now
  1179 				CCalEntry* newEntry = CCalEntry::NewL( calEntry->EntryTypeL(), 
  1173 				CCalEntry* newEntry = CCalEntry::NewL( calEntry->EntryTypeL(), 
  1180 													   guid,
  1174 													   guid,
  1181 													   calEntry->MethodL(),
  1175 													   calEntry->MethodL(),
  1182 													   calEntry->SequenceNumberL(),
  1176 													   calEntry->SequenceNumberL(),
  1183 													   originalCalTime,
  1177 													   originalCalTime,
  1184 													   CalCommon::EThisOnly );
  1178 													   CalCommon::EThisOnly );
  1185 				
  1179 				
  1186 				CleanupStack::Pop(guid);
  1180 				CleanupStack::Pop(guid);
  1187 				CleanupStack::PopAndDestroy(calEntry);
  1181 				CleanupStack::PopAndDestroy(calEntry);
  1188 				CleanupStack::PushL(newEntry);
       
  1189 
  1182 
  1190 				// Update the description.
  1183 				// Update the description.
  1191 				if (!entry.description().isNull()) {
  1184 				if (!entry.description().isNull()) {
  1192 					newEntry->SetDescriptionL(
  1185 					newEntry->SetDescriptionL(
  1193 							TPtrC(reinterpret_cast<const TUint16 *> (
  1186 							TPtrC(reinterpret_cast<const TUint16 *> (
  1220 
  1213 
  1221 				newEntry->SetFavouriteL(entry.favourite());
  1214 				newEntry->SetFavouriteL(entry.favourite());
  1222 
  1215 
  1223 				// Update the entry using the CCalEntryView.
  1216 				// Update the entry using the CCalEntryView.
  1224 				RPointerArray<CCalEntry> entryArray;
  1217 				RPointerArray<CCalEntry> entryArray;
  1225 				CleanupClosePushL(entryArray);
  1218 				CleanupResetAndDestroyPushL(entryArray);
  1226 				entryArray.AppendL(newEntry);
  1219 				entryArray.AppendL(newEntry);
  1227 				iCalEntryView->StoreL(entryArray, success);
  1220 				iCalEntryView->StoreL(entryArray, success);
  1228 
  1221 
  1229 				localUid = newEntry->LocalUidL();
  1222 				localUid = newEntry->LocalUidL();
  1230 				// Cleanup.
  1223 				// Cleanup.
  1231 				CleanupStack::PopAndDestroy(2, newEntry);
  1224 				CleanupStack::PopAndDestroy(&entryArray);
  1232 		)
  1225 		)
  1233 	} else {
  1226 	} else {
  1234 		TRAP(
  1227 		TRAP(
  1235 				iError,	
  1228 				iError,	
  1236 				
  1229 				
  1238 				CleanupStack::PushL(calEntry);
  1231 				CleanupStack::PushL(calEntry);
  1239 				// We are creating an exception, hence get the global Uid
  1232 				// We are creating an exception, hence get the global Uid
  1240 				HBufC8* guid = calEntry->UidL().AllocLC();
  1233 				HBufC8* guid = calEntry->UidL().AllocLC();
  1241 				// create new (child) entry
  1234 				// create new (child) entry
  1242 				// Use original instance time for recurrenceID as this entry hasn't got one.
  1235 				// Use original instance time for recurrenceID as this entry hasn't got one.
  1243 				TCalTime originalCalTime = calEntry->StartTimeL();
  1236 				TCalTime originalCalTime;
       
  1237 				TDateTime originalDateTime(instanceOriginalDateTime.date().year(),
       
  1238 							TMonth(instanceOriginalDateTime.date().month() - 1),
       
  1239 							instanceOriginalDateTime.date().day() -1, 0, 0, 0, 0);
       
  1240 				TTime originalDateTimeTTime(originalDateTime);
       
  1241 				originalCalTime.SetTimeLocalL(originalDateTimeTTime);
  1244 				// create the new child now
  1242 				// create the new child now
  1245 				CCalEntry* newEntry = CCalEntry::NewL( calEntry->EntryTypeL(), 
  1243 				CCalEntry* newEntry = CCalEntry::NewL( calEntry->EntryTypeL(), 
  1246 													   guid,
  1244 													   guid,
  1247 													   calEntry->MethodL(),
  1245 													   calEntry->MethodL(),
  1248 													   calEntry->SequenceNumberL(),
  1246 													   calEntry->SequenceNumberL(),
  1249 													   originalCalTime,
  1247 													   originalCalTime,
  1250 													   CalCommon::EThisOnly );
  1248 													   CalCommon::EThisOnly );
  1251 				
  1249 				
  1252 				CleanupStack::Pop(guid);
  1250 				CleanupStack::Pop(guid);
  1253 				CleanupStack::PopAndDestroy(calEntry);
  1251 				CleanupStack::PopAndDestroy(calEntry);
  1254 				CleanupStack::PushL(newEntry);
       
  1255 				// Store the attendees.
  1252 				// Store the attendees.
  1256 				if (!entry.isNull()) {
  1253 				if (!entry.isNull()) {
  1257 					addAttendeesToEntry(entry.d->m_attendees, *newEntry);
  1254 					addAttendeesToEntry(entry.d->m_attendees, *newEntry);
  1258 					addCategoriesToEntry(entry.d->m_categories, *newEntry);
  1255 					addCategoriesToEntry(entry.d->m_categories, *newEntry);
  1259 				}
  1256 				}
  1357 				
  1354 				
  1358 				// clear repeat rule properties
  1355 				// clear repeat rule properties
  1359 				newEntry->ClearRepeatingPropertiesL();
  1356 				newEntry->ClearRepeatingPropertiesL();
  1360 				// Update the entry using the calen entry view.
  1357 				// Update the entry using the calen entry view.
  1361 				RPointerArray<CCalEntry> entryArray;
  1358 				RPointerArray<CCalEntry> entryArray;
  1362 				CleanupClosePushL(entryArray);
  1359 				CleanupResetAndDestroyPushL(entryArray);
  1363 				entryArray.AppendL(newEntry);
  1360 				entryArray.AppendL(newEntry);
  1364 				iCalEntryView->StoreL(entryArray, success);
  1361 				iCalEntryView->StoreL(entryArray, success);
  1365 				
  1362 				
  1366 				localUid = newEntry->LocalUidL();
  1363 				localUid = newEntry->LocalUidL();
  1367 				// Cleanup.
  1364 				// Cleanup.
  1368 				CleanupStack::PopAndDestroy(&entryArray);
  1365 				CleanupStack::PopAndDestroy(&entryArray);
  1369 				CleanupStack::PopAndDestroy(newEntry);
       
  1370 		)
  1366 		)
  1371 	}
  1367 	}
  1372 
  1368 
  1373 	// Emit the signal to notify the clients.
  1369 	// Emit the signal to notify the clients.
  1374 	if (0 < success) {
  1370 	if (0 < success) {
  1431 
  1427 
  1432 	TRAP(
  1428 	TRAP(
  1433 			iError,
  1429 			iError,
  1434 
  1430 
  1435 			RPointerArray<CCalInstance> instanceList;
  1431 			RPointerArray<CCalInstance> instanceList;
  1436 			CleanupClosePushL(instanceList);
  1432             CleanupResetAndDestroyPushL(instanceList);
  1437 			CalCommon::TCalViewFilter filters = filter;
  1433 			CalCommon::TCalViewFilter filters = filter;
  1438 			TCalTime startDateForInstanceSearch;
  1434 			TCalTime startDateForInstanceSearch;
  1439 			TCalTime endDateForInstanceSearch;
  1435 			TCalTime endDateForInstanceSearch;
  1440 
  1436 
  1441 			TDateTime startTime = TDateTime(
  1437 			TDateTime startTime = TDateTime(
  1458 
  1454 
  1459 			for (int iter = 0; iter < instanceList.Count(); iter++) {
  1455 			for (int iter = 0; iter < instanceList.Count(); iter++) {
  1460 				listOfIds.append(instanceList[iter]->Entry().LocalUidL());
  1456 				listOfIds.append(instanceList[iter]->Entry().LocalUidL());
  1461 			}
  1457 			}
  1462 
  1458 
  1463 			int count = instanceList.Count();
       
  1464 			for (int iter = count - 1; iter >= 0; --iter) {
       
  1465 				CCalInstance *instance = instanceList[iter];
       
  1466 				delete instance;
       
  1467 			}
       
  1468 
       
  1469 			// Cleanup.
  1459 			// Cleanup.
  1470 			CleanupStack::PopAndDestroy();
  1460 			CleanupStack::PopAndDestroy(&instanceList);
  1471 	)
  1461 	)
  1472 
  1462 
  1473 	return listOfIds;
  1463 	return listOfIds;
  1474 }
  1464 }
  1475 
  1465 
  1492 
  1482 
  1493 	TRAP(
  1483 	TRAP(
  1494 			iError,
  1484 			iError,
  1495 
  1485 
  1496 			RPointerArray<CCalInstance> instanceList;
  1486 			RPointerArray<CCalInstance> instanceList;
  1497 			CleanupClosePushL(instanceList);
  1487             CleanupResetAndDestroyPushL(instanceList);
  1498 			CalCommon::TCalViewFilter filters = filter;
  1488 			CalCommon::TCalViewFilter filters = filter;
  1499 			TCalTime startDateForInstanceSearch;
  1489 			TCalTime startDateForInstanceSearch;
  1500 			TCalTime endDateForInstanceSearch;
  1490 			TCalTime endDateForInstanceSearch;
  1501 
  1491 
  1502 			TDateTime startTime = TDateTime(
  1492 			TDateTime startTime = TDateTime(
  1523 						createAgendaEntryFromCalEntry(
  1513 						createAgendaEntryFromCalEntry(
  1524 								instanceList[iter]->Entry(),
  1514 								instanceList[iter]->Entry(),
  1525 								instanceList[iter]));
  1515 								instanceList[iter]));
  1526 			}
  1516 			}
  1527 
  1517 
  1528 			int count = instanceList.Count();
       
  1529 			for (int iter = count - 1; iter >= 0; --iter) {
       
  1530 				CCalInstance *instance = instanceList[iter];
       
  1531 				delete instance;
       
  1532 			}
       
  1533 
       
  1534 			// Cleanup.
  1518 			// Cleanup.
  1535 			CleanupStack::PopAndDestroy();
  1519 			CleanupStack::PopAndDestroy(&instanceList);
  1536 	)
  1520 	)
  1537 
  1521 
  1538 	return entryList;
  1522 	return entryList;
  1539 }
  1523 }
  1540 
  1524 
  1550         }
  1534         }
  1551 
  1535 
  1552     TRAP(iError,
  1536     TRAP(iError,
  1553 
  1537 
  1554         RPointerArray<CCalInstance> instanceList;
  1538         RPointerArray<CCalInstance> instanceList;
  1555         CleanupClosePushL(instanceList);
  1539         CleanupResetAndDestroyPushL(instanceList);
  1556         CalCommon::TCalViewFilter filters = filter;
  1540         CalCommon::TCalViewFilter filters = filter;
  1557         TCalTime startDateForInstanceSearch;
  1541         TCalTime startDateForInstanceSearch;
  1558         TCalTime endDateForInstanceSearch;
  1542         TCalTime endDateForInstanceSearch;
  1559 
  1543 
  1560         TDateTime startTime(rangeStart.date().year(),
  1544         TDateTime startTime(rangeStart.date().year(),
  1583 
  1567 
  1584         for(TInt i = 0; i<instanceList.Count(); i++)
  1568         for(TInt i = 0; i<instanceList.Count(); i++)
  1585         {
  1569         {
  1586             entryList.append(createAgendaEntryFromCalEntry(instanceList[i]->Entry(), instanceList[i]));
  1570             entryList.append(createAgendaEntryFromCalEntry(instanceList[i]->Entry(), instanceList[i]));
  1587         }
  1571         }
  1588         int count = instanceList.Count();
  1572         CleanupStack::PopAndDestroy(&instanceList);
  1589         for (int i = count - 1; i >= 0; --i) {
       
  1590             CCalInstance *instance = instanceList[i];
       
  1591             delete instance;
       
  1592         }
       
  1593         CleanupStack::PopAndDestroy();
       
  1594     )
  1573     )
  1595 
  1574 
  1596     return entryList;
  1575     return entryList;
  1597 }
  1576 }
  1598 
  1577 
  1604 	if(!mInstanceViewCreated) {
  1583 	if(!mInstanceViewCreated) {
  1605 	    // return empty list
  1584 	    // return empty list
  1606 	    return;
  1585 	    return;
  1607 	}
  1586 	}
  1608 	
  1587 	
  1609 	CleanupClosePushL(instanceList);
  1588 	CleanupResetAndDestroyPushL(instanceList);
  1610 	CalCommon::TCalViewFilter filters = filter;
  1589 	CalCommon::TCalViewFilter filters = filter;
  1611 	TCalTime startDateForInstanceSearch;
  1590 	TCalTime startDateForInstanceSearch;
  1612 	TCalTime endDateForInstanceSearch;
  1591 	TCalTime endDateForInstanceSearch;
  1613 
  1592 
  1614 	TDateTime startTime(rangeStart.date().year(),
  1593 	TDateTime startTime(rangeStart.date().year(),
  1632 	CalCommon::TCalTimeRange searchTimeRange(
  1611 	CalCommon::TCalTimeRange searchTimeRange(
  1633 			startDateForInstanceSearch,
  1612 			startDateForInstanceSearch,
  1634 			endDateForInstanceSearch);
  1613 			endDateForInstanceSearch);
  1635 
  1614 
  1636 	iCalInstanceView->FindInstanceL(instanceList, filters, searchTimeRange);
  1615 	iCalInstanceView->FindInstanceL(instanceList, filters, searchTimeRange);
  1637 	
  1616 
  1638 	// Parse thru the list and mark the dates which have events
  1617 	// Parse thru the list and mark the dates which have events
  1639 	for (int i = 0; i < instanceList.Count(); i++) {
  1618 	for (int i = 0; i < instanceList.Count(); i++) {
  1640 		CCalEntry::TType type = instanceList[i]->Entry().EntryTypeL();
  1619 		CCalEntry::TType type = instanceList[i]->Entry().EntryTypeL();
  1641 		// Get the start time and end time of the events
  1620 		// Get the start time and end time of the events
  1642 		TCalTime startCalTime = instanceList[i]->StartTimeL();
  1621 		TCalTime startCalTime = instanceList[i]->StartTimeL();
  1643 		TCalTime endCalTime = instanceList[i]->EndTimeL();
  1622 		TCalTime endCalTime = instanceList[i]->EndTimeL();
  1644 		TDateTime startDateTime = startCalTime.TimeLocalL().DateTime();
  1623 		TDateTime startDateTime = startCalTime.TimeLocalL().DateTime();
  1645     TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
  1624 		TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
  1646 		QDate startDate(startDateTime.Year(), startDateTime.Month()+1,
  1625 		QDate startDate(startDateTime.Year(), startDateTime.Month()+1,
  1647 						startDateTime.Day() + 1);
  1626 						startDateTime.Day() + 1);
  1648     QDate endDate(endDateTime.Year(), endDateTime.Month()+1,
  1627         QDate endDate(endDateTime.Year(), endDateTime.Month()+1,
  1649                     endDateTime.Day() + 1);
  1628                         endDateTime.Day() + 1);
  1650 		if (type == CCalEntry::EEvent || type == CCalEntry::EAppt ||
  1629 		if (type == CCalEntry::EEvent || type == CCalEntry::EAppt ||
  1651 				type == CCalEntry::EReminder) {
  1630 				type == CCalEntry::EReminder) {
  1652 			if(endsAtStartOfDay(instanceList[i], endCalTime.TimeLocalL())) {
  1631 			if(endsAtStartOfDay(instanceList[i], endCalTime.TimeLocalL())) {
  1653 				// instance ends at start of endtime day, month view doesnt 
       
  1654 				// want to show event on this day
       
  1655 				TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
  1632 				TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
       
  1633 				// prevent problems with items ending tomorrow at 00:00
  1656 				endDateTime.SetMinute(endDateTime.Minute() - 1);
  1634 				endDateTime.SetMinute(endDateTime.Minute() - 1);
  1657 				TTime time(endDateTime);
  1635 				TTime time(endDateTime);
       
  1636 				// If it is ending before the start of the grid 
  1658 				if (time <= startDateForInstanceSearch.TimeLocalL()) {
  1637 				if (time <= startDateForInstanceSearch.TimeLocalL()) {
  1659 					continue;
  1638 					continue;
  1660 				}
  1639 				}
  1661 			}
  1640 			}
  1662         // Mark the required dates frm start date to end date
  1641         // Mark the required dates frm start date to end date
  1663         TTimeIntervalDays days ;
  1642         TTimeIntervalDays days ;
       
  1643         int numOfDays = 0;
  1664         //check if the start date of the entry is before the start day of the grid
  1644         //check if the start date of the entry is before the start day of the grid
  1665         if(startDate < rangeStart.date()){
  1645         if(startDate < rangeStart.date()){
  1666             if(endDate<=rangeEnd.date()){
  1646             if(endDate<=rangeEnd.date()){
  1667                 //if the end date of entry is lying in the grid ,
  1647                 //if the end date of entry is lying in the grid ,
  1668                 //then mark the entry from start day of the grid to the end date of the entry
  1648                 //then mark the entry from start day of the grid to the end date of the entry
  1669                 days = endCalTime.TimeLocalL().DaysFrom(startDateForInstanceSearch.TimeLocalL());
  1649                 days = endCalTime.TimeLocalL().DaysFrom(startDateForInstanceSearch.TimeLocalL());
       
  1650                 numOfDays = days.Int();
  1670             }
  1651             }
  1671             else{
  1652             else{
  1672                 //if end date of the entry is greater then the last date of grid, 
  1653                 //if end date of the entry is greater then the last date of grid, 
  1673                 //then mark all the date of the grid with the entry 
  1654                 //then mark all the date of the grid with the entry 
  1674                 days = endDateForInstanceSearch.TimeLocalL().DaysFrom(startDateForInstanceSearch.TimeLocalL()) ;
  1655                 days = endDateForInstanceSearch.TimeLocalL().DaysFrom(startDateForInstanceSearch.TimeLocalL()) ;
       
  1656                 numOfDays = days.Int();
  1675             }
  1657             }
       
  1658             // Check if the event is all-day
       
  1659             if (instanceList[i]->Entry().EntryTypeL() == CCalEntry::EEvent) {
       
  1660                 // no need to consider the date on which it ends
       
  1661                 // reduce days count by 1
       
  1662                 numOfDays--;
       
  1663                 }
  1676             //start the entries from the first day of the grid
  1664             //start the entries from the first day of the grid
  1677             for (int j = 0; j <= days.Int(); j++) {
  1665             for (int j = 0; j <= numOfDays; j++) {
  1678                 QDate date = rangeStart.date().addDays(j);
  1666                 QDate date = rangeStart.date().addDays(j);
  1679                 if (date <= rangeEnd.date()) {
  1667                 if (date <= rangeEnd.date()) {
  1680                     dates.append(date);
  1668                     dates.append(date);
  1681                 } else {
  1669                 } else {
  1682                     break;
  1670                     break;
  1687         else{
  1675         else{
  1688             if(endDate<=rangeEnd.date()){
  1676             if(endDate<=rangeEnd.date()){
  1689                 //if the end date of entry is lying in the grid ,
  1677                 //if the end date of entry is lying in the grid ,
  1690                 //then mark the entry from start date of the entry to the end date of the entry
  1678                 //then mark the entry from start date of the entry to the end date of the entry
  1691                 days = endCalTime.TimeLocalL().DaysFrom(startCalTime.TimeLocalL()) ;
  1679                 days = endCalTime.TimeLocalL().DaysFrom(startCalTime.TimeLocalL()) ;
       
  1680                 numOfDays = days.Int();
  1692             }
  1681             }
  1693             else{
  1682             else{
  1694                 //if end date of the entry is greater then the last date of grid, 
  1683                 //if end date of the entry is greater then the last date of grid, 
  1695                 //then mark all the date from start date of the entry to the end date of the grid 
  1684                 //then mark all the date from start date of the entry to the end date of the grid 
  1696                 days = endDateForInstanceSearch.TimeLocalL().DaysFrom(startCalTime.TimeLocalL()) ;
  1685                 days = endDateForInstanceSearch.TimeLocalL().DaysFrom(startCalTime.TimeLocalL()) ;
       
  1686                 numOfDays = days.Int();
  1697             }
  1687             }
  1698             for (int j = 0; j <= days.Int(); j++) {
  1688             // Check if the event is all-day
       
  1689             if (instanceList[i]->Entry().EntryTypeL() == CCalEntry::EEvent) {
       
  1690                 // no need to consider the date on which it ends
       
  1691                 // reduce days count by 1
       
  1692                 numOfDays--;
       
  1693                 }
       
  1694             for (int j = 0; j <= numOfDays; j++) {
  1699                 QDate date = startDate.addDays(j);
  1695                 QDate date = startDate.addDays(j);
  1700                 if (date <= rangeEnd.date()) {
  1696                 if (date <= rangeEnd.date()) {
  1701                     dates.append(date);
  1697                     dates.append(date);
  1702                 } else {
  1698                 } else {
  1703                     break;
  1699                     break;
  1715             } else {
  1711             } else {
  1716                 dates.append(startDate);
  1712                 dates.append(startDate);
  1717             }
  1713             }
  1718         }
  1714         }
  1719     }
  1715     }
  1720 	int count = instanceList.Count();
  1716     CleanupStack::PopAndDestroy(&instanceList);
  1721 	for (int i = count - 1; i >= 0; --i) {
       
  1722 	            CCalInstance *instance = instanceList[i];
       
  1723 	            delete instance;
       
  1724 	        }
       
  1725     CleanupStack::PopAndDestroy();
       
  1726 }
  1717 }
  1727 
  1718 
  1728 QList<AgendaEntry> AgendaUtilPrivate::createEntryIdListForDay( QDateTime day,
  1719 QList<AgendaEntry> AgendaUtilPrivate::createEntryIdListForDay( QDateTime day,
  1729                             AgendaUtil::FilterFlags filter )
  1720                             AgendaUtil::FilterFlags filter )
  1730 {
  1721 {
  1736     TCalTime dummy;
  1727     TCalTime dummy;
  1737     CalCommon::TCalTimeRange dayRange( dummy, dummy );
  1728     CalCommon::TCalTimeRange dayRange( dummy, dummy );
  1738     TRAP(iError,
  1729     TRAP(iError,
  1739         getDayRange(day, day, dayRange);
  1730         getDayRange(day, day, dayRange);
  1740         RPointerArray<CCalInstance> instanceList;
  1731         RPointerArray<CCalInstance> instanceList;
  1741         CleanupClosePushL(instanceList);
  1732         CleanupResetAndDestroyPushL(instanceList);
  1742         CalCommon::TCalViewFilter filters = filter;
  1733         CalCommon::TCalViewFilter filters = filter;
  1743         // Check if the filter has todos also to be included
  1734         // Check if the filter has todos also to be included
  1744         if(filter & CalCommon::EIncludeIncompletedTodos)
  1735         if(filter & CalCommon::EIncludeIncompletedTodos)
  1745             {
  1736             {
  1746             // Show the incompleted todos till date only for the current date 
  1737             // Show the incompleted todos till date only for the current date 
  1779             }
  1770             }
  1780         else
  1771         else
  1781             {
  1772             {
  1782             iCalInstanceView->FindInstanceL(instanceList, filters, dayRange);
  1773             iCalInstanceView->FindInstanceL(instanceList, filters, dayRange);
  1783             }
  1774             }
       
  1775         
       
  1776         // In this list, check if any all day events are there
       
  1777         // As all day events end at 12.00AM of next day, we should not show it again on next day
       
  1778         TCalTime calTime;
       
  1779         TDateTime dateTime(
       
  1780                 day.date().year(),
       
  1781                 static_cast<TMonth>(day.date().month() - 1),
       
  1782                 day.date().day() - 1, day.time().hour(),
       
  1783                 day.time().minute(), 0, 0);
       
  1784         TTime time(dateTime);
       
  1785         for (int i(0); i < instanceList.Count(); i++) {
       
  1786             if ((endsAtStartOfDay(instanceList[i], time)) &&
       
  1787                     instanceList[i]->Entry().EntryTypeL() == CCalEntry::EEvent) {
       
  1788                 // Previous day all-day event has been found, we are not supposed to
       
  1789                 // show it on current day, hence remove it from the instance list
       
  1790                 instanceList.Remove(i);
       
  1791                 i--;
       
  1792             }
       
  1793         }
       
  1794         
  1784         // Sort the list
  1795         // Sort the list
  1785         sortInstanceList(instanceList);
  1796         sortInstanceList(instanceList);
  1786         for(TInt i = 0; i<instanceList.Count(); i++)
  1797         for(TInt i = 0; i<instanceList.Count(); i++)
  1787             {
  1798             {
  1788                 entryList.append(createAgendaEntryFromCalEntry(
  1799                 entryList.append(createAgendaEntryFromCalEntry(
  1789                                     instanceList[i]->Entry(), instanceList[i]));
  1800                                     instanceList[i]->Entry(), instanceList[i]));
  1790             }
  1801             }
  1791         int count = instanceList.Count();
  1802         CleanupStack::PopAndDestroy( &instanceList );
  1792         for (int i = count - 1; i >= 0; --i) {
       
  1793             CCalInstance *instance = instanceList[i];
       
  1794             delete instance;
       
  1795         }
       
  1796         CleanupStack::PopAndDestroy();
       
  1797         )
  1803         )
  1798 
  1804 
  1799     return entryList;
  1805     return entryList;
  1800 }
  1806 }
  1801 
  1807 
  1923 
  1929 
  1924 			calTime.SetTimeLocalL(time);
  1930 			calTime.SetTimeLocalL(time);
  1925 
  1931 
  1926 			// Fetch the calentry
  1932 			// Fetch the calentry
  1927 			CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
  1933 			CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
  1928 			CleanupStack::PushL(calEntry);
       
  1929 			calEntry->SetCompletedL(complete, calTime);
  1934 			calEntry->SetCompletedL(complete, calTime);
  1930 
  1935 
  1931 			// Update the entry in the Database
  1936 			// Update the entry in the Database
  1932 			RPointerArray<CCalEntry> array;
  1937 			RPointerArray<CCalEntry> array;
  1933 			CleanupClosePushL(array);
  1938 			CleanupResetAndDestroyPushL(array);
  1934 			array.AppendL(calEntry);
  1939 			array.AppendL(calEntry);
  1935 			iCalEntryView->UpdateL(array, success);
  1940 			iCalEntryView->UpdateL(array, success);
  1936 
  1941 
  1937 			// Cleanup.
  1942 			// Cleanup.
  1938 			CleanupStack::PopAndDestroy(&array);
  1943 			CleanupStack::PopAndDestroy( &array );
  1939 			CleanupStack::PopAndDestroy(calEntry);
       
  1940 	)
  1944 	)
  1941 
  1945 
  1942 	if (0 < success) {
  1946 	if (0 < success) {
  1943 		emit q->entryUpdated(entry.id());
  1947 		emit q->entryUpdated(entry.id());
  1944 	}
  1948 	}
  2006 			CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
  2010 			CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
  2007 
  2011 
  2008 			if (calEntry) {
  2012 			if (calEntry) {
  2009 				// Get all the entries with same global Uid.
  2013 				// Get all the entries with same global Uid.
  2010 				RPointerArray<CCalEntry> entries;
  2014 				RPointerArray<CCalEntry> entries;
  2011 				CleanupClosePushL(entries);
  2015 				CleanupResetAndDestroyPushL(entries);
  2012 				iCalEntryView->FetchL(calEntry->UidL(), entries);
  2016 				iCalEntryView->FetchL(calEntry->UidL(), entries);
  2013 				parentEntry = createAgendaEntryFromCalEntry(*entries[0]);
  2017 				parentEntry = createAgendaEntryFromCalEntry(*entries[0]);
  2014 				CleanupStack::PopAndDestroy(&entries);
  2018 				CleanupStack::PopAndDestroy(&entries);
  2015 			}
  2019 			}
  2016 	)
  2020 	)
  2034 	CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
  2038 	CCalEntry* calEntry = iCalEntryView->FetchL(entry.id());
  2035 
  2039 
  2036 	if (calEntry) {
  2040 	if (calEntry) {
  2037 		// Get all the entries with same global Uid.
  2041 		// Get all the entries with same global Uid.
  2038 		RPointerArray<CCalEntry> entries;
  2042 		RPointerArray<CCalEntry> entries;
  2039 		CleanupClosePushL(entries);
  2043 		CleanupResetAndDestroyPushL(entries);
  2040 		iCalEntryView->FetchL(calEntry->UidL(), entries);
  2044 		iCalEntryView->FetchL(calEntry->UidL(), entries);
  2041 		entries[0]->ClearRepeatingPropertiesL();
  2045 		entries[0]->ClearRepeatingPropertiesL();
  2042 		CleanupStack::PopAndDestroy(&entries);
  2046 		CleanupStack::PopAndDestroy(&entries);
  2043 	}
  2047 	}
  2044 }
  2048 }
  2053 void AgendaUtilPrivate::getPreviousInstanceTimes(AgendaEntry& entry, 
  2057 void AgendaUtilPrivate::getPreviousInstanceTimes(AgendaEntry& entry, 
  2054 												QDateTime& startTime, 
  2058 												QDateTime& startTime, 
  2055 												QDateTime& endTime)
  2059 												QDateTime& endTime)
  2056 {
  2060 {
  2057 	RPointerArray<CCalEntry> entries;
  2061 	RPointerArray<CCalEntry> entries;
  2058 	CleanupClosePushL(entries);
  2062 	CleanupResetAndDestroyPushL(entries);
  2059 	TCalTime previousStartTime;
  2063 	TCalTime previousStartTime;
  2060 	TCalTime previousEndTime;
  2064 	TCalTime previousEndTime;
  2061 	TTime zero(TInt64(0));
  2065 	TTime zero(TInt64(0));
  2062 	// Fetch the parent entry 
  2066 	// Fetch the parent entry 
  2063 	// Get the CalEntry equivalent of the entry.
  2067 	// Get the CalEntry equivalent of the entry.
  2170 					break;
  2174 					break;
  2171 			}
  2175 			}
  2172 			// Is currentInstanceDate before parent dt start?
  2176 			// Is currentInstanceDate before parent dt start?
  2173 			if (currentInstanceDate.TimeLocalL() < 
  2177 			if (currentInstanceDate.TimeLocalL() < 
  2174 					entries[0]->StartTimeL().TimeLocalL()) {
  2178 					entries[0]->StartTimeL().TimeLocalL()) {
       
  2179 				TBool exceptionEntryBeforeParentStartPresent = EFalse;
       
  2180 				for (TInt i=0; i<exdates.Count(); ++i) {
       
  2181 					if( exdates[i].TimeLocalL() < currentInstanceDate.TimeLocalL() ) {
       
  2182 						exceptionEntryBeforeParentStartPresent = ETrue;
       
  2183 					}
       
  2184 				}
       
  2185 				if (!exceptionEntryBeforeParentStartPresent) {
       
  2186 					currentInstanceDate.SetTimeLocalL(Time::NullTTime());
       
  2187 					previousStartTime = currentInstanceDate;
       
  2188 				}
  2175 				// There are no instances before the exception
  2189 				// There are no instances before the exception
  2176 				keepLooking = EFalse;
  2190 				keepLooking = EFalse;
  2177 			} else {
  2191 			} else {
  2178 				// TODO: Put the rest of this function into a separate function, as it's identical
  2192 				// TODO: Put the rest of this function into a separate function, as it's identical
  2179 				// to GetNextInstanceTimeL().
  2193 				// to GetNextInstanceTimeL().
  2212 				}
  2226 				}
  2213 			}
  2227 			}
  2214 		}
  2228 		}
  2215 		CleanupStack::PopAndDestroy(&exdates);
  2229 		CleanupStack::PopAndDestroy(&exdates);
  2216 	}
  2230 	}
  2217 	// Convert TCalTimes to QDateTimes
  2231 	
  2218 	TDateTime prevStart = previousStartTime.TimeLocalL().DateTime();
  2232 	if(previousStartTime.TimeUtcL() != Time::NullTTime()) {
  2219 	TDateTime prevEnd = previousEndTime.TimeLocalL().DateTime();
  2233 		// Convert TCalTimes to QDateTimes
  2220 	startTime.setDate(QDate(prevStart.Year(), prevStart.Month()+1,
  2234 		TDateTime prevStart = previousStartTime.TimeLocalL().DateTime();
  2221 					prevStart.Day() + 1));
  2235 		TDateTime prevEnd = previousEndTime.TimeLocalL().DateTime();
  2222 	startTime.setTime(QTime(prevStart.Hour(), prevStart.Minute(), 0, 0));
  2236 		startTime.setDate(QDate(prevStart.Year(), prevStart.Month()+1,
  2223 	endTime.setDate(QDate(prevEnd.Year(), prevEnd.Month()+1,
  2237 		                        prevStart.Day() + 1));
  2224 	                      prevEnd.Day() + 1));
  2238 		startTime.setTime(QTime(prevStart.Hour(), prevStart.Minute(), 0, 0));
  2225 	endTime.setTime(QTime(prevEnd.Hour(), prevEnd.Minute(), 0, 0));
  2239 		endTime.setDate(QDate(prevEnd.Year(), prevEnd.Month()+1,
  2226 	
  2240 		                      prevEnd.Day() + 1));
       
  2241 		endTime.setTime(QTime(prevEnd.Hour(), prevEnd.Minute(), 0, 0));
       
  2242 	} else {
       
  2243 		QDateTime nullDateTime;
       
  2244 		startTime = nullDateTime;
       
  2245 		endTime = nullDateTime;
       
  2246 	}
  2227 	delete calEntry;
  2247 	delete calEntry;
  2228 	int count = entries.Count();
       
  2229 	for (int i = count - 1; i >= 0; --i) {
       
  2230 		CCalEntry *instance = entries[i];
       
  2231 		delete instance;
       
  2232 	}
       
  2233 	CleanupStack::PopAndDestroy(&entries);
  2248 	CleanupStack::PopAndDestroy(&entries);
  2234 }
  2249 }
  2235 
  2250 
  2236 /*!
  2251 /*!
  2237 	Returns the start and end times of next occurence of a particular
  2252 	Returns the start and end times of next occurence of a particular
  2243 void AgendaUtilPrivate::getNextInstanceTimes(AgendaEntry& entry, 
  2258 void AgendaUtilPrivate::getNextInstanceTimes(AgendaEntry& entry, 
  2244                                           QDateTime& startTime, 
  2259                                           QDateTime& startTime, 
  2245                                           QDateTime& endTime)
  2260                                           QDateTime& endTime)
  2246 {
  2261 {
  2247 	RPointerArray<CCalEntry> entries;
  2262 	RPointerArray<CCalEntry> entries;
  2248 	CleanupClosePushL(entries);
  2263 	CleanupResetAndDestroyPushL(entries);
  2249 	TCalTime nextStartTime;
  2264 	TCalTime nextStartTime;
  2250 	TCalTime nextEndTime;
  2265 	TCalTime nextEndTime;
  2251 	TTime zero(TInt64(0));
  2266 	TTime zero(TInt64(0));
  2252 	// Fetch the parent entry 
  2267 	// Fetch the parent entry 
  2253 	// Get the CalEntry equivalent of the entry.
  2268 	// Get the CalEntry equivalent of the entry.
  2357 				default:
  2372 				default:
  2358 				case notRepeated:
  2373 				case notRepeated:
  2359 					keepLooking = EFalse;
  2374 					keepLooking = EFalse;
  2360 					break;
  2375 					break;
  2361 			}
  2376 			}
  2362 			// Is currentInstanceDate before parent dt start?
  2377 			// Is currentInstanceDate after repeat until date?
  2363 			if (currentInstanceDate.TimeLocalL() < 
  2378 			if (currentInstanceDate.TimeLocalL() >  
  2364 					entries[0]->StartTimeL().TimeLocalL()) {
  2379 					rrule.Until().TimeLocalL()) {
       
  2380 				TBool exceptionEntryAfterRepeatUntilPresent = EFalse;
       
  2381 				for (TInt i=0; i<exdates.Count(); ++i) {
       
  2382 					if(exdates[i].TimeLocalL() > rrule.Until().TimeLocalL()) {
       
  2383 						exceptionEntryAfterRepeatUntilPresent = ETrue;
       
  2384 					}
       
  2385 				}
       
  2386 				if (!exceptionEntryAfterRepeatUntilPresent) {
       
  2387 					currentInstanceDate.SetTimeLocalL(Time::NullTTime());
       
  2388 					nextStartTime = currentInstanceDate;
       
  2389 				}
  2365 				// There are no instances before the exception
  2390 				// There are no instances before the exception
  2366 				keepLooking = EFalse;
  2391 				keepLooking = EFalse;
  2367 			} else {
  2392 			} else {
  2368 				// TODO: Put the rest of this function into a separate function, as it's identical
  2393 				// TODO: Put the rest of this function into a separate function, as it's identical
  2369 				// to GetNextInstanceTimeL().
  2394 				// to GetNextInstanceTimeL().
  2402 				}
  2427 				}
  2403 			}
  2428 			}
  2404 		CleanupStack::PopAndDestroy( &exdates );
  2429 		CleanupStack::PopAndDestroy( &exdates );
  2405 		}
  2430 		}
  2406 	}
  2431 	}
  2407 	// Convert TCalTimes to QDateTimes
  2432 	
  2408 	TDateTime nextStart = nextStartTime.TimeLocalL().DateTime();
  2433 	if (nextStartTime.TimeUtcL() != Time::NullTTime()) {
  2409 	TDateTime nextEnd = nextEndTime.TimeLocalL().DateTime();
  2434 		// Convert TCalTimes to QDateTimes
  2410 	startTime.setDate(QDate(nextStart.Year(), nextStart.Month()+1,
  2435 		TDateTime nextStart = nextStartTime.TimeLocalL().DateTime();
  2411 	                        nextStart.Day() + 1));
  2436 		TDateTime nextEnd = nextEndTime.TimeLocalL().DateTime();
  2412 	startTime.setTime(QTime(nextStart.Hour(), nextStart.Minute(), 0, 0));
  2437 		startTime.setDate(QDate(nextStart.Year(), nextStart.Month()+1,
  2413 	endTime.setDate(QDate(nextEnd.Year(), nextEnd.Month()+1,
  2438 		                        nextStart.Day() + 1));
  2414 	                      nextEnd.Day() + 1));
  2439 		startTime.setTime(QTime(nextStart.Hour(), nextStart.Minute(), 0, 0));
  2415 	endTime.setTime(QTime(nextEnd.Hour(), nextEnd.Minute(), 0, 0));	
  2440 		endTime.setDate(QDate(nextEnd.Year(), nextEnd.Month()+1,
  2416 	
  2441 		                      nextEnd.Day() + 1));
       
  2442 		endTime.setTime(QTime(nextEnd.Hour(), nextEnd.Minute(), 0, 0));	
       
  2443 	} else {
       
  2444 		QDateTime nullDateTime;
       
  2445 		startTime = nullDateTime;
       
  2446 		endTime = nullDateTime;
       
  2447 	}
  2417 	delete calEntry;
  2448 	delete calEntry;
  2418 	int count = entries.Count();
  2449 	
  2419 		for (int i = count - 1; i >= 0; --i) {
       
  2420 			CCalEntry *instance = entries[i];
       
  2421 			delete instance;
       
  2422 		}
       
  2423 	CleanupStack::PopAndDestroy(&entries);
  2450 	CleanupStack::PopAndDestroy(&entries);
  2424 }
  2451 }
  2425 
  2452 
  2426 /*!
  2453 /*!
  2427 	 Returns true if there are no entries in the database else returns false
  2454 	 Returns true if there are no entries in the database else returns false
  2436 	}
  2463 	}
  2437 	
  2464 	
  2438 	bool isEmpty;
  2465 	bool isEmpty;
  2439 	// Query for the entries for entire range
  2466 	// Query for the entries for entire range
  2440 	RPointerArray<CCalInstance> instanceList;
  2467 	RPointerArray<CCalInstance> instanceList;
  2441 	CleanupClosePushL(instanceList);
  2468 	CleanupResetAndDestroyPushL(instanceList);
  2442 	
  2469 	
  2443 	// Create the filter
  2470 	// Create the filter
  2444 	CalCommon::TCalViewFilter filters = AgendaUtil::IncludeAnniversaries
  2471 	CalCommon::TCalViewFilter filters = AgendaUtil::IncludeAnniversaries
  2445 										| AgendaUtil::IncludeAppointments
  2472 										| AgendaUtil::IncludeAppointments
  2446 										| AgendaUtil::IncludeEvents
  2473 										| AgendaUtil::IncludeEvents
  2473 	if (instanceList.Count()) {
  2500 	if (instanceList.Count()) {
  2474 		isEmpty = false;
  2501 		isEmpty = false;
  2475 	} else {
  2502 	} else {
  2476 		isEmpty = true;
  2503 		isEmpty = true;
  2477 	}
  2504 	}
  2478 	int count = instanceList.Count();
  2505 	
  2479 	for (int i = count - 1; i >= 0; --i) {
  2506 	// Cleanup
  2480 	            CCalInstance *instance = instanceList[i];
  2507 	CleanupStack::PopAndDestroy( &instanceList );
  2481 	            delete instance;
       
  2482 	        }
       
  2483 	CleanupStack::PopAndDestroy();
       
  2484 	return isEmpty;
  2508 	return isEmpty;
  2485 }
  2509 }
  2486 
  2510 
  2487 /*!
  2511 /*!
  2488 	Returns the minimum time supported.
  2512 	Returns the minimum time supported.
  2642 			QTime(
  2666 			QTime(
  2643 					calEndDateTime.Hour(), calEndDateTime.Minute(), 0, 0));
  2667 					calEndDateTime.Hour(), calEndDateTime.Minute(), 0, 0));
  2644 	entry.setStartAndEndTime(startDateTime, endDateTime);
  2668 	entry.setStartAndEndTime(startDateTime, endDateTime);
  2645 
  2669 
  2646 	// Attendees.
  2670 	// Attendees.
  2647 	RPointerArray<CCalAttendee> calAttendees = calEntry.AttendeesL();
  2671 	RPointerArray<CCalAttendee>& calAttendees = calEntry.AttendeesL();
  2648 	CleanupClosePushL(calAttendees);
       
  2649 
  2672 
  2650 	for (int i = 0; i < calAttendees.Count(); i++) {
  2673 	for (int i = 0; i < calAttendees.Count(); i++) {
  2651 		AgendaAttendee attendee;
  2674 		AgendaAttendee attendee;
  2652 		// Address.
  2675 		// Address.
  2653 		TPtrC calAddress = calAttendees[i]->Address();
  2676 		TPtrC calAddress = calAttendees[i]->Address();
  2670 		attendee.setStatus(
  2693 		attendee.setStatus(
  2671 				static_cast<AgendaAttendee::StatusType>(
  2694 				static_cast<AgendaAttendee::StatusType>(
  2672 						calAttendees[i]->StatusL()));
  2695 						calAttendees[i]->StatusL()));
  2673 		entry.addAttendee(attendee);
  2696 		entry.addAttendee(attendee);
  2674 	}
  2697 	}
  2675 	CleanupStack::Pop(&calAttendees);
       
  2676 
  2698 
  2677 	// Categories.
  2699 	// Categories.
  2678 	RPointerArray<CCalCategory> calCategories = calEntry.CategoryListL();
  2700 	const RPointerArray<CCalCategory>& calCategories = calEntry.CategoryListL();
  2679 	CleanupClosePushL(calCategories);
       
  2680 
  2701 
  2681 	for (int i = 0; i < calCategories.Count(); i++) {
  2702 	for (int i = 0; i < calCategories.Count(); i++) {
  2682 		AgendaCategory category;
  2703 		AgendaCategory category;
  2683 		CCalCategory::TCalCategoryType categoryType =
  2704 		CCalCategory::TCalCategoryType categoryType =
  2684 				calCategories[i]->Category();
  2705 				calCategories[i]->Category();
  2690 		}
  2711 		}
  2691 		category.setCategory(
  2712 		category.setCategory(
  2692 				static_cast<AgendaCategory::CategoryType>(categoryType));
  2713 				static_cast<AgendaCategory::CategoryType>(categoryType));
  2693 		entry.addCategory(category);
  2714 		entry.addCategory(category);
  2694 	}
  2715 	}
  2695 	CleanupStack::PopAndDestroy(&calCategories);
       
  2696 
  2716 
  2697 	// Id.
  2717 	// Id.
  2698 	entry.d->m_id = calEntry.LocalUidL();
  2718 	entry.d->m_id = calEntry.LocalUidL();
  2699 
  2719 
  2700 	// Alarm.
  2720 	// Alarm.
  2972     }
  2992     }
  2973 	TCalTime dummy;
  2993 	TCalTime dummy;
  2974 	CalCommon::TCalTimeRange dayRange(dummy, dummy);
  2994 	CalCommon::TCalTimeRange dayRange(dummy, dummy);
  2975 	getDayRange(entry.startTime(), entry.startTime(), dayRange);
  2995 	getDayRange(entry.startTime(), entry.startTime(), dayRange);
  2976 	RPointerArray<CCalInstance> instances;
  2996 	RPointerArray<CCalInstance> instances;
  2977 	CleanupClosePushL(instances);
  2997 	CleanupResetAndDestroyPushL(instances);
  2978 	iCalInstanceView->FindInstanceL(instances, CalCommon::EIncludeAll, dayRange);
  2998 	iCalInstanceView->FindInstanceL(instances, CalCommon::EIncludeAll, dayRange);
  2979 	TTime entryStartTime(dayRange.StartTime().TimeLocalL());
  2999 	TTime entryStartTime(dayRange.StartTime().TimeLocalL());
  2980 
  3000 
  2981 	CCalInstance* result = 0;
  3001 	CCalInstance* result = 0;
  2982 
  3002 
  3392 
  3412 
  3393 TTime AgendaUtilPrivate::getPreviousInstanceForRepeatOther(CCalEntry& entry, 
  3413 TTime AgendaUtilPrivate::getPreviousInstanceForRepeatOther(CCalEntry& entry, 
  3394 									const CalCommon::TCalTimeRange& timeRange)
  3414 									const CalCommon::TCalTimeRange& timeRange)
  3395 {
  3415 {
  3396 	RPointerArray<CCalInstance> allInstances;
  3416 	RPointerArray<CCalInstance> allInstances;
  3397 	CleanupClosePushL( allInstances );
  3417 	CleanupResetAndDestroyPushL(allInstances);
  3398 	
  3418 	
  3399 	TInt filter;
  3419 	TInt filter;
  3400 	// Get the entry type to be filtered
  3420 	// Get the entry type to be filtered
  3401 	switch(entry.EntryTypeL())
  3421 	switch(entry.EntryTypeL())
  3402 		{
  3422 		{
  3441 
  3461 
  3442 TTime AgendaUtilPrivate::getNextInstanceForRepeatOther(CCalEntry& aEntry, 
  3462 TTime AgendaUtilPrivate::getNextInstanceForRepeatOther(CCalEntry& aEntry, 
  3443 								   const CalCommon::TCalTimeRange& timeRange)
  3463 								   const CalCommon::TCalTimeRange& timeRange)
  3444 {
  3464 {
  3445 	RPointerArray<CCalInstance> allInstances;
  3465 	RPointerArray<CCalInstance> allInstances;
  3446 	CleanupClosePushL( allInstances );
  3466 	CleanupResetAndDestroyPushL(allInstances);
  3447     
  3467     
  3448     TInt filter;
  3468     TInt filter;
  3449     // Get the entry type to be filtered
  3469     // Get the entry type to be filtered
  3450     switch(aEntry.EntryTypeL())
  3470     switch(aEntry.EntryTypeL())
  3451         {
  3471         {
  3682                                                 entry.UidL().AllocL(),
  3702                                                 entry.UidL().AllocL(),
  3683                                                 oldEntries[i]->MethodL(),
  3703                                                 oldEntries[i]->MethodL(),
  3684                                                 oldEntries[i]->SequenceNumberL(),
  3704                                                 oldEntries[i]->SequenceNumberL(),
  3685                                                 recId,
  3705                                                 recId,
  3686                                                 oldEntries[i]->RecurrenceRangeL() );
  3706                                                 oldEntries[i]->RecurrenceRangeL() );
  3687             CleanupStack::PushL(exception);
       
  3688             exception->CopyFromL(*oldEntries[i]);
  3707             exception->CopyFromL(*oldEntries[i]);
  3689             exception->SetLastModifiedDateL();
  3708             exception->SetLastModifiedDateL();
  3690             TInt successCount=0;
  3709             TInt successCount=0;
  3691 			RPointerArray<CCalEntry> entries;
  3710 			RPointerArray<CCalEntry> entries;
  3692 			CleanupClosePushL( entries );
  3711 			CleanupResetAndDestroyPushL(entries);
  3693 			entries.Append( exception );
  3712 			entries.Append( exception );
  3694 			iCalEntryView->StoreL( entries, successCount );
  3713 			iCalEntryView->StoreL( entries, successCount );
  3695 			CleanupStack::PopAndDestroy( &entries );
  3714 			CleanupStack::PopAndDestroy( &entries );
  3696             CleanupStack::PopAndDestroy(exception);
       
  3697             }
  3715             }
  3698         else
  3716         else
  3699             {
  3717             {
  3700             // If the start time of the series has been changed, the call below will
  3718             // If the start time of the series has been changed, the call below will
  3701             // leave with -1, and the child entries will be lost.  To prevent this
  3719             // leave with -1, and the child entries will be lost.  To prevent this
  3704             // Fixing this may cause issues with sync though, as some servers delete the
  3722             // Fixing this may cause issues with sync though, as some servers delete the
  3705             // children when changing the start time of the series anyway.
  3723             // children when changing the start time of the series anyway.
  3706         	oldEntries[i]->SetLastModifiedDateL();
  3724         	oldEntries[i]->SetLastModifiedDateL();
  3707 			TInt successCount=0;
  3725 			TInt successCount=0;
  3708 			RPointerArray<CCalEntry> entries;
  3726 			RPointerArray<CCalEntry> entries;
  3709 			CleanupClosePushL( entries );
  3727 			CleanupClosePushL(entries);
  3710 			entries.Append( oldEntries[i] );
  3728 			entries.Append( oldEntries[i] );
  3711 			iCalEntryView->StoreL( entries, successCount );
  3729 			iCalEntryView->StoreL( entries, successCount );
  3712 			CleanupStack::PopAndDestroy( &entries );
  3730 			CleanupStack::Pop( &entries );
  3713             }
  3731             }
  3714         }
  3732         }
  3715     }
  3733     }
  3716 
  3734 
  3717 TCalTime AgendaUtilPrivate::generateRecurrenceIdFromEntry( CCalEntry& entry, 
  3735 TCalTime AgendaUtilPrivate::generateRecurrenceIdFromEntry( CCalEntry& entry,