author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/filtereditdialog.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'korganizer/filtereditdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/filtereditdialog.cpp | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/korganizer/filtereditdialog.cpp b/korganizer/filtereditdialog.cpp new file mode 100644 index 0000000..2943e41 --- a/dev/null +++ b/korganizer/filtereditdialog.cpp | |||
@@ -0,0 +1,270 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | #include <qlayout.h> | ||
25 | #include <qpushbutton.h> | ||
26 | #include <qcombobox.h> | ||
27 | #include <qcheckbox.h> | ||
28 | #include <qradiobutton.h> | ||
29 | #include <qlistbox.h> | ||
30 | #include <qapplication.h> | ||
31 | |||
32 | #include <kdebug.h> | ||
33 | #include <klocale.h> | ||
34 | #include <klineeditdlg.h> | ||
35 | #include <kmessagebox.h> | ||
36 | |||
37 | #include <libkdepim/categoryselectdialog.h> | ||
38 | |||
39 | #include "koprefs.h" | ||
40 | #include "filteredit_base.h" | ||
41 | |||
42 | #include "filtereditdialog.h" | ||
43 | #include "filtereditdialog.moc" | ||
44 | |||
45 | // TODO: Make dialog work on a copy of the filters objects. | ||
46 | |||
47 | class ComboFilterBox: public QComboBox | ||
48 | { | ||
49 | public: | ||
50 | ComboFilterBox( QWidget *parent=0, const char *name=0) : | ||
51 | QComboBox( parent,name ) { } | ||
52 | void popupBox() { popup(); } | ||
53 | |||
54 | }; | ||
55 | |||
56 | FilterEditDialog::FilterEditDialog(QPtrList<CalFilter> *filters,QWidget *parent, | ||
57 | const char *name) : | ||
58 | KDialogBase(parent,name,true,i18n("Edit Calendar Filters"), | ||
59 | Ok|Apply|Cancel) | ||
60 | { | ||
61 | mFilters = filters; | ||
62 | |||
63 | QWidget *mainWidget = new QWidget(this); | ||
64 | setMainWidget(mainWidget); | ||
65 | |||
66 | mSelectionCombo = new ComboFilterBox(mainWidget); | ||
67 | connect(mSelectionCombo,SIGNAL(activated(int)),SLOT(filterSelected())); | ||
68 | // mSelectionCombo->setEditable ( true ); | ||
69 | QPushButton *addButton = new QPushButton(i18n("Add Filter"),mainWidget); | ||
70 | connect(addButton,SIGNAL(clicked()),SLOT(slotAdd())); | ||
71 | addButton->setMaximumSize( addButton->sizeHint()); | ||
72 | mRemoveButton = new QPushButton( i18n("Remove"), mainWidget ); | ||
73 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotRemove() ) ); | ||
74 | mRemoveButton->setMaximumSize( mRemoveButton->sizeHint()); | ||
75 | |||
76 | QPushButton *upButton = new QPushButton(i18n("Up"),mainWidget); | ||
77 | upButton->setMaximumSize( upButton->sizeHint()); | ||
78 | connect(upButton,SIGNAL(clicked()),SLOT(slotUp())); | ||
79 | |||
80 | |||
81 | mEditor = new FilterEdit_base(mainWidget); | ||
82 | |||
83 | QGridLayout *topLayout = new QGridLayout(mainWidget,2,2); | ||
84 | topLayout->setSpacing(spacingHint()); | ||
85 | topLayout->addWidget(mSelectionCombo,0,0); | ||
86 | topLayout->addWidget(upButton,0,1); | ||
87 | topLayout->addWidget(addButton,0,2); | ||
88 | topLayout->addWidget(mRemoveButton,0,3); | ||
89 | topLayout->addMultiCellWidget(mEditor,1,1,0,3); | ||
90 | mSelectionCombo->setMaximumWidth ( QApplication::desktop()->width() - | ||
91 | addButton->maximumWidth() - | ||
92 | mRemoveButton->maximumWidth() - | ||
93 | upButton->maximumWidth() - | ||
94 | spacingHint() * 5 ); | ||
95 | connect(mEditor->mCatEditButton,SIGNAL(clicked()), | ||
96 | SLOT(editCategorySelection())); | ||
97 | |||
98 | // Clicking cancel exits the dialog without saving | ||
99 | connect(this,SIGNAL(cancelClicked()),SLOT(reject())); | ||
100 | updateFilterList(); | ||
101 | } | ||
102 | |||
103 | FilterEditDialog::~FilterEditDialog() | ||
104 | { | ||
105 | } | ||
106 | void FilterEditDialog::slotUp() | ||
107 | { | ||
108 | |||
109 | if ( mFilters->count() <= 1 ) return; | ||
110 | if ( mSelectionCombo->currentItem() == 0 ) return; | ||
111 | int num = mSelectionCombo->currentItem(); | ||
112 | CalFilter* f = new CalFilter( ); | ||
113 | *f = *(mFilters->at( num )); | ||
114 | mFilters->remove( num ); | ||
115 | mFilters->insert( num-1, f ); | ||
116 | updateFilterList(); | ||
117 | mSelectionCombo->setCurrentItem( num-1 ); | ||
118 | readFilter(f); | ||
119 | //qApp->processEvents(); | ||
120 | //mSelectionCombo->popupBox(); | ||
121 | } | ||
122 | void FilterEditDialog::updateFilterList() | ||
123 | { | ||
124 | mSelectionCombo->clear(); | ||
125 | |||
126 | CalFilter *filter = mFilters->first(); | ||
127 | |||
128 | if (!filter) { | ||
129 | enableButtonOK(false); | ||
130 | enableButtonApply(false); | ||
131 | } else { | ||
132 | while(filter) { | ||
133 | mSelectionCombo->insertItem(filter->name()); | ||
134 | filter = mFilters->next(); | ||
135 | } | ||
136 | CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); | ||
137 | if (f) readFilter(f); | ||
138 | |||
139 | enableButtonOK(true); | ||
140 | enableButtonApply(true); | ||
141 | } | ||
142 | |||
143 | mRemoveButton->setEnabled( mFilters->count() > 1 ); | ||
144 | } | ||
145 | |||
146 | void FilterEditDialog::slotDefault() | ||
147 | { | ||
148 | } | ||
149 | |||
150 | void FilterEditDialog::slotApply() | ||
151 | { | ||
152 | CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); | ||
153 | writeFilter(f); | ||
154 | emit filterChanged(); | ||
155 | } | ||
156 | void FilterEditDialog::accept() | ||
157 | { | ||
158 | slotOk(); | ||
159 | } | ||
160 | void FilterEditDialog::slotOk() | ||
161 | { | ||
162 | CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); | ||
163 | writeFilter(f); | ||
164 | emit filterChanged(); | ||
165 | QDialog::accept(); | ||
166 | } | ||
167 | |||
168 | void FilterEditDialog::slotAdd() | ||
169 | { | ||
170 | KLineEditDlg dlg(i18n("Enter filter name:"), "New Filter", this); | ||
171 | dlg.setCaption(i18n("Add Filter")); | ||
172 | if (dlg.exec()) { | ||
173 | if ( dlg.text().length() > 0 ) { | ||
174 | mFilters->append(new CalFilter(dlg.text())); | ||
175 | updateFilterList(); | ||
176 | int num = mSelectionCombo->count() -1 ; | ||
177 | mSelectionCombo->setCurrentItem( num ); | ||
178 | readFilter(mFilters->at( num ) ); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
183 | void FilterEditDialog::slotRemove() | ||
184 | { | ||
185 | int currentItem = mSelectionCombo->currentItem(); | ||
186 | if ( currentItem < 0 ) return; | ||
187 | |||
188 | // We need at least a default filter object. | ||
189 | if ( mFilters->count() <= 1 ) return; | ||
190 | |||
191 | int result = KMessageBox::questionYesNo( this, | ||
192 | i18n("This item will be\npermanently deleted.") ); | ||
193 | |||
194 | if ( result != KMessageBox::Yes ) { | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | mFilters->remove( currentItem ); | ||
199 | updateFilterList(); | ||
200 | emit filterChanged(); | ||
201 | } | ||
202 | |||
203 | void FilterEditDialog::editCategorySelection() | ||
204 | { | ||
205 | KPIM::CategorySelectDialog *dlg = new KPIM::CategorySelectDialog( | ||
206 | KOPrefs::instance(), this, "filterCatSelect", true ); | ||
207 | dlg->setSelected(mCategories); | ||
208 | |||
209 | connect(dlg,SIGNAL(categoriesSelected(const QStringList &)), | ||
210 | SLOT(updateCategorySelection(const QStringList &))); | ||
211 | |||
212 | dlg->exec(); | ||
213 | } | ||
214 | |||
215 | void FilterEditDialog::updateCategorySelection(const QStringList &categories) | ||
216 | { | ||
217 | mCategories = categories; | ||
218 | |||
219 | mEditor->mCatList->clear(); | ||
220 | mEditor->mCatList->insertStringList(mCategories); | ||
221 | } | ||
222 | |||
223 | void FilterEditDialog::filterSelected() | ||
224 | { | ||
225 | CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); | ||
226 | if (f) readFilter(f); | ||
227 | } | ||
228 | |||
229 | void FilterEditDialog::readFilter(CalFilter *filter) | ||
230 | { | ||
231 | int c = filter->criteria(); | ||
232 | |||
233 | mEditor->mCompletedCheck->setChecked(c & CalFilter::HideCompleted); | ||
234 | mEditor->mRecurringCheck->setChecked(c & CalFilter::HideRecurring); | ||
235 | mEditor->mPublicCheck->setChecked(c & CalFilter::ShowPublic); | ||
236 | mEditor->mPrivateCheck->setChecked(c & CalFilter::ShowPrivate); | ||
237 | mEditor->mConfidentialCheck->setChecked(c & CalFilter::ShowConfidential); | ||
238 | |||
239 | if (c & CalFilter::ShowCategories) { | ||
240 | mEditor->mCatShowCheck->setChecked(true); | ||
241 | } else { | ||
242 | mEditor->mCatHideCheck->setChecked(true); | ||
243 | } | ||
244 | |||
245 | mEditor->mCatList->clear(); | ||
246 | mEditor->mCatList->insertStringList(filter->categoryList()); | ||
247 | mCategories = filter->categoryList(); | ||
248 | |||
249 | setCaption( i18n("Filter position: ") + QString::number ( mSelectionCombo->currentItem()+1 )); | ||
250 | } | ||
251 | |||
252 | void FilterEditDialog::writeFilter(CalFilter *filter) | ||
253 | { | ||
254 | int c = 0; | ||
255 | |||
256 | if (mEditor->mCompletedCheck->isChecked()) c |= CalFilter::HideCompleted; | ||
257 | if (mEditor->mRecurringCheck->isChecked()) c |= CalFilter::HideRecurring; | ||
258 | if (mEditor->mCatShowCheck->isChecked()) c |= CalFilter::ShowCategories; | ||
259 | if (mEditor->mPublicCheck->isChecked()) c |= CalFilter::ShowPublic; | ||
260 | if (mEditor->mPrivateCheck->isChecked()) c |= CalFilter::ShowPrivate; | ||
261 | if (mEditor->mConfidentialCheck->isChecked()) c |= CalFilter::ShowConfidential; | ||
262 | |||
263 | filter->setCriteria(c); | ||
264 | |||
265 | QStringList categoryList; | ||
266 | for(uint i=0;i<mEditor->mCatList->count();++i) { | ||
267 | categoryList.append(mEditor->mCatList->text(i)); | ||
268 | } | ||
269 | filter->setCategoryList(categoryList); | ||
270 | } | ||