author | zautrix <zautrix> | 2005-01-16 11:22:49 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-16 11:22:49 (UTC) |
commit | d57ed4438bbd6e3d9a7a0e46283d3e7645b4e47b (patch) (unidiff) | |
tree | 522438ce187845f6d74d7888be203759138615fa /libkcal | |
parent | 92b8de5ff678bddf69b9f0a45c1d90829c50c592 (diff) | |
download | kdepimpi-d57ed4438bbd6e3d9a7a0e46283d3e7645b4e47b.zip kdepimpi-d57ed4438bbd6e3d9a7a0e46283d3e7645b4e47b.tar.gz kdepimpi-d57ed4438bbd6e3d9a7a0e46283d3e7645b4e47b.tar.bz2 |
filter impl
-rw-r--r-- | libkcal/calfilter.cpp | 29 | ||||
-rw-r--r-- | libkcal/calfilter.h | 3 |
2 files changed, 22 insertions, 10 deletions
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp index c182db5..c425dfc 100644 --- a/libkcal/calfilter.cpp +++ b/libkcal/calfilter.cpp | |||
@@ -19,127 +19,138 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kdebug.h> | 21 | #include <kdebug.h> |
22 | 22 | ||
23 | #include "calfilter.h" | 23 | #include "calfilter.h" |
24 | 24 | ||
25 | using namespace KCal; | 25 | using namespace KCal; |
26 | 26 | ||
27 | CalFilter::CalFilter() | 27 | CalFilter::CalFilter() |
28 | { | 28 | { |
29 | mEnabled = true; | 29 | mEnabled = true; |
30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
31 | } | 31 | } |
32 | 32 | ||
33 | CalFilter::CalFilter(const QString &name) | 33 | CalFilter::CalFilter(const QString &name) |
34 | { | 34 | { |
35 | mName = name; | 35 | mName = name; |
36 | mEnabled = true; | 36 | mEnabled = true; |
37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
38 | } | 38 | } |
39 | 39 | ||
40 | CalFilter::~CalFilter() | 40 | CalFilter::~CalFilter() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | void CalFilter::apply(QPtrList<Event> *eventlist) | 44 | void CalFilter::apply(QPtrList<Event> *eventlist) |
45 | { | 45 | { |
46 | if (!mEnabled) return; | 46 | if (!mEnabled) return; |
47 | 47 | ||
48 | // kdDebug(5800) << "CalFilter::apply()" << endl; | 48 | // kdDebug(5800) << "CalFilter::apply()" << endl; |
49 | 49 | ||
50 | Event *event = eventlist->first(); | 50 | Event *event = eventlist->first(); |
51 | while(event) { | 51 | while(event) { |
52 | if (!filterEvent(event)) { | 52 | if (!filterEvent(event)) { |
53 | eventlist->remove(); | 53 | eventlist->remove(); |
54 | event = eventlist->current(); | 54 | event = eventlist->current(); |
55 | } else { | 55 | } else { |
56 | event = eventlist->next(); | 56 | event = eventlist->next(); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
61 | } | 61 | } |
62 | 62 | ||
63 | // TODO: avoid duplicating apply() code | 63 | // TODO: avoid duplicating apply() code |
64 | void CalFilter::apply(QPtrList<Todo> *eventlist) | 64 | void CalFilter::apply(QPtrList<Todo> *eventlist) |
65 | { | 65 | { |
66 | if (!mEnabled) return; | 66 | if (!mEnabled) return; |
67 | |||
68 | // kdDebug(5800) << "CalFilter::apply()" << endl; | ||
69 | |||
70 | Todo *event = eventlist->first(); | 67 | Todo *event = eventlist->first(); |
71 | while(event) { | 68 | while(event) { |
72 | if (!filterTodo(event)) { | 69 | if (!filterTodo(event)) { |
73 | eventlist->remove(); | 70 | eventlist->remove(); |
74 | event = eventlist->current(); | 71 | event = eventlist->current(); |
75 | } else { | 72 | } else { |
76 | event = eventlist->next(); | 73 | event = eventlist->next(); |
77 | } | 74 | } |
78 | } | 75 | } |
79 | 76 | ||
80 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 77 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
81 | } | 78 | } |
82 | 79 | bool CalFilter::filterCalendarItem(Incidence *in) | |
80 | { | ||
81 | if ( in->type() == "Event" ) | ||
82 | return filterEvent( (Event*) in ); | ||
83 | else if ( in->type() =="Todo" ) | ||
84 | return filterTodo( (Todo*) in); | ||
85 | else if ( in->type() =="Journal" ) | ||
86 | return filterJournal( (Journal*) in ); | ||
87 | return false; | ||
88 | } | ||
83 | bool CalFilter::filterEvent(Event *event) | 89 | bool CalFilter::filterEvent(Event *event) |
84 | { | 90 | { |
85 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 91 | if (mCriteria & HideEvents) |
86 | 92 | return false; | |
87 | if (mCriteria & HideRecurring) { | 93 | if (mCriteria & HideRecurring) { |
88 | if (event->recurrence()->doesRecur()) return false; | 94 | if (event->recurrence()->doesRecur()) return false; |
89 | } | 95 | } |
90 | 96 | ||
91 | return filterIncidence(event); | 97 | return filterIncidence(event); |
92 | } | 98 | } |
93 | 99 | bool CalFilter::filterJournal(Journal *j) | |
100 | { | ||
101 | if (mCriteria & HideJournals) | ||
102 | return false; | ||
103 | return true; | ||
104 | } | ||
94 | bool CalFilter::filterTodo(Todo *todo) | 105 | bool CalFilter::filterTodo(Todo *todo) |
95 | { | 106 | { |
96 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 107 | if (mCriteria & HideTodos) |
97 | 108 | return false; | |
98 | if (mCriteria & HideCompleted) { | 109 | if (mCriteria & HideCompleted) { |
99 | if (todo->isCompleted()) return false; | 110 | if (todo->isCompleted()) return false; |
100 | } | 111 | } |
101 | 112 | ||
102 | return filterIncidence(todo); | 113 | return filterIncidence(todo); |
103 | } | 114 | } |
104 | bool CalFilter::showCategories() | 115 | bool CalFilter::showCategories() |
105 | { | 116 | { |
106 | return mCriteria & ShowCategories; | 117 | return mCriteria & ShowCategories; |
107 | } | 118 | } |
108 | int CalFilter::getSecrecy() | 119 | int CalFilter::getSecrecy() |
109 | { | 120 | { |
110 | if ( (mCriteria & ShowPublic )) | 121 | if ( (mCriteria & ShowPublic )) |
111 | return Incidence::SecrecyPublic; | 122 | return Incidence::SecrecyPublic; |
112 | if ( (mCriteria & ShowPrivate )) | 123 | if ( (mCriteria & ShowPrivate )) |
113 | return Incidence::SecrecyPrivate; | 124 | return Incidence::SecrecyPrivate; |
114 | if ( (mCriteria & ShowConfidential )) | 125 | if ( (mCriteria & ShowConfidential )) |
115 | return Incidence::SecrecyConfidential; | 126 | return Incidence::SecrecyConfidential; |
116 | return Incidence::SecrecyPublic; | 127 | return Incidence::SecrecyPublic; |
117 | } | 128 | } |
118 | bool CalFilter::filterIncidence(Incidence *incidence) | 129 | bool CalFilter::filterIncidence(Incidence *incidence) |
119 | { | 130 | { |
120 | if ( mCriteria > 7 ) { | 131 | if ( mCriteria > 7 ) { |
121 | switch (incidence->secrecy()) { | 132 | switch (incidence->secrecy()) { |
122 | case Incidence::SecrecyPublic: | 133 | case Incidence::SecrecyPublic: |
123 | if (! (mCriteria & ShowPublic )) | 134 | if (! (mCriteria & ShowPublic )) |
124 | return false; | 135 | return false; |
125 | break; | 136 | break; |
126 | case Incidence::SecrecyPrivate: | 137 | case Incidence::SecrecyPrivate: |
127 | if (! (mCriteria & ShowPrivate )) | 138 | if (! (mCriteria & ShowPrivate )) |
128 | return false; | 139 | return false; |
129 | break; | 140 | break; |
130 | case Incidence::SecrecyConfidential: | 141 | case Incidence::SecrecyConfidential: |
131 | if (! (mCriteria & ShowConfidential )) | 142 | if (! (mCriteria & ShowConfidential )) |
132 | return false; | 143 | return false; |
133 | break; | 144 | break; |
134 | default: | 145 | default: |
135 | return false; | 146 | return false; |
136 | break; | 147 | break; |
137 | } | 148 | } |
138 | } | 149 | } |
139 | 150 | ||
140 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 151 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; |
141 | 152 | ||
142 | if (mCriteria & ShowCategories) { | 153 | if (mCriteria & ShowCategories) { |
143 | for (QStringList::Iterator it = mCategoryList.begin(); | 154 | for (QStringList::Iterator it = mCategoryList.begin(); |
144 | it != mCategoryList.end(); ++it ) { | 155 | it != mCategoryList.end(); ++it ) { |
145 | QStringList incidenceCategories = incidence->categories(); | 156 | QStringList incidenceCategories = incidence->categories(); |
diff --git a/libkcal/calfilter.h b/libkcal/calfilter.h index 5ad0064..29db441 100644 --- a/libkcal/calfilter.h +++ b/libkcal/calfilter.h | |||
@@ -16,97 +16,98 @@ | |||
16 | along with this library; see the file COPYING.LIB. If not, write to | 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, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #ifndef _CALFILTER_H | 21 | #ifndef _CALFILTER_H |
22 | #define _CALFILTER_H | 22 | #define _CALFILTER_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include "event.h" | 27 | #include "event.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | namespace KCal { | 30 | namespace KCal { |
31 | 31 | ||
32 | /** | 32 | /** |
33 | Filter for calendar objects. | 33 | Filter for calendar objects. |
34 | */ | 34 | */ |
35 | class CalFilter { | 35 | class CalFilter { |
36 | public: | 36 | public: |
37 | /** Construct filter. */ | 37 | /** Construct filter. */ |
38 | CalFilter(); | 38 | CalFilter(); |
39 | /** Construct filter with name */ | 39 | /** Construct filter with name */ |
40 | CalFilter(const QString &name); | 40 | CalFilter(const QString &name); |
41 | /** Destruct filter. */ | 41 | /** Destruct filter. */ |
42 | ~CalFilter(); | 42 | ~CalFilter(); |
43 | 43 | ||
44 | /** | 44 | /** |
45 | Set name of filter. | 45 | Set name of filter. |
46 | */ | 46 | */ |
47 | void setName(const QString &name) { mName = name; } | 47 | void setName(const QString &name) { mName = name; } |
48 | /** | 48 | /** |
49 | Return name of filter. | 49 | Return name of filter. |
50 | */ | 50 | */ |
51 | QString name() const { return mName; } | 51 | QString name() const { return mName; } |
52 | 52 | ||
53 | /** | 53 | /** |
54 | Apply filter to eventlist, all events not matching filter criterias are | 54 | Apply filter to eventlist, all events not matching filter criterias are |
55 | removed from the list. | 55 | removed from the list. |
56 | */ | 56 | */ |
57 | void apply(QPtrList<Event> *eventlist); | 57 | void apply(QPtrList<Event> *eventlist); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | Apply filter to todolist, all todos not matching filter criterias are | 60 | Apply filter to todolist, all todos not matching filter criterias are |
61 | removed from the list. | 61 | removed from the list. |
62 | */ | 62 | */ |
63 | void apply(QPtrList<Todo> *todolist); | 63 | void apply(QPtrList<Todo> *todolist); |
64 | 64 | bool CalFilter::filterCalendarItem(Incidence *in); | |
65 | bool CalFilter::filterJournal(Journal *in); | ||
65 | /** | 66 | /** |
66 | Apply filter criteria on the specified event. Return true, if event passes | 67 | Apply filter criteria on the specified event. Return true, if event passes |
67 | criteria, otherwise return false. | 68 | criteria, otherwise return false. |
68 | */ | 69 | */ |
69 | bool filterEvent(Event *); | 70 | bool filterEvent(Event *); |
70 | 71 | ||
71 | /** | 72 | /** |
72 | Apply filter criteria on the specified todo. Return true, if event passes | 73 | Apply filter criteria on the specified todo. Return true, if event passes |
73 | criteria, otherwise return false. | 74 | criteria, otherwise return false. |
74 | */ | 75 | */ |
75 | bool filterTodo(Todo *); | 76 | bool filterTodo(Todo *); |
76 | 77 | ||
77 | /** | 78 | /** |
78 | Apply filter criteria on the specified incidence. Return true, if event passes | 79 | Apply filter criteria on the specified incidence. Return true, if event passes |
79 | criteria, otherwise return false. | 80 | criteria, otherwise return false. |
80 | */ | 81 | */ |
81 | bool filterIncidence(Incidence *); | 82 | bool filterIncidence(Incidence *); |
82 | 83 | ||
83 | /** | 84 | /** |
84 | Enable or disable filter. | 85 | Enable or disable filter. |
85 | */ | 86 | */ |
86 | void setEnabled(bool); | 87 | void setEnabled(bool); |
87 | /** | 88 | /** |
88 | Return wheter the filter is enabled or not. | 89 | Return wheter the filter is enabled or not. |
89 | */ | 90 | */ |
90 | bool isEnabled(); | 91 | bool isEnabled(); |
91 | bool showCategories(); | 92 | bool showCategories(); |
92 | int getSecrecy(); | 93 | int getSecrecy(); |
93 | /** | 94 | /** |
94 | Set list of categories, which is used for showing/hiding categories of | 95 | Set list of categories, which is used for showing/hiding categories of |
95 | events. | 96 | events. |
96 | See related functions. | 97 | See related functions. |
97 | */ | 98 | */ |
98 | void setCategoryList(const QStringList &); | 99 | void setCategoryList(const QStringList &); |
99 | /** | 100 | /** |
100 | Return category list, used for showing/hiding categories of events. | 101 | Return category list, used for showing/hiding categories of events. |
101 | See related functions. | 102 | See related functions. |
102 | */ | 103 | */ |
103 | QStringList categoryList(); | 104 | QStringList categoryList(); |
104 | 105 | ||
105 | enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; | 106 | enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; |
106 | 107 | ||
107 | /** | 108 | /** |
108 | Set criteria, which have to be fulfilled by events passing the filter. | 109 | Set criteria, which have to be fulfilled by events passing the filter. |
109 | */ | 110 | */ |
110 | void setCriteria(int); | 111 | void setCriteria(int); |
111 | /** | 112 | /** |
112 | Get inclusive filter criteria. | 113 | Get inclusive filter criteria. |