summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-02-19 10:19:59 (UTC)
committer zautrix <zautrix>2005-02-19 10:19:59 (UTC)
commitd2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3 (patch) (unidiff)
treed57e0a39b6c15b9108c260359fa19986e4823741 /libkcal
parent59a00e603e2ba14885e81c09daf3bb89859ff176 (diff)
downloadkdepimpi-d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3.zip
kdepimpi-d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3.tar.gz
kdepimpi-d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3.tar.bz2
duration fix
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp31
-rw-r--r--libkcal/incidencebase.cpp11
2 files changed, 25 insertions, 17 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 2e38ae3..eae41aa 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -315,197 +315,197 @@ void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
315 enum icalproperty_class classInt; 315 enum icalproperty_class classInt;
316 switch (incidence->secrecy()) { 316 switch (incidence->secrecy()) {
317 case Incidence::SecrecyPublic: 317 case Incidence::SecrecyPublic:
318 classInt = ICAL_CLASS_PUBLIC; 318 classInt = ICAL_CLASS_PUBLIC;
319 break; 319 break;
320 case Incidence::SecrecyConfidential: 320 case Incidence::SecrecyConfidential:
321 classInt = ICAL_CLASS_CONFIDENTIAL; 321 classInt = ICAL_CLASS_CONFIDENTIAL;
322 break; 322 break;
323 case Incidence::SecrecyPrivate: 323 case Incidence::SecrecyPrivate:
324 classInt =ICAL_CLASS_PRIVATE ; 324 classInt =ICAL_CLASS_PRIVATE ;
325 default: 325 default:
326 classInt =ICAL_CLASS_PRIVATE ; 326 classInt =ICAL_CLASS_PRIVATE ;
327 break; 327 break;
328 } 328 }
329 icalcomponent_add_property(parent,icalproperty_new_class(classInt)); 329 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
330 330
331 // priority 331 // priority
332 icalcomponent_add_property(parent,icalproperty_new_priority( 332 icalcomponent_add_property(parent,icalproperty_new_priority(
333 incidence->priority())); 333 incidence->priority()));
334 334
335 // categories 335 // categories
336 QStringList categories = incidence->categories(); 336 QStringList categories = incidence->categories();
337 QStringList::Iterator it; 337 QStringList::Iterator it;
338 for(it = categories.begin(); it != categories.end(); ++it ) { 338 for(it = categories.begin(); it != categories.end(); ++it ) {
339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
340 } 340 }
341// TODO: Ensure correct concatenation of categories properties. 341// TODO: Ensure correct concatenation of categories properties.
342 342
343/* 343/*
344 // categories 344 // categories
345 tmpStrList = incidence->getCategories(); 345 tmpStrList = incidence->getCategories();
346 tmpStr = ""; 346 tmpStr = "";
347 QString catStr; 347 QString catStr;
348 for ( QStringList::Iterator it = tmpStrList.begin(); 348 for ( QStringList::Iterator it = tmpStrList.begin();
349 it != tmpStrList.end(); 349 it != tmpStrList.end();
350 ++it ) { 350 ++it ) {
351 catStr = *it; 351 catStr = *it;
352 if (catStr[0] == ' ') 352 if (catStr[0] == ' ')
353 tmpStr += catStr.mid(1); 353 tmpStr += catStr.mid(1);
354 else 354 else
355 tmpStr += catStr; 355 tmpStr += catStr;
356 // this must be a ';' character as the vCalendar specification requires! 356 // this must be a ';' character as the vCalendar specification requires!
357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
358 // read in. 358 // read in.
359 tmpStr += ";"; 359 tmpStr += ";";
360 } 360 }
361 if (!tmpStr.isEmpty()) { 361 if (!tmpStr.isEmpty()) {
362 tmpStr.truncate(tmpStr.length()-1); 362 tmpStr.truncate(tmpStr.length()-1);
363 icalcomponent_add_property(parent,icalproperty_new_categories( 363 icalcomponent_add_property(parent,icalproperty_new_categories(
364 writeText(incidence->getCategories().join(";")))); 364 writeText(incidence->getCategories().join(";"))));
365 } 365 }
366*/ 366*/
367 367
368 // related event 368 // related event
369 if (incidence->relatedTo()) { 369 if (incidence->relatedTo()) {
370 icalcomponent_add_property(parent,icalproperty_new_relatedto( 370 icalcomponent_add_property(parent,icalproperty_new_relatedto(
371 incidence->relatedTo()->uid().utf8())); 371 incidence->relatedTo()->uid().utf8()));
372 } 372 }
373 373
374 // recurrence rule stuff 374 // recurrence rule stuff
375 Recurrence *recur = incidence->recurrence(); 375 Recurrence *recur = incidence->recurrence();
376 if (recur->doesRecur()) { 376 if (recur->doesRecur()) {
377 377
378 icalcomponent_add_property(parent,writeRecurrenceRule(recur)); 378 icalcomponent_add_property(parent,writeRecurrenceRule(recur));
379 } 379 }
380 380
381 // recurrence excpetion dates 381 // recurrence excpetion dates
382 DateList dateList = incidence->exDates(); 382 DateList dateList = incidence->exDates();
383 DateList::ConstIterator exIt; 383 DateList::ConstIterator exIt;
384 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 384 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
385 icalcomponent_add_property(parent,icalproperty_new_exdate( 385 icalcomponent_add_property(parent,icalproperty_new_exdate(
386 writeICalDate(*exIt))); 386 writeICalDate(*exIt)));
387 } 387 }
388 388
389 // attachments 389 // attachments
390 QPtrList<Attachment> attachments = incidence->attachments(); 390 QPtrList<Attachment> attachments = incidence->attachments();
391 for (Attachment *at = attachments.first(); at; at = attachments.next()) 391 for (Attachment *at = attachments.first(); at; at = attachments.next())
392 icalcomponent_add_property(parent,writeAttachment(at)); 392 icalcomponent_add_property(parent,writeAttachment(at));
393 393
394 // alarms 394 // alarms
395 QPtrList<Alarm> alarms = incidence->alarms(); 395 QPtrList<Alarm> alarms = incidence->alarms();
396 Alarm* alarm; 396 Alarm* alarm;
397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
398 if (alarm->enabled()) { 398 if (alarm->enabled()) {
399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
400 icalcomponent_add_component(parent,writeAlarm(alarm)); 400 icalcomponent_add_component(parent,writeAlarm(alarm));
401 } 401 }
402 } 402 }
403 if( incidence->hasRecurrenceID() ) { 403 if( incidence->hasRecurrenceID() ) {
404 icalcomponent_add_property(parent, 404 icalcomponent_add_property(parent,
405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); 405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID())));
406 } 406 }
407 // duration 407 // duration
408 408
409// 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
410 410
411// if (incidence->hasDuration()) { 411 if (incidence->hasDuration()) {
412// icaldurationtype duration; 412 icaldurationtype duration;
413// duration = writeICalDuration(incidence->duration()); 413 duration = writeICalDuration(incidence->duration());
414// icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 414 icalcomponent_add_property(parent,icalproperty_new_duration(duration));
415// } 415 }
416} 416}
417 417
418void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 418void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
419{ 419{
420 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 420 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
421 writeICalDateTime(QDateTime::currentDateTime()))); 421 writeICalDateTime(QDateTime::currentDateTime())));
422 422
423 // organizer stuff 423 // organizer stuff
424 icalcomponent_add_property(parent,icalproperty_new_organizer( 424 icalcomponent_add_property(parent,icalproperty_new_organizer(
425 ("MAILTO:" + incidenceBase->organizer()).utf8())); 425 ("MAILTO:" + incidenceBase->organizer()).utf8()));
426 426
427 // attendees 427 // attendees
428 if (incidenceBase->attendeeCount() != 0) { 428 if (incidenceBase->attendeeCount() != 0) {
429 QPtrList<Attendee> al = incidenceBase->attendees(); 429 QPtrList<Attendee> al = incidenceBase->attendees();
430 QPtrListIterator<Attendee> ai(al); 430 QPtrListIterator<Attendee> ai(al);
431 for (; ai.current(); ++ai) { 431 for (; ai.current(); ++ai) {
432 icalcomponent_add_property(parent,writeAttendee(ai.current())); 432 icalcomponent_add_property(parent,writeAttendee(ai.current()));
433 } 433 }
434 } 434 }
435 435
436 // custom properties 436 // custom properties
437 writeCustomProperties(parent, incidenceBase); 437 writeCustomProperties(parent, incidenceBase);
438} 438}
439 439
440void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 440void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
441{ 441{
442 QMap<QCString, QString> custom = properties->customProperties(); 442 QMap<QCString, QString> custom = properties->customProperties();
443 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 443 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
444 icalproperty *p = icalproperty_new_x(c.data().utf8()); 444 icalproperty *p = icalproperty_new_x(c.data().utf8());
445 icalproperty_set_x_name(p,c.key()); 445 icalproperty_set_x_name(p,c.key());
446 icalcomponent_add_property(parent,p); 446 icalcomponent_add_property(parent,p);
447 } 447 }
448} 448}
449 449
450icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 450icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
451{ 451{
452 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 452 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
453 453
454 if (!attendee->name().isEmpty()) { 454 if (!attendee->name().isEmpty()) {
455 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 455 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
456 } 456 }
457 457
458 458
459 icalproperty_add_parameter(p,icalparameter_new_rsvp( 459 icalproperty_add_parameter(p,icalparameter_new_rsvp(
460 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 460 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
461 461
462 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 462 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
463 switch (attendee->status()) { 463 switch (attendee->status()) {
464 default: 464 default:
465 case Attendee::NeedsAction: 465 case Attendee::NeedsAction:
466 status = ICAL_PARTSTAT_NEEDSACTION; 466 status = ICAL_PARTSTAT_NEEDSACTION;
467 break; 467 break;
468 case Attendee::Accepted: 468 case Attendee::Accepted:
469 status = ICAL_PARTSTAT_ACCEPTED; 469 status = ICAL_PARTSTAT_ACCEPTED;
470 break; 470 break;
471 case Attendee::Declined: 471 case Attendee::Declined:
472 status = ICAL_PARTSTAT_DECLINED; 472 status = ICAL_PARTSTAT_DECLINED;
473 break; 473 break;
474 case Attendee::Tentative: 474 case Attendee::Tentative:
475 status = ICAL_PARTSTAT_TENTATIVE; 475 status = ICAL_PARTSTAT_TENTATIVE;
476 break; 476 break;
477 case Attendee::Delegated: 477 case Attendee::Delegated:
478 status = ICAL_PARTSTAT_DELEGATED; 478 status = ICAL_PARTSTAT_DELEGATED;
479 break; 479 break;
480 case Attendee::Completed: 480 case Attendee::Completed:
481 status = ICAL_PARTSTAT_COMPLETED; 481 status = ICAL_PARTSTAT_COMPLETED;
482 break; 482 break;
483 case Attendee::InProcess: 483 case Attendee::InProcess:
484 status = ICAL_PARTSTAT_INPROCESS; 484 status = ICAL_PARTSTAT_INPROCESS;
485 break; 485 break;
486 } 486 }
487 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 487 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
488 488
489 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 489 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
490 switch (attendee->role()) { 490 switch (attendee->role()) {
491 case Attendee::Chair: 491 case Attendee::Chair:
492 role = ICAL_ROLE_CHAIR; 492 role = ICAL_ROLE_CHAIR;
493 break; 493 break;
494 default: 494 default:
495 case Attendee::ReqParticipant: 495 case Attendee::ReqParticipant:
496 role = ICAL_ROLE_REQPARTICIPANT; 496 role = ICAL_ROLE_REQPARTICIPANT;
497 break; 497 break;
498 case Attendee::OptParticipant: 498 case Attendee::OptParticipant:
499 role = ICAL_ROLE_OPTPARTICIPANT; 499 role = ICAL_ROLE_OPTPARTICIPANT;
500 break; 500 break;
501 case Attendee::NonParticipant: 501 case Attendee::NonParticipant:
502 role = ICAL_ROLE_NONPARTICIPANT; 502 role = ICAL_ROLE_NONPARTICIPANT;
503 break; 503 break;
504 } 504 }
505 icalproperty_add_parameter(p,icalparameter_new_role(role)); 505 icalproperty_add_parameter(p,icalparameter_new_role(role));
506 506
507 if (!attendee->uid().isEmpty()) { 507 if (!attendee->uid().isEmpty()) {
508 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 508 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
509 icalparameter_set_xname(icalparameter_uid,"X-UID"); 509 icalparameter_set_xname(icalparameter_uid,"X-UID");
510 icalproperty_add_parameter(p,icalparameter_uid); 510 icalproperty_add_parameter(p,icalparameter_uid);
511 } 511 }
@@ -1676,203 +1676,204 @@ void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1676 break; 1676 break;
1677 } 1677 }
1678 default: 1678 default:
1679 break; 1679 break;
1680 } 1680 }
1681 1681
1682 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1682 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1683 } 1683 }
1684 1684
1685 // custom properties 1685 // custom properties
1686 readCustomProperties(alarm, ialarm); 1686 readCustomProperties(alarm, ialarm);
1687 1687
1688 // TODO: check for consistency of alarm properties 1688 // TODO: check for consistency of alarm properties
1689} 1689}
1690 1690
1691icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1691icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1692{ 1692{
1693 icaltimetype t; 1693 icaltimetype t;
1694 1694
1695 t.year = date.year(); 1695 t.year = date.year();
1696 t.month = date.month(); 1696 t.month = date.month();
1697 t.day = date.day(); 1697 t.day = date.day();
1698 1698
1699 t.hour = 0; 1699 t.hour = 0;
1700 t.minute = 0; 1700 t.minute = 0;
1701 t.second = 0; 1701 t.second = 0;
1702 1702
1703 t.is_date = 1; 1703 t.is_date = 1;
1704 1704
1705 t.is_utc = 0; 1705 t.is_utc = 0;
1706 1706
1707 t.zone = 0; 1707 t.zone = 0;
1708 1708
1709 return t; 1709 return t;
1710} 1710}
1711 1711
1712icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1712icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1713{ 1713{
1714 icaltimetype t; 1714 icaltimetype t;
1715 t.is_date = 0; 1715 t.is_date = 0;
1716 t.zone = 0; 1716 t.zone = 0;
1717 QDateTime datetime; 1717 QDateTime datetime;
1718 if ( mParent->utc() ) { 1718 if ( mParent->utc() ) {
1719 int offset = KGlobal::locale()->localTimeOffset( dt ); 1719 int offset = KGlobal::locale()->localTimeOffset( dt );
1720 datetime = dt.addSecs ( -offset*60); 1720 datetime = dt.addSecs ( -offset*60);
1721 t.is_utc = 1; 1721 t.is_utc = 1;
1722 } 1722 }
1723 else { 1723 else {
1724 datetime = dt; 1724 datetime = dt;
1725 t.is_utc = 0; 1725 t.is_utc = 0;
1726 1726
1727 } 1727 }
1728 t.year = datetime.date().year(); 1728 t.year = datetime.date().year();
1729 t.month = datetime.date().month(); 1729 t.month = datetime.date().month();
1730 t.day = datetime.date().day(); 1730 t.day = datetime.date().day();
1731 1731
1732 t.hour = datetime.time().hour(); 1732 t.hour = datetime.time().hour();
1733 t.minute = datetime.time().minute(); 1733 t.minute = datetime.time().minute();
1734 t.second = datetime.time().second(); 1734 t.second = datetime.time().second();
1735 1735
1736 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1736 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1737 1737
1738// if ( mParent->utc() ) { 1738// if ( mParent->utc() ) {
1739// datetime = KGlobal::locale()->localTime( dt ); 1739// datetime = KGlobal::locale()->localTime( dt );
1740// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1740// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1741// if (mParent->timeZoneId().isEmpty()) 1741// if (mParent->timeZoneId().isEmpty())
1742// t = icaltime_as_utc(t, 0); 1742// t = icaltime_as_utc(t, 0);
1743// else 1743// else
1744// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1744// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1745// } 1745// }
1746 1746
1747 return t; 1747 return t;
1748} 1748}
1749 1749
1750QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1750QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1751{ 1751{
1752 QDateTime dt (QDate(t.year,t.month,t.day), 1752 QDateTime dt (QDate(t.year,t.month,t.day),
1753 QTime(t.hour,t.minute,t.second) ); 1753 QTime(t.hour,t.minute,t.second) );
1754 1754
1755 if (t.is_utc) { 1755 if (t.is_utc) {
1756 int offset = KGlobal::locale()->localTimeOffset( dt ); 1756 int offset = KGlobal::locale()->localTimeOffset( dt );
1757 dt = dt.addSecs ( offset*60); 1757 dt = dt.addSecs ( offset*60);
1758 } 1758 }
1759 1759
1760 return dt; 1760 return dt;
1761} 1761}
1762 1762
1763QDate ICalFormatImpl::readICalDate(icaltimetype t) 1763QDate ICalFormatImpl::readICalDate(icaltimetype t)
1764{ 1764{
1765 return QDate(t.year,t.month,t.day); 1765 return QDate(t.year,t.month,t.day);
1766} 1766}
1767 1767
1768icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) 1768icaldurationtype ICalFormatImpl::writeICalDuration(int seconds)
1769{ 1769{
1770 icaldurationtype d; 1770 icaldurationtype d;
1771 1771
1772 d.weeks = seconds % gSecondsPerWeek; 1772 d.is_neg = (seconds<0)?1:0;
1773 seconds -= d.weeks * gSecondsPerWeek; 1773 if (seconds<0) seconds = -seconds;
1774 d.days = seconds % gSecondsPerDay; 1774
1775 seconds -= d.days * gSecondsPerDay; 1775 d.weeks = seconds / gSecondsPerWeek;
1776 d.hours = seconds % gSecondsPerHour; 1776 seconds %= gSecondsPerWeek;
1777 seconds -= d.hours * gSecondsPerHour; 1777 d.days = seconds / gSecondsPerDay;
1778 d.minutes = seconds % gSecondsPerMinute; 1778 seconds %= gSecondsPerDay;
1779 seconds -= d.minutes * gSecondsPerMinute; 1779 d.hours = seconds / gSecondsPerHour;
1780 seconds %= gSecondsPerHour;
1781 d.minutes = seconds / gSecondsPerMinute;
1782 seconds %= gSecondsPerMinute;
1780 d.seconds = seconds; 1783 d.seconds = seconds;
1781 d.is_neg = 0;
1782
1783 return d; 1784 return d;
1784} 1785}
1785 1786
1786int ICalFormatImpl::readICalDuration(icaldurationtype d) 1787int ICalFormatImpl::readICalDuration(icaldurationtype d)
1787{ 1788{
1788 int result = 0; 1789 int result = 0;
1789 1790
1790 result += d.weeks * gSecondsPerWeek; 1791 result += d.weeks * gSecondsPerWeek;
1791 result += d.days * gSecondsPerDay; 1792 result += d.days * gSecondsPerDay;
1792 result += d.hours * gSecondsPerHour; 1793 result += d.hours * gSecondsPerHour;
1793 result += d.minutes * gSecondsPerMinute; 1794 result += d.minutes * gSecondsPerMinute;
1794 result += d.seconds; 1795 result += d.seconds;
1795 1796
1796 if (d.is_neg) result *= -1; 1797 if (d.is_neg) result *= -1;
1797 1798
1798 return result; 1799 return result;
1799} 1800}
1800 1801
1801icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) 1802icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal)
1802{ 1803{
1803 icalcomponent *calendar; 1804 icalcomponent *calendar;
1804 1805
1805 // Root component 1806 // Root component
1806 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); 1807 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
1807 1808
1808 icalproperty *p; 1809 icalproperty *p;
1809 1810
1810 // Product Identifier 1811 // Product Identifier
1811 p = icalproperty_new_prodid(CalFormat::productId().utf8()); 1812 p = icalproperty_new_prodid(CalFormat::productId().utf8());
1812 icalcomponent_add_property(calendar,p); 1813 icalcomponent_add_property(calendar,p);
1813 1814
1814 // TODO: Add time zone 1815 // TODO: Add time zone
1815 1816
1816 // iCalendar version (2.0) 1817 // iCalendar version (2.0)
1817 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); 1818 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
1818 icalcomponent_add_property(calendar,p); 1819 icalcomponent_add_property(calendar,p);
1819 1820
1820 // Custom properties 1821 // Custom properties
1821 if( cal != 0 ) 1822 if( cal != 0 )
1822 writeCustomProperties(calendar, cal); 1823 writeCustomProperties(calendar, cal);
1823 1824
1824 return calendar; 1825 return calendar;
1825} 1826}
1826 1827
1827 1828
1828 1829
1829// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1830// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1830// and break it down from its tree-like format into the dictionary format 1831// and break it down from its tree-like format into the dictionary format
1831// that is used internally in the ICalFormatImpl. 1832// that is used internally in the ICalFormatImpl.
1832bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) 1833bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar)
1833{ 1834{
1834 // this function will populate the caldict dictionary and other event 1835 // this function will populate the caldict dictionary and other event
1835 // lists. It turns vevents into Events and then inserts them. 1836 // lists. It turns vevents into Events and then inserts them.
1836 1837
1837 if (!calendar) return false; 1838 if (!calendar) return false;
1838 1839
1839// TODO: check for METHOD 1840// TODO: check for METHOD
1840#if 0 1841#if 0
1841 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1842 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1842 char *methodType = 0; 1843 char *methodType = 0;
1843 methodType = fakeCString(vObjectUStringZValue(curVO)); 1844 methodType = fakeCString(vObjectUStringZValue(curVO));
1844 if (mEnableDialogs) 1845 if (mEnableDialogs)
1845 KMessageBox::information(mTopWidget, 1846 KMessageBox::information(mTopWidget,
1846 i18n("This calendar is an iTIP transaction of type \"%1\".") 1847 i18n("This calendar is an iTIP transaction of type \"%1\".")
1847 .arg(methodType), 1848 .arg(methodType),
1848 i18n("%1: iTIP Transaction").arg(CalFormat::application())); 1849 i18n("%1: iTIP Transaction").arg(CalFormat::application()));
1849 delete methodType; 1850 delete methodType;
1850 } 1851 }
1851#endif 1852#endif
1852 1853
1853 icalproperty *p; 1854 icalproperty *p;
1854 1855
1855 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); 1856 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
1856 if (!p) { 1857 if (!p) {
1857// TODO: does no PRODID really matter? 1858// TODO: does no PRODID really matter?
1858// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1859// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1859// return false; 1860// return false;
1860 mLoadedProductId = ""; 1861 mLoadedProductId = "";
1861 mCalendarVersion = 0; 1862 mCalendarVersion = 0;
1862 } else { 1863 } else {
1863 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); 1864 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
1864 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); 1865 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId);
1865 1866
1866 delete mCompat; 1867 delete mCompat;
1867 mCompat = CompatFactory::createCompat( mLoadedProductId ); 1868 mCompat = CompatFactory::createCompat( mLoadedProductId );
1868 } 1869 }
1869 1870
1870// TODO: check for unknown PRODID 1871// TODO: check for unknown PRODID
1871#if 0 1872#if 0
1872 if (!mCalendarVersion 1873 if (!mCalendarVersion
1873 && CalFormat::productId() != mLoadedProductId) { 1874 && CalFormat::productId() != mLoadedProductId) {
1874 // warn the user that we might have trouble reading non-known calendar. 1875 // warn the user that we might have trouble reading non-known calendar.
1875 if (mEnableDialogs) 1876 if (mEnableDialogs)
1876 KMessageBox::information(mTopWidget, 1877 KMessageBox::information(mTopWidget,
1877 i18n("This vCalendar file was not created by KOrganizer " 1878 i18n("This vCalendar file was not created by KOrganizer "
1878 "or any other product we support. Loading anyway..."), 1879 "or any other product we support. Loading anyway..."),
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 51f2e9d..1e99082 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -13,199 +13,206 @@
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 <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47} 47}
48 48
49IncidenceBase::IncidenceBase(const IncidenceBase &i) : 49IncidenceBase::IncidenceBase(const IncidenceBase &i) :
50 CustomProperties( i ) 50 CustomProperties( i )
51{ 51{
52 mReadOnly = i.mReadOnly; 52 mReadOnly = i.mReadOnly;
53 mDtStart = i.mDtStart; 53 mDtStart = i.mDtStart;
54 mDuration = i.mDuration; 54 mDuration = i.mDuration;
55 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
56 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
57 mUid = i.mUid; 57 mUid = i.mUid;
58 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
60 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
61 } 61 }
62 mFloats = i.mFloats; 62 mFloats = i.mFloats;
63 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
64 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
65 mTempSyncStat = i.mTempSyncStat; 65 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 66 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 67 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 68 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 69 // of the original object.
70 mObservers.clear(); 70 mObservers.clear();
71 71
72 mAttendees.setAutoDelete( true ); 72 mAttendees.setAutoDelete( true );
73} 73}
74 74
75IncidenceBase::~IncidenceBase() 75IncidenceBase::~IncidenceBase()
76{ 76{
77} 77}
78 78
79 79
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 81{
82 // do not compare mSyncStatus and mExternalId 82 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 83 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 84 return false; // no need to check further
85 } 85 }
86 if ( i1.attendees().count() > 0 ) { 86 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 88 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 89 if ( !( (*a1) == (*a2)) )
90 { 90 {
91 //qDebug("Attendee not equal "); 91 //qDebug("Attendee not equal ");
92 return false; 92 return false;
93 } 93 }
94 a1 = i1.attendees().next(); 94 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 95 a2 = i2.attendees().next();
96 } 96 }
97 } 97 }
98 //if ( i1.dtStart() != i2.dtStart() ) 98 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 99 // return false;
100#if 0 100#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 102 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 106 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 107
108#endif 108#endif
109 if ( i1.hasDuration() == i2.hasDuration() ) {
110 if ( i1.hasDuration() ) {
111 if ( i1.duration() != i2.duration() )
112 return false;
113 }
114 } else {
115 return false;
116 }
117
109 return ( i1.organizer() == i2.organizer() && 118 return ( i1.organizer() == i2.organizer() &&
110 // i1.uid() == i2.uid() && 119 // i1.uid() == i2.uid() &&
111 // Don't compare lastModified, otherwise the operator is not 120 // Don't compare lastModified, otherwise the operator is not
112 // of much use. We are not comparing for identity, after all. 121 // of much use. We are not comparing for identity, after all.
113 i1.doesFloat() == i2.doesFloat() && 122 i1.doesFloat() == i2.doesFloat() &&
114 i1.duration() == i2.duration() &&
115 i1.hasDuration() == i2.hasDuration() &&
116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 123 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
117 // no need to compare mObserver 124 // no need to compare mObserver
118} 125}
119 126
120 127
121QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 128QDateTime IncidenceBase::getEvenTime( QDateTime dt )
122{ 129{
123 QTime t = dt.time(); 130 QTime t = dt.time();
124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 131 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
125 return dt; 132 return dt;
126} 133}
127 134
128 135
129void IncidenceBase::setUid(const QString &uid) 136void IncidenceBase::setUid(const QString &uid)
130{ 137{
131 mUid = uid; 138 mUid = uid;
132 updated(); 139 updated();
133} 140}
134 141
135QString IncidenceBase::uid() const 142QString IncidenceBase::uid() const
136{ 143{
137 return mUid; 144 return mUid;
138} 145}
139 146
140void IncidenceBase::setLastModified(const QDateTime &lm) 147void IncidenceBase::setLastModified(const QDateTime &lm)
141{ 148{
142 // DON'T! updated() because we call this from 149 // DON'T! updated() because we call this from
143 // Calendar::updateEvent(). 150 // Calendar::updateEvent().
144 mLastModified = getEvenTime(lm); 151 mLastModified = getEvenTime(lm);
145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 152 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
146} 153}
147 154
148QDateTime IncidenceBase::lastModified() const 155QDateTime IncidenceBase::lastModified() const
149{ 156{
150 return mLastModified; 157 return mLastModified;
151} 158}
152 159
153void IncidenceBase::setOrganizer(const QString &o) 160void IncidenceBase::setOrganizer(const QString &o)
154{ 161{
155 // we don't check for readonly here, because it is 162 // we don't check for readonly here, because it is
156 // possible that by setting the organizer we are changing 163 // possible that by setting the organizer we are changing
157 // the event's readonly status... 164 // the event's readonly status...
158 mOrganizer = o; 165 mOrganizer = o;
159 if (mOrganizer.left(7).upper() == "MAILTO:") 166 if (mOrganizer.left(7).upper() == "MAILTO:")
160 mOrganizer = mOrganizer.remove(0,7); 167 mOrganizer = mOrganizer.remove(0,7);
161 168
162 updated(); 169 updated();
163} 170}
164 171
165QString IncidenceBase::organizer() const 172QString IncidenceBase::organizer() const
166{ 173{
167 return mOrganizer; 174 return mOrganizer;
168} 175}
169 176
170void IncidenceBase::setReadOnly( bool readOnly ) 177void IncidenceBase::setReadOnly( bool readOnly )
171{ 178{
172 mReadOnly = readOnly; 179 mReadOnly = readOnly;
173} 180}
174 181
175void IncidenceBase::setDtStart(const QDateTime &dtStart) 182void IncidenceBase::setDtStart(const QDateTime &dtStart)
176{ 183{
177// if (mReadOnly) return; 184// if (mReadOnly) return;
178 mDtStart = getEvenTime(dtStart); 185 mDtStart = getEvenTime(dtStart);
179 updated(); 186 updated();
180} 187}
181 188
182 189
183QDateTime IncidenceBase::dtStart() const 190QDateTime IncidenceBase::dtStart() const
184{ 191{
185 return mDtStart; 192 return mDtStart;
186} 193}
187 194
188QString IncidenceBase::dtStartTimeStr() const 195QString IncidenceBase::dtStartTimeStr() const
189{ 196{
190 return KGlobal::locale()->formatTime(dtStart().time()); 197 return KGlobal::locale()->formatTime(dtStart().time());
191} 198}
192 199
193QString IncidenceBase::dtStartDateStr(bool shortfmt) const 200QString IncidenceBase::dtStartDateStr(bool shortfmt) const
194{ 201{
195 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 202 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
196} 203}
197 204
198QString IncidenceBase::dtStartStr(bool shortfmt) const 205QString IncidenceBase::dtStartStr(bool shortfmt) const
199{ 206{
200 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 207 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
201} 208}
202 209
203 210
204bool IncidenceBase::doesFloat() const 211bool IncidenceBase::doesFloat() const
205{ 212{
206 return mFloats; 213 return mFloats;
207} 214}
208 215
209void IncidenceBase::setFloats(bool f) 216void IncidenceBase::setFloats(bool f)
210{ 217{
211 if (mReadOnly) return; 218 if (mReadOnly) return;