-rw-r--r-- | kaddressbook/filter.cpp | 24 | ||||
-rw-r--r-- | kaddressbook/filter.h | 1 |
2 files changed, 18 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 @@ -18,106 +18,114 @@ As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <kconfig.h> #include <kconfigbase.h> #include <kdebug.h> #include "kabprefs.h" #include "filter.h" #include <secrecy.h> Filter::Filter() - : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ), + : mName( QString::null ), mMatchRule( NotMatching ), mEnabled( true ), mInternal( false ) { mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; + noName = true; } Filter::Filter( const QString &name ) - : mName( name ), mMatchRule( Matching ), mEnabled( true ), + : mName( name ), mMatchRule( NotMatching ), mEnabled( true ), mInternal( false ) { mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; + noName = false; } Filter::~Filter() { } void Filter::setName( const QString &name ) { mName = name; + noName = false; } const QString &Filter::name() const { return mName; } bool Filter::isInternal() const { return mInternal; } void Filter::apply( KABC::Addressee::List &addresseeList ) -{ +{ + if ( noName ) + return; KABC::Addressee::List::Iterator iter; for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { if ( filterAddressee( *iter ) ) ++iter; else { #ifndef KAB_EMBEDDED iter = addresseeList.erase( iter ); #else //KAB_EMBEDDED iter = addresseeList.remove( iter ); #endif //KAB_EMBEDDED } } } bool Filter::filterAddressee( const KABC::Addressee &a ) { + + if ( noName ) + return true; + //qDebug("Filter::filterAddressee %s",mName.latin1() ); switch ( a.secrecy().type()) { case KABC::Secrecy::Public: if (! (mCriteria & ShowPublic )) return false; break; case KABC::Secrecy::Private: if (! (mCriteria & ShowPrivate )) return false; break; case KABC::Secrecy::Confidential: if (! (mCriteria & ShowConfidential )) return false; break; default: return false; break; } QStringList::Iterator iter; iter = mCategoryList.begin(); - // empty filter always matches if ( iter == mCategoryList.end() ) - return true; + return ( !(mMatchRule == Matching) ); for ( ; iter != mCategoryList.end(); ++iter ) { if ( a.hasCategory( *iter ) ) return ( mMatchRule == Matching ); } return !( mMatchRule == Matching ); } void Filter::setEnabled( bool on ) { mEnabled = on; } bool Filter::isEnabled() const { @@ -131,33 +139,34 @@ void Filter::setCategories( const QStringList &list ) const QStringList &Filter::categories() const { return mCategoryList; } void Filter::save( KConfig *config ) { config->writeEntry( "Name", mName ); config->writeEntry( "Enabled", mEnabled ); config->writeEntry( "Categories", mCategoryList ); config->writeEntry( "MatchRule", (int)mMatchRule ); config->writeEntry( "Criteria", (int)mCriteria ); } void Filter::restore( KConfig *config ) -{ +{ + noName = false; mName = config->readEntry( "Name", "<internal error>" ); mEnabled = config->readBoolEntry( "Enabled", true ); mCategoryList = config->readListEntry( "Categories" ); mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching ); mCriteria = config->readNumEntry( "Criteria", (ShowPublic | ShowPrivate| ShowConfidential ) ); } void Filter::save( KConfig *config, QString baseGroup, Filter::List &list ) { { KConfigGroupSaver s( config, baseGroup ); // remove the old filters uint count = config->readNumEntry( "Count" ); /* // memory access violation here for ( uint i = 0; i < count; ++i ) @@ -192,33 +201,34 @@ Filter::List Filter::restore( KConfig *config, QString baseGroup ) KConfigGroupSaver s( config, baseGroup ); count = config->readNumEntry( "Count", 0 ); } for ( int i = 0; i < count; i++ ) { { KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); f.restore( config ); } list.append( f ); } if ( list.isEmpty()) { QStringList cats = KABPrefs::instance()->mCustomCategories; for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { - Filter filter; + Filter filter; + filter.noName = false; filter.mName = *it; filter.mEnabled = true; filter.mCategoryList = *it; filter.mMatchRule = Matching; filter.mInternal = true; list.append( filter ); } } return list; } void Filter::setMatchRule( MatchRule rule ) { mMatchRule = rule; } diff --git a/kaddressbook/filter.h b/kaddressbook/filter.h index 93f1352..f4ae123 100644 --- a/kaddressbook/filter.h +++ b/kaddressbook/filter.h @@ -133,25 +133,26 @@ class Filter */ static Filter::List restore( KConfig *config, QString baseGroup ); /** Sets the filter rule. If the rule is Filter::Matching (default), then the filter will return true on items that match the filter. If the rule is Filter::NotMatching, then the filter will return true on items that do not match the filter. */ void setMatchRule( MatchRule rule ); /** @return The current match rule. */ MatchRule matchRule() const; private: + bool noName; int mCriteria; QString mName; QStringList mCategoryList; MatchRule mMatchRule; bool mEnabled; bool mInternal; }; #endif |