summaryrefslogtreecommitdiffabout
path: root/kaddressbook/filter.h
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook/filter.h
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kaddressbook/filter.h') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/filter.h153
1 files changed, 153 insertions, 0 deletions
diff --git a/kaddressbook/filter.h b/kaddressbook/filter.h
new file mode 100644
index 0000000..cf2c0a1
--- a/dev/null
+++ b/kaddressbook/filter.h
@@ -0,0 +1,153 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#ifndef FILTER_H
25#define FILTER_H
26
27#include <qstring.h>
28#include <qstringlist.h>
29#include <qvaluelist.h>
30
31#include <kabc/addressee.h>
32#include <kconfig.h>
33
34/**
35 Filter for AddressBook related objects (Addressees)
36
37 @todo This class should be switched to use shared data.
38 */
39class Filter
40{
41 public:
42 typedef QValueList<Filter> List;
43
44 enum MatchRule { Matching = 0, NotMatching = 1 };
45
46 Filter();
47 Filter( const QString& name );
48 ~Filter();
49
50 /**
51 Set the name of the filter.
52 */
53 void setName( const QString &name );
54
55 /**
56 @return The name of the filter.
57 */
58 const QString &name() const;
59
60 /**
61 @return Whether the filter is an internal one.
62 */
63 bool isInternal() const;
64
65 /**
66 Apply the filter to the addressee list. All addressees not passing
67 the filter criterias will be removed from the list.
68
69 If the MatchRule is NotMatch, then all the addressees matching the
70 filter will be removed from the list.
71 */
72 void apply( KABC::Addressee::List &addresseeList );
73
74 /**
75 Apply the filter to the addressee.
76
77 @return True if the addressee passes the criteria, false otherwise.
78 The return values are opposite if the MatchRule is NotMatch.
79 */
80 bool filterAddressee( const KABC::Addressee &a );
81
82 /**
83 Enable or disable the filter
84 */
85 void setEnabled( bool on );
86
87 /**
88 @return True if this filter is enabled, false otherwise.
89 */
90 bool isEnabled() const;
91
92 /**
93 Set the list of categories. This list is used to filter addressees.
94 */
95 void setCategories( const QStringList &list );
96
97 /**
98 @return The list of categories.
99 */
100 const QStringList &categories() const;
101
102 /**
103 Saves the filter to the config file. The group should already be set.
104 */
105 void save( KConfig *config );
106
107 /**
108 Loads the filter from the config file. The group should already be set.
109 */
110 void restore( KConfig *config );
111
112 /**
113 Saves a list of filters to the config file.
114
115 @param config The config file to use
116 @param baseGroup The base groupname to use. The number of filters
117 will be written to this group, then a _1, _2, etc
118 will be append for each filter saved.
119 @param list The list of filters to be saved.
120 */
121 static void save( KConfig *config, QString baseGroup, Filter::List &list );
122
123 /**
124 Restores a list of filters from a config file.
125
126 @param config The config file to read from.
127 @param baseGroup The base group name to be used to find the filters
128
129 @return The list of filters.
130 */
131 static Filter::List restore( KConfig *config, QString baseGroup );
132
133 /**
134 Sets the filter rule. If the rule is Filter::Matching (default),
135 then the filter will return true on items that match the filter.
136 If the rule is Filter::NotMatching, then the filter will return
137 true on items that do not match the filter.
138 */
139 void setMatchRule( MatchRule rule );
140
141 /** @return The current match rule.
142 */
143 MatchRule matchRule() const;
144
145 private:
146 QString mName;
147 QStringList mCategoryList;
148 MatchRule mMatchRule;
149 bool mEnabled;
150 bool mInternal;
151};
152
153#endif