• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

  • kcalcore
memorycalendar.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5  Copyright (c) 2001,2003,2004 Cornelius Schumacher <schumacher@kde.org>
6  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
35 #include "memorycalendar.h"
36 
37 #include <KDebug>
38 
39 using namespace KCalCore;
40 
45 //@cond PRIVATE
46 class KCalCore::MemoryCalendar::Private
47 {
48  public:
49  Private( MemoryCalendar *qq )
50  : q( qq ), mFormat( 0 )
51  {
52  }
53  ~Private()
54  {
55  }
56 
57  MemoryCalendar *q;
58  QString mFileName; // filename where calendar is stored
59  CalFormat *mFormat; // calendar format
60 
65  QMap<IncidenceBase::IncidenceType, QMultiHash<QString, Incidence::Ptr> > mIncidences;
66 
71  QMap<IncidenceBase::IncidenceType, QMultiHash<QString, Incidence::Ptr> > mDeletedIncidences;
72 
84  QMap<IncidenceBase::IncidenceType, QMultiHash<QString, IncidenceBase::Ptr> > mIncidencesForDate;
85 
86  void insertIncidence( Incidence::Ptr incidence );
87 
88  Incidence::Ptr incidence( const QString &uid,
89  const IncidenceBase::IncidenceType type,
90  const KDateTime &recurrenceId = KDateTime() ) const;
91 
92  Incidence::Ptr deletedIncidence( const QString &uid,
93  const KDateTime &recurrenceId,
94  const IncidenceBase::IncidenceType type ) const;
95 
96  void deleteAllIncidences( const IncidenceBase::IncidenceType type );
97 
98 };
99 
100 MemoryCalendar::MemoryCalendar( const KDateTime::Spec &timeSpec )
101  : Calendar( timeSpec ),
102  d( new KCalCore::MemoryCalendar::Private( this ) )
103 {
104 }
105 
106 MemoryCalendar::MemoryCalendar( const QString &timeZoneId )
107  : Calendar( timeZoneId ),
108  d( new KCalCore::MemoryCalendar::Private( this ) )
109 {
110 }
111 
112 MemoryCalendar::~MemoryCalendar()
113 {
114  close();
115  delete d;
116 }
117 
118 void MemoryCalendar::close()
119 {
120  setObserversEnabled( false );
121  d->mFileName.clear();
122 
123  deleteAllEvents();
124  deleteAllTodos();
125  deleteAllJournals();
126 
127  d->mDeletedIncidences.clear();
128 
129  setModified( false );
130 
131  setObserversEnabled( true );
132 }
133 
134 bool MemoryCalendar::deleteIncidence( const Incidence::Ptr &incidence )
135 {
136  // Handle orphaned children
137  // relations is an Incidence's property, not a Todo's, so
138  // we remove relations in deleteIncidence, not in deleteTodo.
139  removeRelations( incidence );
140  const Incidence::IncidenceType type = incidence->type();
141  const QString uid = incidence->uid();
142  if ( d->mIncidences[type].remove( uid, incidence ) ) {
143  setModified( true );
144  notifyIncidenceDeleted( incidence );
145  d->mDeletedIncidences[type].insert( uid, incidence );
146 
147  const KDateTime dt = incidence->dateTime( Incidence::RoleCalendarHashing );
148  if ( dt.isValid() ) {
149  d->mIncidencesForDate[type].remove( dt.date().toString(), incidence );
150  }
151  // Delete child-incidences.
152  if ( !incidence->hasRecurrenceId() ) {
153  deleteIncidenceInstances( incidence );
154  }
155  return true;
156  } else {
157  kWarning() << incidence->typeStr() << " not found.";
158  return false;
159  }
160 }
161 
162 bool MemoryCalendar::deleteIncidenceInstances( const Incidence::Ptr &incidence )
163 {
164  const Incidence::IncidenceType type = incidence->type();
165  QList<Incidence::Ptr> values = d->mIncidences[type].values( incidence->uid() );
166  QList<Incidence::Ptr>::const_iterator it;
167  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
168  Incidence::Ptr i = *it;
169  if ( i->hasRecurrenceId() ) {
170  kDebug() << "deleting child"
171  << ", type=" << int( type )
172  << ", uid=" << i->uid()
173  << ", start=" << i->dtStart()
174  << " from calendar";
175  deleteIncidence( i );
176  }
177  }
178 
179  return true;
180 }
181 
182 void MemoryCalendar::Private::deleteAllIncidences( const Incidence::IncidenceType incidenceType )
183 {
184  QHashIterator<QString, Incidence::Ptr>i( mIncidences[incidenceType] );
185  while ( i.hasNext() ) {
186  i.next();
187  q->notifyIncidenceDeleted( i.value() );
188  // suppress update notifications for the relation removal triggered
189  // by the following deletions
190  i.value()->startUpdates();
191  }
192  mIncidences[incidenceType].clear();
193  mIncidencesForDate[incidenceType].clear();
194 }
195 
196 Incidence::Ptr MemoryCalendar::Private::incidence( const QString &uid,
197  const Incidence::IncidenceType type,
198  const KDateTime &recurrenceId ) const
199 {
200  QList<Incidence::Ptr> values = mIncidences[type].values( uid );
201  QList<Incidence::Ptr>::const_iterator it;
202  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
203  Incidence::Ptr i = *it;
204  if ( recurrenceId.isNull() ) {
205  if ( !i->hasRecurrenceId() ) {
206  return i;
207  }
208  } else {
209  if ( i->hasRecurrenceId() && i->recurrenceId() == recurrenceId ) {
210  return i;
211  }
212  }
213  }
214  return Incidence::Ptr();
215 }
216 
217 Incidence::Ptr
218 MemoryCalendar::Private::deletedIncidence( const QString &uid,
219  const KDateTime &recurrenceId,
220  const IncidenceBase::IncidenceType type ) const
221 {
222  QList<Incidence::Ptr> values = mDeletedIncidences[type].values( uid );
223  QList<Incidence::Ptr>::const_iterator it;
224  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
225  Incidence::Ptr i = *it;
226  if ( recurrenceId.isNull() ) {
227  if ( !i->hasRecurrenceId() ) {
228  return i;
229  }
230  } else {
231  if ( i->hasRecurrenceId() && i->recurrenceId() == recurrenceId ) {
232  return i;
233  }
234  }
235  }
236  return Incidence::Ptr();
237 }
238 
239 //@cond PRIVATE
240 void MemoryCalendar::Private::insertIncidence( Incidence::Ptr incidence )
241 {
242  const QString uid = incidence->uid();
243  const Incidence::IncidenceType type = incidence->type();
244  if ( !mIncidences[type].contains( uid, incidence ) ) {
245  mIncidences[type].insert( uid, incidence );
246  const KDateTime dt = incidence->dateTime( Incidence::RoleCalendarHashing );
247  if ( dt.isValid() ) {
248  mIncidencesForDate[type].insert( dt.date().toString(), incidence );
249  }
250 
251  } else {
252 #ifndef NDEBUG
253  // if we already have an to-do with this UID, it must be the same incidence,
254  // otherwise something's really broken
255  Q_ASSERT( mIncidences[type].value( uid ) == incidence );
256 #endif
257  }
258 }
259 //@endcond
260 
261 bool MemoryCalendar::addIncidence( const Incidence::Ptr &incidence )
262 {
263  notifyIncidenceAdded( incidence );
264 
265  d->insertIncidence( incidence );
266 
267  incidence->registerObserver( this );
268 
269  setupRelations( incidence );
270 
271  setModified( true );
272 
273  return true;
274 }
275 
276 bool MemoryCalendar::addEvent( const Event::Ptr &event )
277 {
278  return addIncidence( event );
279 }
280 
281 bool MemoryCalendar::deleteEvent( const Event::Ptr &event )
282 {
283  return deleteIncidence( event );
284 }
285 
286 bool MemoryCalendar::deleteEventInstances( const Event::Ptr &event )
287 {
288  return deleteIncidenceInstances( event );
289 }
290 
291 void MemoryCalendar::deleteAllEvents()
292 {
293  d->deleteAllIncidences( Incidence::TypeEvent );
294 }
295 
296 Event::Ptr MemoryCalendar::event( const QString &uid,
297  const KDateTime &recurrenceId ) const
298 {
299  return d->incidence( uid, Incidence::TypeEvent, recurrenceId ).staticCast<Event>();
300 }
301 
302 Event::Ptr MemoryCalendar::deletedEvent( const QString &uid, const KDateTime &recurrenceId ) const
303 {
304  return d->deletedIncidence( uid, recurrenceId, Incidence::TypeEvent ).staticCast<Event>();
305 }
306 
307 bool MemoryCalendar::addTodo( const Todo::Ptr &todo )
308 {
309  return addIncidence( todo );
310 }
311 
312 bool MemoryCalendar::deleteTodo( const Todo::Ptr &todo )
313 {
314  return deleteIncidence( todo );
315 }
316 
317 bool MemoryCalendar::deleteTodoInstances( const Todo::Ptr &todo )
318 {
319  return deleteIncidenceInstances( todo );
320 }
321 
322 void MemoryCalendar::deleteAllTodos()
323 {
324  d->deleteAllIncidences( Incidence::TypeTodo );
325 }
326 
327 Todo::Ptr MemoryCalendar::todo( const QString &uid,
328  const KDateTime &recurrenceId ) const
329 {
330  return d->incidence( uid, Incidence::TypeTodo, recurrenceId ).staticCast<Todo>();
331 }
332 
333 Todo::Ptr MemoryCalendar::deletedTodo( const QString &uid,
334  const KDateTime &recurrenceId ) const
335 {
336  return d->deletedIncidence( uid, recurrenceId, Incidence::TypeTodo ).staticCast<Todo>();
337 }
338 
339 Todo::List MemoryCalendar::rawTodos( TodoSortField sortField,
340  SortDirection sortDirection ) const
341 {
342  Todo::List todoList;
343  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeTodo] );
344  while ( i.hasNext() ) {
345  i.next();
346  todoList.append( i.value().staticCast<Todo>() );
347  }
348  return Calendar::sortTodos( todoList, sortField, sortDirection );
349 }
350 
351 Todo::List MemoryCalendar::deletedTodos( TodoSortField sortField,
352  SortDirection sortDirection ) const
353 {
354  Todo::List todoList;
355  QHashIterator<QString, Incidence::Ptr >i( d->mDeletedIncidences[Incidence::TypeTodo] );
356  while ( i.hasNext() ) {
357  i.next();
358  todoList.append( i.value().staticCast<Todo>() );
359  }
360  return Calendar::sortTodos( todoList, sortField, sortDirection );
361 }
362 
363 Todo::List MemoryCalendar::todoInstances( const Incidence::Ptr &todo,
364  TodoSortField sortField,
365  SortDirection sortDirection ) const
366 {
367  Todo::List list;
368 
369  QList<Incidence::Ptr > values = d->mIncidences[Incidence::TypeTodo].values( todo->uid() );
370  QList<Incidence::Ptr>::const_iterator it;
371  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
372  Todo::Ptr t = ( *it ).staticCast<Todo>();
373  if ( t->hasRecurrenceId() ) {
374  list.append( t );
375  }
376  }
377  return Calendar::sortTodos( list, sortField, sortDirection );
378 }
379 
380 Todo::List MemoryCalendar::rawTodosForDate( const QDate &date ) const
381 {
382  Todo::List todoList;
383  Todo::Ptr t;
384 
385  KDateTime::Spec ts = timeSpec();
386  const QString dateStr = date.toString();
387  QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
388  d->mIncidencesForDate[Incidence::TypeTodo].constFind( dateStr );
389  while ( it != d->mIncidencesForDate[Incidence::TypeTodo].constEnd() && it.key() == dateStr ) {
390  t = it.value().staticCast<Todo>();
391  todoList.append( t );
392  ++it;
393  }
394 
395  // Iterate over all todos. Look for recurring todoss that occur on this date
396  QHashIterator<QString, Incidence::Ptr >i( d->mIncidences[Incidence::TypeTodo] );
397  while ( i.hasNext() ) {
398  i.next();
399  t = i.value().staticCast<Todo>();
400  if ( t->recurs() ) {
401  if ( t->recursOn( date, ts ) ) {
402  todoList.append( t );
403  }
404  }
405  }
406 
407  return todoList;
408 }
409 
410 Todo::List MemoryCalendar::rawTodos( const QDate &start,
411  const QDate &end,
412  const KDateTime::Spec &timespec,
413  bool inclusive ) const
414 {
415  Q_UNUSED( inclusive ); // use only exact dtDue/dtStart, not dtStart and dtEnd
416 
417  Todo::List todoList;
418  KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
419  KDateTime st( start, ts );
420  KDateTime nd( end, ts );
421 
422  // Get todos
423  QHashIterator<QString, Incidence::Ptr >i( d->mIncidences[Incidence::TypeTodo] );
424  Todo::Ptr todo;
425  while ( i.hasNext() ) {
426  i.next();
427  todo = i.value().staticCast<Todo>();
428  if ( !isVisible( todo ) ) {
429  continue;
430  }
431 
432  KDateTime rStart = todo->hasDueDate() ? todo->dtDue() :
433  todo->hasStartDate() ? todo->dtStart() : KDateTime();
434  if ( !rStart.isValid() ) {
435  continue;
436  }
437 
438  if ( !todo->recurs() ) { // non-recurring todos
439  if ( nd.isValid() && nd < rStart ) {
440  continue;
441  }
442  if ( st.isValid() && rStart < st ) {
443  continue;
444  }
445  } else { // recurring events
446  switch( todo->recurrence()->duration() ) {
447  case -1: // infinite
448  break;
449  case 0: // end date given
450  default: // count given
451  KDateTime rEnd( todo->recurrence()->endDate(), ts );
452  if ( !rEnd.isValid() ) {
453  continue;
454  }
455  if ( st.isValid() && rEnd < st ) {
456  continue;
457  }
458  break;
459  } // switch(duration)
460  } //if(recurs)
461 
462  todoList.append( todo );
463  }
464 
465  return todoList;
466 }
467 
468 Alarm::List MemoryCalendar::alarmsTo( const KDateTime &to ) const
469 {
470  return alarms( KDateTime( QDate( 1900, 1, 1 ) ), to );
471 }
472 
473 Alarm::List MemoryCalendar::alarms( const KDateTime &from, const KDateTime &to ) const
474 {
475  Alarm::List alarmList;
476  QHashIterator<QString, Incidence::Ptr>ie( d->mIncidences[Incidence::TypeEvent] );
477  Event::Ptr e;
478  while ( ie.hasNext() ) {
479  ie.next();
480  e = ie.value().staticCast<Event>();
481  if ( e->recurs() ) {
482  appendRecurringAlarms( alarmList, e, from, to );
483  } else {
484  appendAlarms( alarmList, e, from, to );
485  }
486  }
487 
488  QHashIterator<QString, Incidence::Ptr>it( d->mIncidences[Incidence::TypeTodo] );
489  Todo::Ptr t;
490  while ( it.hasNext() ) {
491  it.next();
492  t = it.value().staticCast<Todo>();
493 
494  if ( !t->isCompleted() ) {
495  appendAlarms( alarmList, t, from, to );
496  if ( t->recurs() ) {
497  appendRecurringAlarms( alarmList, t, from, to );
498  } else {
499  appendAlarms( alarmList, t, from, to );
500  }
501  }
502  }
503 
504  return alarmList;
505 }
506 
507 void MemoryCalendar::incidenceUpdate( const QString &uid, const KDateTime &recurrenceId )
508 {
509  Incidence::Ptr inc = incidence( uid, recurrenceId );
510 
511  if ( inc ) {
512  const Incidence::IncidenceType type = inc->type();
513  const KDateTime dt = inc->dateTime( Incidence::RoleCalendarHashing );
514 
515  if ( dt.isValid() ) {
516  d->mIncidencesForDate[type].remove( dt.date().toString(), inc );
517  }
518  }
519 }
520 
521 void MemoryCalendar::incidenceUpdated( const QString &uid, const KDateTime &recurrenceId )
522 {
523  Incidence::Ptr inc = incidence( uid, recurrenceId );
524 
525  if ( inc ) {
526  KDateTime nowUTC = KDateTime::currentUtcDateTime();
527  inc->setLastModified( nowUTC );
528  // we should probably update the revision number here,
529  // or internally in the Event itself when certain things change.
530  // need to verify with ical documentation.
531 
532  const Incidence::IncidenceType type = inc->type();
533  const KDateTime dt = inc->dateTime( Incidence::RoleCalendarHashing );
534 
535  if ( dt.isValid() ) {
536  d->mIncidencesForDate[type].insert( dt.date().toString(), inc );
537  }
538 
539  notifyIncidenceChanged( inc );
540 
541  setModified( true );
542  }
543 }
544 
545 Event::List MemoryCalendar::rawEventsForDate( const QDate &date,
546  const KDateTime::Spec &timespec,
547  EventSortField sortField,
548  SortDirection sortDirection ) const
549 {
550  Event::List eventList;
551  Event::Ptr ev;
552 
553  // Find the hash for the specified date
554  const QString dateStr = date.toString();
555  QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
556  d->mIncidencesForDate[Incidence::TypeEvent].constFind( dateStr );
557  // Iterate over all non-recurring, single-day events that start on this date
558  KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
559  KDateTime kdt( date, ts );
560  while ( it != d->mIncidencesForDate[Incidence::TypeEvent].constEnd() && it.key() == dateStr ) {
561  ev = it.value().staticCast<Event>();
562  KDateTime end( ev->dtEnd().toTimeSpec( ev->dtStart() ) );
563  if ( ev->allDay() ) {
564  end.setDateOnly( true );
565  } else {
566  end = end.addSecs( -1 );
567  }
568  if ( end >= kdt ) {
569  eventList.append( ev );
570  }
571  ++it;
572  }
573 
574  // Iterate over all events. Look for recurring events that occur on this date
575  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
576  while ( i.hasNext() ) {
577  i.next();
578  ev = i.value().staticCast<Event>();
579  if ( ev->recurs() ) {
580  if ( ev->isMultiDay() ) {
581  int extraDays = ev->dtStart().date().daysTo( ev->dtEnd().date() );
582  for ( int i = 0; i <= extraDays; ++i ) {
583  if ( ev->recursOn( date.addDays( -i ), ts ) ) {
584  eventList.append( ev );
585  break;
586  }
587  }
588  } else {
589  if ( ev->recursOn( date, ts ) ) {
590  eventList.append( ev );
591  }
592  }
593  } else {
594  if ( ev->isMultiDay() ) {
595  if ( ev->dtStart().date() <= date && ev->dtEnd().date() >= date ) {
596  eventList.append( ev );
597  }
598  }
599  }
600  }
601 
602  return Calendar::sortEvents( eventList, sortField, sortDirection );
603 }
604 
605 Event::List MemoryCalendar::rawEvents( const QDate &start,
606  const QDate &end,
607  const KDateTime::Spec &timespec,
608  bool inclusive ) const
609 {
610  Event::List eventList;
611  KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
612  KDateTime st( start, ts );
613  KDateTime nd( end, ts );
614  KDateTime yesterStart = st.addDays( -1 );
615 
616  // Get non-recurring events
617  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
618  Event::Ptr event;
619  while ( i.hasNext() ) {
620  i.next();
621  event = i.value().staticCast<Event>();
622  KDateTime rStart = event->dtStart();
623  if ( nd < rStart ) {
624  continue;
625  }
626  if ( inclusive && rStart < st ) {
627  continue;
628  }
629 
630  if ( !event->recurs() ) { // non-recurring events
631  KDateTime rEnd = event->dtEnd();
632  if ( rEnd < st ) {
633  continue;
634  }
635  if ( inclusive && nd < rEnd ) {
636  continue;
637  }
638  } else { // recurring events
639  switch( event->recurrence()->duration() ) {
640  case -1: // infinite
641  if ( inclusive ) {
642  continue;
643  }
644  break;
645  case 0: // end date given
646  default: // count given
647  KDateTime rEnd( event->recurrence()->endDate(), ts );
648  if ( !rEnd.isValid() ) {
649  continue;
650  }
651  if ( rEnd < st ) {
652  continue;
653  }
654  if ( inclusive && nd < rEnd ) {
655  continue;
656  }
657  break;
658  } // switch(duration)
659  } //if(recurs)
660 
661  eventList.append( event );
662  }
663 
664  return eventList;
665 }
666 
667 Event::List MemoryCalendar::rawEventsForDate( const KDateTime &kdt ) const
668 {
669  return rawEventsForDate( kdt.date(), kdt.timeSpec() );
670 }
671 
672 Event::List MemoryCalendar::rawEvents( EventSortField sortField,
673  SortDirection sortDirection ) const
674 {
675  Event::List eventList;
676  QHashIterator<QString, Incidence::Ptr> i( d->mIncidences[Incidence::TypeEvent] );
677  while ( i.hasNext() ) {
678  i.next();
679  eventList.append( i.value().staticCast<Event>() );
680  }
681  return Calendar::sortEvents( eventList, sortField, sortDirection );
682 }
683 
684 Event::List MemoryCalendar::deletedEvents( EventSortField sortField,
685  SortDirection sortDirection ) const
686 {
687  Event::List eventList;
688  QHashIterator<QString, Incidence::Ptr>i( d->mDeletedIncidences[Incidence::TypeEvent] );
689  while ( i.hasNext() ) {
690  i.next();
691  eventList.append( i.value().staticCast<Event>() );
692  }
693  return Calendar::sortEvents( eventList, sortField, sortDirection );
694 }
695 
696 Event::List MemoryCalendar::eventInstances( const Incidence::Ptr &event,
697  EventSortField sortField,
698  SortDirection sortDirection ) const
699 {
700  Event::List list;
701 
702  QList<Incidence::Ptr> values = d->mIncidences[Incidence::TypeEvent].values( event->uid() );
703  QList<Incidence::Ptr>::const_iterator it;
704  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
705  Event::Ptr ev = ( *it ).staticCast<Event>();
706  if ( ev->hasRecurrenceId() ) {
707  list.append( ev );
708  }
709  }
710  return Calendar::sortEvents( list, sortField, sortDirection );
711 }
712 
713 bool MemoryCalendar::addJournal( const Journal::Ptr &journal )
714 {
715  return addIncidence( journal );
716 }
717 
718 bool MemoryCalendar::deleteJournal( const Journal::Ptr &journal )
719 {
720  return deleteIncidence( journal );
721 }
722 
723 bool MemoryCalendar::deleteJournalInstances( const Journal::Ptr &journal )
724 {
725  return deleteIncidenceInstances( journal );
726 }
727 
728 void MemoryCalendar::deleteAllJournals()
729 {
730  d->deleteAllIncidences( Incidence::TypeJournal );
731 }
732 
733 Journal::Ptr MemoryCalendar::journal( const QString &uid,
734  const KDateTime &recurrenceId ) const
735 {
736  return d->incidence( uid, Incidence::TypeJournal, recurrenceId ).staticCast<Journal>();
737 }
738 
739 Journal::Ptr MemoryCalendar::deletedJournal( const QString &uid,
740  const KDateTime &recurrenceId ) const
741 {
742  return d->deletedIncidence( uid, recurrenceId, Incidence::TypeJournal ).staticCast<Journal>();
743 }
744 
745 Journal::List MemoryCalendar::rawJournals( JournalSortField sortField,
746  SortDirection sortDirection ) const
747 {
748  Journal::List journalList;
749  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeJournal] );
750  while ( i.hasNext() ) {
751  i.next();
752  journalList.append( i.value().staticCast<Journal>() );
753  }
754  return Calendar::sortJournals( journalList, sortField, sortDirection );
755 }
756 
757 Journal::List MemoryCalendar::deletedJournals( JournalSortField sortField,
758  SortDirection sortDirection ) const
759 {
760  Journal::List journalList;
761  QHashIterator<QString, Incidence::Ptr>i( d->mDeletedIncidences[Incidence::TypeJournal] );
762  while ( i.hasNext() ) {
763  i.next();
764  journalList.append( i.value().staticCast<Journal>() );
765  }
766  return Calendar::sortJournals( journalList, sortField, sortDirection );
767 }
768 
769 Journal::List MemoryCalendar::journalInstances( const Incidence::Ptr &journal,
770  JournalSortField sortField,
771  SortDirection sortDirection ) const
772 {
773  Journal::List list;
774 
775  QList<Incidence::Ptr> values = d->mIncidences[Incidence::TypeJournal].values( journal->uid() );
776  QList<Incidence::Ptr>::const_iterator it;
777  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
778  Journal::Ptr j = ( *it ).staticCast<Journal>();
779  if ( j->hasRecurrenceId() ) {
780  list.append( j );
781  }
782  }
783  return Calendar::sortJournals( list, sortField, sortDirection );
784 }
785 
786 Journal::List MemoryCalendar::rawJournalsForDate( const QDate &date ) const
787 {
788  Journal::List journalList;
789  Journal::Ptr j;
790 
791  QString dateStr = date.toString();
792  QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
793  d->mIncidencesForDate[Incidence::TypeJournal].constFind( dateStr );
794 
795  while ( it != d->mIncidencesForDate[Incidence::TypeJournal].constEnd() && it.key() == dateStr ) {
796  j = it.value().staticCast<Journal>();
797  journalList.append( j );
798  ++it;
799  }
800  return journalList;
801 }
802 
803 void MemoryCalendar::virtual_hook( int id, void *data )
804 {
805  Q_UNUSED( id );
806  Q_UNUSED( data );
807  Q_ASSERT( false );
808 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed Nov 28 2012 21:41:10 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

Skip menu "KCalCore Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal