summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-02-13 11:55:52 (UTC)
committer zautrix <zautrix>2005-02-13 11:55:52 (UTC)
commit0a33f91e166747406ca2ccb5819881feeecfdb40 (patch) (unidiff)
treee9130a16aaa6365e106d6733c3e1adeca01f72ac /libkcal
parent00ec9899a4727a4c9100d320935dde7da4803801 (diff)
downloadkdepimpi-0a33f91e166747406ca2ccb5819881feeecfdb40.zip
kdepimpi-0a33f91e166747406ca2ccb5819881feeecfdb40.tar.gz
kdepimpi-0a33f91e166747406ca2ccb5819881feeecfdb40.tar.bz2
todo recurchanges
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp10
-rw-r--r--libkcal/incidence.cpp35
-rw-r--r--libkcal/incidence.h9
3 files changed, 52 insertions, 2 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index bd13132..bb9cb29 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -211,385 +211,388 @@ icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
211 211
212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
213 writeICalDateTime(freebusy->dtStart()))); 213 writeICalDateTime(freebusy->dtStart())));
214 214
215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
216 writeICalDateTime(freebusy->dtEnd()))); 216 writeICalDateTime(freebusy->dtEnd())));
217 217
218 if (method == Scheduler::Request) { 218 if (method == Scheduler::Request) {
219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
220 freebusy->uid().utf8())); 220 freebusy->uid().utf8()));
221 } 221 }
222 222
223 //Loops through all the periods in the freebusy object 223 //Loops through all the periods in the freebusy object
224 QValueList<Period> list = freebusy->busyPeriods(); 224 QValueList<Period> list = freebusy->busyPeriods();
225 QValueList<Period>::Iterator it; 225 QValueList<Period>::Iterator it;
226 icalperiodtype period; 226 icalperiodtype period;
227 for (it = list.begin(); it!= list.end(); ++it) { 227 for (it = list.begin(); it!= list.end(); ++it) {
228 period.start = writeICalDateTime((*it).start()); 228 period.start = writeICalDateTime((*it).start());
229 period.end = writeICalDateTime((*it).end()); 229 period.end = writeICalDateTime((*it).end());
230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
231 } 231 }
232 232
233 return vfreebusy; 233 return vfreebusy;
234} 234}
235 235
236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
237{ 237{
238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
239 239
240 writeIncidence(vjournal,journal); 240 writeIncidence(vjournal,journal);
241 241
242 // start time 242 // start time
243 if (journal->dtStart().isValid()) { 243 if (journal->dtStart().isValid()) {
244 icaltimetype start; 244 icaltimetype start;
245 if (journal->doesFloat()) { 245 if (journal->doesFloat()) {
246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
247 start = writeICalDate(journal->dtStart().date()); 247 start = writeICalDate(journal->dtStart().date());
248 } else { 248 } else {
249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
250 start = writeICalDateTime(journal->dtStart()); 250 start = writeICalDateTime(journal->dtStart());
251 } 251 }
252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
253 } 253 }
254 254
255 return vjournal; 255 return vjournal;
256} 256}
257 257
258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
259{ 259{
260 // pilot sync stuff 260 // pilot sync stuff
261// TODO: move this application-specific code to kpilot 261// TODO: move this application-specific code to kpilot
262 if (incidence->pilotId()) { 262 if (incidence->pilotId()) {
263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
265 } 265 }
266 if ( !incidence->IDStr().isEmpty()) { 266 if ( !incidence->IDStr().isEmpty()) {
267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); 267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() );
268 } 268 }
269 269
270 270
271 writeIncidenceBase(parent,incidence); 271 writeIncidenceBase(parent,incidence);
272 if (incidence->cancelled()) { 272 if (incidence->cancelled()) {
273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
274 } 274 }
275 275
276 // creation date 276 // creation date
277 icalcomponent_add_property(parent,icalproperty_new_created( 277 icalcomponent_add_property(parent,icalproperty_new_created(
278 writeICalDateTime(incidence->created()))); 278 writeICalDateTime(incidence->created())));
279 279
280 // unique id 280 // unique id
281 icalcomponent_add_property(parent,icalproperty_new_uid( 281 icalcomponent_add_property(parent,icalproperty_new_uid(
282 incidence->uid().utf8())); 282 incidence->uid().utf8()));
283 283
284 // revision 284 // revision
285 icalcomponent_add_property(parent,icalproperty_new_sequence( 285 icalcomponent_add_property(parent,icalproperty_new_sequence(
286 incidence->revision())); 286 incidence->revision()));
287 287
288 // last modification date 288 // last modification date
289 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 289 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
290 writeICalDateTime(incidence->lastModified()))); 290 writeICalDateTime(incidence->lastModified())));
291 291
292 // description 292 // description
293 if (!incidence->description().isEmpty()) { 293 if (!incidence->description().isEmpty()) {
294 icalcomponent_add_property(parent,icalproperty_new_description( 294 icalcomponent_add_property(parent,icalproperty_new_description(
295 incidence->description().utf8())); 295 incidence->description().utf8()));
296 } 296 }
297 297
298 // summary 298 // summary
299 if (!incidence->summary().isEmpty()) { 299 if (!incidence->summary().isEmpty()) {
300 icalcomponent_add_property(parent,icalproperty_new_summary( 300 icalcomponent_add_property(parent,icalproperty_new_summary(
301 incidence->summary().utf8())); 301 incidence->summary().utf8()));
302 } 302 }
303 303
304 // location 304 // location
305 if (!incidence->location().isEmpty()) { 305 if (!incidence->location().isEmpty()) {
306 icalcomponent_add_property(parent,icalproperty_new_location( 306 icalcomponent_add_property(parent,icalproperty_new_location(
307 incidence->location().utf8())); 307 incidence->location().utf8()));
308 } 308 }
309 309
310// TODO: 310// TODO:
311 // status 311 // status
312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
313 313
314 // secrecy 314 // secrecy
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 403 if( incidence->hasRecurrenceID() ) {
404 icalcomponent_add_property(parent,
405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID())));
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()) {
409// icaldurationtype duration; 412// icaldurationtype duration;
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 QPtrList<Attendee> al = incidenceBase->attendees();
427 QPtrListIterator<Attendee> ai(al); 430 QPtrListIterator<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<QCString, QString> custom = properties->customProperties();
440 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) {
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(
457 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 460 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
458 461
459 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 462 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
460 switch (attendee->status()) { 463 switch (attendee->status()) {
461 default: 464 default:
462 case Attendee::NeedsAction: 465 case Attendee::NeedsAction:
463 status = ICAL_PARTSTAT_NEEDSACTION; 466 status = ICAL_PARTSTAT_NEEDSACTION;
464 break; 467 break;
465 case Attendee::Accepted: 468 case Attendee::Accepted:
466 status = ICAL_PARTSTAT_ACCEPTED; 469 status = ICAL_PARTSTAT_ACCEPTED;
467 break; 470 break;
468 case Attendee::Declined: 471 case Attendee::Declined:
469 status = ICAL_PARTSTAT_DECLINED; 472 status = ICAL_PARTSTAT_DECLINED;
470 break; 473 break;
471 case Attendee::Tentative: 474 case Attendee::Tentative:
472 status = ICAL_PARTSTAT_TENTATIVE; 475 status = ICAL_PARTSTAT_TENTATIVE;
473 break; 476 break;
474 case Attendee::Delegated: 477 case Attendee::Delegated:
475 status = ICAL_PARTSTAT_DELEGATED; 478 status = ICAL_PARTSTAT_DELEGATED;
476 break; 479 break;
477 case Attendee::Completed: 480 case Attendee::Completed:
478 status = ICAL_PARTSTAT_COMPLETED; 481 status = ICAL_PARTSTAT_COMPLETED;
479 break; 482 break;
480 case Attendee::InProcess: 483 case Attendee::InProcess:
481 status = ICAL_PARTSTAT_INPROCESS; 484 status = ICAL_PARTSTAT_INPROCESS;
482 break; 485 break;
483 } 486 }
484 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 487 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
485 488
486 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 489 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
487 switch (attendee->role()) { 490 switch (attendee->role()) {
488 case Attendee::Chair: 491 case Attendee::Chair:
489 role = ICAL_ROLE_CHAIR; 492 role = ICAL_ROLE_CHAIR;
490 break; 493 break;
491 default: 494 default:
492 case Attendee::ReqParticipant: 495 case Attendee::ReqParticipant:
493 role = ICAL_ROLE_REQPARTICIPANT; 496 role = ICAL_ROLE_REQPARTICIPANT;
494 break; 497 break;
495 case Attendee::OptParticipant: 498 case Attendee::OptParticipant:
496 role = ICAL_ROLE_OPTPARTICIPANT; 499 role = ICAL_ROLE_OPTPARTICIPANT;
497 break; 500 break;
498 case Attendee::NonParticipant: 501 case Attendee::NonParticipant:
499 role = ICAL_ROLE_NONPARTICIPANT; 502 role = ICAL_ROLE_NONPARTICIPANT;
500 break; 503 break;
501 } 504 }
502 icalproperty_add_parameter(p,icalparameter_new_role(role)); 505 icalproperty_add_parameter(p,icalparameter_new_role(role));
503 506
504 if (!attendee->uid().isEmpty()) { 507 if (!attendee->uid().isEmpty()) {
505 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 508 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
506 icalparameter_set_xname(icalparameter_uid,"X-UID"); 509 icalparameter_set_xname(icalparameter_uid,"X-UID");
507 icalproperty_add_parameter(p,icalparameter_uid); 510 icalproperty_add_parameter(p,icalparameter_uid);
508 } 511 }
509 512
510 return p; 513 return p;
511} 514}
512 515
513icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 516icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
514{ 517{
515#if 0 518#if 0
516 icalattachtype* attach = icalattachtype_new(); 519 icalattachtype* attach = icalattachtype_new();
517 if (att->isURI()) 520 if (att->isURI())
518 icalattachtype_set_url(attach, att->uri().utf8().data()); 521 icalattachtype_set_url(attach, att->uri().utf8().data());
519 else 522 else
520 icalattachtype_set_base64(attach, att->data(), 0); 523 icalattachtype_set_base64(attach, att->data(), 0);
521#endif 524#endif
522 icalattach *attach; 525 icalattach *attach;
523 if (att->isURI()) 526 if (att->isURI())
524 attach = icalattach_new_from_url( att->uri().utf8().data()); 527 attach = icalattach_new_from_url( att->uri().utf8().data());
525 else 528 else
526 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); 529 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0);
527 icalproperty *p = icalproperty_new_attach(attach); 530 icalproperty *p = icalproperty_new_attach(attach);
528 if (!att->mimeType().isEmpty()) 531 if (!att->mimeType().isEmpty())
529 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); 532 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data()));
530 533
531 if (att->isBinary()) { 534 if (att->isBinary()) {
532 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); 535 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
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 QPtrList<Recurrence::rMonthPos> tmpPositions;
550 QPtrList<int> tmpDays; 553 QPtrList<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:
567 r.freq = ICAL_DAILY_RECURRENCE; 570 r.freq = ICAL_DAILY_RECURRENCE;
568 break; 571 break;
569 case Recurrence::rWeekly: 572 case Recurrence::rWeekly:
570 r.freq = ICAL_WEEKLY_RECURRENCE; 573 r.freq = ICAL_WEEKLY_RECURRENCE;
571 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); 574 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1);
572 for (i = 0; i < 7; i++) { 575 for (i = 0; i < 7; i++) {
573 if (recur->days().testBit(i)) { 576 if (recur->days().testBit(i)) {
574 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 577 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
575 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); 578 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day);
576 } 579 }
577 } 580 }
578// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 581// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
579 break; 582 break;
580 case Recurrence::rMonthlyPos: 583 case Recurrence::rMonthlyPos:
581 r.freq = ICAL_MONTHLY_RECURRENCE; 584 r.freq = ICAL_MONTHLY_RECURRENCE;
582 585
583 tmpPositions = recur->monthPositions(); 586 tmpPositions = recur->monthPositions();
584 for (tmpPos = tmpPositions.first(); 587 for (tmpPos = tmpPositions.first();
585 tmpPos; 588 tmpPos;
586 tmpPos = tmpPositions.next()) { 589 tmpPos = tmpPositions.next()) {
587 for (i = 0; i < 7; i++) { 590 for (i = 0; i < 7; i++) {
588 if (tmpPos->rDays.testBit(i)) { 591 if (tmpPos->rDays.testBit(i)) {
589 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 592 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
590 day += tmpPos->rPos*8; 593 day += tmpPos->rPos*8;
591 if (tmpPos->negative) day = -day; 594 if (tmpPos->negative) day = -day;
592 r.by_day[index++] = day; 595 r.by_day[index++] = day;
593 } 596 }
594 } 597 }
595 } 598 }
@@ -1015,384 +1018,389 @@ Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1015{ 1018{
1016 Journal *journal = new Journal; 1019 Journal *journal = new Journal;
1017 1020
1018 readIncidence(vjournal,journal); 1021 readIncidence(vjournal,journal);
1019 1022
1020 return journal; 1023 return journal;
1021} 1024}
1022 1025
1023Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1026Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1024{ 1027{
1025 icalparameter *p = 0; 1028 icalparameter *p = 0;
1026 1029
1027 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1030 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1028 1031
1029 QString name; 1032 QString name;
1030 QString uid = QString::null; 1033 QString uid = QString::null;
1031 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1034 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1032 if (p) { 1035 if (p) {
1033 name = QString::fromUtf8(icalparameter_get_cn(p)); 1036 name = QString::fromUtf8(icalparameter_get_cn(p));
1034 } else { 1037 } else {
1035 } 1038 }
1036 1039
1037 bool rsvp=false; 1040 bool rsvp=false;
1038 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1041 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1039 if (p) { 1042 if (p) {
1040 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1043 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1041 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1044 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1042 } 1045 }
1043 1046
1044 Attendee::PartStat status = Attendee::NeedsAction; 1047 Attendee::PartStat status = Attendee::NeedsAction;
1045 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1048 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1046 if (p) { 1049 if (p) {
1047 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1050 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1048 switch(partStatParameter) { 1051 switch(partStatParameter) {
1049 default: 1052 default:
1050 case ICAL_PARTSTAT_NEEDSACTION: 1053 case ICAL_PARTSTAT_NEEDSACTION:
1051 status = Attendee::NeedsAction; 1054 status = Attendee::NeedsAction;
1052 break; 1055 break;
1053 case ICAL_PARTSTAT_ACCEPTED: 1056 case ICAL_PARTSTAT_ACCEPTED:
1054 status = Attendee::Accepted; 1057 status = Attendee::Accepted;
1055 break; 1058 break;
1056 case ICAL_PARTSTAT_DECLINED: 1059 case ICAL_PARTSTAT_DECLINED:
1057 status = Attendee::Declined; 1060 status = Attendee::Declined;
1058 break; 1061 break;
1059 case ICAL_PARTSTAT_TENTATIVE: 1062 case ICAL_PARTSTAT_TENTATIVE:
1060 status = Attendee::Tentative; 1063 status = Attendee::Tentative;
1061 break; 1064 break;
1062 case ICAL_PARTSTAT_DELEGATED: 1065 case ICAL_PARTSTAT_DELEGATED:
1063 status = Attendee::Delegated; 1066 status = Attendee::Delegated;
1064 break; 1067 break;
1065 case ICAL_PARTSTAT_COMPLETED: 1068 case ICAL_PARTSTAT_COMPLETED:
1066 status = Attendee::Completed; 1069 status = Attendee::Completed;
1067 break; 1070 break;
1068 case ICAL_PARTSTAT_INPROCESS: 1071 case ICAL_PARTSTAT_INPROCESS:
1069 status = Attendee::InProcess; 1072 status = Attendee::InProcess;
1070 break; 1073 break;
1071 } 1074 }
1072 } 1075 }
1073 1076
1074 Attendee::Role role = Attendee::ReqParticipant; 1077 Attendee::Role role = Attendee::ReqParticipant;
1075 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1078 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1076 if (p) { 1079 if (p) {
1077 icalparameter_role roleParameter = icalparameter_get_role(p); 1080 icalparameter_role roleParameter = icalparameter_get_role(p);
1078 switch(roleParameter) { 1081 switch(roleParameter) {
1079 case ICAL_ROLE_CHAIR: 1082 case ICAL_ROLE_CHAIR:
1080 role = Attendee::Chair; 1083 role = Attendee::Chair;
1081 break; 1084 break;
1082 default: 1085 default:
1083 case ICAL_ROLE_REQPARTICIPANT: 1086 case ICAL_ROLE_REQPARTICIPANT:
1084 role = Attendee::ReqParticipant; 1087 role = Attendee::ReqParticipant;
1085 break; 1088 break;
1086 case ICAL_ROLE_OPTPARTICIPANT: 1089 case ICAL_ROLE_OPTPARTICIPANT:
1087 role = Attendee::OptParticipant; 1090 role = Attendee::OptParticipant;
1088 break; 1091 break;
1089 case ICAL_ROLE_NONPARTICIPANT: 1092 case ICAL_ROLE_NONPARTICIPANT:
1090 role = Attendee::NonParticipant; 1093 role = Attendee::NonParticipant;
1091 break; 1094 break;
1092 } 1095 }
1093 } 1096 }
1094 1097
1095 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1098 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1096 uid = icalparameter_get_xvalue(p); 1099 uid = icalparameter_get_xvalue(p);
1097 // This should be added, but there seems to be a libical bug here. 1100 // This should be added, but there seems to be a libical bug here.
1098 /*while (p) { 1101 /*while (p) {
1099 // if (icalparameter_get_xname(p) == "X-UID") { 1102 // if (icalparameter_get_xname(p) == "X-UID") {
1100 uid = icalparameter_get_xvalue(p); 1103 uid = icalparameter_get_xvalue(p);
1101 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1104 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1102 } */ 1105 } */
1103 1106
1104 return new Attendee( name, email, rsvp, status, role, uid ); 1107 return new Attendee( name, email, rsvp, status, role, uid );
1105} 1108}
1106 1109
1107Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1110Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1108{ 1111{
1109 icalattach *a = icalproperty_get_attach(attach); 1112 icalattach *a = icalproperty_get_attach(attach);
1110 icalparameter_value v = ICAL_VALUE_NONE; 1113 icalparameter_value v = ICAL_VALUE_NONE;
1111 icalparameter_encoding e = ICAL_ENCODING_NONE; 1114 icalparameter_encoding e = ICAL_ENCODING_NONE;
1112 1115
1113 Attachment *attachment = 0; 1116 Attachment *attachment = 0;
1114 /* 1117 /*
1115 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1118 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1116 if (vp) 1119 if (vp)
1117 v = icalparameter_get_value(vp); 1120 v = icalparameter_get_value(vp);
1118 1121
1119 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1122 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1120 if (ep) 1123 if (ep)
1121 e = icalparameter_get_encoding(ep); 1124 e = icalparameter_get_encoding(ep);
1122 */ 1125 */
1123 int isurl = icalattach_get_is_url (a); 1126 int isurl = icalattach_get_is_url (a);
1124 if (isurl == 0) 1127 if (isurl == 0)
1125 attachment = new Attachment((const char*)icalattach_get_data(a)); 1128 attachment = new Attachment((const char*)icalattach_get_data(a));
1126 else { 1129 else {
1127 attachment = new Attachment(QString(icalattach_get_url(a))); 1130 attachment = new Attachment(QString(icalattach_get_url(a)));
1128 } 1131 }
1129 1132
1130 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1133 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1131 if (p) 1134 if (p)
1132 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1135 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1133 1136
1134 return attachment; 1137 return attachment;
1135} 1138}
1136#include <qtextcodec.h> 1139#include <qtextcodec.h>
1137void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1140void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1138{ 1141{
1139 readIncidenceBase(parent,incidence); 1142 readIncidenceBase(parent,incidence);
1140 1143
1141 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1144 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1142 bool readrec = false; 1145 bool readrec = false;
1143 const char *text; 1146 const char *text;
1144 int intvalue; 1147 int intvalue;
1145 icaltimetype icaltime; 1148 icaltimetype icaltime;
1146 icaldurationtype icalduration; 1149 icaldurationtype icalduration;
1147 struct icalrecurrencetype rectype; 1150 struct icalrecurrencetype rectype;
1148 QStringList categories; 1151 QStringList categories;
1149 1152
1150 while (p) { 1153 while (p) {
1151 icalproperty_kind kind = icalproperty_isa(p); 1154 icalproperty_kind kind = icalproperty_isa(p);
1152 switch (kind) { 1155 switch (kind) {
1153 1156
1154 case ICAL_CREATED_PROPERTY: 1157 case ICAL_CREATED_PROPERTY:
1155 icaltime = icalproperty_get_created(p); 1158 icaltime = icalproperty_get_created(p);
1156 incidence->setCreated(readICalDateTime(icaltime)); 1159 incidence->setCreated(readICalDateTime(icaltime));
1157 break; 1160 break;
1158 1161
1159 case ICAL_SEQUENCE_PROPERTY: // sequence 1162 case ICAL_SEQUENCE_PROPERTY: // sequence
1160 intvalue = icalproperty_get_sequence(p); 1163 intvalue = icalproperty_get_sequence(p);
1161 incidence->setRevision(intvalue); 1164 incidence->setRevision(intvalue);
1162 break; 1165 break;
1163 1166
1164 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1167 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1165 icaltime = icalproperty_get_lastmodified(p); 1168 icaltime = icalproperty_get_lastmodified(p);
1166 incidence->setLastModified(readICalDateTime(icaltime)); 1169 incidence->setLastModified(readICalDateTime(icaltime));
1167 break; 1170 break;
1168 1171
1169 case ICAL_DTSTART_PROPERTY: // start date and time 1172 case ICAL_DTSTART_PROPERTY: // start date and time
1170 icaltime = icalproperty_get_dtstart(p); 1173 icaltime = icalproperty_get_dtstart(p);
1171 if (icaltime.is_date) { 1174 if (icaltime.is_date) {
1172 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1175 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1173 incidence->setFloats(true); 1176 incidence->setFloats(true);
1174 } else { 1177 } else {
1175 incidence->setDtStart(readICalDateTime(icaltime)); 1178 incidence->setDtStart(readICalDateTime(icaltime));
1176 } 1179 }
1177 break; 1180 break;
1178 1181
1179 case ICAL_DURATION_PROPERTY: // start date and time 1182 case ICAL_DURATION_PROPERTY: // start date and time
1180 icalduration = icalproperty_get_duration(p); 1183 icalduration = icalproperty_get_duration(p);
1181 incidence->setDuration(readICalDuration(icalduration)); 1184 incidence->setDuration(readICalDuration(icalduration));
1182 break; 1185 break;
1183 1186
1184 case ICAL_DESCRIPTION_PROPERTY: // description 1187 case ICAL_DESCRIPTION_PROPERTY: // description
1185 text = icalproperty_get_description(p); 1188 text = icalproperty_get_description(p);
1186 incidence->setDescription(QString::fromUtf8(text)); 1189 incidence->setDescription(QString::fromUtf8(text));
1187 break; 1190 break;
1188 1191
1189 case ICAL_SUMMARY_PROPERTY: // summary 1192 case ICAL_SUMMARY_PROPERTY: // summary
1190 { 1193 {
1191 text = icalproperty_get_summary(p); 1194 text = icalproperty_get_summary(p);
1192 incidence->setSummary(QString::fromUtf8(text)); 1195 incidence->setSummary(QString::fromUtf8(text));
1193 } 1196 }
1194 break; 1197 break;
1195 case ICAL_STATUS_PROPERTY: // summary 1198 case ICAL_STATUS_PROPERTY: // summary
1196 { 1199 {
1197 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1200 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1198 incidence->setCancelled( true ); 1201 incidence->setCancelled( true );
1199 } 1202 }
1200 break; 1203 break;
1201 1204
1202 case ICAL_LOCATION_PROPERTY: // location 1205 case ICAL_LOCATION_PROPERTY: // location
1203 text = icalproperty_get_location(p); 1206 text = icalproperty_get_location(p);
1204 incidence->setLocation(QString::fromUtf8(text)); 1207 incidence->setLocation(QString::fromUtf8(text));
1205 break; 1208 break;
1206 1209
1210 case ICAL_RECURRENCEID_PROPERTY:
1211 icaltime = icalproperty_get_recurrenceid(p);
1212 incidence->setRecurrenceID( readICalDateTime(icaltime) );
1213 qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() );
1214 break;
1207#if 0 1215#if 0
1208 // status 1216 // status
1209 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1217 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1210 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1218 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1211 deleteStr(s); 1219 deleteStr(s);
1212 } 1220 }
1213 else 1221 else
1214 incidence->setStatus("NEEDS ACTION"); 1222 incidence->setStatus("NEEDS ACTION");
1215#endif 1223#endif
1216 1224
1217 case ICAL_PRIORITY_PROPERTY: // priority 1225 case ICAL_PRIORITY_PROPERTY: // priority
1218 intvalue = icalproperty_get_priority(p); 1226 intvalue = icalproperty_get_priority(p);
1219 incidence->setPriority(intvalue); 1227 incidence->setPriority(intvalue);
1220 break; 1228 break;
1221 1229
1222 case ICAL_CATEGORIES_PROPERTY: // categories 1230 case ICAL_CATEGORIES_PROPERTY: // categories
1223 text = icalproperty_get_categories(p); 1231 text = icalproperty_get_categories(p);
1224 categories.append(QString::fromUtf8(text)); 1232 categories.append(QString::fromUtf8(text));
1225 break; 1233 break;
1226 //******************************************* 1234 //*******************************************
1227 case ICAL_RRULE_PROPERTY: 1235 case ICAL_RRULE_PROPERTY:
1228 // we do need (maybe )start datetime of incidence for recurrence 1236 // we do need (maybe )start datetime of incidence for recurrence
1229 // such that we can read recurrence only after we read incidence completely 1237 // such that we can read recurrence only after we read incidence completely
1230 readrec = true; 1238 readrec = true;
1231 rectype = icalproperty_get_rrule(p); 1239 rectype = icalproperty_get_rrule(p);
1232 break; 1240 break;
1233 1241
1234 case ICAL_EXDATE_PROPERTY: 1242 case ICAL_EXDATE_PROPERTY:
1235 icaltime = icalproperty_get_exdate(p); 1243 icaltime = icalproperty_get_exdate(p);
1236 incidence->addExDate(readICalDate(icaltime)); 1244 incidence->addExDate(readICalDate(icaltime));
1237 break; 1245 break;
1238 1246
1239 case ICAL_CLASS_PROPERTY: { 1247 case ICAL_CLASS_PROPERTY: {
1240 int inttext = icalproperty_get_class(p); 1248 int inttext = icalproperty_get_class(p);
1241 if (inttext == ICAL_CLASS_PUBLIC ) { 1249 if (inttext == ICAL_CLASS_PUBLIC ) {
1242 incidence->setSecrecy(Incidence::SecrecyPublic); 1250 incidence->setSecrecy(Incidence::SecrecyPublic);
1243 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1251 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1244 incidence->setSecrecy(Incidence::SecrecyConfidential); 1252 incidence->setSecrecy(Incidence::SecrecyConfidential);
1245 } else { 1253 } else {
1246 incidence->setSecrecy(Incidence::SecrecyPrivate); 1254 incidence->setSecrecy(Incidence::SecrecyPrivate);
1247 } 1255 }
1248 } 1256 }
1249 break; 1257 break;
1250 1258
1251 case ICAL_ATTACH_PROPERTY: // attachments 1259 case ICAL_ATTACH_PROPERTY: // attachments
1252 incidence->addAttachment(readAttachment(p)); 1260 incidence->addAttachment(readAttachment(p));
1253 break; 1261 break;
1254 1262
1255 default: 1263 default:
1256// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1264// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1257// << endl; 1265// << endl;
1258 break; 1266 break;
1259 } 1267 }
1260 1268
1261 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1269 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1262 } 1270 }
1263 if ( readrec ) { 1271 if ( readrec ) {
1264 readRecurrenceRule(rectype,incidence); 1272 readRecurrenceRule(rectype,incidence);
1265 } 1273 }
1266 // kpilot stuff 1274 // kpilot stuff
1267// TODO: move this application-specific code to kpilot 1275// TODO: move this application-specific code to kpilot
1268 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1276 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1269 if (!kp.isNull()) { 1277 if (!kp.isNull()) {
1270 incidence->setPilotId(kp.toInt()); 1278 incidence->setPilotId(kp.toInt());
1271 } 1279 }
1272 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1280 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1273 if (!kp.isNull()) { 1281 if (!kp.isNull()) {
1274 incidence->setSyncStatus(kp.toInt()); 1282 incidence->setSyncStatus(kp.toInt());
1275 } 1283 }
1276 1284
1277 1285
1278 kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); 1286 kp = incidence->nonKDECustomProperty("X-KOPIEXTID");
1279 if (!kp.isNull()) { 1287 if (!kp.isNull()) {
1280 incidence->setIDStr(kp); 1288 incidence->setIDStr(kp);
1281 } 1289 }
1282 1290
1283 // Cancel backwards compatibility mode for subsequent changes by the application 1291 // Cancel backwards compatibility mode for subsequent changes by the application
1284 incidence->recurrence()->setCompatVersion(); 1292 incidence->recurrence()->setCompatVersion();
1285 1293
1286 // add categories 1294 // add categories
1287 incidence->setCategories(categories); 1295 incidence->setCategories(categories);
1288 1296
1289 // iterate through all alarms 1297 // iterate through all alarms
1290 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1298 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1291 alarm; 1299 alarm;
1292 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1300 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1293 readAlarm(alarm,incidence); 1301 readAlarm(alarm,incidence);
1294 } 1302 }
1295} 1303}
1296 1304
1297void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1305void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1298{ 1306{
1299 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1307 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1300 1308
1301 while (p) { 1309 while (p) {
1302 icalproperty_kind kind = icalproperty_isa(p); 1310 icalproperty_kind kind = icalproperty_isa(p);
1303 switch (kind) { 1311 switch (kind) {
1304 1312
1305 case ICAL_UID_PROPERTY: // unique id 1313 case ICAL_UID_PROPERTY: // unique id
1306 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1314 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1307 break; 1315 break;
1308 1316
1309 case ICAL_ORGANIZER_PROPERTY: // organizer 1317 case ICAL_ORGANIZER_PROPERTY: // organizer
1310 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1318 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1311 break; 1319 break;
1312 1320
1313 case ICAL_ATTENDEE_PROPERTY: // attendee 1321 case ICAL_ATTENDEE_PROPERTY: // attendee
1314 incidenceBase->addAttendee(readAttendee(p)); 1322 incidenceBase->addAttendee(readAttendee(p));
1315 break; 1323 break;
1316 1324
1317 default: 1325 default:
1318 break; 1326 break;
1319 } 1327 }
1320 1328
1321 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1329 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1322 } 1330 }
1323 1331
1324 // custom properties 1332 // custom properties
1325 readCustomProperties(parent, incidenceBase); 1333 readCustomProperties(parent, incidenceBase);
1326} 1334}
1327 1335
1328void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1336void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1329{ 1337{
1330 QMap<QCString, QString> customProperties; 1338 QMap<QCString, QString> customProperties;
1331 1339
1332 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1340 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1333 1341
1334 while (p) { 1342 while (p) {
1335 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1343 QString value = QString::fromUtf8(icalproperty_get_x(p));
1336 customProperties[icalproperty_get_x_name(p)] = value; 1344 customProperties[icalproperty_get_x_name(p)] = value;
1337 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1345 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1338 1346
1339 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1347 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1340 } 1348 }
1341 1349
1342 properties->setCustomProperties(customProperties); 1350 properties->setCustomProperties(customProperties);
1343} 1351}
1344 1352
1345void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1353void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1346{ 1354{
1347// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1355// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1348 1356
1349 Recurrence *recur = incidence->recurrence(); 1357 Recurrence *recur = incidence->recurrence();
1350 recur->setCompatVersion(mCalendarVersion); 1358 recur->setCompatVersion(mCalendarVersion);
1351 recur->unsetRecurs(); 1359 recur->unsetRecurs();
1352 1360
1353 struct icalrecurrencetype r = rrule; 1361 struct icalrecurrencetype r = rrule;
1354 1362
1355 dumpIcalRecurrence(r); 1363 dumpIcalRecurrence(r);
1356 readRecurrence( r, recur, incidence); 1364 readRecurrence( r, recur, incidence);
1357} 1365}
1358 1366
1359void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1367void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1360{ 1368{
1361 int wkst; 1369 int wkst;
1362 int index = 0; 1370 int index = 0;
1363 short day = 0; 1371 short day = 0;
1364 QBitArray qba(7); 1372 QBitArray qba(7);
1365 int frequ = r.freq; 1373 int frequ = r.freq;
1366 int interv = r.interval; 1374 int interv = r.interval;
1367 // preprocessing for odd recurrence definitions 1375 // preprocessing for odd recurrence definitions
1368 1376
1369 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1377 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1370 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1378 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1371 interv = 12; 1379 interv = 12;
1372 } 1380 }
1373 } 1381 }
1374 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1382 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1375 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1383 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1376 frequ = ICAL_MONTHLY_RECURRENCE; 1384 frequ = ICAL_MONTHLY_RECURRENCE;
1377 interv = 12* r.interval; 1385 interv = 12* r.interval;
1378 } 1386 }
1379 } 1387 }
1380 1388
1381 switch (frequ) { 1389 switch (frequ) {
1382 case ICAL_MINUTELY_RECURRENCE: 1390 case ICAL_MINUTELY_RECURRENCE:
1383 if (!icaltime_is_null_time(r.until)) { 1391 if (!icaltime_is_null_time(r.until)) {
1384 recur->setMinutely(interv,readICalDateTime(r.until)); 1392 recur->setMinutely(interv,readICalDateTime(r.until));
1385 } else { 1393 } else {
1386 if (r.count == 0) 1394 if (r.count == 0)
1387 recur->setMinutely(interv,-1); 1395 recur->setMinutely(interv,-1);
1388 else 1396 else
1389 recur->setMinutely(interv,r.count); 1397 recur->setMinutely(interv,r.count);
1390 } 1398 }
1391 break; 1399 break;
1392 case ICAL_HOURLY_RECURRENCE: 1400 case ICAL_HOURLY_RECURRENCE:
1393 if (!icaltime_is_null_time(r.until)) { 1401 if (!icaltime_is_null_time(r.until)) {
1394 recur->setHourly(interv,readICalDateTime(r.until)); 1402 recur->setHourly(interv,readICalDateTime(r.until));
1395 } else { 1403 } else {
1396 if (r.count == 0) 1404 if (r.count == 0)
1397 recur->setHourly(interv,-1); 1405 recur->setHourly(interv,-1);
1398 else 1406 else
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index f9e1e9e..dbc159c 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,364 +1,397 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
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 <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = new Recurrence(this); 36 mRecurrence = new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42 mHasRecurrenceID = false;
42} 43}
43 44
44Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 45Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
45{ 46{
46// TODO: reenable attributes currently commented out. 47// TODO: reenable attributes currently commented out.
47 mRevision = i.mRevision; 48 mRevision = i.mRevision;
48 mCreated = i.mCreated; 49 mCreated = i.mCreated;
49 mDescription = i.mDescription; 50 mDescription = i.mDescription;
50 mSummary = i.mSummary; 51 mSummary = i.mSummary;
51 mCategories = i.mCategories; 52 mCategories = i.mCategories;
52// Incidence *mRelatedTo; Incidence *mRelatedTo; 53// Incidence *mRelatedTo; Incidence *mRelatedTo;
53 mRelatedTo = 0; 54 mRelatedTo = 0;
54 mRelatedToUid = i.mRelatedToUid; 55 mRelatedToUid = i.mRelatedToUid;
55// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 56// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
56 mExDates = i.mExDates; 57 mExDates = i.mExDates;
57 mAttachments = i.mAttachments; 58 mAttachments = i.mAttachments;
58 mResources = i.mResources; 59 mResources = i.mResources;
59 mSecrecy = i.mSecrecy; 60 mSecrecy = i.mSecrecy;
60 mPriority = i.mPriority; 61 mPriority = i.mPriority;
61 mLocation = i.mLocation; 62 mLocation = i.mLocation;
62 mCancelled = i.mCancelled; 63 mCancelled = i.mCancelled;
63 mHasStartDate = i.mHasStartDate; 64 mHasStartDate = i.mHasStartDate;
64 QPtrListIterator<Alarm> it( i.mAlarms ); 65 QPtrListIterator<Alarm> it( i.mAlarms );
65 const Alarm *a; 66 const Alarm *a;
66 while( (a = it.current()) ) { 67 while( (a = it.current()) ) {
67 Alarm *b = new Alarm( *a ); 68 Alarm *b = new Alarm( *a );
68 b->setParent( this ); 69 b->setParent( this );
69 mAlarms.append( b ); 70 mAlarms.append( b );
70 71
71 ++it; 72 ++it;
72 } 73 }
73 mAlarms.setAutoDelete(true); 74 mAlarms.setAutoDelete(true);
74 75 mHasRecurrenceID = i.mHasRecurrenceID;
76 mRecurrenceID = i.mRecurrenceID;
75 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 77 mRecurrence = new Recurrence( *(i.mRecurrence), this );
76} 78}
77 79
78Incidence::~Incidence() 80Incidence::~Incidence()
79{ 81{
80 82
81 Incidence *ev; 83 Incidence *ev;
82 QPtrList<Incidence> Relations = relations(); 84 QPtrList<Incidence> Relations = relations();
83 for (ev=Relations.first();ev;ev=Relations.next()) { 85 for (ev=Relations.first();ev;ev=Relations.next()) {
84 if (ev->relatedTo() == this) ev->setRelatedTo(0); 86 if (ev->relatedTo() == this) ev->setRelatedTo(0);
85 } 87 }
86 if (relatedTo()) relatedTo()->removeRelation(this); 88 if (relatedTo()) relatedTo()->removeRelation(this);
87 delete mRecurrence; 89 delete mRecurrence;
88 90
89} 91}
92bool Incidence::hasRecurrenceID() const
93{
94 return mHasRecurrenceID;
95}
96
97void Incidence::setHasRecurrenceID( bool b )
98{
99 mHasRecurrenceID = b;
100}
101
102void Incidence::setRecurrenceID(QDateTime d)
103{
104 mRecurrenceID = d;
105 mHasRecurrenceID = true;
106 updated();
107}
108QDateTime Incidence::recurrenceID () const
109{
110 return mRecurrenceID;
111}
90 112
91bool Incidence::cancelled() const 113bool Incidence::cancelled() const
92{ 114{
93 return mCancelled; 115 return mCancelled;
94} 116}
95void Incidence::setCancelled( bool b ) 117void Incidence::setCancelled( bool b )
96{ 118{
97 mCancelled = b; 119 mCancelled = b;
98 updated(); 120 updated();
99} 121}
100bool Incidence::hasStartDate() const 122bool Incidence::hasStartDate() const
101{ 123{
102 return mHasStartDate; 124 return mHasStartDate;
103} 125}
104 126
105void Incidence::setHasStartDate(bool f) 127void Incidence::setHasStartDate(bool f)
106{ 128{
107 if (mReadOnly) return; 129 if (mReadOnly) return;
108 mHasStartDate = f; 130 mHasStartDate = f;
109 updated(); 131 updated();
110} 132}
111 133
112// A string comparison that considers that null and empty are the same 134// A string comparison that considers that null and empty are the same
113static bool stringCompare( const QString& s1, const QString& s2 ) 135static bool stringCompare( const QString& s1, const QString& s2 )
114{ 136{
115 if ( s1.isEmpty() && s2.isEmpty() ) 137 if ( s1.isEmpty() && s2.isEmpty() )
116 return true; 138 return true;
117 return s1 == s2; 139 return s1 == s2;
118} 140}
119 141
120bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 142bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
121{ 143{
122 144
123 if( i1.alarms().count() != i2.alarms().count() ) { 145 if( i1.alarms().count() != i2.alarms().count() ) {
124 return false; // no need to check further 146 return false; // no need to check further
125 } 147 }
126 if ( i1.alarms().count() > 0 ) { 148 if ( i1.alarms().count() > 0 ) {
127 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 149 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
128 { 150 {
129 qDebug("alarm not equal "); 151 qDebug("alarm not equal ");
130 return false; 152 return false;
131 } 153 }
132 } 154 }
133#if 0 155#if 0
134 QPtrListIterator<Alarm> a1( i1.alarms() ); 156 QPtrListIterator<Alarm> a1( i1.alarms() );
135 QPtrListIterator<Alarm> a2( i2.alarms() ); 157 QPtrListIterator<Alarm> a2( i2.alarms() );
136 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 158 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
137 if( *a1.current() == *a2.current() ) { 159 if( *a1.current() == *a2.current() ) {
138 continue; 160 continue;
139 } 161 }
140 else { 162 else {
141 return false; 163 return false;
142 } 164 }
143 } 165 }
144#endif 166#endif
145 167
168 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
169 if ( i1.hasRecurrenceID() ) {
170 if ( i1.recurrenceID() != i2.recurrenceID() )
171 return false;
172 }
173
174 } else {
175 return false;
176 }
177
146 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 178 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
147 return false; 179 return false;
148 if ( i1.hasStartDate() == i2.hasStartDate() ) { 180 if ( i1.hasStartDate() == i2.hasStartDate() ) {
149 if ( i1.hasStartDate() ) { 181 if ( i1.hasStartDate() ) {
150 if ( i1.dtStart() != i2.dtStart() ) 182 if ( i1.dtStart() != i2.dtStart() )
151 return false; 183 return false;
152 } 184 }
153 } else { 185 } else {
154 return false; 186 return false;
155 } 187 }
156 if (!( *i1.recurrence() == *i2.recurrence()) ) { 188 if (!( *i1.recurrence() == *i2.recurrence()) ) {
157 qDebug("recurrence is NOT equal "); 189 qDebug("recurrence is NOT equal ");
158 return false; 190 return false;
159 } 191 }
160 return 192 return
161 // i1.created() == i2.created() && 193 // i1.created() == i2.created() &&
162 stringCompare( i1.description(), i2.description() ) && 194 stringCompare( i1.description(), i2.description() ) &&
163 stringCompare( i1.summary(), i2.summary() ) && 195 stringCompare( i1.summary(), i2.summary() ) &&
164 i1.categories() == i2.categories() && 196 i1.categories() == i2.categories() &&
165 // no need to compare mRelatedTo 197 // no need to compare mRelatedTo
166 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 198 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
167 // i1.relations() == i2.relations() && 199 // i1.relations() == i2.relations() &&
168 i1.exDates() == i2.exDates() && 200 i1.exDates() == i2.exDates() &&
169 i1.attachments() == i2.attachments() && 201 i1.attachments() == i2.attachments() &&
170 i1.resources() == i2.resources() && 202 i1.resources() == i2.resources() &&
171 i1.secrecy() == i2.secrecy() && 203 i1.secrecy() == i2.secrecy() &&
172 i1.priority() == i2.priority() && 204 i1.priority() == i2.priority() &&
205 i1.cancelled() == i2.cancelled() &&
173 stringCompare( i1.location(), i2.location() ); 206 stringCompare( i1.location(), i2.location() );
174} 207}
175 208
176Incidence* Incidence::recreateCloneException( QDate d ) 209Incidence* Incidence::recreateCloneException( QDate d )
177{ 210{
178 Incidence* newInc = clone(); 211 Incidence* newInc = clone();
179 newInc->recreate(); 212 newInc->recreate();
180 if ( doesRecur() ) { 213 if ( doesRecur() ) {
181 addExDate( d ); 214 addExDate( d );
182 newInc->recurrence()->unsetRecurs(); 215 newInc->recurrence()->unsetRecurs();
183 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 216 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
184 QTime tim = dtStart().time(); 217 QTime tim = dtStart().time();
185 newInc->setDtStart( QDateTime(d, tim) ); 218 newInc->setDtStart( QDateTime(d, tim) );
186 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 219 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
187 } 220 }
188 return newInc; 221 return newInc;
189} 222}
190 223
191void Incidence::recreate() 224void Incidence::recreate()
192{ 225{
193 setCreated(QDateTime::currentDateTime()); 226 setCreated(QDateTime::currentDateTime());
194 227
195 setUid(CalFormat::createUniqueId()); 228 setUid(CalFormat::createUniqueId());
196 229
197 setRevision(0); 230 setRevision(0);
198 setIDStr( ":" ); 231 setIDStr( ":" );
199 setLastModified(QDateTime::currentDateTime()); 232 setLastModified(QDateTime::currentDateTime());
200} 233}
201 234
202void Incidence::setReadOnly( bool readOnly ) 235void Incidence::setReadOnly( bool readOnly )
203{ 236{
204 IncidenceBase::setReadOnly( readOnly ); 237 IncidenceBase::setReadOnly( readOnly );
205 recurrence()->setRecurReadOnly( readOnly); 238 recurrence()->setRecurReadOnly( readOnly);
206} 239}
207 240
208void Incidence::setCreated(QDateTime created) 241void Incidence::setCreated(QDateTime created)
209{ 242{
210 if (mReadOnly) return; 243 if (mReadOnly) return;
211 mCreated = getEvenTime(created); 244 mCreated = getEvenTime(created);
212} 245}
213 246
214QDateTime Incidence::created() const 247QDateTime Incidence::created() const
215{ 248{
216 return mCreated; 249 return mCreated;
217} 250}
218 251
219void Incidence::setRevision(int rev) 252void Incidence::setRevision(int rev)
220{ 253{
221 if (mReadOnly) return; 254 if (mReadOnly) return;
222 mRevision = rev; 255 mRevision = rev;
223 256
224 updated(); 257 updated();
225} 258}
226 259
227int Incidence::revision() const 260int Incidence::revision() const
228{ 261{
229 return mRevision; 262 return mRevision;
230} 263}
231 264
232void Incidence::setDtStart(const QDateTime &dtStart) 265void Incidence::setDtStart(const QDateTime &dtStart)
233{ 266{
234 267
235 QDateTime dt = getEvenTime(dtStart); 268 QDateTime dt = getEvenTime(dtStart);
236 recurrence()->setRecurStart( dt); 269 recurrence()->setRecurStart( dt);
237 IncidenceBase::setDtStart( dt ); 270 IncidenceBase::setDtStart( dt );
238} 271}
239 272
240void Incidence::setDescription(const QString &description) 273void Incidence::setDescription(const QString &description)
241{ 274{
242 if (mReadOnly) return; 275 if (mReadOnly) return;
243 mDescription = description; 276 mDescription = description;
244 updated(); 277 updated();
245} 278}
246 279
247QString Incidence::description() const 280QString Incidence::description() const
248{ 281{
249 return mDescription; 282 return mDescription;
250} 283}
251 284
252 285
253void Incidence::setSummary(const QString &summary) 286void Incidence::setSummary(const QString &summary)
254{ 287{
255 if (mReadOnly) return; 288 if (mReadOnly) return;
256 mSummary = summary; 289 mSummary = summary;
257 updated(); 290 updated();
258} 291}
259 292
260QString Incidence::summary() const 293QString Incidence::summary() const
261{ 294{
262 return mSummary; 295 return mSummary;
263} 296}
264 297
265void Incidence::setCategories(const QStringList &categories) 298void Incidence::setCategories(const QStringList &categories)
266{ 299{
267 if (mReadOnly) return; 300 if (mReadOnly) return;
268 mCategories = categories; 301 mCategories = categories;
269 updated(); 302 updated();
270} 303}
271 304
272// TODO: remove setCategories(QString) function 305// TODO: remove setCategories(QString) function
273void Incidence::setCategories(const QString &catStr) 306void Incidence::setCategories(const QString &catStr)
274{ 307{
275 if (mReadOnly) return; 308 if (mReadOnly) return;
276 mCategories.clear(); 309 mCategories.clear();
277 310
278 if (catStr.isEmpty()) return; 311 if (catStr.isEmpty()) return;
279 312
280 mCategories = QStringList::split(",",catStr); 313 mCategories = QStringList::split(",",catStr);
281 314
282 QStringList::Iterator it; 315 QStringList::Iterator it;
283 for(it = mCategories.begin();it != mCategories.end(); ++it) { 316 for(it = mCategories.begin();it != mCategories.end(); ++it) {
284 *it = (*it).stripWhiteSpace(); 317 *it = (*it).stripWhiteSpace();
285 } 318 }
286 319
287 updated(); 320 updated();
288} 321}
289 322
290QStringList Incidence::categories() const 323QStringList Incidence::categories() const
291{ 324{
292 return mCategories; 325 return mCategories;
293} 326}
294 327
295QString Incidence::categoriesStr() 328QString Incidence::categoriesStr()
296{ 329{
297 return mCategories.join(","); 330 return mCategories.join(",");
298} 331}
299 332
300void Incidence::setRelatedToUid(const QString &relatedToUid) 333void Incidence::setRelatedToUid(const QString &relatedToUid)
301{ 334{
302 if (mReadOnly) return; 335 if (mReadOnly) return;
303 mRelatedToUid = relatedToUid; 336 mRelatedToUid = relatedToUid;
304} 337}
305 338
306QString Incidence::relatedToUid() const 339QString Incidence::relatedToUid() const
307{ 340{
308 return mRelatedToUid; 341 return mRelatedToUid;
309} 342}
310 343
311void Incidence::setRelatedTo(Incidence *relatedTo) 344void Incidence::setRelatedTo(Incidence *relatedTo)
312{ 345{
313 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 346 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
314 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 347 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
315 if (mReadOnly || mRelatedTo == relatedTo) return; 348 if (mReadOnly || mRelatedTo == relatedTo) return;
316 if(mRelatedTo) { 349 if(mRelatedTo) {
317 // updated(); 350 // updated();
318 mRelatedTo->removeRelation(this); 351 mRelatedTo->removeRelation(this);
319 } 352 }
320 mRelatedTo = relatedTo; 353 mRelatedTo = relatedTo;
321 if (mRelatedTo) mRelatedTo->addRelation(this); 354 if (mRelatedTo) mRelatedTo->addRelation(this);
322} 355}
323 356
324Incidence *Incidence::relatedTo() const 357Incidence *Incidence::relatedTo() const
325{ 358{
326 return mRelatedTo; 359 return mRelatedTo;
327} 360}
328 361
329QPtrList<Incidence> Incidence::relations() const 362QPtrList<Incidence> Incidence::relations() const
330{ 363{
331 return mRelations; 364 return mRelations;
332} 365}
333 366
334void Incidence::addRelation(Incidence *event) 367void Incidence::addRelation(Incidence *event)
335{ 368{
336 if( mRelations.findRef( event ) == -1 ) { 369 if( mRelations.findRef( event ) == -1 ) {
337 mRelations.append(event); 370 mRelations.append(event);
338 //updated(); 371 //updated();
339 } 372 }
340} 373}
341 374
342void Incidence::removeRelation(Incidence *event) 375void Incidence::removeRelation(Incidence *event)
343{ 376{
344 377
345 mRelations.removeRef(event); 378 mRelations.removeRef(event);
346 379
347// if (event->getRelatedTo() == this) event->setRelatedTo(0); 380// if (event->getRelatedTo() == this) event->setRelatedTo(0);
348} 381}
349 382
350bool Incidence::recursOn(const QDate &qd) const 383bool Incidence::recursOn(const QDate &qd) const
351{ 384{
352 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 385 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
353 else return false; 386 else return false;
354} 387}
355 388
356void Incidence::setExDates(const DateList &exDates) 389void Incidence::setExDates(const DateList &exDates)
357{ 390{
358 if (mReadOnly) return; 391 if (mReadOnly) return;
359 mExDates = exDates; 392 mExDates = exDates;
360 393
361 recurrence()->setRecurExDatesCount(mExDates.count()); 394 recurrence()->setRecurExDatesCount(mExDates.count());
362 395
363 updated(); 396 updated();
364} 397}
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index de2a381..38d2aaa 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -74,226 +74,235 @@ class Incidence : public IncidenceBase
74 virtual bool visit(Journal *) { return false; } 74 virtual bool visit(Journal *) { return false; }
75 75
76 protected: 76 protected:
77 /** Constructor is protected to prevent direct creation of visitor base class. */ 77 /** Constructor is protected to prevent direct creation of visitor base class. */
78 Visitor() {} 78 Visitor() {}
79 }; 79 };
80 80
81 /** 81 /**
82 This class implements a visitor for adding an Incidence to a resource 82 This class implements a visitor for adding an Incidence to a resource
83 supporting addEvent(), addTodo() and addJournal() calls. 83 supporting addEvent(), addTodo() and addJournal() calls.
84 */ 84 */
85 template<class T> 85 template<class T>
86 class AddVisitor : public Visitor 86 class AddVisitor : public Visitor
87 { 87 {
88 public: 88 public:
89 AddVisitor( T *r ) : mResource( r ) {} 89 AddVisitor( T *r ) : mResource( r ) {}
90 bool visit( Event *e ) { return mResource->addEvent( e ); } 90 bool visit( Event *e ) { return mResource->addEvent( e ); }
91 bool visit( Todo *t ) { return mResource->addTodo( t ); } 91 bool visit( Todo *t ) { return mResource->addTodo( t ); }
92 bool visit( Journal *j ) { return mResource->addJournal( j ); } 92 bool visit( Journal *j ) { return mResource->addJournal( j ); }
93 93
94 private: 94 private:
95 T *mResource; 95 T *mResource;
96 }; 96 };
97 97
98 /** enumeration for describing an event's secrecy. */ 98 /** enumeration for describing an event's secrecy. */
99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
100 typedef ListBase<Incidence> List; 100 typedef ListBase<Incidence> List;
101 Incidence(); 101 Incidence();
102 Incidence(const Incidence &); 102 Incidence(const Incidence &);
103 ~Incidence(); 103 ~Incidence();
104 104
105 /** 105 /**
106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to 106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
107 provide this implementation: 107 provide this implementation:
108 <pre> 108 <pre>
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 115
116 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; 116 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0;
117 void setReadOnly( bool ); 117 void setReadOnly( bool );
118 118
119 /** 119 /**
120 Recreate event. The event is made a new unique event, but already stored 120 Recreate event. The event is made a new unique event, but already stored
121 event information is preserved. Sets uniquie id, creation date, last 121 event information is preserved. Sets uniquie id, creation date, last
122 modification date and revision number. 122 modification date and revision number.
123 */ 123 */
124 void recreate(); 124 void recreate();
125 Incidence* recreateCloneException(QDate); 125 Incidence* recreateCloneException(QDate);
126 126
127 /** set creation date */ 127 /** set creation date */
128 void setCreated(QDateTime); 128 void setCreated(QDateTime);
129 /** return time and date of creation. */ 129 /** return time and date of creation. */
130 QDateTime created() const; 130 QDateTime created() const;
131 131
132 /** set the number of revisions this event has seen */ 132 /** set the number of revisions this event has seen */
133 void setRevision(int rev); 133 void setRevision(int rev);
134 /** return the number of revisions this event has seen */ 134 /** return the number of revisions this event has seen */
135 int revision() const; 135 int revision() const;
136 136
137 /** Set starting date/time. */ 137 /** Set starting date/time. */
138 virtual void setDtStart(const QDateTime &dtStart); 138 virtual void setDtStart(const QDateTime &dtStart);
139 /** Return the incidence's ending date/time as a QDateTime. */ 139 /** Return the incidence's ending date/time as a QDateTime. */
140 virtual QDateTime dtEnd() const { return QDateTime(); } 140 virtual QDateTime dtEnd() const { return QDateTime(); }
141 141
142 /** sets the event's lengthy description. */ 142 /** sets the event's lengthy description. */
143 void setDescription(const QString &description); 143 void setDescription(const QString &description);
144 /** returns a reference to the event's description. */ 144 /** returns a reference to the event's description. */
145 QString description() const; 145 QString description() const;
146 146
147 /** sets the event's short summary. */ 147 /** sets the event's short summary. */
148 void setSummary(const QString &summary); 148 void setSummary(const QString &summary);
149 /** returns a reference to the event's summary. */ 149 /** returns a reference to the event's summary. */
150 QString summary() const; 150 QString summary() const;
151 151
152 /** set event's applicable categories */ 152 /** set event's applicable categories */
153 void setCategories(const QStringList &categories); 153 void setCategories(const QStringList &categories);
154 /** set event's categories based on a comma delimited string */ 154 /** set event's categories based on a comma delimited string */
155 void setCategories(const QString &catStr); 155 void setCategories(const QString &catStr);
156 /** return categories in a list */ 156 /** return categories in a list */
157 QStringList categories() const; 157 QStringList categories() const;
158 /** return categories as a comma separated string */ 158 /** return categories as a comma separated string */
159 QString categoriesStr(); 159 QString categoriesStr();
160 160
161 /** point at some other event to which the event relates. This function should 161 /** point at some other event to which the event relates. This function should
162 * only be used when constructing a calendar before the related Event 162 * only be used when constructing a calendar before the related Event
163 * exists. */ 163 * exists. */
164 void setRelatedToUid(const QString &); 164 void setRelatedToUid(const QString &);
165 /** what event does this one relate to? This function should 165 /** what event does this one relate to? This function should
166 * only be used when constructing a calendar before the related Event 166 * only be used when constructing a calendar before the related Event
167 * exists. */ 167 * exists. */
168 QString relatedToUid() const; 168 QString relatedToUid() const;
169 /** point at some other event to which the event relates */ 169 /** point at some other event to which the event relates */
170 void setRelatedTo(Incidence *relatedTo); 170 void setRelatedTo(Incidence *relatedTo);
171 /** what event does this one relate to? */ 171 /** what event does this one relate to? */
172 Incidence *relatedTo() const; 172 Incidence *relatedTo() const;
173 /** All events that are related to this event */ 173 /** All events that are related to this event */
174 QPtrList<Incidence> relations() const; 174 QPtrList<Incidence> relations() const;
175 /** Add an event which is related to this event */ 175 /** Add an event which is related to this event */
176 void addRelation(Incidence *); 176 void addRelation(Incidence *);
177 /** Remove event that is related to this event */ 177 /** Remove event that is related to this event */
178 void removeRelation(Incidence *); 178 void removeRelation(Incidence *);
179 179
180 /** returns the list of dates which are exceptions to the recurrence rule */ 180 /** returns the list of dates which are exceptions to the recurrence rule */
181 DateList exDates() const; 181 DateList exDates() const;
182 /** sets the list of dates which are exceptions to the recurrence rule */ 182 /** sets the list of dates which are exceptions to the recurrence rule */
183 void setExDates(const DateList &_exDates); 183 void setExDates(const DateList &_exDates);
184 void setExDates(const char *dates); 184 void setExDates(const char *dates);
185 /** Add a date to the list of exceptions of the recurrence rule. */ 185 /** Add a date to the list of exceptions of the recurrence rule. */
186 void addExDate(const QDate &date); 186 void addExDate(const QDate &date);
187 187
188 /** returns true if there is an exception for this date in the recurrence 188 /** returns true if there is an exception for this date in the recurrence
189 rule set, or false otherwise. */ 189 rule set, or false otherwise. */
190 bool isException(const QDate &qd) const; 190 bool isException(const QDate &qd) const;
191 191
192 /** add attachment to this event */ 192 /** add attachment to this event */
193 void addAttachment(Attachment *attachment); 193 void addAttachment(Attachment *attachment);
194 /** remove and delete a specific attachment */ 194 /** remove and delete a specific attachment */
195 void deleteAttachment(Attachment *attachment); 195 void deleteAttachment(Attachment *attachment);
196 /** remove and delete all attachments with this mime type */ 196 /** remove and delete all attachments with this mime type */
197 void deleteAttachments(const QString& mime); 197 void deleteAttachments(const QString& mime);
198 /** return list of all associated attachments */ 198 /** return list of all associated attachments */
199 QPtrList<Attachment> attachments() const; 199 QPtrList<Attachment> attachments() const;
200 /** find a list of attachments with this mime type */ 200 /** find a list of attachments with this mime type */
201 QPtrList<Attachment> attachments(const QString& mime) const; 201 QPtrList<Attachment> attachments(const QString& mime) const;
202 202
203 /** sets the event's status the value specified. See the enumeration 203 /** sets the event's status the value specified. See the enumeration
204 * above for possible values. */ 204 * above for possible values. */
205 void setSecrecy(int); 205 void setSecrecy(int);
206 /** return the event's secrecy. */ 206 /** return the event's secrecy. */
207 int secrecy() const; 207 int secrecy() const;
208 /** return the event's secrecy in string format. */ 208 /** return the event's secrecy in string format. */
209 QString secrecyStr() const; 209 QString secrecyStr() const;
210 /** return list of all availbale secrecy classes */ 210 /** return list of all availbale secrecy classes */
211 static QStringList secrecyList(); 211 static QStringList secrecyList();
212 /** return human-readable name of secrecy class */ 212 /** return human-readable name of secrecy class */
213 static QString secrecyName(int); 213 static QString secrecyName(int);
214 214
215 /** returns TRUE if the date specified is one on which the event will 215 /** returns TRUE if the date specified is one on which the event will
216 * recur. */ 216 * recur. */
217 bool recursOn(const QDate &qd) const; 217 bool recursOn(const QDate &qd) const;
218 218
219 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 219 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
220 220
221 /** set resources used, such as Office, Car, etc. */ 221 /** set resources used, such as Office, Car, etc. */
222 void setResources(const QStringList &resources); 222 void setResources(const QStringList &resources);
223 /** return list of current resources */ 223 /** return list of current resources */
224 QStringList resources() const; 224 QStringList resources() const;
225 225
226 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 226 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
227 void setPriority(int priority); 227 void setPriority(int priority);
228 /** get the event's priority */ 228 /** get the event's priority */
229 int priority() const; 229 int priority() const;
230 230
231 /** All alarms that are associated with this incidence */ 231 /** All alarms that are associated with this incidence */
232 QPtrList<Alarm> alarms() const; 232 QPtrList<Alarm> alarms() const;
233 /** Create a new alarm which is associated with this incidence */ 233 /** Create a new alarm which is associated with this incidence */
234 Alarm* newAlarm(); 234 Alarm* newAlarm();
235 /** Add an alarm which is associated with this incidence */ 235 /** Add an alarm which is associated with this incidence */
236 void addAlarm(Alarm*); 236 void addAlarm(Alarm*);
237 /** Remove an alarm that is associated with this incidence */ 237 /** Remove an alarm that is associated with this incidence */
238 void removeAlarm(Alarm*); 238 void removeAlarm(Alarm*);
239 /** Remove all alarms that are associated with this incidence */ 239 /** Remove all alarms that are associated with this incidence */
240 void clearAlarms(); 240 void clearAlarms();
241 /** return whether any alarm associated with this incidence is enabled */ 241 /** return whether any alarm associated with this incidence is enabled */
242 bool isAlarmEnabled() const; 242 bool isAlarmEnabled() const;
243 243
244 /** 244 /**
245 Return the recurrence rule associated with this incidence. If there is 245 Return the recurrence rule associated with this incidence. If there is
246 none, returns an appropriate (non-0) object. 246 none, returns an appropriate (non-0) object.
247 */ 247 */
248 Recurrence *recurrence() const; 248 Recurrence *recurrence() const;
249 void setRecurrence(Recurrence * r); 249 void setRecurrence(Recurrence * r);
250 /** 250 /**
251 Forward to Recurrence::doesRecur(). 251 Forward to Recurrence::doesRecur().
252 */ 252 */
253 ushort doesRecur() const; 253 ushort doesRecur() const;
254 254
255 /** set the event's/todo's location. Do _not_ use it with journal */ 255 /** set the event's/todo's location. Do _not_ use it with journal */
256 void setLocation(const QString &location); 256 void setLocation(const QString &location);
257 /** return the event's/todo's location. Do _not_ use it with journal */ 257 /** return the event's/todo's location. Do _not_ use it with journal */
258 QString location() const; 258 QString location() const;
259 /** returns TRUE or FALSE depending on whether the todo has a start date */ 259 /** returns TRUE or FALSE depending on whether the todo has a start date */
260 bool hasStartDate() const; 260 bool hasStartDate() const;
261 /** sets the event's hasStartDate value. */ 261 /** sets the event's hasStartDate value. */
262 void setHasStartDate(bool f); 262 void setHasStartDate(bool f);
263 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 263 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
264 bool cancelled() const; 264 bool cancelled() const;
265 void setCancelled( bool b ); 265 void setCancelled( bool b );
266
267 bool hasRecurrenceID() const;
268 void setHasRecurrenceID( bool b );
269
270 void setRecurrenceID(QDateTime);
271 QDateTime recurrenceID () const;
272
266 273
267protected: 274protected:
268 QPtrList<Alarm> mAlarms; 275 QPtrList<Alarm> mAlarms;
269 QPtrList<Incidence> mRelations; 276 QPtrList<Incidence> mRelations;
270 private: 277 private:
271 int mRevision; 278 int mRevision;
272 bool mCancelled; 279 bool mCancelled;
273 280
274 // base components of jounal, event and todo 281 // base components of jounal, event and todo
282 QDateTime mRecurrenceID;
283 bool mHasRecurrenceID;
275 QDateTime mCreated; 284 QDateTime mCreated;
276 QString mDescription; 285 QString mDescription;
277 QString mSummary; 286 QString mSummary;
278 QStringList mCategories; 287 QStringList mCategories;
279 Incidence *mRelatedTo; 288 Incidence *mRelatedTo;
280 QString mRelatedToUid; 289 QString mRelatedToUid;
281 DateList mExDates; 290 DateList mExDates;
282 QPtrList<Attachment> mAttachments; 291 QPtrList<Attachment> mAttachments;
283 QStringList mResources; 292 QStringList mResources;
284 bool mHasStartDate; // if todo has associated start date 293 bool mHasStartDate; // if todo has associated start date
285 294
286 int mSecrecy; 295 int mSecrecy;
287 int mPriority; // 1 = highest, 2 = less, etc. 296 int mPriority; // 1 = highest, 2 = less, etc.
288 297
289 //QPtrList<Alarm> mAlarms; 298 //QPtrList<Alarm> mAlarms;
290 Recurrence *mRecurrence; 299 Recurrence *mRecurrence;
291 300
292 QString mLocation; 301 QString mLocation;
293}; 302};
294 303
295bool operator==( const Incidence&, const Incidence& ); 304bool operator==( const Incidence&, const Incidence& );
296 305
297} 306}
298 307
299#endif 308#endif