29 #include <KCalCore/Calendar>
30 #include <KCalCore/Event>
31 using namespace KCalCore;
33 #include <KCalUtils/IncidenceFormatter>
34 using namespace KCalUtils;
37 #include <KLocalizedString>
38 #include <KSystemTimeZones>
42 #include <QStringList>
44 bool SummaryEventInfo::mShowBirthdays =
true;
45 bool SummaryEventInfo::mShowAnniversaries =
true;
49 static bool eventLessThan(
const KCalCore::Event::Ptr &event1,
const KCalCore::Event::Ptr &event2)
51 KDateTime kdt1 =
sDateTimeByUid.value(event1->instanceIdentifier());
52 KDateTime kdt2 =
sDateTimeByUid.value(event2->instanceIdentifier());
53 if (kdt1.date() < kdt2.date()) {
55 }
else if (kdt1.date() > kdt2.date()) {
58 if (kdt1.isDateOnly() && !kdt2.isDateOnly()) {
60 }
else if (!kdt1.isDateOnly() && kdt2.isDateOnly()) {
65 }
else if (kdt1 < kdt2) {
68 return event1->summary() > event2->summary();
75 bool showAnniversaries )
77 mShowBirthdays = showBirthdays;
78 mShowAnniversaries = showAnniversaries;
81 bool SummaryEventInfo::skip(
const KCalCore::Event::Ptr &event )
86 if ( !mShowBirthdays &&
90 if ( !mShowAnniversaries &&
98 void SummaryEventInfo::dateDiff(
const QDate &
date,
int &days )
117 int offset = currentDate.
daysTo( eventDate );
135 KCalCore::Calendar *calendar )
137 KCalCore::Event::List allEvents = calendar->events();
138 KCalCore::Event::List events;
139 KDateTime::Spec spec = KSystemTimeZones::local();
140 const KDateTime currentDateTime = KDateTime::currentDateTime( spec );
141 const QDate currentDate = currentDateTime.date();
145 for (
int i=0; i<allEvents.count(); ++i) {
146 KCalCore::Event::Ptr
event = allEvents.at(i);
150 KDateTime eventStart =
event->dtStart().toTimeSpec(spec);
151 KDateTime eventEnd =
event->dtEnd().toTimeSpec(spec);
152 if (event->recurs()) {
153 KCalCore::DateTimeList occurrences =
event->recurrence()->timesInInterval(KDateTime(start, spec), KDateTime(end, spec));
154 if (!occurrences.isEmpty()) {
156 sDateTimeByUid.insert(event->instanceIdentifier(), occurrences.first());
159 if ( ( end >= eventStart.date() && start <= eventEnd.date() ) ||
160 ( start >= eventStart.date() && end <= eventEnd.date() ) ) {
162 if ( eventStart.date() < start ) {
163 sDateTimeByUid.insert(event->instanceIdentifier(), KDateTime(start,spec));
174 KCalCore::Event::Ptr
ev;
175 KCalCore::Event::List::ConstIterator itEnd = events.constEnd();
176 for ( KCalCore::Event::List::ConstIterator it=events.constBegin(); it != itEnd; ++it ) {
181 const KDateTime eventStart = ev->dtStart().toTimeSpec(spec);
182 const KDateTime eventEnd = ev->dtEnd().toTimeSpec(spec);
185 QDate startOfMultiday = eventStart.date();
186 if ( startOfMultiday < currentDate ) {
187 startOfMultiday = currentDate;
189 bool firstDayOfMultiday = ( start == startOfMultiday );
192 eventInfoList.append( summaryEvent );
195 summaryEvent->
ev =
ev;
199 QDate sD = occurrenceStartDate;
200 if (currentDate >= sD) {
201 str = i18nc(
"the appointment is today",
"Today" );
203 }
else if ( sD == currentDate.
addDays(1) ) {
204 str = i18nc(
"the appointment is tomorrow",
"Tomorrow" );
206 str = KGlobal::locale()->formatDate( sD, KLocale::FancyLongDate );
210 if ( ev->isMultiDay() ) {
211 dayof = eventStart.date().daysTo(start)+1;
212 dayof = dayof <= 0 ? 1 : dayof;
213 span = eventStart.date().daysTo(eventEnd.date()) + 1;
217 if ( ev->isMultiDay() && ev->allDay() && firstDayOfMultiday && span > 1 ) {
218 str = IncidenceFormatter::dateToString( ev->dtStart(),
false, spec ) +
220 IncidenceFormatter::dateToString( ev->dtEnd(),
false, spec );
226 const int daysTo = currentDate.
daysTo(occurrenceStartDate);
228 str = i18np(
"in 1 day",
"in %1 days", daysTo );
230 if ( !ev->allDay() ) {
232 if ( !ev->recurs() ) {
233 secs = currentDateTime.secsTo( ev->dtStart() );
235 KDateTime kdt( start,
QTime( 0, 0, 0 ), spec );
236 kdt = kdt.addSecs( -1 );
237 KDateTime next = ev->recurrence()->getNextDateTime( kdt );
238 secs = currentDateTime.secsTo( next );
241 str = i18nc(
"eg. in 1 hour 2 minutes",
"in " );
242 int hours = secs / 3600;
244 str += i18ncp(
"use abbreviation for hour to keep the text short",
245 "1 hr",
"%1 hrs", hours );
247 secs -= ( hours * 3600 );
249 int mins = secs / 60;
251 str += i18ncp(
"use abbreviation for minute to keep the text short",
252 "1 min",
"%1 mins", mins );
258 str = i18n(
"all day" );
264 str = ev->richSummary();
265 if ( ev->isMultiDay() && !ev->allDay() ) {
283 if ( !ev->allDay() ) {
284 QTime sST = eventStart.time();
285 QTime sET = eventEnd.time();
286 if ( ev->isMultiDay() ) {
287 if ( eventStart.date() < start ) {
290 if ( eventEnd.date() > end ) {
291 sET =
QTime( 23, 59 );
294 str = i18nc(
"Time from - to",
"%1 - %2",
295 KGlobal::locale()->formatTime( sST ),
296 KGlobal::locale()->formatTime( sET ) );
301 if ( ev->recurs() ) {
302 KDateTime kdt( start,
QTime( 0, 0, 0 ), spec );
303 kdt = kdt.addSecs( -1 );
304 KDateTime next = ev->recurrence()->getNextDateTime( kdt );
305 QString tmp = IncidenceFormatter::dateTimeToString(
306 ev->recurrence()->getNextDateTime( next ), ev->allDay(),
312 i18nc(
"next occurrence",
"Next: %1", tmp ) +
317 return eventInfoList;
321 KCalCore::Calendar *calendar )
int daysTo(const QDate &d) const
static bool eventLessThan(const KCalCore::Event::Ptr &event1, const KCalCore::Event::Ptr &event2)
QString & append(QChar ch)
static QHash< QString, KDateTime > sDateTimeByUid
static void setShowSpecialEvents(bool skipBirthdays, bool skipAnniversaries)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
bool isLeapYear(int year)
static List eventsForRange(const QDate &start, const QDate &end, KCalCore::Calendar *calendar)
static
QString fromLatin1(const char *str, int size)
QDate addDays(int ndays) const
static List eventsForDate(const QDate &date, KCalCore::Calendar *calendar)