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