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