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/koeditorgeneraltodo.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'korganizer/koeditorgeneraltodo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeditorgeneraltodo.cpp | 467 |
1 files changed, 467 insertions, 0 deletions
diff --git a/korganizer/koeditorgeneraltodo.cpp b/korganizer/koeditorgeneraltodo.cpp new file mode 100644 index 0000000..57837bb --- a/dev/null +++ b/korganizer/koeditorgeneraltodo.cpp | |||
@@ -0,0 +1,467 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2000,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 <qtooltip.h> | ||
25 | #include <qfiledialog.h> | ||
26 | #include <qlayout.h> | ||
27 | #include <qvbox.h> | ||
28 | #include <qbuttongroup.h> | ||
29 | #include <qvgroupbox.h> | ||
30 | #include <qwidgetstack.h> | ||
31 | #include <qdatetime.h> | ||
32 | |||
33 | #include <kglobal.h> | ||
34 | #include <klocale.h> | ||
35 | #include <kiconloader.h> | ||
36 | #include <kmessagebox.h> | ||
37 | #include <kdebug.h> | ||
38 | #include <krestrictedline.h> | ||
39 | #include <kstandarddirs.h> | ||
40 | #include <kfiledialog.h> | ||
41 | |||
42 | #include <libkcal/todo.h> | ||
43 | |||
44 | #include <libkdepim/kdateedit.h> | ||
45 | |||
46 | #include "koprefs.h" | ||
47 | #include "ktimeedit.h" | ||
48 | |||
49 | #include "koeditorgeneraltodo.h" | ||
50 | #include "kolocationbox.h" | ||
51 | #include "koeditorgeneraltodo.moc" | ||
52 | |||
53 | KOEditorGeneralTodo::KOEditorGeneralTodo(QObject* parent, | ||
54 | const char* name) | ||
55 | : KOEditorGeneral( parent, name) | ||
56 | { | ||
57 | } | ||
58 | |||
59 | KOEditorGeneralTodo::~KOEditorGeneralTodo() | ||
60 | { | ||
61 | } | ||
62 | |||
63 | void KOEditorGeneralTodo::finishSetup() | ||
64 | { | ||
65 | |||
66 | // QWidget::setTabOrder(mSummaryEdit, mLocationEdit); | ||
67 | // QWidget::setTabOrder(mLocationEdit, mDueCheck); | ||
68 | // QWidget::setTabOrder(mDueCheck, mDueDateEdit); | ||
69 | // QWidget::setTabOrder(mDueDateEdit, mDueTimeEdit); | ||
70 | // QWidget::setTabOrder(mDueTimeEdit, mStartCheck); | ||
71 | // QWidget::setTabOrder(mStartCheck, mStartDateEdit); | ||
72 | // QWidget::setTabOrder(mStartDateEdit, mStartTimeEdit); | ||
73 | // QWidget::setTabOrder(mStartTimeEdit, mTimeButton); | ||
74 | // QWidget::setTabOrder(mTimeButton, mCompletedCombo); | ||
75 | // QWidget::setTabOrder(mCompletedCombo, mPriorityCombo); | ||
76 | // QWidget::setTabOrder(mPriorityCombo, mAlarmButton); | ||
77 | // QWidget::setTabOrder(mAlarmButton, mCategoriesButton); | ||
78 | // QWidget::setTabOrder(mCategoriesButton, mSecrecyCombo); | ||
79 | // QWidget::setTabOrder(mSecrecyCombo, mDescriptionEdit); | ||
80 | mSummaryEdit->load(KOLocationBox::SUMMARYTODO); | ||
81 | mSummaryEdit->setFocus(); | ||
82 | } | ||
83 | |||
84 | void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout) | ||
85 | { | ||
86 | QBoxLayout *timeLayout = new QVBoxLayout(topLayout); | ||
87 | |||
88 | QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal, | ||
89 | i18n("Date && Time"),parent); | ||
90 | timeLayout->addWidget(timeGroupBox); | ||
91 | timeGroupBox->layout()->setSpacing( 0 ); | ||
92 | timeGroupBox->layout()->setMargin( 5 ); | ||
93 | QFrame *timeBoxFrame = new QFrame(timeGroupBox); | ||
94 | |||
95 | QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,3,3); | ||
96 | layoutTimeBox->setSpacing(topLayout->spacing()); | ||
97 | layoutTimeBox->setColStretch( 1, 1 ); | ||
98 | |||
99 | mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame); | ||
100 | layoutTimeBox->addWidget(mDueCheck,0,0); | ||
101 | connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool))); | ||
102 | connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm())); | ||
103 | |||
104 | |||
105 | mDueDateEdit = new KDateEdit(timeBoxFrame); | ||
106 | layoutTimeBox->addWidget(mDueDateEdit,0,1); | ||
107 | |||
108 | mDueTimeEdit = new KOTimeEdit(timeBoxFrame); | ||
109 | layoutTimeBox->addWidget(mDueTimeEdit,0,2); | ||
110 | |||
111 | |||
112 | mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame); | ||
113 | layoutTimeBox->addWidget(mStartCheck,1,0); | ||
114 | connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool))); | ||
115 | |||
116 | mStartDateEdit = new KDateEdit(timeBoxFrame); | ||
117 | layoutTimeBox->addWidget(mStartDateEdit,1,1); | ||
118 | |||
119 | mStartTimeEdit = new KOTimeEdit(timeBoxFrame); | ||
120 | layoutTimeBox->addWidget(mStartTimeEdit,1,2); | ||
121 | |||
122 | |||
123 | mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame); | ||
124 | layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,1); | ||
125 | |||
126 | connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool))); | ||
127 | |||
128 | // some more layouting | ||
129 | //layoutTimeBox->setColStretch(3,1); | ||
130 | } | ||
131 | |||
132 | |||
133 | void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout) | ||
134 | { | ||
135 | mCompletedCombo = new QComboBox(parent); | ||
136 | // xgettext:no-c-format | ||
137 | mCompletedCombo->insertItem(i18n(" 0 %")); | ||
138 | // xgettext:no-c-format | ||
139 | mCompletedCombo->insertItem(i18n(" 20 %")); | ||
140 | // xgettext:no-c-format | ||
141 | mCompletedCombo->insertItem(i18n(" 40 %")); | ||
142 | // xgettext:no-c-format | ||
143 | mCompletedCombo->insertItem(i18n(" 60 %")); | ||
144 | // xgettext:no-c-format | ||
145 | mCompletedCombo->insertItem(i18n(" 80 %")); | ||
146 | // xgettext:no-c-format | ||
147 | mCompletedCombo->insertItem(i18n("100 %")); | ||
148 | connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int))); | ||
149 | topLayout->addWidget(mCompletedCombo); | ||
150 | |||
151 | mCompletedLabel = new QLabel(i18n("completed"),parent); | ||
152 | topLayout->addWidget(mCompletedLabel); | ||
153 | } | ||
154 | |||
155 | void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout) | ||
156 | { | ||
157 | |||
158 | QHBox* h = new QHBox ( parent ); | ||
159 | topLayout->addWidget( h ); | ||
160 | QLabel *priorityLabel = new QLabel(i18n("Priority:"), h); | ||
161 | // topLayout->addWidget(priorityLabel); | ||
162 | |||
163 | mPriorityCombo = new QComboBox( h ); | ||
164 | mPriorityCombo->insertItem(i18n("1 (high)")); | ||
165 | mPriorityCombo->insertItem(i18n("2")); | ||
166 | mPriorityCombo->insertItem(i18n("3")); | ||
167 | mPriorityCombo->insertItem(i18n("4")); | ||
168 | mPriorityCombo->insertItem(i18n("5 (low)")); | ||
169 | //topLayout->addWidget(mPriorityCombo); | ||
170 | } | ||
171 | |||
172 | void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout) | ||
173 | { | ||
174 | QBoxLayout *statusLayout = new QHBoxLayout(topLayout); | ||
175 | |||
176 | initCompletion( parent, statusLayout ); | ||
177 | |||
178 | statusLayout->addStretch( 1 ); | ||
179 | |||
180 | initPriority( parent, statusLayout ); | ||
181 | } | ||
182 | |||
183 | void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay) | ||
184 | { | ||
185 | |||
186 | mSummaryEdit->load(KOLocationBox::SUMMARYTODO); | ||
187 | mLocationEdit->load(KOLocationBox::LOCATION); | ||
188 | KOEditorGeneral::setDefaults(allDay); | ||
189 | |||
190 | mTimeButton->setChecked( !allDay ); | ||
191 | if(mTimeButton->isChecked()) { | ||
192 | mTimeButton->setEnabled(true); | ||
193 | } | ||
194 | else { | ||
195 | mTimeButton->setEnabled(false); | ||
196 | } | ||
197 | |||
198 | enableTimeEdits( !allDay ); | ||
199 | |||
200 | mDueCheck->setChecked(false); | ||
201 | enableDueEdit(false); | ||
202 | |||
203 | alarmDisable(true); | ||
204 | |||
205 | mStartCheck->setChecked(false); | ||
206 | enableStartEdit(false); | ||
207 | |||
208 | mDueDateEdit->setDate(due.date()); | ||
209 | mDueTimeEdit->setTime(due.time()); | ||
210 | |||
211 | mStartDateEdit->setDate(QDate::currentDate()); | ||
212 | mStartTimeEdit->setTime(QTime::currentTime()); | ||
213 | |||
214 | mPriorityCombo->setCurrentItem(2); | ||
215 | mCompletedLabel->setText(i18n("completed"));; | ||
216 | mCompletedCombo->setCurrentItem(0); | ||
217 | } | ||
218 | |||
219 | void KOEditorGeneralTodo::readTodo(Todo *todo) | ||
220 | { | ||
221 | |||
222 | mSummaryEdit->load(KOLocationBox::SUMMARYTODO); | ||
223 | mLocationEdit->load(KOLocationBox::LOCATION); | ||
224 | KOEditorGeneral::readIncidence(todo); | ||
225 | |||
226 | QDateTime dueDT; | ||
227 | |||
228 | if (todo->hasDueDate()) { | ||
229 | enableAlarmEdit(true); | ||
230 | dueDT = todo->dtDue(); | ||
231 | mDueDateEdit->setDate(todo->dtDue().date()); | ||
232 | mDueTimeEdit->setTime(todo->dtDue().time()); | ||
233 | mDueCheck->setChecked(true); | ||
234 | } else { | ||
235 | alarmDisable(true); | ||
236 | mDueDateEdit->setEnabled(false); | ||
237 | mDueTimeEdit->setEnabled(false); | ||
238 | mDueDateEdit->setDate(QDate::currentDate()); | ||
239 | mDueTimeEdit->setTime(QTime::currentTime()); | ||
240 | mDueCheck->setChecked(false); | ||
241 | } | ||
242 | |||
243 | if (todo->hasStartDate()) { | ||
244 | mStartDateEdit->setDate(todo->dtStart().date()); | ||
245 | mStartTimeEdit->setTime(todo->dtStart().time()); | ||
246 | mStartCheck->setChecked(true); | ||
247 | } else { | ||
248 | mStartDateEdit->setEnabled(false); | ||
249 | mStartTimeEdit->setEnabled(false); | ||
250 | mStartDateEdit->setDate(QDate::currentDate()); | ||
251 | mStartTimeEdit->setTime(QTime::currentTime()); | ||
252 | mStartCheck->setChecked(false); | ||
253 | } | ||
254 | |||
255 | mTimeButton->setChecked( !todo->doesFloat() ); | ||
256 | |||
257 | mCompletedCombo->setCurrentItem(todo->percentComplete() / 20); | ||
258 | if (todo->isCompleted() && todo->hasCompletedDate()) { | ||
259 | mCompleted = todo->completed(); | ||
260 | } | ||
261 | setCompletedDate(); | ||
262 | |||
263 | mPriorityCombo->setCurrentItem(todo->priority()-1); | ||
264 | } | ||
265 | |||
266 | void KOEditorGeneralTodo::writeTodo(Todo *todo) | ||
267 | { | ||
268 | KOEditorGeneral::writeIncidence(todo); | ||
269 | |||
270 | // temp. until something better happens. | ||
271 | QString tmpStr; | ||
272 | |||
273 | todo->setHasDueDate(mDueCheck->isChecked()); | ||
274 | todo->setHasStartDate(mStartCheck->isChecked()); | ||
275 | |||
276 | QDate tmpDate; | ||
277 | QTime tmpTime; | ||
278 | QDateTime tmpDT; | ||
279 | if ( mTimeButton->isChecked() ) { | ||
280 | todo->setFloats(false); | ||
281 | |||
282 | // set due date/time | ||
283 | tmpDate = mDueDateEdit->date(); | ||
284 | tmpTime = mDueTimeEdit->getTime(); | ||
285 | tmpDT.setDate(tmpDate); | ||
286 | tmpDT.setTime(tmpTime); | ||
287 | todo->setDtDue(tmpDT); | ||
288 | |||
289 | // set start date/time | ||
290 | tmpDate = mStartDateEdit->date(); | ||
291 | tmpTime = mStartTimeEdit->getTime(); | ||
292 | tmpDT.setDate(tmpDate); | ||
293 | tmpDT.setTime(tmpTime); | ||
294 | todo->setDtStart(tmpDT); | ||
295 | } else { | ||
296 | todo->setFloats(true); | ||
297 | |||
298 | // need to change this. | ||
299 | tmpDate = mDueDateEdit->date(); | ||
300 | tmpTime.setHMS(0,0,0); | ||
301 | tmpDT.setDate(tmpDate); | ||
302 | tmpDT.setTime(tmpTime); | ||
303 | todo->setDtDue(tmpDT); | ||
304 | |||
305 | tmpDate = mStartDateEdit->date(); | ||
306 | tmpTime.setHMS(0,0,0); | ||
307 | tmpDT.setDate(tmpDate); | ||
308 | tmpDT.setTime(tmpTime); | ||
309 | todo->setDtStart(tmpDT); | ||
310 | } | ||
311 | |||
312 | todo->setPriority(mPriorityCombo->currentItem()+1); | ||
313 | |||
314 | // set completion state | ||
315 | todo->setPercentComplete(mCompletedCombo->currentItem() * 20); | ||
316 | |||
317 | if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) { | ||
318 | todo->setCompleted(mCompleted); | ||
319 | } | ||
320 | mSummaryEdit->save(KOLocationBox::SUMMARYTODO); | ||
321 | } | ||
322 | |||
323 | void KOEditorGeneralTodo::enableDueEdit(bool enable) | ||
324 | { | ||
325 | mDueDateEdit->setEnabled( enable ); | ||
326 | |||
327 | if(mDueCheck->isChecked() || mStartCheck->isChecked()) { | ||
328 | mTimeButton->setEnabled(true); | ||
329 | } | ||
330 | else { | ||
331 | mTimeButton->setEnabled(false); | ||
332 | mTimeButton->setChecked(false); | ||
333 | } | ||
334 | |||
335 | if (enable) { | ||
336 | mDueTimeEdit->setEnabled( mTimeButton->isChecked() ); | ||
337 | } else { | ||
338 | mDueTimeEdit->setEnabled( false ); | ||
339 | } | ||
340 | } | ||
341 | |||
342 | void KOEditorGeneralTodo::enableStartEdit( bool enable ) | ||
343 | { | ||
344 | mStartDateEdit->setEnabled( enable ); | ||
345 | |||
346 | if(mDueCheck->isChecked() || mStartCheck->isChecked()) { | ||
347 | mTimeButton->setEnabled(true); | ||
348 | } | ||
349 | else { | ||
350 | mTimeButton->setEnabled(false); | ||
351 | mTimeButton->setChecked(false); | ||
352 | } | ||
353 | |||
354 | if (enable) { | ||
355 | mStartTimeEdit->setEnabled( mTimeButton->isChecked() ); | ||
356 | } else { | ||
357 | mStartTimeEdit->setEnabled( false ); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | void KOEditorGeneralTodo::enableTimeEdits(bool enable) | ||
362 | { | ||
363 | if(mStartCheck->isChecked()) { | ||
364 | mStartTimeEdit->setEnabled( enable ); | ||
365 | } | ||
366 | if(mDueCheck->isChecked()) { | ||
367 | mDueTimeEdit->setEnabled( enable ); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | void KOEditorGeneralTodo::showAlarm() | ||
372 | { | ||
373 | if ( mDueCheck->isChecked() ) { | ||
374 | alarmDisable(false); | ||
375 | } | ||
376 | else { | ||
377 | alarmDisable(true); | ||
378 | } | ||
379 | } | ||
380 | |||
381 | bool KOEditorGeneralTodo::validateInput() | ||
382 | { | ||
383 | if (mDueCheck->isChecked()) { | ||
384 | if (!mDueDateEdit->inputIsValid()) { | ||
385 | KMessageBox::sorry(0,i18n("Please specify a valid due date.")); | ||
386 | return false; | ||
387 | } | ||
388 | if (mTimeButton->isChecked()) { | ||
389 | if (!mDueTimeEdit->inputIsValid()) { | ||
390 | KMessageBox::sorry(0,i18n("Please specify a valid due time.")); | ||
391 | return false; | ||
392 | } | ||
393 | } | ||
394 | } | ||
395 | |||
396 | if (mStartCheck->isChecked()) { | ||
397 | if (!mStartDateEdit->inputIsValid()) { | ||
398 | KMessageBox::sorry(0,i18n("Please specify a valid start date.")); | ||
399 | return false; | ||
400 | } | ||
401 | if (mTimeButton->isChecked()) { | ||
402 | if (!mStartTimeEdit->inputIsValid()) { | ||
403 | KMessageBox::sorry(0,i18n("Please specify a valid start time.")); | ||
404 | return false; | ||
405 | } | ||
406 | } | ||
407 | } | ||
408 | |||
409 | if (mStartCheck->isChecked() && mDueCheck->isChecked()) { | ||
410 | QDateTime startDate; | ||
411 | QDateTime dueDate; | ||
412 | startDate.setDate(mStartDateEdit->date()); | ||
413 | dueDate.setDate(mDueDateEdit->date()); | ||
414 | if (mTimeButton->isChecked()) { | ||
415 | startDate.setTime(mStartTimeEdit->getTime()); | ||
416 | dueDate.setTime(mDueTimeEdit->getTime()); | ||
417 | } | ||
418 | if (startDate > dueDate) { | ||
419 | KMessageBox::sorry(0, | ||
420 | i18n("The start date cannot be after the due date.")); | ||
421 | return false; | ||
422 | } | ||
423 | } | ||
424 | |||
425 | return KOEditorGeneral::validateInput(); | ||
426 | } | ||
427 | |||
428 | void KOEditorGeneralTodo::completedChanged(int index) | ||
429 | { | ||
430 | if (index == 5) { | ||
431 | mCompleted = QDateTime::currentDateTime(); | ||
432 | } | ||
433 | setCompletedDate(); | ||
434 | } | ||
435 | |||
436 | void KOEditorGeneralTodo::setCompletedDate() | ||
437 | { | ||
438 | if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) { | ||
439 | mCompletedLabel->setText(i18n("completed on %1") | ||
440 | .arg(KGlobal::locale()->formatDateTime(mCompleted))); | ||
441 | } else { | ||
442 | mCompletedLabel->setText(i18n("completed")); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | void KOEditorGeneralTodo::modified (Todo* todo, int modification) | ||
447 | { | ||
448 | switch (modification) { | ||
449 | case KOGlobals::PRIORITY_MODIFIED: | ||
450 | mPriorityCombo->setCurrentItem(todo->priority()-1); | ||
451 | break; | ||
452 | case KOGlobals::COMPLETION_MODIFIED: | ||
453 | mCompletedCombo->setCurrentItem(todo->percentComplete() / 20); | ||
454 | if (todo->isCompleted() && todo->hasCompletedDate()) { | ||
455 | mCompleted = todo->completed(); | ||
456 | } | ||
457 | setCompletedDate(); | ||
458 | break; | ||
459 | case KOGlobals::CATEGORY_MODIFIED: | ||
460 | setCategories (todo->categoriesStr ()); | ||
461 | break; | ||
462 | case KOGlobals::UNKNOWN_MODIFIED: // fall through | ||
463 | default: | ||
464 | readTodo( todo ); | ||
465 | break; | ||
466 | } | ||
467 | } | ||