agendainterface/agendautil/src/agendautil_p.cpp
changeset 83 5aadd1120515
parent 81 ce92091cbd61
equal deleted inserted replaced
82:dcd0ca396fa1 83:5aadd1120515
   880 
   880 
   881 	iCalInstanceView->FindInstanceL(instanceList, filters, searchTimeRange);
   881 	iCalInstanceView->FindInstanceL(instanceList, filters, searchTimeRange);
   882 
   882 
   883 	// Parse thru the list and mark the dates which have events
   883 	// Parse thru the list and mark the dates which have events
   884 	for (int i = 0; i < instanceList.Count(); i++) {
   884 	for (int i = 0; i < instanceList.Count(); i++) {
   885 		CCalEntry::TType type = instanceList[i]->Entry().EntryTypeL();
   885 	    CCalEntry::TType type = instanceList[i]->Entry().EntryTypeL();
   886 		// Get the start time and end time of the events
   886 	    // Get the start time and end time of the events
   887 		TCalTime startCalTime = instanceList[i]->StartTimeL();
   887 	    TCalTime startCalTime = instanceList[i]->StartTimeL();
   888 		TCalTime endCalTime = instanceList[i]->EndTimeL();
   888 	    TCalTime endCalTime = instanceList[i]->EndTimeL();
   889 		TDateTime startDateTime = startCalTime.TimeLocalL().DateTime();
   889 	    TDateTime startDateTime = startCalTime.TimeLocalL().DateTime();
   890 		TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
   890 	    TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
   891 		QDate startDate(startDateTime.Year(), startDateTime.Month()+1,
   891 	    QDate startDate(startDateTime.Year(), startDateTime.Month()+1,
   892 						startDateTime.Day() + 1);
   892 	            startDateTime.Day() + 1);
   893         QDate endDate(endDateTime.Year(), endDateTime.Month()+1,
   893 	    QDate endDate(endDateTime.Year(), endDateTime.Month()+1,
   894                         endDateTime.Day() + 1);
   894 	            endDateTime.Day() + 1);
   895 		if (type == CCalEntry::EEvent || type == CCalEntry::EAppt ||
   895 	    if (type == CCalEntry::EEvent || type == CCalEntry::EAppt ||
   896 				type == CCalEntry::EReminder) {
   896 	            type == CCalEntry::EReminder) {
   897 			if(endsAtStartOfDay(instanceList[i], endCalTime.TimeLocalL())) {
   897 	        if(endsAtStartOfDay(instanceList[i], endCalTime.TimeLocalL())) {
   898 				TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
   898 	            TDateTime endDateTime = endCalTime.TimeLocalL().DateTime();
   899 				// prevent problems with items ending tomorrow at 00:00
   899 	            // prevent problems with items ending tomorrow at 00:00
   900 				endDateTime.SetMinute(endDateTime.Minute() - 1);
   900 	            endDateTime.SetMinute(endDateTime.Minute() - 1);
   901 				TTime time(endDateTime);
   901 	            TTime time(endDateTime);
   902 				// If it is ending before the start of the grid 
   902 	            endDate = endDate.addDays(-1);
   903 				if (time <= startDateForInstanceSearch.TimeLocalL()) {
   903 	            // If it is ending before the start of the grid 
   904 					continue;
   904 	            if (time <= startDateForInstanceSearch.TimeLocalL()) {
   905 				}
   905 	                continue;
   906 			}
   906 	            }
   907         // Mark the required dates frm start date to end date
   907 	        }
   908         int numOfDays = 0;
   908 	        // Mark the required dates frm start date to end date
   909         //check if the start date of the entry is before the start day of the grid
   909 	        int numOfDays = 0;
   910         if(startDate < rangeStart.date()){
   910 	        //check if the start date of the entry is before the start day of the grid
   911             if(endDate<=rangeEnd.date()){
   911 	        if(startDate < rangeStart.date()){
   912                 //if the end date of entry is lying in the grid ,
   912 	            if(endDate<=rangeEnd.date()){
   913                 //then mark the entry from start day of the grid to the end date of the entry
   913 	                //if the end date of entry is lying in the grid ,
   914                 numOfDays = rangeStart.date().daysTo(endDate);
   914 	                //then mark the entry from start day of the grid to the end date of the entry
   915             }
   915 	                numOfDays = rangeStart.date().daysTo(endDate);
   916             else{
   916 	            }
   917                 //if end date of the entry is greater then the last date of grid, 
   917 	            else{
   918                 //then mark all the date of the grid with the entry 
   918 	                //if end date of the entry is greater then the last date of grid, 
   919                numOfDays = rangeStart.daysTo(rangeEnd);
   919 	                //then mark all the date of the grid with the entry 
   920             }
   920 	                numOfDays = rangeStart.daysTo(rangeEnd);
   921             // Check if the event is all-day
   921 	            }
   922             if (instanceList[i]->Entry().EntryTypeL() == CCalEntry::EEvent) {
   922 	            //start the entries from the first day of the grid
   923                 // no need to consider the date on which it ends
   923 	            for (int j = 0; j <= numOfDays; j++) {
   924                 // reduce days count by 1
   924 	                QDate date = rangeStart.date().addDays(j);
   925                 numOfDays--;
   925 	                if (date <= rangeEnd.date()) {
   926                 }
   926 	                    dates.append(date);
   927             //start the entries from the first day of the grid
   927 	                } else {
   928             for (int j = 0; j <= numOfDays; j++) {
   928 	                    break;
   929                 QDate date = rangeStart.date().addDays(j);
   929 	                }
   930                 if (date <= rangeEnd.date()) {
   930 	            }
   931                     dates.append(date);
   931 	        }
   932                 } else {
   932 	        //if the start date of the entry is lying inside the grid
   933                     break;
   933 	        else{
   934                 }
   934 	            if(endDate<=rangeEnd.date()){
   935             }
   935 	                //if the end date of entry is lying in the grid ,
   936         }
   936 	                //then mark the entry from start date of the entry to the end date of the entry
   937         //if the start date of the entry is lying inside the grid
   937 	                numOfDays = startDate.daysTo(endDate);
   938         else{
   938 	            }
   939             if(endDate<=rangeEnd.date()){
   939 	            else{
   940                 //if the end date of entry is lying in the grid ,
   940 	                //if end date of the entry is greater then the last date of grid, 
   941                 //then mark the entry from start date of the entry to the end date of the entry
   941 	                //then mark all the date from start date of the entry to the end date of the grid 
   942                 numOfDays = startDate.daysTo(endDate);
   942 	                numOfDays = startDate.daysTo(rangeEnd.date()); 
   943             }
   943 	            }
   944             else{
   944 	            for (int j = 0; j <= numOfDays; j++) {
   945                 //if end date of the entry is greater then the last date of grid, 
   945 	                QDate date = startDate.addDays(j);
   946                 //then mark all the date from start date of the entry to the end date of the grid 
   946 	                if (date <= rangeEnd.date()) {
   947                 numOfDays = startDate.daysTo(rangeEnd.date()); 
   947 	                    dates.append(date);
   948             }
   948 	                } else {
   949             // Check if the event is all-day
   949 	                    break;
   950             if (instanceList[i]->Entry().EntryTypeL() == CCalEntry::EEvent) {
   950 	                }
   951                 // no need to consider the date on which it ends
   951 	            }   
   952                 // reduce days count by 1
   952 	        }
   953                 numOfDays--;
   953 	    } else if (type == CCalEntry::EAnniv) {
   954                 }
   954 	        if (startDate <= rangeEnd.date()) {
   955             for (int j = 0; j <= numOfDays; j++) {
   955 	            dates.append(startDate);
   956                 QDate date = startDate.addDays(j);
   956 	        }
   957                 if (date <= rangeEnd.date()) {
   957 	    } else if (type == CCalEntry::ETodo) {
   958                     dates.append(date);
   958 	        // if start time is less that today, then mark it for today
   959                 } else {
   959 	        if (startDate < QDate::currentDate()) {
   960                     break;
   960 	            dates.append(QDate::currentDate());
   961                 }
   961 	        } else {
   962             }   
   962 	            dates.append(startDate);
   963         }
   963 	        }
   964     } else if (type == CCalEntry::EAnniv) {
   964 	    }
   965         if (startDate <= rangeEnd.date()) {
   965 	}
   966             dates.append(startDate);
       
   967         }
       
   968     } else if (type == CCalEntry::ETodo) {
       
   969             // if start time is less that today, then mark it for today
       
   970             if (startDate < QDate::currentDate()) {
       
   971                 dates.append(QDate::currentDate());
       
   972             } else {
       
   973                 dates.append(startDate);
       
   974             }
       
   975         }
       
   976     }
       
   977     CleanupStack::PopAndDestroy(&instanceList);
   966     CleanupStack::PopAndDestroy(&instanceList);
   978 }
   967 }
   979 
   968 
   980 QList<AgendaEntry> AgendaUtilPrivate::createEntryIdListForDay( QDateTime day,
   969 QList<AgendaEntry> AgendaUtilPrivate::createEntryIdListForDay( QDateTime day,
   981                             AgendaUtil::FilterFlags filter )
   970                             AgendaUtil::FilterFlags filter )
  2137 				TCalTime calTime;
  2126 				TCalTime calTime;
  2138 				QDateTime dateTime = agendaEntry.lastModifiedDateTime();
  2127 				QDateTime dateTime = agendaEntry.lastModifiedDateTime();
  2139 				TDateTime tempDateTime(dateTime.date().year(),
  2128 				TDateTime tempDateTime(dateTime.date().year(),
  2140 						static_cast<TMonth> (dateTime.date().month() - 1),
  2129 						static_cast<TMonth> (dateTime.date().month() - 1),
  2141 						dateTime.date().day() - 1, dateTime.time().hour(),
  2130 						dateTime.date().day() - 1, dateTime.time().hour(),
  2142 						dateTime.time().minute(), 0, 0);
  2131 						dateTime.time().minute(), dateTime.time().second(), 0);
  2143 				TTime tempTime(tempDateTime);
  2132 				TTime tempTime(tempDateTime);
  2144 				calTime.SetTimeLocalL(tempTime);
  2133 				calTime.SetTimeLocalL(tempTime);
  2145 				calEntry.SetLastModifiedDateL(calTime);
  2134 				calEntry.SetLastModifiedDateL(calTime);
  2146 				
  2135 				
  2147 				// Set the dtstamp time.It is used to set the creation time.
  2136 				// Set the dtstamp time.It is used to set the creation time.
  2149 				QDateTime dtStamp = agendaEntry.dtStamp();
  2138 				QDateTime dtStamp = agendaEntry.dtStamp();
  2150 				TDateTime
  2139 				TDateTime
  2151 				creationDateTime(dtStamp.date().year(),
  2140 				creationDateTime(dtStamp.date().year(),
  2152 						static_cast<TMonth> (dtStamp.date().month() - 1),
  2141 						static_cast<TMonth> (dtStamp.date().month() - 1),
  2153 						dtStamp.date().day() - 1, dtStamp.time().hour(),
  2142 						dtStamp.date().day() - 1, dtStamp.time().hour(),
  2154 						dtStamp.time().minute(), 0, 0);
  2143 						dtStamp.time().minute(), dtStamp.time().second(), 0);
  2155 				TTime creationTTime(creationDateTime);
  2144 				TTime creationTTime(creationDateTime);
  2156 				creationCalTime.SetTimeLocalL(creationTTime);
  2145 				creationCalTime.SetTimeLocalL(creationTTime);
  2157 				calEntry.SetDTStampL(creationCalTime);
  2146 				calEntry.SetDTStampL(creationCalTime);
  2158 			} else {
  2147 			} else {
  2159 	
  2148