summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewconfigurefilterpage.cpp
Unidiff
Diffstat (limited to 'kaddressbook/viewconfigurefilterpage.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/viewconfigurefilterpage.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/kaddressbook/viewconfigurefilterpage.cpp b/kaddressbook/viewconfigurefilterpage.cpp
new file mode 100644
index 0000000..b085a5e
--- a/dev/null
+++ b/kaddressbook/viewconfigurefilterpage.cpp
@@ -0,0 +1,137 @@
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#ifndef KAB_EMBEDDED
25#include <kcombobox.h>
26#else //KAB_EMBEDDED
27#include <qcombobox.h>
28#endif //KAB_EMBEDDED
29
30#include <qbuttongroup.h>
31#include <qlabel.h>
32#include <qlayout.h>
33#include <qradiobutton.h>
34
35#include <kconfig.h>
36#include <kdialog.h>
37#include <klocale.h>
38
39#include "filter.h"
40
41#include "viewconfigurefilterpage.h"
42
43ViewConfigureFilterPage::ViewConfigureFilterPage( QWidget *parent,
44 const char *name )
45 : QWidget( parent, name )
46{
47 QBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
48
49 mFilterGroup = new QButtonGroup();
50 connect( mFilterGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
51
52 QLabel *label = new QLabel( i18n( "The default filter will be activated whenever"
53 " this view is displayed. This feature allows you to configure views that only"
54 " interact with certain types of information based on the filter. Once the view"
55 " is activated, the filter can be changed at anytime." ), this );
56 label->setAlignment( Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak );
57 topLayout->addWidget( label );
58
59 QWidget *spacer = new QWidget( this );
60 spacer->setMinimumHeight( 5 );
61 topLayout->addWidget( spacer );
62
63 QRadioButton *button = new QRadioButton( i18n( "No default filter" ), this );
64 mFilterGroup->insert( button );
65 topLayout->addWidget( button );
66
67 button = new QRadioButton( i18n( "Use last active filter" ), this );
68 mFilterGroup->insert( button );
69 topLayout->addWidget( button );
70
71 QBoxLayout *comboLayout = new QHBoxLayout();
72 topLayout->addLayout( comboLayout );
73 button = new QRadioButton( i18n( "Use filter:" ), this );
74 mFilterGroup->insert( button );
75 comboLayout->addWidget( button );
76
77#ifndef KAB_EMBEDDED
78 mFilterCombo = new KComboBox( this );
79#else //KAB_EMBEDDED
80 mFilterCombo = new QComboBox( this );
81#endif //KAB_EMBEDDED
82
83 comboLayout->addWidget( mFilterCombo );
84}
85
86ViewConfigureFilterPage::~ViewConfigureFilterPage()
87{
88 delete mFilterGroup;
89}
90
91void ViewConfigureFilterPage::restoreSettings( KConfig *config )
92{
93 mFilterCombo->clear();
94
95//US I had to adjust the whole method in order to work with QComboBoxes
96// in case of the Platformindependent version
97 QString defaultfiltername = config->readEntry( "DefaultFilterName" );
98
99 int id = config->readNumEntry( "DefaultFilterType", 1 );
100 mFilterGroup->setButton( id );
101 buttonClicked( id );
102
103 // Load the filter combo
104 Filter::List list = Filter::restore( config, "Filter" );
105 Filter::List::Iterator it;
106 for ( it = list.begin(); it != list.end(); ++it )
107 {
108 mFilterCombo->insertItem( (*it).name() );
109
110 if ( id == 2 && (*it).name() == defaultfiltername) // has default filter
111 {
112 mFilterCombo->insertItem( (*it).name(), 0);
113 }
114 else
115 {
116 mFilterCombo->insertItem( (*it).name() );
117 }
118
119 }
120
121
122}
123
124void ViewConfigureFilterPage::saveSettings( KConfig *config )
125{
126 config->writeEntry( "DefaultFilterName", mFilterCombo->currentText() );
127 config->writeEntry( "DefaultFilterType", mFilterGroup->id( mFilterGroup->selected() ) );
128}
129
130void ViewConfigureFilterPage::buttonClicked( int id )
131{
132 mFilterCombo->setEnabled( id == 2 );
133}
134
135#ifndef KAB_EMBEDDED
136#include "viewconfigurefilterpage.moc"
137#endif //KAB_EMBEDDED