-rw-r--r-- | libkcal/calendarlocal.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 0eba6a9..52c298b 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,724 +1,725 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | if ( mUndoIncidence ) delete mUndoIncidence; | 155 | if ( mUndoIncidence ) delete mUndoIncidence; |
156 | mUndoIncidence = event->clone(); | 156 | mUndoIncidence = event->clone(); |
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | if ( mUndoIncidence ) delete mUndoIncidence; | 204 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | removeRelations( todo ); | 205 | removeRelations( todo ); |
206 | mUndoIncidence = todo->clone(); | 206 | mUndoIncidence = todo->clone(); |
207 | 207 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 208 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 209 | setModified( true ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 213 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 214 | { |
215 | return mTodoList; | 215 | return mTodoList; |
216 | } | 216 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 218 | { |
219 | Todo *todo; | 219 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 221 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 222 | } |
223 | 223 | ||
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 226 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 227 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 228 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 229 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 230 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 231 | inc->removeID( syncProfile ); |
232 | } | 232 | } |
233 | if ( syncProfile.isEmpty() ) { | 233 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 234 | QPtrList<Event> el; |
235 | Event *todo; | 235 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 238 | el.append( todo ); |
239 | } | 239 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 240 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 241 | deleteIncidence ( todo ); |
242 | } | 242 | } |
243 | } else { | 243 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 244 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | deleteIncidence ( lse ); | 245 | if ( lse ) |
246 | deleteIncidence ( lse ); | ||
246 | } | 247 | } |
247 | } | 248 | } |
248 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
249 | { | 250 | { |
250 | QPtrList<Event> el; | 251 | QPtrList<Event> el; |
251 | Event *todo; | 252 | Event *todo; |
252 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
253 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
254 | if ( todo->summary().left(3) == "E: " ) | 255 | if ( todo->summary().left(3) == "E: " ) |
255 | el.append( todo ); | 256 | el.append( todo ); |
256 | } | 257 | } |
257 | 258 | ||
258 | return el; | 259 | return el; |
259 | 260 | ||
260 | } | 261 | } |
261 | Event *CalendarLocal::event( QString syncProf, QString id ) | 262 | Event *CalendarLocal::event( QString syncProf, QString id ) |
262 | { | 263 | { |
263 | Event *todo; | 264 | Event *todo; |
264 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
265 | if ( todo->getID( syncProf ) == id ) return todo; | 266 | if ( todo->getID( syncProf ) == id ) return todo; |
266 | } | 267 | } |
267 | 268 | ||
268 | return 0; | 269 | return 0; |
269 | } | 270 | } |
270 | Todo *CalendarLocal::todo( const QString &uid ) | 271 | Todo *CalendarLocal::todo( const QString &uid ) |
271 | { | 272 | { |
272 | Todo *todo; | 273 | Todo *todo; |
273 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
274 | if ( todo->uid() == uid ) return todo; | 275 | if ( todo->uid() == uid ) return todo; |
275 | } | 276 | } |
276 | 277 | ||
277 | return 0; | 278 | return 0; |
278 | } | 279 | } |
279 | QString CalendarLocal::nextSummary() const | 280 | QString CalendarLocal::nextSummary() const |
280 | { | 281 | { |
281 | return mNextSummary; | 282 | return mNextSummary; |
282 | } | 283 | } |
283 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
284 | { | 285 | { |
285 | return mNextAlarmEventDateTime; | 286 | return mNextAlarmEventDateTime; |
286 | } | 287 | } |
287 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
288 | { | 289 | { |
289 | //mNextAlarmIncidence | 290 | //mNextAlarmIncidence |
290 | //mNextAlarmDateTime | 291 | //mNextAlarmDateTime |
291 | //return mNextSummary; | 292 | //return mNextSummary; |
292 | //return mNextAlarmEventDateTime; | 293 | //return mNextAlarmEventDateTime; |
293 | bool newNextAlarm = false; | 294 | bool newNextAlarm = false; |
294 | bool computeNextAlarm = false; | 295 | bool computeNextAlarm = false; |
295 | bool ok; | 296 | bool ok; |
296 | int offset; | 297 | int offset; |
297 | QDateTime nextA; | 298 | QDateTime nextA; |
298 | // QString nextSum; | 299 | // QString nextSum; |
299 | //QDateTime nextEvent; | 300 | //QDateTime nextEvent; |
300 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 301 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
301 | computeNextAlarm = true; | 302 | computeNextAlarm = true; |
302 | } else { | 303 | } else { |
303 | if ( ! deleted ) { | 304 | if ( ! deleted ) { |
304 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 305 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
305 | if ( ok ) { | 306 | if ( ok ) { |
306 | if ( nextA < mNextAlarmDateTime ) { | 307 | if ( nextA < mNextAlarmDateTime ) { |
307 | deRegisterAlarm(); | 308 | deRegisterAlarm(); |
308 | mNextAlarmDateTime = nextA; | 309 | mNextAlarmDateTime = nextA; |
309 | mNextSummary = incidence->summary(); | 310 | mNextSummary = incidence->summary(); |
310 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 311 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
311 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 312 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
312 | newNextAlarm = true; | 313 | newNextAlarm = true; |
313 | mNextAlarmIncidence = incidence; | 314 | mNextAlarmIncidence = incidence; |
314 | } else { | 315 | } else { |
315 | if ( incidence == mNextAlarmIncidence ) { | 316 | if ( incidence == mNextAlarmIncidence ) { |
316 | computeNextAlarm = true; | 317 | computeNextAlarm = true; |
317 | } | 318 | } |
318 | } | 319 | } |
319 | } else { | 320 | } else { |
320 | if ( mNextAlarmIncidence == incidence ) { | 321 | if ( mNextAlarmIncidence == incidence ) { |
321 | computeNextAlarm = true; | 322 | computeNextAlarm = true; |
322 | } | 323 | } |
323 | } | 324 | } |
324 | } else { // deleted | 325 | } else { // deleted |
325 | if ( incidence == mNextAlarmIncidence ) { | 326 | if ( incidence == mNextAlarmIncidence ) { |
326 | computeNextAlarm = true; | 327 | computeNextAlarm = true; |
327 | } | 328 | } |
328 | } | 329 | } |
329 | } | 330 | } |
330 | if ( computeNextAlarm ) { | 331 | if ( computeNextAlarm ) { |
331 | deRegisterAlarm(); | 332 | deRegisterAlarm(); |
332 | nextA = nextAlarm( 1000 ); | 333 | nextA = nextAlarm( 1000 ); |
333 | if (! mNextAlarmIncidence ) { | 334 | if (! mNextAlarmIncidence ) { |
334 | return; | 335 | return; |
335 | } | 336 | } |
336 | newNextAlarm = true; | 337 | newNextAlarm = true; |
337 | } | 338 | } |
338 | if ( newNextAlarm ) | 339 | if ( newNextAlarm ) |
339 | registerAlarm(); | 340 | registerAlarm(); |
340 | } | 341 | } |
341 | QString CalendarLocal:: getAlarmNotification() | 342 | QString CalendarLocal:: getAlarmNotification() |
342 | { | 343 | { |
343 | QString ret; | 344 | QString ret; |
344 | // this should not happen | 345 | // this should not happen |
345 | if (! mNextAlarmIncidence ) | 346 | if (! mNextAlarmIncidence ) |
346 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 347 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
347 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 348 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
348 | if ( alarm->type() == Alarm::Procedure ) { | 349 | if ( alarm->type() == Alarm::Procedure ) { |
349 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 350 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
350 | } else { | 351 | } else { |
351 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 352 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
352 | } | 353 | } |
353 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 354 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
354 | if ( mNextSummary.length() > 25 ) | 355 | if ( mNextSummary.length() > 25 ) |
355 | ret += "\n" + mNextSummary.mid(25, 25 ); | 356 | ret += "\n" + mNextSummary.mid(25, 25 ); |
356 | ret+= "\n"+mNextAlarmEventDateTimeString; | 357 | ret+= "\n"+mNextAlarmEventDateTimeString; |
357 | return ret; | 358 | return ret; |
358 | } | 359 | } |
359 | void CalendarLocal::registerAlarm() | 360 | void CalendarLocal::registerAlarm() |
360 | { | 361 | { |
361 | mLastAlarmNotificationString = getAlarmNotification(); | 362 | mLastAlarmNotificationString = getAlarmNotification(); |
362 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 363 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
363 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 364 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
364 | // #ifndef DESKTOP_VERSION | 365 | // #ifndef DESKTOP_VERSION |
365 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 366 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
366 | // #endif | 367 | // #endif |
367 | } | 368 | } |
368 | void CalendarLocal::deRegisterAlarm() | 369 | void CalendarLocal::deRegisterAlarm() |
369 | { | 370 | { |
370 | if ( mLastAlarmNotificationString.isNull() ) | 371 | if ( mLastAlarmNotificationString.isNull() ) |
371 | return; | 372 | return; |
372 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 373 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
373 | 374 | ||
374 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 375 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
375 | // #ifndef DESKTOP_VERSION | 376 | // #ifndef DESKTOP_VERSION |
376 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 377 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
377 | // #endif | 378 | // #endif |
378 | } | 379 | } |
379 | 380 | ||
380 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 381 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
381 | { | 382 | { |
382 | QPtrList<Todo> todos; | 383 | QPtrList<Todo> todos; |
383 | 384 | ||
384 | Todo *todo; | 385 | Todo *todo; |
385 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 386 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
386 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 387 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
387 | todos.append( todo ); | 388 | todos.append( todo ); |
388 | } | 389 | } |
389 | } | 390 | } |
390 | 391 | ||
391 | filter()->apply( &todos ); | 392 | filter()->apply( &todos ); |
392 | return todos; | 393 | return todos; |
393 | } | 394 | } |
394 | void CalendarLocal::reInitAlarmSettings() | 395 | void CalendarLocal::reInitAlarmSettings() |
395 | { | 396 | { |
396 | if ( !mNextAlarmIncidence ) { | 397 | if ( !mNextAlarmIncidence ) { |
397 | nextAlarm( 1000 ); | 398 | nextAlarm( 1000 ); |
398 | } | 399 | } |
399 | deRegisterAlarm(); | 400 | deRegisterAlarm(); |
400 | mNextAlarmIncidence = 0; | 401 | mNextAlarmIncidence = 0; |
401 | checkAlarmForIncidence( 0, false ); | 402 | checkAlarmForIncidence( 0, false ); |
402 | 403 | ||
403 | } | 404 | } |
404 | 405 | ||
405 | 406 | ||
406 | 407 | ||
407 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 408 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
408 | { | 409 | { |
409 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 410 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
410 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 411 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
411 | QDateTime next; | 412 | QDateTime next; |
412 | Event *e; | 413 | Event *e; |
413 | bool ok; | 414 | bool ok; |
414 | bool found = false; | 415 | bool found = false; |
415 | int offset; | 416 | int offset; |
416 | mNextAlarmIncidence = 0; | 417 | mNextAlarmIncidence = 0; |
417 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 418 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
418 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 419 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
419 | if ( ok ) { | 420 | if ( ok ) { |
420 | if ( next < nextA ) { | 421 | if ( next < nextA ) { |
421 | nextA = next; | 422 | nextA = next; |
422 | found = true; | 423 | found = true; |
423 | mNextSummary = e->summary(); | 424 | mNextSummary = e->summary(); |
424 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 425 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
425 | mNextAlarmIncidence = (Incidence *) e; | 426 | mNextAlarmIncidence = (Incidence *) e; |
426 | } | 427 | } |
427 | } | 428 | } |
428 | } | 429 | } |
429 | Todo *t; | 430 | Todo *t; |
430 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 431 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
431 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 432 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
432 | if ( ok ) { | 433 | if ( ok ) { |
433 | if ( next < nextA ) { | 434 | if ( next < nextA ) { |
434 | nextA = next; | 435 | nextA = next; |
435 | found = true; | 436 | found = true; |
436 | mNextSummary = t->summary(); | 437 | mNextSummary = t->summary(); |
437 | mNextAlarmEventDateTime = next.addSecs(offset ); | 438 | mNextAlarmEventDateTime = next.addSecs(offset ); |
438 | mNextAlarmIncidence = (Incidence *) t; | 439 | mNextAlarmIncidence = (Incidence *) t; |
439 | } | 440 | } |
440 | } | 441 | } |
441 | } | 442 | } |
442 | if ( mNextAlarmIncidence ) { | 443 | if ( mNextAlarmIncidence ) { |
443 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 444 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
444 | mNextAlarmDateTime = nextA; | 445 | mNextAlarmDateTime = nextA; |
445 | } | 446 | } |
446 | return nextA; | 447 | return nextA; |
447 | } | 448 | } |
448 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 449 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
449 | { | 450 | { |
450 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 451 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
451 | } | 452 | } |
452 | 453 | ||
453 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 454 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
454 | { | 455 | { |
455 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 456 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
456 | << to.toString() << ")\n"; | 457 | << to.toString() << ")\n"; |
457 | 458 | ||
458 | Alarm::List alarms; | 459 | Alarm::List alarms; |
459 | 460 | ||
460 | Event *e; | 461 | Event *e; |
461 | 462 | ||
462 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 463 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
463 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 464 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
464 | else appendAlarms( alarms, e, from, to ); | 465 | else appendAlarms( alarms, e, from, to ); |
465 | } | 466 | } |
466 | 467 | ||
467 | Todo *t; | 468 | Todo *t; |
468 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 469 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
469 | appendAlarms( alarms, t, from, to ); | 470 | appendAlarms( alarms, t, from, to ); |
470 | } | 471 | } |
471 | 472 | ||
472 | return alarms; | 473 | return alarms; |
473 | } | 474 | } |
474 | 475 | ||
475 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 476 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
476 | const QDateTime &from, const QDateTime &to ) | 477 | const QDateTime &from, const QDateTime &to ) |
477 | { | 478 | { |
478 | QPtrList<Alarm> alarmList = incidence->alarms(); | 479 | QPtrList<Alarm> alarmList = incidence->alarms(); |
479 | Alarm *alarm; | 480 | Alarm *alarm; |
480 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 481 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
481 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 482 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
482 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 483 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
483 | if ( alarm->enabled() ) { | 484 | if ( alarm->enabled() ) { |
484 | if ( alarm->time() >= from && alarm->time() <= to ) { | 485 | if ( alarm->time() >= from && alarm->time() <= to ) { |
485 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 486 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
486 | << "': " << alarm->time().toString() << endl; | 487 | << "': " << alarm->time().toString() << endl; |
487 | alarms.append( alarm ); | 488 | alarms.append( alarm ); |
488 | } | 489 | } |
489 | } | 490 | } |
490 | } | 491 | } |
491 | } | 492 | } |
492 | 493 | ||
493 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 494 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
494 | Incidence *incidence, | 495 | Incidence *incidence, |
495 | const QDateTime &from, | 496 | const QDateTime &from, |
496 | const QDateTime &to ) | 497 | const QDateTime &to ) |
497 | { | 498 | { |
498 | 499 | ||
499 | QPtrList<Alarm> alarmList = incidence->alarms(); | 500 | QPtrList<Alarm> alarmList = incidence->alarms(); |
500 | Alarm *alarm; | 501 | Alarm *alarm; |
501 | QDateTime qdt; | 502 | QDateTime qdt; |
502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 503 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
503 | if (incidence->recursOn(from.date())) { | 504 | if (incidence->recursOn(from.date())) { |
504 | qdt.setTime(alarm->time().time()); | 505 | qdt.setTime(alarm->time().time()); |
505 | qdt.setDate(from.date()); | 506 | qdt.setDate(from.date()); |
506 | } | 507 | } |
507 | else qdt = alarm->time(); | 508 | else qdt = alarm->time(); |
508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 509 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
509 | if ( alarm->enabled() ) { | 510 | if ( alarm->enabled() ) { |
510 | if ( qdt >= from && qdt <= to ) { | 511 | if ( qdt >= from && qdt <= to ) { |
511 | alarms.append( alarm ); | 512 | alarms.append( alarm ); |
512 | } | 513 | } |
513 | } | 514 | } |
514 | } | 515 | } |
515 | } | 516 | } |
516 | 517 | ||
517 | 518 | ||
518 | /****************************** PROTECTED METHODS ****************************/ | 519 | /****************************** PROTECTED METHODS ****************************/ |
519 | 520 | ||
520 | // after changes are made to an event, this should be called. | 521 | // after changes are made to an event, this should be called. |
521 | void CalendarLocal::update( IncidenceBase *incidence ) | 522 | void CalendarLocal::update( IncidenceBase *incidence ) |
522 | { | 523 | { |
523 | incidence->setSyncStatus( Event::SYNCMOD ); | 524 | incidence->setSyncStatus( Event::SYNCMOD ); |
524 | incidence->setLastModified( QDateTime::currentDateTime() ); | 525 | incidence->setLastModified( QDateTime::currentDateTime() ); |
525 | // we should probably update the revision number here, | 526 | // we should probably update the revision number here, |
526 | // or internally in the Event itself when certain things change. | 527 | // or internally in the Event itself when certain things change. |
527 | // need to verify with ical documentation. | 528 | // need to verify with ical documentation. |
528 | 529 | ||
529 | setModified( true ); | 530 | setModified( true ); |
530 | } | 531 | } |
531 | 532 | ||
532 | void CalendarLocal::insertEvent( Event *event ) | 533 | void CalendarLocal::insertEvent( Event *event ) |
533 | { | 534 | { |
534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 535 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
535 | } | 536 | } |
536 | 537 | ||
537 | 538 | ||
538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 539 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
539 | { | 540 | { |
540 | QPtrList<Event> eventList; | 541 | QPtrList<Event> eventList; |
541 | 542 | ||
542 | Event *event; | 543 | Event *event; |
543 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 544 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
544 | if ( event->doesRecur() ) { | 545 | if ( event->doesRecur() ) { |
545 | if ( event->isMultiDay() ) { | 546 | if ( event->isMultiDay() ) { |
546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 547 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
547 | int i; | 548 | int i; |
548 | for ( i = 0; i <= extraDays; i++ ) { | 549 | for ( i = 0; i <= extraDays; i++ ) { |
549 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 550 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
550 | eventList.append( event ); | 551 | eventList.append( event ); |
551 | break; | 552 | break; |
552 | } | 553 | } |
553 | } | 554 | } |
554 | } else { | 555 | } else { |
555 | if ( event->recursOn( qd ) ) | 556 | if ( event->recursOn( qd ) ) |
556 | eventList.append( event ); | 557 | eventList.append( event ); |
557 | } | 558 | } |
558 | } else { | 559 | } else { |
559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 560 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
560 | eventList.append( event ); | 561 | eventList.append( event ); |
561 | } | 562 | } |
562 | } | 563 | } |
563 | } | 564 | } |
564 | 565 | ||
565 | if ( !sorted ) { | 566 | if ( !sorted ) { |
566 | return eventList; | 567 | return eventList; |
567 | } | 568 | } |
568 | 569 | ||
569 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 570 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
570 | // now, we have to sort it based on dtStart.time() | 571 | // now, we have to sort it based on dtStart.time() |
571 | QPtrList<Event> eventListSorted; | 572 | QPtrList<Event> eventListSorted; |
572 | Event *sortEvent; | 573 | Event *sortEvent; |
573 | for ( event = eventList.first(); event; event = eventList.next() ) { | 574 | for ( event = eventList.first(); event; event = eventList.next() ) { |
574 | sortEvent = eventListSorted.first(); | 575 | sortEvent = eventListSorted.first(); |
575 | int i = 0; | 576 | int i = 0; |
576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 577 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
577 | { | 578 | { |
578 | i++; | 579 | i++; |
579 | sortEvent = eventListSorted.next(); | 580 | sortEvent = eventListSorted.next(); |
580 | } | 581 | } |
581 | eventListSorted.insert( i, event ); | 582 | eventListSorted.insert( i, event ); |
582 | } | 583 | } |
583 | return eventListSorted; | 584 | return eventListSorted; |
584 | } | 585 | } |
585 | 586 | ||
586 | 587 | ||
587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 588 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
588 | bool inclusive ) | 589 | bool inclusive ) |
589 | { | 590 | { |
590 | Event *event = 0; | 591 | Event *event = 0; |
591 | 592 | ||
592 | QPtrList<Event> eventList; | 593 | QPtrList<Event> eventList; |
593 | 594 | ||
594 | // Get non-recurring events | 595 | // Get non-recurring events |
595 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 596 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
596 | if ( event->doesRecur() ) { | 597 | if ( event->doesRecur() ) { |
597 | QDate rStart = event->dtStart().date(); | 598 | QDate rStart = event->dtStart().date(); |
598 | bool found = false; | 599 | bool found = false; |
599 | if ( inclusive ) { | 600 | if ( inclusive ) { |
600 | if ( rStart >= start && rStart <= end ) { | 601 | if ( rStart >= start && rStart <= end ) { |
601 | // Start date of event is in range. Now check for end date. | 602 | // Start date of event is in range. Now check for end date. |
602 | // if duration is negative, event recurs forever, so do not include it. | 603 | // if duration is negative, event recurs forever, so do not include it. |
603 | if ( event->recurrence()->duration() == 0 ) { // End date set | 604 | if ( event->recurrence()->duration() == 0 ) { // End date set |
604 | QDate rEnd = event->recurrence()->endDate(); | 605 | QDate rEnd = event->recurrence()->endDate(); |
605 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 606 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
606 | found = true; | 607 | found = true; |
607 | } | 608 | } |
608 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 609 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
609 | // TODO: Calculate end date from duration. Should be done in Event | 610 | // TODO: Calculate end date from duration. Should be done in Event |
610 | // For now exclude all events with a duration. | 611 | // For now exclude all events with a duration. |
611 | } | 612 | } |
612 | } | 613 | } |
613 | } else { | 614 | } else { |
614 | bool founOne; | 615 | bool founOne; |
615 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 616 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
616 | if ( founOne ) { | 617 | if ( founOne ) { |
617 | if ( next <= end ) { | 618 | if ( next <= end ) { |
618 | found = true; | 619 | found = true; |
619 | } | 620 | } |
620 | } | 621 | } |
621 | 622 | ||
622 | /* | 623 | /* |
623 | // crap !!! | 624 | // crap !!! |
624 | if ( rStart <= end ) { // Start date not after range | 625 | if ( rStart <= end ) { // Start date not after range |
625 | if ( rStart >= start ) { // Start date within range | 626 | if ( rStart >= start ) { // Start date within range |
626 | found = true; | 627 | found = true; |
627 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 628 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
628 | found = true; | 629 | found = true; |
629 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 630 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
630 | QDate rEnd = event->recurrence()->endDate(); | 631 | QDate rEnd = event->recurrence()->endDate(); |
631 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 632 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
632 | found = true; | 633 | found = true; |
633 | } | 634 | } |
634 | } else { // Duration set | 635 | } else { // Duration set |
635 | // TODO: Calculate end date from duration. Should be done in Event | 636 | // TODO: Calculate end date from duration. Should be done in Event |
636 | // For now include all events with a duration. | 637 | // For now include all events with a duration. |
637 | found = true; | 638 | found = true; |
638 | } | 639 | } |
639 | } | 640 | } |
640 | */ | 641 | */ |
641 | 642 | ||
642 | } | 643 | } |
643 | 644 | ||
644 | if ( found ) eventList.append( event ); | 645 | if ( found ) eventList.append( event ); |
645 | } else { | 646 | } else { |
646 | QDate s = event->dtStart().date(); | 647 | QDate s = event->dtStart().date(); |
647 | QDate e = event->dtEnd().date(); | 648 | QDate e = event->dtEnd().date(); |
648 | 649 | ||
649 | if ( inclusive ) { | 650 | if ( inclusive ) { |
650 | if ( s >= start && e <= end ) { | 651 | if ( s >= start && e <= end ) { |
651 | eventList.append( event ); | 652 | eventList.append( event ); |
652 | } | 653 | } |
653 | } else { | 654 | } else { |
654 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 655 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
655 | eventList.append( event ); | 656 | eventList.append( event ); |
656 | } | 657 | } |
657 | } | 658 | } |
658 | } | 659 | } |
659 | } | 660 | } |
660 | 661 | ||
661 | return eventList; | 662 | return eventList; |
662 | } | 663 | } |
663 | 664 | ||
664 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 665 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
665 | { | 666 | { |
666 | return rawEventsForDate( qdt.date() ); | 667 | return rawEventsForDate( qdt.date() ); |
667 | } | 668 | } |
668 | 669 | ||
669 | QPtrList<Event> CalendarLocal::rawEvents() | 670 | QPtrList<Event> CalendarLocal::rawEvents() |
670 | { | 671 | { |
671 | return mEventList; | 672 | return mEventList; |
672 | } | 673 | } |
673 | 674 | ||
674 | bool CalendarLocal::addJournal(Journal *journal) | 675 | bool CalendarLocal::addJournal(Journal *journal) |
675 | { | 676 | { |
676 | if ( journal->dtStart().isValid()) | 677 | if ( journal->dtStart().isValid()) |
677 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 678 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
678 | else | 679 | else |
679 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 680 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
680 | 681 | ||
681 | mJournalList.append(journal); | 682 | mJournalList.append(journal); |
682 | 683 | ||
683 | journal->registerObserver( this ); | 684 | journal->registerObserver( this ); |
684 | 685 | ||
685 | setModified( true ); | 686 | setModified( true ); |
686 | 687 | ||
687 | return true; | 688 | return true; |
688 | } | 689 | } |
689 | 690 | ||
690 | void CalendarLocal::deleteJournal( Journal *journal ) | 691 | void CalendarLocal::deleteJournal( Journal *journal ) |
691 | { | 692 | { |
692 | if ( mUndoIncidence ) delete mUndoIncidence; | 693 | if ( mUndoIncidence ) delete mUndoIncidence; |
693 | mUndoIncidence = journal->clone(); | 694 | mUndoIncidence = journal->clone(); |
694 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 695 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
695 | if ( mJournalList.removeRef(journal) ) { | 696 | if ( mJournalList.removeRef(journal) ) { |
696 | setModified( true ); | 697 | setModified( true ); |
697 | } | 698 | } |
698 | } | 699 | } |
699 | 700 | ||
700 | Journal *CalendarLocal::journal( const QDate &date ) | 701 | Journal *CalendarLocal::journal( const QDate &date ) |
701 | { | 702 | { |
702 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 703 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
703 | 704 | ||
704 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 705 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
705 | if ( it->dtStart().date() == date ) | 706 | if ( it->dtStart().date() == date ) |
706 | return it; | 707 | return it; |
707 | 708 | ||
708 | return 0; | 709 | return 0; |
709 | } | 710 | } |
710 | 711 | ||
711 | Journal *CalendarLocal::journal( const QString &uid ) | 712 | Journal *CalendarLocal::journal( const QString &uid ) |
712 | { | 713 | { |
713 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 714 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
714 | if ( it->uid() == uid ) | 715 | if ( it->uid() == uid ) |
715 | return it; | 716 | return it; |
716 | 717 | ||
717 | return 0; | 718 | return 0; |
718 | } | 719 | } |
719 | 720 | ||
720 | QPtrList<Journal> CalendarLocal::journals() | 721 | QPtrList<Journal> CalendarLocal::journals() |
721 | { | 722 | { |
722 | return mJournalList; | 723 | return mJournalList; |
723 | } | 724 | } |
724 | 725 | ||