summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-04-04 12:59:35 (UTC)
committer zautrix <zautrix>2005-04-04 12:59:35 (UTC)
commit919f1060a9ef41e6c865f28132cf9e82c3f67409 (patch) (side-by-side diff)
tree8e7c1283071ff2af2897ccf1c7e51e8b2b2bfadc
parent23db4aa99cb7a5feb540b6be578efaee8ec6ef80 (diff)
downloadkdepimpi-919f1060a9ef41e6c865f28132cf9e82c3f67409.zip
kdepimpi-919f1060a9ef41e6c865f28132cf9e82c3f67409.tar.gz
kdepimpi-919f1060a9ef41e6c865f28132cf9e82c3f67409.tar.bz2
kapi filter fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/filter.cpp24
-rw-r--r--kaddressbook/filter.h1
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
@@ -1,228 +1,238 @@
/*
This file is part of KAddressBook.
Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
{
return mEnabled;
}
void Filter::setCategories( const QStringList &list )
{
mCategoryList = 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 )
config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) );
*/
}
int index = 0;
Filter::List::Iterator iter;
for ( iter = list.begin(); iter != list.end(); ++iter ) {
if ( !(*iter).mInternal ) {
KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) );
(*iter).save( config );
index++;
}
}
KConfigGroupSaver s( config, baseGroup );
config->writeEntry( "Count", index );
}
Filter::List Filter::restore( KConfig *config, QString baseGroup )
{
Filter::List list;
int count = 0;
Filter f;
{
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;
}
Filter::MatchRule Filter::matchRule() const
{
return mMatchRule;
}
diff --git a/kaddressbook/filter.h b/kaddressbook/filter.h
index 93f1352..f4ae123 100644
--- a/kaddressbook/filter.h
+++ b/kaddressbook/filter.h
@@ -1,157 +1,158 @@
/*
This file is part of KAddressBook.
Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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.
*/
#ifndef FILTER_H
#define FILTER_H
#include <qstring.h>
#include <qstringlist.h>
#include <qvaluelist.h>
#include <kabc/addressee.h>
#include <kconfig.h>
/**
Filter for AddressBook related objects (Addressees)
@todo This class should be switched to use shared data.
*/
class Filter
{
public:
enum { ShowPublic = 1, ShowPrivate = 2, ShowConfidential = 4 };
void setCriteria(int c) { mCriteria = c ;}
int criteria() const { return mCriteria;}
typedef QValueList<Filter> List;
enum MatchRule { Matching = 0, NotMatching = 1 };
Filter();
Filter( const QString& name );
~Filter();
/**
Set the name of the filter.
*/
void setName( const QString &name );
/**
@return The name of the filter.
*/
const QString &name() const;
/**
@return Whether the filter is an internal one.
*/
bool isInternal() const;
/**
Apply the filter to the addressee list. All addressees not passing
the filter criterias will be removed from the list.
If the MatchRule is NotMatch, then all the addressees matching the
filter will be removed from the list.
*/
void apply( KABC::Addressee::List &addresseeList );
/**
Apply the filter to the addressee.
@return True if the addressee passes the criteria, false otherwise.
The return values are opposite if the MatchRule is NotMatch.
*/
bool filterAddressee( const KABC::Addressee &a );
/**
Enable or disable the filter
*/
void setEnabled( bool on );
/**
@return True if this filter is enabled, false otherwise.
*/
bool isEnabled() const;
/**
Set the list of categories. This list is used to filter addressees.
*/
void setCategories( const QStringList &list );
/**
@return The list of categories.
*/
const QStringList &categories() const;
/**
Saves the filter to the config file. The group should already be set.
*/
void save( KConfig *config );
/**
Loads the filter from the config file. The group should already be set.
*/
void restore( KConfig *config );
/**
Saves a list of filters to the config file.
@param config The config file to use
@param baseGroup The base groupname to use. The number of filters
will be written to this group, then a _1, _2, etc
will be append for each filter saved.
@param list The list of filters to be saved.
*/
static void save( KConfig *config, QString baseGroup, Filter::List &list );
/**
Restores a list of filters from a config file.
@param config The config file to read from.
@param baseGroup The base group name to be used to find the filters
@return The list of filters.
*/
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