25 #include <tqtooltip.h>
26 #include <tqfiledialog.h>
29 #include <tqbuttongroup.h>
30 #include <tqvgroupbox.h>
31 #include <tqwidgetstack.h>
32 #include <tqdatetime.h>
33 #include <tqcheckbox.h>
35 #include <tqspinbox.h>
36 #include <tqpushbutton.h>
37 #include <tqwhatsthis.h>
39 #include <tdeglobal.h>
40 #include <tdelocale.h>
41 #include <tdemessagebox.h>
43 #include <kstandarddirs.h>
44 #include <tdefiledialog.h>
45 #include <ktextedit.h>
47 #include <libkcal/incidenceformatter.h>
48 #include <libkcal/todo.h>
50 #include <libtdepim/kdateedit.h>
53 #include "koglobals.h"
54 #include "ktimeedit.h"
56 #include "koeditorgeneraltodo.h"
57 #include "koeditorgeneraltodo.moc"
59 KOEditorGeneralTodo::KOEditorGeneralTodo( TQObject *parent,
const char *name )
60 : KOEditorGeneral( parent, name )
65 KOEditorGeneralTodo::~KOEditorGeneralTodo()
69 void KOEditorGeneralTodo::finishSetup()
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 );
91 mSummaryEdit->setFocus();
94 void KOEditorGeneralTodo::initTime(TQWidget *parent,TQBoxLayout *topLayout)
96 kdDebug(5850) << k_funcinfo << endl;
97 TQBoxLayout *timeLayout =
new TQVBoxLayout(topLayout);
99 TQGroupBox *timeGroupBox =
new TQGroupBox(1,TQt::Horizontal,
100 i18n(
"Date && Time"),parent);
101 timeLayout->addWidget(timeGroupBox);
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.") );
108 TQGridLayout *layoutTimeBox =
new TQGridLayout(timeBoxFrame,1,1);
109 layoutTimeBox->setSpacing(topLayout->spacing());
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()));
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()));
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()));
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()));
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()));
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()));
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()));
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 );
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 );
177 layoutTimeBox->setColStretch( 3, 1 );
179 TQBoxLayout *secLayout =
new TQHBoxLayout();
180 layoutTimeBox->addLayout( secLayout, 0, 4 );
181 initSecrecy( timeBoxFrame, secLayout );
185 void KOEditorGeneralTodo::initCompletion( TQWidget *parent, TQBoxLayout *topLayout )
187 TQHBoxLayout *completionLayout =
new TQHBoxLayout( topLayout );
189 TQLabel *label =
new TQLabel( i18n(
"&Completed:" ), parent );
190 completionLayout->addWidget( label );
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 );
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 ) {
209 TQString label = i18n(
"Percent complete",
"%1 %" ).arg( i );
210 mCompletedCombo->insertItem( label );
212 connect( mCompletedCombo, TQ_SIGNAL(activated(
int)), TQ_SLOT(completedChanged(
int)) );
213 completionLayout->addWidget( mCompletedCombo );
215 mCompletedLabel =
new TQLabel( i18n(
"completed on",
"on" ), parent );
216 mCompletedLabel->hide();
217 completionLayout->addWidget( mCompletedLabel );
219 mCompletionDateEdit =
new KDateEdit( parent );
220 mCompletionDateEdit->hide();
221 completionLayout->addWidget( mCompletionDateEdit );
223 mCompletionTimeEdit =
new KTimeEdit( parent, TQTime() );
224 mCompletionTimeEdit->hide();
225 completionLayout->addWidget( mCompletionTimeEdit );
228 void KOEditorGeneralTodo::initPriority(TQWidget *parent, TQBoxLayout *topLayout)
230 TQLabel *priorityLabel =
new TQLabel( i18n(
"&Priority:" ), parent );
231 topLayout->addWidget( priorityLabel );
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 );
255 void KOEditorGeneralTodo::iniStatus(TQWidget *parent,TQBoxLayout *topLayout)
257 TQBoxLayout *statusLayout =
new TQHBoxLayout(topLayout);
259 initCompletion( parent, statusLayout );
261 statusLayout->addStretch( 1 );
263 initPriority( parent, statusLayout );
266 void KOEditorGeneralTodo::setDefaults(
const TQDateTime &due,
bool allDay )
268 kdDebug(5850) << k_funcinfo << due <<endl;
269 KOEditorGeneral::setDefaults(allDay);
271 mTimeButton->setChecked( !allDay );
272 mTimeButton->setEnabled( mTimeButton->isChecked() );
274 enableTimeEdits( !allDay );
276 mDueCheck->setChecked( due.isValid() );
277 enableDueEdit( due.isValid() );
279 mStartCheck->setChecked(
false);
280 enableStartEdit(
false);
282 if ( due.isValid() ) {
283 mDueDateEdit->setDate( due.date() );
284 mDueTimeEdit->setTime( due.time() );
287 mDueDateEdit->setDate( TQDate::currentDate().addDays(1) );
288 mDueTimeEdit->setTime( TQTime::currentTime() );
291 if ( !due.isValid() || (TQDateTime::currentDateTime() < due) ) {
292 mStartDateEdit->setDate( TQDate::currentDate() );
293 mStartTimeEdit->setTime( TQTime::currentTime() );
295 mStartDateEdit->setDate( due.date().addDays( -1 ) );
296 mStartTimeEdit->setTime( due.time() );
298 mStartDateModified =
false;
300 mPriorityCombo->setCurrentItem( 5 );
302 mCompletedToggle->setChecked(
false );
303 mCompletedCombo->setCurrentItem( 0 );
306 void KOEditorGeneralTodo::readTodo(
Todo *todo,
Calendar *calendar,
const TQDate &date )
308 KOEditorGeneral::readIncidence(todo, calendar);
313 dueDT = todo->
dtDue();
314 if ( todo->
doesRecur() && date.isValid() ) {
315 TQDateTime dt( date, TQTime( 0, 0, 0 ) );
316 dt = dt.addSecs( -1 );
319 mDueDateEdit->setDate(dueDT.date());
320 mDueTimeEdit->setTime(dueDT.time());
321 mDueCheck->setChecked(
true);
323 mDueDateEdit->setEnabled(
false);
324 mDueTimeEdit->setEnabled(
false);
325 mDueDateEdit->setDate(TQDate::currentDate());
326 mDueTimeEdit->setTime(TQTime::currentTime());
327 mDueCheck->setChecked(
false);
331 TQDateTime startDT = todo->
dtStart();
333 int days = todo->
dtStart(
true ).daysTo( todo->
dtDue(
true ) );
334 startDT.setDate( date.addDays( -days ) );
336 mStartDateEdit->setDate(startDT.date());
337 mStartTimeEdit->setTime(startDT.time());
338 mStartCheck->setChecked(
true);
340 mStartDateEdit->setEnabled(
false);
341 mStartTimeEdit->setEnabled(
false);
342 mStartDateEdit->setDate(TQDate::currentDate());
343 mStartTimeEdit->setTime(TQTime::currentTime());
344 mStartCheck->setChecked(
false);
347 mTimeButton->setChecked( !todo->
doesFloat() );
349 updateRecurrenceSummary( todo );
351 mAlreadyComplete =
false;
355 mCompletedToggle->setChecked(
true );
356 mAlreadyComplete =
true;
360 mPriorityCombo->setCurrentItem( todo->
priority() );
361 mStartDateModified =
false;
364 void KOEditorGeneralTodo::writeTodo(
Todo *todo)
366 KOEditorGeneral::writeIncidence(todo);
374 TQDate tmpSDate, tmpDDate;
375 TQTime tmpSTime, tmpDTime;
376 TQDateTime tmpStartDT, tmpDueDT;
377 if ( mTimeButton->isChecked() ) {
381 tmpDDate = mDueDateEdit->date();
382 tmpDTime = mDueTimeEdit->getTime();
383 tmpDueDT.setDate(tmpDDate);
384 tmpDueDT.setTime(tmpDTime);
387 if ( mStartCheck->isChecked() ) {
388 tmpSDate = mStartDateEdit->date();
389 tmpSTime = mStartTimeEdit->getTime();
390 tmpStartDT.setDate(tmpSDate);
391 tmpStartDT.setTime(tmpSTime);
393 tmpStartDT = tmpDueDT;
399 tmpDDate = mDueDateEdit->date();
400 tmpDTime.setHMS(0,0,0);
401 tmpDueDT.setDate(tmpDDate);
402 tmpDueDT.setTime(tmpDTime);
404 if ( mStartCheck->isChecked() ) {
405 tmpSDate = mStartDateEdit->date();
406 tmpSTime.setHMS(0,0,0);
407 tmpStartDT.setDate(tmpSDate);
408 tmpStartDT.setTime(tmpSTime);
410 tmpStartDT = tmpDueDT;
415 if ( todo->
doesRecur() && !mStartDateModified ) {
423 todo->
setPriority( mPriorityCombo->currentItem() );
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() ) ) {
436 completed = mCompletedDateTime;
442 void KOEditorGeneralTodo::enableDueEdit(
bool enable)
444 mDueDateEdit->setEnabled( enable );
446 if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
447 mTimeButton->setEnabled(
true);
449 mTimeButton->setEnabled(
false);
453 mDueTimeEdit->setEnabled( mTimeButton->isChecked() );
455 mDueTimeEdit->setEnabled(
false );
459 void KOEditorGeneralTodo::enableStartEdit(
bool enable )
461 mStartDateEdit->setEnabled( enable );
463 if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
464 mTimeButton->setEnabled(
true);
467 mTimeButton->setEnabled(
false);
468 mTimeButton->setChecked(
false);
472 mStartTimeEdit->setEnabled( mTimeButton->isChecked() );
474 mStartTimeEdit->setEnabled(
false );
478 void KOEditorGeneralTodo::enableTimeEdits(
bool enable)
480 if(mStartCheck->isChecked()) {
481 mStartTimeEdit->setEnabled( enable );
483 if(mDueCheck->isChecked()) {
484 mDueTimeEdit->setEnabled( enable );
488 bool KOEditorGeneralTodo::validateInput()
490 if (mDueCheck->isChecked()) {
491 if (!mDueDateEdit->date().isValid()) {
492 KMessageBox::sorry(0,i18n(
"Please specify a valid due date."));
495 if (mTimeButton->isChecked()) {
496 if (!mDueTimeEdit->inputIsValid()) {
497 KMessageBox::sorry(0,i18n(
"Please specify a valid due time."));
503 if (mStartCheck->isChecked()) {
504 if (!mStartDateEdit->date().isValid()) {
505 KMessageBox::sorry(0,i18n(
"Please specify a valid start date."));
508 if (mTimeButton->isChecked()) {
509 if (!mStartTimeEdit->inputIsValid()) {
510 KMessageBox::sorry(0,i18n(
"Please specify a valid start time."));
516 if (mStartCheck->isChecked() && mDueCheck->isChecked()) {
517 TQDateTime startDate;
519 startDate.setDate(mStartDateEdit->date());
520 dueDate.setDate(mDueDateEdit->date());
521 if (mTimeButton->isChecked()) {
522 startDate.setTime(mStartTimeEdit->getTime());
523 dueDate.setTime(mDueTimeEdit->getTime());
525 if (startDate > dueDate) {
526 KMessageBox::sorry(0,
527 i18n(
"The start date cannot be after the due date."));
532 return KOEditorGeneral::validateInput();
535 void KOEditorGeneralTodo::updateRecurrenceSummary(
Todo *todo )
538 mRecEditLabel->setText( IncidenceFormatter::recurrenceString( todo ) );
540 mRecEditLabel->setText( TQString() );
544 void KOEditorGeneralTodo::completedChanged(
int index )
547 mCompletedToggle->setChecked(
true );
548 mCompletedDateTime = TQDateTime::currentDateTime();
550 mCompletedToggle->setChecked(
false );
555 void KOEditorGeneralTodo::completedChanged()
557 if ( mCompletedToggle->isChecked() ) {
558 mCompletedCombo->setCurrentItem( 10 );
559 mCompletedDateTime = TQDateTime::currentDateTime();
561 mCompletedCombo->setCurrentItem( 0 );
566 void KOEditorGeneralTodo::dateChanged()
568 TDELocale *l = TDEGlobal::locale();
569 TQString dateTimeStr =
"";
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() ) );
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() ) );
587 emit dateTimeStrChanged( dateTimeStr );
588 TQDateTime endDt( mDueDateEdit->date(), mDueTimeEdit->getTime() );
589 emit signalDateTimeChanged( endDt, endDt );
592 void KOEditorGeneralTodo::startDateModified()
594 mStartDateModified =
true;
598 void KOEditorGeneralTodo::setCompletedDate()
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() );
607 mCompletedLabel->hide();
608 mCompletionDateEdit->hide();
609 mCompletionTimeEdit->hide();
613 void KOEditorGeneralTodo::modified (
Todo* todo, KOGlobals::HowChanged modification)
615 switch (modification) {
616 case KOGlobals::PRIORITY_MODIFIED:
617 mPriorityCombo->setCurrentItem( todo->
priority() );
619 case KOGlobals::COMPLETION_MODIFIED:
623 mCompletedToggle->setChecked(
true );
627 case KOGlobals::CATEGORY_MODIFIED:
630 case KOGlobals::UNKNOWN_MODIFIED:
632 readTodo( todo, 0, TQDate() );
void setPriority(int priority)
TQStringList categories() const
Recurrence * recurrence() const
TQDateTime getNextDateTime(const TQDateTime &preDateTime) 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)