summaryrefslogtreecommitdiffabout
path: root/libkcal/event.cpp
Unidiff
Diffstat (limited to 'libkcal/event.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/event.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 5285559..ad66639 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -1,395 +1,415 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "event.h" 25#include "event.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::Event(const Event &e) : Incidence(e)
35{ 35{
36 mDtEnd = e.mDtEnd; 36 mDtEnd = e.mDtEnd;
37 mHasEndDate = e.mHasEndDate; 37 mHasEndDate = e.mHasEndDate;
38 mTransparency = e.mTransparency; 38 mTransparency = e.mTransparency;
39} 39}
40 40
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
51{ 51{
52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
53 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
54 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
55 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
56} 56}
57 57
58 58
59bool Event::contains ( Event* from ) 59bool Event::contains ( Event* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->dtStart().isValid() ) 65 if ( from->dtStart().isValid() )
66 if (dtStart() != from->dtStart() ) 66 if (dtStart() != from->dtStart() )
67 return false; 67 return false;
68 if ( from->dtEnd().isValid() ) 68 if ( from->dtEnd().isValid() )
69 if ( dtEnd() != from->dtEnd() ) 69 if ( dtEnd() != from->dtEnd() )
70 return false; 70 return false;
71 if ( !from->location().isEmpty() ) 71 if ( !from->location().isEmpty() )
72 if ( !location().startsWith( from->location() ) ) 72 if ( !location().startsWith( from->location() ) )
73 return false; 73 return false;
74 if ( !from->description().isEmpty() ) 74 if ( !from->description().isEmpty() )
75 if ( !description().startsWith( from->description() )) 75 if ( !description().startsWith( from->description() ))
76 return false; 76 return false;
77 if ( from->alarms().count() ) { 77 if ( from->alarms().count() ) {
78 Alarm *a = from->alarms().first(); 78 Alarm *a = from->alarms().first();
79 if ( a->enabled() ){ 79 if ( a->enabled() ){
80 if ( !alarms().count() ) 80 if ( !alarms().count() )
81 return false; 81 return false;
82 Alarm *b = alarms().first(); 82 Alarm *b = alarms().first();
83 if( ! b->enabled() ) 83 if( ! b->enabled() )
84 return false; 84 return false;
85 if ( ! (a->offset() == b->offset() )) 85 if ( ! (a->offset() == b->offset() ))
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 QStringList cat = categories(); 89 QStringList cat = categories();
90 QStringList catFrom = from->categories(); 90 QStringList catFrom = from->categories();
91 QString nCat; 91 QString nCat;
92 unsigned int iii; 92 unsigned int iii;
93 for ( iii = 0; iii < catFrom.count();++iii ) { 93 for ( iii = 0; iii < catFrom.count();++iii ) {
94 nCat = catFrom[iii]; 94 nCat = catFrom[iii];
95 if ( !nCat.isEmpty() ) 95 if ( !nCat.isEmpty() )
96 if ( !cat.contains( nCat )) { 96 if ( !cat.contains( nCat )) {
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 if ( from->doesRecur() ) 100 if ( from->doesRecur() )
101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) 101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
102 return false; 102 return false;
103 return true; 103 return true;
104} 104}
105 105
106void Event::setDtEnd(const QDateTime &dtEnd) 106void Event::setDtEnd(const QDateTime &dtEnd)
107{ 107{
108 if (mReadOnly) return; 108 if (mReadOnly) return;
109 109
110 mDtEnd = getEvenTime( dtEnd ); 110 mDtEnd = getEvenTime( dtEnd );
111 111
112 setHasEndDate(true); 112 setHasEndDate(true);
113 setHasDuration(false); 113 setHasDuration(false);
114 114
115 updated(); 115 updated();
116} 116}
117 117
118QDateTime Event::dtEnd() const 118QDateTime Event::dtEnd() const
119{ 119{
120 if (hasEndDate()) return mDtEnd; 120 if (hasEndDate()) return mDtEnd;
121 if (hasDuration()) return dtStart().addSecs(duration()); 121 if (hasDuration()) return dtStart().addSecs(duration());
122 122
123 return dtStart(); 123 return dtStart();
124} 124}
125 125
126QString Event::dtEndTimeStr() const 126QString Event::dtEndTimeStr() const
127{ 127{
128 return KGlobal::locale()->formatTime(mDtEnd.time()); 128 return KGlobal::locale()->formatTime(mDtEnd.time());
129} 129}
130 130
131QString Event::dtEndDateStr(bool shortfmt) const 131QString Event::dtEndDateStr(bool shortfmt) const
132{ 132{
133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
134} 134}
135 135
136QString Event::dtEndStr(bool shortfmt) const 136QString Event::dtEndStr(bool shortfmt) const
137{ 137{
138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
139} 139}
140 140
141void Event::setHasEndDate(bool b) 141void Event::setHasEndDate(bool b)
142{ 142{
143 mHasEndDate = b; 143 mHasEndDate = b;
144} 144}
145 145
146bool Event::hasEndDate() const 146bool Event::hasEndDate() const
147{ 147{
148 return mHasEndDate; 148 return mHasEndDate;
149} 149}
150 150
151bool Event::isMultiDay() const 151bool Event::isMultiDay() const
152{ 152{
153 bool multi = !(dtStart().date() == dtEnd().date()); 153 bool multi = !(dtStart().date() == dtEnd().date());
154 return multi; 154 return multi;
155} 155}
156 156
157void Event::setTransparency(Event::Transparency transparency) 157void Event::setTransparency(Event::Transparency transparency)
158{ 158{
159 if (mReadOnly) return; 159 if (mReadOnly) return;
160 mTransparency = transparency; 160 mTransparency = transparency;
161 updated(); 161 updated();
162} 162}
163 163
164Event::Transparency Event::transparency() const 164Event::Transparency Event::transparency() const
165{ 165{
166 return mTransparency; 166 return mTransparency;
167} 167}
168 168
169void Event::setDuration(int seconds) 169void Event::setDuration(int seconds)
170{ 170{
171 setHasEndDate(false); 171 setHasEndDate(false);
172 Incidence::setDuration(seconds); 172 Incidence::setDuration(seconds);
173} 173}
174bool Event::matchTime(QDateTime*startDT, QDateTime* endDT)
175{
176 if ( ! doesRecur() ) {
177 if ( doesFloat() ) {
178 if ( mDtEnd.addDays( 1 ) < *startDT)
179 return false;
180 if ( endDT && mDtStart > * endDT)
181 return false;
182 } else {
183 if ( mDtEnd < *startDT )
184 return false;
185 if ( endDT && mDtStart > * endDT)
186 return false;
187 }
188 } else {
189 if ( endDT && mDtStart > * endDT)
190 return false;
191 }
192 return true;
193}
174bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) 194bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT )
175{ 195{
176 if ( testEvent == this ) 196 if ( testEvent == this )
177 return false; 197 return false;
178 if ( ! doesRecur() && !testEvent->doesRecur() ) { 198 if ( ! doesRecur() && !testEvent->doesRecur() ) {
179 QDateTime te; 199 QDateTime te;
180 if ( testEvent->doesFloat() ) 200 if ( testEvent->doesFloat() )
181 te = testEvent->mDtEnd.addDays( 1 ); 201 te = testEvent->mDtEnd.addDays( 1 );
182 else 202 else
183 te = testEvent->mDtEnd; 203 te = testEvent->mDtEnd;
184 QDateTime e; 204 QDateTime e;
185 if ( doesFloat() ) 205 if ( doesFloat() )
186 e = mDtEnd.addDays( 1 ); 206 e = mDtEnd.addDays( 1 );
187 else 207 else
188 e = mDtEnd; 208 e = mDtEnd;
189 if ( mDtStart < te && testEvent->mDtStart < e ) { 209 if ( mDtStart < te && testEvent->mDtStart < e ) {
190 if ( mDtStart < testEvent->mDtStart ) 210 if ( mDtStart < testEvent->mDtStart )
191 *overlapDT = testEvent->mDtStart; 211 *overlapDT = testEvent->mDtStart;
192 else 212 else
193 *overlapDT = mDtStart; 213 *overlapDT = mDtStart;
194 if ( startDT ) 214 if ( startDT )
195 return (*overlapDT >= *startDT ); 215 return (*overlapDT >= *startDT );
196 return true; 216 return true;
197 } 217 }
198 return false; 218 return false;
199 } 219 }
200 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 220 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
201 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { 221 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) {
202 // no need to test. times mismatch 222 // no need to test. times mismatch
203 //fprintf(stderr,"timi "); 223 //fprintf(stderr,"timi ");
204 return false; 224 return false;
205 } 225 }
206 } 226 }
207 Event *nonRecur = 0; 227 Event *nonRecur = 0;
208 Event *recurEvent = 0; 228 Event *recurEvent = 0;
209 if ( ! doesRecur() ) { 229 if ( ! doesRecur() ) {
210 nonRecur = this; 230 nonRecur = this;
211 recurEvent = testEvent; 231 recurEvent = testEvent;
212 } 232 }
213 else if ( !testEvent->doesRecur() ) { 233 else if ( !testEvent->doesRecur() ) {
214 nonRecur = testEvent; 234 nonRecur = testEvent;
215 recurEvent = this; 235 recurEvent = this;
216 } 236 }
217 if ( nonRecur ) { 237 if ( nonRecur ) {
218 QDateTime enr; 238 QDateTime enr;
219 if ( nonRecur->doesFloat() ) 239 if ( nonRecur->doesFloat() )
220 enr = nonRecur->mDtEnd.addDays( 1 ); 240 enr = nonRecur->mDtEnd.addDays( 1 );
221 else 241 else
222 enr = nonRecur->mDtEnd; 242 enr = nonRecur->mDtEnd;
223 if ( enr < recurEvent->mDtStart ) 243 if ( enr < recurEvent->mDtStart )
224 return false; 244 return false;
225 if ( startDT && enr < *startDT ) 245 if ( startDT && enr < *startDT )
226 return false; 246 return false;
227 247
228 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); 248 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd );
229 if ( recurEvent->doesFloat() ) 249 if ( recurEvent->doesFloat() )
230 recDuration += 86400; 250 recDuration += 86400;
231 bool ok = false; 251 bool ok = false;
232 QDateTime recStart; 252 QDateTime recStart;
233 if ( startDT ) { 253 if ( startDT ) {
234 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 254 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
235 } 255 }
236 if ( recStart.isValid() ) { 256 if ( recStart.isValid() ) {
237 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); 257 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1());
238 recStart = recStart.addSecs( -300); 258 recStart = recStart.addSecs( -300);
239 } 259 }
240 else 260 else
241 recStart = recurEvent->mDtStart.addSecs( -300); 261 recStart = recurEvent->mDtStart.addSecs( -300);
242 ok = true; 262 ok = true;
243 263
244 while ( ok ) { 264 while ( ok ) {
245 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); 265 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok );
246 if ( ok ) { 266 if ( ok ) {
247 if ( recStart > enr ) 267 if ( recStart > enr )
248 return false; 268 return false;
249 QDateTime recEnd = recStart.addSecs( recDuration ); 269 QDateTime recEnd = recStart.addSecs( recDuration );
250 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { 270 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) {
251 if ( nonRecur->mDtStart < recStart ) 271 if ( nonRecur->mDtStart < recStart )
252 *overlapDT = recStart; 272 *overlapDT = recStart;
253 else 273 else
254 *overlapDT = nonRecur->mDtStart; 274 *overlapDT = nonRecur->mDtStart;
255 if ( startDT ) { 275 if ( startDT ) {
256 if ( *overlapDT >= *startDT ) 276 if ( *overlapDT >= *startDT )
257 return true; 277 return true;
258 } else 278 } else
259 return true; 279 return true;
260 } 280 }
261 } 281 }
262 } 282 }
263 return false; 283 return false;
264 } 284 }
265 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 285 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
266 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { 286 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) {
267 bool found = false; 287 bool found = false;
268 uint i; 288 uint i;
269 for ( i=0; i< recurrence()->days().size();++i ) { 289 for ( i=0; i< recurrence()->days().size();++i ) {
270 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); 290 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) );
271 } 291 }
272 if ( ! found ) { 292 if ( ! found ) {
273 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); 293 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1());
274 return false; 294 return false;
275 } 295 }
276 296
277 } 297 }
278 } 298 }
279 bool ok = true; 299 bool ok = true;
280 QDateTime incidenceStart;// = mDtStart; 300 QDateTime incidenceStart;// = mDtStart;
281 QDateTime testincidenceStart;// = testEvent->mDtStart; 301 QDateTime testincidenceStart;// = testEvent->mDtStart;
282 if ( startDT ) { 302 if ( startDT ) {
283 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 303 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
284 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 304 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
285 } 305 }
286 if ( !testincidenceStart.isValid() ) 306 if ( !testincidenceStart.isValid() )
287 testincidenceStart = testEvent->mDtStart; 307 testincidenceStart = testEvent->mDtStart;
288 if ( !incidenceStart.isValid() ) 308 if ( !incidenceStart.isValid() )
289 incidenceStart = mDtStart; 309 incidenceStart = mDtStart;
290 int duration = mDtStart.secsTo( mDtEnd ); 310 int duration = mDtStart.secsTo( mDtEnd );
291 if ( doesFloat() ) 311 if ( doesFloat() )
292 duration += 86400; 312 duration += 86400;
293 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); 313 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd );
294 if ( testEvent->doesFloat() ) 314 if ( testEvent->doesFloat() )
295 testduration += 86400; 315 testduration += 86400;
296 bool computeThis = false; 316 bool computeThis = false;
297 if ( incidenceStart < testincidenceStart ) 317 if ( incidenceStart < testincidenceStart )
298 computeThis = true; 318 computeThis = true;
299 if ( computeThis ) 319 if ( computeThis )
300 incidenceStart = incidenceStart.addSecs( -300 ); 320 incidenceStart = incidenceStart.addSecs( -300 );
301 else 321 else
302 testincidenceStart = testincidenceStart.addSecs( -300 ); 322 testincidenceStart = testincidenceStart.addSecs( -300 );
303 int count = 0; 323 int count = 0;
304 ok = true; 324 ok = true;
305 int countbreak = 2000; 325 int countbreak = 2000;
306 QDateTime stopSearch; 326 QDateTime stopSearch;
307 bool testStop = false; 327 bool testStop = false;
308 if ( startDT ) { 328 if ( startDT ) {
309 stopSearch = startDT->addDays( 365*3 ); 329 stopSearch = startDT->addDays( 365*3 );
310 testStop = true; 330 testStop = true;
311 } 331 }
312 while ( ok ) { 332 while ( ok ) {
313 ++count; 333 ++count;
314 if ( count > countbreak ) break; 334 if ( count > countbreak ) break;
315 if ( computeThis ) { 335 if ( computeThis ) {
316 if ( testStop ) 336 if ( testStop )
317 if ( testincidenceStart > stopSearch ) 337 if ( testincidenceStart > stopSearch )
318 break; 338 break;
319 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); 339 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok );
320 } 340 }
321 else { 341 else {
322 if ( testStop ) 342 if ( testStop )
323 if ( incidenceStart > stopSearch ) 343 if ( incidenceStart > stopSearch )
324 break; 344 break;
325 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); 345 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok );
326 } 346 }
327 if ( ok ) { 347 if ( ok ) {
328 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { 348 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) {
329 if ( incidenceStart < testincidenceStart ) 349 if ( incidenceStart < testincidenceStart )
330 *overlapDT = testincidenceStart; 350 *overlapDT = testincidenceStart;
331 else 351 else
332 *overlapDT = incidenceStart; 352 *overlapDT = incidenceStart;
333 if ( startDT ) { 353 if ( startDT ) {
334 if ( *overlapDT >= *startDT ) 354 if ( *overlapDT >= *startDT )
335 return true; 355 return true;
336 } else 356 } else
337 return true; 357 return true;
338 } 358 }
339 computeThis = ( incidenceStart < testincidenceStart ); 359 computeThis = ( incidenceStart < testincidenceStart );
340 } 360 }
341 361
342 } 362 }
343 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); 363 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() );
344 return false; 364 return false;
345} 365}
346QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 366QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
347{ 367{
348 *ok = false; 368 *ok = false;
349 if ( !alarmEnabled() ) 369 if ( !alarmEnabled() )
350 return QDateTime (); 370 return QDateTime ();
351 bool yes; 371 bool yes;
352 QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); 372 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
353 if ( ! yes || cancelled() ) { 373 if ( ! yes || cancelled() ) {
354 *ok = false; 374 *ok = false;
355 return QDateTime (); 375 return QDateTime ();
356 } 376 }
357 377
358 bool enabled = false; 378 bool enabled = false;
359 Alarm* alarm; 379 Alarm* alarm;
360 int off = 0; 380 int off = 0;
361 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 381 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
362 // if ( QDateTime::currentDateTime() > incidenceStart ){ 382 // if ( QDateTime::currentDateTime() > incidenceStart ){
363// *ok = false; 383// *ok = false;
364// return incidenceStart; 384// return incidenceStart;
365// } 385// }
366 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 386 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
367 if (alarm->enabled()) { 387 if (alarm->enabled()) {
368 if ( alarm->hasTime () ) { 388 if ( alarm->hasTime () ) {
369 if ( alarm->time() < alarmStart ) { 389 if ( alarm->time() < alarmStart ) {
370 alarmStart = alarm->time(); 390 alarmStart = alarm->time();
371 enabled = true; 391 enabled = true;
372 off = alarmStart.secsTo( incidenceStart ); 392 off = alarmStart.secsTo( incidenceStart );
373 } 393 }
374 394
375 } else { 395 } else {
376 int secs = alarm->startOffset().asSeconds(); 396 int secs = alarm->startOffset().asSeconds();
377 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 397 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
378 alarmStart = incidenceStart.addSecs( secs ); 398 alarmStart = incidenceStart.addSecs( secs );
379 enabled = true; 399 enabled = true;
380 off = -secs; 400 off = -secs;
381 } 401 }
382 } 402 }
383 } 403 }
384 } 404 }
385 if ( enabled ) { 405 if ( enabled ) {
386 if ( alarmStart > start_dt ) { 406 if ( alarmStart > start_dt ) {
387 *ok = true; 407 *ok = true;
388 * offset = off; 408 * offset = off;
389 return alarmStart; 409 return alarmStart;
390 } 410 }
391 } 411 }
392 *ok = false; 412 *ok = false;
393 return QDateTime (); 413 return QDateTime ();
394 414
395} 415}