KCalendarCore

calfilter.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <[email protected]>
5  SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <[email protected]>
6  SPDX-FileCopyrightText: 2004 Bram Schoenmakers <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
23 #include "calfilter.h"
24 
25 using namespace KCalendarCore;
26 
31 //@cond PRIVATE
32 class Q_DECL_HIDDEN KCalendarCore::CalFilter::Private
33 {
34 public:
35  Private()
36  {}
37  QString mName; // filter name
38  QStringList mCategoryList;
39  QStringList mEmailList;
40  int mCriteria = 0;
41  int mCompletedTimeSpan = 0;
42  bool mEnabled = true;
43 
44 };
45 //@endcond
46 
48 {
49 }
50 
52  : d(new KCalendarCore::CalFilter::Private)
53 {
54  d->mName = name;
55 }
56 
58 {
59  delete d;
60 }
61 
63 {
64  return d->mName == filter.d->mName &&
65  d->mCriteria == filter.d->mCriteria &&
66  d->mCategoryList == filter.d->mCategoryList &&
67  d->mEmailList == filter.d->mEmailList &&
68  d->mCompletedTimeSpan == filter.d->mCompletedTimeSpan;
69 }
70 
71 void CalFilter::apply(Event::List *eventList) const
72 {
73  if (!d->mEnabled) {
74  return;
75  }
76 
77  Event::List::Iterator it = eventList->begin();
78  while (it != eventList->end()) {
79  if (!filterIncidence(*it)) {
80  it = eventList->erase(it);
81  } else {
82  ++it;
83  }
84  }
85 }
86 
87 // TODO: avoid duplicating apply() code
88 void CalFilter::apply(Todo::List *todoList) const
89 {
90  if (!d->mEnabled) {
91  return;
92  }
93 
94  Todo::List::Iterator it = todoList->begin();
95  while (it != todoList->end()) {
96  if (!filterIncidence(*it)) {
97  it = todoList->erase(it);
98  } else {
99  ++it;
100  }
101  }
102 }
103 
104 void CalFilter::apply(Journal::List *journalList) const
105 {
106  if (!d->mEnabled) {
107  return;
108  }
109 
110  Journal::List::Iterator it = journalList->begin();
111  while (it != journalList->end()) {
112  if (!filterIncidence(*it)) {
113  it = journalList->erase(it);
114  } else {
115  ++it;
116  }
117  }
118 }
119 
120 bool CalFilter::filterIncidence(const Incidence::Ptr &incidence) const
121 {
122  if (!d->mEnabled) {
123  return true;
124  }
125 
126  Todo::Ptr todo = incidence.dynamicCast<Todo>();
127  if (todo) {
128  if ((d->mCriteria & HideCompletedTodos) && todo->isCompleted()) {
129  // Check if completion date is suffently long ago:
130  if (todo->completed().addDays(d->mCompletedTimeSpan) <
132  return false;
133  }
134  }
135 
136  if ((d->mCriteria & HideInactiveTodos) &&
137  ((todo->hasStartDate() &&
138  QDateTime::currentDateTimeUtc() < todo->dtStart()) ||
139  todo->isCompleted())) {
140  return false;
141  }
142 
143  if (d->mCriteria & HideNoMatchingAttendeeTodos) {
144  bool iAmOneOfTheAttendees = false;
145  const Attendee::List &attendees = todo->attendees();
146  if (!todo->attendees().isEmpty()) {
148  for (it = attendees.begin(); it != attendees.end(); ++it) {
149  if (d->mEmailList.contains((*it).email())) {
150  iAmOneOfTheAttendees = true;
151  break;
152  }
153  }
154  } else {
155  // no attendees, must be me only
156  iAmOneOfTheAttendees = true;
157  }
158  if (!iAmOneOfTheAttendees) {
159  return false;
160  }
161  }
162  }
163 
164  if (d->mCriteria & HideRecurring) {
165  if (incidence->recurs() || incidence->hasRecurrenceId()) {
166  return false;
167  }
168  }
169 
170  if (d->mCriteria & ShowCategories) {
171  for (QStringList::ConstIterator it = d->mCategoryList.constBegin();
172  it != d->mCategoryList.constEnd(); ++it) {
173  QStringList incidenceCategories = incidence->categories();
174  for (QStringList::ConstIterator it2 = incidenceCategories.constBegin();
175  it2 != incidenceCategories.constEnd(); ++it2) {
176  if ((*it) == (*it2)) {
177  return true;
178  }
179  }
180  }
181  return false;
182  } else {
183  for (QStringList::ConstIterator it = d->mCategoryList.constBegin();
184  it != d->mCategoryList.constEnd(); ++it) {
185  QStringList incidenceCategories = incidence->categories();
186  for (QStringList::ConstIterator it2 = incidenceCategories.constBegin();
187  it2 != incidenceCategories.constEnd(); ++it2) {
188  if ((*it) == (*it2)) {
189  return false;
190  }
191  }
192  }
193  return true;
194  }
195 }
196 
198 {
199  d->mName = name;
200 }
201 
203 {
204  return d->mName;
205 }
206 
207 void CalFilter::setEnabled(bool enabled)
208 {
209  d->mEnabled = enabled;
210 }
211 
213 {
214  return d->mEnabled;
215 }
216 
218 {
219  d->mCriteria = criteria;
220 }
221 
223 {
224  return d->mCriteria;
225 }
226 
228 {
229  d->mCategoryList = categoryList;
230 }
231 
233 {
234  return d->mCategoryList;
235 }
236 
238 {
239  d->mEmailList = emailList;
240 }
241 
243 {
244  return d->mEmailList;
245 }
246 
248 {
249  d->mCompletedTimeSpan = timespan;
250 }
251 
253 {
254  return d->mCompletedTimeSpan;
255 }
int criteria() const
Returns the inclusive filter criteria.
Definition: calfilter.cpp:222
typedef Iterator
~CalFilter()
Destroys this filter.
Definition: calfilter.cpp:57
bool isEnabled() const
Returns whether the filter is enabled or not.
Definition: calfilter.cpp:212
QVector::iterator begin()
void setCategoryList(const QStringList &categoryList)
Sets the list of categories to be considered when filtering incidences according to the ShowCategorie...
Definition: calfilter.cpp:227
void setEmailList(const QStringList &emailList)
Sets the list of email addresses to be considered when filtering incidences according ot the HideNoMa...
Definition: calfilter.cpp:237
int completedTimeSpan() const
Returns the completed time span for this filter.
Definition: calfilter.cpp:252
CalFilter()
Constructs an empty filter – a filter without a name or criteria.
Definition: calfilter.cpp:47
QVector::iterator erase(QVector::iterator begin, QVector::iterator end)
void setCompletedTimeSpan(int timespan)
Sets the number of days for the HideCompletedTodos criteria.
Definition: calfilter.cpp:247
typedef ConstIterator
bool operator==(const CalFilter &filter) const
Compares this with filter for equality.
Definition: calfilter.cpp:62
QStringList emailList() const
Returns the email list for this filter.
Definition: calfilter.cpp:242
Remove to-dos that haven&#39;t started yet.
Definition: calfilter.h:53
void setName(const QString &name)
Sets the filter name.
Definition: calfilter.cpp:197
Show incidences with at least one matching category.
Definition: calfilter.h:52
Provides a To-do in the sense of RFC2445.
Definition: todo.h:31
void apply(Event::List *eventList) const
Applies the filter to a list of Events.
Definition: calfilter.cpp:71
QStringList categoryList() const
Returns the category list for this filter.
Definition: calfilter.cpp:232
Remove incidences that recur.
Definition: calfilter.h:50
void setEnabled(bool enabled)
Enables or disables the filter.
Definition: calfilter.cpp:207
void setCriteria(int criteria)
Sets the criteria which must be fulfilled for an Incidence to pass the filter.
Definition: calfilter.cpp:217
QSharedPointer< X > dynamicCast() const const
typedef ConstIterator
QString name() const
Returns the filter name.
Definition: calfilter.cpp:202
Provides a filter for calendars.
Definition: calfilter.h:43
QList::const_iterator constEnd() const const
QList::const_iterator constBegin() const const
This file is part of the API for handling calendar data and defines the CalFilter class...
bool filterIncidence(const Incidence::Ptr &incidence) const
Applies the filter criteria to the specified Incidence.
Definition: calfilter.cpp:120
QVector::iterator end()
Remove to-dos without a matching attendee.
Definition: calfilter.h:54
QDateTime currentDateTimeUtc()
Namespace for all KCalendarCore types.
Definition: alarm.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Oct 19 2020 22:57:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.