• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
filtereditdialog.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6  Copyright (C) 2005 Thomas Zander <zander@kde.org>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22  As a special exception, permission is given to link this program
23  with any edition of Qt, and distribute the resulting executable,
24  without including the source code for Qt in the source distribution.
25 */
26 
27 #include "filtereditdialog.h"
28 #include "koprefs.h"
29 
30 #include <calendarsupport/categoryconfig.h>
31 
32 #include <incidenceeditor-ng/categoryselectdialog.h>
33 
34 #include <KCalCore/CalFilter>
35 
36 #include <KMessageBox>
37 
38 FilterEditDialog::FilterEditDialog( QList<KCalCore::CalFilter*> *filters, QWidget *parent )
39  : KDialog( parent )
40 {
41  setCaption( i18nc( "@title::window", "Edit Calendar Filters" ) );
42  setButtons( Ok | Apply | Cancel );
43  setMainWidget( mFilterEdit = new FilterEdit( filters, this ) );
44 
45  connect( mFilterEdit, SIGNAL(dataConsistent(bool)), SLOT(setDialogConsistent(bool)) );
46  updateFilterList();
47  connect( mFilterEdit, SIGNAL(editCategories()), SIGNAL(editCategories()) );
48  connect( mFilterEdit, SIGNAL(filterChanged()), SIGNAL(filterChanged()) );
49  connect( this, SIGNAL(okClicked()), this, SLOT(slotOk()) );
50  connect( this, SIGNAL(applyClicked()), this, SLOT(slotApply()) );
51 }
52 
53 FilterEditDialog::~FilterEditDialog()
54 {
55  delete mFilterEdit;
56  mFilterEdit = 0;
57 }
58 
59 void FilterEditDialog::updateFilterList()
60 {
61  mFilterEdit->updateFilterList();
62 }
63 
64 void FilterEditDialog::updateCategoryConfig()
65 {
66  mFilterEdit->updateCategoryConfig();
67 }
68 
69 void FilterEditDialog::slotApply()
70 {
71  mFilterEdit->saveChanges();
72 }
73 
74 void FilterEditDialog::slotOk()
75 {
76  slotApply();
77  accept();
78 }
79 
80 void FilterEditDialog::setDialogConsistent( bool consistent )
81 {
82  enableButton( Ok, consistent );
83  enableButtonApply( consistent );
84 }
85 
86 FilterEdit::FilterEdit( QList<KCalCore::CalFilter*> *filters, QWidget *parent )
87  : QWidget( parent ), mCurrent( 0 ), mCategorySelectDialog( 0 )
88 {
89  setupUi( this );
90  searchline->setListWidget( mRulesList );
91  mDetailsFrame->setEnabled( false );
92  mFilters = filters;
93  mNewButton->setWhatsThis(
94  i18nc( "@info:whatsthis",
95  "Press this button to define a new filter." ) );
96  mDeleteButton->setWhatsThis(
97  i18nc( "@info:whatsthis",
98  "Press this button to remove the currently active filter." ) );
99 
100  connect( mRulesList, SIGNAL(itemSelectionChanged()),
101  this, SLOT(filterSelected()) );
102  connect( mNewButton, SIGNAL(clicked()),
103  SLOT(bNewPressed()) );
104  connect( mDeleteButton, SIGNAL(clicked()),
105  SLOT(bDeletePressed()) );
106  connect( mNameLineEdit, SIGNAL(textChanged(QString)),
107  SLOT(updateSelectedName(QString)) );
108  connect( mCatEditButton, SIGNAL(clicked()), SLOT(editCategorySelection()) );
109  connect( mCompletedCheck, SIGNAL(toggled(bool)),
110  mCompletedTimeSpanLabel, SLOT(setEnabled(bool)) );
111  connect( mCompletedCheck, SIGNAL(toggled(bool)),
112  mCompletedTimeSpan, SLOT(setEnabled(bool)) );
113 
114 }
115 
116 FilterEdit::~FilterEdit()
117 {
118 }
119 
120 void FilterEdit::updateFilterList()
121 {
122  mRulesList->clear();
123  qDebug() << " FilterEdit::updateFilterList() :" << mFilters;
124  if ( mFilters ) {
125  qDebug() << " mFilters->empty() :" << mFilters->empty();
126  }
127  if ( !mFilters || mFilters->empty() ) {
128  mDetailsFrame->setEnabled( false );
129  emit( dataConsistent( false ) );
130  } else {
131  QList<KCalCore::CalFilter*>::iterator i;
132  for ( i = mFilters->begin(); i != mFilters->end(); ++i ) {
133  if ( *i ) {
134  mRulesList->addItem( (*i)->name() );
135  }
136  }
137  if ( mRulesList->currentRow() != -1 ) {
138  KCalCore::CalFilter *f = mFilters->at( mRulesList->currentRow() );
139  if ( f ) {
140  filterSelected( f );
141  }
142  }
143  emit( dataConsistent( true ) );
144  }
145  if ( mFilters && mFilters->count() > 0 && !mCurrent ) {
146  filterSelected( mFilters->at( 0 ) );
147  }
148  if ( mFilters ) {
149  mDeleteButton->setEnabled( !mFilters->isEmpty() );
150  }
151 }
152 
153 void FilterEdit::saveChanges()
154 {
155  if ( !mCurrent ) {
156  return;
157  }
158 
159  mCurrent->setName( mNameLineEdit->text() );
160  int criteria = 0;
161  if ( mCompletedCheck->isChecked() ) {
162  criteria |= KCalCore::CalFilter::HideCompletedTodos;
163  }
164  if ( mRecurringCheck->isChecked() ) {
165  criteria |= KCalCore::CalFilter::HideRecurring;
166  }
167  if ( mCatShowCheck->isChecked() ) {
168  criteria |= KCalCore::CalFilter::ShowCategories;
169  }
170  if ( mHideInactiveTodosCheck->isChecked() ) {
171  criteria |= KCalCore::CalFilter::HideInactiveTodos;
172  }
173  if ( mHideTodosNotAssignedToMeCheck->isChecked() ) {
174  criteria |= KCalCore::CalFilter::HideNoMatchingAttendeeTodos;
175  }
176  mCurrent->setCriteria( criteria );
177  mCurrent->setCompletedTimeSpan( mCompletedTimeSpan->value() );
178 
179  QStringList categoryList;
180  for ( int i = 0; i < mCatList->count(); ++i ) {
181  QListWidgetItem *item = mCatList->item(i);
182  if ( item ) {
183  categoryList.append( item->text() );
184  }
185  }
186  mCurrent->setCategoryList( categoryList );
187  emit filterChanged();
188 }
189 
190 void FilterEdit::filterSelected()
191 {
192  if ( mRulesList->currentRow() < mFilters->count() ) {
193  mDetailsFrame->setEnabled( true );
194  filterSelected( mFilters->at( mRulesList->currentRow() ) );
195  }
196 }
197 
198 void FilterEdit::filterSelected( KCalCore::CalFilter *filter )
199 {
200  if( !filter || filter == mCurrent ) {
201  return;
202  }
203  kDebug() << "Selected filter" << filter->name();
204  saveChanges();
205 
206  mCurrent = filter;
207  mNameLineEdit->blockSignals( true );
208  mNameLineEdit->setText( mCurrent->name() );
209  mNameLineEdit->blockSignals( false );
210  mDetailsFrame->setEnabled( true );
211  mCompletedCheck->setChecked( mCurrent->criteria() & KCalCore::CalFilter::HideCompletedTodos );
212  mCompletedTimeSpan->setValue( mCurrent->completedTimeSpan() );
213  mRecurringCheck->setChecked( mCurrent->criteria() & KCalCore::CalFilter::HideRecurring );
214  mHideInactiveTodosCheck->setChecked(
215  mCurrent->criteria() & KCalCore::CalFilter::HideInactiveTodos );
216  mHideTodosNotAssignedToMeCheck->setChecked(
217  mCurrent->criteria() & KCalCore::CalFilter::HideNoMatchingAttendeeTodos );
218 
219  if ( mCurrent->criteria() & KCalCore::CalFilter::ShowCategories ) {
220  mCatShowCheck->setChecked( true );
221  } else {
222  mCatHideCheck->setChecked( true );
223  }
224  mCatList->clear();
225  mCatList->addItems( mCurrent->categoryList() );
226 }
227 
228 void FilterEdit::bNewPressed()
229 {
230  mDetailsFrame->setEnabled( true );
231  saveChanges();
232  KCalCore::CalFilter *newFilter =
233  new KCalCore::CalFilter( i18nc( "@label default filter name",
234  "New Filter %1", mFilters->count() ) );
235  mFilters->append( newFilter );
236  updateFilterList();
237  mRulesList->setCurrentRow( mRulesList->count() - 1 );
238  emit filterChanged();
239 }
240 
241 void FilterEdit::bDeletePressed()
242 {
243  if ( !mRulesList->currentItem() ) { // nothing selected
244  return;
245  }
246  if ( mFilters->isEmpty() ) { // We need at least a default filter object.
247  return;
248  }
249 
250  if ( KMessageBox::warningContinueCancel(
251  this,
252  i18nc( "@info",
253  "Do you really want to permanently remove the filter \"%1\"?", mCurrent->name() ),
254  i18nc( "@title:window", "Delete Filter?" ),
255  KStandardGuiItem::del() ) == KMessageBox::Cancel ) {
256  return;
257  }
258 
259  int selected = mRulesList->currentRow();
260  KCalCore::CalFilter *filter = mFilters->at( selected );
261  mFilters->removeAll( filter );
262  delete filter;
263  mCurrent = 0;
264  updateFilterList();
265  mRulesList->setCurrentRow( qMin( mRulesList->count() - 1, selected ) );
266  emit filterChanged();
267 }
268 
269 void FilterEdit::updateSelectedName( const QString &newText )
270 {
271  mRulesList->blockSignals( true );
272  QListWidgetItem *item = mRulesList->currentItem();
273  if ( item ) {
274  item->setText( newText );
275  }
276  mRulesList->blockSignals( false );
277  bool allOk = true;
278 
279  foreach ( KCalCore::CalFilter *i, *mFilters ) {
280  if ( i && i->name().isEmpty() ) {
281  allOk = false;
282  }
283  }
284 
285  emit dataConsistent( allOk );
286 }
287 
288 void FilterEdit::editCategorySelection()
289 {
290  if( !mCurrent ) {
291  return;
292  }
293 
294  if ( !mCategorySelectDialog ) {
295  CalendarSupport::CategoryConfig *cc =
296  new CalendarSupport::CategoryConfig( KOPrefs::instance(), this );
297  mCategorySelectDialog = new IncidenceEditorNG::CategorySelectDialog( cc, this );
298  mCategorySelectDialog->setHelp( QLatin1String("categories-view"), QLatin1String("korganizer") );
299  mCategorySelectDialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Help );
300  connect( mCategorySelectDialog, SIGNAL(categoriesSelected(QStringList)),
301  SLOT(updateCategorySelection(QStringList)) );
302  connect( mCategorySelectDialog, SIGNAL(editCategories()),
303  SIGNAL(editCategories()) );
304 
305  }
306  // we need the children not to autoselect or else some unselected
307  // children can also become selected
308  mCategorySelectDialog->setAutoselectChildren( false );
309  mCategorySelectDialog->setSelected( mCurrent->categoryList() );
310  mCategorySelectDialog->setAutoselectChildren( true );
311 
312  mCategorySelectDialog->show();
313 }
314 
315 void FilterEdit::updateCategorySelection( const QStringList &categories )
316 {
317  mCatList->clear();
318  mCatList->addItems( categories );
319  mCurrent->setCategoryList( categories );
320 }
321 
322 void FilterEdit::updateCategoryConfig()
323 {
324  if ( mCategorySelectDialog ) {
325  mCategorySelectDialog->updateCategoryConfig();
326  }
327 }
328 
329 #include "filtereditdialog.moc"
FilterEdit::dataConsistent
void dataConsistent(bool)
FilterEdit::filterChanged
void filterChanged()
FilterEditDialog::updateCategoryConfig
void updateCategoryConfig()
Definition: filtereditdialog.cpp:64
FilterEditDialog::editCategories
void editCategories()
filtereditdialog.h
FilterEditDialog::FilterEditDialog
FilterEditDialog(QList< KCalCore::CalFilter * > *, QWidget *parent=0)
Definition: filtereditdialog.cpp:38
FilterEditDialog::slotApply
void slotApply()
Definition: filtereditdialog.cpp:69
QWidget
FilterEditDialog::updateFilterList
void updateFilterList()
Definition: filtereditdialog.cpp:59
KDialog
FilterEdit::editCategories
void editCategories()
FilterEdit::saveChanges
void saveChanges()
Definition: filtereditdialog.cpp:153
koprefs.h
FilterEditDialog::slotOk
void slotOk()
Definition: filtereditdialog.cpp:74
FilterEditDialog::~FilterEditDialog
virtual ~FilterEditDialog()
Definition: filtereditdialog.cpp:53
FilterEdit
Definition: filtereditdialog.h:74
FilterEditDialog::filterChanged
void filterChanged()
FilterEdit::updateFilterList
void updateFilterList()
Definition: filtereditdialog.cpp:120
KOPrefs::instance
static KOPrefs * instance()
Get instance of KOPrefs.
Definition: koprefs.cpp:68
FilterEdit::updateCategoryConfig
void updateCategoryConfig()
Definition: filtereditdialog.cpp:322
FilterEdit::FilterEdit
FilterEdit(QList< KCalCore::CalFilter * > *filters, QWidget *parent)
Definition: filtereditdialog.cpp:86
FilterEditDialog::setDialogConsistent
void setDialogConsistent(bool consistent)
Definition: filtereditdialog.cpp:80
FilterEdit::~FilterEdit
~FilterEdit()
Definition: filtereditdialog.cpp:116
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal