00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00058 }
00059
00060
00061 void CalFilter::apply(
Todo::List *eventlist )
00062 {
00063
if ( !mEnabled )
return;
00064
00065
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
00077 }
00078
00079 bool CalFilter::filterEvent(
Event *event)
00080 {
00081
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
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
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
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 }