@@ -444,21 +444,29 @@ void IncidenceHandler::prepareImportedIncidence(KCalCore::Incidence::Ptr inciden
444444 LOG_WARNING (" unable to handle imported non-event incidence; skipping" );
445445 return ;
446446 }
447- KCalCore::Event::Ptr event = incidence.staticCast <KCalCore::Event>();
448447
449- if (event-> allDay ()) {
450- KDateTime dtStart = event-> dtStart ();
451- KDateTime dtEnd = event-> dtEnd ();
448+ switch (incidence-> type ()) {
449+ case KCalCore::IncidenceBase::TypeEvent: {
450+ KCalCore::Event::Ptr event = incidence. staticCast <KCalCore::Event> ();
452451
453- // calendar processing requires all-day events to have a dtEnd
454- if (!dtEnd.isValid ()) {
455- LOG_DEBUG (" Adding DTEND to" << incidence->uid () << " as" << dtStart.toString ());
456- event->setCustomProperty (" buteo" , PROP_DTEND_ADDED_USING_DTSTART , PROP_DTEND_ADDED_USING_DTSTART );
457- event->setDtEnd (dtStart);
458- }
452+ if (event->allDay ()) {
453+ KDateTime dtStart = event->dtStart ();
454+ KDateTime dtEnd = event->dtEnd ();
455+
456+ // calendar processing requires all-day events to have a dtEnd
457+ if (!dtEnd.isValid ()) {
458+ LOG_DEBUG (" Adding DTEND to" << incidence->uid () << " as" << dtStart.toString ());
459+ event->setCustomProperty (" buteo" , PROP_DTEND_ADDED_USING_DTSTART , PROP_DTEND_ADDED_USING_DTSTART );
460+ event->setDtEnd (dtStart);
461+ }
459462
460- // setting dtStart/End changes the allDay value, so ensure it is still set to true
461- event->setAllDay (true );
463+ // setting dtStart/End changes the allDay value, so ensure it is still set to true
464+ event->setAllDay (true );
465+ }
466+ break ;
467+ }
468+ default :
469+ break ;
462470 }
463471}
464472
@@ -521,81 +529,59 @@ QString IncidenceHandler::toIcs(KCalCore::Incidence::Ptr incidence,
521529
522530KCalCore::Incidence::Ptr IncidenceHandler::incidenceToExport (KCalCore::Incidence::Ptr sourceIncidence, const KCalCore::Incidence::List &instances)
523531{
524- if (sourceIncidence->type () != KCalCore::IncidenceBase::TypeEvent) {
525- LOG_DEBUG (" Incidence not an event; cannot create exportable version" );
526- return sourceIncidence;
527- }
528-
529532 KCalCore::Incidence::Ptr incidence = QSharedPointer<KCalCore::Incidence>(sourceIncidence->clone ());
530- KCalCore::Event::Ptr event = incidence.staticCast <KCalCore::Event>();
531533
532534 // check to see if the UID is of the special form: NBUID:NotebookUid:EventUid. If so, trim it.
533- if (event ->uid ().startsWith (QStringLiteral (" NBUID:" ))) {
534- QString oldUid = event ->uid ();
535+ if (incidence ->uid ().startsWith (QStringLiteral (" NBUID:" ))) {
536+ QString oldUid = incidence ->uid ();
535537 QString trimmedUid = oldUid.mid (oldUid.indexOf (' :' , 6 )+1 ); // remove NBUID:NotebookUid:
536- event->setUid (trimmedUid); // leaving just the EventUid.
537- }
538-
539- bool eventIsAllDay = event->allDay ();
540- if (eventIsAllDay) {
541- bool sendWithoutDtEnd = !event->customProperty (" buteo" , PROP_DTEND_ADDED_USING_DTSTART ).isEmpty ()
542- && (event->dtStart () == event->dtEnd ());
543- event->removeCustomProperty (" buteo" , PROP_DTEND_ADDED_USING_DTSTART );
544-
545- if (sendWithoutDtEnd) {
546- // A single-day all-day event was received without a DTEND, and it is still a single-day
547- // all-day event, so remove the DTEND before upsyncing.
548- LOG_DEBUG (" Removing DTEND from" << incidence->uid ());
549- event->setDtEnd (KDateTime ());
550- } else {
551- KDateTime dt;
552- if (event->hasEndDate ()) {
553- // Event::dtEnd() is inclusive, but DTEND in iCalendar format is exclusive.
554- dt = KDateTime (event->dtEnd ().addDays (1 ).date (), KDateTime::Spec::ClockTime ());
555- LOG_DEBUG (" Adding +1 day to DTEND to make exclusive DTEND for" << incidence->uid () << " :" << dt.toString ());
556- } else {
557- // No DTEND exists in event, but it's all day. Set to DTSTART+1 to make exclusive DTEND.
558- dt = KDateTime (event->dtStart ().addDays (1 ).date (), KDateTime::Spec::ClockTime ());
559- LOG_DEBUG (" Setting DTEND to DTSTART+1 for" << incidence->uid () << " :" << dt.toString ());
560- }
561- dt.setDateOnly (true );
562- LOG_DEBUG (" Stripping time from date-only DTEND:" << dt.toString ());
563- event->setDtEnd (dt);
564- }
565- }
566-
567- if (event->dtStart ().isDateOnly ()) {
568- KDateTime dt = KDateTime (event->dtStart ().date (), KDateTime::Spec::ClockTime ());
569- dt.setDateOnly (true );
570- event->setDtStart (dt);
571- LOG_DEBUG (" Stripping time from date-only DTSTART:" << dt.toString ());
572- }
573-
574- // setting dtStart/End changes the allDay value, so ensure it is still set to true if needed.
575- if (eventIsAllDay) {
576- event->setAllDay (true );
538+ incidence->setUid (trimmedUid); // leaving just the EventUid.
577539 }
578540
579541 // remove any (obsolete) markers that tell us that the time was added by us
580- event ->removeCustomProperty (" buteo" , " dtstart-date_only" );
581- event ->removeCustomProperty (" buteo" , " dtend-date_only" );
542+ incidence ->removeCustomProperty (" buteo" , " dtstart-date_only" );
543+ incidence ->removeCustomProperty (" buteo" , " dtend-date_only" );
582544
583545 // remove any URI or ETAG data we insert into the event for sync purposes.
584- event ->removeCustomProperty (" buteo" , " uri" );
585- event ->removeCustomProperty (" buteo" , " etag" );
586- const QStringList &comments (event ->comments ());
546+ incidence ->removeCustomProperty (" buteo" , " uri" );
547+ incidence ->removeCustomProperty (" buteo" , " etag" );
548+ const QStringList &comments (incidence ->comments ());
587549 Q_FOREACH (const QString &comment, comments) {
588550 if (comment.startsWith (" buteo:caldav:uri:" ) ||
589551 comment.startsWith (" buteo:caldav:detached-and-synced" ) ||
590552 comment.startsWith (" buteo:caldav:etag:" )) {
591553 LOG_DEBUG (" Discarding buteo-prefixed comment:" << comment);
592- event->removeComment (comment);
554+ incidence->removeComment (comment);
555+ }
556+ }
557+
558+ // The default storage implementation applies the organizer as an attendee by default.
559+ // Undo this as it turns the incidence into a scheduled event requiring acceptance/rejection/etc.
560+ const KCalCore::Person::Ptr organizer = incidence->organizer ();
561+ if (organizer) {
562+ Q_FOREACH (const KCalCore::Attendee::Ptr &attendee, incidence->attendees ()) {
563+ if (attendee->email () == organizer->email () && attendee->fullName () == organizer->fullName ()) {
564+ LOG_DEBUG (" Discarding organizer as attendee" << attendee->fullName ());
565+ incidence->deleteAttendee (attendee);
566+ } else {
567+ LOG_DEBUG (" Not discarding attendee:" << attendee->fullName () << attendee->email () << " : not organizer:" << organizer->fullName () << organizer->email ());
568+ }
569+ }
570+ }
571+
572+ // remove EXDATE values from the recurring incidence which correspond to the persistent occurrences (instances)
573+ if (incidence->recurs ()) {
574+ Q_FOREACH (KCalCore::Incidence::Ptr instance, instances) {
575+ KCalCore::DateTimeList exDateTimes = incidence->recurrence ()->exDateTimes ();
576+ exDateTimes.removeAll (instance->recurrenceId ());
577+ incidence->recurrence ()->setExDateTimes (exDateTimes);
578+ LOG_DEBUG (" Discarding exdate:" << instance->recurrenceId ().toString ());
593579 }
594580 }
595581
596582 // Icalformat from kcalcore converts second-type duration into day-type duration
597583 // whenever possible. We do the same to have consistent comparisons.
598- KCalCore::Alarm::List alarms = event ->alarms ();
584+ KCalCore::Alarm::List alarms = incidence ->alarms ();
599585 Q_FOREACH (KCalCore::Alarm::Ptr alarm, alarms) {
600586 if (!alarm->hasTime ()) {
601587 KCalCore::Duration offset (0 );
@@ -613,29 +599,56 @@ KCalCore::Incidence::Ptr IncidenceHandler::incidenceToExport(KCalCore::Incidence
613599 }
614600 }
615601
616- // The default storage implementation applies the organizer as an attendee by default.
617- // Undo this as it turns the incidence into a scheduled event requiring acceptance/rejection/etc.
618- const KCalCore::Person::Ptr organizer = event->organizer ();
619- if (organizer) {
620- Q_FOREACH (const KCalCore::Attendee::Ptr &attendee, event->attendees ()) {
621- if (attendee->email () == organizer->email () && attendee->fullName () == organizer->fullName ()) {
622- LOG_DEBUG (" Discarding organizer as attendee" << attendee->fullName ());
623- event->deleteAttendee (attendee);
602+ switch (incidence->type ()) {
603+ case KCalCore::IncidenceBase::TypeEvent: {
604+ KCalCore::Event::Ptr event = incidence.staticCast <KCalCore::Event>();
605+ bool eventIsAllDay = event->allDay ();
606+ if (eventIsAllDay) {
607+ bool sendWithoutDtEnd = !event->customProperty (" buteo" , PROP_DTEND_ADDED_USING_DTSTART ).isEmpty ()
608+ && (event->dtStart () == event->dtEnd ());
609+ event->removeCustomProperty (" buteo" , PROP_DTEND_ADDED_USING_DTSTART );
610+
611+ if (sendWithoutDtEnd) {
612+ // A single-day all-day event was received without a DTEND, and it is still a single-day
613+ // all-day event, so remove the DTEND before upsyncing.
614+ LOG_DEBUG (" Removing DTEND from" << incidence->uid ());
615+ event->setDtEnd (KDateTime ());
624616 } else {
625- LOG_DEBUG (" Not discarding attendee:" << attendee->fullName () << attendee->email () << " : not organizer:" << organizer->fullName () << organizer->email ());
617+ KDateTime dt;
618+ if (event->hasEndDate ()) {
619+ // Event::dtEnd() is inclusive, but DTEND in iCalendar format is exclusive.
620+ dt = KDateTime (event->dtEnd ().addDays (1 ).date (), KDateTime::Spec::ClockTime ());
621+ LOG_DEBUG (" Adding +1 day to DTEND to make exclusive DTEND for" << incidence->uid () << " :" << dt.toString ());
622+ } else {
623+ // No DTEND exists in event, but it's all day. Set to DTSTART+1 to make exclusive DTEND.
624+ dt = KDateTime (event->dtStart ().addDays (1 ).date (), KDateTime::Spec::ClockTime ());
625+ LOG_DEBUG (" Setting DTEND to DTSTART+1 for" << incidence->uid () << " :" << dt.toString ());
626+ }
627+ dt.setDateOnly (true );
628+ LOG_DEBUG (" Stripping time from date-only DTEND:" << dt.toString ());
629+ event->setDtEnd (dt);
626630 }
627631 }
628- }
629632
630- // remove EXDATE values from the recurring incidence which correspond to the persistent occurrences (instances)
631- if (incidence->recurs ()) {
632- Q_FOREACH (KCalCore::Incidence::Ptr instance, instances) {
633- KCalCore::DateTimeList exDateTimes = incidence->recurrence ()->exDateTimes ();
634- exDateTimes.removeAll (instance->recurrenceId ());
635- incidence->recurrence ()->setExDateTimes (exDateTimes);
636- LOG_DEBUG (" Discarding exdate:" << instance->recurrenceId ().toString ());
633+ if (event->dtStart ().isDateOnly ()) {
634+ KDateTime dt = KDateTime (event->dtStart ().date (), KDateTime::Spec::ClockTime ());
635+ dt.setDateOnly (true );
636+ event->setDtStart (dt);
637+ LOG_DEBUG (" Stripping time from date-only DTSTART:" << dt.toString ());
638+ }
639+
640+ // setting dtStart/End changes the allDay value, so ensure it is still set to true if needed.
641+ if (eventIsAllDay) {
642+ event->setAllDay (true );
637643 }
644+ break ;
645+ }
646+ case KCalCore::IncidenceBase::TypeTodo:
647+ break ;
648+ default :
649+ LOG_DEBUG (" Incidence type not supported; cannot create proper exportable version" );
650+ break ;
638651 }
639652
640- return event ;
653+ return incidence ;
641654}
0 commit comments