libkcal Library API Documentation

calfilter.cpp

00001 /*
00002     This file is part of libkcal.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <kdebug.h>
00022 
00023 #include "calfilter.h"
00024 
00025 using namespace KCal;
00026 
00027 CalFilter::CalFilter()
00028 {
00029   mEnabled = true;
00030   mCriteria = 0;
00031 }
00032 
00033 CalFilter::CalFilter(const QString &name)
00034 {
00035   mName = name;
00036 }
00037 
00038 CalFilter::~CalFilter()
00039 {
00040 }
00041 
00042 void CalFilter::apply( Event::List *eventlist )
00043 {
00044   if ( !mEnabled ) return;
00045 
00046 //  kdDebug(5800) << "CalFilter::apply()" << endl;
00047 
00048   Event::List::Iterator it = eventlist->begin();
00049   while( it != eventlist->end() ) {
00050     if ( !filterEvent( *it ) ) {
00051       it = eventlist->remove( it );
00052     } else {
00053       ++it;
00054     }
00055   }
00056 
00057 //  kdDebug(5800) << "CalFilter::apply() done" << endl;
00058 }
00059 
00060 // TODO: avoid duplicating apply() code
00061 void CalFilter::apply( Todo::List *eventlist )
00062 {
00063   if ( !mEnabled ) return;
00064 
00065 //  kdDebug(5800) << "CalFilter::apply()" << endl;
00066 
00067   Todo::List::Iterator it = eventlist->begin();
00068   while( it != eventlist->end() ) {
00069     if ( !filterTodo( *it ) ) {
00070       it = eventlist->remove( it );
00071     } else {
00072       ++it;
00073     }
00074   }
00075 
00076 //  kdDebug(5800) << "CalFilter::apply() done" << endl;
00077 }
00078 
00079 bool CalFilter::filterEvent(Event *event)
00080 {
00081 //  kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl;
00082 
00083   if ( !mEnabled ) return true;
00084 
00085   if (mCriteria & HideRecurring) {
00086     if (event->doesRecur()) return false;
00087   }
00088 
00089   return filterIncidence(event);
00090 }
00091 
00092 bool CalFilter::filterTodo(Todo *todo)
00093 {
00094 //  kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl;
00095 
00096   if ( !mEnabled ) return true;
00097 
00098   if (mCriteria & HideCompleted) {
00099     if (todo->isCompleted()) return false;
00100   }
00101 
00102   return filterIncidence(todo);
00103 }
00104 
00105 bool CalFilter::filterIncidence(Incidence *incidence)
00106 {
00107 //  kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl;
00108 
00109   if ( !mEnabled ) return true;
00110 
00111   if (mCriteria & ShowCategories) {
00112     for (QStringList::Iterator it = mCategoryList.begin();
00113          it != mCategoryList.end(); ++it ) {
00114       QStringList incidenceCategories = incidence->categories();
00115       for (QStringList::Iterator it2 = incidenceCategories.begin();
00116            it2 != incidenceCategories.end(); ++it2 ) {
00117         if ((*it) == (*it2)) {
00118           return true;
00119         }
00120       }
00121     }
00122     return false;
00123   } else {
00124     for (QStringList::Iterator it = mCategoryList.begin();
00125          it != mCategoryList.end(); ++it ) {
00126       QStringList incidenceCategories = incidence->categories();
00127       for (QStringList::Iterator it2 = incidenceCategories.begin();
00128            it2 != incidenceCategories.end(); ++it2 ) {
00129         if ((*it) == (*it2)) {
00130           return false;
00131         }
00132       }
00133     }
00134     return true;
00135   }
00136     
00137 //  kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl;
00138   
00139   return true;
00140 }
00141 
00142 void CalFilter::setEnabled(bool enabled)
00143 {
00144   mEnabled = enabled;
00145 }
00146 
00147 bool CalFilter::isEnabled()
00148 {
00149   return mEnabled;
00150 }
00151 
00152 void CalFilter::setCriteria(int criteria)
00153 {
00154   mCriteria = criteria;
00155 }
00156 
00157 int CalFilter::criteria()
00158 {
00159   return mCriteria;
00160 }
00161 
00162 void CalFilter::setCategoryList(const QStringList &categoryList)
00163 {
00164   mCategoryList = categoryList;
00165 }
00166 
00167 QStringList CalFilter::categoryList()
00168 {
00169   return mCategoryList;
00170 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:21 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003