korganizer Library API Documentation

koeditorgeneraltodo.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2000,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., 675 Mass Ave, Cambridge, MA 02139, 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 <qfiledialog.h>
00026 #include <qlayout.h>
00027 #include <qvbox.h>
00028 #include <qbuttongroup.h>
00029 #include <qvgroupbox.h>
00030 #include <qwidgetstack.h>
00031 #include <qdatetime.h>
00032 
00033 #include <kglobal.h>
00034 #include <klocale.h>
00035 #include <kiconloader.h>
00036 #include <kmessagebox.h>
00037 #include <kdebug.h>
00038 #include <krestrictedline.h>
00039 #include <kstandarddirs.h>
00040 #include <kfiledialog.h>
00041 
00042 #include <libkcal/todo.h>
00043 
00044 #include <libkdepim/kdateedit.h>
00045 
00046 #include "koprefs.h"
00047 
00048 #include "koeditorgeneraltodo.h"
00049 #include "koeditorgeneraltodo.moc"
00050 
00051 KOEditorGeneralTodo::KOEditorGeneralTodo(QObject* parent,
00052                                          const char* name)
00053   : KOEditorGeneral( parent, name)
00054 {
00055 }
00056 
00057 KOEditorGeneralTodo::~KOEditorGeneralTodo()
00058 {
00059 }
00060 
00061 void KOEditorGeneralTodo::finishSetup()
00062 {
00063   QWidget::setTabOrder(mSummaryEdit, mLocationEdit);
00064   QWidget::setTabOrder(mLocationEdit, mDueCheck);
00065   QWidget::setTabOrder(mDueCheck, mDueDateEdit);
00066   QWidget::setTabOrder(mDueDateEdit, mDueTimeEdit);
00067   QWidget::setTabOrder(mDueTimeEdit, mStartCheck);
00068   QWidget::setTabOrder(mStartCheck, mStartDateEdit);
00069   QWidget::setTabOrder(mStartDateEdit, mStartTimeEdit);
00070   QWidget::setTabOrder(mStartTimeEdit, mTimeButton);
00071   QWidget::setTabOrder(mTimeButton, mCompletedCombo);
00072   QWidget::setTabOrder(mCompletedCombo, mPriorityCombo);
00073   QWidget::setTabOrder(mPriorityCombo, mAlarmButton);
00074   QWidget::setTabOrder(mAlarmButton, mCategoriesButton);
00075   QWidget::setTabOrder(mCategoriesButton, mSecrecyCombo);
00076   QWidget::setTabOrder(mSecrecyCombo, mDescriptionEdit);
00077   
00078   mSummaryEdit->setFocus();
00079 }
00080 
00081 void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout)
00082 {
00083   QBoxLayout *timeLayout = new QVBoxLayout(topLayout);
00084 
00085   QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal,
00086                                           i18n("Date && Time"),parent);
00087   timeLayout->addWidget(timeGroupBox);
00088 
00089   QFrame *timeBoxFrame = new QFrame(timeGroupBox);
00090 
00091   QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,1,1);
00092   layoutTimeBox->setSpacing(topLayout->spacing());
00093 
00094 
00095   mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame);
00096   layoutTimeBox->addWidget(mDueCheck,0,0);
00097   connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool)));
00098   connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm()));
00099   
00100   
00101   mDueDateEdit = new KDateEdit(timeBoxFrame);
00102   layoutTimeBox->addWidget(mDueDateEdit,0,1);
00103 
00104   mDueTimeEdit = new KTimeEdit(timeBoxFrame);
00105   layoutTimeBox->addWidget(mDueTimeEdit,0,2);
00106 
00107 
00108   mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame);
00109   layoutTimeBox->addWidget(mStartCheck,1,0);
00110   connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool)));
00111 
00112   mStartDateEdit = new KDateEdit(timeBoxFrame);
00113   layoutTimeBox->addWidget(mStartDateEdit,1,1);
00114 
00115   mStartTimeEdit = new KTimeEdit(timeBoxFrame);
00116   layoutTimeBox->addWidget(mStartTimeEdit,1,2);
00117 
00118 
00119   mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame);
00120   layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,2);
00121 
00122   connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool)));
00123   
00124   // some more layouting
00125   layoutTimeBox->setColStretch(3,1);
00126 }
00127 
00128 
00129 void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout)
00130 {
00131   mCompletedCombo = new QComboBox(parent);
00132   // xgettext:no-c-format
00133   mCompletedCombo->insertItem(i18n("0 %"));
00134   // xgettext:no-c-format
00135   mCompletedCombo->insertItem(i18n("20 %"));
00136   // xgettext:no-c-format
00137   mCompletedCombo->insertItem(i18n("40 %"));
00138   // xgettext:no-c-format
00139   mCompletedCombo->insertItem(i18n("60 %"));
00140   // xgettext:no-c-format
00141   mCompletedCombo->insertItem(i18n("80 %"));
00142   // xgettext:no-c-format
00143   mCompletedCombo->insertItem(i18n("100 %"));
00144   connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int)));
00145   topLayout->addWidget(mCompletedCombo);
00146 
00147   mCompletedLabel = new QLabel(i18n("completed"),parent);
00148   topLayout->addWidget(mCompletedLabel);
00149 }
00150 
00151 void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout)
00152 {
00153   QLabel *priorityLabel = new QLabel(i18n("Priority:"),parent);
00154   topLayout->addWidget(priorityLabel);
00155 
00156   mPriorityCombo = new QComboBox(parent);
00157   mPriorityCombo->insertItem(i18n("1 (Highest)"));
00158   mPriorityCombo->insertItem(i18n("2"));
00159   mPriorityCombo->insertItem(i18n("3"));
00160   mPriorityCombo->insertItem(i18n("4"));
00161   mPriorityCombo->insertItem(i18n("5 (lowest)"));
00162   topLayout->addWidget(mPriorityCombo);
00163 }
00164 
00165 void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout)
00166 {
00167   QBoxLayout *statusLayout = new QHBoxLayout(topLayout);
00168 
00169   initCompletion( parent, statusLayout );
00170 
00171   statusLayout->addStretch( 1 );
00172 
00173   initPriority( parent, statusLayout );
00174 }
00175 
00176 void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay)
00177 {
00178   KOEditorGeneral::setDefaults(allDay);
00179 
00180   mTimeButton->setChecked( !allDay );
00181   if(mTimeButton->isChecked()) {
00182     mTimeButton->setEnabled(true);
00183   }
00184   else {
00185     mTimeButton->setEnabled(false);
00186   }
00187   
00188   enableTimeEdits( !allDay );
00189   
00190   mDueCheck->setChecked(false);
00191   enableDueEdit(false);
00192 
00193   alarmDisable(true);
00194   
00195   mStartCheck->setChecked(false);
00196   enableStartEdit(false);
00197 
00198   mDueDateEdit->setDate(due.date());
00199   mDueTimeEdit->setTime(due.time());
00200   
00201   mStartDateEdit->setDate(QDate::currentDate());
00202   mStartTimeEdit->setTime(QTime::currentTime());  
00203 
00204   mPriorityCombo->setCurrentItem(2);
00205   
00206   mCompletedCombo->setCurrentItem(0);
00207 }
00208 
00209 void KOEditorGeneralTodo::readTodo(Todo *todo)
00210 {
00211   KOEditorGeneral::readIncidence(todo);
00212 
00213   QDateTime dueDT;
00214   
00215   if (todo->hasDueDate()) {
00216     enableAlarmEdit(true);
00217     dueDT = todo->dtDue();
00218     mDueDateEdit->setDate(todo->dtDue().date());
00219     mDueTimeEdit->setTime(todo->dtDue().time());
00220     mDueCheck->setChecked(true);
00221   } else {
00222     alarmDisable(true);
00223     mDueDateEdit->setEnabled(false);
00224     mDueTimeEdit->setEnabled(false);
00225     mDueDateEdit->setDate(QDate::currentDate());
00226     mDueTimeEdit->setTime(QTime::currentTime());
00227     mDueCheck->setChecked(false);
00228   }
00229 
00230   if (todo->hasStartDate()) {
00231     mStartDateEdit->setDate(todo->dtStart().date());
00232     mStartTimeEdit->setTime(todo->dtStart().time());
00233     mStartCheck->setChecked(true);
00234   } else {
00235     mStartDateEdit->setEnabled(false);
00236     mStartTimeEdit->setEnabled(false);
00237     mStartDateEdit->setDate(QDate::currentDate());
00238     mStartTimeEdit->setTime(QTime::currentTime());
00239     mStartCheck->setChecked(false);
00240   }
00241 
00242   mTimeButton->setChecked( !todo->doesFloat() );
00243 
00244   mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
00245   if (todo->isCompleted() && todo->hasCompletedDate()) {
00246     mCompleted = todo->completed();
00247   }
00248   setCompletedDate();
00249 
00250   mPriorityCombo->setCurrentItem(todo->priority()-1);
00251 }
00252 
00253 void KOEditorGeneralTodo::writeTodo(Todo *todo)
00254 {
00255   KOEditorGeneral::writeIncidence(todo);
00256 
00257   // temp. until something better happens.
00258   QString tmpStr;
00259   
00260   todo->setHasDueDate(mDueCheck->isChecked());
00261   todo->setHasStartDate(mStartCheck->isChecked());
00262 
00263   QDate tmpDate;
00264   QTime tmpTime;
00265   QDateTime tmpDT;
00266   if ( mTimeButton->isChecked() ) {
00267     todo->setFloats(false);
00268     
00269     // set due date/time
00270     tmpDate = mDueDateEdit->date();
00271     tmpTime = mDueTimeEdit->getTime();
00272     tmpDT.setDate(tmpDate);
00273     tmpDT.setTime(tmpTime);
00274     todo->setDtDue(tmpDT);
00275 
00276     // set start date/time
00277     tmpDate = mStartDateEdit->date();
00278     tmpTime = mStartTimeEdit->getTime();
00279     tmpDT.setDate(tmpDate);
00280     tmpDT.setTime(tmpTime);
00281     todo->setDtStart(tmpDT);
00282   } else {
00283     todo->setFloats(true);
00284 
00285     // need to change this.
00286     tmpDate = mDueDateEdit->date();
00287     tmpTime.setHMS(0,0,0);
00288     tmpDT.setDate(tmpDate);
00289     tmpDT.setTime(tmpTime);
00290     todo->setDtDue(tmpDT);
00291     
00292     tmpDate = mStartDateEdit->date();
00293     tmpTime.setHMS(0,0,0);
00294     tmpDT.setDate(tmpDate);
00295     tmpDT.setTime(tmpTime);
00296     todo->setDtStart(tmpDT);
00297   }
00298   
00299   todo->setPriority(mPriorityCombo->currentItem()+1);
00300 
00301   // set completion state
00302   todo->setPercentComplete(mCompletedCombo->currentItem() * 20);
00303 
00304   if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
00305     todo->setCompleted(mCompleted);
00306   }
00307 }
00308 
00309 void KOEditorGeneralTodo::enableDueEdit(bool enable)
00310 {
00311   mDueDateEdit->setEnabled( enable );
00312 
00313   if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
00314     mTimeButton->setEnabled(true);
00315   }
00316   else {
00317     mTimeButton->setEnabled(false);
00318     mTimeButton->setChecked(false);
00319   }
00320   
00321   if (enable) {
00322     mDueTimeEdit->setEnabled( mTimeButton->isChecked() );
00323   } else {
00324     mDueTimeEdit->setEnabled( false );
00325   }
00326 }
00327 
00328 void KOEditorGeneralTodo::enableStartEdit( bool enable )
00329 {
00330   mStartDateEdit->setEnabled( enable );
00331 
00332   if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
00333     mTimeButton->setEnabled(true);
00334   }
00335   else {
00336     mTimeButton->setEnabled(false);
00337     mTimeButton->setChecked(false);
00338   }
00339 
00340   if (enable) {
00341     mStartTimeEdit->setEnabled( mTimeButton->isChecked() );
00342   } else {
00343     mStartTimeEdit->setEnabled( false );
00344   }
00345 }
00346 
00347 void KOEditorGeneralTodo::enableTimeEdits(bool enable)
00348 {
00349   if(mStartCheck->isChecked()) {
00350     mStartTimeEdit->setEnabled( enable );
00351   }
00352   if(mDueCheck->isChecked()) {
00353     mDueTimeEdit->setEnabled( enable );
00354   }
00355 }
00356 
00357 void KOEditorGeneralTodo::showAlarm()
00358 {
00359   if ( mDueCheck->isChecked() ) {
00360     alarmDisable(false);
00361   }
00362   else {
00363     alarmDisable(true);
00364   }
00365 }
00366 
00367 bool KOEditorGeneralTodo::validateInput()
00368 {
00369   if (mDueCheck->isChecked()) {
00370     if (!mDueDateEdit->inputIsValid()) {
00371       KMessageBox::sorry(0,i18n("Please specify a valid due date."));
00372       return false;
00373     }
00374     if (mTimeButton->isChecked()) {
00375       if (!mDueTimeEdit->inputIsValid()) {
00376         KMessageBox::sorry(0,i18n("Please specify a valid due time."));
00377         return false;
00378       }
00379     }
00380   }
00381 
00382   if (mStartCheck->isChecked()) {
00383     if (!mStartDateEdit->inputIsValid()) {
00384       KMessageBox::sorry(0,i18n("Please specify a valid start date."));
00385       return false;
00386     }
00387     if (mTimeButton->isChecked()) {
00388       if (!mStartTimeEdit->inputIsValid()) {
00389         KMessageBox::sorry(0,i18n("Please specify a valid start time."));
00390         return false;
00391       }
00392     }
00393   }
00394 
00395   if (mStartCheck->isChecked() && mDueCheck->isChecked()) {
00396     QDateTime startDate;
00397     QDateTime dueDate;
00398     startDate.setDate(mStartDateEdit->date());
00399     dueDate.setDate(mDueDateEdit->date());
00400     if (mTimeButton->isChecked()) {
00401       startDate.setTime(mStartTimeEdit->getTime());
00402       dueDate.setTime(mDueTimeEdit->getTime());
00403     }
00404     if (startDate > dueDate) {
00405       KMessageBox::sorry(0,
00406                          i18n("The start date cannot be after the due date."));
00407       return false;
00408     }
00409   }
00410 
00411   return KOEditorGeneral::validateInput();
00412 }
00413 
00414 void KOEditorGeneralTodo::completedChanged(int index)
00415 {
00416   if (index == 5) {
00417     mCompleted = QDateTime::currentDateTime();
00418   }
00419   setCompletedDate();
00420 }
00421 
00422 void KOEditorGeneralTodo::setCompletedDate()
00423 {
00424   if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
00425     mCompletedLabel->setText(i18n("completed on %1")
00426         .arg(KGlobal::locale()->formatDateTime(mCompleted)));
00427   } else {
00428     mCompletedLabel->setText(i18n("completed"));
00429   }
00430 }
00431 
00432 void KOEditorGeneralTodo::modified (Todo* todo, int modification) 
00433 {
00434   switch (modification) {
00435   case KOGlobals::PRIORITY_MODIFIED:
00436     mPriorityCombo->setCurrentItem(todo->priority()-1);
00437     break;
00438   case KOGlobals::COMPLETION_MODIFIED:
00439     mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
00440     if (todo->isCompleted() && todo->hasCompletedDate()) {
00441       mCompleted = todo->completed();
00442     }
00443     setCompletedDate();
00444     break;
00445   case KOGlobals::CATEGORY_MODIFIED:
00446     setCategories (todo->categoriesStr ());
00447     break;
00448   case KOGlobals::UNKNOWN_MODIFIED: // fall through
00449   default:
00450     readTodo( todo );  
00451     break;
00452   }
00453 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:31 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001