summaryrefslogtreecommitdiffabout
path: root/kaddressbook/filter.cpp
Unidiff
Diffstat (limited to 'kaddressbook/filter.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/filter.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/kaddressbook/filter.cpp b/kaddressbook/filter.cpp
index 39d2ae4..9cb4c2d 100644
--- a/kaddressbook/filter.cpp
+++ b/kaddressbook/filter.cpp
@@ -19,35 +19,38 @@
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
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 32
32Filter::Filter() 33Filter::Filter()
33 : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ), 34 : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ),
34 mInternal( false ) 35 mInternal( false )
35{ 36{
37 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ;
36} 38}
37 39
38Filter::Filter( const QString &name ) 40Filter::Filter( const QString &name )
39 : mName( name ), mMatchRule( Matching ), mEnabled( true ), 41 : mName( name ), mMatchRule( Matching ), mEnabled( true ),
40 mInternal( false ) 42 mInternal( false )
41{ 43{
44 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ;
42} 45}
43 46
44Filter::~Filter() 47Filter::~Filter()
45{ 48{
46} 49}
47 50
48void Filter::setName( const QString &name ) 51void Filter::setName( const QString &name )
49{ 52{
50 mName = name; 53 mName = name;
51} 54}
52 55
53const QString &Filter::name() const 56const QString &Filter::name() const
@@ -70,24 +73,41 @@ void Filter::apply( KABC::Addressee::List &addresseeList )
70 { 73 {
71#ifndef KAB_EMBEDDED 74#ifndef KAB_EMBEDDED
72 iter = addresseeList.erase( iter ); 75 iter = addresseeList.erase( iter );
73#else //KAB_EMBEDDED 76#else //KAB_EMBEDDED
74 iter = addresseeList.remove( iter ); 77 iter = addresseeList.remove( iter );
75#endif //KAB_EMBEDDED 78#endif //KAB_EMBEDDED
76 } 79 }
77 } 80 }
78} 81}
79 82
80bool Filter::filterAddressee( const KABC::Addressee &a ) 83bool Filter::filterAddressee( const KABC::Addressee &a )
81{ 84{
85 switch ( a.secrecy().type()) {
86 case KABC::Secrecy::Public:
87 if (! (mCriteria & ShowPublic ))
88 return false;
89 break;
90 case KABC::Secrecy::Private:
91 if (! (mCriteria & ShowPrivate ))
92 return false;
93 break;
94 case KABC::Secrecy::Confidential:
95 if (! (mCriteria & ShowConfidential ))
96 return false;
97 break;
98 default:
99 return false;
100 break;
101 }
82 QStringList::Iterator iter; 102 QStringList::Iterator iter;
83 iter = mCategoryList.begin(); 103 iter = mCategoryList.begin();
84 // empty filter always matches 104 // empty filter always matches
85 105
86 if ( iter == mCategoryList.end() ) 106 if ( iter == mCategoryList.end() )
87 return true; 107 return true;
88 108
89 for ( ; iter != mCategoryList.end(); ++iter ) { 109 for ( ; iter != mCategoryList.end(); ++iter ) {
90 if ( a.hasCategory( *iter ) ) 110 if ( a.hasCategory( *iter ) )
91 return ( mMatchRule == Matching ); 111 return ( mMatchRule == Matching );
92 } 112 }
93 113
@@ -111,32 +131,34 @@ void Filter::setCategories( const QStringList &list )
111 131
112const QStringList &Filter::categories() const 132const QStringList &Filter::categories() const
113{ 133{
114 return mCategoryList; 134 return mCategoryList;
115} 135}
116 136
117void Filter::save( KConfig *config ) 137void Filter::save( KConfig *config )
118{ 138{
119 config->writeEntry( "Name", mName ); 139 config->writeEntry( "Name", mName );
120 config->writeEntry( "Enabled", mEnabled ); 140 config->writeEntry( "Enabled", mEnabled );
121 config->writeEntry( "Categories", mCategoryList ); 141 config->writeEntry( "Categories", mCategoryList );
122 config->writeEntry( "MatchRule", (int)mMatchRule ); 142 config->writeEntry( "MatchRule", (int)mMatchRule );
143 config->writeEntry( "Criteria", (int)mCriteria );
123} 144}
124 145
125void Filter::restore( KConfig *config ) 146void Filter::restore( KConfig *config )
126{ 147{
127 mName = config->readEntry( "Name", "<internal error>" ); 148 mName = config->readEntry( "Name", "<internal error>" );
128 mEnabled = config->readBoolEntry( "Enabled", true ); 149 mEnabled = config->readBoolEntry( "Enabled", true );
129 mCategoryList = config->readListEntry( "Categories" ); 150 mCategoryList = config->readListEntry( "Categories" );
130 mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching ); 151 mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching );
152 mCriteria = config->readNumEntry( "Criteria", (ShowPublic | ShowPrivate| ShowConfidential) );
131} 153}
132 154
133void Filter::save( KConfig *config, QString baseGroup, Filter::List &list ) 155void Filter::save( KConfig *config, QString baseGroup, Filter::List &list )
134{ 156{
135 { 157 {
136 KConfigGroupSaver s( config, baseGroup ); 158 KConfigGroupSaver s( config, baseGroup );
137 159
138 // remove the old filters 160 // remove the old filters
139 uint count = config->readNumEntry( "Count" ); 161 uint count = config->readNumEntry( "Count" );
140 /* // memory access violation here 162 /* // memory access violation here
141 for ( uint i = 0; i < count; ++i ) 163 for ( uint i = 0; i < count; ++i )
142 config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); 164 config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) );