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 mGeneral->enableAlarm( false );
00133 alarmLineLayout->addStretch( 1 );
00134 mGeneral->initDescription(topFrame,topLayout);
00135 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
00136 mGeneral->initCategories( topFrame, detailsLayout );
00137 mGeneral->initSecrecy( topFrame, detailsLayout );
00138 }
00139
00140
00141 mGeneral->setDefaults( QDateTime(), false );
00142
00143 mGeneral->finishSetup();
00144 }
00145
00146 void KOTodoEditor::setupRecurrence()
00147 {
00148 QFrame *topFrame = addPage( i18n("Rec&urrence") );
00149
00150 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00151
00152 mRecurrence = new KOEditorRecurrence( topFrame );
00153 topLayout->addWidget( mRecurrence );
00154
00155 mRecurrence->setEnabled( false );
00156 connect(mGeneral,SIGNAL(dueDateEditToggle( bool ) ),
00157 mRecurrence, SLOT( setEnabled( bool ) ) );
00158 }
00159
00160 void KOTodoEditor::editIncidence(Incidence *incidence)
00161 {
00162 kdDebug(5850) << k_funcinfo << endl;
00163 Todo *todo=dynamic_cast<Todo*>(incidence);
00164 if (todo)
00165 {
00166 init();
00167
00168 mTodo = todo;
00169 readTodo(mTodo);
00170 }
00171
00172 setCaption( i18n("Edit To-do") );
00173 }
00174
00175 void KOTodoEditor::newTodo()
00176 {
00177 kdDebug(5850) << k_funcinfo << endl;
00178 init();
00179 mTodo = 0;
00180 setCaption( i18n("New To-do") );
00181 }
00182
00183 void KOTodoEditor::setTexts( const QString &summary, const QString &description )
00184 {
00185 if ( description.isEmpty() && summary.contains("\n") ) {
00186 mGeneral->setDescription( summary );
00187 int pos = summary.find( "\n" );
00188 mGeneral->setSummary( summary.left( pos ) );
00189 } else {
00190 mGeneral->setSummary( summary );
00191 mGeneral->setDescription( description );
00192 }
00193 }
00194
00195
00196
00197 void KOTodoEditor::loadDefaults()
00198 {
00199 kdDebug(5850) << k_funcinfo << endl;
00200 setDates( QDateTime::currentDateTime().addDays(7), true, 0 );
00201 }
00202
00203 bool KOTodoEditor::processInput()
00204 {
00205 if ( !validateInput() ) return false;
00206
00207 if ( mTodo ) {
00208 bool rc = true;
00209 Todo *oldTodo = mTodo->clone();
00210 Todo *todo = mTodo->clone();
00211
00212 kdDebug(5850) << "KOTodoEditor::processInput() write event." << endl;
00213 writeTodo( todo );
00214 kdDebug(5850) << "KOTodoEditor::processInput() event written." << endl;
00215
00216 if( *mTodo == *todo )
00217
00218 kdDebug(5850) << "Todo not changed\n";
00219 else {
00220 kdDebug(5850) << "Todo changed\n";
00221
00222 writeTodo( mTodo );
00223 mChanger->changeIncidence( oldTodo, mTodo );
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, 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 emit dialogClose(mTodo);
00252 reject();
00253 }
00254
00255 void KOTodoEditor::setDates( const QDateTime &due, bool allDay, Todo *relatedEvent )
00256 {
00257 mRelatedTodo = relatedEvent;
00258
00259
00260 if ( mRelatedTodo ) {
00261 mGeneral->setCategories( mRelatedTodo->categories() );
00262 }
00263 if ( !due.isValid() && mRelatedTodo && mRelatedTodo->hasDueDate() ) {
00264 mGeneral->setDefaults( mRelatedTodo->dtDue(), allDay );
00265 } else {
00266 mGeneral->setDefaults( due, allDay );
00267 }
00268
00269 mDetails->setDefaults();
00270 if ( mTodo )
00271 mRecurrence->setDefaults( mTodo->dtStart(), due, false );
00272 else
00273 mRecurrence->setDefaults( QDateTime::currentDateTime(), due, false );
00274 mAttachments->setDefaults();
00275 }
00276
00277 void KOTodoEditor::readTodo( Todo *todo )
00278 {
00279 if ( !todo ) return;
00280
00281 kdDebug(5850)<<"read todo"<<endl;
00282 mGeneral->readTodo( todo );
00283 mDetails->readEvent( todo );
00284
00285 mRecurrence->readIncidence( todo );
00286 mAttachments->readIncidence( todo );
00287
00288 createEmbeddedURLPages( todo );
00289 readDesignerFields( todo );
00290 }
00291
00292 void KOTodoEditor::writeTodo( Todo *todo )
00293 {
00294 Incidence *oldIncidence = todo->clone();
00295
00296 mRecurrence->writeIncidence( todo );
00297 mGeneral->writeTodo( todo );
00298 mDetails->writeEvent( todo );
00299 mAttachments->writeIncidence( 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 writeDesignerFields( todo );
00307
00308
00309 if ( mRelatedTodo ) {
00310 todo->setRelatedTo( mRelatedTodo );
00311 }
00312
00313 cancelRemovedAttendees( todo );
00314 }
00315
00316 bool KOTodoEditor::validateInput()
00317 {
00318 if ( !mGeneral->validateInput() ) return false;
00319 if ( !mRecurrence->validateInput() ) return false;
00320 if ( !mDetails->validateInput() ) return false;
00321 return true;
00322 }
00323
00324 int KOTodoEditor::msgItemDelete()
00325 {
00326 return KMessageBox::warningContinueCancel(this,
00327 i18n("This item will be permanently deleted."),
00328 i18n("KOrganizer Confirmation"), KStdGuiItem::del() );
00329 }
00330
00331 void KOTodoEditor::modified (int )
00332 {
00333
00334
00335 reload();
00336 }
00337
00338 void KOTodoEditor::loadTemplate( CalendarLocal& cal )
00339 {
00340 Todo::List todos = cal.todos();
00341 if ( todos.count() == 0 ) {
00342 KMessageBox::error( this,
00343 i18n("Template does not contain a valid to-do.") );
00344 } else {
00345 readTodo( todos.first() );
00346 }
00347 }
00348
00349 void KOTodoEditor::slotSaveTemplate( const QString &templateName )
00350 {
00351 Todo *todo = new Todo;
00352 writeTodo( todo );
00353 saveAsTemplate( todo, templateName );
00354 }
00355
00356 QStringList& KOTodoEditor::templates() const
00357 {
00358 return KOPrefs::instance()->mTodoTemplates;
00359 }
00360
00361 #include "kotodoeditor.moc"