agendainterface/agendautil/src/agendautil_p.cpp
changeset 23 fd30d51f876b
parent 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
equal deleted inserted replaced
18:c198609911f9 23:fd30d51f876b
    14 * Description: Definition file for AgendaUtilPrivate class.
    14 * Description: Definition file for AgendaUtilPrivate class.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
       
    19 #include <hbextendedlocale.h>
    19 #include <calsession.h>
    20 #include <calsession.h>
    20 #include <calinstance.h>
    21 #include <calinstance.h>
    21 #include <CalenImporter>
    22 #include <CalenImporter>
    22 #include <calentry.h>
    23 #include <calentry.h>
    23 #include <calrrule.h>
    24 #include <calrrule.h>
    39 _LIT8(KVersionICal,		"VERSION:2.0");
    40 _LIT8(KVersionICal,		"VERSION:2.0");
    40 //recognition string for vcal
    41 //recognition string for vcal
    41 _LIT8(KVersionVCal,		"VERSION:1.0");
    42 _LIT8(KVersionVCal,		"VERSION:1.0");
    42 const TInt KReadDataAmount = 256;
    43 const TInt KReadDataAmount = 256;
    43 const TInt KGuidLength = 30;
    44 const TInt KGuidLength = 30;
       
    45 const TInt KNoOfDaysInWeek = 7;
    44 static const int startDateArray[2] = { 1900, 1};
    46 static const int startDateArray[2] = { 1900, 1};
    45 static const int endDateArray[2] = { 2100, 1};
    47 static const int endDateArray[2] = { 2100, 1};
    46 
    48 
    47 AgendaUtilPrivate::AgendaUtilPrivate(AgendaUtil* parent)
    49 AgendaUtilPrivate::AgendaUtilPrivate(AgendaUtil* parent)
    48 :q(parent)
    50 :q(parent)
   295 						dateTime.time().minute(), 0, 0);
   297 						dateTime.time().minute(), 0, 0);
   296 				TTime tempTime(tempDateTime);
   298 				TTime tempTime(tempDateTime);
   297 				calTime.SetTimeLocalL(tempTime);
   299 				calTime.SetTimeLocalL(tempTime);
   298 				newEntry->SetLastModifiedDateL(calTime);
   300 				newEntry->SetLastModifiedDateL(calTime);
   299 
   301 
       
   302 				// Set the dtstamp time.It is used to set the cretaion time.
       
   303 				TCalTime creationCalTime;
       
   304 				QDateTime dtStamp = entry.dtStamp();
       
   305 				TDateTime creationDateTime(
       
   306 						dtStamp.date().year(),
       
   307 						static_cast<TMonth>(dtStamp.date().month() - 1),
       
   308 						dtStamp.date().day() - 1, dtStamp.time().hour(),
       
   309 						dtStamp.time().minute(), 0, 0);
       
   310 				TTime creationTTime(creationDateTime);
       
   311 				creationCalTime.SetTimeLocalL(creationTTime);
       
   312 				//newEntry->SetDTStampL(creationCalTime);
       
   313 
   300 				// Finally set the entry to the database using the entry view.
   314 				// Finally set the entry to the database using the entry view.
   301 				entryArray.AppendL(newEntry);
   315 				entryArray.AppendL(newEntry);
   302 				iCalEntryView->StoreL(entryArray, success);
   316 				iCalEntryView->StoreL(entryArray, success);
   303 				localUid = newEntry->LocalUidL();
   317 				localUid = newEntry->LocalUidL();
   304 
   318 
   395 				}
   409 				}
   396 
   410 
   397 				// Set the repeat type if applicable.
   411 				// Set the repeat type if applicable.
   398 				if (AgendaRepeatRule::InvalidRule
   412 				if (AgendaRepeatRule::InvalidRule
   399 						!= entry.repeatRule().type()) {
   413 						!= entry.repeatRule().type()) {
   400 					TCalRRule repeatRule(static_cast<TCalRRule::TType>(
   414 					AgendaRepeatRule agendaRepeatRule = entry.repeatRule();
   401 							entry.repeatRule().type()));
   415 					TCalRRule repeatRule = 
   402 					QDate ruleStartDate = entry.repeatRule().repeatRuleStart();
   416 							createTCalRRuleFromAgendaRRule(agendaRepeatRule);
   403 					QTime ruleStartTime = entry.startTime().time();
       
   404 					TDateTime ruleStartCalendarDateTime(
       
   405 							ruleStartDate.year(),
       
   406 							static_cast<TMonth>(ruleStartDate.month() - 1),
       
   407 							ruleStartDate.day() - 1, ruleStartTime.hour(),
       
   408 							ruleStartTime.minute(), 0, 0);
       
   409 
       
   410 					TCalTime ruleStartCalTime;
       
   411 					ruleStartCalTime.SetTimeLocalL(
       
   412 							TTime(ruleStartCalendarDateTime));
       
   413 					repeatRule.SetDtStart(ruleStartCalTime);
       
   414 					repeatRule.SetInterval(entry.repeatRule().interval());
       
   415 					QDate repeatUntilDate = entry.repeatRule().until();
       
   416 					TDateTime repeatTill(
       
   417 							repeatUntilDate.year(),
       
   418 							static_cast<TMonth> (repeatUntilDate.month() - 1),
       
   419 							repeatUntilDate.day() - 1, ruleStartTime.hour(),
       
   420 							ruleStartTime.minute(), 0, 0);
       
   421 
       
   422 					TCalTime ruleRepeatTillTime;
       
   423 					ruleRepeatTillTime.SetTimeLocalL(TTime(repeatTill));
       
   424 					repeatRule.SetUntil(ruleRepeatTillTime);
       
   425 
       
   426 					QList<AgendaRepeatRule::Day> qDays =
       
   427 							entry.repeatRule().byDay();
       
   428 					RArray<TDay> days;
       
   429 					for (int i = 0; i < qDays.count(); i++) {
       
   430 						days.Append(TDay(qDays[i]));
       
   431 					}
       
   432 					if (days.Count() > 0) {
       
   433 						repeatRule.SetByDay(days);
       
   434 					}
       
   435 
       
   436 					QList<int> qmonthDay = entry.repeatRule().byMonthDay();
       
   437 					RArray<TInt> monthDay;
       
   438 					for (int i = 0; i < qmonthDay.count(); i++) {
       
   439 						monthDay.Append(qmonthDay[i] - 1);
       
   440 					}
       
   441 					if (monthDay.Count() > 0) {
       
   442 						repeatRule.SetByMonthDay(monthDay);
       
   443 					}
       
   444 
       
   445 					QList<AgendaRepeatRule::Month> qMonth =
       
   446 							entry.repeatRule().byMonth();
       
   447 					RArray<TMonth> month;
       
   448 					for (int i = 0; i < qMonth.count(); i++) {
       
   449 						month.Append(TMonth(qMonth[i]));
       
   450 					}
       
   451 					if (month.Count() > 0) {
       
   452 						repeatRule.SetByMonth(month);
       
   453 					}
       
   454 					newEntry->SetRRuleL(repeatRule);
   417 					newEntry->SetRRuleL(repeatRule);
   455 				}
   418 				}
   456 
   419 
   457 				// Save the status of the entry.
   420 				// Save the status of the entry.
   458 				newEntry->SetStatusL((CCalEntry::TStatus) entry.status());
   421 				newEntry->SetStatusL((CCalEntry::TStatus) entry.status());
   459 				newEntry->SetLastModifiedDateL();
   422 				newEntry->SetLastModifiedDateL();
       
   423 				
       
   424 				// Save the geo value if any
       
   425 				AgendaGeoValue entryGeoValue = entry.geoValue();
       
   426 				if (!entryGeoValue.isNull()) {
       
   427 					CCalGeoValue* geoValue = CCalGeoValue::NewL();
       
   428 					double latitude;
       
   429 					double longitude;
       
   430 					entryGeoValue.getLatLong(latitude, longitude);
       
   431 					
       
   432 					// set the values to symbian geo value
       
   433 					geoValue->SetLatLongL(latitude, longitude);
       
   434 					
       
   435 					// set it to CCalentry
       
   436 					newEntry->SetGeoValueL(*geoValue);
       
   437 					delete geoValue;
       
   438 				}
   460 				
   439 				
   461 				// Finally set the entry to the database using the entry view.
   440 				// Finally set the entry to the database using the entry view.
   462 				entryArray.AppendL(newEntry);
   441 				entryArray.AppendL(newEntry);
   463 				iCalEntryView->StoreL(entryArray, success);
   442 				iCalEntryView->StoreL(entryArray, success);
   464 				localUid = newEntry->LocalUidL();
   443 				localUid = newEntry->LocalUidL();
   638 				}
   617 				}
   639 
   618 
   640 				// Set the repeat type if applicable.
   619 				// Set the repeat type if applicable.
   641 				if (AgendaRepeatRule::InvalidRule
   620 				if (AgendaRepeatRule::InvalidRule
   642 						!= entry.repeatRule().type()) {
   621 						!= entry.repeatRule().type()) {
   643 					TCalRRule repeatRule(static_cast<TCalRRule::TType>(
   622 					AgendaRepeatRule agendaRepeatRule = entry.repeatRule();
   644 							entry.repeatRule().type()));
   623 					TCalRRule repeatRule = 
   645 					QDate ruleStartDate = entry.repeatRule().repeatRuleStart();
   624 							createTCalRRuleFromAgendaRRule(agendaRepeatRule);
   646 					QTime ruleStartTime = entry.startTime().time();
       
   647 					TDateTime ruleStartCalendarDateTime(
       
   648 							ruleStartDate.year(),
       
   649 							static_cast<TMonth>(ruleStartDate.month() - 1),
       
   650 							ruleStartDate.day() - 1, ruleStartTime.hour(),
       
   651 							ruleStartTime.minute(), 0, 0);
       
   652 
       
   653 					TCalTime ruleStartCalTime;
       
   654 					ruleStartCalTime.SetTimeLocalL(
       
   655 							TTime(ruleStartCalendarDateTime));
       
   656 					repeatRule.SetDtStart(ruleStartCalTime);
       
   657 					repeatRule.SetInterval(entry.repeatRule().interval());
       
   658 					QDate repeatUntilDate = entry.repeatRule().until();
       
   659 					TDateTime repeatTill(
       
   660 							repeatUntilDate.year(),
       
   661 							static_cast<TMonth> (repeatUntilDate.month() - 1),
       
   662 							repeatUntilDate.day() - 1, ruleStartTime.hour(),
       
   663 							ruleStartTime.minute(), 0, 0);
       
   664 
       
   665 					TCalTime ruleRepeatTillTime;
       
   666 					ruleRepeatTillTime.SetTimeLocalL(TTime(repeatTill));
       
   667 					repeatRule.SetUntil(ruleRepeatTillTime);
       
   668 
       
   669 					QList<AgendaRepeatRule::Day> qDays =
       
   670 							entry.repeatRule().byDay();
       
   671 					RArray<TDay> days;
       
   672 					for (int i = 0; i < qDays.count(); i++) {
       
   673 						days.Append(TDay(qDays[i]));
       
   674 					}
       
   675 					if (days.Count() > 0) {
       
   676 						repeatRule.SetByDay(days);
       
   677 					}
       
   678 
       
   679 					QList<int> qmonthDay = entry.repeatRule().byMonthDay();
       
   680 					RArray<TInt> monthDay;
       
   681 					for (int i = 0; i < qmonthDay.count(); i++) {
       
   682 						monthDay.Append(qmonthDay[i] - 1);
       
   683 					}
       
   684 					if (monthDay.Count() > 0) {
       
   685 						repeatRule.SetByMonthDay(monthDay);
       
   686 					}
       
   687 
       
   688 					QList<AgendaRepeatRule::Month> qMonth =
       
   689 							entry.repeatRule().byMonth();
       
   690 					RArray<TMonth> month;
       
   691 					for (int i = 0; i < qMonth.count(); i++) {
       
   692 						month.Append(TMonth(qMonth[i]));
       
   693 					}
       
   694 					if (month.Count() > 0) {
       
   695 						repeatRule.SetByMonth(month);
       
   696 					}
       
   697 					newEntry->SetRRuleL(repeatRule);
   625 					newEntry->SetRRuleL(repeatRule);
   698 				}
   626 				}
   699 
   627 
   700 				// Save the status of the entry.
   628 				// Save the status of the entry.
   701 				newEntry->SetStatusL((CCalEntry::TStatus) entry.status());
   629 				newEntry->SetStatusL((CCalEntry::TStatus) entry.status());
   702 				newEntry->SetLastModifiedDateL();
   630 				newEntry->SetLastModifiedDateL();
       
   631 				
       
   632 				// Save the geo value if any
       
   633 				AgendaGeoValue entryGeoValue = entry.geoValue();
       
   634 				if (!entryGeoValue.isNull()) {
       
   635 					CCalGeoValue* geoValue = CCalGeoValue::NewL();
       
   636 					double latitude;
       
   637 					double longitude;
       
   638 					entryGeoValue.getLatLong(latitude, longitude);
       
   639 					
       
   640 					// set the values to symbian geo value
       
   641 					geoValue->SetLatLongL(latitude, longitude);
       
   642 					
       
   643 					// set it to CCalentry
       
   644 					newEntry->SetGeoValueL(*geoValue);
       
   645 					delete geoValue;
       
   646 				}
       
   647 								
   703 				// Finally set the entry to the database using the entry view.
   648 				// Finally set the entry to the database using the entry view.
   704 				entryArray.AppendL(newEntry);
   649 				entryArray.AppendL(newEntry);
   705 				iCalEntryView->StoreL(entryArray, success);
   650 				iCalEntryView->StoreL(entryArray, success);
   706 				localUid = newEntry->LocalUidL();
   651 				localUid = newEntry->LocalUidL();
   707 
   652 
   874 						TTime lastModTime(lastModDateTime);
   819 						TTime lastModTime(lastModDateTime);
   875 						TCalTime lastModCalTime;
   820 						TCalTime lastModCalTime;
   876 						lastModCalTime.SetTimeLocalL(lastModTime);
   821 						lastModCalTime.SetTimeLocalL(lastModTime);
   877 						calEntry->SetLastModifiedDateL(lastModCalTime);
   822 						calEntry->SetLastModifiedDateL(lastModCalTime);
   878 					}
   823 					}
       
   824 				}
       
   825 
       
   826 				// Update the DTStamp time as the entry is modified.
       
   827 				if (entry.dtStamp().isValid()) {
       
   828 					TCalTime resetCreationTime;
       
   829 					TTime nullTime = Time::NullTTime();
       
   830 					resetCreationTime.SetTimeLocalL(nullTime);
       
   831 					calEntry->SetDTStampL(resetCreationTime);
   879 				}
   832 				}
   880 
   833 
   881 				// Check if the favourite property is changed and update the
   834 				// Check if the favourite property is changed and update the
   882 				// same.
   835 				// same.
   883 				if (entry.favourite() != storedEntry.favourite()) {
   836 				if (entry.favourite() != storedEntry.favourite()) {
  1023 				if (storedEntry.repeatRule() != entry.repeatRule()) {
   976 				if (storedEntry.repeatRule() != entry.repeatRule()) {
  1024 
   977 
  1025 					calEntry->ClearRepeatingPropertiesL();
   978 					calEntry->ClearRepeatingPropertiesL();
  1026 
   979 
  1027 					if(TCalRRule::EInvalid != entry.repeatRule().type()) {
   980 					if(TCalRRule::EInvalid != entry.repeatRule().type()) {
  1028 						TCalRRule
   981 						AgendaRepeatRule agendaRepeatRule = entry.repeatRule();
  1029 						repeatRule(static_cast<TCalRRule::TType> (
   982 						TCalRRule repeatRule = 
  1030 								entry.repeatRule().type()));
   983 							createTCalRRuleFromAgendaRRule(agendaRepeatRule);
  1031 						QDate ruleStartDate =
       
  1032 								entry.repeatRule().repeatRuleStart();
       
  1033 						QTime ruleStartTime = entry.startTime().time();
       
  1034 						TDateTime
       
  1035 						ruleStartCalendarDateTime(
       
  1036 								ruleStartDate.year(),
       
  1037 								static_cast<TMonth> (ruleStartDate.month()
       
  1038 										- 1),
       
  1039 										ruleStartDate.day() - 1,
       
  1040 										ruleStartTime.hour(),
       
  1041 										ruleStartTime.minute(), 0, 0);
       
  1042 
       
  1043 						TCalTime ruleStartCalTime;
       
  1044 						ruleStartCalTime.SetTimeLocalL(
       
  1045 								TTime(ruleStartCalendarDateTime));
       
  1046 						repeatRule.SetDtStart(ruleStartCalTime);
       
  1047 						repeatRule.SetInterval(entry.repeatRule().interval());
       
  1048 						QDate repeatUntilDate = entry.repeatRule().until();
       
  1049 						TDateTime repeatTill(
       
  1050 								repeatUntilDate.year(),
       
  1051 								static_cast<TMonth>(repeatUntilDate.month() - 1),
       
  1052 								repeatUntilDate.day() - 1, ruleStartTime.hour(),
       
  1053 								ruleStartTime.minute(), 0, 0);
       
  1054 						TCalTime ruleRepeatTillTime;
       
  1055 						ruleRepeatTillTime.SetTimeLocalL(TTime(repeatTill));
       
  1056 						repeatRule.SetUntil(ruleRepeatTillTime);
       
  1057 
       
  1058 						QList<AgendaRepeatRule::Day> qDays =
       
  1059 								entry.repeatRule().byDay();
       
  1060 						RArray<TDay> days;
       
  1061 						for (int i = 0; i < qDays.count(); i++) {
       
  1062 							days.Append(TDay(qDays[i]));
       
  1063 						}
       
  1064 						if (days.Count()> 0) {
       
  1065 							repeatRule.SetByDay(days);
       
  1066 						}
       
  1067 
       
  1068 						QList<int> qmonthDay = entry.repeatRule().byMonthDay();
       
  1069 						RArray<TInt> monthDay;
       
  1070 						for (int i = 0; i < qmonthDay.count(); i++) {
       
  1071 							monthDay.Append(qmonthDay[i] - 1);
       
  1072 						}
       
  1073 						if (monthDay.Count()> 0) {
       
  1074 							repeatRule.SetByMonthDay(monthDay);
       
  1075 						}
       
  1076 
       
  1077 						QList<AgendaRepeatRule::Month> qMonth =
       
  1078 								entry.repeatRule().byMonth();
       
  1079 						RArray<TMonth> month;
       
  1080 						for (int i = 0; i < qMonth.count(); i++) {
       
  1081 							month.Append(TMonth(qMonth[i]));
       
  1082 						}
       
  1083 						if (month.Count()> 0) {
       
  1084 							repeatRule.SetByMonth(month);
       
  1085 						}
       
  1086 						calEntry->SetRRuleL(repeatRule);
   984 						calEntry->SetRRuleL(repeatRule);
  1087 					}
   985 					}
  1088 				}
   986 				}
  1089 				
   987 				
  1090 				// Check if the favourite property is changed and update the
   988 				// Check if the favourite property is changed and update the
  1091 				// same.
   989 				// same.
  1092 				if (entry.favourite() != storedEntry.favourite()) {
   990 				if (entry.favourite() != storedEntry.favourite()) {
  1093 					calEntry->SetFavouriteL(entry.favourite());
   991 					calEntry->SetFavouriteL(entry.favourite());
  1094 				}
   992 				}
  1095 				calEntry->SetLastModifiedDateL();
   993 				calEntry->SetLastModifiedDateL();
       
   994 				
       
   995 				// Save the geo value if any
       
   996 				AgendaGeoValue entryGeoValue = entry.geoValue();
       
   997 				if (!entryGeoValue.isNull()) {
       
   998 					CCalGeoValue* geoValue = CCalGeoValue::NewL();
       
   999 					double latitude;
       
  1000 					double longitude;
       
  1001 					entryGeoValue.getLatLong(latitude, longitude);
       
  1002 					
       
  1003 					// set the values to symbian geo value
       
  1004 					geoValue->SetLatLongL(latitude, longitude);
       
  1005 					
       
  1006 					// set it to CCalentry
       
  1007 					calEntry->SetGeoValueL(*geoValue);
       
  1008 					delete geoValue;
       
  1009 				}
       
  1010 								
  1096 				// Update the entry using the calen entry view.
  1011 				// Update the entry using the calen entry view.
  1097 				RPointerArray<CCalEntry> entryArray;
  1012 				RPointerArray<CCalEntry> entryArray;
  1098 				CleanupClosePushL(entryArray);
  1013 				CleanupClosePushL(entryArray);
  1099 				entryArray.AppendL(calEntry);
  1014 				entryArray.AppendL(calEntry);
  1100 				if (!isChild) {
  1015 				if (!isChild) {
  1191 	
  1106 	
  1192 	// set the locaiton
  1107 	// set the locaiton
  1193 	calEntry->SetLocationL(TPtrC(reinterpret_cast<const TUint16 *> (
  1108 	calEntry->SetLocationL(TPtrC(reinterpret_cast<const TUint16 *> (
  1194 										entry.location().utf16())));
  1109 										entry.location().utf16())));
  1195 	
  1110 	
       
  1111 	// Save the geo value if any
       
  1112 	AgendaGeoValue entryGeoValue = entry.geoValue();
       
  1113 	if (!entryGeoValue.isNull()) {
       
  1114 		CCalGeoValue* geoValue = CCalGeoValue::NewL();
       
  1115 		double latitude;
       
  1116 		double longitude;
       
  1117 		entryGeoValue.getLatLong(latitude, longitude);
       
  1118 		
       
  1119 		// set the values to symbian geo value
       
  1120 		geoValue->SetLatLongL(latitude, longitude);
       
  1121 		
       
  1122 		// set it to CCalentry
       
  1123 		calEntry->SetGeoValueL(*geoValue);
       
  1124 		delete geoValue;
       
  1125 	}
       
  1126 	
  1196 	// set the description
  1127 	// set the description
  1197 	calEntry->SetDescriptionL(TPtrC(reinterpret_cast<const TUint16 *> (
  1128 	calEntry->SetDescriptionL(TPtrC(reinterpret_cast<const TUint16 *> (
  1198 										entry.description().utf16())));
  1129 										entry.description().utf16())));
  1199 	
  1130 	
  1200 	// set the instance start and end dates to this
  1131 	// set the instance start and end dates to this
  1226 	calEntry->SetStartAndEndTimeL(originalStartCalTime, originalEndCalTime);
  1157 	calEntry->SetStartAndEndTimeL(originalStartCalTime, originalEndCalTime);
  1227 	
  1158 	
  1228 	// Set the repeat rules
  1159 	// Set the repeat rules
  1229 	calEntry->ClearRepeatingPropertiesL();
  1160 	calEntry->ClearRepeatingPropertiesL();
  1230 
  1161 
  1231 	if(TCalRRule::EInvalid != entry.repeatRule().type()) {
  1162 	if (TCalRRule::EInvalid != entry.repeatRule().type()) {
  1232 		TCalRRule
  1163 		AgendaRepeatRule agendaRepeatRule = entry.repeatRule();
  1233 		repeatRule(static_cast<TCalRRule::TType> (
  1164 		TCalRRule repeatRule = 
  1234 				entry.repeatRule().type()));
  1165 				createTCalRRuleFromAgendaRRule(agendaRepeatRule);
  1235 		QDate ruleStartDate =
       
  1236 				entry.repeatRule().repeatRuleStart();
       
  1237 		QTime ruleStartTime = entry.startTime().time();
       
  1238 		TDateTime
       
  1239 		ruleStartCalendarDateTime(
       
  1240 				ruleStartDate.year(),
       
  1241 				static_cast<TMonth> (ruleStartDate.month()
       
  1242 						- 1),
       
  1243 						ruleStartDate.day() - 1,
       
  1244 						ruleStartTime.hour(),
       
  1245 						ruleStartTime.minute(), 0, 0);
       
  1246 
       
  1247 		TCalTime ruleStartCalTime;
       
  1248 		ruleStartCalTime.SetTimeLocalL(
       
  1249 				TTime(ruleStartCalendarDateTime));
       
  1250 		repeatRule.SetDtStart(ruleStartCalTime);
       
  1251 		repeatRule.SetInterval(entry.repeatRule().interval());
       
  1252 		QDate repeatUntilDate = entry.repeatRule().until();
       
  1253 		TDateTime repeatTill(
       
  1254 				repeatUntilDate.year(),
       
  1255 				static_cast<TMonth>(repeatUntilDate.month() - 1),
       
  1256 				repeatUntilDate.day() - 1, ruleStartTime.hour(),
       
  1257 				ruleStartTime.minute(), 0, 0);
       
  1258 		TCalTime ruleRepeatTillTime;
       
  1259 		ruleRepeatTillTime.SetTimeLocalL(TTime(repeatTill));
       
  1260 		repeatRule.SetUntil(ruleRepeatTillTime);
       
  1261 
       
  1262 		QList<AgendaRepeatRule::Day> qDays =
       
  1263 				entry.repeatRule().byDay();
       
  1264 		RArray<TDay> days;
       
  1265 		for (int i = 0; i < qDays.count(); i++) {
       
  1266 			days.Append(TDay(qDays[i]));
       
  1267 		}
       
  1268 		if (days.Count()> 0) {
       
  1269 			repeatRule.SetByDay(days);
       
  1270 		}
       
  1271 
       
  1272 		QList<int> qmonthDay = entry.repeatRule().byMonthDay();
       
  1273 		RArray<TInt> monthDay;
       
  1274 		for (int i = 0; i < qmonthDay.count(); i++) {
       
  1275 			monthDay.Append(qmonthDay[i] - 1);
       
  1276 		}
       
  1277 		if (monthDay.Count()> 0) {
       
  1278 			repeatRule.SetByMonthDay(monthDay);
       
  1279 		}
       
  1280 
       
  1281 		QList<AgendaRepeatRule::Month> qMonth =
       
  1282 				entry.repeatRule().byMonth();
       
  1283 		RArray<TMonth> month;
       
  1284 		for (int i = 0; i < qMonth.count(); i++) {
       
  1285 			month.Append(TMonth(qMonth[i]));
       
  1286 		}
       
  1287 		if (month.Count()> 0) {
       
  1288 			repeatRule.SetByMonth(month);
       
  1289 		}
       
  1290 		calEntry->SetRRuleL(repeatRule);
  1166 		calEntry->SetRRuleL(repeatRule);
       
  1167 
  1291 	}
  1168 	}
  1292 	
  1169 	
  1293 	bool hasTimeOrDateCanged = (oldEntries[0]->StartTimeL().TimeUtcL() != 
  1170 	bool hasTimeOrDateCanged = (oldEntries[0]->StartTimeL().TimeUtcL() != 
  1294 			calEntry->StartTimeL().TimeUtcL() ||
  1171 			calEntry->StartTimeL().TimeUtcL() ||
  1295 			oldEntries[0]->EndTimeL().TimeUtcL() != calEntry->EndTimeL().TimeUtcL());
  1172 			oldEntries[0]->EndTimeL().TimeUtcL() != calEntry->EndTimeL().TimeUtcL());
  1527 				TTime endCalTime(endCalendarDateTime);
  1404 				TTime endCalTime(endCalendarDateTime);
  1528 				TCalTime calTime2;
  1405 				TCalTime calTime2;
  1529 				calTime2.SetTimeLocalL(endCalTime);
  1406 				calTime2.SetTimeLocalL(endCalTime);
  1530 
  1407 
  1531 				newEntry->SetStartAndEndTimeL(calTime, calTime2);
  1408 				newEntry->SetStartAndEndTimeL(calTime, calTime2);
  1532 
  1409 				
       
  1410 				// Save the geo value if any
       
  1411 				AgendaGeoValue entryGeoValue = entry.geoValue();
       
  1412 				if (!entryGeoValue.isNull()) {
       
  1413 					CCalGeoValue* geoValue = CCalGeoValue::NewL();
       
  1414 					double latitude;
       
  1415 					double longitude;
       
  1416 					entryGeoValue.getLatLong(latitude, longitude);
       
  1417 					
       
  1418 					// set the values to symbian geo value
       
  1419 					geoValue->SetLatLongL(latitude, longitude);
       
  1420 					
       
  1421 					// set it to CCalentry
       
  1422 					newEntry->SetGeoValueL(*geoValue);
       
  1423 					delete geoValue;
       
  1424 				}
       
  1425 				
  1533 				// No need to update the repeat rule as it is an exception
  1426 				// No need to update the repeat rule as it is an exception
  1534 
  1427 
  1535 				// Store the favourite
  1428 				// Store the favourite
  1536 				newEntry->SetFavouriteL(entry.favourite());
  1429 				newEntry->SetFavouriteL(entry.favourite());
  1537 				
  1430 				
  1777     )
  1670     )
  1778 
  1671 
  1779     return entryList;
  1672     return entryList;
  1780 }
  1673 }
  1781 
  1674 
       
  1675 void AgendaUtilPrivate::markDatesWithEvents(QDateTime rangeStart, 
       
  1676 	QDateTime rangeEnd,AgendaUtil::FilterFlags filter, QList<QDate>& dates)
       
  1677 {
       
  1678 	RPointerArray<CCalInstance> instanceList;
       
  1679 	CleanupClosePushL(instanceList);
       
  1680 	CalCommon::TCalViewFilter filters = filter;
       
  1681 	TCalTime startDateForInstanceSearch;
       
  1682 	TCalTime endDateForInstanceSearch;
       
  1683 
       
  1684 	TDateTime startTime(rangeStart.date().year(),
       
  1685 			TMonth(rangeStart.date().month() - 1),
       
  1686 			rangeStart.date().day() - 1,
       
  1687 			rangeStart.time().hour(),
       
  1688 			rangeStart.time().minute(),
       
  1689 			rangeStart.time().second(),
       
  1690 			rangeStart.time().msec());
       
  1691 
       
  1692 	TDateTime endTime(rangeEnd.date().year(),
       
  1693 			TMonth(rangeEnd.date().month() - 1),
       
  1694 			rangeEnd.date().day() - 1,
       
  1695 			rangeEnd.time().hour(),
       
  1696 			rangeEnd.time().minute(),
       
  1697 			rangeEnd.time().second(),
       
  1698 			rangeEnd.time().msec());
       
  1699 
       
  1700 	startDateForInstanceSearch.SetTimeLocalL(startTime);
       
  1701 	endDateForInstanceSearch.SetTimeLocalL(endTime);
       
  1702 	CalCommon::TCalTimeRange searchTimeRange(
       
  1703 			startDateForInstanceSearch,
       
  1704 			endDateForInstanceSearch);
       
  1705 
       
  1706 	iCalInstanceView->FindInstanceL(instanceList, filters, searchTimeRange);
       
  1707 	
       
  1708 	// Parse thru the list and mark the dates which have events
       
  1709 	for (int i = 0; i < instanceList.Count(); i++) {
       
  1710 		CCalEntry::TType type = instanceList[i]->Entry().EntryTypeL();
       
  1711 		// Get the start time and end time of the events
       
  1712 		TCalTime startCalTime = instanceList[i]->StartTimeL();
       
  1713 		TCalTime endCalTime = instanceList[i]->EndTimeL();
       
  1714 		TDateTime startDateTime = startCalTime.TimeLocalL().DateTime();
       
  1715 		QDate startDate(startDateTime.Year(), startDateTime.Month()+1,
       
  1716 						startDateTime.Day() + 1);
       
  1717 		if (type == CCalEntry::EEvent || type == CCalEntry::EAppt ||
       
  1718 				type == CCalEntry::EReminder) {
       
  1719 			if(endsAtStartOfDay(instanceList[i], endCalTime.TimeLocalL())) {
       
  1720 				// instance ends at start of endtime day, month view doesnt 
       
  1721 				// want to show event on this day
       
  1722 				TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
       
  1723 				endDateTime.SetMinute(endDateTime.Minute() - 1);
       
  1724 				TTime time(endDateTime);
       
  1725 				if (time <= startDateForInstanceSearch.TimeLocalL()) {
       
  1726 					continue;
       
  1727 				}
       
  1728 			}
       
  1729 			
       
  1730 			// Mark the required dates frm start date to end date
       
  1731 			TTimeIntervalDays days = endCalTime.TimeLocalL().DaysFrom(startCalTime.TimeLocalL());
       
  1732 			for (int j = -1; j < days.Int(); j++) {
       
  1733 				QDate date = startDate.addDays(j+1);
       
  1734 				if (date <= rangeEnd.date()) {
       
  1735 					dates.append(date);
       
  1736 				} else {
       
  1737 					break;
       
  1738 				}
       
  1739 			}
       
  1740 		} else if (type == CCalEntry::EAnniv) {
       
  1741 			if (startDate <= rangeEnd.date()) {
       
  1742 				dates.append(startDate);
       
  1743 			}
       
  1744 		} else if (type == CCalEntry::ETodo) {
       
  1745 			// if start time is less that today, then mark it for today
       
  1746 			if (startDate < QDate::currentDate()) {
       
  1747 				dates.append(QDate::currentDate());
       
  1748 			} else {
       
  1749 				dates.append(startDate);
       
  1750 			}
       
  1751 		}
       
  1752 	}
       
  1753 	CleanupStack::PopAndDestroy();
       
  1754 }
       
  1755 
  1782 QList<AgendaEntry> AgendaUtilPrivate::createEntryIdListForDay( QDateTime day,
  1756 QList<AgendaEntry> AgendaUtilPrivate::createEntryIdListForDay( QDateTime day,
  1783                             AgendaUtil::FilterFlags filter )
  1757                             AgendaUtil::FilterFlags filter )
  1784 {
  1758 {
  1785     QList<AgendaEntry> entryList;
  1759     QList<AgendaEntry> entryList;
  1786     if(!prepareSession()) {
  1760     if(!prepareSession()) {
  1792     TRAP(iError,
  1766     TRAP(iError,
  1793         getDayRange(day, day, dayRange);
  1767         getDayRange(day, day, dayRange);
  1794         RPointerArray<CCalInstance> instanceList;
  1768         RPointerArray<CCalInstance> instanceList;
  1795         CleanupClosePushL(instanceList);
  1769         CleanupClosePushL(instanceList);
  1796         CalCommon::TCalViewFilter filters = filter;
  1770         CalCommon::TCalViewFilter filters = filter;
  1797         iCalInstanceView->FindInstanceL(instanceList, filters, dayRange);
  1771         // Check if the filter has todos also to be included
  1798 
  1772         if(filter & CalCommon::EIncludeIncompletedTodos)
       
  1773             {
       
  1774             // Show the incompleted todos till date only for the current date 
       
  1775             if(QDate::currentDate() == day.date())
       
  1776                 {
       
  1777                 // Remove the todos from the filter and fetch it separately
       
  1778                 CalCommon::TCalViewFilter changedfilter = 
       
  1779                                    filter ^ CalCommon::EIncludeIncompletedTodos;
       
  1780                 iCalInstanceView->FindInstanceL(
       
  1781                                          instanceList, changedfilter, dayRange);
       
  1782                 // Get the range from minimum datetime till the today
       
  1783                 getDayRange(minTime(), day, dayRange);
       
  1784                 iCalInstanceView->FindInstanceL(
       
  1785                         instanceList ,CalCommon::EIncludeIncompletedTodos | 
       
  1786                         // only fetch the first instance for repeating to-dos!
       
  1787                         CalCommon::EIncludeRptsNextInstanceOnly, 
       
  1788                         dayRange);
       
  1789                 }
       
  1790             else if(QDate::currentDate() < day.date())
       
  1791                 {
       
  1792             	// Fetch all the instances including todos
       
  1793             	// only if the day range is in future dates
       
  1794                 iCalInstanceView->FindInstanceL(
       
  1795                                                instanceList, filters, dayRange);
       
  1796                 }
       
  1797             else if(QDate::currentDate() > day.date())
       
  1798 				{
       
  1799 				// Remove todos from the filter
       
  1800 				CalCommon::TCalViewFilter changedfilter = 
       
  1801 								   filter ^ CalCommon::EIncludeIncompletedTodos;
       
  1802             	// Fetch all the instances excluding todos
       
  1803             	// only if the day range is in past dates
       
  1804 				iCalInstanceView->FindInstanceL(
       
  1805 										 instanceList, changedfilter, dayRange);
       
  1806 				}
       
  1807             }
       
  1808         else
       
  1809             {
       
  1810             iCalInstanceView->FindInstanceL(instanceList, filters, dayRange);
       
  1811             }
  1799         // Sort the list
  1812         // Sort the list
  1800         sortInstanceList(instanceList);
  1813         sortInstanceList(instanceList);
  1801         for(TInt i = 0; i<instanceList.Count(); i++)
  1814         for(TInt i = 0; i<instanceList.Count(); i++)
  1802             {
  1815             {
  1803                 entryList.append(createAgendaEntryFromCalEntry(instanceList[i]->Entry(), instanceList[i]));
  1816                 entryList.append(createAgendaEntryFromCalEntry(
       
  1817                                     instanceList[i]->Entry(), instanceList[i]));
  1804             }
  1818             }
  1805         int count = instanceList.Count();
  1819         int count = instanceList.Count();
  1806         for (int i = count - 1; i >= 0; --i) {
  1820         for (int i = count - 1; i >= 0; --i) {
  1807             CCalInstance *instance = instanceList[i];
  1821             CCalInstance *instance = instanceList[i];
  1808             delete instance;
  1822             delete instance;
  2131 			switch (repeatIndex) {
  2145 			switch (repeatIndex) {
  2132 				case repeatDaily:
  2146 				case repeatDaily:
  2133 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()-TTimeIntervalDays(1) );
  2147 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()-TTimeIntervalDays(1) );
  2134 					break;
  2148 					break;
  2135 				case repeatWeekly:
  2149 				case repeatWeekly:
       
  2150 				case repeatWorkdays:
  2136 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()-TTimeIntervalDays(7) );
  2151 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()-TTimeIntervalDays(7) );
  2137 					break;
  2152 					break;
  2138 				case repeatBiWeekly:
  2153 				case repeatBiWeekly:
  2139 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()-TTimeIntervalDays(14) );
  2154 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()-TTimeIntervalDays(14) );
  2140 					break;
  2155 					break;
  2320 			switch (repeatIndex) {
  2335 			switch (repeatIndex) {
  2321 				case repeatDaily:
  2336 				case repeatDaily:
  2322 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()+TTimeIntervalDays(1) );
  2337 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()+TTimeIntervalDays(1) );
  2323 					break;
  2338 					break;
  2324 				case repeatWeekly:
  2339 				case repeatWeekly:
       
  2340 				case repeatWorkdays:
  2325 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()+TTimeIntervalDays(7) );
  2341 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()+TTimeIntervalDays(7) );
  2326 					break;
  2342 					break;
  2327 				case repeatBiWeekly:
  2343 				case repeatBiWeekly:
  2328 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()+TTimeIntervalDays(14) );
  2344 					currentInstanceDate.SetTimeLocalL( currentInstanceDate.TimeLocalL()+TTimeIntervalDays(14) );
  2329 					break;
  2345 					break;
  2434 		}
  2450 		}
  2435 	CleanupStack::PopAndDestroy(&entries);
  2451 	CleanupStack::PopAndDestroy(&entries);
  2436 }
  2452 }
  2437 
  2453 
  2438 /*!
  2454 /*!
       
  2455 	 Returns true if there are no entries in the database else returns false
       
  2456 	 
       
  2457 	 \return bool 
       
  2458  */
       
  2459 bool AgendaUtilPrivate::areNoEntriesInCalendar()
       
  2460 {
       
  2461 	bool isEmpty;
       
  2462 	// Query for the entries for entire range
       
  2463 	RPointerArray<CCalInstance> instanceList;
       
  2464 	CleanupClosePushL(instanceList);
       
  2465 	
       
  2466 	// Create the filter
       
  2467 	CalCommon::TCalViewFilter filters = AgendaUtil::IncludeAnniversaries
       
  2468 										| AgendaUtil::IncludeAppointments
       
  2469 										| AgendaUtil::IncludeEvents
       
  2470 										| AgendaUtil::IncludeReminders
       
  2471 										| AgendaUtil::IncludeIncompletedTodos;
       
  2472 	
       
  2473 	// Set up the range
       
  2474 	TCalTime startDateForInstanceSearch;
       
  2475 	TCalTime endDateForInstanceSearch;
       
  2476 
       
  2477 	TDateTime startTime = TDateTime(
       
  2478 			startDateArray[0], static_cast<TMonth>(startDateArray[1]),
       
  2479 			0, 0, 0, 0, 0);
       
  2480 
       
  2481 	TDateTime endTime = TDateTime(
       
  2482 			endDateArray[0], static_cast<TMonth>(endDateArray[1]),
       
  2483 			0, 0, 0, 0, 0);
       
  2484 
       
  2485 	startDateForInstanceSearch.SetTimeLocalL(startTime);
       
  2486 	endDateForInstanceSearch.SetTimeLocalL(endTime);
       
  2487 	CalCommon::TCalTimeRange searchTimeRange(
       
  2488 			startDateForInstanceSearch,
       
  2489 			endDateForInstanceSearch);
       
  2490 	
       
  2491 	// Fire a query
       
  2492 	iCalInstanceView->FindInstanceL(
       
  2493 			instanceList, filters, searchTimeRange);
       
  2494 	
       
  2495 	// Check the list count
       
  2496 	if (instanceList.Count()) {
       
  2497 		isEmpty = false;
       
  2498 	} else {
       
  2499 		isEmpty = true;
       
  2500 	}
       
  2501 	CleanupStack::PopAndDestroy();
       
  2502 	return isEmpty;
       
  2503 }
       
  2504 
       
  2505 /*!
  2439 	Returns the minimum time supported.
  2506 	Returns the minimum time supported.
  2440 
  2507 
  2441 	\return QDateTime holding the minimum supported time.
  2508 	\return QDateTime holding the minimum supported time.
  2442  */
  2509  */
  2443 QDateTime AgendaUtilPrivate::minTime()
  2510 QDateTime AgendaUtilPrivate::minTime()
  2477 	QDateTime maximumDateTime(date, time);
  2544 	QDateTime maximumDateTime(date, time);
  2478 
  2545 
  2479 	return maximumDateTime;
  2546 	return maximumDateTime;
  2480 }
  2547 }
  2481 
  2548 
       
  2549 /*!
       
  2550     Returns true if entry repeats on workdays else false
       
  2551 
       
  2552     \return true if entry repeats on workdays else false
       
  2553  */
       
  2554 bool AgendaUtilPrivate::isWorkdaysRepeatingEntry(
       
  2555 											const AgendaRepeatRule& repeatRule)
       
  2556 {
       
  2557 	bool status = true;
       
  2558 	int fixedNum = 1;
       
  2559 	int ruleday = 0;
       
  2560 	HbExtendedLocale locale = HbExtendedLocale::system();
       
  2561 
       
  2562 	QString workDaysString = locale.workDays();
       
  2563 	bool ok;
       
  2564 	uint workDays = workDaysString.toUInt(&ok, 2);
       
  2565 	if (!ok) {
       
  2566 		return false;
       
  2567 	}
       
  2568 	QList<AgendaRepeatRule::Day> weekDaysFromRule = repeatRule.byDay();
       
  2569 
       
  2570 	QList<AgendaRepeatRule::Day> weekDaysFromLocale;
       
  2571 
       
  2572 	// "workDays" is a bit mask of seven bits indicating (by being set) which days are workdays. 
       
  2573 	// The least significant bit corresponds to Monday, the next bit to Tuesday and so on. 
       
  2574 	// "workDays" is converted into weekDaysFromLocale for comparing with "weekDaysFromRule".
       
  2575 	for (TInt i = 0; i < KNoOfDaysInWeek; i++) {
       
  2576 		ruleday = fixedNum << i;
       
  2577 		if (workDays & ruleday) {
       
  2578 			weekDaysFromLocale.append((AgendaRepeatRule::Day) i);
       
  2579 		}
       
  2580 	}
       
  2581 
       
  2582 	// Checks whether the device "workdays" are same as the event's repeat days.
       
  2583 	if (weekDaysFromRule.count() == weekDaysFromLocale.count()) {
       
  2584 		for (int i = 0; i < weekDaysFromLocale.count(); i++) {
       
  2585 			if ((int) weekDaysFromLocale[i] != (int) weekDaysFromRule[i]) {
       
  2586 				status = false;
       
  2587 				break;
       
  2588 			}
       
  2589 		}
       
  2590 	} else {
       
  2591 		status = false;
       
  2592 	}
       
  2593 
       
  2594 	return status;
       
  2595 
       
  2596 }
  2482 /*!
  2597 /*!
  2483 	Creates an AgendaEntry object from a given CCalEntry and CCalInstance.
  2598 	Creates an AgendaEntry object from a given CCalEntry and CCalInstance.
  2484 
  2599 
  2485 	\param calEntry Reference to a CCalEntry.
  2600 	\param calEntry Reference to a CCalEntry.
  2486 	\param instance A CCalInstance.
  2601 	\param instance A CCalInstance.
  2573 		attendee.setStatus(
  2688 		attendee.setStatus(
  2574 				static_cast<AgendaAttendee::StatusType>(
  2689 				static_cast<AgendaAttendee::StatusType>(
  2575 						calAttendees[i]->StatusL()));
  2690 						calAttendees[i]->StatusL()));
  2576 		entry.addAttendee(attendee);
  2691 		entry.addAttendee(attendee);
  2577 	}
  2692 	}
  2578 	CleanupStack::PopAndDestroy(&calAttendees);
  2693 	CleanupStack::Pop(&calAttendees);
  2579 
  2694 
  2580 	// Categories.
  2695 	// Categories.
  2581 	RPointerArray<CCalCategory> calCategories = calEntry.CategoryListL();
  2696 	RPointerArray<CCalCategory> calCategories = calEntry.CategoryListL();
  2582 	CleanupClosePushL(calCategories);
  2697 	CleanupClosePushL(calCategories);
  2583 
  2698 
  2612 		entry.setAlarm(alarm);
  2727 		entry.setAlarm(alarm);
  2613 		CleanupStack::PopAndDestroy(calAlarm);
  2728 		CleanupStack::PopAndDestroy(calAlarm);
  2614 	}
  2729 	}
  2615 
  2730 
  2616 	// Repear rule.
  2731 	// Repear rule.
  2617 	TCalRRule rRule;
  2732 	TCalRRule calRRule;
  2618 	calEntry.GetRRuleL(rRule);
  2733 	calEntry.GetRRuleL(calRRule);
  2619 	if (rRule.Type() != TCalRRule::EInvalid) {
  2734 	if (calRRule.Type() != TCalRRule::EInvalid) {
  2620 		AgendaRepeatRule repeatRule;
  2735 		AgendaRepeatRule agendaRepeatRule =
  2621 		RArray<TDay> days;
  2736 		        createAgendaRRuleFromTCalRRule(calRRule);
  2622 		rRule.GetByDayL(days);
       
  2623 		QList<AgendaRepeatRule::Day> qDays;
       
  2624 		for (int i = 0; i < days.Count(); i++) {
       
  2625 			qDays.append(AgendaRepeatRule::Day(days[i]));
       
  2626 		}
       
  2627 		repeatRule.setByDay(qDays);
       
  2628 
       
  2629 		RArray<TMonth> months;
       
  2630 		rRule.GetByMonthL(months);
       
  2631 		QList<AgendaRepeatRule::Month> qMonths;
       
  2632 		for (int i = 0; i < months.Count(); i++) {
       
  2633 			qMonths.append(AgendaRepeatRule::Month(months[i]));
       
  2634 		}
       
  2635 		repeatRule.setByMonth(qMonths);
       
  2636 
       
  2637 		RArray<TInt> monthDays;
       
  2638 		rRule.GetByMonthDayL(monthDays);
       
  2639 		QList<int> qMonthDays;
       
  2640 		for (int i = 0; i < monthDays.Count(); i++) {
       
  2641 			qMonthDays.append(monthDays[i]);
       
  2642 		}
       
  2643 		repeatRule.setByMonthDay(qMonthDays);
       
  2644 
       
  2645 		repeatRule.setType((AgendaRepeatRule::RuleType)(rRule.Type()));
       
  2646 		repeatRule.setInterval(rRule.Interval());
       
  2647 		TCalTime time = rRule.Until();
       
  2648 		TTime untilTime = time.TimeUtcL();
       
  2649 		QDate qUntilTime(
       
  2650 				untilTime.DateTime().Year(),
       
  2651 				untilTime.DateTime().Month() + 1,
       
  2652 				untilTime.DateTime().Day() + 1);
       
  2653 		repeatRule.setUntil(qUntilTime);
       
  2654 
       
  2655 		TCalTime dayStart = rRule.DtStart();
       
  2656 		TTime ruleStart = dayStart.TimeUtcL();
       
  2657 		QDate qRuleStart(
       
  2658 				untilTime.DateTime().Year(),
       
  2659 				untilTime.DateTime().Month() + 1,
       
  2660 				untilTime.DateTime().Day() + 1);
       
  2661 		repeatRule.setRepeatRuleStart(qRuleStart);
       
  2662 
       
  2663 		TDay wkDay = rRule.WkSt();
       
  2664 		AgendaRepeatRule::Day qWkDay = (AgendaRepeatRule::Day)wkDay;
       
  2665 		repeatRule.setWeekStart(qWkDay);
       
  2666 
       
  2667 		// Set the rule now.
  2737 		// Set the rule now.
  2668 		entry.setRepeatRule(repeatRule);
  2738 		entry.setRepeatRule(agendaRepeatRule);
  2669 	}
  2739 	}
  2670 
  2740 
  2671 	// Get the RDates.
  2741 	// Get the RDates.
  2672 	RArray<TCalTime> rDateList;
  2742 	RArray<TCalTime> rDateList;
  2673 	calEntry.GetRDatesL(rDateList);
  2743 	calEntry.GetRDatesL(rDateList);
  2732 						completionTimeInlocal.DateTime().Hour(),
  2802 						completionTimeInlocal.DateTime().Hour(),
  2733 						completionTimeInlocal.DateTime().Minute(),
  2803 						completionTimeInlocal.DateTime().Minute(),
  2734 						completionTimeInlocal.DateTime().Second(), 0));
  2804 						completionTimeInlocal.DateTime().Second(), 0));
  2735 	entry.setCompletedDateTime(completionDateTime);
  2805 	entry.setCompletedDateTime(completionDateTime);
  2736 
  2806 
       
  2807 	// Set the dtStamp time for agenda entry. Currently dtstamp is used as
       
  2808 	// creation time for the entry type ENote.
       
  2809 	TCalTime dtStampTime = calEntry.DTStampL();
       
  2810 	TTime dtStampTimeInLocal = dtStampTime.TimeLocalL();
       
  2811 	QDateTime dtStampDateTime;
       
  2812 	if (dtStampTimeInLocal != Time::NullTTime()) {
       
  2813 		dtStampDateTime.setDate(
       
  2814 				QDate(
       
  2815 					dtStampTimeInLocal.DateTime().Year(),
       
  2816 					dtStampTimeInLocal.DateTime().Month() + 1,
       
  2817 					dtStampTimeInLocal.DateTime().Day() + 1));
       
  2818 
       
  2819 		dtStampDateTime.setTime(
       
  2820 				QTime(
       
  2821 					dtStampTimeInLocal.DateTime().Hour(),
       
  2822 					dtStampTimeInLocal.DateTime().Minute(),
       
  2823 					dtStampTimeInLocal.DateTime().Second()));
       
  2824 	}
       
  2825 	entry.setDTStamp(dtStampDateTime);
       
  2826 	
       
  2827 	// Copy the geo value if it has any
       
  2828 	CCalGeoValue* geoValue = calEntry.GeoValueL();
       
  2829 	if (geoValue) {
       
  2830 		AgendaGeoValue entryGeoValue;
       
  2831 		double latitude;
       
  2832 		double longitude;
       
  2833 		geoValue->GetLatLong(latitude, longitude);
       
  2834 		entryGeoValue.setLatLong(latitude, longitude);
       
  2835 		
       
  2836 		// Set it to entry
       
  2837 		entry.setGeoValue(entryGeoValue);
       
  2838 		delete geoValue;
       
  2839 	}
       
  2840 	
  2737 	// Return the entry.
  2841 	// Return the entry.
  2738 	return entry;
  2842 	return entry;
  2739 }
  2843 }
  2740 
  2844 
  2741 bool AgendaUtilPrivate::addAttendeesToEntry(
  2845 bool AgendaUtilPrivate::addAttendeesToEntry(
  3199     return ret;
  3303     return ret;
  3200 }
  3304 }
  3201 
  3305 
  3202 RepeatIndex AgendaUtilPrivate::getRepeatIndex(const CCalEntry& aEntry)
  3306 RepeatIndex AgendaUtilPrivate::getRepeatIndex(const CCalEntry& aEntry)
  3203 {
  3307 {
  3204 	RepeatIndex repeatIndex( notRepeated );
  3308 	RepeatIndex repeatIndex(notRepeated);
  3205 
  3309 
  3206     TCalRRule rrule;
  3310 	TCalRRule rrule;
  3207 
  3311 
  3208     if( aEntry.GetRRuleL( rrule) )
  3312 	if (aEntry.GetRRuleL(rrule)) {
  3209         {
  3313 		TCalRRule::TType type(rrule.Type());
  3210         TCalRRule::TType type( rrule.Type() );
  3314 		TInt repeatInterval(rrule.Interval());
  3211         TInt repeatInterval( rrule.Interval() );
  3315 
  3212 
  3316 		// If repeat type of current note is not supported in Calendar,
  3213         // If repeat type of current note is not supported in Calendar,
  3317 		// default repeat value is "Other".
  3214         // default repeat value is "Other".
  3318 		repeatIndex = repeatOther;
  3215         repeatIndex = repeatOther;
  3319 
  3216 
  3320 		switch (type) {
  3217         switch( type )
  3321 			case TCalRRule::EDaily: {
  3218             {
  3322 				switch (repeatInterval) {
  3219             case TCalRRule::EDaily:
  3323 					case 1:
  3220                 {
  3324 						repeatIndex = repeatDaily;
  3221                 switch (repeatInterval)
  3325 						break;
  3222                     {
  3326 					case 7:
  3223                     case 1:   repeatIndex = repeatDaily;     break;
  3327 						repeatIndex = repeatWeekly;
  3224                     case 7:   repeatIndex = repeatWeekly;    break;
  3328 						break;
  3225                     case 14:  repeatIndex = repeatBiWeekly;  break;
  3329 					case 14:
  3226                     default:                                  break;
  3330 						repeatIndex = repeatBiWeekly;
  3227                     }
  3331 						break;
  3228                 break;
  3332 					default:
  3229                 }
  3333 						break;
  3230 
  3334 				}
  3231             case TCalRRule::EWeekly:
  3335 				break;
  3232                 {
  3336 			}
  3233                 RArray<TDay> weekDays(7);
  3337 
  3234                 rrule.GetByDayL( weekDays );
  3338 			case TCalRRule::EWeekly: {
  3235 
  3339 				AgendaRepeatRule agendaRepeatRule =
  3236                 if( weekDays.Count() == 1 ) // FIXME: AL - is this necessary?
  3340 				        createAgendaRRuleFromTCalRRule(rrule);
  3237                     {
  3341 				bool isWorkdaysRepeating =
  3238                     switch( repeatInterval )
  3342 				        isWorkdaysRepeatingEntry(agendaRepeatRule);
  3239                         {
  3343 
  3240                         case 1:   repeatIndex = repeatWeekly;    break;
  3344 				if (isWorkdaysRepeating) {
  3241                         case 2:   repeatIndex = repeatBiWeekly;  break;
  3345 					repeatIndex = repeatWorkdays;
  3242                         default:                                  break;
  3346 				} else {
  3243                         }
  3347 					RArray<TDay> weekDays(7);
  3244                     }
  3348 					rrule.GetByDayL(weekDays);
  3245 
  3349 					if (weekDays.Count() == 1) // FIXME: AL - is this necessary?
  3246                 weekDays.Close();
  3350 					{
  3247 
  3351 						switch (repeatInterval) {
  3248                 break;
  3352 							case 1:
  3249                 }
  3353 								repeatIndex = repeatWeekly;
  3250 
  3354 								break;
  3251             case TCalRRule::EMonthly:
  3355 							case 2:
  3252                 {
  3356 								repeatIndex = repeatBiWeekly;
  3253                 RArray<TInt> monthDays(31);
  3357 								break;
  3254                 rrule.GetByMonthDayL ( monthDays );
  3358 							default:
  3255 
  3359 								break;
  3256                 if( monthDays.Count() == 1) // FIXME: AL - is this necessary?
  3360 						}
  3257                     {
  3361 					}
  3258                     switch( repeatInterval )
  3362 
  3259                         {
  3363 					weekDays.Close();
  3260                         case 1:  repeatIndex = repeatMonthly;  break;
  3364 				}
  3261                         // If interval of repeat is 12 months, 
  3365 				break;
  3262                         // every year is shown in Note Editor, 
  3366 			}
  3263                         // because it means yearly repeat.
  3367 
  3264                         case 12:  repeatIndex = repeatYearly;   break;
  3368 			case TCalRRule::EMonthly: {
  3265                         default:                                 break;
  3369 				RArray<TInt> monthDays(31);
  3266                         }
  3370 				rrule.GetByMonthDayL(monthDays);
  3267                     }
  3371 
  3268 
  3372 				if (monthDays.Count() == 1) // FIXME: AL - is this necessary?
  3269                 monthDays.Close();
  3373 				{
  3270 
  3374 					switch (repeatInterval) {
  3271                 break;
  3375 						case 1:
  3272                 }
  3376 							repeatIndex = repeatMonthly;
  3273             case TCalRRule::EYearly:
  3377 							break;
  3274                 {
  3378 							// If interval of repeat is 12 months, 
  3275                 if( repeatInterval == 1 )
  3379 							// every year is shown in Note Editor, 
  3276                     {
  3380 							// because it means yearly repeat.
  3277                     repeatIndex = repeatYearly;
  3381 						case 12:
  3278                     }
  3382 							repeatIndex = repeatYearly;
  3279                 break;
  3383 							break;
  3280                 }
  3384 						default:
  3281 
  3385 							break;
  3282             default:
  3386 					}
  3283                 {
  3387 				}
  3284                 // If repeat type of current note is not supported in Calendar,
  3388 
  3285                 // default repeat value is "Other".
  3389 				monthDays.Close();
  3286                 repeatIndex = repeatOther;
  3390 
  3287                 break;
  3391 				break;
  3288                 }
  3392 			}
  3289             }
  3393 			case TCalRRule::EYearly: {
  3290         }
  3394 				if (repeatInterval == 1) {
  3291     return repeatIndex;
  3395 					repeatIndex = repeatYearly;
       
  3396 				}
       
  3397 				break;
       
  3398 			}
       
  3399 
       
  3400 			default: {
       
  3401 				// If repeat type of current note is not supported in Calendar,
       
  3402 				// default repeat value is "Other".
       
  3403 				repeatIndex = repeatOther;
       
  3404 				break;
       
  3405 			}
       
  3406 		}
       
  3407 	}
       
  3408 	return repeatIndex;
  3292 }
  3409 }
  3293 
  3410 
  3294 TTime AgendaUtilPrivate::getPreviousInstanceForRepeatOther(CCalEntry& entry, 
  3411 TTime AgendaUtilPrivate::getPreviousInstanceForRepeatOther(CCalEntry& entry, 
  3295 									const CalCommon::TCalTimeRange& timeRange)
  3412 									const CalCommon::TCalTimeRange& timeRange)
  3296 {
  3413 {
  3508 			{
  3625 			{
  3509 			// START TIME
  3626 			// START TIME
  3510 			// Keep aDst's start date, but copy the start time (h/m/s) from aSrc to aDst.
  3627 			// Keep aDst's start date, but copy the start time (h/m/s) from aSrc to aDst.
  3511 			TTime zero(TInt64(0));
  3628 			TTime zero(TInt64(0));
  3512 			TTime srcStartTime = src.StartTimeL().TimeUtcL();
  3629 			TTime srcStartTime = src.StartTimeL().TimeUtcL();
  3513 			TTime dtStartDay = zero + dst.StartTimeL().TimeUtcL().DaysFrom(zero);
  3630 			TTime srcStartDay = zero + src.StartTimeL().TimeUtcL().DaysFrom(zero);
  3514 			TTimeIntervalMinutes dtStartTimeOfDay;
  3631 			TTime dstStartDay = zero + dst.StartTimeL().TimeUtcL().DaysFrom(zero);
  3515 			srcStartTime.MinutesFrom(dtStartDay, dtStartTimeOfDay);
  3632 			TTimeIntervalMinutes dstStartTimeOfDay;
       
  3633 			srcStartTime.MinutesFrom(srcStartDay, dstStartTimeOfDay);
  3516 	
  3634 	
  3517 			TCalTime startTime;
  3635 			TCalTime startTime;
  3518 			startTime.SetTimeUtcL( dtStartDay + (TTimeIntervalMinutes)dtStartTimeOfDay );
  3636 			startTime.SetTimeUtcL( dstStartDay + (TTimeIntervalMinutes)dstStartTimeOfDay );
  3519 	
  3637 	
  3520 	
  3638 	
  3521 			TTimeIntervalMinutes duration;
  3639 			TTimeIntervalMinutes duration;
  3522 			src.EndTimeL().TimeUtcL().MinutesFrom(src.StartTimeL().TimeUtcL(), duration);
  3640 			src.EndTimeL().TimeUtcL().MinutesFrom(src.StartTimeL().TimeUtcL(), duration);
  3523 	
  3641 	
  3536 			break;
  3654 			break;
  3537 		case EntryDifferentDescription:
  3655 		case EntryDifferentDescription:
  3538 			dst.SetDescriptionL(src.DescriptionL());
  3656 			dst.SetDescriptionL(src.DescriptionL());
  3539 			break;
  3657 			break;
  3540 		case EntryDifferentLocation:
  3658 		case EntryDifferentLocation:
       
  3659 		{
  3541 			dst.SetLocationL(src.LocationL());
  3660 			dst.SetLocationL(src.LocationL());
       
  3661 			CCalGeoValue* geoValue = src.GeoValueL();
       
  3662 			if (geoValue) {
       
  3663 				dst.SetGeoValueL(*geoValue);
       
  3664 				delete geoValue;
       
  3665 			}
  3542 			break;
  3666 			break;
       
  3667 		}
  3543 		default:
  3668 		default:
  3544 			break;
  3669 			break;
  3545 	}
  3670 	}
  3546 }
  3671 }
  3547 
  3672 
  3621     toRet.SetTimeUtcL(theTime);
  3746     toRet.SetTimeUtcL(theTime);
  3622     
  3747     
  3623     return toRet;
  3748     return toRet;
  3624 }
  3749 }
  3625 
  3750 
       
  3751 bool AgendaUtilPrivate::endsAtStartOfDay( CCalInstance* instance,
       
  3752                                           const TTime& day )
       
  3753 {
       
  3754 	TTime zero(TInt64(0));
       
  3755 	TTime dayStart = zero + day.DaysFrom( zero );
       
  3756     const TTime startTime( instance->StartTimeL().TimeLocalL());
       
  3757     const TTime endTime( instance->EndTimeL().TimeLocalL());
       
  3758 
       
  3759     const bool result( endTime > startTime && endTime == dayStart );
       
  3760 
       
  3761     return result;
       
  3762 }
       
  3763 	
       
  3764 AgendaRepeatRule AgendaUtilPrivate::createAgendaRRuleFromTCalRRule(
       
  3765 															TCalRRule &calRRule)
       
  3766 {
       
  3767 	AgendaRepeatRule agendaRepeatRule;
       
  3768 	RArray<TDay> days;
       
  3769 	calRRule.GetByDayL(days);
       
  3770 	QList<AgendaRepeatRule::Day> qDays;
       
  3771 	for (int i = 0; i < days.Count(); i++) {
       
  3772 		qDays.append(AgendaRepeatRule::Day(days[i]));
       
  3773 	}
       
  3774 	agendaRepeatRule.setByDay(qDays);
       
  3775 
       
  3776 	RArray<TMonth> months;
       
  3777 	calRRule.GetByMonthL(months);
       
  3778 	QList<AgendaRepeatRule::Month> qMonths;
       
  3779 	for (int i = 0; i < months.Count(); i++) {
       
  3780 		qMonths.append(AgendaRepeatRule::Month(months[i]));
       
  3781 	}
       
  3782 	agendaRepeatRule.setByMonth(qMonths);
       
  3783 
       
  3784 	RArray<TInt> monthDays;
       
  3785 	calRRule.GetByMonthDayL(monthDays);
       
  3786 	QList<int> qMonthDays;
       
  3787 	for (int i = 0; i < monthDays.Count(); i++) {
       
  3788 		qMonthDays.append(monthDays[i]);
       
  3789 	}
       
  3790 	agendaRepeatRule.setByMonthDay(qMonthDays);
       
  3791 
       
  3792 	agendaRepeatRule.setType((AgendaRepeatRule::RuleType) (calRRule.Type()));
       
  3793 	agendaRepeatRule.setInterval(calRRule.Interval());
       
  3794 	TCalTime time = calRRule.Until();
       
  3795 	TTime untilTime = time.TimeUtcL();
       
  3796 	QDateTime repeatUntil(QDate(untilTime.DateTime().Year(), 
       
  3797 	                     untilTime.DateTime().Month() + 1, 
       
  3798 	                     untilTime.DateTime().Day() + 1),
       
  3799 	                     QTime(untilTime.DateTime().Hour(),
       
  3800 	                     untilTime.DateTime().Minute()));
       
  3801 	agendaRepeatRule.setUntil(repeatUntil);
       
  3802 
       
  3803 	TCalTime dayStart = calRRule.DtStart();
       
  3804 	TDateTime ruleStart = dayStart.TimeUtcL().DateTime();
       
  3805 	QDateTime qRuleStart(QDate(ruleStart.Year(), ruleStart.Month() + 1, 
       
  3806 	          ruleStart.Day() + 1),QTime(ruleStart.Hour(), ruleStart.Minute()));
       
  3807 	agendaRepeatRule.setRepeatRuleStart(qRuleStart);
       
  3808 
       
  3809 	TDay wkDay = calRRule.WkSt();
       
  3810 	AgendaRepeatRule::Day qWkDay = (AgendaRepeatRule::Day) wkDay;
       
  3811 	agendaRepeatRule.setWeekStart(qWkDay);
       
  3812 	
       
  3813 	return agendaRepeatRule;
       
  3814 
       
  3815 }
       
  3816 
       
  3817 TCalRRule AgendaUtilPrivate::createTCalRRuleFromAgendaRRule(
       
  3818 												AgendaRepeatRule &agendaRRule)
       
  3819 {
       
  3820 	TCalRRule
       
  3821 	        repeatRule(
       
  3822 	                   static_cast<TCalRRule::TType> (agendaRRule.type()));
       
  3823 	QDateTime ruleStartDateTime = agendaRRule.repeatRuleStart();
       
  3824 	TDateTime ruleStartCalendarDateTime(ruleStartDateTime.date().year(), 
       
  3825 	                 static_cast<TMonth> (ruleStartDateTime.date().month() - 1), 
       
  3826 	                 ruleStartDateTime.date().day() - 1,
       
  3827 	                 ruleStartDateTime.time().hour(),
       
  3828 	                 ruleStartDateTime.time().minute(),
       
  3829 	                 0, 
       
  3830 	                 0);
       
  3831 	
       
  3832 	TCalTime ruleStartCalTime;
       
  3833 	ruleStartCalTime.SetTimeLocalL(TTime(ruleStartCalendarDateTime));
       
  3834 	repeatRule.SetDtStart(ruleStartCalTime);
       
  3835 	repeatRule.SetInterval(agendaRRule.interval());
       
  3836 	QDateTime repeatUntilDate = agendaRRule.until();
       
  3837 	TDateTime repeatTill(repeatUntilDate.date().year(), 
       
  3838 	                   static_cast<TMonth> (repeatUntilDate.date().month() - 1),
       
  3839 	                   repeatUntilDate.date().day() - 1, 
       
  3840 	                   repeatUntilDate.time().hour(), 
       
  3841 	                   repeatUntilDate.time().minute(), 
       
  3842 	                   0, 
       
  3843 	                   0);
       
  3844 
       
  3845 	TCalTime ruleRepeatTillTime;
       
  3846 	ruleRepeatTillTime.SetTimeLocalL(TTime(repeatTill));
       
  3847 	repeatRule.SetUntil(ruleRepeatTillTime);
       
  3848 
       
  3849 	QList<AgendaRepeatRule::Day> qDays = agendaRRule.byDay();
       
  3850 	RArray<TDay> days;
       
  3851 	for (int i = 0; i < qDays.count(); i++) {
       
  3852 		days.Append(TDay(qDays[i]));
       
  3853 	}
       
  3854 	if (days.Count() > 0) {
       
  3855 		repeatRule.SetByDay(days);
       
  3856 	}
       
  3857 
       
  3858 	QList<int> qmonthDay = agendaRRule.byMonthDay();
       
  3859 	RArray<TInt> monthDay;
       
  3860 	for (int i = 0; i < qmonthDay.count(); i++) {
       
  3861 		monthDay.Append(qmonthDay[i] - 1);
       
  3862 	}
       
  3863 	if (monthDay.Count() > 0) {
       
  3864 		repeatRule.SetByMonthDay(monthDay);
       
  3865 	}
       
  3866 
       
  3867 	QList<AgendaRepeatRule::Month> qMonth = agendaRRule.byMonth();
       
  3868 	RArray<TMonth> month;
       
  3869 	for (int i = 0; i < qMonth.count(); i++) {
       
  3870 		month.Append(TMonth(qMonth[i]));
       
  3871 	}
       
  3872 	if (month.Count() > 0) {
       
  3873 		repeatRule.SetByMonth(month);
       
  3874 	}
       
  3875 	
       
  3876 	return repeatRule;
       
  3877 }
       
  3878 
  3626 // End of file  --Don't remove this.
  3879 // End of file  --Don't remove this.