summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp1
-rw-r--r--libkcal/event.cpp6
-rw-r--r--libkcal/todo.cpp4
3 files changed, 5 insertions, 6 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 88351eb..dcfee5d 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,382 +1,383 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <stdlib.h> 22#include <stdlib.h>
23#include <time.h> 23#include <time.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "exceptions.h" 29#include "exceptions.h"
30#include "calfilter.h" 30#include "calfilter.h"
31 31
32#include "calendar.h" 32#include "calendar.h"
33#include "syncdefines.h" 33#include "syncdefines.h"
34 34
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::Calendar()
38{ 38{
39 39
40 init(); 40 init();
41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); 41 setTimeZoneId( i18n (" 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} 128}
128void Calendar::setOwner(const QString &os) 129void Calendar::setOwner(const QString &os)
129{ 130{
130 int i; 131 int i;
131 mOwner = os; 132 mOwner = os;
132 i = mOwner.find(','); 133 i = mOwner.find(',');
133 if (i != -1) 134 if (i != -1)
134 mOwner = mOwner.left(i); 135 mOwner = mOwner.left(i);
135 136
136 setModified( true ); 137 setModified( true );
137} 138}
138 139
139void Calendar::setTimeZone(const QString & tz) 140void Calendar::setTimeZone(const QString & tz)
140{ 141{
141 bool neg = FALSE; 142 bool neg = FALSE;
142 int hours, minutes; 143 int hours, minutes;
143 QString tmpStr(tz); 144 QString tmpStr(tz);
144 145
145 if (tmpStr.left(1) == "-") 146 if (tmpStr.left(1) == "-")
146 neg = TRUE; 147 neg = TRUE;
147 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 148 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
148 tmpStr.remove(0, 1); 149 tmpStr.remove(0, 1);
149 hours = tmpStr.left(2).toInt(); 150 hours = tmpStr.left(2).toInt();
150 if (tmpStr.length() > 2) 151 if (tmpStr.length() > 2)
151 minutes = tmpStr.right(2).toInt(); 152 minutes = tmpStr.right(2).toInt();
152 else 153 else
153 minutes = 0; 154 minutes = 0;
154 mTimeZone = (60*hours+minutes); 155 mTimeZone = (60*hours+minutes);
155 if (neg) 156 if (neg)
156 mTimeZone = -mTimeZone; 157 mTimeZone = -mTimeZone;
157 mLocalTime = false; 158 mLocalTime = false;
158 159
159 setModified( true ); 160 setModified( true );
160} 161}
161 162
162QString Calendar::getTimeZoneStr() const 163QString Calendar::getTimeZoneStr() const
163{ 164{
164 if (mLocalTime) 165 if (mLocalTime)
165 return ""; 166 return "";
166 QString tmpStr; 167 QString tmpStr;
167 int hours = abs(mTimeZone / 60); 168 int hours = abs(mTimeZone / 60);
168 int minutes = abs(mTimeZone % 60); 169 int minutes = abs(mTimeZone % 60);
169 bool neg = mTimeZone < 0; 170 bool neg = mTimeZone < 0;
170 171
171 tmpStr.sprintf("%c%.2d%.2d", 172 tmpStr.sprintf("%c%.2d%.2d",
172 (neg ? '-' : '+'), 173 (neg ? '-' : '+'),
173 hours, minutes); 174 hours, minutes);
174 return tmpStr; 175 return tmpStr;
175} 176}
176 177
177void Calendar::setTimeZone(int tz) 178void Calendar::setTimeZone(int tz)
178{ 179{
179 mTimeZone = tz; 180 mTimeZone = tz;
180 mLocalTime = false; 181 mLocalTime = false;
181 182
182 setModified( true ); 183 setModified( true );
183} 184}
184 185
185int Calendar::getTimeZone() const 186int Calendar::getTimeZone() const
186{ 187{
187 return mTimeZone; 188 return mTimeZone;
188} 189}
189 190
190void Calendar::setTimeZoneId(const QString &id) 191void Calendar::setTimeZoneId(const QString &id)
191{ 192{
192 mTimeZoneId = id; 193 mTimeZoneId = id;
193 mLocalTime = false; 194 mLocalTime = false;
194 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 195 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
195 if ( mTimeZone > 1000) 196 if ( mTimeZone > 1000)
196 setLocalTime(); 197 setLocalTime();
197 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 198 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
198 setModified( true ); 199 setModified( true );
199} 200}
200 201
201QString Calendar::timeZoneId() const 202QString Calendar::timeZoneId() const
202{ 203{
203 return mTimeZoneId; 204 return mTimeZoneId;
204} 205}
205 206
206void Calendar::setLocalTime() 207void Calendar::setLocalTime()
207{ 208{
208 //qDebug("Calendar::setLocalTime() "); 209 //qDebug("Calendar::setLocalTime() ");
209 mLocalTime = true; 210 mLocalTime = true;
210 mTimeZone = 0; 211 mTimeZone = 0;
211 mTimeZoneId = ""; 212 mTimeZoneId = "";
212 213
213 setModified( true ); 214 setModified( true );
214} 215}
215 216
216bool Calendar::isLocalTime() const 217bool Calendar::isLocalTime() const
217{ 218{
218 return mLocalTime; 219 return mLocalTime;
219} 220}
220 221
221const QString &Calendar::getEmail() 222const QString &Calendar::getEmail()
222{ 223{
223 return mOwnerEmail; 224 return mOwnerEmail;
224} 225}
225 226
226void Calendar::setEmail(const QString &e) 227void Calendar::setEmail(const QString &e)
227{ 228{
228 mOwnerEmail = e; 229 mOwnerEmail = e;
229 230
230 setModified( true ); 231 setModified( true );
231} 232}
232 233
233void Calendar::setFilter(CalFilter *filter) 234void Calendar::setFilter(CalFilter *filter)
234{ 235{
235 mFilter = filter; 236 mFilter = filter;
236} 237}
237 238
238CalFilter *Calendar::filter() 239CalFilter *Calendar::filter()
239{ 240{
240 return mFilter; 241 return mFilter;
241} 242}
242 243
243QPtrList<Incidence> Calendar::incidences() 244QPtrList<Incidence> Calendar::incidences()
244{ 245{
245 QPtrList<Incidence> incidences; 246 QPtrList<Incidence> incidences;
246 247
247 Incidence *i; 248 Incidence *i;
248 249
249 QPtrList<Event> e = events(); 250 QPtrList<Event> e = events();
250 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 251 for( i = e.first(); i; i = e.next() ) incidences.append( i );
251 252
252 QPtrList<Todo> t = todos(); 253 QPtrList<Todo> t = todos();
253 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 254 for( i = t.first(); i; i = t.next() ) incidences.append( i );
254 255
255 QPtrList<Journal> j = journals(); 256 QPtrList<Journal> j = journals();
256 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 257 for( i = j.first(); i; i = j.next() ) incidences.append( i );
257 258
258 return incidences; 259 return incidences;
259} 260}
260 261
261void Calendar::resetPilotStat(int id ) 262void Calendar::resetPilotStat(int id )
262{ 263{
263 QPtrList<Incidence> incidences; 264 QPtrList<Incidence> incidences;
264 265
265 Incidence *i; 266 Incidence *i;
266 267
267 QPtrList<Event> e = rawEvents(); 268 QPtrList<Event> e = rawEvents();
268 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 269 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
269 270
270 QPtrList<Todo> t = rawTodos(); 271 QPtrList<Todo> t = rawTodos();
271 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 272 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
272 273
273 QPtrList<Journal> j = journals(); 274 QPtrList<Journal> j = journals();
274 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 275 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
275} 276}
276void Calendar::resetTempSyncStat() 277void Calendar::resetTempSyncStat()
277{ 278{
278 QPtrList<Incidence> incidences; 279 QPtrList<Incidence> incidences;
279 280
280 Incidence *i; 281 Incidence *i;
281 282
282 QPtrList<Event> e = rawEvents(); 283 QPtrList<Event> e = rawEvents();
283 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 );
284 285
285 QPtrList<Todo> t = rawTodos(); 286 QPtrList<Todo> t = rawTodos();
286 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 );
287 288
288 QPtrList<Journal> j = journals(); 289 QPtrList<Journal> j = journals();
289 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 );
290} 291}
291QPtrList<Incidence> Calendar::rawIncidences() 292QPtrList<Incidence> Calendar::rawIncidences()
292{ 293{
293 QPtrList<Incidence> incidences; 294 QPtrList<Incidence> incidences;
294 295
295 Incidence *i; 296 Incidence *i;
296 297
297 QPtrList<Event> e = rawEvents(); 298 QPtrList<Event> e = rawEvents();
298 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 299 for( i = e.first(); i; i = e.next() ) incidences.append( i );
299 300
300 QPtrList<Todo> t = rawTodos(); 301 QPtrList<Todo> t = rawTodos();
301 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 302 for( i = t.first(); i; i = t.next() ) incidences.append( i );
302 303
303 QPtrList<Journal> j = journals(); 304 QPtrList<Journal> j = journals();
304 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 305 for( i = j.first(); i; i = j.next() ) incidences.append( i );
305 306
306 return incidences; 307 return incidences;
307} 308}
308 309
309QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 310QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
310{ 311{
311 QPtrList<Event> el = rawEventsForDate(date,sorted); 312 QPtrList<Event> el = rawEventsForDate(date,sorted);
312 mFilter->apply(&el); 313 mFilter->apply(&el);
313 return el; 314 return el;
314} 315}
315 316
316QPtrList<Event> Calendar::events( const QDateTime &qdt ) 317QPtrList<Event> Calendar::events( const QDateTime &qdt )
317{ 318{
318 QPtrList<Event> el = rawEventsForDate(qdt); 319 QPtrList<Event> el = rawEventsForDate(qdt);
319 mFilter->apply(&el); 320 mFilter->apply(&el);
320 return el; 321 return el;
321} 322}
322 323
323QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 324QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
324 bool inclusive) 325 bool inclusive)
325{ 326{
326 QPtrList<Event> el = rawEvents(start,end,inclusive); 327 QPtrList<Event> el = rawEvents(start,end,inclusive);
327 mFilter->apply(&el); 328 mFilter->apply(&el);
328 return el; 329 return el;
329} 330}
330 331
331QPtrList<Event> Calendar::events() 332QPtrList<Event> Calendar::events()
332{ 333{
333 QPtrList<Event> el = rawEvents(); 334 QPtrList<Event> el = rawEvents();
334 mFilter->apply(&el); 335 mFilter->apply(&el);
335 return el; 336 return el;
336} 337}
337 338
338 339
339bool Calendar::addIncidence(Incidence *i) 340bool Calendar::addIncidence(Incidence *i)
340{ 341{
341 Incidence::AddVisitor<Calendar> v(this); 342 Incidence::AddVisitor<Calendar> v(this);
342 343
343 return i->accept(v); 344 return i->accept(v);
344} 345}
345void Calendar::deleteIncidence(Incidence *in) 346void Calendar::deleteIncidence(Incidence *in)
346{ 347{
347 if ( in->type() == "Event" ) 348 if ( in->type() == "Event" )
348 deleteEvent( (Event*) in ); 349 deleteEvent( (Event*) in );
349 else if ( in->type() =="Todo" ) 350 else if ( in->type() =="Todo" )
350 deleteTodo( (Todo*) in); 351 deleteTodo( (Todo*) in);
351 else if ( in->type() =="Journal" ) 352 else if ( in->type() =="Journal" )
352 deleteJournal( (Journal*) in ); 353 deleteJournal( (Journal*) in );
353} 354}
354 355
355Incidence* Calendar::incidence( const QString& uid ) 356Incidence* Calendar::incidence( const QString& uid )
356{ 357{
357 Incidence* i; 358 Incidence* i;
358 359
359 if( (i = todo( uid )) != 0 ) 360 if( (i = todo( uid )) != 0 )
360 return i; 361 return i;
361 if( (i = event( uid )) != 0 ) 362 if( (i = event( uid )) != 0 )
362 return i; 363 return i;
363 if( (i = journal( uid )) != 0 ) 364 if( (i = journal( uid )) != 0 )
364 return i; 365 return i;
365 366
366 return 0; 367 return 0;
367} 368}
368 369
369QPtrList<Todo> Calendar::todos() 370QPtrList<Todo> Calendar::todos()
370{ 371{
371 QPtrList<Todo> tl = rawTodos(); 372 QPtrList<Todo> tl = rawTodos();
372 mFilter->apply( &tl ); 373 mFilter->apply( &tl );
373 return tl; 374 return tl;
374} 375}
375 376
376// When this is called, the todo have already been added to the calendar. 377// When this is called, the todo have already been added to the calendar.
377// This method is only about linking related todos 378// This method is only about linking related todos
378void Calendar::setupRelations( Incidence *incidence ) 379void Calendar::setupRelations( Incidence *incidence )
379{ 380{
380 QString uid = incidence->uid(); 381 QString uid = incidence->uid();
381 //qDebug("Calendar::setupRelations "); 382 //qDebug("Calendar::setupRelations ");
382 // First, go over the list of orphans and see if this is their parent 383 // First, go over the list of orphans and see if this is their parent
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 7256f05..de8dceb 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -1,223 +1,221 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "event.h" 25#include "event.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::Event(const Event &e) : Incidence(e)
35{ 35{
36 mDtEnd = e.mDtEnd; 36 mDtEnd = e.mDtEnd;
37 mHasEndDate = e.mHasEndDate; 37 mHasEndDate = e.mHasEndDate;
38 mTransparency = e.mTransparency; 38 mTransparency = e.mTransparency;
39} 39}
40 40
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
51{ 51{
52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
53 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
54 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
55 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
56} 56}
57 57
58 58
59bool Event::contains ( Event* from ) 59bool Event::contains ( Event* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->dtStart().isValid() ) 65 if ( from->dtStart().isValid() )
66 if (dtStart() != from->dtStart() ) 66 if (dtStart() != from->dtStart() )
67 return false; 67 return false;
68 if ( from->dtEnd().isValid() ) 68 if ( from->dtEnd().isValid() )
69 if ( dtEnd() != from->dtEnd() ) 69 if ( dtEnd() != from->dtEnd() )
70 return false; 70 return false;
71 if ( !from->location().isEmpty() ) 71 if ( !from->location().isEmpty() )
72 if ( !location().startsWith( from->location() ) ) 72 if ( !location().startsWith( from->location() ) )
73 return false; 73 return false;
74 if ( !from->description().isEmpty() ) 74 if ( !from->description().isEmpty() )
75 if ( !description().startsWith( from->description() )) 75 if ( !description().startsWith( from->description() ))
76 return false; 76 return false;
77 if ( from->alarms().count() ) { 77 if ( from->alarms().count() ) {
78 Alarm *a = from->alarms().first(); 78 Alarm *a = from->alarms().first();
79 if ( a->enabled() ){ 79 if ( a->enabled() ){
80 if ( !alarms().count() ) 80 if ( !alarms().count() )
81 return false; 81 return false;
82 Alarm *b = alarms().first(); 82 Alarm *b = alarms().first();
83 if( ! b->enabled() ) 83 if( ! b->enabled() )
84 return false; 84 return false;
85 if ( ! (a->offset() == b->offset() )) 85 if ( ! (a->offset() == b->offset() ))
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 QStringList cat = categories(); 89 QStringList cat = categories();
90 QStringList catFrom = from->categories(); 90 QStringList catFrom = from->categories();
91 QString nCat; 91 QString nCat;
92 int iii; 92 unsigned int iii;
93 for ( iii = 0; iii < catFrom.count();++iii ) { 93 for ( iii = 0; iii < catFrom.count();++iii ) {
94 nCat = catFrom[iii]; 94 nCat = catFrom[iii];
95 if ( !nCat.isEmpty() ) 95 if ( !nCat.isEmpty() )
96 if ( !cat.contains( nCat )) { 96 if ( !cat.contains( nCat )) {
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 if ( from->doesRecur() ) 100 if ( from->doesRecur() )
101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) 101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
102 return false; 102 return false;
103 return true; 103 return true;
104} 104}
105 105
106void Event::setDtEnd(const QDateTime &dtEnd) 106void Event::setDtEnd(const QDateTime &dtEnd)
107{ 107{
108 if (mReadOnly) return; 108 if (mReadOnly) return;
109 109
110 mDtEnd = getEvenTime( dtEnd ); 110 mDtEnd = getEvenTime( dtEnd );
111 111
112 setHasEndDate(true); 112 setHasEndDate(true);
113 setHasDuration(false); 113 setHasDuration(false);
114 114
115 updated(); 115 updated();
116} 116}
117 117
118QDateTime Event::dtEnd() const 118QDateTime Event::dtEnd() const
119{ 119{
120 if (hasEndDate()) return mDtEnd; 120 if (hasEndDate()) return mDtEnd;
121 if (hasDuration()) return dtStart().addSecs(duration()); 121 if (hasDuration()) return dtStart().addSecs(duration());
122 122
123 kdDebug(5800) << "Warning! Event '" << summary()
124 << "' does have neither end date nor duration." << endl;
125 return dtStart(); 123 return dtStart();
126} 124}
127 125
128QString Event::dtEndTimeStr() const 126QString Event::dtEndTimeStr() const
129{ 127{
130 return KGlobal::locale()->formatTime(mDtEnd.time()); 128 return KGlobal::locale()->formatTime(mDtEnd.time());
131} 129}
132 130
133QString Event::dtEndDateStr(bool shortfmt) const 131QString Event::dtEndDateStr(bool shortfmt) const
134{ 132{
135 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
136} 134}
137 135
138QString Event::dtEndStr(bool shortfmt) const 136QString Event::dtEndStr(bool shortfmt) const
139{ 137{
140 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
141} 139}
142 140
143void Event::setHasEndDate(bool b) 141void Event::setHasEndDate(bool b)
144{ 142{
145 mHasEndDate = b; 143 mHasEndDate = b;
146} 144}
147 145
148bool Event::hasEndDate() const 146bool Event::hasEndDate() const
149{ 147{
150 return mHasEndDate; 148 return mHasEndDate;
151} 149}
152 150
153bool Event::isMultiDay() const 151bool Event::isMultiDay() const
154{ 152{
155 bool multi = !(dtStart().date() == dtEnd().date()); 153 bool multi = !(dtStart().date() == dtEnd().date());
156 return multi; 154 return multi;
157} 155}
158 156
159void Event::setTransparency(Event::Transparency transparency) 157void Event::setTransparency(Event::Transparency transparency)
160{ 158{
161 if (mReadOnly) return; 159 if (mReadOnly) return;
162 mTransparency = transparency; 160 mTransparency = transparency;
163 updated(); 161 updated();
164} 162}
165 163
166Event::Transparency Event::transparency() const 164Event::Transparency Event::transparency() const
167{ 165{
168 return mTransparency; 166 return mTransparency;
169} 167}
170 168
171void Event::setDuration(int seconds) 169void Event::setDuration(int seconds)
172{ 170{
173 setHasEndDate(false); 171 setHasEndDate(false);
174 Incidence::setDuration(seconds); 172 Incidence::setDuration(seconds);
175} 173}
176QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const 174QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const
177{ 175{
178 176
179 bool yes; 177 bool yes;
180 QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); 178 QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes );
181 if ( ! yes || cancelled() ) { 179 if ( ! yes || cancelled() ) {
182 *ok = false; 180 *ok = false;
183 return QDateTime (); 181 return QDateTime ();
184 } 182 }
185 183
186 bool enabled = false; 184 bool enabled = false;
187 Alarm* alarm; 185 Alarm* alarm;
188 int off; 186 int off = 0;
189 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 187 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
190 // if ( QDateTime::currentDateTime() > incidenceStart ){ 188 // if ( QDateTime::currentDateTime() > incidenceStart ){
191// *ok = false; 189// *ok = false;
192// return incidenceStart; 190// return incidenceStart;
193// } 191// }
194 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 192 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
195 if (alarm->enabled()) { 193 if (alarm->enabled()) {
196 if ( alarm->hasTime () ) { 194 if ( alarm->hasTime () ) {
197 if ( alarm->time() < alarmStart ) { 195 if ( alarm->time() < alarmStart ) {
198 alarmStart = alarm->time(); 196 alarmStart = alarm->time();
199 enabled = true; 197 enabled = true;
200 off = alarmStart.secsTo( incidenceStart ); 198 off = alarmStart.secsTo( incidenceStart );
201 } 199 }
202 200
203 } else { 201 } else {
204 int secs = alarm->startOffset().asSeconds(); 202 int secs = alarm->startOffset().asSeconds();
205 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 203 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
206 alarmStart = incidenceStart.addSecs( secs ); 204 alarmStart = incidenceStart.addSecs( secs );
207 enabled = true; 205 enabled = true;
208 off = -secs; 206 off = -secs;
209 } 207 }
210 } 208 }
211 } 209 }
212 } 210 }
213 if ( enabled ) { 211 if ( enabled ) {
214 if ( alarmStart > QDateTime::currentDateTime() ) { 212 if ( alarmStart > QDateTime::currentDateTime() ) {
215 *ok = true; 213 *ok = true;
216 * offset = off; 214 * offset = off;
217 return alarmStart; 215 return alarmStart;
218 } 216 }
219 } 217 }
220 *ok = false; 218 *ok = false;
221 return QDateTime (); 219 return QDateTime ();
222 220
223} 221}
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index d81a68f..9c04a7e 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,414 +1,414 @@
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 "todo.h" 25#include "todo.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Todo::Todo(): Incidence() 29Todo::Todo(): Incidence()
30{ 30{
31// mStatus = TENTATIVE; 31// mStatus = TENTATIVE;
32 32
33 mHasDueDate = false; 33 mHasDueDate = false;
34 setHasStartDate( false ); 34 setHasStartDate( false );
35 mCompleted = getEvenTime(QDateTime::currentDateTime()); 35 mCompleted = getEvenTime(QDateTime::currentDateTime());
36 mHasCompletedDate = false; 36 mHasCompletedDate = false;
37 mPercentComplete = 0; 37 mPercentComplete = 0;
38} 38}
39 39
40Todo::Todo(const Todo &t) : Incidence(t) 40Todo::Todo(const Todo &t) : Incidence(t)
41{ 41{
42 mDtDue = t.mDtDue; 42 mDtDue = t.mDtDue;
43 mHasDueDate = t.mHasDueDate; 43 mHasDueDate = t.mHasDueDate;
44 mCompleted = t.mCompleted; 44 mCompleted = t.mCompleted;
45 mHasCompletedDate = t.mHasCompletedDate; 45 mHasCompletedDate = t.mHasCompletedDate;
46 mPercentComplete = t.mPercentComplete; 46 mPercentComplete = t.mPercentComplete;
47} 47}
48 48
49Todo::~Todo() 49Todo::~Todo()
50{ 50{
51 51
52} 52}
53 53
54Incidence *Todo::clone() 54Incidence *Todo::clone()
55{ 55{
56 return new Todo(*this); 56 return new Todo(*this);
57} 57}
58 58
59bool Todo::contains ( Todo* from ) 59bool Todo::contains ( Todo* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->hasStartDate() ) { 65 if ( from->hasStartDate() ) {
66 if ( !hasStartDate() ) 66 if ( !hasStartDate() )
67 return false; 67 return false;
68 if ( from->dtStart() != dtStart()) 68 if ( from->dtStart() != dtStart())
69 return false; 69 return false;
70 } 70 }
71 if ( from->hasDueDate() ){ 71 if ( from->hasDueDate() ){
72 if ( !hasDueDate() ) 72 if ( !hasDueDate() )
73 return false; 73 return false;
74 if ( from->dtDue() != dtDue()) 74 if ( from->dtDue() != dtDue())
75 return false; 75 return false;
76 } 76 }
77 if ( !from->location().isEmpty() ) 77 if ( !from->location().isEmpty() )
78 if ( !location().startsWith( from->location() ) ) 78 if ( !location().startsWith( from->location() ) )
79 return false; 79 return false;
80 if ( !from->description().isEmpty() ) 80 if ( !from->description().isEmpty() )
81 if ( !description().startsWith( from->description() )) 81 if ( !description().startsWith( from->description() ))
82 return false; 82 return false;
83 if ( from->alarms().count() ) { 83 if ( from->alarms().count() ) {
84 Alarm *a = from->alarms().first(); 84 Alarm *a = from->alarms().first();
85 if ( a->enabled() ){ 85 if ( a->enabled() ){
86 if ( !alarms().count() ) 86 if ( !alarms().count() )
87 return false; 87 return false;
88 Alarm *b = alarms().first(); 88 Alarm *b = alarms().first();
89 if( ! b->enabled() ) 89 if( ! b->enabled() )
90 return false; 90 return false;
91 if ( ! (a->offset() == b->offset() )) 91 if ( ! (a->offset() == b->offset() ))
92 return false; 92 return false;
93 } 93 }
94 } 94 }
95 95
96 QStringList cat = categories(); 96 QStringList cat = categories();
97 QStringList catFrom = from->categories(); 97 QStringList catFrom = from->categories();
98 QString nCat; 98 QString nCat;
99 int iii; 99 unsigned int iii;
100 for ( iii = 0; iii < catFrom.count();++iii ) { 100 for ( iii = 0; iii < catFrom.count();++iii ) {
101 nCat = catFrom[iii]; 101 nCat = catFrom[iii];
102 if ( !nCat.isEmpty() ) 102 if ( !nCat.isEmpty() )
103 if ( !cat.contains( nCat )) { 103 if ( !cat.contains( nCat )) {
104 return false; 104 return false;
105 } 105 }
106 } 106 }
107 if ( from->isCompleted() ) { 107 if ( from->isCompleted() ) {
108 if ( !isCompleted() ) 108 if ( !isCompleted() )
109 return false; 109 return false;
110 } 110 }
111 if( priority() != from->priority() ) 111 if( priority() != from->priority() )
112 return false; 112 return false;
113 113
114 114
115 return true; 115 return true;
116 116
117} 117}
118bool KCal::operator==( const Todo& t1, const Todo& t2 ) 118bool KCal::operator==( const Todo& t1, const Todo& t2 )
119{ 119{
120 120
121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
122 if ( ! ret ) 122 if ( ! ret )
123 return false; 123 return false;
124 if ( t1.hasDueDate() == t2.hasDueDate() ) { 124 if ( t1.hasDueDate() == t2.hasDueDate() ) {
125 if ( t1.hasDueDate() ) { 125 if ( t1.hasDueDate() ) {
126 if ( t1.doesFloat() == t2.doesFloat() ) { 126 if ( t1.doesFloat() == t2.doesFloat() ) {
127 if ( t1.doesFloat() ) { 127 if ( t1.doesFloat() ) {
128 if ( t1.dtDue().date() != t2.dtDue().date() ) 128 if ( t1.dtDue().date() != t2.dtDue().date() )
129 return false; 129 return false;
130 } else 130 } else
131 if ( t1.dtDue() != t2.dtDue() ) 131 if ( t1.dtDue() != t2.dtDue() )
132 return false; 132 return false;
133 } else 133 } else
134 return false;// float != 134 return false;// float !=
135 } 135 }
136 136
137 } else 137 } else
138 return false; 138 return false;
139 if ( t1.percentComplete() != t2.percentComplete() ) 139 if ( t1.percentComplete() != t2.percentComplete() )
140 return false; 140 return false;
141 if ( t1.isCompleted() ) { 141 if ( t1.isCompleted() ) {
142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
143 if ( t1.hasCompletedDate() ) { 143 if ( t1.hasCompletedDate() ) {
144 if ( t1.completed() != t2.completed() ) 144 if ( t1.completed() != t2.completed() )
145 return false; 145 return false;
146 } 146 }
147 147
148 } else 148 } else
149 return false; 149 return false;
150 } 150 }
151 return true; 151 return true;
152 152
153} 153}
154 154
155void Todo::setDtDue(const QDateTime &dtDue) 155void Todo::setDtDue(const QDateTime &dtDue)
156{ 156{
157 //int diffsecs = mDtDue.secsTo(dtDue); 157 //int diffsecs = mDtDue.secsTo(dtDue);
158 158
159 /*if (mReadOnly) return; 159 /*if (mReadOnly) return;
160 const QPtrList<Alarm>& alarms = alarms(); 160 const QPtrList<Alarm>& alarms = alarms();
161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
162 if (alarm->enabled()) { 162 if (alarm->enabled()) {
163 alarm->setTime(alarm->time().addSecs(diffsecs)); 163 alarm->setTime(alarm->time().addSecs(diffsecs));
164 } 164 }
165 }*/ 165 }*/
166 mDtDue = getEvenTime(dtDue); 166 mDtDue = getEvenTime(dtDue);
167 167
168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
169 169
170 /*const QPtrList<Alarm>& alarms = alarms(); 170 /*const QPtrList<Alarm>& alarms = alarms();
171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
172 alarm->setAlarmStart(mDtDue);*/ 172 alarm->setAlarmStart(mDtDue);*/
173 173
174 updated(); 174 updated();
175} 175}
176 176
177QDateTime Todo::dtDue() const 177QDateTime Todo::dtDue() const
178{ 178{
179 return mDtDue; 179 return mDtDue;
180} 180}
181 181
182QString Todo::dtDueTimeStr() const 182QString Todo::dtDueTimeStr() const
183{ 183{
184 return KGlobal::locale()->formatTime(mDtDue.time()); 184 return KGlobal::locale()->formatTime(mDtDue.time());
185} 185}
186 186
187QString Todo::dtDueDateStr(bool shortfmt) const 187QString Todo::dtDueDateStr(bool shortfmt) const
188{ 188{
189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
190} 190}
191 191
192QString Todo::dtDueStr(bool shortfmt) const 192QString Todo::dtDueStr(bool shortfmt) const
193{ 193{
194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
195} 195}
196// retval 0 : no found 196// retval 0 : no found
197// 1 : due for date found 197// 1 : due for date found
198// 2 : overdue for date found 198// 2 : overdue for date found
199int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 199int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
200{ 200{
201 int retval = 0; 201 int retval = 0;
202 if ( isCompleted() ) 202 if ( isCompleted() )
203 return 0; 203 return 0;
204 if ( hasDueDate() ) { 204 if ( hasDueDate() ) {
205 if ( dtDue().date() < date ) 205 if ( dtDue().date() < date )
206 return 2; 206 return 2;
207 // we do not return, because we may find an overdue sub todo 207 // we do not return, because we may find an overdue sub todo
208 if ( dtDue().date() == date ) 208 if ( dtDue().date() == date )
209 retval = 1; 209 retval = 1;
210 } 210 }
211 if ( checkSubtodos ) { 211 if ( checkSubtodos ) {
212 Incidence *aTodo; 212 Incidence *aTodo;
213 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 213 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
214 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 214 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
215 if ( ret == 2 ) 215 if ( ret == 2 )
216 return 2; 216 return 2;
217 if ( ret == 1) 217 if ( ret == 1)
218 retval = 1; 218 retval = 1;
219 } 219 }
220 } 220 }
221 return retval; 221 return retval;
222} 222}
223int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 223int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
224{ 224{
225 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 225 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
226} 226}
227bool Todo::hasDueDate() const 227bool Todo::hasDueDate() const
228{ 228{
229 return mHasDueDate; 229 return mHasDueDate;
230} 230}
231 231
232void Todo::setHasDueDate(bool f) 232void Todo::setHasDueDate(bool f)
233{ 233{
234 if (mReadOnly) return; 234 if (mReadOnly) return;
235 mHasDueDate = f; 235 mHasDueDate = f;
236 updated(); 236 updated();
237} 237}
238 238
239 239
240#if 0 240#if 0
241void Todo::setStatus(const QString &statStr) 241void Todo::setStatus(const QString &statStr)
242{ 242{
243 if (mReadOnly) return; 243 if (mReadOnly) return;
244 QString ss(statStr.upper()); 244 QString ss(statStr.upper());
245 245
246 if (ss == "X-ACTION") 246 if (ss == "X-ACTION")
247 mStatus = NEEDS_ACTION; 247 mStatus = NEEDS_ACTION;
248 else if (ss == "NEEDS ACTION") 248 else if (ss == "NEEDS ACTION")
249 mStatus = NEEDS_ACTION; 249 mStatus = NEEDS_ACTION;
250 else if (ss == "ACCEPTED") 250 else if (ss == "ACCEPTED")
251 mStatus = ACCEPTED; 251 mStatus = ACCEPTED;
252 else if (ss == "SENT") 252 else if (ss == "SENT")
253 mStatus = SENT; 253 mStatus = SENT;
254 else if (ss == "TENTATIVE") 254 else if (ss == "TENTATIVE")
255 mStatus = TENTATIVE; 255 mStatus = TENTATIVE;
256 else if (ss == "CONFIRMED") 256 else if (ss == "CONFIRMED")
257 mStatus = CONFIRMED; 257 mStatus = CONFIRMED;
258 else if (ss == "DECLINED") 258 else if (ss == "DECLINED")
259 mStatus = DECLINED; 259 mStatus = DECLINED;
260 else if (ss == "COMPLETED") 260 else if (ss == "COMPLETED")
261 mStatus = COMPLETED; 261 mStatus = COMPLETED;
262 else if (ss == "DELEGATED") 262 else if (ss == "DELEGATED")
263 mStatus = DELEGATED; 263 mStatus = DELEGATED;
264 264
265 updated(); 265 updated();
266} 266}
267 267
268void Todo::setStatus(int status) 268void Todo::setStatus(int status)
269{ 269{
270 if (mReadOnly) return; 270 if (mReadOnly) return;
271 mStatus = status; 271 mStatus = status;
272 updated(); 272 updated();
273} 273}
274 274
275int Todo::status() const 275int Todo::status() const
276{ 276{
277 return mStatus; 277 return mStatus;
278} 278}
279 279
280QString Todo::statusStr() const 280QString Todo::statusStr() const
281{ 281{
282 switch(mStatus) { 282 switch(mStatus) {
283 case NEEDS_ACTION: 283 case NEEDS_ACTION:
284 return QString("NEEDS ACTION"); 284 return QString("NEEDS ACTION");
285 break; 285 break;
286 case ACCEPTED: 286 case ACCEPTED:
287 return QString("ACCEPTED"); 287 return QString("ACCEPTED");
288 break; 288 break;
289 case SENT: 289 case SENT:
290 return QString("SENT"); 290 return QString("SENT");
291 break; 291 break;
292 case TENTATIVE: 292 case TENTATIVE:
293 return QString("TENTATIVE"); 293 return QString("TENTATIVE");
294 break; 294 break;
295 case CONFIRMED: 295 case CONFIRMED:
296 return QString("CONFIRMED"); 296 return QString("CONFIRMED");
297 break; 297 break;
298 case DECLINED: 298 case DECLINED:
299 return QString("DECLINED"); 299 return QString("DECLINED");
300 break; 300 break;
301 case COMPLETED: 301 case COMPLETED:
302 return QString("COMPLETED"); 302 return QString("COMPLETED");
303 break; 303 break;
304 case DELEGATED: 304 case DELEGATED:
305 return QString("DELEGATED"); 305 return QString("DELEGATED");
306 break; 306 break;
307 } 307 }
308 return QString(""); 308 return QString("");
309} 309}
310#endif 310#endif
311 311
312bool Todo::isCompleted() const 312bool Todo::isCompleted() const
313{ 313{
314 if (mPercentComplete == 100) return true; 314 if (mPercentComplete == 100) return true;
315 else return false; 315 else return false;
316} 316}
317 317
318void Todo::setCompleted(bool completed) 318void Todo::setCompleted(bool completed)
319{ 319{
320 if (completed) mPercentComplete = 100; 320 if (completed) mPercentComplete = 100;
321 else { 321 else {
322 mPercentComplete = 0; 322 mPercentComplete = 0;
323 mHasCompletedDate = false; 323 mHasCompletedDate = false;
324 } 324 }
325 updated(); 325 updated();
326} 326}
327 327
328QDateTime Todo::completed() const 328QDateTime Todo::completed() const
329{ 329{
330 return mCompleted; 330 return mCompleted;
331} 331}
332 332
333QString Todo::completedStr( bool shortF ) const 333QString Todo::completedStr( bool shortF ) const
334{ 334{
335 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 335 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
336} 336}
337 337
338void Todo::setCompleted(const QDateTime &completed) 338void Todo::setCompleted(const QDateTime &completed)
339{ 339{
340 //qDebug("Todo::setCompleted "); 340 //qDebug("Todo::setCompleted ");
341 if ( mHasCompletedDate ) { 341 if ( mHasCompletedDate ) {
342 // qDebug("has completed data - return "); 342 // qDebug("has completed data - return ");
343 return; 343 return;
344 } 344 }
345 mHasCompletedDate = true; 345 mHasCompletedDate = true;
346 mPercentComplete = 100; 346 mPercentComplete = 100;
347 mCompleted = getEvenTime(completed); 347 mCompleted = getEvenTime(completed);
348 updated(); 348 updated();
349} 349}
350 350
351bool Todo::hasCompletedDate() const 351bool Todo::hasCompletedDate() const
352{ 352{
353 return mHasCompletedDate; 353 return mHasCompletedDate;
354} 354}
355 355
356int Todo::percentComplete() const 356int Todo::percentComplete() const
357{ 357{
358 return mPercentComplete; 358 return mPercentComplete;
359} 359}
360 360
361void Todo::setPercentComplete(int v) 361void Todo::setPercentComplete(int v)
362{ 362{
363 mPercentComplete = v; 363 mPercentComplete = v;
364 if ( v != 100 ) 364 if ( v != 100 )
365 mHasCompletedDate = false; 365 mHasCompletedDate = false;
366 updated(); 366 updated();
367} 367}
368QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 368QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
369{ 369{
370 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 370 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
371 *ok = false; 371 *ok = false;
372 return QDateTime (); 372 return QDateTime ();
373 } 373 }
374 QDateTime incidenceStart; 374 QDateTime incidenceStart;
375 incidenceStart = dtDue(); 375 incidenceStart = dtDue();
376 bool enabled = false; 376 bool enabled = false;
377 Alarm* alarm; 377 Alarm* alarm;
378 int off; 378 int off = 0;
379 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 379 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
380 // if ( QDateTime::currentDateTime() > incidenceStart ){ 380 // if ( QDateTime::currentDateTime() > incidenceStart ){
381// *ok = false; 381// *ok = false;
382// return incidenceStart; 382// return incidenceStart;
383// } 383// }
384 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 384 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
385 if (alarm->enabled()) { 385 if (alarm->enabled()) {
386 if ( alarm->hasTime () ) { 386 if ( alarm->hasTime () ) {
387 if ( alarm->time() < alarmStart ) { 387 if ( alarm->time() < alarmStart ) {
388 alarmStart = alarm->time(); 388 alarmStart = alarm->time();
389 enabled = true; 389 enabled = true;
390 off = alarmStart.secsTo( incidenceStart ); 390 off = alarmStart.secsTo( incidenceStart );
391 } 391 }
392 392
393 } else { 393 } else {
394 int secs = alarm->startOffset().asSeconds(); 394 int secs = alarm->startOffset().asSeconds();
395 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 395 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
396 alarmStart = incidenceStart.addSecs( secs ); 396 alarmStart = incidenceStart.addSecs( secs );
397 enabled = true; 397 enabled = true;
398 off = -secs; 398 off = -secs;
399 } 399 }
400 } 400 }
401 } 401 }
402 } 402 }
403 if ( enabled ) { 403 if ( enabled ) {
404 if ( alarmStart > QDateTime::currentDateTime() ) { 404 if ( alarmStart > QDateTime::currentDateTime() ) {
405 *ok = true; 405 *ok = true;
406 * offset = off; 406 * offset = off;
407 return alarmStart; 407 return alarmStart;
408 } 408 }
409 } 409 }
410 *ok = false; 410 *ok = false;
411 return QDateTime (); 411 return QDateTime ();
412 412
413} 413}
414 414