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