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
#include <qtooltip.h>
00027
#include <qframe.h>
00028
#include <qpixmap.h>
00029
#include <qlayout.h>
00030
#include <qdatetime.h>
00031
00032
#include <kabc/addressee.h>
00033
#include <kiconloader.h>
00034
#include <klocale.h>
00035
#include <kmessagebox.h>
00036
00037
#include <libkdepim/categoryselectdialog.h>
00038
#include <libkcal/calendarlocal.h>
00039
#include <libkcal/calendarresources.h>
00040
#include <libkcal/resourcecalendar.h>
00041
00042
#include "koprefs.h"
00043
#include "koeditorattachments.h"
00044
#include "kogroupware.h"
00045
#include "kodialogmanager.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( i18n(
"Edit To-Do"), calendar, parent )
00056 {
00057 mTodo = 0;
00058 mRelatedTodo = 0;
00059 }
00060
00061 KOTodoEditor::~KOTodoEditor()
00062 {
00063 emit dialogClose( mTodo );
00064 }
00065
00066 void KOTodoEditor::init()
00067 {
00068 setupGeneral();
00069 setupAttendeesTab();
00070 setupRecurrence();
00071 setupAttachmentsTab();
00072
00073 connect( mGeneral, SIGNAL( dateTimeStrChanged(
const QString & ) ),
00074 mRecurrence, SLOT( setDateTimeStr(
const QString & ) ) );
00075 connect( mGeneral, SIGNAL( signalDateTimeChanged(
QDateTime,
QDateTime ) ),
00076 mRecurrence, SLOT( setDateTimes(
QDateTime,
QDateTime ) ) );
00077 }
00078
00079
void KOTodoEditor::reload()
00080 {
00081 kdDebug()<<
"reloading todo"<<endl;
00082
if ( mTodo )
readTodo( mTodo );
00083 }
00084
00085
void KOTodoEditor::setupGeneral()
00086 {
00087 mGeneral =
new KOEditorGeneralTodo(
this);
00088
00089 connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
00090 connect(mCategoryDialog, SIGNAL(categoriesSelected(
const QString &)),
00091 mGeneral,SLOT(setCategories(
const QString &)));
00092 connect(mGeneral,SIGNAL( todoCompleted( Todo * )),
00093 SIGNAL( todoCompleted( Todo * ) ) );
00094
00095
if (KOPrefs::instance()->mCompactDialogs) {
00096
QFrame *topFrame = addPage(i18n(
"General"));
00097
00098
QBoxLayout *topLayout =
new QVBoxLayout(topFrame);
00099 topLayout->
setMargin(marginHint());
00100 topLayout->
setSpacing(spacingHint());
00101
00102 mGeneral->initHeader(topFrame,topLayout);
00103 mGeneral->initTime(topFrame,topLayout);
00104
QHBoxLayout *priorityLayout =
new QHBoxLayout( topLayout );
00105 mGeneral->initPriority(topFrame,priorityLayout);
00106 mGeneral->initCategories( topFrame, topLayout );
00107 topLayout->addStretch(1);
00108
00109
QFrame *topFrame2 = addPage(i18n(
"Details"));
00110
00111
QBoxLayout *topLayout2 =
new QVBoxLayout(topFrame2);
00112 topLayout2->
setMargin(marginHint());
00113 topLayout2->
setSpacing(spacingHint());
00114
00115
QHBoxLayout *completionLayout =
new QHBoxLayout( topLayout2 );
00116 mGeneral->initCompletion(topFrame2,completionLayout);
00117
00118 mGeneral->initAlarm(topFrame,topLayout);
00119 mGeneral->enableAlarm(
false );
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
QBoxLayout *alarmLineLayout =
new QHBoxLayout(topLayout);
00133 mGeneral->initAlarm(topFrame,alarmLineLayout);
00134 mGeneral->initDescription(topFrame,topLayout);
00135
QBoxLayout *detailsLayout =
new QHBoxLayout(topLayout);
00136 mGeneral->initCategories( topFrame, detailsLayout );
00137 mGeneral->initSecrecy( topFrame, detailsLayout );
00138 }
00139
00140 mGeneral->finishSetup();
00141 }
00142
00143
void KOTodoEditor::setupRecurrence()
00144 {
00145
QFrame *topFrame = addPage( i18n(
"Rec&urrence") );
00146
00147
QBoxLayout *topLayout =
new QVBoxLayout( topFrame );
00148
00149 mRecurrence =
new KOEditorRecurrence( topFrame );
00150 topLayout->
addWidget( mRecurrence );
00151
00152 mRecurrence->setEnabled(
false );
00153 connect(mGeneral,SIGNAL(dueDateEditToggle(
bool ) ),
00154 mRecurrence, SLOT( setEnabled(
bool ) ) );
00155 }
00156
00157 void KOTodoEditor::editIncidence(Incidence *incidence)
00158 {
00159 Todo *todo=dynamic_cast<Todo*>(incidence);
00160
if (todo)
00161 {
00162
init();
00163
00164 mTodo = todo;
00165
readTodo(mTodo);
00166 }
00167 }
00168
00169 void KOTodoEditor::newTodo(
QDateTime due,Todo *relatedTodo,
bool allDay)
00170 {
00171
init();
00172
00173 mTodo = 0;
00174
setDefaults(due,relatedTodo,allDay);
00175 }
00176
00177 void KOTodoEditor::newTodo(
const QString &text )
00178 {
00179
init();
00180
00181 mTodo = 0;
00182
00183 loadDefaults();
00184
00185 mGeneral->setDescription( text );
00186
00187
int pos = text.find(
"\n" );
00188
if ( pos > 0 ) {
00189 mGeneral->setSummary( text.left( pos ) );
00190 mGeneral->setDescription( text );
00191 }
else {
00192 mGeneral->setSummary( text );
00193 }
00194 }
00195
00196 void KOTodoEditor::newTodo(
const QString &summary,
00197
const QString &description,
00198
const QString &attachment )
00199 {
00200
init();
00201
00202 mTodo = 0;
00203
00204 loadDefaults();
00205
00206 mGeneral->setSummary( summary );
00207 mGeneral->setDescription( description );
00208
00209
if ( !attachment.isEmpty() ) {
00210 mAttachments->addAttachment( attachment );
00211 }
00212 }
00213
00214 void KOTodoEditor::newTodo(
const QString &summary,
00215
const QString &description,
00216
const QString &attachment,
00217
const QStringList &attendees )
00218 {
00219
newTodo( summary, description, attachment );
00220
00221 QStringList::ConstIterator it;
00222
for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00223
QString name, email;
00224 KABC::Addressee::parseEmailAddress( *it, name, email );
00225 mDetails->insertAttendee(
new Attendee( name, email ) );
00226 }
00227 }
00228
00229
void KOTodoEditor::loadDefaults()
00230 {
00231
setDefaults(QDateTime::currentDateTime().addDays(7),0,
false);
00232 }
00233
00234
00235 bool KOTodoEditor::processInput()
00236 {
00237
if ( !
validateInput() )
return false;
00238
00239
if ( mTodo ) {
00240
bool rc =
true;
00241 Todo *todo = mTodo->clone();
00242 Todo *oldTodo = mTodo->clone();
00243
00244 kdDebug(5850) <<
"KOTodoEditor::processInput() write todo." << endl;
00245
writeTodo( todo );
00246 kdDebug(5850) <<
"KOTodoEditor::processInput() event written." << endl;
00247
00248
if( *mTodo == *todo )
00249
00250 kdDebug(5850) <<
"Todo not changed\n";
00251
else {
00252 kdDebug(5850) <<
"Todo changed\n";
00253
int revision = todo->revision();
00254 todo->setRevision( revision + 1 );
00255
if( !KOPrefs::instance()->mUseGroupwareCommunication ||
00256 KOGroupware::instance()->sendICalMessage(
this,
00257 KCal::Scheduler::Request,
00258 todo ) ) {
00259
00260
writeTodo( mTodo );
00261 mTodo->setRevision( revision + 1 );
00262 emit incidenceChanged( oldTodo, mTodo );
00263 }
else {
00264
00265 todo->setRevision( revision );
00266 rc =
false;
00267 }
00268 }
00269
delete todo;
00270
delete oldTodo;
00271
return rc;
00272
00273 }
else {
00274 mTodo =
new Todo;
00275 mTodo->setOrganizer( KOPrefs::instance()->email() );
00276
00277
writeTodo( mTodo );
00278
if ( KOPrefs::instance()->mUseGroupwareCommunication ) {
00279
if ( !KOGroupware::instance()->sendICalMessage(
this,
00280 KCal::Scheduler::Request,
00281 mTodo ) ) {
00282 kdError() <<
"sendIcalMessage failed." << endl;
00283 }
00284 }
00285
00286
if ( !mCalendar->addIncidence( mTodo ) ) {
00287 KODialogManager::errorSaveTodo(
this );
00288
delete mTodo;
00289 mTodo = 0;
00290
return false;
00291 }
00292
00293 emit incidenceAdded( mTodo );
00294
00295 }
00296
00297
return true;
00298
00299 }
00300
00301
void KOTodoEditor::processCancel()
00302 {
00303
if ( mTodo ) {
00304 emit editCanceled( mTodo );
00305 }
00306 }
00307
00308
void KOTodoEditor::deleteTodo()
00309 {
00310
if (mTodo) {
00311
if (KOPrefs::instance()->mConfirm) {
00312
switch (msgItemDelete()) {
00313
case KMessageBox::Continue:
00314 emit incidenceToBeDeleted(mTodo);
00315 emit dialogClose(mTodo);
00316 mCalendar->deleteTodo(mTodo);
00317 emit incidenceDeleted( mTodo );
00318 reject();
00319
break;
00320 }
00321 }
00322
else {
00323 emit incidenceToBeDeleted(mTodo);
00324 emit dialogClose(mTodo);
00325 mCalendar->deleteTodo(mTodo);
00326 emit incidenceDeleted( mTodo );
00327 reject();
00328 }
00329 }
else {
00330 reject();
00331 }
00332 }
00333
00334 void KOTodoEditor::setDefaults(
QDateTime due, Todo *relatedEvent,
bool allDay )
00335 {
00336 mRelatedTodo = relatedEvent;
00337
00338
00339
if ( mRelatedTodo ) {
00340 mGeneral->setCategories( mRelatedTodo->categoriesStr() );
00341 mCategoryDialog->setSelected( mRelatedTodo->categories() );
00342
if ( mRelatedTodo->hasDueDate() )
00343 mGeneral->setDefaults( mRelatedTodo->dtDue(), allDay );
00344
else
00345 mGeneral->setDefaults( due, allDay );
00346 }
00347
else
00348 mGeneral->setDefaults( due, allDay );
00349
00350 mDetails->setDefaults();
00351
if ( mTodo )
00352 mRecurrence->setDefaults( mTodo->dtStart(), due,
false );
00353
else
00354 mRecurrence->setDefaults( QDateTime::currentDateTime(), due,
false );
00355 mAttachments->setDefaults();
00356 }
00357
00358 void KOTodoEditor::readTodo( Todo *todo )
00359 {
00360 kdDebug()<<
"read todo"<<endl;
00361 mGeneral->readTodo( todo );
00362 mDetails->readEvent( todo );
00363 mRecurrence->readIncidence( todo );
00364 mAttachments->readIncidence( todo );
00365
00366
00367 mCategoryDialog->setSelected( todo->categories() );
00368 }
00369
00370 void KOTodoEditor::writeTodo( Todo *todo )
00371 {
00372 mGeneral->writeTodo( todo );
00373 mDetails->writeEvent( todo );
00374 mRecurrence->writeIncidence( todo );
00375 mAttachments->writeIncidence( todo );
00376
00377
00378
if ( mRelatedTodo ) {
00379 todo->setRelatedTo( mRelatedTodo );
00380 }
00381
00382 cancelRemovedAttendees( todo );
00383 }
00384
00385 bool KOTodoEditor::validateInput()
00386 {
00387
if ( !mGeneral->validateInput() )
return false;
00388
if ( !mRecurrence->validateInput() )
return false;
00389
if ( !mDetails->validateInput() )
return false;
00390
return true;
00391 }
00392
00393
int KOTodoEditor::msgItemDelete()
00394 {
00395
return KMessageBox::warningContinueCancel(
this,
00396 i18n(
"This item will be permanently deleted."),
00397 i18n(
"KOrganizer Confirmation"),KGuiItem(i18n(
"Delete"),
"editdelete"));
00398 }
00399
00400 void KOTodoEditor::modified (
int )
00401 {
00402
00403
00404 reload();
00405 }
00406
00407
void KOTodoEditor::slotLoadTemplate()
00408 {
00409 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId );
00410 Todo *todo =
new Todo;
00411
QString templateName = loadTemplate( &cal, todo->type(),
00412 KOPrefs::instance()->mTodoTemplates );
00413
delete todo;
00414
if ( templateName.isEmpty() ) {
00415
return;
00416 }
00417
00418 Todo::List todos = cal.todos();
00419
if ( todos.count() == 0 ) {
00420 KMessageBox::error(
this,
00421 i18n(
"Template '%1' does not contain a valid todo.")
00422 .arg( templateName ) );
00423 }
else {
00424
readTodo( todos.first() );
00425 }
00426 }
00427
00428
void KOTodoEditor::saveTemplate(
const QString &templateName )
00429 {
00430 Todo *todo =
new Todo;
00431
writeTodo( todo );
00432 saveAsTemplate( todo, templateName );
00433 }
00434
00435
#include "kotodoeditor.moc"