korganizer Library API Documentation

koeditorgeneralevent.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <qtooltip.h> 00025 #include <qlayout.h> 00026 #include <qvbox.h> 00027 #include <qbuttongroup.h> 00028 #include <qvgroupbox.h> 00029 #include <qwidgetstack.h> 00030 #include <qdatetime.h> 00031 00032 #include <kdebug.h> 00033 #include <kglobal.h> 00034 #include <klocale.h> 00035 #include <kiconloader.h> 00036 #include <kmessagebox.h> 00037 #include <kfiledialog.h> 00038 #include <kstandarddirs.h> 00039 00040 #include <libkcal/event.h> 00041 00042 #include <libkdepim/kdateedit.h> 00043 00044 #include "koprefs.h" 00045 00046 #include "koeditorgeneralevent.h" 00047 #include "koeditorgeneralevent.moc" 00048 00049 KOEditorGeneralEvent::KOEditorGeneralEvent(QObject* parent, 00050 const char* name) : 00051 KOEditorGeneral( parent, name) 00052 { 00053 connect(this,SIGNAL(dateTimesChanged(QDateTime,QDateTime)), 00054 SLOT(setDuration())); 00055 connect(this,SIGNAL(dateTimesChanged(QDateTime,QDateTime)), 00056 SLOT(emitDateTimeStr())); 00057 } 00058 00059 KOEditorGeneralEvent::~KOEditorGeneralEvent() 00060 { 00061 } 00062 00063 void KOEditorGeneralEvent::finishSetup() 00064 { 00065 QWidget::setTabOrder( mSummaryEdit, mLocationEdit ); 00066 QWidget::setTabOrder( mLocationEdit, mStartDateEdit ); 00067 QWidget::setTabOrder( mStartDateEdit, mStartTimeEdit ); 00068 QWidget::setTabOrder( mStartTimeEdit, mEndDateEdit ); 00069 QWidget::setTabOrder( mEndDateEdit, mEndTimeEdit ); 00070 QWidget::setTabOrder( mEndTimeEdit, mNoTimeButton ); 00071 QWidget::setTabOrder( mNoTimeButton, mAlarmButton ); 00072 QWidget::setTabOrder( mAlarmButton, mAlarmTimeEdit ); 00073 QWidget::setTabOrder( mAlarmTimeEdit, mAlarmIncrCombo ); 00074 QWidget::setTabOrder( mAlarmIncrCombo, mAlarmSoundButton ); 00075 QWidget::setTabOrder( mAlarmSoundButton, mAlarmProgramButton ); 00076 QWidget::setTabOrder( mAlarmProgramButton, mFreeTimeCombo ); 00077 QWidget::setTabOrder( mFreeTimeCombo, mDescriptionEdit ); 00078 QWidget::setTabOrder( mDescriptionEdit, mCategoriesButton ); 00079 QWidget::setTabOrder( mCategoriesButton, mSecrecyCombo ); 00080 // QWidget::setTabOrder( mSecrecyCombo, mDescriptionEdit ); 00081 00082 mSummaryEdit->setFocus(); 00083 } 00084 00085 void KOEditorGeneralEvent::initTime(QWidget *parent,QBoxLayout *topLayout) 00086 { 00087 QBoxLayout *timeLayout = new QVBoxLayout(topLayout); 00088 00089 QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal, 00090 i18n("Date && Time"),parent); 00091 timeLayout->addWidget(timeGroupBox); 00092 00093 QFrame *timeBoxFrame = new QFrame(timeGroupBox); 00094 00095 QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,2,3); 00096 layoutTimeBox->setSpacing(topLayout->spacing()); 00097 00098 00099 mStartDateLabel = new QLabel(i18n("&Start:"),timeBoxFrame); 00100 layoutTimeBox->addWidget(mStartDateLabel,0,0); 00101 00102 mStartDateEdit = new KDateEdit(timeBoxFrame); 00103 layoutTimeBox->addWidget(mStartDateEdit,0,1); 00104 mStartDateLabel->setBuddy( mStartDateEdit ); 00105 00106 mStartTimeEdit = new KOTimeEdit(timeBoxFrame); 00107 layoutTimeBox->addWidget(mStartTimeEdit,0,2); 00108 00109 00110 mEndDateLabel = new QLabel(i18n("&End:"),timeBoxFrame); 00111 layoutTimeBox->addWidget(mEndDateLabel,1,0); 00112 00113 mEndDateEdit = new KDateEdit(timeBoxFrame); 00114 layoutTimeBox->addWidget(mEndDateEdit,1,1); 00115 mEndDateLabel->setBuddy( mEndDateEdit ); 00116 00117 mEndTimeEdit = new KOTimeEdit(timeBoxFrame); 00118 layoutTimeBox->addWidget(mEndTimeEdit,1,2); 00119 00120 QHBoxLayout *flagsBox = new QHBoxLayout( timeBoxFrame ); 00121 00122 mNoTimeButton = new QCheckBox(i18n("&No time associated"),timeBoxFrame); 00123 flagsBox->addWidget(mNoTimeButton); 00124 connect(mNoTimeButton, SIGNAL(toggled(bool)),SLOT(dontAssociateTime(bool))); 00125 00126 mDurationLabel = new QLabel( timeBoxFrame ); 00127 if ( KOPrefs::instance()->mCompactDialogs ) { 00128 layoutTimeBox->addMultiCellWidget( mDurationLabel, 3, 3, 0, 3 ); 00129 } else { 00130 flagsBox->addWidget( mDurationLabel, 0, 2 ); 00131 } 00132 00133 layoutTimeBox->addMultiCellLayout( flagsBox, 2, 2, 0, 3 ); 00134 00135 // time widgets are checked if they contain a valid time 00136 connect(mStartTimeEdit, SIGNAL(timeChanged(QTime)), 00137 this, SLOT(startTimeChanged(QTime))); 00138 connect(mEndTimeEdit, SIGNAL(timeChanged(QTime)), 00139 this, SLOT(endTimeChanged(QTime))); 00140 00141 // date widgets are checked if they contain a valid date 00142 connect(mStartDateEdit, SIGNAL(dateChanged(QDate)), 00143 this, SLOT(startDateChanged(QDate))); 00144 connect(mEndDateEdit, SIGNAL(dateChanged(QDate)), 00145 this, SLOT(endDateChanged(QDate))); 00146 } 00147 00148 void KOEditorGeneralEvent::initClass(QWidget *parent,QBoxLayout *topLayout) 00149 { 00150 QBoxLayout *classLayout = new QHBoxLayout(topLayout); 00151 00152 QLabel *freeTimeLabel = new QLabel(i18n("S&how time as:"),parent); 00153 classLayout->addWidget(freeTimeLabel); 00154 00155 mFreeTimeCombo = new QComboBox(false, parent); 00156 mFreeTimeCombo->insertItem(i18n("Busy")); 00157 mFreeTimeCombo->insertItem(i18n("Free")); 00158 classLayout->addWidget(mFreeTimeCombo); 00159 freeTimeLabel->setBuddy( mFreeTimeCombo ); 00160 } 00161 00162 void KOEditorGeneralEvent::timeStuffDisable(bool disable) 00163 { 00164 mStartTimeEdit->setEnabled( !disable ); 00165 mEndTimeEdit->setEnabled( !disable ); 00166 00167 setDuration(); 00168 emitDateTimeStr(); 00169 } 00170 00171 void KOEditorGeneralEvent::dontAssociateTime(bool noTime) 00172 { 00173 timeStuffDisable(noTime); 00174 //if(alarmButton->isChecked()) alarmStuffDisable(noTime); 00175 allDayChanged(noTime); 00176 } 00177 00178 void KOEditorGeneralEvent::setDateTimes(QDateTime start, QDateTime end) 00179 { 00180 // kdDebug(5850) << "KOEditorGeneralEvent::setDateTimes(): Start DateTime: " << start.toString() << endl; 00181 00182 mStartDateEdit->setDate(start.date()); 00183 // KTimeEdit seems to emit some signals when setTime() is called. 00184 mStartTimeEdit->blockSignals( true ); 00185 mStartTimeEdit->setTime(start.time()); 00186 mStartTimeEdit->blockSignals( false ); 00187 mEndDateEdit->setDate(end.date()); 00188 mEndTimeEdit->setTime(end.time()); 00189 00190 mCurrStartDateTime = start; 00191 mCurrEndDateTime = end; 00192 00193 setDuration(); 00194 emitDateTimeStr(); 00195 } 00196 00197 void KOEditorGeneralEvent::startTimeChanged(QTime newtime) 00198 { 00199 kdDebug(5850) << "KOEditorGeneralEvent::startTimeChanged() " << newtime.toString() << endl; 00200 00201 int secsep = mCurrStartDateTime.secsTo(mCurrEndDateTime); 00202 00203 mCurrStartDateTime.setTime(newtime); 00204 00205 // adjust end time so that the event has the same duration as before. 00206 mCurrEndDateTime = mCurrStartDateTime.addSecs(secsep); 00207 mEndTimeEdit->setTime(mCurrEndDateTime.time()); 00208 mEndDateEdit->setDate(mCurrEndDateTime.date()); 00209 00210 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime); 00211 } 00212 00213 void KOEditorGeneralEvent::endTimeChanged(QTime newtime) 00214 { 00215 // kdDebug(5850) << "KOEditorGeneralEvent::endTimeChanged " << newtime.toString() << endl; 00216 00217 QDateTime newdt(mCurrEndDateTime.date(), newtime); 00218 mCurrEndDateTime = newdt; 00219 00220 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime); 00221 } 00222 00223 void KOEditorGeneralEvent::startDateChanged(QDate newdate) 00224 { 00225 int daysep = mCurrStartDateTime.daysTo(mCurrEndDateTime); 00226 00227 mCurrStartDateTime.setDate(newdate); 00228 00229 // adjust end date so that the event has the same duration as before 00230 mCurrEndDateTime.setDate(mCurrStartDateTime.date().addDays(daysep)); 00231 mEndDateEdit->setDate(mCurrEndDateTime.date()); 00232 00233 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime); 00234 } 00235 00236 void KOEditorGeneralEvent::endDateChanged(QDate newdate) 00237 { 00238 QDateTime newdt(newdate, mCurrEndDateTime.time()); 00239 00240 if(newdt < mCurrStartDateTime) { 00241 // oops, we can't let that happen. 00242 newdt = mCurrStartDateTime; 00243 mEndDateEdit->setDate(newdt.date()); 00244 mEndTimeEdit->setTime(newdt.time()); 00245 } 00246 mCurrEndDateTime = newdt; 00247 00248 emit dateTimesChanged(mCurrStartDateTime,mCurrEndDateTime); 00249 } 00250 00251 void KOEditorGeneralEvent::setDefaults(QDateTime from,QDateTime to,bool allDay) 00252 { 00253 KOEditorGeneral::setDefaults(allDay); 00254 00255 mNoTimeButton->setChecked(allDay); 00256 timeStuffDisable(allDay); 00257 00258 setDateTimes(from,to); 00259 } 00260 00261 void KOEditorGeneralEvent::readEvent( Event *event, bool tmpl ) 00262 { 00263 QString tmpStr; 00264 00265 mNoTimeButton->setChecked(event->doesFloat()); 00266 timeStuffDisable(event->doesFloat()); 00267 00268 if ( !tmpl ) { 00269 // the rest is for the events only 00270 setDateTimes(event->dtStart(),event->dtEnd()); 00271 } 00272 00273 switch( event->transparency() ) { 00274 case Event::Transparent: 00275 mFreeTimeCombo->setCurrentItem(1); 00276 break; 00277 case Event::Opaque: 00278 mFreeTimeCombo->setCurrentItem(0); 00279 break; 00280 } 00281 00282 readIncidence(event); 00283 } 00284 00285 void KOEditorGeneralEvent::writeEvent(Event *event) 00286 { 00287 // kdDebug(5850) << "KOEditorGeneralEvent::writeEvent()" << endl; 00288 00289 writeIncidence(event); 00290 00291 QDate tmpDate; 00292 QTime tmpTime; 00293 QDateTime tmpDT; 00294 00295 // temp. until something better happens. 00296 QString tmpStr; 00297 00298 if (mNoTimeButton->isChecked()) { 00299 event->setFloats(true); 00300 // need to change this. 00301 tmpDate = mStartDateEdit->date(); 00302 tmpTime.setHMS(0,0,0); 00303 tmpDT.setDate(tmpDate); 00304 tmpDT.setTime(tmpTime); 00305 event->setDtStart(tmpDT); 00306 00307 tmpDate = mEndDateEdit->date(); 00308 tmpTime.setHMS(0,0,0); 00309 tmpDT.setDate(tmpDate); 00310 tmpDT.setTime(tmpTime); 00311 event->setDtEnd(tmpDT); 00312 } else { 00313 event->setFloats(false); 00314 00315 // set date/time end 00316 tmpDate = mEndDateEdit->date(); 00317 tmpTime = mEndTimeEdit->getTime(); 00318 tmpDT.setDate(tmpDate); 00319 tmpDT.setTime(tmpTime); 00320 event->setDtEnd(tmpDT); 00321 00322 // set date/time start 00323 tmpDate = mStartDateEdit->date(); 00324 tmpTime = mStartTimeEdit->getTime(); 00325 tmpDT.setDate(tmpDate); 00326 tmpDT.setTime(tmpTime); 00327 event->setDtStart(tmpDT); 00328 } // check for float 00329 00330 event->setTransparency(mFreeTimeCombo->currentItem() > 0 00331 ? KCal::Event::Transparent 00332 : KCal::Event::Opaque); 00333 00334 // kdDebug(5850) << "KOEditorGeneralEvent::writeEvent() done" << endl; 00335 } 00336 00337 void KOEditorGeneralEvent::setDuration() 00338 { 00339 QString tmpStr, catStr; 00340 int hourdiff, minutediff; 00341 // end<date is an accepted temporary state while typing, but don't show 00342 // any duration if this happens 00343 if(mCurrEndDateTime >= mCurrStartDateTime) { 00344 00345 if (mNoTimeButton->isChecked()) { 00346 int daydiff = mCurrStartDateTime.date().daysTo(mCurrEndDateTime.date()) + 1; 00347 tmpStr = i18n("Duration: "); 00348 tmpStr.append(i18n("1 Day","%n Days",daydiff)); 00349 } else { 00350 hourdiff = mCurrStartDateTime.date().daysTo(mCurrEndDateTime.date()) * 24; 00351 hourdiff += mCurrEndDateTime.time().hour() - 00352 mCurrStartDateTime.time().hour(); 00353 minutediff = mCurrEndDateTime.time().minute() - 00354 mCurrStartDateTime.time().minute(); 00355 // If minutediff is negative, "borrow" 60 minutes from hourdiff 00356 if (minutediff < 0 && hourdiff > 0) { 00357 hourdiff -= 1; 00358 minutediff += 60; 00359 } 00360 if (hourdiff || minutediff){ 00361 tmpStr = i18n("Duration: "); 00362 if (hourdiff){ 00363 catStr = i18n("1 hour","%n hours",hourdiff); 00364 tmpStr.append(catStr); 00365 } 00366 if (hourdiff && minutediff){ 00367 tmpStr += i18n(", "); 00368 } 00369 if (minutediff){ 00370 catStr = i18n("1 minute","%n minutes",minutediff); 00371 tmpStr += catStr; 00372 } 00373 } else tmpStr = ""; 00374 } 00375 } 00376 mDurationLabel->setText(tmpStr); 00377 } 00378 00379 void KOEditorGeneralEvent::emitDateTimeStr() 00380 { 00381 KLocale *l = KGlobal::locale(); 00382 00383 QString from,to; 00384 if (mNoTimeButton->isChecked()) { 00385 from = l->formatDate(mCurrStartDateTime.date()); 00386 to = l->formatDate(mCurrEndDateTime.date()); 00387 } else { 00388 from = l->formatDateTime(mCurrStartDateTime); 00389 to = l->formatDateTime(mCurrEndDateTime); 00390 } 00391 00392 QString str = i18n("From: %1 To: %2 %3").arg(from).arg(to) 00393 .arg(mDurationLabel->text()); 00394 00395 emit dateTimeStrChanged(str); 00396 } 00397 00398 bool KOEditorGeneralEvent::validateInput() 00399 { 00400 // kdDebug(5850) << "KOEditorGeneralEvent::validateInput()" << endl; 00401 00402 if (!mNoTimeButton->isChecked()) { 00403 if (!mStartTimeEdit->inputIsValid()) { 00404 KMessageBox::sorry( 0, 00405 i18n("Please specify a valid start time, for example '%1'.") 00406 .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) ); 00407 return false; 00408 } 00409 00410 if (!mEndTimeEdit->inputIsValid()) { 00411 KMessageBox::sorry( 0, 00412 i18n("Please specify a valid end time, for example '%1'.") 00413 .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) ); 00414 return false; 00415 } 00416 } 00417 00418 if (!mStartDateEdit->inputIsValid()) { 00419 KMessageBox::sorry( 0, 00420 i18n("Please specify a valid start date, for example '%1'.") 00421 .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) ); 00422 return false; 00423 } 00424 00425 if (!mEndDateEdit->inputIsValid()) { 00426 KMessageBox::sorry( 0, 00427 i18n("Please specify a valid end date, for example '%1'.") 00428 .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) ); 00429 return false; 00430 } 00431 00432 QDateTime startDt,endDt; 00433 startDt.setDate(mStartDateEdit->date()); 00434 endDt.setDate(mEndDateEdit->date()); 00435 if (!mNoTimeButton->isChecked()) { 00436 startDt.setTime(mStartTimeEdit->getTime()); 00437 endDt.setTime(mEndTimeEdit->getTime()); 00438 } 00439 00440 if (startDt > endDt) { 00441 KMessageBox::sorry(0,i18n("The event ends before it starts.\n" 00442 "Please correct dates and times.")); 00443 return false; 00444 } 00445 00446 return KOEditorGeneral::validateInput(); 00447 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003