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