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

KCalCore Library

memorycalendar.cpp
Go to the documentation of this file.
00001 /*
00002   This file is part of the kcalcore library.
00003 
00004   Copyright (c) 1998 Preston Brown <pbrown@kde.org>
00005   Copyright (c) 2001,2003,2004 Cornelius Schumacher <schumacher@kde.org>
00006   Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Library General Public
00010   License as published by the Free Software Foundation; either
00011   version 2 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Library General Public License for more details.
00017 
00018   You should have received a copy of the GNU Library General Public License
00019   along with this library; see the file COPYING.LIB.  If not, write to
00020   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021   Boston, MA 02110-1301, USA.
00022 */
00035 #include "memorycalendar.h"
00036 
00037 #include <KDebug>
00038 
00039 using namespace KCalCore;
00040 
00045 //@cond PRIVATE
00046 class KCalCore::MemoryCalendar::Private
00047 {
00048   public:
00049     Private( MemoryCalendar *qq )
00050       : q( qq ), mFormat( 0 )
00051     {
00052     }
00053     ~Private()
00054     {
00055     }
00056 
00057     MemoryCalendar *q;
00058     QString mFileName;                     // filename where calendar is stored
00059     CalFormat *mFormat;                    // calendar format
00060 
00065     QMap<IncidenceBase::IncidenceType, QMultiHash<QString, Incidence::Ptr> > mIncidences;
00066 
00071     QMap<IncidenceBase::IncidenceType, QMultiHash<QString, Incidence::Ptr> > mDeletedIncidences;
00072 
00084     QMap<IncidenceBase::IncidenceType, QMultiHash<QString, IncidenceBase::Ptr> > mIncidencesForDate;
00085 
00086     void insertIncidence( Incidence::Ptr incidence );
00087 
00088     Incidence::Ptr incidence( const QString &uid,
00089                               const IncidenceBase::IncidenceType type,
00090                               const KDateTime &recurrenceId = KDateTime() ) const;
00091 
00092     Incidence::Ptr deletedIncidence( const QString &uid,
00093                                      const KDateTime &recurrenceId,
00094                                      const IncidenceBase::IncidenceType type ) const;
00095 
00096     void deleteAllIncidences( const IncidenceBase::IncidenceType type );
00097 
00098 };
00099 
00100 MemoryCalendar::MemoryCalendar( const KDateTime::Spec &timeSpec )
00101   : Calendar( timeSpec ),
00102   d( new KCalCore::MemoryCalendar::Private( this ) )
00103 {
00104 }
00105 
00106 MemoryCalendar::MemoryCalendar( const QString &timeZoneId )
00107   : Calendar( timeZoneId ),
00108     d( new KCalCore::MemoryCalendar::Private( this ) )
00109 {
00110 }
00111 
00112 MemoryCalendar::~MemoryCalendar()
00113 {
00114   close();
00115   delete d;
00116 }
00117 
00118 void MemoryCalendar::close()
00119 {
00120   setObserversEnabled( false );
00121   d->mFileName.clear();
00122 
00123   deleteAllEvents();
00124   deleteAllTodos();
00125   deleteAllJournals();
00126 
00127   d->mDeletedIncidences.clear();
00128 
00129   setModified( false );
00130 
00131   setObserversEnabled( true );
00132 }
00133 
00134 bool MemoryCalendar::deleteIncidence( const Incidence::Ptr &incidence )
00135 {
00136   // Handle orphaned children
00137   // relations is an Incidence's property, not a Todo's, so
00138   // we remove relations in deleteIncidence, not in deleteTodo.
00139   removeRelations( incidence );
00140   const Incidence::IncidenceType type = incidence->type();
00141   const QString uid = incidence->uid();
00142   if ( d->mIncidences[type].remove( uid, incidence ) ) {
00143     setModified( true );
00144     notifyIncidenceDeleted( incidence );
00145     d->mDeletedIncidences[type].insert( uid, incidence );
00146 
00147     const KDateTime dt = incidence->dateTime( Incidence::RoleCalendarHashing );
00148     if ( dt.isValid() ) {
00149       d->mIncidencesForDate[type].remove( dt.date().toString(), incidence );
00150     }
00151     // Delete child-incidences.
00152     if ( !incidence->hasRecurrenceId() ) {
00153       deleteIncidenceInstances( incidence );
00154     }
00155     return true;
00156   } else {
00157     kWarning() << incidence->typeStr() << " not found.";
00158     return false;
00159   }
00160 }
00161 
00162 bool MemoryCalendar::deleteIncidenceInstances( const Incidence::Ptr &incidence )
00163 {
00164   const Incidence::IncidenceType type = incidence->type();
00165   QList<Incidence::Ptr> values = d->mIncidences[type].values( incidence->uid() );
00166   QList<Incidence::Ptr>::const_iterator it;
00167   for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
00168     Incidence::Ptr i = *it;
00169     if ( i->hasRecurrenceId() ) {
00170       kDebug() << "deleting child"
00171                << ", type=" << int( type )
00172                << ", uid=" << i->uid()
00173                << ", start=" << i->dtStart()
00174                << " from calendar";
00175       deleteIncidence( i );
00176     }
00177   }
00178 
00179   return true;
00180 }
00181 
00182 void MemoryCalendar::Private::deleteAllIncidences( const Incidence::IncidenceType incidenceType )
00183 {
00184   QHashIterator<QString, Incidence::Ptr>i( mIncidences[incidenceType] );
00185   while ( i.hasNext() ) {
00186     i.next();
00187     q->notifyIncidenceDeleted( i.value() );
00188     // suppress update notifications for the relation removal triggered
00189     // by the following deletions
00190     i.value()->startUpdates();
00191   }
00192   mIncidences[incidenceType].clear();
00193   mIncidencesForDate[incidenceType].clear();
00194 }
00195 
00196 Incidence::Ptr MemoryCalendar::Private::incidence( const QString &uid,
00197                                                    const Incidence::IncidenceType type,
00198                                                    const KDateTime &recurrenceId ) const
00199 {
00200   QList<Incidence::Ptr> values = mIncidences[type].values( uid );
00201   QList<Incidence::Ptr>::const_iterator it;
00202   for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
00203     Incidence::Ptr i = *it;
00204     if ( recurrenceId.isNull() ) {
00205       if ( !i->hasRecurrenceId() ) {
00206         return i;
00207       }
00208     } else {
00209       if ( i->hasRecurrenceId() && i->recurrenceId() == recurrenceId ) {
00210         return i;
00211       }
00212     }
00213   }
00214   return Incidence::Ptr();
00215 }
00216 
00217 Incidence::Ptr
00218 MemoryCalendar::Private::deletedIncidence( const QString &uid,
00219                                            const KDateTime &recurrenceId,
00220                                            const IncidenceBase::IncidenceType type ) const
00221 {
00222   QList<Incidence::Ptr> values = mDeletedIncidences[type].values( uid );
00223   QList<Incidence::Ptr>::const_iterator it;
00224   for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
00225     Incidence::Ptr i = *it;
00226     if ( recurrenceId.isNull() ) {
00227       if ( !i->hasRecurrenceId() ) {
00228         return i;
00229       }
00230     } else {
00231       if ( i->hasRecurrenceId() && i->recurrenceId() == recurrenceId ) {
00232         return i;
00233       }
00234     }
00235   }
00236   return Incidence::Ptr();
00237 }
00238 
00239 //@cond PRIVATE
00240 void MemoryCalendar::Private::insertIncidence( Incidence::Ptr incidence )
00241 {
00242   const QString uid = incidence->uid();
00243   const Incidence::IncidenceType type = incidence->type();
00244   if ( !mIncidences[type].contains( uid, incidence ) ) {
00245     mIncidences[type].insert( uid, incidence );
00246     const KDateTime dt = incidence->dateTime( Incidence::RoleCalendarHashing );
00247     if ( dt.isValid() ) {
00248       mIncidencesForDate[type].insert( dt.date().toString(), incidence );
00249     }
00250 
00251   } else {
00252 #ifndef NDEBUG
00253     // if we already have an to-do with this UID, it must be the same incidence,
00254     // otherwise something's really broken
00255     Q_ASSERT( mIncidences[type].value( uid ) == incidence );
00256 #endif
00257   }
00258 }
00259 //@endcond
00260 
00261 bool MemoryCalendar::addIncidence( const Incidence::Ptr &incidence )
00262 {
00263   notifyIncidenceAdded( incidence );
00264 
00265   d->insertIncidence( incidence );
00266 
00267   incidence->registerObserver( this );
00268 
00269   setupRelations( incidence );
00270 
00271   setModified( true );
00272 
00273   return true;
00274 }
00275 
00276 bool MemoryCalendar::addEvent( const Event::Ptr &event )
00277 {
00278   return addIncidence( event );
00279 }
00280 
00281 bool MemoryCalendar::deleteEvent( const Event::Ptr &event )
00282 {
00283   return deleteIncidence( event );
00284 }
00285 
00286 bool MemoryCalendar::deleteEventInstances( const Event::Ptr &event )
00287 {
00288   return deleteIncidenceInstances( event );
00289 }
00290 
00291 void MemoryCalendar::deleteAllEvents()
00292 {
00293   d->deleteAllIncidences( Incidence::TypeEvent );
00294 }
00295 
00296 Event::Ptr MemoryCalendar::event( const QString &uid,
00297                                   const KDateTime &recurrenceId ) const
00298 {
00299   return d->incidence( uid, Incidence::TypeEvent, recurrenceId ).staticCast<Event>();
00300 }
00301 
00302 Event::Ptr MemoryCalendar::deletedEvent( const QString &uid, const KDateTime &recurrenceId ) const
00303 {
00304   return d->deletedIncidence( uid, recurrenceId, Incidence::TypeEvent ).staticCast<Event>();
00305 }
00306 
00307 bool MemoryCalendar::addTodo( const Todo::Ptr &todo )
00308 {
00309   return addIncidence( todo );
00310 }
00311 
00312 bool MemoryCalendar::deleteTodo( const Todo::Ptr &todo )
00313 {
00314   return deleteIncidence( todo );
00315 }
00316 
00317 bool MemoryCalendar::deleteTodoInstances( const Todo::Ptr &todo )
00318 {
00319   return deleteIncidenceInstances( todo );
00320 }
00321 
00322 void MemoryCalendar::deleteAllTodos()
00323 {
00324   d->deleteAllIncidences( Incidence::TypeTodo );
00325 }
00326 
00327 Todo::Ptr MemoryCalendar::todo( const QString &uid,
00328                                 const KDateTime &recurrenceId ) const
00329 {
00330   return d->incidence( uid, Incidence::TypeTodo, recurrenceId ).staticCast<Todo>();
00331 }
00332 
00333 Todo::Ptr MemoryCalendar::deletedTodo( const QString &uid,
00334                                        const KDateTime &recurrenceId ) const
00335 {
00336   return d->deletedIncidence( uid, recurrenceId, Incidence::TypeTodo ).staticCast<Todo>();
00337 }
00338 
00339 Todo::List MemoryCalendar::rawTodos( TodoSortField sortField,
00340                                      SortDirection sortDirection ) const
00341 {
00342   Todo::List todoList;
00343   QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeTodo] );
00344   while ( i.hasNext() ) {
00345     i.next();
00346     todoList.append( i.value().staticCast<Todo>() );
00347   }
00348   return Calendar::sortTodos( todoList, sortField, sortDirection );
00349 }
00350 
00351 Todo::List MemoryCalendar::deletedTodos( TodoSortField sortField,
00352                                          SortDirection sortDirection ) const
00353 {
00354   Todo::List todoList;
00355   QHashIterator<QString, Incidence::Ptr >i( d->mDeletedIncidences[Incidence::TypeTodo] );
00356   while ( i.hasNext() ) {
00357     i.next();
00358     todoList.append( i.value().staticCast<Todo>() );
00359   }
00360   return Calendar::sortTodos( todoList, sortField, sortDirection );
00361 }
00362 
00363 Todo::List MemoryCalendar::todoInstances( const Incidence::Ptr &todo,
00364                                           TodoSortField sortField,
00365                                           SortDirection sortDirection ) const
00366 {
00367   Todo::List list;
00368 
00369   QList<Incidence::Ptr > values = d->mIncidences[Incidence::TypeTodo].values( todo->uid() );
00370   QList<Incidence::Ptr>::const_iterator it;
00371   for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
00372     Todo::Ptr t = ( *it ).staticCast<Todo>();
00373     if ( t->hasRecurrenceId() ) {
00374       list.append( t );
00375     }
00376   }
00377   return Calendar::sortTodos( list, sortField, sortDirection );
00378 }
00379 
00380 Todo::List MemoryCalendar::rawTodosForDate( const QDate &date ) const
00381 {
00382   Todo::List todoList;
00383   Todo::Ptr t;
00384 
00385   KDateTime::Spec ts = timeSpec();
00386   const QString dateStr = date.toString();
00387   QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
00388     d->mIncidencesForDate[Incidence::TypeTodo].constFind( dateStr );
00389   while ( it != d->mIncidencesForDate[Incidence::TypeTodo].constEnd() && it.key() == dateStr ) {
00390     t = it.value().staticCast<Todo>();
00391     todoList.append( t );
00392     ++it;
00393   }
00394 
00395   // Iterate over all todos. Look for recurring todoss that occur on this date
00396   QHashIterator<QString, Incidence::Ptr >i( d->mIncidences[Incidence::TypeTodo] );
00397   while ( i.hasNext() ) {
00398     i.next();
00399     t = i.value().staticCast<Todo>();
00400     if ( t->recurs() ) {
00401       if ( t->recursOn( date, ts ) ) {
00402         todoList.append( t );
00403       }
00404     }
00405   }
00406 
00407   return todoList;
00408 }
00409 
00410 Todo::List MemoryCalendar::rawTodos( const QDate &start,
00411                                      const QDate &end,
00412                                      const KDateTime::Spec &timespec,
00413                                      bool inclusive ) const
00414 {
00415   Q_UNUSED( inclusive ); // use only exact dtDue/dtStart, not dtStart and dtEnd
00416 
00417   Todo::List todoList;
00418   KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
00419   KDateTime st( start, ts );
00420   KDateTime nd( end, ts );
00421 
00422   // Get todos
00423   QHashIterator<QString, Incidence::Ptr >i( d->mIncidences[Incidence::TypeTodo] );
00424   Todo::Ptr todo;
00425   while ( i.hasNext() ) {
00426     i.next();
00427     todo = i.value().staticCast<Todo>();
00428     if ( !isVisible( todo ) ) {
00429       continue;
00430     }
00431 
00432     KDateTime rStart = todo->hasDueDate() ? todo->dtDue() :
00433                        todo->hasStartDate() ? todo->dtStart() : KDateTime();
00434     if ( !rStart.isValid() ) {
00435       continue;
00436     }
00437 
00438     if ( !todo->recurs() ) { // non-recurring todos
00439       if ( nd.isValid() && nd < rStart ) {
00440         continue;
00441       }
00442       if ( st.isValid() && rStart < st ) {
00443         continue;
00444       }
00445     } else { // recurring events
00446       switch( todo->recurrence()->duration() ) {
00447       case -1: // infinite
00448         break;
00449       case 0: // end date given
00450       default: // count given
00451         KDateTime rEnd( todo->recurrence()->endDate(), ts );
00452         if ( !rEnd.isValid() ) {
00453           continue;
00454         }
00455         if ( st.isValid() && rEnd < st ) {
00456           continue;
00457         }
00458         break;
00459       } // switch(duration)
00460     } //if(recurs)
00461 
00462     todoList.append( todo );
00463   }
00464 
00465   return todoList;
00466 }
00467 
00468 Alarm::List MemoryCalendar::alarmsTo( const KDateTime &to ) const
00469 {
00470   return alarms( KDateTime( QDate( 1900, 1, 1 ) ), to );
00471 }
00472 
00473 Alarm::List MemoryCalendar::alarms( const KDateTime &from, const KDateTime &to ) const
00474 {
00475   Alarm::List alarmList;
00476   QHashIterator<QString, Incidence::Ptr>ie( d->mIncidences[Incidence::TypeEvent] );
00477   Event::Ptr e;
00478   while ( ie.hasNext() ) {
00479     ie.next();
00480     e = ie.value().staticCast<Event>();
00481     if ( e->recurs() ) {
00482       appendRecurringAlarms( alarmList, e, from, to );
00483     } else {
00484       appendAlarms( alarmList, e, from, to );
00485     }
00486   }
00487 
00488   QHashIterator<QString, Incidence::Ptr>it( d->mIncidences[Incidence::TypeTodo] );
00489   Todo::Ptr t;
00490   while ( it.hasNext() ) {
00491     it.next();
00492     t = it.value().staticCast<Todo>();
00493 
00494     if ( !t->isCompleted() ) {
00495       appendAlarms( alarmList, t, from, to );
00496       if ( t->recurs() ) {
00497         appendRecurringAlarms( alarmList, t, from, to );
00498       } else {
00499         appendAlarms( alarmList, t, from, to );
00500       }
00501     }
00502   }
00503 
00504   return alarmList;
00505 }
00506 
00507 void MemoryCalendar::incidenceUpdate( const QString &uid, const KDateTime &recurrenceId )
00508 {
00509   Incidence::Ptr inc = incidence( uid, recurrenceId );
00510 
00511   if ( inc ) {
00512     const Incidence::IncidenceType type = inc->type();
00513     const KDateTime dt = inc->dateTime( Incidence::RoleCalendarHashing );
00514 
00515     if ( dt.isValid() ) {
00516       d->mIncidencesForDate[type].remove( dt.date().toString(), inc );
00517     }
00518   }
00519 }
00520 
00521 void MemoryCalendar::incidenceUpdated( const QString &uid, const KDateTime &recurrenceId )
00522 {
00523   Incidence::Ptr inc = incidence( uid, recurrenceId );
00524 
00525   if ( inc ) {
00526     KDateTime nowUTC = KDateTime::currentUtcDateTime();
00527     inc->setLastModified( nowUTC );
00528     // we should probably update the revision number here,
00529     // or internally in the Event itself when certain things change.
00530     // need to verify with ical documentation.
00531 
00532     const Incidence::IncidenceType type = inc->type();
00533     const KDateTime dt = inc->dateTime( Incidence::RoleCalendarHashing );
00534 
00535     if ( dt.isValid() ) {
00536       d->mIncidencesForDate[type].insert( dt.date().toString(), inc );
00537     }
00538 
00539     notifyIncidenceChanged( inc );
00540 
00541     setModified( true );
00542   }
00543 }
00544 
00545 Event::List MemoryCalendar::rawEventsForDate( const QDate &date,
00546                                               const KDateTime::Spec &timespec,
00547                                               EventSortField sortField,
00548                                               SortDirection sortDirection ) const
00549 {
00550   Event::List eventList;
00551   Event::Ptr ev;
00552 
00553   // Find the hash for the specified date
00554   const QString dateStr = date.toString();
00555   QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
00556     d->mIncidencesForDate[Incidence::TypeEvent].constFind( dateStr );
00557   // Iterate over all non-recurring, single-day events that start on this date
00558   KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
00559   KDateTime kdt( date, ts );
00560   while ( it != d->mIncidencesForDate[Incidence::TypeEvent].constEnd() && it.key() == dateStr ) {
00561     ev = it.value().staticCast<Event>();
00562     KDateTime end( ev->dtEnd().toTimeSpec( ev->dtStart() ) );
00563     if ( ev->allDay() ) {
00564       end.setDateOnly( true );
00565     } else {
00566       end = end.addSecs( -1 );
00567     }
00568     if ( end >= kdt ) {
00569       eventList.append( ev );
00570     }
00571     ++it;
00572   }
00573 
00574   // Iterate over all events. Look for recurring events that occur on this date
00575   QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
00576   while ( i.hasNext() ) {
00577     i.next();
00578     ev = i.value().staticCast<Event>();
00579     if ( ev->recurs() ) {
00580       if ( ev->isMultiDay() ) {
00581         int extraDays = ev->dtStart().date().daysTo( ev->dtEnd().date() );
00582         for ( int i = 0; i <= extraDays; ++i ) {
00583           if ( ev->recursOn( date.addDays( -i ), ts ) ) {
00584             eventList.append( ev );
00585             break;
00586           }
00587         }
00588       } else {
00589         if ( ev->recursOn( date, ts ) ) {
00590           eventList.append( ev );
00591         }
00592       }
00593     } else {
00594       if ( ev->isMultiDay() ) {
00595         if ( ev->dtStart().date() <= date && ev->dtEnd().date() >= date ) {
00596           eventList.append( ev );
00597         }
00598       }
00599     }
00600   }
00601 
00602   return Calendar::sortEvents( eventList, sortField, sortDirection );
00603 }
00604 
00605 Event::List MemoryCalendar::rawEvents( const QDate &start,
00606                                        const QDate &end,
00607                                        const KDateTime::Spec &timespec,
00608                                        bool inclusive ) const
00609 {
00610   Event::List eventList;
00611   KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
00612   KDateTime st( start, ts );
00613   KDateTime nd( end, ts );
00614   KDateTime yesterStart = st.addDays( -1 );
00615 
00616   // Get non-recurring events
00617   QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
00618   Event::Ptr event;
00619   while ( i.hasNext() ) {
00620     i.next();
00621     event = i.value().staticCast<Event>();
00622     KDateTime rStart = event->dtStart();
00623     if ( nd < rStart ) {
00624       continue;
00625     }
00626     if ( inclusive && rStart < st ) {
00627       continue;
00628     }
00629 
00630     if ( !event->recurs() ) { // non-recurring events
00631       KDateTime rEnd = event->dtEnd();
00632       if ( rEnd < st ) {
00633         continue;
00634       }
00635       if ( inclusive && nd < rEnd ) {
00636         continue;
00637       }
00638     } else { // recurring events
00639       switch( event->recurrence()->duration() ) {
00640       case -1: // infinite
00641         if ( inclusive ) {
00642           continue;
00643         }
00644         break;
00645       case 0: // end date given
00646       default: // count given
00647         KDateTime rEnd( event->recurrence()->endDate(), ts );
00648         if ( !rEnd.isValid() ) {
00649           continue;
00650         }
00651         if ( rEnd < st ) {
00652           continue;
00653         }
00654         if ( inclusive && nd < rEnd ) {
00655           continue;
00656         }
00657         break;
00658       } // switch(duration)
00659     } //if(recurs)
00660 
00661     eventList.append( event );
00662   }
00663 
00664   return eventList;
00665 }
00666 
00667 Event::List MemoryCalendar::rawEventsForDate( const KDateTime &kdt ) const
00668 {
00669   return rawEventsForDate( kdt.date(), kdt.timeSpec() );
00670 }
00671 
00672 Event::List MemoryCalendar::rawEvents( EventSortField sortField,
00673                                        SortDirection sortDirection ) const
00674 {
00675   Event::List eventList;
00676   QHashIterator<QString, Incidence::Ptr> i( d->mIncidences[Incidence::TypeEvent] );
00677   while ( i.hasNext() ) {
00678     i.next();
00679     eventList.append( i.value().staticCast<Event>() );
00680   }
00681   return Calendar::sortEvents( eventList, sortField, sortDirection );
00682 }
00683 
00684 Event::List MemoryCalendar::deletedEvents( EventSortField sortField,
00685                                            SortDirection sortDirection ) const
00686 {
00687   Event::List eventList;
00688   QHashIterator<QString, Incidence::Ptr>i( d->mDeletedIncidences[Incidence::TypeEvent] );
00689   while ( i.hasNext() ) {
00690     i.next();
00691     eventList.append( i.value().staticCast<Event>() );
00692   }
00693   return Calendar::sortEvents( eventList, sortField, sortDirection );
00694 }
00695 
00696 Event::List MemoryCalendar::eventInstances( const Incidence::Ptr &event,
00697                                             EventSortField sortField,
00698                                             SortDirection sortDirection ) const
00699 {
00700   Event::List list;
00701 
00702   QList<Incidence::Ptr> values = d->mIncidences[Incidence::TypeEvent].values( event->uid() );
00703   QList<Incidence::Ptr>::const_iterator it;
00704   for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
00705     Event::Ptr ev = ( *it ).staticCast<Event>();
00706     if ( ev->hasRecurrenceId() ) {
00707       list.append( ev );
00708     }
00709   }
00710   return Calendar::sortEvents( list, sortField, sortDirection );
00711 }
00712 
00713 bool MemoryCalendar::addJournal( const Journal::Ptr &journal )
00714 {
00715   return addIncidence( journal );
00716 }
00717 
00718 bool MemoryCalendar::deleteJournal( const Journal::Ptr &journal )
00719 {
00720   return deleteIncidence( journal );
00721 }
00722 
00723 bool MemoryCalendar::deleteJournalInstances( const Journal::Ptr &journal )
00724 {
00725   return deleteIncidenceInstances( journal );
00726 }
00727 
00728 void MemoryCalendar::deleteAllJournals()
00729 {
00730   d->deleteAllIncidences( Incidence::TypeJournal );
00731 }
00732 
00733 Journal::Ptr MemoryCalendar::journal( const QString &uid,
00734                                       const KDateTime &recurrenceId ) const
00735 {
00736   return d->incidence( uid, Incidence::TypeJournal, recurrenceId ).staticCast<Journal>();
00737 }
00738 
00739 Journal::Ptr MemoryCalendar::deletedJournal( const QString &uid,
00740                                              const KDateTime &recurrenceId ) const
00741 {
00742   return d->deletedIncidence( uid, recurrenceId, Incidence::TypeJournal ).staticCast<Journal>();
00743 }
00744 
00745 Journal::List MemoryCalendar::rawJournals( JournalSortField sortField,
00746                                            SortDirection sortDirection ) const
00747 {
00748   Journal::List journalList;
00749   QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeJournal] );
00750   while ( i.hasNext() ) {
00751     i.next();
00752     journalList.append( i.value().staticCast<Journal>() );
00753   }
00754   return Calendar::sortJournals( journalList, sortField, sortDirection );
00755 }
00756 
00757 Journal::List MemoryCalendar::deletedJournals( JournalSortField sortField,
00758                                                SortDirection sortDirection ) const
00759 {
00760   Journal::List journalList;
00761   QHashIterator<QString, Incidence::Ptr>i( d->mDeletedIncidences[Incidence::TypeJournal] );
00762   while ( i.hasNext() ) {
00763     i.next();
00764     journalList.append( i.value().staticCast<Journal>() );
00765   }
00766   return Calendar::sortJournals( journalList, sortField, sortDirection );
00767 }
00768 
00769 Journal::List MemoryCalendar::journalInstances( const Incidence::Ptr &journal,
00770                                                 JournalSortField sortField,
00771                                                 SortDirection sortDirection ) const
00772 {
00773   Journal::List list;
00774 
00775   QList<Incidence::Ptr> values = d->mIncidences[Incidence::TypeJournal].values( journal->uid() );
00776   QList<Incidence::Ptr>::const_iterator it;
00777   for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
00778     Journal::Ptr j = ( *it ).staticCast<Journal>();
00779     if ( j->hasRecurrenceId() ) {
00780       list.append( j );
00781     }
00782   }
00783   return Calendar::sortJournals( list, sortField, sortDirection );
00784 }
00785 
00786 Journal::List MemoryCalendar::rawJournalsForDate( const QDate &date ) const
00787 {
00788   Journal::List journalList;
00789   Journal::Ptr j;
00790 
00791   QString dateStr = date.toString();
00792   QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
00793     d->mIncidencesForDate[Incidence::TypeJournal].constFind( dateStr );
00794 
00795   while ( it != d->mIncidencesForDate[Incidence::TypeJournal].constEnd() && it.key() == dateStr ) {
00796     j = it.value().staticCast<Journal>();
00797     journalList.append( j );
00798     ++it;
00799   }
00800   return journalList;
00801 }
00802 
00803 void MemoryCalendar::virtual_hook( int id, void *data )
00804 {
00805   Q_UNUSED( id );
00806   Q_UNUSED( data );
00807   Q_ASSERT( false );
00808 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:21 by doxygen 1.8.0 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.8.3 API Reference

Skip menu "kdepimlibs-4.8.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