libkcal

calfilter.cpp
1 /*
2  This file is part of libkcal.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6  Copyright (C) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include <kdebug.h>
25 
26 #include "calfilter.h"
27 
28 using namespace KCal;
29 
31 {
32  mEnabled = true;
33  mCriteria = 0;
34  mCompletedTimeSpan = 0;
35 }
36 
37 CalFilter::CalFilter(const TQString &name)
38 {
39  mName = name;
40  mEnabled = true;
41  mCriteria = 0;
42  mCompletedTimeSpan = 0;
43 }
44 
46 {
47 }
48 
49 void CalFilter::apply( Event::List *eventlist ) const
50 {
51  if ( !mEnabled ) return;
52 
53 // kdDebug(5800) << "CalFilter::apply()" << endl;
54 
55  Event::List::Iterator it = eventlist->begin();
56  while( it != eventlist->end() ) {
57  if ( !filterIncidence( *it ) ) {
58  it = eventlist->remove( it );
59  } else {
60  ++it;
61  }
62  }
63 
64 // kdDebug(5800) << "CalFilter::apply() done" << endl;
65 }
66 
67 // TODO: avoid duplicating apply() code
68 void CalFilter::apply( Todo::List *todolist ) const
69 {
70  if ( !mEnabled ) return;
71 
72 // kdDebug(5800) << "CalFilter::apply()" << endl;
73 
74  Todo::List::Iterator it = todolist->begin();
75  while( it != todolist->end() ) {
76  if ( !filterIncidence( *it ) ) {
77  it = todolist->remove( it );
78  } else {
79  ++it;
80  }
81  }
82 
83 // kdDebug(5800) << "CalFilter::apply() done" << endl;
84 }
85 
86 void CalFilter::apply( Journal::List *journallist ) const
87 {
88  if ( !mEnabled ) return;
89 
90  Journal::List::Iterator it = journallist->begin();
91  while( it != journallist->end() ) {
92  if ( !filterIncidence( *it ) ) {
93  it = journallist->remove( it );
94  } else {
95  ++it;
96  }
97  }
98 }
99 
100 bool CalFilter::filterIncidence(Incidence *incidence) const
101 {
102 // kdDebug(5800) << "CalFilter::filterIncidence(): " << incidence->summary() << endl;
103 
104  if ( !mEnabled ) return true;
105 
106  Todo *todo = dynamic_cast<Todo *>(incidence);
107  if( todo ) {
108  if ( (mCriteria & HideCompleted) && todo->isCompleted() ) {
109  // Check if completion date is suffently long ago:
110  if ( todo->completed().addDays( mCompletedTimeSpan ) <
111  TQDateTime::currentDateTime() ) {
112  return false;
113  }
114  }
115 
116  if( ( mCriteria & HideInactiveTodos ) &&
117  ( todo->hasStartDate() &&
118  TQDateTime::currentDateTime() < todo->dtStart() ||
119  todo->isCompleted() ) )
120  return false;
121 
122  if ( mCriteria & HideTodosWithoutAttendeeInEmailList ) {
123  bool iAmOneOfTheAttendees = false;
124  const Attendee::List &attendees = todo->attendees();
125  if ( !todo->attendees().isEmpty() ) {
126  Attendee::List::ConstIterator it;
127  for( it = attendees.begin(); it != attendees.end(); ++it ) {
128  if ( mEmailList.find( (*it)->email() ) != mEmailList.end() ) {
129  iAmOneOfTheAttendees = true;
130  break;
131  }
132  }
133  } else {
134  // no attendees, must be me only
135  iAmOneOfTheAttendees = true;
136  }
137  if ( !iAmOneOfTheAttendees )
138  return false;
139  }
140  }
141 
142 
143  if (mCriteria & HideRecurring) {
144  if (incidence->doesRecur()) return false;
145  }
146 
147  if (mCriteria & ShowCategories) {
148  for (TQStringList::ConstIterator it = mCategoryList.constBegin();
149  it != mCategoryList.constEnd(); ++it ) {
150  TQStringList incidenceCategories = incidence->categories();
151  for (TQStringList::ConstIterator it2 = incidenceCategories.constBegin();
152  it2 != incidenceCategories.constEnd(); ++it2 ) {
153  if ((*it) == (*it2)) {
154  return true;
155  }
156  }
157  }
158  return false;
159  } else {
160  for (TQStringList::ConstIterator it = mCategoryList.constBegin();
161  it != mCategoryList.constEnd(); ++it ) {
162  TQStringList incidenceCategories = incidence->categories();
163  for (TQStringList::ConstIterator it2 = incidenceCategories.constBegin();
164  it2 != incidenceCategories.constEnd(); ++it2 ) {
165  if ((*it) == (*it2)) {
166  return false;
167  }
168  }
169  }
170  return true;
171  }
172 
173 // kdDebug(5800) << "CalFilter::filterIncidence(): passed" << endl;
174 
175  return true;
176 }
177 
178 void CalFilter::setEnabled(bool enabled)
179 {
180  mEnabled = enabled;
181 }
182 
184 {
185  return mEnabled;
186 }
187 
188 void CalFilter::setCriteria(int criteria)
189 {
190  mCriteria = criteria;
191 }
192 
194 {
195  return mCriteria;
196 }
197 
198 void CalFilter::setCategoryList(const TQStringList &categoryList)
199 {
200  mCategoryList = categoryList;
201 }
202 
203 TQStringList CalFilter::categoryList() const
204 {
205  return mCategoryList;
206 }
207 
208 void CalFilter::setEmailList(const TQStringList &emailList)
209 {
210  mEmailList = emailList;
211 }
212 
213 TQStringList CalFilter::emailList() const
214 {
215  return mEmailList;
216 }
217 
219 {
220  mCompletedTimeSpan = timespan;
221 }
222 
224 {
225  return mCompletedTimeSpan;
226 }
TQStringList emailList() const
Return list of email addresses which are to be considered when finding incidences which the current u...
Definition: calfilter.cpp:213
void setCompletedTimeSpan(int timespan)
Set the number of days for "Hide completed todos", after which todos are not shown any more.
Definition: calfilter.cpp:218
TQStringList categoryList() const
Return category list, used for showing/hiding categories of events.
Definition: calfilter.cpp:203
TQString name() const
Return name of filter.
Definition: calfilter.h:55
void apply(Event::List *eventlist) const
Apply filter to eventlist, all events not matching filter criterias are removed from the list.
Definition: calfilter.cpp:49
void setEnabled(bool)
Enable or disable filter.
Definition: calfilter.cpp:178
void setCategoryList(const TQStringList &)
Set list of categories, which is used for showing/hiding categories of events.
Definition: calfilter.cpp:198
int criteria() const
Get inclusive filter criteria.
Definition: calfilter.cpp:193
bool isEnabled() const
Return wheter the filter is enabled or not.
Definition: calfilter.cpp:183
bool filterIncidence(Incidence *) const
Apply filter criteria on the specified incidence.
Definition: calfilter.cpp:100
void setCriteria(int)
Set criteria, which have to be fulfilled by events passing the filter.
Definition: calfilter.cpp:188
~CalFilter()
Destruct filter.
Definition: calfilter.cpp:45
CalFilter()
Construct filter.
Definition: calfilter.cpp:30
void setEmailList(const TQStringList &)
Set list of email addresses which are to be considered when finding incidences which the current user...
Definition: calfilter.cpp:208
int completedTimeSpan() const
Return the number of days for "Hide completed todos", after which todos are not shown any more.
Definition: calfilter.cpp:223
const Attendee::List & attendees() const
Return list of attendees.
This class provides the base class common to all calendar components.
Definition: incidence.h:48
TQStringList categories() const
Return categories as a list of strings.
Definition: incidence.cpp:323
bool doesRecur() const
Forward to Recurrence::doesRecur().
Definition: incidence.cpp:416
This class provides a Todo in the sense of RFC2445.
Definition: todo.h:32
bool isCompleted() const
Returns true if the todo is 100% completed, otherwise return false.
Definition: todo.cpp:217
bool hasStartDate() const
Returns true if the todo has a start date, otherwise return false.
Definition: todo.cpp:157
TQDateTime dtStart(bool first=false) const
Returns the startdate of the todo.
Definition: todo.cpp:177
TQDateTime completed() const
Returns date and time when todo was completed.
Definition: todo.cpp:235
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38