40 #include "versit/vcc.h"
41 #include "versit/vobject.h"
44 #include <kdatetime.h>
45 #include <klocalizedstring.h>
47 #include <QtCore/QString>
48 #include <QtCore/QRegExp>
49 #include <QtCore/QFile>
50 #include <QtCore/QByteArray>
51 #include <QTextDocument>
60 class KCal::VCalFormat::Private
69 VCalFormat::VCalFormat() : d( new KCal::VCalFormat::Private )
73 VCalFormat::~VCalFormat()
80 d->mCalendar = calendar;
90 vcal = Parse_MIME_FromFileName( const_cast<char *>(
QFile::encodeName( fileName ).data() ) );
103 cleanVObjects( vcal );
111 d->mCalendar = calendar;
116 kDebug() << fileName;
118 vcal = newVObject( VCCalProp );
121 addPropValue( vcal, VCProdIdProp, productId().toLatin1() );
122 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
125 Todo::List todoList = d->mCalendar->rawTodos();
128 vo = eventToVTodo( *it );
129 addVObjectProp( vcal, vo );
136 vo = eventToVEvent( *it2 );
137 addVObjectProp( vcal, vo );
141 cleanVObjects( vcal );
153 bool VCalFormat::fromString(
Calendar *calendar,
const QString &
string )
155 return fromRawString( calendar,
string.toUtf8() );
160 d->mCalendar = calendar;
162 if ( !
string.size() ) {
166 VObject *vcal = Parse_MIME(
string.data(),
string.size() );
173 initPropIterator( &i, vcal );
177 curvo = nextVObject( &i );
178 }
while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
179 strcmp( vObjectName( curvo ), VCTodoProp ) );
181 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
182 Event *
event = VEventToEvent( curvo );
185 kDebug() <<
"Unknown object type.";
186 deleteVObject( vcal );
190 deleteVObject( vcal );
198 d->mCalendar = calendar;
200 VObject *vcal = newVObject( VCCalProp );
203 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
208 cleanVObject ( vcal );
213 cleanVObject ( vcal );
216 VObject *vevent = eventToVEvent( event );
218 addVObjectProp( vcal, vevent );
220 char *buf = writeMemVObject( 0, 0, vcal );
224 cleanVObject( vcal );
229 VObject *VCalFormat::eventToVTodo(
const Todo *anEvent )
234 vtodo = newVObject( VCTodoProp );
238 tmpStr = kDateTimeToISO( anEvent->
dtDue(), !anEvent->
allDay() );
239 addPropValue( vtodo, VCDueProp, tmpStr.
toLocal8Bit() );
244 tmpStr = kDateTimeToISO( anEvent->
dtStart(), !anEvent->
allDay() );
245 addPropValue( vtodo, VCDTstartProp, tmpStr.
toLocal8Bit() );
249 tmpStr = kDateTimeToISO( anEvent->
created() );
250 addPropValue( vtodo, VCDCreatedProp, tmpStr.
toLocal8Bit() );
253 addPropValue( vtodo, VCUniqueStringProp,
258 addPropValue( vtodo, VCSequenceProp, tmpStr.
toLocal8Bit() );
262 addPropValue( vtodo, VCLastModifiedProp, tmpStr.toLocal8Bit() );
268 addPropValue( vtodo, ICOrganizerProp, tmpStr.toLocal8Bit() );
280 tmpStr =
"MAILTO:" + curAttendee->
name() +
" <" + curAttendee->
email() +
'>';
282 tmpStr =
"MAILTO: " + curAttendee->
email();
284 tmpStr =
"MAILTO: " + curAttendee->
name();
286 kDebug() <<
"warning! this Event has an attendee w/o name or email!";
288 VObject *aProp = addPropValue( vtodo, VCAttendeeProp, tmpStr.toLocal8Bit() );
289 addPropValue( aProp, VCRSVPProp, curAttendee->
RSVP() ?
"TRUE" :
"FALSE" );
290 addPropValue( aProp, VCStatusProp, writeStatus( curAttendee->
status() ) );
296 VObject *dObject = addPropValue( vtodo, VCDescriptionProp,
299 addPropValue( dObject, VCEncodingProp, VCQuotedPrintableProp );
315 addPropValue( vtodo, VCStatusProp, anEvent->
isCompleted() ?
"COMPLETED" :
"NEEDS_ACTION" );
319 tmpStr = kDateTimeToISO( anEvent->
completed() );
320 addPropValue( vtodo, VCCompletedProp, tmpStr.toLocal8Bit() );
324 tmpStr.sprintf(
"%i", anEvent->
priority() );
325 addPropValue( vtodo, VCPriorityProp, tmpStr.toLocal8Bit() );
329 addPropValue( vtodo, VCRelatedToProp,
340 if ( catStr[0] ==
' ' ) {
341 tmpStr += catStr.
mid( 1 );
350 if ( !tmpStr.isEmpty() ) {
351 tmpStr.
truncate( tmpStr.length() - 1 );
352 addPropValue( vtodo, VCCategoriesProp, tmpStr.toLocal8Bit() );
360 VObject *a = addProp( vtodo, VCDAlarmProp );
361 tmpStr = kDateTimeToISO( alarm->
time() );
362 addPropValue( a, VCRunTimeProp, tmpStr.toLocal8Bit() );
363 addPropValue( a, VCRepeatCountProp,
"1" );
364 addPropValue( a, VCDisplayStringProp,
"beep!" );
366 a = addProp( vtodo, VCAAlarmProp );
367 addPropValue( a, VCRunTimeProp, tmpStr.toLocal8Bit() );
368 addPropValue( a, VCRepeatCountProp,
"1" );
371 a = addProp( vtodo, VCPAlarmProp );
372 addPropValue( a, VCRunTimeProp, tmpStr.toLocal8Bit() );
373 addPropValue( a, VCRepeatCountProp,
"1" );
382 addPropValue( vtodo, KPilotIdProp, pilotId.
toLocal8Bit() );
383 addPropValue( vtodo, KPilotStatusProp,
390 VObject *VCalFormat::eventToVEvent(
const Event *anEvent )
395 vevent = newVObject( VCEventProp );
398 tmpStr = kDateTimeToISO( anEvent->
dtStart(), !anEvent->
allDay() );
399 addPropValue( vevent, VCDTstartProp, tmpStr.
toLocal8Bit() );
404 tmpStr = kDateTimeToISO( anEvent->
dtEnd(), !anEvent->
allDay() );
405 addPropValue( vevent, VCDTendProp, tmpStr.
toLocal8Bit() );
409 tmpStr = kDateTimeToISO( anEvent->
created() );
410 addPropValue( vevent, VCDCreatedProp, tmpStr.
toLocal8Bit() );
413 addPropValue( vevent, VCUniqueStringProp,
418 addPropValue( vevent, VCSequenceProp, tmpStr.
toLocal8Bit() );
422 addPropValue( vevent, VCLastModifiedProp, tmpStr.toLocal8Bit() );
428 addPropValue( vevent, ICOrganizerProp, tmpStr.toLocal8Bit() );
438 tmpStr =
"MAILTO:" + curAttendee->
name() +
" <" + curAttendee->
email() +
'>';
440 tmpStr =
"MAILTO: " + curAttendee->
email();
442 tmpStr =
"MAILTO: " + curAttendee->
name();
444 kDebug() <<
"warning! this Event has an attendee w/o name or email!";
446 VObject *aProp = addPropValue( vevent, VCAttendeeProp, tmpStr.toLocal8Bit() );
447 addPropValue( aProp, VCRSVPProp, curAttendee->
RSVP() ?
"TRUE" :
"FALSE" );
448 addPropValue( aProp, VCStatusProp, writeStatus( curAttendee->
status() ) );
455 bool validRecur =
true;
458 case Recurrence::rDaily:
461 case Recurrence::rWeekly:
463 for (
int i = 0; i < 7; ++i ) {
465 if ( days.testBit(i) ) {
466 tmpStr += dayFromNum( i );
470 case Recurrence::rMonthlyPos:
472 tmpStr.sprintf(
"MP%i ", recur->
frequency() );
476 posit != tmpPositions.
constEnd(); ++posit ) {
477 int pos = (*posit).pos();
478 tmpStr2.
sprintf(
"%i", ( pos > 0 ) ? pos : (-pos) );
485 tmpStr += dayFromNum( (*posit).day() - 1 );
489 case Recurrence::rMonthlyDay:
495 tmpDay != tmpDays.
constEnd(); ++tmpDay ) {
496 tmpStr2.
sprintf(
"%i ", *tmpDay );
501 case Recurrence::rYearlyMonth:
509 tmpStr2.
sprintf(
"%i ", *mit );
514 case Recurrence::rYearlyDay:
520 tmpDay != tmpDays.
end(); ++tmpDay ) {
521 tmpStr2.
sprintf(
"%i ", *tmpDay );
528 kDebug() <<
"ERROR, it should never get here in eventToVEvent!";
536 }
else if ( recur->
duration() == -1 ) {
539 tmpStr += kDateTimeToISO( recur->
endDateTime(), false );
544 addPropValue( vevent, VCRRuleProp, tmpStr.toLocal8Bit() );
550 DateList dateList = recur->exDates();
555 tmpStr = qDateToISO(*it) +
';';
560 addPropValue( vevent, VCExpDateProp, tmpStr2.
toLocal8Bit() );
565 VObject *dObject = addPropValue( vevent, VCDescriptionProp,
568 addPropValue( dObject, VCEncodingProp, VCQuotedPrintableProp );
587 const char *text = 0;
588 switch ( anEvent->
secrecy() ) {
596 text =
"CONFIDENTIAL";
600 addPropValue( vevent, VCClassProp, text );
610 if ( catStr[0] ==
' ' ) {
611 tmpStr += catStr.
mid( 1 );
620 if ( !tmpStr.isEmpty() ) {
621 tmpStr.
truncate( tmpStr.length() - 1 );
622 addPropValue( vevent, VCCategoriesProp, tmpStr.toLocal8Bit() );
630 addPropValue( vevent, VCAttachProp, (*atIt)->uri().toLocal8Bit() );
635 tmpStr = tmpStrList.
join(
";" );
636 if ( !tmpStr.isEmpty() ) {
637 addPropValue( vevent, VCResourcesProp, tmpStr.toLocal8Bit() );
645 VObject *a = addProp( vevent, VCDAlarmProp );
646 tmpStr = kDateTimeToISO( alarm->
time() );
647 addPropValue( a, VCRunTimeProp, tmpStr.toLocal8Bit() );
648 addPropValue( a, VCRepeatCountProp,
"1" );
649 addPropValue( a, VCDisplayStringProp,
"beep!" );
651 a = addProp( vevent, VCAAlarmProp );
652 addPropValue( a, VCRunTimeProp, tmpStr.toLocal8Bit() );
653 addPropValue( a, VCRepeatCountProp,
"1" );
657 a = addProp( vevent, VCPAlarmProp );
658 addPropValue( a, VCRunTimeProp, tmpStr.toLocal8Bit() );
659 addPropValue( a, VCRepeatCountProp,
"1" );
666 tmpStr.sprintf(
"%i", anEvent->
priority() );
667 addPropValue( vevent, VCPriorityProp, tmpStr.toLocal8Bit() );
671 addPropValue( vevent, VCTranspProp, tmpStr.toLocal8Bit() );
681 addPropValue( vevent, KPilotIdProp, pilotId.
toLocal8Bit() );
682 addPropValue( vevent, KPilotStatusProp,
689 Todo *VCalFormat::VTodoToEvent( VObject *vtodo )
698 if ( ( vo = isAPropertyOf( vtodo, VCDCreatedProp ) ) != 0 ) {
699 anEvent->
setCreated( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
704 vo = isAPropertyOf( vtodo, VCUniqueStringProp );
708 anEvent->
setUid( s = fakeCString( vObjectUStringZValue( vo ) ) );
713 if ( ( vo = isAPropertyOf( vtodo, VCLastModifiedProp ) ) != 0 ) {
714 anEvent->
setLastModified( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
722 if ( ( vo = isAPropertyOf( vtodo, ICOrganizerProp ) ) != 0 ) {
723 anEvent->
setOrganizer( s = fakeCString( vObjectUStringZValue( vo ) ) );
730 initPropIterator( &voi, vtodo );
731 while ( moreIteration( &voi ) ) {
732 vo = nextVObject( &voi );
733 if ( strcmp( vObjectName( vo ), VCAttendeeProp ) == 0 ) {
736 s = fakeCString( vObjectUStringZValue( vo ) );
740 int emailPos1, emailPos2;
741 if ( ( emailPos1 = tmpStr.
indexOf(
'<' ) ) > 0 ) {
745 tmpStr.
mid( emailPos1 + 1,
746 emailPos2 - ( emailPos1 + 1 ) ) );
747 }
else if ( tmpStr.
indexOf(
'@' ) > 0 ) {
758 if ( ( vp = isAPropertyOf( vo, VCRSVPProp ) ) != 0 ) {
759 a->
setRSVP( vObjectStringZValue( vp ) );
762 if ( ( vp = isAPropertyOf( vo, VCStatusProp ) ) != 0 ) {
763 a->
setStatus( readStatus( vObjectStringZValue( vp ) ) );
771 if ( ( vo = isAPropertyOf( vtodo, VCDescriptionProp ) ) != 0 ) {
772 s = fakeCString( vObjectUStringZValue( vo ) );
778 if ( ( vo = isAPropertyOf( vtodo, VCSummaryProp ) ) ) {
779 s = fakeCString( vObjectUStringZValue( vo ) );
785 if ( ( vo = isAPropertyOf( vtodo, VCLocationProp ) ) != 0 ) {
786 s = fakeCString( vObjectUStringZValue( vo ) );
793 if ( ( vo = isAPropertyOf( vtodo, VCStatusProp ) ) != 0 ) {
794 s = fakeCString( vObjectUStringZValue( vo ) );
795 if ( s && strcmp( s,
"COMPLETED" ) == 0 ) {
806 if ( ( vo = isAPropertyOf( vtodo, VCCompletedProp ) ) != 0 ) {
807 anEvent->
setCompleted( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
812 if ( ( vo = isAPropertyOf( vtodo, VCPriorityProp ) ) ) {
813 s = fakeCString( vObjectUStringZValue( vo ) );
821 if ( ( vo = isAPropertyOf( vtodo, VCDueProp ) ) != 0 ) {
822 anEvent->
setDtDue( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
830 if ( ( vo = isAPropertyOf( vtodo, VCDTstartProp ) ) != 0 ) {
831 anEvent->
setDtStart( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
839 if ( ( vo = isAPropertyOf( vtodo, VCDAlarmProp ) ) ) {
842 if ( ( a = isAPropertyOf( vo, VCRunTimeProp ) ) ) {
843 alarm->
setTime( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( a ) ) ) );
847 if ( ( vo = isAPropertyOf( vtodo, VCPAlarmProp ) ) ) {
848 if ( ( a = isAPropertyOf( vo, VCProcedureNameProp ) ) ) {
849 s = fakeCString( vObjectUStringZValue( a ) );
854 if ( ( vo = isAPropertyOf( vtodo, VCAAlarmProp ) ) ) {
855 if ( ( a = isAPropertyOf( vo, VCAudioContentProp ) ) ) {
856 s = fakeCString( vObjectUStringZValue( a ) );
864 if ( ( vo = isAPropertyOf( vtodo, VCRelatedToProp ) ) != 0 ) {
865 anEvent->
setRelatedToUid( s = fakeCString( vObjectUStringZValue( vo ) ) );
867 d->mTodosRelate.append( anEvent );
871 if ( ( vo = isAPropertyOf( vtodo, VCCategoriesProp ) ) != 0 ) {
872 s = fakeCString( vObjectUStringZValue( vo ) );
880 if ( ( vo = isAPropertyOf( vtodo, KPilotIdProp ) ) ) {
884 if ( ( vo = isAPropertyOf( vtodo, KPilotStatusProp ) ) ) {
896 Event *VCalFormat::VEventToEvent( VObject *vevent )
905 if ( ( vo = isAPropertyOf( vevent, VCDCreatedProp ) ) != 0 ) {
906 anEvent->
setCreated( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
911 vo = isAPropertyOf( vevent, VCUniqueStringProp );
915 anEvent->
setUid( s = fakeCString( vObjectUStringZValue( vo ) ) );
922 if ( ( vo = isAPropertyOf( vevent, VCSequenceProp ) ) != 0 ) {
923 s = fakeCString( vObjectUStringZValue( vo ) );
931 if ( ( vo = isAPropertyOf( vevent, VCLastModifiedProp ) ) != 0 ) {
932 anEvent->
setLastModified( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
940 if ( ( vo = isAPropertyOf( vevent, ICOrganizerProp ) ) != 0 ) {
942 anEvent->
setOrganizer( s = fakeCString( vObjectUStringZValue( vo ) ) );
949 initPropIterator( &voi, vevent );
950 while ( moreIteration( &voi ) ) {
951 vo = nextVObject( &voi );
952 if ( strcmp( vObjectName( vo ), VCAttendeeProp ) == 0 ) {
955 s = fakeCString( vObjectUStringZValue( vo ) );
959 int emailPos1, emailPos2;
960 if ( ( emailPos1 = tmpStr.
indexOf(
'<' ) ) > 0 ) {
964 tmpStr.
mid( emailPos1 + 1,
965 emailPos2 - ( emailPos1 + 1 ) ) );
966 }
else if ( tmpStr.
indexOf(
'@' ) > 0 ) {
976 if ( ( vp = isAPropertyOf( vo, VCRSVPProp ) ) != 0 ) {
977 a->
setRSVP( vObjectStringZValue( vp ) );
980 if ( ( vp = isAPropertyOf( vo, VCStatusProp ) ) != 0 ) {
981 a->
setStatus( readStatus( vObjectStringZValue( vp ) ) );
1000 if ( ( vo = isAPropertyOf( vevent, VCDTstartProp ) ) != 0 ) {
1001 anEvent->
setDtStart( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
1003 if ( anEvent->
dtStart().time().isNull() ) {
1009 if ( ( vo = isAPropertyOf( vevent, VCDTendProp ) ) != 0 ) {
1010 anEvent->
setDtEnd( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( vo ) ) ) );
1012 if ( anEvent->
dtEnd().time().isNull() ) {
1019 if ( !( vo = isAPropertyOf( vevent, VCDTstartProp ) ) ) {
1022 if ( !( vo = isAPropertyOf( vevent, VCDTendProp ) ) ) {
1029 if ( ( vo = isAPropertyOf( vevent, VCRRuleProp ) ) != 0 ) {
1030 QString tmpStr = ( s = fakeCString( vObjectUStringZValue( vo ) ) );
1037 uint type = Recurrence::rNone;
1038 if ( tmpStr.
left(1) ==
"D" ) {
1039 type = Recurrence::rDaily;
1040 }
else if ( tmpStr.
left(1) ==
"W" ) {
1041 type = Recurrence::rWeekly;
1044 if ( tmpStr.
left(2) ==
"MP" ) {
1045 type = Recurrence::rMonthlyPos;
1046 }
else if ( tmpStr.
left(2) ==
"MD" ) {
1047 type = Recurrence::rMonthlyDay;
1048 }
else if ( tmpStr.
left(2) ==
"YM" ) {
1049 type = Recurrence::rYearlyMonth;
1050 }
else if ( tmpStr.
left(2) ==
"YD" ) {
1051 type = Recurrence::rYearlyDay;
1055 if ( type != Recurrence::rNone ) {
1058 int index = tmpStr.
indexOf(
' ' );
1060 int rFreq = tmpStr.
mid( typelen, ( index - 1 ) ).
toInt();
1065 case Recurrence::rDaily:
1069 case Recurrence::rWeekly:
1073 if ( index == last ) {
1075 qba.setBit( anEvent->
dtStart().date().dayOfWeek() - 1 );
1078 while ( index < last ) {
1079 dayStr = tmpStr.
mid( index, 3 );
1080 int dayNum = numFromDay( dayStr );
1081 if ( dayNum >= 0 ) {
1082 qba.setBit( dayNum );
1091 case Recurrence::rMonthlyPos:
1097 if ( index == last ) {
1099 tmpPos = anEvent->
dtStart().date().day() / 7 + 1;
1100 if ( tmpPos == 5 ) {
1103 qba.setBit( anEvent->
dtStart().date().dayOfWeek() - 1 );
1107 while ( index < last ) {
1110 if ( tmpStr.
mid( index, 1 ) ==
"-" ) {
1112 tmpPos = 0 - tmpPos;
1115 while ( numFromDay( tmpStr.
mid( index, 3 ) ) >= 0 ) {
1116 int dayNum = numFromDay( tmpStr.
mid( index, 3 ) );
1117 qba.setBit( dayNum );
1128 case Recurrence::rMonthlyDay:
1130 if( index == last ) {
1132 short tmpDay = anEvent->
dtStart().date().day();
1136 while ( index < last ) {
1137 int index2 = tmpStr.
indexOf(
' ', index );
1138 short tmpDay = tmpStr.
mid( index, ( index2 - index ) ).
toShort();
1140 if ( tmpStr.
mid( index, 1 ) ==
"-" ) {
1141 tmpDay = 0 - tmpDay;
1149 case Recurrence::rYearlyMonth:
1152 if ( index == last ) {
1154 short tmpMonth = anEvent->
dtStart().date().month();
1158 while ( index < last ) {
1159 int index2 = tmpStr.
indexOf(
' ', index );
1160 short tmpMonth = tmpStr.
mid( index, ( index2 - index ) ).
toShort();
1167 case Recurrence::rYearlyDay:
1170 if ( index == last ) {
1172 short tmpDay = anEvent->
dtStart().date().dayOfYear();
1176 while ( index < last ) {
1177 int index2 = tmpStr.
indexOf(
' ', index );
1178 short tmpDay = tmpStr.
mid( index, ( index2 - index ) ).
toShort();
1191 if ( tmpStr.
mid( index, 1 ) ==
"#" ) {
1194 int rDuration = tmpStr.
mid( index, tmpStr.
length() - index ).toInt();
1195 if ( rDuration > 0 ) {
1198 }
else if ( tmpStr.
indexOf(
'T', index ) != -1 ) {
1199 KDateTime rEndDate = ISOToKDateTime( tmpStr.
mid( index, tmpStr.
length() - index ) );
1200 rEndDate.setDateOnly(
true );
1206 kDebug() <<
"we don't understand this type of recurrence!";
1211 if ( ( vo = isAPropertyOf( vevent, VCExpDateProp ) ) != 0 ) {
1212 s = fakeCString( vObjectUStringZValue( vo ) );
1216 anEvent->
recurrence()->addExDate( ISOToQDate(*it) );
1222 if ( ( vo = isAPropertyOf( vevent, VCSummaryProp ) ) ) {
1223 s = fakeCString( vObjectUStringZValue( vo ) );
1229 if ( ( vo = isAPropertyOf( vevent, VCDescriptionProp ) ) != 0 ) {
1230 s = fakeCString( vObjectUStringZValue( vo ) );
1242 if ( ( vo = isAPropertyOf( vevent, VCLocationProp ) ) != 0 ) {
1243 s = fakeCString( vObjectUStringZValue( vo ) );
1258 if ( ( vo = isAPropertyOf( vevent, VCStatusProp ) ) != 0 ) {
1259 QString tmpStr( s = fakeCString( vObjectUStringZValue( vo ) ) );
1270 if ( ( vo = isAPropertyOf( vevent, VCClassProp ) ) != 0 ) {
1271 s = fakeCString( vObjectUStringZValue( vo ) );
1272 if ( s && strcmp( s,
"PRIVATE" ) == 0 ) {
1274 }
else if ( s && strcmp( s,
"CONFIDENTIAL" ) == 0 ) {
1282 if ( ( vo = isAPropertyOf( vevent, VCCategoriesProp ) ) != 0 ) {
1283 s = fakeCString( vObjectUStringZValue( vo ) );
1291 initPropIterator( &voi, vevent );
1292 while ( moreIteration( &voi ) ) {
1293 vo = nextVObject( &voi );
1294 if ( strcmp( vObjectName( vo ), VCAttachProp ) == 0 ) {
1295 s = fakeCString( vObjectUStringZValue( vo ) );
1302 if ( ( vo = isAPropertyOf( vevent, VCResourcesProp ) ) != 0 ) {
1303 QString resources = ( s = fakeCString( vObjectUStringZValue( vo ) ) );
1310 if ( ( vo = isAPropertyOf( vevent, VCDAlarmProp ) ) ) {
1313 if ( ( a = isAPropertyOf( vo, VCRunTimeProp ) ) ) {
1314 alarm->
setTime( ISOToKDateTime( s = fakeCString( vObjectUStringZValue( a ) ) ) );
1318 if ( ( vo = isAPropertyOf( vevent, VCPAlarmProp ) ) ) {
1319 if ( ( a = isAPropertyOf( vo, VCProcedureNameProp ) ) ) {
1320 s = fakeCString( vObjectUStringZValue( a ) );
1325 if ( ( vo = isAPropertyOf( vevent, VCAAlarmProp ) ) ) {
1326 if ( ( a = isAPropertyOf( vo, VCAudioContentProp ) ) ) {
1327 s = fakeCString( vObjectUStringZValue( a ) );
1335 if ( ( vo = isAPropertyOf( vevent, VCPriorityProp ) ) ) {
1336 s = fakeCString( vObjectUStringZValue( vo ) );
1344 if ( ( vo = isAPropertyOf( vevent, VCTranspProp ) ) != 0 ) {
1345 s = fakeCString( vObjectUStringZValue( vo ) );
1354 if ( ( vo = isAPropertyOf( vevent, VCRelatedToProp ) ) != 0 ) {
1355 anEvent->
setRelatedToUid( s = fakeCString( vObjectUStringZValue( vo ) ) );
1357 d->mEventsRelate.append( anEvent );
1361 if ( ( vo = isAPropertyOf( vevent, KPilotIdProp ) ) ) {
1365 if ( ( vo = isAPropertyOf( vevent, KPilotStatusProp ) ) ) {
1390 QString VCalFormat::kDateTimeToISO(
const KDateTime &dt,
bool zulu )
1394 if ( !dt.isValid() ) {
1400 tmpDT = dt.toUtc().dateTime();
1402 tmpDT = dt.
toTimeSpec( d->mCalendar->timeSpec() ).dateTime();
1404 tmpStr.
sprintf(
"%.2d%.2d%.2dT%.2d%.2d%.2d",
1414 KDateTime VCalFormat::ISOToKDateTime(
const QString &dtStr )
1419 int year, month, day, hour, minute, second;
1423 month = tmpStr.
mid( 4, 2 ).
toInt();
1426 minute = tmpStr.
mid( 11, 2 ).
toInt();
1427 second = tmpStr.
mid( 13, 2 ).
toInt();
1428 tmpDate.
setYMD( year, month, day );
1429 tmpTime.
setHMS( hour, minute, second );
1433 if ( dtStr.
at( dtStr.
length() - 1 ) ==
'Z' ) {
1434 return KDateTime( tmpDate, tmpTime, KDateTime::UTC );
1436 return KDateTime( tmpDate, tmpTime, d->mCalendar->timeSpec() );
1445 int year, month, day;
1448 month = dateStr.
mid( 4, 2 ).
toInt();
1451 return QDate( year, month, day );
1457 void VCalFormat::populate( VObject *vcal )
1463 VObject *curVO, *curVOProp;
1466 if ( ( curVO = isAPropertyOf( vcal, ICMethodProp ) ) != 0 ) {
1467 char *methodType = 0;
1468 methodType = fakeCString( vObjectUStringZValue( curVO ) );
1469 kDebug() <<
"This calendar is an iTIP transaction of type '"
1470 << methodType <<
"'";
1471 deleteStr( methodType );
1475 if ( ( curVO = isAPropertyOf( vcal, VCProdIdProp ) ) != 0 ) {
1476 char *s = fakeCString( vObjectUStringZValue( curVO ) );
1477 if ( !s || strcmp( productId().toLocal8Bit(), s ) != 0 ) {
1478 kDebug() <<
"This vCalendar file was not created by KOrganizer or"
1479 <<
"any other product we support. Loading anyway...";
1481 setLoadedProductId( s );
1486 if ( ( curVO = isAPropertyOf( vcal, VCVersionProp ) ) != 0 ) {
1487 char *s = fakeCString( vObjectUStringZValue( curVO ) );
1488 if ( !s || strcmp( _VCAL_VERSION, s ) != 0 ) {
1489 kDebug() <<
"This vCalendar file has version" << s
1490 <<
"We only support" << _VCAL_VERSION;
1497 if ( ( curVO = isAPropertyOf( vcal, VCTimeZoneProp ) ) != 0 ) {
1498 char *s = fakeCString( vObjectUStringZValue( curVO ) );
1499 d->mCalendar->setTimeZone( s );
1505 d->mEventsRelate.clear();
1506 d->mTodosRelate.clear();
1508 initPropIterator( &i, vcal );
1511 while ( moreIteration( &i ) ) {
1512 curVO = nextVObject( &i );
1517 if ( strcmp( vObjectName( curVO ), VCEventProp ) == 0 ) {
1519 if ( ( curVOProp = isAPropertyOf( curVO, KPilotStatusProp ) ) != 0 ) {
1521 s = fakeCString( vObjectUStringZValue( curVOProp ) );
1524 if ( atoi( s ) == SYNCDEL ) {
1526 kDebug() <<
"skipping pilot-deleted event";
1536 if ( ( curVOProp = isAPropertyOf( curVO, VCUniqueStringProp ) ) != 0 ) {
1537 char *s = fakeCString( vObjectUStringZValue( curVOProp ) );
1541 if ( d->mCalendar->incidence( tmpStr ) ) {
1546 if ( ( !( curVOProp = isAPropertyOf( curVO, VCDTstartProp ) ) ) &&
1547 ( !( curVOProp = isAPropertyOf( curVO, VCDTendProp ) ) ) ) {
1548 kDebug() <<
"found a VEvent with no DTSTART and no DTEND! Skipping...";
1552 anEvent = VEventToEvent( curVO );
1556 if ( anEvent->
dtStart().isValid() && anEvent->
dtEnd().isValid() ) {
1557 d->mCalendar->addEvent( anEvent );
1563 }
else if ( strcmp( vObjectName( curVO ), VCTodoProp ) == 0 ) {
1564 Todo *aTodo = VTodoToEvent( curVO );
1566 Todo *old = d->mCalendar->todo( aTodo->
uid() );
1568 d->mCalendar->deleteTodo( old );
1569 d->mTodosRelate.removeAll( old );
1572 d->mCalendar->addTodo( aTodo );
1573 }
else if ( ( strcmp( vObjectName( curVO ), VCVersionProp ) == 0 ) ||
1574 ( strcmp( vObjectName( curVO ), VCProdIdProp ) == 0 ) ||
1575 ( strcmp( vObjectName( curVO ), VCTimeZoneProp ) == 0 ) ) {
1580 kDebug() <<
"Ignoring unknown vObject \"" << vObjectName(curVO) <<
"\"";
1588 for ( eIt = d->mEventsRelate.constBegin(); eIt != d->mEventsRelate.constEnd(); ++eIt ) {
1589 (*eIt)->setRelatedTo( d->mCalendar->incidence( (*eIt)->relatedToUid() ) );
1592 for ( tIt = d->mTodosRelate.constBegin(); tIt != d->mTodosRelate.constEnd(); ++tIt ) {
1593 (*tIt)->setRelatedTo( d->mCalendar->incidence( (*tIt)->relatedToUid() ) );
1597 const char *VCalFormat::dayFromNum(
int day )
1599 const char *days[7] = {
"MO ",
"TU ",
"WE ",
"TH ",
"FR ",
"SA ",
"SU " };
1604 int VCalFormat::numFromDay(
const QString &day )
1606 if ( day ==
"MO " ) {
1609 if ( day ==
"TU " ) {
1612 if ( day ==
"WE " ) {
1615 if ( day ==
"TH " ) {
1618 if ( day ==
"FR " ) {
1621 if ( day ==
"SA " ) {
1624 if ( day ==
"SU " ) {
1637 if ( statStr ==
"X-ACTION" ) {
1639 }
else if ( statStr ==
"NEEDS ACTION" ) {
1641 }
else if ( statStr ==
"ACCEPTED" ) {
1643 }
else if ( statStr ==
"SENT" ) {
1645 }
else if ( statStr ==
"TENTATIVE" ) {
1647 }
else if ( statStr ==
"CONFIRMED" ) {
1649 }
else if ( statStr ==
"DECLINED" ) {
1651 }
else if ( statStr ==
"COMPLETED" ) {
1653 }
else if ( statStr ==
"DELEGATED" ) {
1656 kDebug() <<
"error setting attendee mStatus, unknown mStatus!";
1668 return "NEEDS ACTION";
1686 return "NEEDS ACTION";
void addMonthlyPos(short pos, const QBitArray &days)
Adds a position (e.g.
void setResources(const QStringList &resources)
Sets a list of incidence resources.
QString description() const
Returns the incidence description.
void setLastModified(const KDateTime &lm)
Sets the time the incidence was last modified to lm.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString email() const
Returns the email address for this person.
void setLocation(const QString &location, bool isRich)
Sets the incidence location.
void truncate(int position)
void setEnabled(bool enable)
Sets the enabled status of the alarm.
short toShort(bool *ok, int base) const
Incidence * relatedTo() const
Returns a pointer for the incidence that is related to this one.
QList< int > yearMonths() const
Returns the months within a yearly recurrence.
void setCreated(const KDateTime &dt)
Sets the incidence creation date/time.
const Attendee::List & attendees() const
Returns a list of incidence attendees.
bool setHMS(int h, int m, int s, int ms)
void setEndDateTime(const KDateTime &endDateTime)
Sets the date and time of the last recurrence.
QString nonKDECustomProperty(const QByteArray &name) const
Return the value of a non-KDE or non-standard custom calendar property.
bool hasCompletedDate() const
Returns true, if the to-do has a date associated with completion, otherwise return false...
Provides a To-do in the sense of RFC2445.
Represents the main calendar class.
int duration() const
Returns -1 if the event recurs infinitely, 0 if the end date is set, otherwise the total number of re...
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
void setProcedureAlarm(const QString &programFile, const QString &arguments=QString())
Sets the Procedure type for this alarm and the program (with arguments) to execute when the alarm is ...
QList< int > yearDays() const
Returns the day numbers within a yearly recurrence.
void setYearly(int freq)
Sets an event to recur yearly.
virtual KDateTime dtStart() const
Returns an incidence's starting date/time as a KDateTime.
QString simplified() const
QList< RecurrenceRule::WDayPos > monthPositions() const
Returns list of day positions in months.
Represents information related to an attendee of an Calendar Incidence, typically a meeting or task (...
QString programFile() const
Returns the program file name for a Procedure alarm type.
This class provides an Event in the sense of RFC2445.
To-do in process of being completed.
QString uid() const
Returns the unique id (uid) for the incidence.
int frequency() const
Returns frequency of recurrence, in terms of the recurrence time period type.
QString join(const QString &separator) const
void addMonthlyDate(short day)
Adds a date (e.g.
virtual KDateTime dtStart() const
QBitArray days() const
Returns week day mask (bit 0 = Monday).
void setAllDay(bool allDay)
virtual bool addEvent(Event *event)=0
Inserts an Event into the calendar.
KDateTime dtDue(bool first=false) const
Returns due date and time.
KDateTime created() const
Returns the incidence creation date/time.
Alarm * newAlarm()
Create a new incidence alarm.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
PartStat status() const
Returns the PartStat of the attendee.
bool isCompleted() const
Returns true if the todo is 100% completed, otherwise return false.
void setDuration(int duration)
Sets the total number of times the event is to occur, including both the first and last...
bool recurs() const
Returns whether the event recurs at all.
PartStat
The different types of participant status.
Event, to-do or journal declined.
void setMonthly(int freq)
Sets an event to recur monthly.
void setDescription(const QString &description, bool isRich)
Sets the incidence description.
void setAudioAlarm(const QString &audioFile=QString())
Sets the Audio type for this alarm and the name of the audio file to play when the alarm is triggered...
QString number(int n, int base)
void setRelatedToUid(const QString &uid)
Relates another incidence to this one, by UID.
QString fromLocal8Bit(const char *str, int size)
KDateTime lastModified() const
Returns the time the incidence was last modified.
void setDtStart(const KDateTime &dtStart)
Sets the start date of the todo.
void setWeekly(int freq, int weekStart=1)
Sets an event to recur weekly.
void setDtEnd(const KDateTime &dtEnd)
Sets the event end date and time.
bool setYMD(int y, int m, int d)
bool allDay() const
Returns true or false depending on whether the incidence is all-day.
int toInt(bool *ok, int base) const
void setCompleted(bool completed)
Sets completed state.
Attachment::List attachments() const
Returns a list of all incidence attachments.
This file is part of the API for handling calendar data and defines the Calendar class.
QString name() const
Returns the person name string.
void setNonKDECustomProperty(const QByteArray &name, const QString &value)
Create or modify a non-KDE or non-standard custom calendar property.
void setTransparency(Transparency transparency)
Sets the event's time transparency level.
void addYearlyMonth(short _rNum)
Adds month in yearly recurrence.
void setHasDueDate(bool hasDueDate)
Sets if the todo has a due date.
Person organizer() const
Returns the Person associated with this incidence.
This class provides a template for lists of pointers.
KDateTime completed() const
Returns date and time when todo was completed.
Represents information related to an attachment for a Calendar Incidence.
bool hasDueDate() const
Returns true if the todo has a due date, otherwise return false.
QStringList resources() const
Returns the incidence resources as a list of strings.
void setUid(const QString &uid)
Returns the type of Incidence as a translated string.
const Alarm::List & alarms() const
Returns a list of all incidence alarms.
KDateTime endDateTime() const
Returns the date/time of the last recurrence.
Event appears in free/busy time.
QByteArray toLocal8Bit() const
Event, to-do or journal accepted.
Secrecy
The different types of incidence access classifications.
Event, to-do or journal needs action (default)
QString audioFile() const
Returns the audio file name for an Audio alarm type.
void addAttachment(Attachment *attachment)
Adds an attachment to the incidence.
bool RSVP() const
Returns the attendee RSVP flag.
QString & replace(int position, int n, QChar after)
Secret to the owner and some others.
Event does not appear in free/busy time.
int attendeeCount() const
Returns the number of incidence attendees.
A QList which can be sorted.
QString mid(int position, int n) const
void setRSVP(bool rsvp)
Sets the RSVP flag of the attendee to rsvp.
bool hasStartDate() const
Returns true if the todo has a start date, otherwise return false.
void addAttendee(Attendee *attendee, bool doUpdate=true)
Add Attendee to this incidence.
QString & sprintf(const char *cformat,...)
void setRevision(int rev)
Sets the number of revisions this incidence has seen.
const QChar at(int position) const
QDateTime toTimeSpec(Qt::TimeSpec specification) const
bool enabled() const
Returns the alarm enabled status: true (enabled) or false (disabled).
Type type() const
Returns the Type of the alarm.
void setSecrecy(Secrecy secrecy)
Sets the incidence Secrecy.
Transparency transparency() const
Returns the event's time transparency level.
bool mightBeRichText(const QString &text)
void setDaily(int freq)
Sets an event to recur daily.
QString left(int n) const
Recurrence * recurrence() const
Returns the recurrence rule associated with this incidence.
int priority() const
Returns the incidence priority.
void addYearlyDay(int day)
Adds day number of year within a yearly recurrence.
void setTime(const KDateTime &alarmTime)
Sets the trigger time of the alarm.
ushort recurrenceType() const
Returns the event's recurrence status.
int revision() const
Returns the number of revisions this incidence has seen.
Event or to-do delegated.
QStringList categories() const
Returns the incidence categories as a list of strings.
QString location() const
Returns the incidence location.
virtual Event::List events(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Returns a sorted, filtered list of all Events for this Calendar.
const_iterator constEnd() const
void setOrganizer(const Person &organizer)
Sets the organizer for the incidence.
const_iterator constBegin() const
KDateTime time() const
Returns the alarm trigger date/time.
void setPriority(int priority)
Sets the incidences priority.
void setSummary(const QString &summary, bool isRich)
Sets the incidence summary.
void setStatus(PartStat status)
Sets the PartStat of the attendee to status.
void setHasStartDate(bool hasStartDate)
Sets if the todo has a start date.
Secrecy secrecy() const
Returns the incidence Secrecy.
Represents an alarm notification.
Event or to-do tentatively accepted.
QList< int > monthDays() const
Returns list of day numbers of a month.
void setCategories(const QStringList &categories)
Sets the incidence category list.
This class represents a recurrence rule for a calendar incidence.
QByteArray encodeName(const QString &fileName)
QString decodeName(const QByteArray &localFileName)
virtual void setDtStart(const KDateTime &dt)
Sets the incidence starting date/time.
virtual KDateTime dtEnd() const
Returns the event end date and time.
QString summary() const
Returns the incidence summary.
void setDtDue(const KDateTime &dtDue, bool first=false)
Sets due date and time.