libkcal
calfilter.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <kdebug.h>
00025
00026 #include "calfilter.h"
00027
00028 using namespace KCal;
00029
00030 CalFilter::CalFilter()
00031 {
00032 mEnabled = true;
00033 mCriteria = 0;
00034 mCompletedTimeSpan = 0;
00035 }
00036
00037 CalFilter::CalFilter(const QString &name)
00038 {
00039 mName = name;
00040 mEnabled = true;
00041 mCriteria = 0;
00042 mCompletedTimeSpan = 0;
00043 }
00044
00045 CalFilter::~CalFilter()
00046 {
00047 }
00048
00049 void CalFilter::apply( Event::List *eventlist ) const
00050 {
00051 if ( !mEnabled ) return;
00052
00053
00054
00055 Event::List::Iterator it = eventlist->begin();
00056 while( it != eventlist->end() ) {
00057 if ( !filterIncidence( *it ) ) {
00058 it = eventlist->remove( it );
00059 } else {
00060 ++it;
00061 }
00062 }
00063
00064
00065 }
00066
00067
00068 void CalFilter::apply( Todo::List *todolist ) const
00069 {
00070 if ( !mEnabled ) return;
00071
00072
00073
00074 Todo::List::Iterator it = todolist->begin();
00075 while( it != todolist->end() ) {
00076 if ( !filterIncidence( *it ) ) {
00077 it = todolist->remove( it );
00078 } else {
00079 ++it;
00080 }
00081 }
00082
00083
00084 }
00085
00086 void CalFilter::apply( Journal::List *journallist ) const
00087 {
00088 if ( !mEnabled ) return;
00089
00090 Journal::List::Iterator it = journallist->begin();
00091 while( it != journallist->end() ) {
00092 if ( !filterIncidence( *it ) ) {
00093 it = journallist->remove( it );
00094 } else {
00095 ++it;
00096 }
00097 }
00098 }
00099
00100 bool CalFilter::filterIncidence(Incidence *incidence) const
00101 {
00102
00103
00104 if ( !mEnabled ) return true;
00105
00106 Todo *todo = dynamic_cast<Todo *>(incidence);
00107 if( todo ) {
00108 if ( (mCriteria & HideCompleted) && todo->isCompleted() ) {
00109
00110 if ( todo->completed().addDays( mCompletedTimeSpan ) <
00111 QDateTime::currentDateTime() ) {
00112 return false;
00113 }
00114 }
00115
00116 if( ( mCriteria & HideInactiveTodos ) &&
00117 ( todo->hasStartDate() &&
00118 QDateTime::currentDateTime() < todo->dtStart() ||
00119 todo->isCompleted() ) )
00120 return false;
00121
00122 if ( mCriteria & HideTodosWithoutAttendeeInEmailList ) {
00123 bool iAmOneOfTheAttendees = false;
00124 const Attendee::List &attendees = todo->attendees();
00125 if ( !todo->attendees().isEmpty() ) {
00126 Attendee::List::ConstIterator it;
00127 for( it = attendees.begin(); it != attendees.end(); ++it ) {
00128 if ( mEmailList.find( (*it)->email() ) != mEmailList.end() ) {
00129 iAmOneOfTheAttendees = true;
00130 break;
00131 }
00132 }
00133 } else {
00134
00135 iAmOneOfTheAttendees = true;
00136 }
00137 if ( !iAmOneOfTheAttendees )
00138 return false;
00139 }
00140 }
00141
00142
00143 if (mCriteria & HideRecurring) {
00144 if (incidence->doesRecur()) return false;
00145 }
00146
00147 if (mCriteria & ShowCategories) {
00148 for (QStringList::ConstIterator it = mCategoryList.constBegin();
00149 it != mCategoryList.constEnd(); ++it ) {
00150 QStringList incidenceCategories = incidence->categories();
00151 for (QStringList::ConstIterator it2 = incidenceCategories.constBegin();
00152 it2 != incidenceCategories.constEnd(); ++it2 ) {
00153 if ((*it) == (*it2)) {
00154 return true;
00155 }
00156 }
00157 }
00158 return false;
00159 } else {
00160 for (QStringList::ConstIterator it = mCategoryList.constBegin();
00161 it != mCategoryList.constEnd(); ++it ) {
00162 QStringList incidenceCategories = incidence->categories();
00163 for (QStringList::ConstIterator it2 = incidenceCategories.constBegin();
00164 it2 != incidenceCategories.constEnd(); ++it2 ) {
00165 if ((*it) == (*it2)) {
00166 return false;
00167 }
00168 }
00169 }
00170 return true;
00171 }
00172
00173
00174
00175 return true;
00176 }
00177
00178 void CalFilter::setEnabled(bool enabled)
00179 {
00180 mEnabled = enabled;
00181 }
00182
00183 bool CalFilter::isEnabled() const
00184 {
00185 return mEnabled;
00186 }
00187
00188 void CalFilter::setCriteria(int criteria)
00189 {
00190 mCriteria = criteria;
00191 }
00192
00193 int CalFilter::criteria() const
00194 {
00195 return mCriteria;
00196 }
00197
00198 void CalFilter::setCategoryList(const QStringList &categoryList)
00199 {
00200 mCategoryList = categoryList;
00201 }
00202
00203 QStringList CalFilter::categoryList() const
00204 {
00205 return mCategoryList;
00206 }
00207
00208 void CalFilter::setEmailList(const QStringList &emailList)
00209 {
00210 mEmailList = emailList;
00211 }
00212
00213 QStringList CalFilter::emailList() const
00214 {
00215 return mEmailList;
00216 }
00217
00218 void CalFilter::setCompletedTimeSpan( int timespan )
00219 {
00220 mCompletedTimeSpan = timespan;
00221 }
00222
00223 int CalFilter::completedTimeSpan() const
00224 {
00225 return mCompletedTimeSpan;
00226 }
|