• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

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

KDE's Doxygen guidelines are available online.

KCalCore Library

Skip menu "KCalCore Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal