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"
52 static TQDateTime ICalDate2TQDate(
const icaltimetype& t)
56 const int year = (t.year>=1754) ? t.year : 1754;
57 return TQDateTime(TQDate(year,t.month,t.day), TQTime(t.hour,t.minute,t.second));
72 static TQString quoteForParam(
const TQString &text )
76 if ( tmp.contains(
';' ) || tmp.contains(
':' ) || tmp.contains(
',' ) )
78 return TQString::fromLatin1(
"\"" ) + tmp + TQString::fromLatin1(
"\"" );
81 const int gSecondsPerMinute = 60;
82 const int gSecondsPerHour = gSecondsPerMinute * 60;
83 const int gSecondsPerDay = gSecondsPerHour * 24;
84 const int gSecondsPerWeek = gSecondsPerDay * 7;
86 ICalFormatImpl::ICalFormatImpl(
ICalFormat *parent ) :
87 mParent( parent ), mCompat( new
Compat )
91 ICalFormatImpl::~ICalFormatImpl()
99 ToComponentVisitor( ICalFormatImpl *impl,
Scheduler::Method m ) : mImpl( impl ), mComponent( 0 ), mMethod( m ) {}
101 bool visit(
Event *e ) { mComponent = mImpl->writeEvent( e );
return true; }
102 bool visit(
Todo *e ) { mComponent = mImpl->writeTodo( e );
return true; }
103 bool visit(
Journal *e ) { mComponent = mImpl->writeJournal( e );
return true; }
104 bool visit(
FreeBusy *fb ) { mComponent = mImpl->writeFreeBusy( fb, mMethod );
return true; }
106 icalcomponent *component() {
return mComponent; }
109 ICalFormatImpl *mImpl;
110 icalcomponent *mComponent;
116 ToComponentVisitor v(
this, method );
117 if ( incidence->
accept(v) )
118 return v.component();
122 icalcomponent *ICalFormatImpl::writeTodo(
Todo *todo)
125 TQStringList tmpStrList;
127 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
129 writeIncidence(vtodo,todo);
135 due = writeICalDate(todo->
dtDue(
true).date());
137 due = writeICalDateTime(todo->
dtDue(
true));
139 icalcomponent_add_property(vtodo,icalproperty_new_due(due));
147 start = writeICalDate(todo->
dtStart(
true).date());
150 start = writeICalDateTime(todo->
dtStart(
true));
152 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start));
162 icaltimetype completed = writeICalDateTime(todo->
completed());
163 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed));
166 icalcomponent_add_property(vtodo,
170 icalcomponent_add_property(vtodo,
171 icalproperty_new_recurrenceid( writeICalDateTime( todo->
dtDue())));
177 icalcomponent *ICalFormatImpl::writeEvent(
Event *event)
180 kdDebug(5800) <<
"Write Event '" <<
event->summary() <<
"' (" <<
event->uid()
185 TQStringList tmpStrList;
187 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
189 writeIncidence(vevent,event);
195 start = writeICalDate(event->
dtStart().date());
198 start = writeICalDateTime(event->
dtStart());
200 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start));
209 end = writeICalDate( event->
dtEnd().date().addDays( 1 ) );
210 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
213 if (event->
dtEnd() !=
event->dtStart()) {
214 end = writeICalDateTime(event->
dtEnd());
215 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
223 tmpStrList = anEvent->resources();
224 tmpStr = tmpStrList.join(
";");
225 if (!tmpStr.isEmpty())
226 addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
232 case Event::Transparent:
233 icalcomponent_add_property(
235 icalproperty_new_transp( ICAL_TRANSP_TRANSPARENT ) );
238 icalcomponent_add_property(
240 icalproperty_new_transp( ICAL_TRANSP_OPAQUE ) );
247 icalcomponent *ICalFormatImpl::writeFreeBusy(
FreeBusy *freebusy,
250 kdDebug(5800) <<
"icalformatimpl: writeFreeBusy: startDate: "
251 << freebusy->
dtStart().toString(
"ddd MMMM d yyyy: h:m:s ap") <<
" End Date: "
252 << freebusy->dtEnd().toString(
"ddd MMMM d yyyy: h:m:s ap") << endl;
254 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
256 writeIncidenceBase(vfreebusy,freebusy);
258 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
259 writeICalDateTime(freebusy->
dtStart())));
261 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
262 writeICalDateTime(freebusy->dtEnd())));
264 if (method == Scheduler::Request) {
265 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
266 freebusy->
uid().utf8()));
270 TQValueList<Period> list = freebusy->busyPeriods();
271 TQValueList<Period>::Iterator it;
272 icalperiodtype period = icalperiodtype_null_period();
273 for (it = list.begin(); it!= list.end(); ++it) {
274 period.start = writeICalDateTime((*it).start());
275 if ( (*it).hasDuration() ) {
276 period.duration = writeICalDuration( (*it).duration().asSeconds() );
278 period.end = writeICalDateTime((*it).end());
280 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
286 icalcomponent *ICalFormatImpl::writeJournal(
Journal *journal)
288 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
290 writeIncidence(vjournal,journal);
293 if (journal->
dtStart().isValid()) {
297 start = writeICalDate(journal->
dtStart().date());
300 start = writeICalDateTime(journal->
dtStart());
302 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
308 void ICalFormatImpl::writeIncidence(icalcomponent *parent,
Incidence *incidence)
319 p = icalproperty_new_x(TQString::number(incidence->
syncStatus()).utf8());
320 icalproperty_set_x_name(p,
"X-PILOTSTAT");
321 icalcomponent_add_property(parent,p);
323 p = icalproperty_new_x(TQString::number(incidence->
pilotId()).utf8());
324 icalproperty_set_x_name(p,
"X-PILOTID");
325 icalcomponent_add_property(parent,p);
328 TQString modifiedUid;
334 IncidenceListIterator it;
339 modifiedUid = incidence->
uid();
349 writeIncidenceBase(parent,incidence);
352 icalcomponent_add_property(parent,icalproperty_new_created(
353 writeICalDateTime(incidence->
created())));
360 icalcomponent_add_property(parent,icalproperty_new_uid(modifiedUid.utf8()));
364 icalcomponent_add_property(parent,icalproperty_new_uid(
371 icalcomponent_add_property(parent,icalproperty_new_sequence(
377 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
383 icalcomponent_add_property(parent,icalproperty_new_description(
388 if (!incidence->
summary().isEmpty()) {
389 icalcomponent_add_property(parent,icalproperty_new_summary(
394 if (!incidence->
location().isEmpty()) {
395 icalcomponent_add_property(parent,icalproperty_new_location(
400 icalproperty_status status = ICAL_STATUS_NONE;
401 switch (incidence->
status()) {
402 case Incidence::StatusTentative: status = ICAL_STATUS_TENTATIVE;
break;
403 case Incidence::StatusConfirmed: status = ICAL_STATUS_CONFIRMED;
break;
404 case Incidence::StatusCompleted: status = ICAL_STATUS_COMPLETED;
break;
405 case Incidence::StatusNeedsAction: status = ICAL_STATUS_NEEDSACTION;
break;
406 case Incidence::StatusCanceled: status = ICAL_STATUS_CANCELLED;
break;
407 case Incidence::StatusInProcess: status = ICAL_STATUS_INPROCESS;
break;
408 case Incidence::StatusDraft: status = ICAL_STATUS_DRAFT;
break;
409 case Incidence::StatusFinal: status = ICAL_STATUS_FINAL;
break;
410 case Incidence::StatusX: {
411 icalproperty* p = icalproperty_new_status(ICAL_STATUS_X);
412 icalvalue_set_x(icalproperty_get_value(p), incidence->
statusStr().utf8());
413 icalcomponent_add_property(parent, p);
416 case Incidence::StatusNone:
420 if (status != ICAL_STATUS_NONE)
421 icalcomponent_add_property(parent, icalproperty_new_status(status));
424 icalproperty_class secClass;
425 switch (incidence->
secrecy()) {
426 case Incidence::SecrecyPublic:
427 secClass = ICAL_CLASS_PUBLIC;
429 case Incidence::SecrecyConfidential:
430 secClass = ICAL_CLASS_CONFIDENTIAL;
432 case Incidence::SecrecyPrivate:
434 secClass = ICAL_CLASS_PRIVATE;
437 if ( secClass != ICAL_CLASS_PUBLIC ) {
438 icalcomponent_add_property(parent,icalproperty_new_class(secClass));
443 icalcomponent_add_property(parent,icalproperty_new_priority(
448 TQStringList categories = incidence->
categories();
449 TQStringList::Iterator it;
450 for(it = categories.begin(); it != categories.end(); ++it ) {
451 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
456 icalcomponent_add_property(parent,icalproperty_new_relatedto(
462 icalcomponent_add_property(parent, icalproperty_new_recurrenceid( writeICalDateTime( incidence->
recurrenceID() ) ));
469 RecurrenceRule::List::ConstIterator rit;
470 for ( rit = rrules.begin(); rit != rrules.end(); ++rit ) {
471 icalcomponent_add_property( parent, icalproperty_new_rrule(
472 writeRecurrenceRule( (*rit) ) ) );
476 RecurrenceRule::List::ConstIterator exit;
477 for ( exit = exrules.begin(); exit != exrules.end(); ++exit ) {
478 icalcomponent_add_property( parent, icalproperty_new_rrule(
479 writeRecurrenceRule( (*exit) ) ) );
482 DateList dateList = incidence->
recurrence()->exDates();
483 DateList::ConstIterator exIt;
484 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
485 icalcomponent_add_property(parent,icalproperty_new_exdate(
486 writeICalDate(*exIt)));
488 DateTimeList dateTimeList = incidence->
recurrence()->exDateTimes();
489 DateTimeList::ConstIterator extIt;
490 for(extIt = dateTimeList.begin(); extIt != dateTimeList.end(); ++extIt) {
491 icalcomponent_add_property(parent,icalproperty_new_exdate(
492 writeICalDateTime(*extIt)));
497 DateList::ConstIterator rdIt;
498 for( rdIt = dateList.begin(); rdIt != dateList.end(); ++rdIt) {
499 icalcomponent_add_property( parent, icalproperty_new_rdate(
500 writeICalDatePeriod(*rdIt) ) );
502 dateTimeList = incidence->
recurrence()->rDateTimes();
503 DateTimeList::ConstIterator rdtIt;
504 for( rdtIt = dateTimeList.begin(); rdtIt != dateTimeList.end(); ++rdtIt) {
505 icalcomponent_add_property( parent, icalproperty_new_rdate(
506 writeICalDateTimePeriod(*rdtIt) ) );
511 Attachment::List::ConstIterator atIt;
512 for ( atIt = attachments.begin(); atIt != attachments.end(); ++atIt ) {
513 icalcomponent_add_property( parent, writeAttachment( *atIt ) );
517 Alarm::List::ConstIterator alarmIt;
518 for ( alarmIt = incidence->
alarms().begin();
519 alarmIt != incidence->
alarms().end(); ++alarmIt ) {
520 if ( (*alarmIt)->enabled() ) {
522 icalcomponent_add_component( parent, writeAlarm( *alarmIt ) );
527 if (incidence->hasDuration()) {
528 icaldurationtype duration;
529 duration = writeICalDuration( incidence->duration() );
530 icalcomponent_add_property(parent,icalproperty_new_duration(duration));
534 void ICalFormatImpl::writeIncidenceBase( icalcomponent *parent,
537 icalcomponent_add_property( parent, icalproperty_new_dtstamp(
538 writeICalDateTime( TQDateTime::currentDateTime() ) ) );
541 if ( !incidenceBase->organizer().isEmpty() ) {
542 icalcomponent_add_property( parent, writeOrganizer( incidenceBase->organizer() ) );
547 Attendee::List::ConstIterator it;
548 for( it = incidenceBase->
attendees().begin();
549 it != incidenceBase->
attendees().end(); ++it ) {
550 icalcomponent_add_property( parent, writeAttendee( *it ) );
555 TQStringList comments = incidenceBase->
comments();
556 for (TQStringList::Iterator it=comments.begin(); it!=comments.end(); ++it) {
557 icalcomponent_add_property(parent, icalproperty_new_comment((*it).utf8()));
561 writeCustomProperties( parent, incidenceBase );
564 void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,
CustomProperties *properties)
567 for (TQMap<TQCString, TQString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
568 icalproperty *p = icalproperty_new_x(c.data().utf8());
569 icalproperty_set_x_name(p,c.key());
570 icalcomponent_add_property(parent,p);
574 icalproperty *ICalFormatImpl::writeOrganizer(
const Person &organizer )
576 icalproperty *p = icalproperty_new_organizer(
"MAILTO:" + organizer.email().utf8());
578 if (!organizer.name().isEmpty()) {
579 icalproperty_add_parameter( p, icalparameter_new_cn(quoteForParam(organizer.name()).utf8()) );
587 icalproperty *ICalFormatImpl::writeAttendee(
Attendee *attendee)
589 icalproperty *p = icalproperty_new_attendee(
"mailto:" + attendee->email().utf8());
591 if (!attendee->name().isEmpty()) {
592 icalproperty_add_parameter(p,icalparameter_new_cn(quoteForParam(attendee->name()).utf8()));
596 icalproperty_add_parameter(p,icalparameter_new_rsvp(
597 attendee->
RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
599 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
600 switch (attendee->
status()) {
602 case Attendee::NeedsAction:
603 status = ICAL_PARTSTAT_NEEDSACTION;
605 case Attendee::Accepted:
606 status = ICAL_PARTSTAT_ACCEPTED;
608 case Attendee::Declined:
609 status = ICAL_PARTSTAT_DECLINED;
611 case Attendee::Tentative:
612 status = ICAL_PARTSTAT_TENTATIVE;
614 case Attendee::Delegated:
615 status = ICAL_PARTSTAT_DELEGATED;
617 case Attendee::Completed:
618 status = ICAL_PARTSTAT_COMPLETED;
620 case Attendee::InProcess:
621 status = ICAL_PARTSTAT_INPROCESS;
624 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
626 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
627 switch (attendee->
role()) {
628 case Attendee::Chair:
629 role = ICAL_ROLE_CHAIR;
632 case Attendee::ReqParticipant:
633 role = ICAL_ROLE_REQPARTICIPANT;
635 case Attendee::OptParticipant:
636 role = ICAL_ROLE_OPTPARTICIPANT;
638 case Attendee::NonParticipant:
639 role = ICAL_ROLE_NONPARTICIPANT;
642 icalproperty_add_parameter(p,icalparameter_new_role(role));
644 if (!attendee->
uid().isEmpty()) {
645 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->
uid().utf8());
646 icalparameter_set_xname(icalparameter_uid,
"X-UID");
647 icalproperty_add_parameter(p,icalparameter_uid);
650 if ( !attendee->
delegate().isEmpty() ) {
651 icalparameter* icalparameter_delegate = icalparameter_new_delegatedto( attendee->
delegate().utf8() );
652 icalproperty_add_parameter( p, icalparameter_delegate );
655 if ( !attendee->
delegator().isEmpty() ) {
656 icalparameter* icalparameter_delegator = icalparameter_new_delegatedfrom( attendee->
delegator().utf8() );
657 icalproperty_add_parameter( p, icalparameter_delegator );
663 icalproperty *ICalFormatImpl::writeAttachment(
Attachment *att )
666 if ( att->isUri() ) {
667 attach = icalattach_new_from_url( att->uri().utf8().data() );
669 #ifdef USE_LIBICAL_0_46
670 attach = icalattach_new_from_data ( (
const char *)att->data(), 0, 0 );
672 attach = icalattach_new_from_data ( (
unsigned char *)att->data(), 0, 0 );
675 icalproperty *p = icalproperty_new_attach( attach );
677 if ( !att->mimeType().isEmpty() ) {
678 icalproperty_add_parameter( p,
679 icalparameter_new_fmttype( att->mimeType().utf8().data() ) );
682 if ( att->isBinary() ) {
683 icalproperty_add_parameter( p,
684 icalparameter_new_value( ICAL_VALUE_BINARY ) );
685 icalproperty_add_parameter( p,
686 icalparameter_new_encoding( ICAL_ENCODING_BASE64 ) );
689 if ( att->showInline() ) {
690 icalparameter* icalparameter_inline = icalparameter_new_x(
"inline" );
691 icalparameter_set_xname( icalparameter_inline,
"X-CONTENT-DISPOSITION" );
692 icalproperty_add_parameter( p, icalparameter_inline );
695 if ( !att->label().isEmpty() ) {
696 icalparameter* icalparameter_label = icalparameter_new_x( att->label().utf8() );
697 icalparameter_set_xname( icalparameter_label,
"X-LABEL" );
698 icalproperty_add_parameter( p, icalparameter_label );
704 icalrecurrencetype ICalFormatImpl::writeRecurrenceRule(
RecurrenceRule *recur )
708 icalrecurrencetype r;
709 icalrecurrencetype_clear(&r);
711 switch( recur->recurrenceType() ) {
712 case RecurrenceRule::rSecondly:
713 r.freq = ICAL_SECONDLY_RECURRENCE;
715 case RecurrenceRule::rMinutely:
716 r.freq = ICAL_MINUTELY_RECURRENCE;
718 case RecurrenceRule::rHourly:
719 r.freq = ICAL_HOURLY_RECURRENCE;
721 case RecurrenceRule::rDaily:
722 r.freq = ICAL_DAILY_RECURRENCE;
724 case RecurrenceRule::rWeekly:
725 r.freq = ICAL_WEEKLY_RECURRENCE;
727 case RecurrenceRule::rMonthly:
728 r.freq = ICAL_MONTHLY_RECURRENCE;
730 case RecurrenceRule::rYearly:
731 r.freq = ICAL_YEARLY_RECURRENCE;
734 r.freq = ICAL_NO_RECURRENCE;
735 kdDebug(5800) <<
"ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
740 TQValueList<int> bys;
741 TQValueList<int>::ConstIterator it;
744 bys = recur->bySeconds();
746 for ( it = bys.begin(); it != bys.end(); ++it ) {
747 r.by_second[index++] = *it;
750 bys = recur->byMinutes();
752 for ( it = bys.begin(); it != bys.end(); ++it ) {
753 r.by_minute[index++] = *it;
756 bys = recur->byHours();
758 for ( it = bys.begin(); it != bys.end(); ++it ) {
759 r.by_hour[index++] = *it;
762 bys = recur->byMonthDays();
764 for ( it = bys.begin(); it != bys.end(); ++it ) {
765 r.by_month_day[index++] = icalrecurrencetype_day_position( (*it) * 8 );
768 bys = recur->byYearDays();
770 for ( it = bys.begin(); it != bys.end(); ++it ) {
771 r.by_year_day[index++] = *it;
774 bys = recur->byWeekNumbers();
776 for ( it = bys.begin(); it != bys.end(); ++it ) {
777 r.by_week_no[index++] = *it;
780 bys = recur->byMonths();
782 for ( it = bys.begin(); it != bys.end(); ++it ) {
783 r.by_month[index++] = *it;
786 bys = recur->bySetPos();
788 for ( it = bys.begin(); it != bys.end(); ++it ) {
789 r.by_set_pos[index++] = *it;
793 TQValueList<RecurrenceRule::WDayPos> byd = recur->byDays();
796 for ( TQValueList<RecurrenceRule::WDayPos>::ConstIterator dit = byd.begin();
797 dit != byd.end(); ++dit ) {
798 day = (*dit).day() % 7 + 1;
799 if ( (*dit).pos() < 0 ) {
800 day += (-(*dit).pos())*8;
803 day += (*dit).pos()*8;
805 r.by_day[index++] = day;
808 r.week_start =
static_cast<icalrecurrencetype_weekday
>(
809 recur->weekStart()%7 + 1);
818 }
else if ( recur->
duration() == -1 ) {
822 r.until = writeICalDate(recur->
endDt().date());
824 r.until = writeICalDateTime(recur->
endDt());
829 const char *str = icalrecurrencetype_as_string(&r);
831 kdDebug(5800) <<
" String: " << str << endl;
833 kdDebug(5800) <<
" No String" << endl;
841 icalcomponent *ICalFormatImpl::writeAlarm(
Alarm *alarm)
844 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
846 icalproperty_action action;
847 icalattach *attach = 0;
849 switch (alarm->
type()) {
850 case Alarm::Procedure:
851 action = ICAL_ACTION_PROCEDURE;
852 attach = icalattach_new_from_url(TQFile::encodeName(alarm->
programFile()).data());
853 icalcomponent_add_property(a,icalproperty_new_attach(attach));
855 icalcomponent_add_property(a,icalproperty_new_description(alarm->
programArguments().utf8()));
859 action = ICAL_ACTION_AUDIO;
862 attach = icalattach_new_from_url(TQFile::encodeName( alarm->
audioFile() ).data());
863 icalcomponent_add_property(a,icalproperty_new_attach(attach));
867 action = ICAL_ACTION_EMAIL;
869 for (TQValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
870 icalproperty *p = icalproperty_new_attendee(
"MAILTO:" + (*ad).email().utf8());
871 if (!(*ad).name().isEmpty()) {
872 icalproperty_add_parameter(p,icalparameter_new_cn(quoteForParam((*ad).name()).utf8()));
874 icalcomponent_add_property(a,p);
876 icalcomponent_add_property(a,icalproperty_new_summary(alarm->
mailSubject().utf8()));
877 icalcomponent_add_property(a,icalproperty_new_description(alarm->
mailText().utf8()));
879 if (attachments.count() > 0) {
880 for (TQStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
881 attach = icalattach_new_from_url(TQFile::encodeName( *at ).data());
882 icalcomponent_add_property(a,icalproperty_new_attach(attach));
888 action = ICAL_ACTION_DISPLAY;
889 icalcomponent_add_property(a,icalproperty_new_description(alarm->
text().utf8()));
893 kdDebug(5800) <<
"Unknown type of alarm" << endl;
894 action = ICAL_ACTION_NONE;
897 icalcomponent_add_property(a,icalproperty_new_action(action));
900 icaltriggertype trigger;
902 trigger.time = writeICalDateTime(alarm->
time());
903 trigger.duration = icaldurationtype_null_duration();
905 trigger.time = icaltime_null_time();
911 trigger.duration = writeICalDuration( offset.
asSeconds() );
913 icalproperty *p = icalproperty_new_trigger(trigger);
915 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
916 icalcomponent_add_property(a,p);
920 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->
repeatCount()));
921 icalcomponent_add_property(a,icalproperty_new_duration(
927 for (TQMap<TQCString, TQString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
928 icalproperty *p = icalproperty_new_x(c.data().utf8());
929 icalproperty_set_x_name(p,c.key());
930 icalcomponent_add_property(a,p);
936 Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
940 readIncidence(vtodo, 0, todo);
942 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
945 icaltimetype icaltime;
947 TQStringList categories;
950 icalproperty_kind kind = icalproperty_isa(p);
953 case ICAL_DUE_PROPERTY:
954 icaltime = icalproperty_get_due(p);
955 if (icaltime.is_date) {
956 todo->
setDtDue(TQDateTime(readICalDate(icaltime),TQTime(0,0,0)),
true);
958 todo->
setDtDue(readICalDateTime(p, icaltime),
true);
964 case ICAL_COMPLETED_PROPERTY:
965 icaltime = icalproperty_get_completed(p);
969 case ICAL_PERCENTCOMPLETE_PROPERTY:
973 case ICAL_RELATEDTO_PROPERTY:
974 todo->
setRelatedToUid(TQString::fromUtf8(icalproperty_get_relatedto(p)));
975 mTodosRelate.append(todo);
978 case ICAL_DTSTART_PROPERTY: {
980 if ( todo->
comments().grep(
"NoStartDate").count() )
987 case ICAL_RECURRENCEID_PROPERTY:
988 icaltime = icalproperty_get_recurrenceid(p);
998 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY);
1001 if (mCompat) mCompat->fixEmptySummary( todo );
1006 Event *ICalFormatImpl::readEvent( icalcomponent *vevent, icalcomponent *vtimezone )
1011 icaltimezone *tz = icaltimezone_new();
1012 if ( !icaltimezone_set_component( tz, vtimezone ) ) {
1013 icaltimezone_free( tz, 1 );
1017 readIncidence( vevent, tz, event);
1019 icalproperty *p = icalcomponent_get_first_property( vevent, ICAL_ANY_PROPERTY );
1022 icaltimetype icaltime;
1024 TQStringList categories;
1025 icalproperty_transp transparency;
1027 bool dtEndProcessed =
false;
1030 icalproperty_kind kind = icalproperty_isa( p );
1033 case ICAL_DTEND_PROPERTY:
1034 icaltime = icalproperty_get_dtend( p );
1035 if ( icaltime.is_date ) {
1037 TQDate endDate = readICalDate( icaltime ).addDays( -1 );
1039 mCompat->fixFloatingEnd( endDate );
1042 if ( endDate < event->dtStart().date() ) {
1043 endDate =
event->dtStart().date();
1045 event->setDtEnd( TQDateTime( endDate, TQTime( 0, 0, 0 ) ) );
1047 event->setDtEnd(readICalDateTime(p, icaltime, tz));
1048 event->setFloats(
false );
1050 dtEndProcessed =
true;
1053 case ICAL_RELATEDTO_PROPERTY:
1054 event->setRelatedToUid( TQString::fromUtf8( icalproperty_get_relatedto( p ) ) );
1055 mEventsRelate.append( event );
1058 case ICAL_TRANSP_PROPERTY:
1059 transparency = icalproperty_get_transp( p );
1060 if ( transparency == ICAL_TRANSP_TRANSPARENT ) {
1061 event->setTransparency( Event::Transparent );
1063 event->setTransparency( Event::Opaque );
1073 p = icalcomponent_get_next_property( vevent, ICAL_ANY_PROPERTY );
1078 if ( !dtEndProcessed && !event->hasDuration() ) {
1079 event->setDtEnd( event->
dtStart() );
1082 const TQString msade =
event->nonKDECustomProperty(
"X-MICROSOFT-CDO-ALLDAYEVENT");
1083 if ( !msade.isEmpty() ) {
1084 const bool floats = ( msade == TQString::fromLatin1(
"TRUE") );
1085 event->setFloats(floats);
1089 mCompat->fixEmptySummary( event );
1095 FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
1099 readIncidenceBase(vfreebusy, freebusy);
1101 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
1103 icaltimetype icaltime;
1107 icalproperty_kind kind = icalproperty_isa(p);
1110 case ICAL_DTSTART_PROPERTY:
1111 icaltime = icalproperty_get_dtstart(p);
1112 freebusy->
setDtStart(readICalDateTime(p, icaltime));
1115 case ICAL_DTEND_PROPERTY:
1116 icaltime = icalproperty_get_dtend(p);
1117 freebusy->setDtEnd(readICalDateTime(p, icaltime));
1120 case ICAL_FREEBUSY_PROPERTY:
1122 icalperiodtype icalperiod = icalproperty_get_freebusy(p);
1123 TQDateTime period_start = readICalDateTime(p, icalperiod.start);
1125 if ( !icaltime_is_null_time(icalperiod.end) ) {
1126 TQDateTime period_end = readICalDateTime(p, icalperiod.end);
1127 period =
Period(period_start, period_end);
1129 Duration duration = readICalDuration( icalperiod.duration );
1130 period =
Period(period_start, duration);
1132 icalparameter *param = icalproperty_get_first_parameter( p, ICAL_X_PARAMETER );
1134 if ( strncmp( icalparameter_get_xname( param ),
"X-SUMMARY", 9 ) == 0 ) {
1135 period.setSummary( TQString::fromUtf8(
1136 KCodecs::base64Decode( TQCString( icalparameter_get_xvalue( param ) ) ) ) );
1138 if ( strncmp( icalparameter_get_xname( param ),
"X-LOCATION", 10 ) == 0 ) {
1139 period.setLocation( TQString::fromUtf8(
1140 KCodecs::base64Decode( TQCString( icalparameter_get_xvalue( param ) ) ) ) );
1142 param = icalproperty_get_next_parameter( p, ICAL_X_PARAMETER );
1144 periods.append( period );
1153 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1160 Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1164 readIncidence(vjournal, 0, journal);
1169 Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1171 icalparameter *p = 0;
1173 TQString email = TQString::fromUtf8(icalproperty_get_attendee(attendee));
1174 if ( email.startsWith(
"mailto:",
false ) ) {
1175 email = email.mid( 7 );
1179 TQString uid = TQString();
1180 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1182 name = TQString::fromUtf8(icalparameter_get_cn(p));
1187 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1189 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1190 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp =
true;
1193 Attendee::PartStat status = Attendee::NeedsAction;
1194 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1196 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1197 switch(partStatParameter) {
1199 case ICAL_PARTSTAT_NEEDSACTION:
1200 status = Attendee::NeedsAction;
1202 case ICAL_PARTSTAT_ACCEPTED:
1203 status = Attendee::Accepted;
1205 case ICAL_PARTSTAT_DECLINED:
1206 status = Attendee::Declined;
1208 case ICAL_PARTSTAT_TENTATIVE:
1209 status = Attendee::Tentative;
1211 case ICAL_PARTSTAT_DELEGATED:
1212 status = Attendee::Delegated;
1214 case ICAL_PARTSTAT_COMPLETED:
1215 status = Attendee::Completed;
1217 case ICAL_PARTSTAT_INPROCESS:
1218 status = Attendee::InProcess;
1223 Attendee::Role role = Attendee::ReqParticipant;
1224 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1226 icalparameter_role roleParameter = icalparameter_get_role(p);
1227 switch(roleParameter) {
1228 case ICAL_ROLE_CHAIR:
1229 role = Attendee::Chair;
1232 case ICAL_ROLE_REQPARTICIPANT:
1233 role = Attendee::ReqParticipant;
1235 case ICAL_ROLE_OPTPARTICIPANT:
1236 role = Attendee::OptParticipant;
1238 case ICAL_ROLE_NONPARTICIPANT:
1239 role = Attendee::NonParticipant;
1244 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1245 uid = icalparameter_get_xvalue(p);
1256 p = icalproperty_get_first_parameter( attendee, ICAL_DELEGATEDTO_PARAMETER );
1258 a->
setDelegate( icalparameter_get_delegatedto( p ) );
1260 p = icalproperty_get_first_parameter( attendee, ICAL_DELEGATEDFROM_PARAMETER );
1262 a->
setDelegator( icalparameter_get_delegatedfrom( p ) );
1267 Person ICalFormatImpl::readOrganizer( icalproperty *organizer )
1269 TQString email = TQString::fromUtf8(icalproperty_get_organizer(organizer));
1270 if ( email.startsWith(
"mailto:",
false ) ) {
1271 email = email.mid( 7 );
1275 icalparameter *p = icalproperty_get_first_parameter(
1276 organizer, ICAL_CN_PARAMETER );
1279 cn = TQString::fromUtf8( icalparameter_get_cn( p ) );
1286 Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1291 icalvalue *value = icalproperty_get_value( attach );
1293 switch( icalvalue_isa( value ) ) {
1294 case ICAL_ATTACH_VALUE:
1296 icalattach *a = icalproperty_get_attach( attach );
1297 if ( !icalattach_get_is_url( a ) ) {
1298 p = (
const char *)icalattach_get_data( a );
1303 p = icalattach_get_url( a );
1305 attachment =
new Attachment( TQString::fromUtf8( p ) );
1310 case ICAL_BINARY_VALUE:
1312 icalattach *a = icalproperty_get_attach( attach );
1313 p = (
const char *)icalattach_get_data( a );
1319 case ICAL_URI_VALUE:
1320 p = icalvalue_get_uri( value );
1321 attachment =
new Attachment( TQString::fromUtf8( p ) );
1329 icalproperty_get_first_parameter( attach, ICAL_FMTTYPE_PARAMETER );
1331 attachment->setMimeType( TQString( icalparameter_get_fmttype( p ) ) );
1334 p = icalproperty_get_first_parameter( attach, ICAL_X_PARAMETER );
1336 TQString xname = TQString( icalparameter_get_xname( p ) ).upper();
1337 TQString xvalue = TQString::fromUtf8( icalparameter_get_xvalue( p ) );
1338 if ( xname ==
"X-CONTENT-DISPOSITION" ) {
1339 attachment->setShowInline( xvalue.lower() ==
"inline" );
1341 if ( xname ==
"X-LABEL" ) {
1342 attachment->setLabel( xvalue );
1344 p = icalproperty_get_next_parameter( attach, ICAL_X_PARAMETER );
1347 p = icalproperty_get_first_parameter( attach, ICAL_X_PARAMETER );
1349 if ( strncmp( icalparameter_get_xname( p ),
"X-LABEL", 7 ) == 0 ) {
1350 attachment->setLabel( TQString::fromUtf8( icalparameter_get_xvalue( p ) ) );
1352 p = icalproperty_get_next_parameter( attach, ICAL_X_PARAMETER );
1359 void ICalFormatImpl::readIncidence(icalcomponent *parent, icaltimezone *tz,
Incidence *incidence)
1361 readIncidenceBase(parent,incidence);
1363 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1366 int intvalue, inttext;
1367 icaltimetype icaltime;
1368 icaldurationtype icalduration;
1370 TQStringList categories;
1373 icalproperty_kind kind = icalproperty_isa(p);
1376 case ICAL_CREATED_PROPERTY:
1377 icaltime = icalproperty_get_created(p);
1378 incidence->
setCreated(readICalDateTime(p, icaltime, tz));
1381 case ICAL_SEQUENCE_PROPERTY:
1382 intvalue = icalproperty_get_sequence(p);
1386 case ICAL_LASTMODIFIED_PROPERTY:
1387 icaltime = icalproperty_get_lastmodified(p);
1391 case ICAL_DTSTART_PROPERTY:
1392 icaltime = icalproperty_get_dtstart(p);
1393 if (icaltime.is_date) {
1394 incidence->
setDtStart(TQDateTime(readICalDate(icaltime),TQTime(0,0,0)));
1397 incidence->
setDtStart(readICalDateTime(p, icaltime, tz));
1402 case ICAL_DURATION_PROPERTY:
1403 icalduration = icalproperty_get_duration(p);
1404 incidence->setDuration(readICalDuration(icalduration));
1407 case ICAL_DESCRIPTION_PROPERTY:
1408 text = icalproperty_get_description(p);
1412 case ICAL_SUMMARY_PROPERTY:
1413 text = icalproperty_get_summary(p);
1414 incidence->
setSummary(TQString::fromUtf8(text));
1417 case ICAL_LOCATION_PROPERTY:
1418 text = icalproperty_get_location(p);
1422 case ICAL_STATUS_PROPERTY: {
1424 switch (icalproperty_get_status(p)) {
1425 case ICAL_STATUS_TENTATIVE: stat = Incidence::StatusTentative;
break;
1426 case ICAL_STATUS_CONFIRMED: stat = Incidence::StatusConfirmed;
break;
1427 case ICAL_STATUS_COMPLETED: stat = Incidence::StatusCompleted;
break;
1428 case ICAL_STATUS_NEEDSACTION: stat = Incidence::StatusNeedsAction;
break;
1429 case ICAL_STATUS_CANCELLED: stat = Incidence::StatusCanceled;
break;
1430 case ICAL_STATUS_INPROCESS: stat = Incidence::StatusInProcess;
break;
1431 case ICAL_STATUS_DRAFT: stat = Incidence::StatusDraft;
break;
1432 case ICAL_STATUS_FINAL: stat = Incidence::StatusFinal;
break;
1434 incidence->
setCustomStatus(TQString::fromUtf8(icalvalue_get_x(icalproperty_get_value(p))));
1435 stat = Incidence::StatusX;
1437 case ICAL_STATUS_NONE:
1438 default: stat = Incidence::StatusNone;
break;
1440 if (stat != Incidence::StatusX)
1445 case ICAL_PRIORITY_PROPERTY:
1446 intvalue = icalproperty_get_priority( p );
1448 intvalue = mCompat->fixPriority( intvalue );
1452 case ICAL_CATEGORIES_PROPERTY:
1453 text = icalproperty_get_categories(p);
1454 categories.append(TQString::fromUtf8(text));
1457 case ICAL_RECURRENCEID_PROPERTY:
1458 icaltime = icalproperty_get_recurrenceid(p);
1463 case ICAL_RRULE_PROPERTY:
1464 readRecurrenceRule( p, incidence );
1472 case ICAL_RDATE_PROPERTY: {
1473 icaldatetimeperiodtype rd = icalproperty_get_rdate( p );
1474 if ( icaltime_is_valid_time( rd.time ) ) {
1475 if ( icaltime_is_date( rd.time ) ) {
1476 incidence->
recurrence()->addRDate( readICalDate( rd.time ) );
1478 incidence->
recurrence()->addRDateTime( readICalDateTime(p, rd.time, tz ) );
1485 case ICAL_EXRULE_PROPERTY:
1486 readExceptionRule( p, incidence );
1489 case ICAL_EXDATE_PROPERTY:
1490 icaltime = icalproperty_get_exdate(p);
1491 if ( icaltime_is_date(icaltime) ) {
1492 incidence->
recurrence()->addExDate( readICalDate(icaltime) );
1494 incidence->
recurrence()->addExDateTime( readICalDateTime(p, icaltime, tz) );
1498 case ICAL_CLASS_PROPERTY:
1499 inttext = icalproperty_get_class(p);
1500 if (inttext == ICAL_CLASS_PUBLIC ) {
1501 incidence->
setSecrecy(Incidence::SecrecyPublic);
1502 }
else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1503 incidence->
setSecrecy(Incidence::SecrecyConfidential);
1505 incidence->
setSecrecy(Incidence::SecrecyPrivate);
1509 case ICAL_ATTACH_PROPERTY:
1519 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1523 const TQString uid = incidence->
customProperty(
"LIBKCAL",
"ID" );
1524 if ( !uid.isNull() ) {
1529 incidence->
setUid( uid );
1534 if ( incidence->
doesRecur() && mCompat )
1535 mCompat->fixRecurrence( incidence );
1541 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1543 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1544 readAlarm(alarm,incidence);
1547 if ( mCompat ) mCompat->fixAlarms( incidence );
1551 void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,
IncidenceBase *incidenceBase)
1553 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1555 bool uidProcessed =
false;
1558 icalproperty_kind kind = icalproperty_isa( p );
1561 case ICAL_UID_PROPERTY:
1562 uidProcessed =
true;
1563 incidenceBase->
setUid( TQString::fromUtf8(icalproperty_get_uid( p ) ) );
1566 case ICAL_ORGANIZER_PROPERTY:
1570 case ICAL_ATTENDEE_PROPERTY:
1574 case ICAL_COMMENT_PROPERTY:
1576 TQString::fromUtf8( icalproperty_get_comment( p ) ) );
1583 p = icalcomponent_get_next_property( parent, ICAL_ANY_PROPERTY );
1586 if ( !uidProcessed ) {
1587 kdWarning() <<
"The incidence didn't have any UID! Report a bug "
1588 <<
"to the application that generated this file."
1593 incidenceBase->
setUid( TQString() );
1605 icalproperty *next =0;
1607 for ( p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1612 next = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1614 TQString value = TQString::fromUtf8(icalproperty_get_x(p));
1615 TQString name = icalproperty_get_x_name(p);
1617 if (name ==
"X-PILOTID" && !value.isEmpty()) {
1619 icalcomponent_remove_property(parent,p);
1620 }
else if (name ==
"X-PILOTSTAT" && !value.isEmpty()) {
1622 icalcomponent_remove_property(parent,p);
1627 readCustomProperties(parent, incidenceBase);
1630 void ICalFormatImpl::readCustomProperties(icalcomponent *parent,
CustomProperties *properties)
1632 TQMap<TQCString, TQString> customProperties;
1633 TQString lastProperty;
1635 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1639 TQString value = TQString::fromUtf8(icalproperty_get_x(p));
1640 const char *name = icalproperty_get_x_name(p);
1641 if ( lastProperty != name ) {
1642 customProperties[name] = value;
1644 customProperties[name] = customProperties[name].append(
"," ).append( value );
1647 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1648 lastProperty = name;
1656 void ICalFormatImpl::readRecurrenceRule(icalproperty *rrule,
Incidence *incidence )
1662 struct icalrecurrencetype r = icalproperty_get_rrule(rrule);
1667 readRecurrence( r, recurrule );
1668 recur->addRRule( recurrule );
1671 void ICalFormatImpl::readExceptionRule( icalproperty *rrule,
Incidence *incidence )
1675 struct icalrecurrencetype r = icalproperty_get_exrule(rrule);
1680 readRecurrence( r, recurrule );
1683 recur->addExRule( recurrule );
1686 void ICalFormatImpl::readRecurrence(
const struct icalrecurrencetype &r,
RecurrenceRule* recur )
1689 recur->mRRule = TQString( icalrecurrencetype_as_string( const_cast<struct icalrecurrencetype*>(&r) ) );
1692 case ICAL_SECONDLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rSecondly );
break;
1693 case ICAL_MINUTELY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rMinutely );
break;
1694 case ICAL_HOURLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rHourly );
break;
1695 case ICAL_DAILY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rDaily );
break;
1696 case ICAL_WEEKLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rWeekly );
break;
1697 case ICAL_MONTHLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rMonthly );
break;
1698 case ICAL_YEARLY_RECURRENCE: recur->setRecurrenceType( RecurrenceRule::rYearly );
break;
1699 case ICAL_NO_RECURRENCE:
1701 recur->setRecurrenceType( RecurrenceRule::rNone );
1707 if ( !icaltime_is_null_time( r.until ) ) {
1711 TQDateTime endDate( readICalDateTime(0, t) );
1721 int wkst = (r.week_start + 5)%7 + 1;
1722 recur->setWeekStart( wkst );
1725 TQValueList<int> lst;
1729 #define readSetByList(rrulecomp,setfunc) \
1732 while ( (i = r.rrulecomp[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) \
1734 if ( !lst.isEmpty() ) recur->setfunc( lst );
1739 readSetByList( by_second, setBySeconds );
1740 readSetByList( by_minute, setByMinutes );
1741 readSetByList( by_hour, setByHours );
1742 readSetByList( by_month_day, setByMonthDays );
1743 readSetByList( by_year_day, setByYearDays );
1744 readSetByList( by_week_no, setByWeekNumbers );
1745 readSetByList( by_month, setByMonths );
1746 readSetByList( by_set_pos, setBySetPos );
1747 #undef readSetByList
1750 TQValueList<RecurrenceRule::WDayPos> wdlst;
1753 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1755 pos.setDay( ( icalrecurrencetype_day_day_of_week( day ) + 5 )%7 + 1 );
1756 pos.setPos( icalrecurrencetype_day_position( day ) );
1758 wdlst.append( pos );
1760 if ( !wdlst.isEmpty() ) recur->setByDays( wdlst );
1768 void ICalFormatImpl::readAlarm(icalcomponent *alarm,
Incidence *incidence)
1777 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1778 Alarm::Type type = Alarm::Display;
1779 icalproperty_action action = ICAL_ACTION_DISPLAY;
1781 kdDebug(5800) <<
"Unknown type of alarm, using default" << endl;
1785 action = icalproperty_get_action(p);
1787 case ICAL_ACTION_DISPLAY: type = Alarm::Display;
break;
1788 case ICAL_ACTION_AUDIO: type = Alarm::Audio;
break;
1789 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure;
break;
1790 case ICAL_ACTION_EMAIL: type = Alarm::Email;
break;
1792 kdDebug(5800) <<
"Unknown type of alarm: " << action << endl;
1799 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1801 icalproperty_kind kind = icalproperty_isa(p);
1805 case ICAL_TRIGGER_PROPERTY: {
1806 icaltriggertype trigger = icalproperty_get_trigger(p);
1807 if (icaltime_is_null_time(trigger.time)) {
1808 if (icaldurationtype_is_null_duration(trigger.duration)) {
1809 kdDebug(5800) <<
"ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1811 Duration duration = icaldurationtype_as_int( trigger.duration );
1812 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1813 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1819 ialarm->
setTime(readICalDateTime(p, trigger.time));
1823 case ICAL_DURATION_PROPERTY: {
1824 icaldurationtype duration = icalproperty_get_duration(p);
1828 case ICAL_REPEAT_PROPERTY:
1833 case ICAL_DESCRIPTION_PROPERTY: {
1834 TQString description = TQString::fromUtf8(icalproperty_get_description(p));
1836 case ICAL_ACTION_DISPLAY:
1837 ialarm->
setText( description );
1839 case ICAL_ACTION_PROCEDURE:
1842 case ICAL_ACTION_EMAIL:
1851 case ICAL_SUMMARY_PROPERTY:
1852 ialarm->
setMailSubject(TQString::fromUtf8(icalproperty_get_summary(p)));
1856 case ICAL_ATTENDEE_PROPERTY: {
1857 TQString email = TQString::fromUtf8(icalproperty_get_attendee(p));
1858 if ( email.startsWith(
"mailto:",
false ) ) {
1859 email = email.mid( 7 );
1862 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1864 name = TQString::fromUtf8(icalparameter_get_cn(param));
1870 case ICAL_ATTACH_PROPERTY: {
1872 if ( attach && attach->isUri() ) {
1874 case ICAL_ACTION_AUDIO:
1877 case ICAL_ACTION_PROCEDURE:
1880 case ICAL_ACTION_EMAIL:
1887 kdDebug() <<
"Alarm attachments currently only support URIs, but "
1888 "no binary data" << endl;
1897 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1901 readCustomProperties(alarm, ialarm);
1906 icaldatetimeperiodtype ICalFormatImpl::writeICalDatePeriod(
const TQDate &date )
1908 icaldatetimeperiodtype t;
1909 t.time = writeICalDate( date );
1910 t.period = icalperiodtype_null_period();
1914 icaldatetimeperiodtype ICalFormatImpl::writeICalDateTimePeriod(
const TQDateTime &date )
1916 icaldatetimeperiodtype t;
1917 t.time = writeICalDateTime( date );
1918 t.period = icalperiodtype_null_period();
1922 icaltimetype ICalFormatImpl::writeICalDate(
const TQDate &date)
1924 icaltimetype t = icaltime_null_time();
1926 t.year = date.year();
1927 t.month = date.month();
1940 icaltimetype ICalFormatImpl::writeICalDateTime(
const TQDateTime &datetime)
1942 icaltimetype t = icaltime_null_time();
1944 t.year = datetime.date().year();
1945 t.month = datetime.date().month();
1946 t.day = datetime.date().day();
1948 t.hour = datetime.time().hour();
1949 t.minute = datetime.time().minute();
1950 t.second = datetime.time().second();
1953 t.zone = icaltimezone_get_builtin_timezone ( mParent->timeZoneId().latin1() );
1959 if (mParent->timeZoneId().isEmpty())
1960 t = icaltime_convert_to_zone( t, 0 );
1962 icaltimezone* tz = icaltimezone_get_builtin_timezone ( mParent->timeZoneId().latin1() );
1963 icaltimezone* utc = icaltimezone_get_utc_timezone();
1966 t = icaltime_convert_to_zone( t, utc );
1976 TQDateTime ICalFormatImpl::readICalDateTime( icalproperty *p, icaltimetype& t, icaltimezone* tz )
1979 if (tz && !icaltime_is_utc(t)) {
1982 if (tz != icaltimezone_get_utc_timezone()) {
1983 icalparameter *param = p ? icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER) : 0;
1984 const char *tzid = param ? icalparameter_get_tzid(param) : 0;
1988 icaltimezone* icaltz;
1990 icaltz = icaltimezone_get_builtin_timezone( tzid );
1998 t.zone = icaltimezone_get_utc_timezone();
2003 if ( !mParent->timeZoneId().isEmpty() && t.zone ) {
2005 icaltimezone* viewTimeZone = icaltimezone_get_builtin_timezone ( mParent->timeZoneId().latin1() );
2006 icaltimezone_convert_time( &t, const_cast<icaltimezone*>(t.zone), viewTimeZone );
2010 return ICalDate2TQDate(t);
2013 TQDate ICalFormatImpl::readICalDate(icaltimetype t)
2015 return ICalDate2TQDate(t).date();
2018 icaldurationtype ICalFormatImpl::writeICalDuration(
int seconds)
2026 d.is_neg = (seconds<0)?1:0;
2027 if (seconds<0) seconds = -seconds;
2030 d.days = seconds / gSecondsPerDay;
2031 seconds %= gSecondsPerDay;
2032 d.hours = seconds / gSecondsPerHour;
2033 seconds %= gSecondsPerHour;
2034 d.minutes = seconds / gSecondsPerMinute;
2035 seconds %= gSecondsPerMinute;
2036 d.seconds = seconds;
2041 int ICalFormatImpl::readICalDuration(icaldurationtype d)
2045 result += d.weeks * gSecondsPerWeek;
2046 result += d.days * gSecondsPerDay;
2047 result += d.hours * gSecondsPerHour;
2048 result += d.minutes * gSecondsPerMinute;
2049 result += d.seconds;
2051 if (d.is_neg) result *= -1;
2056 icalcomponent *ICalFormatImpl::createCalendarComponent(
Calendar *cal)
2058 icalcomponent *calendar;
2061 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
2067 icalcomponent_add_property(calendar,p);
2072 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
2073 icalcomponent_add_property(calendar,p);
2077 writeCustomProperties(calendar, cal);
2087 bool ICalFormatImpl::populate(
Calendar *cal, icalcomponent *calendar )
2092 if (!calendar)
return false;
2098 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
2100 kdDebug(5800) <<
"No PRODID property found" << endl;
2101 mLoadedProductId =
"";
2103 mLoadedProductId = TQString::fromUtf8(icalproperty_get_prodid(p));
2107 mCompat = CompatFactory::createCompat( mLoadedProductId );
2110 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
2112 kdDebug(5800) <<
"No VERSION property found" << endl;
2116 const char *version = icalproperty_get_version(p);
2118 kdDebug(5800) <<
"No VERSION property found" << endl;
2121 i18n(
"No VERSION property found" ) ) );
2127 if (strcmp(version,
"1.0") == 0) {
2128 kdDebug(5800) <<
"Expected iCalendar, got vCalendar" << endl;
2130 i18n(
"Expected iCalendar format")));
2132 }
else if (strcmp(version,
"2.0") != 0) {
2133 kdDebug(5800) <<
"Expected iCalendar, got unknown format" << endl;
2140 readCustomProperties(calendar, cal);
2145 icalcomponent *ctz =
2146 icalcomponent_get_first_component( calendar, ICAL_VTIMEZONE_COMPONENT );
2149 mEventsRelate.clear();
2150 mTodosRelate.clear();
2156 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
2159 Todo *todo = readTodo(c);
2162 TQString originalUid = todo->
uid();
2163 todo->
setUid(originalUid + TQString(
"-recur-%1").arg(todo->
recurrenceID().toTime_t()));
2164 if (!cal->
todo(todo->
uid())) {
2165 if ( !cal->
addTodo( todo ) ) {
2170 if (!cal->
event(originalUid)) {
2171 printf(
"FIXME! [WARNING] Parent for child event does not yet exist!\n");
2182 if (!cal->
todo(todo->
uid())) {
2183 if ( !cal->
addTodo( todo ) ) {
2190 mTodosRelate.remove( todo );
2194 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT);
2198 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
2201 Event *
event = readEvent(c, ctz);
2204 TQString originalUid =
event->uid();
2205 event->setUid(originalUid + TQString(
"-recur-%1").arg(event->
recurrenceID().toTime_t()));
2208 if (!cal->
event(originalUid)) {
2209 printf(
"FIXME! [WARNING] Parent for child event does not yet exist!\n");
2215 event->addChildIncidence(cal->
event(originalUid)->
uid());
2228 mEventsRelate.remove( event );
2232 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT);
2236 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
2239 Journal *journal = readJournal(c);
2242 TQString originalUid = journal->
uid();
2243 journal->
setUid(originalUid + TQString(
"-recur-%1").arg(journal->
recurrenceID().toTime_t()));
2246 if (!cal->
event(originalUid)) {
2247 printf(
"FIXME! [WARNING] Parent for child event does not yet exist!\n");
2269 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT);
2275 Event::List::ConstIterator eIt;
2276 for ( eIt = mEventsRelate.begin(); eIt != mEventsRelate.end(); ++eIt ) {
2277 (*eIt)->setRelatedTo( cal->
incidence( (*eIt)->relatedToUid() ) );
2279 Todo::List::ConstIterator tIt;
2280 for ( tIt = mTodosRelate.begin(); tIt != mTodosRelate.end(); ++tIt ) {
2281 (*tIt)->setRelatedTo( cal->
incidence( (*tIt)->relatedToUid() ) );
2287 TQString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
2292 TQString errorMessage;
2294 icalproperty *error;
2295 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY);
2297 errorMessage += icalproperty_get_xlicerror(error);
2298 errorMessage +=
"\n";
2299 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY);
2304 return errorMessage;
2307 void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r)
2311 kdDebug(5800) <<
" Freq: " << r.freq << endl;
2312 kdDebug(5800) <<
" Until: " << icaltime_as_ical_string(r.until) << endl;
2313 kdDebug(5800) <<
" Count: " << r.count << endl;
2314 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2316 TQString out =
" By Day: ";
2317 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2318 out.append(TQString::number(i) +
" ");
2320 kdDebug(5800) << out << endl;
2322 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2324 TQString out =
" By Month Day: ";
2325 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2326 out.append(TQString::number(i) +
" ");
2328 kdDebug(5800) << out << endl;
2330 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2332 TQString out =
" By Year Day: ";
2333 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2334 out.append(TQString::number(i) +
" ");
2336 kdDebug(5800) << out << endl;
2338 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2340 TQString out =
" By Month: ";
2341 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2342 out.append(TQString::number(i) +
" ");
2344 kdDebug(5800) << out << endl;
2346 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2348 TQString out =
" By Set Pos: ";
2349 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2350 kdDebug(5800) <<
"========= " << i << endl;
2351 out.append(TQString::number(i) +
" ");
2353 kdDebug(5800) << out << endl;
2357 icalcomponent *ICalFormatImpl::createScheduleComponent(
IncidenceBase *incidence,
2360 icalcomponent *message = createCalendarComponent();
2362 icalproperty_method icalmethod = ICAL_METHOD_NONE;
2365 case Scheduler::Publish:
2366 icalmethod = ICAL_METHOD_PUBLISH;
2368 case Scheduler::Request:
2369 icalmethod = ICAL_METHOD_REQUEST;
2371 case Scheduler::Refresh:
2372 icalmethod = ICAL_METHOD_REFRESH;
2374 case Scheduler::Cancel:
2375 icalmethod = ICAL_METHOD_CANCEL;
2377 case Scheduler::Add:
2378 icalmethod = ICAL_METHOD_ADD;
2380 case Scheduler::Reply:
2381 icalmethod = ICAL_METHOD_REPLY;
2383 case Scheduler::Counter:
2384 icalmethod = ICAL_METHOD_COUNTER;
2386 case Scheduler::Declinecounter:
2387 icalmethod = ICAL_METHOD_DECLINECOUNTER;
2390 kdDebug(5800) <<
"ICalFormat::createScheduleMessage(): Unknow method" << endl;
2394 icalcomponent_add_property(message,icalproperty_new_method(icalmethod));
2396 icalcomponent *inc = writeIncidence( incidence, method );
2405 if ( icalmethod == ICAL_METHOD_REPLY ) {
2406 struct icalreqstattype rst;
2407 rst.code = ICAL_2_0_SUCCESS_STATUS;
2410 icalcomponent_add_property( inc, icalproperty_new_requeststatus( rst ) );
2412 icalcomponent_add_component( message, inc );