24 #include <tdeconfig.h>
32 : mName( TQString() ), mMatchRule( Matching ), mEnabled( true ),
33 mInternal( false ), mIsEmpty( true )
37 Filter::Filter(
const TQString &name )
38 : mName( name ), mMatchRule( Matching ), mEnabled( true ),
39 mInternal( false ), mIsEmpty( false )
66 TDEABC::Addressee::List::Iterator iter;
67 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) {
71 iter = addresseeList.erase( iter );
77 TQStringList::ConstIterator iter;
78 iter = mCategoryList.begin();
81 if ( iter == mCategoryList.end() ) {
82 if ( mMatchRule == Matching )
85 if ( a.categories().empty() )
92 for ( ; iter != mCategoryList.end(); ++iter ) {
93 if ( a.hasCategory( *iter ) )
94 return ( mMatchRule == Matching );
97 return !( mMatchRule == Matching );
114 mCategoryList = list;
121 return mCategoryList;
126 config->writeEntry(
"Name", mName );
127 config->writeEntry(
"Enabled", mEnabled );
128 config->writeEntry(
"Categories", mCategoryList );
129 config->writeEntry(
"MatchRule", (
int)mMatchRule );
134 mName = config->readEntry(
"Name",
"<internal error>" );
135 mEnabled = config->readBoolEntry(
"Enabled",
true );
136 mCategoryList = config->readListEntry(
"Categories" );
137 mMatchRule = (MatchRule)config->readNumEntry(
"MatchRule", Matching );
142 void Filter::save( TDEConfig *config,
const TQString &baseGroup, Filter::List &list )
145 TDEConfigGroupSaver s( config, baseGroup );
148 uint count = config->readNumEntry(
"Count" );
149 for ( uint i = 0; i < count; ++i )
150 config->deleteGroup( TQString(
"%1_%2" ).arg( baseGroup ).arg( i ) );
155 Filter::List::Iterator iter;
156 for ( iter = list.begin(); iter != list.end(); ++iter ) {
157 if ( !(*iter).mInternal ) {
158 TDEConfigGroupSaver s( config, TQString(
"%1_%2" ).arg( baseGroup )
160 (*iter).save( config );
165 TDEConfigGroupSaver s( config, baseGroup );
166 config->writeEntry(
"Count", index );
176 TDEConfigGroupSaver s( config, baseGroup );
177 count = config->readNumEntry(
"Count", 0 );
180 for (
int i = 0; i < count; i++ ) {
182 TDEConfigGroupSaver s( config, TQString(
"%1_%2" ).arg( baseGroup ).arg( i ) );
189 const TQStringList cats = KABPrefs::instance()->customCategories();
190 for ( TQStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) {
193 filter.mEnabled =
true;
194 filter.mCategoryList = *it;
195 filter.mMatchRule = Matching;
196 filter.mInternal =
true;
197 filter.mIsEmpty =
false;
198 list.append( filter );
Filter for AddressBook related objects (Addressees)
MatchRule matchRule() const
void setName(const TQString &name)
Set the name of the filter.
void restore(TDEConfig *config)
Loads the filter from the config file.
void setEnabled(bool on)
Enable or disable the filter.
const TQStringList & categories() const
void setCategories(const TQStringList &list)
Set the list of categories.
bool filterAddressee(const TDEABC::Addressee &a) const
Apply the filter to the addressee.
void save(TDEConfig *config)
Saves the filter to the config file.
const TQString & name() const
void apply(TDEABC::Addressee::List &addresseeList)
Apply the filter to the addressee list.
void setMatchRule(MatchRule rule)
Sets the filter rule.