author | zautrix <zautrix> | 2004-08-07 14:52:25 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-07 14:52:25 (UTC) |
commit | 31764784e8753157a936e42e21dcdc41bd8e2eb7 (patch) (unidiff) | |
tree | ddfe5653aadd0277d1181dc459ff73c50256be13 /libkcal/calendarlocal.cpp | |
parent | 5f86d160a6d4406bdef53c8fe244baed0518142d (diff) | |
download | kdepimpi-31764784e8753157a936e42e21dcdc41bd8e2eb7.zip kdepimpi-31764784e8753157a936e42e21dcdc41bd8e2eb7.tar.gz kdepimpi-31764784e8753157a936e42e21dcdc41bd8e2eb7.tar.bz2 |
Sync fixes
-rw-r--r-- | libkcal/calendarlocal.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index e464a77..21b4aaf 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -23,408 +23,408 @@ | |||
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 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | 155 | ||
156 | 156 | ||
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | removeRelations( todo ); | 204 | removeRelations( todo ); |
205 | 205 | ||
206 | if ( mTodoList.removeRef( todo ) ) { | 206 | if ( mTodoList.removeRef( todo ) ) { |
207 | setModified( true ); | 207 | setModified( true ); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | QPtrList<Todo> CalendarLocal::rawTodos() | 211 | QPtrList<Todo> CalendarLocal::rawTodos() |
212 | { | 212 | { |
213 | return mTodoList; | 213 | return mTodoList; |
214 | } | 214 | } |
215 | Todo *CalendarLocal::todo( QString syncProf, int id ) | 215 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
216 | { | 216 | { |
217 | Todo *todo; | 217 | Todo *todo; |
218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
219 | if ( todo->getID( syncProf ) == id ) return todo; | 219 | if ( todo->getID( syncProf ) == id ) return todo; |
220 | } | 220 | } |
221 | 221 | ||
222 | return 0; | 222 | return 0; |
223 | } | 223 | } |
224 | 224 | ||
225 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 225 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
226 | { | 226 | { |
227 | QPtrList<Event> el; | 227 | QPtrList<Event> el; |
228 | Event *todo; | 228 | Event *todo; |
229 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 229 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
230 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 230 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
231 | if ( todo->summary().left(3) == "E: " ) | 231 | if ( todo->summary().left(3) == "E: " ) |
232 | el.append( todo ); | 232 | el.append( todo ); |
233 | } | 233 | } |
234 | 234 | ||
235 | return el; | 235 | return el; |
236 | 236 | ||
237 | } | 237 | } |
238 | Event *CalendarLocal::event( QString syncProf, int id ) | 238 | Event *CalendarLocal::event( QString syncProf, QString id ) |
239 | { | 239 | { |
240 | Event *todo; | 240 | Event *todo; |
241 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 241 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
242 | if ( todo->getID( syncProf ) == id ) return todo; | 242 | if ( todo->getID( syncProf ) == id ) return todo; |
243 | } | 243 | } |
244 | 244 | ||
245 | return 0; | 245 | return 0; |
246 | } | 246 | } |
247 | Todo *CalendarLocal::todo( const QString &uid ) | 247 | Todo *CalendarLocal::todo( const QString &uid ) |
248 | { | 248 | { |
249 | Todo *todo; | 249 | Todo *todo; |
250 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 250 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
251 | if ( todo->uid() == uid ) return todo; | 251 | if ( todo->uid() == uid ) return todo; |
252 | } | 252 | } |
253 | 253 | ||
254 | return 0; | 254 | return 0; |
255 | } | 255 | } |
256 | QString CalendarLocal::nextSummary() const | 256 | QString CalendarLocal::nextSummary() const |
257 | { | 257 | { |
258 | return mNextSummary; | 258 | return mNextSummary; |
259 | } | 259 | } |
260 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 260 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
261 | { | 261 | { |
262 | return mNextAlarmEventDateTime; | 262 | return mNextAlarmEventDateTime; |
263 | } | 263 | } |
264 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 264 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
265 | { | 265 | { |
266 | //mNextAlarmIncidence | 266 | //mNextAlarmIncidence |
267 | //mNextAlarmDateTime | 267 | //mNextAlarmDateTime |
268 | //return mNextSummary; | 268 | //return mNextSummary; |
269 | //return mNextAlarmEventDateTime; | 269 | //return mNextAlarmEventDateTime; |
270 | bool newNextAlarm = false; | 270 | bool newNextAlarm = false; |
271 | bool computeNextAlarm = false; | 271 | bool computeNextAlarm = false; |
272 | bool ok; | 272 | bool ok; |
273 | int offset; | 273 | int offset; |
274 | QDateTime nextA; | 274 | QDateTime nextA; |
275 | // QString nextSum; | 275 | // QString nextSum; |
276 | //QDateTime nextEvent; | 276 | //QDateTime nextEvent; |
277 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 277 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
278 | computeNextAlarm = true; | 278 | computeNextAlarm = true; |
279 | } else { | 279 | } else { |
280 | if ( ! deleted ) { | 280 | if ( ! deleted ) { |
281 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 281 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
282 | if ( ok ) { | 282 | if ( ok ) { |
283 | if ( nextA < mNextAlarmDateTime ) { | 283 | if ( nextA < mNextAlarmDateTime ) { |
284 | deRegisterAlarm(); | 284 | deRegisterAlarm(); |
285 | mNextAlarmDateTime = nextA; | 285 | mNextAlarmDateTime = nextA; |
286 | mNextSummary = incidence->summary(); | 286 | mNextSummary = incidence->summary(); |
287 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 287 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
288 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 288 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
289 | newNextAlarm = true; | 289 | newNextAlarm = true; |
290 | mNextAlarmIncidence = incidence; | 290 | mNextAlarmIncidence = incidence; |
291 | } else { | 291 | } else { |
292 | if ( incidence == mNextAlarmIncidence ) { | 292 | if ( incidence == mNextAlarmIncidence ) { |
293 | computeNextAlarm = true; | 293 | computeNextAlarm = true; |
294 | } | 294 | } |
295 | } | 295 | } |
296 | } else { | 296 | } else { |
297 | if ( mNextAlarmIncidence == incidence ) { | 297 | if ( mNextAlarmIncidence == incidence ) { |
298 | computeNextAlarm = true; | 298 | computeNextAlarm = true; |
299 | } | 299 | } |
300 | } | 300 | } |
301 | } else { // deleted | 301 | } else { // deleted |
302 | if ( incidence == mNextAlarmIncidence ) { | 302 | if ( incidence == mNextAlarmIncidence ) { |
303 | computeNextAlarm = true; | 303 | computeNextAlarm = true; |
304 | } | 304 | } |
305 | } | 305 | } |
306 | } | 306 | } |
307 | if ( computeNextAlarm ) { | 307 | if ( computeNextAlarm ) { |
308 | deRegisterAlarm(); | 308 | deRegisterAlarm(); |
309 | nextA = nextAlarm( 1000 ); | 309 | nextA = nextAlarm( 1000 ); |
310 | if (! mNextAlarmIncidence ) { | 310 | if (! mNextAlarmIncidence ) { |
311 | return; | 311 | return; |
312 | } | 312 | } |
313 | newNextAlarm = true; | 313 | newNextAlarm = true; |
314 | } | 314 | } |
315 | if ( newNextAlarm ) | 315 | if ( newNextAlarm ) |
316 | registerAlarm(); | 316 | registerAlarm(); |
317 | } | 317 | } |
318 | QString CalendarLocal:: getAlarmNotification() | 318 | QString CalendarLocal:: getAlarmNotification() |
319 | { | 319 | { |
320 | QString ret; | 320 | QString ret; |
321 | // this should not happen | 321 | // this should not happen |
322 | if (! mNextAlarmIncidence ) | 322 | if (! mNextAlarmIncidence ) |
323 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 323 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
324 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 324 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
325 | if ( alarm->type() == Alarm::Procedure ) { | 325 | if ( alarm->type() == Alarm::Procedure ) { |
326 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 326 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
327 | } else { | 327 | } else { |
328 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 328 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
329 | } | 329 | } |
330 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 330 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
331 | if ( mNextSummary.length() > 25 ) | 331 | if ( mNextSummary.length() > 25 ) |
332 | ret += "\n" + mNextSummary.mid(25, 25 ); | 332 | ret += "\n" + mNextSummary.mid(25, 25 ); |
333 | ret+= "\n"+mNextAlarmEventDateTimeString; | 333 | ret+= "\n"+mNextAlarmEventDateTimeString; |
334 | return ret; | 334 | return ret; |
335 | } | 335 | } |
336 | void CalendarLocal::registerAlarm() | 336 | void CalendarLocal::registerAlarm() |
337 | { | 337 | { |
338 | mLastAlarmNotificationString = getAlarmNotification(); | 338 | mLastAlarmNotificationString = getAlarmNotification(); |
339 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 339 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
340 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 340 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
341 | // #ifndef DESKTOP_VERSION | 341 | // #ifndef DESKTOP_VERSION |
342 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 342 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
343 | // #endif | 343 | // #endif |
344 | } | 344 | } |
345 | void CalendarLocal::deRegisterAlarm() | 345 | void CalendarLocal::deRegisterAlarm() |
346 | { | 346 | { |
347 | if ( mLastAlarmNotificationString.isNull() ) | 347 | if ( mLastAlarmNotificationString.isNull() ) |
348 | return; | 348 | return; |
349 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 349 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
350 | 350 | ||
351 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 351 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
352 | // #ifndef DESKTOP_VERSION | 352 | // #ifndef DESKTOP_VERSION |
353 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 353 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
354 | // #endif | 354 | // #endif |
355 | } | 355 | } |
356 | 356 | ||
357 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 357 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
358 | { | 358 | { |
359 | QPtrList<Todo> todos; | 359 | QPtrList<Todo> todos; |
360 | 360 | ||
361 | Todo *todo; | 361 | Todo *todo; |
362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
363 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 363 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
364 | todos.append( todo ); | 364 | todos.append( todo ); |
365 | } | 365 | } |
366 | } | 366 | } |
367 | 367 | ||
368 | filter()->apply( &todos ); | 368 | filter()->apply( &todos ); |
369 | return todos; | 369 | return todos; |
370 | } | 370 | } |
371 | void CalendarLocal::reInitAlarmSettings() | 371 | void CalendarLocal::reInitAlarmSettings() |
372 | { | 372 | { |
373 | if ( !mNextAlarmIncidence ) { | 373 | if ( !mNextAlarmIncidence ) { |
374 | nextAlarm( 1000 ); | 374 | nextAlarm( 1000 ); |
375 | } | 375 | } |
376 | deRegisterAlarm(); | 376 | deRegisterAlarm(); |
377 | mNextAlarmIncidence = 0; | 377 | mNextAlarmIncidence = 0; |
378 | checkAlarmForIncidence( 0, false ); | 378 | checkAlarmForIncidence( 0, false ); |
379 | 379 | ||
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | 383 | ||
384 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 384 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
385 | { | 385 | { |
386 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 386 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
387 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 387 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
388 | QDateTime next; | 388 | QDateTime next; |
389 | Event *e; | 389 | Event *e; |
390 | bool ok; | 390 | bool ok; |
391 | bool found = false; | 391 | bool found = false; |
392 | int offset; | 392 | int offset; |
393 | mNextAlarmIncidence = 0; | 393 | mNextAlarmIncidence = 0; |
394 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 394 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
395 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 395 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
396 | if ( ok ) { | 396 | if ( ok ) { |
397 | if ( next < nextA ) { | 397 | if ( next < nextA ) { |
398 | nextA = next; | 398 | nextA = next; |
399 | found = true; | 399 | found = true; |
400 | mNextSummary = e->summary(); | 400 | mNextSummary = e->summary(); |
401 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 401 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
402 | mNextAlarmIncidence = (Incidence *) e; | 402 | mNextAlarmIncidence = (Incidence *) e; |
403 | } | 403 | } |
404 | } | 404 | } |
405 | } | 405 | } |
406 | Todo *t; | 406 | Todo *t; |
407 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 407 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
408 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 408 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
409 | if ( ok ) { | 409 | if ( ok ) { |
410 | if ( next < nextA ) { | 410 | if ( next < nextA ) { |
411 | nextA = next; | 411 | nextA = next; |
412 | found = true; | 412 | found = true; |
413 | mNextSummary = t->summary(); | 413 | mNextSummary = t->summary(); |
414 | mNextAlarmEventDateTime = next.addSecs(offset ); | 414 | mNextAlarmEventDateTime = next.addSecs(offset ); |
415 | mNextAlarmIncidence = (Incidence *) t; | 415 | mNextAlarmIncidence = (Incidence *) t; |
416 | } | 416 | } |
417 | } | 417 | } |
418 | } | 418 | } |
419 | if ( mNextAlarmIncidence ) { | 419 | if ( mNextAlarmIncidence ) { |
420 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 420 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
421 | mNextAlarmDateTime = nextA; | 421 | mNextAlarmDateTime = nextA; |
422 | } | 422 | } |
423 | return nextA; | 423 | return nextA; |
424 | } | 424 | } |
425 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 425 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
426 | { | 426 | { |
427 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 427 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
428 | } | 428 | } |
429 | 429 | ||
430 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 430 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |