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 <libkdepim/categoryselectdialog.h> 00038 00039 #include "koprefs.h" 00040 #include "filteredit_base.h" 00041 00042 #include "filtereditdialog.h" 00043 #include "filtereditdialog.moc" 00044 00045 // TODO: Make dialog work on a copy of the filters objects. 00046 00047 FilterEditDialog::FilterEditDialog( QPtrList<CalFilter> *filters, 00048 QWidget *parent, const char *name) 00049 : KDialogBase( parent, name, false, i18n("Edit Calendar Filters"), 00050 Ok | Apply | Cancel ), 00051 mCategorySelectDialog( 0 ) 00052 { 00053 mFilters = filters; 00054 00055 QWidget *mainWidget = new QWidget( this ); 00056 setMainWidget( mainWidget ); 00057 00058 mSelectionCombo = new QComboBox( mainWidget ); 00059 connect( mSelectionCombo, SIGNAL( activated( int ) ), 00060 SLOT( filterSelected() ) ); 00061 00062 QPushButton *addButton = new QPushButton( i18n("Add Filter..."), mainWidget ); 00063 connect( addButton, SIGNAL( clicked() ), SLOT( slotAdd() ) ); 00064 00065 mRemoveButton = new QPushButton( i18n("Remove"), mainWidget ); 00066 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotRemove() ) ); 00067 00068 mEditor = new FilterEdit_base( mainWidget ); 00069 00070 QGridLayout *topLayout = new QGridLayout( mainWidget, 2, 2 ); 00071 topLayout->setSpacing( spacingHint() ); 00072 topLayout->addWidget( mSelectionCombo, 0, 0 ); 00073 topLayout->addWidget( addButton, 0, 1 ); 00074 topLayout->addWidget( mRemoveButton, 0, 2 ); 00075 topLayout->addMultiCellWidget( mEditor, 1, 1, 0, 2 ); 00076 00077 connect( mEditor->mCatEditButton, SIGNAL( clicked() ), 00078 SLOT( editCategorySelection() ) ); 00079 00080 // Clicking cancel exits the dialog without saving 00081 connect( this, SIGNAL( cancelClicked() ), SLOT( reject() ) ); 00082 00083 updateFilterList(); 00084 } 00085 00086 FilterEditDialog::~FilterEditDialog() 00087 { 00088 } 00089 00090 void FilterEditDialog::updateFilterList() 00091 { 00092 mSelectionCombo->clear(); 00093 00094 CalFilter *filter = mFilters->first(); 00095 00096 if ( !filter ) { 00097 enableButtonOK( false ); 00098 enableButtonApply( false ); 00099 } else { 00100 while( filter ) { 00101 mSelectionCombo->insertItem( filter->name() ); 00102 filter = mFilters->next(); 00103 } 00104 00105 CalFilter *f = mFilters->at( mSelectionCombo->currentItem() ); 00106 if ( f ) readFilter( f ); 00107 00108 enableButtonOK( true ); 00109 enableButtonApply( true ); 00110 } 00111 00112 mRemoveButton->setEnabled( mFilters->count() > 1 ); 00113 } 00114 00115 void FilterEditDialog::updateCategoryConfig() 00116 { 00117 if ( mCategorySelectDialog ) mCategorySelectDialog->updateCategoryConfig(); 00118 } 00119 00120 void FilterEditDialog::slotDefault() 00121 { 00122 } 00123 00124 void FilterEditDialog::slotApply() 00125 { 00126 CalFilter *f = mFilters->at( mSelectionCombo->currentItem() ); 00127 writeFilter( f ); 00128 emit filterChanged(); 00129 } 00130 00131 void FilterEditDialog::slotOk() 00132 { 00133 CalFilter *f = mFilters->at( mSelectionCombo->currentItem() ); 00134 writeFilter( f ); 00135 emit filterChanged(); 00136 accept(); 00137 } 00138 00139 void FilterEditDialog::slotAdd() 00140 { 00141 QString txt = KInputDialog::getText( i18n("Add Filter"), 00142 i18n("Enter filter name:"), 00143 QString::null, 0, this ); 00144 if ( !txt.isEmpty() ) { 00145 mFilters->append( new CalFilter( txt ) ); 00146 updateFilterList(); 00147 } 00148 } 00149 00150 void FilterEditDialog::slotRemove() 00151 { 00152 int currentItem = mSelectionCombo->currentItem(); 00153 if ( currentItem < 0 ) return; 00154 00155 // We need at least a default filter object. 00156 if ( mFilters->count() <= 1 ) return; 00157 00158 int result = KMessageBox::questionYesNo( this, 00159 i18n("This item will be permanently deleted.") ); 00160 00161 if ( result != KMessageBox::Yes ) { 00162 return; 00163 } 00164 00165 mFilters->remove( currentItem ); 00166 updateFilterList(); 00167 emit filterChanged(); 00168 } 00169 00170 void FilterEditDialog::editCategorySelection() 00171 { 00172 if ( !mCategorySelectDialog ) { 00173 mCategorySelectDialog = new KPIM::CategorySelectDialog( 00174 KOPrefs::instance(), this, "filterCatSelect" ); 00175 mCategorySelectDialog->setSelected( mCategories ); 00176 connect( mCategorySelectDialog, 00177 SIGNAL( categoriesSelected( const QStringList & ) ), 00178 SLOT( updateCategorySelection( const QStringList & ) ) ); 00179 connect( mCategorySelectDialog, SIGNAL( editCategories() ), 00180 SIGNAL( editCategories() ) ); 00181 } 00182 00183 mCategorySelectDialog->show(); 00184 } 00185 00186 void FilterEditDialog::updateCategorySelection( const QStringList &categories ) 00187 { 00188 mCategories = categories; 00189 00190 mEditor->mCatList->clear(); 00191 mEditor->mCatList->insertStringList( mCategories ); 00192 } 00193 00194 void FilterEditDialog::filterSelected() 00195 { 00196 CalFilter *f = mFilters->at( mSelectionCombo->currentItem() ); 00197 kdDebug(5850) << "Selected filter " << f->name() << endl; 00198 if ( f ) readFilter( f ); 00199 } 00200 00201 void FilterEditDialog::readFilter( CalFilter *filter ) 00202 { 00203 int c = filter->criteria(); 00204 00205 mEditor->mCompletedCheck->setChecked( c & CalFilter::HideCompleted ); 00206 mEditor->mRecurringCheck->setChecked( c & CalFilter::HideRecurring ); 00207 00208 if ( c & CalFilter::ShowCategories ) { 00209 mEditor->mCatShowCheck->setChecked( true ); 00210 } else { 00211 mEditor->mCatHideCheck->setChecked( true ); 00212 } 00213 00214 mEditor->mCatList->clear(); 00215 mEditor->mCatList->insertStringList( filter->categoryList() ); 00216 mCategories = filter->categoryList(); 00217 } 00218 00219 void FilterEditDialog::writeFilter( CalFilter *filter ) 00220 { 00221 int c = 0; 00222 00223 if ( mEditor->mCompletedCheck->isChecked() ) c |= CalFilter::HideCompleted; 00224 if ( mEditor->mRecurringCheck->isChecked() ) c |= CalFilter::HideRecurring; 00225 if ( mEditor->mCatShowCheck->isChecked() ) c |= CalFilter::ShowCategories; 00226 00227 filter->setCriteria( c ); 00228 00229 QStringList categoryList; 00230 for( uint i = 0; i < mEditor->mCatList->count(); ++i ) { 00231 categoryList.append( mEditor->mCatList->text( i ) ); 00232 } 00233 filter->setCategoryList( categoryList ); 00234 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003