author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkcal/calfilter.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
-rw-r--r-- | libkcal/calfilter.cpp | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp new file mode 100644 index 0000000..c182db5 --- a/dev/null +++ b/libkcal/calfilter.cpp | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | This file is part of libkcal. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #include <kdebug.h> | ||
22 | |||
23 | #include "calfilter.h" | ||
24 | |||
25 | using namespace KCal; | ||
26 | |||
27 | CalFilter::CalFilter() | ||
28 | { | ||
29 | mEnabled = true; | ||
30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | ||
31 | } | ||
32 | |||
33 | CalFilter::CalFilter(const QString &name) | ||
34 | { | ||
35 | mName = name; | ||
36 | mEnabled = true; | ||
37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | ||
38 | } | ||
39 | |||
40 | CalFilter::~CalFilter() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | void CalFilter::apply(QPtrList<Event> *eventlist) | ||
45 | { | ||
46 | if (!mEnabled) return; | ||
47 | |||
48 | // kdDebug(5800) << "CalFilter::apply()" << endl; | ||
49 | |||
50 | Event *event = eventlist->first(); | ||
51 | while(event) { | ||
52 | if (!filterEvent(event)) { | ||
53 | eventlist->remove(); | ||
54 | event = eventlist->current(); | ||
55 | } else { | ||
56 | event = eventlist->next(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | ||
61 | } | ||
62 | |||
63 | // TODO: avoid duplicating apply() code | ||
64 | void CalFilter::apply(QPtrList<Todo> *eventlist) | ||
65 | { | ||
66 | if (!mEnabled) return; | ||
67 | |||
68 | // kdDebug(5800) << "CalFilter::apply()" << endl; | ||
69 | |||
70 | Todo *event = eventlist->first(); | ||
71 | while(event) { | ||
72 | if (!filterTodo(event)) { | ||
73 | eventlist->remove(); | ||
74 | event = eventlist->current(); | ||
75 | } else { | ||
76 | event = eventlist->next(); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | ||
81 | } | ||
82 | |||
83 | bool CalFilter::filterEvent(Event *event) | ||
84 | { | ||
85 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | ||
86 | |||
87 | if (mCriteria & HideRecurring) { | ||
88 | if (event->recurrence()->doesRecur()) return false; | ||
89 | } | ||
90 | |||
91 | return filterIncidence(event); | ||
92 | } | ||
93 | |||
94 | bool CalFilter::filterTodo(Todo *todo) | ||
95 | { | ||
96 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | ||
97 | |||
98 | if (mCriteria & HideCompleted) { | ||
99 | if (todo->isCompleted()) return false; | ||
100 | } | ||
101 | |||
102 | return filterIncidence(todo); | ||
103 | } | ||
104 | bool CalFilter::showCategories() | ||
105 | { | ||
106 | return mCriteria & ShowCategories; | ||
107 | } | ||
108 | int CalFilter::getSecrecy() | ||
109 | { | ||
110 | if ( (mCriteria & ShowPublic )) | ||
111 | return Incidence::SecrecyPublic; | ||
112 | if ( (mCriteria & ShowPrivate )) | ||
113 | return Incidence::SecrecyPrivate; | ||
114 | if ( (mCriteria & ShowConfidential )) | ||
115 | return Incidence::SecrecyConfidential; | ||
116 | return Incidence::SecrecyPublic; | ||
117 | } | ||
118 | bool CalFilter::filterIncidence(Incidence *incidence) | ||
119 | { | ||
120 | if ( mCriteria > 7 ) { | ||
121 | switch (incidence->secrecy()) { | ||
122 | case Incidence::SecrecyPublic: | ||
123 | if (! (mCriteria & ShowPublic )) | ||
124 | return false; | ||
125 | break; | ||
126 | case Incidence::SecrecyPrivate: | ||
127 | if (! (mCriteria & ShowPrivate )) | ||
128 | return false; | ||
129 | break; | ||
130 | case Incidence::SecrecyConfidential: | ||
131 | if (! (mCriteria & ShowConfidential )) | ||
132 | return false; | ||
133 | break; | ||
134 | default: | ||
135 | return false; | ||
136 | break; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | ||
141 | |||
142 | if (mCriteria & ShowCategories) { | ||
143 | for (QStringList::Iterator it = mCategoryList.begin(); | ||
144 | it != mCategoryList.end(); ++it ) { | ||
145 | QStringList incidenceCategories = incidence->categories(); | ||
146 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | ||
147 | it2 != incidenceCategories.end(); ++it2 ) { | ||
148 | if ((*it) == (*it2)) { | ||
149 | return true; | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | return false; | ||
154 | } else { | ||
155 | for (QStringList::Iterator it = mCategoryList.begin(); | ||
156 | it != mCategoryList.end(); ++it ) { | ||
157 | QStringList incidenceCategories = incidence->categories(); | ||
158 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | ||
159 | it2 != incidenceCategories.end(); ++it2 ) { | ||
160 | if ((*it) == (*it2)) { | ||
161 | return false; | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | return true; | ||
166 | } | ||
167 | |||
168 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; | ||
169 | |||
170 | return true; | ||
171 | } | ||
172 | |||
173 | void CalFilter::setEnabled(bool enabled) | ||
174 | { | ||
175 | mEnabled = enabled; | ||
176 | } | ||
177 | |||
178 | bool CalFilter::isEnabled() | ||
179 | { | ||
180 | return mEnabled; | ||
181 | } | ||
182 | |||
183 | void CalFilter::setCriteria(int criteria) | ||
184 | { | ||
185 | mCriteria = criteria; | ||
186 | } | ||
187 | |||
188 | int CalFilter::criteria() | ||
189 | { | ||
190 | return mCriteria; | ||
191 | } | ||
192 | |||
193 | void CalFilter::setCategoryList(const QStringList &categoryList) | ||
194 | { | ||
195 | mCategoryList = categoryList; | ||
196 | } | ||
197 | |||
198 | QStringList CalFilter::categoryList() | ||
199 | { | ||
200 | return mCategoryList; | ||
201 | } | ||