kaddressbook

viewconfigurefilterpage.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqbuttongroup.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqradiobutton.h>
28 
29 #include <tdeconfig.h>
30 #include <kcombobox.h>
31 #include <kdialog.h>
32 #include <tdelocale.h>
33 
34 #include "viewconfigurefilterpage.h"
35 #include "filter.h"
36 
37 ViewConfigureFilterPage::ViewConfigureFilterPage( TQWidget *parent,
38  const char *name )
39  : TQWidget( parent, name )
40 {
41  TQBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
42 
43  mFilterGroup = new TQButtonGroup();
44  connect( mFilterGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( buttonClicked( int ) ) );
45 
46  TQLabel *label = new TQLabel( i18n( "The default filter will be activated whenever"
47  " this view is displayed. This feature allows you to configure views that only"
48  " interact with certain types of information based on the filter. Once the view"
49  " is activated, the filter can be changed at anytime." ), this );
50  label->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
51  topLayout->addWidget( label );
52 
53  TQWidget *spacer = new TQWidget( this );
54  spacer->setMinimumHeight( 5 );
55  topLayout->addWidget( spacer );
56 
57  TQRadioButton *button = new TQRadioButton( i18n( "No default filter" ), this );
58  mFilterGroup->insert( button );
59  topLayout->addWidget( button );
60 
61  button = new TQRadioButton( i18n( "Use last active filter" ), this );
62  mFilterGroup->insert( button );
63  topLayout->addWidget( button );
64 
65  TQBoxLayout *comboLayout = new TQHBoxLayout();
66  topLayout->addLayout( comboLayout );
67  button = new TQRadioButton( i18n( "Use filter:" ), this );
68  mFilterGroup->insert( button );
69  comboLayout->addWidget( button );
70 
71  mFilterCombo = new KComboBox( this );
72  comboLayout->addWidget( mFilterCombo );
73 
74  topLayout->addStretch( 100 );
75 }
76 
77 ViewConfigureFilterPage::~ViewConfigureFilterPage()
78 {
79  delete mFilterGroup;
80 }
81 
82 void ViewConfigureFilterPage::restoreSettings( TDEConfig *config )
83 {
84  mFilterCombo->clear();
85 
86  // Load the filter combo
87  const Filter::List list = Filter::restore( config, "Filter" );
88  Filter::List::ConstIterator it;
89  for ( it = list.begin(); it != list.end(); ++it )
90  mFilterCombo->insertItem( (*it).name() );
91 
92  int id = config->readNumEntry( "DefaultFilterType", 1 );
93  mFilterGroup->setButton( id );
94  buttonClicked( id );
95 
96  if ( id == 2 ) // has default filter
97  mFilterCombo->setCurrentText( config->readEntry( "DefaultFilterName" ) );
98 }
99 
100 void ViewConfigureFilterPage::saveSettings( TDEConfig *config )
101 {
102  config->writeEntry( "DefaultFilterName", mFilterCombo->currentText() );
103  config->writeEntry( "DefaultFilterType", mFilterGroup->id( mFilterGroup->selected() ) );
104 }
105 
106 void ViewConfigureFilterPage::buttonClicked( int id )
107 {
108  mFilterCombo->setEnabled( id == 2 );
109 }
110 
111 #include "viewconfigurefilterpage.moc"
void restore(TDEConfig *config)
Loads the filter from the config file.
Definition: filter.cpp:132