summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 3c572f0..09ce9f0 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -97,355 +97,367 @@ void CalendarLocal::close()
97 setModified( false ); 97 setModified( false );
98} 98}
99 99
100bool CalendarLocal::addAnniversaryNoDup( Event *event ) 100bool 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}
130bool CalendarLocal::addEventNoDup( Event *event ) 130bool 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
142bool CalendarLocal::addEvent( Event *event ) 142bool 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
153void CalendarLocal::deleteEvent( Event *event ) 153void 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
163Event *CalendarLocal::event( const QString &uid ) 163Event *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}
176bool CalendarLocal::addTodoNoDup( Todo *todo ) 176bool 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}
187bool CalendarLocal::addTodo( Todo *todo ) 187bool 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
201void CalendarLocal::deleteTodo( Todo *todo ) 201void 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
211QPtrList<Todo> CalendarLocal::rawTodos() 211QPtrList<Todo> CalendarLocal::rawTodos()
212{ 212{
213 return mTodoList; 213 return mTodoList;
214} 214}
215Todo *CalendarLocal::todo( int id ) 215Todo *CalendarLocal::todo( int 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->zaurusId() == id ) return todo; 219 if ( todo->zaurusId() == id ) return todo;
220 } 220 }
221 221
222 return 0; 222 return 0;
223} 223}
224 224
225QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
226{
227 QPtrList<Event> el;
228 Event *todo;
229 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
230 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
231 if ( todo->summary().left(3) == "E: " )
232 el.append( todo );
233 }
234
235 return el;
236
237}
225Event *CalendarLocal::event( int id ) 238Event *CalendarLocal::event( int id )
226{ 239{
227 Event *todo; 240 Event *todo;
228 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 241 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
229 if ( todo->zaurusId() == id ) return todo; 242 if ( todo->zaurusId() == id ) return todo;
230 } 243 }
231 244
232 return 0; 245 return 0;
233} 246}
234Todo *CalendarLocal::todo( const QString &uid ) 247Todo *CalendarLocal::todo( const QString &uid )
235{ 248{
236 Todo *todo; 249 Todo *todo;
237 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 250 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
238 if ( todo->uid() == uid ) return todo; 251 if ( todo->uid() == uid ) return todo;
239 } 252 }
240 253
241 return 0; 254 return 0;
242} 255}
243QString CalendarLocal::nextSummary() const 256QString CalendarLocal::nextSummary() const
244{ 257{
245 return mNextSummary; 258 return mNextSummary;
246} 259}
247QDateTime CalendarLocal::nextAlarmEventDateTime() const 260QDateTime CalendarLocal::nextAlarmEventDateTime() const
248{ 261{
249 return mNextAlarmEventDateTime; 262 return mNextAlarmEventDateTime;
250} 263}
251void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 264void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
252{ 265{
253 //mNextAlarmIncidence 266 //mNextAlarmIncidence
254 //mNextAlarmDateTime 267 //mNextAlarmDateTime
255 //return mNextSummary; 268 //return mNextSummary;
256 //return mNextAlarmEventDateTime; 269 //return mNextAlarmEventDateTime;
257 bool newNextAlarm = false; 270 bool newNextAlarm = false;
258 bool computeNextAlarm = false; 271 bool computeNextAlarm = false;
259 bool ok; 272 bool ok;
260 int offset; 273 int offset;
261 QDateTime nextA; 274 QDateTime nextA;
262 // QString nextSum; 275 // QString nextSum;
263 //QDateTime nextEvent; 276 //QDateTime nextEvent;
264 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 277 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
265 computeNextAlarm = true; 278 computeNextAlarm = true;
266 } else { 279 } else {
267 if ( ! deleted ) { 280 if ( ! deleted ) {
268 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; 281 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ;
269 if ( ok ) { 282 if ( ok ) {
270 if ( nextA < mNextAlarmDateTime ) { 283 if ( nextA < mNextAlarmDateTime ) {
271 deRegisterAlarm(); 284 deRegisterAlarm();
272 mNextAlarmDateTime = nextA; 285 mNextAlarmDateTime = nextA;
273 mNextSummary = incidence->summary(); 286 mNextSummary = incidence->summary();
274 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 287 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
275 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 288 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
276 newNextAlarm = true; 289 newNextAlarm = true;
277 mNextAlarmIncidence = incidence; 290 mNextAlarmIncidence = incidence;
278 } else { 291 } else {
279 if ( incidence == mNextAlarmIncidence ) { 292 if ( incidence == mNextAlarmIncidence ) {
280 computeNextAlarm = true; 293 computeNextAlarm = true;
281 } 294 }
282 } 295 }
283 } else { 296 } else {
284 if ( mNextAlarmIncidence == incidence ) { 297 if ( mNextAlarmIncidence == incidence ) {
285 computeNextAlarm = true; 298 computeNextAlarm = true;
286 } 299 }
287 } 300 }
288 } else { // deleted 301 } else { // deleted
289 if ( incidence == mNextAlarmIncidence ) { 302 if ( incidence == mNextAlarmIncidence ) {
290 computeNextAlarm = true; 303 computeNextAlarm = true;
291 } 304 }
292 } 305 }
293 } 306 }
294 if ( computeNextAlarm ) { 307 if ( computeNextAlarm ) {
295 deRegisterAlarm(); 308 deRegisterAlarm();
296 nextA = nextAlarm( 1000 ); 309 nextA = nextAlarm( 1000 );
297 if (! mNextAlarmIncidence ) { 310 if (! mNextAlarmIncidence ) {
298 return; 311 return;
299 } 312 }
300 newNextAlarm = true; 313 newNextAlarm = true;
301 } 314 }
302 if ( newNextAlarm ) 315 if ( newNextAlarm )
303 registerAlarm(); 316 registerAlarm();
304} 317}
305QString CalendarLocal:: getAlarmNotification() 318QString CalendarLocal:: getAlarmNotification()
306{ 319{
307 QString ret; 320 QString ret;
308 // this should not happen 321 // this should not happen
309 if (! mNextAlarmIncidence ) 322 if (! mNextAlarmIncidence )
310 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 323 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
311 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 324 Alarm* alarm = mNextAlarmIncidence->alarms().first();
312 if ( alarm->type() == Alarm::Procedure ) { 325 if ( alarm->type() == Alarm::Procedure ) {
313 ret = "proc_alarm" + alarm->programFile()+"+++"; 326 ret = "proc_alarm" + alarm->programFile()+"+++";
314 } else { 327 } else {
315 ret = "audio_alarm" +alarm->audioFile() +"+++"; 328 ret = "audio_alarm" +alarm->audioFile() +"+++";
316 } 329 }
317 ret += "cal_alarm"+ mNextSummary.left( 25 ); 330 ret += "cal_alarm"+ mNextSummary.left( 25 );
318 if ( mNextSummary.length() > 25 ) 331 if ( mNextSummary.length() > 25 )
319 ret += "\n" + mNextSummary.mid(25, 25 ); 332 ret += "\n" + mNextSummary.mid(25, 25 );
320 ret+= "\n"+mNextAlarmEventDateTimeString; 333 ret+= "\n"+mNextAlarmEventDateTimeString;
321 return ret; 334 return ret;
322} 335}
323
324void CalendarLocal::registerAlarm() 336void CalendarLocal::registerAlarm()
325{ 337{
326 mLastAlarmNotificationString = getAlarmNotification(); 338 mLastAlarmNotificationString = getAlarmNotification();
327 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 339 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
328 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 340 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
329// #ifndef DESKTOP_VERSION 341// #ifndef DESKTOP_VERSION
330// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 342// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
331// #endif 343// #endif
332} 344}
333void CalendarLocal::deRegisterAlarm() 345void CalendarLocal::deRegisterAlarm()
334{ 346{
335 if ( mLastAlarmNotificationString.isNull() ) 347 if ( mLastAlarmNotificationString.isNull() )
336 return; 348 return;
337 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 349 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
338 350
339 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 351 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
340// #ifndef DESKTOP_VERSION 352// #ifndef DESKTOP_VERSION
341// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 353// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
342// #endif 354// #endif
343} 355}
344 356
345QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 357QPtrList<Todo> CalendarLocal::todos( const QDate &date )
346{ 358{
347 QPtrList<Todo> todos; 359 QPtrList<Todo> todos;
348 360
349 Todo *todo; 361 Todo *todo;
350 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 362 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
351 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 363 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
352 todos.append( todo ); 364 todos.append( todo );
353 } 365 }
354 } 366 }
355 367
356 filter()->apply( &todos ); 368 filter()->apply( &todos );
357 return todos; 369 return todos;
358} 370}
359void CalendarLocal::reInitAlarmSettings() 371void CalendarLocal::reInitAlarmSettings()
360{ 372{
361 if ( !mNextAlarmIncidence ) { 373 if ( !mNextAlarmIncidence ) {
362 nextAlarm( 1000 ); 374 nextAlarm( 1000 );
363 } 375 }
364 deRegisterAlarm(); 376 deRegisterAlarm();
365 mNextAlarmIncidence = 0; 377 mNextAlarmIncidence = 0;
366 checkAlarmForIncidence( 0, false ); 378 checkAlarmForIncidence( 0, false );
367 379
368} 380}
369 381
370 382
371 383
372QDateTime CalendarLocal::nextAlarm( int daysTo ) 384QDateTime CalendarLocal::nextAlarm( int daysTo )
373{ 385{
374 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 386 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
375 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 387 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
376 QDateTime next; 388 QDateTime next;
377 Event *e; 389 Event *e;
378 bool ok; 390 bool ok;
379 bool found = false; 391 bool found = false;
380 int offset; 392 int offset;
381 mNextAlarmIncidence = 0; 393 mNextAlarmIncidence = 0;
382 for( e = mEventList.first(); e; e = mEventList.next() ) { 394 for( e = mEventList.first(); e; e = mEventList.next() ) {
383 next = e->getNextAlarmDateTime(& ok, &offset ) ; 395 next = e->getNextAlarmDateTime(& ok, &offset ) ;
384 if ( ok ) { 396 if ( ok ) {
385 if ( next < nextA ) { 397 if ( next < nextA ) {
386 nextA = next; 398 nextA = next;
387 found = true; 399 found = true;
388 mNextSummary = e->summary(); 400 mNextSummary = e->summary();
389 mNextAlarmEventDateTime = next.addSecs(offset ) ; 401 mNextAlarmEventDateTime = next.addSecs(offset ) ;
390 mNextAlarmIncidence = (Incidence *) e; 402 mNextAlarmIncidence = (Incidence *) e;
391 } 403 }
392 } 404 }
393 } 405 }
394 Todo *t; 406 Todo *t;
395 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 407 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
396 next = t->getNextAlarmDateTime(& ok, &offset ) ; 408 next = t->getNextAlarmDateTime(& ok, &offset ) ;
397 if ( ok ) { 409 if ( ok ) {
398 if ( next < nextA ) { 410 if ( next < nextA ) {
399 nextA = next; 411 nextA = next;
400 found = true; 412 found = true;
401 mNextSummary = t->summary(); 413 mNextSummary = t->summary();
402 mNextAlarmEventDateTime = next.addSecs(offset ); 414 mNextAlarmEventDateTime = next.addSecs(offset );
403 mNextAlarmIncidence = (Incidence *) t; 415 mNextAlarmIncidence = (Incidence *) t;
404 } 416 }
405 } 417 }
406 } 418 }
407 if ( mNextAlarmIncidence ) { 419 if ( mNextAlarmIncidence ) {
408 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 420 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
409 mNextAlarmDateTime = nextA; 421 mNextAlarmDateTime = nextA;
410 } 422 }
411 return nextA; 423 return nextA;
412} 424}
413Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 425Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
414{ 426{
415 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 427 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
416} 428}
417 429
418Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 430Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
419{ 431{
420 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " 432 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - "
421 << to.toString() << ")\n"; 433 << to.toString() << ")\n";
422 434
423 Alarm::List alarms; 435 Alarm::List alarms;
424 436
425 Event *e; 437 Event *e;
426 438
427 for( e = mEventList.first(); e; e = mEventList.next() ) { 439 for( e = mEventList.first(); e; e = mEventList.next() ) {
428 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 440 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
429 else appendAlarms( alarms, e, from, to ); 441 else appendAlarms( alarms, e, from, to );
430 } 442 }
431 443
432 Todo *t; 444 Todo *t;
433 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 445 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
434 appendAlarms( alarms, t, from, to ); 446 appendAlarms( alarms, t, from, to );
435 } 447 }
436 448
437 return alarms; 449 return alarms;
438} 450}
439 451
440void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 452void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
441 const QDateTime &from, const QDateTime &to ) 453 const QDateTime &from, const QDateTime &to )
442{ 454{
443 QPtrList<Alarm> alarmList = incidence->alarms(); 455 QPtrList<Alarm> alarmList = incidence->alarms();
444 Alarm *alarm; 456 Alarm *alarm;
445 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 457 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
446// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 458// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
447// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 459// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
448 if ( alarm->enabled() ) { 460 if ( alarm->enabled() ) {
449 if ( alarm->time() >= from && alarm->time() <= to ) { 461 if ( alarm->time() >= from && alarm->time() <= to ) {
450 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() 462 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary()
451 << "': " << alarm->time().toString() << endl; 463 << "': " << alarm->time().toString() << endl;