summaryrefslogtreecommitdiffabout
path: root/korganizer/kotodoeditor.cpp
Unidiff
Diffstat (limited to 'korganizer/kotodoeditor.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/kotodoeditor.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
index 9073bca..8b90ae5 100644
--- a/korganizer/kotodoeditor.cpp
+++ b/korganizer/kotodoeditor.cpp
@@ -30,96 +30,98 @@
30#include <qdir.h> 30#include <qdir.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qapplication.h> 32#include <qapplication.h>
33#include <qtabwidget.h> 33#include <qtabwidget.h>
34 34
35#include <kiconloader.h> 35#include <kiconloader.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kfiledialog.h> 37#include <kfiledialog.h>
38#include <kstandarddirs.h> 38#include <kstandarddirs.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40 40
41#include <libkdepim/categoryselectdialog.h> 41#include <libkdepim/categoryselectdialog.h>
42#include <libkcal/calendarlocal.h> 42#include <libkcal/calendarlocal.h>
43#include <libkcal/calendarresources.h> 43#include <libkcal/calendarresources.h>
44#include <libkcal/resourcecalendar.h> 44#include <libkcal/resourcecalendar.h>
45#include <libkcal/icalformat.h> 45#include <libkcal/icalformat.h>
46#include <kresources/resourceselectdialog.h> 46#include <kresources/resourceselectdialog.h>
47#include <libkdepim/kdateedit.h> 47#include <libkdepim/kdateedit.h>
48 48
49#include "koprefs.h" 49#include "koprefs.h"
50#include "kolocationbox.h" 50#include "kolocationbox.h"
51 51
52#include "kotodoeditor.h" 52#include "kotodoeditor.h"
53extern int globalFlagBlockAgenda; 53extern int globalFlagBlockAgenda;
54 54
55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
57{ 57{
58 mTodo = 0; 58 mTodo = 0;
59 mRelatedTodo = 0; 59 mRelatedTodo = 0;
60 findButton(User1)->hide(); 60 findButton(User1)->hide();
61 init(); 61 init();
62 if ( QApplication::desktop()->height() <= 240 ) 62 if ( QApplication::desktop()->height() <= 240 )
63 hideButtons(); 63 hideButtons();
64} 64}
65 65
66KOTodoEditor::~KOTodoEditor() 66KOTodoEditor::~KOTodoEditor()
67{ 67{
68 emit dialogClose( mTodo ); 68 emit dialogClose( mTodo );
69} 69}
70 70
71void KOTodoEditor::init() 71void KOTodoEditor::init()
72{ 72{
73 setupGeneral(); 73 setupGeneral();
74 setupAttendeesTab(); 74 setupAttendeesTab();
75 setupRecurrence(); 75 setupRecurrence();
76 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence())); 76 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence()));
77 mRecurrence->setDateTimeStr( i18n("<i>The recurrence is computed from the start datetime!</i>") ); 77 mRecurrence->setDateTimeStr( i18n("<i>The recurrence is computed from the start datetime!</i>") );
78 connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)),
79 mRecurrence,SLOT(setDefaultsDates(QDateTime,QDateTime)));
78} 80}
79void KOTodoEditor::setupRecurrence() 81void KOTodoEditor::setupRecurrence()
80{ 82{
81 QFrame *topFrame = addPage( i18n("Recurrence") ); 83 QFrame *topFrame = addPage( i18n("Recurrence") );
82 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 84 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
83 85
84 mRecurrence = new KOEditorRecurrence( topFrame ); 86 mRecurrence = new KOEditorRecurrence( topFrame );
85 topLayout->addWidget( mRecurrence ); 87 topLayout->addWidget( mRecurrence );
86} 88}
87 89
88void KOTodoEditor::setCategories( QString s ) 90void KOTodoEditor::setCategories( QString s )
89{ 91{
90 mGeneral->setCategories(s); 92 mGeneral->setCategories(s);
91} 93}
92void KOTodoEditor::setSecrecy( int sec ) 94void KOTodoEditor::setSecrecy( int sec )
93{ 95{
94 mGeneral->setSecrecy( sec ); 96 mGeneral->setSecrecy( sec );
95} 97}
96void KOTodoEditor::reload() 98void KOTodoEditor::reload()
97{ 99{
98 if ( mTodo ) readTodo( mTodo ); 100 if ( mTodo ) readTodo( mTodo );
99} 101}
100 102
101void KOTodoEditor::setupGeneral() 103void KOTodoEditor::setupGeneral()
102{ 104{
103 mGeneral = new KOEditorGeneralTodo(this); 105 mGeneral = new KOEditorGeneralTodo(this);
104 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); 106 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
105 107
106 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 108 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
107 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 109 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
108 // mGeneral,SLOT(setCategories(const QString &))); 110 // mGeneral,SLOT(setCategories(const QString &)));
109 111
110 if (KOPrefs::instance()->mCompactDialogs) { 112 if (KOPrefs::instance()->mCompactDialogs) {
111 QFrame *topFrame = addPage(i18n("General")); 113 QFrame *topFrame = addPage(i18n("General"));
112 114
113 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 115 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
114 if ( QApplication::desktop()->width() < 480 ) { 116 if ( QApplication::desktop()->width() < 480 ) {
115 topLayout->setMargin(marginHintSmall()); 117 topLayout->setMargin(marginHintSmall());
116 topLayout->setSpacing(spacingHintSmall()); 118 topLayout->setSpacing(spacingHintSmall());
117 } else { 119 } else {
118 topLayout->setMargin(marginHint()); 120 topLayout->setMargin(marginHint());
119 topLayout->setSpacing(spacingHint()); 121 topLayout->setSpacing(spacingHint());
120 } 122 }
121 mGeneral->initHeader(topFrame,topLayout); 123 mGeneral->initHeader(topFrame,topLayout);
122 mGeneral->initTime(topFrame,topLayout); 124 mGeneral->initTime(topFrame,topLayout);
123 mGeneral->initAlarm(topFrame,topLayout); 125 mGeneral->initAlarm(topFrame,topLayout);
124 mGeneral->enableAlarm( false ); 126 mGeneral->enableAlarm( false );
125 127
@@ -260,122 +262,122 @@ bool KOTodoEditor::processInput( bool emitTime )
260 262
261void KOTodoEditor::deleteTodo() 263void KOTodoEditor::deleteTodo()
262{ 264{
263 if (mTodo) { 265 if (mTodo) {
264 if (KOPrefs::instance()->mConfirm) { 266 if (KOPrefs::instance()->mConfirm) {
265 switch (msgItemDelete()) { 267 switch (msgItemDelete()) {
266 case KMessageBox::Continue: // OK 268 case KMessageBox::Continue: // OK
267 emit todoToBeDeleted(mTodo); 269 emit todoToBeDeleted(mTodo);
268 emit dialogClose(mTodo); 270 emit dialogClose(mTodo);
269 mCalendar->deleteTodo(mTodo); 271 mCalendar->deleteTodo(mTodo);
270 emit todoDeleted(); 272 emit todoDeleted();
271 reject(); 273 reject();
272 break; 274 break;
273 } 275 }
274 } 276 }
275 else { 277 else {
276 emit todoToBeDeleted(mTodo); 278 emit todoToBeDeleted(mTodo);
277 emit dialogClose(mTodo); 279 emit dialogClose(mTodo);
278 mCalendar->deleteTodo(mTodo); 280 mCalendar->deleteTodo(mTodo);
279 emit todoDeleted(); 281 emit todoDeleted();
280 reject(); 282 reject();
281 } 283 }
282 } else { 284 } else {
283 reject(); 285 reject();
284 } 286 }
285} 287}
286 288
287void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) 289void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
288{ 290{
289 mRelatedTodo = relatedEvent; 291 mRelatedTodo = relatedEvent;
290 292
291 mGeneral->setDefaults(due,allDay); 293 mGeneral->setDefaults(due,allDay);
292 mDetails->setDefaults(); 294 mDetails->setDefaults();
293 showPage( 0 ); 295 showPage( 0 );
294 if ( mRelatedTodo ) { 296 if ( mRelatedTodo ) {
295 mGeneral->setCategories (mRelatedTodo->categoriesStr ()); 297 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
296 mGeneral->setSecrecy (mRelatedTodo->secrecy ()); 298 mGeneral->setSecrecy (mRelatedTodo->secrecy ());
297 if ( mRelatedTodo->priority() < 3 ) 299 if ( mRelatedTodo->priority() < 3 )
298 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); 300 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1);
299 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); 301 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": ");
300 int len = mRelatedTodo->summary().length(); 302 int len = mRelatedTodo->summary().length();
301 mGeneral->mSummaryEdit->lineEdit()->setFocus(); 303 mGeneral->mSummaryEdit->lineEdit()->setFocus();
302 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); 304 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 );
303 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); 305 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 );
304 306
305 } else 307 } else
306 mGeneral->setFocusOn( 2 ); 308 mGeneral->setFocusOn( 2 );
307 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 309 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
308 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); 310 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ));
309} 311}
310void KOTodoEditor::checkRecurrence() 312void KOTodoEditor::checkRecurrence()
311{ 313{
312 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 314 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
313 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); 315 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true );
314 316
315 if ( mTodo ) 317 if ( mTodo )
316 mRecurrence->readEvent( mTodo ); 318 mRecurrence->readEvent( mTodo );
317 else { 319 else {
318 bool time = mGeneral->mTimeButton->isChecked(); 320 bool time = mGeneral->mTimeButton->isChecked();
319 QDateTime from,to; 321 QDateTime from,to;
320 if ( time ) { 322 if ( time ) {
321 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; 323 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
322 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; 324 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
323 } else { 325 } else {
324 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; 326 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
325 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; 327 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
326 } 328 }
327 if ( to < from ) 329 if ( to < from )
328 to = from; 330 to = from;
329 mRecurrence->setDefaults(from,to,!time); 331 mRecurrence->setDefaults(from,to);
330 } 332 }
331 } else { 333 } else {
332 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 334 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
333 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); 335 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ));
334 } 336 }
335} 337}
336void KOTodoEditor::readTodo(Todo *todo) 338void KOTodoEditor::readTodo(Todo *todo)
337{ 339{
338 mGeneral->readTodo(todo); 340 mGeneral->readTodo(todo);
339 mDetails->readEvent(todo); 341 mDetails->readEvent(todo);
340 mRelatedTodo = 0;//todo->relatedTo(); 342 mRelatedTodo = 0;//todo->relatedTo();
341 // categories 343 // categories
342 // mCategoryDialog->setSelected(todo->categories()); 344 // mCategoryDialog->setSelected(todo->categories());
343 345
344 // We should handle read-only events here. 346 // We should handle read-only events here.
345} 347}
346 348
347void KOTodoEditor::writeTodo(Todo *event) 349void KOTodoEditor::writeTodo(Todo *event)
348{ 350{
349 bool maybeComputeRecurrenceTime = false; 351 bool maybeComputeRecurrenceTime = false;
350 if( event->hasRecurrenceID() && event->percentComplete() < 100) 352 if( event->hasRecurrenceID() && event->percentComplete() < 100)
351 maybeComputeRecurrenceTime = true; 353 maybeComputeRecurrenceTime = true;
352 event->setHasRecurrenceID( false ); 354 event->setHasRecurrenceID( false );
353 mGeneral->writeTodo(event); 355 mGeneral->writeTodo(event);
354 mDetails->writeEvent(event); 356 mDetails->writeEvent(event);
355 357
356 // set related event, i.e. parent to-do in this case. 358 // set related event, i.e. parent to-do in this case.
357 if (mRelatedTodo) { 359 if (mRelatedTodo) {
358 event->setRelatedTo(mRelatedTodo); 360 event->setRelatedTo(mRelatedTodo);
359 } 361 }
360 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 362 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
361 mRecurrence->writeEvent(event); 363 mRecurrence->writeEvent(event);
362 if ( event->doesRecur() ) { 364 if ( event->doesRecur() ) {
363 int addSec = -1 ; 365 int addSec = -1 ;
364 if ( maybeComputeRecurrenceTime && event->percentComplete() == 100 ) 366 if ( maybeComputeRecurrenceTime && event->percentComplete() == 100 )
365 addSec = 1; 367 addSec = 1;
366 event->setRecurrenceID( event->dtStart().addSecs( addSec ) ); 368 event->setRecurrenceID( event->dtStart().addSecs( addSec ) );
367 event->setRecurDates(); 369 event->setRecurDates();
368 } else { 370 } else {
369 event->setHasRecurrenceID( false ); 371 event->setHasRecurrenceID( false );
370 } 372 }
371 } else { 373 } else {
372 event->setHasRecurrenceID( false ); 374 event->setHasRecurrenceID( false );
373 event->recurrence()->unsetRecurs(); 375 event->recurrence()->unsetRecurs();
374 } 376 }
375} 377}
376 378
377bool KOTodoEditor::validateInput() 379bool KOTodoEditor::validateInput()
378{ 380{
379 if (!mGeneral->validateInput()) return false; 381 if (!mGeneral->validateInput()) return false;
380 if (!mDetails->validateInput()) return false; 382 if (!mDetails->validateInput()) return false;
381 return true; 383 return true;