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