-rw-r--r-- | libkcal/calendarlocal.cpp | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index c5500bf..e48122a 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,262 +1,300 @@ | |||
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 |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | ||
70 | } | ||
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | ||
72 | { | ||
73 | CalendarLocal calendar( timeZoneId() ); | ||
74 | calendar.setDefaultCalendar( id ); | ||
75 | if ( calendar.load( name ) ) { | ||
76 | addCalendar( &calendar ); | ||
77 | return true; | ||
78 | } | ||
79 | return false; | ||
80 | } | ||
81 | void CalendarLocal::addCalendar( Calendar* cal ) | ||
82 | { | ||
83 | cal->setDontDeleteIncidencesOnClose(); | ||
84 | { | ||
85 | QPtrList<Event> EventList = cal->rawEvents(); | ||
86 | Event * ev = EventList.first(); | ||
87 | while ( ev ) { | ||
88 | mEventList.append( ev ); | ||
89 | ev = EventList.next(); | ||
90 | } | ||
91 | } | ||
92 | { | ||
93 | QPtrList<Todo> TodoList = cal->rawTodos(); | ||
94 | Todo * ev = TodoList.first(); | ||
95 | while ( ev ) { | ||
96 | mTodoList.append( ev ); | ||
97 | ev = TodoList.next(); | ||
98 | } | ||
99 | } | ||
100 | { | ||
101 | QPtrList<Journal> JournalList = cal->journals(); | ||
102 | Journal * ev = JournalList.first(); | ||
103 | while ( ev ) { | ||
104 | mJournalList.append( ev ); | ||
105 | ev = JournalList.next(); | ||
106 | } | ||
107 | } | ||
69 | } | 108 | } |
70 | |||
71 | bool CalendarLocal::load( const QString &fileName ) | 109 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 110 | { |
73 | FileStorage storage( this, fileName ); | 111 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 112 | return storage.load(); |
75 | } | 113 | } |
76 | 114 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 115 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 116 | { |
79 | FileStorage storage( this, fileName, format ); | 117 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 118 | return storage.save(); |
81 | } | 119 | } |
82 | 120 | ||
83 | void CalendarLocal::close() | 121 | void CalendarLocal::close() |
84 | { | 122 | { |
85 | 123 | ||
86 | Todo * i; | 124 | Todo * i; |
87 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 125 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
88 | 126 | ||
89 | mEventList.setAutoDelete( true ); | 127 | mEventList.setAutoDelete( true ); |
90 | mTodoList.setAutoDelete( true ); | 128 | mTodoList.setAutoDelete( true ); |
91 | mJournalList.setAutoDelete( false ); | 129 | mJournalList.setAutoDelete( false ); |
92 | 130 | ||
93 | mEventList.clear(); | 131 | mEventList.clear(); |
94 | mTodoList.clear(); | 132 | mTodoList.clear(); |
95 | mJournalList.clear(); | 133 | mJournalList.clear(); |
96 | 134 | ||
97 | mEventList.setAutoDelete( false ); | 135 | mEventList.setAutoDelete( false ); |
98 | mTodoList.setAutoDelete( false ); | 136 | mTodoList.setAutoDelete( false ); |
99 | mJournalList.setAutoDelete( false ); | 137 | mJournalList.setAutoDelete( false ); |
100 | 138 | ||
101 | setModified( false ); | 139 | setModified( false ); |
102 | } | 140 | } |
103 | 141 | ||
104 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 142 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
105 | { | 143 | { |
106 | QString cat; | 144 | QString cat; |
107 | bool isBirthday = true; | 145 | bool isBirthday = true; |
108 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 146 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
109 | isBirthday = false; | 147 | isBirthday = false; |
110 | cat = i18n( "Anniversary" ); | 148 | cat = i18n( "Anniversary" ); |
111 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 149 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
112 | isBirthday = true; | 150 | isBirthday = true; |
113 | cat = i18n( "Birthday" ); | 151 | cat = i18n( "Birthday" ); |
114 | } else { | 152 | } else { |
115 | qDebug("addAnniversaryNoDup called without fitting category! "); | 153 | qDebug("addAnniversaryNoDup called without fitting category! "); |
116 | return false; | 154 | return false; |
117 | } | 155 | } |
118 | Event * eve; | 156 | Event * eve; |
119 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 157 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
120 | if ( !(eve->categories().contains( cat ) )) | 158 | if ( !(eve->categories().contains( cat ) )) |
121 | continue; | 159 | continue; |
122 | // now we have an event with fitting category | 160 | // now we have an event with fitting category |
123 | if ( eve->dtStart().date() != event->dtStart().date() ) | 161 | if ( eve->dtStart().date() != event->dtStart().date() ) |
124 | continue; | 162 | continue; |
125 | // now we have an event with fitting category+date | 163 | // now we have an event with fitting category+date |
126 | if ( eve->summary() != event->summary() ) | 164 | if ( eve->summary() != event->summary() ) |
127 | continue; | 165 | continue; |
128 | // now we have an event with fitting category+date+summary | 166 | // now we have an event with fitting category+date+summary |
129 | return false; | 167 | return false; |
130 | } | 168 | } |
131 | return addEvent( event ); | 169 | return addEvent( event ); |
132 | 170 | ||
133 | } | 171 | } |
134 | bool CalendarLocal::addEventNoDup( Event *event ) | 172 | bool CalendarLocal::addEventNoDup( Event *event ) |
135 | { | 173 | { |
136 | Event * eve; | 174 | Event * eve; |
137 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 175 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
138 | if ( *eve == *event ) { | 176 | if ( *eve == *event ) { |
139 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 177 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
140 | return false; | 178 | return false; |
141 | } | 179 | } |
142 | } | 180 | } |
143 | return addEvent( event ); | 181 | return addEvent( event ); |
144 | } | 182 | } |
145 | 183 | ||
146 | bool CalendarLocal::addEvent( Event *event ) | 184 | bool CalendarLocal::addEvent( Event *event ) |
147 | { | 185 | { |
148 | insertEvent( event ); | 186 | insertEvent( event ); |
149 | 187 | ||
150 | event->registerObserver( this ); | 188 | event->registerObserver( this ); |
151 | 189 | ||
152 | setModified( true ); | 190 | setModified( true ); |
153 | event->setCalID( mDefaultCalendar ); | 191 | event->setCalID( mDefaultCalendar ); |
154 | event->setCalEnabled( true ); | 192 | event->setCalEnabled( true ); |
155 | 193 | ||
156 | return true; | 194 | return true; |
157 | } | 195 | } |
158 | 196 | ||
159 | void CalendarLocal::deleteEvent( Event *event ) | 197 | void CalendarLocal::deleteEvent( Event *event ) |
160 | { | 198 | { |
161 | if ( mUndoIncidence ) delete mUndoIncidence; | 199 | if ( mUndoIncidence ) delete mUndoIncidence; |
162 | mUndoIncidence = event->clone(); | 200 | mUndoIncidence = event->clone(); |
163 | if ( mEventList.removeRef( event ) ) { | 201 | if ( mEventList.removeRef( event ) ) { |
164 | setModified( true ); | 202 | setModified( true ); |
165 | } | 203 | } |
166 | } | 204 | } |
167 | 205 | ||
168 | 206 | ||
169 | Event *CalendarLocal::event( const QString &uid ) | 207 | Event *CalendarLocal::event( const QString &uid ) |
170 | { | 208 | { |
171 | 209 | ||
172 | Event *event; | 210 | Event *event; |
173 | 211 | ||
174 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 212 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
175 | if ( event->uid() == uid && event->calEnabled() ) { | 213 | if ( event->uid() == uid && event->calEnabled() ) { |
176 | return event; | 214 | return event; |
177 | } | 215 | } |
178 | } | 216 | } |
179 | 217 | ||
180 | return 0; | 218 | return 0; |
181 | } | 219 | } |
182 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 220 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
183 | { | 221 | { |
184 | Todo * eve; | 222 | Todo * eve; |
185 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 223 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
186 | if ( *eve == *todo ) { | 224 | if ( *eve == *todo ) { |
187 | //qDebug("duplicate todo found! not inserted! "); | 225 | //qDebug("duplicate todo found! not inserted! "); |
188 | return false; | 226 | return false; |
189 | } | 227 | } |
190 | } | 228 | } |
191 | return addTodo( todo ); | 229 | return addTodo( todo ); |
192 | } | 230 | } |
193 | bool CalendarLocal::addTodo( Todo *todo ) | 231 | bool CalendarLocal::addTodo( Todo *todo ) |
194 | { | 232 | { |
195 | mTodoList.append( todo ); | 233 | mTodoList.append( todo ); |
196 | 234 | ||
197 | todo->registerObserver( this ); | 235 | todo->registerObserver( this ); |
198 | 236 | ||
199 | // Set up subtask relations | 237 | // Set up subtask relations |
200 | setupRelations( todo ); | 238 | setupRelations( todo ); |
201 | 239 | ||
202 | setModified( true ); | 240 | setModified( true ); |
203 | todo->setCalID( mDefaultCalendar ); | 241 | todo->setCalID( mDefaultCalendar ); |
204 | todo->setCalEnabled( true ); | 242 | todo->setCalEnabled( true ); |
205 | return true; | 243 | return true; |
206 | } | 244 | } |
207 | 245 | ||
208 | void CalendarLocal::deleteTodo( Todo *todo ) | 246 | void CalendarLocal::deleteTodo( Todo *todo ) |
209 | { | 247 | { |
210 | // Handle orphaned children | 248 | // Handle orphaned children |
211 | if ( mUndoIncidence ) delete mUndoIncidence; | 249 | if ( mUndoIncidence ) delete mUndoIncidence; |
212 | removeRelations( todo ); | 250 | removeRelations( todo ); |
213 | mUndoIncidence = todo->clone(); | 251 | mUndoIncidence = todo->clone(); |
214 | 252 | ||
215 | if ( mTodoList.removeRef( todo ) ) { | 253 | if ( mTodoList.removeRef( todo ) ) { |
216 | setModified( true ); | 254 | setModified( true ); |
217 | } | 255 | } |
218 | } | 256 | } |
219 | 257 | ||
220 | QPtrList<Todo> CalendarLocal::rawTodos() | 258 | QPtrList<Todo> CalendarLocal::rawTodos() |
221 | { | 259 | { |
222 | QPtrList<Todo> el; | 260 | QPtrList<Todo> el; |
223 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 261 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
224 | if ( it->calEnabled() ) el.append( it ); | 262 | if ( it->calEnabled() ) el.append( it ); |
225 | return el; | 263 | return el; |
226 | } | 264 | } |
227 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 265 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
228 | { | 266 | { |
229 | Todo *todo; | 267 | Todo *todo; |
230 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 268 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
231 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 269 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
232 | } | 270 | } |
233 | 271 | ||
234 | return 0; | 272 | return 0; |
235 | } | 273 | } |
236 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 274 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
237 | { | 275 | { |
238 | QPtrList<Incidence> all = rawIncidences() ; | 276 | QPtrList<Incidence> all = rawIncidences() ; |
239 | Incidence *inc; | 277 | Incidence *inc; |
240 | for ( inc = all.first(); inc; inc = all.next() ) { | 278 | for ( inc = all.first(); inc; inc = all.next() ) { |
241 | inc->removeID( syncProfile ); | 279 | inc->removeID( syncProfile ); |
242 | } | 280 | } |
243 | if ( syncProfile.isEmpty() ) { | 281 | if ( syncProfile.isEmpty() ) { |
244 | QPtrList<Event> el; | 282 | QPtrList<Event> el; |
245 | Event *todo; | 283 | Event *todo; |
246 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 284 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
247 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 285 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
248 | el.append( todo ); | 286 | el.append( todo ); |
249 | } | 287 | } |
250 | for ( todo = el.first(); todo; todo = el.next() ) { | 288 | for ( todo = el.first(); todo; todo = el.next() ) { |
251 | deleteIncidence ( todo ); | 289 | deleteIncidence ( todo ); |
252 | } | 290 | } |
253 | } else { | 291 | } else { |
254 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 292 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
255 | if ( lse ) | 293 | if ( lse ) |
256 | deleteIncidence ( lse ); | 294 | deleteIncidence ( lse ); |
257 | } | 295 | } |
258 | } | 296 | } |
259 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 297 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
260 | { | 298 | { |
261 | QPtrList<Event> el; | 299 | QPtrList<Event> el; |
262 | Event *todo; | 300 | Event *todo; |
@@ -567,216 +605,230 @@ QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | |||
567 | } | 605 | } |
568 | } else { | 606 | } else { |
569 | if ( event->recursOn( qd ) ) | 607 | if ( event->recursOn( qd ) ) |
570 | eventList.append( event ); | 608 | eventList.append( event ); |
571 | } | 609 | } |
572 | } else { | 610 | } else { |
573 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 611 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
574 | eventList.append( event ); | 612 | eventList.append( event ); |
575 | } | 613 | } |
576 | } | 614 | } |
577 | } | 615 | } |
578 | 616 | ||
579 | if ( !sorted ) { | 617 | if ( !sorted ) { |
580 | return eventList; | 618 | return eventList; |
581 | } | 619 | } |
582 | 620 | ||
583 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 621 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
584 | // now, we have to sort it based on dtStart.time() | 622 | // now, we have to sort it based on dtStart.time() |
585 | QPtrList<Event> eventListSorted; | 623 | QPtrList<Event> eventListSorted; |
586 | Event *sortEvent; | 624 | Event *sortEvent; |
587 | for ( event = eventList.first(); event; event = eventList.next() ) { | 625 | for ( event = eventList.first(); event; event = eventList.next() ) { |
588 | sortEvent = eventListSorted.first(); | 626 | sortEvent = eventListSorted.first(); |
589 | int i = 0; | 627 | int i = 0; |
590 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 628 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
591 | { | 629 | { |
592 | i++; | 630 | i++; |
593 | sortEvent = eventListSorted.next(); | 631 | sortEvent = eventListSorted.next(); |
594 | } | 632 | } |
595 | eventListSorted.insert( i, event ); | 633 | eventListSorted.insert( i, event ); |
596 | } | 634 | } |
597 | return eventListSorted; | 635 | return eventListSorted; |
598 | } | 636 | } |
599 | 637 | ||
600 | 638 | ||
601 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 639 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
602 | bool inclusive ) | 640 | bool inclusive ) |
603 | { | 641 | { |
604 | Event *event = 0; | 642 | Event *event = 0; |
605 | 643 | ||
606 | QPtrList<Event> eventList; | 644 | QPtrList<Event> eventList; |
607 | 645 | ||
608 | // Get non-recurring events | 646 | // Get non-recurring events |
609 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 647 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
610 | if ( !event->calEnabled() ) continue; | 648 | if ( !event->calEnabled() ) continue; |
611 | if ( event->doesRecur() ) { | 649 | if ( event->doesRecur() ) { |
612 | QDate rStart = event->dtStart().date(); | 650 | QDate rStart = event->dtStart().date(); |
613 | bool found = false; | 651 | bool found = false; |
614 | if ( inclusive ) { | 652 | if ( inclusive ) { |
615 | if ( rStart >= start && rStart <= end ) { | 653 | if ( rStart >= start && rStart <= end ) { |
616 | // Start date of event is in range. Now check for end date. | 654 | // Start date of event is in range. Now check for end date. |
617 | // if duration is negative, event recurs forever, so do not include it. | 655 | // if duration is negative, event recurs forever, so do not include it. |
618 | if ( event->recurrence()->duration() == 0 ) { // End date set | 656 | if ( event->recurrence()->duration() == 0 ) { // End date set |
619 | QDate rEnd = event->recurrence()->endDate(); | 657 | QDate rEnd = event->recurrence()->endDate(); |
620 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 658 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
621 | found = true; | 659 | found = true; |
622 | } | 660 | } |
623 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 661 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
624 | // TODO: Calculate end date from duration. Should be done in Event | 662 | // TODO: Calculate end date from duration. Should be done in Event |
625 | // For now exclude all events with a duration. | 663 | // For now exclude all events with a duration. |
626 | } | 664 | } |
627 | } | 665 | } |
628 | } else { | 666 | } else { |
629 | bool founOne; | 667 | bool founOne; |
630 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 668 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
631 | if ( founOne ) { | 669 | if ( founOne ) { |
632 | if ( next <= end ) { | 670 | if ( next <= end ) { |
633 | found = true; | 671 | found = true; |
634 | } | 672 | } |
635 | } | 673 | } |
636 | 674 | ||
637 | /* | 675 | /* |
638 | // crap !!! | 676 | // crap !!! |
639 | if ( rStart <= end ) { // Start date not after range | 677 | if ( rStart <= end ) { // Start date not after range |
640 | if ( rStart >= start ) { // Start date within range | 678 | if ( rStart >= start ) { // Start date within range |
641 | found = true; | 679 | found = true; |
642 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 680 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
643 | found = true; | 681 | found = true; |
644 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 682 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
645 | QDate rEnd = event->recurrence()->endDate(); | 683 | QDate rEnd = event->recurrence()->endDate(); |
646 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 684 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
647 | found = true; | 685 | found = true; |
648 | } | 686 | } |
649 | } else { // Duration set | 687 | } else { // Duration set |
650 | // TODO: Calculate end date from duration. Should be done in Event | 688 | // TODO: Calculate end date from duration. Should be done in Event |
651 | // For now include all events with a duration. | 689 | // For now include all events with a duration. |
652 | found = true; | 690 | found = true; |
653 | } | 691 | } |
654 | } | 692 | } |
655 | */ | 693 | */ |
656 | 694 | ||
657 | } | 695 | } |
658 | 696 | ||
659 | if ( found ) eventList.append( event ); | 697 | if ( found ) eventList.append( event ); |
660 | } else { | 698 | } else { |
661 | QDate s = event->dtStart().date(); | 699 | QDate s = event->dtStart().date(); |
662 | QDate e = event->dtEnd().date(); | 700 | QDate e = event->dtEnd().date(); |
663 | 701 | ||
664 | if ( inclusive ) { | 702 | if ( inclusive ) { |
665 | if ( s >= start && e <= end ) { | 703 | if ( s >= start && e <= end ) { |
666 | eventList.append( event ); | 704 | eventList.append( event ); |
667 | } | 705 | } |
668 | } else { | 706 | } else { |
669 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 707 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
670 | eventList.append( event ); | 708 | eventList.append( event ); |
671 | } | 709 | } |
672 | } | 710 | } |
673 | } | 711 | } |
674 | } | 712 | } |
675 | 713 | ||
676 | return eventList; | 714 | return eventList; |
677 | } | 715 | } |
678 | 716 | ||
679 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 717 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
680 | { | 718 | { |
681 | return rawEventsForDate( qdt.date() ); | 719 | return rawEventsForDate( qdt.date() ); |
682 | } | 720 | } |
683 | 721 | ||
684 | QPtrList<Event> CalendarLocal::rawEvents() | 722 | QPtrList<Event> CalendarLocal::rawEvents() |
685 | { | 723 | { |
686 | QPtrList<Event> el; | 724 | QPtrList<Event> el; |
687 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 725 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
688 | if ( it->calEnabled() ) el.append( it ); | 726 | if ( it->calEnabled() ) el.append( it ); |
689 | return el; | 727 | return el; |
690 | } | 728 | } |
691 | 729 | ||
692 | bool CalendarLocal::addJournal(Journal *journal) | 730 | bool CalendarLocal::addJournal(Journal *journal) |
693 | { | 731 | { |
694 | if ( journal->dtStart().isValid()) | 732 | if ( journal->dtStart().isValid()) |
695 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 733 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
696 | else | 734 | else |
697 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 735 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
698 | 736 | ||
699 | mJournalList.append(journal); | 737 | mJournalList.append(journal); |
700 | 738 | ||
701 | journal->registerObserver( this ); | 739 | journal->registerObserver( this ); |
702 | 740 | ||
703 | setModified( true ); | 741 | setModified( true ); |
704 | journal->setCalID( mDefaultCalendar ); | 742 | journal->setCalID( mDefaultCalendar ); |
705 | journal->setCalEnabled( true ); | 743 | journal->setCalEnabled( true ); |
706 | return true; | 744 | return true; |
707 | } | 745 | } |
708 | 746 | ||
709 | void CalendarLocal::deleteJournal( Journal *journal ) | 747 | void CalendarLocal::deleteJournal( Journal *journal ) |
710 | { | 748 | { |
711 | if ( mUndoIncidence ) delete mUndoIncidence; | 749 | if ( mUndoIncidence ) delete mUndoIncidence; |
712 | mUndoIncidence = journal->clone(); | 750 | mUndoIncidence = journal->clone(); |
713 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 751 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
714 | if ( mJournalList.removeRef(journal) ) { | 752 | if ( mJournalList.removeRef(journal) ) { |
715 | setModified( true ); | 753 | setModified( true ); |
716 | } | 754 | } |
717 | } | 755 | } |
718 | 756 | ||
719 | Journal *CalendarLocal::journal( const QDate &date ) | 757 | Journal *CalendarLocal::journal( const QDate &date ) |
720 | { | 758 | { |
721 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 759 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
722 | 760 | ||
723 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
724 | if ( it->calEnabled() && it->dtStart().date() == date ) | 762 | if ( it->calEnabled() && it->dtStart().date() == date ) |
725 | return it; | 763 | return it; |
726 | 764 | ||
727 | return 0; | 765 | return 0; |
728 | } | 766 | } |
729 | 767 | ||
730 | Journal *CalendarLocal::journal( const QString &uid ) | 768 | Journal *CalendarLocal::journal( const QString &uid ) |
731 | { | 769 | { |
732 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 770 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
733 | if ( it->calEnabled() && it->uid() == uid ) | 771 | if ( it->calEnabled() && it->uid() == uid ) |
734 | return it; | 772 | return it; |
735 | 773 | ||
736 | return 0; | 774 | return 0; |
737 | } | 775 | } |
738 | 776 | ||
739 | QPtrList<Journal> CalendarLocal::journals() | 777 | QPtrList<Journal> CalendarLocal::journals() |
740 | { | 778 | { |
741 | QPtrList<Journal> el; | 779 | QPtrList<Journal> el; |
742 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 780 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
743 | if ( it->calEnabled() ) el.append( it ); | 781 | if ( it->calEnabled() ) el.append( it ); |
744 | return el; | 782 | return el; |
745 | } | 783 | } |
746 | 784 | ||
747 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 785 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
748 | { | 786 | { |
749 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 787 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
750 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 788 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
751 | 789 | ||
752 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 790 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
753 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 791 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
754 | 792 | ||
755 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 793 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
756 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 794 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
757 | 795 | ||
758 | } | 796 | } |
797 | |||
798 | void CalendarLocal::setReadOnly( int id, bool enable ) | ||
799 | { | ||
800 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
801 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
802 | |||
803 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
804 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
805 | |||
806 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
807 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
808 | |||
809 | } | ||
810 | |||
759 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 811 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
760 | { | 812 | { |
761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 813 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
762 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 814 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
763 | 815 | ||
764 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 816 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
765 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 817 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
766 | 818 | ||
767 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 819 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
768 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 820 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
769 | 821 | ||
770 | } | 822 | } |
771 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 823 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
772 | { | 824 | { |
773 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 825 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
774 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 826 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
775 | 827 | ||
776 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 828 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
777 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 829 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
778 | 830 | ||
779 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 831 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
780 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 832 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
781 | 833 | ||
782 | } | 834 | } |