summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index ca64e66..cce798f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -162,182 +162,184 @@ void CalendarLocal::close()
162 mEventList.setAutoDelete( true ); 162 mEventList.setAutoDelete( true );
163 mTodoList.setAutoDelete( true ); 163 mTodoList.setAutoDelete( true );
164 mJournalList.setAutoDelete( false ); 164 mJournalList.setAutoDelete( false );
165 165
166 mEventList.clear(); 166 mEventList.clear();
167 mTodoList.clear(); 167 mTodoList.clear();
168 mJournalList.clear(); 168 mJournalList.clear();
169 169
170 mEventList.setAutoDelete( false ); 170 mEventList.setAutoDelete( false );
171 mTodoList.setAutoDelete( false ); 171 mTodoList.setAutoDelete( false );
172 mJournalList.setAutoDelete( false ); 172 mJournalList.setAutoDelete( false );
173 173
174 setModified( false ); 174 setModified( false );
175} 175}
176 176
177bool CalendarLocal::addAnniversaryNoDup( Event *event ) 177bool CalendarLocal::addAnniversaryNoDup( Event *event )
178{ 178{
179 QString cat; 179 QString cat;
180 bool isBirthday = true; 180 bool isBirthday = true;
181 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 181 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
182 isBirthday = false; 182 isBirthday = false;
183 cat = i18n( "Anniversary" ); 183 cat = i18n( "Anniversary" );
184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
185 isBirthday = true; 185 isBirthday = true;
186 cat = i18n( "Birthday" ); 186 cat = i18n( "Birthday" );
187 } else { 187 } else {
188 qDebug("addAnniversaryNoDup called without fitting category! "); 188 qDebug("addAnniversaryNoDup called without fitting category! ");
189 return false; 189 return false;
190 } 190 }
191 Event * eve; 191 Event * eve;
192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
193 if ( !(eve->categories().contains( cat ) )) 193 if ( !(eve->categories().contains( cat ) ))
194 continue; 194 continue;
195 // now we have an event with fitting category 195 // now we have an event with fitting category
196 if ( eve->dtStart().date() != event->dtStart().date() ) 196 if ( eve->dtStart().date() != event->dtStart().date() )
197 continue; 197 continue;
198 // now we have an event with fitting category+date 198 // now we have an event with fitting category+date
199 if ( eve->summary() != event->summary() ) 199 if ( eve->summary() != event->summary() )
200 continue; 200 continue;
201 // now we have an event with fitting category+date+summary 201 // now we have an event with fitting category+date+summary
202 return false; 202 return false;
203 } 203 }
204 return addEvent( event ); 204 return addEvent( event );
205 205
206} 206}
207bool CalendarLocal::addEventNoDup( Event *event ) 207bool CalendarLocal::addEventNoDup( Event *event )
208{ 208{
209 Event * eve; 209 Event * eve;
210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
211 if ( *eve == *event ) { 211 if ( *eve == *event ) {
212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
213 return false; 213 return false;
214 } 214 }
215 } 215 }
216 return addEvent( event ); 216 return addEvent( event );
217} 217}
218 218
219bool CalendarLocal::addEvent( Event *event ) 219bool CalendarLocal::addEvent( Event *event )
220{ 220{
221 insertEvent( event ); 221 insertEvent( event );
222 222
223 event->registerObserver( this ); 223 event->registerObserver( this );
224 224
225 setModified( true ); 225 setModified( true );
226 event->setCalID( mDefaultCalendar ); 226 if ( event->calID() == 0 )
227 event->setCalID( mDefaultCalendar );
227 event->setCalEnabled( true ); 228 event->setCalEnabled( true );
228 229
229 return true; 230 return true;
230} 231}
231 232
232void CalendarLocal::deleteEvent( Event *event ) 233void CalendarLocal::deleteEvent( Event *event )
233{ 234{
234 if ( mUndoIncidence ) delete mUndoIncidence; 235 if ( mUndoIncidence ) delete mUndoIncidence;
235 mUndoIncidence = event->clone(); 236 mUndoIncidence = event->clone();
236 if ( mEventList.removeRef( event ) ) { 237 if ( mEventList.removeRef( event ) ) {
237 setModified( true ); 238 setModified( true );
238 } 239 }
239} 240}
240 241
241 242
242Event *CalendarLocal::event( const QString &uid ) 243Event *CalendarLocal::event( const QString &uid )
243{ 244{
244 Event *event; 245 Event *event;
245 Event *retVal = 0; 246 Event *retVal = 0;
246 for ( event = mEventList.first(); event; event = mEventList.next() ) { 247 for ( event = mEventList.first(); event; event = mEventList.next() ) {
247 if ( event->calEnabled() && event->uid() == uid ) { 248 if ( event->calEnabled() && event->uid() == uid ) {
248 if ( retVal ) { 249 if ( retVal ) {
249 if ( retVal->calID() > event->calID() ) { 250 if ( retVal->calID() > event->calID() ) {
250 retVal = event; 251 retVal = event;
251 } 252 }
252 } else { 253 } else {
253 retVal = event; 254 retVal = event;
254 } 255 }
255 } 256 }
256 } 257 }
257 return retVal; 258 return retVal;
258} 259}
259bool CalendarLocal::addTodoNoDup( Todo *todo ) 260bool CalendarLocal::addTodoNoDup( Todo *todo )
260{ 261{
261 Todo * eve; 262 Todo * eve;
262 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 263 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
263 if ( *eve == *todo ) { 264 if ( *eve == *todo ) {
264 //qDebug("duplicate todo found! not inserted! "); 265 //qDebug("duplicate todo found! not inserted! ");
265 return false; 266 return false;
266 } 267 }
267 } 268 }
268 return addTodo( todo ); 269 return addTodo( todo );
269} 270}
270bool CalendarLocal::addTodo( Todo *todo ) 271bool CalendarLocal::addTodo( Todo *todo )
271{ 272{
272 mTodoList.append( todo ); 273 mTodoList.append( todo );
273 274
274 todo->registerObserver( this ); 275 todo->registerObserver( this );
275 276
276 // Set up subtask relations 277 // Set up subtask relations
277 setupRelations( todo ); 278 setupRelations( todo );
278 279
279 setModified( true ); 280 setModified( true );
281 if ( todo->calID() == 0 )
280 todo->setCalID( mDefaultCalendar ); 282 todo->setCalID( mDefaultCalendar );
281 todo->setCalEnabled( true ); 283 todo->setCalEnabled( true );
282 return true; 284 return true;
283} 285}
284 286
285void CalendarLocal::deleteTodo( Todo *todo ) 287void CalendarLocal::deleteTodo( Todo *todo )
286{ 288{
287 // Handle orphaned children 289 // Handle orphaned children
288 if ( mUndoIncidence ) delete mUndoIncidence; 290 if ( mUndoIncidence ) delete mUndoIncidence;
289 removeRelations( todo ); 291 removeRelations( todo );
290 mUndoIncidence = todo->clone(); 292 mUndoIncidence = todo->clone();
291 293
292 if ( mTodoList.removeRef( todo ) ) { 294 if ( mTodoList.removeRef( todo ) ) {
293 setModified( true ); 295 setModified( true );
294 } 296 }
295} 297}
296 298
297QPtrList<Todo> CalendarLocal::rawTodos() 299QPtrList<Todo> CalendarLocal::rawTodos()
298{ 300{
299 QPtrList<Todo> el; 301 QPtrList<Todo> el;
300 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 302 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
301 if ( it->calEnabled() ) el.append( it ); 303 if ( it->calEnabled() ) el.append( it );
302 return el; 304 return el;
303} 305}
304Todo *CalendarLocal::todo( QString syncProf, QString id ) 306Todo *CalendarLocal::todo( QString syncProf, QString id )
305{ 307{
306 Todo *todo; 308 Todo *todo;
307 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 309 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
308 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 310 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
309 } 311 }
310 312
311 return 0; 313 return 0;
312} 314}
313void CalendarLocal::removeSyncInfo( QString syncProfile) 315void CalendarLocal::removeSyncInfo( QString syncProfile)
314{ 316{
315 QPtrList<Incidence> all = rawIncidences() ; 317 QPtrList<Incidence> all = rawIncidences() ;
316 Incidence *inc; 318 Incidence *inc;
317 for ( inc = all.first(); inc; inc = all.next() ) { 319 for ( inc = all.first(); inc; inc = all.next() ) {
318 inc->removeID( syncProfile ); 320 inc->removeID( syncProfile );
319 } 321 }
320 if ( syncProfile.isEmpty() ) { 322 if ( syncProfile.isEmpty() ) {
321 QPtrList<Event> el; 323 QPtrList<Event> el;
322 Event *todo; 324 Event *todo;
323 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 325 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
324 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 326 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
325 el.append( todo ); 327 el.append( todo );
326 } 328 }
327 for ( todo = el.first(); todo; todo = el.next() ) { 329 for ( todo = el.first(); todo; todo = el.next() ) {
328 deleteIncidence ( todo ); 330 deleteIncidence ( todo );
329 } 331 }
330 } else { 332 } else {
331 Event *lse = event( "last-syncEvent-"+ syncProfile); 333 Event *lse = event( "last-syncEvent-"+ syncProfile);
332 if ( lse ) 334 if ( lse )
333 deleteIncidence ( lse ); 335 deleteIncidence ( lse );
334 } 336 }
335} 337}
336QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 338QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
337{ 339{
338 QPtrList<Event> el; 340 QPtrList<Event> el;
339 Event *todo; 341 Event *todo;
340 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 342 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
341 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 343 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
342 if ( todo->summary().left(3) == "E: " ) 344 if ( todo->summary().left(3) == "E: " )
343 el.append( todo ); 345 el.append( todo );
@@ -720,129 +722,130 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
720 } 722 }
721 723
722 /* 724 /*
723 // crap !!! 725 // crap !!!
724 if ( rStart <= end ) { // Start date not after range 726 if ( rStart <= end ) { // Start date not after range
725 if ( rStart >= start ) { // Start date within range 727 if ( rStart >= start ) { // Start date within range
726 found = true; 728 found = true;
727 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 729 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
728 found = true; 730 found = true;
729 } else if ( event->recurrence()->duration() == 0 ) { // End date set 731 } else if ( event->recurrence()->duration() == 0 ) { // End date set
730 QDate rEnd = event->recurrence()->endDate(); 732 QDate rEnd = event->recurrence()->endDate();
731 if ( rEnd >= start && rEnd <= end ) { // End date within range 733 if ( rEnd >= start && rEnd <= end ) { // End date within range
732 found = true; 734 found = true;
733 } 735 }
734 } else { // Duration set 736 } else { // Duration set
735 // TODO: Calculate end date from duration. Should be done in Event 737 // TODO: Calculate end date from duration. Should be done in Event
736 // For now include all events with a duration. 738 // For now include all events with a duration.
737 found = true; 739 found = true;
738 } 740 }
739 } 741 }
740 */ 742 */
741 743
742 } 744 }
743 745
744 if ( found ) eventList.append( event ); 746 if ( found ) eventList.append( event );
745 } else { 747 } else {
746 QDate s = event->dtStart().date(); 748 QDate s = event->dtStart().date();
747 QDate e = event->dtEnd().date(); 749 QDate e = event->dtEnd().date();
748 750
749 if ( inclusive ) { 751 if ( inclusive ) {
750 if ( s >= start && e <= end ) { 752 if ( s >= start && e <= end ) {
751 eventList.append( event ); 753 eventList.append( event );
752 } 754 }
753 } else { 755 } else {
754 if ( ( e >= start && s <= end ) ) { 756 if ( ( e >= start && s <= end ) ) {
755 eventList.append( event ); 757 eventList.append( event );
756 } 758 }
757 } 759 }
758 } 760 }
759 } 761 }
760 762
761 return eventList; 763 return eventList;
762} 764}
763 765
764QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 766QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
765{ 767{
766 return rawEventsForDate( qdt.date() ); 768 return rawEventsForDate( qdt.date() );
767} 769}
768 770
769QPtrList<Event> CalendarLocal::rawEvents() 771QPtrList<Event> CalendarLocal::rawEvents()
770{ 772{
771 QPtrList<Event> el; 773 QPtrList<Event> el;
772 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 774 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
773 if ( it->calEnabled() ) el.append( it ); 775 if ( it->calEnabled() ) el.append( it );
774 return el; 776 return el;
775} 777}
776 778
777bool CalendarLocal::addJournal(Journal *journal) 779bool CalendarLocal::addJournal(Journal *journal)
778{ 780{
779 mJournalList.append(journal); 781 mJournalList.append(journal);
780 782
781 journal->registerObserver( this ); 783 journal->registerObserver( this );
782 784
783 setModified( true ); 785 setModified( true );
784 journal->setCalID( mDefaultCalendar ); 786 if ( journal->calID() == 0 )
787 journal->setCalID( mDefaultCalendar );
785 journal->setCalEnabled( true ); 788 journal->setCalEnabled( true );
786 return true; 789 return true;
787} 790}
788 791
789void CalendarLocal::deleteJournal( Journal *journal ) 792void CalendarLocal::deleteJournal( Journal *journal )
790{ 793{
791 if ( mUndoIncidence ) delete mUndoIncidence; 794 if ( mUndoIncidence ) delete mUndoIncidence;
792 mUndoIncidence = journal->clone(); 795 mUndoIncidence = journal->clone();
793 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 796 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
794 if ( mJournalList.removeRef(journal) ) { 797 if ( mJournalList.removeRef(journal) ) {
795 setModified( true ); 798 setModified( true );
796 } 799 }
797} 800}
798 801
799QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 802QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
800{ 803{
801 QPtrList<Journal> el; 804 QPtrList<Journal> el;
802 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 805 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
803 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 806 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
804 return el; 807 return el;
805} 808}
806Journal *CalendarLocal::journal( const QDate &date ) 809Journal *CalendarLocal::journal( const QDate &date )
807{ 810{
808// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 811// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
809 812
810 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 813 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
811 if ( it->calEnabled() && it->dtStart().date() == date ) 814 if ( it->calEnabled() && it->dtStart().date() == date )
812 return it; 815 return it;
813 816
814 return 0; 817 return 0;
815} 818}
816 819
817Journal *CalendarLocal::journal( const QString &uid ) 820Journal *CalendarLocal::journal( const QString &uid )
818{ 821{
819 Journal * retVal = 0; 822 Journal * retVal = 0;
820 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 823 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
821 if ( it->calEnabled() && it->uid() == uid ) { 824 if ( it->calEnabled() && it->uid() == uid ) {
822 if ( retVal ) { 825 if ( retVal ) {
823 if ( retVal->calID() > it->calID() ) { 826 if ( retVal->calID() > it->calID() ) {
824 retVal = it; 827 retVal = it;
825 } 828 }
826 } else { 829 } else {
827 retVal = it; 830 retVal = it;
828 } 831 }
829 } 832 }
830 return retVal; 833 return retVal;
831} 834}
832 835
833QPtrList<Journal> CalendarLocal::journals() 836QPtrList<Journal> CalendarLocal::journals()
834{ 837{
835 QPtrList<Journal> el; 838 QPtrList<Journal> el;
836 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 839 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
837 if ( it->calEnabled() ) el.append( it ); 840 if ( it->calEnabled() ) el.append( it );
838 return el; 841 return el;
839} 842}
840void CalendarLocal::setCalendarRemove( int id ) 843void CalendarLocal::setCalendarRemove( int id )
841{ 844{
842 845
843 { 846 {
844 QPtrList<Event> EventList = mEventList; 847 QPtrList<Event> EventList = mEventList;
845 Event * ev = EventList.first(); 848 Event * ev = EventList.first();
846 while ( ev ) { 849 while ( ev ) {
847 if ( ev->calID() == id ) 850 if ( ev->calID() == id )
848 deleteEvent( ev ); 851 deleteEvent( ev );