KCalCore Library
calfilter.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00036 #include "calfilter.h"
00037
00038 using namespace KCalCore;
00039
00044
00045 class KCalCore::CalFilter::Private
00046 {
00047 public:
00048 Private()
00049 : mCriteria( 0 ),
00050 mCompletedTimeSpan( 0 ),
00051 mEnabled( true )
00052 {}
00053 QString mName;
00054 QStringList mCategoryList;
00055 QStringList mEmailList;
00056 int mCriteria;
00057 int mCompletedTimeSpan;
00058 bool mEnabled;
00059
00060 };
00061
00062
00063 CalFilter::CalFilter() : d( new KCalCore::CalFilter::Private )
00064 {
00065 }
00066
00067 CalFilter::CalFilter( const QString &name )
00068 : d( new KCalCore::CalFilter::Private )
00069 {
00070 d->mName = name;
00071 }
00072
00073 CalFilter::~CalFilter()
00074 {
00075 delete d;
00076 }
00077
00078 bool KCalCore::CalFilter::operator==( const CalFilter &filter ) const
00079 {
00080 return d->mName == filter.d->mName &&
00081 d->mCriteria == filter.d->mCriteria &&
00082 d->mCategoryList == filter.d->mCategoryList &&
00083 d->mEmailList == filter.d->mEmailList &&
00084 d->mCompletedTimeSpan == filter.d->mCompletedTimeSpan;
00085 }
00086
00087 void CalFilter::apply( Event::List *eventList ) const
00088 {
00089 if ( !d->mEnabled ) {
00090 return;
00091 }
00092
00093 Event::List::Iterator it = eventList->begin();
00094 while ( it != eventList->end() ) {
00095 if ( !filterIncidence( *it ) ) {
00096 it = eventList->erase( it );
00097 } else {
00098 ++it;
00099 }
00100 }
00101 }
00102
00103
00104 void CalFilter::apply( Todo::List *todoList ) const
00105 {
00106 if ( !d->mEnabled ) {
00107 return;
00108 }
00109
00110 Todo::List::Iterator it = todoList->begin();
00111 while ( it != todoList->end() ) {
00112 if ( !filterIncidence( *it ) ) {
00113 it = todoList->erase( it );
00114 } else {
00115 ++it;
00116 }
00117 }
00118 }
00119
00120 void CalFilter::apply( Journal::List *journalList ) const
00121 {
00122 if ( !d->mEnabled ) {
00123 return;
00124 }
00125
00126 Journal::List::Iterator it = journalList->begin();
00127 while ( it != journalList->end() ) {
00128 if ( !filterIncidence( *it ) ) {
00129 it = journalList->erase( it );
00130 } else {
00131 ++it;
00132 }
00133 }
00134 }
00135
00136 bool CalFilter::filterIncidence( Incidence::Ptr incidence ) const
00137 {
00138 if ( !d->mEnabled ) {
00139 return true;
00140 }
00141
00142 Todo::Ptr todo = incidence.dynamicCast<Todo>();
00143 if ( todo ) {
00144 if ( ( d->mCriteria & HideCompletedTodos ) && todo->isCompleted() ) {
00145
00146 if ( todo->completed().addDays( d->mCompletedTimeSpan ) <
00147 KDateTime::currentUtcDateTime() ) {
00148 return false;
00149 }
00150 }
00151
00152 if ( ( d->mCriteria & HideInactiveTodos ) &&
00153 ( ( todo->hasStartDate() &&
00154 KDateTime::currentUtcDateTime() < todo->dtStart() ) ||
00155 todo->isCompleted() ) ) {
00156 return false;
00157 }
00158
00159 if ( d->mCriteria & HideNoMatchingAttendeeTodos ) {
00160 bool iAmOneOfTheAttendees = false;
00161 const Attendee::List &attendees = todo->attendees();
00162 if ( !todo->attendees().isEmpty() ) {
00163 Attendee::List::ConstIterator it;
00164 for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00165 if ( d->mEmailList.contains( (*it)->email() ) ) {
00166 iAmOneOfTheAttendees = true;
00167 break;
00168 }
00169 }
00170 } else {
00171
00172 iAmOneOfTheAttendees = true;
00173 }
00174 if ( !iAmOneOfTheAttendees ) {
00175 return false;
00176 }
00177 }
00178 }
00179
00180 if ( d->mCriteria & HideRecurring ) {
00181 if ( incidence->recurs() ) {
00182 return false;
00183 }
00184 }
00185
00186 if ( d->mCriteria & ShowCategories ) {
00187 for ( QStringList::ConstIterator it = d->mCategoryList.constBegin();
00188 it != d->mCategoryList.constEnd(); ++it ) {
00189 QStringList incidenceCategories = incidence->categories();
00190 for ( QStringList::ConstIterator it2 = incidenceCategories.constBegin();
00191 it2 != incidenceCategories.constEnd(); ++it2 ) {
00192 if ( (*it) == (*it2) ) {
00193 return true;
00194 }
00195 }
00196 }
00197 return false;
00198 } else {
00199 for ( QStringList::ConstIterator it = d->mCategoryList.constBegin();
00200 it != d->mCategoryList.constEnd(); ++it ) {
00201 QStringList incidenceCategories = incidence->categories();
00202 for ( QStringList::ConstIterator it2 = incidenceCategories.constBegin();
00203 it2 != incidenceCategories.constEnd(); ++it2 ) {
00204 if ( (*it) == (*it2) ) {
00205 return false;
00206 }
00207 }
00208 }
00209 return true;
00210 }
00211
00212 return true;
00213 }
00214
00215 void CalFilter::setName( const QString &name )
00216 {
00217 d->mName = name;
00218 }
00219
00220 QString CalFilter::name() const
00221 {
00222 return d->mName;
00223 }
00224
00225 void CalFilter::setEnabled( bool enabled )
00226 {
00227 d->mEnabled = enabled;
00228 }
00229
00230 bool CalFilter::isEnabled() const
00231 {
00232 return d->mEnabled;
00233 }
00234
00235 void CalFilter::setCriteria( int criteria )
00236 {
00237 d->mCriteria = criteria;
00238 }
00239
00240 int CalFilter::criteria() const
00241 {
00242 return d->mCriteria;
00243 }
00244
00245 void CalFilter::setCategoryList( const QStringList &categoryList )
00246 {
00247 d->mCategoryList = categoryList;
00248 }
00249
00250 QStringList CalFilter::categoryList() const
00251 {
00252 return d->mCategoryList;
00253 }
00254
00255 void CalFilter::setEmailList( const QStringList &emailList )
00256 {
00257 d->mEmailList = emailList;
00258 }
00259
00260 QStringList CalFilter::emailList() const
00261 {
00262 return d->mEmailList;
00263 }
00264
00265 void CalFilter::setCompletedTimeSpan( int timespan )
00266 {
00267 d->mCompletedTimeSpan = timespan;
00268 }
00269
00270 int CalFilter::completedTimeSpan() const
00271 {
00272 return d->mCompletedTimeSpan;
00273 }