25 #include <tqtooltip.h>
28 #include <tqbuttongroup.h>
29 #include <tqvgroupbox.h>
30 #include <tqwidgetstack.h>
31 #include <tqspinbox.h>
32 #include <tqdatetime.h>
34 #include <tqcheckbox.h>
35 #include <tqcombobox.h>
36 #include <tqpushbutton.h>
37 #include <tqwhatsthis.h>
40 #include <tdeglobal.h>
41 #include <tdelocale.h>
42 #include <tdemessagebox.h>
43 #include <tdefiledialog.h>
44 #include <kstandarddirs.h>
45 #include <ktextedit.h>
47 #include <libkcal/event.h>
48 #include <libkcal/incidenceformatter.h>
50 #include "ktimeedit.h"
51 #include <libtdepim/kdateedit.h>
54 #include "koglobals.h"
56 #include "koeditorgeneralevent.h"
57 #include "koeditorgeneralevent.moc"
59 KOEditorGeneralEvent::KOEditorGeneralEvent(TQObject* parent,
61 KOEditorGeneral( parent, name)
63 connect(
this, TQ_SIGNAL( dateTimesChanged(
const TQDateTime &,
const TQDateTime & )),
64 TQ_SLOT( setDuration() ) );
65 connect(
this, TQ_SIGNAL( dateTimesChanged(
const TQDateTime &,
const TQDateTime & )),
66 TQ_SLOT( emitDateTimeStr() ));
69 KOEditorGeneralEvent::~KOEditorGeneralEvent()
73 void KOEditorGeneralEvent::finishSetup()
75 TQWidget::setTabOrder( mSummaryEdit, mLocationEdit );
76 TQWidget::setTabOrder( mLocationEdit, mStartDateEdit );
77 TQWidget::setTabOrder( mStartDateEdit, mStartTimeEdit );
78 TQWidget::setTabOrder( mStartTimeEdit, mEndDateEdit );
79 TQWidget::setTabOrder( mEndDateEdit, mEndTimeEdit );
80 TQWidget::setTabOrder( mEndTimeEdit, mAlldayEventCheckbox );
81 TQWidget::setTabOrder( mAlldayEventCheckbox, mRecEditButton );
82 TQWidget::setTabOrder( mRecEditButton, mAlarmButton );
83 TQWidget::setTabOrder( mAlarmButton, mAlarmTimeEdit );
84 TQWidget::setTabOrder( mAlarmTimeEdit, mAlarmIncrCombo );
85 TQWidget::setTabOrder( mAlarmIncrCombo, mAlarmAdvancedButton );
86 TQWidget::setTabOrder( mAlarmAdvancedButton, mFreeTimeCombo );
87 TQWidget::setTabOrder( mFreeTimeCombo, mDescriptionEdit );
88 TQWidget::setTabOrder( mDescriptionEdit, mCategoriesButton );
89 TQWidget::setTabOrder( mCategoriesButton, mSecrecyCombo );
91 mSummaryEdit->setFocus();
94 void KOEditorGeneralEvent::initTime(TQWidget *parent,TQBoxLayout *topLayout)
96 TQBoxLayout *timeLayout =
new TQVBoxLayout(topLayout);
98 TQGroupBox *timeGroupBox =
new TQGroupBox(1,TQt::Horizontal,
99 i18n(
"Date && Time"),parent);
100 TQWhatsThis::add( timeGroupBox,
101 i18n(
"Sets options related to the date and time of the "
102 "event or to-do.") );
103 timeLayout->addWidget(timeGroupBox);
105 TQFrame *timeBoxFrame =
new TQFrame(timeGroupBox);
107 TQGridLayout *layoutTimeBox =
new TQGridLayout( timeBoxFrame );
108 layoutTimeBox->setSpacing(topLayout->spacing());
109 layoutTimeBox->setColStretch( 3, 1 );
111 mStartDateLabel =
new TQLabel(i18n(
"&Start:"),timeBoxFrame);
112 layoutTimeBox->addWidget(mStartDateLabel,0,0);
114 mStartDateEdit =
new KDateEdit(timeBoxFrame);
115 layoutTimeBox->addWidget(mStartDateEdit,0,1);
116 mStartDateLabel->setBuddy( mStartDateEdit );
118 mStartTimeEdit =
new KTimeEdit(timeBoxFrame);
119 layoutTimeBox->addWidget(mStartTimeEdit,0,2);
121 mEndDateLabel =
new TQLabel(i18n(
"&End:"),timeBoxFrame);
122 layoutTimeBox->addWidget(mEndDateLabel,1,0);
124 mEndDateEdit =
new KDateEdit(timeBoxFrame);
125 layoutTimeBox->addWidget(mEndDateEdit,1,1);
126 mEndDateLabel->setBuddy( mEndDateEdit );
128 mEndTimeEdit =
new KTimeEdit(timeBoxFrame);
129 layoutTimeBox->addWidget(mEndTimeEdit,1,2);
131 mAlldayEventCheckbox =
new TQCheckBox(i18n(
"All-&day"),timeBoxFrame);
132 layoutTimeBox->addWidget( mAlldayEventCheckbox, 0, 3 );
133 connect(mAlldayEventCheckbox, TQ_SIGNAL(toggled(
bool)),TQ_SLOT(associateTime(
bool)));
135 mDurationLabel =
new TQLabel( timeBoxFrame );
136 layoutTimeBox->addWidget( mDurationLabel, 1, 3 );
139 connect(mStartTimeEdit, TQ_SIGNAL(timeChanged(TQTime)),
140 this, TQ_SLOT(startTimeChanged(TQTime)));
141 connect(mEndTimeEdit, TQ_SIGNAL(timeChanged(TQTime)),
142 this, TQ_SLOT(endTimeChanged(TQTime)));
145 connect(mStartDateEdit, TQ_SIGNAL(dateChanged(
const TQDate&)),
146 this, TQ_SLOT(startDateChanged(
const TQDate&)));
147 connect(mEndDateEdit, TQ_SIGNAL(dateChanged(
const TQDate&)),
148 this, TQ_SLOT(endDateChanged(
const TQDate&)));
150 TQLabel *label =
new TQLabel( i18n(
"Recurrence:" ), timeBoxFrame );
151 layoutTimeBox->addWidget( label, 2, 0 );
152 TQBoxLayout *recLayout =
new TQHBoxLayout();
153 layoutTimeBox->addMultiCellLayout( recLayout, 2, 2, 1, 4 );
154 mRecEditButton =
new TQPushButton( timeBoxFrame );
155 mRecEditButton->setIconSet( KOGlobals::self()->smallIconSet(
"recur", 16 ) );
156 recLayout->addWidget( mRecEditButton );
157 connect( mRecEditButton, TQ_SIGNAL(clicked()), TQ_SIGNAL(editRecurrence()) );
158 mRecEditLabel =
new TQLabel( TQString(), timeBoxFrame );
159 recLayout->addWidget( mRecEditLabel );
160 recLayout->addStretch( 1 );
162 label =
new TQLabel( i18n(
"Reminder:"), timeBoxFrame );
163 layoutTimeBox->addWidget( label, 3, 0 );
164 TQBoxLayout *alarmLineLayout =
new TQHBoxLayout();
165 layoutTimeBox->addMultiCellLayout( alarmLineLayout, 3, 3, 1, 4 );
166 initAlarm( timeBoxFrame, alarmLineLayout );
167 alarmLineLayout->addStretch( 1 );
169 TQBoxLayout *secLayout =
new TQHBoxLayout();
170 layoutTimeBox->addLayout( secLayout, 0, 4 );
171 initSecrecy( timeBoxFrame, secLayout );
173 TQBoxLayout *classLayout =
new TQHBoxLayout();
174 layoutTimeBox->addLayout( classLayout, 1, 4 );
175 initClass( timeBoxFrame, classLayout );
178 void KOEditorGeneralEvent::initClass(TQWidget *parent,TQBoxLayout *topLayout)
180 TQBoxLayout *classLayout =
new TQHBoxLayout(topLayout);
182 TQLabel *freeTimeLabel =
new TQLabel(i18n(
"S&how time as:"),parent);
183 TQString whatsThis = i18n(
"Sets how this time will appear on your Free/Busy "
185 TQWhatsThis::add( freeTimeLabel, whatsThis );
186 classLayout->addWidget(freeTimeLabel);
188 mFreeTimeCombo =
new TQComboBox(
false, parent);
189 TQWhatsThis::add( mFreeTimeCombo, whatsThis );
190 mFreeTimeCombo->insertItem(i18n(
"Busy"));
191 mFreeTimeCombo->insertItem(i18n(
"Free"));
192 classLayout->addWidget(mFreeTimeCombo);
193 freeTimeLabel->setBuddy( mFreeTimeCombo );
196 void KOEditorGeneralEvent::initInvitationBar(TQWidget * parent, TQBoxLayout * layout)
198 TQBoxLayout *topLayout =
new TQHBoxLayout( layout );
199 mInvitationBar =
new TQFrame( parent );
200 mInvitationBar->setPaletteBackgroundColor( TDEGlobalSettings::alternateBackgroundColor() );
201 topLayout->addWidget( mInvitationBar );
203 TQBoxLayout *barLayout =
new TQHBoxLayout( mInvitationBar );
204 barLayout->setSpacing( layout->spacing() );
205 TQLabel *label =
new TQLabel( i18n(
"You have not yet definitely responded to this invitation." ), mInvitationBar );
206 barLayout->addWidget( label );
207 barLayout->addStretch( 1 );
208 TQPushButton *button =
new TQPushButton( i18n(
"Accept"), mInvitationBar );
209 connect( button, TQ_SIGNAL(clicked()), TQ_SIGNAL(acceptInvitation()) );
210 connect( button, TQ_SIGNAL(clicked()), mInvitationBar, TQ_SLOT(hide()) );
211 barLayout->addWidget( button );
212 button =
new TQPushButton( i18n(
"Decline"), mInvitationBar );
213 connect( button, TQ_SIGNAL(clicked()), TQ_SIGNAL(declineInvitation()) );
214 connect( button, TQ_SIGNAL(clicked()), mInvitationBar, TQ_SLOT(hide()) );
215 barLayout->addWidget( button );
217 mInvitationBar->hide();
220 void KOEditorGeneralEvent::timeStuffDisable(
bool disable)
222 mStartTimeEdit->setEnabled( !disable );
223 mEndTimeEdit->setEnabled( !disable );
229 void KOEditorGeneralEvent::associateTime(
bool time)
231 timeStuffDisable(time);
235 void KOEditorGeneralEvent::setDateTimes(
const TQDateTime &start,
const TQDateTime &end )
239 mStartDateEdit->setDate(start.date());
241 mStartTimeEdit->blockSignals(
true );
242 mStartTimeEdit->setTime(start.time());
243 mStartTimeEdit->blockSignals(
false );
244 mEndDateEdit->setDate(end.date());
245 mEndTimeEdit->setTime(end.time());
247 mCurrStartDateTime = start;
248 mCurrEndDateTime = end;
254 void KOEditorGeneralEvent::startTimeChanged( TQTime newtime )
256 kdDebug(5850) <<
"KOEditorGeneralEvent::startTimeChanged() " << TQString(newtime.toString()) << endl;
258 int secsep = mCurrStartDateTime.secsTo(mCurrEndDateTime);
260 mCurrStartDateTime.setTime(newtime);
263 mCurrEndDateTime = mCurrStartDateTime.addSecs(secsep);
264 mEndTimeEdit->setTime(mCurrEndDateTime.time());
265 mEndDateEdit->setDate(mCurrEndDateTime.date());
267 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
270 void KOEditorGeneralEvent::endTimeChanged( TQTime newtime )
274 TQDateTime newdt(mCurrEndDateTime.date(), newtime);
275 mCurrEndDateTime = newdt;
277 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
280 void KOEditorGeneralEvent::startDateChanged(
const TQDate &newdate )
282 if ( !newdate.isValid() )
285 int daysep = mCurrStartDateTime.daysTo(mCurrEndDateTime);
287 mCurrStartDateTime.setDate(newdate);
290 mCurrEndDateTime.setDate(mCurrStartDateTime.date().addDays(daysep));
291 mEndDateEdit->setDate(mCurrEndDateTime.date());
293 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
296 void KOEditorGeneralEvent::endDateChanged(
const TQDate &newdate )
298 if ( !newdate.isValid() )
301 TQDateTime newdt(newdate, mCurrEndDateTime.time());
302 mCurrEndDateTime = newdt;
304 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
307 void KOEditorGeneralEvent::setDefaults(
const TQDateTime &from,
308 const TQDateTime &to,
bool allDay)
310 KOEditorGeneral::setDefaults(allDay);
312 mAlldayEventCheckbox->setChecked(allDay);
313 timeStuffDisable(allDay);
315 setDateTimes(from,to);
318 void KOEditorGeneralEvent::readEvent(
Event *event,
Calendar *calendar,
const TQDate &date,
bool tmpl )
322 mAlldayEventCheckbox->setChecked(event->
doesFloat());
326 TQDateTime startDT =
event->dtStart();
327 TQDateTime endDT =
event->dtEnd();
328 if ( event->
doesRecur() && date.isValid() ) {
330 TQDateTime kdt( date, TQTime( 0, 0, 0 ) );
331 const int eventLength = startDT.daysTo( endDT );
332 kdt = kdt.addSecs( -1 );
335 endDT.setDate( startDT.addDays( eventLength ).date() );
337 if ( event->hasDuration() ) {
338 endDT = startDT.addSecs( event->duration() );
345 setDateTimes( startDT, endDT );
349 case Event::Transparent:
350 mFreeTimeCombo->setCurrentItem(1);
353 mFreeTimeCombo->setCurrentItem(0);
357 updateRecurrenceSummary( event );
359 Attendee *me =
event->attendeeByMails( KOPrefs::instance()->allEmails() );
361 me && ( me->
status() == Attendee::NeedsAction ||
362 me->
status() == Attendee::Tentative ||
363 me->
status() == Attendee::InProcess ) ) {
364 mInvitationBar->show();
366 mInvitationBar->hide();
369 readIncidence(event, calendar);
372 void KOEditorGeneralEvent::writeEvent(
Event *event)
376 writeIncidence(event);
385 if (mAlldayEventCheckbox->isChecked()) {
386 event->setFloats(
true);
388 tmpDate = mStartDateEdit->date();
389 tmpTime.setHMS(0,0,0);
390 tmpDT.setDate(tmpDate);
391 tmpDT.setTime(tmpTime);
392 event->setDtStart(tmpDT);
394 tmpDate = mEndDateEdit->date();
395 tmpTime.setHMS(0,0,0);
396 tmpDT.setDate(tmpDate);
397 tmpDT.setTime(tmpTime);
398 event->setDtEnd(tmpDT);
400 event->setFloats(
false);
403 tmpDate = mEndDateEdit->date();
404 tmpTime = mEndTimeEdit->getTime();
405 tmpDT.setDate(tmpDate);
406 tmpDT.setTime(tmpTime);
407 event->setDtEnd(tmpDT);
410 tmpDate = mStartDateEdit->date();
411 tmpTime = mStartTimeEdit->getTime();
412 tmpDT.setDate(tmpDate);
413 tmpDT.setTime(tmpTime);
414 event->setDtStart(tmpDT);
417 event->setTransparency(mFreeTimeCombo->currentItem() > 0
418 ? KCal::Event::Transparent
419 : KCal::Event::Opaque);
424 void KOEditorGeneralEvent::setDuration()
426 TQString tmpStr, catStr;
427 int hourdiff, minutediff;
430 if(mCurrEndDateTime >= mCurrStartDateTime) {
432 if (mAlldayEventCheckbox->isChecked()) {
433 int daydiff = mCurrStartDateTime.date().daysTo(mCurrEndDateTime.date()) + 1;
434 tmpStr = i18n(
"Duration: ");
435 tmpStr.append(i18n(
"1 Day",
"%n Days",daydiff));
437 hourdiff = mCurrStartDateTime.date().daysTo(mCurrEndDateTime.date()) * 24;
438 hourdiff += mCurrEndDateTime.time().hour() -
439 mCurrStartDateTime.time().hour();
440 minutediff = mCurrEndDateTime.time().minute() -
441 mCurrStartDateTime.time().minute();
443 if (minutediff < 0 && hourdiff > 0) {
447 if (hourdiff || minutediff){
448 tmpStr = i18n(
"Duration: ");
450 catStr = i18n(
"1 hour",
"%n hours",hourdiff);
451 tmpStr.append(catStr);
453 if (hourdiff && minutediff){
454 tmpStr += i18n(
", ");
457 catStr = i18n(
"1 minute",
"%n minutes",minutediff);
463 mDurationLabel->setText(tmpStr);
464 TQWhatsThis::add( mDurationLabel,
465 i18n(
"Shows the duration of the event or to-do with the "
466 "current start and end dates and times.") );
469 void KOEditorGeneralEvent::emitDateTimeStr()
471 TDELocale *l = TDEGlobal::locale();
474 if (mAlldayEventCheckbox->isChecked()) {
475 from = l->formatDate(mCurrStartDateTime.date());
476 to = l->formatDate(mCurrEndDateTime.date());
478 from = l->formatDateTime(mCurrStartDateTime);
479 to = l->formatDateTime(mCurrEndDateTime);
482 TQString str = i18n(
"From: %1 To: %2 %3").arg(from).arg(to)
483 .arg(mDurationLabel->text());
485 emit dateTimeStrChanged(str);
488 bool KOEditorGeneralEvent::validateInput()
492 if (!mAlldayEventCheckbox->isChecked()) {
493 if (!mStartTimeEdit->inputIsValid()) {
494 KMessageBox::sorry( 0,
495 i18n(
"Please specify a valid start time, for example '%1'.")
496 .arg( TDEGlobal::locale()->formatTime( TQTime::currentTime() ) ) );
500 if (!mEndTimeEdit->inputIsValid()) {
501 KMessageBox::sorry( 0,
502 i18n(
"Please specify a valid end time, for example '%1'.")
503 .arg( TDEGlobal::locale()->formatTime( TQTime::currentTime() ) ) );
508 if (!mStartDateEdit->date().isValid()) {
509 KMessageBox::sorry( 0,
510 i18n(
"Please specify a valid start date, for example '%1'.")
511 .arg( TDEGlobal::locale()->formatDate( TQDate::currentDate() ) ) );
515 if (!mEndDateEdit->date().isValid()) {
516 KMessageBox::sorry( 0,
517 i18n(
"Please specify a valid end date, for example '%1'.")
518 .arg( TDEGlobal::locale()->formatDate( TQDate::currentDate() ) ) );
522 TQDateTime startDt,endDt;
523 startDt.setDate(mStartDateEdit->date());
524 endDt.setDate(mEndDateEdit->date());
525 if (!mAlldayEventCheckbox->isChecked()) {
526 startDt.setTime(mStartTimeEdit->getTime());
527 endDt.setTime(mEndTimeEdit->getTime());
530 if ( startDt > endDt ) {
533 i18n(
"The event ends before it starts.\n"
534 "Please correct dates and times." ) );
538 return KOEditorGeneral::validateInput();
541 void KOEditorGeneralEvent::updateRecurrenceSummary(
Event *event )
544 mRecEditLabel->setText( IncidenceFormatter::recurrenceString( event ) );
546 mRecEditLabel->setText( TQString() );
Transparency transparency() const
int attendeeCount() const
Recurrence * recurrence() const
TQDateTime getNextDateTime(const TQDateTime &preDateTime) const