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

KCal Library

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

KDE's Doxygen guidelines are available online.

KCal Library

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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