viewconfigurefilterpage.cpp
00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #include <tqbuttongroup.h> 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 #include <tqradiobutton.h> 00028 00029 #include <tdeconfig.h> 00030 #include <kcombobox.h> 00031 #include <kdialog.h> 00032 #include <tdelocale.h> 00033 00034 #include "viewconfigurefilterpage.h" 00035 #include "filter.h" 00036 00037 ViewConfigureFilterPage::ViewConfigureFilterPage( TQWidget *parent, 00038 const char *name ) 00039 : TQWidget( parent, name ) 00040 { 00041 TQBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() ); 00042 00043 mFilterGroup = new TQButtonGroup(); 00044 connect( mFilterGroup, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( buttonClicked( int ) ) ); 00045 00046 TQLabel *label = new TQLabel( i18n( "The default filter will be activated whenever" 00047 " this view is displayed. This feature allows you to configure views that only" 00048 " interact with certain types of information based on the filter. Once the view" 00049 " is activated, the filter can be changed at anytime." ), this ); 00050 label->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak ); 00051 topLayout->addWidget( label ); 00052 00053 TQWidget *spacer = new TQWidget( this ); 00054 spacer->setMinimumHeight( 5 ); 00055 topLayout->addWidget( spacer ); 00056 00057 TQRadioButton *button = new TQRadioButton( i18n( "No default filter" ), this ); 00058 mFilterGroup->insert( button ); 00059 topLayout->addWidget( button ); 00060 00061 button = new TQRadioButton( i18n( "Use last active filter" ), this ); 00062 mFilterGroup->insert( button ); 00063 topLayout->addWidget( button ); 00064 00065 TQBoxLayout *comboLayout = new TQHBoxLayout(); 00066 topLayout->addLayout( comboLayout ); 00067 button = new TQRadioButton( i18n( "Use filter:" ), this ); 00068 mFilterGroup->insert( button ); 00069 comboLayout->addWidget( button ); 00070 00071 mFilterCombo = new KComboBox( this ); 00072 comboLayout->addWidget( mFilterCombo ); 00073 00074 topLayout->addStretch( 100 ); 00075 } 00076 00077 ViewConfigureFilterPage::~ViewConfigureFilterPage() 00078 { 00079 delete mFilterGroup; 00080 } 00081 00082 void ViewConfigureFilterPage::restoreSettings( TDEConfig *config ) 00083 { 00084 mFilterCombo->clear(); 00085 00086 // Load the filter combo 00087 const Filter::List list = Filter::restore( config, "Filter" ); 00088 Filter::List::ConstIterator it; 00089 for ( it = list.begin(); it != list.end(); ++it ) 00090 mFilterCombo->insertItem( (*it).name() ); 00091 00092 int id = config->readNumEntry( "DefaultFilterType", 1 ); 00093 mFilterGroup->setButton( id ); 00094 buttonClicked( id ); 00095 00096 if ( id == 2 ) // has default filter 00097 mFilterCombo->setCurrentText( config->readEntry( "DefaultFilterName" ) ); 00098 } 00099 00100 void ViewConfigureFilterPage::saveSettings( TDEConfig *config ) 00101 { 00102 config->writeEntry( "DefaultFilterName", mFilterCombo->currentText() ); 00103 config->writeEntry( "DefaultFilterType", mFilterGroup->id( mFilterGroup->selected() ) ); 00104 } 00105 00106 void ViewConfigureFilterPage::buttonClicked( int id ) 00107 { 00108 mFilterCombo->setEnabled( id == 2 ); 00109 } 00110 00111 #include "viewconfigurefilterpage.moc"