23 #include <tqdatetime.h>
25 #include <tqptrlist.h>
30 #include <tdelocale.h>
34 #include <libical/ical.h>
35 #include <libical/icalparser.h>
36 #include <libical/icalrestriction.h>
41 #include "icalformat.h"
42 #include "icalformatimpl.h"
47 #define _ICAL_VERSION "2.0"
49 #if ICAL_CHECK_VERSION(4,0,0)
50 #define FIELD_BY_SECOND ICAL_BY_SECOND
51 #define FIELD_BY_MINUTE ICAL_BY_MINUTE
52 #define FIELD_BY_HOUR ICAL_BY_HOUR
53 #define FIELD_BY_DAY ICAL_BY_DAY
54 #define FIELD_BY_MONTH_DAY ICAL_BY_MONTH_DAY
55 #define FIELD_BY_YEAR_DAY ICAL_BY_YEAR_DAY
56 #define FIELD_BY_WEEK_NO ICAL_BY_WEEK_NO
57 #define FIELD_BY_MONTH ICAL_BY_MONTH
58 #define FIELD_BY_SET_POS ICAL_BY_SET_POS
60 #define FIELD_BY_SECOND by_second
61 #define FIELD_BY_MINUTE by_minute
62 #define FIELD_BY_HOUR by_hour
63 #define FIELD_BY_DAY by_day
64 #define FIELD_BY_MONTH_DAY by_month_day
65 #define FIELD_BY_YEAR_DAY by_year_day
66 #define FIELD_BY_WEEK_NO by_week_no
67 #define FIELD_BY_MONTH by_month
68 #define FIELD_BY_SET_POS by_set_pos
74 static TQDateTime ICalDate2TQDate(
const icaltimetype& t)
78 const int year = (t.year>=1754) ? t.year : 1754;
79 return TQDateTime(TQDate(year,t.month,t.day), TQTime(t.hour,t.minute,t.second));
94 const int gSecondsPerMinute = 60;
95 const int gSecondsPerHour = gSecondsPerMinute * 60;
96 const int gSecondsPerDay = gSecondsPerHour * 24;
97 const int gSecondsPerWeek = gSecondsPerDay * 7;
99 ICalFormatImpl::ICalFormatImpl(
ICalFormat *parent ) :
100 mParent( parent ), mCompat( new
Compat )
104 ICalFormatImpl::~ICalFormatImpl()
112 ToComponentVisitor( ICalFormatImpl *impl,
Scheduler::Method m ) : mImpl( impl ), mComponent( 0 ), mMethod( m ) {}
114 bool visit(
Event *e ) { mComponent = mImpl->writeEvent( e );
return true; }
115 bool visit(
Todo *e ) { mComponent = mImpl->writeTodo( e );
return true; }
116 bool visit(
Journal *e ) { mComponent = mImpl->writeJournal( e );
return true; }
117 bool visit(
FreeBusy *fb ) { mComponent = mImpl->writeFreeBusy( fb, mMethod );
return true; }
119 icalcomponent *component() {
return mComponent; }
122 ICalFormatImpl *mImpl;
123 icalcomponent *mComponent;
129 ToComponentVisitor v(
this, method );
130 if ( incidence->
accept(v) )
131 return v.component();
135 icalcomponent *ICalFormatImpl::writeTodo(
Todo *todo)
138 TQStringList tmpStrList;
140 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
142 writeIncidence(vtodo,todo);
148 due = writeICalDate(todo->
dtDue(
true).date());
150 due = writeICalDateTime(todo->
dtDue(
true));
152 icalcomponent_add_property(vtodo,icalproperty_new_due(due));
160 start = writeICalDate(todo->
dtStart(
true).date());
163 start = writeICalDateTime(todo->
dtStart(
true));
165 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start));
175 icaltimetype completed = writeICalDateTime(todo->
completed());
176 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed));
179 icalcomponent_add_property(vtodo,
183 icalcomponent_add_property(vtodo,
184 icalproperty_new_recurrenceid( writeICalDateTime( todo->
dtDue())));
190 icalcomponent *ICalFormatImpl::writeEvent(
Event *event)
193 kdDebug(5800) <<
"Write Event '" <<
event->summary() <<
"' (" <<
event->uid()
198 TQStringList tmpStrList;
200 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
202 writeIncidence(vevent,event);
208 start = writeICalDate(event->
dtStart().date());
211 start = writeICalDateTime(event->
dtStart());
213 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start));
222 end = writeICalDate( event->
dtEnd().date().addDays( 1 ) );
223 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
227 end = writeICalDateTime(event->
dtEnd());
228 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
236 tmpStrList = anEvent->resources();
237 tmpStr = tmpStrList.join(
";");
238 if (!tmpStr.isEmpty())
239 addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
245 case Event::Transparent:
246 icalcomponent_add_property(
248 icalproperty_new_transp( ICAL_TRANSP_TRANSPARENT ) );
251 icalcomponent_add_property(
253 icalproperty_new_transp( ICAL_TRANSP_OPAQUE ) );
260 icalcomponent *ICalFormatImpl::writeFreeBusy(
FreeBusy *freebusy,
263 kdDebug(5800) <<
"icalformatimpl: writeFreeBusy: startDate: "
264 << freebusy->
dtStart().toString(
"ddd MMMM d yyyy: h:m:s ap") <<
" End Date: "
265 << freebusy->dtEnd().toString(
"ddd MMMM d yyyy: h:m:s ap") << endl;
267 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
269 writeIncidenceBase(vfreebusy,freebusy);
271 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
272 writeICalDateTime(freebusy->
dtStart())));
274 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
275 writeICalDateTime(freebusy->dtEnd())));
277 if (method == Scheduler::Request) {
278 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
279 freebusy->
uid().utf8()));
283 TQValueList<Period> list = freebusy->busyPeriods();
284 TQValueList<Period>::Iterator it;
285 icalperiodtype period = icalperiodtype_null_period();
286 for (it = list.begin(); it!= list.end(); ++it) {
287 period.start = writeICalDateTime((*it).start());
288 if ( (*it).hasDuration() ) {
289 period.duration = writeICalDuration( (*it).duration().asSeconds() );
291 period.end = writeICalDateTime((*it).end());
293 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
299 icalcomponent *ICalFormatImpl::writeJournal(
Journal *journal)
301 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
303 writeIncidence(vjournal,journal);
306 if (journal->
dtStart().isValid()) {
310 start = writeICalDate(journal->
dtStart().date());
313 start = writeICalDateTime(journal->
dtStart());
315 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
321 void ICalFormatImpl::writeIncidence(icalcomponent *parent,
Incidence *incidence)
332 p = icalproperty_new_x(TQString::number(incidence->
syncStatus()).utf8());
333 icalproperty_set_x_name(p,
"X-PILOTSTAT");
334 icalcomponent_add_property(parent,p);
336 p = icalproperty_new_x(TQString::number(incidence->
pilotId()).utf8());
337 icalproperty_set_x_name(p,
"X-PILOTID");
338 icalcomponent_add_property(parent,p);
341 TQString modifiedUid;
347 IncidenceListIterator it;
352 modifiedUid = incidence->
uid();
362 writeIncidenceBase(parent,incidence);
365 icalcomponent_add_property(parent,icalproperty_new_created(
366 writeICalDateTime(incidence->
created())));
373 icalcomponent_add_property(parent,icalproperty_new_uid(modifiedUid.utf8()));
377 icalcomponent_add_property(parent,icalproperty_new_uid(
384 icalcomponent_add_property(parent,icalproperty_new_sequence(
390 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
396 icalcomponent_add_property(parent,icalproperty_new_description(
401 if (!incidence->
summary().isEmpty()) {
402 icalcomponent_add_property(parent,icalproperty_new_summary(
407 if (!incidence->
location().isEmpty()) {
408 icalcomponent_add_property(parent,icalproperty_new_location(
413 icalproperty_status status = ICAL_STATUS_NONE;
414 switch (incidence->
status()) {
415 case Incidence::StatusTentative: status = ICAL_STATUS_TENTATIVE;
break;
416 case Incidence::StatusConfirmed: status = ICAL_STATUS_CONFIRMED;
break;
417 case Incidence::StatusCompleted: status = ICAL_STATUS_COMPLETED;
break;
418 case Incidence::StatusNeedsAction: status = ICAL_STATUS_NEEDSACTION;
break;
419 case Incidence::StatusCanceled: status = ICAL_STATUS_CANCELLED;
break;
420 case Incidence::StatusInProcess: status = ICAL_STATUS_INPROCESS;
break;
421 case Incidence::StatusDraft: status = ICAL_STATUS_DRAFT;
break;
422 case Incidence::StatusFinal: status = ICAL_STATUS_FINAL;
break;
423 case Incidence::StatusX: {
424 icalproperty* p = icalproperty_new_status(ICAL_STATUS_X);
425 icalvalue_set_x(icalproperty_get_value(p), incidence->
statusStr().utf8());
426 icalcomponent_add_property(parent, p);
429 case Incidence::StatusNone:
433 if (status != ICAL_STATUS_NONE)
434 icalcomponent_add_property(parent, icalproperty_new_status(status));
437 icalproperty_class secClass;
438 switch (incidence->
secrecy()) {
439 case Incidence::SecrecyPublic:
440 secClass = ICAL_CLASS_PUBLIC;
442 case Incidence::SecrecyConfidential:
443 secClass = ICAL_CLASS_CONFIDENTIAL;
445 case Incidence::SecrecyPrivate:
447 secClass = ICAL_CLASS_PRIVATE;
450 if ( secClass != ICAL_CLASS_PUBLIC ) {
451 icalcomponent_add_property(parent,icalproperty_new_class(secClass));
456 icalcomponent_add_property(parent,icalproperty_new_priority(
461 TQStringList categories = incidence->
categories();
462 TQStringList::Iterator it;
463 for(it = categories.begin(); it != categories.end(); ++it ) {
464 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
469 icalcomponent_add_property(parent,icalproperty_new_relatedto(
475 icalcomponent_add_property(parent, icalproperty_new_recurrenceid( writeICalDateTime( incidence->
recurrenceID() ) ));
482 RecurrenceRule::List::ConstIterator rit;
483 for ( rit = rrules.begin(); rit != rrules.end(); ++rit ) {
484 icalrecurrencetype *recur = writeRecurrenceRule( (*rit) );
485 #if ICAL_CHECK_VERSION(4,0,0)
486 icalcomponent_add_property( parent, icalproperty_new_rrule( recur ) );
487 icalrecurrencetype_unref( recur );
489 icalcomponent_add_property( parent, icalproperty_new_rrule( *recur ) );
495 RecurrenceRule::List::ConstIterator exit;
496 for ( exit = exrules.begin(); exit != exrules.end(); ++exit ) {
497 icalrecurrencetype *recur = writeRecurrenceRule( (*exit) );
498 #if ICAL_CHECK_VERSION(4,0,0)
499 icalcomponent_add_property( parent, icalproperty_new_rrule( recur ) );
500 icalrecurrencetype_unref( recur );
502 icalcomponent_add_property( parent, icalproperty_new_rrule( *recur ) );
507 DateList dateList = incidence->
recurrence()->exDates();
508 DateList::ConstIterator exIt;
509 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
510 icalcomponent_add_property(parent,icalproperty_new_exdate(
511 writeICalDate(*exIt)));
513 DateTimeList dateTimeList = incidence->
recurrence()->exDateTimes();
514 DateTimeList::ConstIterator extIt;
515 for(extIt = dateTimeList.begin(); extIt != dateTimeList.end(); ++extIt) {
516 icalcomponent_add_property(parent,icalproperty_new_exdate(
517 writeICalDateTime(*extIt)));
522 DateList::ConstIterator rdIt;
523 for( rdIt = dateList.begin(); rdIt != dateList.end(); ++rdIt) {
524 icalcomponent_add_property( parent, icalproperty_new_rdate(
525 writeICalDatePeriod(*rdIt) ) );
527 dateTimeList = incidence->
recurrence()->rDateTimes();
528 DateTimeList::ConstIterator rdtIt;
529 for( rdtIt = dateTimeList.begin(); rdtIt != dateTimeList.end(); ++rdtIt) {
530 icalcomponent_add_property( parent, icalproperty_new_rdate(
531 writeICalDateTimePeriod(*rdtIt) ) );
536 Attachment::List::ConstIterator atIt;
537 for ( atIt = attachments.begin(); atIt != attachments.end(); ++atIt ) {
538 icalcomponent_add_property( parent, writeAttachment( *atIt ) );
542 Alarm::List::ConstIterator alarmIt;
543 for ( alarmIt = incidence->
alarms().begin();
544 alarmIt != incidence->
alarms().end(); ++alarmIt ) {
545 if ( (*alarmIt)->enabled() ) {
547 icalcomponent_add_component( parent, writeAlarm( *alarmIt ) );
552 if (incidence->hasDuration()) {
553 icaldurationtype duration;
554 duration = writeICalDuration( incidence->duration() );
555 icalcomponent_add_property(parent,icalproperty_new_duration(duration));
559 void ICalFormatImpl::writeIncidenceBase( icalcomponent *parent,
562 icalcomponent_add_property( parent, icalproperty_new_dtstamp(
563 writeICalDateTime( TQDateTime::currentDateTime() ) ) );
566 if ( !incidenceBase->organizer().isEmpty() ) {
567 icalcomponent_add_property( parent, writeOrganizer( incidenceBase->organizer() ) );
572 Attendee::List::ConstIterator it;
573 for( it = incidenceBase->
attendees().begin();
574 it != incidenceBase->
attendees().end(); ++it ) {
575 icalcomponent_add_property( parent, writeAttendee( *it ) );
580 TQStringList comments = incidenceBase->
comments();
581 for (TQStringList::Iterator it=comments.begin(); it!=comments.end(); ++it) {
582 icalcomponent_add_property(parent, icalproperty_new_comment((*it).utf8()));
586 writeCustomProperties( parent, incidenceBase );
589 void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,
CustomProperties *properties)
592 for (TQMap<TQCString, TQString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
593 icalproperty *p = icalproperty_new_x(c.data().utf8());
594 icalproperty_set_x_name(p,c.key());
595 icalcomponent_add_property(parent,p);
599 icalproperty *ICalFormatImpl::writeOrganizer(
const Person &organizer )
601 icalproperty *p = icalproperty_new_organizer(
"MAILTO:" + organizer.email().utf8());
603 if (!organizer.name().isEmpty()) {
604 icalproperty_add_parameter( p, icalparameter_new_cn(organizer.name().utf8()) );
612 icalproperty *ICalFormatImpl::writeAttendee(
Attendee *attendee)
614 icalproperty *p = icalproperty_new_attendee(
"mailto:" + attendee->email().utf8());
616 if (!attendee->name().isEmpty()) {
617 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
621 icalproperty_add_parameter(p,icalparameter_new_rsvp(
622 attendee->
RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
624 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
625 switch (attendee->
status()) {
627 case Attendee::NeedsAction:
628 status = ICAL_PARTSTAT_NEEDSACTION;
630 case Attendee::Accepted:
631 status = ICAL_PARTSTAT_ACCEPTED;
633 case Attendee::Declined:
634 status = ICAL_PARTSTAT_DECLINED;
636 case Attendee::Tentative:
637 status = ICAL_PARTSTAT_TENTATIVE;
639 case Attendee::Delegated:
640 status = ICAL_PARTSTAT_DELEGATED;
642 case Attendee::Completed:
643 status = ICAL_PARTSTAT_COMPLETED;
645 case Attendee::InProcess:
646 status = ICAL_PARTSTAT_INPROCESS;
649 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
651 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
652 switch (attendee->
role()) {
653 case Attendee::Chair:
654 role = ICAL_ROLE_CHAIR;
657 case Attendee::ReqParticipant:
658 role = ICAL_ROLE_REQPARTICIPANT;
660 case Attendee::OptParticipant:
661 role = ICAL_ROLE_OPTPARTICIPANT;
663 case Attendee::NonParticipant:
664 role = ICAL_ROLE_NONPARTICIPANT;
667 icalproperty_add_parameter(p,icalparameter_new_role(role));
669 if (!attendee->
uid().isEmpty()) {
670 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->
uid().utf8());
671 icalparameter_set_xname(icalparameter_uid,
"X-UID");
672 icalproperty_add_parameter(p,icalparameter_uid);
675 if ( !attendee->
delegate().isEmpty() ) {
676 icalparameter* icalparameter_delegate = icalparameter_new_delegatedto( attendee->
delegate().utf8() );
677 icalproperty_add_parameter( p, icalparameter_delegate );
680 if ( !attendee->
delegator().isEmpty() ) {
681 icalparameter* icalparameter_delegator = icalparameter_new_delegatedfrom( attendee->
delegator().utf8() );
682 icalproperty_add_parameter( p, icalparameter_delegator );
688 icalproperty *ICalFormatImpl::writeAttachment(
Attachment *att )
691 if ( att->isUri() ) {
692 attach = icalattach_new_from_url( att->uri().utf8().data() );
694 attach = icalattach_new_from_data ( (
const char *)att->data(), 0, 0 );
696 icalproperty *p = icalproperty_new_attach( attach );
698 if ( !att->mimeType().isEmpty() ) {
699 icalproperty_add_parameter( p,
700 icalparameter_new_fmttype( att->mimeType().utf8().data() ) );
703 if ( att->isBinary() ) {
704 icalproperty_add_parameter( p,
705 icalparameter_new_value( ICAL_VALUE_BINARY ) );
706 icalproperty_add_parameter( p,
707 icalparameter_new_encoding( ICAL_ENCODING_BASE64 ) );
710 if ( att->showInline() ) {
711 icalparameter* icalparameter_inline = icalparameter_new_x(
"inline" );
712 icalparameter_set_xname( icalparameter_inline,
"X-CONTENT-DISPOSITION" );
713 icalproperty_add_parameter( p, icalparameter_inline );
716 if ( !att->label().isEmpty() ) {
717 icalparameter* icalparameter_label = icalparameter_new_x( att->label().utf8() );
718 icalparameter_set_xname( icalparameter_label,
"X-LABEL" );
719 icalproperty_add_parameter( p, icalparameter_label );
725 #if ICAL_CHECK_VERSION(4,0,0)
726 #define writeByData(by_enum) \
727 if ( bys.count() > 0 ) { \
728 icalrecur_resize_by( &r->by[by_enum], bys.count() ); \
730 for ( it = bys.begin(); it != bys.end(); ++it ) { \
731 r->by[by_enum].data[index++] = *it; \
735 #define writeByData(by_enum) \
737 for ( it = bys.begin(); it != bys.end(); ++it ) { \
738 r->by_enum[index++] = *it; \
741 icalrecurrencetype *ICalFormatImpl::writeRecurrenceRule(
RecurrenceRule *recur )
745 #if ICAL_CHECK_VERSION(4,0,0)
746 icalrecurrencetype *r = icalrecurrencetype_new();
748 icalrecurrencetype *r =
new icalrecurrencetype;
749 icalrecurrencetype_clear(r);
753 switch( recur->recurrenceType() ) {
754 case RecurrenceRule::rSecondly:
755 r->freq = ICAL_SECONDLY_RECURRENCE;
757 case RecurrenceRule::rMinutely:
758 r->freq = ICAL_MINUTELY_RECURRENCE;
760 case RecurrenceRule::rHourly:
761 r->freq = ICAL_HOURLY_RECURRENCE;
763 case RecurrenceRule::rDaily:
764 r->freq = ICAL_DAILY_RECURRENCE;
766 case RecurrenceRule::rWeekly:
767 r->freq = ICAL_WEEKLY_RECURRENCE;
769 case RecurrenceRule::rMonthly:
770 r->freq = ICAL_MONTHLY_RECURRENCE;
772 case RecurrenceRule::rYearly:
773 r->freq = ICAL_YEARLY_RECURRENCE;
776 r->freq = ICAL_NO_RECURRENCE;
777 kdDebug(5800) <<
"ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
782 TQValueList<int> bys;
783 TQValueList<int>::ConstIterator it;
786 bys = recur->bySeconds();
787 writeByData(FIELD_BY_SECOND);
789 bys = recur->byMinutes();
790 writeByData(FIELD_BY_MINUTE);
792 bys = recur->byHours();
793 writeByData(FIELD_BY_HOUR);
795 bys = recur->byMonthDays();
796 #if ICAL_CHECK_VERSION(4,0,0)
797 if ( bys.count() > 0 ) {
798 icalrecur_resize_by( &r->by[ICAL_BY_MONTH_DAY], bys.count() );
800 for ( it = bys.begin(); it != bys.end(); ++it ) {
801 r->by[ICAL_BY_MONTH_DAY].data[index++] = icalrecurrencetype_day_position( (*it) * 8 );
806 for ( it = bys.begin(); it != bys.end(); ++it ) {
807 r->by_month_day[index++] = icalrecurrencetype_day_position( (*it) * 8 );
811 bys = recur->byYearDays();
812 writeByData(FIELD_BY_YEAR_DAY);
814 bys = recur->byWeekNumbers();
815 writeByData(FIELD_BY_WEEK_NO);
817 bys = recur->byMonths();
818 writeByData(FIELD_BY_MONTH);
820 bys = recur->bySetPos();
821 writeByData(FIELD_BY_SET_POS);
823 TQValueList<RecurrenceRule::WDayPos> byd = recur->byDays();
824 #if ICAL_CHECK_VERSION(4,0,0)
825 if ( byd.count() > 0 )
827 icalrecur_resize_by( &r->by[ICAL_BY_DAY], byd.count() );
832 for ( TQValueList<RecurrenceRule::WDayPos>::ConstIterator dit = byd.begin();
833 dit != byd.end(); ++dit ) {
834 day = (*dit).day() % 7 + 1;
835 #if ICAL_CHECK_VERSION(4,0,0)
836 r->by[ICAL_BY_DAY].data[index++] = icalrecurrencetype_encode_day(
837 static_cast<icalrecurrencetype_weekday
>( day ),
840 if ( (*dit).pos() < 0 ) {
841 day += (-(*dit).pos())*8;
844 day += (*dit).pos()*8;
846 r->by_day[index++] = day;
850 r->week_start =
static_cast<icalrecurrencetype_weekday
>(
851 recur->weekStart()%7 + 1);
860 }
else if ( recur->
duration() == -1 ) {
864 r->until = writeICalDate(recur->
endDt().date());
866 r->until = writeICalDateTime(recur->
endDt());
871 const char *str = icalrecurrencetype_as_string(r);
873 kdDebug(5800) <<
" String: " << str << endl;
875 kdDebug(5800) <<
" No String" << endl;
883 icalcomponent *ICalFormatImpl::writeAlarm(
Alarm *alarm)
886 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
888 icalproperty_action action;
889 icalattach *attach = 0;
891 switch (alarm->
type()) {
892 case Alarm::Procedure:
893 action = ICAL_ACTION_PROCEDURE;
894 attach = icalattach_new_from_url(TQFile::encodeName(alarm->
programFile()).data());
895 icalcomponent_add_property(a,icalproperty_new_attach(attach));
897 icalcomponent_add_property(a,icalproperty_new_description(alarm->
programArguments().utf8()));
901 action = ICAL_ACTION_AUDIO;
904 attach = icalattach_new_from_url(TQFile::encodeName( alarm->
audioFile() ).data());
905 icalcomponent_add_property(a,icalproperty_new_attach(attach));
909 action = ICAL_ACTION_EMAIL;
911 for (TQValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
912 icalproperty *p = icalproperty_new_attendee(
"MAILTO:" + (*ad).email().utf8());
913 if (!(*ad).name().isEmpty()) {
914 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
916 icalcomponent_add_property(a,p);
918 icalcomponent_add_property(a,icalproperty_new_summary(alarm->
mailSubject().utf8()));
919 icalcomponent_add_property(a,icalproperty_new_description(alarm->
mailText().utf8()));
921 if (attachments.count() > 0) {
922 for (TQStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
923 attach = icalattach_new_from_url(TQFile::encodeName( *at ).data());
924 icalcomponent_add_property(a,icalproperty_new_attach(attach));
930 action = ICAL_ACTION_DISPLAY;
931 icalcomponent_add_property(a,icalproperty_new_description(alarm->
text().utf8()));
935 kdDebug(5800) <<
"Unknown type of alarm" << endl;
936 action = ICAL_ACTION_NONE;
939 icalcomponent_add_property(a,icalproperty_new_action(action));
942 icaltriggertype trigger;
944 trigger.time = writeICalDateTime(alarm->
time());
945 trigger.duration = icaldurationtype_null_duration();
947 trigger.time = icaltime_null_time();
953 trigger.duration = writeICalDuration( offset.
asSeconds() );
955 icalproperty *p = icalproperty_new_trigger(trigger);
957 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
958 icalcomponent_add_property(a,p);
962 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->
repeatCount()));
963 icalcomponent_add_property(a,icalproperty_new_duration(
969 for (TQMap<TQCString, TQString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
970 icalproperty *p = icalproperty_new_x(c.data().utf8());
971 icalproperty_set_x_name(p,c.key());
972 icalcomponent_add_property(a,p);
978 Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
982 readIncidence(vtodo, 0, todo);
984 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
987 icaltimetype icaltime;
989 TQStringList categories;
992 icalproperty_kind kind = icalproperty_isa(p);
995 case ICAL_DUE_PROPERTY:
996 icaltime = icalproperty_get_due(p);
997 if (icaltime.is_date) {
998 todo->
setDtDue(TQDateTime(readICalDate(icaltime),TQTime(0,0,0)),
true);
1000 todo->
setDtDue(readICalDateTime(p, icaltime),
true);
1006 case ICAL_COMPLETED_PROPERTY:
1007 icaltime = icalproperty_get_completed(p);
1011 case ICAL_PERCENTCOMPLETE_PROPERTY:
1015 case ICAL_RELATEDTO_PROPERTY:
1016 todo->
setRelatedToUid(TQString::fromUtf8(icalproperty_get_relatedto(p)));
1017 mTodosRelate.append(todo);
1020 case ICAL_DTSTART_PROPERTY: {
1022 if ( todo->
comments().grep(
"NoStartDate").count() )
1029 case ICAL_RECURRENCEID_PROPERTY:
1030 icaltime = icalproperty_get_recurrenceid(p);
1040 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY);
1043 if (mCompat) mCompat->fixEmptySummary( todo );
1048 Event *ICalFormatImpl::readEvent( icalcomponent *vevent, icalcomponent *vtimezone )
1053 icaltimezone *tz = icaltimezone_new();
1054 if ( !icaltimezone_set_component( tz, vtimezone ) ) {
1055 icaltimezone_free( tz, 1 );
1059 readIncidence( vevent, tz, event);
1061 icalproperty *p = icalcomponent_get_first_property( vevent, ICAL_ANY_PROPERTY );
1064 icaltimetype icaltime;
1066 TQStringList categories;
1067 icalproperty_transp transparency;
1069 bool dtEndProcessed =
false;
1072 icalproperty_kind kind = icalproperty_isa( p );
1075 case ICAL_DTEND_PROPERTY:
1076 icaltime = icalproperty_get_dtend( p );
1077 if ( icaltime.is_date ) {
1079 TQDate endDate = readICalDate( icaltime ).addDays( -1 );
1081 mCompat->fixFloatingEnd( endDate );
1084 if ( endDate < event->dtStart().date() ) {
1085 endDate =
event->dtStart().date();
1087 event->setDtEnd( TQDateTime( endDate, TQTime( 0, 0, 0 ) ) );
1089 event->setDtEnd(readICalDateTime(p, icaltime, tz));
1090 event->setFloats(
false );
1092 dtEndProcessed =
true;
1095 case ICAL_RELATEDTO_PROPERTY:
1096 event->setRelatedToUid( TQString::fromUtf8( icalproperty_get_relatedto( p ) ) );
1097 mEventsRelate.append( event );
1100 case ICAL_TRANSP_PROPERTY:
1101 transparency = icalproperty_get_transp( p );
1102 if ( transparency == ICAL_TRANSP_TRANSPARENT ) {
1103 event->setTransparency( Event::Transparent );
1105 event->setTransparency( Event::Opaque );
1115 p = icalcomponent_get_next_property( vevent, ICAL_ANY_PROPERTY );
1120 if ( !dtEndProcessed && !event->hasDuration() ) {
1121 event->setDtEnd( event->
dtStart() );
1124 const TQString msade =
event->nonKDECustomProperty(
"X-MICROSOFT-CDO-ALLDAYEVENT");
1125 if ( !msade.isEmpty() ) {
1126 const bool floats = ( msade == TQString::fromLatin1(
"TRUE") );
1127 event->setFloats(floats);
1131 mCompat->fixEmptySummary( event );
1137 FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
1141 readIncidenceBase(vfreebusy, freebusy);
1143 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
1145 icaltimetype icaltime;
1149 icalproperty_kind kind = icalproperty_isa(p);
1152 case ICAL_DTSTART_PROPERTY:
1153 icaltime = icalproperty_get_dtstart(p);
1154 freebusy->
setDtStart(readICalDateTime(p, icaltime));
1157 case ICAL_DTEND_PROPERTY:
1158 icaltime = icalproperty_get_dtend(p);
1159 freebusy->setDtEnd(readICalDateTime(p, icaltime));
1162 case ICAL_FREEBUSY_PROPERTY:
1164 icalperiodtype icalperiod = icalproperty_get_freebusy(p);
1165 TQDateTime period_start = readICalDateTime(p, icalperiod.start);
1167 if ( !icaltime_is_null_time(icalperiod.end) ) {
1168 TQDateTime period_end = readICalDateTime(p, icalperiod.end);
1169 period =
Period(period_start, period_end);
1171 Duration duration = readICalDuration( icalperiod.duration );
1172 period =
Period(period_start, duration);
1174 icalparameter *param = icalproperty_get_first_parameter( p, ICAL_X_PARAMETER );
1176 if ( strncmp( icalparameter_get_xname( param ),
"X-SUMMARY", 9 ) == 0 ) {
1177 period.setSummary( TQString::fromUtf8(
1178 KCodecs::base64Decode( TQCString( icalparameter_get_xvalue( param ) ) ) ) );
1180 if ( strncmp( icalparameter_get_xname( param ),
"X-LOCATION", 10 ) == 0 ) {
1181 period.setLocation( TQString::fromUtf8(
1182 KCodecs::base64Decode( TQCString( icalparameter_get_xvalue( param ) ) ) ) );
1184 param = icalproperty_get_next_parameter( p, ICAL_X_PARAMETER );
1186 periods.append( period );
1195 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1202 Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1206 readIncidence(vjournal, 0, journal);
1211 Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1213 icalparameter *p = 0;
1215 TQString email = TQString::fromUtf8(icalproperty_get_attendee(attendee));
1216 if ( email.startsWith(
"mailto:",
false ) ) {
1217 email = email.mid( 7 );
1221 TQString uid = TQString();
1222 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1224 name = TQString::fromUtf8(icalparameter_get_cn(p));
1229 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1231 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1232 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp =
true;
1235 Attendee::PartStat status = Attendee::NeedsAction;
1236 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1238 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1239 switch(partStatParameter) {
1241 case ICAL_PARTSTAT_NEEDSACTION:
1242 status = Attendee::NeedsAction;
1244 case ICAL_PARTSTAT_ACCEPTED:
1245 status = Attendee::Accepted;
1247 case ICAL_PARTSTAT_DECLINED:
1248 status = Attendee::Declined;
1250 case ICAL_PARTSTAT_TENTATIVE:
1251 status = Attendee::Tentative;
1253 case ICAL_PARTSTAT_DELEGATED:
1254 status = Attendee::Delegated;
1256 case ICAL_PARTSTAT_COMPLETED:
1257 status = Attendee::Completed;
1259 case ICAL_PARTSTAT_INPROCESS:
1260 status = Attendee::InProcess;
1265 Attendee::Role role = Attendee::ReqParticipant;
1266 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1268 icalparameter_role roleParameter = icalparameter_get_role(p);
1269 switch(roleParameter) {
1270 case ICAL_ROLE_CHAIR:
1271 role = Attendee::Chair;
1274 case ICAL_ROLE_REQPARTICIPANT:
1275 role = Attendee::ReqParticipant;
1277 case ICAL_ROLE_OPTPARTICIPANT:
1278 role = Attendee::OptParticipant;
1280 case ICAL_ROLE_NONPARTICIPANT:
1281 role = Attendee::NonParticipant;
1286 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1287 uid = icalparameter_get_xvalue(p);
1298 p = icalproperty_get_first_parameter( attendee, ICAL_DELEGATEDTO_PARAMETER );
1301 #if ICAL_CHECK_VERSION(4,0,0)
1302 a->
setDelegate( icalparameter_get_delegatedto_nth( p, 0 ) );
1304 a->
setDelegate( icalparameter_get_delegatedto( p ) );
1308 p = icalproperty_get_first_parameter( attendee, ICAL_DELEGATEDFROM_PARAMETER );
1311 #if ICAL_CHECK_VERSION(4,0,0)
1312 a->
setDelegator( icalparameter_get_delegatedfrom_nth( p, 0 ) );
1314 a->
setDelegator( icalparameter_get_delegatedfrom( p ) );
1321 Person ICalFormatImpl::readOrganizer( icalproperty *organizer )
1323 TQString email = TQString::fromUtf8(icalproperty_get_organizer(organizer));
1324 if ( email.startsWith(
"mailto:",
false ) ) {
1325 email = email.mid( 7 );
1329 icalparameter *p = icalproperty_get_first_parameter(
1330 organizer, ICAL_CN_PARAMETER );
1333 cn = TQString::fromUtf8( icalparameter_get_cn( p ) );
1340 Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1345 icalvalue *value = icalproperty_get_value( attach );
1347 switch( icalvalue_isa( value ) ) {
1348 case ICAL_ATTACH_VALUE:
1350 icalattach *a = icalproperty_get_attach( attach );
1351 if ( !icalattach_get_is_url( a ) ) {
1352 p = (
const char *)icalattach_get_data( a );
1357 p = icalattach_get_url( a );
1359 attachment =
new Attachment( TQString::fromUtf8( p ) );
1364 case ICAL_BINARY_VALUE:
1366 icalattach *a = icalproperty_get_attach( attach );
1367 p = (
const char *)icalattach_get_data( a );
1373 case ICAL_URI_VALUE:
1374 p = icalvalue_get_uri( value );
1375 attachment =
new Attachment( TQString::fromUtf8( p ) );
1383 icalproperty_get_first_parameter( attach, ICAL_FMTTYPE_PARAMETER );
1385 attachment->setMimeType( TQString( icalparameter_get_fmttype( p ) ) );
1388 p = icalproperty_get_first_parameter( attach, ICAL_X_PARAMETER );
1390 TQString xname = TQString( icalparameter_get_xname( p ) ).upper();
1391 TQString xvalue = TQString::fromUtf8( icalparameter_get_xvalue( p ) );
1392 if ( xname ==
"X-CONTENT-DISPOSITION" ) {
1393 attachment->setShowInline( xvalue.lower() ==
"inline" );
1395 if ( xname ==
"X-LABEL" ) {
1396 attachment->setLabel( xvalue );
1398 p = icalproperty_get_next_parameter( attach, ICAL_X_PARAMETER );
1401 p = icalproperty_get_first_parameter( attach, ICAL_X_PARAMETER );
1403 if ( strncmp( icalparameter_get_xname( p ),
"X-LABEL", 7 ) == 0 ) {
1404 attachment->setLabel( TQString::fromUtf8( icalparameter_get_xvalue( p ) ) );
1406 p = icalproperty_get_next_parameter( attach, ICAL_X_PARAMETER );
1413 void ICalFormatImpl::readIncidence(icalcomponent *parent, icaltimezone *tz,
Incidence *incidence)
1415 readIncidenceBase(parent,incidence);
1417 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1420 int intvalue, inttext;
1421 icaltimetype icaltime;
1422 icaldurationtype icalduration;
1424 TQStringList categories;
1427 icalproperty_kind kind = icalproperty_isa(p);
1430 case ICAL_CREATED_PROPERTY:
1431 icaltime = icalproperty_get_created(p);
1432 incidence->
setCreated(readICalDateTime(p, icaltime, tz));
1435 case ICAL_SEQUENCE_PROPERTY:
1436 intvalue = icalproperty_get_sequence(p);
1440 case ICAL_LASTMODIFIED_PROPERTY:
1441 icaltime = icalproperty_get_lastmodified(p);
1445 case ICAL_DTSTART_PROPERTY:
1446 icaltime = icalproperty_get_dtstart(p);
1447 if (icaltime.is_date) {
1448 incidence->
setDtStart(TQDateTime(readICalDate(icaltime),TQTime(0,0,0)));
1451 incidence->
setDtStart(readICalDateTime(p, icaltime, tz));
1456 case ICAL_DURATION_PROPERTY:
1457 icalduration = icalproperty_get_duration(p);
1458 incidence->setDuration(readICalDuration(icalduration));
1461 case ICAL_DESCRIPTION_PROPERTY:
1462 text = icalproperty_get_description(p);
1466 case ICAL_SUMMARY_PROPERTY:
1467 text = icalproperty_get_summary(p);
1468 incidence->
setSummary(TQString::fromUtf8(text));
1471 case ICAL_LOCATION_PROPERTY:
1472 text = icalproperty_get_location(p);
1476 case ICAL_STATUS_PROPERTY: {
1478 switch (icalproperty_get_status(p)) {
1479 case ICAL_STATUS_TENTATIVE: stat = Incidence::StatusTentative;
break;
1480 case ICAL_STATUS_CONFIRMED: stat = Incidence::StatusConfirmed;
break;
1481 case ICAL_STATUS_COMPLETED: stat = Incidence::StatusCompleted;
break;
1482 case ICAL_STATUS_NEEDSACTION: stat = Incidence::StatusNeedsAction;
break;
1483 case ICAL_STATUS_CANCELLED: stat = Incidence::StatusCanceled;
break;
1484 case ICAL_STATUS_INPROCESS: stat = Incidence::StatusInProcess;
break;
1485 case ICAL_STATUS_DRAFT: stat = Incidence::StatusDraft;
break;
1486 case ICAL_STATUS_FINAL: stat = Incidence::StatusFinal;
break;
1488 incidence->
setCustomStatus(TQString::fromUtf8(icalvalue_get_x(icalproperty_get_value(p))));
1489 stat = Incidence::StatusX;
1491 case ICAL_STATUS_NONE:
1492 default: stat = Incidence::StatusNone;
break;
1494 if (stat != Incidence::StatusX)
1499 case ICAL_PRIORITY_PROPERTY:
1500 intvalue = icalproperty_get_priority( p );
1502 intvalue = mCompat->fixPriority( intvalue );
1506 case ICAL_CATEGORIES_PROPERTY:
1507 text = icalproperty_get_categories(p);
1508 categories.append(TQString::fromUtf8(text));
1511 case ICAL_RECURRENCEID_PROPERTY:
1512 icaltime = icalproperty_get_recurrenceid(p);
1517 case ICAL_RRULE_PROPERTY:
1518 readRecurrenceRule( p, incidence );
1526 case ICAL_RDATE_PROPERTY: {
1527 icaldatetimeperiodtype rd = icalproperty_get_rdate( p );
1528 if ( icaltime_is_valid_time( rd.time ) ) {
1529 if ( icaltime_is_date( rd.time ) ) {
1530 incidence->
recurrence()->addRDate( readICalDate( rd.time ) );
1532 incidence->
recurrence()->addRDateTime( readICalDateTime(p, rd.time, tz ) );
1539 case ICAL_EXRULE_PROPERTY:
1540 readExceptionRule( p, incidence );
1543 case ICAL_EXDATE_PROPERTY:
1544 icaltime = icalproperty_get_exdate(p);
1545 if ( icaltime_is_date(icaltime) ) {
1546 incidence->
recurrence()->addExDate( readICalDate(icaltime) );
1548 incidence->
recurrence()->addExDateTime( readICalDateTime(p, icaltime, tz) );
1552 case ICAL_CLASS_PROPERTY:
1553 inttext = icalproperty_get_class(p);
1554 if (inttext == ICAL_CLASS_PUBLIC ) {
1555 incidence->
setSecrecy(Incidence::SecrecyPublic);
1556 }
else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1557 incidence->
setSecrecy(Incidence::SecrecyConfidential);
1559 incidence->
setSecrecy(Incidence::SecrecyPrivate);
1563 case ICAL_ATTACH_PROPERTY:
1573 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1577 const TQString uid = incidence->
customProperty(
"LIBKCAL",
"ID" );
1578 if ( !uid.isNull() ) {
1583 incidence->
setUid( uid );
1588 if ( incidence->
doesRecur() && mCompat )
1589 mCompat->fixRecurrence( incidence );
1595 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1597 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1598 readAlarm(alarm,incidence);
1601 if ( mCompat ) mCompat->fixAlarms( incidence );
1605 void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,
IncidenceBase *incidenceBase)
1607 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1609 bool uidProcessed =
false;
1612 icalproperty_kind kind = icalproperty_isa( p );
1615 case ICAL_UID_PROPERTY:
1616 uidProcessed =
true;
1617 incidenceBase->
setUid( TQString::fromUtf8(icalproperty_get_uid( p ) ) );
1620 case ICAL_ORGANIZER_PROPERTY:
1624 case ICAL_ATTENDEE_PROPERTY:
1628 case ICAL_COMMENT_PROPERTY:
1630 TQString::fromUtf8( icalproperty_get_comment( p ) ) );
1637 p = icalcomponent_get_next_property( parent, ICAL_ANY_PROPERTY );
1640 if ( !uidProcessed ) {
1641 kdWarning() <<
"The incidence didn't have any UID! Report a bug "
1642 <<
"to the application that generated this file."
1647 incidenceBase->
setUid( TQString() );
1659 icalproperty *next =0;
1661 for ( p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1666 next = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1668 TQString value = TQString::fromUtf8(icalproperty_get_x(p));
1669 TQString name = icalproperty_get_x_name(p);
1671 if (name ==
"X-PILOTID" && !value.isEmpty()) {
1673 icalcomponent_remove_property(parent,p);
1674 }
else if (name ==
"X-PILOTSTAT" && !value.isEmpty()) {
1676 icalcomponent_remove_property(parent,p);
1681 readCustomProperties(parent, incidenceBase);
1684 void ICalFormatImpl::readCustomProperties(icalcomponent *parent,
CustomProperties *properties)
1686 TQMap<TQCString, TQString> customProperties;
1687 TQString lastProperty;
1689 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1693 TQString value = TQString::fromUtf8(icalproperty_get_x(p));
1694 const char *name = icalproperty_get_x_name(p);
1695 if ( lastProperty != name ) {
1696 customProperties[name] = value;
1698 customProperties[name] = customProperties[name].append(
"," ).append( value );
1701 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1702 lastProperty = name;
1710 void ICalFormatImpl::readRecurrenceRule(icalproperty *rrule,
Incidence *incidence )
1716 #if ICAL_CHECK_VERSION(4,0,0)
1717 struct icalrecurrencetype *r = icalproperty_get_rrule(rrule);
1720 struct icalrecurrencetype _r = icalproperty_get_rrule(rrule);
1721 struct icalrecurrencetype *r = &_r;
1727 readRecurrence( r, recurrule );
1728 recur->addRRule( recurrule );
1731 void ICalFormatImpl::readExceptionRule( icalproperty *rrule,
Incidence *incidence )
1735 #if ICAL_CHECK_VERSION(4,0,0)
1736 struct icalrecurrencetype *r = icalproperty_get_exrule(rrule);
1739 struct icalrecurrencetype _r = icalproperty_get_exrule(rrule);
1740 struct icalrecurrencetype *r = &_r;
1746 readRecurrence( r, recurrule );
1749 recur->addExRule( recurrule );
1752 #if ICAL_CHECK_VERSION(4,0,0)
1753 #define readSetByList(by_enum,setfunc) \
1756 while ( index < r->by[by_enum].size ) { \
1757 i = r->by[by_enum].data[index++]; \
1760 if ( !lst.isEmpty() ) recur->setfunc( lst );
1762 #define readSetByList(by_enum,setfunc) \
1765 while ( (i = r->by_enum[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) \
1767 if ( !lst.isEmpty() ) recur->setfunc( lst );
1769 void ICalFormatImpl::readRecurrence(
const struct icalrecurrencetype *r,
RecurrenceRule* recur )
1772 recur->mRRule = TQString( icalrecurrencetype_as_string(
const_cast<struct icalrecurrencetype*
>(r) ) );
1774 switch ( r->freq ) {
1775 case ICAL_SECONDLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rSecondly );
break;
1776 case ICAL_MINUTELY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rMinutely );
break;
1777 case ICAL_HOURLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rHourly );
break;
1778 case ICAL_DAILY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rDaily );
break;
1779 case ICAL_WEEKLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rWeekly );
break;
1780 case ICAL_MONTHLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rMonthly );
break;
1781 case ICAL_YEARLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rYearly );
break;
1782 case ICAL_NO_RECURRENCE:
1784 recur->setRecurrenceType( RecurrenceRule::rNone );
1790 if ( !icaltime_is_null_time( r->until ) ) {
1794 TQDateTime endDate( readICalDateTime(0, t) );
1804 int wkst = (r->week_start + 5)%7 + 1;
1805 recur->setWeekStart( wkst );
1808 TQValueList<int> lst;
1812 readSetByList( FIELD_BY_SECOND, setBySeconds );
1813 readSetByList( FIELD_BY_MINUTE, setByMinutes );
1814 readSetByList( FIELD_BY_HOUR, setByHours );
1815 readSetByList( FIELD_BY_MONTH_DAY, setByMonthDays );
1816 readSetByList( FIELD_BY_YEAR_DAY, setByYearDays );
1817 readSetByList( FIELD_BY_WEEK_NO, setByWeekNumbers );
1818 readSetByList( FIELD_BY_MONTH, setByMonths );
1819 readSetByList( FIELD_BY_SET_POS, setBySetPos );
1822 TQValueList<RecurrenceRule::WDayPos> wdlst;
1825 #if ICAL_CHECK_VERSION(4,0,0)
1826 while( index < r->by[ICAL_BY_DAY].size && (day = r->by[ICAL_BY_DAY].data[index++]) )
1828 while( (day = r->by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX )
1832 pos.setDay( ( icalrecurrencetype_day_day_of_week( day ) + 5 )%7 + 1 );
1833 pos.setPos( icalrecurrencetype_day_position( day ) );
1834 wdlst.append( pos );
1836 if ( !wdlst.isEmpty() ) recur->setByDays( wdlst );
1841 #undef readSetByList
1843 void ICalFormatImpl::readAlarm(icalcomponent *alarm,
Incidence *incidence)
1852 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1853 Alarm::Type type = Alarm::Display;
1854 icalproperty_action action = ICAL_ACTION_DISPLAY;
1856 kdDebug(5800) <<
"Unknown type of alarm, using default" << endl;
1860 action = icalproperty_get_action(p);
1862 case ICAL_ACTION_DISPLAY: type = Alarm::Display;
break;
1863 case ICAL_ACTION_AUDIO: type = Alarm::Audio;
break;
1864 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure;
break;
1865 case ICAL_ACTION_EMAIL: type = Alarm::Email;
break;
1867 kdDebug(5800) <<
"Unknown type of alarm: " << action << endl;
1874 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1876 icalproperty_kind kind = icalproperty_isa(p);
1880 case ICAL_TRIGGER_PROPERTY: {
1881 icaltriggertype trigger = icalproperty_get_trigger(p);
1882 if (icaltime_is_null_time(trigger.time)) {
1883 if (icaldurationtype_is_null_duration(trigger.duration)) {
1884 kdDebug(5800) <<
"ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1887 #if ICAL_CHECK_VERSION(4,0,0)
1888 icaldurationtype_as_utc_seconds( trigger.duration );
1890 icaldurationtype_as_int( trigger.duration );
1892 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1893 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1899 ialarm->
setTime(readICalDateTime(p, trigger.time));
1903 case ICAL_DURATION_PROPERTY: {
1904 icaldurationtype duration = icalproperty_get_duration(p);
1908 case ICAL_REPEAT_PROPERTY:
1913 case ICAL_DESCRIPTION_PROPERTY: {
1914 TQString description = TQString::fromUtf8(icalproperty_get_description(p));
1916 case ICAL_ACTION_DISPLAY:
1917 ialarm->
setText( description );
1919 case ICAL_ACTION_PROCEDURE:
1922 case ICAL_ACTION_EMAIL:
1931 case ICAL_SUMMARY_PROPERTY:
1932 ialarm->
setMailSubject(TQString::fromUtf8(icalproperty_get_summary(p)));
1936 case ICAL_ATTENDEE_PROPERTY: {
1937 TQString email = TQString::fromUtf8(icalproperty_get_attendee(p));
1938 if ( email.startsWith(
"mailto:",
false ) ) {
1939 email = email.mid( 7 );
1942 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1944 name = TQString::fromUtf8(icalparameter_get_cn(param));
1950 case ICAL_ATTACH_PROPERTY: {
1952 if ( attach && attach->isUri() ) {
1954 case ICAL_ACTION_AUDIO:
1957 case ICAL_ACTION_PROCEDURE:
1960 case ICAL_ACTION_EMAIL:
1967 kdDebug() <<
"Alarm attachments currently only support URIs, but "
1968 "no binary data" << endl;
1977 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1981 readCustomProperties(alarm, ialarm);
1986 icaldatetimeperiodtype ICalFormatImpl::writeICalDatePeriod(
const TQDate &date )
1988 icaldatetimeperiodtype t;
1989 t.time = writeICalDate( date );
1990 t.period = icalperiodtype_null_period();
1994 icaldatetimeperiodtype ICalFormatImpl::writeICalDateTimePeriod(
const TQDateTime &date )
1996 icaldatetimeperiodtype t;
1997 t.time = writeICalDateTime( date );
1998 t.period = icalperiodtype_null_period();
2002 icaltimetype ICalFormatImpl::writeICalDate(
const TQDate &date)
2004 icaltimetype t = icaltime_null_time();
2006 t.year = date.year();
2007 t.month = date.month();
2015 #if !ICAL_CHECK_VERSION(3,0,0)
2023 icaltimetype ICalFormatImpl::writeICalDateTime(
const TQDateTime &datetime)
2025 icaltimetype t = icaltime_null_time();
2027 t.year = datetime.date().year();
2028 t.month = datetime.date().month();
2029 t.day = datetime.date().day();
2031 t.hour = datetime.time().hour();
2032 t.minute = datetime.time().minute();
2033 t.second = datetime.time().second();
2036 t.zone = icaltimezone_get_builtin_timezone ( mParent->timeZoneId().latin1() );
2037 #if !ICAL_CHECK_VERSION(3,0,0)
2045 if (mParent->timeZoneId().isEmpty())
2046 t = icaltime_convert_to_zone( t, 0 );
2048 icaltimezone* tz = icaltimezone_get_builtin_timezone ( mParent->timeZoneId().latin1() );
2049 icaltimezone* utc = icaltimezone_get_utc_timezone();
2052 t = icaltime_convert_to_zone( t, utc );
2054 #if !ICAL_CHECK_VERSION(3,0,0)
2065 TQDateTime ICalFormatImpl::readICalDateTime( icalproperty *p, icaltimetype& t, icaltimezone* tz )
2068 #if ICAL_CHECK_VERSION(3,0,0)
2069 bool time_is_utc = icaltime_is_utc(t);
2071 bool time_is_utc = t.is_utc;
2073 if ( !time_is_utc ) {
2076 icalparameter *param = p ? icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER) : 0;
2077 const char *tzid = param ? icalparameter_get_tzid(param) : 0;
2079 icaltimezone* icaltz;
2081 icaltz = icaltimezone_get_builtin_timezone( tzid );
2088 if (tz && tz != icaltimezone_get_utc_timezone()) {
2089 #if !ICAL_CHECK_VERSION(3,0,0)
2095 #if !ICAL_CHECK_VERSION(3,0,0)
2098 t.zone = icaltimezone_get_utc_timezone();
2102 t.zone = icaltimezone_get_utc_timezone();
2107 if ( !mParent->timeZoneId().isEmpty() && t.zone ) {
2109 icaltimezone* viewTimeZone = icaltimezone_get_builtin_timezone ( mParent->timeZoneId().latin1() );
2110 icaltimezone_convert_time( &t,
const_cast<icaltimezone*
>(t.zone), viewTimeZone );
2114 return ICalDate2TQDate(t);
2117 TQDate ICalFormatImpl::readICalDate(icaltimetype t)
2119 return ICalDate2TQDate(t).date();
2122 icaldurationtype ICalFormatImpl::writeICalDuration(
int seconds)
2130 d.is_neg = (seconds<0)?1:0;
2131 if (seconds<0) seconds = -seconds;
2134 d.days = seconds / gSecondsPerDay;
2135 seconds %= gSecondsPerDay;
2136 d.hours = seconds / gSecondsPerHour;
2137 seconds %= gSecondsPerHour;
2138 d.minutes = seconds / gSecondsPerMinute;
2139 seconds %= gSecondsPerMinute;
2140 d.seconds = seconds;
2145 int ICalFormatImpl::readICalDuration(icaldurationtype d)
2149 result += d.weeks * gSecondsPerWeek;
2150 result += d.days * gSecondsPerDay;
2151 result += d.hours * gSecondsPerHour;
2152 result += d.minutes * gSecondsPerMinute;
2153 result += d.seconds;
2155 if (d.is_neg) result *= -1;
2160 icalcomponent *ICalFormatImpl::createCalendarComponent(
Calendar *cal)
2162 icalcomponent *calendar;
2165 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
2171 icalcomponent_add_property(calendar,p);
2176 p = icalproperty_new_version(
const_cast<char *
>(_ICAL_VERSION));
2177 icalcomponent_add_property(calendar,p);
2181 writeCustomProperties(calendar, cal);
2191 bool ICalFormatImpl::populate(
Calendar *cal, icalcomponent *calendar )
2196 if (!calendar)
return false;
2202 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
2204 kdDebug(5800) <<
"No PRODID property found" << endl;
2205 mLoadedProductId =
"";
2207 mLoadedProductId = TQString::fromUtf8(icalproperty_get_prodid(p));
2211 mCompat = CompatFactory::createCompat( mLoadedProductId );
2214 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
2216 kdDebug(5800) <<
"No VERSION property found" << endl;
2220 const char *version = icalproperty_get_version(p);
2222 kdDebug(5800) <<
"No VERSION property found" << endl;
2225 i18n(
"No VERSION property found" ) ) );
2231 if (strcmp(version,
"1.0") == 0) {
2232 kdDebug(5800) <<
"Expected iCalendar, got vCalendar" << endl;
2234 i18n(
"Expected iCalendar format")));
2236 }
else if (strcmp(version,
"2.0") != 0) {
2237 kdDebug(5800) <<
"Expected iCalendar, got unknown format" << endl;
2244 readCustomProperties(calendar, cal);
2249 icalcomponent *ctz =
2250 icalcomponent_get_first_component( calendar, ICAL_VTIMEZONE_COMPONENT );
2253 mEventsRelate.clear();
2254 mTodosRelate.clear();
2260 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
2263 Todo *todo = readTodo(c);
2266 TQString originalUid = todo->
uid();
2267 todo->
setUid(originalUid + TQString(
"-recur-%1").arg(todo->
recurrenceID().toTime_t()));
2268 if (!cal->
todo(todo->
uid())) {
2269 if ( !cal->
addTodo( todo ) ) {
2274 if (!cal->
event(originalUid)) {
2275 printf(
"FIXME! [WARNING] Parent for child event does not yet exist!\n");
2286 if (!cal->
todo(todo->
uid())) {
2287 if ( !cal->
addTodo( todo ) ) {
2294 mTodosRelate.remove( todo );
2298 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT);
2302 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
2305 Event *
event = readEvent(c, ctz);
2308 TQString originalUid =
event->uid();
2309 event->setUid(originalUid + TQString(
"-recur-%1").arg(event->
recurrenceID().toTime_t()));
2312 if (!cal->
event(originalUid)) {
2313 printf(
"FIXME! [WARNING] Parent for child event does not yet exist!\n");
2319 event->addChildIncidence(cal->
event(originalUid)->
uid());
2332 mEventsRelate.remove( event );
2336 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT);
2340 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
2343 Journal *journal = readJournal(c);
2346 TQString originalUid = journal->
uid();
2347 journal->
setUid(originalUid + TQString(
"-recur-%1").arg(journal->
recurrenceID().toTime_t()));
2350 if (!cal->
event(originalUid)) {
2351 printf(
"FIXME! [WARNING] Parent for child event does not yet exist!\n");
2373 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT);
2379 Event::List::ConstIterator eIt;
2380 for ( eIt = mEventsRelate.begin(); eIt != mEventsRelate.end(); ++eIt ) {
2381 (*eIt)->setRelatedTo( cal->
incidence( (*eIt)->relatedToUid() ) );
2383 Todo::List::ConstIterator tIt;
2384 for ( tIt = mTodosRelate.begin(); tIt != mTodosRelate.end(); ++tIt ) {
2385 (*tIt)->setRelatedTo( cal->
incidence( (*tIt)->relatedToUid() ) );
2391 TQString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
2396 TQString errorMessage;
2398 icalproperty *error;
2399 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY);
2401 errorMessage += icalproperty_get_xlicerror(error);
2402 errorMessage +=
"\n";
2403 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY);
2408 return errorMessage;
2411 #if ICAL_CHECK_VERSION(4,0,0)
2412 #define dumpByData(by_enum,by_string) \
2413 if (r->by[by_enum].size > 0) { \
2415 TQString out = by_string; \
2416 while( index < r->by[by_enum].size ) { \
2417 out.append(TQString::number(r->by[by_enum].data[index++]) + " "); \
2419 kdDebug(5800) << out << endl; \
2422 #define dumpByData(by_enum,by_string) \
2423 if (r->by_enum[0] != ICAL_RECURRENCE_ARRAY_MAX) { \
2426 TQString out = by_string; \
2427 while((i = r->by_enum[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { \
2428 out.append(TQString::number(i) + " "); \
2430 kdDebug(5800) << out << endl; \
2433 void ICalFormatImpl::dumpIcalRecurrence(
const icalrecurrencetype *r)
2440 kdDebug(5800) <<
" Freq: " << r->freq << endl;
2441 kdDebug(5800) <<
" Until: " << icaltime_as_ical_string(r->until) << endl;
2442 kdDebug(5800) <<
" Count: " << r->count << endl;
2444 dumpByData(FIELD_BY_DAY,
" By Day: ");
2445 dumpByData(FIELD_BY_MONTH_DAY,
" By Month Day: ");
2446 dumpByData(FIELD_BY_YEAR_DAY,
" By Year Day: ");
2447 dumpByData(FIELD_BY_MONTH,
" By Month: ");
2448 dumpByData(FIELD_BY_SET_POS,
" By Set Pos: ");
2452 icalcomponent *ICalFormatImpl::createScheduleComponent(
IncidenceBase *incidence,
2455 icalcomponent *message = createCalendarComponent();
2457 icalproperty_method icalmethod = ICAL_METHOD_NONE;
2460 case Scheduler::Publish:
2461 icalmethod = ICAL_METHOD_PUBLISH;
2463 case Scheduler::Request:
2464 icalmethod = ICAL_METHOD_REQUEST;
2466 case Scheduler::Refresh:
2467 icalmethod = ICAL_METHOD_REFRESH;
2469 case Scheduler::Cancel:
2470 icalmethod = ICAL_METHOD_CANCEL;
2472 case Scheduler::Add:
2473 icalmethod = ICAL_METHOD_ADD;
2475 case Scheduler::Reply:
2476 icalmethod = ICAL_METHOD_REPLY;
2478 case Scheduler::Counter:
2479 icalmethod = ICAL_METHOD_COUNTER;
2481 case Scheduler::Declinecounter:
2482 icalmethod = ICAL_METHOD_DECLINECOUNTER;
2485 kdDebug(5800) <<
"ICalFormat::createScheduleMessage(): Unknow method" << endl;
2489 icalcomponent_add_property(message,icalproperty_new_method(icalmethod));
2491 icalcomponent *inc = writeIncidence( incidence, method );
2500 if ( icalmethod == ICAL_METHOD_REPLY ) {
2501 struct icalreqstattype rst;
2502 rst.code = ICAL_2_0_SUCCESS_STATUS;
2505 icalcomponent_add_property( inc, icalproperty_new_requeststatus( rst ) );
2507 icalcomponent_add_component( message, inc );