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