-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 | |||
@@ -239,181 +239,194 @@ bool CalendarLocal::load( const QString &fileName ) | |||
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; |
@@ -857,67 +870,66 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | |||
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 | } |
@@ -938,66 +950,65 @@ QPtrList<Journal> CalendarLocal::journals() | |||
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() ) |