24 #include <tqbuttongroup.h>
28 #include <tqpushbutton.h>
29 #include <tqradiobutton.h>
32 #include <tqtoolbutton.h>
33 #include <tqtooltip.h>
36 #include <tdeapplication.h>
37 #include <kbuttonbox.h>
39 #include <kiconloader.h>
40 #include <klineedit.h>
41 #include <tdelistbox.h>
42 #include <tdelistview.h>
43 #include <tdelocale.h>
46 #include "filtereditdialog.h"
48 FilterEditDialog::FilterEditDialog( TQWidget *parent,
const char *name )
49 : KDialogBase( Plain, i18n(
"Edit Address Book Filter" ),
50 Help | Ok | Cancel, Ok, parent, name, false, true )
54 const TQStringList cats = KABPrefs::instance()->customCategories();
56 TQStringList::ConstIterator it;
57 for ( it = cats.begin(); it != cats.end(); ++it )
58 mCategoriesView->insertItem(
new TQCheckListItem( mCategoriesView, *it, TQCheckListItem::CheckBox ) );
60 filterNameTextChanged( mNameEdit->text() );
63 FilterEditDialog::~FilterEditDialog()
67 void FilterEditDialog::setFilter(
const Filter &filter )
69 mNameEdit->setText( filter.
name() );
72 TQListViewItem *item = mCategoriesView->firstChild();
74 if ( categories.contains( item->text( 0 ) ) ) {
75 TQCheckListItem *checkItem =
static_cast<TQCheckListItem*
>( item );
76 checkItem->setOn(
true );
79 item = item->nextSibling();
82 if ( filter.
matchRule() == Filter::Matching )
83 mMatchRuleGroup->setButton( 0 );
85 mMatchRuleGroup->setButton( 1 );
88 Filter FilterEditDialog::filter()
92 filter.
setName( mNameEdit->text() );
94 TQStringList categories;
95 TQListViewItem *item = mCategoriesView->firstChild();
97 TQCheckListItem *checkItem =
static_cast<TQCheckListItem*
>( item );
98 if ( checkItem->isOn() )
99 categories.append( item->text( 0 ) );
101 item = item->nextSibling();
105 if ( mMatchRuleGroup->find( 0 )->isOn() )
113 void FilterEditDialog::initGUI()
117 TQWidget *page = plainPage();
120 TQGridLayout *topLayout =
new TQGridLayout( page, 3, 2, 0, spacingHint() );
122 label =
new TQLabel( i18n(
"Name:" ), page );
123 mNameEdit =
new KLineEdit( page );
124 mNameEdit->setFocus();
125 topLayout->addWidget( label, 0, 0 );
126 topLayout->addWidget( mNameEdit, 0, 1 );
127 connect( mNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
128 TQ_SLOT( filterNameTextChanged(
const TQString&) ) );
130 mCategoriesView =
new TDEListView( page );
131 mCategoriesView->addColumn( i18n(
"Category" ) );
132 mCategoriesView->setFullWidth(
true );
133 topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 );
135 mMatchRuleGroup =
new TQButtonGroup( page );
136 mMatchRuleGroup->setExclusive(
true );
138 TQBoxLayout *gbLayout =
new TQVBoxLayout( mMatchRuleGroup );
139 gbLayout->setSpacing( KDialog::spacingHint() );
140 gbLayout->setMargin( KDialog::marginHint() );
142 TQRadioButton *radio =
new TQRadioButton( i18n(
"Show only contacts matching the selected categories" ), mMatchRuleGroup );
143 radio->setChecked(
true );
144 mMatchRuleGroup->insert( radio );
145 gbLayout->addWidget( radio );
147 radio =
new TQRadioButton( i18n(
"Show all contacts except those matching the selected categories" ), mMatchRuleGroup );
148 mMatchRuleGroup->insert( radio );
149 gbLayout->addWidget( radio );
151 topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 );
154 void FilterEditDialog::filterNameTextChanged(
const TQString &text )
156 enableButtonOK( !text.isEmpty() );
159 void FilterEditDialog::slotHelp()
161 kapp->invokeHelp(
"using-filters" );
164 FilterDialog::FilterDialog( TQWidget *parent,
const char *name )
165 : KDialogBase( Plain, i18n(
"Edit Address Book Filters" ),
166 Ok | Cancel, Ok, parent, name, false, true )
171 FilterDialog::~FilterDialog()
175 void FilterDialog::setFilters(
const Filter::List &list )
178 mInternalFilterList.clear();
180 Filter::List::ConstIterator it;
181 for ( it = list.begin(); it != list.end(); ++it ) {
182 if ( (*it).isInternal() )
183 mInternalFilterList.append( *it );
185 mFilterList.append( *it );
191 Filter::List FilterDialog::filters()
const
193 Filter::List list = mFilterList + mInternalFilterList;
197 void FilterDialog::add()
199 FilterEditDialog dlg(
this );
202 mFilterList.append( dlg.filter() );
206 mFilterListBox->setCurrentItem( mFilterListBox->count() - 1 );
209 void FilterDialog::edit()
211 FilterEditDialog dlg(
this );
213 uint pos = mFilterListBox->currentItem();
215 dlg.setFilter( mFilterList[ pos ] );
218 mFilterList.remove( mFilterList.at( pos ) );
219 mFilterList.insert( mFilterList.at( pos ), dlg.filter() );
224 mFilterListBox->setCurrentItem( pos );
227 void FilterDialog::remove()
229 mFilterList.remove( mFilterList.at( mFilterListBox->currentItem() ) );
231 selectionChanged( 0 );
236 void FilterDialog::refresh()
238 mFilterListBox->clear();
240 Filter::List::ConstIterator it;
241 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
242 mFilterListBox->insertItem( (*it).name() );
245 void FilterDialog::selectionChanged( TQListBoxItem *item )
247 bool state = ( item != 0 );
249 mEditButton->setEnabled( state );
250 mRemoveButton->setEnabled( state );
253 void FilterDialog::initGUI()
257 TQWidget *page = plainPage();
259 TQGridLayout *topLayout =
new TQGridLayout( page, 1, 2, 0, spacingHint() );
261 mFilterListBox =
new TDEListBox( page );
262 topLayout->addWidget( mFilterListBox, 0, 0 );
263 connect( mFilterListBox, TQ_SIGNAL( selectionChanged( TQListBoxItem * ) ),
264 TQ_SLOT( selectionChanged( TQListBoxItem * ) ) );
265 connect( mFilterListBox, TQ_SIGNAL( doubleClicked ( TQListBoxItem * ) ),
268 KButtonBox *buttonBox =
new KButtonBox( page, TQt::Vertical );
269 buttonBox->addButton( i18n(
"&Add..." ),
this, TQ_SLOT( add() ) );
270 mEditButton = buttonBox->addButton( i18n(
"&Edit..." ),
this, TQ_SLOT( edit() ) );
271 mEditButton->setEnabled(
false );
272 mRemoveButton = buttonBox->addButton( i18n(
"&Remove" ),
this, TQ_SLOT( remove() ) );
273 mRemoveButton->setEnabled(
false );
276 topLayout->addWidget( buttonBox, 0, 1 );
279 #include "filtereditdialog.moc"
Filter for AddressBook related objects (Addressees)
MatchRule matchRule() const
void setName(const TQString &name)
Set the name of the filter.
const TQStringList & categories() const
void setCategories(const TQStringList &list)
Set the list of categories.
const TQString & name() const
void setMatchRule(MatchRule rule)
Sets the filter rule.