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     Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006     Copyright (C) 2005 Thomas Zander <zander@kde.org>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022     As a special exception, permission is given to link this program
00023     with any edition of Qt, and distribute the resulting executable,
00024     without including the source code for Qt in the source distribution.
00025 */
00026 
00027 #include <qpushbutton.h>
00028 #include <qcheckbox.h>
00029 #include <qbuttongroup.h>
00030 #include <qlineedit.h>
00031 #include <qradiobutton.h>
00032 #include <qlistbox.h>
00033 #include <qwhatsthis.h>
00034 
00035 #include <kdebug.h>
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038 #include <knuminput.h>
00039 
00040 #include <libkcal/calfilter.h>
00041 #include <libkdepim/categoryselectdialog.h>
00042 
00043 #include "koprefs.h"
00044 #include "filteredit_base.h"
00045 
00046 #include "filtereditdialog.h"
00047 #include "filtereditdialog.moc"
00048 
00049 FilterEditDialog::FilterEditDialog( QPtrList<CalFilter> *filters,
00050                                     QWidget *parent, const char *name)
00051   : KDialogBase( parent, name, false, i18n("Edit Calendar Filters"),
00052                  Ok | Apply | Cancel )
00053 {
00054   setMainWidget( mFilterEdit = new FilterEdit(filters, this));
00055 
00056   connect(mFilterEdit, SIGNAL(dataConsistent(bool)),
00057         SLOT(setDialogConsistent(bool)));
00058     updateFilterList();
00059     connect( mFilterEdit, SIGNAL( editCategories() ), SIGNAL( editCategories() ) );
00060     connect( mFilterEdit, SIGNAL( filterChanged() ), SIGNAL( filterChanged() ) );
00061 }
00062 
00063 FilterEditDialog::~FilterEditDialog()
00064 {
00065   delete mFilterEdit;
00066   mFilterEdit = 0L;
00067 }
00068 
00069 void FilterEditDialog::updateFilterList()
00070 {
00071   mFilterEdit->updateFilterList();
00072 }
00073 
00074 void FilterEditDialog::updateCategoryConfig()
00075 {
00076   mFilterEdit->updateCategoryConfig();
00077 }
00078 
00079 void FilterEditDialog::slotApply()
00080 {
00081   mFilterEdit->saveChanges();
00082 }
00083 
00084 void FilterEditDialog::slotOk()
00085 {
00086   slotApply();
00087   accept();
00088 }
00089 
00090 void FilterEditDialog::setDialogConsistent(bool consistent) {
00091     enableButtonOK( consistent );
00092     enableButtonApply( consistent );
00093 }
00094 
00095 FilterEdit::FilterEdit(QPtrList<CalFilter> *filters, QWidget *parent)
00096   : FilterEdit_base( parent), current(0), mCategorySelectDialog( 0 )
00097 {
00098   mFilters = filters;
00099   QWhatsThis::add( mNewButton, i18n( "Press this button to define a new filter." ) );
00100   QWhatsThis::add( mDeleteButton, i18n( "Press this button to remove the currently active filter." ) );
00101 
00102   connect( mRulesList, SIGNAL(selectionChanged()), this, SLOT(filterSelected()) );
00103   connect( mNewButton, SIGNAL( clicked() ), SLOT( bNewPressed() ) );
00104   connect( mDeleteButton, SIGNAL( clicked() ), SLOT( bDeletePressed() ) );
00105   connect( mNameLineEdit, SIGNAL( textChanged(const QString &) ), SLOT( updateSelectedName(const QString &) ) );
00106   connect( mCatEditButton, SIGNAL( clicked() ), SLOT( editCategorySelection() ) );
00107 }
00108 
00109 FilterEdit::~FilterEdit() {
00110 }
00111 
00112 
00113 void FilterEdit::updateFilterList()
00114 {
00115   mRulesList->clear();
00116 
00117   CalFilter *filter = mFilters->first();
00118 
00119   if ( !filter )
00120     emit(dataConsistent(false));
00121   else {
00122     while( filter ) {
00123       mRulesList->insertItem( filter->name() );
00124       filter = mFilters->next();
00125     }
00126 
00127     CalFilter *f = mFilters->at( mRulesList->currentItem() );
00128     if ( f ) filterSelected( f );
00129 
00130     emit(dataConsistent(true));
00131   }
00132 
00133   if(current == 0L && mFilters->count() > 0)
00134     filterSelected(mFilters->at(0));
00135   mDeleteButton->setEnabled( mFilters->count() > 1 );
00136 }
00137 
00138 void FilterEdit::saveChanges()
00139 {
00140   if(current == 0L)
00141     return;
00142   
00143   current->setName(mNameLineEdit->text());
00144   int criteria = 0;
00145   if ( mCompletedCheck->isChecked() ) criteria |= CalFilter::HideCompleted;
00146   if ( mRecurringCheck->isChecked() ) criteria |= CalFilter::HideRecurring;
00147   if ( mCatShowCheck->isChecked() ) criteria |= CalFilter::ShowCategories;
00148   current->setCriteria( criteria );
00149 
00150   QStringList categoryList;
00151   for( uint i = 0; i < mCatList->count(); ++i )
00152       categoryList.append( mCatList->text( i ) );
00153   current->setCategoryList( categoryList );
00154   emit filterChanged();
00155 }
00156 
00157 void FilterEdit::filterSelected()
00158 {
00159   filterSelected(mFilters->at(mRulesList->currentItem()));
00160 }
00161 
00162 void FilterEdit::filterSelected(CalFilter *filter)
00163 {
00164   if(filter == current) return;
00165   kdDebug(5850) << "Selected filter " << (filter!=0?filter->name():"") << endl;
00166   saveChanges();
00167 
00168   current = filter;
00169   mNameLineEdit->blockSignals(true);
00170   mNameLineEdit->setText(current->name());
00171   mNameLineEdit->blockSignals(false);
00172   mDetailsFrame->setEnabled(current != 0L);
00173   mCompletedCheck->setChecked( current->criteria() & CalFilter::HideCompleted );
00174   mRecurringCheck->setChecked( current->criteria() & CalFilter::HideRecurring );
00175   mCategoriesButtonGroup->setButton( (current->criteria() & CalFilter::ShowCategories)?0:1 );
00176   mCatList->clear();
00177   mCatList->insertStringList( current->categoryList() );
00178 }
00179 
00180 void FilterEdit::bNewPressed() {
00181   CalFilter *newFilter = new CalFilter( i18n("New Filter %1").arg(mFilters->count()) );
00182   mFilters->append( newFilter );
00183   updateFilterList();
00184   mRulesList->setSelected(mRulesList->count()-1, true);
00185   emit filterChanged();
00186 }
00187 
00188 void FilterEdit::bDeletePressed() {
00189   if ( mRulesList->currentItem() < 0 ) return; // nothing selected
00190   if ( mFilters->count() <= 1 ) return; // We need at least a default filter object.
00191 
00192   int result = KMessageBox::warningContinueCancel( this,
00193      i18n("This item will be permanently deleted."), i18n("Delete Confirmation"), KGuiItem(i18n("Delete"),"editdelete") );
00194 
00195   if ( result != KMessageBox::Continue )
00196     return;
00197 
00198   unsigned int selected = mRulesList->currentItem();
00199   mFilters->remove( selected );
00200   current = 0L;
00201   updateFilterList();
00202   mRulesList->setSelected(QMIN(mRulesList->count()-1, selected), true);
00203   emit filterChanged();
00204 }
00205 
00206 void FilterEdit::updateSelectedName(const QString &newText) {
00207   mRulesList->blockSignals( true );
00208   mRulesList->changeItem(newText, mRulesList->currentItem());
00209   mRulesList->blockSignals( false );
00210   bool allOk = true;
00211   CalFilter *filter = mFilters->first();
00212   while( allOk && filter ) {
00213     if(filter->name().isEmpty())
00214      allOk = false;
00215     filter = mFilters->next();
00216   }
00217   emit dataConsistent(allOk);
00218 }
00219 
00220 void FilterEdit::editCategorySelection()
00221 {
00222   if( !current ) return;
00223   if ( !mCategorySelectDialog ) {
00224     mCategorySelectDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), this, "filterCatSelect" );
00225     connect( mCategorySelectDialog,
00226              SIGNAL( categoriesSelected( const QStringList & ) ),
00227              SLOT( updateCategorySelection( const QStringList & ) ) );
00228     connect( mCategorySelectDialog, SIGNAL( editCategories() ),
00229              SIGNAL( editCategories() ) );
00230 
00231   }
00232   mCategorySelectDialog->setSelected( current->categoryList() );
00233 
00234   mCategorySelectDialog->show();
00235 }
00236 
00237 void FilterEdit::updateCategorySelection( const QStringList &categories )
00238 {
00239   mCatList->clear();
00240   mCatList->insertStringList(categories);
00241   current->setCategoryList(categories);
00242 }
00243 
00244 void FilterEdit::updateCategoryConfig()
00245 {
00246   if ( mCategorySelectDialog ) mCategorySelectDialog->updateCategoryConfig();
00247 }
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 Jan 31 15:55:47 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003