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
00026
00027 #include <qtooltip.h>
00028 #include <qframe.h>
00029 #include <qpixmap.h>
00030 #include <qlayout.h>
00031 #include <qdatetime.h>
00032
00033 #include <kiconloader.h>
00034 #include <klocale.h>
00035 #include <kmessagebox.h>
00036
00037 #include <libkcal/calendarlocal.h>
00038 #include <libkcal/calendarresources.h>
00039 #include <libkcal/resourcecalendar.h>
00040
00041 #include "koprefs.h"
00042 #include "koeditorattachments.h"
00043 #include "kogroupware.h"
00044 #include "kodialogmanager.h"
00045 #include "incidencechanger.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( QString::null, calendar, parent ),
00056 mTodo( 0 ), mCalendar( 0 ), mRelatedTodo( 0 ), mGeneral( 0 ), mRecurrence( 0 )
00057 {
00058 }
00059
00060 KOTodoEditor::~KOTodoEditor()
00061 {
00062 emit dialogClose( mTodo );
00063 }
00064
00065 void KOTodoEditor::init()
00066 {
00067 setupGeneral();
00068 setupRecurrence();
00069 setupAttendeesTab();
00070
00071 connect( mGeneral, SIGNAL( dateTimeStrChanged( const QString & ) ),
00072 mRecurrence, SLOT( setDateTimeStr( const QString & ) ) );
00073 connect( mGeneral, SIGNAL( signalDateTimeChanged( const QDateTime &, const QDateTime & ) ),
00074 mRecurrence, SLOT( setDateTimes( const QDateTime &, const QDateTime & ) ) );
00075
00076 connect( mGeneral, SIGNAL( openCategoryDialog() ),
00077 SIGNAL( editCategories() ) );
00078
00079 connect( mDetails, SIGNAL(updateAttendeeSummary(int)),
00080 mGeneral, SLOT(updateAttendeeSummary(int)) );
00081
00082 connect( mGeneral, SIGNAL(editRecurrence()),
00083 mRecurrenceDialog, SLOT(show()) );
00084 connect( mRecurrenceDialog, SIGNAL(okClicked()),
00085 SLOT(updateRecurrenceSummary()) );
00086 }
00087
00088 void KOTodoEditor::reload()
00089 {
00090 if ( mTodo ) {
00091 readTodo( mTodo, mCalendar, QDate() );
00092 }
00093 }
00094
00095 void KOTodoEditor::setupGeneral()
00096 {
00097 mGeneral = new KOEditorGeneralTodo(this);
00098
00099 if (KOPrefs::instance()->mCompactDialogs) {
00100 QFrame *topFrame = addPage(i18n("General"));
00101
00102 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00103 topLayout->setMargin(marginHint());
00104 topLayout->setSpacing(spacingHint());
00105
00106 mGeneral->initHeader( topFrame, topLayout );
00107 mGeneral->initTime(topFrame,topLayout);
00108 QHBoxLayout *priorityLayout = new QHBoxLayout( topLayout );
00109 mGeneral->initPriority(topFrame,priorityLayout);
00110 topLayout->addStretch(1);
00111
00112 QFrame *topFrame2 = addPage(i18n("Details"));
00113
00114 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
00115 topLayout2->setMargin(marginHint());
00116 topLayout2->setSpacing(spacingHint());
00117
00118 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
00119 mGeneral->initCompletion(topFrame2,completionLayout);
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 mGeneral->initDescription(topFrame,topLayout);
00133 mGeneral->initAttachments(topFrame,topLayout);
00134 connect( mGeneral, SIGNAL( openURL( const KURL& ) ),
00135 this, SLOT( openURL( const KURL& ) ) );
00136 connect( this, SIGNAL( signalAddAttachments( const QStringList&, const QStringList&, bool ) ),
00137 mGeneral, SLOT( addAttachments( const QStringList&, const QStringList&, bool ) ) );
00138 }
00139 mGeneral->finishSetup();
00140 }
00141
00142 void KOTodoEditor::setupRecurrence()
00143 {
00144 mRecurrenceDialog = new KOEditorRecurrenceDialog( this );
00145 mRecurrenceDialog->hide();
00146 mRecurrence = mRecurrenceDialog->editor();
00147 }
00148
00149 void KOTodoEditor::editIncidence( Incidence *incidence, const QDate &date, Calendar *calendar )
00150 {
00151 kdDebug(5850) << k_funcinfo << endl;
00152 Todo *todo = dynamic_cast<Todo*>( incidence );
00153 if ( todo ) {
00154 init();
00155 mTodo = todo;
00156 mCalendar = calendar;
00157 readTodo( mTodo, mCalendar, date );
00158 }
00159
00160 setCaption( i18n("Edit To-do") );
00161 }
00162
00163 void KOTodoEditor::newTodo()
00164 {
00165 kdDebug(5850) << k_funcinfo << endl;
00166 init();
00167 mTodo = 0;
00168 mCalendar = 0;
00169 setCaption( i18n("New To-do") );
00170 loadDefaults();
00171 }
00172
00173 void KOTodoEditor::setTexts( const QString &summary, const QString &description )
00174 {
00175 if ( description.isEmpty() && summary.contains("\n") ) {
00176 mGeneral->setDescription( summary );
00177 int pos = summary.find( "\n" );
00178 mGeneral->setSummary( summary.left( pos ) );
00179 } else {
00180 mGeneral->setSummary( summary );
00181 mGeneral->setDescription( description );
00182 }
00183 }
00184
00185 void KOTodoEditor::loadDefaults()
00186 {
00187 kdDebug(5850) << k_funcinfo << endl;
00188 setDates( QDateTime::currentDateTime().addDays( 7 ), true, 0 );
00189 mGeneral->toggleAlarm( KOPrefs::instance()->defaultTodoReminders() );
00190 }
00191
00192 bool KOTodoEditor::processInput()
00193 {
00194 if ( !validateInput() ) {
00195 return false;
00196 }
00197
00198 if ( mTodo ) {
00199 bool rc = true;
00200 Todo *oldTodo = mTodo->clone();
00201 Todo *todo = mTodo->clone();
00202
00203 kdDebug(5850) << "KOTodoEditor::processInput() write event." << endl;
00204 writeTodo( todo );
00205 kdDebug(5850) << "KOTodoEditor::processInput() event written." << endl;
00206
00207 if ( *mTodo == *todo ) {
00208
00209 kdDebug(5850) << "Todo not changed\n";
00210 } else {
00211 kdDebug(5850) << "Todo changed\n";
00212
00213 writeTodo( mTodo );
00214
00215 KOGlobals::WhatChanged whatChanged;
00216
00217 if ( !oldTodo->isCompleted() && todo->isCompleted() ) {
00218 whatChanged = KOGlobals::COMPLETION_MODIFIED;
00219 } else {
00220 whatChanged = KOGlobals::NOTHING_MODIFIED;
00221 }
00222
00223 mChanger->changeIncidence( oldTodo, mTodo, whatChanged, this );
00224 }
00225 delete todo;
00226 delete oldTodo;
00227 return rc;
00228
00229 } else {
00230 mTodo = new Todo;
00231 mTodo->setOrganizer( Person( KOPrefs::instance()->fullName(),
00232 KOPrefs::instance()->email() ) );
00233
00234 writeTodo( mTodo );
00235
00236 if ( !mChanger->addIncidence( mTodo, mResource, mSubResource, this ) ) {
00237 delete mTodo;
00238 mTodo = 0;
00239 return false;
00240 }
00241 }
00242
00243 return true;
00244
00245 }
00246
00247 void KOTodoEditor::deleteTodo()
00248 {
00249 if ( mTodo ) {
00250 emit deleteIncidenceSignal( mTodo );
00251 }
00252 emit dialogClose( mTodo );
00253 reject();
00254 }
00255
00256 void KOTodoEditor::setDates( const QDateTime &due, bool allDay, Todo *relatedEvent )
00257 {
00258 mRelatedTodo = relatedEvent;
00259
00260
00261 if ( mRelatedTodo ) {
00262 mGeneral->setCategories( mRelatedTodo->categories() );
00263 }
00264 if ( !due.isValid() && mRelatedTodo && mRelatedTodo->hasDueDate() ) {
00265 mGeneral->setDefaults( mRelatedTodo->dtDue(), allDay );
00266 } else {
00267 mGeneral->setDefaults( due, allDay );
00268 }
00269
00270 mDetails->setDefaults();
00271 if ( mTodo ) {
00272 mRecurrence->setDefaults( mTodo->dtStart(), due, false );
00273 } else {
00274 mRecurrence->setDefaults( QDateTime::currentDateTime(), due, false );
00275 }
00276 }
00277
00278 void KOTodoEditor::readTodo( Todo *todo, Calendar *calendar, const QDate &date )
00279 {
00280 if ( !todo ) {
00281 return;
00282 }
00283
00284
00285 mGeneral->readTodo( todo, calendar, date );
00286 mDetails->readEvent( todo );
00287 mRecurrence->readIncidence( todo );
00288
00289 createEmbeddedURLPages( todo );
00290 readDesignerFields( todo );
00291 }
00292
00293 void KOTodoEditor::writeTodo( Todo *todo )
00294 {
00295 Incidence *oldIncidence = todo->clone();
00296
00297 mRecurrence->writeIncidence( todo );
00298 mGeneral->writeTodo( todo );
00299 mDetails->writeEvent( todo );
00300
00301 if ( *(oldIncidence->recurrence()) != *(todo->recurrence() ) ) {
00302 todo->setDtDue( todo->dtDue(), true );
00303 if ( todo->hasStartDate() ) {
00304 todo->setDtStart( todo->dtStart() );
00305 }
00306 }
00307 writeDesignerFields( todo );
00308
00309
00310 if ( mRelatedTodo ) {
00311 todo->setRelatedTo( mRelatedTodo );
00312 }
00313
00314 cancelRemovedAttendees( todo );
00315 }
00316
00317 bool KOTodoEditor::validateInput()
00318 {
00319 Todo *todo = new Todo();
00320 writeTodo( todo );
00321
00322 if ( !mGeneral->validateInput() ) return false;
00323 if ( !mRecurrence->validateInput( mTodo ) ) return false;
00324 if ( !mDetails->validateInput() ) return false;
00325 return true;
00326 }
00327
00328 int KOTodoEditor::msgItemDelete()
00329 {
00330 return KMessageBox::warningContinueCancel(this,
00331 i18n("This item will be permanently deleted."),
00332 i18n("KOrganizer Confirmation"), KStdGuiItem::del() );
00333 }
00334
00335 void KOTodoEditor::modified()
00336 {
00337
00338
00339 reload();
00340 }
00341
00342 void KOTodoEditor::loadTemplate( CalendarLocal& cal )
00343 {
00344 Todo::List todos = cal.todos();
00345 if ( todos.count() == 0 ) {
00346 KMessageBox::error( this,
00347 i18n("Template does not contain a valid to-do.") );
00348 } else {
00349 readTodo( todos.first(), 0, QDate() );
00350 }
00351 }
00352
00353 void KOTodoEditor::slotSaveTemplate( const QString &templateName )
00354 {
00355 Todo *todo = new Todo;
00356 writeTodo( todo );
00357 saveAsTemplate( todo, templateName );
00358 }
00359
00360 QStringList& KOTodoEditor::templates() const
00361 {
00362 return KOPrefs::instance()->mTodoTemplates;
00363 }
00364
00365 void KOTodoEditor::updateRecurrenceSummary()
00366 {
00367 Todo *todo = new Todo();
00368 writeTodo( todo );
00369 mGeneral->updateRecurrenceSummary( todo );
00370 delete todo;
00371 }
00372
00373 #include "kotodoeditor.moc"