calfilter.cpp
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(QPtrList<Event> *eventlist)
00043 {
00044 if (!mEnabled) return;
00045
00046
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
00059 }
00060
00061
00062 void CalFilter::apply(QPtrList<Todo> *eventlist)
00063 {
00064 if (!mEnabled) return;
00065
00066
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
00079 }
00080
00081 bool CalFilter::filterEvent(Event *event)
00082 {
00083
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
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
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
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 }
This file is part of the documentation for kdelibs Version 3.1.4.