30 #include <calendarsupport/categoryconfig.h>
31 #include <libkdepim/widgets/tagwidgets.h>
33 #include <KCalCore/CalFilter>
35 #include <KMessageBox>
36 #include <kcolorscheme.h>
41 setCaption( i18nc(
"@title::window",
"Edit Calendar Filters" ) );
42 setButtons( Ok | Apply | Cancel );
43 setMainWidget( mFilterEdit =
new FilterEdit( filters,
this ) );
49 connect(
this, SIGNAL(okClicked()),
this, SLOT(
slotOk()) );
50 connect(
this, SIGNAL(applyClicked()),
this, SLOT(
slotApply()) );
77 enableButton( Ok, consistent );
78 enableButtonApply( consistent );
82 :
QWidget( parent ), mCurrent( 0 ), mCategorySelectDialog( 0 )
85 searchline->setListWidget( mRulesList );
86 searchline->setTrapReturnKey(
true);
87 mDetailsFrame->setEnabled(
false );
89 mNewButton->setWhatsThis(
90 i18nc(
"@info:whatsthis",
91 "Press this button to define a new filter." ) );
92 mDeleteButton->setWhatsThis(
93 i18nc(
"@info:whatsthis",
94 "Press this button to remove the currently active filter." ) );
96 connect( mRulesList, SIGNAL(itemSelectionChanged()),
97 this, SLOT(filterSelected()) );
98 connect( mNewButton, SIGNAL(clicked()),
99 SLOT(bNewPressed()) );
100 connect( mDeleteButton, SIGNAL(clicked()),
101 SLOT(bDeletePressed()) );
103 SLOT(updateSelectedName(
QString)) );
104 connect( mCatEditButton, SIGNAL(clicked()), SLOT(editCategorySelection()) );
105 connect( mCompletedCheck, SIGNAL(toggled(
bool)),
106 mCompletedTimeSpanLabel, SLOT(
setEnabled(
bool)) );
107 connect( mCompletedCheck, SIGNAL(toggled(
bool)),
119 if ( !mFilters || mFilters->
empty() ) {
120 mDetailsFrame->setEnabled(
false );
124 for ( i = mFilters->
begin(); i != mFilters->
end(); ++i ) {
126 mRulesList->addItem( (*i)->name() );
129 if ( mRulesList->currentRow() != -1 ) {
130 KCalCore::CalFilter *f = mFilters->
at( mRulesList->currentRow() );
137 if ( mFilters && mFilters->
count() > 0 && !mCurrent ) {
138 filterSelected( mFilters->
at( 0 ) );
141 mDeleteButton->setEnabled( !mFilters->
isEmpty() );
151 mCurrent->setName( mNameLineEdit->text() );
153 if ( mCompletedCheck->isChecked() ) {
154 criteria |= KCalCore::CalFilter::HideCompletedTodos;
156 if ( mRecurringCheck->isChecked() ) {
157 criteria |= KCalCore::CalFilter::HideRecurring;
159 if ( mCatShowCheck->isChecked() ) {
160 criteria |= KCalCore::CalFilter::ShowCategories;
162 if ( mHideInactiveTodosCheck->isChecked() ) {
163 criteria |= KCalCore::CalFilter::HideInactiveTodos;
165 if ( mHideTodosNotAssignedToMeCheck->isChecked() ) {
166 criteria |= KCalCore::CalFilter::HideNoMatchingAttendeeTodos;
168 mCurrent->setCriteria( criteria );
169 mCurrent->setCompletedTimeSpan( mCompletedTimeSpan->value() );
172 for (
int i = 0; i < mCatList->count(); ++i ) {
178 mCurrent->setCategoryList( categoryList );
182 void FilterEdit::filterSelected()
184 if ( mRulesList->currentRow() < mFilters->
count() ) {
185 mDetailsFrame->setEnabled(
true );
186 filterSelected( mFilters->
at( mRulesList->currentRow() ) );
190 void FilterEdit::filterSelected( KCalCore::CalFilter *filter )
192 if( !filter || filter == mCurrent ) {
195 kDebug() <<
"Selected filter" << filter->name();
199 mNameLineEdit->blockSignals(
true );
200 mNameLineEdit->setText( mCurrent->name() );
201 mNameLineEdit->blockSignals(
false );
202 mDetailsFrame->setEnabled(
true );
203 mCompletedCheck->setChecked( mCurrent->criteria() & KCalCore::CalFilter::HideCompletedTodos );
204 mCompletedTimeSpan->setValue( mCurrent->completedTimeSpan() );
205 mRecurringCheck->setChecked( mCurrent->criteria() & KCalCore::CalFilter::HideRecurring );
206 mHideInactiveTodosCheck->setChecked(
207 mCurrent->criteria() & KCalCore::CalFilter::HideInactiveTodos );
208 mHideTodosNotAssignedToMeCheck->setChecked(
209 mCurrent->criteria() & KCalCore::CalFilter::HideNoMatchingAttendeeTodos );
211 if ( mCurrent->criteria() & KCalCore::CalFilter::ShowCategories ) {
212 mCatShowCheck->setChecked(
true );
214 mCatHideCheck->setChecked(
true );
217 mCatList->addItems( mCurrent->categoryList() );
220 void FilterEdit::bNewPressed()
222 mDetailsFrame->setEnabled(
true );
225 for (
int i=0; i < mRulesList->count(); ++i) {
226 filterNames << mRulesList->item(i)->text();
229 for (
int i = 1;;++i) {
230 newFilterName = i18nc(
"@label default filter name",
231 "New Filter %1", i );
232 if (!filterNames.
contains(newFilterName)) {
236 KCalCore::CalFilter *newFilter =
237 new KCalCore::CalFilter( newFilterName );
238 mFilters->
append( newFilter );
240 mRulesList->setCurrentRow( mRulesList->count() - 1 );
244 void FilterEdit::bDeletePressed()
246 if ( !mRulesList->currentItem() ) {
253 if ( KMessageBox::warningContinueCancel(
256 "Do you really want to permanently remove the filter \"%1\"?", mCurrent->name() ),
257 i18nc(
"@title:window",
"Delete Filter?" ),
258 KStandardGuiItem::del() ) == KMessageBox::Cancel ) {
262 int selected = mRulesList->currentRow();
263 KCalCore::CalFilter *filter = mFilters->
at( selected );
268 mRulesList->setCurrentRow( qMin( mRulesList->count() - 1, selected ) );
272 void FilterEdit::updateSelectedName(
const QString &newText )
274 mRulesList->blockSignals(
true );
279 mRulesList->blockSignals(
false );
280 if (correctName(newText)) {
286 foreach ( KCalCore::CalFilter *i, *mFilters ) {
287 if ( i && i->name().isEmpty() ) {
295 bool FilterEdit::correctName(
const QString &newText)
297 #ifndef QT_NO_STYLE_STYLESHEET
299 if (mNegativeBackground.
isEmpty()) {
300 KStatefulBrush bgBrush = KStatefulBrush(KColorScheme::View, KColorScheme::NegativeBackground);
301 mNegativeBackground =
QString::fromLatin1(
"QLineEdit{ background-color:%1 }").
arg(bgBrush.brush(mNameLineEdit).color().name());
303 bool negative =
false;
305 for (
int i = 0; i < mRulesList->count(); ++i ) {
307 if ( item && (mRulesList->currentItem() != item)) {
308 if (newText == item->
text()) {
318 styleSheet = mNegativeBackground;
319 mNameLineEdit->setStyleSheet(styleSheet);
325 void FilterEdit::editCategorySelection()
331 if ( !mCategorySelectDialog ) {
332 mCategorySelectDialog =
new KPIM::TagSelectionDialog(
this );
334 mCategorySelectDialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Help );
335 connect(mCategorySelectDialog, SIGNAL(accepted()),
this, SLOT(updateCategorySelection()));
337 mCategorySelectDialog->setSelection( mCurrent->categoryList() );
339 mCategorySelectDialog->show();
342 void FilterEdit::updateCategorySelection()
344 const QStringList &categories = mCategorySelectDialog->selection();
346 mCatList->addItems( categories );
347 mCurrent->setCategoryList( categories );
void dataConsistent(bool)
FilterEditDialog(QList< KCalCore::CalFilter * > *, QWidget *parent=0)
const T & at(int i) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
int count(const T &value) const
void append(const T &value)
int removeAll(const T &value)
virtual ~FilterEditDialog()
QString fromLatin1(const char *str, int size)
FilterEdit(QList< KCalCore::CalFilter * > *filters, QWidget *parent)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setDialogConsistent(bool consistent)
void setText(const QString &text)