-rw-r--r-- | libkcal/calendarlocal.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 8a5a76f..ce3cd09 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -158,287 +158,287 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckD | |||
158 | if ( retVal ) return retVal; | 158 | if ( retVal ) return retVal; |
159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
160 | if ( it->uid() == uid ) { | 160 | if ( it->uid() == uid ) { |
161 | if( calID ) { | 161 | if( calID ) { |
162 | if ( event->calID() != calID ) | 162 | if ( event->calID() != calID ) |
163 | continue; | 163 | continue; |
164 | } | 164 | } |
165 | else { | 165 | else { |
166 | if ( enabledOnly ) { | 166 | if ( enabledOnly ) { |
167 | if ( !it->calEnabled() ) { | 167 | if ( !it->calEnabled() ) { |
168 | if ( isDup ) | 168 | if ( isDup ) |
169 | *isDup = it->calID(); | 169 | *isDup = it->calID(); |
170 | continue; | 170 | continue; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | if ( doNotCheckDuplicates ) return it; | 174 | if ( doNotCheckDuplicates ) return it; |
175 | if ( retVal ) { | 175 | if ( retVal ) { |
176 | if ( retVal->calID() > it->calID() ) { | 176 | if ( retVal->calID() > it->calID() ) { |
177 | if ( isDup ) | 177 | if ( isDup ) |
178 | *isDup = retVal->calID(); | 178 | *isDup = retVal->calID(); |
179 | retVal = it; | 179 | retVal = it; |
180 | } | 180 | } |
181 | } else { | 181 | } else { |
182 | retVal = it; | 182 | retVal = it; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return retVal; | 185 | return retVal; |
186 | } | 186 | } |
187 | 187 | ||
188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
189 | { | 189 | { |
190 | // 1 look for raw inc in local | 190 | // 1 look for raw inc in local |
191 | // if inc not in remote, delete in local | 191 | // if inc not in remote, delete in local |
192 | // 2 look for raw inc in remote | 192 | // 2 look for raw inc in remote |
193 | // if inc in local, replace it | 193 | // if inc in local, replace it |
194 | // if not in local, add it to default calendar | 194 | // if not in local, add it to default calendar |
195 | QPtrList<Incidence> localInc = rawIncidences(); | 195 | QPtrList<Incidence> localInc = rawIncidences(); |
196 | Incidence* inL = localInc.first(); | 196 | Incidence* inL = localInc.first(); |
197 | while ( inL ) { | 197 | while ( inL ) { |
198 | if ( ! inL->isReadOnly () ) | 198 | if ( ! inL->isReadOnly () ) |
199 | if ( !remote->incidenceForUid( inL->uid(), true )) | 199 | if ( !remote->incidenceForUid( inL->uid(), true )) |
200 | deleteIncidence( inL ); | 200 | deleteIncidence( inL ); |
201 | inL = localInc.next(); | 201 | inL = localInc.next(); |
202 | } | 202 | } |
203 | QPtrList<Incidence> er = remote->rawIncidences(); | 203 | QPtrList<Incidence> er = remote->rawIncidences(); |
204 | Incidence* inR = er.first(); | 204 | Incidence* inR = er.first(); |
205 | while ( inR ) { | 205 | while ( inR ) { |
206 | inL = incidenceForUid( inR->uid(),false ); | 206 | inL = incidenceForUid( inR->uid(),false ); |
207 | if ( inL ) { | 207 | if ( inL ) { |
208 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 208 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
209 | int calID = inL->calID(); | 209 | int calID = inL->calID(); |
210 | deleteIncidence( inL ); | 210 | deleteIncidence( inL ); |
211 | inL = inR->clone(); | 211 | inL = inR->clone(); |
212 | inL->setCalID_block( calID ); | 212 | inL->setCalID_block( calID ); |
213 | addIncidence( inL ); | 213 | addIncidence( inL ); |
214 | } | 214 | } |
215 | } else { | 215 | } else { |
216 | inL = inR->clone(); | 216 | inL = inR->clone(); |
217 | inL->setCalID_block( 0 );// add to default cal | 217 | inL->setCalID_block( 0 );// add to default cal |
218 | addIncidence( inL ); | 218 | addIncidence( inL ); |
219 | } | 219 | } |
220 | inR = er.next(); | 220 | inR = er.next(); |
221 | } | 221 | } |
222 | return true; | 222 | return true; |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 226 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
227 | { | 227 | { |
228 | CalendarLocal calendar( timeZoneId() ); | 228 | CalendarLocal calendar( timeZoneId() ); |
229 | calendar.setDefaultCalendar( id ); | 229 | calendar.setDefaultCalendar( id ); |
230 | if ( calendar.load( name ) ) { | 230 | if ( calendar.load( name ) ) { |
231 | addCalendar( &calendar ); | 231 | addCalendar( &calendar ); |
232 | return true; | 232 | return true; |
233 | } | 233 | } |
234 | return false; | 234 | return false; |
235 | } | 235 | } |
236 | void CalendarLocal::setSyncEventsEnabled() | 236 | void CalendarLocal::setSyncEventsEnabled() |
237 | { | 237 | { |
238 | Event * ev; | 238 | Event * ev; |
239 | ev = mEventList.first(); | 239 | ev = mEventList.first(); |
240 | while ( ev ) { | 240 | while ( ev ) { |
241 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 241 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
242 | ev->setCalEnabled( true ); | 242 | ev->setCalEnabled( true ); |
243 | ev = mEventList.next(); | 243 | ev = mEventList.next(); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | void CalendarLocal::setSyncEventsReadOnly() | 246 | void CalendarLocal::setSyncEventsReadOnly() |
247 | { | 247 | { |
248 | Event * ev; | 248 | Event * ev; |
249 | ev = mEventList.first(); | 249 | ev = mEventList.first(); |
250 | while ( ev ) { | 250 | while ( ev ) { |
251 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 251 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
252 | ev->setReadOnly( true ); | 252 | ev->setReadOnly( true ); |
253 | } | 253 | } |
254 | ev = mEventList.next(); | 254 | ev = mEventList.next(); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | void CalendarLocal::addCalendar( Calendar* cal ) | 258 | void CalendarLocal::addCalendar( Calendar* cal ) |
259 | { | 259 | { |
260 | cal->setDontDeleteIncidencesOnClose(); | 260 | cal->setDontDeleteIncidencesOnClose(); |
261 | setSyncEventsEnabled(); | 261 | setSyncEventsEnabled(); |
262 | QPtrList<Incidence> incList; | 262 | QPtrList<Incidence> incList; |
263 | { | 263 | { |
264 | QPtrList<Event> EventList = cal->rawEvents(); | 264 | QPtrList<Event> EventList = cal->rawEvents(); |
265 | Event * ev = EventList.first(); | 265 | Event * ev = EventList.first(); |
266 | while ( ev ) { | 266 | while ( ev ) { |
267 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | 267 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { |
268 | ev->setCalID_block( 1 ); | 268 | ev->setCalID_block( 1 ); |
269 | } | 269 | } |
270 | Event * se = event( ev->uid() ); | 270 | Event * se = event( ev->uid() ); |
271 | if ( se ) | 271 | if ( se ) |
272 | incList.append( se ); | 272 | incList.append( se ); |
273 | ev->unRegisterObserver( cal ); | 273 | ev->unRegisterObserver( cal ); |
274 | ev->registerObserver( this ); | 274 | ev->registerObserver( this ); |
275 | mEventList.append( ev ); | 275 | mEventList.append( ev ); |
276 | ev = EventList.next(); | 276 | ev = EventList.next(); |
277 | } | 277 | } |
278 | 278 | ||
279 | } | 279 | } |
280 | { | 280 | { |
281 | 281 | ||
282 | QPtrList<Todo> TodoList = cal->rawTodos(); | 282 | QPtrList<Todo> TodoList = cal->rawTodos(); |
283 | Todo * ev = TodoList.first(); | 283 | Todo * ev = TodoList.first(); |
284 | while ( ev ) { | 284 | while ( ev ) { |
285 | ev->resetRelatedTo(); | 285 | ev->resetRelatedTo(); |
286 | ev = TodoList.next(); | 286 | Todo * se = todo( ev->uid() ); |
287 | if ( se ) | ||
288 | deleteTodo( se ); | ||
289 | ev = TodoList.next(); | ||
287 | } | 290 | } |
288 | //TodoList = cal->rawTodos(); | 291 | //TodoList = cal->rawTodos(); |
289 | ev = TodoList.first(); | 292 | ev = TodoList.first(); |
290 | while ( ev ) { | 293 | while ( ev ) { |
291 | Todo * se = todo( ev->uid() ); | ||
292 | if ( se ) | ||
293 | incList.append( se ); | ||
294 | ev->unRegisterObserver( cal ); | 294 | ev->unRegisterObserver( cal ); |
295 | ev->registerObserver( this ); | 295 | ev->registerObserver( this ); |
296 | mTodoList.append( ev ); | 296 | mTodoList.append( ev ); |
297 | setupRelations( ev ); | 297 | setupRelations( ev ); |
298 | ev = TodoList.next(); | 298 | ev = TodoList.next(); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | { | 301 | { |
302 | QPtrList<Journal> JournalList = cal->journals(); | 302 | QPtrList<Journal> JournalList = cal->journals(); |
303 | Journal * ev = JournalList.first(); | 303 | Journal * ev = JournalList.first(); |
304 | while ( ev ) { | 304 | while ( ev ) { |
305 | Journal * se = journal( ev->uid() ); | 305 | Journal * se = journal( ev->uid() ); |
306 | if ( se ) | 306 | if ( se ) |
307 | incList.append( se ); | 307 | incList.append( se ); |
308 | ev->unRegisterObserver( cal ); | 308 | ev->unRegisterObserver( cal ); |
309 | ev->registerObserver( this ); | 309 | ev->registerObserver( this ); |
310 | mJournalList.append( ev ); | 310 | mJournalList.append( ev ); |
311 | ev = JournalList.next(); | 311 | ev = JournalList.next(); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | { | 314 | { |
315 | for (Incidence * ev = incList.first(); ev; ev = incList.next() ) { | 315 | for (Incidence * inc = incList.first(); inc; inc = incList.next() ) { |
316 | deleteIncidence ( ev ); | 316 | deleteIncidence ( inc ); |
317 | } | 317 | } |
318 | } | 318 | } |
319 | setModified( true ); | 319 | setModified( true ); |
320 | } | 320 | } |
321 | bool CalendarLocal::load( const QString &fileName ) | 321 | bool CalendarLocal::load( const QString &fileName ) |
322 | { | 322 | { |
323 | FileStorage storage( this, fileName ); | 323 | FileStorage storage( this, fileName ); |
324 | return storage.load(); | 324 | return storage.load(); |
325 | } | 325 | } |
326 | 326 | ||
327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
328 | { | 328 | { |
329 | FileStorage storage( this, fileName, format ); | 329 | FileStorage storage( this, fileName, format ); |
330 | return storage.save(); | 330 | return storage.save(); |
331 | } | 331 | } |
332 | 332 | ||
333 | void CalendarLocal::stopAllTodos() | 333 | void CalendarLocal::stopAllTodos() |
334 | { | 334 | { |
335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
336 | it->setRunning( false ); | 336 | it->setRunning( false ); |
337 | 337 | ||
338 | } | 338 | } |
339 | void CalendarLocal::close() | 339 | void CalendarLocal::close() |
340 | { | 340 | { |
341 | 341 | ||
342 | Todo * i; | 342 | Todo * i; |
343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
344 | 344 | ||
345 | mEventList.setAutoDelete( true ); | 345 | mEventList.setAutoDelete( true ); |
346 | mTodoList.setAutoDelete( true ); | 346 | mTodoList.setAutoDelete( true ); |
347 | mJournalList.setAutoDelete( true ); | 347 | mJournalList.setAutoDelete( true ); |
348 | 348 | ||
349 | mEventList.clear(); | 349 | mEventList.clear(); |
350 | mTodoList.clear(); | 350 | mTodoList.clear(); |
351 | mJournalList.clear(); | 351 | mJournalList.clear(); |
352 | 352 | ||
353 | mEventList.setAutoDelete( false ); | 353 | mEventList.setAutoDelete( false ); |
354 | mTodoList.setAutoDelete( false ); | 354 | mTodoList.setAutoDelete( false ); |
355 | mJournalList.setAutoDelete( false ); | 355 | mJournalList.setAutoDelete( false ); |
356 | 356 | ||
357 | setModified( false ); | 357 | setModified( false ); |
358 | } | 358 | } |
359 | 359 | ||
360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
361 | { | 361 | { |
362 | QString cat; | 362 | QString cat; |
363 | bool isBirthday = true; | 363 | bool isBirthday = true; |
364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
365 | isBirthday = false; | 365 | isBirthday = false; |
366 | cat = i18n( "Anniversary" ); | 366 | cat = i18n( "Anniversary" ); |
367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
368 | isBirthday = true; | 368 | isBirthday = true; |
369 | cat = i18n( "Birthday" ); | 369 | cat = i18n( "Birthday" ); |
370 | } else { | 370 | } else { |
371 | qDebug("addAnniversaryNoDup called without fitting category! "); | 371 | qDebug("addAnniversaryNoDup called without fitting category! "); |
372 | return false; | 372 | return false; |
373 | } | 373 | } |
374 | Event * eve; | 374 | Event * eve; |
375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
376 | if ( !(eve->categories().contains( cat ) )) | 376 | if ( !(eve->categories().contains( cat ) )) |
377 | continue; | 377 | continue; |
378 | // now we have an event with fitting category | 378 | // now we have an event with fitting category |
379 | if ( eve->dtStart().date() != event->dtStart().date() ) | 379 | if ( eve->dtStart().date() != event->dtStart().date() ) |
380 | continue; | 380 | continue; |
381 | // now we have an event with fitting category+date | 381 | // now we have an event with fitting category+date |
382 | if ( eve->summary() != event->summary() ) | 382 | if ( eve->summary() != event->summary() ) |
383 | continue; | 383 | continue; |
384 | // now we have an event with fitting category+date+summary | 384 | // now we have an event with fitting category+date+summary |
385 | return false; | 385 | return false; |
386 | } | 386 | } |
387 | return addEvent( event ); | 387 | return addEvent( event ); |
388 | 388 | ||
389 | } | 389 | } |
390 | bool CalendarLocal::addEventNoDup( Event *event ) | 390 | bool CalendarLocal::addEventNoDup( Event *event ) |
391 | { | 391 | { |
392 | Event * eve; | 392 | Event * eve; |
393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
394 | if ( *eve == *event ) { | 394 | if ( *eve == *event ) { |
395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
396 | return false; | 396 | return false; |
397 | } | 397 | } |
398 | } | 398 | } |
399 | return addEvent( event ); | 399 | return addEvent( event ); |
400 | } | 400 | } |
401 | 401 | ||
402 | bool CalendarLocal::addEvent( Event *event ) | 402 | bool CalendarLocal::addEvent( Event *event ) |
403 | { | 403 | { |
404 | insertEvent( event ); | 404 | insertEvent( event ); |
405 | 405 | ||
406 | event->registerObserver( this ); | 406 | event->registerObserver( this ); |
407 | 407 | ||
408 | setModified( true ); | 408 | setModified( true ); |
409 | if ( event->calID() == 0 ) | 409 | if ( event->calID() == 0 ) |
410 | event->setCalID_block( mDefaultCalendar ); | 410 | event->setCalID_block( mDefaultCalendar ); |
411 | event->setCalEnabled( true ); | 411 | event->setCalEnabled( true ); |
412 | 412 | ||
413 | return true; | 413 | return true; |
414 | } | 414 | } |
415 | 415 | ||
416 | void CalendarLocal::deleteEvent( Event *event ) | 416 | void CalendarLocal::deleteEvent( Event *event ) |
417 | { | 417 | { |
418 | clearUndo(event); | 418 | clearUndo(event); |
419 | if ( mEventList.removeRef( event ) ) { | 419 | if ( mEventList.removeRef( event ) ) { |
420 | setModified( true ); | 420 | setModified( true ); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | 424 | ||
425 | Event *CalendarLocal::event( const QString &uid ) | 425 | Event *CalendarLocal::event( const QString &uid ) |
426 | { | 426 | { |
427 | Event *event; | 427 | Event *event; |
428 | Event *retVal = 0; | 428 | Event *retVal = 0; |
429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
430 | if ( event->calEnabled() && event->uid() == uid ) { | 430 | if ( event->calEnabled() && event->uid() == uid ) { |
431 | if ( retVal ) { | 431 | if ( retVal ) { |
432 | if ( retVal->calID() > event->calID() ) { | 432 | if ( retVal->calID() > event->calID() ) { |
433 | retVal = event; | 433 | retVal = event; |
434 | } | 434 | } |
435 | } else { | 435 | } else { |
436 | retVal = event; | 436 | retVal = event; |
437 | } | 437 | } |
438 | } | 438 | } |
439 | } | 439 | } |
440 | return retVal; | 440 | return retVal; |
441 | } | 441 | } |
442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
443 | { | 443 | { |
444 | Todo * eve; | 444 | Todo * eve; |