korganizer Library API Documentation

filtereditdialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qlayout.h>
00026 #include <qpushbutton.h>
00027 #include <qcombobox.h>
00028 #include <qcheckbox.h>
00029 #include <qradiobutton.h>
00030 #include <qlistbox.h>
00031 
00032 #include <kdebug.h>
00033 #include <klocale.h>
00034 #include <kinputdialog.h>
00035 #include <kmessagebox.h>
00036 
00037 #include <libkcal/calfilter.h>
00038 #include <libkdepim/categoryselectdialog.h>
00039 
00040 #include "koprefs.h"
00041 #include "filteredit_base.h"
00042 
00043 #include "filtereditdialog.h"
00044 #include "filtereditdialog.moc"
00045 
00046 // TODO: Make dialog work on a copy of the filters objects.
00047 
00048 FilterEditDialog::FilterEditDialog( QPtrList<CalFilter> *filters,
00049                                     QWidget *parent, const char *name)
00050   : KDialogBase( parent, name, false, i18n("Edit Calendar Filters"),
00051                  Ok | Apply | Cancel ),
00052     mCategorySelectDialog( 0 )
00053 {
00054   mFilters = filters;
00055 
00056   QWidget *mainWidget = new QWidget( this );
00057   setMainWidget( mainWidget );
00058 
00059   mSelectionCombo = new QComboBox( mainWidget );
00060   connect( mSelectionCombo, SIGNAL( activated( int ) ),
00061            SLOT( filterSelected() ) );
00062 
00063   QPushButton *addButton = new QPushButton( i18n("Add Filter..."), mainWidget );
00064   connect( addButton, SIGNAL( clicked() ), SLOT( slotAdd() ) );
00065 
00066   mRemoveButton = new QPushButton( i18n("Remove"), mainWidget );
00067   connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotRemove() ) );
00068 
00069   mEditor = new FilterEdit_base( mainWidget );
00070 
00071   QGridLayout *topLayout = new QGridLayout( mainWidget, 2, 2 );
00072   topLayout->setSpacing( spacingHint() );
00073   topLayout->addWidget( mSelectionCombo, 0, 0 );
00074   topLayout->addWidget( addButton, 0, 1 );
00075   topLayout->addWidget( mRemoveButton, 0, 2 );
00076   topLayout->addMultiCellWidget( mEditor, 1, 1, 0, 2 );
00077 
00078   connect( mEditor->mCatEditButton, SIGNAL( clicked() ),
00079            SLOT( editCategorySelection() ) );
00080 
00081   // Clicking cancel exits the dialog without saving
00082   connect( this, SIGNAL( cancelClicked() ), SLOT( reject() ) );
00083 
00084   updateFilterList();
00085 }
00086 
00087 FilterEditDialog::~FilterEditDialog()
00088 {
00089 }
00090 
00091 void FilterEditDialog::updateFilterList()
00092 {
00093   mSelectionCombo->clear();
00094 
00095   CalFilter *filter = mFilters->first();
00096 
00097   if ( !filter ) {
00098     enableButtonOK( false );
00099     enableButtonApply( false );
00100   } else {
00101     while( filter ) {
00102       mSelectionCombo->insertItem( filter->name() );
00103       filter = mFilters->next();
00104     }
00105 
00106     CalFilter *f = mFilters->at( mSelectionCombo->currentItem() );
00107     if ( f ) readFilter( f );
00108 
00109     enableButtonOK( true );
00110     enableButtonApply( true );
00111   }
00112 
00113   mRemoveButton->setEnabled( mFilters->count() > 1 );
00114 }
00115 
00116 void FilterEditDialog::updateCategoryConfig()
00117 {
00118   if ( mCategorySelectDialog ) mCategorySelectDialog->updateCategoryConfig();
00119 }
00120 
00121 void FilterEditDialog::slotDefault()
00122 {
00123 }
00124 
00125 void FilterEditDialog::slotApply()
00126 {
00127   CalFilter *f = mFilters->at( mSelectionCombo->currentItem() );
00128   writeFilter( f );
00129   emit filterChanged();
00130 }
00131 
00132 void FilterEditDialog::slotOk()
00133 {
00134   CalFilter *f = mFilters->at( mSelectionCombo->currentItem() );
00135   writeFilter( f );
00136   emit filterChanged();
00137   accept();
00138 }
00139 
00140 void FilterEditDialog::slotAdd()
00141 {
00142   QString txt = KInputDialog::getText( i18n("Add Filter"),
00143                                        i18n("Enter filter name:"),
00144                                        QString::null, 0, this );
00145   if ( !txt.isEmpty() ) {
00146     mFilters->append( new CalFilter( txt ) );
00147     updateFilterList();
00148   }
00149 }
00150 
00151 void FilterEditDialog::slotRemove()
00152 {
00153   int currentItem = mSelectionCombo->currentItem();
00154   if ( currentItem < 0 ) return;
00155 
00156   // We need at least a default filter object.
00157   if ( mFilters->count() <= 1 ) return;
00158 
00159   int result = KMessageBox::warningContinueCancel( this,
00160      i18n("This item will be permanently deleted."), i18n("Delete Confirmation"), KGuiItem(i18n("Delete"),"editdelete") );
00161 
00162   if ( result != KMessageBox::Continue ) {
00163     return;
00164   }
00165 
00166   mFilters->remove( currentItem );
00167   updateFilterList();
00168   emit filterChanged();
00169 }
00170 
00171 void FilterEditDialog::editCategorySelection()
00172 {
00173   if ( !mCategorySelectDialog ) {
00174     mCategorySelectDialog = new KPIM::CategorySelectDialog(
00175         KOPrefs::instance(), this, "filterCatSelect" );
00176     mCategorySelectDialog->setSelected( mCategories );
00177     connect( mCategorySelectDialog,
00178              SIGNAL( categoriesSelected( const QStringList & ) ),
00179              SLOT( updateCategorySelection( const QStringList & ) ) );
00180     connect( mCategorySelectDialog, SIGNAL( editCategories() ),
00181              SIGNAL( editCategories() ) );
00182   }
00183 
00184   mCategorySelectDialog->show();
00185 }
00186 
00187 void FilterEditDialog::updateCategorySelection( const QStringList &categories )
00188 {
00189   mCategories = categories;
00190 
00191   mEditor->mCatList->clear();
00192   mEditor->mCatList->insertStringList( mCategories );
00193 }
00194 
00195 void FilterEditDialog::filterSelected()
00196 {
00197   CalFilter *f = mFilters->at( mSelectionCombo->currentItem() );
00198   kdDebug(5850) << "Selected filter " << f->name() << endl;
00199   if ( f ) readFilter( f );
00200 }
00201 
00202 void FilterEditDialog::readFilter( CalFilter *filter )
00203 {
00204   int c = filter->criteria();
00205 
00206   mEditor->mCompletedCheck->setChecked( c & CalFilter::HideCompleted );
00207   mEditor->mRecurringCheck->setChecked( c & CalFilter::HideRecurring );
00208 
00209   if ( c & CalFilter::ShowCategories ) {
00210     mEditor->mCatShowCheck->setChecked( true );
00211   } else {
00212     mEditor->mCatHideCheck->setChecked( true );
00213   }
00214 
00215   mEditor->mCatList->clear();
00216   mEditor->mCatList->insertStringList( filter->categoryList() );
00217   mCategories = filter->categoryList();
00218 }
00219 
00220 void FilterEditDialog::writeFilter( CalFilter *filter )
00221 {
00222   int c = 0;
00223 
00224   if ( mEditor->mCompletedCheck->isChecked() ) c |= CalFilter::HideCompleted;
00225   if ( mEditor->mRecurringCheck->isChecked() ) c |= CalFilter::HideRecurring;
00226   if ( mEditor->mCatShowCheck->isChecked() ) c |= CalFilter::ShowCategories;
00227 
00228   filter->setCriteria( c );
00229 
00230   QStringList categoryList;
00231   for( uint i = 0; i < mEditor->mCatList->count(); ++i ) {
00232     categoryList.append( mEditor->mCatList->text( i ) );
00233   }
00234   filter->setCategoryList( categoryList );
00235 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:45:23 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003