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(QPtrList<Event> *eventlist)
00043 {
00044   if (!mEnabled) return;
00045 
00046 //  kdDebug(5800) << "CalFilter::apply()" << endl;
00047 
00048   Event *event = eventlist->first();
00049   while(event) {
00050     if (!filterEvent(event)) {
00051       eventlist->remove();
00052       event = eventlist->current();
00053     } else {
00054       event = eventlist->next();
00055     }
00056   }
00057 
00058 //  kdDebug(5800) << "CalFilter::apply() done" << endl;
00059 }
00060 
00061 // TODO: avoid duplicating apply() code
00062 void CalFilter::apply(QPtrList<Todo> *eventlist)
00063 {
00064   if (!mEnabled) return;
00065 
00066 //  kdDebug(5800) << "CalFilter::apply()" << endl;
00067 
00068   Todo *event = eventlist->first();
00069   while(event) {
00070     if (!filterTodo(event)) {
00071       eventlist->remove();
00072       event = eventlist->current();
00073     } else {
00074       event = eventlist->next();
00075     }
00076   }
00077 
00078 //  kdDebug(5800) << "CalFilter::apply() done" << endl;
00079 }
00080 
00081 bool CalFilter::filterEvent(Event *event)
00082 {
00083 //  kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl;
00084 
00085   if (mCriteria & HideRecurring) {
00086     if (event->recurrence()->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 (mCriteria & HideCompleted) {
00097     if (todo->isCompleted()) return false;
00098   }
00099 
00100   return filterIncidence(todo);
00101 }
00102 
00103 bool CalFilter::filterIncidence(Incidence *incidence)
00104 {
00105 //  kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl;
00106 
00107   if (mCriteria & ShowCategories) {
00108     for (QStringList::Iterator it = mCategoryList.begin();
00109          it != mCategoryList.end(); ++it ) {
00110       QStringList incidenceCategories = incidence->categories();
00111       for (QStringList::Iterator it2 = incidenceCategories.begin();
00112            it2 != incidenceCategories.end(); ++it2 ) {
00113         if ((*it) == (*it2)) {
00114           return true;
00115         }
00116       }
00117     }
00118     return false;
00119   } else {
00120     for (QStringList::Iterator it = mCategoryList.begin();
00121          it != mCategoryList.end(); ++it ) {
00122       QStringList incidenceCategories = incidence->categories();
00123       for (QStringList::Iterator it2 = incidenceCategories.begin();
00124            it2 != incidenceCategories.end(); ++it2 ) {
00125         if ((*it) == (*it2)) {
00126           return false;
00127         }
00128       }
00129     }
00130     return true;
00131   }
00132     
00133 //  kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl;
00134   
00135   return true;
00136 }
00137 
00138 void CalFilter::setEnabled(bool enabled)
00139 {
00140   mEnabled = enabled;
00141 }
00142 
00143 bool CalFilter::isEnabled()
00144 {
00145   return mEnabled;
00146 }
00147 
00148 void CalFilter::setCriteria(int criteria)
00149 {
00150   mCriteria = criteria;
00151 }
00152 
00153 int CalFilter::criteria()
00154 {
00155   return mCriteria;
00156 }
00157 
00158 void CalFilter::setCategoryList(const QStringList &categoryList)
00159 {
00160   mCategoryList = categoryList;
00161 }
00162 
00163 QStringList CalFilter::categoryList()
00164 {
00165   return mCategoryList;
00166 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:27 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001