kaddressbook

selectionpage.cpp
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
4 Tobias Koenig <tokoe@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <kdialog.h>
26#include <tdelocale.h>
27
28#include <tqbuttongroup.h>
29#include <tqcombobox.h>
30#include <tqheader.h>
31#include <tqlabel.h>
32#include <tqlayout.h>
33#include <tqlistview.h>
34#include <tqpushbutton.h>
35#include <tqradiobutton.h>
36#include <tqstringlist.h>
37#include <tqwhatsthis.h>
38
39#include "selectionpage.h"
40
41SelectionPage::SelectionPage( TQWidget* parent, const char* name )
42 : TQWidget( parent, name )
43{
44 setCaption( i18n( "Choose Which Contacts to Print" ) );
45
46 TQVBoxLayout *topLayout = new TQVBoxLayout( this, KDialog::marginHint(),
47 KDialog::spacingHint() );
48
49 TQLabel *label = new TQLabel( i18n( "Which contacts do you want to print?" ), this );
50 topLayout->addWidget( label );
51
52 mButtonGroup = new TQButtonGroup( this );
53 mButtonGroup->setFrameShape( TQButtonGroup::NoFrame );
54 mButtonGroup->setColumnLayout( 0, TQt::Vertical );
55 mButtonGroup->layout()->setSpacing( KDialog::spacingHint() );
56 mButtonGroup->layout()->setMargin( KDialog::marginHint() );
57
58 TQGridLayout *groupLayout = new TQGridLayout( mButtonGroup->layout() );
59 groupLayout->setAlignment( TQt::AlignTop );
60
61 mUseWholeBook = new TQRadioButton( i18n( "&All contacts" ), mButtonGroup );
62 mUseWholeBook->setChecked( true );
63 TQWhatsThis::add( mUseWholeBook, i18n( "Print the entire address book" ) );
64 groupLayout->addWidget( mUseWholeBook, 0, 0 );
65
66 mUseSelection = new TQRadioButton( i18n( "&Selected contacts" ), mButtonGroup );
67 TQWhatsThis::add( mUseSelection, i18n( "Only print contacts selected in KAddressBook.\n"
68 "This option is disabled if no contacts are selected." ) );
69 groupLayout->addWidget( mUseSelection, 1, 0 );
70
71 mUseFilters = new TQRadioButton( i18n( "Contacts matching &filter" ), mButtonGroup );
72 TQWhatsThis::add( mUseFilters, i18n( "Only print contacts matching the selected filter.\n"
73 "This option is disabled if you have not defined any filters." ) );
74 groupLayout->addWidget( mUseFilters, 2, 0 );
75
76 mUseCategories = new TQRadioButton( i18n( "Category &members" ), mButtonGroup );
77 TQWhatsThis::add( mUseCategories, i18n( "Only print contacts who are members of a category that is checked on the list to the left.\n"
78 "This option is disabled if you have no categories." ) );
79 groupLayout->addWidget( mUseCategories, 3, 0, TQt::AlignTop );
80
81 mFiltersCombo = new TQComboBox( false, mButtonGroup );
82 TQWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to print." ) );
83 groupLayout->addWidget( mFiltersCombo, 2, 1 );
84
85 mCategoriesView = new TQListView( mButtonGroup );
86 mCategoriesView->addColumn( "" );
87 mCategoriesView->header()->hide();
88 TQWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to print." ) );
89 groupLayout->addWidget( mCategoriesView, 3, 1 );
90
91 topLayout->addWidget( mButtonGroup );
92
93 connect( mFiltersCombo, TQ_SIGNAL( activated(int) ), TQ_SLOT( filterChanged(int) ) );
94 connect( mCategoriesView, TQ_SIGNAL( clicked(TQListViewItem*) ), TQ_SLOT( categoryClicked(TQListViewItem*) ) );
95}
96
97SelectionPage::~SelectionPage()
98{
99}
100
101void SelectionPage::setFilters( const TQStringList& filters )
102{
103 mFiltersCombo->clear();
104 mFiltersCombo->insertStringList( filters );
105
106 mUseFilters->setEnabled( filters.count() > 0 );
107}
108
109TQString SelectionPage::filter() const
110{
111 return mFiltersCombo->currentText();
112}
113
114bool SelectionPage::useFilters() const
115{
116 return mUseFilters->isChecked();
117}
118
119void SelectionPage::setCategories( const TQStringList& list )
120{
121 TQStringList::ConstIterator it;
122 for ( it = list.begin(); it != list.end(); ++it )
123 new TQCheckListItem( mCategoriesView, *it, TQCheckListItem::CheckBox );
124
125 mUseCategories->setEnabled( list.count() > 0 );
126}
127
128TQStringList SelectionPage::categories() const
129{
130 TQStringList list;
131
132 TQListViewItemIterator it( mCategoriesView );
133 for ( ; it.current(); ++it ) {
134 TQCheckListItem *qcli = static_cast<TQCheckListItem*>(it.current());
135 if ( qcli->isOn() )
136 list.append( it.current()->text( 0 ) );
137 }
138
139 return list;
140}
141
142bool SelectionPage::useCategories()
143{
144 return mUseCategories->isChecked();
145}
146
147void SelectionPage::setUseSelection( bool value )
148{
149 mUseSelection->setEnabled( value );
150}
151
152bool SelectionPage::useSelection() const
153{
154 return mUseSelection->isChecked();
155}
156
157void SelectionPage::filterChanged( int )
158{
159 mUseFilters->setChecked( true );
160}
161
162void SelectionPage::categoryClicked( TQListViewItem *i )
163{
164 TQCheckListItem *qcli = static_cast<TQCheckListItem*>( i );
165 if ( i && qcli->isOn() )
166 mUseCategories->setChecked( true );
167}
168
169#include "selectionpage.moc"