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 ( !filterIncidence( *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 *todolist ) 00062 { 00063 if ( !mEnabled ) return; 00064 00065 // kdDebug(5800) << "CalFilter::apply()" << endl; 00066 00067 Todo::List::Iterator it = todolist->begin(); 00068 while( it != todolist->end() ) { 00069 if ( !filterIncidence( *it ) ) { 00070 it = todolist->remove( it ); 00071 } else { 00072 ++it; 00073 } 00074 } 00075 00076 // kdDebug(5800) << "CalFilter::apply() done" << endl; 00077 } 00078 00079 void CalFilter::apply( Journal::List *journallist ) 00080 { 00081 if ( !mEnabled ) return; 00082 00083 Journal::List::Iterator it = journallist->begin(); 00084 while( it != journallist->end() ) { 00085 if ( !filterIncidence( *it ) ) { 00086 it = journallist->remove( it ); 00087 } else { 00088 ++it; 00089 } 00090 } 00091 } 00092 00093 bool CalFilter::filterIncidence(Incidence *incidence) 00094 { 00095 // kdDebug(5800) << "CalFilter::filterIncidence(): " << incidence->summary() << endl; 00096 00097 if ( !mEnabled ) return true; 00098 00099 if ( (mCriteria & HideCompleted) && (incidence->type() == "Todo") ) { 00100 if ( (static_cast<Todo *>(incidence))->isCompleted() ) 00101 return false; 00102 } 00103 00104 if (mCriteria & HideRecurring) { 00105 if (incidence->doesRecur()) return false; 00106 } 00107 00108 if (mCriteria & ShowCategories) { 00109 for (QStringList::Iterator it = mCategoryList.begin(); 00110 it != mCategoryList.end(); ++it ) { 00111 QStringList incidenceCategories = incidence->categories(); 00112 for (QStringList::Iterator it2 = incidenceCategories.begin(); 00113 it2 != incidenceCategories.end(); ++it2 ) { 00114 if ((*it) == (*it2)) { 00115 return true; 00116 } 00117 } 00118 } 00119 return false; 00120 } else { 00121 for (QStringList::Iterator it = mCategoryList.begin(); 00122 it != mCategoryList.end(); ++it ) { 00123 QStringList incidenceCategories = incidence->categories(); 00124 for (QStringList::Iterator it2 = incidenceCategories.begin(); 00125 it2 != incidenceCategories.end(); ++it2 ) { 00126 if ((*it) == (*it2)) { 00127 return false; 00128 } 00129 } 00130 } 00131 return true; 00132 } 00133 00134 // kdDebug(5800) << "CalFilter::filterIncidence(): passed" << endl; 00135 00136 return true; 00137 } 00138 00139 void CalFilter::setEnabled(bool enabled) 00140 { 00141 mEnabled = enabled; 00142 } 00143 00144 bool CalFilter::isEnabled() 00145 { 00146 return mEnabled; 00147 } 00148 00149 void CalFilter::setCriteria(int criteria) 00150 { 00151 mCriteria = criteria; 00152 } 00153 00154 int CalFilter::criteria() 00155 { 00156 return mCriteria; 00157 } 00158 00159 void CalFilter::setCategoryList(const QStringList &categoryList) 00160 { 00161 mCategoryList = categoryList; 00162 } 00163 00164 QStringList CalFilter::categoryList() 00165 { 00166 return mCategoryList; 00167 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:42 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003