23 #include <tqapplication.h>
24 #include <tqdatetime.h>
26 #include <tqptrlist.h>
28 #include <tqclipboard.h>
33 #include <tdemessagebox.h>
34 #include <kiconloader.h>
35 #include <tdelocale.h>
40 #include <libical/icaltime.h>
41 #include <libical/icaltimezone.h>
46 #include "vcalformat.h"
50 VCalFormat::VCalFormat()
54 VCalFormat::~VCalFormat()
64 kdDebug(5800) <<
"VCalFormat::load() " << fileName << endl;
70 vcal = Parse_MIME_FromFileName(
const_cast<char *
>(TQFile::encodeName(fileName).data()));
97 kdDebug(5800) <<
"VCalFormat::save(): " << fileName << endl;
99 vcal = newVObject(VCCalProp);
102 addPropValue(vcal,VCProdIdProp,
productId().latin1());
103 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
107 Todo::List::ConstIterator it;
108 for ( it = todoList.begin(); it != todoList.end(); ++it ) {
110 addVObjectProp( vcal, vo );
115 Event::List::ConstIterator it2;
116 for( it2 = events.begin(); it2 != events.end(); ++it2 ) {
118 addVObjectProp( vcal, vo );
121 writeVObjectToFile(TQFile::encodeName(fileName).data() ,vcal);
125 if (TQFile::exists(fileName)) {
126 kdDebug(5800) <<
"No error" << endl;
129 kdDebug(5800) <<
"Error" << endl;
139 mCalendar = calendar;
141 TQCString data = text.utf8();
143 if ( !data.size() )
return false;
145 VObject *vcal = Parse_MIME( data.data(), data.size());
146 if ( !vcal )
return false;
150 initPropIterator( &i, vcal );
154 curvo = nextVObject( &i );
155 }
while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
156 strcmp( vObjectName( curvo ), VCTodoProp ) );
158 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
162 kdDebug(5800) <<
"VCalFormat::fromString(): Unknown object type." << endl;
163 deleteVObject( vcal );
167 deleteVObject( vcal );
175 mCalendar = calendar;
177 VObject *vcal = newVObject(VCCalProp);
180 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
184 Event *
event = events.first();
186 cleanVObject( vcal );
192 addVObjectProp( vcal, vevent );
194 char *buf = writeMemVObject( 0, 0, vcal );
196 TQString result( buf );
198 cleanVObject( vcal );
208 vtodo = newVObject(VCTodoProp);
214 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
221 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
226 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
229 addPropValue(vtodo, VCUniqueStringProp,
230 anEvent->
uid().local8Bit());
233 tmpStr.sprintf(
"%i", anEvent->
revision());
234 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
238 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
242 tmpStr =
"MAILTO:" + anEvent->organizer().email();
243 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
247 Attendee::List::ConstIterator it;
252 if (!curAttendee->email().isEmpty() &&
253 !curAttendee->name().isEmpty())
254 tmpStr =
"MAILTO:" + curAttendee->name() +
" <" +
255 curAttendee->email() +
">";
256 else if (curAttendee->name().isEmpty())
257 tmpStr =
"MAILTO: " + curAttendee->email();
258 else if (curAttendee->email().isEmpty())
259 tmpStr =
"MAILTO: " + curAttendee->name();
260 else if (curAttendee->name().isEmpty() &&
261 curAttendee->email().isEmpty())
262 kdDebug(5800) <<
"warning! this Event has an attendee w/o name or email!" << endl;
263 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
264 addPropValue(aProp, VCRSVPProp, curAttendee->
RSVP() ?
"TRUE" :
"FALSE");
265 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->
status()));
271 VObject *d = addPropValue(vtodo, VCDescriptionProp,
274 addPropValue(d, VCEncodingProp, VCQuotedPrintableProp);
278 if (!anEvent->
summary().isEmpty())
279 addPropValue(vtodo, VCSummaryProp, anEvent->
summary().local8Bit());
283 addPropValue(vtodo, VCLocationProp, anEvent->
location().local8Bit());
288 addPropValue(vtodo, VCStatusProp, anEvent->
isCompleted() ?
"COMPLETED" :
293 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
297 tmpStr.sprintf(
"%i",anEvent->
priority());
298 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
302 addPropValue(vtodo, VCRelatedToProp,
307 TQStringList tmpStrList = anEvent->
categories();
310 for ( TQStringList::Iterator it = tmpStrList.begin();
311 it != tmpStrList.end();
314 if (catStr[0] ==
' ')
315 tmpStr += catStr.mid(1);
323 if (!tmpStr.isEmpty()) {
324 tmpStr.truncate(tmpStr.length()-1);
325 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
329 kdDebug(5800) <<
"vcalformat::eventToVTodo was called" << endl;
330 Alarm::List::ConstIterator it;
331 for ( it = anEvent->
alarms().begin(); it != anEvent->
alarms().end(); ++it ) {
334 VObject *a = addProp(vtodo, VCDAlarmProp);
336 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
337 addPropValue(a, VCRepeatCountProp,
"1");
338 addPropValue(a, VCDisplayStringProp,
"beep!");
339 if (alarm->
type() == Alarm::Audio) {
340 a = addProp(vtodo, VCAAlarmProp);
341 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
342 addPropValue(a, VCRepeatCountProp,
"1");
343 addPropValue(a, VCAudioContentProp, TQFile::encodeName(alarm->
audioFile()));
345 else if (alarm->
type() == Alarm::Procedure) {
346 a = addProp(vtodo, VCPAlarmProp);
347 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
348 addPropValue(a, VCRepeatCountProp,
"1");
349 addPropValue(a, VCProcedureNameProp, TQFile::encodeName(alarm->
programFile()));
356 tmpStr.sprintf(
"%lu",anEvent->
pilotId());
357 addPropValue(vtodo, KPilotIdProp, tmpStr.local8Bit());
359 addPropValue(vtodo, KPiloStatusProp, tmpStr.local8Bit());
370 vevent = newVObject(VCEventProp);
375 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
382 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
387 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
390 addPropValue(vevent, VCUniqueStringProp,
391 anEvent->
uid().local8Bit());
394 tmpStr.sprintf(
"%i", anEvent->
revision());
395 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
399 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
403 tmpStr =
"MAILTO:" + anEvent->organizer().email();
404 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
408 Attendee::List::ConstIterator it;
412 if (!curAttendee->email().isEmpty() &&
413 !curAttendee->name().isEmpty())
414 tmpStr =
"MAILTO:" + curAttendee->name() +
" <" +
415 curAttendee->email() +
">";
416 else if (curAttendee->name().isEmpty())
417 tmpStr =
"MAILTO: " + curAttendee->email();
418 else if (curAttendee->email().isEmpty())
419 tmpStr =
"MAILTO: " + curAttendee->name();
420 else if (curAttendee->name().isEmpty() &&
421 curAttendee->email().isEmpty())
422 kdDebug(5800) <<
"warning! this Event has an attendee w/o name or email!" << endl;
423 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
424 addPropValue(aProp, VCRSVPProp, curAttendee->
RSVP() ?
"TRUE" :
"FALSE");
425 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->
status()));
432 bool validRecur =
true;
435 case Recurrence::rDaily:
436 tmpStr.sprintf(
"D%i ",recur->
frequency());
438 case Recurrence::rWeekly:
439 tmpStr.sprintf(
"W%i ",recur->
frequency());
440 for (
int i = 0; i < 7; i++ ) {
441 TQBitArray days ( recur->
days() );
442 if ( days.testBit(i) )
446 case Recurrence::rMonthlyPos: {
447 tmpStr.sprintf(
"MP%i ", recur->
frequency());
449 TQValueList<RecurrenceRule::WDayPos> tmpPositions = recur->
monthPositions();
450 for ( TQValueListConstIterator<RecurrenceRule::WDayPos> posit = tmpPositions.begin();
451 posit != tmpPositions.end(); ++posit ) {
452 int pos = (*posit).pos();
453 tmpStr2.sprintf(
"%i", (pos>0) ? pos : (-pos) );
462 case Recurrence::rMonthlyDay: {
463 tmpStr.sprintf(
"MD%i ", recur->
frequency());
465 TQValueList<int> tmpDays = recur->
monthDays();
466 for ( TQValueListIterator<int> tmpDay = tmpDays.begin();
467 tmpDay != tmpDays.end(); ++tmpDay ) {
468 tmpStr2.sprintf(
"%i ", *tmpDay );
472 case Recurrence::rYearlyMonth: {
473 tmpStr.sprintf(
"YM%i ", recur->
frequency());
476 TQValueList<int> months = recur->
yearMonths();
477 for ( TQValueListIterator<int> mit = months.begin();
478 mit != months.end(); ++mit ) {
479 tmpStr2.sprintf(
"%i ", *mit );
483 case Recurrence::rYearlyDay: {
484 tmpStr.sprintf(
"YD%i ", recur->
frequency());
486 TQValueList<int> tmpDays = recur->
yearDays();
487 for ( TQValueListIterator<int> tmpDay = tmpDays.begin();
488 tmpDay != tmpDays.end(); ++tmpDay ) {
489 tmpStr2.sprintf(
"%i ", *tmpDay );
495 kdDebug(5800) <<
"ERROR, it should never get here in eventToVEvent!" << endl;
501 tmpStr2.sprintf(
"#%i",recur->
duration());
503 }
else if (recur->
duration() == -1) {
511 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
516 DateList dateList = recur->exDates();
517 DateList::ConstIterator it;
520 for (it = dateList.begin(); it != dateList.end(); ++it) {
524 if (!tmpStr2.isEmpty()) {
525 tmpStr2.truncate(tmpStr2.length()-1);
526 addPropValue(vevent, VCExDateProp, tmpStr2.local8Bit());
531 VObject *d = addPropValue(vevent, VCDescriptionProp,
534 addPropValue(d, VCEncodingProp, VCQuotedPrintableProp);
538 if (!anEvent->
summary().isEmpty())
539 addPropValue(vevent, VCSummaryProp, anEvent->
summary().local8Bit());
543 addPropValue(vevent, VCLocationProp, anEvent->
location().local8Bit());
550 const char *text = 0;
552 case Incidence::SecrecyPublic:
555 case Incidence::SecrecyPrivate:
558 case Incidence::SecrecyConfidential:
559 text =
"CONFIDENTIAL";
563 addPropValue(vevent, VCClassProp, text);
567 TQStringList tmpStrList = anEvent->
categories();
570 for ( TQStringList::Iterator it = tmpStrList.begin();
571 it != tmpStrList.end();
574 if (catStr[0] ==
' ')
575 tmpStr += catStr.mid(1);
583 if (!tmpStr.isEmpty()) {
584 tmpStr.truncate(tmpStr.length()-1);
585 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
591 Attachment::List::ConstIterator atIt;
592 for ( atIt = attachments.begin(); atIt != attachments.end(); ++atIt )
593 addPropValue( vevent, VCAttachProp, (*atIt)->uri().local8Bit() );
597 tmpStr = tmpStrList.join(
";");
598 if (!tmpStr.isEmpty())
599 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
602 Alarm::List::ConstIterator it2;
603 for ( it2 = anEvent->
alarms().begin(); it2 != anEvent->
alarms().end(); ++it2 ) {
606 VObject *a = addProp(vevent, VCDAlarmProp);
608 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
609 addPropValue(a, VCRepeatCountProp,
"1");
610 addPropValue(a, VCDisplayStringProp,
"beep!");
611 if (alarm->
type() == Alarm::Audio) {
612 a = addProp(vevent, VCAAlarmProp);
613 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
614 addPropValue(a, VCRepeatCountProp,
"1");
615 addPropValue(a, VCAudioContentProp, TQFile::encodeName(alarm->
audioFile()));
617 if (alarm->
type() == Alarm::Procedure) {
618 a = addProp(vevent, VCPAlarmProp);
619 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
620 addPropValue(a, VCRepeatCountProp,
"1");
621 addPropValue(a, VCProcedureNameProp, TQFile::encodeName(alarm->
programFile()));
627 tmpStr.sprintf(
"%i",anEvent->
priority());
628 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
632 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
636 addPropValue(vevent, VCRelatedToProp,
642 tmpStr.sprintf(
"%lu",anEvent->
pilotId());
643 addPropValue(vevent, KPilotIdProp, tmpStr.local8Bit());
645 addPropValue(vevent, KPiloStatusProp, tmpStr.local8Bit());
660 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
666 vo = isAPropertyOf(vtodo, VCUniqueStringProp);
670 anEvent->
setUid(s = fakeCString(vObjectUStringZValue(vo)));
675 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
681 TQTime::currentTime()));
685 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
686 anEvent->
setOrganizer( s = fakeCString(vObjectUStringZValue(vo) ) );
693 initPropIterator(&voi, vtodo);
694 while (moreIteration(&voi)) {
695 vo = nextVObject(&voi);
696 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
699 s = fakeCString(vObjectUStringZValue(vo));
700 TQString tmpStr = TQString::fromLocal8Bit(s);
702 tmpStr = tmpStr.simplifyWhiteSpace();
703 int emailPos1, emailPos2;
704 if ((emailPos1 = tmpStr.find(
'<')) > 0) {
706 emailPos2 = tmpStr.findRev(
'>');
707 a =
new Attendee(tmpStr.left(emailPos1 - 1),
708 tmpStr.mid(emailPos1 + 1,
709 emailPos2 - (emailPos1 + 1)));
710 }
else if (tmpStr.find(
'@') > 0) {
716 TQString email = tmpStr.replace(
' ',
'.' );
721 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
722 a->
setRSVP(vObjectStringZValue(vp));
724 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
725 a->
setStatus(readStatus(vObjectStringZValue(vp)));
732 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) {
733 s = fakeCString(vObjectUStringZValue(vo));
739 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) {
740 s = fakeCString(vObjectUStringZValue(vo));
741 anEvent->
setSummary(TQString::fromLocal8Bit(s));
747 if ((vo = isAPropertyOf(vtodo, VCLocationProp)) != 0) {
748 s = fakeCString(vObjectUStringZValue(vo));
749 anEvent->
setLocation( TQString::fromLocal8Bit(s) );
754 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) {
755 s = fakeCString(vObjectUStringZValue(vo));
756 if (strcmp(s,
"COMPLETED") == 0) {
767 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) {
773 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) {
774 anEvent->
setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
779 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) {
788 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) {
799 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) {
802 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
807 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) {
808 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
809 s = fakeCString(vObjectUStringZValue(a));
814 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) {
815 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
816 s = fakeCString(vObjectUStringZValue(a));
824 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) {
827 mTodosRelate.append(anEvent);
831 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) {
832 s = fakeCString(vObjectUStringZValue(vo));
833 TQString categories = TQString::fromLocal8Bit(s);
835 TQStringList tmpStrList = TQStringList::split(
';', categories );
840 if ((vo = isAPropertyOf(vtodo, KPilotIdProp))) {
841 anEvent->
setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
847 if ((vo = isAPropertyOf(vtodo, KPiloStatusProp))) {
848 anEvent->
setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
866 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) {
872 vo = isAPropertyOf(vevent, VCUniqueStringProp);
876 anEvent->
setUid(s = fakeCString(vObjectUStringZValue(vo)));
882 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) {
883 anEvent->
setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo))));
890 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) {
896 TQTime::currentTime()));
900 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) {
902 anEvent->
setOrganizer( s = fakeCString(vObjectUStringZValue(vo) ) );
909 initPropIterator(&voi, vevent);
910 while (moreIteration(&voi)) {
911 vo = nextVObject(&voi);
912 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
915 s = fakeCString(vObjectUStringZValue(vo));
916 TQString tmpStr = TQString::fromLocal8Bit(s);
918 tmpStr = tmpStr.simplifyWhiteSpace();
919 int emailPos1, emailPos2;
920 if ((emailPos1 = tmpStr.find(
'<')) > 0) {
922 emailPos2 = tmpStr.findRev(
'>');
923 a =
new Attendee(tmpStr.left(emailPos1 - 1),
924 tmpStr.mid(emailPos1 + 1,
925 emailPos2 - (emailPos1 + 1)));
926 }
else if (tmpStr.find(
'@') > 0) {
931 TQString email = tmpStr.replace(
' ',
'.' );
936 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
937 a->
setRSVP(vObjectStringZValue(vp));
939 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
940 a->
setStatus(readStatus(vObjectStringZValue(vp)));
958 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) {
962 if (anEvent->
dtStart().time().isNull())
967 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) {
970 if (anEvent->
dtEnd().time().isNull())
976 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
978 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
984 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) {
985 TQString tmpStr = (s = fakeCString(vObjectUStringZValue(vo)));
987 tmpStr.simplifyWhiteSpace();
988 tmpStr = tmpStr.upper();
993 uint type = Recurrence::rNone;
994 if ( tmpStr.left(1) ==
"D") {
995 type = Recurrence::rDaily;
996 }
else if ( tmpStr.left(1) ==
"W") {
997 type = Recurrence::rWeekly;
1000 if ( tmpStr.left(2) ==
"MP") {
1001 type = Recurrence::rMonthlyPos;
1002 }
else if ( tmpStr.left(2) ==
"MD" ) {
1003 type = Recurrence::rMonthlyDay;
1004 }
else if ( tmpStr.left(2) ==
"YM" ) {
1005 type = Recurrence::rYearlyMonth;
1006 }
else if ( tmpStr.left(2) ==
"YD" ) {
1007 type = Recurrence::rYearlyDay;
1011 if ( type != Recurrence::rNone ) {
1015 int index = tmpStr.find(
' ');
1016 int last = tmpStr.findRev(
' ') + 1;
1017 int rFreq = tmpStr.mid(typelen, (index-1)).toInt();
1022 case Recurrence::rDaily:
1026 case Recurrence::rWeekly: {
1029 if( index == last ) {
1031 qba.setBit(anEvent->
dtStart().date().dayOfWeek() - 1);
1035 while (index < last) {
1036 dayStr = tmpStr.mid(index, 3);
1045 case Recurrence::rMonthlyPos: {
1050 if( index == last ) {
1052 tmpPos = anEvent->
dtStart().date().day()/7 + 1;
1055 qba.setBit(anEvent->
dtStart().date().dayOfWeek() - 1);
1060 while (index < last) {
1061 tmpPos = tmpStr.mid(index,1).toShort();
1063 if (tmpStr.mid(index,1) ==
"-")
1065 tmpPos = 0 - tmpPos;
1067 while (
numFromDay(tmpStr.mid(index,3)) >= 0) {
1068 int dayNum =
numFromDay(tmpStr.mid(index,3));
1079 case Recurrence::rMonthlyDay:
1081 if( index == last ) {
1083 short tmpDay = anEvent->
dtStart().date().day();
1088 while (index < last) {
1089 int index2 = tmpStr.find(
' ', index);
1090 short tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1092 if (tmpStr.mid(index, 1) ==
"-")
1093 tmpDay = 0 - tmpDay;
1100 case Recurrence::rYearlyMonth:
1103 if( index == last ) {
1105 short tmpMonth = anEvent->
dtStart().date().month();
1110 while (index < last) {
1111 int index2 = tmpStr.find(
' ', index);
1112 short tmpMonth = tmpStr.mid(index, (index2-index)).toShort();
1119 case Recurrence::rYearlyDay:
1122 if( index == last ) {
1124 short tmpDay = anEvent->
dtStart().date().dayOfYear();
1129 while (index < last) {
1130 int index2 = tmpStr.find(
' ', index);
1131 short tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1143 if ( tmpStr.mid(index,1) ==
"#") {
1146 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1147 if ( rDuration > 0 )
1149 }
else if ( tmpStr.find(
'T', index) != -1 ) {
1150 TQDate rEndDate = (
ISOToTQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1156 kdDebug(5800) <<
"we don't understand this type of recurrence!" << endl;
1162 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) {
1163 s = fakeCString(vObjectUStringZValue(vo));
1164 TQStringList exDates = TQStringList::split(
",",s);
1165 TQStringList::ConstIterator it;
1166 for(it = exDates.begin(); it != exDates.end(); ++it ) {
1173 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) {
1174 s = fakeCString(vObjectUStringZValue(vo));
1175 anEvent->
setSummary(TQString::fromLocal8Bit(s));
1180 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) {
1181 s = fakeCString(vObjectUStringZValue(vo));
1184 TQString::fromLocal8Bit(s));
1192 if ((vo = isAPropertyOf(vevent, VCLocationProp)) != 0) {
1193 s = fakeCString(vObjectUStringZValue(vo));
1194 anEvent->
setLocation( TQString::fromLocal8Bit(s) );
1200 if (anEvent->
summary().isEmpty() &&
1202 TQString tmpStr = anEvent->
description().simplifyWhiteSpace();
1209 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) {
1210 TQString tmpStr(s = fakeCString(vObjectUStringZValue(vo)));
1220 int secrecy = Incidence::SecrecyPublic;
1221 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
1222 s = fakeCString(vObjectUStringZValue(vo));
1223 if (strcmp(s,
"PRIVATE") == 0) {
1224 secrecy = Incidence::SecrecyPrivate;
1225 }
else if (strcmp(s,
"CONFIDENTIAL") == 0) {
1226 secrecy = Incidence::SecrecyConfidential;
1233 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) {
1234 s = fakeCString(vObjectUStringZValue(vo));
1235 TQString categories = TQString::fromLocal8Bit(s);
1237 TQStringList tmpStrList = TQStringList::split(
',', categories );
1242 initPropIterator(&voi, vevent);
1243 while (moreIteration(&voi)) {
1244 vo = nextVObject(&voi);
1245 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
1246 s = fakeCString(vObjectUStringZValue(vo));
1253 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
1254 TQString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1256 TQStringList tmpStrList = TQStringList::split(
';', resources );
1261 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1264 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1269 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1270 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1271 s = fakeCString(vObjectUStringZValue(a));
1276 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1277 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1278 s = fakeCString(vObjectUStringZValue(a));
1286 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1287 anEvent->
setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1292 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1293 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1294 anEvent->
setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1299 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1302 mEventsRelate.append(anEvent);
1306 if ((vo = isAPropertyOf(vevent, KPilotIdProp))) {
1307 anEvent->
setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1313 if ((vo = isAPropertyOf(vevent, KPiloStatusProp))) {
1314 anEvent->
setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1328 Q_ASSERT(qd.isValid());
1330 tmpStr.sprintf(
"%.2d%.2d%.2d",
1331 qd.year(), qd.month(), qd.day());
1338 int vcaltime_utc_offset( TQDateTime ictt, TQString tzid )
1344 struct icaltimetype tt = icaltime_from_timet_with_zone( ictt.toTime_t(),
false, NULL);
1345 return icaltimezone_get_utc_offset(
1346 icaltimezone_get_builtin_timezone( tzid.latin1() ),
1354 Q_ASSERT(qdt.date().isValid());
1355 Q_ASSERT(qdt.time().isValid());
1357 TQDateTime tmpDT(qdt);
1359 tmpDT = tmpDT.addSecs(-vcaltime_utc_offset( tmpDT, mCalendar->
timeZoneId()));
1360 tmpStr.sprintf(
"%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1361 tmpDT.date().year(), tmpDT.date().month(),
1362 tmpDT.date().day(), tmpDT.time().hour(),
1363 tmpDT.time().minute(), tmpDT.time().second());
1365 tmpStr.sprintf(
"%.2d%.2d%.2dT%.2d%.2d%.2d",
1366 qdt.date().year(), qdt.date().month(),
1367 qdt.date().day(), qdt.time().hour(),
1368 qdt.time().minute(), qdt.time().second());
1378 int year, month, day, hour, minute, second;
1381 year = tmpStr.left(4).toInt();
1382 month = tmpStr.mid(4,2).toInt();
1383 day = tmpStr.mid(6,2).toInt();
1384 hour = tmpStr.mid(9,2).toInt();
1385 minute = tmpStr.mid(11,2).toInt();
1386 second = tmpStr.mid(13,2).toInt();
1387 tmpDate.setYMD(year, month, day);
1388 tmpTime.setHMS(hour, minute, second);
1390 Q_ASSERT(tmpDate.isValid());
1391 Q_ASSERT(tmpTime.isValid());
1392 TQDateTime tmpDT(tmpDate, tmpTime);
1394 if (dtStr.at(dtStr.length()-1) ==
'Z') {
1395 tmpDT = tmpDT.addSecs(vcaltime_utc_offset( tmpDT, mCalendar->
timeZoneId()));
1402 int year, month, day;
1404 year = dateStr.left(4).toInt();
1405 month = dateStr.mid(4,2).toInt();
1406 day = dateStr.mid(6,2).toInt();
1408 return(TQDate(year, month, day));
1420 VObject *curVO, *curVOProp;
1423 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1424 char *methodType = 0;
1425 methodType = fakeCString(vObjectUStringZValue(curVO));
1426 kdDebug(5800) <<
"This calendar is an iTIP transaction of type '"
1427 << methodType <<
"'" << endl;
1428 deleteStr(methodType);
1432 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1433 char *s = fakeCString(vObjectUStringZValue(curVO));
1434 if (strcmp(
productId().local8Bit(), s) != 0)
1435 kdDebug(5800) <<
"This vCalendar file was not created by KOrganizer "
1436 "or any other product we support. Loading anyway..." << endl;
1437 mLoadedProductId = s;
1442 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1443 char *s = fakeCString(vObjectUStringZValue(curVO));
1444 if (strcmp(_VCAL_VERSION, s) != 0)
1445 kdDebug(5800) <<
"This vCalendar file has version " << s
1446 <<
"We only support " << _VCAL_VERSION << endl;
1452 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1453 char *s = fakeCString(vObjectUStringZValue(curVO));
1454 mCalendar->setTimeZone(s);
1460 mEventsRelate.clear();
1461 mTodosRelate.clear();
1463 initPropIterator(&i, vcal);
1466 while (moreIteration(&i)) {
1467 curVO = nextVObject(&i);
1472 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1474 if ((curVOProp = isAPropertyOf(curVO, KPiloStatusProp)) != 0) {
1476 s = fakeCString(vObjectUStringZValue(curVOProp));
1478 if (atoi(s) == Event::SYNCDEL) {
1480 kdDebug(5800) <<
"skipping pilot-deleted event" << endl;
1489 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1490 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1499 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1500 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1501 kdDebug(5800) <<
"found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1509 if ( !anEvent->
dtStart().isValid() || !anEvent->
dtEnd().isValid() ) {
1510 kdDebug(5800) <<
"VCalFormat::populate(): Event has invalid dates."
1519 }
else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
1522 }
else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
1523 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
1524 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
1529 kdDebug(5800) <<
"Ignoring unknown vObject \"" << vObjectName(curVO) <<
"\"" << endl;
1536 Event::List::ConstIterator eIt;
1537 for ( eIt = mEventsRelate.begin(); eIt != mEventsRelate.end(); ++eIt ) {
1538 (*eIt)->setRelatedTo( mCalendar->
incidence( (*eIt)->relatedToUid() ) );
1540 Todo::List::ConstIterator tIt;
1541 for ( tIt = mTodosRelate.begin(); tIt != mTodosRelate.end(); ++tIt ) {
1542 (*tIt)->setRelatedTo( mCalendar->
incidence( (*tIt)->relatedToUid() ) );
1548 const char *days[7] = {
"MO ",
"TU ",
"WE ",
"TH ",
"FR ",
"SA ",
"SU " };
1555 if (day ==
"MO ")
return 0;
1556 if (day ==
"TU ")
return 1;
1557 if (day ==
"WE ")
return 2;
1558 if (day ==
"TH ")
return 3;
1559 if (day ==
"FR ")
return 4;
1560 if (day ==
"SA ")
return 5;
1561 if (day ==
"SU ")
return 6;
1566 Attendee::PartStat VCalFormat::readStatus(
const char *s)
const
1568 TQString statStr = s;
1569 statStr = statStr.upper();
1570 Attendee::PartStat status;
1572 if (statStr ==
"X-ACTION")
1573 status = Attendee::NeedsAction;
1574 else if (statStr ==
"NEEDS ACTION")
1575 status = Attendee::NeedsAction;
1576 else if (statStr==
"ACCEPTED")
1577 status = Attendee::Accepted;
1578 else if (statStr==
"SENT")
1579 status = Attendee::NeedsAction;
1580 else if (statStr==
"TENTATIVE")
1581 status = Attendee::Tentative;
1582 else if (statStr==
"CONFIRMED")
1583 status = Attendee::Accepted;
1584 else if (statStr==
"DECLINED")
1585 status = Attendee::Declined;
1586 else if (statStr==
"COMPLETED")
1587 status = Attendee::Completed;
1588 else if (statStr==
"DELEGATED")
1589 status = Attendee::Delegated;
1591 kdDebug(5800) <<
"error setting attendee mStatus, unknown mStatus!" << endl;
1592 status = Attendee::NeedsAction;
1598 TQCString VCalFormat::writeStatus(Attendee::PartStat status)
const
1602 case Attendee::NeedsAction:
1603 return "NEEDS ACTION";
1605 case Attendee::Accepted:
1608 case Attendee::Declined:
1611 case Attendee::Tentative:
1614 case Attendee::Delegated:
1617 case Attendee::Completed:
1620 case Attendee::InProcess:
1621 return "NEEDS ACTION";