summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 3e28714..4794bc9 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1,2172 +1,2175 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <qptrlist.h>
24#include <qfile.h> 24#include <qfile.h>
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28#include <kglobal.h> 28#include <kglobal.h>
29 29
30extern "C" { 30extern "C" {
31 #include <ical.h> 31 #include <ical.h>
32 #include <icalss.h> 32 #include <icalss.h>
33 #include <icalparser.h> 33 #include <icalparser.h>
34 #include <icalrestriction.h> 34 #include <icalrestriction.h>
35} 35}
36 36
37#include "calendar.h" 37#include "calendar.h"
38#include "journal.h" 38#include "journal.h"
39#include "icalformat.h" 39#include "icalformat.h"
40#include "icalformatimpl.h" 40#include "icalformatimpl.h"
41#include "compat.h" 41#include "compat.h"
42 42
43#define _ICAL_VERSION "2.0" 43#define _ICAL_VERSION "2.0"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47const int gSecondsPerMinute = 60; 47const int gSecondsPerMinute = 60;
48const int gSecondsPerHour = gSecondsPerMinute * 60; 48const int gSecondsPerHour = gSecondsPerMinute * 60;
49const int gSecondsPerDay = gSecondsPerHour * 24; 49const int gSecondsPerDay = gSecondsPerHour * 24;
50const int gSecondsPerWeek = gSecondsPerDay * 7; 50const int gSecondsPerWeek = gSecondsPerDay * 7;
51 51
52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : 52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) :
53 mParent( parent ), mCalendarVersion( 0 ) 53 mParent( parent ), mCalendarVersion( 0 )
54{ 54{
55 mCompat = new Compat; 55 mCompat = new Compat;
56} 56}
57 57
58ICalFormatImpl::~ICalFormatImpl() 58ICalFormatImpl::~ICalFormatImpl()
59{ 59{
60 delete mCompat; 60 delete mCompat;
61} 61}
62 62
63class ToStringVisitor : public Incidence::Visitor 63class ToStringVisitor : public Incidence::Visitor
64{ 64{
65 public: 65 public:
66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} 66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {}
67 67
68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } 68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; }
69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } 69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; }
70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } 70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; }
71 71
72 icalcomponent *component() { return mComponent; } 72 icalcomponent *component() { return mComponent; }
73 73
74 private: 74 private:
75 ICalFormatImpl *mImpl; 75 ICalFormatImpl *mImpl;
76 icalcomponent *mComponent; 76 icalcomponent *mComponent;
77}; 77};
78 78
79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) 79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence)
80{ 80{
81 ToStringVisitor v( this ); 81 ToStringVisitor v( this );
82 incidence->accept(v); 82 incidence->accept(v);
83 return v.component(); 83 return v.component();
84} 84}
85 85
86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) 86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo)
87{ 87{
88 QString tmpStr; 88 QString tmpStr;
89 QStringList tmpStrList; 89 QStringList tmpStrList;
90 90
91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); 91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
92 92
93 writeIncidence(vtodo,todo); 93 writeIncidence(vtodo,todo);
94 94
95 // due date 95 // due date
96 if (todo->hasDueDate()) { 96 if (todo->hasDueDate()) {
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(ICAL_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(ICAL_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 206
207 207
208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
209 209
210 writeIncidenceBase(vfreebusy,freebusy); 210 writeIncidenceBase(vfreebusy,freebusy);
211 211
212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
213 writeICalDateTime(freebusy->dtStart()))); 213 writeICalDateTime(freebusy->dtStart())));
214 214
215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
216 writeICalDateTime(freebusy->dtEnd()))); 216 writeICalDateTime(freebusy->dtEnd())));
217 217
218 if (method == Scheduler::Request) { 218 if (method == Scheduler::Request) {
219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
220 freebusy->uid().utf8())); 220 freebusy->uid().utf8()));
221 } 221 }
222 222
223 //Loops through all the periods in the freebusy object 223 //Loops through all the periods in the freebusy object
224 QValueList<Period> list = freebusy->busyPeriods(); 224 QValueList<Period> list = freebusy->busyPeriods();
225 QValueList<Period>::Iterator it; 225 QValueList<Period>::Iterator it;
226 icalperiodtype period; 226 icalperiodtype period;
227 for (it = list.begin(); it!= list.end(); ++it) { 227 for (it = list.begin(); it!= list.end(); ++it) {
228 period.start = writeICalDateTime((*it).start()); 228 period.start = writeICalDateTime((*it).start());
229 period.end = writeICalDateTime((*it).end()); 229 period.end = writeICalDateTime((*it).end());
230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
231 } 231 }
232 232
233 return vfreebusy; 233 return vfreebusy;
234} 234}
235 235
236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
237{ 237{
238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
239 239
240 writeIncidence(vjournal,journal); 240 writeIncidence(vjournal,journal);
241 241
242 // start time 242 // start time
243 if (journal->dtStart().isValid()) { 243 if (journal->dtStart().isValid()) {
244 icaltimetype start; 244 icaltimetype start;
245 if (journal->doesFloat()) { 245 if (journal->doesFloat()) {
246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
247 start = writeICalDate(journal->dtStart().date()); 247 start = writeICalDate(journal->dtStart().date());
248 } else { 248 } else {
249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
250 start = writeICalDateTime(journal->dtStart()); 250 start = writeICalDateTime(journal->dtStart());
251 } 251 }
252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
253 } 253 }
254 254
255 return vjournal; 255 return vjournal;
256} 256}
257 257
258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
259{ 259{
260 // pilot sync stuff 260 // pilot sync stuff
261// TODO: move this application-specific code to kpilot 261// TODO: move this application-specific code to kpilot
262 if (incidence->pilotId()) { 262 if (incidence->pilotId()) {
263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
265 } 265 }
266 if ( !incidence->IDStr().isEmpty()) { 266 if ( !incidence->IDStr().isEmpty()) {
267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); 267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() );
268 } 268 }
269 269
270 270
271 writeIncidenceBase(parent,incidence); 271 writeIncidenceBase(parent,incidence);
272 if (incidence->cancelled()) { 272 if (incidence->cancelled()) {
273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
274 } 274 }
275 275
276 // creation date 276 // creation date
277 icalcomponent_add_property(parent,icalproperty_new_created( 277 icalcomponent_add_property(parent,icalproperty_new_created(
278 writeICalDateTime(incidence->created()))); 278 writeICalDateTime(incidence->created())));
279 279
280 // unique id 280 // unique id
281 icalcomponent_add_property(parent,icalproperty_new_uid( 281 icalcomponent_add_property(parent,icalproperty_new_uid(
282 incidence->uid().utf8())); 282 incidence->uid().utf8()));
283 283
284 // revision 284 // revision
285 icalcomponent_add_property(parent,icalproperty_new_sequence( 285 icalcomponent_add_property(parent,icalproperty_new_sequence(
286 incidence->revision())); 286 incidence->revision()));
287 287
288 // last modification date 288 // last modification date
289 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 289 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
290 writeICalDateTime(incidence->lastModified()))); 290 writeICalDateTime(incidence->lastModified())));
291 291
292 // description 292 // description
293 if (!incidence->description().isEmpty()) { 293 if (!incidence->description().isEmpty()) {
294 icalcomponent_add_property(parent,icalproperty_new_description( 294 icalcomponent_add_property(parent,icalproperty_new_description(
295 incidence->description().utf8())); 295 incidence->description().utf8()));
296 } 296 }
297 297
298 // summary 298 // summary
299 if (!incidence->summary().isEmpty()) { 299 if (!incidence->summary().isEmpty()) {
300 icalcomponent_add_property(parent,icalproperty_new_summary( 300 icalcomponent_add_property(parent,icalproperty_new_summary(
301 incidence->summary().utf8())); 301 incidence->summary().utf8()));
302 } 302 }
303 303
304 // location 304 // location
305 if (!incidence->location().isEmpty()) { 305 if (!incidence->location().isEmpty()) {
306 icalcomponent_add_property(parent,icalproperty_new_location( 306 icalcomponent_add_property(parent,icalproperty_new_location(
307 incidence->location().utf8())); 307 incidence->location().utf8()));
308 } 308 }
309 309
310// TODO: 310// TODO:
311 // status 311 // status
312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
313 313
314 // secrecy 314 // secrecy
315 enum icalproperty_class classInt; 315 enum icalproperty_class classInt;
316 switch (incidence->secrecy()) { 316 switch (incidence->secrecy()) {
317 case Incidence::SecrecyPublic: 317 case Incidence::SecrecyPublic:
318 classInt = ICAL_CLASS_PUBLIC; 318 classInt = ICAL_CLASS_PUBLIC;
319 break; 319 break;
320 case Incidence::SecrecyConfidential: 320 case Incidence::SecrecyConfidential:
321 classInt = ICAL_CLASS_CONFIDENTIAL; 321 classInt = ICAL_CLASS_CONFIDENTIAL;
322 break; 322 break;
323 case Incidence::SecrecyPrivate: 323 case Incidence::SecrecyPrivate:
324 classInt =ICAL_CLASS_PRIVATE ; 324 classInt =ICAL_CLASS_PRIVATE ;
325 default: 325 default:
326 classInt =ICAL_CLASS_PRIVATE ; 326 classInt =ICAL_CLASS_PRIVATE ;
327 break; 327 break;
328 } 328 }
329 icalcomponent_add_property(parent,icalproperty_new_class(classInt)); 329 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
330 330
331 // priority 331 // priority
332 icalcomponent_add_property(parent,icalproperty_new_priority( 332 icalcomponent_add_property(parent,icalproperty_new_priority(
333 incidence->priority())); 333 incidence->priority()));
334 334
335 // categories 335 // categories
336 QStringList categories = incidence->categories(); 336 QStringList categories = incidence->categories();
337 QStringList::Iterator it; 337 QStringList::Iterator it;
338 for(it = categories.begin(); it != categories.end(); ++it ) { 338 for(it = categories.begin(); it != categories.end(); ++it ) {
339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
340 } 340 }
341// TODO: Ensure correct concatenation of categories properties. 341// TODO: Ensure correct concatenation of categories properties.
342 342
343/* 343/*
344 // categories 344 // categories
345 tmpStrList = incidence->getCategories(); 345 tmpStrList = incidence->getCategories();
346 tmpStr = ""; 346 tmpStr = "";
347 QString catStr; 347 QString catStr;
348 for ( QStringList::Iterator it = tmpStrList.begin(); 348 for ( QStringList::Iterator it = tmpStrList.begin();
349 it != tmpStrList.end(); 349 it != tmpStrList.end();
350 ++it ) { 350 ++it ) {
351 catStr = *it; 351 catStr = *it;
352 if (catStr[0] == ' ') 352 if (catStr[0] == ' ')
353 tmpStr += catStr.mid(1); 353 tmpStr += catStr.mid(1);
354 else 354 else
355 tmpStr += catStr; 355 tmpStr += catStr;
356 // this must be a ';' character as the vCalendar specification requires! 356 // this must be a ';' character as the vCalendar specification requires!
357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
358 // read in. 358 // read in.
359 tmpStr += ";"; 359 tmpStr += ";";
360 } 360 }
361 if (!tmpStr.isEmpty()) { 361 if (!tmpStr.isEmpty()) {
362 tmpStr.truncate(tmpStr.length()-1); 362 tmpStr.truncate(tmpStr.length()-1);
363 icalcomponent_add_property(parent,icalproperty_new_categories( 363 icalcomponent_add_property(parent,icalproperty_new_categories(
364 writeText(incidence->getCategories().join(";")))); 364 writeText(incidence->getCategories().join(";"))));
365 } 365 }
366*/ 366*/
367 367
368 // related event 368 // related event
369 if (!incidence->relatedToUid().isEmpty()) { 369 if (!incidence->relatedToUid().isEmpty()) {
370 icalcomponent_add_property(parent,icalproperty_new_relatedto( 370 icalcomponent_add_property(parent,icalproperty_new_relatedto(
371 incidence->relatedToUid().utf8())); 371 incidence->relatedToUid().utf8()));
372 } 372 }
373 373
374 // recurrence rule stuff 374 // recurrence rule stuff
375 Recurrence *recur = incidence->recurrence(); 375 Recurrence *recur = incidence->recurrence();
376 if (recur->doesRecur()) { 376 if (recur->doesRecur()) {
377 377
378 icalcomponent_add_property(parent,writeRecurrenceRule(recur)); 378 icalcomponent_add_property(parent,writeRecurrenceRule(recur));
379 } 379 }
380 380
381 // recurrence excpetion dates 381 // recurrence excpetion dates
382 DateList dateList = incidence->exDates(); 382 DateList dateList = incidence->exDates();
383 DateList::ConstIterator exIt; 383 DateList::ConstIterator exIt;
384 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 384 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
385 icalcomponent_add_property(parent,icalproperty_new_exdate( 385 icalcomponent_add_property(parent,icalproperty_new_exdate(
386 writeICalDate(*exIt))); 386 writeICalDate(*exIt)));
387 } 387 }
388 388
389 // attachments 389 // attachments
390 QPtrList<Attachment> attachments = incidence->attachments(); 390 QPtrList<Attachment> attachments = incidence->attachments();
391 for (Attachment *at = attachments.first(); at; at = attachments.next()) 391 for (Attachment *at = attachments.first(); at; at = attachments.next())
392 icalcomponent_add_property(parent,writeAttachment(at)); 392 icalcomponent_add_property(parent,writeAttachment(at));
393 393
394 // alarms 394 // alarms
395 QPtrList<Alarm> alarms = incidence->alarms(); 395 QPtrList<Alarm> alarms = incidence->alarms();
396 Alarm* alarm; 396 Alarm* alarm;
397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
398 if (alarm->enabled()) { 398 if (alarm->enabled()) {
399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
400 icalcomponent_add_component(parent,writeAlarm(alarm)); 400 icalcomponent_add_component(parent,writeAlarm(alarm));
401 } 401 }
402 } 402 }
403 if( incidence->hasRecurrenceID() ) { 403 if( incidence->hasRecurrenceID() ) {
404 icalcomponent_add_property(parent, 404 icalcomponent_add_property(parent,
405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); 405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID())));
406 } 406 }
407 // duration 407 // duration
408 408
409// turned off as it always is set to PTS0 (and must not occur together with DTEND 409// turned off as it always is set to PTS0 (and must not occur together with DTEND
410 410
411 if (incidence->hasDuration()) { 411 if (incidence->hasDuration()) {
412 icaldurationtype duration; 412 icaldurationtype duration;
413 duration = writeICalDuration(incidence->duration()); 413 duration = writeICalDuration(incidence->duration());
414 icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 414 icalcomponent_add_property(parent,icalproperty_new_duration(duration));
415 } 415 }
416} 416}
417 417
418void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 418void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
419{ 419{
420 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 420 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
421 writeICalDateTime(QDateTime::currentDateTime()))); 421 writeICalDateTime(QDateTime::currentDateTime())));
422 422
423 // organizer stuff 423 // organizer stuff
424 icalcomponent_add_property(parent,icalproperty_new_organizer( 424 icalcomponent_add_property(parent,icalproperty_new_organizer(
425 ("MAILTO:" + incidenceBase->organizer()).utf8())); 425 ("MAILTO:" + incidenceBase->organizer()).utf8()));
426 426
427 // attendees 427 // attendees
428 if (incidenceBase->attendeeCount() != 0) { 428 if (incidenceBase->attendeeCount() != 0) {
429 QPtrList<Attendee> al = incidenceBase->attendees(); 429 QPtrList<Attendee> al = incidenceBase->attendees();
430 QPtrListIterator<Attendee> ai(al); 430 QPtrListIterator<Attendee> ai(al);
431 for (; ai.current(); ++ai) { 431 for (; ai.current(); ++ai) {
432 icalcomponent_add_property(parent,writeAttendee(ai.current())); 432 icalcomponent_add_property(parent,writeAttendee(ai.current()));
433 } 433 }
434 } 434 }
435 435
436 // custom properties 436 // custom properties
437 writeCustomProperties(parent, incidenceBase); 437 writeCustomProperties(parent, incidenceBase);
438} 438}
439 439
440void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 440void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
441{ 441{
442 QMap<QCString, QString> custom = properties->customProperties(); 442 QMap<QCString, QString> custom = properties->customProperties();
443 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 443 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
444 icalproperty *p = icalproperty_new_x(c.data().utf8()); 444 icalproperty *p = icalproperty_new_x(c.data().utf8());
445 icalproperty_set_x_name(p,c.key()); 445 icalproperty_set_x_name(p,c.key());
446 icalcomponent_add_property(parent,p); 446 icalcomponent_add_property(parent,p);
447 } 447 }
448} 448}
449 449
450icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 450icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
451{ 451{
452 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 452 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
453 453
454 if (!attendee->name().isEmpty()) { 454 if (!attendee->name().isEmpty()) {
455 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 455 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
456 } 456 }
457 457
458 458
459 icalproperty_add_parameter(p,icalparameter_new_rsvp( 459 icalproperty_add_parameter(p,icalparameter_new_rsvp(
460 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 460 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
461 461
462 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 462 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
463 switch (attendee->status()) { 463 switch (attendee->status()) {
464 default: 464 default:
465 case Attendee::NeedsAction: 465 case Attendee::NeedsAction:
466 status = ICAL_PARTSTAT_NEEDSACTION; 466 status = ICAL_PARTSTAT_NEEDSACTION;
467 break; 467 break;
468 case Attendee::Accepted: 468 case Attendee::Accepted:
469 status = ICAL_PARTSTAT_ACCEPTED; 469 status = ICAL_PARTSTAT_ACCEPTED;
470 break; 470 break;
471 case Attendee::Declined: 471 case Attendee::Declined:
472 status = ICAL_PARTSTAT_DECLINED; 472 status = ICAL_PARTSTAT_DECLINED;
473 break; 473 break;
474 case Attendee::Tentative: 474 case Attendee::Tentative:
475 status = ICAL_PARTSTAT_TENTATIVE; 475 status = ICAL_PARTSTAT_TENTATIVE;
476 break; 476 break;
477 case Attendee::Delegated: 477 case Attendee::Delegated:
478 status = ICAL_PARTSTAT_DELEGATED; 478 status = ICAL_PARTSTAT_DELEGATED;
479 break; 479 break;
480 case Attendee::Completed: 480 case Attendee::Completed:
481 status = ICAL_PARTSTAT_COMPLETED; 481 status = ICAL_PARTSTAT_COMPLETED;
482 break; 482 break;
483 case Attendee::InProcess: 483 case Attendee::InProcess:
484 status = ICAL_PARTSTAT_INPROCESS; 484 status = ICAL_PARTSTAT_INPROCESS;
485 break; 485 break;
486 } 486 }
487 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 487 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
488 488
489 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 489 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
490 switch (attendee->role()) { 490 switch (attendee->role()) {
491 case Attendee::Chair: 491 case Attendee::Chair:
492 role = ICAL_ROLE_CHAIR; 492 role = ICAL_ROLE_CHAIR;
493 break; 493 break;
494 default: 494 default:
495 case Attendee::ReqParticipant: 495 case Attendee::ReqParticipant:
496 role = ICAL_ROLE_REQPARTICIPANT; 496 role = ICAL_ROLE_REQPARTICIPANT;
497 break; 497 break;
498 case Attendee::OptParticipant: 498 case Attendee::OptParticipant:
499 role = ICAL_ROLE_OPTPARTICIPANT; 499 role = ICAL_ROLE_OPTPARTICIPANT;
500 break; 500 break;
501 case Attendee::NonParticipant: 501 case Attendee::NonParticipant:
502 role = ICAL_ROLE_NONPARTICIPANT; 502 role = ICAL_ROLE_NONPARTICIPANT;
503 break; 503 break;
504 } 504 }
505 icalproperty_add_parameter(p,icalparameter_new_role(role)); 505 icalproperty_add_parameter(p,icalparameter_new_role(role));
506 506
507 if (!attendee->uid().isEmpty()) { 507 if (!attendee->uid().isEmpty()) {
508 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 508 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
509 icalparameter_set_xname(icalparameter_uid,"X-UID"); 509 icalparameter_set_xname(icalparameter_uid,"X-UID");
510 icalproperty_add_parameter(p,icalparameter_uid); 510 icalproperty_add_parameter(p,icalparameter_uid);
511 } 511 }
512 512
513 return p; 513 return p;
514} 514}
515 515
516icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 516icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
517{ 517{
518#if 0 518#if 0
519 icalattachtype* attach = icalattachtype_new(); 519 icalattachtype* attach = icalattachtype_new();
520 if (att->isURI()) 520 if (att->isURI())
521 icalattachtype_set_url(attach, att->uri().utf8().data()); 521 icalattachtype_set_url(attach, att->uri().utf8().data());
522 else 522 else
523 icalattachtype_set_base64(attach, att->data(), 0); 523 icalattachtype_set_base64(attach, att->data(), 0);
524#endif 524#endif
525 icalattach *attach; 525 icalattach *attach;
526 if (att->isURI()) 526 if (att->isURI())
527 attach = icalattach_new_from_url( att->uri().utf8().data()); 527 attach = icalattach_new_from_url( att->uri().utf8().data());
528 else 528 else
529 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); 529 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0);
530 icalproperty *p = icalproperty_new_attach(attach); 530 icalproperty *p = icalproperty_new_attach(attach);
531 if (!att->mimeType().isEmpty()) 531 if (!att->mimeType().isEmpty())
532 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); 532 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data()));
533 533
534 if (att->isBinary()) { 534 if (att->isBinary()) {
535 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); 535 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
536 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); 536 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64));
537 } 537 }
538 return p; 538 return p;
539} 539}
540 540
541icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) 541icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur)
542{ 542{
543// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; 543// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl;
544 544
545 icalrecurrencetype r; 545 icalrecurrencetype r;
546 546
547 icalrecurrencetype_clear(&r); 547 icalrecurrencetype_clear(&r);
548 548
549 int index = 0; 549 int index = 0;
550 int index2 = 0; 550 int index2 = 0;
551 551
552 QPtrList<Recurrence::rMonthPos> tmpPositions; 552 QPtrList<Recurrence::rMonthPos> tmpPositions;
553 QPtrList<int> tmpDays; 553 QPtrList<int> tmpDays;
554 int *tmpDay; 554 int *tmpDay;
555 Recurrence::rMonthPos *tmpPos; 555 Recurrence::rMonthPos *tmpPos;
556 bool datetime = false; 556 bool datetime = false;
557 int day; 557 int day;
558 int i; 558 int i;
559 559
560 switch(recur->doesRecur()) { 560 switch(recur->doesRecur()) {
561 case Recurrence::rMinutely: 561 case Recurrence::rMinutely:
562 r.freq = ICAL_MINUTELY_RECURRENCE; 562 r.freq = ICAL_MINUTELY_RECURRENCE;
563 datetime = true; 563 datetime = true;
564 break; 564 break;
565 case Recurrence::rHourly: 565 case Recurrence::rHourly:
566 r.freq = ICAL_HOURLY_RECURRENCE; 566 r.freq = ICAL_HOURLY_RECURRENCE;
567 datetime = true; 567 datetime = true;
568 break; 568 break;
569 case Recurrence::rDaily: 569 case Recurrence::rDaily:
570 r.freq = ICAL_DAILY_RECURRENCE; 570 r.freq = ICAL_DAILY_RECURRENCE;
571 break; 571 break;
572 case Recurrence::rWeekly: 572 case Recurrence::rWeekly:
573 r.freq = ICAL_WEEKLY_RECURRENCE; 573 r.freq = ICAL_WEEKLY_RECURRENCE;
574 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); 574 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1);
575 for (i = 0; i < 7; i++) { 575 for (i = 0; i < 7; i++) {
576 if (recur->days().testBit(i)) { 576 if (recur->days().testBit(i)) {
577 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 577 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
578 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); 578 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day);
579 } 579 }
580 } 580 }
581// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 581// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
582 break; 582 break;
583 case Recurrence::rMonthlyPos: 583 case Recurrence::rMonthlyPos:
584 r.freq = ICAL_MONTHLY_RECURRENCE; 584 r.freq = ICAL_MONTHLY_RECURRENCE;
585 585
586 tmpPositions = recur->monthPositions(); 586 tmpPositions = recur->monthPositions();
587 for (tmpPos = tmpPositions.first(); 587 for (tmpPos = tmpPositions.first();
588 tmpPos; 588 tmpPos;
589 tmpPos = tmpPositions.next()) { 589 tmpPos = tmpPositions.next()) {
590 for (i = 0; i < 7; i++) { 590 for (i = 0; i < 7; i++) {
591 if (tmpPos->rDays.testBit(i)) { 591 if (tmpPos->rDays.testBit(i)) {
592 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 592 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
593 day += tmpPos->rPos*8; 593 day += tmpPos->rPos*8;
594 if (tmpPos->negative) day = -day; 594 if (tmpPos->negative) day = -day;
595 r.by_day[index++] = day; 595 r.by_day[index++] = day;
596 } 596 }
597 } 597 }
598 } 598 }
599// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 599// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
600 break; 600 break;
601 case Recurrence::rMonthlyDay: 601 case Recurrence::rMonthlyDay:
602 r.freq = ICAL_MONTHLY_RECURRENCE; 602 r.freq = ICAL_MONTHLY_RECURRENCE;
603 603
604 tmpDays = recur->monthDays(); 604 tmpDays = recur->monthDays();
605 for (tmpDay = tmpDays.first(); 605 for (tmpDay = tmpDays.first();
606 tmpDay; 606 tmpDay;
607 tmpDay = tmpDays.next()) { 607 tmpDay = tmpDays.next()) {
608 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); 608 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay);
609 } 609 }
610// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 610// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
611 break; 611 break;
612 case Recurrence::rYearlyMonth: 612 case Recurrence::rYearlyMonth:
613 case Recurrence::rYearlyPos: 613 case Recurrence::rYearlyPos:
614 r.freq = ICAL_YEARLY_RECURRENCE; 614 r.freq = ICAL_YEARLY_RECURRENCE;
615 615
616 tmpDays = recur->yearNums(); 616 tmpDays = recur->yearNums();
617 for (tmpDay = tmpDays.first(); 617 for (tmpDay = tmpDays.first();
618 tmpDay; 618 tmpDay;
619 tmpDay = tmpDays.next()) { 619 tmpDay = tmpDays.next()) {
620 r.by_month[index++] = *tmpDay; 620 r.by_month[index++] = *tmpDay;
621 } 621 }
622// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; 622// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX;
623 if (recur->doesRecur() == Recurrence::rYearlyPos) { 623 if (recur->doesRecur() == Recurrence::rYearlyPos) {
624 tmpPositions = recur->monthPositions(); 624 tmpPositions = recur->monthPositions();
625 for (tmpPos = tmpPositions.first(); 625 for (tmpPos = tmpPositions.first();
626 tmpPos; 626 tmpPos;
627 tmpPos = tmpPositions.next()) { 627 tmpPos = tmpPositions.next()) {
628 for (i = 0; i < 7; i++) { 628 for (i = 0; i < 7; i++) {
629 if (tmpPos->rDays.testBit(i)) { 629 if (tmpPos->rDays.testBit(i)) {
630 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 630 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
631 day += tmpPos->rPos*8; 631 day += tmpPos->rPos*8;
632 if (tmpPos->negative) day = -day; 632 if (tmpPos->negative) day = -day;
633 r.by_day[index2++] = day; 633 r.by_day[index2++] = day;
634 } 634 }
635 } 635 }
636 } 636 }
637// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; 637// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX;
638 } 638 }
639 break; 639 break;
640 case Recurrence::rYearlyDay: 640 case Recurrence::rYearlyDay:
641 r.freq = ICAL_YEARLY_RECURRENCE; 641 r.freq = ICAL_YEARLY_RECURRENCE;
642 642
643 tmpDays = recur->yearNums(); 643 tmpDays = recur->yearNums();
644 for (tmpDay = tmpDays.first(); 644 for (tmpDay = tmpDays.first();
645 tmpDay; 645 tmpDay;
646 tmpDay = tmpDays.next()) { 646 tmpDay = tmpDays.next()) {
647 r.by_year_day[index++] = *tmpDay; 647 r.by_year_day[index++] = *tmpDay;
648 } 648 }
649// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 649// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
650 break; 650 break;
651 default: 651 default:
652 r.freq = ICAL_NO_RECURRENCE; 652 r.freq = ICAL_NO_RECURRENCE;
653 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; 653 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
654 break; 654 break;
655 } 655 }
656 656
657 r.interval = recur->frequency(); 657 r.interval = recur->frequency();
658 658
659 if (recur->duration() > 0) { 659 if (recur->duration() > 0) {
660 r.count = recur->duration(); 660 r.count = recur->duration();
661 } else if (recur->duration() == -1) { 661 } else if (recur->duration() == -1) {
662 r.count = 0; 662 r.count = 0;
663 } else { 663 } else {
664 if (datetime) 664 if (datetime)
665 r.until = writeICalDateTime(recur->endDateTime()); 665 r.until = writeICalDateTime(recur->endDateTime());
666 else 666 else
667 r.until = writeICalDate(recur->endDate()); 667 r.until = writeICalDate(recur->endDate());
668 } 668 }
669 669
670// Debug output 670// Debug output
671#if 0 671#if 0
672 const char *str = icalrecurrencetype_as_string(&r); 672 const char *str = icalrecurrencetype_as_string(&r);
673 if (str) { 673 if (str) {
674 kdDebug(5800) << " String: " << str << endl; 674 kdDebug(5800) << " String: " << str << endl;
675 } else { 675 } else {
676 kdDebug(5800) << " No String" << endl; 676 kdDebug(5800) << " No String" << endl;
677 } 677 }
678#endif 678#endif
679 679
680 return icalproperty_new_rrule(r); 680 return icalproperty_new_rrule(r);
681} 681}
682 682
683icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) 683icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
684{ 684{
685 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); 685 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
686 686
687 icalproperty_action action; 687 icalproperty_action action;
688 icalattach *attach = 0; 688 icalattach *attach = 0;
689 689
690 switch (alarm->type()) { 690 switch (alarm->type()) {
691 case Alarm::Procedure: 691 case Alarm::Procedure:
692 action = ICAL_ACTION_PROCEDURE; 692 action = ICAL_ACTION_PROCEDURE;
693 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); 693 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() );
694 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 694 icalcomponent_add_property(a,icalproperty_new_attach(attach));
695 if (!alarm->programArguments().isEmpty()) { 695 if (!alarm->programArguments().isEmpty()) {
696 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); 696 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8()));
697 } 697 }
698 icalattach_unref( attach ); 698 icalattach_unref( attach );
699 break; 699 break;
700 case Alarm::Audio: 700 case Alarm::Audio:
701 action = ICAL_ACTION_AUDIO; 701 action = ICAL_ACTION_AUDIO;
702 if (!alarm->audioFile().isEmpty()) { 702 if (!alarm->audioFile().isEmpty()) {
703 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); 703 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data());
704 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 704 icalcomponent_add_property(a,icalproperty_new_attach(attach));
705 icalattach_unref( attach ); 705 icalattach_unref( attach );
706 } 706 }
707 break; 707 break;
708 case Alarm::Email: { 708 case Alarm::Email: {
709 action = ICAL_ACTION_EMAIL; 709 action = ICAL_ACTION_EMAIL;
710 QValueList<Person> addresses = alarm->mailAddresses(); 710 QValueList<Person> addresses = alarm->mailAddresses();
711 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { 711 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
712 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); 712 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8());
713 if (!(*ad).name().isEmpty()) { 713 if (!(*ad).name().isEmpty()) {
714 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); 714 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
715 } 715 }
716 icalcomponent_add_property(a,p); 716 icalcomponent_add_property(a,p);
717 } 717 }
718 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); 718 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
719 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 719 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
720 QStringList attachments = alarm->mailAttachments(); 720 QStringList attachments = alarm->mailAttachments();
721 if (attachments.count() > 0) { 721 if (attachments.count() > 0) {
722 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { 722 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
723 attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); 723 attach = icalattach_new_from_url(QFile::encodeName( *at ).data());
724 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 724 icalcomponent_add_property(a,icalproperty_new_attach(attach));
725 icalattach_unref( attach ); 725 icalattach_unref( attach );
726 } 726 }
727 } 727 }
728 break; 728 break;
729 } 729 }
730 case Alarm::Display: 730 case Alarm::Display:
731 action = ICAL_ACTION_DISPLAY; 731 action = ICAL_ACTION_DISPLAY;
732 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 732 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
733 break; 733 break;
734 case Alarm::Invalid: 734 case Alarm::Invalid:
735 default: 735 default:
736 kdDebug(5800) << "Unknown type of alarm" << endl; 736 kdDebug(5800) << "Unknown type of alarm" << endl;
737 action = ICAL_ACTION_NONE; 737 action = ICAL_ACTION_NONE;
738 break; 738 break;
739 } 739 }
740 icalcomponent_add_property(a,icalproperty_new_action(action)); 740 icalcomponent_add_property(a,icalproperty_new_action(action));
741 741
742 // Trigger time 742 // Trigger time
743 icaltriggertype trigger; 743 icaltriggertype trigger;
744 if ( alarm->hasTime() ) { 744 if ( alarm->hasTime() ) {
745 trigger.time = writeICalDateTime(alarm->time()); 745 trigger.time = writeICalDateTime(alarm->time());
746 trigger.duration = icaldurationtype_null_duration(); 746 trigger.duration = icaldurationtype_null_duration();
747 } else { 747 } else {
748 trigger.time = icaltime_null_time(); 748 trigger.time = icaltime_null_time();
749 Duration offset; 749 Duration offset;
750 if ( alarm->hasStartOffset() ) 750 if ( alarm->hasStartOffset() )
751 offset = alarm->startOffset(); 751 offset = alarm->startOffset();
752 else 752 else
753 offset = alarm->endOffset(); 753 offset = alarm->endOffset();
754 trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); 754 trigger.duration = icaldurationtype_from_int( offset.asSeconds() );
755 } 755 }
756 icalproperty *p = icalproperty_new_trigger(trigger); 756 icalproperty *p = icalproperty_new_trigger(trigger);
757 if ( alarm->hasEndOffset() ) 757 if ( alarm->hasEndOffset() )
758 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); 758 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
759 icalcomponent_add_property(a,p); 759 icalcomponent_add_property(a,p);
760 760
761 // Repeat count and duration 761 // Repeat count and duration
762 if (alarm->repeatCount()) { 762 if (alarm->repeatCount()) {
763 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); 763 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount()));
764 icalcomponent_add_property(a,icalproperty_new_duration( 764 icalcomponent_add_property(a,icalproperty_new_duration(
765 icaldurationtype_from_int(alarm->snoozeTime()*60))); 765 icaldurationtype_from_int(alarm->snoozeTime()*60)));
766 } 766 }
767 767
768 // Custom properties 768 // Custom properties
769 QMap<QCString, QString> custom = alarm->customProperties(); 769 QMap<QCString, QString> custom = alarm->customProperties();
770 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 770 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
771 icalproperty *p = icalproperty_new_x(c.data().utf8()); 771 icalproperty *p = icalproperty_new_x(c.data().utf8());
772 icalproperty_set_x_name(p,c.key()); 772 icalproperty_set_x_name(p,c.key());
773 icalcomponent_add_property(a,p); 773 icalcomponent_add_property(a,p);
774 } 774 }
775 775
776 return a; 776 return a;
777} 777}
778 778
779Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) 779Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
780{ 780{
781 Todo *todo = new Todo; 781 Todo *todo = new Todo;
782 782
783 readIncidence(vtodo,todo); 783 readIncidence(vtodo,todo);
784 784
785 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); 785 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
786 786
787// int intvalue; 787// int intvalue;
788 icaltimetype icaltime; 788 icaltimetype icaltime;
789 789
790 QStringList categories; 790 QStringList categories;
791 791
792 while (p) { 792 while (p) {
793 icalproperty_kind kind = icalproperty_isa(p); 793 icalproperty_kind kind = icalproperty_isa(p);
794 switch (kind) { 794 switch (kind) {
795 795
796 case ICAL_DUE_PROPERTY: // due date 796 case ICAL_DUE_PROPERTY: // due date
797 icaltime = icalproperty_get_due(p); 797 icaltime = icalproperty_get_due(p);
798 if (icaltime.is_date) { 798 if (icaltime.is_date) {
799 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 799 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
800 todo->setFloats(true); 800 todo->setFloats(true);
801 801
802 } else { 802 } else {
803 todo->setDtDue(readICalDateTime(icaltime)); 803 todo->setDtDue(readICalDateTime(icaltime));
804 todo->setFloats(false); 804 todo->setFloats(false);
805 } 805 }
806 todo->setHasDueDate(true); 806 todo->setHasDueDate(true);
807 break; 807 break;
808 808
809 case ICAL_COMPLETED_PROPERTY: // completion date 809 case ICAL_COMPLETED_PROPERTY: // completion date
810 icaltime = icalproperty_get_completed(p); 810 icaltime = icalproperty_get_completed(p);
811 todo->setCompleted(readICalDateTime(icaltime)); 811 todo->setCompleted(readICalDateTime(icaltime));
812 break; 812 break;
813 813
814 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed 814 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
815 todo->setPercentComplete(icalproperty_get_percentcomplete(p)); 815 todo->setPercentComplete(icalproperty_get_percentcomplete(p));
816 break; 816 break;
817 817
818 case ICAL_RELATEDTO_PROPERTY: // related todo (parent) 818 case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
819 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 819 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
820 mTodosRelate.append(todo); 820 mTodosRelate.append(todo);
821 break; 821 break;
822 822
823 case ICAL_DTSTART_PROPERTY: 823 case ICAL_DTSTART_PROPERTY:
824 // Flag that todo has start date. Value is read in by readIncidence(). 824 // Flag that todo has start date. Value is read in by readIncidence().
825 todo->setHasStartDate(true); 825 todo->setHasStartDate(true);
826 break; 826 break;
827 827
828 default: 828 default:
829// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind 829// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind
830// << endl; 830// << endl;
831 break; 831 break;
832 } 832 }
833 833
834 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); 834 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY);
835 } 835 }
836 836
837 return todo; 837 return todo;
838} 838}
839 839
840Event *ICalFormatImpl::readEvent(icalcomponent *vevent) 840Event *ICalFormatImpl::readEvent(icalcomponent *vevent)
841{ 841{
842 Event *event = new Event; 842 Event *event = new Event;
843 event->setFloats(false); 843 event->setFloats(false);
844 844
845 readIncidence(vevent,event); 845 readIncidence(vevent,event);
846 846
847 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); 847 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY);
848 848
849// int intvalue; 849// int intvalue;
850 icaltimetype icaltime; 850 icaltimetype icaltime;
851 851
852 QStringList categories; 852 QStringList categories;
853 QString transparency; 853 QString transparency;
854 854
855 while (p) { 855 while (p) {
856 icalproperty_kind kind = icalproperty_isa(p); 856 icalproperty_kind kind = icalproperty_isa(p);
857 switch (kind) { 857 switch (kind) {
858 858
859 case ICAL_DTEND_PROPERTY: // start date and time 859 case ICAL_DTEND_PROPERTY: // start date and time
860 icaltime = icalproperty_get_dtend(p); 860 icaltime = icalproperty_get_dtend(p);
861 if (icaltime.is_date) { 861 if (icaltime.is_date) {
862 event->setFloats( true ); 862 event->setFloats( true );
863 // End date is non-inclusive 863 // End date is non-inclusive
864 QDate endDate = readICalDate( icaltime ).addDays( -1 ); 864 QDate endDate = readICalDate( icaltime ).addDays( -1 );
865 mCompat->fixFloatingEnd( endDate ); 865 mCompat->fixFloatingEnd( endDate );
866 if ( endDate < event->dtStart().date() ) { 866 if ( endDate < event->dtStart().date() ) {
867 endDate = event->dtStart().date(); 867 endDate = event->dtStart().date();
868 } 868 }
869 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); 869 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) );
870 } else { 870 } else {
871 event->setDtEnd(readICalDateTime(icaltime)); 871 event->setDtEnd(readICalDateTime(icaltime));
872 } 872 }
873 break; 873 break;
874 874
875// TODO: 875// TODO:
876 // at this point, there should be at least a start or end time. 876 // at this point, there should be at least a start or end time.
877 // fix up for events that take up no time but have a time associated 877 // fix up for events that take up no time but have a time associated
878#if 0 878#if 0
879 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 879 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
880 anEvent->setDtStart(anEvent->dtEnd()); 880 anEvent->setDtStart(anEvent->dtEnd());
881 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 881 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
882 anEvent->setDtEnd(anEvent->dtStart()); 882 anEvent->setDtEnd(anEvent->dtStart());
883#endif 883#endif
884 884
885// TODO: exdates 885// TODO: exdates
886#if 0 886#if 0
887 // recurrence exceptions 887 // recurrence exceptions
888 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { 888 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) {
889 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); 889 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo)));
890 deleteStr(s); 890 deleteStr(s);
891 } 891 }
892#endif 892#endif
893 893
894#if 0 894#if 0
895 // secrecy 895 // secrecy
896 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 896 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
897 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); 897 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo)));
898 deleteStr(s); 898 deleteStr(s);
899 } 899 }
900 else 900 else
901 anEvent->setSecrecy("PUBLIC"); 901 anEvent->setSecrecy("PUBLIC");
902 902
903 // attachments 903 // attachments
904 tmpStrList.clear(); 904 tmpStrList.clear();
905 initPropIterator(&voi, vevent); 905 initPropIterator(&voi, vevent);
906 while (moreIteration(&voi)) { 906 while (moreIteration(&voi)) {
907 vo = nextVObject(&voi); 907 vo = nextVObject(&voi);
908 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 908 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
909 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); 909 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo)));
910 deleteStr(s); 910 deleteStr(s);
911 } 911 }
912 } 912 }
913 anEvent->setAttachments(tmpStrList); 913 anEvent->setAttachments(tmpStrList);
914 914
915 // resources 915 // resources
916 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 916 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
917 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 917 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
918 deleteStr(s); 918 deleteStr(s);
919 tmpStrList.clear(); 919 tmpStrList.clear();
920 index1 = 0; 920 index1 = 0;
921 index2 = 0; 921 index2 = 0;
922 QString resource; 922 QString resource;
923 while ((index2 = resources.find(';', index1)) != -1) { 923 while ((index2 = resources.find(';', index1)) != -1) {
924 resource = resources.mid(index1, (index2 - index1)); 924 resource = resources.mid(index1, (index2 - index1));
925 tmpStrList.append(resource); 925 tmpStrList.append(resource);
926 index1 = index2; 926 index1 = index2;
927 } 927 }
928 anEvent->setResources(tmpStrList); 928 anEvent->setResources(tmpStrList);
929 } 929 }
930#endif 930#endif
931 931
932 case ICAL_RELATEDTO_PROPERTY: // releated event (parent) 932 case ICAL_RELATEDTO_PROPERTY: // releated event (parent)
933 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 933 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
934 mEventsRelate.append(event); 934 mEventsRelate.append(event);
935 break; 935 break;
936 936
937 case ICAL_TRANSP_PROPERTY: // Transparency 937 case ICAL_TRANSP_PROPERTY: // Transparency
938 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) 938 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT )
939 event->setTransparency( Event::Transparent ); 939 event->setTransparency( Event::Transparent );
940 else 940 else
941 event->setTransparency( Event::Opaque ); 941 event->setTransparency( Event::Opaque );
942 break; 942 break;
943 943
944 default: 944 default:
945// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind 945// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind
946// << endl; 946// << endl;
947 break; 947 break;
948 } 948 }
949 949
950 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); 950 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY);
951 } 951 }
952 952
953 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); 953 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT");
954 if (!msade.isNull()) { 954 if (!msade.isNull()) {
955 bool floats = (msade == QString::fromLatin1("TRUE")); 955 bool floats = (msade == QString::fromLatin1("TRUE"));
956 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; 956 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl;
957 event->setFloats(floats); 957 event->setFloats(floats);
958 if (floats) { 958 if (floats) {
959 QDateTime endDate = event->dtEnd(); 959 QDateTime endDate = event->dtEnd();
960 event->setDtEnd(endDate.addDays(-1)); 960 event->setDtEnd(endDate.addDays(-1));
961 } 961 }
962 } 962 }
963 963
964 // some stupid vCal exporters ignore the standard and use Description 964 // some stupid vCal exporters ignore the standard and use Description
965 // instead of Summary for the default field. Correct for this. 965 // instead of Summary for the default field. Correct for this.
966 if (event->summary().isEmpty() && 966 if (event->summary().isEmpty() &&
967 !(event->description().isEmpty())) { 967 !(event->description().isEmpty())) {
968 QString tmpStr = event->description().simplifyWhiteSpace(); 968 QString tmpStr = event->description().simplifyWhiteSpace();
969 event->setDescription(""); 969 event->setDescription("");
970 event->setSummary(tmpStr); 970 event->setSummary(tmpStr);
971 } 971 }
972 972
973 return event; 973 return event;
974} 974}
975 975
976FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) 976FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
977{ 977{
978 FreeBusy *freebusy = new FreeBusy; 978 FreeBusy *freebusy = new FreeBusy;
979 979
980 readIncidenceBase(vfreebusy,freebusy); 980 readIncidenceBase(vfreebusy,freebusy);
981 981
982 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); 982 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
983 983
984 icaltimetype icaltime; 984 icaltimetype icaltime;
985 icalperiodtype icalperiod; 985 icalperiodtype icalperiod;
986 QDateTime period_start, period_end; 986 QDateTime period_start, period_end;
987 987
988 while (p) { 988 while (p) {
989 icalproperty_kind kind = icalproperty_isa(p); 989 icalproperty_kind kind = icalproperty_isa(p);
990 switch (kind) { 990 switch (kind) {
991 991
992 case ICAL_DTSTART_PROPERTY: // start date and time 992 case ICAL_DTSTART_PROPERTY: // start date and time
993 icaltime = icalproperty_get_dtstart(p); 993 icaltime = icalproperty_get_dtstart(p);
994 freebusy->setDtStart(readICalDateTime(icaltime)); 994 freebusy->setDtStart(readICalDateTime(icaltime));
995 break; 995 break;
996 996
997 case ICAL_DTEND_PROPERTY: // start End Date and Time 997 case ICAL_DTEND_PROPERTY: // start End Date and Time
998 icaltime = icalproperty_get_dtend(p); 998 icaltime = icalproperty_get_dtend(p);
999 freebusy->setDtEnd(readICalDateTime(icaltime)); 999 freebusy->setDtEnd(readICalDateTime(icaltime));
1000 break; 1000 break;
1001 1001
1002 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times 1002 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times
1003 icalperiod = icalproperty_get_freebusy(p); 1003 icalperiod = icalproperty_get_freebusy(p);
1004 period_start = readICalDateTime(icalperiod.start); 1004 period_start = readICalDateTime(icalperiod.start);
1005 period_end = readICalDateTime(icalperiod.end); 1005 period_end = readICalDateTime(icalperiod.end);
1006 freebusy->addPeriod(period_start, period_end); 1006 freebusy->addPeriod(period_start, period_end);
1007 break; 1007 break;
1008 1008
1009 default: 1009 default:
1010 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1010 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1011 << endl; 1011 << endl;
1012 break; 1012 break;
1013 } 1013 }
1014 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); 1014 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1015 } 1015 }
1016 1016
1017 return freebusy; 1017 return freebusy;
1018} 1018}
1019 1019
1020Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) 1020Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1021{ 1021{
1022 Journal *journal = new Journal; 1022 Journal *journal = new Journal;
1023 1023
1024 readIncidence(vjournal,journal); 1024 readIncidence(vjournal,journal);
1025 1025
1026 if ( !journal->dtStart().isValid() && journal->created().isValid() ) {
1027 journal->setDtStart( journal->created() );
1028 }
1026 return journal; 1029 return journal;
1027} 1030}
1028 1031
1029Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1032Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1030{ 1033{
1031 icalparameter *p = 0; 1034 icalparameter *p = 0;
1032 1035
1033 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1036 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1034 1037
1035 QString name; 1038 QString name;
1036 QString uid = QString::null; 1039 QString uid = QString::null;
1037 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1040 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1038 if (p) { 1041 if (p) {
1039 name = QString::fromUtf8(icalparameter_get_cn(p)); 1042 name = QString::fromUtf8(icalparameter_get_cn(p));
1040 } else { 1043 } else {
1041 } 1044 }
1042 1045
1043 bool rsvp=false; 1046 bool rsvp=false;
1044 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1047 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1045 if (p) { 1048 if (p) {
1046 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1049 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1047 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1050 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1048 } 1051 }
1049 1052
1050 Attendee::PartStat status = Attendee::NeedsAction; 1053 Attendee::PartStat status = Attendee::NeedsAction;
1051 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1054 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1052 if (p) { 1055 if (p) {
1053 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1056 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1054 switch(partStatParameter) { 1057 switch(partStatParameter) {
1055 default: 1058 default:
1056 case ICAL_PARTSTAT_NEEDSACTION: 1059 case ICAL_PARTSTAT_NEEDSACTION:
1057 status = Attendee::NeedsAction; 1060 status = Attendee::NeedsAction;
1058 break; 1061 break;
1059 case ICAL_PARTSTAT_ACCEPTED: 1062 case ICAL_PARTSTAT_ACCEPTED:
1060 status = Attendee::Accepted; 1063 status = Attendee::Accepted;
1061 break; 1064 break;
1062 case ICAL_PARTSTAT_DECLINED: 1065 case ICAL_PARTSTAT_DECLINED:
1063 status = Attendee::Declined; 1066 status = Attendee::Declined;
1064 break; 1067 break;
1065 case ICAL_PARTSTAT_TENTATIVE: 1068 case ICAL_PARTSTAT_TENTATIVE:
1066 status = Attendee::Tentative; 1069 status = Attendee::Tentative;
1067 break; 1070 break;
1068 case ICAL_PARTSTAT_DELEGATED: 1071 case ICAL_PARTSTAT_DELEGATED:
1069 status = Attendee::Delegated; 1072 status = Attendee::Delegated;
1070 break; 1073 break;
1071 case ICAL_PARTSTAT_COMPLETED: 1074 case ICAL_PARTSTAT_COMPLETED:
1072 status = Attendee::Completed; 1075 status = Attendee::Completed;
1073 break; 1076 break;
1074 case ICAL_PARTSTAT_INPROCESS: 1077 case ICAL_PARTSTAT_INPROCESS:
1075 status = Attendee::InProcess; 1078 status = Attendee::InProcess;
1076 break; 1079 break;
1077 } 1080 }
1078 } 1081 }
1079 1082
1080 Attendee::Role role = Attendee::ReqParticipant; 1083 Attendee::Role role = Attendee::ReqParticipant;
1081 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1084 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1082 if (p) { 1085 if (p) {
1083 icalparameter_role roleParameter = icalparameter_get_role(p); 1086 icalparameter_role roleParameter = icalparameter_get_role(p);
1084 switch(roleParameter) { 1087 switch(roleParameter) {
1085 case ICAL_ROLE_CHAIR: 1088 case ICAL_ROLE_CHAIR:
1086 role = Attendee::Chair; 1089 role = Attendee::Chair;
1087 break; 1090 break;
1088 default: 1091 default:
1089 case ICAL_ROLE_REQPARTICIPANT: 1092 case ICAL_ROLE_REQPARTICIPANT:
1090 role = Attendee::ReqParticipant; 1093 role = Attendee::ReqParticipant;
1091 break; 1094 break;
1092 case ICAL_ROLE_OPTPARTICIPANT: 1095 case ICAL_ROLE_OPTPARTICIPANT:
1093 role = Attendee::OptParticipant; 1096 role = Attendee::OptParticipant;
1094 break; 1097 break;
1095 case ICAL_ROLE_NONPARTICIPANT: 1098 case ICAL_ROLE_NONPARTICIPANT:
1096 role = Attendee::NonParticipant; 1099 role = Attendee::NonParticipant;
1097 break; 1100 break;
1098 } 1101 }
1099 } 1102 }
1100 1103
1101 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1104 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1102 uid = icalparameter_get_xvalue(p); 1105 uid = icalparameter_get_xvalue(p);
1103 // This should be added, but there seems to be a libical bug here. 1106 // This should be added, but there seems to be a libical bug here.
1104 /*while (p) { 1107 /*while (p) {
1105 // if (icalparameter_get_xname(p) == "X-UID") { 1108 // if (icalparameter_get_xname(p) == "X-UID") {
1106 uid = icalparameter_get_xvalue(p); 1109 uid = icalparameter_get_xvalue(p);
1107 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1110 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1108 } */ 1111 } */
1109 1112
1110 return new Attendee( name, email, rsvp, status, role, uid ); 1113 return new Attendee( name, email, rsvp, status, role, uid );
1111} 1114}
1112 1115
1113Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1116Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1114{ 1117{
1115 icalattach *a = icalproperty_get_attach(attach); 1118 icalattach *a = icalproperty_get_attach(attach);
1116 icalparameter_value v = ICAL_VALUE_NONE; 1119 icalparameter_value v = ICAL_VALUE_NONE;
1117 icalparameter_encoding e = ICAL_ENCODING_NONE; 1120 icalparameter_encoding e = ICAL_ENCODING_NONE;
1118 1121
1119 Attachment *attachment = 0; 1122 Attachment *attachment = 0;
1120 /* 1123 /*
1121 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1124 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1122 if (vp) 1125 if (vp)
1123 v = icalparameter_get_value(vp); 1126 v = icalparameter_get_value(vp);
1124 1127
1125 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1128 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1126 if (ep) 1129 if (ep)
1127 e = icalparameter_get_encoding(ep); 1130 e = icalparameter_get_encoding(ep);
1128 */ 1131 */
1129 int isurl = icalattach_get_is_url (a); 1132 int isurl = icalattach_get_is_url (a);
1130 if (isurl == 0) 1133 if (isurl == 0)
1131 attachment = new Attachment((const char*)icalattach_get_data(a)); 1134 attachment = new Attachment((const char*)icalattach_get_data(a));
1132 else { 1135 else {
1133 attachment = new Attachment(QString(icalattach_get_url(a))); 1136 attachment = new Attachment(QString(icalattach_get_url(a)));
1134 } 1137 }
1135 1138
1136 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1139 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1137 if (p) 1140 if (p)
1138 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1141 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1139 1142
1140 return attachment; 1143 return attachment;
1141} 1144}
1142#include <qtextcodec.h> 1145#include <qtextcodec.h>
1143void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1146void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1144{ 1147{
1145 readIncidenceBase(parent,incidence); 1148 readIncidenceBase(parent,incidence);
1146 1149
1147 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1150 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1148 bool readrec = false; 1151 bool readrec = false;
1149 const char *text; 1152 const char *text;
1150 int intvalue; 1153 int intvalue;
1151 icaltimetype icaltime; 1154 icaltimetype icaltime;
1152 icaldurationtype icalduration; 1155 icaldurationtype icalduration;
1153 struct icalrecurrencetype rectype; 1156 struct icalrecurrencetype rectype;
1154 QStringList categories; 1157 QStringList categories;
1155 1158
1156 while (p) { 1159 while (p) {
1157 icalproperty_kind kind = icalproperty_isa(p); 1160 icalproperty_kind kind = icalproperty_isa(p);
1158 switch (kind) { 1161 switch (kind) {
1159 1162
1160 case ICAL_CREATED_PROPERTY: 1163 case ICAL_CREATED_PROPERTY:
1161 icaltime = icalproperty_get_created(p); 1164 icaltime = icalproperty_get_created(p);
1162 incidence->setCreated(readICalDateTime(icaltime)); 1165 incidence->setCreated(readICalDateTime(icaltime));
1163 break; 1166 break;
1164 1167
1165 case ICAL_SEQUENCE_PROPERTY: // sequence 1168 case ICAL_SEQUENCE_PROPERTY: // sequence
1166 intvalue = icalproperty_get_sequence(p); 1169 intvalue = icalproperty_get_sequence(p);
1167 incidence->setRevision(intvalue); 1170 incidence->setRevision(intvalue);
1168 break; 1171 break;
1169 1172
1170 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1173 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1171 icaltime = icalproperty_get_lastmodified(p); 1174 icaltime = icalproperty_get_lastmodified(p);
1172 incidence->setLastModified(readICalDateTime(icaltime)); 1175 incidence->setLastModified(readICalDateTime(icaltime));
1173 break; 1176 break;
1174 1177
1175 case ICAL_DTSTART_PROPERTY: // start date and time 1178 case ICAL_DTSTART_PROPERTY: // start date and time
1176 icaltime = icalproperty_get_dtstart(p); 1179 icaltime = icalproperty_get_dtstart(p);
1177 if (icaltime.is_date) { 1180 if (icaltime.is_date) {
1178 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1181 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1179 incidence->setFloats(true); 1182 incidence->setFloats(true);
1180 } else { 1183 } else {
1181 incidence->setDtStart(readICalDateTime(icaltime)); 1184 incidence->setDtStart(readICalDateTime(icaltime));
1182 } 1185 }
1183 break; 1186 break;
1184 1187
1185 case ICAL_DURATION_PROPERTY: // start date and time 1188 case ICAL_DURATION_PROPERTY: // start date and time
1186 icalduration = icalproperty_get_duration(p); 1189 icalduration = icalproperty_get_duration(p);
1187 incidence->setDuration(readICalDuration(icalduration)); 1190 incidence->setDuration(readICalDuration(icalduration));
1188 break; 1191 break;
1189 1192
1190 case ICAL_DESCRIPTION_PROPERTY: // description 1193 case ICAL_DESCRIPTION_PROPERTY: // description
1191 text = icalproperty_get_description(p); 1194 text = icalproperty_get_description(p);
1192 incidence->setDescription(QString::fromUtf8(text)); 1195 incidence->setDescription(QString::fromUtf8(text));
1193 break; 1196 break;
1194 1197
1195 case ICAL_SUMMARY_PROPERTY: // summary 1198 case ICAL_SUMMARY_PROPERTY: // summary
1196 { 1199 {
1197 text = icalproperty_get_summary(p); 1200 text = icalproperty_get_summary(p);
1198 incidence->setSummary(QString::fromUtf8(text)); 1201 incidence->setSummary(QString::fromUtf8(text));
1199 } 1202 }
1200 break; 1203 break;
1201 case ICAL_STATUS_PROPERTY: // summary 1204 case ICAL_STATUS_PROPERTY: // summary
1202 { 1205 {
1203 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1206 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1204 incidence->setCancelled( true ); 1207 incidence->setCancelled( true );
1205 } 1208 }
1206 break; 1209 break;
1207 1210
1208 case ICAL_LOCATION_PROPERTY: // location 1211 case ICAL_LOCATION_PROPERTY: // location
1209 text = icalproperty_get_location(p); 1212 text = icalproperty_get_location(p);
1210 incidence->setLocation(QString::fromUtf8(text)); 1213 incidence->setLocation(QString::fromUtf8(text));
1211 break; 1214 break;
1212 1215
1213 case ICAL_RECURRENCEID_PROPERTY: 1216 case ICAL_RECURRENCEID_PROPERTY:
1214 icaltime = icalproperty_get_recurrenceid(p); 1217 icaltime = icalproperty_get_recurrenceid(p);
1215 incidence->setRecurrenceID( readICalDateTime(icaltime) ); 1218 incidence->setRecurrenceID( readICalDateTime(icaltime) );
1216 //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() ); 1219 //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() );
1217 break; 1220 break;
1218#if 0 1221#if 0
1219 // status 1222 // status
1220 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1223 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1221 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1224 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1222 deleteStr(s); 1225 deleteStr(s);
1223 } 1226 }
1224 else 1227 else
1225 incidence->setStatus("NEEDS ACTION"); 1228 incidence->setStatus("NEEDS ACTION");
1226#endif 1229#endif
1227 1230
1228 case ICAL_PRIORITY_PROPERTY: // priority 1231 case ICAL_PRIORITY_PROPERTY: // priority
1229 intvalue = icalproperty_get_priority(p); 1232 intvalue = icalproperty_get_priority(p);
1230 incidence->setPriority(intvalue); 1233 incidence->setPriority(intvalue);
1231 break; 1234 break;
1232 1235
1233 case ICAL_CATEGORIES_PROPERTY: // categories 1236 case ICAL_CATEGORIES_PROPERTY: // categories
1234 text = icalproperty_get_categories(p); 1237 text = icalproperty_get_categories(p);
1235 categories.append(QString::fromUtf8(text)); 1238 categories.append(QString::fromUtf8(text));
1236 break; 1239 break;
1237 //******************************************* 1240 //*******************************************
1238 case ICAL_RRULE_PROPERTY: 1241 case ICAL_RRULE_PROPERTY:
1239 // we do need (maybe )start datetime of incidence for recurrence 1242 // we do need (maybe )start datetime of incidence for recurrence
1240 // such that we can read recurrence only after we read incidence completely 1243 // such that we can read recurrence only after we read incidence completely
1241 readrec = true; 1244 readrec = true;
1242 rectype = icalproperty_get_rrule(p); 1245 rectype = icalproperty_get_rrule(p);
1243 break; 1246 break;
1244 1247
1245 case ICAL_EXDATE_PROPERTY: 1248 case ICAL_EXDATE_PROPERTY:
1246 icaltime = icalproperty_get_exdate(p); 1249 icaltime = icalproperty_get_exdate(p);
1247 incidence->addExDate(readICalDate(icaltime)); 1250 incidence->addExDate(readICalDate(icaltime));
1248 break; 1251 break;
1249 1252
1250 case ICAL_CLASS_PROPERTY: { 1253 case ICAL_CLASS_PROPERTY: {
1251 int inttext = icalproperty_get_class(p); 1254 int inttext = icalproperty_get_class(p);
1252 if (inttext == ICAL_CLASS_PUBLIC ) { 1255 if (inttext == ICAL_CLASS_PUBLIC ) {
1253 incidence->setSecrecy(Incidence::SecrecyPublic); 1256 incidence->setSecrecy(Incidence::SecrecyPublic);
1254 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1257 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1255 incidence->setSecrecy(Incidence::SecrecyConfidential); 1258 incidence->setSecrecy(Incidence::SecrecyConfidential);
1256 } else { 1259 } else {
1257 incidence->setSecrecy(Incidence::SecrecyPrivate); 1260 incidence->setSecrecy(Incidence::SecrecyPrivate);
1258 } 1261 }
1259 } 1262 }
1260 break; 1263 break;
1261 1264
1262 case ICAL_ATTACH_PROPERTY: // attachments 1265 case ICAL_ATTACH_PROPERTY: // attachments
1263 incidence->addAttachment(readAttachment(p)); 1266 incidence->addAttachment(readAttachment(p));
1264 break; 1267 break;
1265 1268
1266 default: 1269 default:
1267// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1270// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1268// << endl; 1271// << endl;
1269 break; 1272 break;
1270 } 1273 }
1271 1274
1272 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1275 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1273 } 1276 }
1274 if ( readrec ) { 1277 if ( readrec ) {
1275 readRecurrenceRule(rectype,incidence); 1278 readRecurrenceRule(rectype,incidence);
1276 } 1279 }
1277 // kpilot stuff 1280 // kpilot stuff
1278// TODO: move this application-specific code to kpilot 1281// TODO: move this application-specific code to kpilot
1279 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1282 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1280 if (!kp.isNull()) { 1283 if (!kp.isNull()) {
1281 incidence->setPilotId(kp.toInt()); 1284 incidence->setPilotId(kp.toInt());
1282 } 1285 }
1283 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1286 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1284 if (!kp.isNull()) { 1287 if (!kp.isNull()) {
1285 incidence->setSyncStatus(kp.toInt()); 1288 incidence->setSyncStatus(kp.toInt());
1286 } 1289 }
1287 1290
1288 1291
1289 kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); 1292 kp = incidence->nonKDECustomProperty("X-KOPIEXTID");
1290 if (!kp.isNull()) { 1293 if (!kp.isNull()) {
1291 incidence->setIDStr(kp); 1294 incidence->setIDStr(kp);
1292 } 1295 }
1293 1296
1294 // Cancel backwards compatibility mode for subsequent changes by the application 1297 // Cancel backwards compatibility mode for subsequent changes by the application
1295 incidence->recurrence()->setCompatVersion(); 1298 incidence->recurrence()->setCompatVersion();
1296 1299
1297 // add categories 1300 // add categories
1298 incidence->setCategories(categories); 1301 incidence->setCategories(categories);
1299 1302
1300 // iterate through all alarms 1303 // iterate through all alarms
1301 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1304 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1302 alarm; 1305 alarm;
1303 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1306 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1304 readAlarm(alarm,incidence); 1307 readAlarm(alarm,incidence);
1305 } 1308 }
1306} 1309}
1307 1310
1308void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1311void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1309{ 1312{
1310 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1313 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1311 1314
1312 while (p) { 1315 while (p) {
1313 icalproperty_kind kind = icalproperty_isa(p); 1316 icalproperty_kind kind = icalproperty_isa(p);
1314 switch (kind) { 1317 switch (kind) {
1315 1318
1316 case ICAL_UID_PROPERTY: // unique id 1319 case ICAL_UID_PROPERTY: // unique id
1317 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1320 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1318 break; 1321 break;
1319 1322
1320 case ICAL_ORGANIZER_PROPERTY: // organizer 1323 case ICAL_ORGANIZER_PROPERTY: // organizer
1321 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1324 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1322 break; 1325 break;
1323 1326
1324 case ICAL_ATTENDEE_PROPERTY: // attendee 1327 case ICAL_ATTENDEE_PROPERTY: // attendee
1325 incidenceBase->addAttendee(readAttendee(p)); 1328 incidenceBase->addAttendee(readAttendee(p));
1326 break; 1329 break;
1327 1330
1328 default: 1331 default:
1329 break; 1332 break;
1330 } 1333 }
1331 1334
1332 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1335 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1333 } 1336 }
1334 1337
1335 // custom properties 1338 // custom properties
1336 readCustomProperties(parent, incidenceBase); 1339 readCustomProperties(parent, incidenceBase);
1337} 1340}
1338 1341
1339void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1342void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1340{ 1343{
1341 QMap<QCString, QString> customProperties; 1344 QMap<QCString, QString> customProperties;
1342 1345
1343 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1346 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1344 1347
1345 while (p) { 1348 while (p) {
1346 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1349 QString value = QString::fromUtf8(icalproperty_get_x(p));
1347 customProperties[icalproperty_get_x_name(p)] = value; 1350 customProperties[icalproperty_get_x_name(p)] = value;
1348 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1351 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1349 1352
1350 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1353 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1351 } 1354 }
1352 1355
1353 properties->setCustomProperties(customProperties); 1356 properties->setCustomProperties(customProperties);
1354} 1357}
1355 1358
1356void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1359void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1357{ 1360{
1358// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1361// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1359 1362
1360 Recurrence *recur = incidence->recurrence(); 1363 Recurrence *recur = incidence->recurrence();
1361 recur->setCompatVersion(mCalendarVersion); 1364 recur->setCompatVersion(mCalendarVersion);
1362 recur->unsetRecurs(); 1365 recur->unsetRecurs();
1363 1366
1364 struct icalrecurrencetype r = rrule; 1367 struct icalrecurrencetype r = rrule;
1365 1368
1366 dumpIcalRecurrence(r); 1369 dumpIcalRecurrence(r);
1367 readRecurrence( r, recur, incidence); 1370 readRecurrence( r, recur, incidence);
1368} 1371}
1369 1372
1370void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1373void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1371{ 1374{
1372 int wkst; 1375 int wkst;
1373 int index = 0; 1376 int index = 0;
1374 short day = 0; 1377 short day = 0;
1375 QBitArray qba(7); 1378 QBitArray qba(7);
1376 int frequ = r.freq; 1379 int frequ = r.freq;
1377 int interv = r.interval; 1380 int interv = r.interval;
1378 // preprocessing for odd recurrence definitions 1381 // preprocessing for odd recurrence definitions
1379 1382
1380 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1383 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1381 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1384 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1382 interv = 12; 1385 interv = 12;
1383 } 1386 }
1384 } 1387 }
1385 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1388 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1386 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1389 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1387 frequ = ICAL_MONTHLY_RECURRENCE; 1390 frequ = ICAL_MONTHLY_RECURRENCE;
1388 interv = 12* r.interval; 1391 interv = 12* r.interval;
1389 } 1392 }
1390 } 1393 }
1391 1394
1392 switch (frequ) { 1395 switch (frequ) {
1393 case ICAL_MINUTELY_RECURRENCE: 1396 case ICAL_MINUTELY_RECURRENCE:
1394 if (!icaltime_is_null_time(r.until)) { 1397 if (!icaltime_is_null_time(r.until)) {
1395 recur->setMinutely(interv,readICalDateTime(r.until)); 1398 recur->setMinutely(interv,readICalDateTime(r.until));
1396 } else { 1399 } else {
1397 if (r.count == 0) 1400 if (r.count == 0)
1398 recur->setMinutely(interv,-1); 1401 recur->setMinutely(interv,-1);
1399 else 1402 else
1400 recur->setMinutely(interv,r.count); 1403 recur->setMinutely(interv,r.count);
1401 } 1404 }
1402 break; 1405 break;
1403 case ICAL_HOURLY_RECURRENCE: 1406 case ICAL_HOURLY_RECURRENCE:
1404 if (!icaltime_is_null_time(r.until)) { 1407 if (!icaltime_is_null_time(r.until)) {
1405 recur->setHourly(interv,readICalDateTime(r.until)); 1408 recur->setHourly(interv,readICalDateTime(r.until));
1406 } else { 1409 } else {
1407 if (r.count == 0) 1410 if (r.count == 0)
1408 recur->setHourly(interv,-1); 1411 recur->setHourly(interv,-1);
1409 else 1412 else
1410 recur->setHourly(interv,r.count); 1413 recur->setHourly(interv,r.count);
1411 } 1414 }
1412 break; 1415 break;
1413 case ICAL_DAILY_RECURRENCE: 1416 case ICAL_DAILY_RECURRENCE:
1414 if (!icaltime_is_null_time(r.until)) { 1417 if (!icaltime_is_null_time(r.until)) {
1415 recur->setDaily(interv,readICalDate(r.until)); 1418 recur->setDaily(interv,readICalDate(r.until));
1416 } else { 1419 } else {
1417 if (r.count == 0) 1420 if (r.count == 0)
1418 recur->setDaily(interv,-1); 1421 recur->setDaily(interv,-1);
1419 else 1422 else
1420 recur->setDaily(interv,r.count); 1423 recur->setDaily(interv,r.count);
1421 } 1424 }
1422 break; 1425 break;
1423 case ICAL_WEEKLY_RECURRENCE: 1426 case ICAL_WEEKLY_RECURRENCE:
1424 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1427 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1425 wkst = (r.week_start + 5)%7 + 1; 1428 wkst = (r.week_start + 5)%7 + 1;
1426 if (!icaltime_is_null_time(r.until)) { 1429 if (!icaltime_is_null_time(r.until)) {
1427 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1430 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1428 } else { 1431 } else {
1429 if (r.count == 0) 1432 if (r.count == 0)
1430 recur->setWeekly(interv,qba,-1,wkst); 1433 recur->setWeekly(interv,qba,-1,wkst);
1431 else 1434 else
1432 recur->setWeekly(interv,qba,r.count,wkst); 1435 recur->setWeekly(interv,qba,r.count,wkst);
1433 } 1436 }
1434 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1437 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1435 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1438 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1436 //qDebug("weekly error found "); 1439 //qDebug("weekly error found ");
1437 qba.setBit(wday); 1440 qba.setBit(wday);
1438 } else { 1441 } else {
1439 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1442 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1440 // kdDebug(5800) << " " << day << endl; 1443 // kdDebug(5800) << " " << day << endl;
1441 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1444 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1442 } 1445 }
1443 } 1446 }
1444 break; 1447 break;
1445 case ICAL_MONTHLY_RECURRENCE: 1448 case ICAL_MONTHLY_RECURRENCE:
1446 1449
1447 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1450 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1448 if (!icaltime_is_null_time(r.until)) { 1451 if (!icaltime_is_null_time(r.until)) {
1449 recur->setMonthly(Recurrence::rMonthlyPos,interv, 1452 recur->setMonthly(Recurrence::rMonthlyPos,interv,
1450 readICalDate(r.until)); 1453 readICalDate(r.until));
1451 } else { 1454 } else {
1452 if (r.count == 0) 1455 if (r.count == 0)
1453 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); 1456 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1);
1454 else 1457 else
1455 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); 1458 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count);
1456 } 1459 }
1457 bool useSetPos = false; 1460 bool useSetPos = false;
1458 short pos = 0; 1461 short pos = 0;
1459 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1462 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1460 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1463 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1461 pos = icalrecurrencetype_day_position(day); 1464 pos = icalrecurrencetype_day_position(day);
1462 if (pos) { 1465 if (pos) {
1463 day = icalrecurrencetype_day_day_of_week(day); 1466 day = icalrecurrencetype_day_day_of_week(day);
1464 QBitArray ba(7); // don't wipe qba 1467 QBitArray ba(7); // don't wipe qba
1465 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1468 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1466 recur->addMonthlyPos(pos,ba); 1469 recur->addMonthlyPos(pos,ba);
1467 } else { 1470 } else {
1468 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1471 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1469 useSetPos = true; 1472 useSetPos = true;
1470 } 1473 }
1471 } 1474 }
1472 if (useSetPos) { 1475 if (useSetPos) {
1473 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1476 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1474 recur->addMonthlyPos(r.by_set_pos[0],qba); 1477 recur->addMonthlyPos(r.by_set_pos[0],qba);
1475 } 1478 }
1476 } 1479 }
1477 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1480 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1478 if (!icaltime_is_null_time(r.until)) { 1481 if (!icaltime_is_null_time(r.until)) {
1479 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1482 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1480 readICalDate(r.until)); 1483 readICalDate(r.until));
1481 } else { 1484 } else {
1482 if (r.count == 0) 1485 if (r.count == 0)
1483 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1486 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1484 else 1487 else
1485 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1488 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1486 } 1489 }
1487 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1490 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1488 // kdDebug(5800) << "----b " << day << endl; 1491 // kdDebug(5800) << "----b " << day << endl;
1489 recur->addMonthlyDay(day); 1492 recur->addMonthlyDay(day);
1490 } 1493 }
1491 } 1494 }
1492 break; 1495 break;
1493 case ICAL_YEARLY_RECURRENCE: 1496 case ICAL_YEARLY_RECURRENCE:
1494 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1497 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1495 //qDebug(" YEARLY DAY OF YEAR"); 1498 //qDebug(" YEARLY DAY OF YEAR");
1496 if (!icaltime_is_null_time(r.until)) { 1499 if (!icaltime_is_null_time(r.until)) {
1497 recur->setYearly(Recurrence::rYearlyDay,interv, 1500 recur->setYearly(Recurrence::rYearlyDay,interv,
1498 readICalDate(r.until)); 1501 readICalDate(r.until));
1499 } else { 1502 } else {
1500 if (r.count == 0) 1503 if (r.count == 0)
1501 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1504 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1502 else 1505 else
1503 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1506 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1504 } 1507 }
1505 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1508 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1506 recur->addYearlyNum(day); 1509 recur->addYearlyNum(day);
1507 } 1510 }
1508 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1511 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1509 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1512 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1510 qDebug("YEARLY POS NOT SUPPORTED BY GUI"); 1513 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1511 if (!icaltime_is_null_time(r.until)) { 1514 if (!icaltime_is_null_time(r.until)) {
1512 recur->setYearly(Recurrence::rYearlyPos,interv, 1515 recur->setYearly(Recurrence::rYearlyPos,interv,
1513 readICalDate(r.until)); 1516 readICalDate(r.until));
1514 } else { 1517 } else {
1515 if (r.count == 0) 1518 if (r.count == 0)
1516 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1519 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1517 else 1520 else
1518 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1521 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1519 } 1522 }
1520 bool useSetPos = false; 1523 bool useSetPos = false;
1521 short pos = 0; 1524 short pos = 0;
1522 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1525 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1523 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1526 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1524 pos = icalrecurrencetype_day_position(day); 1527 pos = icalrecurrencetype_day_position(day);
1525 if (pos) { 1528 if (pos) {
1526 day = icalrecurrencetype_day_day_of_week(day); 1529 day = icalrecurrencetype_day_day_of_week(day);
1527 QBitArray ba(7); // don't wipe qba 1530 QBitArray ba(7); // don't wipe qba
1528 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1531 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1529 recur->addYearlyMonthPos(pos,ba); 1532 recur->addYearlyMonthPos(pos,ba);
1530 } else { 1533 } else {
1531 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1534 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1532 useSetPos = true; 1535 useSetPos = true;
1533 } 1536 }
1534 } 1537 }
1535 if (useSetPos) { 1538 if (useSetPos) {
1536 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1539 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1537 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1540 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1538 } 1541 }
1539 } 1542 }
1540 } else { 1543 } else {
1541 //qDebug("YEARLY MONTH "); 1544 //qDebug("YEARLY MONTH ");
1542 if (!icaltime_is_null_time(r.until)) { 1545 if (!icaltime_is_null_time(r.until)) {
1543 recur->setYearly(Recurrence::rYearlyMonth,interv, 1546 recur->setYearly(Recurrence::rYearlyMonth,interv,
1544 readICalDate(r.until)); 1547 readICalDate(r.until));
1545 } else { 1548 } else {
1546 if (r.count == 0) 1549 if (r.count == 0)
1547 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1550 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
1548 else 1551 else
1549 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); 1552 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
1550 } 1553 }
1551 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1554 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1552 index = 0; 1555 index = 0;
1553 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1556 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1554 recur->addYearlyNum(day); 1557 recur->addYearlyNum(day);
1555 } 1558 }
1556 } else { 1559 } else {
1557 recur->addYearlyNum(incidence->dtStart().date().month()); 1560 recur->addYearlyNum(incidence->dtStart().date().month());
1558 } 1561 }
1559 } 1562 }
1560 1563
1561 } 1564 }
1562 break; 1565 break;
1563 default: 1566 default:
1564 ; 1567 ;
1565 break; 1568 break;
1566 } 1569 }
1567} 1570}
1568 1571
1569void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1572void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1570{ 1573{
1571 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1574 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1572 1575
1573 Alarm* ialarm = incidence->newAlarm(); 1576 Alarm* ialarm = incidence->newAlarm();
1574 ialarm->setRepeatCount(0); 1577 ialarm->setRepeatCount(0);
1575 ialarm->setEnabled(true); 1578 ialarm->setEnabled(true);
1576 1579
1577 // Determine the alarm's action type 1580 // Determine the alarm's action type
1578 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1581 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1579 if ( !p ) { 1582 if ( !p ) {
1580 return; 1583 return;
1581 } 1584 }
1582 1585
1583 icalproperty_action action = icalproperty_get_action(p); 1586 icalproperty_action action = icalproperty_get_action(p);
1584 Alarm::Type type = Alarm::Display; 1587 Alarm::Type type = Alarm::Display;
1585 switch ( action ) { 1588 switch ( action ) {
1586 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; 1589 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break;
1587 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; 1590 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break;
1588 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; 1591 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break;
1589 case ICAL_ACTION_EMAIL: type = Alarm::Email; break; 1592 case ICAL_ACTION_EMAIL: type = Alarm::Email; break;
1590 default: 1593 default:
1591 ; 1594 ;
1592 return; 1595 return;
1593 } 1596 }
1594 ialarm->setType(type); 1597 ialarm->setType(type);
1595 1598
1596 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); 1599 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1597 while (p) { 1600 while (p) {
1598 icalproperty_kind kind = icalproperty_isa(p); 1601 icalproperty_kind kind = icalproperty_isa(p);
1599 1602
1600 switch (kind) { 1603 switch (kind) {
1601 case ICAL_TRIGGER_PROPERTY: { 1604 case ICAL_TRIGGER_PROPERTY: {
1602 icaltriggertype trigger = icalproperty_get_trigger(p); 1605 icaltriggertype trigger = icalproperty_get_trigger(p);
1603 if (icaltime_is_null_time(trigger.time)) { 1606 if (icaltime_is_null_time(trigger.time)) {
1604 if (icaldurationtype_is_null_duration(trigger.duration)) { 1607 if (icaldurationtype_is_null_duration(trigger.duration)) {
1605 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;
1606 } else { 1609 } else {
1607 Duration duration = icaldurationtype_as_int( trigger.duration ); 1610 Duration duration = icaldurationtype_as_int( trigger.duration );
1608 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); 1611 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1609 if (param && icalparameter_get_related(param) == ICAL_RELATED_END) 1612 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1610 ialarm->setEndOffset(duration); 1613 ialarm->setEndOffset(duration);
1611 else 1614 else
1612 ialarm->setStartOffset(duration); 1615 ialarm->setStartOffset(duration);
1613 } 1616 }
1614 } else { 1617 } else {
1615 ialarm->setTime(readICalDateTime(trigger.time)); 1618 ialarm->setTime(readICalDateTime(trigger.time));
1616 } 1619 }
1617 break; 1620 break;
1618 } 1621 }
1619 case ICAL_DURATION_PROPERTY: { 1622 case ICAL_DURATION_PROPERTY: {
1620 icaldurationtype duration = icalproperty_get_duration(p); 1623 icaldurationtype duration = icalproperty_get_duration(p);
1621 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); 1624 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60);
1622 break; 1625 break;
1623 } 1626 }
1624 case ICAL_REPEAT_PROPERTY: 1627 case ICAL_REPEAT_PROPERTY:
1625 ialarm->setRepeatCount(icalproperty_get_repeat(p)); 1628 ialarm->setRepeatCount(icalproperty_get_repeat(p));
1626 break; 1629 break;
1627 1630
1628 // Only in DISPLAY and EMAIL and PROCEDURE alarms 1631 // Only in DISPLAY and EMAIL and PROCEDURE alarms
1629 case ICAL_DESCRIPTION_PROPERTY: { 1632 case ICAL_DESCRIPTION_PROPERTY: {
1630 QString description = QString::fromUtf8(icalproperty_get_description(p)); 1633 QString description = QString::fromUtf8(icalproperty_get_description(p));
1631 switch ( action ) { 1634 switch ( action ) {
1632 case ICAL_ACTION_DISPLAY: 1635 case ICAL_ACTION_DISPLAY:
1633 ialarm->setText( description ); 1636 ialarm->setText( description );
1634 break; 1637 break;
1635 case ICAL_ACTION_PROCEDURE: 1638 case ICAL_ACTION_PROCEDURE:
1636 ialarm->setProgramArguments( description ); 1639 ialarm->setProgramArguments( description );
1637 break; 1640 break;
1638 case ICAL_ACTION_EMAIL: 1641 case ICAL_ACTION_EMAIL:
1639 ialarm->setMailText( description ); 1642 ialarm->setMailText( description );
1640 break; 1643 break;
1641 default: 1644 default:
1642 break; 1645 break;
1643 } 1646 }
1644 break; 1647 break;
1645 } 1648 }
1646 // Only in EMAIL alarm 1649 // Only in EMAIL alarm
1647 case ICAL_SUMMARY_PROPERTY: 1650 case ICAL_SUMMARY_PROPERTY:
1648 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); 1651 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
1649 break; 1652 break;
1650 1653
1651 // Only in EMAIL alarm 1654 // Only in EMAIL alarm
1652 case ICAL_ATTENDEE_PROPERTY: { 1655 case ICAL_ATTENDEE_PROPERTY: {
1653 QString email = QString::fromUtf8(icalproperty_get_attendee(p)); 1656 QString email = QString::fromUtf8(icalproperty_get_attendee(p));
1654 QString name; 1657 QString name;
1655 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); 1658 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1656 if (param) { 1659 if (param) {
1657 name = QString::fromUtf8(icalparameter_get_cn(param)); 1660 name = QString::fromUtf8(icalparameter_get_cn(param));
1658 } 1661 }
1659 ialarm->addMailAddress(Person(name, email)); 1662 ialarm->addMailAddress(Person(name, email));
1660 break; 1663 break;
1661 } 1664 }
1662 // Only in AUDIO and EMAIL and PROCEDURE alarms 1665 // Only in AUDIO and EMAIL and PROCEDURE alarms
1663 case ICAL_ATTACH_PROPERTY: { 1666 case ICAL_ATTACH_PROPERTY: {
1664 icalattach *attach = icalproperty_get_attach(p); 1667 icalattach *attach = icalproperty_get_attach(p);
1665 QString url = QFile::decodeName(icalattach_get_url(attach)); 1668 QString url = QFile::decodeName(icalattach_get_url(attach));
1666 switch ( action ) { 1669 switch ( action ) {
1667 case ICAL_ACTION_AUDIO: 1670 case ICAL_ACTION_AUDIO:
1668 ialarm->setAudioFile( url ); 1671 ialarm->setAudioFile( url );
1669 break; 1672 break;
1670 case ICAL_ACTION_PROCEDURE: 1673 case ICAL_ACTION_PROCEDURE:
1671 ialarm->setProgramFile( url ); 1674 ialarm->setProgramFile( url );
1672 break; 1675 break;
1673 case ICAL_ACTION_EMAIL: 1676 case ICAL_ACTION_EMAIL:
1674 ialarm->addMailAttachment( url ); 1677 ialarm->addMailAttachment( url );
1675 break; 1678 break;
1676 default: 1679 default:
1677 break; 1680 break;
1678 } 1681 }
1679 break; 1682 break;
1680 } 1683 }
1681 default: 1684 default:
1682 break; 1685 break;
1683 } 1686 }
1684 1687
1685 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1688 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1686 } 1689 }
1687 1690
1688 // custom properties 1691 // custom properties
1689 readCustomProperties(alarm, ialarm); 1692 readCustomProperties(alarm, ialarm);
1690 1693
1691 // TODO: check for consistency of alarm properties 1694 // TODO: check for consistency of alarm properties
1692} 1695}
1693 1696
1694icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1697icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1695{ 1698{
1696 icaltimetype t; 1699 icaltimetype t;
1697 1700
1698 t.year = date.year(); 1701 t.year = date.year();
1699 t.month = date.month(); 1702 t.month = date.month();
1700 t.day = date.day(); 1703 t.day = date.day();
1701 1704
1702 t.hour = 0; 1705 t.hour = 0;
1703 t.minute = 0; 1706 t.minute = 0;
1704 t.second = 0; 1707 t.second = 0;
1705 1708
1706 t.is_date = 1; 1709 t.is_date = 1;
1707 1710
1708 t.is_utc = 0; 1711 t.is_utc = 0;
1709 1712
1710 t.zone = 0; 1713 t.zone = 0;
1711 1714
1712 return t; 1715 return t;
1713} 1716}
1714 1717
1715icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1718icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1716{ 1719{
1717 icaltimetype t; 1720 icaltimetype t;
1718 t.is_date = 0; 1721 t.is_date = 0;
1719 t.zone = 0; 1722 t.zone = 0;
1720 QDateTime datetime; 1723 QDateTime datetime;
1721 if ( mParent->utc() ) { 1724 if ( mParent->utc() ) {
1722 int offset = KGlobal::locale()->localTimeOffset( dt ); 1725 int offset = KGlobal::locale()->localTimeOffset( dt );
1723 datetime = dt.addSecs ( -offset*60); 1726 datetime = dt.addSecs ( -offset*60);
1724 t.is_utc = 1; 1727 t.is_utc = 1;
1725 } 1728 }
1726 else { 1729 else {
1727 datetime = dt; 1730 datetime = dt;
1728 t.is_utc = 0; 1731 t.is_utc = 0;
1729 1732
1730 } 1733 }
1731 t.year = datetime.date().year(); 1734 t.year = datetime.date().year();
1732 t.month = datetime.date().month(); 1735 t.month = datetime.date().month();
1733 t.day = datetime.date().day(); 1736 t.day = datetime.date().day();
1734 1737
1735 t.hour = datetime.time().hour(); 1738 t.hour = datetime.time().hour();
1736 t.minute = datetime.time().minute(); 1739 t.minute = datetime.time().minute();
1737 t.second = datetime.time().second(); 1740 t.second = datetime.time().second();
1738 1741
1739 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1742 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1740 1743
1741// if ( mParent->utc() ) { 1744// if ( mParent->utc() ) {
1742// datetime = KGlobal::locale()->localTime( dt ); 1745// datetime = KGlobal::locale()->localTime( dt );
1743// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1746// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1744// if (mParent->timeZoneId().isEmpty()) 1747// if (mParent->timeZoneId().isEmpty())
1745// t = icaltime_as_utc(t, 0); 1748// t = icaltime_as_utc(t, 0);
1746// else 1749// else
1747// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1750// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1748// } 1751// }
1749 1752
1750 return t; 1753 return t;
1751} 1754}
1752 1755
1753QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1756QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1754{ 1757{
1755 QDateTime dt (QDate(t.year,t.month,t.day), 1758 QDateTime dt (QDate(t.year,t.month,t.day),
1756 QTime(t.hour,t.minute,t.second) ); 1759 QTime(t.hour,t.minute,t.second) );
1757 1760
1758 if (t.is_utc) { 1761 if (t.is_utc) {
1759 int offset = KGlobal::locale()->localTimeOffset( dt ); 1762 int offset = KGlobal::locale()->localTimeOffset( dt );
1760 dt = dt.addSecs ( offset*60); 1763 dt = dt.addSecs ( offset*60);
1761 } 1764 }
1762 1765
1763 return dt; 1766 return dt;
1764} 1767}
1765 1768
1766QDate ICalFormatImpl::readICalDate(icaltimetype t) 1769QDate ICalFormatImpl::readICalDate(icaltimetype t)
1767{ 1770{
1768 return QDate(t.year,t.month,t.day); 1771 return QDate(t.year,t.month,t.day);
1769} 1772}
1770 1773
1771icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) 1774icaldurationtype ICalFormatImpl::writeICalDuration(int seconds)
1772{ 1775{
1773 icaldurationtype d; 1776 icaldurationtype d;
1774 1777
1775 d.is_neg = (seconds<0)?1:0; 1778 d.is_neg = (seconds<0)?1:0;
1776 if (seconds<0) seconds = -seconds; 1779 if (seconds<0) seconds = -seconds;
1777 1780
1778 d.weeks = seconds / gSecondsPerWeek; 1781 d.weeks = seconds / gSecondsPerWeek;
1779 seconds %= gSecondsPerWeek; 1782 seconds %= gSecondsPerWeek;
1780 d.days = seconds / gSecondsPerDay; 1783 d.days = seconds / gSecondsPerDay;
1781 seconds %= gSecondsPerDay; 1784 seconds %= gSecondsPerDay;
1782 d.hours = seconds / gSecondsPerHour; 1785 d.hours = seconds / gSecondsPerHour;
1783 seconds %= gSecondsPerHour; 1786 seconds %= gSecondsPerHour;
1784 d.minutes = seconds / gSecondsPerMinute; 1787 d.minutes = seconds / gSecondsPerMinute;
1785 seconds %= gSecondsPerMinute; 1788 seconds %= gSecondsPerMinute;
1786 d.seconds = seconds; 1789 d.seconds = seconds;
1787 return d; 1790 return d;
1788} 1791}
1789 1792
1790int ICalFormatImpl::readICalDuration(icaldurationtype d) 1793int ICalFormatImpl::readICalDuration(icaldurationtype d)
1791{ 1794{
1792 int result = 0; 1795 int result = 0;
1793 1796
1794 result += d.weeks * gSecondsPerWeek; 1797 result += d.weeks * gSecondsPerWeek;
1795 result += d.days * gSecondsPerDay; 1798 result += d.days * gSecondsPerDay;
1796 result += d.hours * gSecondsPerHour; 1799 result += d.hours * gSecondsPerHour;
1797 result += d.minutes * gSecondsPerMinute; 1800 result += d.minutes * gSecondsPerMinute;
1798 result += d.seconds; 1801 result += d.seconds;
1799 1802
1800 if (d.is_neg) result *= -1; 1803 if (d.is_neg) result *= -1;
1801 1804
1802 return result; 1805 return result;
1803} 1806}
1804 1807
1805icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) 1808icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal)
1806{ 1809{
1807 icalcomponent *calendar; 1810 icalcomponent *calendar;
1808 1811
1809 // Root component 1812 // Root component
1810 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); 1813 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
1811 1814
1812 icalproperty *p; 1815 icalproperty *p;
1813 1816
1814 // Product Identifier 1817 // Product Identifier
1815 p = icalproperty_new_prodid(CalFormat::productId().utf8()); 1818 p = icalproperty_new_prodid(CalFormat::productId().utf8());
1816 icalcomponent_add_property(calendar,p); 1819 icalcomponent_add_property(calendar,p);
1817 1820
1818 // TODO: Add time zone 1821 // TODO: Add time zone
1819 1822
1820 // iCalendar version (2.0) 1823 // iCalendar version (2.0)
1821 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); 1824 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
1822 icalcomponent_add_property(calendar,p); 1825 icalcomponent_add_property(calendar,p);
1823 1826
1824 // Custom properties 1827 // Custom properties
1825 if( cal != 0 ) 1828 if( cal != 0 )
1826 writeCustomProperties(calendar, cal); 1829 writeCustomProperties(calendar, cal);
1827 1830
1828 return calendar; 1831 return calendar;
1829} 1832}
1830 1833
1831 1834
1832 1835
1833// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1836// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1834// and break it down from its tree-like format into the dictionary format 1837// and break it down from its tree-like format into the dictionary format
1835// that is used internally in the ICalFormatImpl. 1838// that is used internally in the ICalFormatImpl.
1836bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) 1839bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar)
1837{ 1840{
1838 // this function will populate the caldict dictionary and other event 1841 // this function will populate the caldict dictionary and other event
1839 // lists. It turns vevents into Events and then inserts them. 1842 // lists. It turns vevents into Events and then inserts them.
1840 1843
1841 if (!calendar) return false; 1844 if (!calendar) return false;
1842 1845
1843// TODO: check for METHOD 1846// TODO: check for METHOD
1844#if 0 1847#if 0
1845 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1848 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1846 char *methodType = 0; 1849 char *methodType = 0;
1847 methodType = fakeCString(vObjectUStringZValue(curVO)); 1850 methodType = fakeCString(vObjectUStringZValue(curVO));
1848 if (mEnableDialogs) 1851 if (mEnableDialogs)
1849 KMessageBox::information(mTopWidget, 1852 KMessageBox::information(mTopWidget,
1850 i18n("This calendar is an iTIP transaction of type \"%1\".") 1853 i18n("This calendar is an iTIP transaction of type \"%1\".")
1851 .arg(methodType), 1854 .arg(methodType),
1852 i18n("%1: iTIP Transaction").arg(CalFormat::application())); 1855 i18n("%1: iTIP Transaction").arg(CalFormat::application()));
1853 delete methodType; 1856 delete methodType;
1854 } 1857 }
1855#endif 1858#endif
1856 1859
1857 icalproperty *p; 1860 icalproperty *p;
1858 1861
1859 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); 1862 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
1860 if (!p) { 1863 if (!p) {
1861// TODO: does no PRODID really matter? 1864// TODO: does no PRODID really matter?
1862// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1865// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1863// return false; 1866// return false;
1864 mLoadedProductId = ""; 1867 mLoadedProductId = "";
1865 mCalendarVersion = 0; 1868 mCalendarVersion = 0;
1866 } else { 1869 } else {
1867 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); 1870 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
1868 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); 1871 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId);
1869 1872
1870 delete mCompat; 1873 delete mCompat;
1871 mCompat = CompatFactory::createCompat( mLoadedProductId ); 1874 mCompat = CompatFactory::createCompat( mLoadedProductId );
1872 } 1875 }
1873 1876
1874// TODO: check for unknown PRODID 1877// TODO: check for unknown PRODID
1875#if 0 1878#if 0
1876 if (!mCalendarVersion 1879 if (!mCalendarVersion
1877 && CalFormat::productId() != mLoadedProductId) { 1880 && CalFormat::productId() != mLoadedProductId) {
1878 // warn the user that we might have trouble reading non-known calendar. 1881 // warn the user that we might have trouble reading non-known calendar.
1879 if (mEnableDialogs) 1882 if (mEnableDialogs)
1880 KMessageBox::information(mTopWidget, 1883 KMessageBox::information(mTopWidget,
1881 i18n("This vCalendar file was not created by KOrganizer " 1884 i18n("This vCalendar file was not created by KOrganizer "
1882 "or any other product we support. Loading anyway..."), 1885 "or any other product we support. Loading anyway..."),
1883 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); 1886 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application()));
1884 } 1887 }
1885#endif 1888#endif
1886 1889
1887 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); 1890 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
1888 if (!p) { 1891 if (!p) {
1889 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1892 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1890 return false; 1893 return false;
1891 } else { 1894 } else {
1892 const char *version = icalproperty_get_version(p); 1895 const char *version = icalproperty_get_version(p);
1893 1896
1894 if (strcmp(version,"1.0") == 0) { 1897 if (strcmp(version,"1.0") == 0) {
1895 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, 1898 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1,
1896 i18n("Expected iCalendar format"))); 1899 i18n("Expected iCalendar format")));
1897 return false; 1900 return false;
1898 } else if (strcmp(version,"2.0") != 0) { 1901 } else if (strcmp(version,"2.0") != 0) {
1899 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1902 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1900 return false; 1903 return false;
1901 } 1904 }
1902 } 1905 }
1903 1906
1904 1907
1905// TODO: check for calendar format version 1908// TODO: check for calendar format version
1906#if 0 1909#if 0
1907 // warn the user we might have trouble reading this unknown version. 1910 // warn the user we might have trouble reading this unknown version.
1908 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1911 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1909 char *s = fakeCString(vObjectUStringZValue(curVO)); 1912 char *s = fakeCString(vObjectUStringZValue(curVO));
1910 if (strcmp(_VCAL_VERSION, s) != 0) 1913 if (strcmp(_VCAL_VERSION, s) != 0)
1911 if (mEnableDialogs) 1914 if (mEnableDialogs)
1912 KMessageBox::sorry(mTopWidget, 1915 KMessageBox::sorry(mTopWidget,
1913 i18n("This vCalendar file has version %1.\n" 1916 i18n("This vCalendar file has version %1.\n"
1914 "We only support %2.") 1917 "We only support %2.")
1915 .arg(s).arg(_VCAL_VERSION), 1918 .arg(s).arg(_VCAL_VERSION),
1916 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); 1919 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application()));
1917 deleteStr(s); 1920 deleteStr(s);
1918 } 1921 }
1919#endif 1922#endif
1920 1923
1921 // custom properties 1924 // custom properties
1922 readCustomProperties(calendar, cal); 1925 readCustomProperties(calendar, cal);
1923 1926
1924// TODO: set time zone 1927// TODO: set time zone
1925#if 0 1928#if 0
1926 // set the time zone 1929 // set the time zone
1927 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1930 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1928 char *s = fakeCString(vObjectUStringZValue(curVO)); 1931 char *s = fakeCString(vObjectUStringZValue(curVO));
1929 cal->setTimeZone(s); 1932 cal->setTimeZone(s);
1930 deleteStr(s); 1933 deleteStr(s);
1931 } 1934 }
1932#endif 1935#endif
1933 1936
1934 // Store all events with a relatedTo property in a list for post-processing 1937 // Store all events with a relatedTo property in a list for post-processing
1935 mEventsRelate.clear(); 1938 mEventsRelate.clear();
1936 mTodosRelate.clear(); 1939 mTodosRelate.clear();
1937 // TODO: make sure that only actually added ecvens go to this lists. 1940 // TODO: make sure that only actually added ecvens go to this lists.
1938 1941
1939 icalcomponent *c; 1942 icalcomponent *c;
1940 1943
1941 // Iterate through all todos 1944 // Iterate through all todos
1942 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); 1945 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
1943 while (c) { 1946 while (c) {
1944// kdDebug(5800) << "----Todo found" << endl; 1947// kdDebug(5800) << "----Todo found" << endl;
1945 Todo *todo = readTodo(c); 1948 Todo *todo = readTodo(c);
1946 if (!cal->todo(todo->uid())) cal->addTodo(todo); 1949 if (!cal->todo(todo->uid())) cal->addTodo(todo);
1947 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); 1950 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT);
1948 } 1951 }
1949 1952
1950 // Iterate through all events 1953 // Iterate through all events
1951 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); 1954 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
1952 while (c) { 1955 while (c) {
1953// kdDebug(5800) << "----Event found" << endl; 1956// kdDebug(5800) << "----Event found" << endl;
1954 Event *event = readEvent(c); 1957 Event *event = readEvent(c);
1955 if (!cal->event(event->uid())) cal->addEvent(event); 1958 if (!cal->event(event->uid())) cal->addEvent(event);
1956 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); 1959 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT);
1957 } 1960 }
1958 1961
1959 // Iterate through all journals 1962 // Iterate through all journals
1960 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); 1963 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
1961 while (c) { 1964 while (c) {
1962// kdDebug(5800) << "----Journal found" << endl; 1965// kdDebug(5800) << "----Journal found" << endl;
1963 Journal *journal = readJournal(c); 1966 Journal *journal = readJournal(c);
1964 if (!cal->journal(journal->uid())) cal->addJournal(journal); 1967 if (!cal->journal(journal->uid())) cal->addJournal(journal);
1965 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); 1968 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT);
1966 } 1969 }
1967 1970
1968#if 0 1971#if 0
1969 initPropIterator(&i, vcal); 1972 initPropIterator(&i, vcal);
1970 1973
1971 // go through all the vobjects in the vcal 1974 // go through all the vobjects in the vcal
1972 while (moreIteration(&i)) { 1975 while (moreIteration(&i)) {
1973 curVO = nextVObject(&i); 1976 curVO = nextVObject(&i);
1974 1977
1975 /************************************************************************/ 1978 /************************************************************************/
1976 1979
1977 // now, check to see that the object is an event or todo. 1980 // now, check to see that the object is an event or todo.
1978 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1981 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1979 1982
1980 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { 1983 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) {
1981 char *s; 1984 char *s;
1982 s = fakeCString(vObjectUStringZValue(curVOProp)); 1985 s = fakeCString(vObjectUStringZValue(curVOProp));
1983 // check to see if event was deleted by the kpilot conduit 1986 // check to see if event was deleted by the kpilot conduit
1984 if (atoi(s) == Event::SYNCDEL) { 1987 if (atoi(s) == Event::SYNCDEL) {
1985 deleteStr(s); 1988 deleteStr(s);
1986 goto SKIP; 1989 goto SKIP;
1987 } 1990 }
1988 deleteStr(s); 1991 deleteStr(s);
1989 } 1992 }
1990 1993
1991 // this code checks to see if we are trying to read in an event 1994 // this code checks to see if we are trying to read in an event
1992 // that we already find to be in the calendar. If we find this 1995 // that we already find to be in the calendar. If we find this
1993 // to be the case, we skip the event. 1996 // to be the case, we skip the event.
1994 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1997 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1995 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1998 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1996 QString tmpStr(s); 1999 QString tmpStr(s);
1997 deleteStr(s); 2000 deleteStr(s);
1998 2001
1999 if (cal->event(tmpStr)) { 2002 if (cal->event(tmpStr)) {
2000 goto SKIP; 2003 goto SKIP;
2001 } 2004 }
2002 if (cal->todo(tmpStr)) { 2005 if (cal->todo(tmpStr)) {
2003 goto SKIP; 2006 goto SKIP;
2004 } 2007 }
2005 } 2008 }
2006 2009
2007 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 2010 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
2008 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 2011 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
2009 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 2012 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
2010 goto SKIP; 2013 goto SKIP;
2011 } 2014 }
2012 2015
2013 anEvent = VEventToEvent(curVO); 2016 anEvent = VEventToEvent(curVO);
2014 // we now use addEvent instead of insertEvent so that the 2017 // we now use addEvent instead of insertEvent so that the
2015 // signal/slot get connected. 2018 // signal/slot get connected.
2016 if (anEvent) 2019 if (anEvent)
2017 cal->addEvent(anEvent); 2020 cal->addEvent(anEvent);
2018 else { 2021 else {
2019 // some sort of error must have occurred while in translation. 2022 // some sort of error must have occurred while in translation.
2020 goto SKIP; 2023 goto SKIP;
2021 } 2024 }
2022 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 2025 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
2023 anEvent = VTodoToEvent(curVO); 2026 anEvent = VTodoToEvent(curVO);
2024 cal->addTodo(anEvent); 2027 cal->addTodo(anEvent);
2025 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 2028 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
2026 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 2029 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
2027 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 2030 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
2028 // do nothing, we know these properties and we want to skip them. 2031 // do nothing, we know these properties and we want to skip them.
2029 // we have either already processed them or are ignoring them. 2032 // we have either already processed them or are ignoring them.
2030 ; 2033 ;
2031 } else { 2034 } else {
2032 ; 2035 ;
2033 } 2036 }
2034 SKIP: 2037 SKIP:
2035 ; 2038 ;
2036 } // while 2039 } // while
2037#endif 2040#endif
2038 2041
2039 // Post-Process list of events with relations, put Event objects in relation 2042 // Post-Process list of events with relations, put Event objects in relation
2040 Event *ev; 2043 Event *ev;
2041 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 2044 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
2042 Incidence * inc = cal->event(ev->relatedToUid()); 2045 Incidence * inc = cal->event(ev->relatedToUid());
2043 if ( inc ) 2046 if ( inc )
2044 ev->setRelatedTo( inc ); 2047 ev->setRelatedTo( inc );
2045 } 2048 }
2046 Todo *todo; 2049 Todo *todo;
2047 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 2050 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
2048 Incidence * inc = cal->todo(todo->relatedToUid()); 2051 Incidence * inc = cal->todo(todo->relatedToUid());
2049 if ( inc ) 2052 if ( inc )
2050 todo->setRelatedTo( inc ); 2053 todo->setRelatedTo( inc );
2051 } 2054 }
2052 2055
2053 return true; 2056 return true;
2054} 2057}
2055 2058
2056QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) 2059QString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
2057{ 2060{
2058// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " 2061// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: "
2059// << icalcomponent_as_ical_string(c) << endl; 2062// << icalcomponent_as_ical_string(c) << endl;
2060 2063
2061 QString errorMessage; 2064 QString errorMessage;
2062 2065
2063 icalproperty *error; 2066 icalproperty *error;
2064 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); 2067 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY);
2065 while(error) { 2068 while(error) {
2066 errorMessage += icalproperty_get_xlicerror(error); 2069 errorMessage += icalproperty_get_xlicerror(error);
2067 errorMessage += "\n"; 2070 errorMessage += "\n";
2068 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); 2071 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY);
2069 } 2072 }
2070 2073
2071// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; 2074// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl;
2072 2075
2073 return errorMessage; 2076 return errorMessage;
2074} 2077}
2075 2078
2076void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) 2079void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r)
2077{ 2080{
2078 int i; 2081 int i;
2079 2082
2080 2083
2081 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2084 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2082 int index = 0; 2085 int index = 0;
2083 QString out = " By Day: "; 2086 QString out = " By Day: ";
2084 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2087 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2085 out.append(QString::number(i) + " "); 2088 out.append(QString::number(i) + " ");
2086 } 2089 }
2087 } 2090 }
2088 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2091 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2089 int index = 0; 2092 int index = 0;
2090 QString out = " By Month Day: "; 2093 QString out = " By Month Day: ";
2091 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2094 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2092 out.append(QString::number(i) + " "); 2095 out.append(QString::number(i) + " ");
2093 } 2096 }
2094 } 2097 }
2095 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2098 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2096 int index = 0; 2099 int index = 0;
2097 QString out = " By Year Day: "; 2100 QString out = " By Year Day: ";
2098 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2101 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2099 out.append(QString::number(i) + " "); 2102 out.append(QString::number(i) + " ");
2100 } 2103 }
2101 } 2104 }
2102 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2105 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2103 int index = 0; 2106 int index = 0;
2104 QString out = " By Month: "; 2107 QString out = " By Month: ";
2105 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2108 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2106 out.append(QString::number(i) + " "); 2109 out.append(QString::number(i) + " ");
2107 } 2110 }
2108 } 2111 }
2109 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2112 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2110 int index = 0; 2113 int index = 0;
2111 QString out = " By Set Pos: "; 2114 QString out = " By Set Pos: ";
2112 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2115 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2113 out.append(QString::number(i) + " "); 2116 out.append(QString::number(i) + " ");
2114 } 2117 }
2115 } 2118 }
2116} 2119}
2117 2120
2118icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, 2121icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence,
2119 Scheduler::Method method) 2122 Scheduler::Method method)
2120{ 2123{
2121 icalcomponent *message = createCalendarComponent(); 2124 icalcomponent *message = createCalendarComponent();
2122 2125
2123 icalproperty_method icalmethod = ICAL_METHOD_NONE; 2126 icalproperty_method icalmethod = ICAL_METHOD_NONE;
2124 2127
2125 switch (method) { 2128 switch (method) {
2126 case Scheduler::Publish: 2129 case Scheduler::Publish:
2127 icalmethod = ICAL_METHOD_PUBLISH; 2130 icalmethod = ICAL_METHOD_PUBLISH;
2128 break; 2131 break;
2129 case Scheduler::Request: 2132 case Scheduler::Request:
2130 icalmethod = ICAL_METHOD_REQUEST; 2133 icalmethod = ICAL_METHOD_REQUEST;
2131 break; 2134 break;
2132 case Scheduler::Refresh: 2135 case Scheduler::Refresh:
2133 icalmethod = ICAL_METHOD_REFRESH; 2136 icalmethod = ICAL_METHOD_REFRESH;
2134 break; 2137 break;
2135 case Scheduler::Cancel: 2138 case Scheduler::Cancel:
2136 icalmethod = ICAL_METHOD_CANCEL; 2139 icalmethod = ICAL_METHOD_CANCEL;
2137 break; 2140 break;
2138 case Scheduler::Add: 2141 case Scheduler::Add:
2139 icalmethod = ICAL_METHOD_ADD; 2142 icalmethod = ICAL_METHOD_ADD;
2140 break; 2143 break;
2141 case Scheduler::Reply: 2144 case Scheduler::Reply:
2142 icalmethod = ICAL_METHOD_REPLY; 2145 icalmethod = ICAL_METHOD_REPLY;
2143 break; 2146 break;
2144 case Scheduler::Counter: 2147 case Scheduler::Counter:
2145 icalmethod = ICAL_METHOD_COUNTER; 2148 icalmethod = ICAL_METHOD_COUNTER;
2146 break; 2149 break;
2147 case Scheduler::Declinecounter: 2150 case Scheduler::Declinecounter:
2148 icalmethod = ICAL_METHOD_DECLINECOUNTER; 2151 icalmethod = ICAL_METHOD_DECLINECOUNTER;
2149 break; 2152 break;
2150 default: 2153 default:
2151 2154
2152 return message; 2155 return message;
2153 } 2156 }
2154 2157
2155 icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); 2158 icalcomponent_add_property(message,icalproperty_new_method(icalmethod));
2156 2159
2157 // TODO: check, if dynamic cast is required 2160 // TODO: check, if dynamic cast is required
2158 if(incidence->typeID() == todoID ) { 2161 if(incidence->typeID() == todoID ) {
2159 Todo *todo = static_cast<Todo *>(incidence); 2162 Todo *todo = static_cast<Todo *>(incidence);
2160 icalcomponent_add_component(message,writeTodo(todo)); 2163 icalcomponent_add_component(message,writeTodo(todo));
2161 } 2164 }
2162 if(incidence->typeID() == eventID ) { 2165 if(incidence->typeID() == eventID ) {
2163 Event *event = static_cast<Event *>(incidence); 2166 Event *event = static_cast<Event *>(incidence);
2164 icalcomponent_add_component(message,writeEvent(event)); 2167 icalcomponent_add_component(message,writeEvent(event));
2165 } 2168 }
2166 if(incidence->typeID() == freebusyID) { 2169 if(incidence->typeID() == freebusyID) {
2167 FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); 2170 FreeBusy *freebusy = static_cast<FreeBusy *>(incidence);
2168 icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); 2171 icalcomponent_add_component(message,writeFreeBusy(freebusy, method));
2169 } 2172 }
2170 2173
2171 return message; 2174 return message;
2172} 2175}