author | zautrix <zautrix> | 2005-04-15 20:51:58 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-15 20:51:58 (UTC) |
commit | 85bdc33419eef0ffa9f00eb7222944518fe39b6c (patch) (unidiff) | |
tree | 57000de41f5e29c5ebd07f3ed2951a7b89730fb1 /libkcal | |
parent | e1d62b2afac2b625a3e0b8d4df137647de34e04f (diff) | |
download | kdepimpi-85bdc33419eef0ffa9f00eb7222944518fe39b6c.zip kdepimpi-85bdc33419eef0ffa9f00eb7222944518fe39b6c.tar.gz kdepimpi-85bdc33419eef0ffa9f00eb7222944518fe39b6c.tar.bz2 |
fixxx
-rw-r--r-- | libkcal/calendarlocal.cpp | 4 | ||||
-rw-r--r-- | libkcal/todo.cpp | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 00a43e5..e75df70 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,726 +1,730 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | |||
86 | Todo * i; | ||
87 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | ||
88 | |||
85 | mEventList.setAutoDelete( true ); | 89 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 90 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 91 | mJournalList.setAutoDelete( false ); |
88 | 92 | ||
89 | mEventList.clear(); | 93 | mEventList.clear(); |
90 | mTodoList.clear(); | 94 | mTodoList.clear(); |
91 | mJournalList.clear(); | 95 | mJournalList.clear(); |
92 | 96 | ||
93 | mEventList.setAutoDelete( false ); | 97 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 98 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 99 | mJournalList.setAutoDelete( false ); |
96 | 100 | ||
97 | setModified( false ); | 101 | setModified( false ); |
98 | } | 102 | } |
99 | 103 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 104 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 105 | { |
102 | QString cat; | 106 | QString cat; |
103 | bool isBirthday = true; | 107 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 108 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 109 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 110 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 111 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 112 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 113 | cat = i18n( "Birthday" ); |
110 | } else { | 114 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 115 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 116 | return false; |
113 | } | 117 | } |
114 | Event * eve; | 118 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 119 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 120 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 121 | continue; |
118 | // now we have an event with fitting category | 122 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 123 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 124 | continue; |
121 | // now we have an event with fitting category+date | 125 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 126 | if ( eve->summary() != event->summary() ) |
123 | continue; | 127 | continue; |
124 | // now we have an event with fitting category+date+summary | 128 | // now we have an event with fitting category+date+summary |
125 | return false; | 129 | return false; |
126 | } | 130 | } |
127 | return addEvent( event ); | 131 | return addEvent( event ); |
128 | 132 | ||
129 | } | 133 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 134 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 135 | { |
132 | Event * eve; | 136 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 137 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 138 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 139 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 140 | return false; |
137 | } | 141 | } |
138 | } | 142 | } |
139 | return addEvent( event ); | 143 | return addEvent( event ); |
140 | } | 144 | } |
141 | 145 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 146 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 147 | { |
144 | insertEvent( event ); | 148 | insertEvent( event ); |
145 | 149 | ||
146 | event->registerObserver( this ); | 150 | event->registerObserver( this ); |
147 | 151 | ||
148 | setModified( true ); | 152 | setModified( true ); |
149 | 153 | ||
150 | return true; | 154 | return true; |
151 | } | 155 | } |
152 | 156 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 157 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 158 | { |
155 | if ( mUndoIncidence ) delete mUndoIncidence; | 159 | if ( mUndoIncidence ) delete mUndoIncidence; |
156 | mUndoIncidence = event->clone(); | 160 | mUndoIncidence = event->clone(); |
157 | if ( mEventList.removeRef( event ) ) { | 161 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 162 | setModified( true ); |
159 | } | 163 | } |
160 | } | 164 | } |
161 | 165 | ||
162 | 166 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 167 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 168 | { |
165 | 169 | ||
166 | Event *event; | 170 | Event *event; |
167 | 171 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 172 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 173 | if ( event->uid() == uid ) { |
170 | return event; | 174 | return event; |
171 | } | 175 | } |
172 | } | 176 | } |
173 | 177 | ||
174 | return 0; | 178 | return 0; |
175 | } | 179 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 180 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 181 | { |
178 | Todo * eve; | 182 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 183 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 184 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 185 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 186 | return false; |
183 | } | 187 | } |
184 | } | 188 | } |
185 | return addTodo( todo ); | 189 | return addTodo( todo ); |
186 | } | 190 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 191 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 192 | { |
189 | mTodoList.append( todo ); | 193 | mTodoList.append( todo ); |
190 | 194 | ||
191 | todo->registerObserver( this ); | 195 | todo->registerObserver( this ); |
192 | 196 | ||
193 | // Set up subtask relations | 197 | // Set up subtask relations |
194 | setupRelations( todo ); | 198 | setupRelations( todo ); |
195 | 199 | ||
196 | setModified( true ); | 200 | setModified( true ); |
197 | 201 | ||
198 | return true; | 202 | return true; |
199 | } | 203 | } |
200 | 204 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 205 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 206 | { |
203 | // Handle orphaned children | 207 | // Handle orphaned children |
204 | if ( mUndoIncidence ) delete mUndoIncidence; | 208 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | removeRelations( todo ); | 209 | removeRelations( todo ); |
206 | mUndoIncidence = todo->clone(); | 210 | mUndoIncidence = todo->clone(); |
207 | 211 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 212 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 213 | setModified( true ); |
210 | } | 214 | } |
211 | } | 215 | } |
212 | 216 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 217 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 218 | { |
215 | return mTodoList; | 219 | return mTodoList; |
216 | } | 220 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 221 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 222 | { |
219 | Todo *todo; | 223 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 224 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 225 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 226 | } |
223 | 227 | ||
224 | return 0; | 228 | return 0; |
225 | } | 229 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 230 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 231 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 232 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 233 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 234 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 235 | inc->removeID( syncProfile ); |
232 | } | 236 | } |
233 | if ( syncProfile.isEmpty() ) { | 237 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 238 | QPtrList<Event> el; |
235 | Event *todo; | 239 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 240 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 241 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 242 | el.append( todo ); |
239 | } | 243 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 244 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 245 | deleteIncidence ( todo ); |
242 | } | 246 | } |
243 | } else { | 247 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 248 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | if ( lse ) | 249 | if ( lse ) |
246 | deleteIncidence ( lse ); | 250 | deleteIncidence ( lse ); |
247 | } | 251 | } |
248 | } | 252 | } |
249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 253 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
250 | { | 254 | { |
251 | QPtrList<Event> el; | 255 | QPtrList<Event> el; |
252 | Event *todo; | 256 | Event *todo; |
253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 257 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 258 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
255 | if ( todo->summary().left(3) == "E: " ) | 259 | if ( todo->summary().left(3) == "E: " ) |
256 | el.append( todo ); | 260 | el.append( todo ); |
257 | } | 261 | } |
258 | 262 | ||
259 | return el; | 263 | return el; |
260 | 264 | ||
261 | } | 265 | } |
262 | Event *CalendarLocal::event( QString syncProf, QString id ) | 266 | Event *CalendarLocal::event( QString syncProf, QString id ) |
263 | { | 267 | { |
264 | Event *todo; | 268 | Event *todo; |
265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 269 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
266 | if ( todo->getID( syncProf ) == id ) return todo; | 270 | if ( todo->getID( syncProf ) == id ) return todo; |
267 | } | 271 | } |
268 | 272 | ||
269 | return 0; | 273 | return 0; |
270 | } | 274 | } |
271 | Todo *CalendarLocal::todo( const QString &uid ) | 275 | Todo *CalendarLocal::todo( const QString &uid ) |
272 | { | 276 | { |
273 | Todo *todo; | 277 | Todo *todo; |
274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 278 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
275 | if ( todo->uid() == uid ) return todo; | 279 | if ( todo->uid() == uid ) return todo; |
276 | } | 280 | } |
277 | 281 | ||
278 | return 0; | 282 | return 0; |
279 | } | 283 | } |
280 | QString CalendarLocal::nextSummary() const | 284 | QString CalendarLocal::nextSummary() const |
281 | { | 285 | { |
282 | return mNextSummary; | 286 | return mNextSummary; |
283 | } | 287 | } |
284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 288 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
285 | { | 289 | { |
286 | return mNextAlarmEventDateTime; | 290 | return mNextAlarmEventDateTime; |
287 | } | 291 | } |
288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 292 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
289 | { | 293 | { |
290 | //mNextAlarmIncidence | 294 | //mNextAlarmIncidence |
291 | //mNextAlarmDateTime | 295 | //mNextAlarmDateTime |
292 | //return mNextSummary; | 296 | //return mNextSummary; |
293 | //return mNextAlarmEventDateTime; | 297 | //return mNextAlarmEventDateTime; |
294 | bool newNextAlarm = false; | 298 | bool newNextAlarm = false; |
295 | bool computeNextAlarm = false; | 299 | bool computeNextAlarm = false; |
296 | bool ok; | 300 | bool ok; |
297 | int offset; | 301 | int offset; |
298 | QDateTime nextA; | 302 | QDateTime nextA; |
299 | // QString nextSum; | 303 | // QString nextSum; |
300 | //QDateTime nextEvent; | 304 | //QDateTime nextEvent; |
301 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 305 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
302 | computeNextAlarm = true; | 306 | computeNextAlarm = true; |
303 | } else { | 307 | } else { |
304 | if ( ! deleted ) { | 308 | if ( ! deleted ) { |
305 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 309 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
306 | if ( ok ) { | 310 | if ( ok ) { |
307 | if ( nextA < mNextAlarmDateTime ) { | 311 | if ( nextA < mNextAlarmDateTime ) { |
308 | deRegisterAlarm(); | 312 | deRegisterAlarm(); |
309 | mNextAlarmDateTime = nextA; | 313 | mNextAlarmDateTime = nextA; |
310 | mNextSummary = incidence->summary(); | 314 | mNextSummary = incidence->summary(); |
311 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 315 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
312 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 316 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
313 | newNextAlarm = true; | 317 | newNextAlarm = true; |
314 | mNextAlarmIncidence = incidence; | 318 | mNextAlarmIncidence = incidence; |
315 | } else { | 319 | } else { |
316 | if ( incidence == mNextAlarmIncidence ) { | 320 | if ( incidence == mNextAlarmIncidence ) { |
317 | computeNextAlarm = true; | 321 | computeNextAlarm = true; |
318 | } | 322 | } |
319 | } | 323 | } |
320 | } else { | 324 | } else { |
321 | if ( mNextAlarmIncidence == incidence ) { | 325 | if ( mNextAlarmIncidence == incidence ) { |
322 | computeNextAlarm = true; | 326 | computeNextAlarm = true; |
323 | } | 327 | } |
324 | } | 328 | } |
325 | } else { // deleted | 329 | } else { // deleted |
326 | if ( incidence == mNextAlarmIncidence ) { | 330 | if ( incidence == mNextAlarmIncidence ) { |
327 | computeNextAlarm = true; | 331 | computeNextAlarm = true; |
328 | } | 332 | } |
329 | } | 333 | } |
330 | } | 334 | } |
331 | if ( computeNextAlarm ) { | 335 | if ( computeNextAlarm ) { |
332 | deRegisterAlarm(); | 336 | deRegisterAlarm(); |
333 | nextA = nextAlarm( 1000 ); | 337 | nextA = nextAlarm( 1000 ); |
334 | if (! mNextAlarmIncidence ) { | 338 | if (! mNextAlarmIncidence ) { |
335 | return; | 339 | return; |
336 | } | 340 | } |
337 | newNextAlarm = true; | 341 | newNextAlarm = true; |
338 | } | 342 | } |
339 | if ( newNextAlarm ) | 343 | if ( newNextAlarm ) |
340 | registerAlarm(); | 344 | registerAlarm(); |
341 | } | 345 | } |
342 | QString CalendarLocal:: getAlarmNotification() | 346 | QString CalendarLocal:: getAlarmNotification() |
343 | { | 347 | { |
344 | QString ret; | 348 | QString ret; |
345 | // this should not happen | 349 | // this should not happen |
346 | if (! mNextAlarmIncidence ) | 350 | if (! mNextAlarmIncidence ) |
347 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 351 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
348 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 352 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
349 | if ( alarm->type() == Alarm::Procedure ) { | 353 | if ( alarm->type() == Alarm::Procedure ) { |
350 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 354 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
351 | } else { | 355 | } else { |
352 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 356 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
353 | } | 357 | } |
354 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 358 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
355 | if ( mNextSummary.length() > 25 ) | 359 | if ( mNextSummary.length() > 25 ) |
356 | ret += "\n" + mNextSummary.mid(25, 25 ); | 360 | ret += "\n" + mNextSummary.mid(25, 25 ); |
357 | ret+= "\n"+mNextAlarmEventDateTimeString; | 361 | ret+= "\n"+mNextAlarmEventDateTimeString; |
358 | return ret; | 362 | return ret; |
359 | } | 363 | } |
360 | void CalendarLocal::registerAlarm() | 364 | void CalendarLocal::registerAlarm() |
361 | { | 365 | { |
362 | mLastAlarmNotificationString = getAlarmNotification(); | 366 | mLastAlarmNotificationString = getAlarmNotification(); |
363 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 367 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
364 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 368 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
365 | // #ifndef DESKTOP_VERSION | 369 | // #ifndef DESKTOP_VERSION |
366 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 370 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
367 | // #endif | 371 | // #endif |
368 | } | 372 | } |
369 | void CalendarLocal::deRegisterAlarm() | 373 | void CalendarLocal::deRegisterAlarm() |
370 | { | 374 | { |
371 | if ( mLastAlarmNotificationString.isNull() ) | 375 | if ( mLastAlarmNotificationString.isNull() ) |
372 | return; | 376 | return; |
373 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 377 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
374 | 378 | ||
375 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 379 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
376 | mNextAlarmEventDateTime = QDateTime(); | 380 | mNextAlarmEventDateTime = QDateTime(); |
377 | // #ifndef DESKTOP_VERSION | 381 | // #ifndef DESKTOP_VERSION |
378 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 382 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
379 | // #endif | 383 | // #endif |
380 | } | 384 | } |
381 | 385 | ||
382 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 386 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
383 | { | 387 | { |
384 | QPtrList<Todo> todos; | 388 | QPtrList<Todo> todos; |
385 | 389 | ||
386 | Todo *todo; | 390 | Todo *todo; |
387 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 391 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
388 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 392 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
389 | todos.append( todo ); | 393 | todos.append( todo ); |
390 | } | 394 | } |
391 | } | 395 | } |
392 | 396 | ||
393 | filter()->apply( &todos ); | 397 | filter()->apply( &todos ); |
394 | return todos; | 398 | return todos; |
395 | } | 399 | } |
396 | void CalendarLocal::reInitAlarmSettings() | 400 | void CalendarLocal::reInitAlarmSettings() |
397 | { | 401 | { |
398 | if ( !mNextAlarmIncidence ) { | 402 | if ( !mNextAlarmIncidence ) { |
399 | nextAlarm( 1000 ); | 403 | nextAlarm( 1000 ); |
400 | } | 404 | } |
401 | deRegisterAlarm(); | 405 | deRegisterAlarm(); |
402 | mNextAlarmIncidence = 0; | 406 | mNextAlarmIncidence = 0; |
403 | checkAlarmForIncidence( 0, false ); | 407 | checkAlarmForIncidence( 0, false ); |
404 | 408 | ||
405 | } | 409 | } |
406 | 410 | ||
407 | 411 | ||
408 | 412 | ||
409 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 413 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
410 | { | 414 | { |
411 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 415 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
412 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 416 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
413 | QDateTime next; | 417 | QDateTime next; |
414 | Event *e; | 418 | Event *e; |
415 | bool ok; | 419 | bool ok; |
416 | bool found = false; | 420 | bool found = false; |
417 | int offset; | 421 | int offset; |
418 | mNextAlarmIncidence = 0; | 422 | mNextAlarmIncidence = 0; |
419 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 423 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
420 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 424 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
421 | if ( ok ) { | 425 | if ( ok ) { |
422 | if ( next < nextA ) { | 426 | if ( next < nextA ) { |
423 | nextA = next; | 427 | nextA = next; |
424 | found = true; | 428 | found = true; |
425 | mNextSummary = e->summary(); | 429 | mNextSummary = e->summary(); |
426 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 430 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
427 | mNextAlarmIncidence = (Incidence *) e; | 431 | mNextAlarmIncidence = (Incidence *) e; |
428 | } | 432 | } |
429 | } | 433 | } |
430 | } | 434 | } |
431 | Todo *t; | 435 | Todo *t; |
432 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 436 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
433 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 437 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
434 | if ( ok ) { | 438 | if ( ok ) { |
435 | if ( next < nextA ) { | 439 | if ( next < nextA ) { |
436 | nextA = next; | 440 | nextA = next; |
437 | found = true; | 441 | found = true; |
438 | mNextSummary = t->summary(); | 442 | mNextSummary = t->summary(); |
439 | mNextAlarmEventDateTime = next.addSecs(offset ); | 443 | mNextAlarmEventDateTime = next.addSecs(offset ); |
440 | mNextAlarmIncidence = (Incidence *) t; | 444 | mNextAlarmIncidence = (Incidence *) t; |
441 | } | 445 | } |
442 | } | 446 | } |
443 | } | 447 | } |
444 | if ( mNextAlarmIncidence ) { | 448 | if ( mNextAlarmIncidence ) { |
445 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 449 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
446 | mNextAlarmDateTime = nextA; | 450 | mNextAlarmDateTime = nextA; |
447 | } | 451 | } |
448 | return nextA; | 452 | return nextA; |
449 | } | 453 | } |
450 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 454 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
451 | { | 455 | { |
452 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 456 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
453 | } | 457 | } |
454 | 458 | ||
455 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 459 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
456 | { | 460 | { |
457 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 461 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
458 | << to.toString() << ")\n"; | 462 | << to.toString() << ")\n"; |
459 | 463 | ||
460 | Alarm::List alarms; | 464 | Alarm::List alarms; |
461 | 465 | ||
462 | Event *e; | 466 | Event *e; |
463 | 467 | ||
464 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 468 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
465 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 469 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
466 | else appendAlarms( alarms, e, from, to ); | 470 | else appendAlarms( alarms, e, from, to ); |
467 | } | 471 | } |
468 | 472 | ||
469 | Todo *t; | 473 | Todo *t; |
470 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 474 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
471 | appendAlarms( alarms, t, from, to ); | 475 | appendAlarms( alarms, t, from, to ); |
472 | } | 476 | } |
473 | 477 | ||
474 | return alarms; | 478 | return alarms; |
475 | } | 479 | } |
476 | 480 | ||
477 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 481 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
478 | const QDateTime &from, const QDateTime &to ) | 482 | const QDateTime &from, const QDateTime &to ) |
479 | { | 483 | { |
480 | QPtrList<Alarm> alarmList = incidence->alarms(); | 484 | QPtrList<Alarm> alarmList = incidence->alarms(); |
481 | Alarm *alarm; | 485 | Alarm *alarm; |
482 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 486 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
483 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 487 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
484 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 488 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
485 | if ( alarm->enabled() ) { | 489 | if ( alarm->enabled() ) { |
486 | if ( alarm->time() >= from && alarm->time() <= to ) { | 490 | if ( alarm->time() >= from && alarm->time() <= to ) { |
487 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 491 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
488 | << "': " << alarm->time().toString() << endl; | 492 | << "': " << alarm->time().toString() << endl; |
489 | alarms.append( alarm ); | 493 | alarms.append( alarm ); |
490 | } | 494 | } |
491 | } | 495 | } |
492 | } | 496 | } |
493 | } | 497 | } |
494 | 498 | ||
495 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 499 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
496 | Incidence *incidence, | 500 | Incidence *incidence, |
497 | const QDateTime &from, | 501 | const QDateTime &from, |
498 | const QDateTime &to ) | 502 | const QDateTime &to ) |
499 | { | 503 | { |
500 | 504 | ||
501 | QPtrList<Alarm> alarmList = incidence->alarms(); | 505 | QPtrList<Alarm> alarmList = incidence->alarms(); |
502 | Alarm *alarm; | 506 | Alarm *alarm; |
503 | QDateTime qdt; | 507 | QDateTime qdt; |
504 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 508 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
505 | if (incidence->recursOn(from.date())) { | 509 | if (incidence->recursOn(from.date())) { |
506 | qdt.setTime(alarm->time().time()); | 510 | qdt.setTime(alarm->time().time()); |
507 | qdt.setDate(from.date()); | 511 | qdt.setDate(from.date()); |
508 | } | 512 | } |
509 | else qdt = alarm->time(); | 513 | else qdt = alarm->time(); |
510 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 514 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
511 | if ( alarm->enabled() ) { | 515 | if ( alarm->enabled() ) { |
512 | if ( qdt >= from && qdt <= to ) { | 516 | if ( qdt >= from && qdt <= to ) { |
513 | alarms.append( alarm ); | 517 | alarms.append( alarm ); |
514 | } | 518 | } |
515 | } | 519 | } |
516 | } | 520 | } |
517 | } | 521 | } |
518 | 522 | ||
519 | 523 | ||
520 | /****************************** PROTECTED METHODS ****************************/ | 524 | /****************************** PROTECTED METHODS ****************************/ |
521 | 525 | ||
522 | // after changes are made to an event, this should be called. | 526 | // after changes are made to an event, this should be called. |
523 | void CalendarLocal::update( IncidenceBase *incidence ) | 527 | void CalendarLocal::update( IncidenceBase *incidence ) |
524 | { | 528 | { |
525 | incidence->setSyncStatus( Event::SYNCMOD ); | 529 | incidence->setSyncStatus( Event::SYNCMOD ); |
526 | incidence->setLastModified( QDateTime::currentDateTime() ); | 530 | incidence->setLastModified( QDateTime::currentDateTime() ); |
527 | // we should probably update the revision number here, | 531 | // we should probably update the revision number here, |
528 | // or internally in the Event itself when certain things change. | 532 | // or internally in the Event itself when certain things change. |
529 | // need to verify with ical documentation. | 533 | // need to verify with ical documentation. |
530 | 534 | ||
531 | setModified( true ); | 535 | setModified( true ); |
532 | } | 536 | } |
533 | 537 | ||
534 | void CalendarLocal::insertEvent( Event *event ) | 538 | void CalendarLocal::insertEvent( Event *event ) |
535 | { | 539 | { |
536 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 540 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
537 | } | 541 | } |
538 | 542 | ||
539 | 543 | ||
540 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 544 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
541 | { | 545 | { |
542 | QPtrList<Event> eventList; | 546 | QPtrList<Event> eventList; |
543 | 547 | ||
544 | Event *event; | 548 | Event *event; |
545 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 549 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
546 | if ( event->doesRecur() ) { | 550 | if ( event->doesRecur() ) { |
547 | if ( event->isMultiDay() ) { | 551 | if ( event->isMultiDay() ) { |
548 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 552 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
549 | int i; | 553 | int i; |
550 | for ( i = 0; i <= extraDays; i++ ) { | 554 | for ( i = 0; i <= extraDays; i++ ) { |
551 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 555 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
552 | eventList.append( event ); | 556 | eventList.append( event ); |
553 | break; | 557 | break; |
554 | } | 558 | } |
555 | } | 559 | } |
556 | } else { | 560 | } else { |
557 | if ( event->recursOn( qd ) ) | 561 | if ( event->recursOn( qd ) ) |
558 | eventList.append( event ); | 562 | eventList.append( event ); |
559 | } | 563 | } |
560 | } else { | 564 | } else { |
561 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 565 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
562 | eventList.append( event ); | 566 | eventList.append( event ); |
563 | } | 567 | } |
564 | } | 568 | } |
565 | } | 569 | } |
566 | 570 | ||
567 | if ( !sorted ) { | 571 | if ( !sorted ) { |
568 | return eventList; | 572 | return eventList; |
569 | } | 573 | } |
570 | 574 | ||
571 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 575 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
572 | // now, we have to sort it based on dtStart.time() | 576 | // now, we have to sort it based on dtStart.time() |
573 | QPtrList<Event> eventListSorted; | 577 | QPtrList<Event> eventListSorted; |
574 | Event *sortEvent; | 578 | Event *sortEvent; |
575 | for ( event = eventList.first(); event; event = eventList.next() ) { | 579 | for ( event = eventList.first(); event; event = eventList.next() ) { |
576 | sortEvent = eventListSorted.first(); | 580 | sortEvent = eventListSorted.first(); |
577 | int i = 0; | 581 | int i = 0; |
578 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 582 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
579 | { | 583 | { |
580 | i++; | 584 | i++; |
581 | sortEvent = eventListSorted.next(); | 585 | sortEvent = eventListSorted.next(); |
582 | } | 586 | } |
583 | eventListSorted.insert( i, event ); | 587 | eventListSorted.insert( i, event ); |
584 | } | 588 | } |
585 | return eventListSorted; | 589 | return eventListSorted; |
586 | } | 590 | } |
587 | 591 | ||
588 | 592 | ||
589 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 593 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
590 | bool inclusive ) | 594 | bool inclusive ) |
591 | { | 595 | { |
592 | Event *event = 0; | 596 | Event *event = 0; |
593 | 597 | ||
594 | QPtrList<Event> eventList; | 598 | QPtrList<Event> eventList; |
595 | 599 | ||
596 | // Get non-recurring events | 600 | // Get non-recurring events |
597 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 601 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
598 | if ( event->doesRecur() ) { | 602 | if ( event->doesRecur() ) { |
599 | QDate rStart = event->dtStart().date(); | 603 | QDate rStart = event->dtStart().date(); |
600 | bool found = false; | 604 | bool found = false; |
601 | if ( inclusive ) { | 605 | if ( inclusive ) { |
602 | if ( rStart >= start && rStart <= end ) { | 606 | if ( rStart >= start && rStart <= end ) { |
603 | // Start date of event is in range. Now check for end date. | 607 | // Start date of event is in range. Now check for end date. |
604 | // if duration is negative, event recurs forever, so do not include it. | 608 | // if duration is negative, event recurs forever, so do not include it. |
605 | if ( event->recurrence()->duration() == 0 ) { // End date set | 609 | if ( event->recurrence()->duration() == 0 ) { // End date set |
606 | QDate rEnd = event->recurrence()->endDate(); | 610 | QDate rEnd = event->recurrence()->endDate(); |
607 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 611 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
608 | found = true; | 612 | found = true; |
609 | } | 613 | } |
610 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 614 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
611 | // TODO: Calculate end date from duration. Should be done in Event | 615 | // TODO: Calculate end date from duration. Should be done in Event |
612 | // For now exclude all events with a duration. | 616 | // For now exclude all events with a duration. |
613 | } | 617 | } |
614 | } | 618 | } |
615 | } else { | 619 | } else { |
616 | bool founOne; | 620 | bool founOne; |
617 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 621 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
618 | if ( founOne ) { | 622 | if ( founOne ) { |
619 | if ( next <= end ) { | 623 | if ( next <= end ) { |
620 | found = true; | 624 | found = true; |
621 | } | 625 | } |
622 | } | 626 | } |
623 | 627 | ||
624 | /* | 628 | /* |
625 | // crap !!! | 629 | // crap !!! |
626 | if ( rStart <= end ) { // Start date not after range | 630 | if ( rStart <= end ) { // Start date not after range |
627 | if ( rStart >= start ) { // Start date within range | 631 | if ( rStart >= start ) { // Start date within range |
628 | found = true; | 632 | found = true; |
629 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 633 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
630 | found = true; | 634 | found = true; |
631 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 635 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
632 | QDate rEnd = event->recurrence()->endDate(); | 636 | QDate rEnd = event->recurrence()->endDate(); |
633 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 637 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
634 | found = true; | 638 | found = true; |
635 | } | 639 | } |
636 | } else { // Duration set | 640 | } else { // Duration set |
637 | // TODO: Calculate end date from duration. Should be done in Event | 641 | // TODO: Calculate end date from duration. Should be done in Event |
638 | // For now include all events with a duration. | 642 | // For now include all events with a duration. |
639 | found = true; | 643 | found = true; |
640 | } | 644 | } |
641 | } | 645 | } |
642 | */ | 646 | */ |
643 | 647 | ||
644 | } | 648 | } |
645 | 649 | ||
646 | if ( found ) eventList.append( event ); | 650 | if ( found ) eventList.append( event ); |
647 | } else { | 651 | } else { |
648 | QDate s = event->dtStart().date(); | 652 | QDate s = event->dtStart().date(); |
649 | QDate e = event->dtEnd().date(); | 653 | QDate e = event->dtEnd().date(); |
650 | 654 | ||
651 | if ( inclusive ) { | 655 | if ( inclusive ) { |
652 | if ( s >= start && e <= end ) { | 656 | if ( s >= start && e <= end ) { |
653 | eventList.append( event ); | 657 | eventList.append( event ); |
654 | } | 658 | } |
655 | } else { | 659 | } else { |
656 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 660 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
657 | eventList.append( event ); | 661 | eventList.append( event ); |
658 | } | 662 | } |
659 | } | 663 | } |
660 | } | 664 | } |
661 | } | 665 | } |
662 | 666 | ||
663 | return eventList; | 667 | return eventList; |
664 | } | 668 | } |
665 | 669 | ||
666 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 670 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
667 | { | 671 | { |
668 | return rawEventsForDate( qdt.date() ); | 672 | return rawEventsForDate( qdt.date() ); |
669 | } | 673 | } |
670 | 674 | ||
671 | QPtrList<Event> CalendarLocal::rawEvents() | 675 | QPtrList<Event> CalendarLocal::rawEvents() |
672 | { | 676 | { |
673 | return mEventList; | 677 | return mEventList; |
674 | } | 678 | } |
675 | 679 | ||
676 | bool CalendarLocal::addJournal(Journal *journal) | 680 | bool CalendarLocal::addJournal(Journal *journal) |
677 | { | 681 | { |
678 | if ( journal->dtStart().isValid()) | 682 | if ( journal->dtStart().isValid()) |
679 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 683 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
680 | else | 684 | else |
681 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 685 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
682 | 686 | ||
683 | mJournalList.append(journal); | 687 | mJournalList.append(journal); |
684 | 688 | ||
685 | journal->registerObserver( this ); | 689 | journal->registerObserver( this ); |
686 | 690 | ||
687 | setModified( true ); | 691 | setModified( true ); |
688 | 692 | ||
689 | return true; | 693 | return true; |
690 | } | 694 | } |
691 | 695 | ||
692 | void CalendarLocal::deleteJournal( Journal *journal ) | 696 | void CalendarLocal::deleteJournal( Journal *journal ) |
693 | { | 697 | { |
694 | if ( mUndoIncidence ) delete mUndoIncidence; | 698 | if ( mUndoIncidence ) delete mUndoIncidence; |
695 | mUndoIncidence = journal->clone(); | 699 | mUndoIncidence = journal->clone(); |
696 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 700 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
697 | if ( mJournalList.removeRef(journal) ) { | 701 | if ( mJournalList.removeRef(journal) ) { |
698 | setModified( true ); | 702 | setModified( true ); |
699 | } | 703 | } |
700 | } | 704 | } |
701 | 705 | ||
702 | Journal *CalendarLocal::journal( const QDate &date ) | 706 | Journal *CalendarLocal::journal( const QDate &date ) |
703 | { | 707 | { |
704 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 708 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
705 | 709 | ||
706 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 710 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
707 | if ( it->dtStart().date() == date ) | 711 | if ( it->dtStart().date() == date ) |
708 | return it; | 712 | return it; |
709 | 713 | ||
710 | return 0; | 714 | return 0; |
711 | } | 715 | } |
712 | 716 | ||
713 | Journal *CalendarLocal::journal( const QString &uid ) | 717 | Journal *CalendarLocal::journal( const QString &uid ) |
714 | { | 718 | { |
715 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 719 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
716 | if ( it->uid() == uid ) | 720 | if ( it->uid() == uid ) |
717 | return it; | 721 | return it; |
718 | 722 | ||
719 | return 0; | 723 | return 0; |
720 | } | 724 | } |
721 | 725 | ||
722 | QPtrList<Journal> CalendarLocal::journals() | 726 | QPtrList<Journal> CalendarLocal::journals() |
723 | { | 727 | { |
724 | return mJournalList; | 728 | return mJournalList; |
725 | } | 729 | } |
726 | 730 | ||
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index b89abce..5e6ac22 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,560 +1,561 @@ | |||
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 <kglobalsettings.h> | 22 | #include <kglobalsettings.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qfileinfo.h> | 26 | #include <qfileinfo.h> |
27 | 27 | ||
28 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
29 | #include "icalformat.h" | 29 | #include "icalformat.h" |
30 | #include "todo.h" | 30 | #include "todo.h" |
31 | 31 | ||
32 | using namespace KCal; | 32 | using namespace KCal; |
33 | 33 | ||
34 | Todo::Todo(): QObject(), Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
35 | { | 35 | { |
36 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
37 | 37 | ||
38 | mHasDueDate = false; | 38 | mHasDueDate = false; |
39 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
41 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
42 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
43 | mRunning = false; | 43 | mRunning = false; |
44 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
48 | { | 48 | { |
49 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
50 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
51 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
52 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
53 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
54 | mRunning = false; | 54 | mRunning = false; |
55 | mRunSaveTimer = 0; | 55 | mRunSaveTimer = 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | Todo::~Todo() | 58 | Todo::~Todo() |
59 | { | 59 | { |
60 | setRunning( false ); | 60 | setRunning( false ); |
61 | //qDebug("Todo::~Todo() "); | 61 | //qDebug("Todo::~Todo() "); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Todo::setRunning( bool run ) | 64 | void Todo::setRunning( bool run ) |
65 | { | 65 | { |
66 | if ( run == mRunning ) | 66 | if ( run == mRunning ) |
67 | return; | 67 | return; |
68 | //qDebug("Todo::setRunning %d ", run); | ||
68 | if ( !mRunSaveTimer ) { | 69 | if ( !mRunSaveTimer ) { |
69 | mRunSaveTimer = new QTimer ( this ); | 70 | mRunSaveTimer = new QTimer ( this ); |
70 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 71 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
71 | } | 72 | } |
72 | mRunning = run; | 73 | mRunning = run; |
73 | if ( mRunning ) { | 74 | if ( mRunning ) { |
74 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 75 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
75 | mRunStart = QDateTime::currentDateTime(); | 76 | mRunStart = QDateTime::currentDateTime(); |
76 | } else { | 77 | } else { |
77 | mRunSaveTimer->stop(); | 78 | mRunSaveTimer->stop(); |
78 | saveRunningInfoToFile(); | 79 | saveRunningInfoToFile(); |
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
82 | void Todo::saveRunningInfoToFile() | 83 | void Todo::saveRunningInfoToFile() |
83 | { | 84 | { |
84 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 85 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
85 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { | 86 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
86 | qDebug("Running time < 30 seconds. Skipped. "); | 87 | qDebug("Running time < 30 seconds. Skipped. "); |
87 | return; | 88 | return; |
88 | } | 89 | } |
89 | QString dir = KGlobalSettings::timeTrackerDir(); | 90 | QString dir = KGlobalSettings::timeTrackerDir(); |
90 | //qDebug("%s ", dir.latin1()); | 91 | //qDebug("%s ", dir.latin1()); |
91 | QString file = "%1%2%3-%4%5%6-"; | 92 | QString file = "%1%2%3-%4%5%6-"; |
92 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); | 93 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); |
93 | file.replace ( QRegExp (" "), "0" ); | 94 | file.replace ( QRegExp (" "), "0" ); |
94 | file += uid(); | 95 | file += uid(); |
95 | //qDebug("File %s ",file.latin1() ); | 96 | //qDebug("File %s ",file.latin1() ); |
96 | CalendarLocal cal; | 97 | CalendarLocal cal; |
97 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 98 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
98 | Todo * to = (Todo*) clone(); | 99 | Todo * to = (Todo*) clone(); |
99 | to->setFloats( false ); | 100 | to->setFloats( false ); |
100 | to->setDtStart( mRunStart ); | 101 | to->setDtStart( mRunStart ); |
101 | to->setHasStartDate( true ); | 102 | to->setHasStartDate( true ); |
102 | to->setDtDue( QDateTime::currentDateTime() ); | 103 | to->setDtDue( QDateTime::currentDateTime() ); |
103 | to->setHasDueDate( true ); | 104 | to->setHasDueDate( true ); |
104 | to->setUid( file ); | 105 | to->setUid( file ); |
105 | cal.addIncidence( to ); | 106 | cal.addIncidence( to ); |
106 | ICalFormat format; | 107 | ICalFormat format; |
107 | file = dir +"/" +file +".ics"; | 108 | file = dir +"/" +file +".ics"; |
108 | format.save( &cal, file ); | 109 | format.save( &cal, file ); |
109 | saveParents(); | 110 | saveParents(); |
110 | 111 | ||
111 | } | 112 | } |
112 | void Todo::saveParents() | 113 | void Todo::saveParents() |
113 | { | 114 | { |
114 | if (!relatedTo() ) | 115 | if (!relatedTo() ) |
115 | return; | 116 | return; |
116 | Incidence * inc = relatedTo(); | 117 | Incidence * inc = relatedTo(); |
117 | if ( inc->type() != "Todo" ) | 118 | if ( inc->type() != "Todo" ) |
118 | return; | 119 | return; |
119 | Todo* to = (Todo*)inc; | 120 | Todo* to = (Todo*)inc; |
120 | bool saveTodo = false; | 121 | bool saveTodo = false; |
121 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 122 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
122 | QFileInfo fi ( file ); | 123 | QFileInfo fi ( file ); |
123 | if ( fi.exists() ) { | 124 | if ( fi.exists() ) { |
124 | if ( fi.lastModified () < to->lastModified ()) | 125 | if ( fi.lastModified () < to->lastModified ()) |
125 | saveTodo = true; | 126 | saveTodo = true; |
126 | } else { | 127 | } else { |
127 | saveTodo = true; | 128 | saveTodo = true; |
128 | } | 129 | } |
129 | if ( saveTodo ) { | 130 | if ( saveTodo ) { |
130 | CalendarLocal cal; | 131 | CalendarLocal cal; |
131 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 132 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
132 | Todo * par = (Todo *) to->clone(); | 133 | Todo * par = (Todo *) to->clone(); |
133 | cal.addIncidence( par ); | 134 | cal.addIncidence( par ); |
134 | ICalFormat format; | 135 | ICalFormat format; |
135 | format.save( &cal, file ); | 136 | format.save( &cal, file ); |
136 | } | 137 | } |
137 | } | 138 | } |
138 | 139 | ||
139 | int Todo::runTime() | 140 | int Todo::runTime() |
140 | { | 141 | { |
141 | if ( !mRunning ) | 142 | if ( !mRunning ) |
142 | return 0; | 143 | return 0; |
143 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 144 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
144 | } | 145 | } |
145 | bool Todo::hasRunningSub() | 146 | bool Todo::hasRunningSub() |
146 | { | 147 | { |
147 | if ( mRunning ) | 148 | if ( mRunning ) |
148 | return true; | 149 | return true; |
149 | Incidence *aTodo; | 150 | Incidence *aTodo; |
150 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 151 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
151 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 152 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
152 | return true; | 153 | return true; |
153 | } | 154 | } |
154 | return false; | 155 | return false; |
155 | } | 156 | } |
156 | Incidence *Todo::clone() | 157 | Incidence *Todo::clone() |
157 | { | 158 | { |
158 | return new Todo(*this); | 159 | return new Todo(*this); |
159 | } | 160 | } |
160 | 161 | ||
161 | bool Todo::contains ( Todo* from ) | 162 | bool Todo::contains ( Todo* from ) |
162 | { | 163 | { |
163 | 164 | ||
164 | if ( !from->summary().isEmpty() ) | 165 | if ( !from->summary().isEmpty() ) |
165 | if ( !summary().startsWith( from->summary() )) | 166 | if ( !summary().startsWith( from->summary() )) |
166 | return false; | 167 | return false; |
167 | if ( from->hasStartDate() ) { | 168 | if ( from->hasStartDate() ) { |
168 | if ( !hasStartDate() ) | 169 | if ( !hasStartDate() ) |
169 | return false; | 170 | return false; |
170 | if ( from->dtStart() != dtStart()) | 171 | if ( from->dtStart() != dtStart()) |
171 | return false; | 172 | return false; |
172 | } | 173 | } |
173 | if ( from->hasDueDate() ){ | 174 | if ( from->hasDueDate() ){ |
174 | if ( !hasDueDate() ) | 175 | if ( !hasDueDate() ) |
175 | return false; | 176 | return false; |
176 | if ( from->dtDue() != dtDue()) | 177 | if ( from->dtDue() != dtDue()) |
177 | return false; | 178 | return false; |
178 | } | 179 | } |
179 | if ( !from->location().isEmpty() ) | 180 | if ( !from->location().isEmpty() ) |
180 | if ( !location().startsWith( from->location() ) ) | 181 | if ( !location().startsWith( from->location() ) ) |
181 | return false; | 182 | return false; |
182 | if ( !from->description().isEmpty() ) | 183 | if ( !from->description().isEmpty() ) |
183 | if ( !description().startsWith( from->description() )) | 184 | if ( !description().startsWith( from->description() )) |
184 | return false; | 185 | return false; |
185 | if ( from->alarms().count() ) { | 186 | if ( from->alarms().count() ) { |
186 | Alarm *a = from->alarms().first(); | 187 | Alarm *a = from->alarms().first(); |
187 | if ( a->enabled() ){ | 188 | if ( a->enabled() ){ |
188 | if ( !alarms().count() ) | 189 | if ( !alarms().count() ) |
189 | return false; | 190 | return false; |
190 | Alarm *b = alarms().first(); | 191 | Alarm *b = alarms().first(); |
191 | if( ! b->enabled() ) | 192 | if( ! b->enabled() ) |
192 | return false; | 193 | return false; |
193 | if ( ! (a->offset() == b->offset() )) | 194 | if ( ! (a->offset() == b->offset() )) |
194 | return false; | 195 | return false; |
195 | } | 196 | } |
196 | } | 197 | } |
197 | 198 | ||
198 | QStringList cat = categories(); | 199 | QStringList cat = categories(); |
199 | QStringList catFrom = from->categories(); | 200 | QStringList catFrom = from->categories(); |
200 | QString nCat; | 201 | QString nCat; |
201 | unsigned int iii; | 202 | unsigned int iii; |
202 | for ( iii = 0; iii < catFrom.count();++iii ) { | 203 | for ( iii = 0; iii < catFrom.count();++iii ) { |
203 | nCat = catFrom[iii]; | 204 | nCat = catFrom[iii]; |
204 | if ( !nCat.isEmpty() ) | 205 | if ( !nCat.isEmpty() ) |
205 | if ( !cat.contains( nCat )) { | 206 | if ( !cat.contains( nCat )) { |
206 | return false; | 207 | return false; |
207 | } | 208 | } |
208 | } | 209 | } |
209 | if ( from->isCompleted() ) { | 210 | if ( from->isCompleted() ) { |
210 | if ( !isCompleted() ) | 211 | if ( !isCompleted() ) |
211 | return false; | 212 | return false; |
212 | } | 213 | } |
213 | if( priority() != from->priority() ) | 214 | if( priority() != from->priority() ) |
214 | return false; | 215 | return false; |
215 | 216 | ||
216 | 217 | ||
217 | return true; | 218 | return true; |
218 | 219 | ||
219 | } | 220 | } |
220 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 221 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
221 | { | 222 | { |
222 | 223 | ||
223 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 224 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
224 | if ( ! ret ) | 225 | if ( ! ret ) |
225 | return false; | 226 | return false; |
226 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 227 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
227 | if ( t1.hasDueDate() ) { | 228 | if ( t1.hasDueDate() ) { |
228 | if ( t1.doesFloat() == t2.doesFloat() ) { | 229 | if ( t1.doesFloat() == t2.doesFloat() ) { |
229 | if ( t1.doesFloat() ) { | 230 | if ( t1.doesFloat() ) { |
230 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 231 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
231 | return false; | 232 | return false; |
232 | } else | 233 | } else |
233 | if ( t1.dtDue() != t2.dtDue() ) | 234 | if ( t1.dtDue() != t2.dtDue() ) |
234 | return false; | 235 | return false; |
235 | } else | 236 | } else |
236 | return false;// float != | 237 | return false;// float != |
237 | } | 238 | } |
238 | 239 | ||
239 | } else | 240 | } else |
240 | return false; | 241 | return false; |
241 | if ( t1.percentComplete() != t2.percentComplete() ) | 242 | if ( t1.percentComplete() != t2.percentComplete() ) |
242 | return false; | 243 | return false; |
243 | if ( t1.isCompleted() ) { | 244 | if ( t1.isCompleted() ) { |
244 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 245 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
245 | if ( t1.hasCompletedDate() ) { | 246 | if ( t1.hasCompletedDate() ) { |
246 | if ( t1.completed() != t2.completed() ) | 247 | if ( t1.completed() != t2.completed() ) |
247 | return false; | 248 | return false; |
248 | } | 249 | } |
249 | 250 | ||
250 | } else | 251 | } else |
251 | return false; | 252 | return false; |
252 | } | 253 | } |
253 | return true; | 254 | return true; |
254 | 255 | ||
255 | } | 256 | } |
256 | 257 | ||
257 | void Todo::setDtDue(const QDateTime &dtDue) | 258 | void Todo::setDtDue(const QDateTime &dtDue) |
258 | { | 259 | { |
259 | //int diffsecs = mDtDue.secsTo(dtDue); | 260 | //int diffsecs = mDtDue.secsTo(dtDue); |
260 | 261 | ||
261 | /*if (mReadOnly) return; | 262 | /*if (mReadOnly) return; |
262 | const QPtrList<Alarm>& alarms = alarms(); | 263 | const QPtrList<Alarm>& alarms = alarms(); |
263 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 264 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
264 | if (alarm->enabled()) { | 265 | if (alarm->enabled()) { |
265 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 266 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
266 | } | 267 | } |
267 | }*/ | 268 | }*/ |
268 | mDtDue = getEvenTime(dtDue); | 269 | mDtDue = getEvenTime(dtDue); |
269 | 270 | ||
270 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 271 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
271 | 272 | ||
272 | /*const QPtrList<Alarm>& alarms = alarms(); | 273 | /*const QPtrList<Alarm>& alarms = alarms(); |
273 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 274 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
274 | alarm->setAlarmStart(mDtDue);*/ | 275 | alarm->setAlarmStart(mDtDue);*/ |
275 | updated(); | 276 | updated(); |
276 | } | 277 | } |
277 | 278 | ||
278 | QDateTime Todo::dtDue() const | 279 | QDateTime Todo::dtDue() const |
279 | { | 280 | { |
280 | return mDtDue; | 281 | return mDtDue; |
281 | } | 282 | } |
282 | 283 | ||
283 | QString Todo::dtDueTimeStr() const | 284 | QString Todo::dtDueTimeStr() const |
284 | { | 285 | { |
285 | return KGlobal::locale()->formatTime(mDtDue.time()); | 286 | return KGlobal::locale()->formatTime(mDtDue.time()); |
286 | } | 287 | } |
287 | 288 | ||
288 | QString Todo::dtDueDateStr(bool shortfmt) const | 289 | QString Todo::dtDueDateStr(bool shortfmt) const |
289 | { | 290 | { |
290 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 291 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
291 | } | 292 | } |
292 | 293 | ||
293 | QString Todo::dtDueStr(bool shortfmt) const | 294 | QString Todo::dtDueStr(bool shortfmt) const |
294 | { | 295 | { |
295 | if ( doesFloat() ) | 296 | if ( doesFloat() ) |
296 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 297 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
297 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 298 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
298 | } | 299 | } |
299 | // retval 0 : no found | 300 | // retval 0 : no found |
300 | // 1 : due for date found | 301 | // 1 : due for date found |
301 | // 2 : overdue for date found | 302 | // 2 : overdue for date found |
302 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 303 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
303 | { | 304 | { |
304 | int retval = 0; | 305 | int retval = 0; |
305 | if ( isCompleted() ) | 306 | if ( isCompleted() ) |
306 | return 0; | 307 | return 0; |
307 | if ( hasDueDate() ) { | 308 | if ( hasDueDate() ) { |
308 | if ( dtDue().date() < date ) | 309 | if ( dtDue().date() < date ) |
309 | return 2; | 310 | return 2; |
310 | // we do not return, because we may find an overdue sub todo | 311 | // we do not return, because we may find an overdue sub todo |
311 | if ( dtDue().date() == date ) | 312 | if ( dtDue().date() == date ) |
312 | retval = 1; | 313 | retval = 1; |
313 | } | 314 | } |
314 | if ( checkSubtodos ) { | 315 | if ( checkSubtodos ) { |
315 | Incidence *aTodo; | 316 | Incidence *aTodo; |
316 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 317 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
317 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 318 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
318 | if ( ret == 2 ) | 319 | if ( ret == 2 ) |
319 | return 2; | 320 | return 2; |
320 | if ( ret == 1) | 321 | if ( ret == 1) |
321 | retval = 1; | 322 | retval = 1; |
322 | } | 323 | } |
323 | } | 324 | } |
324 | return retval; | 325 | return retval; |
325 | } | 326 | } |
326 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 327 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
327 | { | 328 | { |
328 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 329 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
329 | } | 330 | } |
330 | bool Todo::hasDueDate() const | 331 | bool Todo::hasDueDate() const |
331 | { | 332 | { |
332 | return mHasDueDate; | 333 | return mHasDueDate; |
333 | } | 334 | } |
334 | 335 | ||
335 | void Todo::setHasDueDate(bool f) | 336 | void Todo::setHasDueDate(bool f) |
336 | { | 337 | { |
337 | if (mReadOnly) return; | 338 | if (mReadOnly) return; |
338 | mHasDueDate = f; | 339 | mHasDueDate = f; |
339 | updated(); | 340 | updated(); |
340 | } | 341 | } |
341 | 342 | ||
342 | 343 | ||
343 | #if 0 | 344 | #if 0 |
344 | void Todo::setStatus(const QString &statStr) | 345 | void Todo::setStatus(const QString &statStr) |
345 | { | 346 | { |
346 | if (mReadOnly) return; | 347 | if (mReadOnly) return; |
347 | QString ss(statStr.upper()); | 348 | QString ss(statStr.upper()); |
348 | 349 | ||
349 | if (ss == "X-ACTION") | 350 | if (ss == "X-ACTION") |
350 | mStatus = NEEDS_ACTION; | 351 | mStatus = NEEDS_ACTION; |
351 | else if (ss == "NEEDS ACTION") | 352 | else if (ss == "NEEDS ACTION") |
352 | mStatus = NEEDS_ACTION; | 353 | mStatus = NEEDS_ACTION; |
353 | else if (ss == "ACCEPTED") | 354 | else if (ss == "ACCEPTED") |
354 | mStatus = ACCEPTED; | 355 | mStatus = ACCEPTED; |
355 | else if (ss == "SENT") | 356 | else if (ss == "SENT") |
356 | mStatus = SENT; | 357 | mStatus = SENT; |
357 | else if (ss == "TENTATIVE") | 358 | else if (ss == "TENTATIVE") |
358 | mStatus = TENTATIVE; | 359 | mStatus = TENTATIVE; |
359 | else if (ss == "CONFIRMED") | 360 | else if (ss == "CONFIRMED") |
360 | mStatus = CONFIRMED; | 361 | mStatus = CONFIRMED; |
361 | else if (ss == "DECLINED") | 362 | else if (ss == "DECLINED") |
362 | mStatus = DECLINED; | 363 | mStatus = DECLINED; |
363 | else if (ss == "COMPLETED") | 364 | else if (ss == "COMPLETED") |
364 | mStatus = COMPLETED; | 365 | mStatus = COMPLETED; |
365 | else if (ss == "DELEGATED") | 366 | else if (ss == "DELEGATED") |
366 | mStatus = DELEGATED; | 367 | mStatus = DELEGATED; |
367 | 368 | ||
368 | updated(); | 369 | updated(); |
369 | } | 370 | } |
370 | 371 | ||
371 | void Todo::setStatus(int status) | 372 | void Todo::setStatus(int status) |
372 | { | 373 | { |
373 | if (mReadOnly) return; | 374 | if (mReadOnly) return; |
374 | mStatus = status; | 375 | mStatus = status; |
375 | updated(); | 376 | updated(); |
376 | } | 377 | } |
377 | 378 | ||
378 | int Todo::status() const | 379 | int Todo::status() const |
379 | { | 380 | { |
380 | return mStatus; | 381 | return mStatus; |
381 | } | 382 | } |
382 | 383 | ||
383 | QString Todo::statusStr() const | 384 | QString Todo::statusStr() const |
384 | { | 385 | { |
385 | switch(mStatus) { | 386 | switch(mStatus) { |
386 | case NEEDS_ACTION: | 387 | case NEEDS_ACTION: |
387 | return QString("NEEDS ACTION"); | 388 | return QString("NEEDS ACTION"); |
388 | break; | 389 | break; |
389 | case ACCEPTED: | 390 | case ACCEPTED: |
390 | return QString("ACCEPTED"); | 391 | return QString("ACCEPTED"); |
391 | break; | 392 | break; |
392 | case SENT: | 393 | case SENT: |
393 | return QString("SENT"); | 394 | return QString("SENT"); |
394 | break; | 395 | break; |
395 | case TENTATIVE: | 396 | case TENTATIVE: |
396 | return QString("TENTATIVE"); | 397 | return QString("TENTATIVE"); |
397 | break; | 398 | break; |
398 | case CONFIRMED: | 399 | case CONFIRMED: |
399 | return QString("CONFIRMED"); | 400 | return QString("CONFIRMED"); |
400 | break; | 401 | break; |
401 | case DECLINED: | 402 | case DECLINED: |
402 | return QString("DECLINED"); | 403 | return QString("DECLINED"); |
403 | break; | 404 | break; |
404 | case COMPLETED: | 405 | case COMPLETED: |
405 | return QString("COMPLETED"); | 406 | return QString("COMPLETED"); |
406 | break; | 407 | break; |
407 | case DELEGATED: | 408 | case DELEGATED: |
408 | return QString("DELEGATED"); | 409 | return QString("DELEGATED"); |
409 | break; | 410 | break; |
410 | } | 411 | } |
411 | return QString(""); | 412 | return QString(""); |
412 | } | 413 | } |
413 | #endif | 414 | #endif |
414 | 415 | ||
415 | bool Todo::isCompleted() const | 416 | bool Todo::isCompleted() const |
416 | { | 417 | { |
417 | if (mPercentComplete == 100) { | 418 | if (mPercentComplete == 100) { |
418 | return true; | 419 | return true; |
419 | } | 420 | } |
420 | else return false; | 421 | else return false; |
421 | } | 422 | } |
422 | 423 | ||
423 | void Todo::setCompleted(bool completed) | 424 | void Todo::setCompleted(bool completed) |
424 | { | 425 | { |
425 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 426 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
426 | if ( !setRecurDates() ) | 427 | if ( !setRecurDates() ) |
427 | completed = false; | 428 | completed = false; |
428 | } | 429 | } |
429 | if (completed) mPercentComplete = 100; | 430 | if (completed) mPercentComplete = 100; |
430 | else { | 431 | else { |
431 | mPercentComplete = 0; | 432 | mPercentComplete = 0; |
432 | mHasCompletedDate = false; | 433 | mHasCompletedDate = false; |
433 | } | 434 | } |
434 | updated(); | 435 | updated(); |
435 | } | 436 | } |
436 | 437 | ||
437 | QDateTime Todo::completed() const | 438 | QDateTime Todo::completed() const |
438 | { | 439 | { |
439 | return mCompleted; | 440 | return mCompleted; |
440 | } | 441 | } |
441 | 442 | ||
442 | QString Todo::completedStr( bool shortF ) const | 443 | QString Todo::completedStr( bool shortF ) const |
443 | { | 444 | { |
444 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 445 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
445 | } | 446 | } |
446 | 447 | ||
447 | void Todo::setCompleted(const QDateTime &completed) | 448 | void Todo::setCompleted(const QDateTime &completed) |
448 | { | 449 | { |
449 | //qDebug("Todo::setCompleted "); | 450 | //qDebug("Todo::setCompleted "); |
450 | if ( mHasCompletedDate ) { | 451 | if ( mHasCompletedDate ) { |
451 | // qDebug("has completed data - return "); | 452 | // qDebug("has completed data - return "); |
452 | return; | 453 | return; |
453 | } | 454 | } |
454 | mHasCompletedDate = true; | 455 | mHasCompletedDate = true; |
455 | mPercentComplete = 100; | 456 | mPercentComplete = 100; |
456 | mCompleted = getEvenTime(completed); | 457 | mCompleted = getEvenTime(completed); |
457 | updated(); | 458 | updated(); |
458 | } | 459 | } |
459 | 460 | ||
460 | bool Todo::hasCompletedDate() const | 461 | bool Todo::hasCompletedDate() const |
461 | { | 462 | { |
462 | return mHasCompletedDate; | 463 | return mHasCompletedDate; |
463 | } | 464 | } |
464 | 465 | ||
465 | int Todo::percentComplete() const | 466 | int Todo::percentComplete() const |
466 | { | 467 | { |
467 | return mPercentComplete; | 468 | return mPercentComplete; |
468 | } | 469 | } |
469 | bool Todo::setRecurDates() | 470 | bool Todo::setRecurDates() |
470 | { | 471 | { |
471 | if ( !mHasRecurrenceID ) | 472 | if ( !mHasRecurrenceID ) |
472 | return true; | 473 | return true; |
473 | int secs = mDtStart.secsTo( dtDue() ); | 474 | int secs = mDtStart.secsTo( dtDue() ); |
474 | bool ok; | 475 | bool ok; |
475 | qDebug("T:setRecurDates() "); | 476 | qDebug("T:setRecurDates() "); |
476 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 477 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
477 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 478 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
478 | if ( ok ) { | 479 | if ( ok ) { |
479 | mRecurrenceID = next; | 480 | mRecurrenceID = next; |
480 | mDtStart = next; | 481 | mDtStart = next; |
481 | setDtDue( next.addSecs( secs ) ); | 482 | setDtDue( next.addSecs( secs ) ); |
482 | if ( QDateTime::currentDateTime() > next) | 483 | if ( QDateTime::currentDateTime() > next) |
483 | return false; | 484 | return false; |
484 | } else { | 485 | } else { |
485 | setHasRecurrenceID( false ); | 486 | setHasRecurrenceID( false ); |
486 | recurrence()->unsetRecurs(); | 487 | recurrence()->unsetRecurs(); |
487 | } | 488 | } |
488 | return true; | 489 | return true; |
489 | } | 490 | } |
490 | void Todo::setPercentComplete(int v) | 491 | void Todo::setPercentComplete(int v) |
491 | { | 492 | { |
492 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 493 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
493 | if ( !setRecurDates() ) | 494 | if ( !setRecurDates() ) |
494 | v = 0; | 495 | v = 0; |
495 | } | 496 | } |
496 | mPercentComplete = v; | 497 | mPercentComplete = v; |
497 | if ( v != 100 ) | 498 | if ( v != 100 ) |
498 | mHasCompletedDate = false; | 499 | mHasCompletedDate = false; |
499 | updated(); | 500 | updated(); |
500 | } | 501 | } |
501 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const | 502 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const |
502 | { | 503 | { |
503 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { | 504 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { |
504 | *ok = false; | 505 | *ok = false; |
505 | return QDateTime (); | 506 | return QDateTime (); |
506 | } | 507 | } |
507 | QDateTime incidenceStart; | 508 | QDateTime incidenceStart; |
508 | incidenceStart = dtDue(); | 509 | incidenceStart = dtDue(); |
509 | bool enabled = false; | 510 | bool enabled = false; |
510 | Alarm* alarm; | 511 | Alarm* alarm; |
511 | int off = 0; | 512 | int off = 0; |
512 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 513 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
513 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 514 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
514 | // *ok = false; | 515 | // *ok = false; |
515 | // return incidenceStart; | 516 | // return incidenceStart; |
516 | // } | 517 | // } |
517 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 518 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
518 | if (alarm->enabled()) { | 519 | if (alarm->enabled()) { |
519 | if ( alarm->hasTime () ) { | 520 | if ( alarm->hasTime () ) { |
520 | if ( alarm->time() < alarmStart ) { | 521 | if ( alarm->time() < alarmStart ) { |
521 | alarmStart = alarm->time(); | 522 | alarmStart = alarm->time(); |
522 | enabled = true; | 523 | enabled = true; |
523 | off = alarmStart.secsTo( incidenceStart ); | 524 | off = alarmStart.secsTo( incidenceStart ); |
524 | } | 525 | } |
525 | 526 | ||
526 | } else { | 527 | } else { |
527 | int secs = alarm->startOffset().asSeconds(); | 528 | int secs = alarm->startOffset().asSeconds(); |
528 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 529 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
529 | alarmStart = incidenceStart.addSecs( secs ); | 530 | alarmStart = incidenceStart.addSecs( secs ); |
530 | enabled = true; | 531 | enabled = true; |
531 | off = -secs; | 532 | off = -secs; |
532 | } | 533 | } |
533 | } | 534 | } |
534 | } | 535 | } |
535 | } | 536 | } |
536 | if ( enabled ) { | 537 | if ( enabled ) { |
537 | if ( alarmStart > QDateTime::currentDateTime() ) { | 538 | if ( alarmStart > QDateTime::currentDateTime() ) { |
538 | *ok = true; | 539 | *ok = true; |
539 | * offset = off; | 540 | * offset = off; |
540 | return alarmStart; | 541 | return alarmStart; |
541 | } | 542 | } |
542 | } | 543 | } |
543 | *ok = false; | 544 | *ok = false; |
544 | return QDateTime (); | 545 | return QDateTime (); |
545 | 546 | ||
546 | } | 547 | } |
547 | 548 | ||
548 | void Todo::checkSetCompletedFalse() | 549 | void Todo::checkSetCompletedFalse() |
549 | { | 550 | { |
550 | if ( !hasRecurrenceID() ) { | 551 | if ( !hasRecurrenceID() ) { |
551 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 552 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
552 | } | 553 | } |
553 | // qDebug("Todo::checkSetCompletedFalse()"); | 554 | // qDebug("Todo::checkSetCompletedFalse()"); |
554 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 555 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
555 | if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { | 556 | if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { |
556 | qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 557 | qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
557 | setCompleted( false ); | 558 | setCompleted( false ); |
558 | qDebug("Todo::checkSetCompletedFalse "); | 559 | qDebug("Todo::checkSetCompletedFalse "); |
559 | } | 560 | } |
560 | } | 561 | } |