summaryrefslogtreecommitdiffabout
path: root/libkcal/icalformatimpl.cpp
Unidiff
Diffstat (limited to 'libkcal/icalformatimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp79
1 files changed, 38 insertions, 41 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index e5c27a0..32a1337 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -97,729 +97,729 @@ icalcomponent *ICalFormatImpl::writeTodo(Todo *todo)
97 icaltimetype due; 97 icaltimetype due;
98 if (todo->doesFloat()) { 98 if (todo->doesFloat()) {
99 due = writeICalDate(todo->dtDue().date()); 99 due = writeICalDate(todo->dtDue().date());
100 } else { 100 } else {
101 due = writeICalDateTime(todo->dtDue()); 101 due = writeICalDateTime(todo->dtDue());
102 } 102 }
103 icalcomponent_add_property(vtodo,icalproperty_new_due(due)); 103 icalcomponent_add_property(vtodo,icalproperty_new_due(due));
104 } 104 }
105 105
106 // start time 106 // start time
107 if (todo->hasStartDate()) { 107 if (todo->hasStartDate()) {
108 icaltimetype start; 108 icaltimetype start;
109 if (todo->doesFloat()) { 109 if (todo->doesFloat()) {
110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; 110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl;
111 start = writeICalDate(todo->dtStart().date()); 111 start = writeICalDate(todo->dtStart().date());
112 } else { 112 } else {
113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; 113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl;
114 start = writeICalDateTime(todo->dtStart()); 114 start = writeICalDateTime(todo->dtStart());
115 } 115 }
116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); 116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start));
117 } 117 }
118 118
119 // completion date 119 // completion date
120 if (todo->isCompleted()) { 120 if (todo->isCompleted()) {
121 if (!todo->hasCompletedDate()) { 121 if (!todo->hasCompletedDate()) {
122 // If todo was created by KOrganizer <2.2 it has no correct completion 122 // If todo was created by KOrganizer <2.2 it has no correct completion
123 // date. Set it to now. 123 // date. Set it to now.
124 todo->setCompleted(QDateTime::currentDateTime()); 124 todo->setCompleted(QDateTime::currentDateTime());
125 } 125 }
126 icaltimetype completed = writeICalDateTime(todo->completed()); 126 icaltimetype completed = writeICalDateTime(todo->completed());
127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); 127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed));
128 } 128 }
129 129
130 icalcomponent_add_property(vtodo, 130 icalcomponent_add_property(vtodo,
131 icalproperty_new_percentcomplete(todo->percentComplete())); 131 icalproperty_new_percentcomplete(todo->percentComplete()));
132 132
133 return vtodo; 133 return vtodo;
134} 134}
135 135
136icalcomponent *ICalFormatImpl::writeEvent(Event *event) 136icalcomponent *ICalFormatImpl::writeEvent(Event *event)
137{ 137{
138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() 138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid()
139 << ")" << endl; 139 << ")" << endl;
140 140
141 QString tmpStr; 141 QString tmpStr;
142 QStringList tmpStrList; 142 QStringList tmpStrList;
143 143
144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); 144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
145 145
146 writeIncidence(vevent,event); 146 writeIncidence(vevent,event);
147 147
148 // start time 148 // start time
149 icaltimetype start; 149 icaltimetype start;
150 if (event->doesFloat()) { 150 if (event->doesFloat()) {
151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
152 start = writeICalDate(event->dtStart().date()); 152 start = writeICalDate(event->dtStart().date());
153 } else { 153 } else {
154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
155 start = writeICalDateTime(event->dtStart()); 155 start = writeICalDateTime(event->dtStart());
156 } 156 }
157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); 157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start));
158 158
159 if (event->hasEndDate()) { 159 if (event->hasEndDate()) {
160 // end time 160 // end time
161 icaltimetype end; 161 icaltimetype end;
162 if (event->doesFloat()) { 162 if (event->doesFloat()) {
163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; 163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl;
164 // +1 day because end date is non-inclusive. 164 // +1 day because end date is non-inclusive.
165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); 165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) );
166 } else { 166 } else {
167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; 167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl;
168 end = writeICalDateTime(event->dtEnd()); 168 end = writeICalDateTime(event->dtEnd());
169 } 169 }
170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); 170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
171 } 171 }
172 172
173// TODO: attachments, resources 173// TODO: attachments, resources
174#if 0 174#if 0
175 // attachments 175 // attachments
176 tmpStrList = anEvent->attachments(); 176 tmpStrList = anEvent->attachments();
177 for ( QStringList::Iterator it = tmpStrList.begin(); 177 for ( QStringList::Iterator it = tmpStrList.begin();
178 it != tmpStrList.end(); 178 it != tmpStrList.end();
179 ++it ) 179 ++it )
180 addPropValue(vevent, VCAttachProp, (*it).utf8()); 180 addPropValue(vevent, VCAttachProp, (*it).utf8());
181 181
182 // resources 182 // resources
183 tmpStrList = anEvent->resources(); 183 tmpStrList = anEvent->resources();
184 tmpStr = tmpStrList.join(";"); 184 tmpStr = tmpStrList.join(";");
185 if (!tmpStr.isEmpty()) 185 if (!tmpStr.isEmpty())
186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); 186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
187 187
188#endif 188#endif
189 189
190 // Transparency 190 // Transparency
191 switch( event->transparency() ) { 191 switch( event->transparency() ) {
192 case Event::Transparent: 192 case Event::Transparent:
193 icalcomponent_add_property(vevent, icalproperty_new_transp("TRANSPARENT")); 193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT));
194 break; 194 break;
195 case Event::Opaque: 195 case Event::Opaque:
196 icalcomponent_add_property(vevent, icalproperty_new_transp("OPAQUE")); 196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE));
197 break; 197 break;
198 } 198 }
199 199
200 return vevent; 200 return vevent;
201} 201}
202 202
203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, 203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
204 Scheduler::Method method) 204 Scheduler::Method method)
205{ 205{
206#if QT_VERSION >= 300 206#if QT_VERSION >= 300
207 kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: " 207 kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: "
208 << freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: " 208 << freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: "
209 << freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl; 209 << freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl;
210#endif 210#endif
211 211
212 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 212 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
213 213
214 writeIncidenceBase(vfreebusy,freebusy); 214 writeIncidenceBase(vfreebusy,freebusy);
215 215
216 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 216 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
217 writeICalDateTime(freebusy->dtStart()))); 217 writeICalDateTime(freebusy->dtStart())));
218 218
219 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 219 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
220 writeICalDateTime(freebusy->dtEnd()))); 220 writeICalDateTime(freebusy->dtEnd())));
221 221
222 if (method == Scheduler::Request) { 222 if (method == Scheduler::Request) {
223 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 223 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
224 freebusy->uid().utf8())); 224 freebusy->uid().utf8()));
225 } 225 }
226 226
227 //Loops through all the periods in the freebusy object 227 //Loops through all the periods in the freebusy object
228 QValueList<Period> list = freebusy->busyPeriods(); 228 QValueList<Period> list = freebusy->busyPeriods();
229 QValueList<Period>::Iterator it; 229 QValueList<Period>::Iterator it;
230 icalperiodtype period; 230 icalperiodtype period;
231 for (it = list.begin(); it!= list.end(); ++it) { 231 for (it = list.begin(); it!= list.end(); ++it) {
232 period.start = writeICalDateTime((*it).start()); 232 period.start = writeICalDateTime((*it).start());
233 period.end = writeICalDateTime((*it).end()); 233 period.end = writeICalDateTime((*it).end());
234 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 234 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
235 } 235 }
236 236
237 return vfreebusy; 237 return vfreebusy;
238} 238}
239 239
240icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 240icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
241{ 241{
242 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 242 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
243 243
244 writeIncidence(vjournal,journal); 244 writeIncidence(vjournal,journal);
245 245
246 // start time 246 // start time
247 if (journal->dtStart().isValid()) { 247 if (journal->dtStart().isValid()) {
248 icaltimetype start; 248 icaltimetype start;
249 if (journal->doesFloat()) { 249 if (journal->doesFloat()) {
250// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 250// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
251 start = writeICalDate(journal->dtStart().date()); 251 start = writeICalDate(journal->dtStart().date());
252 } else { 252 } else {
253// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 253// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
254 start = writeICalDateTime(journal->dtStart()); 254 start = writeICalDateTime(journal->dtStart());
255 } 255 }
256 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 256 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
257 } 257 }
258 258
259 return vjournal; 259 return vjournal;
260} 260}
261 261
262void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 262void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
263{ 263{
264 // pilot sync stuff 264 // pilot sync stuff
265// TODO: move this application-specific code to kpilot 265// TODO: move this application-specific code to kpilot
266 if (incidence->pilotId()) { 266 if (incidence->pilotId()) {
267 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 267 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
268 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 268 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
269 } 269 }
270 if (incidence->zaurusId() >= 0) { 270 if (incidence->zaurusId() >= 0) {
271 incidence->setNonKDECustomProperty("X-ZAURUSID", QString::number(incidence->zaurusId())); 271 incidence->setNonKDECustomProperty("X-ZAURUSID", QString::number(incidence->zaurusId()));
272 } 272 }
273 273
274 if (incidence->zaurusUid() > 0) { 274 if (incidence->zaurusUid() > 0) {
275 incidence->setNonKDECustomProperty("X-ZAURUSUID", QString::number(incidence->zaurusUid())); 275 incidence->setNonKDECustomProperty("X-ZAURUSUID", QString::number(incidence->zaurusUid()));
276 } 276 }
277 if (incidence->zaurusStat() > 0) { 277 if (incidence->zaurusStat() > 0) {
278 incidence->setNonKDECustomProperty("X-ZAURUSSTAT", QString::number(incidence->zaurusStat())); 278 incidence->setNonKDECustomProperty("X-ZAURUSSTAT", QString::number(incidence->zaurusStat()));
279 } 279 }
280 280
281 writeIncidenceBase(parent,incidence); 281 writeIncidenceBase(parent,incidence);
282 if (incidence->cancelled()) { 282 if (incidence->cancelled()) {
283 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 283 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
284 } 284 }
285 285
286 // creation date 286 // creation date
287 icalcomponent_add_property(parent,icalproperty_new_created( 287 icalcomponent_add_property(parent,icalproperty_new_created(
288 writeICalDateTime(incidence->created()))); 288 writeICalDateTime(incidence->created())));
289 289
290 // unique id 290 // unique id
291 icalcomponent_add_property(parent,icalproperty_new_uid( 291 icalcomponent_add_property(parent,icalproperty_new_uid(
292 incidence->uid().utf8())); 292 incidence->uid().utf8()));
293 293
294 // revision 294 // revision
295 icalcomponent_add_property(parent,icalproperty_new_sequence( 295 icalcomponent_add_property(parent,icalproperty_new_sequence(
296 incidence->revision())); 296 incidence->revision()));
297 297
298 // last modification date 298 // last modification date
299 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 299 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
300 writeICalDateTime(incidence->lastModified()))); 300 writeICalDateTime(incidence->lastModified())));
301 301
302 // description 302 // description
303 if (!incidence->description().isEmpty()) { 303 if (!incidence->description().isEmpty()) {
304 icalcomponent_add_property(parent,icalproperty_new_description( 304 icalcomponent_add_property(parent,icalproperty_new_description(
305 incidence->description().utf8())); 305 incidence->description().utf8()));
306 } 306 }
307 307
308 // summary 308 // summary
309 if (!incidence->summary().isEmpty()) { 309 if (!incidence->summary().isEmpty()) {
310 icalcomponent_add_property(parent,icalproperty_new_summary( 310 icalcomponent_add_property(parent,icalproperty_new_summary(
311 incidence->summary().utf8())); 311 incidence->summary().utf8()));
312 } 312 }
313 313
314 // location 314 // location
315 if (!incidence->location().isEmpty()) { 315 if (!incidence->location().isEmpty()) {
316 icalcomponent_add_property(parent,icalproperty_new_location( 316 icalcomponent_add_property(parent,icalproperty_new_location(
317 incidence->location().utf8())); 317 incidence->location().utf8()));
318 } 318 }
319 319
320// TODO: 320// TODO:
321 // status 321 // status
322// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 322// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
323 323
324 // secrecy 324 // secrecy
325 const char *classStr; 325 enum icalproperty_class classInt;
326 switch (incidence->secrecy()) { 326 switch (incidence->secrecy()) {
327 case Incidence::SecrecyPublic: 327 case Incidence::SecrecyPublic:
328 classStr = "PUBLIC"; 328 classInt = ICAL_CLASS_PUBLIC;
329 break; 329 break;
330 case Incidence::SecrecyConfidential: 330 case Incidence::SecrecyConfidential:
331 classStr = "CONFIDENTIAL"; 331 classInt = ICAL_CLASS_CONFIDENTIAL;
332 break; 332 break;
333 case Incidence::SecrecyPrivate: 333 case Incidence::SecrecyPrivate:
334 classInt =ICAL_CLASS_PRIVATE ;
334 default: 335 default:
335 classStr = "PRIVATE"; 336 classInt =ICAL_CLASS_PRIVATE ;
336 break; 337 break;
337 } 338 }
338 icalcomponent_add_property(parent,icalproperty_new_class(classStr)); 339 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
339 340
340 // priority 341 // priority
341 icalcomponent_add_property(parent,icalproperty_new_priority( 342 icalcomponent_add_property(parent,icalproperty_new_priority(
342 incidence->priority())); 343 incidence->priority()));
343 344
344 // categories 345 // categories
345 QStringList categories = incidence->categories(); 346 QStringList categories = incidence->categories();
346 QStringList::Iterator it; 347 QStringList::Iterator it;
347 for(it = categories.begin(); it != categories.end(); ++it ) { 348 for(it = categories.begin(); it != categories.end(); ++it ) {
348 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 349 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
349 } 350 }
350// TODO: Ensure correct concatenation of categories properties. 351// TODO: Ensure correct concatenation of categories properties.
351 352
352/* 353/*
353 // categories 354 // categories
354 tmpStrList = incidence->getCategories(); 355 tmpStrList = incidence->getCategories();
355 tmpStr = ""; 356 tmpStr = "";
356 QString catStr; 357 QString catStr;
357 for ( QStringList::Iterator it = tmpStrList.begin(); 358 for ( QStringList::Iterator it = tmpStrList.begin();
358 it != tmpStrList.end(); 359 it != tmpStrList.end();
359 ++it ) { 360 ++it ) {
360 catStr = *it; 361 catStr = *it;
361 if (catStr[0] == ' ') 362 if (catStr[0] == ' ')
362 tmpStr += catStr.mid(1); 363 tmpStr += catStr.mid(1);
363 else 364 else
364 tmpStr += catStr; 365 tmpStr += catStr;
365 // this must be a ';' character as the vCalendar specification requires! 366 // this must be a ';' character as the vCalendar specification requires!
366 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 367 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
367 // read in. 368 // read in.
368 tmpStr += ";"; 369 tmpStr += ";";
369 } 370 }
370 if (!tmpStr.isEmpty()) { 371 if (!tmpStr.isEmpty()) {
371 tmpStr.truncate(tmpStr.length()-1); 372 tmpStr.truncate(tmpStr.length()-1);
372 icalcomponent_add_property(parent,icalproperty_new_categories( 373 icalcomponent_add_property(parent,icalproperty_new_categories(
373 writeText(incidence->getCategories().join(";")))); 374 writeText(incidence->getCategories().join(";"))));
374 } 375 }
375*/ 376*/
376 377
377 // related event 378 // related event
378 if (incidence->relatedTo()) { 379 if (incidence->relatedTo()) {
379 icalcomponent_add_property(parent,icalproperty_new_relatedto( 380 icalcomponent_add_property(parent,icalproperty_new_relatedto(
380 incidence->relatedTo()->uid().utf8())); 381 incidence->relatedTo()->uid().utf8()));
381 } 382 }
382 383
383 // recurrence rule stuff 384 // recurrence rule stuff
384 Recurrence *recur = incidence->recurrence(); 385 Recurrence *recur = incidence->recurrence();
385 if (recur->doesRecur()) { 386 if (recur->doesRecur()) {
386 387
387 icalcomponent_add_property(parent,writeRecurrenceRule(recur)); 388 icalcomponent_add_property(parent,writeRecurrenceRule(recur));
388 } 389 }
389 390
390 // recurrence excpetion dates 391 // recurrence excpetion dates
391 DateList dateList = incidence->exDates(); 392 DateList dateList = incidence->exDates();
392 DateList::ConstIterator exIt; 393 DateList::ConstIterator exIt;
393 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 394 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
394 icalcomponent_add_property(parent,icalproperty_new_exdate( 395 icalcomponent_add_property(parent,icalproperty_new_exdate(
395 writeICalDate(*exIt))); 396 writeICalDate(*exIt)));
396 } 397 }
397 398
398 // attachments 399 // attachments
399 QPtrList<Attachment> attachments = incidence->attachments(); 400 QPtrList<Attachment> attachments = incidence->attachments();
400 for (Attachment *at = attachments.first(); at; at = attachments.next()) 401 for (Attachment *at = attachments.first(); at; at = attachments.next())
401 icalcomponent_add_property(parent,writeAttachment(at)); 402 icalcomponent_add_property(parent,writeAttachment(at));
402 403
403 // alarms 404 // alarms
404 QPtrList<Alarm> alarms = incidence->alarms(); 405 QPtrList<Alarm> alarms = incidence->alarms();
405 Alarm* alarm; 406 Alarm* alarm;
406 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 407 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
407 if (alarm->enabled()) { 408 if (alarm->enabled()) {
408 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 409 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
409 icalcomponent_add_component(parent,writeAlarm(alarm)); 410 icalcomponent_add_component(parent,writeAlarm(alarm));
410 } 411 }
411 } 412 }
412 413
413 // duration 414 // duration
414 415
415// turned off as it always is set to PTS0 (and must not occur together with DTEND 416// turned off as it always is set to PTS0 (and must not occur together with DTEND
416 417
417// if (incidence->hasDuration()) { 418// if (incidence->hasDuration()) {
418// icaldurationtype duration; 419// icaldurationtype duration;
419// duration = writeICalDuration(incidence->duration()); 420// duration = writeICalDuration(incidence->duration());
420// icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 421// icalcomponent_add_property(parent,icalproperty_new_duration(duration));
421// } 422// }
422} 423}
423 424
424void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 425void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
425{ 426{
426 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 427 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
427 writeICalDateTime(QDateTime::currentDateTime()))); 428 writeICalDateTime(QDateTime::currentDateTime())));
428 429
429 // organizer stuff 430 // organizer stuff
430 icalcomponent_add_property(parent,icalproperty_new_organizer( 431 icalcomponent_add_property(parent,icalproperty_new_organizer(
431 ("MAILTO:" + incidenceBase->organizer()).utf8())); 432 ("MAILTO:" + incidenceBase->organizer()).utf8()));
432 433
433 // attendees 434 // attendees
434 if (incidenceBase->attendeeCount() != 0) { 435 if (incidenceBase->attendeeCount() != 0) {
435 QPtrList<Attendee> al = incidenceBase->attendees(); 436 QPtrList<Attendee> al = incidenceBase->attendees();
436 QPtrListIterator<Attendee> ai(al); 437 QPtrListIterator<Attendee> ai(al);
437 for (; ai.current(); ++ai) { 438 for (; ai.current(); ++ai) {
438 icalcomponent_add_property(parent,writeAttendee(ai.current())); 439 icalcomponent_add_property(parent,writeAttendee(ai.current()));
439 } 440 }
440 } 441 }
441 442
442 // custom properties 443 // custom properties
443 writeCustomProperties(parent, incidenceBase); 444 writeCustomProperties(parent, incidenceBase);
444} 445}
445 446
446void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 447void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
447{ 448{
448 QMap<QCString, QString> custom = properties->customProperties(); 449 QMap<QCString, QString> custom = properties->customProperties();
449 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 450 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
450 icalproperty *p = icalproperty_new_x(c.data().utf8()); 451 icalproperty *p = icalproperty_new_x(c.data().utf8());
451 icalproperty_set_x_name(p,c.key()); 452 icalproperty_set_x_name(p,c.key());
452 icalcomponent_add_property(parent,p); 453 icalcomponent_add_property(parent,p);
453 } 454 }
454} 455}
455 456
456icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 457icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
457{ 458{
458 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 459 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
459 460
460 if (!attendee->name().isEmpty()) { 461 if (!attendee->name().isEmpty()) {
461 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 462 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
462 } 463 }
463 464
464 465
465 icalproperty_add_parameter(p,icalparameter_new_rsvp( 466 icalproperty_add_parameter(p,icalparameter_new_rsvp(
466 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 467 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
467 468
468 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 469 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
469 switch (attendee->status()) { 470 switch (attendee->status()) {
470 default: 471 default:
471 case Attendee::NeedsAction: 472 case Attendee::NeedsAction:
472 status = ICAL_PARTSTAT_NEEDSACTION; 473 status = ICAL_PARTSTAT_NEEDSACTION;
473 break; 474 break;
474 case Attendee::Accepted: 475 case Attendee::Accepted:
475 status = ICAL_PARTSTAT_ACCEPTED; 476 status = ICAL_PARTSTAT_ACCEPTED;
476 break; 477 break;
477 case Attendee::Declined: 478 case Attendee::Declined:
478 status = ICAL_PARTSTAT_DECLINED; 479 status = ICAL_PARTSTAT_DECLINED;
479 break; 480 break;
480 case Attendee::Tentative: 481 case Attendee::Tentative:
481 status = ICAL_PARTSTAT_TENTATIVE; 482 status = ICAL_PARTSTAT_TENTATIVE;
482 break; 483 break;
483 case Attendee::Delegated: 484 case Attendee::Delegated:
484 status = ICAL_PARTSTAT_DELEGATED; 485 status = ICAL_PARTSTAT_DELEGATED;
485 break; 486 break;
486 case Attendee::Completed: 487 case Attendee::Completed:
487 status = ICAL_PARTSTAT_COMPLETED; 488 status = ICAL_PARTSTAT_COMPLETED;
488 break; 489 break;
489 case Attendee::InProcess: 490 case Attendee::InProcess:
490 status = ICAL_PARTSTAT_INPROCESS; 491 status = ICAL_PARTSTAT_INPROCESS;
491 break; 492 break;
492 } 493 }
493 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 494 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
494 495
495 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 496 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
496 switch (attendee->role()) { 497 switch (attendee->role()) {
497 case Attendee::Chair: 498 case Attendee::Chair:
498 role = ICAL_ROLE_CHAIR; 499 role = ICAL_ROLE_CHAIR;
499 break; 500 break;
500 default: 501 default:
501 case Attendee::ReqParticipant: 502 case Attendee::ReqParticipant:
502 role = ICAL_ROLE_REQPARTICIPANT; 503 role = ICAL_ROLE_REQPARTICIPANT;
503 break; 504 break;
504 case Attendee::OptParticipant: 505 case Attendee::OptParticipant:
505 role = ICAL_ROLE_OPTPARTICIPANT; 506 role = ICAL_ROLE_OPTPARTICIPANT;
506 break; 507 break;
507 case Attendee::NonParticipant: 508 case Attendee::NonParticipant:
508 role = ICAL_ROLE_NONPARTICIPANT; 509 role = ICAL_ROLE_NONPARTICIPANT;
509 break; 510 break;
510 } 511 }
511 icalproperty_add_parameter(p,icalparameter_new_role(role)); 512 icalproperty_add_parameter(p,icalparameter_new_role(role));
512 513
513 if (!attendee->uid().isEmpty()) { 514 if (!attendee->uid().isEmpty()) {
514 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 515 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
515 icalparameter_set_xname(icalparameter_uid,"X-UID"); 516 icalparameter_set_xname(icalparameter_uid,"X-UID");
516 icalproperty_add_parameter(p,icalparameter_uid); 517 icalproperty_add_parameter(p,icalparameter_uid);
517 } 518 }
518 519
519 return p; 520 return p;
520} 521}
521 522
522icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 523icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
523{ 524{
524 icalattachtype* attach = icalattachtype_new(); 525#if 0
526 icalattachtype* attach = icalattachtype_new();
525 if (att->isURI()) 527 if (att->isURI())
526 icalattachtype_set_url(attach, att->uri().utf8().data()); 528 icalattachtype_set_url(attach, att->uri().utf8().data());
527 else 529 else
528 icalattachtype_set_base64(attach, att->data(), 0); 530 icalattachtype_set_base64(attach, att->data(), 0);
529 531#endif
532 icalattach *attach;
533 if (att->isURI())
534 attach = icalattach_new_from_url( att->uri().utf8().data());
535 else
536 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0);
530 icalproperty *p = icalproperty_new_attach(attach); 537 icalproperty *p = icalproperty_new_attach(attach);
531
532 if (!att->mimeType().isEmpty()) 538 if (!att->mimeType().isEmpty())
533 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); 539 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data()));
534 540
535 if (att->isBinary()) { 541 if (att->isBinary()) {
536 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); 542 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
537 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); 543 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64));
538 } 544 }
539 return p; 545 return p;
540} 546}
541 547
542icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) 548icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur)
543{ 549{
544// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; 550// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl;
545 551
546 icalrecurrencetype r; 552 icalrecurrencetype r;
547 553
548 icalrecurrencetype_clear(&r); 554 icalrecurrencetype_clear(&r);
549 555
550 int index = 0; 556 int index = 0;
551 int index2 = 0; 557 int index2 = 0;
552 558
553 QPtrList<Recurrence::rMonthPos> tmpPositions; 559 QPtrList<Recurrence::rMonthPos> tmpPositions;
554 QPtrList<int> tmpDays; 560 QPtrList<int> tmpDays;
555 int *tmpDay; 561 int *tmpDay;
556 Recurrence::rMonthPos *tmpPos; 562 Recurrence::rMonthPos *tmpPos;
557 bool datetime = false; 563 bool datetime = false;
558 int day; 564 int day;
559 int i; 565 int i;
560 566
561 switch(recur->doesRecur()) { 567 switch(recur->doesRecur()) {
562 case Recurrence::rMinutely: 568 case Recurrence::rMinutely:
563 r.freq = ICAL_MINUTELY_RECURRENCE; 569 r.freq = ICAL_MINUTELY_RECURRENCE;
564 datetime = true; 570 datetime = true;
565 break; 571 break;
566 case Recurrence::rHourly: 572 case Recurrence::rHourly:
567 r.freq = ICAL_HOURLY_RECURRENCE; 573 r.freq = ICAL_HOURLY_RECURRENCE;
568 datetime = true; 574 datetime = true;
569 break; 575 break;
570 case Recurrence::rDaily: 576 case Recurrence::rDaily:
571 r.freq = ICAL_DAILY_RECURRENCE; 577 r.freq = ICAL_DAILY_RECURRENCE;
572 break; 578 break;
573 case Recurrence::rWeekly: 579 case Recurrence::rWeekly:
574 r.freq = ICAL_WEEKLY_RECURRENCE; 580 r.freq = ICAL_WEEKLY_RECURRENCE;
575 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); 581 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1);
576 for (i = 0; i < 7; i++) { 582 for (i = 0; i < 7; i++) {
577 if (recur->days().testBit(i)) { 583 if (recur->days().testBit(i)) {
578 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 584 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
579 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); 585 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day);
580 } 586 }
581 } 587 }
582// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 588// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
583 break; 589 break;
584 case Recurrence::rMonthlyPos: 590 case Recurrence::rMonthlyPos:
585 r.freq = ICAL_MONTHLY_RECURRENCE; 591 r.freq = ICAL_MONTHLY_RECURRENCE;
586 592
587 tmpPositions = recur->monthPositions(); 593 tmpPositions = recur->monthPositions();
588 for (tmpPos = tmpPositions.first(); 594 for (tmpPos = tmpPositions.first();
589 tmpPos; 595 tmpPos;
590 tmpPos = tmpPositions.next()) { 596 tmpPos = tmpPositions.next()) {
591 for (i = 0; i < 7; i++) { 597 for (i = 0; i < 7; i++) {
592 if (tmpPos->rDays.testBit(i)) { 598 if (tmpPos->rDays.testBit(i)) {
593 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 599 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
594 day += tmpPos->rPos*8; 600 day += tmpPos->rPos*8;
595 if (tmpPos->negative) day = -day; 601 if (tmpPos->negative) day = -day;
596 r.by_day[index++] = day; 602 r.by_day[index++] = day;
597 } 603 }
598 } 604 }
599 } 605 }
600// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 606// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
601 break; 607 break;
602 case Recurrence::rMonthlyDay: 608 case Recurrence::rMonthlyDay:
603 r.freq = ICAL_MONTHLY_RECURRENCE; 609 r.freq = ICAL_MONTHLY_RECURRENCE;
604 610
605 tmpDays = recur->monthDays(); 611 tmpDays = recur->monthDays();
606 for (tmpDay = tmpDays.first(); 612 for (tmpDay = tmpDays.first();
607 tmpDay; 613 tmpDay;
608 tmpDay = tmpDays.next()) { 614 tmpDay = tmpDays.next()) {
609 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); 615 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay);
610 } 616 }
611// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 617// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
612 break; 618 break;
613 case Recurrence::rYearlyMonth: 619 case Recurrence::rYearlyMonth:
614 case Recurrence::rYearlyPos: 620 case Recurrence::rYearlyPos:
615 r.freq = ICAL_YEARLY_RECURRENCE; 621 r.freq = ICAL_YEARLY_RECURRENCE;
616 622
617 tmpDays = recur->yearNums(); 623 tmpDays = recur->yearNums();
618 for (tmpDay = tmpDays.first(); 624 for (tmpDay = tmpDays.first();
619 tmpDay; 625 tmpDay;
620 tmpDay = tmpDays.next()) { 626 tmpDay = tmpDays.next()) {
621 r.by_month[index++] = *tmpDay; 627 r.by_month[index++] = *tmpDay;
622 } 628 }
623// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; 629// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX;
624 if (recur->doesRecur() == Recurrence::rYearlyPos) { 630 if (recur->doesRecur() == Recurrence::rYearlyPos) {
625 tmpPositions = recur->monthPositions(); 631 tmpPositions = recur->monthPositions();
626 for (tmpPos = tmpPositions.first(); 632 for (tmpPos = tmpPositions.first();
627 tmpPos; 633 tmpPos;
628 tmpPos = tmpPositions.next()) { 634 tmpPos = tmpPositions.next()) {
629 for (i = 0; i < 7; i++) { 635 for (i = 0; i < 7; i++) {
630 if (tmpPos->rDays.testBit(i)) { 636 if (tmpPos->rDays.testBit(i)) {
631 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 637 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
632 day += tmpPos->rPos*8; 638 day += tmpPos->rPos*8;
633 if (tmpPos->negative) day = -day; 639 if (tmpPos->negative) day = -day;
634 r.by_day[index2++] = day; 640 r.by_day[index2++] = day;
635 } 641 }
636 } 642 }
637 } 643 }
638// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; 644// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX;
639 } 645 }
640 break; 646 break;
641 case Recurrence::rYearlyDay: 647 case Recurrence::rYearlyDay:
642 r.freq = ICAL_YEARLY_RECURRENCE; 648 r.freq = ICAL_YEARLY_RECURRENCE;
643 649
644 tmpDays = recur->yearNums(); 650 tmpDays = recur->yearNums();
645 for (tmpDay = tmpDays.first(); 651 for (tmpDay = tmpDays.first();
646 tmpDay; 652 tmpDay;
647 tmpDay = tmpDays.next()) { 653 tmpDay = tmpDays.next()) {
648 r.by_year_day[index++] = *tmpDay; 654 r.by_year_day[index++] = *tmpDay;
649 } 655 }
650// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 656// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
651 break; 657 break;
652 default: 658 default:
653 r.freq = ICAL_NO_RECURRENCE; 659 r.freq = ICAL_NO_RECURRENCE;
654 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; 660 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
655 break; 661 break;
656 } 662 }
657 663
658 r.interval = recur->frequency(); 664 r.interval = recur->frequency();
659 665
660 if (recur->duration() > 0) { 666 if (recur->duration() > 0) {
661 r.count = recur->duration(); 667 r.count = recur->duration();
662 } else if (recur->duration() == -1) { 668 } else if (recur->duration() == -1) {
663 r.count = 0; 669 r.count = 0;
664 } else { 670 } else {
665 if (datetime) 671 if (datetime)
666 r.until = writeICalDateTime(recur->endDateTime()); 672 r.until = writeICalDateTime(recur->endDateTime());
667 else 673 else
668 r.until = writeICalDate(recur->endDate()); 674 r.until = writeICalDate(recur->endDate());
669 } 675 }
670 676
671// Debug output 677// Debug output
672#if 0 678#if 0
673 const char *str = icalrecurrencetype_as_string(&r); 679 const char *str = icalrecurrencetype_as_string(&r);
674 if (str) { 680 if (str) {
675 kdDebug(5800) << " String: " << str << endl; 681 kdDebug(5800) << " String: " << str << endl;
676 } else { 682 } else {
677 kdDebug(5800) << " No String" << endl; 683 kdDebug(5800) << " No String" << endl;
678 } 684 }
679#endif 685#endif
680 686
681 return icalproperty_new_rrule(r); 687 return icalproperty_new_rrule(r);
682} 688}
683 689
684icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) 690icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
685{ 691{
686 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); 692 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
687 693
688 icalproperty_action action; 694 icalproperty_action action;
689 icalattachtype *attach = 0; 695 icalattach *attach = 0;
690 696
691 switch (alarm->type()) { 697 switch (alarm->type()) {
692 case Alarm::Procedure: 698 case Alarm::Procedure:
693 action = ICAL_ACTION_PROCEDURE; 699 action = ICAL_ACTION_PROCEDURE;
694 attach = icalattachtype_new(); 700 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() );
695 icalattachtype_set_url(attach,QFile::encodeName(alarm->programFile()).data());
696 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 701 icalcomponent_add_property(a,icalproperty_new_attach(attach));
697 icalattachtype_free(attach);
698 if (!alarm->programArguments().isEmpty()) { 702 if (!alarm->programArguments().isEmpty()) {
699 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); 703 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8()));
700 } 704 }
701 break; 705 break;
702 case Alarm::Audio: 706 case Alarm::Audio:
703 action = ICAL_ACTION_AUDIO; 707 action = ICAL_ACTION_AUDIO;
704 if (!alarm->audioFile().isEmpty()) { 708 if (!alarm->audioFile().isEmpty()) {
705 attach = icalattachtype_new(); 709 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data());
706 icalattachtype_set_url(attach,QFile::encodeName( alarm->audioFile() ).data());
707 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 710 icalcomponent_add_property(a,icalproperty_new_attach(attach));
708 icalattachtype_free(attach);
709 } 711 }
710 break; 712 break;
711 case Alarm::Email: { 713 case Alarm::Email: {
712 action = ICAL_ACTION_EMAIL; 714 action = ICAL_ACTION_EMAIL;
713 QValueList<Person> addresses = alarm->mailAddresses(); 715 QValueList<Person> addresses = alarm->mailAddresses();
714 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { 716 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
715 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); 717 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8());
716 if (!(*ad).name().isEmpty()) { 718 if (!(*ad).name().isEmpty()) {
717 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); 719 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
718 } 720 }
719 icalcomponent_add_property(a,p); 721 icalcomponent_add_property(a,p);
720 } 722 }
721 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); 723 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
722 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 724 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
723 QStringList attachments = alarm->mailAttachments(); 725 QStringList attachments = alarm->mailAttachments();
724 if (attachments.count() > 0) { 726 if (attachments.count() > 0) {
725 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { 727 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
726 attach = icalattachtype_new(); 728 attach = icalattach_new_from_url(QFile::encodeName( *at ).data());
727 icalattachtype_set_url(attach,QFile::encodeName( *at ).data());
728 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 729 icalcomponent_add_property(a,icalproperty_new_attach(attach));
729 icalattachtype_free(attach);
730 } 730 }
731 } 731 }
732 break; 732 break;
733 } 733 }
734 case Alarm::Display: 734 case Alarm::Display:
735 action = ICAL_ACTION_DISPLAY; 735 action = ICAL_ACTION_DISPLAY;
736 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 736 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
737 break; 737 break;
738 case Alarm::Invalid: 738 case Alarm::Invalid:
739 default: 739 default:
740 kdDebug(5800) << "Unknown type of alarm" << endl; 740 kdDebug(5800) << "Unknown type of alarm" << endl;
741 action = ICAL_ACTION_NONE; 741 action = ICAL_ACTION_NONE;
742 break; 742 break;
743 } 743 }
744 icalcomponent_add_property(a,icalproperty_new_action(action)); 744 icalcomponent_add_property(a,icalproperty_new_action(action));
745 745
746 // Trigger time 746 // Trigger time
747 icaltriggertype trigger; 747 icaltriggertype trigger;
748 if ( alarm->hasTime() ) { 748 if ( alarm->hasTime() ) {
749 trigger.time = writeICalDateTime(alarm->time()); 749 trigger.time = writeICalDateTime(alarm->time());
750 trigger.duration = icaldurationtype_null_duration(); 750 trigger.duration = icaldurationtype_null_duration();
751 } else { 751 } else {
752 trigger.time = icaltime_null_time(); 752 trigger.time = icaltime_null_time();
753 Duration offset; 753 Duration offset;
754 if ( alarm->hasStartOffset() ) 754 if ( alarm->hasStartOffset() )
755 offset = alarm->startOffset(); 755 offset = alarm->startOffset();
756 else 756 else
757 offset = alarm->endOffset(); 757 offset = alarm->endOffset();
758 trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); 758 trigger.duration = icaldurationtype_from_int( offset.asSeconds() );
759 } 759 }
760 icalproperty *p = icalproperty_new_trigger(trigger); 760 icalproperty *p = icalproperty_new_trigger(trigger);
761 if ( alarm->hasEndOffset() ) 761 if ( alarm->hasEndOffset() )
762 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); 762 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
763 icalcomponent_add_property(a,p); 763 icalcomponent_add_property(a,p);
764 764
765 // Repeat count and duration 765 // Repeat count and duration
766 if (alarm->repeatCount()) { 766 if (alarm->repeatCount()) {
767 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); 767 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount()));
768 icalcomponent_add_property(a,icalproperty_new_duration( 768 icalcomponent_add_property(a,icalproperty_new_duration(
769 icaldurationtype_from_int(alarm->snoozeTime()*60))); 769 icaldurationtype_from_int(alarm->snoozeTime()*60)));
770 } 770 }
771 771
772 // Custom properties 772 // Custom properties
773 QMap<QCString, QString> custom = alarm->customProperties(); 773 QMap<QCString, QString> custom = alarm->customProperties();
774 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 774 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
775 icalproperty *p = icalproperty_new_x(c.data().utf8()); 775 icalproperty *p = icalproperty_new_x(c.data().utf8());
776 icalproperty_set_x_name(p,c.key()); 776 icalproperty_set_x_name(p,c.key());
777 icalcomponent_add_property(a,p); 777 icalcomponent_add_property(a,p);
778 } 778 }
779 779
780 return a; 780 return a;
781} 781}
782 782
783Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) 783Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
784{ 784{
785 Todo *todo = new Todo; 785 Todo *todo = new Todo;
786 786
787 readIncidence(vtodo,todo); 787 readIncidence(vtodo,todo);
788 788
789 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); 789 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
790 790
791// int intvalue; 791// int intvalue;
792 icaltimetype icaltime; 792 icaltimetype icaltime;
793 793
794 QStringList categories; 794 QStringList categories;
795 795
796 while (p) { 796 while (p) {
797 icalproperty_kind kind = icalproperty_isa(p); 797 icalproperty_kind kind = icalproperty_isa(p);
798 switch (kind) { 798 switch (kind) {
799 799
800 case ICAL_DUE_PROPERTY: // due date 800 case ICAL_DUE_PROPERTY: // due date
801 icaltime = icalproperty_get_due(p); 801 icaltime = icalproperty_get_due(p);
802 if (icaltime.is_date) { 802 if (icaltime.is_date) {
803 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 803 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
804 todo->setFloats(true); 804 todo->setFloats(true);
805 805
806 } else { 806 } else {
807 todo->setDtDue(readICalDateTime(icaltime)); 807 todo->setDtDue(readICalDateTime(icaltime));
808 todo->setFloats(false); 808 todo->setFloats(false);
809 } 809 }
810 todo->setHasDueDate(true); 810 todo->setHasDueDate(true);
811 break; 811 break;
812 812
813 case ICAL_COMPLETED_PROPERTY: // completion date 813 case ICAL_COMPLETED_PROPERTY: // completion date
814 icaltime = icalproperty_get_completed(p); 814 icaltime = icalproperty_get_completed(p);
815 todo->setCompleted(readICalDateTime(icaltime)); 815 todo->setCompleted(readICalDateTime(icaltime));
816 break; 816 break;
817 817
818 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed 818 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
819 todo->setPercentComplete(icalproperty_get_percentcomplete(p)); 819 todo->setPercentComplete(icalproperty_get_percentcomplete(p));
820 break; 820 break;
821 821
822 case ICAL_RELATEDTO_PROPERTY: // related todo (parent) 822 case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
823 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 823 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
824 mTodosRelate.append(todo); 824 mTodosRelate.append(todo);
825 break; 825 break;
@@ -845,610 +845,607 @@ Event *ICalFormatImpl::readEvent(icalcomponent *vevent)
845{ 845{
846 Event *event = new Event; 846 Event *event = new Event;
847 event->setFloats(false); 847 event->setFloats(false);
848 848
849 readIncidence(vevent,event); 849 readIncidence(vevent,event);
850 850
851 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); 851 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY);
852 852
853// int intvalue; 853// int intvalue;
854 icaltimetype icaltime; 854 icaltimetype icaltime;
855 855
856 QStringList categories; 856 QStringList categories;
857 QString transparency; 857 QString transparency;
858 858
859 while (p) { 859 while (p) {
860 icalproperty_kind kind = icalproperty_isa(p); 860 icalproperty_kind kind = icalproperty_isa(p);
861 switch (kind) { 861 switch (kind) {
862 862
863 case ICAL_DTEND_PROPERTY: // start date and time 863 case ICAL_DTEND_PROPERTY: // start date and time
864 icaltime = icalproperty_get_dtend(p); 864 icaltime = icalproperty_get_dtend(p);
865 if (icaltime.is_date) { 865 if (icaltime.is_date) {
866 event->setFloats( true ); 866 event->setFloats( true );
867 // End date is non-inclusive 867 // End date is non-inclusive
868 QDate endDate = readICalDate( icaltime ).addDays( -1 ); 868 QDate endDate = readICalDate( icaltime ).addDays( -1 );
869 mCompat->fixFloatingEnd( endDate ); 869 mCompat->fixFloatingEnd( endDate );
870 if ( endDate < event->dtStart().date() ) { 870 if ( endDate < event->dtStart().date() ) {
871 endDate = event->dtStart().date(); 871 endDate = event->dtStart().date();
872 } 872 }
873 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); 873 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) );
874 } else { 874 } else {
875 event->setDtEnd(readICalDateTime(icaltime)); 875 event->setDtEnd(readICalDateTime(icaltime));
876 } 876 }
877 break; 877 break;
878 878
879// TODO: 879// TODO:
880 // at this point, there should be at least a start or end time. 880 // at this point, there should be at least a start or end time.
881 // fix up for events that take up no time but have a time associated 881 // fix up for events that take up no time but have a time associated
882#if 0 882#if 0
883 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 883 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
884 anEvent->setDtStart(anEvent->dtEnd()); 884 anEvent->setDtStart(anEvent->dtEnd());
885 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 885 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
886 anEvent->setDtEnd(anEvent->dtStart()); 886 anEvent->setDtEnd(anEvent->dtStart());
887#endif 887#endif
888 888
889// TODO: exdates 889// TODO: exdates
890#if 0 890#if 0
891 // recurrence exceptions 891 // recurrence exceptions
892 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { 892 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) {
893 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); 893 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo)));
894 deleteStr(s); 894 deleteStr(s);
895 } 895 }
896#endif 896#endif
897 897
898#if 0 898#if 0
899 // secrecy 899 // secrecy
900 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 900 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
901 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); 901 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo)));
902 deleteStr(s); 902 deleteStr(s);
903 } 903 }
904 else 904 else
905 anEvent->setSecrecy("PUBLIC"); 905 anEvent->setSecrecy("PUBLIC");
906 906
907 // attachments 907 // attachments
908 tmpStrList.clear(); 908 tmpStrList.clear();
909 initPropIterator(&voi, vevent); 909 initPropIterator(&voi, vevent);
910 while (moreIteration(&voi)) { 910 while (moreIteration(&voi)) {
911 vo = nextVObject(&voi); 911 vo = nextVObject(&voi);
912 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 912 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
913 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); 913 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo)));
914 deleteStr(s); 914 deleteStr(s);
915 } 915 }
916 } 916 }
917 anEvent->setAttachments(tmpStrList); 917 anEvent->setAttachments(tmpStrList);
918 918
919 // resources 919 // resources
920 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 920 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
921 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 921 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
922 deleteStr(s); 922 deleteStr(s);
923 tmpStrList.clear(); 923 tmpStrList.clear();
924 index1 = 0; 924 index1 = 0;
925 index2 = 0; 925 index2 = 0;
926 QString resource; 926 QString resource;
927 while ((index2 = resources.find(';', index1)) != -1) { 927 while ((index2 = resources.find(';', index1)) != -1) {
928 resource = resources.mid(index1, (index2 - index1)); 928 resource = resources.mid(index1, (index2 - index1));
929 tmpStrList.append(resource); 929 tmpStrList.append(resource);
930 index1 = index2; 930 index1 = index2;
931 } 931 }
932 anEvent->setResources(tmpStrList); 932 anEvent->setResources(tmpStrList);
933 } 933 }
934#endif 934#endif
935 935
936 case ICAL_RELATEDTO_PROPERTY: // releated event (parent) 936 case ICAL_RELATEDTO_PROPERTY: // releated event (parent)
937 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 937 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
938 mEventsRelate.append(event); 938 mEventsRelate.append(event);
939 break; 939 break;
940 940
941
942 case ICAL_TRANSP_PROPERTY: // Transparency 941 case ICAL_TRANSP_PROPERTY: // Transparency
943 transparency = QString::fromUtf8(icalproperty_get_transp(p)); 942 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT )
944 if( transparency == "TRANSPARENT" )
945 event->setTransparency( Event::Transparent ); 943 event->setTransparency( Event::Transparent );
946 else 944 else
947 event->setTransparency( Event::Opaque ); 945 event->setTransparency( Event::Opaque );
948 break; 946 break;
949 947
950 default: 948 default:
951// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind 949// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind
952// << endl; 950// << endl;
953 break; 951 break;
954 } 952 }
955 953
956 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); 954 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY);
957 } 955 }
958 956
959 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); 957 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT");
960 if (!msade.isNull()) { 958 if (!msade.isNull()) {
961 bool floats = (msade == QString::fromLatin1("TRUE")); 959 bool floats = (msade == QString::fromLatin1("TRUE"));
962 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; 960 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl;
963 event->setFloats(floats); 961 event->setFloats(floats);
964 if (floats) { 962 if (floats) {
965 QDateTime endDate = event->dtEnd(); 963 QDateTime endDate = event->dtEnd();
966 event->setDtEnd(endDate.addDays(-1)); 964 event->setDtEnd(endDate.addDays(-1));
967 } 965 }
968 } 966 }
969 967
970 // some stupid vCal exporters ignore the standard and use Description 968 // some stupid vCal exporters ignore the standard and use Description
971 // instead of Summary for the default field. Correct for this. 969 // instead of Summary for the default field. Correct for this.
972 if (event->summary().isEmpty() && 970 if (event->summary().isEmpty() &&
973 !(event->description().isEmpty())) { 971 !(event->description().isEmpty())) {
974 QString tmpStr = event->description().simplifyWhiteSpace(); 972 QString tmpStr = event->description().simplifyWhiteSpace();
975 event->setDescription(""); 973 event->setDescription("");
976 event->setSummary(tmpStr); 974 event->setSummary(tmpStr);
977 } 975 }
978 976
979 return event; 977 return event;
980} 978}
981 979
982FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) 980FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
983{ 981{
984 FreeBusy *freebusy = new FreeBusy; 982 FreeBusy *freebusy = new FreeBusy;
985 983
986 readIncidenceBase(vfreebusy,freebusy); 984 readIncidenceBase(vfreebusy,freebusy);
987 985
988 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); 986 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
989 987
990 icaltimetype icaltime; 988 icaltimetype icaltime;
991 icalperiodtype icalperiod; 989 icalperiodtype icalperiod;
992 QDateTime period_start, period_end; 990 QDateTime period_start, period_end;
993 991
994 while (p) { 992 while (p) {
995 icalproperty_kind kind = icalproperty_isa(p); 993 icalproperty_kind kind = icalproperty_isa(p);
996 switch (kind) { 994 switch (kind) {
997 995
998 case ICAL_DTSTART_PROPERTY: // start date and time 996 case ICAL_DTSTART_PROPERTY: // start date and time
999 icaltime = icalproperty_get_dtstart(p); 997 icaltime = icalproperty_get_dtstart(p);
1000 freebusy->setDtStart(readICalDateTime(icaltime)); 998 freebusy->setDtStart(readICalDateTime(icaltime));
1001 break; 999 break;
1002 1000
1003 case ICAL_DTEND_PROPERTY: // start End Date and Time 1001 case ICAL_DTEND_PROPERTY: // start End Date and Time
1004 icaltime = icalproperty_get_dtend(p); 1002 icaltime = icalproperty_get_dtend(p);
1005 freebusy->setDtEnd(readICalDateTime(icaltime)); 1003 freebusy->setDtEnd(readICalDateTime(icaltime));
1006 break; 1004 break;
1007 1005
1008 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times 1006 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times
1009 icalperiod = icalproperty_get_freebusy(p); 1007 icalperiod = icalproperty_get_freebusy(p);
1010 period_start = readICalDateTime(icalperiod.start); 1008 period_start = readICalDateTime(icalperiod.start);
1011 period_end = readICalDateTime(icalperiod.end); 1009 period_end = readICalDateTime(icalperiod.end);
1012 freebusy->addPeriod(period_start, period_end); 1010 freebusy->addPeriod(period_start, period_end);
1013 break; 1011 break;
1014 1012
1015 default: 1013 default:
1016 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1014 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1017 << endl; 1015 << endl;
1018 break; 1016 break;
1019 } 1017 }
1020 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); 1018 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1021 } 1019 }
1022 1020
1023 return freebusy; 1021 return freebusy;
1024} 1022}
1025 1023
1026Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) 1024Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1027{ 1025{
1028 Journal *journal = new Journal; 1026 Journal *journal = new Journal;
1029 1027
1030 readIncidence(vjournal,journal); 1028 readIncidence(vjournal,journal);
1031 1029
1032 return journal; 1030 return journal;
1033} 1031}
1034 1032
1035Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1033Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1036{ 1034{
1037 icalparameter *p = 0; 1035 icalparameter *p = 0;
1038 1036
1039 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1037 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1040 1038
1041 QString name; 1039 QString name;
1042 QString uid = QString::null; 1040 QString uid = QString::null;
1043 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1041 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1044 if (p) { 1042 if (p) {
1045 name = QString::fromUtf8(icalparameter_get_cn(p)); 1043 name = QString::fromUtf8(icalparameter_get_cn(p));
1046 } else { 1044 } else {
1047 } 1045 }
1048 1046
1049 bool rsvp=false; 1047 bool rsvp=false;
1050 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1048 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1051 if (p) { 1049 if (p) {
1052 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1050 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1053 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1051 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1054 } 1052 }
1055 1053
1056 Attendee::PartStat status = Attendee::NeedsAction; 1054 Attendee::PartStat status = Attendee::NeedsAction;
1057 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1055 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1058 if (p) { 1056 if (p) {
1059 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1057 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1060 switch(partStatParameter) { 1058 switch(partStatParameter) {
1061 default: 1059 default:
1062 case ICAL_PARTSTAT_NEEDSACTION: 1060 case ICAL_PARTSTAT_NEEDSACTION:
1063 status = Attendee::NeedsAction; 1061 status = Attendee::NeedsAction;
1064 break; 1062 break;
1065 case ICAL_PARTSTAT_ACCEPTED: 1063 case ICAL_PARTSTAT_ACCEPTED:
1066 status = Attendee::Accepted; 1064 status = Attendee::Accepted;
1067 break; 1065 break;
1068 case ICAL_PARTSTAT_DECLINED: 1066 case ICAL_PARTSTAT_DECLINED:
1069 status = Attendee::Declined; 1067 status = Attendee::Declined;
1070 break; 1068 break;
1071 case ICAL_PARTSTAT_TENTATIVE: 1069 case ICAL_PARTSTAT_TENTATIVE:
1072 status = Attendee::Tentative; 1070 status = Attendee::Tentative;
1073 break; 1071 break;
1074 case ICAL_PARTSTAT_DELEGATED: 1072 case ICAL_PARTSTAT_DELEGATED:
1075 status = Attendee::Delegated; 1073 status = Attendee::Delegated;
1076 break; 1074 break;
1077 case ICAL_PARTSTAT_COMPLETED: 1075 case ICAL_PARTSTAT_COMPLETED:
1078 status = Attendee::Completed; 1076 status = Attendee::Completed;
1079 break; 1077 break;
1080 case ICAL_PARTSTAT_INPROCESS: 1078 case ICAL_PARTSTAT_INPROCESS:
1081 status = Attendee::InProcess; 1079 status = Attendee::InProcess;
1082 break; 1080 break;
1083 } 1081 }
1084 } 1082 }
1085 1083
1086 Attendee::Role role = Attendee::ReqParticipant; 1084 Attendee::Role role = Attendee::ReqParticipant;
1087 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1085 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1088 if (p) { 1086 if (p) {
1089 icalparameter_role roleParameter = icalparameter_get_role(p); 1087 icalparameter_role roleParameter = icalparameter_get_role(p);
1090 switch(roleParameter) { 1088 switch(roleParameter) {
1091 case ICAL_ROLE_CHAIR: 1089 case ICAL_ROLE_CHAIR:
1092 role = Attendee::Chair; 1090 role = Attendee::Chair;
1093 break; 1091 break;
1094 default: 1092 default:
1095 case ICAL_ROLE_REQPARTICIPANT: 1093 case ICAL_ROLE_REQPARTICIPANT:
1096 role = Attendee::ReqParticipant; 1094 role = Attendee::ReqParticipant;
1097 break; 1095 break;
1098 case ICAL_ROLE_OPTPARTICIPANT: 1096 case ICAL_ROLE_OPTPARTICIPANT:
1099 role = Attendee::OptParticipant; 1097 role = Attendee::OptParticipant;
1100 break; 1098 break;
1101 case ICAL_ROLE_NONPARTICIPANT: 1099 case ICAL_ROLE_NONPARTICIPANT:
1102 role = Attendee::NonParticipant; 1100 role = Attendee::NonParticipant;
1103 break; 1101 break;
1104 } 1102 }
1105 } 1103 }
1106 1104
1107 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1105 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1108 uid = icalparameter_get_xvalue(p); 1106 uid = icalparameter_get_xvalue(p);
1109 // This should be added, but there seems to be a libical bug here. 1107 // This should be added, but there seems to be a libical bug here.
1110 /*while (p) { 1108 /*while (p) {
1111 // if (icalparameter_get_xname(p) == "X-UID") { 1109 // if (icalparameter_get_xname(p) == "X-UID") {
1112 uid = icalparameter_get_xvalue(p); 1110 uid = icalparameter_get_xvalue(p);
1113 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1111 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1114 } */ 1112 } */
1115 1113
1116 return new Attendee( name, email, rsvp, status, role, uid ); 1114 return new Attendee( name, email, rsvp, status, role, uid );
1117} 1115}
1118 1116
1119Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1117Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1120{ 1118{
1121 icalattachtype *a = icalproperty_get_attach(attach); 1119 icalattach *a = icalproperty_get_attach(attach);
1122 icalparameter_value v = ICAL_VALUE_NONE; 1120 icalparameter_value v = ICAL_VALUE_NONE;
1123 icalparameter_encoding e = ICAL_ENCODING_NONE; 1121 icalparameter_encoding e = ICAL_ENCODING_NONE;
1124 1122
1125 Attachment *attachment = 0; 1123 Attachment *attachment = 0;
1126 1124 /*
1127 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1125 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1128 if (vp) 1126 if (vp)
1129 v = icalparameter_get_value(vp); 1127 v = icalparameter_get_value(vp);
1130 1128
1131 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1129 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1132 if (ep) 1130 if (ep)
1133 e = icalparameter_get_encoding(ep); 1131 e = icalparameter_get_encoding(ep);
1134 1132 */
1135 if (v == ICAL_VALUE_BINARY && e == ICAL_ENCODING_BASE64) 1133 int isurl = icalattach_get_is_url (a);
1136 attachment = new Attachment(icalattachtype_get_base64(a)); 1134 if (isurl == 0)
1137 else if ((v == ICAL_VALUE_NONE || v == ICAL_VALUE_URI) && (e == ICAL_ENCODING_NONE || e == ICAL_ENCODING_8BIT)) { 1135 attachment = new Attachment((const char*)icalattach_get_data(a));
1138 attachment = new Attachment(QString(icalattachtype_get_url(a))); 1136 else {
1139 } else { 1137 attachment = new Attachment(QString(icalattach_get_url(a)));
1140 kdWarning(5800) << "Unsupported attachment format, discarding it!" << endl;
1141 return 0;
1142 } 1138 }
1143 1139
1144 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1140 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1145 if (p) 1141 if (p)
1146 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1142 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1147 1143
1148 return attachment; 1144 return attachment;
1149} 1145}
1150#include <qtextcodec.h> 1146#include <qtextcodec.h>
1151void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1147void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1152{ 1148{
1153 readIncidenceBase(parent,incidence); 1149 readIncidenceBase(parent,incidence);
1154 1150
1155 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1151 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1156 bool readrec = false; 1152 bool readrec = false;
1157 const char *text; 1153 const char *text;
1158 int intvalue; 1154 int intvalue;
1159 icaltimetype icaltime; 1155 icaltimetype icaltime;
1160 icaldurationtype icalduration; 1156 icaldurationtype icalduration;
1161 struct icalrecurrencetype rectype; 1157 struct icalrecurrencetype rectype;
1162 QStringList categories; 1158 QStringList categories;
1163 1159
1164 while (p) { 1160 while (p) {
1165 icalproperty_kind kind = icalproperty_isa(p); 1161 icalproperty_kind kind = icalproperty_isa(p);
1166 switch (kind) { 1162 switch (kind) {
1167 1163
1168 case ICAL_CREATED_PROPERTY: 1164 case ICAL_CREATED_PROPERTY:
1169 icaltime = icalproperty_get_created(p); 1165 icaltime = icalproperty_get_created(p);
1170 incidence->setCreated(readICalDateTime(icaltime)); 1166 incidence->setCreated(readICalDateTime(icaltime));
1171 break; 1167 break;
1172 1168
1173 case ICAL_SEQUENCE_PROPERTY: // sequence 1169 case ICAL_SEQUENCE_PROPERTY: // sequence
1174 intvalue = icalproperty_get_sequence(p); 1170 intvalue = icalproperty_get_sequence(p);
1175 incidence->setRevision(intvalue); 1171 incidence->setRevision(intvalue);
1176 break; 1172 break;
1177 1173
1178 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1174 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1179 icaltime = icalproperty_get_lastmodified(p); 1175 icaltime = icalproperty_get_lastmodified(p);
1180 incidence->setLastModified(readICalDateTime(icaltime)); 1176 incidence->setLastModified(readICalDateTime(icaltime));
1181 break; 1177 break;
1182 1178
1183 case ICAL_DTSTART_PROPERTY: // start date and time 1179 case ICAL_DTSTART_PROPERTY: // start date and time
1184 icaltime = icalproperty_get_dtstart(p); 1180 icaltime = icalproperty_get_dtstart(p);
1185 if (icaltime.is_date) { 1181 if (icaltime.is_date) {
1186 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1182 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1187 incidence->setFloats(true); 1183 incidence->setFloats(true);
1188 } else { 1184 } else {
1189 incidence->setDtStart(readICalDateTime(icaltime)); 1185 incidence->setDtStart(readICalDateTime(icaltime));
1190 } 1186 }
1191 break; 1187 break;
1192 1188
1193 case ICAL_DURATION_PROPERTY: // start date and time 1189 case ICAL_DURATION_PROPERTY: // start date and time
1194 icalduration = icalproperty_get_duration(p); 1190 icalduration = icalproperty_get_duration(p);
1195 incidence->setDuration(readICalDuration(icalduration)); 1191 incidence->setDuration(readICalDuration(icalduration));
1196 break; 1192 break;
1197 1193
1198 case ICAL_DESCRIPTION_PROPERTY: // description 1194 case ICAL_DESCRIPTION_PROPERTY: // description
1199 text = icalproperty_get_description(p); 1195 text = icalproperty_get_description(p);
1200 incidence->setDescription(QString::fromUtf8(text)); 1196 incidence->setDescription(QString::fromUtf8(text));
1201 break; 1197 break;
1202 1198
1203 case ICAL_SUMMARY_PROPERTY: // summary 1199 case ICAL_SUMMARY_PROPERTY: // summary
1204 { 1200 {
1205 text = icalproperty_get_summary(p); 1201 text = icalproperty_get_summary(p);
1206 incidence->setSummary(QString::fromUtf8(text)); 1202 incidence->setSummary(QString::fromUtf8(text));
1207 } 1203 }
1208 break; 1204 break;
1209 case ICAL_STATUS_PROPERTY: // summary 1205 case ICAL_STATUS_PROPERTY: // summary
1210 { 1206 {
1211 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1207 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1212 incidence->setCancelled( true ); 1208 incidence->setCancelled( true );
1213 } 1209 }
1214 break; 1210 break;
1215 1211
1216 case ICAL_LOCATION_PROPERTY: // location 1212 case ICAL_LOCATION_PROPERTY: // location
1217 text = icalproperty_get_location(p); 1213 text = icalproperty_get_location(p);
1218 incidence->setLocation(QString::fromUtf8(text)); 1214 incidence->setLocation(QString::fromUtf8(text));
1219 break; 1215 break;
1220 1216
1221#if 0 1217#if 0
1222 // status 1218 // status
1223 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1219 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1224 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1220 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1225 deleteStr(s); 1221 deleteStr(s);
1226 } 1222 }
1227 else 1223 else
1228 incidence->setStatus("NEEDS ACTION"); 1224 incidence->setStatus("NEEDS ACTION");
1229#endif 1225#endif
1230 1226
1231 case ICAL_PRIORITY_PROPERTY: // priority 1227 case ICAL_PRIORITY_PROPERTY: // priority
1232 intvalue = icalproperty_get_priority(p); 1228 intvalue = icalproperty_get_priority(p);
1233 incidence->setPriority(intvalue); 1229 incidence->setPriority(intvalue);
1234 break; 1230 break;
1235 1231
1236 case ICAL_CATEGORIES_PROPERTY: // categories 1232 case ICAL_CATEGORIES_PROPERTY: // categories
1237 text = icalproperty_get_categories(p); 1233 text = icalproperty_get_categories(p);
1238 categories.append(QString::fromUtf8(text)); 1234 categories.append(QString::fromUtf8(text));
1239 break; 1235 break;
1240 //******************************************* 1236 //*******************************************
1241 case ICAL_RRULE_PROPERTY: 1237 case ICAL_RRULE_PROPERTY:
1242 // we do need (maybe )start datetime of incidence for recurrence 1238 // we do need (maybe )start datetime of incidence for recurrence
1243 // such that we can read recurrence only after we read incidence completely 1239 // such that we can read recurrence only after we read incidence completely
1244 readrec = true; 1240 readrec = true;
1245 rectype = icalproperty_get_rrule(p); 1241 rectype = icalproperty_get_rrule(p);
1246 break; 1242 break;
1247 1243
1248 case ICAL_EXDATE_PROPERTY: 1244 case ICAL_EXDATE_PROPERTY:
1249 icaltime = icalproperty_get_exdate(p); 1245 icaltime = icalproperty_get_exdate(p);
1250 incidence->addExDate(readICalDate(icaltime)); 1246 incidence->addExDate(readICalDate(icaltime));
1251 break; 1247 break;
1252 1248
1253 case ICAL_CLASS_PROPERTY: 1249 case ICAL_CLASS_PROPERTY: {
1254 text = icalproperty_get_class(p); 1250 int inttext = icalproperty_get_class(p);
1255 if (strcmp(text,"PUBLIC") == 0) { 1251 if (inttext == ICAL_CLASS_PUBLIC ) {
1256 incidence->setSecrecy(Incidence::SecrecyPublic); 1252 incidence->setSecrecy(Incidence::SecrecyPublic);
1257 } else if (strcmp(text,"CONFIDENTIAL") == 0) { 1253 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1258 incidence->setSecrecy(Incidence::SecrecyConfidential); 1254 incidence->setSecrecy(Incidence::SecrecyConfidential);
1259 } else { 1255 } else {
1260 incidence->setSecrecy(Incidence::SecrecyPrivate); 1256 incidence->setSecrecy(Incidence::SecrecyPrivate);
1261 } 1257 }
1258 }
1262 break; 1259 break;
1263 1260
1264 case ICAL_ATTACH_PROPERTY: // attachments 1261 case ICAL_ATTACH_PROPERTY: // attachments
1265 incidence->addAttachment(readAttachment(p)); 1262 incidence->addAttachment(readAttachment(p));
1266 break; 1263 break;
1267 1264
1268 default: 1265 default:
1269// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1266// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1270// << endl; 1267// << endl;
1271 break; 1268 break;
1272 } 1269 }
1273 1270
1274 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1271 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1275 } 1272 }
1276 if ( readrec ) { 1273 if ( readrec ) {
1277 readRecurrenceRule(rectype,incidence); 1274 readRecurrenceRule(rectype,incidence);
1278 } 1275 }
1279 // kpilot stuff 1276 // kpilot stuff
1280// TODO: move this application-specific code to kpilot 1277// TODO: move this application-specific code to kpilot
1281 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1278 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1282 if (!kp.isNull()) { 1279 if (!kp.isNull()) {
1283 incidence->setPilotId(kp.toInt()); 1280 incidence->setPilotId(kp.toInt());
1284 } 1281 }
1285 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1282 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1286 if (!kp.isNull()) { 1283 if (!kp.isNull()) {
1287 incidence->setSyncStatus(kp.toInt()); 1284 incidence->setSyncStatus(kp.toInt());
1288 } 1285 }
1289 kp = incidence->nonKDECustomProperty("X-ZAURUSID"); 1286 kp = incidence->nonKDECustomProperty("X-ZAURUSID");
1290 if (!kp.isNull()) { 1287 if (!kp.isNull()) {
1291 incidence->setZaurusId(kp.toInt()); 1288 incidence->setZaurusId(kp.toInt());
1292 } 1289 }
1293 1290
1294 kp = incidence->nonKDECustomProperty("X-ZAURUSUID"); 1291 kp = incidence->nonKDECustomProperty("X-ZAURUSUID");
1295 if (!kp.isNull()) { 1292 if (!kp.isNull()) {
1296 incidence->setZaurusUid(kp.toInt()); 1293 incidence->setZaurusUid(kp.toInt());
1297 } 1294 }
1298 1295
1299 kp = incidence->nonKDECustomProperty("X-ZAURUSSTAT"); 1296 kp = incidence->nonKDECustomProperty("X-ZAURUSSTAT");
1300 if (!kp.isNull()) { 1297 if (!kp.isNull()) {
1301 incidence->setZaurusStat(kp.toInt()); 1298 incidence->setZaurusStat(kp.toInt());
1302 } 1299 }
1303 1300
1304 // Cancel backwards compatibility mode for subsequent changes by the application 1301 // Cancel backwards compatibility mode for subsequent changes by the application
1305 incidence->recurrence()->setCompatVersion(); 1302 incidence->recurrence()->setCompatVersion();
1306 1303
1307 // add categories 1304 // add categories
1308 incidence->setCategories(categories); 1305 incidence->setCategories(categories);
1309 1306
1310 // iterate through all alarms 1307 // iterate through all alarms
1311 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1308 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1312 alarm; 1309 alarm;
1313 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1310 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1314 readAlarm(alarm,incidence); 1311 readAlarm(alarm,incidence);
1315 } 1312 }
1316} 1313}
1317 1314
1318void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1315void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1319{ 1316{
1320 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1317 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1321 1318
1322 while (p) { 1319 while (p) {
1323 icalproperty_kind kind = icalproperty_isa(p); 1320 icalproperty_kind kind = icalproperty_isa(p);
1324 switch (kind) { 1321 switch (kind) {
1325 1322
1326 case ICAL_UID_PROPERTY: // unique id 1323 case ICAL_UID_PROPERTY: // unique id
1327 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1324 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1328 break; 1325 break;
1329 1326
1330 case ICAL_ORGANIZER_PROPERTY: // organizer 1327 case ICAL_ORGANIZER_PROPERTY: // organizer
1331 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1328 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1332 break; 1329 break;
1333 1330
1334 case ICAL_ATTENDEE_PROPERTY: // attendee 1331 case ICAL_ATTENDEE_PROPERTY: // attendee
1335 incidenceBase->addAttendee(readAttendee(p)); 1332 incidenceBase->addAttendee(readAttendee(p));
1336 break; 1333 break;
1337 1334
1338 default: 1335 default:
1339 break; 1336 break;
1340 } 1337 }
1341 1338
1342 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1339 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1343 } 1340 }
1344 1341
1345 // custom properties 1342 // custom properties
1346 readCustomProperties(parent, incidenceBase); 1343 readCustomProperties(parent, incidenceBase);
1347} 1344}
1348 1345
1349void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1346void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1350{ 1347{
1351 QMap<QCString, QString> customProperties; 1348 QMap<QCString, QString> customProperties;
1352 1349
1353 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1350 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1354 1351
1355 while (p) { 1352 while (p) {
1356
1357 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1353 QString value = QString::fromUtf8(icalproperty_get_x(p));
1358 customProperties[icalproperty_get_name(p)] = value; 1354 customProperties[icalproperty_get_x_name(p)] = value;
1355 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1359 1356
1360 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1357 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1361 } 1358 }
1362 1359
1363 properties->setCustomProperties(customProperties); 1360 properties->setCustomProperties(customProperties);
1364} 1361}
1365 1362
1366void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1363void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1367{ 1364{
1368// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1365// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1369 1366
1370 Recurrence *recur = incidence->recurrence(); 1367 Recurrence *recur = incidence->recurrence();
1371 recur->setCompatVersion(mCalendarVersion); 1368 recur->setCompatVersion(mCalendarVersion);
1372 recur->unsetRecurs(); 1369 recur->unsetRecurs();
1373 1370
1374 struct icalrecurrencetype r = rrule; 1371 struct icalrecurrencetype r = rrule;
1375 1372
1376 dumpIcalRecurrence(r); 1373 dumpIcalRecurrence(r);
1377 readRecurrence( r, recur, incidence); 1374 readRecurrence( r, recur, incidence);
1378} 1375}
1379 1376
1380void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1377void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1381{ 1378{
1382 int wkst; 1379 int wkst;
1383 int index = 0; 1380 int index = 0;
1384 short day = 0; 1381 short day = 0;
1385 QBitArray qba(7); 1382 QBitArray qba(7);
1386 int frequ = r.freq; 1383 int frequ = r.freq;
1387 int interv = r.interval; 1384 int interv = r.interval;
1388 // preprocessing for odd recurrence definitions 1385 // preprocessing for odd recurrence definitions
1389 1386
1390 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1387 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1391 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1388 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1392 interv = 12; 1389 interv = 12;
1393 } 1390 }
1394 } 1391 }
1395 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1392 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1396 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1393 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1397 frequ = ICAL_MONTHLY_RECURRENCE; 1394 frequ = ICAL_MONTHLY_RECURRENCE;
1398 interv = 12; 1395 interv = 12;
1399 } 1396 }
1400 } 1397 }
1401 1398
1402 switch (frequ) { 1399 switch (frequ) {
1403 case ICAL_MINUTELY_RECURRENCE: 1400 case ICAL_MINUTELY_RECURRENCE:
1404 if (!icaltime_is_null_time(r.until)) { 1401 if (!icaltime_is_null_time(r.until)) {
1405 recur->setMinutely(interv,readICalDateTime(r.until)); 1402 recur->setMinutely(interv,readICalDateTime(r.until));
1406 } else { 1403 } else {
1407 if (r.count == 0) 1404 if (r.count == 0)
1408 recur->setMinutely(interv,-1); 1405 recur->setMinutely(interv,-1);
1409 else 1406 else
1410 recur->setMinutely(interv,r.count); 1407 recur->setMinutely(interv,r.count);
1411 } 1408 }
1412 break; 1409 break;
1413 case ICAL_HOURLY_RECURRENCE: 1410 case ICAL_HOURLY_RECURRENCE:
1414 if (!icaltime_is_null_time(r.until)) { 1411 if (!icaltime_is_null_time(r.until)) {
1415 recur->setHourly(interv,readICalDateTime(r.until)); 1412 recur->setHourly(interv,readICalDateTime(r.until));
1416 } else { 1413 } else {
1417 if (r.count == 0) 1414 if (r.count == 0)
1418 recur->setHourly(interv,-1); 1415 recur->setHourly(interv,-1);
1419 else 1416 else
1420 recur->setHourly(interv,r.count); 1417 recur->setHourly(interv,r.count);
1421 } 1418 }
1422 break; 1419 break;
1423 case ICAL_DAILY_RECURRENCE: 1420 case ICAL_DAILY_RECURRENCE:
1424 if (!icaltime_is_null_time(r.until)) { 1421 if (!icaltime_is_null_time(r.until)) {
1425 recur->setDaily(interv,readICalDate(r.until)); 1422 recur->setDaily(interv,readICalDate(r.until));
1426 } else { 1423 } else {
1427 if (r.count == 0) 1424 if (r.count == 0)
1428 recur->setDaily(interv,-1); 1425 recur->setDaily(interv,-1);
1429 else 1426 else
1430 recur->setDaily(interv,r.count); 1427 recur->setDaily(interv,r.count);
1431 } 1428 }
1432 break; 1429 break;
1433 case ICAL_WEEKLY_RECURRENCE: 1430 case ICAL_WEEKLY_RECURRENCE:
1434 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1431 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1435 wkst = (r.week_start + 5)%7 + 1; 1432 wkst = (r.week_start + 5)%7 + 1;
1436 if (!icaltime_is_null_time(r.until)) { 1433 if (!icaltime_is_null_time(r.until)) {
1437 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1434 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1438 } else { 1435 } else {
1439 if (r.count == 0) 1436 if (r.count == 0)
1440 recur->setWeekly(interv,qba,-1,wkst); 1437 recur->setWeekly(interv,qba,-1,wkst);
1441 else 1438 else
1442 recur->setWeekly(interv,qba,r.count,wkst); 1439 recur->setWeekly(interv,qba,r.count,wkst);
1443 } 1440 }
1444 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1441 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1445 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1442 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1446 //qDebug("weekly error found "); 1443 //qDebug("weekly error found ");
1447 qba.setBit(wday); 1444 qba.setBit(wday);
1448 } else { 1445 } else {
1449 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1446 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1450 // kdDebug(5800) << " " << day << endl; 1447 // kdDebug(5800) << " " << day << endl;
1451 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1448 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1452 } 1449 }
1453 } 1450 }
1454 break; 1451 break;
@@ -1574,194 +1571,194 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
1574 1571
1575void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1572void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1576{ 1573{
1577 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1574 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1578 1575
1579 Alarm* ialarm = incidence->newAlarm(); 1576 Alarm* ialarm = incidence->newAlarm();
1580 ialarm->setRepeatCount(0); 1577 ialarm->setRepeatCount(0);
1581 ialarm->setEnabled(true); 1578 ialarm->setEnabled(true);
1582 1579
1583 // Determine the alarm's action type 1580 // Determine the alarm's action type
1584 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1581 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1585 if ( !p ) { 1582 if ( !p ) {
1586 return; 1583 return;
1587 } 1584 }
1588 1585
1589 icalproperty_action action = icalproperty_get_action(p); 1586 icalproperty_action action = icalproperty_get_action(p);
1590 Alarm::Type type = Alarm::Display; 1587 Alarm::Type type = Alarm::Display;
1591 switch ( action ) { 1588 switch ( action ) {
1592 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; 1589 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break;
1593 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; 1590 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break;
1594 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; 1591 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break;
1595 case ICAL_ACTION_EMAIL: type = Alarm::Email; break; 1592 case ICAL_ACTION_EMAIL: type = Alarm::Email; break;
1596 default: 1593 default:
1597 ; 1594 ;
1598 return; 1595 return;
1599 } 1596 }
1600 ialarm->setType(type); 1597 ialarm->setType(type);
1601 1598
1602 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); 1599 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1603 while (p) { 1600 while (p) {
1604 icalproperty_kind kind = icalproperty_isa(p); 1601 icalproperty_kind kind = icalproperty_isa(p);
1605 1602
1606 switch (kind) { 1603 switch (kind) {
1607 case ICAL_TRIGGER_PROPERTY: { 1604 case ICAL_TRIGGER_PROPERTY: {
1608 icaltriggertype trigger = icalproperty_get_trigger(p); 1605 icaltriggertype trigger = icalproperty_get_trigger(p);
1609 if (icaltime_is_null_time(trigger.time)) { 1606 if (icaltime_is_null_time(trigger.time)) {
1610 if (icaldurationtype_is_null_duration(trigger.duration)) { 1607 if (icaldurationtype_is_null_duration(trigger.duration)) {
1611 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; 1608 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1612 } else { 1609 } else {
1613 Duration duration = icaldurationtype_as_int( trigger.duration ); 1610 Duration duration = icaldurationtype_as_int( trigger.duration );
1614 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); 1611 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1615 if (param && icalparameter_get_related(param) == ICAL_RELATED_END) 1612 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1616 ialarm->setEndOffset(duration); 1613 ialarm->setEndOffset(duration);
1617 else 1614 else
1618 ialarm->setStartOffset(duration); 1615 ialarm->setStartOffset(duration);
1619 } 1616 }
1620 } else { 1617 } else {
1621 ialarm->setTime(readICalDateTime(trigger.time)); 1618 ialarm->setTime(readICalDateTime(trigger.time));
1622 } 1619 }
1623 break; 1620 break;
1624 } 1621 }
1625 case ICAL_DURATION_PROPERTY: { 1622 case ICAL_DURATION_PROPERTY: {
1626 icaldurationtype duration = icalproperty_get_duration(p); 1623 icaldurationtype duration = icalproperty_get_duration(p);
1627 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); 1624 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60);
1628 break; 1625 break;
1629 } 1626 }
1630 case ICAL_REPEAT_PROPERTY: 1627 case ICAL_REPEAT_PROPERTY:
1631 ialarm->setRepeatCount(icalproperty_get_repeat(p)); 1628 ialarm->setRepeatCount(icalproperty_get_repeat(p));
1632 break; 1629 break;
1633 1630
1634 // Only in DISPLAY and EMAIL and PROCEDURE alarms 1631 // Only in DISPLAY and EMAIL and PROCEDURE alarms
1635 case ICAL_DESCRIPTION_PROPERTY: { 1632 case ICAL_DESCRIPTION_PROPERTY: {
1636 QString description = QString::fromUtf8(icalproperty_get_description(p)); 1633 QString description = QString::fromUtf8(icalproperty_get_description(p));
1637 switch ( action ) { 1634 switch ( action ) {
1638 case ICAL_ACTION_DISPLAY: 1635 case ICAL_ACTION_DISPLAY:
1639 ialarm->setText( description ); 1636 ialarm->setText( description );
1640 break; 1637 break;
1641 case ICAL_ACTION_PROCEDURE: 1638 case ICAL_ACTION_PROCEDURE:
1642 ialarm->setProgramArguments( description ); 1639 ialarm->setProgramArguments( description );
1643 break; 1640 break;
1644 case ICAL_ACTION_EMAIL: 1641 case ICAL_ACTION_EMAIL:
1645 ialarm->setMailText( description ); 1642 ialarm->setMailText( description );
1646 break; 1643 break;
1647 default: 1644 default:
1648 break; 1645 break;
1649 } 1646 }
1650 break; 1647 break;
1651 } 1648 }
1652 // Only in EMAIL alarm 1649 // Only in EMAIL alarm
1653 case ICAL_SUMMARY_PROPERTY: 1650 case ICAL_SUMMARY_PROPERTY:
1654 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); 1651 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
1655 break; 1652 break;
1656 1653
1657 // Only in EMAIL alarm 1654 // Only in EMAIL alarm
1658 case ICAL_ATTENDEE_PROPERTY: { 1655 case ICAL_ATTENDEE_PROPERTY: {
1659 QString email = QString::fromUtf8(icalproperty_get_attendee(p)); 1656 QString email = QString::fromUtf8(icalproperty_get_attendee(p));
1660 QString name; 1657 QString name;
1661 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); 1658 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1662 if (param) { 1659 if (param) {
1663 name = QString::fromUtf8(icalparameter_get_cn(param)); 1660 name = QString::fromUtf8(icalparameter_get_cn(param));
1664 } 1661 }
1665 ialarm->addMailAddress(Person(name, email)); 1662 ialarm->addMailAddress(Person(name, email));
1666 break; 1663 break;
1667 } 1664 }
1668 // Only in AUDIO and EMAIL and PROCEDURE alarms 1665 // Only in AUDIO and EMAIL and PROCEDURE alarms
1669 case ICAL_ATTACH_PROPERTY: { 1666 case ICAL_ATTACH_PROPERTY: {
1670 icalattachtype *attach = icalproperty_get_attach(p); 1667 icalattach *attach = icalproperty_get_attach(p);
1671 QString url = QFile::decodeName(icalattachtype_get_url(attach)); 1668 QString url = QFile::decodeName(icalattach_get_url(attach));
1672 switch ( action ) { 1669 switch ( action ) {
1673 case ICAL_ACTION_AUDIO: 1670 case ICAL_ACTION_AUDIO:
1674 ialarm->setAudioFile( url ); 1671 ialarm->setAudioFile( url );
1675 break; 1672 break;
1676 case ICAL_ACTION_PROCEDURE: 1673 case ICAL_ACTION_PROCEDURE:
1677 ialarm->setProgramFile( url ); 1674 ialarm->setProgramFile( url );
1678 break; 1675 break;
1679 case ICAL_ACTION_EMAIL: 1676 case ICAL_ACTION_EMAIL:
1680 ialarm->addMailAttachment( url ); 1677 ialarm->addMailAttachment( url );
1681 break; 1678 break;
1682 default: 1679 default:
1683 break; 1680 break;
1684 } 1681 }
1685 break; 1682 break;
1686 } 1683 }
1687 default: 1684 default:
1688 break; 1685 break;
1689 } 1686 }
1690 1687
1691 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1688 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1692 } 1689 }
1693 1690
1694 // custom properties 1691 // custom properties
1695 readCustomProperties(alarm, ialarm); 1692 readCustomProperties(alarm, ialarm);
1696 1693
1697 // TODO: check for consistency of alarm properties 1694 // TODO: check for consistency of alarm properties
1698} 1695}
1699 1696
1700icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1697icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1701{ 1698{
1702 icaltimetype t; 1699 icaltimetype t;
1703 1700
1704 t.year = date.year(); 1701 t.year = date.year();
1705 t.month = date.month(); 1702 t.month = date.month();
1706 t.day = date.day(); 1703 t.day = date.day();
1707 1704
1708 t.hour = 0; 1705 t.hour = 0;
1709 t.minute = 0; 1706 t.minute = 0;
1710 t.second = 0; 1707 t.second = 0;
1711 1708
1712 t.is_date = 1; 1709 t.is_date = 1;
1713 1710
1714 t.is_utc = 0; 1711 t.is_utc = 0;
1715 1712
1716 t.zone = 0; 1713 t.zone = 0;
1717 1714
1718 return t; 1715 return t;
1719} 1716}
1720 1717
1721icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1718icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1722{ 1719{
1723 icaltimetype t; 1720 icaltimetype t;
1724 t.is_date = 0; 1721 t.is_date = 0;
1725 t.zone = 0; 1722 t.zone = 0;
1726 QDateTime datetime; 1723 QDateTime datetime;
1727 if ( mParent->utc() ) { 1724 if ( mParent->utc() ) {
1728 int offset = KGlobal::locale()->localTimeOffset( dt ); 1725 int offset = KGlobal::locale()->localTimeOffset( dt );
1729 datetime = dt.addSecs ( -offset*60); 1726 datetime = dt.addSecs ( -offset*60);
1730 t.is_utc = 1; 1727 t.is_utc = 1;
1731 } 1728 }
1732 else { 1729 else {
1733 datetime = dt; 1730 datetime = dt;
1734 t.is_utc = 0; 1731 t.is_utc = 0;
1735 1732
1736 } 1733 }
1737 t.year = datetime.date().year(); 1734 t.year = datetime.date().year();
1738 t.month = datetime.date().month(); 1735 t.month = datetime.date().month();
1739 t.day = datetime.date().day(); 1736 t.day = datetime.date().day();
1740 1737
1741 t.hour = datetime.time().hour(); 1738 t.hour = datetime.time().hour();
1742 t.minute = datetime.time().minute(); 1739 t.minute = datetime.time().minute();
1743 t.second = datetime.time().second(); 1740 t.second = datetime.time().second();
1744 1741
1745 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1742 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1746 1743
1747// if ( mParent->utc() ) { 1744// if ( mParent->utc() ) {
1748// datetime = KGlobal::locale()->localTime( dt ); 1745// datetime = KGlobal::locale()->localTime( dt );
1749// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1746// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1750// if (mParent->timeZoneId().isEmpty()) 1747// if (mParent->timeZoneId().isEmpty())
1751// t = icaltime_as_utc(t, 0); 1748// t = icaltime_as_utc(t, 0);
1752// else 1749// else
1753// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1750// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1754// } 1751// }
1755 1752
1756 return t; 1753 return t;
1757} 1754}
1758 1755
1759QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1756QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1760{ 1757{
1761 QDateTime dt (QDate(t.year,t.month,t.day), 1758 QDateTime dt (QDate(t.year,t.month,t.day),
1762 QTime(t.hour,t.minute,t.second) ); 1759 QTime(t.hour,t.minute,t.second) );
1763 1760
1764 if (t.is_utc) { 1761 if (t.is_utc) {
1765 int offset = KGlobal::locale()->localTimeOffset( dt ); 1762 int offset = KGlobal::locale()->localTimeOffset( dt );
1766 dt = dt.addSecs ( offset*60); 1763 dt = dt.addSecs ( offset*60);
1767 } 1764 }