summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e48122a..749d9f6 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,299 +1,318 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 if ( mDeleteIncidencesOnClose ) 68 if ( mDeleteIncidencesOnClose )
69 close(); 69 close();
70} 70}
71bool CalendarLocal::addCalendarFile( QString name, int id ) 71bool CalendarLocal::addCalendarFile( QString name, int id )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( id ); 74 calendar.setDefaultCalendar( id );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 addCalendar( &calendar ); 76 addCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81void CalendarLocal::addCalendar( Calendar* cal ) 81void CalendarLocal::addCalendar( Calendar* cal )
82{ 82{
83 cal->setDontDeleteIncidencesOnClose(); 83 cal->setDontDeleteIncidencesOnClose();
84 { 84 {
85 QPtrList<Event> EventList = cal->rawEvents(); 85 QPtrList<Event> EventList = cal->rawEvents();
86 Event * ev = EventList.first(); 86 Event * ev = EventList.first();
87 while ( ev ) { 87 while ( ev ) {
88 ev->unRegisterObserver( cal );
89 ev->registerObserver( this );
88 mEventList.append( ev ); 90 mEventList.append( ev );
89 ev = EventList.next(); 91 ev = EventList.next();
90 } 92 }
91 } 93 }
92 { 94 {
95
93 QPtrList<Todo> TodoList = cal->rawTodos(); 96 QPtrList<Todo> TodoList = cal->rawTodos();
94 Todo * ev = TodoList.first(); 97 Todo * ev = TodoList.first();
95 while ( ev ) { 98 while ( ev ) {
99 QString rel = ev->relatedToUid();
100 if ( !rel.isEmpty() ){
101 ev->setRelatedTo ( 0 );
102 ev->setRelatedToUid( rel );
103 }
104 ev = TodoList.next();
105 }
106 //TodoList = cal->rawTodos();
107 ev = TodoList.first();
108 while ( ev ) {
109 ev->unRegisterObserver( cal );
110 ev->registerObserver( this );
96 mTodoList.append( ev ); 111 mTodoList.append( ev );
112 setupRelations( ev );
97 ev = TodoList.next(); 113 ev = TodoList.next();
98 } 114 }
99 } 115 }
100 { 116 {
101 QPtrList<Journal> JournalList = cal->journals(); 117 QPtrList<Journal> JournalList = cal->journals();
102 Journal * ev = JournalList.first(); 118 Journal * ev = JournalList.first();
103 while ( ev ) { 119 while ( ev ) {
120 ev->unRegisterObserver( cal );
121 ev->registerObserver( this );
104 mJournalList.append( ev ); 122 mJournalList.append( ev );
105 ev = JournalList.next(); 123 ev = JournalList.next();
106 } 124 }
107 } 125 }
126 setModified( true );
108} 127}
109bool CalendarLocal::load( const QString &fileName ) 128bool CalendarLocal::load( const QString &fileName )
110{ 129{
111 FileStorage storage( this, fileName ); 130 FileStorage storage( this, fileName );
112 return storage.load(); 131 return storage.load();
113} 132}
114 133
115bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 134bool CalendarLocal::save( const QString &fileName, CalFormat *format )
116{ 135{
117 FileStorage storage( this, fileName, format ); 136 FileStorage storage( this, fileName, format );
118 return storage.save(); 137 return storage.save();
119} 138}
120 139
121void CalendarLocal::close() 140void CalendarLocal::close()
122{ 141{
123 142
124 Todo * i; 143 Todo * i;
125 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 144 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
126 145
127 mEventList.setAutoDelete( true ); 146 mEventList.setAutoDelete( true );
128 mTodoList.setAutoDelete( true ); 147 mTodoList.setAutoDelete( true );
129 mJournalList.setAutoDelete( false ); 148 mJournalList.setAutoDelete( false );
130 149
131 mEventList.clear(); 150 mEventList.clear();
132 mTodoList.clear(); 151 mTodoList.clear();
133 mJournalList.clear(); 152 mJournalList.clear();
134 153
135 mEventList.setAutoDelete( false ); 154 mEventList.setAutoDelete( false );
136 mTodoList.setAutoDelete( false ); 155 mTodoList.setAutoDelete( false );
137 mJournalList.setAutoDelete( false ); 156 mJournalList.setAutoDelete( false );
138 157
139 setModified( false ); 158 setModified( false );
140} 159}
141 160
142bool CalendarLocal::addAnniversaryNoDup( Event *event ) 161bool CalendarLocal::addAnniversaryNoDup( Event *event )
143{ 162{
144 QString cat; 163 QString cat;
145 bool isBirthday = true; 164 bool isBirthday = true;
146 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 165 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
147 isBirthday = false; 166 isBirthday = false;
148 cat = i18n( "Anniversary" ); 167 cat = i18n( "Anniversary" );
149 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 168 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
150 isBirthday = true; 169 isBirthday = true;
151 cat = i18n( "Birthday" ); 170 cat = i18n( "Birthday" );
152 } else { 171 } else {
153 qDebug("addAnniversaryNoDup called without fitting category! "); 172 qDebug("addAnniversaryNoDup called without fitting category! ");
154 return false; 173 return false;
155 } 174 }
156 Event * eve; 175 Event * eve;
157 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 176 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
158 if ( !(eve->categories().contains( cat ) )) 177 if ( !(eve->categories().contains( cat ) ))
159 continue; 178 continue;
160 // now we have an event with fitting category 179 // now we have an event with fitting category
161 if ( eve->dtStart().date() != event->dtStart().date() ) 180 if ( eve->dtStart().date() != event->dtStart().date() )
162 continue; 181 continue;
163 // now we have an event with fitting category+date 182 // now we have an event with fitting category+date
164 if ( eve->summary() != event->summary() ) 183 if ( eve->summary() != event->summary() )
165 continue; 184 continue;
166 // now we have an event with fitting category+date+summary 185 // now we have an event with fitting category+date+summary
167 return false; 186 return false;
168 } 187 }
169 return addEvent( event ); 188 return addEvent( event );
170 189
171} 190}
172bool CalendarLocal::addEventNoDup( Event *event ) 191bool CalendarLocal::addEventNoDup( Event *event )
173{ 192{
174 Event * eve; 193 Event * eve;
175 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 194 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
176 if ( *eve == *event ) { 195 if ( *eve == *event ) {
177 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 196 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
178 return false; 197 return false;
179 } 198 }
180 } 199 }
181 return addEvent( event ); 200 return addEvent( event );
182} 201}
183 202
184bool CalendarLocal::addEvent( Event *event ) 203bool CalendarLocal::addEvent( Event *event )
185{ 204{
186 insertEvent( event ); 205 insertEvent( event );
187 206
188 event->registerObserver( this ); 207 event->registerObserver( this );
189 208
190 setModified( true ); 209 setModified( true );
191 event->setCalID( mDefaultCalendar ); 210 event->setCalID( mDefaultCalendar );
192 event->setCalEnabled( true ); 211 event->setCalEnabled( true );
193 212
194 return true; 213 return true;
195} 214}
196 215
197void CalendarLocal::deleteEvent( Event *event ) 216void CalendarLocal::deleteEvent( Event *event )
198{ 217{
199 if ( mUndoIncidence ) delete mUndoIncidence; 218 if ( mUndoIncidence ) delete mUndoIncidence;
200 mUndoIncidence = event->clone(); 219 mUndoIncidence = event->clone();
201 if ( mEventList.removeRef( event ) ) { 220 if ( mEventList.removeRef( event ) ) {
202 setModified( true ); 221 setModified( true );
203 } 222 }
204} 223}
205 224
206 225
207Event *CalendarLocal::event( const QString &uid ) 226Event *CalendarLocal::event( const QString &uid )
208{ 227{
209 228
210 Event *event; 229 Event *event;
211 230
212 for ( event = mEventList.first(); event; event = mEventList.next() ) { 231 for ( event = mEventList.first(); event; event = mEventList.next() ) {
213 if ( event->uid() == uid && event->calEnabled() ) { 232 if ( event->uid() == uid && event->calEnabled() ) {
214 return event; 233 return event;
215 } 234 }
216 } 235 }
217 236
218 return 0; 237 return 0;
219} 238}
220bool CalendarLocal::addTodoNoDup( Todo *todo ) 239bool CalendarLocal::addTodoNoDup( Todo *todo )
221{ 240{
222 Todo * eve; 241 Todo * eve;
223 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 242 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
224 if ( *eve == *todo ) { 243 if ( *eve == *todo ) {
225 //qDebug("duplicate todo found! not inserted! "); 244 //qDebug("duplicate todo found! not inserted! ");
226 return false; 245 return false;
227 } 246 }
228 } 247 }
229 return addTodo( todo ); 248 return addTodo( todo );
230} 249}
231bool CalendarLocal::addTodo( Todo *todo ) 250bool CalendarLocal::addTodo( Todo *todo )
232{ 251{
233 mTodoList.append( todo ); 252 mTodoList.append( todo );
234 253
235 todo->registerObserver( this ); 254 todo->registerObserver( this );
236 255
237 // Set up subtask relations 256 // Set up subtask relations
238 setupRelations( todo ); 257 setupRelations( todo );
239 258
240 setModified( true ); 259 setModified( true );
241 todo->setCalID( mDefaultCalendar ); 260 todo->setCalID( mDefaultCalendar );
242 todo->setCalEnabled( true ); 261 todo->setCalEnabled( true );
243 return true; 262 return true;
244} 263}
245 264
246void CalendarLocal::deleteTodo( Todo *todo ) 265void CalendarLocal::deleteTodo( Todo *todo )
247{ 266{
248 // Handle orphaned children 267 // Handle orphaned children
249 if ( mUndoIncidence ) delete mUndoIncidence; 268 if ( mUndoIncidence ) delete mUndoIncidence;
250 removeRelations( todo ); 269 removeRelations( todo );
251 mUndoIncidence = todo->clone(); 270 mUndoIncidence = todo->clone();
252 271
253 if ( mTodoList.removeRef( todo ) ) { 272 if ( mTodoList.removeRef( todo ) ) {
254 setModified( true ); 273 setModified( true );
255 } 274 }
256} 275}
257 276
258QPtrList<Todo> CalendarLocal::rawTodos() 277QPtrList<Todo> CalendarLocal::rawTodos()
259{ 278{
260 QPtrList<Todo> el; 279 QPtrList<Todo> el;
261 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 280 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
262 if ( it->calEnabled() ) el.append( it ); 281 if ( it->calEnabled() ) el.append( it );
263 return el; 282 return el;
264} 283}
265Todo *CalendarLocal::todo( QString syncProf, QString id ) 284Todo *CalendarLocal::todo( QString syncProf, QString id )
266{ 285{
267 Todo *todo; 286 Todo *todo;
268 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 287 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
269 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 288 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
270 } 289 }
271 290
272 return 0; 291 return 0;
273} 292}
274void CalendarLocal::removeSyncInfo( QString syncProfile) 293void CalendarLocal::removeSyncInfo( QString syncProfile)
275{ 294{
276 QPtrList<Incidence> all = rawIncidences() ; 295 QPtrList<Incidence> all = rawIncidences() ;
277 Incidence *inc; 296 Incidence *inc;
278 for ( inc = all.first(); inc; inc = all.next() ) { 297 for ( inc = all.first(); inc; inc = all.next() ) {
279 inc->removeID( syncProfile ); 298 inc->removeID( syncProfile );
280 } 299 }
281 if ( syncProfile.isEmpty() ) { 300 if ( syncProfile.isEmpty() ) {
282 QPtrList<Event> el; 301 QPtrList<Event> el;
283 Event *todo; 302 Event *todo;
284 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 303 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
285 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 304 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
286 el.append( todo ); 305 el.append( todo );
287 } 306 }
288 for ( todo = el.first(); todo; todo = el.next() ) { 307 for ( todo = el.first(); todo; todo = el.next() ) {
289 deleteIncidence ( todo ); 308 deleteIncidence ( todo );
290 } 309 }
291 } else { 310 } else {
292 Event *lse = event( "last-syncEvent-"+ syncProfile); 311 Event *lse = event( "last-syncEvent-"+ syncProfile);
293 if ( lse ) 312 if ( lse )
294 deleteIncidence ( lse ); 313 deleteIncidence ( lse );
295 } 314 }
296} 315}
297QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 316QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
298{ 317{
299 QPtrList<Event> el; 318 QPtrList<Event> el;
@@ -592,243 +611,280 @@ QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
592 611
593 Event *event; 612 Event *event;
594 for( event = mEventList.first(); event; event = mEventList.next() ) { 613 for( event = mEventList.first(); event; event = mEventList.next() ) {
595 if ( !event->calEnabled() ) continue; 614 if ( !event->calEnabled() ) continue;
596 if ( event->doesRecur() ) { 615 if ( event->doesRecur() ) {
597 if ( event->isMultiDay() ) { 616 if ( event->isMultiDay() ) {
598 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 617 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
599 int i; 618 int i;
600 for ( i = 0; i <= extraDays; i++ ) { 619 for ( i = 0; i <= extraDays; i++ ) {
601 if ( event->recursOn( qd.addDays( -i ) ) ) { 620 if ( event->recursOn( qd.addDays( -i ) ) ) {
602 eventList.append( event ); 621 eventList.append( event );
603 break; 622 break;
604 } 623 }
605 } 624 }
606 } else { 625 } else {
607 if ( event->recursOn( qd ) ) 626 if ( event->recursOn( qd ) )
608 eventList.append( event ); 627 eventList.append( event );
609 } 628 }
610 } else { 629 } else {
611 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 630 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
612 eventList.append( event ); 631 eventList.append( event );
613 } 632 }
614 } 633 }
615 } 634 }
616 635
617 if ( !sorted ) { 636 if ( !sorted ) {
618 return eventList; 637 return eventList;
619 } 638 }
620 639
621 // kdDebug(5800) << "Sorting events for date\n" << endl; 640 // kdDebug(5800) << "Sorting events for date\n" << endl;
622 // now, we have to sort it based on dtStart.time() 641 // now, we have to sort it based on dtStart.time()
623 QPtrList<Event> eventListSorted; 642 QPtrList<Event> eventListSorted;
624 Event *sortEvent; 643 Event *sortEvent;
625 for ( event = eventList.first(); event; event = eventList.next() ) { 644 for ( event = eventList.first(); event; event = eventList.next() ) {
626 sortEvent = eventListSorted.first(); 645 sortEvent = eventListSorted.first();
627 int i = 0; 646 int i = 0;
628 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 647 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
629 { 648 {
630 i++; 649 i++;
631 sortEvent = eventListSorted.next(); 650 sortEvent = eventListSorted.next();
632 } 651 }
633 eventListSorted.insert( i, event ); 652 eventListSorted.insert( i, event );
634 } 653 }
635 return eventListSorted; 654 return eventListSorted;
636} 655}
637 656
638 657
639QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 658QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
640 bool inclusive ) 659 bool inclusive )
641{ 660{
642 Event *event = 0; 661 Event *event = 0;
643 662
644 QPtrList<Event> eventList; 663 QPtrList<Event> eventList;
645 664
646 // Get non-recurring events 665 // Get non-recurring events
647 for( event = mEventList.first(); event; event = mEventList.next() ) { 666 for( event = mEventList.first(); event; event = mEventList.next() ) {
648 if ( !event->calEnabled() ) continue; 667 if ( !event->calEnabled() ) continue;
649 if ( event->doesRecur() ) { 668 if ( event->doesRecur() ) {
650 QDate rStart = event->dtStart().date(); 669 QDate rStart = event->dtStart().date();
651 bool found = false; 670 bool found = false;
652 if ( inclusive ) { 671 if ( inclusive ) {
653 if ( rStart >= start && rStart <= end ) { 672 if ( rStart >= start && rStart <= end ) {
654 // Start date of event is in range. Now check for end date. 673 // Start date of event is in range. Now check for end date.
655 // if duration is negative, event recurs forever, so do not include it. 674 // if duration is negative, event recurs forever, so do not include it.
656 if ( event->recurrence()->duration() == 0 ) { // End date set 675 if ( event->recurrence()->duration() == 0 ) { // End date set
657 QDate rEnd = event->recurrence()->endDate(); 676 QDate rEnd = event->recurrence()->endDate();
658 if ( rEnd >= start && rEnd <= end ) { // End date within range 677 if ( rEnd >= start && rEnd <= end ) { // End date within range
659 found = true; 678 found = true;
660 } 679 }
661 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 680 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
662 // TODO: Calculate end date from duration. Should be done in Event 681 // TODO: Calculate end date from duration. Should be done in Event
663 // For now exclude all events with a duration. 682 // For now exclude all events with a duration.
664 } 683 }
665 } 684 }
666 } else { 685 } else {
667 bool founOne; 686 bool founOne;
668 QDate next = event->getNextOccurence( start, &founOne ).date(); 687 QDate next = event->getNextOccurence( start, &founOne ).date();
669 if ( founOne ) { 688 if ( founOne ) {
670 if ( next <= end ) { 689 if ( next <= end ) {
671 found = true; 690 found = true;
672 } 691 }
673 } 692 }
674 693
675 /* 694 /*
676 // crap !!! 695 // crap !!!
677 if ( rStart <= end ) { // Start date not after range 696 if ( rStart <= end ) { // Start date not after range
678 if ( rStart >= start ) { // Start date within range 697 if ( rStart >= start ) { // Start date within range
679 found = true; 698 found = true;
680 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 699 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
681 found = true; 700 found = true;
682 } else if ( event->recurrence()->duration() == 0 ) { // End date set 701 } else if ( event->recurrence()->duration() == 0 ) { // End date set
683 QDate rEnd = event->recurrence()->endDate(); 702 QDate rEnd = event->recurrence()->endDate();
684 if ( rEnd >= start && rEnd <= end ) { // End date within range 703 if ( rEnd >= start && rEnd <= end ) { // End date within range
685 found = true; 704 found = true;
686 } 705 }
687 } else { // Duration set 706 } else { // Duration set
688 // TODO: Calculate end date from duration. Should be done in Event 707 // TODO: Calculate end date from duration. Should be done in Event
689 // For now include all events with a duration. 708 // For now include all events with a duration.
690 found = true; 709 found = true;
691 } 710 }
692 } 711 }
693 */ 712 */
694 713
695 } 714 }
696 715
697 if ( found ) eventList.append( event ); 716 if ( found ) eventList.append( event );
698 } else { 717 } else {
699 QDate s = event->dtStart().date(); 718 QDate s = event->dtStart().date();
700 QDate e = event->dtEnd().date(); 719 QDate e = event->dtEnd().date();
701 720
702 if ( inclusive ) { 721 if ( inclusive ) {
703 if ( s >= start && e <= end ) { 722 if ( s >= start && e <= end ) {
704 eventList.append( event ); 723 eventList.append( event );
705 } 724 }
706 } else { 725 } else {
707 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 726 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
708 eventList.append( event ); 727 eventList.append( event );
709 } 728 }
710 } 729 }
711 } 730 }
712 } 731 }
713 732
714 return eventList; 733 return eventList;
715} 734}
716 735
717QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 736QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
718{ 737{
719 return rawEventsForDate( qdt.date() ); 738 return rawEventsForDate( qdt.date() );
720} 739}
721 740
722QPtrList<Event> CalendarLocal::rawEvents() 741QPtrList<Event> CalendarLocal::rawEvents()
723{ 742{
724 QPtrList<Event> el; 743 QPtrList<Event> el;
725 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 744 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
726 if ( it->calEnabled() ) el.append( it ); 745 if ( it->calEnabled() ) el.append( it );
727 return el; 746 return el;
728} 747}
729 748
730bool CalendarLocal::addJournal(Journal *journal) 749bool CalendarLocal::addJournal(Journal *journal)
731{ 750{
732 if ( journal->dtStart().isValid()) 751 if ( journal->dtStart().isValid())
733 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 752 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
734 else 753 else
735 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 754 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
736 755
737 mJournalList.append(journal); 756 mJournalList.append(journal);
738 757
739 journal->registerObserver( this ); 758 journal->registerObserver( this );
740 759
741 setModified( true ); 760 setModified( true );
742 journal->setCalID( mDefaultCalendar ); 761 journal->setCalID( mDefaultCalendar );
743 journal->setCalEnabled( true ); 762 journal->setCalEnabled( true );
744 return true; 763 return true;
745} 764}
746 765
747void CalendarLocal::deleteJournal( Journal *journal ) 766void CalendarLocal::deleteJournal( Journal *journal )
748{ 767{
749 if ( mUndoIncidence ) delete mUndoIncidence; 768 if ( mUndoIncidence ) delete mUndoIncidence;
750 mUndoIncidence = journal->clone(); 769 mUndoIncidence = journal->clone();
751 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 770 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
752 if ( mJournalList.removeRef(journal) ) { 771 if ( mJournalList.removeRef(journal) ) {
753 setModified( true ); 772 setModified( true );
754 } 773 }
755} 774}
756 775
757Journal *CalendarLocal::journal( const QDate &date ) 776Journal *CalendarLocal::journal( const QDate &date )
758{ 777{
759// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 778// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
760 779
761 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 780 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
762 if ( it->calEnabled() && it->dtStart().date() == date ) 781 if ( it->calEnabled() && it->dtStart().date() == date )
763 return it; 782 return it;
764 783
765 return 0; 784 return 0;
766} 785}
767 786
768Journal *CalendarLocal::journal( const QString &uid ) 787Journal *CalendarLocal::journal( const QString &uid )
769{ 788{
770 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 789 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
771 if ( it->calEnabled() && it->uid() == uid ) 790 if ( it->calEnabled() && it->uid() == uid )
772 return it; 791 return it;
773 792
774 return 0; 793 return 0;
775} 794}
776 795
777QPtrList<Journal> CalendarLocal::journals() 796QPtrList<Journal> CalendarLocal::journals()
778{ 797{
779 QPtrList<Journal> el; 798 QPtrList<Journal> el;
780 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 799 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
781 if ( it->calEnabled() ) el.append( it ); 800 if ( it->calEnabled() ) el.append( it );
782 return el; 801 return el;
783} 802}
803void CalendarLocal::setCalendarRemove( int id )
804{
805
806 {
807 QPtrList<Event> EventList = mEventList;
808 Event * ev = EventList.first();
809 while ( ev ) {
810 if ( ev->calID() == id )
811 deleteEvent( ev );
812 ev = EventList.next();
813 }
814 }
815 {
816
817 QPtrList<Todo> TodoList = mTodoList;
818 Todo * ev = TodoList.first();
819 while ( ev ) {
820 if ( ev->calID() == id )
821 deleteTodo( ev );
822 ev = TodoList.next();
823 }
824 }
825 {
826 QPtrList<Journal> JournalList = mJournalList;
827 Journal * ev = JournalList.first();
828 while ( ev ) {
829 if ( ev->calID() == id )
830 deleteJournal( ev );
831 ev = JournalList.next();
832 }
833 }
834
835 if ( mUndoIncidence ) delete mUndoIncidence;
836 mUndoIncidence = 0;
837
838}
784 839
785void CalendarLocal::setCalendarEnabled( int id, bool enable ) 840void CalendarLocal::setCalendarEnabled( int id, bool enable )
786{ 841{
787 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 842 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
788 if ( it->calID() == id ) it->setCalEnabled( enable ); 843 if ( it->calID() == id ) it->setCalEnabled( enable );
789 844
790 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 845 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
791 if ( it->calID() == id ) it->setCalEnabled( enable ); 846 if ( it->calID() == id ) it->setCalEnabled( enable );
792 847
793 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 848 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
794 if ( it->calID() == id ) it->setCalEnabled( enable ); 849 if ( it->calID() == id ) it->setCalEnabled( enable );
795 850
796} 851}
797 852
798void CalendarLocal::setReadOnly( int id, bool enable ) 853void CalendarLocal::setReadOnly( int id, bool enable )
799{ 854{
800 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 855 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
801 if ( it->calID() == id ) it->setReadOnly( enable ); 856 if ( it->calID() == id ) it->setReadOnly( enable );
802 857
803 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 858 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
804 if ( it->calID() == id ) it->setReadOnly( enable ); 859 if ( it->calID() == id ) it->setReadOnly( enable );
805 860
806 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 861 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
807 if ( it->calID() == id ) it->setReadOnly( enable ); 862 if ( it->calID() == id ) it->setReadOnly( enable );
808 863
809} 864}
810 865
811void CalendarLocal::setAlarmEnabled( int id, bool enable ) 866void CalendarLocal::setAlarmEnabled( int id, bool enable )
812{ 867{
813 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 868 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
814 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 869 if ( it->calID() == id ) it->setAlarmEnabled( enable );
815 870
816 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 871 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
817 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 872 if ( it->calID() == id ) it->setAlarmEnabled( enable );
818 873
819 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 874 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
820 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 875 if ( it->calID() == id ) it->setAlarmEnabled( enable );
876 reInitAlarmSettings();
821 877
822} 878}
823void CalendarLocal::setDefaultCalendarEnabledOnly() 879void CalendarLocal::setDefaultCalendarEnabledOnly()
824{ 880{
825 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 881 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
826 it->setCalEnabled( it->calID() == mDefaultCalendar ); 882 it->setCalEnabled( it->calID() == mDefaultCalendar );
827 883
828 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 884 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
829 it->setCalEnabled( it->calID() == mDefaultCalendar); 885 it->setCalEnabled( it->calID() == mDefaultCalendar);
830 886
831 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 887 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
832 it->setCalEnabled( it->calID() == mDefaultCalendar); 888 it->setCalEnabled( it->calID() == mDefaultCalendar);
833 889
834} 890}