-rw-r--r-- | libkcal/calendarlocal.cpp | 31 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/journal.cpp | 4 |
3 files changed, 24 insertions, 12 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 5baa7dc..e8c969f 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -259,25 +259,38 @@ void CalendarLocal::close() | |||
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! "); |
@@ -318,26 +331,26 @@ bool CalendarLocal::addEvent( Event *event ) | |||
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 ) { |
@@ -373,27 +386,27 @@ bool CalendarLocal::addTodo( Todo *todo ) | |||
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; |
@@ -877,27 +890,26 @@ bool CalendarLocal::addJournal(Journal *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 | } |
@@ -958,26 +970,25 @@ void CalendarLocal::setCalendarRemove( int id ) | |||
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() ) |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index a7a85c8..ae7e30c 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -60,24 +60,25 @@ class CalendarLocal : public Calendar | |||
60 | /** | 60 | /** |
61 | Writes out the calendar to disk in the specified \a format. | 61 | Writes out the calendar to disk in the specified \a format. |
62 | CalendarLocal takes ownership of the CalFormat object. | 62 | CalendarLocal takes ownership of the CalFormat object. |
63 | @return true, if successfull, false on error. | 63 | @return true, if successfull, false on error. |
64 | @param fileName the name of the file | 64 | @param fileName the name of the file |
65 | */ | 65 | */ |
66 | bool save( const QString &fileName, CalFormat *format = 0 ); | 66 | bool save( const QString &fileName, CalFormat *format = 0 ); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | Clears out the current calendar, freeing all used memory etc. etc. | 69 | Clears out the current calendar, freeing all used memory etc. etc. |
70 | */ | 70 | */ |
71 | void close(); | 71 | void close(); |
72 | void clearUndo(); | ||
72 | 73 | ||
73 | void save() {} | 74 | void save() {} |
74 | 75 | ||
75 | /** | 76 | /** |
76 | Add Event to calendar. | 77 | Add Event to calendar. |
77 | */ | 78 | */ |
78 | void removeSyncInfo( QString syncProfile); | 79 | void removeSyncInfo( QString syncProfile); |
79 | bool addAnniversaryNoDup( Event *event ); | 80 | bool addAnniversaryNoDup( Event *event ); |
80 | bool addEventNoDup( Event *event ); | 81 | bool addEventNoDup( Event *event ); |
81 | bool addEvent( Event *event ); | 82 | bool addEvent( Event *event ); |
82 | /** | 83 | /** |
83 | Deletes an event from this calendar. | 84 | Deletes an event from this calendar. |
diff --git a/libkcal/journal.cpp b/libkcal/journal.cpp index c4e4474..328db46 100644 --- a/libkcal/journal.cpp +++ b/libkcal/journal.cpp | |||
@@ -15,30 +15,30 @@ | |||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "journal.h" | 21 | #include "journal.h" |
22 | 22 | ||
23 | using namespace KCal; | 23 | using namespace KCal; |
24 | 24 | ||
25 | Journal::Journal() | 25 | Journal::Journal() |
26 | { | 26 | { |
27 | qDebug("New JJJ "); | 27 | |
28 | } | 28 | } |
29 | 29 | ||
30 | Journal::~Journal() | 30 | Journal::~Journal() |
31 | { | 31 | { |
32 | qDebug("delete JJJ "); | 32 | |
33 | } | 33 | } |
34 | 34 | ||
35 | Incidence *Journal::clone() | 35 | Incidence *Journal::clone() |
36 | { | 36 | { |
37 | return new Journal(*this); | 37 | return new Journal(*this); |
38 | } | 38 | } |
39 | 39 | ||
40 | 40 | ||
41 | bool KCal::operator==( const Journal& j1, const Journal& j2 ) | 41 | bool KCal::operator==( const Journal& j1, const Journal& j2 ) |
42 | { | 42 | { |
43 | return operator==( (const Incidence&)j1, (const Incidence&)j2 ); | 43 | return operator==( (const Incidence&)j1, (const Incidence&)j2 ); |
44 | } | 44 | } |