-rw-r--r-- | kaddressbook/filter.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kaddressbook/filter.cpp b/kaddressbook/filter.cpp index 12ab1e3..6462310 100644 --- a/kaddressbook/filter.cpp +++ b/kaddressbook/filter.cpp | |||
@@ -29,210 +29,210 @@ | |||
29 | 29 | ||
30 | #include "filter.h" | 30 | #include "filter.h" |
31 | #include <secrecy.h> | 31 | #include <secrecy.h> |
32 | 32 | ||
33 | Filter::Filter() | 33 | Filter::Filter() |
34 | : mName( QString::null ), mMatchRule( NotMatching ), mEnabled( true ), | 34 | : mName( QString::null ), mMatchRule( NotMatching ), mEnabled( true ), |
35 | mInternal( false ) | 35 | mInternal( false ) |
36 | { | 36 | { |
37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
38 | noName = true; | 38 | noName = true; |
39 | } | 39 | } |
40 | 40 | ||
41 | Filter::Filter( const QString &name ) | 41 | Filter::Filter( const QString &name ) |
42 | : mName( name ), mMatchRule( NotMatching ), mEnabled( true ), | 42 | : mName( name ), mMatchRule( NotMatching ), mEnabled( true ), |
43 | mInternal( false ) | 43 | mInternal( false ) |
44 | { | 44 | { |
45 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 45 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
46 | noName = false; | 46 | noName = false; |
47 | } | 47 | } |
48 | 48 | ||
49 | Filter::~Filter() | 49 | Filter::~Filter() |
50 | { | 50 | { |
51 | } | 51 | } |
52 | 52 | ||
53 | void Filter::setName( const QString &name ) | 53 | void Filter::setName( const QString &name ) |
54 | { | 54 | { |
55 | mName = name; | 55 | mName = name; |
56 | noName = false; | 56 | noName = false; |
57 | } | 57 | } |
58 | 58 | ||
59 | const QString &Filter::name() const | 59 | const QString &Filter::name() const |
60 | { | 60 | { |
61 | return mName; | 61 | return mName; |
62 | } | 62 | } |
63 | 63 | ||
64 | bool Filter::isInternal() const | 64 | bool Filter::isInternal() const |
65 | { | 65 | { |
66 | return mInternal; | 66 | return mInternal; |
67 | } | 67 | } |
68 | 68 | ||
69 | void Filter::apply( KABC::Addressee::List &addresseeList ) | 69 | void Filter::apply( KABC::Addressee::List &addresseeList ) |
70 | { | 70 | { |
71 | if ( noName ) | 71 | if ( noName ) |
72 | return; | 72 | return; |
73 | KABC::Addressee::List::Iterator iter; | 73 | KABC::Addressee::List::Iterator iter; |
74 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { | 74 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { |
75 | if ( filterAddressee( *iter ) ) | 75 | if ( filterAddressee( *iter ) ) |
76 | ++iter; | 76 | ++iter; |
77 | else | 77 | else |
78 | { | 78 | { |
79 | #ifndef KAB_EMBEDDED | 79 | #ifndef KAB_EMBEDDED |
80 | iter = addresseeList.erase( iter ); | 80 | iter = addresseeList.erase( iter ); |
81 | #else //KAB_EMBEDDED | 81 | #else //KAB_EMBEDDED |
82 | iter = addresseeList.remove( iter ); | 82 | iter = addresseeList.remove( iter ); |
83 | #endif //KAB_EMBEDDED | 83 | #endif //KAB_EMBEDDED |
84 | } | 84 | } |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | bool Filter::filterAddressee( const KABC::Addressee &a ) | 88 | bool Filter::filterAddressee( const KABC::Addressee &a ) |
89 | { | 89 | { |
90 | 90 | ||
91 | if ( noName ) | 91 | if ( noName ) |
92 | return true; | 92 | return true; |
93 | //qDebug("Filter::filterAddressee %s",mName.latin1() ); | 93 | //qDebug("Filter::filterAddressee %s",mName.latin1() ); |
94 | switch ( a.secrecy().type()) { | 94 | switch ( a.secrecy().type()) { |
95 | case KABC::Secrecy::Public: | 95 | case KABC::Secrecy::Public: |
96 | if (! (mCriteria & ShowPublic )) | 96 | if (! (mCriteria & ShowPublic )) |
97 | return false; | 97 | return false; |
98 | break; | 98 | break; |
99 | case KABC::Secrecy::Private: | 99 | case KABC::Secrecy::Private: |
100 | if (! (mCriteria & ShowPrivate )) | 100 | if (! (mCriteria & ShowPrivate )) |
101 | return false; | 101 | return false; |
102 | break; | 102 | break; |
103 | case KABC::Secrecy::Confidential: | 103 | case KABC::Secrecy::Confidential: |
104 | if (! (mCriteria & ShowConfidential )) | 104 | if (! (mCriteria & ShowConfidential )) |
105 | return false; | 105 | return false; |
106 | break; | 106 | break; |
107 | default: | 107 | default: |
108 | return false; | 108 | return false; |
109 | break; | 109 | break; |
110 | } | 110 | } |
111 | QStringList::Iterator iter; | 111 | QStringList::Iterator iter; |
112 | iter = mCategoryList.begin(); | 112 | iter = mCategoryList.begin(); |
113 | 113 | ||
114 | if ( iter == mCategoryList.end() ) | 114 | if ( iter == mCategoryList.end() ) |
115 | return ( !(mMatchRule == Matching) ); | 115 | return ( !(mMatchRule == Matching) ); |
116 | 116 | ||
117 | for ( ; iter != mCategoryList.end(); ++iter ) { | 117 | for ( ; iter != mCategoryList.end(); ++iter ) { |
118 | if ( a.hasCategory( *iter ) ) | 118 | if ( a.hasCategory( *iter ) ) |
119 | return ( mMatchRule == Matching ); | 119 | return ( mMatchRule == Matching ); |
120 | } | 120 | } |
121 | 121 | ||
122 | return !( mMatchRule == Matching ); | 122 | return !( mMatchRule == Matching ); |
123 | } | 123 | } |
124 | 124 | ||
125 | void Filter::setEnabled( bool on ) | 125 | void Filter::setEnabled( bool on ) |
126 | { | 126 | { |
127 | mEnabled = on; | 127 | mEnabled = on; |
128 | } | 128 | } |
129 | 129 | ||
130 | bool Filter::isEnabled() const | 130 | bool Filter::isEnabled() const |
131 | { | 131 | { |
132 | return mEnabled; | 132 | return mEnabled; |
133 | } | 133 | } |
134 | 134 | ||
135 | void Filter::setCategories( const QStringList &list ) | 135 | void Filter::setCategories( const QStringList &list ) |
136 | { | 136 | { |
137 | mCategoryList = list; | 137 | mCategoryList = list; |
138 | } | 138 | } |
139 | 139 | ||
140 | const QStringList &Filter::categories() const | 140 | const QStringList &Filter::categories() const |
141 | { | 141 | { |
142 | return mCategoryList; | 142 | return mCategoryList; |
143 | } | 143 | } |
144 | 144 | ||
145 | void Filter::save( KConfig *config ) | 145 | void Filter::save( KConfig *config ) |
146 | { | 146 | { |
147 | config->writeEntry( "Name", mName ); | 147 | config->writeEntry( "Name", mName ); |
148 | config->writeEntry( "Enabled", mEnabled ); | 148 | config->writeEntry( "Enabled", mEnabled ); |
149 | config->writeEntry( "Categories", mCategoryList ); | 149 | config->writeEntry( "Categories", mCategoryList ); |
150 | config->writeEntry( "MatchRule", (int)mMatchRule ); | 150 | config->writeEntry( "MatchRule", (int)mMatchRule ); |
151 | config->writeEntry( "Criteria", (int)mCriteria ); | 151 | config->writeEntry( "Criteria", (int)mCriteria ); |
152 | } | 152 | } |
153 | 153 | ||
154 | void Filter::restore( KConfig *config ) | 154 | void Filter::restore( KConfig *config ) |
155 | { | 155 | { |
156 | noName = false; | 156 | noName = false; |
157 | mName = config->readEntry( "Name", "<internal error>" ); | 157 | mName = config->readEntry( "Name", "<internal error>" ); |
158 | mEnabled = config->readBoolEntry( "Enabled", true ); | 158 | mEnabled = config->readBoolEntry( "Enabled", true ); |
159 | mCategoryList = config->readListEntry( "Categories" ); | 159 | mCategoryList = config->readListEntry( "Categories" ); |
160 | mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching ); | 160 | mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching ); |
161 | mCriteria = config->readNumEntry( "Criteria", (ShowPublic | ShowPrivate| ShowConfidential ) ); | 161 | mCriteria = config->readNumEntry( "Criteria", (ShowPublic | ShowPrivate| ShowConfidential ) ); |
162 | } | 162 | } |
163 | 163 | ||
164 | void Filter::save( KConfig *config, QString baseGroup, Filter::List &list ) | 164 | void Filter::save( KConfig *config, QString baseGroup, Filter::List &list ) |
165 | { | 165 | { |
166 | { | 166 | { |
167 | KConfigGroupSaver s( config, baseGroup ); | 167 | KConfigGroupSaver s( config, baseGroup ); |
168 | 168 | ||
169 | // remove the old filters | 169 | // remove the old filters |
170 | uint count = config->readNumEntry( "Count" ); | 170 | uint count = config->readNumEntry( "Count" ); |
171 | /* // memory access violation here | 171 | /* // memory access violation here |
172 | for ( uint i = 0; i < count; ++i ) | 172 | for ( uint i = 0; i < count; ++i ) |
173 | config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); | 173 | config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); |
174 | */ | 174 | */ |
175 | } | 175 | } |
176 | 176 | ||
177 | int index = 0; | 177 | int index = 0; |
178 | Filter::List::Iterator iter; | 178 | Filter::List::Iterator iter; |
179 | for ( iter = list.begin(); iter != list.end(); ++iter ) { | 179 | for ( iter = list.begin(); iter != list.end(); ++iter ) { |
180 | if ( !(*iter).mInternal ) { | 180 | if ( !(*iter).mInternal ) { |
181 | KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) ); | 181 | KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) ); |
182 | 182 | ||
183 | (*iter).save( config ); | 183 | (*iter).save( config ); |
184 | index++; | 184 | index++; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | KConfigGroupSaver s( config, baseGroup ); | 188 | KConfigGroupSaver s( config, baseGroup ); |
189 | 189 | ||
190 | config->writeEntry( "Count", index ); | 190 | config->writeEntry( "Count", index ); |
191 | 191 | ||
192 | } | 192 | } |
193 | 193 | ||
194 | Filter::List Filter::restore( KConfig *config, QString baseGroup ) | 194 | Filter::List Filter::restore( KConfig *config, QString baseGroup ) |
195 | { | 195 | { |
196 | Filter::List list; | 196 | Filter::List list; |
197 | int count = 0; | 197 | int count = 0; |
198 | Filter f; | 198 | Filter f; |
199 | 199 | ||
200 | { | 200 | { |
201 | KConfigGroupSaver s( config, baseGroup ); | 201 | KConfigGroupSaver s( config, baseGroup ); |
202 | count = config->readNumEntry( "Count", 0 ); | 202 | count = config->readNumEntry( "Count", 0 ); |
203 | } | 203 | } |
204 | 204 | ||
205 | for ( int i = 0; i < count; i++ ) { | 205 | for ( int i = 0; i < count; i++ ) { |
206 | { | 206 | { |
207 | KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); | 207 | KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); |
208 | f.restore( config ); | 208 | f.restore( config ); |
209 | } | 209 | } |
210 | 210 | ||
211 | list.append( f ); | 211 | list.append( f ); |
212 | } | 212 | } |
213 | 213 | ||
214 | if ( list.isEmpty()) { | 214 | if ( list.isEmpty()) { |
215 | QStringList cats = KABPrefs::instance()->mCustomCategories; | 215 | QStringList cats = KABPrefs::instance()->mCustomCategories; |
216 | for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { | 216 | for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { |
217 | Filter filter; | 217 | Filter filter; |
218 | filter.noName = false; | 218 | filter.noName = false; |
219 | filter.mName = *it; | 219 | filter.mName = *it; |
220 | filter.mEnabled = true; | 220 | filter.mEnabled = true; |
221 | filter.mCategoryList = *it; | 221 | filter.mCategoryList = QStringList(*it); |
222 | filter.mMatchRule = Matching; | 222 | filter.mMatchRule = Matching; |
223 | filter.mInternal = true; | 223 | filter.mInternal = true; |
224 | list.append( filter ); | 224 | list.append( filter ); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | return list; | 227 | return list; |
228 | } | 228 | } |
229 | 229 | ||
230 | void Filter::setMatchRule( MatchRule rule ) | 230 | void Filter::setMatchRule( MatchRule rule ) |
231 | { | 231 | { |
232 | mMatchRule = rule; | 232 | mMatchRule = rule; |
233 | } | 233 | } |
234 | 234 | ||
235 | Filter::MatchRule Filter::matchRule() const | 235 | Filter::MatchRule Filter::matchRule() const |
236 | { | 236 | { |
237 | return mMatchRule; | 237 | return mMatchRule; |
238 | } | 238 | } |