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