korganizer Library API Documentation

kotodoeditor.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 1997, 1998 Preston Brown 00005 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00020 00021 As a special exception, permission is given to link this program 00022 with any edition of Qt, and distribute the resulting executable, 00023 without including the source code for Qt in the source distribution. 00024 */ 00025 00026 #include <qtooltip.h> 00027 #include <qframe.h> 00028 #include <qpixmap.h> 00029 #include <qlayout.h> 00030 #include <qdatetime.h> 00031 00032 #include <kabc/addressee.h> 00033 #include <kiconloader.h> 00034 #include <klocale.h> 00035 #include <kmessagebox.h> 00036 00037 #include <libkdepim/categoryselectdialog.h> 00038 #include <libkcal/calendarlocal.h> 00039 #include <libkcal/calendarresources.h> 00040 #include <libkcal/resourcecalendar.h> 00041 00042 #include "koprefs.h" 00043 #include "koeditorattachments.h" 00044 #include "kogroupware.h" 00045 #include "kodialogmanager.h" 00046 00047 #include "koeditorgeneraltodo.h" 00048 #include "koeditordetails.h" 00049 #include "koeditorrecurrence.h" 00050 00051 #include "kotodoeditor.h" 00052 #include "kocore.h" 00053 00054 KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 00055 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 00056 { 00057 mTodo = 0; 00058 mRelatedTodo = 0; 00059 } 00060 00061 KOTodoEditor::~KOTodoEditor() 00062 { 00063 emit dialogClose( mTodo ); 00064 } 00065 00066 void KOTodoEditor::init() 00067 { 00068 setupGeneral(); 00069 setupAttendeesTab(); 00070 setupRecurrence(); 00071 setupAttachmentsTab(); 00072 00073 connect( mGeneral, SIGNAL( dateTimeStrChanged( const QString & ) ), 00074 mRecurrence, SLOT( setDateTimeStr( const QString & ) ) ); 00075 connect( mGeneral, SIGNAL( signalDateTimeChanged( QDateTime, QDateTime ) ), 00076 mRecurrence, SLOT( setDateTimes( QDateTime, QDateTime ) ) ); 00077 } 00078 00079 void KOTodoEditor::reload() 00080 { 00081 kdDebug()<<"reloading todo"<<endl; 00082 if ( mTodo ) readTodo( mTodo ); 00083 } 00084 00085 void KOTodoEditor::setupGeneral() 00086 { 00087 mGeneral = new KOEditorGeneralTodo(this); 00088 00089 connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 00090 connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 00091 mGeneral,SLOT(setCategories(const QString &))); 00092 connect(mGeneral,SIGNAL( todoCompleted( Todo * )), 00093 SIGNAL( todoCompleted( Todo * ) ) ); 00094 00095 if (KOPrefs::instance()->mCompactDialogs) { 00096 QFrame *topFrame = addPage(i18n("General")); 00097 00098 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 00099 topLayout->setMargin(marginHint()); 00100 topLayout->setSpacing(spacingHint()); 00101 00102 mGeneral->initHeader(topFrame,topLayout); 00103 mGeneral->initTime(topFrame,topLayout); 00104 QHBoxLayout *priorityLayout = new QHBoxLayout( topLayout ); 00105 mGeneral->initPriority(topFrame,priorityLayout); 00106 mGeneral->initCategories( topFrame, topLayout ); 00107 topLayout->addStretch(1); 00108 00109 QFrame *topFrame2 = addPage(i18n("Details")); 00110 00111 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); 00112 topLayout2->setMargin(marginHint()); 00113 topLayout2->setSpacing(spacingHint()); 00114 00115 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); 00116 mGeneral->initCompletion(topFrame2,completionLayout); 00117 00118 mGeneral->initAlarm(topFrame,topLayout); 00119 mGeneral->enableAlarm( false ); 00120 00121 mGeneral->initSecrecy( topFrame2, topLayout2 ); 00122 mGeneral->initDescription(topFrame2,topLayout2); 00123 } else { 00124 QFrame *topFrame = addPage(i18n("&General")); 00125 00126 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 00127 topLayout->setSpacing(spacingHint()); 00128 00129 mGeneral->initHeader(topFrame,topLayout); 00130 mGeneral->initTime(topFrame,topLayout); 00131 mGeneral->initStatus(topFrame,topLayout); 00132 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); 00133 mGeneral->initAlarm(topFrame,alarmLineLayout); 00134 mGeneral->initDescription(topFrame,topLayout); 00135 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); 00136 mGeneral->initCategories( topFrame, detailsLayout ); 00137 mGeneral->initSecrecy( topFrame, detailsLayout ); 00138 } 00139 00140 mGeneral->finishSetup(); 00141 } 00142 00143 void KOTodoEditor::setupRecurrence() 00144 { 00145 QFrame *topFrame = addPage( i18n("Rec&urrence") ); 00146 00147 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 00148 00149 mRecurrence = new KOEditorRecurrence( topFrame ); 00150 topLayout->addWidget( mRecurrence ); 00151 00152 mRecurrence->setEnabled( false ); 00153 connect(mGeneral,SIGNAL(dueDateEditToggle( bool ) ), 00154 mRecurrence, SLOT( setEnabled( bool ) ) ); 00155 } 00156 00157 void KOTodoEditor::editIncidence(Incidence *incidence) 00158 { 00159 Todo *todo=dynamic_cast<Todo*>(incidence); 00160 if (todo) 00161 { 00162 init(); 00163 00164 mTodo = todo; 00165 readTodo(mTodo); 00166 } 00167 } 00168 00169 void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 00170 { 00171 init(); 00172 00173 mTodo = 0; 00174 setDefaults(due,relatedTodo,allDay); 00175 } 00176 00177 void KOTodoEditor::newTodo( const QString &text ) 00178 { 00179 init(); 00180 00181 mTodo = 0; 00182 00183 loadDefaults(); 00184 00185 mGeneral->setDescription( text ); 00186 00187 int pos = text.find( "\n" ); 00188 if ( pos > 0 ) { 00189 mGeneral->setSummary( text.left( pos ) ); 00190 mGeneral->setDescription( text ); 00191 } else { 00192 mGeneral->setSummary( text ); 00193 } 00194 } 00195 00196 void KOTodoEditor::newTodo( const QString &summary, 00197 const QString &description, 00198 const QString &attachment ) 00199 { 00200 init(); 00201 00202 mTodo = 0; 00203 00204 loadDefaults(); 00205 00206 mGeneral->setSummary( summary ); 00207 mGeneral->setDescription( description ); 00208 00209 if ( !attachment.isEmpty() ) { 00210 mAttachments->addAttachment( attachment ); 00211 } 00212 } 00213 00214 void KOTodoEditor::newTodo( const QString &summary, 00215 const QString &description, 00216 const QString &attachment, 00217 const QStringList &attendees ) 00218 { 00219 newTodo( summary, description, attachment ); 00220 00221 QStringList::ConstIterator it; 00222 for ( it = attendees.begin(); it != attendees.end(); ++it ) { 00223 QString name, email; 00224 KABC::Addressee::parseEmailAddress( *it, name, email ); 00225 mDetails->insertAttendee( new Attendee( name, email ) ); 00226 } 00227 } 00228 00229 void KOTodoEditor::loadDefaults() 00230 { 00231 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 00232 } 00233 00234 // TODO_RK: make sure calendar()->endChange is called somewhere! 00235 bool KOTodoEditor::processInput() 00236 { 00237 if ( !validateInput() ) return false; 00238 00239 if ( mTodo ) { 00240 bool rc = true; 00241 Todo *todo = mTodo->clone(); 00242 Todo *oldTodo = mTodo->clone(); 00243 00244 kdDebug(5850) << "KOTodoEditor::processInput() write todo." << endl; 00245 writeTodo( todo ); 00246 kdDebug(5850) << "KOTodoEditor::processInput() event written." << endl; 00247 00248 if( *mTodo == *todo ) 00249 // Don't do anything 00250 kdDebug(5850) << "Todo not changed\n"; 00251 else { 00252 kdDebug(5850) << "Todo changed\n"; 00253 int revision = todo->revision(); 00254 todo->setRevision( revision + 1 ); 00255 if( !KOPrefs::instance()->mUseGroupwareCommunication || 00256 KOGroupware::instance()->sendICalMessage( this, 00257 KCal::Scheduler::Request, 00258 todo ) ) { 00259 // Accept the event changes 00260 writeTodo( mTodo ); 00261 mTodo->setRevision( revision + 1 ); 00262 emit incidenceChanged( oldTodo, mTodo ); 00263 } else { 00264 // Revert the changes 00265 todo->setRevision( revision ); 00266 rc = false; 00267 } 00268 } 00269 delete todo; 00270 delete oldTodo; 00271 return rc; 00272 00273 } else { 00274 mTodo = new Todo; 00275 mTodo->setOrganizer( KOPrefs::instance()->email() ); 00276 00277 writeTodo( mTodo ); 00278 if ( KOPrefs::instance()->mUseGroupwareCommunication ) { 00279 if ( !KOGroupware::instance()->sendICalMessage( this, 00280 KCal::Scheduler::Request, 00281 mTodo ) ) { 00282 kdError() << "sendIcalMessage failed." << endl; 00283 } 00284 } 00285 00286 if ( !mCalendar->addIncidence( mTodo ) ) { 00287 KODialogManager::errorSaveTodo( this ); 00288 delete mTodo; 00289 mTodo = 0; 00290 return false; 00291 } 00292 00293 emit incidenceAdded( mTodo ); 00294 00295 } 00296 00297 return true; 00298 00299 } 00300 00301 void KOTodoEditor::processCancel() 00302 { 00303 if ( mTodo ) { 00304 emit editCanceled( mTodo ); 00305 } 00306 } 00307 00308 void KOTodoEditor::deleteTodo() 00309 { 00310 if (mTodo) { 00311 if (KOPrefs::instance()->mConfirm) { 00312 switch (msgItemDelete()) { 00313 case KMessageBox::Continue: // OK 00314 emit incidenceToBeDeleted(mTodo); 00315 emit dialogClose(mTodo); 00316 mCalendar->deleteTodo(mTodo); 00317 emit incidenceDeleted( mTodo ); 00318 reject(); 00319 break; 00320 } 00321 } 00322 else { 00323 emit incidenceToBeDeleted(mTodo); 00324 emit dialogClose(mTodo); 00325 mCalendar->deleteTodo(mTodo); 00326 emit incidenceDeleted( mTodo ); 00327 reject(); 00328 } 00329 } else { 00330 reject(); 00331 } 00332 } 00333 00334 void KOTodoEditor::setDefaults( QDateTime due, Todo *relatedEvent, bool allDay ) 00335 { 00336 mRelatedTodo = relatedEvent; 00337 00338 // inherit some properties from parent todo 00339 if ( mRelatedTodo ) { 00340 mGeneral->setCategories( mRelatedTodo->categoriesStr() ); 00341 mCategoryDialog->setSelected( mRelatedTodo->categories() ); 00342 if ( mRelatedTodo->hasDueDate() ) 00343 mGeneral->setDefaults( mRelatedTodo->dtDue(), allDay ); 00344 else 00345 mGeneral->setDefaults( due, allDay ); 00346 } 00347 else 00348 mGeneral->setDefaults( due, allDay ); 00349 00350 mDetails->setDefaults(); 00351 if ( mTodo ) 00352 mRecurrence->setDefaults( mTodo->dtStart(), due, false ); 00353 else 00354 mRecurrence->setDefaults( QDateTime::currentDateTime(), due, false ); 00355 mAttachments->setDefaults(); 00356 } 00357 00358 void KOTodoEditor::readTodo( Todo *todo ) 00359 { 00360 kdDebug()<<"read todo"<<endl; 00361 mGeneral->readTodo( todo ); 00362 mDetails->readEvent( todo ); 00363 mRecurrence->readIncidence( todo ); 00364 mAttachments->readIncidence( todo ); 00365 00366 // categories 00367 mCategoryDialog->setSelected( todo->categories() ); 00368 } 00369 00370 void KOTodoEditor::writeTodo( Todo *todo ) 00371 { 00372 Incidence *oldIncidence = todo->clone(); 00373 00374 mRecurrence->writeIncidence( todo ); 00375 mGeneral->writeTodo( todo ); 00376 mDetails->writeEvent( todo ); 00377 mAttachments->writeIncidence( todo ); 00378 00379 if ( *(oldIncidence->recurrence()) != *(todo->recurrence() ) ) { 00380 todo->setDtDue( todo->dtDue(), true ); 00381 if ( todo->hasStartDate() ) 00382 todo->setDtStart( todo->dtStart() ); 00383 } 00384 00385 // set related event, i.e. parent to-do in this case. 00386 if ( mRelatedTodo ) { 00387 todo->setRelatedTo( mRelatedTodo ); 00388 } 00389 00390 cancelRemovedAttendees( todo ); 00391 } 00392 00393 bool KOTodoEditor::validateInput() 00394 { 00395 if ( !mGeneral->validateInput() ) return false; 00396 if ( !mRecurrence->validateInput() ) return false; 00397 if ( !mDetails->validateInput() ) return false; 00398 return true; 00399 } 00400 00401 int KOTodoEditor::msgItemDelete() 00402 { 00403 return KMessageBox::warningContinueCancel(this, 00404 i18n("This item will be permanently deleted."), 00405 i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete")); 00406 } 00407 00408 void KOTodoEditor::modified (int /*modification*/) 00409 { 00410 // Play dump, just reload the todo. This dialog has become so complicated that 00411 // there is no point in trying to be smart here... 00412 reload(); 00413 } 00414 00415 void KOTodoEditor::slotLoadTemplate() 00416 { 00417 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId ); 00418 Todo *todo = new Todo; 00419 QString templateName = loadTemplate( &cal, todo->type(), 00420 KOPrefs::instance()->mTodoTemplates ); 00421 delete todo; 00422 if ( templateName.isEmpty() ) { 00423 return; 00424 } 00425 00426 Todo::List todos = cal.todos(); 00427 if ( todos.count() == 0 ) { 00428 KMessageBox::error( this, 00429 i18n("Template '%1' does not contain a valid todo.") 00430 .arg( templateName ) ); 00431 } else { 00432 readTodo( todos.first() ); 00433 } 00434 } 00435 00436 void KOTodoEditor::saveTemplate( const QString &templateName ) 00437 { 00438 Todo *todo = new Todo; 00439 writeTodo( todo ); 00440 saveAsTemplate( todo, templateName ); 00441 } 00442 00443 #include "kotodoeditor.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:57 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003