summaryrefslogtreecommitdiffabout
path: root/libkcal/icalformatimpl.cpp
Unidiff
Diffstat (limited to 'libkcal/icalformatimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 65eabc8..ea144ee 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -7,34 +7,37 @@
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <q3ptrlist.h>
24#include <qfile.h> 24#include <qfile.h>
25//Added by qt3to4:
26#include <Q3ValueList>
27#include <Q3CString>
25 28
26#include <kdebug.h> 29#include <kdebug.h>
27#include <klocale.h> 30#include <klocale.h>
28#include <kglobal.h> 31#include <kglobal.h>
29 32
30extern "C" { 33extern "C" {
31 #include <ical.h> 34 #include <ical.h>
32 #include <icalss.h> 35 #include <icalss.h>
33 #include <icalparser.h> 36 #include <icalparser.h>
34 #include <icalrestriction.h> 37 #include <icalrestriction.h>
35} 38}
36 39
37#include "calendar.h" 40#include "calendar.h"
38#include "journal.h" 41#include "journal.h"
39#include "icalformat.h" 42#include "icalformat.h"
40#include "icalformatimpl.h" 43#include "icalformatimpl.h"
@@ -208,34 +211,34 @@ icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 211 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
209 212
210 writeIncidenceBase(vfreebusy,freebusy); 213 writeIncidenceBase(vfreebusy,freebusy);
211 214
212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
213 writeICalDateTime(freebusy->dtStart()))); 216 writeICalDateTime(freebusy->dtStart())));
214 217
215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 218 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
216 writeICalDateTime(freebusy->dtEnd()))); 219 writeICalDateTime(freebusy->dtEnd())));
217 220
218 if (method == Scheduler::Request) { 221 if (method == Scheduler::Request) {
219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 222 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
220 freebusy->uid().utf8())); 223 freebusy->uid().utf8()));
221 } 224 }
222 225
223 //Loops through all the periods in the freebusy object 226 //Loops through all the periods in the freebusy object
224 QValueList<Period> list = freebusy->busyPeriods(); 227 Q3ValueList<Period> list = freebusy->busyPeriods();
225 QValueList<Period>::Iterator it; 228 Q3ValueList<Period>::Iterator it;
226 icalperiodtype period; 229 icalperiodtype period;
227 for (it = list.begin(); it!= list.end(); ++it) { 230 for (it = list.begin(); it!= list.end(); ++it) {
228 period.start = writeICalDateTime((*it).start()); 231 period.start = writeICalDateTime((*it).start());
229 period.end = writeICalDateTime((*it).end()); 232 period.end = writeICalDateTime((*it).end());
230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 233 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
231 } 234 }
232 235
233 return vfreebusy; 236 return vfreebusy;
234} 237}
235 238
236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 239icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
237{ 240{
238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 241 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
239 242
240 writeIncidence(vjournal,journal); 243 writeIncidence(vjournal,journal);
241 244
@@ -371,38 +374,38 @@ void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
371 incidence->relatedToUid().utf8())); 374 incidence->relatedToUid().utf8()));
372 } 375 }
373 376
374 // recurrence rule stuff 377 // recurrence rule stuff
375 if (incidence->doesRecur()) { 378 if (incidence->doesRecur()) {
376 icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); 379 icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence()));
377 // recurrence excpetion dates 380 // recurrence excpetion dates
378 DateList dateList = incidence->exDates(); 381 DateList dateList = incidence->exDates();
379 DateList::ConstIterator exIt; 382 DateList::ConstIterator exIt;
380 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 383 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
381 icalcomponent_add_property(parent,icalproperty_new_exdate( 384 icalcomponent_add_property(parent,icalproperty_new_exdate(
382 writeICalDate(*exIt))); 385 writeICalDate(*exIt)));
383 } 386 }
384 } 387 }
385 388
386 // attachments 389 // attachments
387 QPtrList<Attachment> attachments = incidence->attachments(); 390 Q3PtrList<Attachment> attachments = incidence->attachments();
388 for (Attachment *at = attachments.first(); at; at = attachments.next()) 391 for (Attachment *at = attachments.first(); at; at = attachments.next())
389 icalcomponent_add_property(parent,writeAttachment(at)); 392 icalcomponent_add_property(parent,writeAttachment(at));
390 393
391 // alarms 394 // alarms
392 QPtrList<Alarm> alarms = incidence->alarms(); 395 Q3PtrList<Alarm> alarms = incidence->alarms();
393 Alarm* alarm; 396 Alarm* alarm;
394 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
395 if (alarm->enabled()) { 398 if (alarm->enabled()) {
396 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
397 icalcomponent_add_component(parent,writeAlarm(alarm)); 400 icalcomponent_add_component(parent,writeAlarm(alarm));
398 } 401 }
399 } 402 }
400 if( incidence->hasRecurrenceID() ) { 403 if( incidence->hasRecurrenceID() ) {
401 icalcomponent_add_property(parent, 404 icalcomponent_add_property(parent,
402 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); 405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID())));
403 } 406 }
404 // duration 407 // duration
405 408
406// turned off as it always is set to PTS0 (and must not occur together with DTEND 409// turned off as it always is set to PTS0 (and must not occur together with DTEND
407 410
408 if (incidence->hasDuration()) { 411 if (incidence->hasDuration()) {
@@ -410,47 +413,47 @@ void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
410 duration = writeICalDuration(incidence->duration()); 413 duration = writeICalDuration(incidence->duration());
411 icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 414 icalcomponent_add_property(parent,icalproperty_new_duration(duration));
412 } 415 }
413} 416}
414 417
415void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 418void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
416{ 419{
417 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 420 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
418 writeICalDateTime(QDateTime::currentDateTime()))); 421 writeICalDateTime(QDateTime::currentDateTime())));
419 422
420 // organizer stuff 423 // organizer stuff
421 icalcomponent_add_property(parent,icalproperty_new_organizer( 424 icalcomponent_add_property(parent,icalproperty_new_organizer(
422 ("MAILTO:" + incidenceBase->organizer()).utf8())); 425 ("MAILTO:" + incidenceBase->organizer()).utf8()));
423 426
424 // attendees 427 // attendees
425 if (incidenceBase->attendeeCount() != 0) { 428 if (incidenceBase->attendeeCount() != 0) {
426 QPtrList<Attendee> al = incidenceBase->attendees(); 429 Q3PtrList<Attendee> al = incidenceBase->attendees();
427 QPtrListIterator<Attendee> ai(al); 430 Q3PtrListIterator<Attendee> ai(al);
428 for (; ai.current(); ++ai) { 431 for (; ai.current(); ++ai) {
429 icalcomponent_add_property(parent,writeAttendee(ai.current())); 432 icalcomponent_add_property(parent,writeAttendee(ai.current()));
430 } 433 }
431 } 434 }
432 435
433 // custom properties 436 // custom properties
434 writeCustomProperties(parent, incidenceBase); 437 writeCustomProperties(parent, incidenceBase);
435} 438}
436 439
437void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 440void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
438{ 441{
439 QMap<QCString, QString> custom = properties->customProperties(); 442 QMap<Q3CString, QString> custom = properties->customProperties();
440 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 443 for (QMap<Q3CString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
441 icalproperty *p = icalproperty_new_x(c.data().utf8()); 444 icalproperty *p = icalproperty_new_x(c.data().utf8());
442 icalproperty_set_x_name(p,c.key()); 445 icalproperty_set_x_name(p,c.key());
443 icalcomponent_add_property(parent,p); 446 icalcomponent_add_property(parent,p);
444 } 447 }
445} 448}
446 449
447icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 450icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
448{ 451{
449 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 452 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
450 453
451 if (!attendee->name().isEmpty()) { 454 if (!attendee->name().isEmpty()) {
452 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 455 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
453 } 456 }
454 457
455 458
456 icalproperty_add_parameter(p,icalparameter_new_rsvp( 459 icalproperty_add_parameter(p,icalparameter_new_rsvp(
@@ -533,34 +536,34 @@ icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
533 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); 536 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64));
534 } 537 }
535 return p; 538 return p;
536} 539}
537 540
538icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) 541icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur)
539{ 542{
540// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; 543// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl;
541 544
542 icalrecurrencetype r; 545 icalrecurrencetype r;
543 546
544 icalrecurrencetype_clear(&r); 547 icalrecurrencetype_clear(&r);
545 548
546 int index = 0; 549 int index = 0;
547 int index2 = 0; 550 int index2 = 0;
548 551
549 QPtrList<Recurrence::rMonthPos> tmpPositions; 552 Q3PtrList<Recurrence::rMonthPos> tmpPositions;
550 QPtrList<int> tmpDays; 553 Q3PtrList<int> tmpDays;
551 int *tmpDay; 554 int *tmpDay;
552 Recurrence::rMonthPos *tmpPos; 555 Recurrence::rMonthPos *tmpPos;
553 bool datetime = false; 556 bool datetime = false;
554 int day; 557 int day;
555 int i; 558 int i;
556 559
557 switch(recur->doesRecur()) { 560 switch(recur->doesRecur()) {
558 case Recurrence::rMinutely: 561 case Recurrence::rMinutely:
559 r.freq = ICAL_MINUTELY_RECURRENCE; 562 r.freq = ICAL_MINUTELY_RECURRENCE;
560 datetime = true; 563 datetime = true;
561 break; 564 break;
562 case Recurrence::rHourly: 565 case Recurrence::rHourly:
563 r.freq = ICAL_HOURLY_RECURRENCE; 566 r.freq = ICAL_HOURLY_RECURRENCE;
564 datetime = true; 567 datetime = true;
565 break; 568 break;
566 case Recurrence::rDaily: 569 case Recurrence::rDaily:
@@ -691,34 +694,34 @@ icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
691 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 694 icalcomponent_add_property(a,icalproperty_new_attach(attach));
692 if (!alarm->programArguments().isEmpty()) { 695 if (!alarm->programArguments().isEmpty()) {
693 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); 696 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8()));
694 } 697 }
695 icalattach_unref( attach ); 698 icalattach_unref( attach );
696 break; 699 break;
697 case Alarm::Audio: 700 case Alarm::Audio:
698 action = ICAL_ACTION_AUDIO; 701 action = ICAL_ACTION_AUDIO;
699 if (!alarm->audioFile().isEmpty()) { 702 if (!alarm->audioFile().isEmpty()) {
700 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); 703 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data());
701 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 704 icalcomponent_add_property(a,icalproperty_new_attach(attach));
702 icalattach_unref( attach ); 705 icalattach_unref( attach );
703 } 706 }
704 break; 707 break;
705 case Alarm::Email: { 708 case Alarm::Email: {
706 action = ICAL_ACTION_EMAIL; 709 action = ICAL_ACTION_EMAIL;
707 QValueList<Person> addresses = alarm->mailAddresses(); 710 Q3ValueList<Person> addresses = alarm->mailAddresses();
708 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { 711 for (Q3ValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
709 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); 712 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8());
710 if (!(*ad).name().isEmpty()) { 713 if (!(*ad).name().isEmpty()) {
711 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); 714 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
712 } 715 }
713 icalcomponent_add_property(a,p); 716 icalcomponent_add_property(a,p);
714 } 717 }
715 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); 718 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
716 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 719 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
717 QStringList attachments = alarm->mailAttachments(); 720 QStringList attachments = alarm->mailAttachments();
718 if (attachments.count() > 0) { 721 if (attachments.count() > 0) {
719 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { 722 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
720 attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); 723 attach = icalattach_new_from_url(QFile::encodeName( *at ).data());
721 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 724 icalcomponent_add_property(a,icalproperty_new_attach(attach));
722 icalattach_unref( attach ); 725 icalattach_unref( attach );
723 } 726 }
724 } 727 }
@@ -750,34 +753,34 @@ icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
750 offset = alarm->endOffset(); 753 offset = alarm->endOffset();
751 trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); 754 trigger.duration = icaldurationtype_from_int( offset.asSeconds() );
752 } 755 }
753 icalproperty *p = icalproperty_new_trigger(trigger); 756 icalproperty *p = icalproperty_new_trigger(trigger);
754 if ( alarm->hasEndOffset() ) 757 if ( alarm->hasEndOffset() )
755 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); 758 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
756 icalcomponent_add_property(a,p); 759 icalcomponent_add_property(a,p);
757 760
758 // Repeat count and duration 761 // Repeat count and duration
759 if (alarm->repeatCount()) { 762 if (alarm->repeatCount()) {
760 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); 763 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount()));
761 icalcomponent_add_property(a,icalproperty_new_duration( 764 icalcomponent_add_property(a,icalproperty_new_duration(
762 icaldurationtype_from_int(alarm->snoozeTime()*60))); 765 icaldurationtype_from_int(alarm->snoozeTime()*60)));
763 } 766 }
764 767
765 // Custom properties 768 // Custom properties
766 QMap<QCString, QString> custom = alarm->customProperties(); 769 QMap<Q3CString, QString> custom = alarm->customProperties();
767 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 770 for (QMap<Q3CString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
768 icalproperty *p = icalproperty_new_x(c.data().utf8()); 771 icalproperty *p = icalproperty_new_x(c.data().utf8());
769 icalproperty_set_x_name(p,c.key()); 772 icalproperty_set_x_name(p,c.key());
770 icalcomponent_add_property(a,p); 773 icalcomponent_add_property(a,p);
771 } 774 }
772 775
773 return a; 776 return a;
774} 777}
775 778
776Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) 779Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
777{ 780{
778 Todo *todo = new Todo; 781 Todo *todo = new Todo;
779 782
780 readIncidence(vtodo,todo); 783 readIncidence(vtodo,todo);
781 784
782 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); 785 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
783 786
@@ -1326,33 +1329,33 @@ void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *inci
1326 incidenceBase->addAttendee(readAttendee(p)); 1329 incidenceBase->addAttendee(readAttendee(p));
1327 break; 1330 break;
1328 1331
1329 default: 1332 default:
1330 break; 1333 break;
1331 } 1334 }
1332 1335
1333 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1336 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1334 } 1337 }
1335 1338
1336 // custom properties 1339 // custom properties
1337 readCustomProperties(parent, incidenceBase); 1340 readCustomProperties(parent, incidenceBase);
1338} 1341}
1339 1342
1340void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1343void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1341{ 1344{
1342 QMap<QCString, QString> customProperties; 1345 QMap<Q3CString, QString> customProperties;
1343 1346
1344 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1347 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1345 1348
1346 while (p) { 1349 while (p) {
1347 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1350 QString value = QString::fromUtf8(icalproperty_get_x(p));
1348 customProperties[icalproperty_get_x_name(p)] = value; 1351 customProperties[icalproperty_get_x_name(p)] = value;
1349 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1352 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1350 1353
1351 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1354 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1352 } 1355 }
1353 1356
1354 properties->setCustomProperties(customProperties); 1357 properties->setCustomProperties(customProperties);
1355} 1358}
1356 1359
1357void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1360void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1358{ 1361{