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