korganizer

koeditorgeneraltodo.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqtooltip.h>
26 #include <tqfiledialog.h>
27 #include <tqlayout.h>
28 #include <tqvbox.h>
29 #include <tqbuttongroup.h>
30 #include <tqvgroupbox.h>
31 #include <tqwidgetstack.h>
32 #include <tqdatetime.h>
33 #include <tqcheckbox.h>
34 #include <tqlabel.h>
35 #include <tqspinbox.h>
36 #include <tqpushbutton.h>
37 #include <tqwhatsthis.h>
38 
39 #include <tdeglobal.h>
40 #include <tdelocale.h>
41 #include <tdemessagebox.h>
42 #include <kdebug.h>
43 #include <kstandarddirs.h>
44 #include <tdefiledialog.h>
45 #include <ktextedit.h>
46 
47 #include <libkcal/incidenceformatter.h>
48 #include <libkcal/todo.h>
49 
50 #include <libtdepim/kdateedit.h>
51 
52 #include "koprefs.h"
53 #include "koglobals.h"
54 #include "ktimeedit.h"
55 
56 #include "koeditorgeneraltodo.h"
57 #include "koeditorgeneraltodo.moc"
58 
59 KOEditorGeneralTodo::KOEditorGeneralTodo( TQObject *parent, const char *name )
60  : KOEditorGeneral( parent, name )
61 {
62  setType( "Todo" );
63 }
64 
65 KOEditorGeneralTodo::~KOEditorGeneralTodo()
66 {
67 }
68 
69 void KOEditorGeneralTodo::finishSetup()
70 {
71  TQWidget::setTabOrder( mSummaryEdit, mLocationEdit );
72  TQWidget::setTabOrder( mLocationEdit, mStartCheck );
73  TQWidget::setTabOrder( mStartCheck, mStartDateEdit );
74  TQWidget::setTabOrder( mStartDateEdit, mStartTimeEdit );
75  TQWidget::setTabOrder( mStartTimeEdit, mDueCheck );
76  TQWidget::setTabOrder( mDueCheck, mDueDateEdit );
77  TQWidget::setTabOrder( mDueDateEdit, mDueTimeEdit );
78  TQWidget::setTabOrder( mDueTimeEdit, mTimeButton );
79  TQWidget::setTabOrder( mTimeButton, mRecEditButton );
80  TQWidget::setTabOrder( mRecEditButton, mCompletedToggle );
81  TQWidget::setTabOrder( mCompletedToggle, mCompletedCombo );
82  TQWidget::setTabOrder( mCompletedCombo, mPriorityCombo );
83  TQWidget::setTabOrder( mPriorityCombo, mAlarmButton );
84  TQWidget::setTabOrder( mAlarmButton, mAlarmTimeEdit );
85  TQWidget::setTabOrder( mAlarmTimeEdit, mAlarmIncrCombo );
86  TQWidget::setTabOrder( mAlarmIncrCombo, mAlarmAdvancedButton );
87  TQWidget::setTabOrder( mAlarmAdvancedButton, mDescriptionEdit );
88  TQWidget::setTabOrder( mDescriptionEdit, mCategoriesButton );
89  TQWidget::setTabOrder( mCategoriesButton, mSecrecyCombo );
90 
91  mSummaryEdit->setFocus();
92 }
93 
94 void KOEditorGeneralTodo::initTime(TQWidget *parent,TQBoxLayout *topLayout)
95 {
96  kdDebug(5850) << k_funcinfo << endl;
97  TQBoxLayout *timeLayout = new TQVBoxLayout(topLayout);
98 
99  TQGroupBox *timeGroupBox = new TQGroupBox(1,TQt::Horizontal,
100  i18n("Date && Time"),parent);
101  timeLayout->addWidget(timeGroupBox);
102 
103  TQFrame *timeBoxFrame = new TQFrame(timeGroupBox);
104  TQWhatsThis::add( timeBoxFrame,
105  i18n("Sets options for due and start dates and times "
106  "for this to-do.") );
107 
108  TQGridLayout *layoutTimeBox = new TQGridLayout(timeBoxFrame,1,1);
109  layoutTimeBox->setSpacing(topLayout->spacing());
110 
111 
112  TQString whatsThis = i18n("Sets the start date for this to-do");
113  mStartCheck = new TQCheckBox(i18n("Sta&rt:"),timeBoxFrame);
114  TQWhatsThis::add( mStartCheck, whatsThis );
115  layoutTimeBox->addWidget(mStartCheck,0,0);
116  connect(mStartCheck,TQ_SIGNAL(toggled(bool)),TQ_SLOT(enableStartEdit(bool)));
117  connect(mStartCheck,TQ_SIGNAL(toggled(bool)),TQ_SLOT(startDateModified()));
118 
119  mStartDateEdit = new KDateEdit(timeBoxFrame);
120  TQWhatsThis::add( mStartDateEdit, whatsThis );
121  layoutTimeBox->addWidget(mStartDateEdit,0,1);
122  connect(mStartDateEdit,TQ_SIGNAL(dateChanged(const TQDate&)),TQ_SLOT(startDateModified()));
123 
124  mStartTimeEdit = new KTimeEdit(timeBoxFrame);
125  TQWhatsThis::add( mStartTimeEdit,
126  i18n("Sets the start time for this to-do.") );
127  layoutTimeBox->addWidget(mStartTimeEdit,0,2);
128  connect(mStartTimeEdit,TQ_SIGNAL(timeChanged(TQTime)),TQ_SLOT(startDateModified()));
129 
130  whatsThis = i18n("Sets the due date for this to-do.");
131  mDueCheck = new TQCheckBox(i18n("&Due:"),timeBoxFrame);
132  TQWhatsThis::add( mDueCheck, whatsThis );
133  layoutTimeBox->addWidget(mDueCheck,1,0);
134  connect(mDueCheck,TQ_SIGNAL(toggled(bool)),TQ_SLOT(enableDueEdit(bool)));
135  connect(mDueCheck,TQ_SIGNAL(toggled(bool)),TQ_SIGNAL(dueDateEditToggle(bool)));
136  connect(mDueCheck,TQ_SIGNAL(toggled(bool)),TQ_SLOT(dateChanged()));
137 
138  mDueDateEdit = new KDateEdit(timeBoxFrame);
139  TQWhatsThis::add( mDueDateEdit, whatsThis );
140  layoutTimeBox->addWidget(mDueDateEdit,1,1);
141  connect(mDueDateEdit,TQ_SIGNAL(dateChanged(const TQDate&)),TQ_SLOT(dateChanged()));
142 
143  mDueTimeEdit = new KTimeEdit(timeBoxFrame);
144  TQWhatsThis::add( mDueTimeEdit,
145  i18n("Sets the due time for this to-do.") );
146  layoutTimeBox->addWidget(mDueTimeEdit,1,2);
147  connect(mDueTimeEdit,TQ_SIGNAL(timeChanged( TQTime )),TQ_SLOT(dateChanged()));
148 
149  mTimeButton = new TQCheckBox(i18n("Ti&me associated"),timeBoxFrame);
150  TQWhatsThis::add( mTimeButton,
151  i18n("Sets whether or not this to-do's start and due dates "
152  "have times associated with them.") );
153  layoutTimeBox->addWidget( mTimeButton, 0, 3 );
154  connect(mTimeButton,TQ_SIGNAL(toggled(bool)),TQ_SLOT(enableTimeEdits(bool)));
155  connect(mTimeButton,TQ_SIGNAL(toggled(bool)),TQ_SLOT(dateChanged()));
156 
157  TQLabel *label = new TQLabel( i18n( "Recurrence:" ), timeBoxFrame );
158  layoutTimeBox->addWidget( label, 3, 0 );
159  TQBoxLayout *recLayout = new TQHBoxLayout();
160  layoutTimeBox->addMultiCellLayout( recLayout, 3, 3, 1, 4 );
161  mRecEditButton = new TQPushButton( timeBoxFrame );
162  mRecEditButton->setIconSet( KOGlobals::self()->smallIconSet( "recur", 16 ) );
163  recLayout->addWidget( mRecEditButton );
164  connect( mRecEditButton, TQ_SIGNAL(clicked()), TQ_SIGNAL(editRecurrence()) );
165  mRecEditLabel = new TQLabel( TQString(), timeBoxFrame );
166  recLayout->addWidget( mRecEditLabel );
167  recLayout->addStretch( 1 );
168 
169  label = new TQLabel( i18n("Reminder:"), timeBoxFrame );
170  layoutTimeBox->addWidget( label, 4, 0 );
171  TQBoxLayout *alarmLineLayout = new TQHBoxLayout();
172  layoutTimeBox->addMultiCellLayout( alarmLineLayout, 4, 4, 1, 4 );
173  initAlarm( timeBoxFrame, alarmLineLayout );
174  alarmLineLayout->addStretch( 1 );
175 
176  // some more layouting
177  layoutTimeBox->setColStretch( 3, 1 );
178 
179  TQBoxLayout *secLayout = new TQHBoxLayout();
180  layoutTimeBox->addLayout( secLayout, 0, 4 );
181  initSecrecy( timeBoxFrame, secLayout );
182 }
183 
184 
185 void KOEditorGeneralTodo::initCompletion( TQWidget *parent, TQBoxLayout *topLayout )
186 {
187  TQHBoxLayout *completionLayout = new TQHBoxLayout( topLayout );
188 
189  TQLabel *label = new TQLabel( i18n( "&Completed:" ), parent );
190  completionLayout->addWidget( label );
191 
192  mCompletedToggle = new TQCheckBox( parent );
193  TQToolTip::add( mCompletedToggle,
194  i18n( "Toggle between 0% and 100% complete" ) );
195  TQWhatsThis::add( mCompletedToggle,
196  i18n( "Click this checkbox to toggle the completed percentage of the to-do "
197  "between 0% or 100%" ) );
198  connect( mCompletedToggle, TQ_SIGNAL(clicked()), TQ_SLOT(completedChanged()) );
199  completionLayout->addWidget( mCompletedToggle );
200  label->setBuddy( mCompletedToggle );
201 
202  mCompletedCombo = new TQComboBox( parent );
203  TQToolTip::add( mCompletedCombo,
204  i18n( "Select the completed percentage" ) );
205  TQWhatsThis::add( mCompletedCombo,
206  i18n( "Use this combobox to set the completion percentage of the to-do." ) );
207  for ( int i = 0; i <= 100; i+=10 ) {
208  // xgettext:no-c-format
209  TQString label = i18n( "Percent complete", "%1 %" ).arg( i );
210  mCompletedCombo->insertItem( label );
211  }
212  connect( mCompletedCombo, TQ_SIGNAL(activated(int)), TQ_SLOT(completedChanged(int)) );
213  completionLayout->addWidget( mCompletedCombo );
214 
215  mCompletedLabel = new TQLabel( i18n( "completed on", "on" ), parent );
216  mCompletedLabel->hide();
217  completionLayout->addWidget( mCompletedLabel );
218 
219  mCompletionDateEdit = new KDateEdit( parent );
220  mCompletionDateEdit->hide();
221  completionLayout->addWidget( mCompletionDateEdit );
222 
223  mCompletionTimeEdit = new KTimeEdit( parent, TQTime() );
224  mCompletionTimeEdit->hide();
225  completionLayout->addWidget( mCompletionTimeEdit );
226 }
227 
228 void KOEditorGeneralTodo::initPriority(TQWidget *parent, TQBoxLayout *topLayout)
229 {
230  TQLabel *priorityLabel = new TQLabel( i18n( "&Priority:" ), parent );
231  topLayout->addWidget( priorityLabel );
232 
233  mPriorityCombo = new TQComboBox( parent );
234  TQToolTip::add( mPriorityCombo,
235  i18n( "Set the priority of the to-do" ) );
236  TQWhatsThis::add( mPriorityCombo,
237  i18n( "Sets the priority of this to-do on a scale from one to nine, "
238  "with one being the highest priority, five being a medium priority, "
239  "and nine being the lowest. In programs that have a different scale, "
240  "the numbers will be adjusted to match the appropriate scale." ) );
241  mPriorityCombo->insertItem( i18n( "unspecified" ) );
242  mPriorityCombo->insertItem( i18n( "1 (highest)" ) );
243  mPriorityCombo->insertItem( i18n( "2" ) );
244  mPriorityCombo->insertItem( i18n( "3" ) );
245  mPriorityCombo->insertItem( i18n( "4" ) );
246  mPriorityCombo->insertItem( i18n( "5 (medium)" ) );
247  mPriorityCombo->insertItem( i18n( "6" ) );
248  mPriorityCombo->insertItem( i18n( "7" ) );
249  mPriorityCombo->insertItem( i18n( "8" ) );
250  mPriorityCombo->insertItem( i18n( "9 (lowest)" ) );
251  topLayout->addWidget( mPriorityCombo );
252  priorityLabel->setBuddy( mPriorityCombo );
253 }
254 
255 void KOEditorGeneralTodo::iniStatus(TQWidget *parent,TQBoxLayout *topLayout)
256 {
257  TQBoxLayout *statusLayout = new TQHBoxLayout(topLayout);
258 
259  initCompletion( parent, statusLayout );
260 
261  statusLayout->addStretch( 1 );
262 
263  initPriority( parent, statusLayout );
264 }
265 
266 void KOEditorGeneralTodo::setDefaults( const TQDateTime &due, bool allDay )
267 {
268  kdDebug(5850) << k_funcinfo << due <<endl;
269  KOEditorGeneral::setDefaults(allDay);
270 
271  mTimeButton->setChecked( !allDay );
272  mTimeButton->setEnabled( mTimeButton->isChecked() /* i.e. !allDay */ );
273 
274  enableTimeEdits( !allDay );
275 
276  mDueCheck->setChecked( due.isValid() );
277  enableDueEdit( due.isValid() );
278 
279  mStartCheck->setChecked(false);
280  enableStartEdit(false);
281 
282  if ( due.isValid() ) {
283  mDueDateEdit->setDate( due.date() );
284  mDueTimeEdit->setTime( due.time() );
285  } else {
286  // Make it due tomorrow.
287  mDueDateEdit->setDate( TQDate::currentDate().addDays(1) );
288  mDueTimeEdit->setTime( TQTime::currentTime() );
289  }
290 
291  if ( !due.isValid() || (TQDateTime::currentDateTime() < due) ) {
292  mStartDateEdit->setDate( TQDate::currentDate() );
293  mStartTimeEdit->setTime( TQTime::currentTime() );
294  } else {
295  mStartDateEdit->setDate( due.date().addDays( -1 ) );
296  mStartTimeEdit->setTime( due.time() );
297  }
298  mStartDateModified = false;
299 
300  mPriorityCombo->setCurrentItem( 5 );
301 
302  mCompletedToggle->setChecked( false );
303  mCompletedCombo->setCurrentItem( 0 );
304 }
305 
306 void KOEditorGeneralTodo::readTodo(Todo *todo, Calendar *calendar, const TQDate &date )
307 {
308  KOEditorGeneral::readIncidence(todo, calendar);
309 
310  TQDateTime dueDT;
311 
312  if (todo->hasDueDate()) {
313  dueDT = todo->dtDue();
314  if ( todo->doesRecur() && date.isValid() ) {
315  TQDateTime dt( date, TQTime( 0, 0, 0 ) );
316  dt = dt.addSecs( -1 );
317  dueDT.setDate( todo->recurrence()->getNextDateTime( dt ).date() );
318  }
319  mDueDateEdit->setDate(dueDT.date());
320  mDueTimeEdit->setTime(dueDT.time());
321  mDueCheck->setChecked(true);
322  } else {
323  mDueDateEdit->setEnabled(false);
324  mDueTimeEdit->setEnabled(false);
325  mDueDateEdit->setDate(TQDate::currentDate());
326  mDueTimeEdit->setTime(TQTime::currentTime());
327  mDueCheck->setChecked(false);
328  }
329 
330  if (todo->hasStartDate()) {
331  TQDateTime startDT = todo->dtStart();
332  if ( todo->doesRecur() && date.isValid() && todo->hasDueDate() ) {
333  int days = todo->dtStart( true ).daysTo( todo->dtDue( true ) );
334  startDT.setDate( date.addDays( -days ) );
335  }
336  mStartDateEdit->setDate(startDT.date());
337  mStartTimeEdit->setTime(startDT.time());
338  mStartCheck->setChecked(true);
339  } else {
340  mStartDateEdit->setEnabled(false);
341  mStartTimeEdit->setEnabled(false);
342  mStartDateEdit->setDate(TQDate::currentDate());
343  mStartTimeEdit->setTime(TQTime::currentTime());
344  mStartCheck->setChecked(false);
345  }
346 
347  mTimeButton->setChecked( !todo->doesFloat() );
348 
349  updateRecurrenceSummary( todo );
350 
351  mAlreadyComplete = false;
352  mCompletedCombo->setCurrentItem( todo->percentComplete() / 10 );
353  if ( todo->isCompleted() && todo->hasCompletedDate() ) {
354  mCompletedDateTime = todo->completed();
355  mCompletedToggle->setChecked( true );
356  mAlreadyComplete = true;
357  }
358  setCompletedDate();
359 
360  mPriorityCombo->setCurrentItem( todo->priority() );
361  mStartDateModified = false;
362 }
363 
364 void KOEditorGeneralTodo::writeTodo(Todo *todo)
365 {
366  KOEditorGeneral::writeIncidence(todo);
367 
368  // temp. until something better happens.
369  TQString tmpStr;
370 
371  todo->setHasDueDate(mDueCheck->isChecked());
372  todo->setHasStartDate(mStartCheck->isChecked());
373 
374  TQDate tmpSDate, tmpDDate;
375  TQTime tmpSTime, tmpDTime;
376  TQDateTime tmpStartDT, tmpDueDT;
377  if ( mTimeButton->isChecked() ) {
378  todo->setFloats(false);
379 
380  // set due date/time
381  tmpDDate = mDueDateEdit->date();
382  tmpDTime = mDueTimeEdit->getTime();
383  tmpDueDT.setDate(tmpDDate);
384  tmpDueDT.setTime(tmpDTime);
385 
386  // set start date/time
387  if ( mStartCheck->isChecked() ) {
388  tmpSDate = mStartDateEdit->date();
389  tmpSTime = mStartTimeEdit->getTime();
390  tmpStartDT.setDate(tmpSDate);
391  tmpStartDT.setTime(tmpSTime);
392  } else {
393  tmpStartDT = tmpDueDT;
394  }
395  } else {
396  todo->setFloats(true);
397 
398  // need to change this.
399  tmpDDate = mDueDateEdit->date();
400  tmpDTime.setHMS(0,0,0);
401  tmpDueDT.setDate(tmpDDate);
402  tmpDueDT.setTime(tmpDTime);
403 
404  if ( mStartCheck->isChecked() ) {
405  tmpSDate = mStartDateEdit->date();
406  tmpSTime.setHMS(0,0,0);
407  tmpStartDT.setDate(tmpSDate);
408  tmpStartDT.setTime(tmpSTime);
409  } else {
410  tmpStartDT = tmpDueDT;
411  }
412  }
413 
414  // TODO: Don't use the due date for the recurrence, but the start date (cf. rfc 2445)
415  if ( todo->doesRecur() && !mStartDateModified ) {
416  todo->setDtDue( tmpDueDT );
417  } else {
418  todo->setDtDue( tmpDueDT, true );
419  todo->setDtStart( tmpStartDT );
420  todo->setDtRecurrence( tmpDueDT );
421  }
422 
423  todo->setPriority( mPriorityCombo->currentItem() );
424 
425  // set completion state
426  todo->setPercentComplete( mCompletedCombo->currentItem() * 10 );
427 
428  if (mCompletedCombo->currentItem() == 10 && mCompletedDateTime.isValid()) {
429  TQDateTime completed( mCompletionDateEdit->date(),
430  mCompletionTimeEdit->getTime() );
431  int difference = mCompletedDateTime.secsTo( completed );
432  if ( (difference < 60) && (difference > -60) &&
433  (completed.time().minute() == mCompletedDateTime.time().minute() ) ) {
434  // completion time wasn't changed substantially (only the seconds
435  // truncated, but that's an effect done by KTimeEdit automatically).
436  completed = mCompletedDateTime;
437  }
438  todo->setCompleted( completed );
439  }
440 }
441 
442 void KOEditorGeneralTodo::enableDueEdit(bool enable)
443 {
444  mDueDateEdit->setEnabled( enable );
445 
446  if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
447  mTimeButton->setEnabled(true);
448  } else {
449  mTimeButton->setEnabled(false);
450  }
451 
452  if (enable) {
453  mDueTimeEdit->setEnabled( mTimeButton->isChecked() );
454  } else {
455  mDueTimeEdit->setEnabled( false );
456  }
457 }
458 
459 void KOEditorGeneralTodo::enableStartEdit( bool enable )
460 {
461  mStartDateEdit->setEnabled( enable );
462 
463  if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
464  mTimeButton->setEnabled(true);
465  }
466  else {
467  mTimeButton->setEnabled(false);
468  mTimeButton->setChecked(false);
469  }
470 
471  if (enable) {
472  mStartTimeEdit->setEnabled( mTimeButton->isChecked() );
473  } else {
474  mStartTimeEdit->setEnabled( false );
475  }
476 }
477 
478 void KOEditorGeneralTodo::enableTimeEdits(bool enable)
479 {
480  if(mStartCheck->isChecked()) {
481  mStartTimeEdit->setEnabled( enable );
482  }
483  if(mDueCheck->isChecked()) {
484  mDueTimeEdit->setEnabled( enable );
485  }
486 }
487 
488 bool KOEditorGeneralTodo::validateInput()
489 {
490  if (mDueCheck->isChecked()) {
491  if (!mDueDateEdit->date().isValid()) {
492  KMessageBox::sorry(0,i18n("Please specify a valid due date."));
493  return false;
494  }
495  if (mTimeButton->isChecked()) {
496  if (!mDueTimeEdit->inputIsValid()) {
497  KMessageBox::sorry(0,i18n("Please specify a valid due time."));
498  return false;
499  }
500  }
501  }
502 
503  if (mStartCheck->isChecked()) {
504  if (!mStartDateEdit->date().isValid()) {
505  KMessageBox::sorry(0,i18n("Please specify a valid start date."));
506  return false;
507  }
508  if (mTimeButton->isChecked()) {
509  if (!mStartTimeEdit->inputIsValid()) {
510  KMessageBox::sorry(0,i18n("Please specify a valid start time."));
511  return false;
512  }
513  }
514  }
515 
516  if (mStartCheck->isChecked() && mDueCheck->isChecked()) {
517  TQDateTime startDate;
518  TQDateTime dueDate;
519  startDate.setDate(mStartDateEdit->date());
520  dueDate.setDate(mDueDateEdit->date());
521  if (mTimeButton->isChecked()) {
522  startDate.setTime(mStartTimeEdit->getTime());
523  dueDate.setTime(mDueTimeEdit->getTime());
524  }
525  if (startDate > dueDate) {
526  KMessageBox::sorry(0,
527  i18n("The start date cannot be after the due date."));
528  return false;
529  }
530  }
531 
532  return KOEditorGeneral::validateInput();
533 }
534 
535 void KOEditorGeneralTodo::updateRecurrenceSummary( Todo *todo )
536 {
537  if ( todo->doesRecur() ) {
538  mRecEditLabel->setText( IncidenceFormatter::recurrenceString( todo ) );
539  } else {
540  mRecEditLabel->setText( TQString() );
541  }
542 }
543 
544 void KOEditorGeneralTodo::completedChanged( int index )
545 {
546  if ( index == 10 ) {
547  mCompletedToggle->setChecked( true );
548  mCompletedDateTime = TQDateTime::currentDateTime();
549  } else {
550  mCompletedToggle->setChecked( false );
551  }
552  setCompletedDate();
553 }
554 
555 void KOEditorGeneralTodo::completedChanged()
556 {
557  if ( mCompletedToggle->isChecked() ) {
558  mCompletedCombo->setCurrentItem( 10 );
559  mCompletedDateTime = TQDateTime::currentDateTime();
560  } else {
561  mCompletedCombo->setCurrentItem( 0 );
562  }
563  setCompletedDate();
564 }
565 
566 void KOEditorGeneralTodo::dateChanged()
567 {
568  TDELocale *l = TDEGlobal::locale();
569  TQString dateTimeStr = "";
570 
571  if ( mStartCheck->isChecked() ) {
572  dateTimeStr += i18n("Start: %1").arg(
573  l->formatDate( mStartDateEdit->date() ) );
574  if ( mTimeButton->isChecked() )
575  dateTimeStr += TQString(" %1").arg(
576  l->formatTime( mStartTimeEdit->getTime() ) );
577  }
578 
579  if ( mDueCheck->isChecked() ) {
580  dateTimeStr += i18n(" Due: %1").arg(
581  l->formatDate( mDueDateEdit->date() ) );
582  if ( mTimeButton->isChecked() )
583  dateTimeStr += TQString(" %1").arg(
584  l->formatTime( mDueTimeEdit->getTime() ) );
585  }
586 
587  emit dateTimeStrChanged( dateTimeStr );
588  TQDateTime endDt( mDueDateEdit->date(), mDueTimeEdit->getTime() );
589  emit signalDateTimeChanged( endDt, endDt );
590 }
591 
592 void KOEditorGeneralTodo::startDateModified()
593 {
594  mStartDateModified = true;
595  dateChanged();
596 }
597 
598 void KOEditorGeneralTodo::setCompletedDate()
599 {
600  if ( mCompletedCombo->currentItem() == 10 && mCompletedDateTime.isValid() ) {
601  mCompletedLabel->show();
602  mCompletionDateEdit->show();
603  mCompletionTimeEdit->show();
604  mCompletionDateEdit->setDate( mCompletedDateTime.date() );
605  mCompletionTimeEdit->setTime( mCompletedDateTime.time() );
606  } else {
607  mCompletedLabel->hide();
608  mCompletionDateEdit->hide();
609  mCompletionTimeEdit->hide();
610  }
611 }
612 
613 void KOEditorGeneralTodo::modified (Todo* todo, KOGlobals::HowChanged modification)
614 {
615  switch (modification) {
616  case KOGlobals::PRIORITY_MODIFIED:
617  mPriorityCombo->setCurrentItem( todo->priority() );
618  break;
619  case KOGlobals::COMPLETION_MODIFIED:
620  mCompletedCombo->setCurrentItem(todo->percentComplete() / 10);
621  if (todo->isCompleted() && todo->hasCompletedDate()) {
622  mCompletedDateTime = todo->completed();
623  mCompletedToggle->setChecked( true );
624  }
625  setCompletedDate();
626  break;
627  case KOGlobals::CATEGORY_MODIFIED:
628  setCategories( todo->categories() );
629  break;
630  case KOGlobals::UNKNOWN_MODIFIED: // fall through
631  default:
632  readTodo( todo, 0, TQDate() );
633  break;
634  }
635 }
bool doesFloat() const
void setPriority(int priority)
TQStringList categories() const
int priority() const
void setFloats(bool f)
bool doesRecur() const
Recurrence * recurrence() const
TQDateTime getNextDateTime(const TQDateTime &preDateTime) const
bool hasDueDate() const
bool isCompleted() const
void setDtRecurrence(const TQDateTime &dt)
bool hasStartDate() const
void setDtDue(const TQDateTime &dtDue, bool first=false)
void setCompleted(bool completed)
TQDateTime dtStart(bool first=false) const
TQDateTime completed() const
void setHasStartDate(bool hasStartDate)
void setDtStart(const TQDateTime &dtStart)
int percentComplete() const
bool hasCompletedDate() const
TQDateTime dtDue(bool first=false) const
void setHasDueDate(bool hasDueDate)
void setPercentComplete(int)