author | zautrix <zautrix> | 2005-06-28 13:53:45 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-28 13:53:45 (UTC) |
commit | f9ba5ebe92b1ec1e00e6977b6433a5ad25fc45ff (patch) (unidiff) | |
tree | edebb12db30f3043450386da58adb7d5981b1044 /libkcal/calendarlocal.cpp | |
parent | 5861dc779cce151b7a05f3295ca11ffbf39e5a20 (diff) | |
download | kdepimpi-f9ba5ebe92b1ec1e00e6977b6433a5ad25fc45ff.zip kdepimpi-f9ba5ebe92b1ec1e00e6977b6433a5ad25fc45ff.tar.gz kdepimpi-f9ba5ebe92b1ec1e00e6977b6433a5ad25fc45ff.tar.bz2 |
cal time fix
-rw-r--r-- | libkcal/calendarlocal.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 18f1af8..418bfca 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,925 +1,925 @@ | |||
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 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 71 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
72 | { | 72 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 73 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( id ); | 74 | calendar.setDefaultCalendar( id ); |
75 | if ( calendar.load( name ) ) { | 75 | if ( calendar.load( name ) ) { |
76 | addCalendar( &calendar ); | 76 | addCalendar( &calendar ); |
77 | return true; | 77 | return true; |
78 | } | 78 | } |
79 | return false; | 79 | return false; |
80 | } | 80 | } |
81 | void CalendarLocal::setSyncEventsReadOnly() | 81 | void CalendarLocal::setSyncEventsReadOnly() |
82 | { | 82 | { |
83 | Event * ev; | 83 | Event * ev; |
84 | ev = mEventList.first(); | 84 | ev = mEventList.first(); |
85 | while ( ev ) { | 85 | while ( ev ) { |
86 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 86 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
87 | ev->setReadOnly( true ); | 87 | ev->setReadOnly( true ); |
88 | ev = mEventList.next(); | 88 | ev = mEventList.next(); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | void CalendarLocal::addCalendar( Calendar* cal ) | 91 | void CalendarLocal::addCalendar( Calendar* cal ) |
92 | { | 92 | { |
93 | cal->setDontDeleteIncidencesOnClose(); | 93 | cal->setDontDeleteIncidencesOnClose(); |
94 | { | 94 | { |
95 | QPtrList<Event> EventList = cal->rawEvents(); | 95 | QPtrList<Event> EventList = cal->rawEvents(); |
96 | Event * ev = EventList.first(); | 96 | Event * ev = EventList.first(); |
97 | while ( ev ) { | 97 | while ( ev ) { |
98 | ev->unRegisterObserver( cal ); | 98 | ev->unRegisterObserver( cal ); |
99 | ev->registerObserver( this ); | 99 | ev->registerObserver( this ); |
100 | mEventList.append( ev ); | 100 | mEventList.append( ev ); |
101 | ev = EventList.next(); | 101 | ev = EventList.next(); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | { | 104 | { |
105 | 105 | ||
106 | QPtrList<Todo> TodoList = cal->rawTodos(); | 106 | QPtrList<Todo> TodoList = cal->rawTodos(); |
107 | Todo * ev = TodoList.first(); | 107 | Todo * ev = TodoList.first(); |
108 | while ( ev ) { | 108 | while ( ev ) { |
109 | QString rel = ev->relatedToUid(); | 109 | QString rel = ev->relatedToUid(); |
110 | if ( !rel.isEmpty() ){ | 110 | if ( !rel.isEmpty() ){ |
111 | ev->setRelatedTo ( 0 ); | 111 | ev->setRelatedTo ( 0 ); |
112 | ev->setRelatedToUid( rel ); | 112 | ev->setRelatedToUid( rel ); |
113 | } | 113 | } |
114 | ev = TodoList.next(); | 114 | ev = TodoList.next(); |
115 | } | 115 | } |
116 | //TodoList = cal->rawTodos(); | 116 | //TodoList = cal->rawTodos(); |
117 | ev = TodoList.first(); | 117 | ev = TodoList.first(); |
118 | while ( ev ) { | 118 | while ( ev ) { |
119 | ev->unRegisterObserver( cal ); | 119 | ev->unRegisterObserver( cal ); |
120 | ev->registerObserver( this ); | 120 | ev->registerObserver( this ); |
121 | mTodoList.append( ev ); | 121 | mTodoList.append( ev ); |
122 | setupRelations( ev ); | 122 | setupRelations( ev ); |
123 | ev = TodoList.next(); | 123 | ev = TodoList.next(); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | { | 126 | { |
127 | QPtrList<Journal> JournalList = cal->journals(); | 127 | QPtrList<Journal> JournalList = cal->journals(); |
128 | Journal * ev = JournalList.first(); | 128 | Journal * ev = JournalList.first(); |
129 | while ( ev ) { | 129 | while ( ev ) { |
130 | ev->unRegisterObserver( cal ); | 130 | ev->unRegisterObserver( cal ); |
131 | ev->registerObserver( this ); | 131 | ev->registerObserver( this ); |
132 | mJournalList.append( ev ); | 132 | mJournalList.append( ev ); |
133 | ev = JournalList.next(); | 133 | ev = JournalList.next(); |
134 | } | 134 | } |
135 | } | 135 | } |
136 | setModified( true ); | 136 | setModified( true ); |
137 | } | 137 | } |
138 | bool CalendarLocal::load( const QString &fileName ) | 138 | bool CalendarLocal::load( const QString &fileName ) |
139 | { | 139 | { |
140 | FileStorage storage( this, fileName ); | 140 | FileStorage storage( this, fileName ); |
141 | return storage.load(); | 141 | return storage.load(); |
142 | } | 142 | } |
143 | 143 | ||
144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
145 | { | 145 | { |
146 | FileStorage storage( this, fileName, format ); | 146 | FileStorage storage( this, fileName, format ); |
147 | return storage.save(); | 147 | return storage.save(); |
148 | } | 148 | } |
149 | 149 | ||
150 | void CalendarLocal::stopAllTodos() | 150 | void CalendarLocal::stopAllTodos() |
151 | { | 151 | { |
152 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 152 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
153 | it->setRunning( false ); | 153 | it->setRunning( false ); |
154 | 154 | ||
155 | } | 155 | } |
156 | void CalendarLocal::close() | 156 | void CalendarLocal::close() |
157 | { | 157 | { |
158 | 158 | ||
159 | Todo * i; | 159 | Todo * i; |
160 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 160 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
161 | 161 | ||
162 | mEventList.setAutoDelete( true ); | 162 | mEventList.setAutoDelete( true ); |
163 | mTodoList.setAutoDelete( true ); | 163 | mTodoList.setAutoDelete( true ); |
164 | mJournalList.setAutoDelete( false ); | 164 | mJournalList.setAutoDelete( false ); |
165 | 165 | ||
166 | mEventList.clear(); | 166 | mEventList.clear(); |
167 | mTodoList.clear(); | 167 | mTodoList.clear(); |
168 | mJournalList.clear(); | 168 | mJournalList.clear(); |
169 | 169 | ||
170 | mEventList.setAutoDelete( false ); | 170 | mEventList.setAutoDelete( false ); |
171 | mTodoList.setAutoDelete( false ); | 171 | mTodoList.setAutoDelete( false ); |
172 | mJournalList.setAutoDelete( false ); | 172 | mJournalList.setAutoDelete( false ); |
173 | 173 | ||
174 | setModified( false ); | 174 | setModified( false ); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 177 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
178 | { | 178 | { |
179 | QString cat; | 179 | QString cat; |
180 | bool isBirthday = true; | 180 | bool isBirthday = true; |
181 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 181 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
182 | isBirthday = false; | 182 | isBirthday = false; |
183 | cat = i18n( "Anniversary" ); | 183 | cat = i18n( "Anniversary" ); |
184 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 184 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
185 | isBirthday = true; | 185 | isBirthday = true; |
186 | cat = i18n( "Birthday" ); | 186 | cat = i18n( "Birthday" ); |
187 | } else { | 187 | } else { |
188 | qDebug("addAnniversaryNoDup called without fitting category! "); | 188 | qDebug("addAnniversaryNoDup called without fitting category! "); |
189 | return false; | 189 | return false; |
190 | } | 190 | } |
191 | Event * eve; | 191 | Event * eve; |
192 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 192 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
193 | if ( !(eve->categories().contains( cat ) )) | 193 | if ( !(eve->categories().contains( cat ) )) |
194 | continue; | 194 | continue; |
195 | // now we have an event with fitting category | 195 | // now we have an event with fitting category |
196 | if ( eve->dtStart().date() != event->dtStart().date() ) | 196 | if ( eve->dtStart().date() != event->dtStart().date() ) |
197 | continue; | 197 | continue; |
198 | // now we have an event with fitting category+date | 198 | // now we have an event with fitting category+date |
199 | if ( eve->summary() != event->summary() ) | 199 | if ( eve->summary() != event->summary() ) |
200 | continue; | 200 | continue; |
201 | // now we have an event with fitting category+date+summary | 201 | // now we have an event with fitting category+date+summary |
202 | return false; | 202 | return false; |
203 | } | 203 | } |
204 | return addEvent( event ); | 204 | return addEvent( event ); |
205 | 205 | ||
206 | } | 206 | } |
207 | bool CalendarLocal::addEventNoDup( Event *event ) | 207 | bool CalendarLocal::addEventNoDup( Event *event ) |
208 | { | 208 | { |
209 | Event * eve; | 209 | Event * eve; |
210 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 210 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
211 | if ( *eve == *event ) { | 211 | if ( *eve == *event ) { |
212 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 212 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | } | 215 | } |
216 | return addEvent( event ); | 216 | return addEvent( event ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool CalendarLocal::addEvent( Event *event ) | 219 | bool CalendarLocal::addEvent( Event *event ) |
220 | { | 220 | { |
221 | insertEvent( event ); | 221 | insertEvent( event ); |
222 | 222 | ||
223 | event->registerObserver( this ); | 223 | event->registerObserver( this ); |
224 | 224 | ||
225 | setModified( true ); | 225 | setModified( true ); |
226 | event->setCalID( mDefaultCalendar ); | 226 | event->setCalID( mDefaultCalendar ); |
227 | event->setCalEnabled( true ); | 227 | event->setCalEnabled( true ); |
228 | 228 | ||
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | 231 | ||
232 | void CalendarLocal::deleteEvent( Event *event ) | 232 | void CalendarLocal::deleteEvent( Event *event ) |
233 | { | 233 | { |
234 | if ( mUndoIncidence ) delete mUndoIncidence; | 234 | if ( mUndoIncidence ) delete mUndoIncidence; |
235 | mUndoIncidence = event->clone(); | 235 | mUndoIncidence = event->clone(); |
236 | if ( mEventList.removeRef( event ) ) { | 236 | if ( mEventList.removeRef( event ) ) { |
237 | setModified( true ); | 237 | setModified( true ); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | Event *CalendarLocal::event( const QString &uid ) | 242 | Event *CalendarLocal::event( const QString &uid ) |
243 | { | 243 | { |
244 | Event *event; | 244 | Event *event; |
245 | Event *retVal = 0; | 245 | Event *retVal = 0; |
246 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 246 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
247 | if ( event->calEnabled() && event->uid() == uid ) { | 247 | if ( event->calEnabled() && event->uid() == uid ) { |
248 | if ( retVal ) { | 248 | if ( retVal ) { |
249 | if ( retVal->calID() > event->calID() ) { | 249 | if ( retVal->calID() > event->calID() ) { |
250 | retVal = event; | 250 | retVal = event; |
251 | } | 251 | } |
252 | } else { | 252 | } else { |
253 | retVal = event; | 253 | retVal = event; |
254 | } | 254 | } |
255 | } | 255 | } |
256 | } | 256 | } |
257 | return retVal; | 257 | return retVal; |
258 | } | 258 | } |
259 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 259 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
260 | { | 260 | { |
261 | Todo * eve; | 261 | Todo * eve; |
262 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 262 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
263 | if ( *eve == *todo ) { | 263 | if ( *eve == *todo ) { |
264 | //qDebug("duplicate todo found! not inserted! "); | 264 | //qDebug("duplicate todo found! not inserted! "); |
265 | return false; | 265 | return false; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | return addTodo( todo ); | 268 | return addTodo( todo ); |
269 | } | 269 | } |
270 | bool CalendarLocal::addTodo( Todo *todo ) | 270 | bool CalendarLocal::addTodo( Todo *todo ) |
271 | { | 271 | { |
272 | mTodoList.append( todo ); | 272 | mTodoList.append( todo ); |
273 | 273 | ||
274 | todo->registerObserver( this ); | 274 | todo->registerObserver( this ); |
275 | 275 | ||
276 | // Set up subtask relations | 276 | // Set up subtask relations |
277 | setupRelations( todo ); | 277 | setupRelations( todo ); |
278 | 278 | ||
279 | setModified( true ); | 279 | setModified( true ); |
280 | todo->setCalID( mDefaultCalendar ); | 280 | todo->setCalID( mDefaultCalendar ); |
281 | todo->setCalEnabled( true ); | 281 | todo->setCalEnabled( true ); |
282 | return true; | 282 | return true; |
283 | } | 283 | } |
284 | 284 | ||
285 | void CalendarLocal::deleteTodo( Todo *todo ) | 285 | void CalendarLocal::deleteTodo( Todo *todo ) |
286 | { | 286 | { |
287 | // Handle orphaned children | 287 | // Handle orphaned children |
288 | if ( mUndoIncidence ) delete mUndoIncidence; | 288 | if ( mUndoIncidence ) delete mUndoIncidence; |
289 | removeRelations( todo ); | 289 | removeRelations( todo ); |
290 | mUndoIncidence = todo->clone(); | 290 | mUndoIncidence = todo->clone(); |
291 | 291 | ||
292 | if ( mTodoList.removeRef( todo ) ) { | 292 | if ( mTodoList.removeRef( todo ) ) { |
293 | setModified( true ); | 293 | setModified( true ); |
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | QPtrList<Todo> CalendarLocal::rawTodos() | 297 | QPtrList<Todo> CalendarLocal::rawTodos() |
298 | { | 298 | { |
299 | QPtrList<Todo> el; | 299 | QPtrList<Todo> el; |
300 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 300 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
301 | if ( it->calEnabled() ) el.append( it ); | 301 | if ( it->calEnabled() ) el.append( it ); |
302 | return el; | 302 | return el; |
303 | } | 303 | } |
304 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 304 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
305 | { | 305 | { |
306 | Todo *todo; | 306 | Todo *todo; |
307 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 307 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
308 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 308 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
309 | } | 309 | } |
310 | 310 | ||
311 | return 0; | 311 | return 0; |
312 | } | 312 | } |
313 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 313 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
314 | { | 314 | { |
315 | QPtrList<Incidence> all = rawIncidences() ; | 315 | QPtrList<Incidence> all = rawIncidences() ; |
316 | Incidence *inc; | 316 | Incidence *inc; |
317 | for ( inc = all.first(); inc; inc = all.next() ) { | 317 | for ( inc = all.first(); inc; inc = all.next() ) { |
318 | inc->removeID( syncProfile ); | 318 | inc->removeID( syncProfile ); |
319 | } | 319 | } |
320 | if ( syncProfile.isEmpty() ) { | 320 | if ( syncProfile.isEmpty() ) { |
321 | QPtrList<Event> el; | 321 | QPtrList<Event> el; |
322 | Event *todo; | 322 | Event *todo; |
323 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 323 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
324 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 324 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
325 | el.append( todo ); | 325 | el.append( todo ); |
326 | } | 326 | } |
327 | for ( todo = el.first(); todo; todo = el.next() ) { | 327 | for ( todo = el.first(); todo; todo = el.next() ) { |
328 | deleteIncidence ( todo ); | 328 | deleteIncidence ( todo ); |
329 | } | 329 | } |
330 | } else { | 330 | } else { |
331 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 331 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
332 | if ( lse ) | 332 | if ( lse ) |
333 | deleteIncidence ( lse ); | 333 | deleteIncidence ( lse ); |
334 | } | 334 | } |
335 | } | 335 | } |
336 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 336 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
337 | { | 337 | { |
338 | QPtrList<Event> el; | 338 | QPtrList<Event> el; |
339 | Event *todo; | 339 | Event *todo; |
340 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 340 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
341 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 341 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
342 | if ( todo->summary().left(3) == "E: " ) | 342 | if ( todo->summary().left(3) == "E: " ) |
343 | el.append( todo ); | 343 | el.append( todo ); |
344 | } | 344 | } |
345 | 345 | ||
346 | return el; | 346 | return el; |
347 | 347 | ||
348 | } | 348 | } |
349 | Event *CalendarLocal::event( QString syncProf, QString id ) | 349 | Event *CalendarLocal::event( QString syncProf, QString id ) |
350 | { | 350 | { |
351 | Event *todo; | 351 | Event *todo; |
352 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 352 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
353 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 353 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
354 | } | 354 | } |
355 | 355 | ||
356 | return 0; | 356 | return 0; |
357 | } | 357 | } |
358 | Todo *CalendarLocal::todo( const QString &uid ) | 358 | Todo *CalendarLocal::todo( const QString &uid ) |
359 | { | 359 | { |
360 | Todo *todo;; | 360 | Todo *todo;; |
361 | Todo *retVal = 0; | 361 | Todo *retVal = 0; |
362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
363 | if ( todo->calEnabled() && todo->uid() == uid ) { | 363 | if ( todo->calEnabled() && todo->uid() == uid ) { |
364 | if ( retVal ) { | 364 | if ( retVal ) { |
365 | if ( retVal->calID() > todo->calID() ) { | 365 | if ( retVal->calID() > todo->calID() ) { |
366 | retVal = todo; | 366 | retVal = todo; |
367 | } | 367 | } |
368 | } else { | 368 | } else { |
369 | retVal = todo; | 369 | retVal = todo; |
370 | } | 370 | } |
371 | } | 371 | } |
372 | } | 372 | } |
373 | return retVal; | 373 | return retVal; |
374 | } | 374 | } |
375 | QString CalendarLocal::nextSummary() const | 375 | QString CalendarLocal::nextSummary() const |
376 | { | 376 | { |
377 | return mNextSummary; | 377 | return mNextSummary; |
378 | } | 378 | } |
379 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 379 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
380 | { | 380 | { |
381 | return mNextAlarmEventDateTime; | 381 | return mNextAlarmEventDateTime; |
382 | } | 382 | } |
383 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 383 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
384 | { | 384 | { |
385 | //mNextAlarmIncidence | 385 | //mNextAlarmIncidence |
386 | //mNextAlarmDateTime | 386 | //mNextAlarmDateTime |
387 | //return mNextSummary; | 387 | //return mNextSummary; |
388 | //return mNextAlarmEventDateTime; | 388 | //return mNextAlarmEventDateTime; |
389 | bool newNextAlarm = false; | 389 | bool newNextAlarm = false; |
390 | bool computeNextAlarm = false; | 390 | bool computeNextAlarm = false; |
391 | bool ok; | 391 | bool ok; |
392 | int offset; | 392 | int offset; |
393 | QDateTime nextA; | 393 | QDateTime nextA; |
394 | // QString nextSum; | 394 | // QString nextSum; |
395 | //QDateTime nextEvent; | 395 | //QDateTime nextEvent; |
396 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 396 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
397 | computeNextAlarm = true; | 397 | computeNextAlarm = true; |
398 | } else { | 398 | } else { |
399 | if ( ! deleted ) { | 399 | if ( ! deleted ) { |
400 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 400 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
401 | if ( ok ) { | 401 | if ( ok ) { |
402 | if ( nextA < mNextAlarmDateTime ) { | 402 | if ( nextA < mNextAlarmDateTime ) { |
403 | deRegisterAlarm(); | 403 | deRegisterAlarm(); |
404 | mNextAlarmDateTime = nextA; | 404 | mNextAlarmDateTime = nextA; |
405 | mNextSummary = incidence->summary(); | 405 | mNextSummary = incidence->summary(); |
406 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 406 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
407 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 407 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
408 | newNextAlarm = true; | 408 | newNextAlarm = true; |
409 | mNextAlarmIncidence = incidence; | 409 | mNextAlarmIncidence = incidence; |
410 | } else { | 410 | } else { |
411 | if ( incidence == mNextAlarmIncidence ) { | 411 | if ( incidence == mNextAlarmIncidence ) { |
412 | computeNextAlarm = true; | 412 | computeNextAlarm = true; |
413 | } | 413 | } |
414 | } | 414 | } |
415 | } else { | 415 | } else { |
416 | if ( mNextAlarmIncidence == incidence ) { | 416 | if ( mNextAlarmIncidence == incidence ) { |
417 | computeNextAlarm = true; | 417 | computeNextAlarm = true; |
418 | } | 418 | } |
419 | } | 419 | } |
420 | } else { // deleted | 420 | } else { // deleted |
421 | if ( incidence == mNextAlarmIncidence ) { | 421 | if ( incidence == mNextAlarmIncidence ) { |
422 | computeNextAlarm = true; | 422 | computeNextAlarm = true; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | } | 425 | } |
426 | if ( computeNextAlarm ) { | 426 | if ( computeNextAlarm ) { |
427 | deRegisterAlarm(); | 427 | deRegisterAlarm(); |
428 | nextA = nextAlarm( 1000 ); | 428 | nextA = nextAlarm( 1000 ); |
429 | if (! mNextAlarmIncidence ) { | 429 | if (! mNextAlarmIncidence ) { |
430 | return; | 430 | return; |
431 | } | 431 | } |
432 | newNextAlarm = true; | 432 | newNextAlarm = true; |
433 | } | 433 | } |
434 | if ( newNextAlarm ) | 434 | if ( newNextAlarm ) |
435 | registerAlarm(); | 435 | registerAlarm(); |
436 | } | 436 | } |
437 | QString CalendarLocal:: getAlarmNotification() | 437 | QString CalendarLocal:: getAlarmNotification() |
438 | { | 438 | { |
439 | QString ret; | 439 | QString ret; |
440 | // this should not happen | 440 | // this should not happen |
441 | if (! mNextAlarmIncidence ) | 441 | if (! mNextAlarmIncidence ) |
442 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 442 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
443 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 443 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
444 | if ( alarm->type() == Alarm::Procedure ) { | 444 | if ( alarm->type() == Alarm::Procedure ) { |
445 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 445 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
446 | } else { | 446 | } else { |
447 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 447 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
448 | } | 448 | } |
449 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 449 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
450 | if ( mNextSummary.length() > 25 ) | 450 | if ( mNextSummary.length() > 25 ) |
451 | ret += "\n" + mNextSummary.mid(25, 25 ); | 451 | ret += "\n" + mNextSummary.mid(25, 25 ); |
452 | ret+= "\n"+mNextAlarmEventDateTimeString; | 452 | ret+= "\n"+mNextAlarmEventDateTimeString; |
453 | return ret; | 453 | return ret; |
454 | } | 454 | } |
455 | void CalendarLocal::registerAlarm() | 455 | void CalendarLocal::registerAlarm() |
456 | { | 456 | { |
457 | mLastAlarmNotificationString = getAlarmNotification(); | 457 | mLastAlarmNotificationString = getAlarmNotification(); |
458 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 458 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
459 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 459 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
460 | // #ifndef DESKTOP_VERSION | 460 | // #ifndef DESKTOP_VERSION |
461 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 461 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
462 | // #endif | 462 | // #endif |
463 | } | 463 | } |
464 | void CalendarLocal::deRegisterAlarm() | 464 | void CalendarLocal::deRegisterAlarm() |
465 | { | 465 | { |
466 | if ( mLastAlarmNotificationString.isNull() ) | 466 | if ( mLastAlarmNotificationString.isNull() ) |
467 | return; | 467 | return; |
468 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 468 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
469 | 469 | ||
470 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 470 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
471 | mNextAlarmEventDateTime = QDateTime(); | 471 | mNextAlarmEventDateTime = QDateTime(); |
472 | // #ifndef DESKTOP_VERSION | 472 | // #ifndef DESKTOP_VERSION |
473 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 473 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
474 | // #endif | 474 | // #endif |
475 | } | 475 | } |
476 | 476 | ||
477 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 477 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
478 | { | 478 | { |
479 | QPtrList<Todo> todos; | 479 | QPtrList<Todo> todos; |
480 | 480 | ||
481 | Todo *todo; | 481 | Todo *todo; |
482 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 482 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
483 | if ( !todo->calEnabled() ) continue; | 483 | if ( !todo->calEnabled() ) continue; |
484 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 484 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
485 | todos.append( todo ); | 485 | todos.append( todo ); |
486 | } | 486 | } |
487 | } | 487 | } |
488 | 488 | ||
489 | filter()->apply( &todos ); | 489 | filter()->apply( &todos ); |
490 | return todos; | 490 | return todos; |
491 | } | 491 | } |
492 | void CalendarLocal::reInitAlarmSettings() | 492 | void CalendarLocal::reInitAlarmSettings() |
493 | { | 493 | { |
494 | if ( !mNextAlarmIncidence ) { | 494 | if ( !mNextAlarmIncidence ) { |
495 | nextAlarm( 1000 ); | 495 | nextAlarm( 1000 ); |
496 | } | 496 | } |
497 | deRegisterAlarm(); | 497 | deRegisterAlarm(); |
498 | mNextAlarmIncidence = 0; | 498 | mNextAlarmIncidence = 0; |
499 | checkAlarmForIncidence( 0, false ); | 499 | checkAlarmForIncidence( 0, false ); |
500 | 500 | ||
501 | } | 501 | } |
502 | 502 | ||
503 | 503 | ||
504 | 504 | ||
505 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 505 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
506 | { | 506 | { |
507 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 507 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
508 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 508 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
509 | QDateTime next; | 509 | QDateTime next; |
510 | Event *e; | 510 | Event *e; |
511 | bool ok; | 511 | bool ok; |
512 | bool found = false; | 512 | bool found = false; |
513 | int offset; | 513 | int offset; |
514 | mNextAlarmIncidence = 0; | 514 | mNextAlarmIncidence = 0; |
515 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 515 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
516 | if ( !e->calEnabled() ) continue; | 516 | if ( !e->calEnabled() ) continue; |
517 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 517 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
518 | if ( ok ) { | 518 | if ( ok ) { |
519 | if ( next < nextA ) { | 519 | if ( next < nextA ) { |
520 | nextA = next; | 520 | nextA = next; |
521 | found = true; | 521 | found = true; |
522 | mNextSummary = e->summary(); | 522 | mNextSummary = e->summary(); |
523 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 523 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
524 | mNextAlarmIncidence = (Incidence *) e; | 524 | mNextAlarmIncidence = (Incidence *) e; |
525 | } | 525 | } |
526 | } | 526 | } |
527 | } | 527 | } |
528 | Todo *t; | 528 | Todo *t; |
529 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 529 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
530 | if ( !t->calEnabled() ) continue; | 530 | if ( !t->calEnabled() ) continue; |
531 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 531 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
532 | if ( ok ) { | 532 | if ( ok ) { |
533 | if ( next < nextA ) { | 533 | if ( next < nextA ) { |
534 | nextA = next; | 534 | nextA = next; |
535 | found = true; | 535 | found = true; |
536 | mNextSummary = t->summary(); | 536 | mNextSummary = t->summary(); |
537 | mNextAlarmEventDateTime = next.addSecs(offset ); | 537 | mNextAlarmEventDateTime = next.addSecs(offset ); |
538 | mNextAlarmIncidence = (Incidence *) t; | 538 | mNextAlarmIncidence = (Incidence *) t; |
539 | } | 539 | } |
540 | } | 540 | } |
541 | } | 541 | } |
542 | if ( mNextAlarmIncidence ) { | 542 | if ( mNextAlarmIncidence ) { |
543 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 543 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
544 | mNextAlarmDateTime = nextA; | 544 | mNextAlarmDateTime = nextA; |
545 | } | 545 | } |
546 | return nextA; | 546 | return nextA; |
547 | } | 547 | } |
548 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 548 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
549 | { | 549 | { |
550 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 550 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
551 | } | 551 | } |
552 | 552 | ||
553 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 553 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
554 | { | 554 | { |
555 | 555 | ||
556 | Alarm::List alarms; | 556 | Alarm::List alarms; |
557 | 557 | ||
558 | Event *e; | 558 | Event *e; |
559 | 559 | ||
560 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 560 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
561 | if ( !e->calEnabled() ) continue; | 561 | if ( !e->calEnabled() ) continue; |
562 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 562 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
563 | else appendAlarms( alarms, e, from, to ); | 563 | else appendAlarms( alarms, e, from, to ); |
564 | } | 564 | } |
565 | 565 | ||
566 | Todo *t; | 566 | Todo *t; |
567 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 567 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
568 | if ( !t->calEnabled() ) continue; | 568 | if ( !t->calEnabled() ) continue; |
569 | appendAlarms( alarms, t, from, to ); | 569 | appendAlarms( alarms, t, from, to ); |
570 | } | 570 | } |
571 | 571 | ||
572 | return alarms; | 572 | return alarms; |
573 | } | 573 | } |
574 | 574 | ||
575 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 575 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
576 | const QDateTime &from, const QDateTime &to ) | 576 | const QDateTime &from, const QDateTime &to ) |
577 | { | 577 | { |
578 | QPtrList<Alarm> alarmList = incidence->alarms(); | 578 | QPtrList<Alarm> alarmList = incidence->alarms(); |
579 | Alarm *alarm; | 579 | Alarm *alarm; |
580 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 580 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
581 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 581 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
582 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 582 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
583 | if ( alarm->enabled() ) { | 583 | if ( alarm->enabled() ) { |
584 | if ( alarm->time() >= from && alarm->time() <= to ) { | 584 | if ( alarm->time() >= from && alarm->time() <= to ) { |
585 | alarms.append( alarm ); | 585 | alarms.append( alarm ); |
586 | } | 586 | } |
587 | } | 587 | } |
588 | } | 588 | } |
589 | } | 589 | } |
590 | 590 | ||
591 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 591 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
592 | Incidence *incidence, | 592 | Incidence *incidence, |
593 | const QDateTime &from, | 593 | const QDateTime &from, |
594 | const QDateTime &to ) | 594 | const QDateTime &to ) |
595 | { | 595 | { |
596 | 596 | ||
597 | QPtrList<Alarm> alarmList = incidence->alarms(); | 597 | QPtrList<Alarm> alarmList = incidence->alarms(); |
598 | Alarm *alarm; | 598 | Alarm *alarm; |
599 | QDateTime qdt; | 599 | QDateTime qdt; |
600 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 600 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
601 | if (incidence->recursOn(from.date())) { | 601 | if (incidence->recursOn(from.date())) { |
602 | qdt.setTime(alarm->time().time()); | 602 | qdt.setTime(alarm->time().time()); |
603 | qdt.setDate(from.date()); | 603 | qdt.setDate(from.date()); |
604 | } | 604 | } |
605 | else qdt = alarm->time(); | 605 | else qdt = alarm->time(); |
606 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 606 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
607 | if ( alarm->enabled() ) { | 607 | if ( alarm->enabled() ) { |
608 | if ( qdt >= from && qdt <= to ) { | 608 | if ( qdt >= from && qdt <= to ) { |
609 | alarms.append( alarm ); | 609 | alarms.append( alarm ); |
610 | } | 610 | } |
611 | } | 611 | } |
612 | } | 612 | } |
613 | } | 613 | } |
614 | 614 | ||
615 | 615 | ||
616 | /****************************** PROTECTED METHODS ****************************/ | 616 | /****************************** PROTECTED METHODS ****************************/ |
617 | 617 | ||
618 | // after changes are made to an event, this should be called. | 618 | // after changes are made to an event, this should be called. |
619 | void CalendarLocal::update( IncidenceBase *incidence ) | 619 | void CalendarLocal::update( IncidenceBase *incidence ) |
620 | { | 620 | { |
621 | incidence->setSyncStatus( Event::SYNCMOD ); | 621 | incidence->setSyncStatus( Event::SYNCMOD ); |
622 | incidence->setLastModified( QDateTime::currentDateTime() ); | 622 | incidence->setLastModified( QDateTime::currentDateTime() ); |
623 | // we should probably update the revision number here, | 623 | // we should probably update the revision number here, |
624 | // or internally in the Event itself when certain things change. | 624 | // or internally in the Event itself when certain things change. |
625 | // need to verify with ical documentation. | 625 | // need to verify with ical documentation. |
626 | 626 | ||
627 | setModified( true ); | 627 | setModified( true ); |
628 | } | 628 | } |
629 | 629 | ||
630 | void CalendarLocal::insertEvent( Event *event ) | 630 | void CalendarLocal::insertEvent( Event *event ) |
631 | { | 631 | { |
632 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 632 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
633 | } | 633 | } |
634 | 634 | ||
635 | 635 | ||
636 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 636 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
637 | { | 637 | { |
638 | QPtrList<Event> eventList; | 638 | QPtrList<Event> eventList; |
639 | 639 | ||
640 | Event *event; | 640 | Event *event; |
641 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 641 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
642 | if ( !event->calEnabled() ) continue; | 642 | if ( !event->calEnabled() ) continue; |
643 | if ( event->doesRecur() ) { | 643 | if ( event->doesRecur() ) { |
644 | if ( event->isMultiDay() ) { | 644 | if ( event->isMultiDay() ) { |
645 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 645 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
646 | int i; | 646 | int i; |
647 | for ( i = 0; i <= extraDays; i++ ) { | 647 | for ( i = 0; i <= extraDays; i++ ) { |
648 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 648 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
649 | eventList.append( event ); | 649 | eventList.append( event ); |
650 | break; | 650 | break; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | } else { | 653 | } else { |
654 | if ( event->recursOn( qd ) ) | 654 | if ( event->recursOn( qd ) ) |
655 | eventList.append( event ); | 655 | eventList.append( event ); |
656 | } | 656 | } |
657 | } else { | 657 | } else { |
658 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 658 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
659 | eventList.append( event ); | 659 | eventList.append( event ); |
660 | } | 660 | } |
661 | } | 661 | } |
662 | } | 662 | } |
663 | 663 | ||
664 | if ( !sorted ) { | 664 | if ( !sorted ) { |
665 | return eventList; | 665 | return eventList; |
666 | } | 666 | } |
667 | 667 | ||
668 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 668 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
669 | // now, we have to sort it based on dtStart.time() | 669 | // now, we have to sort it based on dtStart.time() |
670 | QPtrList<Event> eventListSorted; | 670 | QPtrList<Event> eventListSorted; |
671 | Event *sortEvent; | 671 | Event *sortEvent; |
672 | for ( event = eventList.first(); event; event = eventList.next() ) { | 672 | for ( event = eventList.first(); event; event = eventList.next() ) { |
673 | sortEvent = eventListSorted.first(); | 673 | sortEvent = eventListSorted.first(); |
674 | int i = 0; | 674 | int i = 0; |
675 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 675 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
676 | { | 676 | { |
677 | i++; | 677 | i++; |
678 | sortEvent = eventListSorted.next(); | 678 | sortEvent = eventListSorted.next(); |
679 | } | 679 | } |
680 | eventListSorted.insert( i, event ); | 680 | eventListSorted.insert( i, event ); |
681 | } | 681 | } |
682 | return eventListSorted; | 682 | return eventListSorted; |
683 | } | 683 | } |
684 | 684 | ||
685 | 685 | ||
686 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 686 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
687 | bool inclusive ) | 687 | bool inclusive ) |
688 | { | 688 | { |
689 | Event *event = 0; | 689 | Event *event = 0; |
690 | 690 | ||
691 | QPtrList<Event> eventList; | 691 | QPtrList<Event> eventList; |
692 | 692 | ||
693 | // Get non-recurring events | 693 | // Get non-recurring events |
694 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 694 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
695 | if ( !event->calEnabled() ) continue; | 695 | if ( !event->calEnabled() ) continue; |
696 | if ( event->doesRecur() ) { | 696 | if ( event->doesRecur() ) { |
697 | QDate rStart = event->dtStart().date(); | 697 | QDate rStart = event->dtStart().date(); |
698 | bool found = false; | 698 | bool found = false; |
699 | if ( inclusive ) { | 699 | if ( inclusive ) { |
700 | if ( rStart >= start && rStart <= end ) { | 700 | if ( rStart >= start && rStart <= end ) { |
701 | // Start date of event is in range. Now check for end date. | 701 | // Start date of event is in range. Now check for end date. |
702 | // if duration is negative, event recurs forever, so do not include it. | 702 | // if duration is negative, event recurs forever, so do not include it. |
703 | if ( event->recurrence()->duration() == 0 ) { // End date set | 703 | if ( event->recurrence()->duration() == 0 ) { // End date set |
704 | QDate rEnd = event->recurrence()->endDate(); | 704 | QDate rEnd = event->recurrence()->endDate(); |
705 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 705 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
706 | found = true; | 706 | found = true; |
707 | } | 707 | } |
708 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 708 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
709 | // TODO: Calculate end date from duration. Should be done in Event | 709 | // TODO: Calculate end date from duration. Should be done in Event |
710 | // For now exclude all events with a duration. | 710 | // For now exclude all events with a duration. |
711 | } | 711 | } |
712 | } | 712 | } |
713 | } else { | 713 | } else { |
714 | bool founOne; | 714 | bool founOne; |
715 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 715 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
716 | if ( founOne ) { | 716 | if ( founOne ) { |
717 | if ( next <= end ) { | 717 | if ( next <= end ) { |
718 | found = true; | 718 | found = true; |
719 | } | 719 | } |
720 | } | 720 | } |
721 | 721 | ||
722 | /* | 722 | /* |
723 | // crap !!! | 723 | // crap !!! |
724 | if ( rStart <= end ) { // Start date not after range | 724 | if ( rStart <= end ) { // Start date not after range |
725 | if ( rStart >= start ) { // Start date within range | 725 | if ( rStart >= start ) { // Start date within range |
726 | found = true; | 726 | found = true; |
727 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 727 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
728 | found = true; | 728 | found = true; |
729 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 729 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
730 | QDate rEnd = event->recurrence()->endDate(); | 730 | QDate rEnd = event->recurrence()->endDate(); |
731 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 731 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
732 | found = true; | 732 | found = true; |
733 | } | 733 | } |
734 | } else { // Duration set | 734 | } else { // Duration set |
735 | // TODO: Calculate end date from duration. Should be done in Event | 735 | // TODO: Calculate end date from duration. Should be done in Event |
736 | // For now include all events with a duration. | 736 | // For now include all events with a duration. |
737 | found = true; | 737 | found = true; |
738 | } | 738 | } |
739 | } | 739 | } |
740 | */ | 740 | */ |
741 | 741 | ||
742 | } | 742 | } |
743 | 743 | ||
744 | if ( found ) eventList.append( event ); | 744 | if ( found ) eventList.append( event ); |
745 | } else { | 745 | } else { |
746 | QDate s = event->dtStart().date(); | 746 | QDate s = event->dtStart().date(); |
747 | QDate e = event->dtEnd().date(); | 747 | QDate e = event->dtEnd().date(); |
748 | 748 | ||
749 | if ( inclusive ) { | 749 | if ( inclusive ) { |
750 | if ( s >= start && e <= end ) { | 750 | if ( s >= start && e <= end ) { |
751 | eventList.append( event ); | 751 | eventList.append( event ); |
752 | } | 752 | } |
753 | } else { | 753 | } else { |
754 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 754 | if ( ( e >= start && s <= end ) ) { |
755 | eventList.append( event ); | 755 | eventList.append( event ); |
756 | } | 756 | } |
757 | } | 757 | } |
758 | } | 758 | } |
759 | } | 759 | } |
760 | 760 | ||
761 | return eventList; | 761 | return eventList; |
762 | } | 762 | } |
763 | 763 | ||
764 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 764 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
765 | { | 765 | { |
766 | return rawEventsForDate( qdt.date() ); | 766 | return rawEventsForDate( qdt.date() ); |
767 | } | 767 | } |
768 | 768 | ||
769 | QPtrList<Event> CalendarLocal::rawEvents() | 769 | QPtrList<Event> CalendarLocal::rawEvents() |
770 | { | 770 | { |
771 | QPtrList<Event> el; | 771 | QPtrList<Event> el; |
772 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 772 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
773 | if ( it->calEnabled() ) el.append( it ); | 773 | if ( it->calEnabled() ) el.append( it ); |
774 | return el; | 774 | return el; |
775 | } | 775 | } |
776 | 776 | ||
777 | bool CalendarLocal::addJournal(Journal *journal) | 777 | bool CalendarLocal::addJournal(Journal *journal) |
778 | { | 778 | { |
779 | if ( journal->dtStart().isValid()) | 779 | if ( journal->dtStart().isValid()) |
780 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 780 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
781 | else | 781 | else |
782 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 782 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
783 | 783 | ||
784 | mJournalList.append(journal); | 784 | mJournalList.append(journal); |
785 | 785 | ||
786 | journal->registerObserver( this ); | 786 | journal->registerObserver( this ); |
787 | 787 | ||
788 | setModified( true ); | 788 | setModified( true ); |
789 | journal->setCalID( mDefaultCalendar ); | 789 | journal->setCalID( mDefaultCalendar ); |
790 | journal->setCalEnabled( true ); | 790 | journal->setCalEnabled( true ); |
791 | return true; | 791 | return true; |
792 | } | 792 | } |
793 | 793 | ||
794 | void CalendarLocal::deleteJournal( Journal *journal ) | 794 | void CalendarLocal::deleteJournal( Journal *journal ) |
795 | { | 795 | { |
796 | if ( mUndoIncidence ) delete mUndoIncidence; | 796 | if ( mUndoIncidence ) delete mUndoIncidence; |
797 | mUndoIncidence = journal->clone(); | 797 | mUndoIncidence = journal->clone(); |
798 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 798 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
799 | if ( mJournalList.removeRef(journal) ) { | 799 | if ( mJournalList.removeRef(journal) ) { |
800 | setModified( true ); | 800 | setModified( true ); |
801 | } | 801 | } |
802 | } | 802 | } |
803 | 803 | ||
804 | Journal *CalendarLocal::journal( const QDate &date ) | 804 | Journal *CalendarLocal::journal( const QDate &date ) |
805 | { | 805 | { |
806 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 806 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
807 | 807 | ||
808 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 808 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
809 | if ( it->calEnabled() && it->dtStart().date() == date ) | 809 | if ( it->calEnabled() && it->dtStart().date() == date ) |
810 | return it; | 810 | return it; |
811 | 811 | ||
812 | return 0; | 812 | return 0; |
813 | } | 813 | } |
814 | 814 | ||
815 | Journal *CalendarLocal::journal( const QString &uid ) | 815 | Journal *CalendarLocal::journal( const QString &uid ) |
816 | { | 816 | { |
817 | Journal * retVal = 0; | 817 | Journal * retVal = 0; |
818 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 818 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
819 | if ( it->calEnabled() && it->uid() == uid ) { | 819 | if ( it->calEnabled() && it->uid() == uid ) { |
820 | if ( retVal ) { | 820 | if ( retVal ) { |
821 | if ( retVal->calID() > it->calID() ) { | 821 | if ( retVal->calID() > it->calID() ) { |
822 | retVal = it; | 822 | retVal = it; |
823 | } | 823 | } |
824 | } else { | 824 | } else { |
825 | retVal = it; | 825 | retVal = it; |
826 | } | 826 | } |
827 | } | 827 | } |
828 | return retVal; | 828 | return retVal; |
829 | } | 829 | } |
830 | 830 | ||
831 | QPtrList<Journal> CalendarLocal::journals() | 831 | QPtrList<Journal> CalendarLocal::journals() |
832 | { | 832 | { |
833 | QPtrList<Journal> el; | 833 | QPtrList<Journal> el; |
834 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 834 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
835 | if ( it->calEnabled() ) el.append( it ); | 835 | if ( it->calEnabled() ) el.append( it ); |
836 | return el; | 836 | return el; |
837 | } | 837 | } |
838 | void CalendarLocal::setCalendarRemove( int id ) | 838 | void CalendarLocal::setCalendarRemove( int id ) |
839 | { | 839 | { |
840 | 840 | ||
841 | { | 841 | { |
842 | QPtrList<Event> EventList = mEventList; | 842 | QPtrList<Event> EventList = mEventList; |
843 | Event * ev = EventList.first(); | 843 | Event * ev = EventList.first(); |
844 | while ( ev ) { | 844 | while ( ev ) { |
845 | if ( ev->calID() == id ) | 845 | if ( ev->calID() == id ) |
846 | deleteEvent( ev ); | 846 | deleteEvent( ev ); |
847 | ev = EventList.next(); | 847 | ev = EventList.next(); |
848 | } | 848 | } |
849 | } | 849 | } |
850 | { | 850 | { |
851 | 851 | ||
852 | QPtrList<Todo> TodoList = mTodoList; | 852 | QPtrList<Todo> TodoList = mTodoList; |
853 | Todo * ev = TodoList.first(); | 853 | Todo * ev = TodoList.first(); |
854 | while ( ev ) { | 854 | while ( ev ) { |
855 | if ( ev->calID() == id ) | 855 | if ( ev->calID() == id ) |
856 | deleteTodo( ev ); | 856 | deleteTodo( ev ); |
857 | ev = TodoList.next(); | 857 | ev = TodoList.next(); |
858 | } | 858 | } |
859 | } | 859 | } |
860 | { | 860 | { |
861 | QPtrList<Journal> JournalList = mJournalList; | 861 | QPtrList<Journal> JournalList = mJournalList; |
862 | Journal * ev = JournalList.first(); | 862 | Journal * ev = JournalList.first(); |
863 | while ( ev ) { | 863 | while ( ev ) { |
864 | if ( ev->calID() == id ) | 864 | if ( ev->calID() == id ) |
865 | deleteJournal( ev ); | 865 | deleteJournal( ev ); |
866 | ev = JournalList.next(); | 866 | ev = JournalList.next(); |
867 | } | 867 | } |
868 | } | 868 | } |
869 | 869 | ||
870 | if ( mUndoIncidence ) delete mUndoIncidence; | 870 | if ( mUndoIncidence ) delete mUndoIncidence; |
871 | mUndoIncidence = 0; | 871 | mUndoIncidence = 0; |
872 | 872 | ||
873 | } | 873 | } |
874 | 874 | ||
875 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 875 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
876 | { | 876 | { |
877 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 877 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
878 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 878 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
879 | 879 | ||
880 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 880 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
881 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 881 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
882 | 882 | ||
883 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 883 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
884 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 884 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
885 | 885 | ||
886 | } | 886 | } |
887 | 887 | ||
888 | void CalendarLocal::setReadOnly( int id, bool enable ) | 888 | void CalendarLocal::setReadOnly( int id, bool enable ) |
889 | { | 889 | { |
890 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 890 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
891 | if ( it->calID() == id ) it->setReadOnly( enable ); | 891 | if ( it->calID() == id ) it->setReadOnly( enable ); |
892 | 892 | ||
893 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 893 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
894 | if ( it->calID() == id ) it->setReadOnly( enable ); | 894 | if ( it->calID() == id ) it->setReadOnly( enable ); |
895 | 895 | ||
896 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 896 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
897 | if ( it->calID() == id ) it->setReadOnly( enable ); | 897 | if ( it->calID() == id ) it->setReadOnly( enable ); |
898 | 898 | ||
899 | } | 899 | } |
900 | 900 | ||
901 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 901 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
902 | { | 902 | { |
903 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 903 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
904 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 904 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
905 | 905 | ||
906 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 906 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
907 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 907 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
908 | 908 | ||
909 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 909 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
910 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 910 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
911 | reInitAlarmSettings(); | 911 | reInitAlarmSettings(); |
912 | 912 | ||
913 | } | 913 | } |
914 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 914 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
915 | { | 915 | { |
916 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 916 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
917 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 917 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
918 | 918 | ||
919 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 919 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
920 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 920 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
921 | 921 | ||
922 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 922 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
923 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 923 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
924 | 924 | ||
925 | } | 925 | } |