• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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 
552  if ( !date.isValid() ) {
553  // There can't be events on invalid dates
554  return eventList;
555  }
556 
557  Event::Ptr ev;
558 
559  // Find the hash for the specified date
560  const QString dateStr = date.toString();
561  QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
562  d->mIncidencesForDate[Incidence::TypeEvent].constFind( dateStr );
563  // Iterate over all non-recurring, single-day events that start on this date
564  KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
565  KDateTime kdt( date, ts );
566  while ( it != d->mIncidencesForDate[Incidence::TypeEvent].constEnd() && it.key() == dateStr ) {
567  ev = it.value().staticCast<Event>();
568  KDateTime end( ev->dtEnd().toTimeSpec( ev->dtStart() ) );
569  if ( ev->allDay() ) {
570  end.setDateOnly( true );
571  } else {
572  end = end.addSecs( -1 );
573  }
574  if ( end >= kdt ) {
575  eventList.append( ev );
576  }
577  ++it;
578  }
579 
580  // Iterate over all events. Look for recurring events that occur on this date
581  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
582  while ( i.hasNext() ) {
583  i.next();
584  ev = i.value().staticCast<Event>();
585  if ( ev->recurs() ) {
586  if ( ev->isMultiDay() ) {
587  int extraDays = ev->dtStart().date().daysTo( ev->dtEnd().date() );
588  for ( int i = 0; i <= extraDays; ++i ) {
589  if ( ev->recursOn( date.addDays( -i ), ts ) ) {
590  eventList.append( ev );
591  break;
592  }
593  }
594  } else {
595  if ( ev->recursOn( date, ts ) ) {
596  eventList.append( ev );
597  }
598  }
599  } else {
600  if ( ev->isMultiDay() ) {
601  if ( ev->dtStart().date() <= date && ev->dtEnd().date() >= date ) {
602  eventList.append( ev );
603  }
604  }
605  }
606  }
607 
608  return Calendar::sortEvents( eventList, sortField, sortDirection );
609 }
610 
611 Event::List MemoryCalendar::rawEvents( const QDate &start,
612  const QDate &end,
613  const KDateTime::Spec &timespec,
614  bool inclusive ) const
615 {
616  Event::List eventList;
617  KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
618  KDateTime st( start, ts );
619  KDateTime nd( end, ts );
620  KDateTime yesterStart = st.addDays( -1 );
621 
622  // Get non-recurring events
623  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
624  Event::Ptr event;
625  while ( i.hasNext() ) {
626  i.next();
627  event = i.value().staticCast<Event>();
628  KDateTime rStart = event->dtStart();
629  if ( nd < rStart ) {
630  continue;
631  }
632  if ( inclusive && rStart < st ) {
633  continue;
634  }
635 
636  if ( !event->recurs() ) { // non-recurring events
637  KDateTime rEnd = event->dtEnd();
638  if ( rEnd < st ) {
639  continue;
640  }
641  if ( inclusive && nd < rEnd ) {
642  continue;
643  }
644  } else { // recurring events
645  switch ( event->recurrence()->duration() ) {
646  case -1: // infinite
647  if ( inclusive ) {
648  continue;
649  }
650  break;
651  case 0: // end date given
652  default: // count given
653  KDateTime rEnd( event->recurrence()->endDate(), ts );
654  if ( !rEnd.isValid() ) {
655  continue;
656  }
657  if ( rEnd < st ) {
658  continue;
659  }
660  if ( inclusive && nd < rEnd ) {
661  continue;
662  }
663  break;
664  } // switch(duration)
665  } //if(recurs)
666 
667  eventList.append( event );
668  }
669 
670  return eventList;
671 }
672 
673 Event::List MemoryCalendar::rawEventsForDate( const KDateTime &kdt ) const
674 {
675  return rawEventsForDate( kdt.date(), kdt.timeSpec() );
676 }
677 
678 Event::List MemoryCalendar::rawEvents( EventSortField sortField,
679  SortDirection sortDirection ) const
680 {
681  Event::List eventList;
682  QHashIterator<QString, Incidence::Ptr> i( d->mIncidences[Incidence::TypeEvent] );
683  while ( i.hasNext() ) {
684  i.next();
685  eventList.append( i.value().staticCast<Event>() );
686  }
687  return Calendar::sortEvents( eventList, sortField, sortDirection );
688 }
689 
690 Event::List MemoryCalendar::deletedEvents( EventSortField sortField,
691  SortDirection sortDirection ) const
692 {
693  Event::List eventList;
694  QHashIterator<QString, Incidence::Ptr>i( d->mDeletedIncidences[Incidence::TypeEvent] );
695  while ( i.hasNext() ) {
696  i.next();
697  eventList.append( i.value().staticCast<Event>() );
698  }
699  return Calendar::sortEvents( eventList, sortField, sortDirection );
700 }
701 
702 Event::List MemoryCalendar::eventInstances( const Incidence::Ptr &event,
703  EventSortField sortField,
704  SortDirection sortDirection ) const
705 {
706  Event::List list;
707 
708  QList<Incidence::Ptr> values = d->mIncidences[Incidence::TypeEvent].values( event->uid() );
709  QList<Incidence::Ptr>::const_iterator it;
710  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
711  Event::Ptr ev = ( *it ).staticCast<Event>();
712  if ( ev->hasRecurrenceId() ) {
713  list.append( ev );
714  }
715  }
716  return Calendar::sortEvents( list, sortField, sortDirection );
717 }
718 
719 bool MemoryCalendar::addJournal( const Journal::Ptr &journal )
720 {
721  return addIncidence( journal );
722 }
723 
724 bool MemoryCalendar::deleteJournal( const Journal::Ptr &journal )
725 {
726  return deleteIncidence( journal );
727 }
728 
729 bool MemoryCalendar::deleteJournalInstances( const Journal::Ptr &journal )
730 {
731  return deleteIncidenceInstances( journal );
732 }
733 
734 void MemoryCalendar::deleteAllJournals()
735 {
736  d->deleteAllIncidences( Incidence::TypeJournal );
737 }
738 
739 Journal::Ptr MemoryCalendar::journal( const QString &uid,
740  const KDateTime &recurrenceId ) const
741 {
742  return d->incidence( uid, Incidence::TypeJournal, recurrenceId ).staticCast<Journal>();
743 }
744 
745 Journal::Ptr MemoryCalendar::deletedJournal( const QString &uid,
746  const KDateTime &recurrenceId ) const
747 {
748  return d->deletedIncidence( uid, recurrenceId, Incidence::TypeJournal ).staticCast<Journal>();
749 }
750 
751 Journal::List MemoryCalendar::rawJournals( JournalSortField sortField,
752  SortDirection sortDirection ) const
753 {
754  Journal::List journalList;
755  QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeJournal] );
756  while ( i.hasNext() ) {
757  i.next();
758  journalList.append( i.value().staticCast<Journal>() );
759  }
760  return Calendar::sortJournals( journalList, sortField, sortDirection );
761 }
762 
763 Journal::List MemoryCalendar::deletedJournals( JournalSortField sortField,
764  SortDirection sortDirection ) const
765 {
766  Journal::List journalList;
767  QHashIterator<QString, Incidence::Ptr>i( d->mDeletedIncidences[Incidence::TypeJournal] );
768  while ( i.hasNext() ) {
769  i.next();
770  journalList.append( i.value().staticCast<Journal>() );
771  }
772  return Calendar::sortJournals( journalList, sortField, sortDirection );
773 }
774 
775 Journal::List MemoryCalendar::journalInstances( const Incidence::Ptr &journal,
776  JournalSortField sortField,
777  SortDirection sortDirection ) const
778 {
779  Journal::List list;
780 
781  QList<Incidence::Ptr> values = d->mIncidences[Incidence::TypeJournal].values( journal->uid() );
782  QList<Incidence::Ptr>::const_iterator it;
783  for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
784  Journal::Ptr j = ( *it ).staticCast<Journal>();
785  if ( j->hasRecurrenceId() ) {
786  list.append( j );
787  }
788  }
789  return Calendar::sortJournals( list, sortField, sortDirection );
790 }
791 
792 Journal::List MemoryCalendar::rawJournalsForDate( const QDate &date ) const
793 {
794  Journal::List journalList;
795  Journal::Ptr j;
796 
797  QString dateStr = date.toString();
798  QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
799  d->mIncidencesForDate[Incidence::TypeJournal].constFind( dateStr );
800 
801  while ( it != d->mIncidencesForDate[Incidence::TypeJournal].constEnd() && it.key() == dateStr ) {
802  j = it.value().staticCast<Journal>();
803  journalList.append( j );
804  ++it;
805  }
806  return journalList;
807 }
808 
809 void MemoryCalendar::virtual_hook( int id, void *data )
810 {
811  Q_UNUSED( id );
812  Q_UNUSED( data );
813  Q_ASSERT( false );
814 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:24:52 by doxygen 1.8.3.1 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.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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