author | zautrix <zautrix> | 2005-06-14 08:23:19 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-14 08:23:19 (UTC) |
commit | 1dccb9dd9ea32989ecec33c72a3ebd873dce048e (patch) (unidiff) | |
tree | 6b7dd7e4696c91a3afaba89225dd4f31f376a30b /libkcal | |
parent | b3743f5abe0a95c9ffeadf6701c9943f604febd6 (diff) | |
download | kdepimpi-1dccb9dd9ea32989ecec33c72a3ebd873dce048e.zip kdepimpi-1dccb9dd9ea32989ecec33c72a3ebd873dce048e.tar.gz kdepimpi-1dccb9dd9ea32989ecec33c72a3ebd873dce048e.tar.bz2 |
faster filter
-rw-r--r-- | libkcal/calendarlocal.cpp | 55 | ||||
-rw-r--r-- | libkcal/calfilter.cpp | 12 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 5 | ||||
-rw-r--r-- | libkcal/incidence.h | 1 |
4 files changed, 49 insertions, 24 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 749d9f6..336c3e8 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,890 +1,909 @@ | |||
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 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 71 | bool 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 | } |
81 | void CalendarLocal::addCalendar( Calendar* cal ) | 81 | void 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 ); | 88 | ev->unRegisterObserver( cal ); |
89 | ev->registerObserver( this ); | 89 | ev->registerObserver( this ); |
90 | mEventList.append( ev ); | 90 | mEventList.append( ev ); |
91 | ev = EventList.next(); | 91 | ev = EventList.next(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | { | 94 | { |
95 | 95 | ||
96 | QPtrList<Todo> TodoList = cal->rawTodos(); | 96 | QPtrList<Todo> TodoList = cal->rawTodos(); |
97 | Todo * ev = TodoList.first(); | 97 | Todo * ev = TodoList.first(); |
98 | while ( ev ) { | 98 | while ( ev ) { |
99 | QString rel = ev->relatedToUid(); | 99 | QString rel = ev->relatedToUid(); |
100 | if ( !rel.isEmpty() ){ | 100 | if ( !rel.isEmpty() ){ |
101 | ev->setRelatedTo ( 0 ); | 101 | ev->setRelatedTo ( 0 ); |
102 | ev->setRelatedToUid( rel ); | 102 | ev->setRelatedToUid( rel ); |
103 | } | 103 | } |
104 | ev = TodoList.next(); | 104 | ev = TodoList.next(); |
105 | } | 105 | } |
106 | //TodoList = cal->rawTodos(); | 106 | //TodoList = cal->rawTodos(); |
107 | ev = TodoList.first(); | 107 | ev = TodoList.first(); |
108 | while ( ev ) { | 108 | while ( ev ) { |
109 | ev->unRegisterObserver( cal ); | 109 | ev->unRegisterObserver( cal ); |
110 | ev->registerObserver( this ); | 110 | ev->registerObserver( this ); |
111 | mTodoList.append( ev ); | 111 | mTodoList.append( ev ); |
112 | setupRelations( ev ); | 112 | setupRelations( ev ); |
113 | ev = TodoList.next(); | 113 | ev = TodoList.next(); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | { | 116 | { |
117 | QPtrList<Journal> JournalList = cal->journals(); | 117 | QPtrList<Journal> JournalList = cal->journals(); |
118 | Journal * ev = JournalList.first(); | 118 | Journal * ev = JournalList.first(); |
119 | while ( ev ) { | 119 | while ( ev ) { |
120 | ev->unRegisterObserver( cal ); | 120 | ev->unRegisterObserver( cal ); |
121 | ev->registerObserver( this ); | 121 | ev->registerObserver( this ); |
122 | mJournalList.append( ev ); | 122 | mJournalList.append( ev ); |
123 | ev = JournalList.next(); | 123 | ev = JournalList.next(); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | setModified( true ); | 126 | setModified( true ); |
127 | } | 127 | } |
128 | bool CalendarLocal::load( const QString &fileName ) | 128 | bool CalendarLocal::load( const QString &fileName ) |
129 | { | 129 | { |
130 | FileStorage storage( this, fileName ); | 130 | FileStorage storage( this, fileName ); |
131 | return storage.load(); | 131 | return storage.load(); |
132 | } | 132 | } |
133 | 133 | ||
134 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 134 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
135 | { | 135 | { |
136 | FileStorage storage( this, fileName, format ); | 136 | FileStorage storage( this, fileName, format ); |
137 | return storage.save(); | 137 | return storage.save(); |
138 | } | 138 | } |
139 | 139 | ||
140 | void CalendarLocal::close() | 140 | void CalendarLocal::close() |
141 | { | 141 | { |
142 | 142 | ||
143 | Todo * i; | 143 | Todo * i; |
144 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 144 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
145 | 145 | ||
146 | mEventList.setAutoDelete( true ); | 146 | mEventList.setAutoDelete( true ); |
147 | mTodoList.setAutoDelete( true ); | 147 | mTodoList.setAutoDelete( true ); |
148 | mJournalList.setAutoDelete( false ); | 148 | mJournalList.setAutoDelete( false ); |
149 | 149 | ||
150 | mEventList.clear(); | 150 | mEventList.clear(); |
151 | mTodoList.clear(); | 151 | mTodoList.clear(); |
152 | mJournalList.clear(); | 152 | mJournalList.clear(); |
153 | 153 | ||
154 | mEventList.setAutoDelete( false ); | 154 | mEventList.setAutoDelete( false ); |
155 | mTodoList.setAutoDelete( false ); | 155 | mTodoList.setAutoDelete( false ); |
156 | mJournalList.setAutoDelete( false ); | 156 | mJournalList.setAutoDelete( false ); |
157 | 157 | ||
158 | setModified( false ); | 158 | setModified( false ); |
159 | } | 159 | } |
160 | 160 | ||
161 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 161 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
162 | { | 162 | { |
163 | QString cat; | 163 | QString cat; |
164 | bool isBirthday = true; | 164 | bool isBirthday = true; |
165 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 165 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
166 | isBirthday = false; | 166 | isBirthday = false; |
167 | cat = i18n( "Anniversary" ); | 167 | cat = i18n( "Anniversary" ); |
168 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 168 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
169 | isBirthday = true; | 169 | isBirthday = true; |
170 | cat = i18n( "Birthday" ); | 170 | cat = i18n( "Birthday" ); |
171 | } else { | 171 | } else { |
172 | qDebug("addAnniversaryNoDup called without fitting category! "); | 172 | qDebug("addAnniversaryNoDup called without fitting category! "); |
173 | return false; | 173 | return false; |
174 | } | 174 | } |
175 | Event * eve; | 175 | Event * eve; |
176 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 176 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
177 | if ( !(eve->categories().contains( cat ) )) | 177 | if ( !(eve->categories().contains( cat ) )) |
178 | continue; | 178 | continue; |
179 | // now we have an event with fitting category | 179 | // now we have an event with fitting category |
180 | if ( eve->dtStart().date() != event->dtStart().date() ) | 180 | if ( eve->dtStart().date() != event->dtStart().date() ) |
181 | continue; | 181 | continue; |
182 | // now we have an event with fitting category+date | 182 | // now we have an event with fitting category+date |
183 | if ( eve->summary() != event->summary() ) | 183 | if ( eve->summary() != event->summary() ) |
184 | continue; | 184 | continue; |
185 | // now we have an event with fitting category+date+summary | 185 | // now we have an event with fitting category+date+summary |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | return addEvent( event ); | 188 | return addEvent( event ); |
189 | 189 | ||
190 | } | 190 | } |
191 | bool CalendarLocal::addEventNoDup( Event *event ) | 191 | bool CalendarLocal::addEventNoDup( Event *event ) |
192 | { | 192 | { |
193 | Event * eve; | 193 | Event * eve; |
194 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 194 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
195 | if ( *eve == *event ) { | 195 | if ( *eve == *event ) { |
196 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 196 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
197 | return false; | 197 | return false; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | return addEvent( event ); | 200 | return addEvent( event ); |
201 | } | 201 | } |
202 | 202 | ||
203 | bool CalendarLocal::addEvent( Event *event ) | 203 | bool CalendarLocal::addEvent( Event *event ) |
204 | { | 204 | { |
205 | insertEvent( event ); | 205 | insertEvent( event ); |
206 | 206 | ||
207 | event->registerObserver( this ); | 207 | event->registerObserver( this ); |
208 | 208 | ||
209 | setModified( true ); | 209 | setModified( true ); |
210 | event->setCalID( mDefaultCalendar ); | 210 | event->setCalID( mDefaultCalendar ); |
211 | event->setCalEnabled( true ); | 211 | event->setCalEnabled( true ); |
212 | 212 | ||
213 | return true; | 213 | return true; |
214 | } | 214 | } |
215 | 215 | ||
216 | void CalendarLocal::deleteEvent( Event *event ) | 216 | void CalendarLocal::deleteEvent( Event *event ) |
217 | { | 217 | { |
218 | if ( mUndoIncidence ) delete mUndoIncidence; | 218 | if ( mUndoIncidence ) delete mUndoIncidence; |
219 | mUndoIncidence = event->clone(); | 219 | mUndoIncidence = event->clone(); |
220 | if ( mEventList.removeRef( event ) ) { | 220 | if ( mEventList.removeRef( event ) ) { |
221 | setModified( true ); | 221 | setModified( true ); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | Event *CalendarLocal::event( const QString &uid ) | 226 | Event *CalendarLocal::event( const QString &uid ) |
227 | { | 227 | { |
228 | 228 | Event *event; | |
229 | Event *event; | 229 | Event *retVal = 0; |
230 | 230 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | |
231 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 231 | if ( event->calEnabled() && event->uid() == uid ) { |
232 | if ( event->uid() == uid && event->calEnabled() ) { | 232 | if ( retVal ) { |
233 | return event; | 233 | if ( retVal->calID() > event->calID() ) { |
234 | retVal = event; | ||
235 | } | ||
236 | } else { | ||
237 | retVal = event; | ||
238 | } | ||
239 | } | ||
234 | } | 240 | } |
235 | } | 241 | return retVal; |
236 | |||
237 | return 0; | ||
238 | } | 242 | } |
239 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 243 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
240 | { | 244 | { |
241 | Todo * eve; | 245 | Todo * eve; |
242 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 246 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
243 | if ( *eve == *todo ) { | 247 | if ( *eve == *todo ) { |
244 | //qDebug("duplicate todo found! not inserted! "); | 248 | //qDebug("duplicate todo found! not inserted! "); |
245 | return false; | 249 | return false; |
246 | } | 250 | } |
247 | } | 251 | } |
248 | return addTodo( todo ); | 252 | return addTodo( todo ); |
249 | } | 253 | } |
250 | bool CalendarLocal::addTodo( Todo *todo ) | 254 | bool CalendarLocal::addTodo( Todo *todo ) |
251 | { | 255 | { |
252 | mTodoList.append( todo ); | 256 | mTodoList.append( todo ); |
253 | 257 | ||
254 | todo->registerObserver( this ); | 258 | todo->registerObserver( this ); |
255 | 259 | ||
256 | // Set up subtask relations | 260 | // Set up subtask relations |
257 | setupRelations( todo ); | 261 | setupRelations( todo ); |
258 | 262 | ||
259 | setModified( true ); | 263 | setModified( true ); |
260 | todo->setCalID( mDefaultCalendar ); | 264 | todo->setCalID( mDefaultCalendar ); |
261 | todo->setCalEnabled( true ); | 265 | todo->setCalEnabled( true ); |
262 | return true; | 266 | return true; |
263 | } | 267 | } |
264 | 268 | ||
265 | void CalendarLocal::deleteTodo( Todo *todo ) | 269 | void CalendarLocal::deleteTodo( Todo *todo ) |
266 | { | 270 | { |
267 | // Handle orphaned children | 271 | // Handle orphaned children |
268 | if ( mUndoIncidence ) delete mUndoIncidence; | 272 | if ( mUndoIncidence ) delete mUndoIncidence; |
269 | removeRelations( todo ); | 273 | removeRelations( todo ); |
270 | mUndoIncidence = todo->clone(); | 274 | mUndoIncidence = todo->clone(); |
271 | 275 | ||
272 | if ( mTodoList.removeRef( todo ) ) { | 276 | if ( mTodoList.removeRef( todo ) ) { |
273 | setModified( true ); | 277 | setModified( true ); |
274 | } | 278 | } |
275 | } | 279 | } |
276 | 280 | ||
277 | QPtrList<Todo> CalendarLocal::rawTodos() | 281 | QPtrList<Todo> CalendarLocal::rawTodos() |
278 | { | 282 | { |
279 | QPtrList<Todo> el; | 283 | QPtrList<Todo> el; |
280 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 284 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
281 | if ( it->calEnabled() ) el.append( it ); | 285 | if ( it->calEnabled() ) el.append( it ); |
282 | return el; | 286 | return el; |
283 | } | 287 | } |
284 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 288 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
285 | { | 289 | { |
286 | Todo *todo; | 290 | Todo *todo; |
287 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 291 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
288 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 292 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
289 | } | 293 | } |
290 | 294 | ||
291 | return 0; | 295 | return 0; |
292 | } | 296 | } |
293 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 297 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
294 | { | 298 | { |
295 | QPtrList<Incidence> all = rawIncidences() ; | 299 | QPtrList<Incidence> all = rawIncidences() ; |
296 | Incidence *inc; | 300 | Incidence *inc; |
297 | for ( inc = all.first(); inc; inc = all.next() ) { | 301 | for ( inc = all.first(); inc; inc = all.next() ) { |
298 | inc->removeID( syncProfile ); | 302 | inc->removeID( syncProfile ); |
299 | } | 303 | } |
300 | if ( syncProfile.isEmpty() ) { | 304 | if ( syncProfile.isEmpty() ) { |
301 | QPtrList<Event> el; | 305 | QPtrList<Event> el; |
302 | Event *todo; | 306 | Event *todo; |
303 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 307 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
304 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 308 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
305 | el.append( todo ); | 309 | el.append( todo ); |
306 | } | 310 | } |
307 | for ( todo = el.first(); todo; todo = el.next() ) { | 311 | for ( todo = el.first(); todo; todo = el.next() ) { |
308 | deleteIncidence ( todo ); | 312 | deleteIncidence ( todo ); |
309 | } | 313 | } |
310 | } else { | 314 | } else { |
311 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 315 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
312 | if ( lse ) | 316 | if ( lse ) |
313 | deleteIncidence ( lse ); | 317 | deleteIncidence ( lse ); |
314 | } | 318 | } |
315 | } | 319 | } |
316 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 320 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
317 | { | 321 | { |
318 | QPtrList<Event> el; | 322 | QPtrList<Event> el; |
319 | Event *todo; | 323 | Event *todo; |
320 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 324 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
321 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 325 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
322 | if ( todo->summary().left(3) == "E: " ) | 326 | if ( todo->summary().left(3) == "E: " ) |
323 | el.append( todo ); | 327 | el.append( todo ); |
324 | } | 328 | } |
325 | 329 | ||
326 | return el; | 330 | return el; |
327 | 331 | ||
328 | } | 332 | } |
329 | Event *CalendarLocal::event( QString syncProf, QString id ) | 333 | Event *CalendarLocal::event( QString syncProf, QString id ) |
330 | { | 334 | { |
331 | Event *todo; | 335 | Event *todo; |
332 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 336 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
333 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 337 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
334 | } | 338 | } |
335 | 339 | ||
336 | return 0; | 340 | return 0; |
337 | } | 341 | } |
338 | Todo *CalendarLocal::todo( const QString &uid ) | 342 | Todo *CalendarLocal::todo( const QString &uid ) |
339 | { | 343 | { |
340 | Todo *todo; | 344 | Todo *todo;; |
345 | Todo *retVal = 0; | ||
341 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 346 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
342 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; | 347 | if ( todo->calEnabled() && todo->uid() == uid ) { |
348 | if ( retVal ) { | ||
349 | if ( retVal->calID() > todo->calID() ) { | ||
350 | retVal = todo; | ||
351 | } | ||
352 | } else { | ||
353 | retVal = todo; | ||
354 | } | ||
355 | } | ||
343 | } | 356 | } |
344 | 357 | return retVal; | |
345 | return 0; | ||
346 | } | 358 | } |
347 | QString CalendarLocal::nextSummary() const | 359 | QString CalendarLocal::nextSummary() const |
348 | { | 360 | { |
349 | return mNextSummary; | 361 | return mNextSummary; |
350 | } | 362 | } |
351 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 363 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
352 | { | 364 | { |
353 | return mNextAlarmEventDateTime; | 365 | return mNextAlarmEventDateTime; |
354 | } | 366 | } |
355 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 367 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
356 | { | 368 | { |
357 | //mNextAlarmIncidence | 369 | //mNextAlarmIncidence |
358 | //mNextAlarmDateTime | 370 | //mNextAlarmDateTime |
359 | //return mNextSummary; | 371 | //return mNextSummary; |
360 | //return mNextAlarmEventDateTime; | 372 | //return mNextAlarmEventDateTime; |
361 | bool newNextAlarm = false; | 373 | bool newNextAlarm = false; |
362 | bool computeNextAlarm = false; | 374 | bool computeNextAlarm = false; |
363 | bool ok; | 375 | bool ok; |
364 | int offset; | 376 | int offset; |
365 | QDateTime nextA; | 377 | QDateTime nextA; |
366 | // QString nextSum; | 378 | // QString nextSum; |
367 | //QDateTime nextEvent; | 379 | //QDateTime nextEvent; |
368 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 380 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
369 | computeNextAlarm = true; | 381 | computeNextAlarm = true; |
370 | } else { | 382 | } else { |
371 | if ( ! deleted ) { | 383 | if ( ! deleted ) { |
372 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 384 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
373 | if ( ok ) { | 385 | if ( ok ) { |
374 | if ( nextA < mNextAlarmDateTime ) { | 386 | if ( nextA < mNextAlarmDateTime ) { |
375 | deRegisterAlarm(); | 387 | deRegisterAlarm(); |
376 | mNextAlarmDateTime = nextA; | 388 | mNextAlarmDateTime = nextA; |
377 | mNextSummary = incidence->summary(); | 389 | mNextSummary = incidence->summary(); |
378 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 390 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
379 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 391 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
380 | newNextAlarm = true; | 392 | newNextAlarm = true; |
381 | mNextAlarmIncidence = incidence; | 393 | mNextAlarmIncidence = incidence; |
382 | } else { | 394 | } else { |
383 | if ( incidence == mNextAlarmIncidence ) { | 395 | if ( incidence == mNextAlarmIncidence ) { |
384 | computeNextAlarm = true; | 396 | computeNextAlarm = true; |
385 | } | 397 | } |
386 | } | 398 | } |
387 | } else { | 399 | } else { |
388 | if ( mNextAlarmIncidence == incidence ) { | 400 | if ( mNextAlarmIncidence == incidence ) { |
389 | computeNextAlarm = true; | 401 | computeNextAlarm = true; |
390 | } | 402 | } |
391 | } | 403 | } |
392 | } else { // deleted | 404 | } else { // deleted |
393 | if ( incidence == mNextAlarmIncidence ) { | 405 | if ( incidence == mNextAlarmIncidence ) { |
394 | computeNextAlarm = true; | 406 | computeNextAlarm = true; |
395 | } | 407 | } |
396 | } | 408 | } |
397 | } | 409 | } |
398 | if ( computeNextAlarm ) { | 410 | if ( computeNextAlarm ) { |
399 | deRegisterAlarm(); | 411 | deRegisterAlarm(); |
400 | nextA = nextAlarm( 1000 ); | 412 | nextA = nextAlarm( 1000 ); |
401 | if (! mNextAlarmIncidence ) { | 413 | if (! mNextAlarmIncidence ) { |
402 | return; | 414 | return; |
403 | } | 415 | } |
404 | newNextAlarm = true; | 416 | newNextAlarm = true; |
405 | } | 417 | } |
406 | if ( newNextAlarm ) | 418 | if ( newNextAlarm ) |
407 | registerAlarm(); | 419 | registerAlarm(); |
408 | } | 420 | } |
409 | QString CalendarLocal:: getAlarmNotification() | 421 | QString CalendarLocal:: getAlarmNotification() |
410 | { | 422 | { |
411 | QString ret; | 423 | QString ret; |
412 | // this should not happen | 424 | // this should not happen |
413 | if (! mNextAlarmIncidence ) | 425 | if (! mNextAlarmIncidence ) |
414 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 426 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
415 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 427 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
416 | if ( alarm->type() == Alarm::Procedure ) { | 428 | if ( alarm->type() == Alarm::Procedure ) { |
417 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 429 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
418 | } else { | 430 | } else { |
419 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 431 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
420 | } | 432 | } |
421 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 433 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
422 | if ( mNextSummary.length() > 25 ) | 434 | if ( mNextSummary.length() > 25 ) |
423 | ret += "\n" + mNextSummary.mid(25, 25 ); | 435 | ret += "\n" + mNextSummary.mid(25, 25 ); |
424 | ret+= "\n"+mNextAlarmEventDateTimeString; | 436 | ret+= "\n"+mNextAlarmEventDateTimeString; |
425 | return ret; | 437 | return ret; |
426 | } | 438 | } |
427 | void CalendarLocal::registerAlarm() | 439 | void CalendarLocal::registerAlarm() |
428 | { | 440 | { |
429 | mLastAlarmNotificationString = getAlarmNotification(); | 441 | mLastAlarmNotificationString = getAlarmNotification(); |
430 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 442 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
431 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 443 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
432 | // #ifndef DESKTOP_VERSION | 444 | // #ifndef DESKTOP_VERSION |
433 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 445 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
434 | // #endif | 446 | // #endif |
435 | } | 447 | } |
436 | void CalendarLocal::deRegisterAlarm() | 448 | void CalendarLocal::deRegisterAlarm() |
437 | { | 449 | { |
438 | if ( mLastAlarmNotificationString.isNull() ) | 450 | if ( mLastAlarmNotificationString.isNull() ) |
439 | return; | 451 | return; |
440 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 452 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
441 | 453 | ||
442 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 454 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
443 | mNextAlarmEventDateTime = QDateTime(); | 455 | mNextAlarmEventDateTime = QDateTime(); |
444 | // #ifndef DESKTOP_VERSION | 456 | // #ifndef DESKTOP_VERSION |
445 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 457 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
446 | // #endif | 458 | // #endif |
447 | } | 459 | } |
448 | 460 | ||
449 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 461 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
450 | { | 462 | { |
451 | QPtrList<Todo> todos; | 463 | QPtrList<Todo> todos; |
452 | 464 | ||
453 | Todo *todo; | 465 | Todo *todo; |
454 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 466 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
455 | if ( !todo->calEnabled() ) continue; | 467 | if ( !todo->calEnabled() ) continue; |
456 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 468 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
457 | todos.append( todo ); | 469 | todos.append( todo ); |
458 | } | 470 | } |
459 | } | 471 | } |
460 | 472 | ||
461 | filter()->apply( &todos ); | 473 | filter()->apply( &todos ); |
462 | return todos; | 474 | return todos; |
463 | } | 475 | } |
464 | void CalendarLocal::reInitAlarmSettings() | 476 | void CalendarLocal::reInitAlarmSettings() |
465 | { | 477 | { |
466 | if ( !mNextAlarmIncidence ) { | 478 | if ( !mNextAlarmIncidence ) { |
467 | nextAlarm( 1000 ); | 479 | nextAlarm( 1000 ); |
468 | } | 480 | } |
469 | deRegisterAlarm(); | 481 | deRegisterAlarm(); |
470 | mNextAlarmIncidence = 0; | 482 | mNextAlarmIncidence = 0; |
471 | checkAlarmForIncidence( 0, false ); | 483 | checkAlarmForIncidence( 0, false ); |
472 | 484 | ||
473 | } | 485 | } |
474 | 486 | ||
475 | 487 | ||
476 | 488 | ||
477 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 489 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
478 | { | 490 | { |
479 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 491 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
480 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 492 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
481 | QDateTime next; | 493 | QDateTime next; |
482 | Event *e; | 494 | Event *e; |
483 | bool ok; | 495 | bool ok; |
484 | bool found = false; | 496 | bool found = false; |
485 | int offset; | 497 | int offset; |
486 | mNextAlarmIncidence = 0; | 498 | mNextAlarmIncidence = 0; |
487 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 499 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
488 | if ( !e->calEnabled() ) continue; | 500 | if ( !e->calEnabled() ) continue; |
489 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 501 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
490 | if ( ok ) { | 502 | if ( ok ) { |
491 | if ( next < nextA ) { | 503 | if ( next < nextA ) { |
492 | nextA = next; | 504 | nextA = next; |
493 | found = true; | 505 | found = true; |
494 | mNextSummary = e->summary(); | 506 | mNextSummary = e->summary(); |
495 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 507 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
496 | mNextAlarmIncidence = (Incidence *) e; | 508 | mNextAlarmIncidence = (Incidence *) e; |
497 | } | 509 | } |
498 | } | 510 | } |
499 | } | 511 | } |
500 | Todo *t; | 512 | Todo *t; |
501 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 513 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
502 | if ( !t->calEnabled() ) continue; | 514 | if ( !t->calEnabled() ) continue; |
503 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 515 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
504 | if ( ok ) { | 516 | if ( ok ) { |
505 | if ( next < nextA ) { | 517 | if ( next < nextA ) { |
506 | nextA = next; | 518 | nextA = next; |
507 | found = true; | 519 | found = true; |
508 | mNextSummary = t->summary(); | 520 | mNextSummary = t->summary(); |
509 | mNextAlarmEventDateTime = next.addSecs(offset ); | 521 | mNextAlarmEventDateTime = next.addSecs(offset ); |
510 | mNextAlarmIncidence = (Incidence *) t; | 522 | mNextAlarmIncidence = (Incidence *) t; |
511 | } | 523 | } |
512 | } | 524 | } |
513 | } | 525 | } |
514 | if ( mNextAlarmIncidence ) { | 526 | if ( mNextAlarmIncidence ) { |
515 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 527 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
516 | mNextAlarmDateTime = nextA; | 528 | mNextAlarmDateTime = nextA; |
517 | } | 529 | } |
518 | return nextA; | 530 | return nextA; |
519 | } | 531 | } |
520 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 532 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
521 | { | 533 | { |
522 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 534 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
523 | } | 535 | } |
524 | 536 | ||
525 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 537 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
526 | { | 538 | { |
527 | 539 | ||
528 | Alarm::List alarms; | 540 | Alarm::List alarms; |
529 | 541 | ||
530 | Event *e; | 542 | Event *e; |
531 | 543 | ||
532 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 544 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
533 | if ( !e->calEnabled() ) continue; | 545 | if ( !e->calEnabled() ) continue; |
534 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 546 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
535 | else appendAlarms( alarms, e, from, to ); | 547 | else appendAlarms( alarms, e, from, to ); |
536 | } | 548 | } |
537 | 549 | ||
538 | Todo *t; | 550 | Todo *t; |
539 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 551 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
540 | if ( !t->calEnabled() ) continue; | 552 | if ( !t->calEnabled() ) continue; |
541 | appendAlarms( alarms, t, from, to ); | 553 | appendAlarms( alarms, t, from, to ); |
542 | } | 554 | } |
543 | 555 | ||
544 | return alarms; | 556 | return alarms; |
545 | } | 557 | } |
546 | 558 | ||
547 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 559 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
548 | const QDateTime &from, const QDateTime &to ) | 560 | const QDateTime &from, const QDateTime &to ) |
549 | { | 561 | { |
550 | QPtrList<Alarm> alarmList = incidence->alarms(); | 562 | QPtrList<Alarm> alarmList = incidence->alarms(); |
551 | Alarm *alarm; | 563 | Alarm *alarm; |
552 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 564 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
553 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 565 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
554 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 566 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
555 | if ( alarm->enabled() ) { | 567 | if ( alarm->enabled() ) { |
556 | if ( alarm->time() >= from && alarm->time() <= to ) { | 568 | if ( alarm->time() >= from && alarm->time() <= to ) { |
557 | alarms.append( alarm ); | 569 | alarms.append( alarm ); |
558 | } | 570 | } |
559 | } | 571 | } |
560 | } | 572 | } |
561 | } | 573 | } |
562 | 574 | ||
563 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 575 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
564 | Incidence *incidence, | 576 | Incidence *incidence, |
565 | const QDateTime &from, | 577 | const QDateTime &from, |
566 | const QDateTime &to ) | 578 | const QDateTime &to ) |
567 | { | 579 | { |
568 | 580 | ||
569 | QPtrList<Alarm> alarmList = incidence->alarms(); | 581 | QPtrList<Alarm> alarmList = incidence->alarms(); |
570 | Alarm *alarm; | 582 | Alarm *alarm; |
571 | QDateTime qdt; | 583 | QDateTime qdt; |
572 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 584 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
573 | if (incidence->recursOn(from.date())) { | 585 | if (incidence->recursOn(from.date())) { |
574 | qdt.setTime(alarm->time().time()); | 586 | qdt.setTime(alarm->time().time()); |
575 | qdt.setDate(from.date()); | 587 | qdt.setDate(from.date()); |
576 | } | 588 | } |
577 | else qdt = alarm->time(); | 589 | else qdt = alarm->time(); |
578 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 590 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
579 | if ( alarm->enabled() ) { | 591 | if ( alarm->enabled() ) { |
580 | if ( qdt >= from && qdt <= to ) { | 592 | if ( qdt >= from && qdt <= to ) { |
581 | alarms.append( alarm ); | 593 | alarms.append( alarm ); |
582 | } | 594 | } |
583 | } | 595 | } |
584 | } | 596 | } |
585 | } | 597 | } |
586 | 598 | ||
587 | 599 | ||
588 | /****************************** PROTECTED METHODS ****************************/ | 600 | /****************************** PROTECTED METHODS ****************************/ |
589 | 601 | ||
590 | // after changes are made to an event, this should be called. | 602 | // after changes are made to an event, this should be called. |
591 | void CalendarLocal::update( IncidenceBase *incidence ) | 603 | void CalendarLocal::update( IncidenceBase *incidence ) |
592 | { | 604 | { |
593 | incidence->setSyncStatus( Event::SYNCMOD ); | 605 | incidence->setSyncStatus( Event::SYNCMOD ); |
594 | incidence->setLastModified( QDateTime::currentDateTime() ); | 606 | incidence->setLastModified( QDateTime::currentDateTime() ); |
595 | // we should probably update the revision number here, | 607 | // we should probably update the revision number here, |
596 | // or internally in the Event itself when certain things change. | 608 | // or internally in the Event itself when certain things change. |
597 | // need to verify with ical documentation. | 609 | // need to verify with ical documentation. |
598 | 610 | ||
599 | setModified( true ); | 611 | setModified( true ); |
600 | } | 612 | } |
601 | 613 | ||
602 | void CalendarLocal::insertEvent( Event *event ) | 614 | void CalendarLocal::insertEvent( Event *event ) |
603 | { | 615 | { |
604 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 616 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
605 | } | 617 | } |
606 | 618 | ||
607 | 619 | ||
608 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 620 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
609 | { | 621 | { |
610 | QPtrList<Event> eventList; | 622 | QPtrList<Event> eventList; |
611 | 623 | ||
612 | Event *event; | 624 | Event *event; |
613 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 625 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
614 | if ( !event->calEnabled() ) continue; | 626 | if ( !event->calEnabled() ) continue; |
615 | if ( event->doesRecur() ) { | 627 | if ( event->doesRecur() ) { |
616 | if ( event->isMultiDay() ) { | 628 | if ( event->isMultiDay() ) { |
617 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 629 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
618 | int i; | 630 | int i; |
619 | for ( i = 0; i <= extraDays; i++ ) { | 631 | for ( i = 0; i <= extraDays; i++ ) { |
620 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 632 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
621 | eventList.append( event ); | 633 | eventList.append( event ); |
622 | break; | 634 | break; |
623 | } | 635 | } |
624 | } | 636 | } |
625 | } else { | 637 | } else { |
626 | if ( event->recursOn( qd ) ) | 638 | if ( event->recursOn( qd ) ) |
627 | eventList.append( event ); | 639 | eventList.append( event ); |
628 | } | 640 | } |
629 | } else { | 641 | } else { |
630 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 642 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
631 | eventList.append( event ); | 643 | eventList.append( event ); |
632 | } | 644 | } |
633 | } | 645 | } |
634 | } | 646 | } |
635 | 647 | ||
636 | if ( !sorted ) { | 648 | if ( !sorted ) { |
637 | return eventList; | 649 | return eventList; |
638 | } | 650 | } |
639 | 651 | ||
640 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 652 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
641 | // now, we have to sort it based on dtStart.time() | 653 | // now, we have to sort it based on dtStart.time() |
642 | QPtrList<Event> eventListSorted; | 654 | QPtrList<Event> eventListSorted; |
643 | Event *sortEvent; | 655 | Event *sortEvent; |
644 | for ( event = eventList.first(); event; event = eventList.next() ) { | 656 | for ( event = eventList.first(); event; event = eventList.next() ) { |
645 | sortEvent = eventListSorted.first(); | 657 | sortEvent = eventListSorted.first(); |
646 | int i = 0; | 658 | int i = 0; |
647 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 659 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
648 | { | 660 | { |
649 | i++; | 661 | i++; |
650 | sortEvent = eventListSorted.next(); | 662 | sortEvent = eventListSorted.next(); |
651 | } | 663 | } |
652 | eventListSorted.insert( i, event ); | 664 | eventListSorted.insert( i, event ); |
653 | } | 665 | } |
654 | return eventListSorted; | 666 | return eventListSorted; |
655 | } | 667 | } |
656 | 668 | ||
657 | 669 | ||
658 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 670 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
659 | bool inclusive ) | 671 | bool inclusive ) |
660 | { | 672 | { |
661 | Event *event = 0; | 673 | Event *event = 0; |
662 | 674 | ||
663 | QPtrList<Event> eventList; | 675 | QPtrList<Event> eventList; |
664 | 676 | ||
665 | // Get non-recurring events | 677 | // Get non-recurring events |
666 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 678 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
667 | if ( !event->calEnabled() ) continue; | 679 | if ( !event->calEnabled() ) continue; |
668 | if ( event->doesRecur() ) { | 680 | if ( event->doesRecur() ) { |
669 | QDate rStart = event->dtStart().date(); | 681 | QDate rStart = event->dtStart().date(); |
670 | bool found = false; | 682 | bool found = false; |
671 | if ( inclusive ) { | 683 | if ( inclusive ) { |
672 | if ( rStart >= start && rStart <= end ) { | 684 | if ( rStart >= start && rStart <= end ) { |
673 | // Start date of event is in range. Now check for end date. | 685 | // Start date of event is in range. Now check for end date. |
674 | // if duration is negative, event recurs forever, so do not include it. | 686 | // if duration is negative, event recurs forever, so do not include it. |
675 | if ( event->recurrence()->duration() == 0 ) { // End date set | 687 | if ( event->recurrence()->duration() == 0 ) { // End date set |
676 | QDate rEnd = event->recurrence()->endDate(); | 688 | QDate rEnd = event->recurrence()->endDate(); |
677 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 689 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
678 | found = true; | 690 | found = true; |
679 | } | 691 | } |
680 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 692 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
681 | // TODO: Calculate end date from duration. Should be done in Event | 693 | // TODO: Calculate end date from duration. Should be done in Event |
682 | // For now exclude all events with a duration. | 694 | // For now exclude all events with a duration. |
683 | } | 695 | } |
684 | } | 696 | } |
685 | } else { | 697 | } else { |
686 | bool founOne; | 698 | bool founOne; |
687 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 699 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
688 | if ( founOne ) { | 700 | if ( founOne ) { |
689 | if ( next <= end ) { | 701 | if ( next <= end ) { |
690 | found = true; | 702 | found = true; |
691 | } | 703 | } |
692 | } | 704 | } |
693 | 705 | ||
694 | /* | 706 | /* |
695 | // crap !!! | 707 | // crap !!! |
696 | if ( rStart <= end ) { // Start date not after range | 708 | if ( rStart <= end ) { // Start date not after range |
697 | if ( rStart >= start ) { // Start date within range | 709 | if ( rStart >= start ) { // Start date within range |
698 | found = true; | 710 | found = true; |
699 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 711 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
700 | found = true; | 712 | found = true; |
701 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 713 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
702 | QDate rEnd = event->recurrence()->endDate(); | 714 | QDate rEnd = event->recurrence()->endDate(); |
703 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 715 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
704 | found = true; | 716 | found = true; |
705 | } | 717 | } |
706 | } else { // Duration set | 718 | } else { // Duration set |
707 | // TODO: Calculate end date from duration. Should be done in Event | 719 | // TODO: Calculate end date from duration. Should be done in Event |
708 | // For now include all events with a duration. | 720 | // For now include all events with a duration. |
709 | found = true; | 721 | found = true; |
710 | } | 722 | } |
711 | } | 723 | } |
712 | */ | 724 | */ |
713 | 725 | ||
714 | } | 726 | } |
715 | 727 | ||
716 | if ( found ) eventList.append( event ); | 728 | if ( found ) eventList.append( event ); |
717 | } else { | 729 | } else { |
718 | QDate s = event->dtStart().date(); | 730 | QDate s = event->dtStart().date(); |
719 | QDate e = event->dtEnd().date(); | 731 | QDate e = event->dtEnd().date(); |
720 | 732 | ||
721 | if ( inclusive ) { | 733 | if ( inclusive ) { |
722 | if ( s >= start && e <= end ) { | 734 | if ( s >= start && e <= end ) { |
723 | eventList.append( event ); | 735 | eventList.append( event ); |
724 | } | 736 | } |
725 | } else { | 737 | } else { |
726 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 738 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
727 | eventList.append( event ); | 739 | eventList.append( event ); |
728 | } | 740 | } |
729 | } | 741 | } |
730 | } | 742 | } |
731 | } | 743 | } |
732 | 744 | ||
733 | return eventList; | 745 | return eventList; |
734 | } | 746 | } |
735 | 747 | ||
736 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 748 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
737 | { | 749 | { |
738 | return rawEventsForDate( qdt.date() ); | 750 | return rawEventsForDate( qdt.date() ); |
739 | } | 751 | } |
740 | 752 | ||
741 | QPtrList<Event> CalendarLocal::rawEvents() | 753 | QPtrList<Event> CalendarLocal::rawEvents() |
742 | { | 754 | { |
743 | QPtrList<Event> el; | 755 | QPtrList<Event> el; |
744 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 756 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
745 | if ( it->calEnabled() ) el.append( it ); | 757 | if ( it->calEnabled() ) el.append( it ); |
746 | return el; | 758 | return el; |
747 | } | 759 | } |
748 | 760 | ||
749 | bool CalendarLocal::addJournal(Journal *journal) | 761 | bool CalendarLocal::addJournal(Journal *journal) |
750 | { | 762 | { |
751 | if ( journal->dtStart().isValid()) | 763 | if ( journal->dtStart().isValid()) |
752 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 764 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
753 | else | 765 | else |
754 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 766 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
755 | 767 | ||
756 | mJournalList.append(journal); | 768 | mJournalList.append(journal); |
757 | 769 | ||
758 | journal->registerObserver( this ); | 770 | journal->registerObserver( this ); |
759 | 771 | ||
760 | setModified( true ); | 772 | setModified( true ); |
761 | journal->setCalID( mDefaultCalendar ); | 773 | journal->setCalID( mDefaultCalendar ); |
762 | journal->setCalEnabled( true ); | 774 | journal->setCalEnabled( true ); |
763 | return true; | 775 | return true; |
764 | } | 776 | } |
765 | 777 | ||
766 | void CalendarLocal::deleteJournal( Journal *journal ) | 778 | void CalendarLocal::deleteJournal( Journal *journal ) |
767 | { | 779 | { |
768 | if ( mUndoIncidence ) delete mUndoIncidence; | 780 | if ( mUndoIncidence ) delete mUndoIncidence; |
769 | mUndoIncidence = journal->clone(); | 781 | mUndoIncidence = journal->clone(); |
770 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 782 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
771 | if ( mJournalList.removeRef(journal) ) { | 783 | if ( mJournalList.removeRef(journal) ) { |
772 | setModified( true ); | 784 | setModified( true ); |
773 | } | 785 | } |
774 | } | 786 | } |
775 | 787 | ||
776 | Journal *CalendarLocal::journal( const QDate &date ) | 788 | Journal *CalendarLocal::journal( const QDate &date ) |
777 | { | 789 | { |
778 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 790 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
779 | 791 | ||
780 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 792 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
781 | if ( it->calEnabled() && it->dtStart().date() == date ) | 793 | if ( it->calEnabled() && it->dtStart().date() == date ) |
782 | return it; | 794 | return it; |
783 | 795 | ||
784 | return 0; | 796 | return 0; |
785 | } | 797 | } |
786 | 798 | ||
787 | Journal *CalendarLocal::journal( const QString &uid ) | 799 | Journal *CalendarLocal::journal( const QString &uid ) |
788 | { | 800 | { |
789 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 801 | Journal * retVal = 0; |
790 | if ( it->calEnabled() && it->uid() == uid ) | 802 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
791 | return it; | 803 | if ( it->calEnabled() && it->uid() == uid ) { |
792 | 804 | if ( retVal ) { | |
793 | return 0; | 805 | if ( retVal->calID() > it->calID() ) { |
806 | retVal = it; | ||
807 | } | ||
808 | } else { | ||
809 | retVal = it; | ||
810 | } | ||
811 | } | ||
812 | return retVal; | ||
794 | } | 813 | } |
795 | 814 | ||
796 | QPtrList<Journal> CalendarLocal::journals() | 815 | QPtrList<Journal> CalendarLocal::journals() |
797 | { | 816 | { |
798 | QPtrList<Journal> el; | 817 | QPtrList<Journal> el; |
799 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 818 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
800 | if ( it->calEnabled() ) el.append( it ); | 819 | if ( it->calEnabled() ) el.append( it ); |
801 | return el; | 820 | return el; |
802 | } | 821 | } |
803 | void CalendarLocal::setCalendarRemove( int id ) | 822 | void CalendarLocal::setCalendarRemove( int id ) |
804 | { | 823 | { |
805 | 824 | ||
806 | { | 825 | { |
807 | QPtrList<Event> EventList = mEventList; | 826 | QPtrList<Event> EventList = mEventList; |
808 | Event * ev = EventList.first(); | 827 | Event * ev = EventList.first(); |
809 | while ( ev ) { | 828 | while ( ev ) { |
810 | if ( ev->calID() == id ) | 829 | if ( ev->calID() == id ) |
811 | deleteEvent( ev ); | 830 | deleteEvent( ev ); |
812 | ev = EventList.next(); | 831 | ev = EventList.next(); |
813 | } | 832 | } |
814 | } | 833 | } |
815 | { | 834 | { |
816 | 835 | ||
817 | QPtrList<Todo> TodoList = mTodoList; | 836 | QPtrList<Todo> TodoList = mTodoList; |
818 | Todo * ev = TodoList.first(); | 837 | Todo * ev = TodoList.first(); |
819 | while ( ev ) { | 838 | while ( ev ) { |
820 | if ( ev->calID() == id ) | 839 | if ( ev->calID() == id ) |
821 | deleteTodo( ev ); | 840 | deleteTodo( ev ); |
822 | ev = TodoList.next(); | 841 | ev = TodoList.next(); |
823 | } | 842 | } |
824 | } | 843 | } |
825 | { | 844 | { |
826 | QPtrList<Journal> JournalList = mJournalList; | 845 | QPtrList<Journal> JournalList = mJournalList; |
827 | Journal * ev = JournalList.first(); | 846 | Journal * ev = JournalList.first(); |
828 | while ( ev ) { | 847 | while ( ev ) { |
829 | if ( ev->calID() == id ) | 848 | if ( ev->calID() == id ) |
830 | deleteJournal( ev ); | 849 | deleteJournal( ev ); |
831 | ev = JournalList.next(); | 850 | ev = JournalList.next(); |
832 | } | 851 | } |
833 | } | 852 | } |
834 | 853 | ||
835 | if ( mUndoIncidence ) delete mUndoIncidence; | 854 | if ( mUndoIncidence ) delete mUndoIncidence; |
836 | mUndoIncidence = 0; | 855 | mUndoIncidence = 0; |
837 | 856 | ||
838 | } | 857 | } |
839 | 858 | ||
840 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 859 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
841 | { | 860 | { |
842 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 861 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
843 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 862 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
844 | 863 | ||
845 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 864 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
846 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 865 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
847 | 866 | ||
848 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 867 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
849 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 868 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
850 | 869 | ||
851 | } | 870 | } |
852 | 871 | ||
853 | void CalendarLocal::setReadOnly( int id, bool enable ) | 872 | void CalendarLocal::setReadOnly( int id, bool enable ) |
854 | { | 873 | { |
855 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 874 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
856 | if ( it->calID() == id ) it->setReadOnly( enable ); | 875 | if ( it->calID() == id ) it->setReadOnly( enable ); |
857 | 876 | ||
858 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 877 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
859 | if ( it->calID() == id ) it->setReadOnly( enable ); | 878 | if ( it->calID() == id ) it->setReadOnly( enable ); |
860 | 879 | ||
861 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 880 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
862 | if ( it->calID() == id ) it->setReadOnly( enable ); | 881 | if ( it->calID() == id ) it->setReadOnly( enable ); |
863 | 882 | ||
864 | } | 883 | } |
865 | 884 | ||
866 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 885 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
867 | { | 886 | { |
868 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 887 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
869 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 888 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
870 | 889 | ||
871 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 890 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
872 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 891 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
873 | 892 | ||
874 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 893 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
875 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 894 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
876 | reInitAlarmSettings(); | 895 | reInitAlarmSettings(); |
877 | 896 | ||
878 | } | 897 | } |
879 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 898 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
880 | { | 899 | { |
881 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 900 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
882 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 901 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
883 | 902 | ||
884 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 903 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
885 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 904 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
886 | 905 | ||
887 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 906 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
888 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 907 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
889 | 908 | ||
890 | } | 909 | } |
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp index 3510c7d..72f70c2 100644 --- a/libkcal/calfilter.cpp +++ b/libkcal/calfilter.cpp | |||
@@ -1,221 +1,221 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kdebug.h> | 21 | #include <kdebug.h> |
22 | 22 | ||
23 | #include "calfilter.h" | 23 | #include "calfilter.h" |
24 | 24 | ||
25 | using namespace KCal; | 25 | using namespace KCal; |
26 | 26 | ||
27 | CalFilter::CalFilter() | 27 | CalFilter::CalFilter() |
28 | { | 28 | { |
29 | mEnabled = true; | 29 | mEnabled = true; |
30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
31 | } | 31 | } |
32 | 32 | ||
33 | CalFilter::CalFilter(const QString &name) | 33 | CalFilter::CalFilter(const QString &name) |
34 | { | 34 | { |
35 | mName = name; | 35 | mName = name; |
36 | mEnabled = true; | 36 | mEnabled = true; |
37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
38 | } | 38 | } |
39 | 39 | ||
40 | CalFilter::~CalFilter() | 40 | CalFilter::~CalFilter() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | void CalFilter::apply(QPtrList<Event> *eventlist) | 44 | void CalFilter::apply(QPtrList<Event> *eventlist) |
45 | { | 45 | { |
46 | if (!mEnabled) return; | 46 | if (!mEnabled) return; |
47 | 47 | ||
48 | // kdDebug(5800) << "CalFilter::apply()" << endl; | 48 | // kdDebug(5800) << "CalFilter::apply()" << endl; |
49 | 49 | ||
50 | Event *event = eventlist->first(); | 50 | Event *event = eventlist->first(); |
51 | while(event) { | 51 | while(event) { |
52 | if (!filterEvent(event)) { | 52 | if (!filterEvent(event)) { |
53 | eventlist->remove(); | 53 | eventlist->remove(); |
54 | event = eventlist->current(); | 54 | event = eventlist->current(); |
55 | } else { | 55 | } else { |
56 | event = eventlist->next(); | 56 | event = eventlist->next(); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
61 | } | 61 | } |
62 | 62 | ||
63 | // TODO: avoid duplicating apply() code | 63 | // TODO: avoid duplicating apply() code |
64 | void CalFilter::apply(QPtrList<Todo> *eventlist) | 64 | void CalFilter::apply(QPtrList<Todo> *eventlist) |
65 | { | 65 | { |
66 | if (!mEnabled) return; | 66 | if (!mEnabled) return; |
67 | Todo *event = eventlist->first(); | 67 | Todo *event = eventlist->first(); |
68 | while(event) { | 68 | while(event) { |
69 | if (!filterTodo(event)) { | 69 | if (!filterTodo(event)) { |
70 | eventlist->remove(); | 70 | eventlist->remove(); |
71 | event = eventlist->current(); | 71 | event = eventlist->current(); |
72 | } else { | 72 | } else { |
73 | event = eventlist->next(); | 73 | event = eventlist->next(); |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 77 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
78 | } | 78 | } |
79 | bool CalFilter::filterCalendarItem(Incidence *in) | 79 | bool CalFilter::filterCalendarItem(Incidence *in) |
80 | { | 80 | { |
81 | if ( !in->calEnabled() ) | 81 | if ( !in->calEnabled() ) |
82 | return false; | 82 | return false; |
83 | if ( in->typeID() == eventID ) | 83 | if ( in->typeID() == eventID ) |
84 | return filterEvent( (Event*) in ); | 84 | return filterEvent( (Event*) in ); |
85 | else if ( in->typeID() == todoID ) | 85 | else if ( in->typeID() == todoID ) |
86 | return filterTodo( (Todo*) in); | 86 | return filterTodo( (Todo*) in); |
87 | else if ( in->typeID () == journalID ) | 87 | else if ( in->typeID () == journalID ) |
88 | return filterJournal( (Journal*) in ); | 88 | return filterJournal( (Journal*) in ); |
89 | return false; | 89 | return false; |
90 | } | 90 | } |
91 | bool CalFilter::filterEvent(Event *event) | 91 | bool CalFilter::filterEvent(Event *event) |
92 | { | 92 | { |
93 | 93 | ||
94 | if ( !event->calEnabled() ) | 94 | if ( !event->calEnabled() ) |
95 | return false; | 95 | return false; |
96 | if (mCriteria & HideEvents) | 96 | if (mCriteria & HideEvents) |
97 | return false; | 97 | return false; |
98 | if (mCriteria & HideRecurring) { | 98 | if (mCriteria & HideRecurring) { |
99 | if (event->recurrence()->doesRecur()) return false; | 99 | if (event->recurrence()->doesRecur()) return false; |
100 | } | 100 | } |
101 | 101 | ||
102 | return filterIncidence(event); | 102 | return filterIncidence(event); |
103 | } | 103 | } |
104 | bool CalFilter::filterJournal(Journal *j) | 104 | bool CalFilter::filterJournal(Journal *j) |
105 | { | 105 | { |
106 | if ( !j->calEnabled() ) | 106 | if ( !j->calEnabled() ) |
107 | return false; | 107 | return false; |
108 | if (mCriteria & HideJournals) | 108 | if (mCriteria & HideJournals) |
109 | return false; | 109 | return false; |
110 | return true; | 110 | return true; |
111 | } | 111 | } |
112 | bool CalFilter::filterTodo(Todo *todo) | 112 | bool CalFilter::filterTodo(Todo *todo) |
113 | { | 113 | { |
114 | if ( !todo->calEnabled() ) | 114 | if ( !todo->calEnabled() ) |
115 | return false; | 115 | return false; |
116 | if (mCriteria & HideTodos) | 116 | if (mCriteria & HideTodos) |
117 | return false; | 117 | return false; |
118 | if (mCriteria & HideCompleted) { | 118 | if (mCriteria & HideCompleted) { |
119 | if (todo->isCompleted()) return false; | 119 | if (todo->isCompleted()) return false; |
120 | } | 120 | } |
121 | 121 | ||
122 | return filterIncidence(todo); | 122 | return filterIncidence(todo); |
123 | } | 123 | } |
124 | bool CalFilter::showCategories() | 124 | bool CalFilter::showCategories() |
125 | { | 125 | { |
126 | return mCriteria & ShowCategories; | 126 | return mCriteria & ShowCategories; |
127 | } | 127 | } |
128 | int CalFilter::getSecrecy() | 128 | int CalFilter::getSecrecy() |
129 | { | 129 | { |
130 | if ( (mCriteria & ShowPublic )) | 130 | if ( (mCriteria & ShowPublic )) |
131 | return Incidence::SecrecyPublic; | 131 | return Incidence::SecrecyPublic; |
132 | if ( (mCriteria & ShowPrivate )) | 132 | if ( (mCriteria & ShowPrivate )) |
133 | return Incidence::SecrecyPrivate; | 133 | return Incidence::SecrecyPrivate; |
134 | if ( (mCriteria & ShowConfidential )) | 134 | if ( (mCriteria & ShowConfidential )) |
135 | return Incidence::SecrecyConfidential; | 135 | return Incidence::SecrecyConfidential; |
136 | return Incidence::SecrecyPublic; | 136 | return Incidence::SecrecyPublic; |
137 | } | 137 | } |
138 | bool CalFilter::filterIncidence(Incidence *incidence) | 138 | bool CalFilter::filterIncidence(Incidence *incidence) |
139 | { | 139 | { |
140 | if ( mCriteria > 7 ) { | 140 | if ( mCriteria > 7 ) { |
141 | switch (incidence->secrecy()) { | 141 | switch (incidence->secrecy()) { |
142 | case Incidence::SecrecyPublic: | 142 | case Incidence::SecrecyPublic: |
143 | if (! (mCriteria & ShowPublic )) | 143 | if (! (mCriteria & ShowPublic )) |
144 | return false; | 144 | return false; |
145 | break; | 145 | break; |
146 | case Incidence::SecrecyPrivate: | 146 | case Incidence::SecrecyPrivate: |
147 | if (! (mCriteria & ShowPrivate )) | 147 | if (! (mCriteria & ShowPrivate )) |
148 | return false; | 148 | return false; |
149 | break; | 149 | break; |
150 | case Incidence::SecrecyConfidential: | 150 | case Incidence::SecrecyConfidential: |
151 | if (! (mCriteria & ShowConfidential )) | 151 | if (! (mCriteria & ShowConfidential )) |
152 | return false; | 152 | return false; |
153 | break; | 153 | break; |
154 | default: | 154 | default: |
155 | return false; | 155 | return false; |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 160 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; |
161 | 161 | ||
162 | if (mCriteria & ShowCategories) { | 162 | if (mCriteria & ShowCategories) { |
163 | for (QStringList::Iterator it = mCategoryList.begin(); | 163 | for (QStringList::Iterator it = mCategoryList.begin(); |
164 | it != mCategoryList.end(); ++it ) { | 164 | it != mCategoryList.end(); ++it ) { |
165 | QStringList incidenceCategories = incidence->categories(); | 165 | //QStringList incidenceCategories = incidence->categories(); |
166 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | 166 | for (QStringList::Iterator it2 = incidence->categoriesP()->begin(); |
167 | it2 != incidenceCategories.end(); ++it2 ) { | 167 | it2 != incidence->categoriesP()->end(); ++it2 ) { |
168 | if ((*it) == (*it2)) { | 168 | if ((*it) == (*it2)) { |
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | } | 171 | } |
172 | } | 172 | } |
173 | return false; | 173 | return false; |
174 | } else { | 174 | } else { |
175 | for (QStringList::Iterator it = mCategoryList.begin(); | 175 | for (QStringList::Iterator it = mCategoryList.begin(); |
176 | it != mCategoryList.end(); ++it ) { | 176 | it != mCategoryList.end(); ++it ) { |
177 | QStringList incidenceCategories = incidence->categories(); | 177 | //QStringList incidenceCategories = incidence->categories(); |
178 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | 178 | for (QStringList::Iterator it2 = incidence->categoriesP()->begin(); |
179 | it2 != incidenceCategories.end(); ++it2 ) { | 179 | it2 != incidence->categoriesP()->end(); ++it2 ) { |
180 | if ((*it) == (*it2)) { | 180 | if ((*it) == (*it2)) { |
181 | return false; | 181 | return false; |
182 | } | 182 | } |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return true; | 185 | return true; |
186 | } | 186 | } |
187 | 187 | ||
188 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; | 188 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; |
189 | 189 | ||
190 | return true; | 190 | return true; |
191 | } | 191 | } |
192 | 192 | ||
193 | void CalFilter::setEnabled(bool enabled) | 193 | void CalFilter::setEnabled(bool enabled) |
194 | { | 194 | { |
195 | mEnabled = enabled; | 195 | mEnabled = enabled; |
196 | } | 196 | } |
197 | 197 | ||
198 | bool CalFilter::isEnabled() | 198 | bool CalFilter::isEnabled() |
199 | { | 199 | { |
200 | return mEnabled; | 200 | return mEnabled; |
201 | } | 201 | } |
202 | 202 | ||
203 | void CalFilter::setCriteria(int criteria) | 203 | void CalFilter::setCriteria(int criteria) |
204 | { | 204 | { |
205 | mCriteria = criteria; | 205 | mCriteria = criteria; |
206 | } | 206 | } |
207 | 207 | ||
208 | int CalFilter::criteria() | 208 | int CalFilter::criteria() |
209 | { | 209 | { |
210 | return mCriteria; | 210 | return mCriteria; |
211 | } | 211 | } |
212 | 212 | ||
213 | void CalFilter::setCategoryList(const QStringList &categoryList) | 213 | void CalFilter::setCategoryList(const QStringList &categoryList) |
214 | { | 214 | { |
215 | mCategoryList = categoryList; | 215 | mCategoryList = categoryList; |
216 | } | 216 | } |
217 | 217 | ||
218 | QStringList CalFilter::categoryList() | 218 | QStringList CalFilter::categoryList() |
219 | { | 219 | { |
220 | return mCategoryList; | 220 | return mCategoryList; |
221 | } | 221 | } |
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 4382416..11f7ecc 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,755 +1,760 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | mAttachments = i.mAttachments; |
63 | mResources = i.mResources; | 63 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 64 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 65 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 66 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 67 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 68 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 69 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 70 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 71 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 72 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 73 | b->setParent( this ); |
74 | mAlarms.append( b ); | 74 | mAlarms.append( b ); |
75 | 75 | ||
76 | ++it; | 76 | ++it; |
77 | } | 77 | } |
78 | mAlarms.setAutoDelete(true); | 78 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 79 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 80 | mRecurrenceID = i.mRecurrenceID; |
81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
82 | mHoliday = i.mHoliday ; | 82 | mHoliday = i.mHoliday ; |
83 | mBirthday = i.mBirthday; | 83 | mBirthday = i.mBirthday; |
84 | mAnniversary = i.mAnniversary; | 84 | mAnniversary = i.mAnniversary; |
85 | } | 85 | } |
86 | 86 | ||
87 | Incidence::~Incidence() | 87 | Incidence::~Incidence() |
88 | { | 88 | { |
89 | 89 | ||
90 | Incidence *ev; | 90 | Incidence *ev; |
91 | QPtrList<Incidence> Relations = relations(); | 91 | QPtrList<Incidence> Relations = relations(); |
92 | for (ev=Relations.first();ev;ev=Relations.next()) { | 92 | for (ev=Relations.first();ev;ev=Relations.next()) { |
93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
94 | } | 94 | } |
95 | if (relatedTo()) relatedTo()->removeRelation(this); | 95 | if (relatedTo()) relatedTo()->removeRelation(this); |
96 | delete mRecurrence; | 96 | delete mRecurrence; |
97 | 97 | ||
98 | } | 98 | } |
99 | 99 | ||
100 | bool Incidence::isHoliday() const | 100 | bool Incidence::isHoliday() const |
101 | { | 101 | { |
102 | return mHoliday; | 102 | return mHoliday; |
103 | } | 103 | } |
104 | bool Incidence::isBirthday() const | 104 | bool Incidence::isBirthday() const |
105 | { | 105 | { |
106 | 106 | ||
107 | return mBirthday ; | 107 | return mBirthday ; |
108 | } | 108 | } |
109 | bool Incidence::isAnniversary() const | 109 | bool Incidence::isAnniversary() const |
110 | { | 110 | { |
111 | return mAnniversary ; | 111 | return mAnniversary ; |
112 | 112 | ||
113 | } | 113 | } |
114 | 114 | ||
115 | bool Incidence::hasRecurrenceID() const | 115 | bool Incidence::hasRecurrenceID() const |
116 | { | 116 | { |
117 | return mHasRecurrenceID; | 117 | return mHasRecurrenceID; |
118 | } | 118 | } |
119 | 119 | ||
120 | void Incidence::setHasRecurrenceID( bool b ) | 120 | void Incidence::setHasRecurrenceID( bool b ) |
121 | { | 121 | { |
122 | mHasRecurrenceID = b; | 122 | mHasRecurrenceID = b; |
123 | } | 123 | } |
124 | 124 | ||
125 | void Incidence::setRecurrenceID(QDateTime d) | 125 | void Incidence::setRecurrenceID(QDateTime d) |
126 | { | 126 | { |
127 | mRecurrenceID = d; | 127 | mRecurrenceID = d; |
128 | mHasRecurrenceID = true; | 128 | mHasRecurrenceID = true; |
129 | updated(); | 129 | updated(); |
130 | } | 130 | } |
131 | QDateTime Incidence::recurrenceID () const | 131 | QDateTime Incidence::recurrenceID () const |
132 | { | 132 | { |
133 | return mRecurrenceID; | 133 | return mRecurrenceID; |
134 | } | 134 | } |
135 | 135 | ||
136 | bool Incidence::cancelled() const | 136 | bool Incidence::cancelled() const |
137 | { | 137 | { |
138 | return mCancelled; | 138 | return mCancelled; |
139 | } | 139 | } |
140 | void Incidence::setCancelled( bool b ) | 140 | void Incidence::setCancelled( bool b ) |
141 | { | 141 | { |
142 | mCancelled = b; | 142 | mCancelled = b; |
143 | updated(); | 143 | updated(); |
144 | } | 144 | } |
145 | bool Incidence::hasStartDate() const | 145 | bool Incidence::hasStartDate() const |
146 | { | 146 | { |
147 | return mHasStartDate; | 147 | return mHasStartDate; |
148 | } | 148 | } |
149 | 149 | ||
150 | void Incidence::setHasStartDate(bool f) | 150 | void Incidence::setHasStartDate(bool f) |
151 | { | 151 | { |
152 | if (mReadOnly) return; | 152 | if (mReadOnly) return; |
153 | mHasStartDate = f; | 153 | mHasStartDate = f; |
154 | updated(); | 154 | updated(); |
155 | } | 155 | } |
156 | 156 | ||
157 | // A string comparison that considers that null and empty are the same | 157 | // A string comparison that considers that null and empty are the same |
158 | static bool stringCompare( const QString& s1, const QString& s2 ) | 158 | static bool stringCompare( const QString& s1, const QString& s2 ) |
159 | { | 159 | { |
160 | if ( s1.isEmpty() && s2.isEmpty() ) | 160 | if ( s1.isEmpty() && s2.isEmpty() ) |
161 | return true; | 161 | return true; |
162 | return s1 == s2; | 162 | return s1 == s2; |
163 | } | 163 | } |
164 | 164 | ||
165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
166 | { | 166 | { |
167 | 167 | ||
168 | if( i1.alarms().count() != i2.alarms().count() ) { | 168 | if( i1.alarms().count() != i2.alarms().count() ) { |
169 | return false; // no need to check further | 169 | return false; // no need to check further |
170 | } | 170 | } |
171 | if ( i1.alarms().count() > 0 ) { | 171 | if ( i1.alarms().count() > 0 ) { |
172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
173 | { | 173 | { |
174 | qDebug("alarm not equal "); | 174 | qDebug("alarm not equal "); |
175 | return false; | 175 | return false; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | #if 0 | 178 | #if 0 |
179 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 179 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
180 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 180 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
182 | if( *a1.current() == *a2.current() ) { | 182 | if( *a1.current() == *a2.current() ) { |
183 | continue; | 183 | continue; |
184 | } | 184 | } |
185 | else { | 185 | else { |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | #endif | 189 | #endif |
190 | 190 | ||
191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
192 | if ( i1.hasRecurrenceID() ) { | 192 | if ( i1.hasRecurrenceID() ) { |
193 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 193 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
194 | return false; | 194 | return false; |
195 | } | 195 | } |
196 | 196 | ||
197 | } else { | 197 | } else { |
198 | return false; | 198 | return false; |
199 | } | 199 | } |
200 | 200 | ||
201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
202 | return false; | 202 | return false; |
203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
204 | if ( i1.hasStartDate() ) { | 204 | if ( i1.hasStartDate() ) { |
205 | if ( i1.dtStart() != i2.dtStart() ) | 205 | if ( i1.dtStart() != i2.dtStart() ) |
206 | return false; | 206 | return false; |
207 | } | 207 | } |
208 | } else { | 208 | } else { |
209 | return false; | 209 | return false; |
210 | } | 210 | } |
211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
212 | qDebug("recurrence is NOT equal "); | 212 | qDebug("recurrence is NOT equal "); |
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | return | 215 | return |
216 | // i1.created() == i2.created() && | 216 | // i1.created() == i2.created() && |
217 | stringCompare( i1.description(), i2.description() ) && | 217 | stringCompare( i1.description(), i2.description() ) && |
218 | stringCompare( i1.summary(), i2.summary() ) && | 218 | stringCompare( i1.summary(), i2.summary() ) && |
219 | i1.categories() == i2.categories() && | 219 | i1.categories() == i2.categories() && |
220 | // no need to compare mRelatedTo | 220 | // no need to compare mRelatedTo |
221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
222 | // i1.relations() == i2.relations() && | 222 | // i1.relations() == i2.relations() && |
223 | i1.exDates() == i2.exDates() && | 223 | i1.exDates() == i2.exDates() && |
224 | i1.attachments() == i2.attachments() && | 224 | i1.attachments() == i2.attachments() && |
225 | i1.resources() == i2.resources() && | 225 | i1.resources() == i2.resources() && |
226 | i1.secrecy() == i2.secrecy() && | 226 | i1.secrecy() == i2.secrecy() && |
227 | i1.priority() == i2.priority() && | 227 | i1.priority() == i2.priority() && |
228 | i1.cancelled() == i2.cancelled() && | 228 | i1.cancelled() == i2.cancelled() && |
229 | stringCompare( i1.location(), i2.location() ); | 229 | stringCompare( i1.location(), i2.location() ); |
230 | } | 230 | } |
231 | 231 | ||
232 | Incidence* Incidence::recreateCloneException( QDate d ) | 232 | Incidence* Incidence::recreateCloneException( QDate d ) |
233 | { | 233 | { |
234 | Incidence* newInc = clone(); | 234 | Incidence* newInc = clone(); |
235 | newInc->recreate(); | 235 | newInc->recreate(); |
236 | if ( doesRecur() ) { | 236 | if ( doesRecur() ) { |
237 | addExDate( d ); | 237 | addExDate( d ); |
238 | newInc->recurrence()->unsetRecurs(); | 238 | newInc->recurrence()->unsetRecurs(); |
239 | if ( typeID() == eventID ) { | 239 | if ( typeID() == eventID ) { |
240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
241 | QTime tim = dtStart().time(); | 241 | QTime tim = dtStart().time(); |
242 | newInc->setDtStart( QDateTime(d, tim) ); | 242 | newInc->setDtStart( QDateTime(d, tim) ); |
243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
244 | } else { | 244 | } else { |
245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
246 | QTime tim = ((Todo*)this)->dtDue().time(); | 246 | QTime tim = ((Todo*)this)->dtDue().time(); |
247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
249 | ((Todo*)this)->setRecurDates(); | 249 | ((Todo*)this)->setRecurDates(); |
250 | } | 250 | } |
251 | newInc->setExDates( DateList () ); | 251 | newInc->setExDates( DateList () ); |
252 | } | 252 | } |
253 | return newInc; | 253 | return newInc; |
254 | } | 254 | } |
255 | 255 | ||
256 | void Incidence::recreate() | 256 | void Incidence::recreate() |
257 | { | 257 | { |
258 | setCreated(QDateTime::currentDateTime()); | 258 | setCreated(QDateTime::currentDateTime()); |
259 | 259 | ||
260 | setUid(CalFormat::createUniqueId()); | 260 | setUid(CalFormat::createUniqueId()); |
261 | 261 | ||
262 | setRevision(0); | 262 | setRevision(0); |
263 | setIDStr( ":" ); | 263 | setIDStr( ":" ); |
264 | setLastModified(QDateTime::currentDateTime()); | 264 | setLastModified(QDateTime::currentDateTime()); |
265 | } | 265 | } |
266 | void Incidence::cloneRelations( Incidence * newInc ) | 266 | void Incidence::cloneRelations( Incidence * newInc ) |
267 | { | 267 | { |
268 | // newInc is already a clone of this incidence | 268 | // newInc is already a clone of this incidence |
269 | Incidence * inc; | 269 | Incidence * inc; |
270 | Incidence * cloneInc; | 270 | Incidence * cloneInc; |
271 | QPtrList<Incidence> Relations = relations(); | 271 | QPtrList<Incidence> Relations = relations(); |
272 | for (inc=Relations.first();inc;inc=Relations.next()) { | 272 | for (inc=Relations.first();inc;inc=Relations.next()) { |
273 | cloneInc = inc->clone(); | 273 | cloneInc = inc->clone(); |
274 | cloneInc->recreate(); | 274 | cloneInc->recreate(); |
275 | cloneInc->setRelatedTo( newInc ); | 275 | cloneInc->setRelatedTo( newInc ); |
276 | inc->cloneRelations( cloneInc ); | 276 | inc->cloneRelations( cloneInc ); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | void Incidence::setReadOnly( bool readOnly ) | 279 | void Incidence::setReadOnly( bool readOnly ) |
280 | { | 280 | { |
281 | IncidenceBase::setReadOnly( readOnly ); | 281 | IncidenceBase::setReadOnly( readOnly ); |
282 | recurrence()->setRecurReadOnly( readOnly); | 282 | recurrence()->setRecurReadOnly( readOnly); |
283 | } | 283 | } |
284 | 284 | ||
285 | void Incidence::setCreated(QDateTime created) | 285 | void Incidence::setCreated(QDateTime created) |
286 | { | 286 | { |
287 | if (mReadOnly) return; | 287 | if (mReadOnly) return; |
288 | mCreated = getEvenTime(created); | 288 | mCreated = getEvenTime(created); |
289 | } | 289 | } |
290 | 290 | ||
291 | QDateTime Incidence::created() const | 291 | QDateTime Incidence::created() const |
292 | { | 292 | { |
293 | return mCreated; | 293 | return mCreated; |
294 | } | 294 | } |
295 | 295 | ||
296 | void Incidence::setRevision(int rev) | 296 | void Incidence::setRevision(int rev) |
297 | { | 297 | { |
298 | if (mReadOnly) return; | 298 | if (mReadOnly) return; |
299 | mRevision = rev; | 299 | mRevision = rev; |
300 | 300 | ||
301 | updated(); | 301 | updated(); |
302 | } | 302 | } |
303 | 303 | ||
304 | int Incidence::revision() const | 304 | int Incidence::revision() const |
305 | { | 305 | { |
306 | return mRevision; | 306 | return mRevision; |
307 | } | 307 | } |
308 | 308 | ||
309 | void Incidence::setDtStart(const QDateTime &dtStart) | 309 | void Incidence::setDtStart(const QDateTime &dtStart) |
310 | { | 310 | { |
311 | 311 | ||
312 | QDateTime dt = getEvenTime(dtStart); | 312 | QDateTime dt = getEvenTime(dtStart); |
313 | recurrence()->setRecurStart( dt); | 313 | recurrence()->setRecurStart( dt); |
314 | IncidenceBase::setDtStart( dt ); | 314 | IncidenceBase::setDtStart( dt ); |
315 | } | 315 | } |
316 | 316 | ||
317 | void Incidence::setDescription(const QString &description) | 317 | void Incidence::setDescription(const QString &description) |
318 | { | 318 | { |
319 | if (mReadOnly) return; | 319 | if (mReadOnly) return; |
320 | mDescription = description; | 320 | mDescription = description; |
321 | updated(); | 321 | updated(); |
322 | } | 322 | } |
323 | 323 | ||
324 | QString Incidence::description() const | 324 | QString Incidence::description() const |
325 | { | 325 | { |
326 | return mDescription; | 326 | return mDescription; |
327 | } | 327 | } |
328 | 328 | ||
329 | 329 | ||
330 | void Incidence::setSummary(const QString &summary) | 330 | void Incidence::setSummary(const QString &summary) |
331 | { | 331 | { |
332 | if (mReadOnly) return; | 332 | if (mReadOnly) return; |
333 | mSummary = summary; | 333 | mSummary = summary; |
334 | updated(); | 334 | updated(); |
335 | } | 335 | } |
336 | 336 | ||
337 | QString Incidence::summary() const | 337 | QString Incidence::summary() const |
338 | { | 338 | { |
339 | return mSummary; | 339 | return mSummary; |
340 | } | 340 | } |
341 | void Incidence::checkCategories() | 341 | void Incidence::checkCategories() |
342 | { | 342 | { |
343 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 343 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
344 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 344 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
345 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 345 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
346 | } | 346 | } |
347 | 347 | ||
348 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false | 348 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false |
349 | { | 349 | { |
350 | if (mReadOnly) return; | 350 | if (mReadOnly) return; |
351 | int i; | 351 | int i; |
352 | for( i = 0; i < categories.count(); ++i ) { | 352 | for( i = 0; i < categories.count(); ++i ) { |
353 | if ( !mCategories.contains (categories[i])) | 353 | if ( !mCategories.contains (categories[i])) |
354 | mCategories.append( categories[i] ); | 354 | mCategories.append( categories[i] ); |
355 | } | 355 | } |
356 | checkCategories(); | 356 | checkCategories(); |
357 | updated(); | 357 | updated(); |
358 | if ( addToRelations ) { | 358 | if ( addToRelations ) { |
359 | Incidence * inc; | 359 | Incidence * inc; |
360 | QPtrList<Incidence> Relations = relations(); | 360 | QPtrList<Incidence> Relations = relations(); |
361 | for (inc=Relations.first();inc;inc=Relations.next()) { | 361 | for (inc=Relations.first();inc;inc=Relations.next()) { |
362 | inc->addCategories( categories, true ); | 362 | inc->addCategories( categories, true ); |
363 | } | 363 | } |
364 | } | 364 | } |
365 | } | 365 | } |
366 | 366 | ||
367 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false | 367 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false |
368 | { | 368 | { |
369 | if (mReadOnly) return; | 369 | if (mReadOnly) return; |
370 | mCategories = categories; | 370 | mCategories = categories; |
371 | checkCategories(); | 371 | checkCategories(); |
372 | updated(); | 372 | updated(); |
373 | if ( setForRelations ) { | 373 | if ( setForRelations ) { |
374 | Incidence * inc; | 374 | Incidence * inc; |
375 | QPtrList<Incidence> Relations = relations(); | 375 | QPtrList<Incidence> Relations = relations(); |
376 | for (inc=Relations.first();inc;inc=Relations.next()) { | 376 | for (inc=Relations.first();inc;inc=Relations.next()) { |
377 | inc->setCategories( categories, true ); | 377 | inc->setCategories( categories, true ); |
378 | } | 378 | } |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||
382 | // TODO: remove setCategories(QString) function | 382 | // TODO: remove setCategories(QString) function |
383 | void Incidence::setCategories(const QString &catStr) | 383 | void Incidence::setCategories(const QString &catStr) |
384 | { | 384 | { |
385 | if (mReadOnly) return; | 385 | if (mReadOnly) return; |
386 | mCategories.clear(); | 386 | mCategories.clear(); |
387 | 387 | ||
388 | if (catStr.isEmpty()) return; | 388 | if (catStr.isEmpty()) return; |
389 | 389 | ||
390 | mCategories = QStringList::split(",",catStr); | 390 | mCategories = QStringList::split(",",catStr); |
391 | 391 | ||
392 | QStringList::Iterator it; | 392 | QStringList::Iterator it; |
393 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 393 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
394 | *it = (*it).stripWhiteSpace(); | 394 | *it = (*it).stripWhiteSpace(); |
395 | } | 395 | } |
396 | checkCategories(); | 396 | checkCategories(); |
397 | updated(); | 397 | updated(); |
398 | } | 398 | } |
399 | // using this makes filtering 3 times faster | ||
400 | QStringList* Incidence::categoriesP() | ||
401 | { | ||
402 | return &mCategories; | ||
403 | } | ||
399 | 404 | ||
400 | QStringList Incidence::categories() const | 405 | QStringList Incidence::categories() const |
401 | { | 406 | { |
402 | return mCategories; | 407 | return mCategories; |
403 | } | 408 | } |
404 | 409 | ||
405 | QString Incidence::categoriesStr() | 410 | QString Incidence::categoriesStr() |
406 | { | 411 | { |
407 | return mCategories.join(","); | 412 | return mCategories.join(","); |
408 | } | 413 | } |
409 | QString Incidence::categoriesStrWithSpace() | 414 | QString Incidence::categoriesStrWithSpace() |
410 | { | 415 | { |
411 | return mCategories.join(", "); | 416 | return mCategories.join(", "); |
412 | } | 417 | } |
413 | 418 | ||
414 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 419 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
415 | { | 420 | { |
416 | if (mReadOnly) return; | 421 | if (mReadOnly) return; |
417 | mRelatedToUid = relatedToUid; | 422 | mRelatedToUid = relatedToUid; |
418 | } | 423 | } |
419 | 424 | ||
420 | QString Incidence::relatedToUid() const | 425 | QString Incidence::relatedToUid() const |
421 | { | 426 | { |
422 | return mRelatedToUid; | 427 | return mRelatedToUid; |
423 | } | 428 | } |
424 | 429 | ||
425 | void Incidence::setRelatedTo(Incidence *relatedTo) | 430 | void Incidence::setRelatedTo(Incidence *relatedTo) |
426 | { | 431 | { |
427 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 432 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
428 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 433 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
429 | if (mReadOnly || mRelatedTo == relatedTo) return; | 434 | if (mReadOnly || mRelatedTo == relatedTo) return; |
430 | if(mRelatedTo) { | 435 | if(mRelatedTo) { |
431 | // updated(); | 436 | // updated(); |
432 | mRelatedTo->removeRelation(this); | 437 | mRelatedTo->removeRelation(this); |
433 | } | 438 | } |
434 | mRelatedTo = relatedTo; | 439 | mRelatedTo = relatedTo; |
435 | if (mRelatedTo) { | 440 | if (mRelatedTo) { |
436 | mRelatedTo->addRelation(this); | 441 | mRelatedTo->addRelation(this); |
437 | mRelatedToUid = mRelatedTo->uid(); | 442 | mRelatedToUid = mRelatedTo->uid(); |
438 | } else { | 443 | } else { |
439 | mRelatedToUid = ""; | 444 | mRelatedToUid = ""; |
440 | } | 445 | } |
441 | } | 446 | } |
442 | 447 | ||
443 | Incidence *Incidence::relatedTo() const | 448 | Incidence *Incidence::relatedTo() const |
444 | { | 449 | { |
445 | return mRelatedTo; | 450 | return mRelatedTo; |
446 | } | 451 | } |
447 | 452 | ||
448 | QPtrList<Incidence> Incidence::relations() const | 453 | QPtrList<Incidence> Incidence::relations() const |
449 | { | 454 | { |
450 | return mRelations; | 455 | return mRelations; |
451 | } | 456 | } |
452 | 457 | ||
453 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) | 458 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) |
454 | { | 459 | { |
455 | Incidence* inc; | 460 | Incidence* inc; |
456 | QPtrList<Incidence> Relations = relations(); | 461 | QPtrList<Incidence> Relations = relations(); |
457 | for (inc=Relations.first();inc;inc=Relations.next()) { | 462 | for (inc=Relations.first();inc;inc=Relations.next()) { |
458 | inc->addRelationsToList( rel ); | 463 | inc->addRelationsToList( rel ); |
459 | } | 464 | } |
460 | if ( rel->findRef( this ) == -1 ) | 465 | if ( rel->findRef( this ) == -1 ) |
461 | rel->append( this ); | 466 | rel->append( this ); |
462 | } | 467 | } |
463 | 468 | ||
464 | void Incidence::addRelation(Incidence *event) | 469 | void Incidence::addRelation(Incidence *event) |
465 | { | 470 | { |
466 | if( mRelations.findRef( event ) == -1 ) { | 471 | if( mRelations.findRef( event ) == -1 ) { |
467 | mRelations.append(event); | 472 | mRelations.append(event); |
468 | //updated(); | 473 | //updated(); |
469 | } | 474 | } |
470 | } | 475 | } |
471 | 476 | ||
472 | void Incidence::removeRelation(Incidence *event) | 477 | void Incidence::removeRelation(Incidence *event) |
473 | { | 478 | { |
474 | 479 | ||
475 | mRelations.removeRef(event); | 480 | mRelations.removeRef(event); |
476 | 481 | ||
477 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 482 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
478 | } | 483 | } |
479 | 484 | ||
480 | bool Incidence::recursOn(const QDate &qd) const | 485 | bool Incidence::recursOn(const QDate &qd) const |
481 | { | 486 | { |
482 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 487 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
483 | else return false; | 488 | else return false; |
484 | } | 489 | } |
485 | 490 | ||
486 | void Incidence::setExDates(const DateList &exDates) | 491 | void Incidence::setExDates(const DateList &exDates) |
487 | { | 492 | { |
488 | if (mReadOnly) return; | 493 | if (mReadOnly) return; |
489 | mExDates = exDates; | 494 | mExDates = exDates; |
490 | 495 | ||
491 | recurrence()->setRecurExDatesCount(mExDates.count()); | 496 | recurrence()->setRecurExDatesCount(mExDates.count()); |
492 | 497 | ||
493 | updated(); | 498 | updated(); |
494 | } | 499 | } |
495 | 500 | ||
496 | void Incidence::addExDate(const QDate &date) | 501 | void Incidence::addExDate(const QDate &date) |
497 | { | 502 | { |
498 | if (mReadOnly) return; | 503 | if (mReadOnly) return; |
499 | mExDates.append(date); | 504 | mExDates.append(date); |
500 | 505 | ||
501 | recurrence()->setRecurExDatesCount(mExDates.count()); | 506 | recurrence()->setRecurExDatesCount(mExDates.count()); |
502 | 507 | ||
503 | updated(); | 508 | updated(); |
504 | } | 509 | } |
505 | 510 | ||
506 | DateList Incidence::exDates() const | 511 | DateList Incidence::exDates() const |
507 | { | 512 | { |
508 | return mExDates; | 513 | return mExDates; |
509 | } | 514 | } |
510 | 515 | ||
511 | bool Incidence::isException(const QDate &date) const | 516 | bool Incidence::isException(const QDate &date) const |
512 | { | 517 | { |
513 | DateList::ConstIterator it; | 518 | DateList::ConstIterator it; |
514 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 519 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
515 | if ( (*it) == date ) { | 520 | if ( (*it) == date ) { |
516 | return true; | 521 | return true; |
517 | } | 522 | } |
518 | } | 523 | } |
519 | 524 | ||
520 | return false; | 525 | return false; |
521 | } | 526 | } |
522 | 527 | ||
523 | void Incidence::addAttachment(Attachment *attachment) | 528 | void Incidence::addAttachment(Attachment *attachment) |
524 | { | 529 | { |
525 | if (mReadOnly || !attachment) return; | 530 | if (mReadOnly || !attachment) return; |
526 | mAttachments.append(attachment); | 531 | mAttachments.append(attachment); |
527 | updated(); | 532 | updated(); |
528 | } | 533 | } |
529 | 534 | ||
530 | void Incidence::deleteAttachment(Attachment *attachment) | 535 | void Incidence::deleteAttachment(Attachment *attachment) |
531 | { | 536 | { |
532 | mAttachments.removeRef(attachment); | 537 | mAttachments.removeRef(attachment); |
533 | } | 538 | } |
534 | 539 | ||
535 | void Incidence::deleteAttachments(const QString& mime) | 540 | void Incidence::deleteAttachments(const QString& mime) |
536 | { | 541 | { |
537 | Attachment *at = mAttachments.first(); | 542 | Attachment *at = mAttachments.first(); |
538 | while (at) { | 543 | while (at) { |
539 | if (at->mimeType() == mime) | 544 | if (at->mimeType() == mime) |
540 | mAttachments.remove(); | 545 | mAttachments.remove(); |
541 | else | 546 | else |
542 | at = mAttachments.next(); | 547 | at = mAttachments.next(); |
543 | } | 548 | } |
544 | } | 549 | } |
545 | 550 | ||
546 | QPtrList<Attachment> Incidence::attachments() const | 551 | QPtrList<Attachment> Incidence::attachments() const |
547 | { | 552 | { |
548 | return mAttachments; | 553 | return mAttachments; |
549 | } | 554 | } |
550 | 555 | ||
551 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 556 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
552 | { | 557 | { |
553 | QPtrList<Attachment> attachments; | 558 | QPtrList<Attachment> attachments; |
554 | QPtrListIterator<Attachment> it( mAttachments ); | 559 | QPtrListIterator<Attachment> it( mAttachments ); |
555 | Attachment *at; | 560 | Attachment *at; |
556 | while ( (at = it.current()) ) { | 561 | while ( (at = it.current()) ) { |
557 | if (at->mimeType() == mime) | 562 | if (at->mimeType() == mime) |
558 | attachments.append(at); | 563 | attachments.append(at); |
559 | ++it; | 564 | ++it; |
560 | } | 565 | } |
561 | 566 | ||
562 | return attachments; | 567 | return attachments; |
563 | } | 568 | } |
564 | 569 | ||
565 | void Incidence::setResources(const QStringList &resources) | 570 | void Incidence::setResources(const QStringList &resources) |
566 | { | 571 | { |
567 | if (mReadOnly) return; | 572 | if (mReadOnly) return; |
568 | mResources = resources; | 573 | mResources = resources; |
569 | updated(); | 574 | updated(); |
570 | } | 575 | } |
571 | 576 | ||
572 | QStringList Incidence::resources() const | 577 | QStringList Incidence::resources() const |
573 | { | 578 | { |
574 | return mResources; | 579 | return mResources; |
575 | } | 580 | } |
576 | 581 | ||
577 | 582 | ||
578 | void Incidence::setPriority(int priority) | 583 | void Incidence::setPriority(int priority) |
579 | { | 584 | { |
580 | if (mReadOnly) return; | 585 | if (mReadOnly) return; |
581 | mPriority = priority; | 586 | mPriority = priority; |
582 | updated(); | 587 | updated(); |
583 | } | 588 | } |
584 | 589 | ||
585 | int Incidence::priority() const | 590 | int Incidence::priority() const |
586 | { | 591 | { |
587 | return mPriority; | 592 | return mPriority; |
588 | } | 593 | } |
589 | 594 | ||
590 | void Incidence::setSecrecy(int sec) | 595 | void Incidence::setSecrecy(int sec) |
591 | { | 596 | { |
592 | if (mReadOnly) return; | 597 | if (mReadOnly) return; |
593 | mSecrecy = sec; | 598 | mSecrecy = sec; |
594 | updated(); | 599 | updated(); |
595 | } | 600 | } |
596 | 601 | ||
597 | int Incidence::secrecy() const | 602 | int Incidence::secrecy() const |
598 | { | 603 | { |
599 | return mSecrecy; | 604 | return mSecrecy; |
600 | } | 605 | } |
601 | 606 | ||
602 | QString Incidence::secrecyStr() const | 607 | QString Incidence::secrecyStr() const |
603 | { | 608 | { |
604 | return secrecyName(mSecrecy); | 609 | return secrecyName(mSecrecy); |
605 | } | 610 | } |
606 | 611 | ||
607 | QString Incidence::secrecyName(int secrecy) | 612 | QString Incidence::secrecyName(int secrecy) |
608 | { | 613 | { |
609 | switch (secrecy) { | 614 | switch (secrecy) { |
610 | case SecrecyPublic: | 615 | case SecrecyPublic: |
611 | return i18n("Public"); | 616 | return i18n("Public"); |
612 | break; | 617 | break; |
613 | case SecrecyPrivate: | 618 | case SecrecyPrivate: |
614 | return i18n("Private"); | 619 | return i18n("Private"); |
615 | break; | 620 | break; |
616 | case SecrecyConfidential: | 621 | case SecrecyConfidential: |
617 | return i18n("Confidential"); | 622 | return i18n("Confidential"); |
618 | break; | 623 | break; |
619 | default: | 624 | default: |
620 | return i18n("Undefined"); | 625 | return i18n("Undefined"); |
621 | break; | 626 | break; |
622 | } | 627 | } |
623 | } | 628 | } |
624 | 629 | ||
625 | QStringList Incidence::secrecyList() | 630 | QStringList Incidence::secrecyList() |
626 | { | 631 | { |
627 | QStringList list; | 632 | QStringList list; |
628 | list << secrecyName(SecrecyPublic); | 633 | list << secrecyName(SecrecyPublic); |
629 | list << secrecyName(SecrecyPrivate); | 634 | list << secrecyName(SecrecyPrivate); |
630 | list << secrecyName(SecrecyConfidential); | 635 | list << secrecyName(SecrecyConfidential); |
631 | 636 | ||
632 | return list; | 637 | return list; |
633 | } | 638 | } |
634 | 639 | ||
635 | 640 | ||
636 | QPtrList<Alarm> Incidence::alarms() const | 641 | QPtrList<Alarm> Incidence::alarms() const |
637 | { | 642 | { |
638 | return mAlarms; | 643 | return mAlarms; |
639 | } | 644 | } |
640 | 645 | ||
641 | Alarm* Incidence::newAlarm() | 646 | Alarm* Incidence::newAlarm() |
642 | { | 647 | { |
643 | Alarm* alarm = new Alarm(this); | 648 | Alarm* alarm = new Alarm(this); |
644 | mAlarms.append(alarm); | 649 | mAlarms.append(alarm); |
645 | // updated(); | 650 | // updated(); |
646 | return alarm; | 651 | return alarm; |
647 | } | 652 | } |
648 | 653 | ||
649 | void Incidence::addAlarm(Alarm *alarm) | 654 | void Incidence::addAlarm(Alarm *alarm) |
650 | { | 655 | { |
651 | mAlarms.append(alarm); | 656 | mAlarms.append(alarm); |
652 | updated(); | 657 | updated(); |
653 | } | 658 | } |
654 | 659 | ||
655 | void Incidence::removeAlarm(Alarm *alarm) | 660 | void Incidence::removeAlarm(Alarm *alarm) |
656 | { | 661 | { |
657 | mAlarms.removeRef(alarm); | 662 | mAlarms.removeRef(alarm); |
658 | updated(); | 663 | updated(); |
659 | } | 664 | } |
660 | 665 | ||
661 | void Incidence::clearAlarms() | 666 | void Incidence::clearAlarms() |
662 | { | 667 | { |
663 | mAlarms.clear(); | 668 | mAlarms.clear(); |
664 | updated(); | 669 | updated(); |
665 | } | 670 | } |
666 | 671 | ||
667 | bool Incidence::isAlarmEnabled() const | 672 | bool Incidence::isAlarmEnabled() const |
668 | { | 673 | { |
669 | Alarm* alarm; | 674 | Alarm* alarm; |
670 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 675 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
671 | if (alarm->enabled()) | 676 | if (alarm->enabled()) |
672 | return true; | 677 | return true; |
673 | } | 678 | } |
674 | return false; | 679 | return false; |
675 | } | 680 | } |
676 | 681 | ||
677 | Recurrence *Incidence::recurrence() const | 682 | Recurrence *Incidence::recurrence() const |
678 | { | 683 | { |
679 | return mRecurrence; | 684 | return mRecurrence; |
680 | } | 685 | } |
681 | void Incidence::setRecurrence( Recurrence * r) | 686 | void Incidence::setRecurrence( Recurrence * r) |
682 | { | 687 | { |
683 | delete mRecurrence; | 688 | delete mRecurrence; |
684 | mRecurrence = r; | 689 | mRecurrence = r; |
685 | } | 690 | } |
686 | 691 | ||
687 | void Incidence::setLocation(const QString &location) | 692 | void Incidence::setLocation(const QString &location) |
688 | { | 693 | { |
689 | if (mReadOnly) return; | 694 | if (mReadOnly) return; |
690 | mLocation = location; | 695 | mLocation = location; |
691 | updated(); | 696 | updated(); |
692 | } | 697 | } |
693 | 698 | ||
694 | QString Incidence::location() const | 699 | QString Incidence::location() const |
695 | { | 700 | { |
696 | return mLocation; | 701 | return mLocation; |
697 | } | 702 | } |
698 | 703 | ||
699 | ushort Incidence::doesRecur() const | 704 | ushort Incidence::doesRecur() const |
700 | { | 705 | { |
701 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 706 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
702 | else return Recurrence::rNone; | 707 | else return Recurrence::rNone; |
703 | } | 708 | } |
704 | 709 | ||
705 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 710 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
706 | { | 711 | { |
707 | QDateTime incidenceStart = dt; | 712 | QDateTime incidenceStart = dt; |
708 | *ok = false; | 713 | *ok = false; |
709 | if ( doesRecur() ) { | 714 | if ( doesRecur() ) { |
710 | bool last; | 715 | bool last; |
711 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 716 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
712 | int count = 0; | 717 | int count = 0; |
713 | if ( !last ) { | 718 | if ( !last ) { |
714 | while ( !last ) { | 719 | while ( !last ) { |
715 | ++count; | 720 | ++count; |
716 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 721 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
717 | if ( recursOn( incidenceStart.date() ) ) { | 722 | if ( recursOn( incidenceStart.date() ) ) { |
718 | last = true; // exit while llop | 723 | last = true; // exit while llop |
719 | } else { | 724 | } else { |
720 | if ( last ) { // no alarm on last recurrence | 725 | if ( last ) { // no alarm on last recurrence |
721 | return QDateTime (); | 726 | return QDateTime (); |
722 | } | 727 | } |
723 | int year = incidenceStart.date().year(); | 728 | int year = incidenceStart.date().year(); |
724 | // workaround for bug in recurrence | 729 | // workaround for bug in recurrence |
725 | if ( count == 100 || year < 1000 || year > 5000 ) { | 730 | if ( count == 100 || year < 1000 || year > 5000 ) { |
726 | return QDateTime (); | 731 | return QDateTime (); |
727 | } | 732 | } |
728 | incidenceStart = incidenceStart.addSecs( 1 ); | 733 | incidenceStart = incidenceStart.addSecs( 1 ); |
729 | } | 734 | } |
730 | } | 735 | } |
731 | } else { | 736 | } else { |
732 | return QDateTime (); | 737 | return QDateTime (); |
733 | } | 738 | } |
734 | } else { | 739 | } else { |
735 | if ( hasStartDate () ) { | 740 | if ( hasStartDate () ) { |
736 | incidenceStart = dtStart(); | 741 | incidenceStart = dtStart(); |
737 | } | 742 | } |
738 | if ( typeID() == todoID ) { | 743 | if ( typeID() == todoID ) { |
739 | if ( ((Todo*)this)->hasDueDate() ) | 744 | if ( ((Todo*)this)->hasDueDate() ) |
740 | incidenceStart = ((Todo*)this)->dtDue(); | 745 | incidenceStart = ((Todo*)this)->dtDue(); |
741 | } | 746 | } |
742 | } | 747 | } |
743 | if ( incidenceStart > dt ) | 748 | if ( incidenceStart > dt ) |
744 | *ok = true; | 749 | *ok = true; |
745 | return incidenceStart; | 750 | return incidenceStart; |
746 | } | 751 | } |
747 | QDateTime Incidence::dtStart() const | 752 | QDateTime Incidence::dtStart() const |
748 | { | 753 | { |
749 | if ( doesRecur() ) { | 754 | if ( doesRecur() ) { |
750 | if ( typeID() == todoID ) { | 755 | if ( typeID() == todoID ) { |
751 | ((Todo*)this)->checkSetCompletedFalse(); | 756 | ((Todo*)this)->checkSetCompletedFalse(); |
752 | } | 757 | } |
753 | } | 758 | } |
754 | return mDtStart; | 759 | return mDtStart; |
755 | } | 760 | } |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index fc97ce9..c88ba2f 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -1,317 +1,318 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | #ifndef INCIDENCE_H | 20 | #ifndef INCIDENCE_H |
21 | #define INCIDENCE_H | 21 | #define INCIDENCE_H |
22 | // | 22 | // |
23 | // Incidence - base class of calendaring components | 23 | // Incidence - base class of calendaring components |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | #include "recurrence.h" | 30 | #include "recurrence.h" |
31 | #include "alarm.h" | 31 | #include "alarm.h" |
32 | #include "attachment.h" | 32 | #include "attachment.h" |
33 | #include "listbase.h" | 33 | #include "listbase.h" |
34 | #include "incidencebase.h" | 34 | #include "incidencebase.h" |
35 | 35 | ||
36 | namespace KCal { | 36 | namespace KCal { |
37 | 37 | ||
38 | class Event; | 38 | class Event; |
39 | class Todo; | 39 | class Todo; |
40 | class Journal; | 40 | class Journal; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | This class provides the base class common to all calendar components. | 43 | This class provides the base class common to all calendar components. |
44 | */ | 44 | */ |
45 | class Incidence : public IncidenceBase | 45 | class Incidence : public IncidenceBase |
46 | { | 46 | { |
47 | public: | 47 | public: |
48 | /** | 48 | /** |
49 | This class provides the interface for a visitor of calendar components. It | 49 | This class provides the interface for a visitor of calendar components. It |
50 | serves as base class for concrete visitors, which implement certain actions on | 50 | serves as base class for concrete visitors, which implement certain actions on |
51 | calendar components. It allows to add functions, which operate on the concrete | 51 | calendar components. It allows to add functions, which operate on the concrete |
52 | types of calendar components, without changing the calendar component classes. | 52 | types of calendar components, without changing the calendar component classes. |
53 | */ | 53 | */ |
54 | class Visitor | 54 | class Visitor |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | /** Destruct Incidence::Visitor */ | 57 | /** Destruct Incidence::Visitor */ |
58 | virtual ~Visitor() {} | 58 | virtual ~Visitor() {} |
59 | 59 | ||
60 | /** | 60 | /** |
61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
62 | on an Event object. | 62 | on an Event object. |
63 | */ | 63 | */ |
64 | virtual bool visit(Event *) { return false; } | 64 | virtual bool visit(Event *) { return false; } |
65 | /** | 65 | /** |
66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
67 | on an Todo object. | 67 | on an Todo object. |
68 | */ | 68 | */ |
69 | virtual bool visit(Todo *) { return false; } | 69 | virtual bool visit(Todo *) { return false; } |
70 | /** | 70 | /** |
71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
72 | on an Journal object. | 72 | on an Journal object. |
73 | */ | 73 | */ |
74 | virtual bool visit(Journal *) { return false; } | 74 | virtual bool visit(Journal *) { return false; } |
75 | 75 | ||
76 | protected: | 76 | protected: |
77 | /** Constructor is protected to prevent direct creation of visitor base class. */ | 77 | /** Constructor is protected to prevent direct creation of visitor base class. */ |
78 | Visitor() {} | 78 | Visitor() {} |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | This class implements a visitor for adding an Incidence to a resource | 82 | This class implements a visitor for adding an Incidence to a resource |
83 | supporting addEvent(), addTodo() and addJournal() calls. | 83 | supporting addEvent(), addTodo() and addJournal() calls. |
84 | */ | 84 | */ |
85 | template<class T> | 85 | template<class T> |
86 | class AddVisitor : public Visitor | 86 | class AddVisitor : public Visitor |
87 | { | 87 | { |
88 | public: | 88 | public: |
89 | AddVisitor( T *r ) : mResource( r ) {} | 89 | AddVisitor( T *r ) : mResource( r ) {} |
90 | bool visit( Event *e ) { return mResource->addEvent( e ); } | 90 | bool visit( Event *e ) { return mResource->addEvent( e ); } |
91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } | 91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } |
92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } | 92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } |
93 | 93 | ||
94 | private: | 94 | private: |
95 | T *mResource; | 95 | T *mResource; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | /** enumeration for describing an event's secrecy. */ | 98 | /** enumeration for describing an event's secrecy. */ |
99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; | 99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; |
100 | typedef ListBase<Incidence> List; | 100 | typedef ListBase<Incidence> List; |
101 | Incidence(); | 101 | Incidence(); |
102 | Incidence(const Incidence &); | 102 | Incidence(const Incidence &); |
103 | ~Incidence(); | 103 | ~Incidence(); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to | 106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to |
107 | provide this implementation: | 107 | provide this implementation: |
108 | <pre> | 108 | <pre> |
109 | bool accept(Visitor &v) { return v.visit(this); } | 109 | bool accept(Visitor &v) { return v.visit(this); } |
110 | </pre> | 110 | </pre> |
111 | */ | 111 | */ |
112 | virtual bool accept(Visitor &) { return false; } | 112 | virtual bool accept(Visitor &) { return false; } |
113 | 113 | ||
114 | virtual Incidence *clone() = 0; | 114 | virtual Incidence *clone() = 0; |
115 | virtual void cloneRelations( Incidence * ); | 115 | virtual void cloneRelations( Incidence * ); |
116 | void addRelationsToList(QPtrList<Incidence> *rel); | 116 | void addRelationsToList(QPtrList<Incidence> *rel); |
117 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; | 117 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; |
118 | void setReadOnly( bool ); | 118 | void setReadOnly( bool ); |
119 | 119 | ||
120 | /** | 120 | /** |
121 | Recreate event. The event is made a new unique event, but already stored | 121 | Recreate event. The event is made a new unique event, but already stored |
122 | event information is preserved. Sets uniquie id, creation date, last | 122 | event information is preserved. Sets uniquie id, creation date, last |
123 | modification date and revision number. | 123 | modification date and revision number. |
124 | */ | 124 | */ |
125 | void recreate(); | 125 | void recreate(); |
126 | Incidence* recreateCloneException(QDate); | 126 | Incidence* recreateCloneException(QDate); |
127 | 127 | ||
128 | /** set creation date */ | 128 | /** set creation date */ |
129 | void setCreated(QDateTime); | 129 | void setCreated(QDateTime); |
130 | /** return time and date of creation. */ | 130 | /** return time and date of creation. */ |
131 | QDateTime created() const; | 131 | QDateTime created() const; |
132 | 132 | ||
133 | /** set the number of revisions this event has seen */ | 133 | /** set the number of revisions this event has seen */ |
134 | void setRevision(int rev); | 134 | void setRevision(int rev); |
135 | /** return the number of revisions this event has seen */ | 135 | /** return the number of revisions this event has seen */ |
136 | int revision() const; | 136 | int revision() const; |
137 | 137 | ||
138 | /** Set starting date/time. */ | 138 | /** Set starting date/time. */ |
139 | virtual void setDtStart(const QDateTime &dtStart); | 139 | virtual void setDtStart(const QDateTime &dtStart); |
140 | /** Return the incidence's ending date/time as a QDateTime. */ | 140 | /** Return the incidence's ending date/time as a QDateTime. */ |
141 | virtual QDateTime dtEnd() const { return QDateTime(); } | 141 | virtual QDateTime dtEnd() const { return QDateTime(); } |
142 | 142 | ||
143 | /** sets the event's lengthy description. */ | 143 | /** sets the event's lengthy description. */ |
144 | void setDescription(const QString &description); | 144 | void setDescription(const QString &description); |
145 | /** returns a reference to the event's description. */ | 145 | /** returns a reference to the event's description. */ |
146 | QString description() const; | 146 | QString description() const; |
147 | 147 | ||
148 | /** sets the event's short summary. */ | 148 | /** sets the event's short summary. */ |
149 | void setSummary(const QString &summary); | 149 | void setSummary(const QString &summary); |
150 | /** returns a reference to the event's summary. */ | 150 | /** returns a reference to the event's summary. */ |
151 | QString summary() const; | 151 | QString summary() const; |
152 | 152 | ||
153 | /** set event's applicable categories */ | 153 | /** set event's applicable categories */ |
154 | void setCategories(const QStringList &categories, bool setForRelations = false); | 154 | void setCategories(const QStringList &categories, bool setForRelations = false); |
155 | void addCategories(const QStringList &categories, bool addToRelations = false); | 155 | void addCategories(const QStringList &categories, bool addToRelations = false); |
156 | /** set event's categories based on a comma delimited string */ | 156 | /** set event's categories based on a comma delimited string */ |
157 | void setCategories(const QString &catStr); | 157 | void setCategories(const QString &catStr); |
158 | /** return categories in a list */ | 158 | /** return categories in a list */ |
159 | QStringList categories() const; | 159 | QStringList categories() const; |
160 | QStringList* categoriesP(); | ||
160 | /** return categories as a comma separated string */ | 161 | /** return categories as a comma separated string */ |
161 | QString categoriesStr(); | 162 | QString categoriesStr(); |
162 | QString categoriesStrWithSpace(); | 163 | QString categoriesStrWithSpace(); |
163 | 164 | ||
164 | /** point at some other event to which the event relates. This function should | 165 | /** point at some other event to which the event relates. This function should |
165 | * only be used when constructing a calendar before the related Event | 166 | * only be used when constructing a calendar before the related Event |
166 | * exists. */ | 167 | * exists. */ |
167 | void setRelatedToUid(const QString &); | 168 | void setRelatedToUid(const QString &); |
168 | /** what event does this one relate to? This function should | 169 | /** what event does this one relate to? This function should |
169 | * only be used when constructing a calendar before the related Event | 170 | * only be used when constructing a calendar before the related Event |
170 | * exists. */ | 171 | * exists. */ |
171 | QString relatedToUid() const; | 172 | QString relatedToUid() const; |
172 | /** point at some other event to which the event relates */ | 173 | /** point at some other event to which the event relates */ |
173 | void setRelatedTo(Incidence *relatedTo); | 174 | void setRelatedTo(Incidence *relatedTo); |
174 | /** what event does this one relate to? */ | 175 | /** what event does this one relate to? */ |
175 | Incidence *relatedTo() const; | 176 | Incidence *relatedTo() const; |
176 | /** All events that are related to this event */ | 177 | /** All events that are related to this event */ |
177 | QPtrList<Incidence> relations() const; | 178 | QPtrList<Incidence> relations() const; |
178 | /** Add an event which is related to this event */ | 179 | /** Add an event which is related to this event */ |
179 | void addRelation(Incidence *); | 180 | void addRelation(Incidence *); |
180 | /** Remove event that is related to this event */ | 181 | /** Remove event that is related to this event */ |
181 | void removeRelation(Incidence *); | 182 | void removeRelation(Incidence *); |
182 | 183 | ||
183 | /** returns the list of dates which are exceptions to the recurrence rule */ | 184 | /** returns the list of dates which are exceptions to the recurrence rule */ |
184 | DateList exDates() const; | 185 | DateList exDates() const; |
185 | /** sets the list of dates which are exceptions to the recurrence rule */ | 186 | /** sets the list of dates which are exceptions to the recurrence rule */ |
186 | void setExDates(const DateList &_exDates); | 187 | void setExDates(const DateList &_exDates); |
187 | void setExDates(const char *dates); | 188 | void setExDates(const char *dates); |
188 | /** Add a date to the list of exceptions of the recurrence rule. */ | 189 | /** Add a date to the list of exceptions of the recurrence rule. */ |
189 | void addExDate(const QDate &date); | 190 | void addExDate(const QDate &date); |
190 | 191 | ||
191 | /** returns true if there is an exception for this date in the recurrence | 192 | /** returns true if there is an exception for this date in the recurrence |
192 | rule set, or false otherwise. */ | 193 | rule set, or false otherwise. */ |
193 | bool isException(const QDate &qd) const; | 194 | bool isException(const QDate &qd) const; |
194 | 195 | ||
195 | /** add attachment to this event */ | 196 | /** add attachment to this event */ |
196 | void addAttachment(Attachment *attachment); | 197 | void addAttachment(Attachment *attachment); |
197 | /** remove and delete a specific attachment */ | 198 | /** remove and delete a specific attachment */ |
198 | void deleteAttachment(Attachment *attachment); | 199 | void deleteAttachment(Attachment *attachment); |
199 | /** remove and delete all attachments with this mime type */ | 200 | /** remove and delete all attachments with this mime type */ |
200 | void deleteAttachments(const QString& mime); | 201 | void deleteAttachments(const QString& mime); |
201 | /** return list of all associated attachments */ | 202 | /** return list of all associated attachments */ |
202 | QPtrList<Attachment> attachments() const; | 203 | QPtrList<Attachment> attachments() const; |
203 | /** find a list of attachments with this mime type */ | 204 | /** find a list of attachments with this mime type */ |
204 | QPtrList<Attachment> attachments(const QString& mime) const; | 205 | QPtrList<Attachment> attachments(const QString& mime) const; |
205 | 206 | ||
206 | /** sets the event's status the value specified. See the enumeration | 207 | /** sets the event's status the value specified. See the enumeration |
207 | * above for possible values. */ | 208 | * above for possible values. */ |
208 | void setSecrecy(int); | 209 | void setSecrecy(int); |
209 | /** return the event's secrecy. */ | 210 | /** return the event's secrecy. */ |
210 | int secrecy() const; | 211 | int secrecy() const; |
211 | /** return the event's secrecy in string format. */ | 212 | /** return the event's secrecy in string format. */ |
212 | QString secrecyStr() const; | 213 | QString secrecyStr() const; |
213 | /** return list of all availbale secrecy classes */ | 214 | /** return list of all availbale secrecy classes */ |
214 | static QStringList secrecyList(); | 215 | static QStringList secrecyList(); |
215 | /** return human-readable name of secrecy class */ | 216 | /** return human-readable name of secrecy class */ |
216 | static QString secrecyName(int); | 217 | static QString secrecyName(int); |
217 | 218 | ||
218 | /** returns TRUE if the date specified is one on which the event will | 219 | /** returns TRUE if the date specified is one on which the event will |
219 | * recur. */ | 220 | * recur. */ |
220 | bool recursOn(const QDate &qd) const; | 221 | bool recursOn(const QDate &qd) const; |
221 | 222 | ||
222 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): | 223 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): |
223 | 224 | ||
224 | /** set resources used, such as Office, Car, etc. */ | 225 | /** set resources used, such as Office, Car, etc. */ |
225 | void setResources(const QStringList &resources); | 226 | void setResources(const QStringList &resources); |
226 | /** return list of current resources */ | 227 | /** return list of current resources */ |
227 | QStringList resources() const; | 228 | QStringList resources() const; |
228 | 229 | ||
229 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ | 230 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ |
230 | void setPriority(int priority); | 231 | void setPriority(int priority); |
231 | /** get the event's priority */ | 232 | /** get the event's priority */ |
232 | int priority() const; | 233 | int priority() const; |
233 | 234 | ||
234 | /** All alarms that are associated with this incidence */ | 235 | /** All alarms that are associated with this incidence */ |
235 | QPtrList<Alarm> alarms() const; | 236 | QPtrList<Alarm> alarms() const; |
236 | /** Create a new alarm which is associated with this incidence */ | 237 | /** Create a new alarm which is associated with this incidence */ |
237 | Alarm* newAlarm(); | 238 | Alarm* newAlarm(); |
238 | /** Add an alarm which is associated with this incidence */ | 239 | /** Add an alarm which is associated with this incidence */ |
239 | void addAlarm(Alarm*); | 240 | void addAlarm(Alarm*); |
240 | /** Remove an alarm that is associated with this incidence */ | 241 | /** Remove an alarm that is associated with this incidence */ |
241 | void removeAlarm(Alarm*); | 242 | void removeAlarm(Alarm*); |
242 | /** Remove all alarms that are associated with this incidence */ | 243 | /** Remove all alarms that are associated with this incidence */ |
243 | void clearAlarms(); | 244 | void clearAlarms(); |
244 | /** return whether any alarm associated with this incidence is enabled */ | 245 | /** return whether any alarm associated with this incidence is enabled */ |
245 | bool isAlarmEnabled() const; | 246 | bool isAlarmEnabled() const; |
246 | 247 | ||
247 | /** | 248 | /** |
248 | Return the recurrence rule associated with this incidence. If there is | 249 | Return the recurrence rule associated with this incidence. If there is |
249 | none, returns an appropriate (non-0) object. | 250 | none, returns an appropriate (non-0) object. |
250 | */ | 251 | */ |
251 | Recurrence *recurrence() const; | 252 | Recurrence *recurrence() const; |
252 | void setRecurrence(Recurrence * r); | 253 | void setRecurrence(Recurrence * r); |
253 | /** | 254 | /** |
254 | Forward to Recurrence::doesRecur(). | 255 | Forward to Recurrence::doesRecur(). |
255 | */ | 256 | */ |
256 | ushort doesRecur() const; | 257 | ushort doesRecur() const; |
257 | 258 | ||
258 | /** set the event's/todo's location. Do _not_ use it with journal */ | 259 | /** set the event's/todo's location. Do _not_ use it with journal */ |
259 | void setLocation(const QString &location); | 260 | void setLocation(const QString &location); |
260 | /** return the event's/todo's location. Do _not_ use it with journal */ | 261 | /** return the event's/todo's location. Do _not_ use it with journal */ |
261 | QString location() const; | 262 | QString location() const; |
262 | /** returns TRUE or FALSE depending on whether the todo has a start date */ | 263 | /** returns TRUE or FALSE depending on whether the todo has a start date */ |
263 | bool hasStartDate() const; | 264 | bool hasStartDate() const; |
264 | /** sets the event's hasStartDate value. */ | 265 | /** sets the event's hasStartDate value. */ |
265 | void setHasStartDate(bool f); | 266 | void setHasStartDate(bool f); |
266 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; | 267 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; |
267 | bool cancelled() const; | 268 | bool cancelled() const; |
268 | void setCancelled( bool b ); | 269 | void setCancelled( bool b ); |
269 | 270 | ||
270 | bool hasRecurrenceID() const; | 271 | bool hasRecurrenceID() const; |
271 | void setHasRecurrenceID( bool b ); | 272 | void setHasRecurrenceID( bool b ); |
272 | 273 | ||
273 | void setRecurrenceID(QDateTime); | 274 | void setRecurrenceID(QDateTime); |
274 | QDateTime recurrenceID () const; | 275 | QDateTime recurrenceID () const; |
275 | QDateTime dtStart() const; | 276 | QDateTime dtStart() const; |
276 | bool isHoliday() const; | 277 | bool isHoliday() const; |
277 | bool isBirthday() const; | 278 | bool isBirthday() const; |
278 | bool isAnniversary() const; | 279 | bool isAnniversary() const; |
279 | 280 | ||
280 | 281 | ||
281 | protected: | 282 | protected: |
282 | QPtrList<Alarm> mAlarms; | 283 | QPtrList<Alarm> mAlarms; |
283 | QPtrList<Incidence> mRelations; | 284 | QPtrList<Incidence> mRelations; |
284 | QDateTime mRecurrenceID; | 285 | QDateTime mRecurrenceID; |
285 | bool mHasRecurrenceID; | 286 | bool mHasRecurrenceID; |
286 | private: | 287 | private: |
287 | void checkCategories(); | 288 | void checkCategories(); |
288 | bool mHoliday, mBirthday, mAnniversary; | 289 | bool mHoliday, mBirthday, mAnniversary; |
289 | int mRevision; | 290 | int mRevision; |
290 | bool mCancelled; | 291 | bool mCancelled; |
291 | 292 | ||
292 | // base components of jounal, event and todo | 293 | // base components of jounal, event and todo |
293 | QDateTime mCreated; | 294 | QDateTime mCreated; |
294 | QString mDescription; | 295 | QString mDescription; |
295 | QString mSummary; | 296 | QString mSummary; |
296 | QStringList mCategories; | 297 | QStringList mCategories; |
297 | Incidence *mRelatedTo; | 298 | Incidence *mRelatedTo; |
298 | QString mRelatedToUid; | 299 | QString mRelatedToUid; |
299 | DateList mExDates; | 300 | DateList mExDates; |
300 | QPtrList<Attachment> mAttachments; | 301 | QPtrList<Attachment> mAttachments; |
301 | QStringList mResources; | 302 | QStringList mResources; |
302 | bool mHasStartDate; // if todo has associated start date | 303 | bool mHasStartDate; // if todo has associated start date |
303 | 304 | ||
304 | int mSecrecy; | 305 | int mSecrecy; |
305 | int mPriority; // 1 = highest, 2 = less, etc. | 306 | int mPriority; // 1 = highest, 2 = less, etc. |
306 | 307 | ||
307 | //QPtrList<Alarm> mAlarms; | 308 | //QPtrList<Alarm> mAlarms; |
308 | Recurrence *mRecurrence; | 309 | Recurrence *mRecurrence; |
309 | 310 | ||
310 | QString mLocation; | 311 | QString mLocation; |
311 | }; | 312 | }; |
312 | 313 | ||
313 | bool operator==( const Incidence&, const Incidence& ); | 314 | bool operator==( const Incidence&, const Incidence& ); |
314 | 315 | ||
315 | } | 316 | } |
316 | 317 | ||
317 | #endif | 318 | #endif |