kaddressbook Library API Documentation

configureviewfilterpage.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., 675 Mass Ave, Cambridge, MA 02139, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include <qbuttongroup.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qradiobutton.h>
00028 
00029 #include <kconfig.h>
00030 #include <kcombobox.h>
00031 #include <kdialog.h>
00032 #include <klocale.h>
00033 
00034 #include "configureviewfilterpage.h"
00035 #include "filter.h"
00036 
00037 ConfigureViewFilterPage::ConfigureViewFilterPage( QWidget *parent, const char *name )
00038   : QWidget( parent, name )
00039 {
00040   QBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
00041   
00042   mFilterGroup = new QButtonGroup();
00043   connect( mFilterGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
00044   
00045   QLabel *label = new QLabel( i18n( "The default filter will be activated whenever"
00046   " this view is displayed. This feature allows you to configure views that only"
00047   " interact with certain types of information based on the filter. Once the view"
00048   " is activated, the filter can be changed at anytime." ), this );
00049   label->setAlignment( Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak );
00050   topLayout->addWidget( label );
00051   
00052   QWidget *spacer = new QWidget( this );
00053   spacer->setMinimumHeight( 5 );
00054   topLayout->addWidget( spacer );
00055   
00056   QRadioButton *button = new QRadioButton( i18n( "No default filter" ), this );
00057   mFilterGroup->insert( button );
00058   topLayout->addWidget( button );
00059   
00060   button = new QRadioButton( i18n( "Use last active filter" ), this );
00061   mFilterGroup->insert( button );
00062   topLayout->addWidget( button );
00063   
00064   QBoxLayout *comboLayout = new QHBoxLayout();
00065   topLayout->addLayout( comboLayout );
00066   button = new QRadioButton( i18n( "Use filter:" ), this );
00067   mFilterGroup->insert( button );
00068   comboLayout->addWidget( button );
00069   
00070   mFilterCombo = new KComboBox( this );
00071   comboLayout->addWidget( mFilterCombo );
00072 }
00073 
00074 ConfigureViewFilterPage::~ConfigureViewFilterPage()
00075 {
00076   delete mFilterGroup;
00077 }
00078     
00079 void ConfigureViewFilterPage::readConfig( KConfig *config )
00080 {
00081   mFilterCombo->clear();
00082   
00083   // Load the filter combo
00084   Filter::List list = Filter::restore( config, "Filter" );
00085   Filter::List::Iterator it;
00086   for ( it = list.begin(); it != list.end(); ++it )
00087     mFilterCombo->insertItem( (*it).name() );
00088     
00089   int id = config->readNumEntry( "DefaultFilterType", 1 );
00090   mFilterGroup->setButton( id );
00091   buttonClicked( id );
00092 
00093   if ( id == 2 ) // has default filter
00094     mFilterCombo->setCurrentText( config->readEntry( "DefaultFilterName" ) );
00095 }
00096 
00097 void ConfigureViewFilterPage::writeConfig( KConfig *config )
00098 {
00099   config->writeEntry( "DefaultFilterName", mFilterCombo->currentText() );
00100   config->writeEntry( "DefaultFilterType", mFilterGroup->id( mFilterGroup->selected() ) );
00101 }
00102     
00103 void ConfigureViewFilterPage::buttonClicked( int id )
00104 {
00105   mFilterCombo->setEnabled( id == 2 );
00106 }
00107 
00108 #include "configureviewfilterpage.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:36 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001