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

KCalCore Library

calfilter.cpp
Go to the documentation of this file.
00001 /*
00002   This file is part of the kcalcore library.
00003 
00004   Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005   Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006   Copyright (C) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
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 */
00036 #include "calfilter.h"
00037 
00038 using namespace KCalCore;
00039 
00044 //@cond PRIVATE
00045 class KCalCore::CalFilter::Private
00046 {
00047   public:
00048     Private()
00049       : mCriteria( 0 ),
00050         mCompletedTimeSpan( 0 ),
00051         mEnabled( true )
00052     {}
00053     QString mName;   // filter name
00054     QStringList mCategoryList;
00055     QStringList mEmailList;
00056     int mCriteria;
00057     int mCompletedTimeSpan;
00058     bool mEnabled;
00059 
00060 };
00061 //@endcond
00062 
00063 CalFilter::CalFilter() : d( new KCalCore::CalFilter::Private )
00064 {
00065 }
00066 
00067 CalFilter::CalFilter( const QString &name )
00068   : d( new KCalCore::CalFilter::Private )
00069 {
00070   d->mName = name;
00071 }
00072 
00073 CalFilter::~CalFilter()
00074 {
00075   delete d;
00076 }
00077 
00078 bool KCalCore::CalFilter::operator==( const CalFilter &filter ) const
00079 {
00080   return d->mName == filter.d->mName &&
00081     d->mCriteria == filter.d->mCriteria &&
00082     d->mCategoryList == filter.d->mCategoryList &&
00083     d->mEmailList == filter.d->mEmailList &&
00084     d->mCompletedTimeSpan == filter.d->mCompletedTimeSpan;
00085 }
00086 
00087 void CalFilter::apply( Event::List *eventList ) const
00088 {
00089   if ( !d->mEnabled ) {
00090     return;
00091   }
00092 
00093   Event::List::Iterator it = eventList->begin();
00094   while ( it != eventList->end() ) {
00095     if ( !filterIncidence( *it ) ) {
00096       it = eventList->erase( it );
00097     } else {
00098       ++it;
00099     }
00100   }
00101 }
00102 
00103 // TODO: avoid duplicating apply() code
00104 void CalFilter::apply( Todo::List *todoList ) const
00105 {
00106   if ( !d->mEnabled ) {
00107     return;
00108   }
00109 
00110   Todo::List::Iterator it = todoList->begin();
00111   while ( it != todoList->end() ) {
00112     if ( !filterIncidence( *it ) ) {
00113       it = todoList->erase( it );
00114     } else {
00115       ++it;
00116     }
00117   }
00118 }
00119 
00120 void CalFilter::apply( Journal::List *journalList ) const
00121 {
00122   if ( !d->mEnabled ) {
00123     return;
00124   }
00125 
00126   Journal::List::Iterator it = journalList->begin();
00127   while ( it != journalList->end() ) {
00128     if ( !filterIncidence( *it ) ) {
00129       it = journalList->erase( it );
00130     } else {
00131       ++it;
00132     }
00133   }
00134 }
00135 
00136 bool CalFilter::filterIncidence( Incidence::Ptr incidence ) const
00137 {
00138   if ( !d->mEnabled ) {
00139     return true;
00140   }
00141 
00142   Todo::Ptr todo = incidence.dynamicCast<Todo>();
00143   if ( todo ) {
00144     if ( ( d->mCriteria & HideCompletedTodos ) && todo->isCompleted() ) {
00145       // Check if completion date is suffently long ago:
00146       if ( todo->completed().addDays( d->mCompletedTimeSpan ) <
00147            KDateTime::currentUtcDateTime() ) {
00148         return false;
00149       }
00150     }
00151 
00152     if ( ( d->mCriteria & HideInactiveTodos ) &&
00153          ( ( todo->hasStartDate() &&
00154              KDateTime::currentUtcDateTime() < todo->dtStart() ) ||
00155            todo->isCompleted() ) ) {
00156       return false;
00157     }
00158 
00159     if ( d->mCriteria & HideNoMatchingAttendeeTodos ) {
00160       bool iAmOneOfTheAttendees = false;
00161       const Attendee::List &attendees = todo->attendees();
00162       if ( !todo->attendees().isEmpty() ) {
00163         Attendee::List::ConstIterator it;
00164         for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00165           if ( d->mEmailList.contains( (*it)->email() ) ) {
00166             iAmOneOfTheAttendees = true;
00167             break;
00168           }
00169         }
00170       } else {
00171         // no attendees, must be me only
00172         iAmOneOfTheAttendees = true;
00173       }
00174       if ( !iAmOneOfTheAttendees ) {
00175         return false;
00176       }
00177     }
00178   }
00179 
00180   if ( d->mCriteria & HideRecurring ) {
00181     if ( incidence->recurs() ) {
00182       return false;
00183     }
00184   }
00185 
00186   if ( d->mCriteria & ShowCategories ) {
00187     for ( QStringList::ConstIterator it = d->mCategoryList.constBegin();
00188           it != d->mCategoryList.constEnd(); ++it ) {
00189       QStringList incidenceCategories = incidence->categories();
00190       for ( QStringList::ConstIterator it2 = incidenceCategories.constBegin();
00191             it2 != incidenceCategories.constEnd(); ++it2 ) {
00192         if ( (*it) == (*it2) ) {
00193           return true;
00194         }
00195       }
00196     }
00197     return false;
00198   } else {
00199     for ( QStringList::ConstIterator it = d->mCategoryList.constBegin();
00200           it != d->mCategoryList.constEnd(); ++it ) {
00201       QStringList incidenceCategories = incidence->categories();
00202       for ( QStringList::ConstIterator it2 = incidenceCategories.constBegin();
00203             it2 != incidenceCategories.constEnd(); ++it2 ) {
00204         if ( (*it) == (*it2) ) {
00205           return false;
00206         }
00207       }
00208     }
00209     return true;
00210   }
00211 
00212   return true;
00213 }
00214 
00215 void CalFilter::setName( const QString &name )
00216 {
00217   d->mName = name;
00218 }
00219 
00220 QString CalFilter::name() const
00221 {
00222   return d->mName;
00223 }
00224 
00225 void CalFilter::setEnabled( bool enabled )
00226 {
00227   d->mEnabled = enabled;
00228 }
00229 
00230 bool CalFilter::isEnabled() const
00231 {
00232   return d->mEnabled;
00233 }
00234 
00235 void CalFilter::setCriteria( int criteria )
00236 {
00237   d->mCriteria = criteria;
00238 }
00239 
00240 int CalFilter::criteria() const
00241 {
00242   return d->mCriteria;
00243 }
00244 
00245 void CalFilter::setCategoryList( const QStringList &categoryList )
00246 {
00247   d->mCategoryList = categoryList;
00248 }
00249 
00250 QStringList CalFilter::categoryList() const
00251 {
00252   return d->mCategoryList;
00253 }
00254 
00255 void CalFilter::setEmailList( const QStringList &emailList )
00256 {
00257   d->mEmailList = emailList;
00258 }
00259 
00260 QStringList CalFilter::emailList() const
00261 {
00262   return d->mEmailList;
00263 }
00264 
00265 void CalFilter::setCompletedTimeSpan( int timespan )
00266 {
00267   d->mCompletedTimeSpan = timespan;
00268 }
00269 
00270 int CalFilter::completedTimeSpan() const
00271 {
00272   return d->mCompletedTimeSpan;
00273 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:16:56 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