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