00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qtooltip.h>
00026 #include <qlayout.h>
00027 #include <qvbox.h>
00028 #include <qbuttongroup.h>
00029 #include <qvgroupbox.h>
00030 #include <qwidgetstack.h>
00031 #include <qspinbox.h>
00032 #include <qdatetime.h>
00033 #include <qlabel.h>
00034 #include <qcheckbox.h>
00035 #include <qcombobox.h>
00036 #include <qpushbutton.h>
00037 #include <qwhatsthis.h>
00038
00039 #include <kdebug.h>
00040 #include <kglobal.h>
00041 #include <klocale.h>
00042 #include <kmessagebox.h>
00043 #include <kfiledialog.h>
00044 #include <kstandarddirs.h>
00045 #include <ktextedit.h>
00046
00047 #include <libkcal/event.h>
00048 #include <libkcal/incidenceformatter.h>
00049
00050 #include "ktimeedit.h"
00051 #include <libkdepim/kdateedit.h>
00052
00053 #include "koprefs.h"
00054 #include "koglobals.h"
00055
00056 #include "koeditorgeneralevent.h"
00057 #include "koeditorgeneralevent.moc"
00058
00059 KOEditorGeneralEvent::KOEditorGeneralEvent(QObject* parent,
00060 const char* name) :
00061 KOEditorGeneral( parent, name)
00062 {
00063 connect( this, SIGNAL( dateTimesChanged( const QDateTime &, const QDateTime & )),
00064 SLOT( setDuration() ) );
00065 connect( this, SIGNAL( dateTimesChanged( const QDateTime &, const QDateTime & )),
00066 SLOT( emitDateTimeStr() ));
00067 }
00068
00069 KOEditorGeneralEvent::~KOEditorGeneralEvent()
00070 {
00071 }
00072
00073 void KOEditorGeneralEvent::finishSetup()
00074 {
00075 QWidget::setTabOrder( mSummaryEdit, mLocationEdit );
00076 QWidget::setTabOrder( mLocationEdit, mStartDateEdit );
00077 QWidget::setTabOrder( mStartDateEdit, mStartTimeEdit );
00078 QWidget::setTabOrder( mStartTimeEdit, mEndDateEdit );
00079 QWidget::setTabOrder( mEndDateEdit, mEndTimeEdit );
00080 QWidget::setTabOrder( mEndTimeEdit, mAlldayEventCheckbox );
00081 QWidget::setTabOrder( mAlldayEventCheckbox, mRecEditButton );
00082 QWidget::setTabOrder( mRecEditButton, mAlarmButton );
00083 QWidget::setTabOrder( mAlarmButton, mAlarmTimeEdit );
00084 QWidget::setTabOrder( mAlarmTimeEdit, mAlarmIncrCombo );
00085
00086 QWidget::setTabOrder( mAlarmIncrCombo, mAlarmEditButton );
00087
00088
00089 QWidget::setTabOrder( mAlarmEditButton, mFreeTimeCombo );
00090 QWidget::setTabOrder( mFreeTimeCombo, mDescriptionEdit );
00091 QWidget::setTabOrder( mDescriptionEdit, mCategoriesButton );
00092 QWidget::setTabOrder( mCategoriesButton, mSecrecyCombo );
00093
00094
00095 mSummaryEdit->setFocus();
00096 }
00097
00098 void KOEditorGeneralEvent::initTime(QWidget *parent,QBoxLayout *topLayout)
00099 {
00100 QBoxLayout *timeLayout = new QVBoxLayout(topLayout);
00101
00102 QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal,
00103 i18n("Date && Time"),parent);
00104 QWhatsThis::add( timeGroupBox,
00105 i18n("Sets options related to the date and time of the "
00106 "event or to-do.") );
00107 timeLayout->addWidget(timeGroupBox);
00108
00109 QFrame *timeBoxFrame = new QFrame(timeGroupBox);
00110
00111 QGridLayout *layoutTimeBox = new QGridLayout( timeBoxFrame );
00112 layoutTimeBox->setSpacing(topLayout->spacing());
00113 layoutTimeBox->setColStretch( 3, 1 );
00114
00115 mStartDateLabel = new QLabel(i18n("&Start:"),timeBoxFrame);
00116 layoutTimeBox->addWidget(mStartDateLabel,0,0);
00117
00118 mStartDateEdit = new KDateEdit(timeBoxFrame);
00119 layoutTimeBox->addWidget(mStartDateEdit,0,1);
00120 mStartDateLabel->setBuddy( mStartDateEdit );
00121
00122 mStartTimeEdit = new KTimeEdit(timeBoxFrame);
00123 layoutTimeBox->addWidget(mStartTimeEdit,0,2);
00124
00125 mEndDateLabel = new QLabel(i18n("&End:"),timeBoxFrame);
00126 layoutTimeBox->addWidget(mEndDateLabel,1,0);
00127
00128 mEndDateEdit = new KDateEdit(timeBoxFrame);
00129 layoutTimeBox->addWidget(mEndDateEdit,1,1);
00130 mEndDateLabel->setBuddy( mEndDateEdit );
00131
00132 mEndTimeEdit = new KTimeEdit(timeBoxFrame);
00133 layoutTimeBox->addWidget(mEndTimeEdit,1,2);
00134
00135 mAlldayEventCheckbox = new QCheckBox(i18n("All-&day"),timeBoxFrame);
00136 layoutTimeBox->addWidget( mAlldayEventCheckbox, 0, 3 );
00137 connect(mAlldayEventCheckbox, SIGNAL(toggled(bool)),SLOT(associateTime(bool)));
00138
00139 mDurationLabel = new QLabel( timeBoxFrame );
00140 layoutTimeBox->addWidget( mDurationLabel, 1, 3 );
00141
00142
00143 connect(mStartTimeEdit, SIGNAL(timeChanged(QTime)),
00144 this, SLOT(startTimeChanged(QTime)));
00145 connect(mEndTimeEdit, SIGNAL(timeChanged(QTime)),
00146 this, SLOT(endTimeChanged(QTime)));
00147
00148
00149 connect(mStartDateEdit, SIGNAL(dateChanged(const QDate&)),
00150 this, SLOT(startDateChanged(const QDate&)));
00151 connect(mEndDateEdit, SIGNAL(dateChanged(const QDate&)),
00152 this, SLOT(endDateChanged(const QDate&)));
00153
00154 QLabel *label = new QLabel( i18n( "Recurrence:" ), timeBoxFrame );
00155 layoutTimeBox->addWidget( label, 2, 0 );
00156 QBoxLayout *recLayout = new QHBoxLayout();
00157 layoutTimeBox->addMultiCellLayout( recLayout, 2, 2, 1, 4 );
00158 mRecEditButton = new QPushButton( timeBoxFrame );
00159 mRecEditButton->setIconSet( KOGlobals::self()->smallIconSet( "recur", 16 ) );
00160 recLayout->addWidget( mRecEditButton );
00161 connect( mRecEditButton, SIGNAL(clicked()), SIGNAL(editRecurrence()) );
00162 mRecEditLabel = new QLabel( QString(), timeBoxFrame );
00163 recLayout->addWidget( mRecEditLabel );
00164 recLayout->addStretch( 1 );
00165
00166 label = new QLabel( i18n("Reminder:"), timeBoxFrame );
00167 layoutTimeBox->addWidget( label, 3, 0 );
00168 QBoxLayout *alarmLineLayout = new QHBoxLayout();
00169 layoutTimeBox->addMultiCellLayout( alarmLineLayout, 3, 3, 1, 4 );
00170 initAlarm( timeBoxFrame, alarmLineLayout );
00171 alarmLineLayout->addStretch( 1 );
00172
00173 QBoxLayout *secLayout = new QHBoxLayout();
00174 layoutTimeBox->addLayout( secLayout, 0, 4 );
00175 initSecrecy( timeBoxFrame, secLayout );
00176
00177 QBoxLayout *classLayout = new QHBoxLayout();
00178 layoutTimeBox->addLayout( classLayout, 1, 4 );
00179 initClass( timeBoxFrame, classLayout );
00180 }
00181
00182 void KOEditorGeneralEvent::initClass(QWidget *parent,QBoxLayout *topLayout)
00183 {
00184 QBoxLayout *classLayout = new QHBoxLayout(topLayout);
00185
00186 QLabel *freeTimeLabel = new QLabel(i18n("S&how time as:"),parent);
00187 QString whatsThis = i18n("Sets how this time will appear on your Free/Busy "
00188 "information.");
00189 QWhatsThis::add( freeTimeLabel, whatsThis );
00190 classLayout->addWidget(freeTimeLabel);
00191
00192 mFreeTimeCombo = new QComboBox(false, parent);
00193 QWhatsThis::add( mFreeTimeCombo, whatsThis );
00194 mFreeTimeCombo->insertItem(i18n("Busy"));
00195 mFreeTimeCombo->insertItem(i18n("Free"));
00196 classLayout->addWidget(mFreeTimeCombo);
00197 freeTimeLabel->setBuddy( mFreeTimeCombo );
00198 }
00199
00200 void KOEditorGeneralEvent::initInvitationBar(QWidget * parent, QBoxLayout * layout)
00201 {
00202 QBoxLayout *topLayout = new QHBoxLayout( layout );
00203 mInvitationBar = new QFrame( parent );
00204 mInvitationBar->setPaletteBackgroundColor( KGlobalSettings::alternateBackgroundColor() );
00205 topLayout->addWidget( mInvitationBar );
00206
00207 QBoxLayout *barLayout = new QHBoxLayout( mInvitationBar );
00208 barLayout->setSpacing( layout->spacing() );
00209 QLabel *label = new QLabel( i18n("You have not yet definitely responded to this invitation." ), mInvitationBar );
00210 barLayout->addWidget( label );
00211 barLayout->addStretch( 1 );
00212 QPushButton *button = new QPushButton( i18n("Accept"), mInvitationBar );
00213 connect( button, SIGNAL(clicked()), SIGNAL(acceptInvitation()) );
00214 connect( button, SIGNAL(clicked()), mInvitationBar, SLOT(hide()) );
00215 barLayout->addWidget( button );
00216 button = new QPushButton( i18n("Decline"), mInvitationBar );
00217 connect( button, SIGNAL(clicked()), SIGNAL(declineInvitation()) );
00218 connect( button, SIGNAL(clicked()), mInvitationBar, SLOT(hide()) );
00219 barLayout->addWidget( button );
00220
00221 mInvitationBar->hide();
00222 }
00223
00224 void KOEditorGeneralEvent::timeStuffDisable(bool disable)
00225 {
00226 mStartTimeEdit->setEnabled( !disable );
00227 mEndTimeEdit->setEnabled( !disable );
00228
00229 setDuration();
00230 emitDateTimeStr();
00231 }
00232
00233 void KOEditorGeneralEvent::associateTime(bool time)
00234 {
00235 timeStuffDisable(time);
00236
00237 allDayChanged(time);
00238 }
00239
00240 void KOEditorGeneralEvent::setDateTimes( const QDateTime &start, const QDateTime &end )
00241 {
00242
00243
00244 mStartDateEdit->setDate(start.date());
00245
00246 mStartTimeEdit->blockSignals( true );
00247 mStartTimeEdit->setTime(start.time());
00248 mStartTimeEdit->blockSignals( false );
00249 mEndDateEdit->setDate(end.date());
00250 mEndTimeEdit->setTime(end.time());
00251
00252 mCurrStartDateTime = start;
00253 mCurrEndDateTime = end;
00254
00255 setDuration();
00256 emitDateTimeStr();
00257 }
00258
00259 void KOEditorGeneralEvent::startTimeChanged( QTime newtime )
00260 {
00261 kdDebug(5850) << "KOEditorGeneralEvent::startTimeChanged() " << newtime.toString() << endl;
00262
00263 int secsep = mCurrStartDateTime.secsTo(mCurrEndDateTime);
00264
00265 mCurrStartDateTime.setTime(newtime);
00266
00267
00268 mCurrEndDateTime = mCurrStartDateTime.addSecs(secsep);
00269 mEndTimeEdit->setTime(mCurrEndDateTime.time());
00270 mEndDateEdit->setDate(mCurrEndDateTime.date());
00271
00272 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
00273 }
00274
00275 void KOEditorGeneralEvent::endTimeChanged( QTime newtime )
00276 {
00277
00278
00279 QDateTime newdt(mCurrEndDateTime.date(), newtime);
00280 mCurrEndDateTime = newdt;
00281
00282 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
00283 }
00284
00285 void KOEditorGeneralEvent::startDateChanged( const QDate &newdate )
00286 {
00287 if ( !newdate.isValid() )
00288 return;
00289
00290 int daysep = mCurrStartDateTime.daysTo(mCurrEndDateTime);
00291
00292 mCurrStartDateTime.setDate(newdate);
00293
00294
00295 mCurrEndDateTime.setDate(mCurrStartDateTime.date().addDays(daysep));
00296 mEndDateEdit->setDate(mCurrEndDateTime.date());
00297
00298 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
00299 }
00300
00301 void KOEditorGeneralEvent::endDateChanged( const QDate &newdate )
00302 {
00303 if ( !newdate.isValid() )
00304 return;
00305
00306 QDateTime newdt(newdate, mCurrEndDateTime.time());
00307 mCurrEndDateTime = newdt;
00308
00309 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime);
00310 }
00311
00312 void KOEditorGeneralEvent::setDefaults( const QDateTime &from,
00313 const QDateTime &to, bool allDay)
00314 {
00315 KOEditorGeneral::setDefaults(allDay);
00316
00317 mAlldayEventCheckbox->setChecked(allDay);
00318 timeStuffDisable(allDay);
00319
00320 setDateTimes(from,to);
00321 }
00322
00323 void KOEditorGeneralEvent::readEvent( Event *event, Calendar *calendar, const QDate &date, bool tmpl )
00324 {
00325 QString tmpStr;
00326
00327 mAlldayEventCheckbox->setChecked(event->doesFloat());
00328 timeStuffDisable(event->doesFloat());
00329
00330 if ( !tmpl ) {
00331 QDateTime startDT = event->dtStart();
00332 QDateTime endDT = event->dtEnd();
00333 if ( event->doesRecur() && date.isValid() ) {
00334
00335 QDateTime kdt( date, QTime( 0, 0, 0 ) );
00336 const int eventLength = startDT.daysTo( endDT );
00337 kdt = kdt.addSecs( -1 );
00338 startDT.setDate( event->recurrence()->getNextDateTime( kdt ).date() );
00339 if ( event->hasEndDate() ) {
00340 endDT.setDate( startDT.addDays( eventLength ).date() );
00341 } else {
00342 if ( event->hasDuration() ) {
00343 endDT = startDT.addSecs( event->duration() );
00344 } else {
00345 endDT = startDT;
00346 }
00347 }
00348 }
00349
00350 setDateTimes( startDT, endDT );
00351 }
00352
00353 switch( event->transparency() ) {
00354 case Event::Transparent:
00355 mFreeTimeCombo->setCurrentItem(1);
00356 break;
00357 case Event::Opaque:
00358 mFreeTimeCombo->setCurrentItem(0);
00359 break;
00360 }
00361
00362 updateRecurrenceSummary( event );
00363
00364 Attendee *me = event->attendeeByMails( KOPrefs::instance()->allEmails() );
00365 if ( event->attendeeCount() > 1 &&
00366 me && ( me->status() == Attendee::NeedsAction ||
00367 me->status() == Attendee::Tentative ||
00368 me->status() == Attendee::InProcess ) ) {
00369 mInvitationBar->show();
00370 } else {
00371 mInvitationBar->hide();
00372 }
00373
00374 readIncidence(event, calendar);
00375 }
00376
00377 void KOEditorGeneralEvent::writeEvent(Event *event)
00378 {
00379
00380
00381 writeIncidence(event);
00382
00383 QDate tmpDate;
00384 QTime tmpTime;
00385 QDateTime tmpDT;
00386
00387
00388 QString tmpStr;
00389
00390 if (mAlldayEventCheckbox->isChecked()) {
00391 event->setFloats(true);
00392
00393 tmpDate = mStartDateEdit->date();
00394 tmpTime.setHMS(0,0,0);
00395 tmpDT.setDate(tmpDate);
00396 tmpDT.setTime(tmpTime);
00397 event->setDtStart(tmpDT);
00398
00399 tmpDate = mEndDateEdit->date();
00400 tmpTime.setHMS(0,0,0);
00401 tmpDT.setDate(tmpDate);
00402 tmpDT.setTime(tmpTime);
00403 event->setDtEnd(tmpDT);
00404 } else {
00405 event->setFloats(false);
00406
00407
00408 tmpDate = mEndDateEdit->date();
00409 tmpTime = mEndTimeEdit->getTime();
00410 tmpDT.setDate(tmpDate);
00411 tmpDT.setTime(tmpTime);
00412 event->setDtEnd(tmpDT);
00413
00414
00415 tmpDate = mStartDateEdit->date();
00416 tmpTime = mStartTimeEdit->getTime();
00417 tmpDT.setDate(tmpDate);
00418 tmpDT.setTime(tmpTime);
00419 event->setDtStart(tmpDT);
00420 }
00421
00422 event->setTransparency(mFreeTimeCombo->currentItem() > 0
00423 ? KCal::Event::Transparent
00424 : KCal::Event::Opaque);
00425
00426
00427 }
00428
00429 void KOEditorGeneralEvent::setDuration()
00430 {
00431 QString tmpStr, catStr;
00432 int hourdiff, minutediff;
00433
00434
00435 if(mCurrEndDateTime >= mCurrStartDateTime) {
00436
00437 if (mAlldayEventCheckbox->isChecked()) {
00438 int daydiff = mCurrStartDateTime.date().daysTo(mCurrEndDateTime.date()) + 1;
00439 tmpStr = i18n("Duration: ");
00440 tmpStr.append(i18n("1 Day","%n Days",daydiff));
00441 } else {
00442 hourdiff = mCurrStartDateTime.date().daysTo(mCurrEndDateTime.date()) * 24;
00443 hourdiff += mCurrEndDateTime.time().hour() -
00444 mCurrStartDateTime.time().hour();
00445 minutediff = mCurrEndDateTime.time().minute() -
00446 mCurrStartDateTime.time().minute();
00447
00448 if (minutediff < 0 && hourdiff > 0) {
00449 hourdiff -= 1;
00450 minutediff += 60;
00451 }
00452 if (hourdiff || minutediff){
00453 tmpStr = i18n("Duration: ");
00454 if (hourdiff){
00455 catStr = i18n("1 hour","%n hours",hourdiff);
00456 tmpStr.append(catStr);
00457 }
00458 if (hourdiff && minutediff){
00459 tmpStr += i18n(", ");
00460 }
00461 if (minutediff){
00462 catStr = i18n("1 minute","%n minutes",minutediff);
00463 tmpStr += catStr;
00464 }
00465 } else tmpStr = "";
00466 }
00467 }
00468 mDurationLabel->setText(tmpStr);
00469 QWhatsThis::add( mDurationLabel,
00470 i18n("Shows the duration of the event or to-do with the "
00471 "current start and end dates and times.") );
00472 }
00473
00474 void KOEditorGeneralEvent::emitDateTimeStr()
00475 {
00476 KLocale *l = KGlobal::locale();
00477
00478 QString from,to;
00479 if (mAlldayEventCheckbox->isChecked()) {
00480 from = l->formatDate(mCurrStartDateTime.date());
00481 to = l->formatDate(mCurrEndDateTime.date());
00482 } else {
00483 from = l->formatDateTime(mCurrStartDateTime);
00484 to = l->formatDateTime(mCurrEndDateTime);
00485 }
00486
00487 QString str = i18n("From: %1 To: %2 %3").arg(from).arg(to)
00488 .arg(mDurationLabel->text());
00489
00490 emit dateTimeStrChanged(str);
00491 }
00492
00493 bool KOEditorGeneralEvent::validateInput()
00494 {
00495
00496
00497 if (!mAlldayEventCheckbox->isChecked()) {
00498 if (!mStartTimeEdit->inputIsValid()) {
00499 KMessageBox::sorry( 0,
00500 i18n("Please specify a valid start time, for example '%1'.")
00501 .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) );
00502 return false;
00503 }
00504
00505 if (!mEndTimeEdit->inputIsValid()) {
00506 KMessageBox::sorry( 0,
00507 i18n("Please specify a valid end time, for example '%1'.")
00508 .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) );
00509 return false;
00510 }
00511 }
00512
00513 if (!mStartDateEdit->date().isValid()) {
00514 KMessageBox::sorry( 0,
00515 i18n("Please specify a valid start date, for example '%1'.")
00516 .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) );
00517 return false;
00518 }
00519
00520 if (!mEndDateEdit->date().isValid()) {
00521 KMessageBox::sorry( 0,
00522 i18n("Please specify a valid end date, for example '%1'.")
00523 .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) );
00524 return false;
00525 }
00526
00527 QDateTime startDt,endDt;
00528 startDt.setDate(mStartDateEdit->date());
00529 endDt.setDate(mEndDateEdit->date());
00530 if (!mAlldayEventCheckbox->isChecked()) {
00531 startDt.setTime(mStartTimeEdit->getTime());
00532 endDt.setTime(mEndTimeEdit->getTime());
00533 }
00534
00535 if ( startDt > endDt ) {
00536 KMessageBox::sorry(
00537 0,
00538 i18n( "The event ends before it starts.\n"
00539 "Please correct dates and times." ) );
00540 return false;
00541 }
00542
00543 return KOEditorGeneral::validateInput();
00544 }
00545
00546 void KOEditorGeneralEvent::updateRecurrenceSummary( Event *event )
00547 {
00548 if ( event->doesRecur() ) {
00549 mRecEditLabel->setText( IncidenceFormatter::recurrenceString( event ) );
00550 } else {
00551 mRecEditLabel->setText( QString() );
00552 }
00553 }