summaryrefslogtreecommitdiffabout
path: root/kaddressbook/filter.cpp
Unidiff
Diffstat (limited to 'kaddressbook/filter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/filter.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/kaddressbook/filter.cpp b/kaddressbook/filter.cpp
index 7a869fa..12ab1e3 100644
--- a/kaddressbook/filter.cpp
+++ b/kaddressbook/filter.cpp
@@ -22,98 +22,106 @@
22*/ 22*/
23 23
24#include <kconfig.h> 24#include <kconfig.h>
25#include <kconfigbase.h> 25#include <kconfigbase.h>
26#include <kdebug.h> 26#include <kdebug.h>
27 27
28#include "kabprefs.h" 28#include "kabprefs.h"
29 29
30#include "filter.h" 30#include "filter.h"
31#include <secrecy.h> 31#include <secrecy.h>
32 32
33Filter::Filter() 33Filter::Filter()
34 : mName( QString::null ), mMatchRule( Matching ), 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} 39}
39 40
40Filter::Filter( const QString &name ) 41Filter::Filter( const QString &name )
41 : mName( name ), mMatchRule( Matching ), mEnabled( true ), 42 : mName( name ), mMatchRule( NotMatching ), mEnabled( true ),
42 mInternal( false ) 43 mInternal( false )
43{ 44{
44 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; 45 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ;
46 noName = false;
45} 47}
46 48
47Filter::~Filter() 49Filter::~Filter()
48{ 50{
49} 51}
50 52
51void Filter::setName( const QString &name ) 53void Filter::setName( const QString &name )
52{ 54{
53 mName = name; 55 mName = name;
56 noName = false;
54} 57}
55 58
56const QString &Filter::name() const 59const QString &Filter::name() const
57{ 60{
58 return mName; 61 return mName;
59} 62}
60 63
61bool Filter::isInternal() const 64bool Filter::isInternal() const
62{ 65{
63 return mInternal; 66 return mInternal;
64} 67}
65 68
66void Filter::apply( KABC::Addressee::List &addresseeList ) 69void Filter::apply( KABC::Addressee::List &addresseeList )
67{ 70{
71 if ( noName )
72 return;
68 KABC::Addressee::List::Iterator iter; 73 KABC::Addressee::List::Iterator iter;
69 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { 74 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) {
70 if ( filterAddressee( *iter ) ) 75 if ( filterAddressee( *iter ) )
71 ++iter; 76 ++iter;
72 else 77 else
73 { 78 {
74#ifndef KAB_EMBEDDED 79#ifndef KAB_EMBEDDED
75 iter = addresseeList.erase( iter ); 80 iter = addresseeList.erase( iter );
76#else //KAB_EMBEDDED 81#else //KAB_EMBEDDED
77 iter = addresseeList.remove( iter ); 82 iter = addresseeList.remove( iter );
78#endif //KAB_EMBEDDED 83#endif //KAB_EMBEDDED
79 } 84 }
80 } 85 }
81} 86}
82 87
83bool Filter::filterAddressee( const KABC::Addressee &a ) 88bool Filter::filterAddressee( const KABC::Addressee &a )
84{ 89{
90
91 if ( noName )
92 return true;
93 //qDebug("Filter::filterAddressee %s",mName.latin1() );
85 switch ( a.secrecy().type()) { 94 switch ( a.secrecy().type()) {
86 case KABC::Secrecy::Public: 95 case KABC::Secrecy::Public:
87 if (! (mCriteria & ShowPublic )) 96 if (! (mCriteria & ShowPublic ))
88 return false; 97 return false;
89 break; 98 break;
90 case KABC::Secrecy::Private: 99 case KABC::Secrecy::Private:
91 if (! (mCriteria & ShowPrivate )) 100 if (! (mCriteria & ShowPrivate ))
92 return false; 101 return false;
93 break; 102 break;
94 case KABC::Secrecy::Confidential: 103 case KABC::Secrecy::Confidential:
95 if (! (mCriteria & ShowConfidential )) 104 if (! (mCriteria & ShowConfidential ))
96 return false; 105 return false;
97 break; 106 break;
98 default: 107 default:
99 return false; 108 return false;
100 break; 109 break;
101 } 110 }
102 QStringList::Iterator iter; 111 QStringList::Iterator iter;
103 iter = mCategoryList.begin(); 112 iter = mCategoryList.begin();
104 // empty filter always matches
105 113
106 if ( iter == mCategoryList.end() ) 114 if ( iter == mCategoryList.end() )
107 return true; 115 return ( !(mMatchRule == Matching) );
108 116
109 for ( ; iter != mCategoryList.end(); ++iter ) { 117 for ( ; iter != mCategoryList.end(); ++iter ) {
110 if ( a.hasCategory( *iter ) ) 118 if ( a.hasCategory( *iter ) )
111 return ( mMatchRule == Matching ); 119 return ( mMatchRule == Matching );
112 } 120 }
113 121
114 return !( mMatchRule == Matching ); 122 return !( mMatchRule == Matching );
115} 123}
116 124
117void Filter::setEnabled( bool on ) 125void Filter::setEnabled( bool on )
118{ 126{
119 mEnabled = on; 127 mEnabled = on;
@@ -135,25 +143,26 @@ const QStringList &Filter::categories() const
135} 143}
136 144
137void Filter::save( KConfig *config ) 145void Filter::save( KConfig *config )
138{ 146{
139 config->writeEntry( "Name", mName ); 147 config->writeEntry( "Name", mName );
140 config->writeEntry( "Enabled", mEnabled ); 148 config->writeEntry( "Enabled", mEnabled );
141 config->writeEntry( "Categories", mCategoryList ); 149 config->writeEntry( "Categories", mCategoryList );
142 config->writeEntry( "MatchRule", (int)mMatchRule ); 150 config->writeEntry( "MatchRule", (int)mMatchRule );
143 config->writeEntry( "Criteria", (int)mCriteria ); 151 config->writeEntry( "Criteria", (int)mCriteria );
144} 152}
145 153
146void Filter::restore( KConfig *config ) 154void Filter::restore( KConfig *config )
147{ 155{
156 noName = false;
148 mName = config->readEntry( "Name", "<internal error>" ); 157 mName = config->readEntry( "Name", "<internal error>" );
149 mEnabled = config->readBoolEntry( "Enabled", true ); 158 mEnabled = config->readBoolEntry( "Enabled", true );
150 mCategoryList = config->readListEntry( "Categories" ); 159 mCategoryList = config->readListEntry( "Categories" );
151 mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching ); 160 mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching );
152 mCriteria = config->readNumEntry( "Criteria", (ShowPublic | ShowPrivate| ShowConfidential ) ); 161 mCriteria = config->readNumEntry( "Criteria", (ShowPublic | ShowPrivate| ShowConfidential ) );
153} 162}
154 163
155void Filter::save( KConfig *config, QString baseGroup, Filter::List &list ) 164void Filter::save( KConfig *config, QString baseGroup, Filter::List &list )
156{ 165{
157 { 166 {
158 KConfigGroupSaver s( config, baseGroup ); 167 KConfigGroupSaver s( config, baseGroup );
159 168
@@ -196,25 +205,26 @@ Filter::List Filter::restore( KConfig *config, QString baseGroup )
196 for ( int i = 0; i < count; i++ ) { 205 for ( int i = 0; i < count; i++ ) {
197 { 206 {
198 KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); 207 KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) );
199 f.restore( config ); 208 f.restore( config );
200 } 209 }
201 210
202 list.append( f ); 211 list.append( f );
203 } 212 }
204 213
205 if ( list.isEmpty()) { 214 if ( list.isEmpty()) {
206 QStringList cats = KABPrefs::instance()->mCustomCategories; 215 QStringList cats = KABPrefs::instance()->mCustomCategories;
207 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { 216 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
208 Filter filter; 217 Filter filter;
218 filter.noName = false;
209 filter.mName = *it; 219 filter.mName = *it;
210 filter.mEnabled = true; 220 filter.mEnabled = true;
211 filter.mCategoryList = *it; 221 filter.mCategoryList = *it;
212 filter.mMatchRule = Matching; 222 filter.mMatchRule = Matching;
213 filter.mInternal = true; 223 filter.mInternal = true;
214 list.append( filter ); 224 list.append( filter );
215 } 225 }
216 } 226 }
217 return list; 227 return list;
218} 228}
219 229
220void Filter::setMatchRule( MatchRule rule ) 230void Filter::setMatchRule( MatchRule rule )