From de5f08d69c716f85cc92f20700cd24fb1ad41295 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 16 Jan 2005 14:10:42 +0000 Subject: added AB filter settings --- (limited to 'kaddressbook') diff --git a/kaddressbook/filter.cpp b/kaddressbook/filter.cpp index 39d2ae4..9cb4c2d 100644 --- a/kaddressbook/filter.cpp +++ b/kaddressbook/filter.cpp @@ -28,17 +28,20 @@ #include "kabprefs.h" #include "filter.h" +#include Filter::Filter() : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ), mInternal( false ) { + mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; } Filter::Filter( const QString &name ) : mName( name ), mMatchRule( Matching ), mEnabled( true ), mInternal( false ) { + mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; } Filter::~Filter() @@ -79,6 +82,23 @@ void Filter::apply( KABC::Addressee::List &addresseeList ) bool Filter::filterAddressee( const KABC::Addressee &a ) { + 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 @@ -120,6 +140,7 @@ void Filter::save( KConfig *config ) config->writeEntry( "Enabled", mEnabled ); config->writeEntry( "Categories", mCategoryList ); config->writeEntry( "MatchRule", (int)mMatchRule ); + config->writeEntry( "Criteria", (int)mCriteria ); } void Filter::restore( KConfig *config ) @@ -128,6 +149,7 @@ void Filter::restore( KConfig *config ) 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 ) diff --git a/kaddressbook/filter.h b/kaddressbook/filter.h index cf2c0a1..26870d7 100644 --- a/kaddressbook/filter.h +++ b/kaddressbook/filter.h @@ -38,7 +38,10 @@ */ class Filter { - public: + public: + enum { ShowPublic = 1, ShowPrivate = 2, ShowConfidential = 4}; + void setCriteria(int c) { mCriteria = c ;} + int criteria() const { return mCriteria;} typedef QValueList List; enum MatchRule { Matching = 0, NotMatching = 1 }; @@ -143,6 +146,7 @@ class Filter MatchRule matchRule() const; private: + int mCriteria; QString mName; QStringList mCategoryList; MatchRule mMatchRule; diff --git a/kaddressbook/filtereditdialog.cpp b/kaddressbook/filtereditdialog.cpp index 063585a..987f234 100644 --- a/kaddressbook/filtereditdialog.cpp +++ b/kaddressbook/filtereditdialog.cpp @@ -34,6 +34,7 @@ $Id$ #include #include #include +#include #include #include #include @@ -90,6 +91,12 @@ void FilterEditDialog::setFilter( const Filter &filter ) mMatchRuleGroup->setButton( 0 ); else mMatchRuleGroup->setButton( 1 ); + + int c = filter.criteria() ; + mPublic->setChecked(c &Filter::ShowPublic); + mPrivate->setChecked(c & Filter::ShowPrivate); + mConfidential->setChecked(c & Filter::ShowConfidential); + } Filter FilterEditDialog::filter() @@ -114,6 +121,12 @@ Filter FilterEditDialog::filter() else filter.setMatchRule( Filter::NotMatching ); + int c = 0; + if (mPublic->isChecked()) c |= Filter::ShowPublic; + if (mPrivate->isChecked()) c |= Filter::ShowPrivate; + if (mConfidential->isChecked()) c |= Filter::ShowConfidential; + filter.setCriteria( c ) ; + return filter; } @@ -143,23 +156,24 @@ void FilterEditDialog::initGUI() mCategoriesView->addColumn( i18n( "Categories" ) ); topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 ); - mMatchRuleGroup = new QButtonGroup( page ); + mMatchRuleGroup = new QHButtonGroup( i18n( "Category rule" ), page ); mMatchRuleGroup->setExclusive( true ); - - QBoxLayout *gbLayout = new QVBoxLayout( mMatchRuleGroup ); - gbLayout->setSpacing( KDialog::spacingHint() ); - gbLayout->setMargin( KDialog::marginHint() ); - - QRadioButton *radio = new QRadioButton( i18n( "Show only contacts matching\n the selected categories" ), mMatchRuleGroup ); + QRadioButton *radio = new QRadioButton( i18n( "Include categories" ), mMatchRuleGroup ); radio->setChecked( true ); - mMatchRuleGroup->insert( radio ); - gbLayout->addWidget( radio ); + //mMatchRuleGroup->insert( radio ); + radio = new QRadioButton( i18n( "Exclude categories" ), mMatchRuleGroup ); + //mMatchRuleGroup->insert( radio ); + topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 ); - radio = new QRadioButton( i18n( "Show all contacts except those\n matching the selected categories" ), mMatchRuleGroup ); - mMatchRuleGroup->insert( radio ); - gbLayout->addWidget( radio ); + QHButtonGroup * mMatchPPCGroup = new QHButtonGroup(i18n( "Include contacts, that are:" ), page ); + mPublic = new QCheckBox( i18n( "public" ), mMatchPPCGroup ); + mPrivate = new QCheckBox( i18n( "private" ), mMatchPPCGroup ); + mConfidential = new QCheckBox( i18n( "confidential" ), mMatchPPCGroup ); + mPublic->setChecked( true ); + mPrivate->setChecked( true ); + mConfidential->setChecked( true ); + topLayout->addMultiCellWidget( mMatchPPCGroup, 3, 3, 0, 1 ); - topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 ); } void FilterEditDialog::filterNameTextChanged( const QString &text ) diff --git a/kaddressbook/filtereditdialog.h b/kaddressbook/filtereditdialog.h index 4dd75e4..5a8bad1 100644 --- a/kaddressbook/filtereditdialog.h +++ b/kaddressbook/filtereditdialog.h @@ -36,12 +36,14 @@ class QString; class QToolButton; class QWidget; class QListBoxItem; +class QCheckBox; class KLineEdit; class KListBox; class KListView; #include +#include #include "filter.h" @@ -96,7 +98,10 @@ class FilterEditDialog : public KDialogBase KLineEdit *mNameEdit; KListView *mCategoriesView; - QButtonGroup *mMatchRuleGroup; + QHButtonGroup *mMatchRuleGroup; + QCheckBox *mPrivate; + QCheckBox *mPublic; + QCheckBox *mConfidential; QPushButton *mEditButton; QPushButton *mRemoveButton; }; -- cgit v0.9.0.2