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