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