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