-rw-r--r-- | kaddressbook/filter.cpp | 22 |
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 | |||
@@ -7,148 +7,170 @@ | |||
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 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. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
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 | ||
32 | Filter::Filter() | 33 | Filter::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 | ||
38 | Filter::Filter( const QString &name ) | 40 | Filter::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 | ||
44 | Filter::~Filter() | 47 | Filter::~Filter() |
45 | { | 48 | { |
46 | } | 49 | } |
47 | 50 | ||
48 | void Filter::setName( const QString &name ) | 51 | void Filter::setName( const QString &name ) |
49 | { | 52 | { |
50 | mName = name; | 53 | mName = name; |
51 | } | 54 | } |
52 | 55 | ||
53 | const QString &Filter::name() const | 56 | const QString &Filter::name() const |
54 | { | 57 | { |
55 | return mName; | 58 | return mName; |
56 | } | 59 | } |
57 | 60 | ||
58 | bool Filter::isInternal() const | 61 | bool Filter::isInternal() const |
59 | { | 62 | { |
60 | return mInternal; | 63 | return mInternal; |
61 | } | 64 | } |
62 | 65 | ||
63 | void Filter::apply( KABC::Addressee::List &addresseeList ) | 66 | void Filter::apply( KABC::Addressee::List &addresseeList ) |
64 | { | 67 | { |
65 | KABC::Addressee::List::Iterator iter; | 68 | KABC::Addressee::List::Iterator iter; |
66 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { | 69 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { |
67 | if ( filterAddressee( *iter ) ) | 70 | if ( filterAddressee( *iter ) ) |
68 | ++iter; | 71 | ++iter; |
69 | else | 72 | else |
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 | ||
80 | bool Filter::filterAddressee( const KABC::Addressee &a ) | 83 | bool 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 | ||
94 | return !( mMatchRule == Matching ); | 114 | return !( mMatchRule == Matching ); |
95 | } | 115 | } |
96 | 116 | ||
97 | void Filter::setEnabled( bool on ) | 117 | void Filter::setEnabled( bool on ) |
98 | { | 118 | { |
99 | mEnabled = on; | 119 | mEnabled = on; |
100 | } | 120 | } |
101 | 121 | ||
102 | bool Filter::isEnabled() const | 122 | bool Filter::isEnabled() const |
103 | { | 123 | { |
104 | return mEnabled; | 124 | return mEnabled; |
105 | } | 125 | } |
106 | 126 | ||
107 | void Filter::setCategories( const QStringList &list ) | 127 | void Filter::setCategories( const QStringList &list ) |
108 | { | 128 | { |
109 | mCategoryList = list; | 129 | mCategoryList = list; |
110 | } | 130 | } |
111 | 131 | ||
112 | const QStringList &Filter::categories() const | 132 | const QStringList &Filter::categories() const |
113 | { | 133 | { |
114 | return mCategoryList; | 134 | return mCategoryList; |
115 | } | 135 | } |
116 | 136 | ||
117 | void Filter::save( KConfig *config ) | 137 | void 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 | ||
125 | void Filter::restore( KConfig *config ) | 146 | void 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 | ||
133 | void Filter::save( KConfig *config, QString baseGroup, Filter::List &list ) | 155 | void 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 ) ); |
143 | */ | 165 | */ |
144 | } | 166 | } |
145 | 167 | ||
146 | int index = 0; | 168 | int index = 0; |
147 | Filter::List::Iterator iter; | 169 | Filter::List::Iterator iter; |
148 | for ( iter = list.begin(); iter != list.end(); ++iter ) { | 170 | for ( iter = list.begin(); iter != list.end(); ++iter ) { |
149 | if ( !(*iter).mInternal ) { | 171 | if ( !(*iter).mInternal ) { |
150 | KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) ); | 172 | KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) ); |
151 | 173 | ||
152 | (*iter).save( config ); | 174 | (*iter).save( config ); |
153 | index++; | 175 | index++; |
154 | } | 176 | } |