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