author | zautrix <zautrix> | 2005-07-08 10:00:24 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-08 10:00:24 (UTC) |
commit | e1ed9342934d027f8b72a97eb710a52abe53b719 (patch) (unidiff) | |
tree | 2d1eef77b64cb5cc9e040fea3a35d240fee5bfd2 | |
parent | 9635c9a7b8f5c19a1784079d4b67cb3ca600fc33 (diff) | |
download | kdepimpi-e1ed9342934d027f8b72a97eb710a52abe53b719.zip kdepimpi-e1ed9342934d027f8b72a97eb710a52abe53b719.tar.gz kdepimpi-e1ed9342934d027f8b72a97eb710a52abe53b719.tar.bz2 |
rec dect fix
-rw-r--r-- | libkcal/event.cpp | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index 46e8174..5285559 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp | |||
@@ -1,338 +1,395 @@ | |||
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 | ||
27 | using namespace KCal; | 27 | using namespace KCal; |
28 | 28 | ||
29 | Event::Event() : | 29 | Event::Event() : |
30 | mHasEndDate( false ), mTransparency( Opaque ) | 30 | mHasEndDate( false ), mTransparency( Opaque ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | Event::Event(const Event &e) : Incidence(e) | 34 | Event::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 | ||
41 | Event::~Event() | 41 | Event::~Event() |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | Incidence *Event::clone() | 45 | Incidence *Event::clone() |
46 | { | 46 | { |
47 | return new Event(*this); | 47 | return new Event(*this); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool KCal::operator==( const Event& e1, const Event& e2 ) | 50 | bool 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 | ||
59 | bool Event::contains ( Event* from ) | 59 | bool 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 | ||
106 | void Event::setDtEnd(const QDateTime &dtEnd) | 106 | void 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 | ||
118 | QDateTime Event::dtEnd() const | 118 | QDateTime 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 | ||
126 | QString Event::dtEndTimeStr() const | 126 | QString Event::dtEndTimeStr() const |
127 | { | 127 | { |
128 | return KGlobal::locale()->formatTime(mDtEnd.time()); | 128 | return KGlobal::locale()->formatTime(mDtEnd.time()); |
129 | } | 129 | } |
130 | 130 | ||
131 | QString Event::dtEndDateStr(bool shortfmt) const | 131 | QString 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 | ||
136 | QString Event::dtEndStr(bool shortfmt) const | 136 | QString 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 | ||
141 | void Event::setHasEndDate(bool b) | 141 | void Event::setHasEndDate(bool b) |
142 | { | 142 | { |
143 | mHasEndDate = b; | 143 | mHasEndDate = b; |
144 | } | 144 | } |
145 | 145 | ||
146 | bool Event::hasEndDate() const | 146 | bool Event::hasEndDate() const |
147 | { | 147 | { |
148 | return mHasEndDate; | 148 | return mHasEndDate; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool Event::isMultiDay() const | 151 | bool 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 | ||
157 | void Event::setTransparency(Event::Transparency transparency) | 157 | void 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 | ||
164 | Event::Transparency Event::transparency() const | 164 | Event::Transparency Event::transparency() const |
165 | { | 165 | { |
166 | return mTransparency; | 166 | return mTransparency; |
167 | } | 167 | } |
168 | 168 | ||
169 | void Event::setDuration(int seconds) | 169 | void Event::setDuration(int seconds) |
170 | { | 170 | { |
171 | setHasEndDate(false); | 171 | setHasEndDate(false); |
172 | Incidence::setDuration(seconds); | 172 | Incidence::setDuration(seconds); |
173 | } | 173 | } |
174 | bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) | 174 | bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) |
175 | { | 175 | { |
176 | if ( testEvent == this ) | 176 | if ( testEvent == this ) |
177 | return false; | 177 | return false; |
178 | if ( ! doesRecur() && !testEvent->doesRecur() ) { | 178 | if ( ! doesRecur() && !testEvent->doesRecur() ) { |
179 | QDateTime te; | 179 | QDateTime te; |
180 | if ( testEvent->doesFloat() ) | 180 | if ( testEvent->doesFloat() ) |
181 | te = testEvent->mDtEnd.addDays( 1 ); | 181 | te = testEvent->mDtEnd.addDays( 1 ); |
182 | else | 182 | else |
183 | te = testEvent->mDtEnd; | 183 | te = testEvent->mDtEnd; |
184 | QDateTime e; | 184 | QDateTime e; |
185 | if ( doesFloat() ) | 185 | if ( doesFloat() ) |
186 | e = mDtEnd.addDays( 1 ); | 186 | e = mDtEnd.addDays( 1 ); |
187 | else | 187 | else |
188 | e = mDtEnd; | 188 | e = mDtEnd; |
189 | if ( mDtStart < te && testEvent->mDtStart < e ) { | 189 | if ( mDtStart < te && testEvent->mDtStart < e ) { |
190 | if ( mDtStart < testEvent->mDtStart ) | 190 | if ( mDtStart < testEvent->mDtStart ) |
191 | *overlapDT = testEvent->mDtStart; | 191 | *overlapDT = testEvent->mDtStart; |
192 | else | 192 | else |
193 | *overlapDT = mDtStart; | 193 | *overlapDT = mDtStart; |
194 | if ( startDT ) | 194 | if ( startDT ) |
195 | return (*overlapDT >= *startDT ); | 195 | return (*overlapDT >= *startDT ); |
196 | return true; | 196 | return true; |
197 | } | 197 | } |
198 | return false; | 198 | return false; |
199 | } | 199 | } |
200 | if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { | ||
201 | if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { | ||
202 | // no need to test. times mismatch | ||
203 | //fprintf(stderr,"timi "); | ||
204 | return false; | ||
205 | } | ||
206 | } | ||
200 | Event *nonRecur = 0; | 207 | Event *nonRecur = 0; |
201 | Event *recurEvent = 0; | 208 | Event *recurEvent = 0; |
202 | if ( ! doesRecur() ) { | 209 | if ( ! doesRecur() ) { |
203 | nonRecur = this; | 210 | nonRecur = this; |
204 | recurEvent = testEvent; | 211 | recurEvent = testEvent; |
205 | } | 212 | } |
206 | else if ( !testEvent->doesRecur() ) { | 213 | else if ( !testEvent->doesRecur() ) { |
207 | nonRecur = testEvent; | 214 | nonRecur = testEvent; |
208 | recurEvent = this; | 215 | recurEvent = this; |
209 | } | 216 | } |
210 | if ( nonRecur ) { | 217 | if ( nonRecur ) { |
211 | QDateTime enr; | 218 | QDateTime enr; |
212 | if ( nonRecur->doesFloat() ) | 219 | if ( nonRecur->doesFloat() ) |
213 | enr = nonRecur->mDtEnd.addDays( 1 ); | 220 | enr = nonRecur->mDtEnd.addDays( 1 ); |
214 | else | 221 | else |
215 | enr = nonRecur->mDtEnd; | 222 | enr = nonRecur->mDtEnd; |
216 | if ( enr < recurEvent->mDtStart ) | 223 | if ( enr < recurEvent->mDtStart ) |
217 | return false; | 224 | return false; |
218 | if ( startDT && enr < *startDT ) | 225 | if ( startDT && enr < *startDT ) |
219 | return false; | 226 | return false; |
227 | |||
220 | int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); | 228 | int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); |
221 | if ( recurEvent->doesFloat() ) | 229 | if ( recurEvent->doesFloat() ) |
222 | recDuration += 86400; | 230 | recDuration += 86400; |
223 | bool ok = true; | 231 | bool ok = false; |
224 | QDateTime recStart = recurEvent->mDtStart.addSecs( -300);; | 232 | QDateTime recStart; |
233 | if ( startDT ) { | ||
234 | recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); | ||
235 | } | ||
236 | if ( recStart.isValid() ) { | ||
237 | //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); | ||
238 | recStart = recStart.addSecs( -300); | ||
239 | } | ||
240 | else | ||
241 | recStart = recurEvent->mDtStart.addSecs( -300); | ||
242 | ok = true; | ||
243 | |||
225 | while ( ok ) { | 244 | while ( ok ) { |
226 | recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); | 245 | recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); |
227 | if ( ok ) { | 246 | if ( ok ) { |
228 | if ( recStart > enr ) | 247 | if ( recStart > enr ) |
229 | return false; | 248 | return false; |
230 | QDateTime recEnd = recStart.addSecs( recDuration ); | 249 | QDateTime recEnd = recStart.addSecs( recDuration ); |
231 | if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { | 250 | if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { |
232 | if ( nonRecur->mDtStart < recStart ) | 251 | if ( nonRecur->mDtStart < recStart ) |
233 | *overlapDT = recStart; | 252 | *overlapDT = recStart; |
234 | else | 253 | else |
235 | *overlapDT = nonRecur->mDtStart; | 254 | *overlapDT = nonRecur->mDtStart; |
236 | if ( startDT ) { | 255 | if ( startDT ) { |
237 | if ( *overlapDT >= *startDT ) | 256 | if ( *overlapDT >= *startDT ) |
238 | return true; | 257 | return true; |
239 | } else | 258 | } else |
240 | return true; | 259 | return true; |
241 | } | 260 | } |
242 | } | 261 | } |
243 | } | 262 | } |
244 | return false; | 263 | return false; |
245 | } | 264 | } |
246 | 265 | if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { | |
247 | QDateTime incidenceStart = mDtStart; | 266 | if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { |
267 | bool found = false; | ||
268 | uint i; | ||
269 | for ( i=0; i< recurrence()->days().size();++i ) { | ||
270 | found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); | ||
271 | } | ||
272 | if ( ! found ) { | ||
273 | //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); | ||
274 | return false; | ||
275 | } | ||
276 | |||
277 | } | ||
278 | } | ||
279 | bool ok = true; | ||
280 | QDateTime incidenceStart;// = mDtStart; | ||
281 | QDateTime testincidenceStart;// = testEvent->mDtStart; | ||
282 | if ( startDT ) { | ||
283 | incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); | ||
284 | testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); | ||
285 | } | ||
286 | if ( !testincidenceStart.isValid() ) | ||
287 | testincidenceStart = testEvent->mDtStart; | ||
288 | if ( !incidenceStart.isValid() ) | ||
289 | incidenceStart = mDtStart; | ||
248 | int duration = mDtStart.secsTo( mDtEnd ); | 290 | int duration = mDtStart.secsTo( mDtEnd ); |
249 | if ( doesFloat() ) | 291 | if ( doesFloat() ) |
250 | duration += 86400; | 292 | duration += 86400; |
251 | QDateTime testincidenceStart = testEvent->mDtStart; | ||
252 | int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); | 293 | int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); |
253 | if ( testEvent->doesFloat() ) | 294 | if ( testEvent->doesFloat() ) |
254 | testduration += 86400; | 295 | testduration += 86400; |
255 | bool computeThis = false; | 296 | bool computeThis = false; |
256 | if ( incidenceStart < testincidenceStart ) | 297 | if ( incidenceStart < testincidenceStart ) |
257 | computeThis = true; | 298 | computeThis = true; |
258 | bool ok = true; | ||
259 | if ( computeThis ) | 299 | if ( computeThis ) |
260 | incidenceStart = incidenceStart.addSecs( -300 ); | 300 | incidenceStart = incidenceStart.addSecs( -300 ); |
261 | else | 301 | else |
262 | testincidenceStart = testincidenceStart.addSecs( -300 ); | 302 | testincidenceStart = testincidenceStart.addSecs( -300 ); |
263 | int count = 0; | 303 | int count = 0; |
304 | ok = true; | ||
305 | int countbreak = 2000; | ||
306 | QDateTime stopSearch; | ||
307 | bool testStop = false; | ||
308 | if ( startDT ) { | ||
309 | stopSearch = startDT->addDays( 365*3 ); | ||
310 | testStop = true; | ||
311 | } | ||
264 | while ( ok ) { | 312 | while ( ok ) { |
265 | ++count; | 313 | ++count; |
266 | if ( count > 1000 ) break; | 314 | if ( count > countbreak ) break; |
267 | if ( computeThis ) | 315 | if ( computeThis ) { |
316 | if ( testStop ) | ||
317 | if ( testincidenceStart > stopSearch ) | ||
318 | break; | ||
268 | incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); | 319 | incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); |
269 | else | 320 | } |
321 | else { | ||
322 | if ( testStop ) | ||
323 | if ( incidenceStart > stopSearch ) | ||
324 | break; | ||
270 | testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); | 325 | testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); |
326 | } | ||
271 | if ( ok ) { | 327 | if ( ok ) { |
272 | if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { | 328 | if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { |
273 | if ( incidenceStart < testincidenceStart ) | 329 | if ( incidenceStart < testincidenceStart ) |
274 | *overlapDT = testincidenceStart; | 330 | *overlapDT = testincidenceStart; |
275 | else | 331 | else |
276 | *overlapDT = incidenceStart; | 332 | *overlapDT = incidenceStart; |
277 | if ( startDT ) { | 333 | if ( startDT ) { |
278 | if ( *overlapDT >= *startDT ) | 334 | if ( *overlapDT >= *startDT ) |
279 | return true; | 335 | return true; |
280 | } else | 336 | } else |
281 | return true; | 337 | return true; |
282 | } | 338 | } |
283 | computeThis = ( incidenceStart < testincidenceStart ); | 339 | computeThis = ( incidenceStart < testincidenceStart ); |
284 | } | 340 | } |
285 | 341 | ||
286 | } | 342 | } |
343 | //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); | ||
287 | return false; | 344 | return false; |
288 | } | 345 | } |
289 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 346 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
290 | { | 347 | { |
291 | *ok = false; | 348 | *ok = false; |
292 | if ( !alarmEnabled() ) | 349 | if ( !alarmEnabled() ) |
293 | return QDateTime (); | 350 | return QDateTime (); |
294 | bool yes; | 351 | bool yes; |
295 | QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); | 352 | QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); |
296 | if ( ! yes || cancelled() ) { | 353 | if ( ! yes || cancelled() ) { |
297 | *ok = false; | 354 | *ok = false; |
298 | return QDateTime (); | 355 | return QDateTime (); |
299 | } | 356 | } |
300 | 357 | ||
301 | bool enabled = false; | 358 | bool enabled = false; |
302 | Alarm* alarm; | 359 | Alarm* alarm; |
303 | int off = 0; | 360 | int off = 0; |
304 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 361 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
305 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 362 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
306 | // *ok = false; | 363 | // *ok = false; |
307 | // return incidenceStart; | 364 | // return incidenceStart; |
308 | // } | 365 | // } |
309 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 366 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
310 | if (alarm->enabled()) { | 367 | if (alarm->enabled()) { |
311 | if ( alarm->hasTime () ) { | 368 | if ( alarm->hasTime () ) { |
312 | if ( alarm->time() < alarmStart ) { | 369 | if ( alarm->time() < alarmStart ) { |
313 | alarmStart = alarm->time(); | 370 | alarmStart = alarm->time(); |
314 | enabled = true; | 371 | enabled = true; |
315 | off = alarmStart.secsTo( incidenceStart ); | 372 | off = alarmStart.secsTo( incidenceStart ); |
316 | } | 373 | } |
317 | 374 | ||
318 | } else { | 375 | } else { |
319 | int secs = alarm->startOffset().asSeconds(); | 376 | int secs = alarm->startOffset().asSeconds(); |
320 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 377 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
321 | alarmStart = incidenceStart.addSecs( secs ); | 378 | alarmStart = incidenceStart.addSecs( secs ); |
322 | enabled = true; | 379 | enabled = true; |
323 | off = -secs; | 380 | off = -secs; |
324 | } | 381 | } |
325 | } | 382 | } |
326 | } | 383 | } |
327 | } | 384 | } |
328 | if ( enabled ) { | 385 | if ( enabled ) { |
329 | if ( alarmStart > start_dt ) { | 386 | if ( alarmStart > start_dt ) { |
330 | *ok = true; | 387 | *ok = true; |
331 | * offset = off; | 388 | * offset = off; |
332 | return alarmStart; | 389 | return alarmStart; |
333 | } | 390 | } |
334 | } | 391 | } |
335 | *ok = false; | 392 | *ok = false; |
336 | return QDateTime (); | 393 | return QDateTime (); |
337 | 394 | ||
338 | } | 395 | } |