summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 3f46d53..12294c0 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -91,178 +91,180 @@ void CalendarLocal::close()
91 mJournalList.clear(); 91 mJournalList.clear();
92 92
93 mEventList.setAutoDelete( false ); 93 mEventList.setAutoDelete( false );
94 mTodoList.setAutoDelete( false ); 94 mTodoList.setAutoDelete( false );
95 mJournalList.setAutoDelete( false ); 95 mJournalList.setAutoDelete( false );
96 96
97 setModified( false ); 97 setModified( false );
98} 98}
99 99
100bool CalendarLocal::addAnniversaryNoDup( Event *event ) 100bool CalendarLocal::addAnniversaryNoDup( Event *event )
101{ 101{
102 QString cat; 102 QString cat;
103 bool isBirthday = true; 103 bool isBirthday = true;
104 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 104 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
105 isBirthday = false; 105 isBirthday = false;
106 cat = i18n( "Anniversary" ); 106 cat = i18n( "Anniversary" );
107 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 107 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
108 isBirthday = true; 108 isBirthday = true;
109 cat = i18n( "Birthday" ); 109 cat = i18n( "Birthday" );
110 } else { 110 } else {
111 qDebug("addAnniversaryNoDup called without fitting category! "); 111 qDebug("addAnniversaryNoDup called without fitting category! ");
112 return false; 112 return false;
113 } 113 }
114 Event * eve; 114 Event * eve;
115 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 115 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
116 if ( !(eve->categories().contains( cat ) )) 116 if ( !(eve->categories().contains( cat ) ))
117 continue; 117 continue;
118 // now we have an event with fitting category 118 // now we have an event with fitting category
119 if ( eve->dtStart().date() != event->dtStart().date() ) 119 if ( eve->dtStart().date() != event->dtStart().date() )
120 continue; 120 continue;
121 // now we have an event with fitting category+date 121 // now we have an event with fitting category+date
122 if ( eve->summary() != event->summary() ) 122 if ( eve->summary() != event->summary() )
123 continue; 123 continue;
124 // now we have an event with fitting category+date+summary 124 // now we have an event with fitting category+date+summary
125 return false; 125 return false;
126 } 126 }
127 return addEvent( event ); 127 return addEvent( event );
128 128
129} 129}
130bool CalendarLocal::addEventNoDup( Event *event ) 130bool CalendarLocal::addEventNoDup( Event *event )
131{ 131{
132 Event * eve; 132 Event * eve;
133 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 133 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
134 if ( *eve == *event ) { 134 if ( *eve == *event ) {
135 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 135 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
136 return false; 136 return false;
137 } 137 }
138 } 138 }
139 return addEvent( event ); 139 return addEvent( event );
140} 140}
141 141
142bool CalendarLocal::addEvent( Event *event ) 142bool CalendarLocal::addEvent( Event *event )
143{ 143{
144 insertEvent( event ); 144 insertEvent( event );
145 145
146 event->registerObserver( this ); 146 event->registerObserver( this );
147 147
148 setModified( true ); 148 setModified( true );
149 149
150 return true; 150 return true;
151} 151}
152 152
153void CalendarLocal::deleteEvent( Event *event ) 153void CalendarLocal::deleteEvent( Event *event )
154{ 154{
155 155 if ( mUndoIncidence ) delete mUndoIncidence;
156 156 mUndoIncidence = event->clone();
157 if ( mEventList.removeRef( event ) ) { 157 if ( mEventList.removeRef( event ) ) {
158 setModified( true ); 158 setModified( true );
159 } 159 }
160} 160}
161 161
162 162
163Event *CalendarLocal::event( const QString &uid ) 163Event *CalendarLocal::event( const QString &uid )
164{ 164{
165 165
166 Event *event; 166 Event *event;
167 167
168 for ( event = mEventList.first(); event; event = mEventList.next() ) { 168 for ( event = mEventList.first(); event; event = mEventList.next() ) {
169 if ( event->uid() == uid ) { 169 if ( event->uid() == uid ) {
170 return event; 170 return event;
171 } 171 }
172 } 172 }
173 173
174 return 0; 174 return 0;
175} 175}
176bool CalendarLocal::addTodoNoDup( Todo *todo ) 176bool CalendarLocal::addTodoNoDup( Todo *todo )
177{ 177{
178 Todo * eve; 178 Todo * eve;
179 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 179 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
180 if ( *eve == *todo ) { 180 if ( *eve == *todo ) {
181 //qDebug("duplicate todo found! not inserted! "); 181 //qDebug("duplicate todo found! not inserted! ");
182 return false; 182 return false;
183 } 183 }
184 } 184 }
185 return addTodo( todo ); 185 return addTodo( todo );
186} 186}
187bool CalendarLocal::addTodo( Todo *todo ) 187bool CalendarLocal::addTodo( Todo *todo )
188{ 188{
189 mTodoList.append( todo ); 189 mTodoList.append( todo );
190 190
191 todo->registerObserver( this ); 191 todo->registerObserver( this );
192 192
193 // Set up subtask relations 193 // Set up subtask relations
194 setupRelations( todo ); 194 setupRelations( todo );
195 195
196 setModified( true ); 196 setModified( true );
197 197
198 return true; 198 return true;
199} 199}
200 200
201void CalendarLocal::deleteTodo( Todo *todo ) 201void CalendarLocal::deleteTodo( Todo *todo )
202{ 202{
203 // Handle orphaned children 203 // Handle orphaned children
204 removeRelations( todo ); 204 if ( mUndoIncidence ) delete mUndoIncidence;
205 mUndoIncidence = todo->clone();
206 removeRelations( todo );
205 207
206 if ( mTodoList.removeRef( todo ) ) { 208 if ( mTodoList.removeRef( todo ) ) {
207 setModified( true ); 209 setModified( true );
208 } 210 }
209} 211}
210 212
211QPtrList<Todo> CalendarLocal::rawTodos() 213QPtrList<Todo> CalendarLocal::rawTodos()
212{ 214{
213 return mTodoList; 215 return mTodoList;
214} 216}
215Todo *CalendarLocal::todo( QString syncProf, QString id ) 217Todo *CalendarLocal::todo( QString syncProf, QString id )
216{ 218{
217 Todo *todo; 219 Todo *todo;
218 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 220 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
219 if ( todo->getID( syncProf ) == id ) return todo; 221 if ( todo->getID( syncProf ) == id ) return todo;
220 } 222 }
221 223
222 return 0; 224 return 0;
223} 225}
224void CalendarLocal::removeSyncInfo( QString syncProfile) 226void CalendarLocal::removeSyncInfo( QString syncProfile)
225{ 227{
226 QPtrList<Incidence> all = rawIncidences() ; 228 QPtrList<Incidence> all = rawIncidences() ;
227 Incidence *inc; 229 Incidence *inc;
228 for ( inc = all.first(); inc; inc = all.next() ) { 230 for ( inc = all.first(); inc; inc = all.next() ) {
229 inc->removeID( syncProfile ); 231 inc->removeID( syncProfile );
230 } 232 }
231 if ( syncProfile.isEmpty() ) { 233 if ( syncProfile.isEmpty() ) {
232 QPtrList<Event> el; 234 QPtrList<Event> el;
233 Event *todo; 235 Event *todo;
234 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 236 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
235 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 237 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
236 el.append( todo ); 238 el.append( todo );
237 } 239 }
238 for ( todo = el.first(); todo; todo = el.next() ) { 240 for ( todo = el.first(); todo; todo = el.next() ) {
239 deleteIncidence ( todo ); 241 deleteIncidence ( todo );
240 } 242 }
241 } else { 243 } else {
242 Event *lse = event( "last-syncEvent-"+ syncProfile); 244 Event *lse = event( "last-syncEvent-"+ syncProfile);
243 deleteIncidence ( lse ); 245 deleteIncidence ( lse );
244 } 246 }
245} 247}
246QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 248QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
247{ 249{
248 QPtrList<Event> el; 250 QPtrList<Event> el;
249 Event *todo; 251 Event *todo;
250 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 252 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
251 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 253 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
252 if ( todo->summary().left(3) == "E: " ) 254 if ( todo->summary().left(3) == "E: " )
253 el.append( todo ); 255 el.append( todo );
254 } 256 }
255 257
256 return el; 258 return el;
257 259
258} 260}
259Event *CalendarLocal::event( QString syncProf, QString id ) 261Event *CalendarLocal::event( QString syncProf, QString id )
260{ 262{
261 Event *todo; 263 Event *todo;
262 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 264 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
263 if ( todo->getID( syncProf ) == id ) return todo; 265 if ( todo->getID( syncProf ) == id ) return todo;
264 } 266 }
265 267
266 return 0; 268 return 0;
267} 269}
268Todo *CalendarLocal::todo( const QString &uid ) 270Todo *CalendarLocal::todo( const QString &uid )
@@ -626,94 +628,97 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
626 found = true; 628 found = true;
627 } else if ( event->recurrence()->duration() == 0 ) { // End date set 629 } else if ( event->recurrence()->duration() == 0 ) { // End date set
628 QDate rEnd = event->recurrence()->endDate(); 630 QDate rEnd = event->recurrence()->endDate();
629 if ( rEnd >= start && rEnd <= end ) { // End date within range 631 if ( rEnd >= start && rEnd <= end ) { // End date within range
630 found = true; 632 found = true;
631 } 633 }
632 } else { // Duration set 634 } else { // Duration set
633 // TODO: Calculate end date from duration. Should be done in Event 635 // TODO: Calculate end date from duration. Should be done in Event
634 // For now include all events with a duration. 636 // For now include all events with a duration.
635 found = true; 637 found = true;
636 } 638 }
637 } 639 }
638 */ 640 */
639 641
640 } 642 }
641 643
642 if ( found ) eventList.append( event ); 644 if ( found ) eventList.append( event );
643 } else { 645 } else {
644 QDate s = event->dtStart().date(); 646 QDate s = event->dtStart().date();
645 QDate e = event->dtEnd().date(); 647 QDate e = event->dtEnd().date();
646 648
647 if ( inclusive ) { 649 if ( inclusive ) {
648 if ( s >= start && e <= end ) { 650 if ( s >= start && e <= end ) {
649 eventList.append( event ); 651 eventList.append( event );
650 } 652 }
651 } else { 653 } else {
652 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 654 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
653 eventList.append( event ); 655 eventList.append( event );
654 } 656 }
655 } 657 }
656 } 658 }
657 } 659 }
658 660
659 return eventList; 661 return eventList;
660} 662}
661 663
662QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 664QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
663{ 665{
664 return rawEventsForDate( qdt.date() ); 666 return rawEventsForDate( qdt.date() );
665} 667}
666 668
667QPtrList<Event> CalendarLocal::rawEvents() 669QPtrList<Event> CalendarLocal::rawEvents()
668{ 670{
669 return mEventList; 671 return mEventList;
670} 672}
671 673
672bool CalendarLocal::addJournal(Journal *journal) 674bool CalendarLocal::addJournal(Journal *journal)
673{ 675{
674 if ( journal->dtStart().isValid()) 676 if ( journal->dtStart().isValid())
675 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 677 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
676 else 678 else
677 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 679 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
678 680
679 mJournalList.append(journal); 681 mJournalList.append(journal);
680 682
681 journal->registerObserver( this ); 683 journal->registerObserver( this );
682 684
683 setModified( true ); 685 setModified( true );
684 686
685 return true; 687 return true;
686} 688}
687 689
688void CalendarLocal::deleteJournal( Journal *journal ) 690void CalendarLocal::deleteJournal( Journal *journal )
689{ 691{
692 if ( mUndoIncidence ) delete mUndoIncidence;
693 mUndoIncidence = journal->clone();
694 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
690 if ( mJournalList.removeRef(journal) ) { 695 if ( mJournalList.removeRef(journal) ) {
691 setModified( true ); 696 setModified( true );
692 } 697 }
693} 698}
694 699
695Journal *CalendarLocal::journal( const QDate &date ) 700Journal *CalendarLocal::journal( const QDate &date )
696{ 701{
697// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 702// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
698 703
699 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 704 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
700 if ( it->dtStart().date() == date ) 705 if ( it->dtStart().date() == date )
701 return it; 706 return it;
702 707
703 return 0; 708 return 0;
704} 709}
705 710
706Journal *CalendarLocal::journal( const QString &uid ) 711Journal *CalendarLocal::journal( const QString &uid )
707{ 712{
708 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 713 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
709 if ( it->uid() == uid ) 714 if ( it->uid() == uid )
710 return it; 715 return it;
711 716
712 return 0; 717 return 0;
713} 718}
714 719
715QPtrList<Journal> CalendarLocal::journals() 720QPtrList<Journal> CalendarLocal::journals()
716{ 721{
717 return mJournalList; 722 return mJournalList;
718} 723}
719 724