summaryrefslogtreecommitdiffabout
path: root/libkcal/vcalformat.cpp
authorzautrix <zautrix>2004-08-20 04:28:28 (UTC)
committer zautrix <zautrix>2004-08-20 04:28:28 (UTC)
commit93decd4185adc7197008e8397cf753a5ab674d99 (patch) (side-by-side diff)
tree0d701d0a687c22cfe2894121f8540d60a5fbe7a9 /libkcal/vcalformat.cpp
parentf7a401f03c18ef96eb40dc5540b31cd10880e845 (diff)
downloadkdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.zip
kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.tar.gz
kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.tar.bz2
Bugfixes for syncing
Diffstat (limited to 'libkcal/vcalformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/vcalformat.cpp71
1 files changed, 38 insertions, 33 deletions
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 076cd3f..9307f12 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -254,208 +254,210 @@ VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
tmpStr = qDateTimeToISO(anEvent->lastModified());
addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
// organizer stuff
tmpStr = "MAILTO:" + anEvent->organizer();
addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
// attendees
if (anEvent->attendeeCount() != 0) {
QPtrList<Attendee> al = anEvent->attendees();
QPtrListIterator<Attendee> ai(al);
Attendee *curAttendee;
for (; ai.current(); ++ai) {
curAttendee = ai.current();
if (!curAttendee->email().isEmpty() &&
!curAttendee->name().isEmpty())
tmpStr = "MAILTO:" + curAttendee->name() + " <" +
curAttendee->email() + ">";
else if (curAttendee->name().isEmpty())
tmpStr = "MAILTO: " + curAttendee->email();
else if (curAttendee->email().isEmpty())
tmpStr = "MAILTO: " + curAttendee->name();
else if (curAttendee->name().isEmpty() &&
curAttendee->email().isEmpty())
kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
}
}
// description BL:
if (!anEvent->description().isEmpty()) {
VObject *d = addPropValue(vtodo, VCDescriptionProp,
anEvent->description().local8Bit());
if (anEvent->description().find('\n') != -1)
addProp(d, VCQuotedPrintableProp);
}
// summary
if (!anEvent->summary().isEmpty())
addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
if (!anEvent->location().isEmpty())
addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
// completed
// status
// backward compatibility, KOrganizer used to interpret only these two values
addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
"NEEDS_ACTION");
// completion date
if (anEvent->hasCompletedDate()) {
tmpStr = qDateTimeToISO(anEvent->completed());
addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
}
// priority
tmpStr.sprintf("%i",anEvent->priority());
addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
// related event
if (anEvent->relatedTo()) {
addPropValue(vtodo, VCRelatedToProp,
anEvent->relatedTo()->uid().local8Bit());
}
// categories
tmpStrList = anEvent->categories();
tmpStr = "";
QString catStr;
for ( QStringList::Iterator it = tmpStrList.begin();
it != tmpStrList.end();
++it ) {
catStr = *it;
if (catStr[0] == ' ')
tmpStr += catStr.mid(1);
else
tmpStr += catStr;
// this must be a ';' character as the vCalendar specification requires!
// vcc.y has been hacked to translate the ';' to a ',' when the vcal is
// read in.
tmpStr += ";";
}
if (!tmpStr.isEmpty()) {
tmpStr.truncate(tmpStr.length()-1);
addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
}
// alarm stuff
kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
QPtrList<Alarm> alarms = anEvent->alarms();
Alarm* alarm;
for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
if (alarm->enabled()) {
- VObject *a = addProp(vtodo, VCDAlarmProp);
- tmpStr = qDateTimeToISO(alarm->time());
- addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
- addPropValue(a, VCRepeatCountProp, "1");
- addPropValue(a, VCDisplayStringProp, "beep!");
- if (alarm->type() == Alarm::Audio) {
- a = addProp(vtodo, VCAAlarmProp);
- addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
- addPropValue(a, VCRepeatCountProp, "1");
- addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
- }
- else if (alarm->type() == Alarm::Procedure) {
- a = addProp(vtodo, VCPAlarmProp);
- addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
- addPropValue(a, VCRepeatCountProp, "1");
- addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
+ VObject *a;
+ tmpStr = qDateTimeToISO(alarm->time());
+ if (alarm->type() == Alarm::Audio) {
+ a = addProp(vtodo, VCAAlarmProp);
+ addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
+ addPropValue(a, VCRepeatCountProp, "1");
+ addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
+ }
+ else if (alarm->type() == Alarm::Procedure) {
+ a = addProp(vtodo, VCPAlarmProp);
+ addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
+ addPropValue(a, VCRepeatCountProp, "1");
+ addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
+ } else {
+ a = addProp(vtodo, VCDAlarmProp);
+ addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
+ addPropValue(a, VCRepeatCountProp, "1");
+ addPropValue(a, VCDisplayStringProp, "beep!");
}
}
}
if (anEvent->pilotId()) {
// pilot sync stuff
tmpStr.sprintf("%i",anEvent->pilotId());
addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
tmpStr.sprintf("%i",anEvent->syncStatus());
addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
}
return vtodo;
}
VObject* VCalFormat::eventToVEvent(const Event *anEvent)
{
VObject *vevent;
QString tmpStr;
QStringList tmpStrList;
vevent = newVObject(VCEventProp);
// start and end time
tmpStr = qDateTimeToISO(anEvent->dtStart(),
!anEvent->doesFloat());
addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
// events that have time associated but take up no time should
// not have both DTSTART and DTEND.
if (anEvent->dtStart() != anEvent->dtEnd()) {
tmpStr = qDateTimeToISO(anEvent->dtEnd(),
!anEvent->doesFloat());
addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
}
// creation date
tmpStr = qDateTimeToISO(anEvent->created());
addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
// unique id
addPropValue(vevent, VCUniqueStringProp,
anEvent->uid().local8Bit());
// revision
tmpStr.sprintf("%i", anEvent->revision());
addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
// last modification date
tmpStr = qDateTimeToISO(anEvent->lastModified());
addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
// attendee and organizer stuff
tmpStr = "MAILTO:" + anEvent->organizer();
addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
if (anEvent->attendeeCount() != 0) {
QPtrList<Attendee> al = anEvent->attendees();
QPtrListIterator<Attendee> ai(al);
Attendee *curAttendee;
// TODO: Put this functionality into Attendee class
for (; ai.current(); ++ai) {
curAttendee = ai.current();
if (!curAttendee->email().isEmpty() &&
!curAttendee->name().isEmpty())
tmpStr = "MAILTO:" + curAttendee->name() + " <" +
curAttendee->email() + ">";
else if (curAttendee->name().isEmpty())
tmpStr = "MAILTO: " + curAttendee->email();
else if (curAttendee->email().isEmpty())
tmpStr = "MAILTO: " + curAttendee->name();
else if (curAttendee->name().isEmpty() &&
curAttendee->email().isEmpty())
kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");;
addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
}
}
// recurrence rule stuff
if (anEvent->recurrence()->doesRecur()) {
// some more variables
QPtrList<Recurrence::rMonthPos> tmpPositions;
QPtrList<int> tmpDays;
int *tmpDay;
Recurrence::rMonthPos *tmpPos;
QString tmpStr2;
int i;
switch(anEvent->recurrence()->doesRecur()) {
case Recurrence::rDaily:
tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
// if (anEvent->rDuration > 0)
// tmpStr += "#";
@@ -532,209 +534,212 @@ VObject* VCalFormat::eventToVEvent(const Event *anEvent)
tmpStr += "#0"; // defined as repeat forever
} else {
tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE);
}
addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
} // event repeats
// exceptions to recurrence
DateList dateList = anEvent->exDates();
DateList::ConstIterator it;
QString tmpStr2;
for (it = dateList.begin(); it != dateList.end(); ++it) {
tmpStr = qDateToISO(*it) + ";";
tmpStr2 += tmpStr;
}
if (!tmpStr2.isEmpty()) {
tmpStr2.truncate(tmpStr2.length()-1);
addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit());
}
// description
if (!anEvent->description().isEmpty()) {
VObject *d = addPropValue(vevent, VCDescriptionProp,
anEvent->description().local8Bit());
if (anEvent->description().find('\n') != -1)
addProp(d, VCQuotedPrintableProp);
}
// summary
if (!anEvent->summary().isEmpty())
addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit());
if (!anEvent->location().isEmpty())
addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit());
// status
// TODO: define Event status
// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit());
// secrecy
const char *text = 0;
switch (anEvent->secrecy()) {
case Incidence::SecrecyPublic:
text = "PUBLIC";
break;
case Incidence::SecrecyPrivate:
text = "PRIVATE";
break;
case Incidence::SecrecyConfidential:
text = "CONFIDENTIAL";
break;
}
if (text) {
addPropValue(vevent, VCClassProp, text);
}
// categories
tmpStrList = anEvent->categories();
tmpStr = "";
QString catStr;
for ( QStringList::Iterator it = tmpStrList.begin();
it != tmpStrList.end();
++it ) {
catStr = *it;
if (catStr[0] == ' ')
tmpStr += catStr.mid(1);
else
tmpStr += catStr;
// this must be a ';' character as the vCalendar specification requires!
// vcc.y has been hacked to translate the ';' to a ',' when the vcal is
// read in.
tmpStr += ";";
}
if (!tmpStr.isEmpty()) {
tmpStr.truncate(tmpStr.length()-1);
addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
}
// attachments
// TODO: handle binary attachments!
QPtrList<Attachment> attachments = anEvent->attachments();
for ( Attachment *at = attachments.first(); at; at = attachments.next() )
addPropValue(vevent, VCAttachProp, at->uri().local8Bit());
// resources
tmpStrList = anEvent->resources();
tmpStr = tmpStrList.join(";");
if (!tmpStr.isEmpty())
addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
// alarm stuff
QPtrList<Alarm> alarms = anEvent->alarms();
Alarm* alarm;
for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
- if (alarm->enabled()) {
- VObject *a = addProp(vevent, VCDAlarmProp);
- tmpStr = qDateTimeToISO(alarm->time());
- addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
- addPropValue(a, VCRepeatCountProp, "1");
- addPropValue(a, VCDisplayStringProp, "beep!");
- if (alarm->type() == Alarm::Audio) {
- a = addProp(vevent, VCAAlarmProp);
- addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
- addPropValue(a, VCRepeatCountProp, "1");
- addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
- }
- if (alarm->type() == Alarm::Procedure) {
- a = addProp(vevent, VCPAlarmProp);
- addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
- addPropValue(a, VCRepeatCountProp, "1");
- addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
+ if (alarm->enabled()) {
+ VObject *a ;
+ tmpStr = qDateTimeToISO(alarm->time());
+ if (alarm->type() == Alarm::Audio) {
+ a = addProp(vevent, VCAAlarmProp);
+ addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
+ addPropValue(a, VCRepeatCountProp, "1");
+ addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
+ }
+ if (alarm->type() == Alarm::Procedure) {
+ a = addProp(vevent, VCPAlarmProp);
+ addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
+ addPropValue(a, VCRepeatCountProp, "1");
+ addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
+ } else {
+ a = addProp(vevent, VCDAlarmProp);
+ addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
+ addPropValue(a, VCRepeatCountProp, "1");
+ addPropValue(a, VCDisplayStringProp, "beep!");
+
}
}
}
// priority
tmpStr.sprintf("%i",anEvent->priority());
addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
// transparency
tmpStr.sprintf("%i",anEvent->transparency());
addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
// related event
if (anEvent->relatedTo()) {
addPropValue(vevent, VCRelatedToProp,
anEvent->relatedTo()->uid().local8Bit());
}
if (anEvent->pilotId()) {
// pilot sync stuff
tmpStr.sprintf("%i",anEvent->pilotId());
addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit());
tmpStr.sprintf("%i",anEvent->syncStatus());
addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit());
}
return vevent;
}
Todo *VCalFormat::VTodoToEvent(VObject *vtodo)
{
VObject *vo;
VObjectIterator voi;
char *s;
Todo *anEvent = new Todo;
// creation date
if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
deleteStr(s);
}
// unique id
vo = isAPropertyOf(vtodo, VCUniqueStringProp);
// while the UID property is preferred, it is not required. We'll use the
// default Event UID if none is given.
if (vo) {
anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
deleteStr(s);
}
// last modification date
if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
deleteStr(s);
}
else
anEvent->setLastModified(QDateTime(QDate::currentDate(),
QTime::currentTime()));
// organizer
// if our extension property for the event's ORGANIZER exists, add it.
if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
deleteStr(s);
} else {
anEvent->setOrganizer(mCalendar->getEmail());
}
// attendees.
initPropIterator(&voi, vtodo);
while (moreIteration(&voi)) {
vo = nextVObject(&voi);
if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
Attendee *a;
VObject *vp;
s = fakeCString(vObjectUStringZValue(vo));
QString tmpStr = QString::fromLocal8Bit(s);
deleteStr(s);
tmpStr = tmpStr.simplifyWhiteSpace();
int emailPos1, emailPos2;
if ((emailPos1 = tmpStr.find('<')) > 0) {
// both email address and name
emailPos2 = tmpStr.findRev('>');
a = new Attendee(tmpStr.left(emailPos1 - 1),
tmpStr.mid(emailPos1 + 1,
emailPos2 - (emailPos1 + 1)));
} else if (tmpStr.find('@') > 0) {
// just an email address
a = new Attendee(0, tmpStr);
} else {
// just a name
QString email = tmpStr.replace( QRegExp(" "), "." );
a = new Attendee(tmpStr,email);
}