File indexing completed on 2024-04-21 03:52:45
0001 /* 0002 This file is part of the kcalcore library. 0003 0004 SPDX-FileCopyrightText: 2001, 2003, 2004 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 /** 0010 @file 0011 This file is part of the API for handling calendar data and 0012 defines the CalFilter class. 0013 0014 @author Cornelius Schumacher \<schumacher@kde.org\> 0015 @author Reinhold Kainhofer \<reinhold@kainhofer.com\> 0016 */ 0017 0018 #ifndef KCALCORE_CALFILTER_H 0019 #define KCALCORE_CALFILTER_H 0020 0021 #include "event.h" 0022 #include "journal.h" 0023 #include "kcalendarcore_export.h" 0024 #include "todo.h" 0025 0026 namespace KCalendarCore 0027 { 0028 /** 0029 @brief 0030 Provides a filter for calendars. 0031 0032 This class provides a means for filtering calendar incidences by 0033 a list of email addresses, a list of categories, or other #Criteria. 0034 0035 The following #Criteria are available: 0036 - remove recurring Incidences 0037 - keep Incidences with a matching category (see setCategoryList()) 0038 - remove completed To-dos (see setCompletedTimeSpan()) 0039 - remove inactive To-dos 0040 - remove To-dos without a matching attendee (see setEmailList()) 0041 */ 0042 class KCALENDARCORE_EXPORT CalFilter 0043 { 0044 public: 0045 /** 0046 Filtering Criteria. 0047 */ 0048 enum Criteria { 0049 HideRecurring = 1, /**< Remove incidences that recur */ 0050 HideCompletedTodos = 2, /**< Remove completed to-dos */ 0051 ShowCategories = 4, /**< Show incidences with at least one matching category */ 0052 HideInactiveTodos = 8, /**< Remove to-dos that haven't started yet */ 0053 HideNoMatchingAttendeeTodos = 16, /**< Remove to-dos without a matching attendee */ 0054 }; 0055 0056 /** 0057 Constructs an empty filter -- a filter without a name or criteria. 0058 */ 0059 CalFilter(); 0060 0061 /** 0062 Constructs a filter with @p name. 0063 0064 @param name is the name of this filter. 0065 */ 0066 explicit CalFilter(const QString &name); 0067 0068 /** 0069 Destroys this filter. 0070 */ 0071 ~CalFilter(); 0072 0073 /** 0074 Sets the filter name. 0075 0076 @param name is the name of this filter. 0077 @see name(). 0078 */ 0079 void setName(const QString &name); 0080 0081 /** 0082 Returns the filter name. 0083 @see setName(). 0084 */ 0085 Q_REQUIRED_RESULT QString name() const; 0086 0087 /** 0088 Sets the criteria which must be fulfilled for an Incidence to pass 0089 the filter. 0090 0091 @param criteria is a combination of #Criteria. 0092 @see criteria(). 0093 */ 0094 void setCriteria(int criteria); 0095 0096 /** 0097 Returns the inclusive filter criteria. 0098 @see setCriteria(). 0099 */ 0100 Q_REQUIRED_RESULT int criteria() const; 0101 0102 /** 0103 Applies the filter to a list of Events. All events not matching the 0104 filter criteria are removed from the list. 0105 0106 @param eventList is a list of Events to filter. 0107 */ 0108 void apply(Event::List *eventList) const; 0109 0110 /** 0111 Applies the filter to a list of To-dos. All to-dos not matching the 0112 filter criteria are removed from the list. 0113 0114 @param todoList is a list of To-dos to filter. 0115 */ 0116 void apply(Todo::List *todoList) const; 0117 0118 /** 0119 Applies the filter to a list of Journals. All journals not matching the 0120 filter criteria are removed from the list. 0121 0122 @param journalList is a list of Journals to filter. 0123 */ 0124 void apply(Journal::List *journalList) const; 0125 0126 /** 0127 Applies the filter criteria to the specified Incidence. 0128 0129 @param incidence is the Incidence to filter. 0130 @return true if the Incidence passes the criteria; false otherwise. 0131 */ 0132 Q_REQUIRED_RESULT bool filterIncidence(const Incidence::Ptr &incidence) const; 0133 0134 /** 0135 Enables or disables the filter. 0136 0137 @param enabled is true if the filter is to be enabled; false otherwise. 0138 @see isEnabled(). 0139 */ 0140 void setEnabled(bool enabled); 0141 0142 /** 0143 Returns whether the filter is enabled or not. 0144 @see setEnabled(). 0145 */ 0146 Q_REQUIRED_RESULT bool isEnabled() const; 0147 0148 /** 0149 Sets the list of categories to be considered when filtering incidences 0150 according to the #ShowCategories criteria. 0151 0152 @param categoryList is a QStringList of categories. 0153 @see categoryList(). 0154 */ 0155 void setCategoryList(const QStringList &categoryList); 0156 0157 /** 0158 Returns the category list for this filter. 0159 @see setCategoryList(). 0160 */ 0161 Q_REQUIRED_RESULT QStringList categoryList() const; 0162 0163 /** 0164 Sets the list of email addresses to be considered when filtering 0165 incidences according to the #HideNoMatchingAttendeeTodos criteria. 0166 0167 @param emailList is a QStringList of email addresses. 0168 @see emailList(). 0169 */ 0170 void setEmailList(const QStringList &emailList); 0171 0172 /** 0173 Returns the email list for this filter. 0174 @see setEmailList(). 0175 */ 0176 Q_REQUIRED_RESULT QStringList emailList() const; 0177 0178 /** 0179 Sets the number of days for the #HideCompletedTodos criteria. 0180 If a to-do has been completed within the recent @p timespan days, 0181 then that to-do will be removed during filtering. If a time span is 0182 not specified in the filter, then all completed to-dos will be removed 0183 if the #HideCompletedTodos criteria is set. 0184 0185 @param timespan is an integer representing a time span in days. 0186 @see completedTimeSpan(). 0187 */ 0188 void setCompletedTimeSpan(int timespan); 0189 0190 /** 0191 Returns the completed time span for this filter. 0192 @see setCompletedTimeSpan() 0193 */ 0194 Q_REQUIRED_RESULT int completedTimeSpan() const; 0195 0196 /** 0197 Compares this with @p filter for equality. 0198 0199 @param filter the CalFilter to compare. 0200 */ 0201 bool operator==(const CalFilter &filter) const; 0202 0203 private: 0204 //@cond PRIVATE 0205 Q_DISABLE_COPY(CalFilter) 0206 class Private; 0207 Private *const d; 0208 //@endcond 0209 }; 0210 0211 } 0212 0213 #endif