summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoeditor.cpp29
-rw-r--r--korganizer/kotodoviewitem.cpp42
-rw-r--r--libkcal/incidence.cpp9
-rw-r--r--libkcal/incidence.h5
-rw-r--r--libkcal/incidencebase.cpp1
-rw-r--r--libkcal/incidencebase.h4
-rw-r--r--libkcal/todo.cpp51
-rw-r--r--libkcal/todo.h2
8 files changed, 133 insertions, 10 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
index 069dda8..9232e09 100644
--- a/korganizer/kotodoeditor.cpp
+++ b/korganizer/kotodoeditor.cpp
@@ -196,231 +196,260 @@ void KOTodoEditor::setupGeneral()
196 196
197void KOTodoEditor::editTodo(Todo *todo, bool editDescription) 197void KOTodoEditor::editTodo(Todo *todo, bool editDescription)
198{ 198{
199 //init(); 199 //init();
200 200
201 mTodo = todo; 201 mTodo = todo;
202 readTodo(mTodo); 202 readTodo(mTodo);
203 if ( editDescription ) { 203 if ( editDescription ) {
204 showPage( 1 ); 204 showPage( 1 );
205 mGeneral->setFocusOn( 1 ); 205 mGeneral->setFocusOn( 1 );
206 } else { 206 } else {
207 showPage( 0 ); 207 showPage( 0 );
208 mGeneral->setFocusOn( 2 ); 208 mGeneral->setFocusOn( 2 );
209 } 209 }
210 checkRecurrence(); 210 checkRecurrence();
211} 211}
212 212
213void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 213void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
214{ 214{
215 //init(); 215 //init();
216 216
217 mTodo = 0; 217 mTodo = 0;
218 setDefaults(due,relatedTodo,allDay); 218 setDefaults(due,relatedTodo,allDay);
219} 219}
220 220
221void KOTodoEditor::loadDefaults() 221void KOTodoEditor::loadDefaults()
222{ 222{
223 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 223 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
224} 224}
225 225
226bool KOTodoEditor::processInput( bool emitTime ) 226bool KOTodoEditor::processInput( bool emitTime )
227{ 227{
228 if (!validateInput()) return false; 228 if (!validateInput()) return false;
229 229
230 Todo *todo = 0; 230 Todo *todo = 0;
231 231
232 if (mTodo) todo = mTodo; 232 if (mTodo) todo = mTodo;
233 else { 233 else {
234 todo = new Todo; 234 todo = new Todo;
235 todo->setOrganizer(KOPrefs::instance()->email()); 235 todo->setOrganizer(KOPrefs::instance()->email());
236 } 236 }
237 237
238 writeTodo(todo); 238 writeTodo(todo);
239 if ( emitTime ) { 239 if ( emitTime ) {
240 globalFlagBlockAgenda = 1; 240 globalFlagBlockAgenda = 1;
241 emit showAgendaView( false ); 241 emit showAgendaView( false );
242 if ( todo->hasDueDate() ) 242 if ( todo->hasDueDate() )
243 emit jumpToTime( todo->dtDue().date() ); 243 emit jumpToTime( todo->dtDue().date() );
244 globalFlagBlockAgenda = 2; 244 globalFlagBlockAgenda = 2;
245 } 245 }
246 if (mTodo) { 246 if (mTodo) {
247 todo->setRevision(todo->revision()+1); 247 todo->setRevision(todo->revision()+1);
248 emit todoChanged(todo); 248 emit todoChanged(todo);
249 } else { 249 } else {
250 mCalendar->addTodo(todo); 250 mCalendar->addTodo(todo);
251 mTodo = todo; 251 mTodo = todo;
252 emit todoAdded(todo); 252 emit todoAdded(todo);
253 } 253 }
254 254
255 return true; 255 return true;
256} 256}
257 257
258void KOTodoEditor::deleteTodo() 258void KOTodoEditor::deleteTodo()
259{ 259{
260 if (mTodo) { 260 if (mTodo) {
261 if (KOPrefs::instance()->mConfirm) { 261 if (KOPrefs::instance()->mConfirm) {
262 switch (msgItemDelete()) { 262 switch (msgItemDelete()) {
263 case KMessageBox::Continue: // OK 263 case KMessageBox::Continue: // OK
264 emit todoToBeDeleted(mTodo); 264 emit todoToBeDeleted(mTodo);
265 emit dialogClose(mTodo); 265 emit dialogClose(mTodo);
266 mCalendar->deleteTodo(mTodo); 266 mCalendar->deleteTodo(mTodo);
267 emit todoDeleted(); 267 emit todoDeleted();
268 reject(); 268 reject();
269 break; 269 break;
270 } 270 }
271 } 271 }
272 else { 272 else {
273 emit todoToBeDeleted(mTodo); 273 emit todoToBeDeleted(mTodo);
274 emit dialogClose(mTodo); 274 emit dialogClose(mTodo);
275 mCalendar->deleteTodo(mTodo); 275 mCalendar->deleteTodo(mTodo);
276 emit todoDeleted(); 276 emit todoDeleted();
277 reject(); 277 reject();
278 } 278 }
279 } else { 279 } else {
280 reject(); 280 reject();
281 } 281 }
282} 282}
283 283
284void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) 284void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
285{ 285{
286 mRelatedTodo = relatedEvent; 286 mRelatedTodo = relatedEvent;
287 287
288 mGeneral->setDefaults(due,allDay); 288 mGeneral->setDefaults(due,allDay);
289 mDetails->setDefaults(); 289 mDetails->setDefaults();
290 showPage( 0 ); 290 showPage( 0 );
291 if ( mRelatedTodo ) { 291 if ( mRelatedTodo ) {
292 mGeneral->setCategories (mRelatedTodo->categoriesStr ()); 292 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
293 mGeneral->setSecrecy (mRelatedTodo->secrecy ()); 293 mGeneral->setSecrecy (mRelatedTodo->secrecy ());
294 if ( mRelatedTodo->priority() < 3 ) 294 if ( mRelatedTodo->priority() < 3 )
295 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); 295 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1);
296 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); 296 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": ");
297 int len = mRelatedTodo->summary().length(); 297 int len = mRelatedTodo->summary().length();
298 mGeneral->mSummaryEdit->lineEdit()->setFocus(); 298 mGeneral->mSummaryEdit->lineEdit()->setFocus();
299 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); 299 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 );
300 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); 300 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 );
301 301
302 } else 302 } else
303 mGeneral->setFocusOn( 2 ); 303 mGeneral->setFocusOn( 2 );
304 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 304 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
305 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); 305 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true);
306} 306}
307void KOTodoEditor::checkRecurrence() 307void KOTodoEditor::checkRecurrence()
308{ 308{
309 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 309 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
310 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); 310 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true );
311 311
312 if ( mTodo ) 312 if ( mTodo )
313 mRecurrence->readEvent( mTodo ); 313 mRecurrence->readEvent( mTodo );
314 else { 314 else {
315 bool time = mGeneral->mTimeButton->isChecked(); 315 bool time = mGeneral->mTimeButton->isChecked();
316 QDateTime from,to; 316 QDateTime from,to;
317 if ( time ) { 317 if ( time ) {
318 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; 318 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
319 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; 319 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
320 } else { 320 } else {
321 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; 321 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
322 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; 322 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
323 } 323 }
324 if ( to < from )
325 to = from;
324 mRecurrence->setDefaults(from,to,!time); 326 mRecurrence->setDefaults(from,to,!time);
325 } 327 }
326 } else { 328 } else {
327 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 329 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
328 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); 330 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true);
329 } 331 }
330} 332}
331void KOTodoEditor::readTodo(Todo *todo) 333void KOTodoEditor::readTodo(Todo *todo)
332{ 334{
333 mGeneral->readTodo(todo); 335 mGeneral->readTodo(todo);
334 mDetails->readEvent(todo); 336 mDetails->readEvent(todo);
335 mRelatedTodo = 0;//todo->relatedTo(); 337 mRelatedTodo = 0;//todo->relatedTo();
336 // categories 338 // categories
337 // mCategoryDialog->setSelected(todo->categories()); 339 // mCategoryDialog->setSelected(todo->categories());
338 340
339 // We should handle read-only events here. 341 // We should handle read-only events here.
340} 342}
341 343
342void KOTodoEditor::writeTodo(Todo *event) 344void KOTodoEditor::writeTodo(Todo *event)
343{ 345{
344 mGeneral->writeTodo(event); 346 mGeneral->writeTodo(event);
345 mDetails->writeEvent(event); 347 mDetails->writeEvent(event);
346 348
347 // set related event, i.e. parent to-do in this case. 349 // set related event, i.e. parent to-do in this case.
348 if (mRelatedTodo) { 350 if (mRelatedTodo) {
349 event->setRelatedTo(mRelatedTodo); 351 event->setRelatedTo(mRelatedTodo);
350 } 352 }
351 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 353 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
352 mRecurrence->writeEvent(event); 354 mRecurrence->writeEvent(event);
355 event->setRecurrenceID( event->dtStart().addSecs(-1) );
356 event->setRecurDates();
357#if 0
358 bool ok;
359 QDateTime next = event->getNextOccurence( event->dtStart().addSecs(-1), &ok );
360 if ( ok ) {
361 QDateTime from,to;
362 bool time = mGeneral->mTimeButton->isChecked();
363 if ( time ) {
364 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
365 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
366 } else {
367 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
368 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
369 }
370 if ( to < from )
371 to = from;
372 int secs = from.secsTo( to );
373 event->setRecurrenceID( next );
374 event->setDtStart( next );
375 event->setDtDue( next.addSecs( secs ) );
376 }
377 else {
378 event->setHasRecurrenceID( false );
379 event->recurrence()->unsetRecurs();
380 }
381#endif
353 } else 382 } else
354 event->recurrence()->unsetRecurs(); 383 event->recurrence()->unsetRecurs();
355} 384}
356 385
357bool KOTodoEditor::validateInput() 386bool KOTodoEditor::validateInput()
358{ 387{
359 if (!mGeneral->validateInput()) return false; 388 if (!mGeneral->validateInput()) return false;
360 if (!mDetails->validateInput()) return false; 389 if (!mDetails->validateInput()) return false;
361 return true; 390 return true;
362} 391}
363 392
364int KOTodoEditor::msgItemDelete() 393int KOTodoEditor::msgItemDelete()
365{ 394{
366 return KMessageBox::warningContinueCancel(this, 395 return KMessageBox::warningContinueCancel(this,
367 i18n("This item will be permanently deleted."), 396 i18n("This item will be permanently deleted."),
368 i18n("KOrganizer Confirmation"),i18n("Delete")); 397 i18n("KOrganizer Confirmation"),i18n("Delete"));
369} 398}
370 399
371void KOTodoEditor::modified (int modification) 400void KOTodoEditor::modified (int modification)
372{ 401{
373 if (modification == KOGlobals::CATEGORY_MODIFIED || 402 if (modification == KOGlobals::CATEGORY_MODIFIED ||
374 KOGlobals::UNKNOWN_MODIFIED == modification ) 403 KOGlobals::UNKNOWN_MODIFIED == modification )
375 // mCategoryDialog->setSelected (mTodo->categories ()); 404 // mCategoryDialog->setSelected (mTodo->categories ());
376 mGeneral->modified (mTodo, modification); 405 mGeneral->modified (mTodo, modification);
377 406
378} 407}
379 408
380void KOTodoEditor::slotLoadTemplate() 409void KOTodoEditor::slotLoadTemplate()
381{ 410{
382 411
383 QString fileName =locateLocal( "templates", "todos" ); 412 QString fileName =locateLocal( "templates", "todos" );
384 QDir t_dir; 413 QDir t_dir;
385 if ( !t_dir.exists(fileName) ) 414 if ( !t_dir.exists(fileName) )
386 t_dir.mkdir ( fileName ); 415 t_dir.mkdir ( fileName );
387 fileName += "/todo"; 416 fileName += "/todo";
388 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); 417 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this );
389 if ( fileName.length() == 0 ) 418 if ( fileName.length() == 0 )
390 return; 419 return;
391 CalendarLocal cal; 420 CalendarLocal cal;
392 ICalFormat format; 421 ICalFormat format;
393 if ( !format.load( &cal, fileName ) ) { 422 if ( !format.load( &cal, fileName ) ) {
394 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 423 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
395 .arg( fileName ) ); 424 .arg( fileName ) );
396 return ; 425 return ;
397 } 426 }
398 QPtrList<Todo> todos = cal.todos(); 427 QPtrList<Todo> todos = cal.todos();
399 Todo * todo = todos.first(); 428 Todo * todo = todos.first();
400 if ( !todo ) { 429 if ( !todo ) {
401 KMessageBox::error( this, 430 KMessageBox::error( this,
402 i18n("Template does not\ncontain a valid Todo.")); 431 i18n("Template does not\ncontain a valid Todo."));
403 } else { 432 } else {
404 readTodo( todo ); 433 readTodo( todo );
405 } 434 }
406 435
407} 436}
408 437
409void KOTodoEditor::slotSaveTemplate() 438void KOTodoEditor::slotSaveTemplate()
410{ 439{
411 QString fileName =locateLocal( "templates", "todos" ); 440 QString fileName =locateLocal( "templates", "todos" );
412 QDir t_dir; 441 QDir t_dir;
413 if ( !t_dir.exists(fileName) ) 442 if ( !t_dir.exists(fileName) )
414 t_dir.mkdir ( fileName ); 443 t_dir.mkdir ( fileName );
415 fileName += "/todo"; 444 fileName += "/todo";
416 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); 445 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this );
417 if ( fileName.length() > 0 ) 446 if ( fileName.length() > 0 )
418 saveTemplate( fileName ); 447 saveTemplate( fileName );
419} 448}
420 449
421void KOTodoEditor::saveTemplate( const QString &templateName ) 450void KOTodoEditor::saveTemplate( const QString &templateName )
422{ 451{
423 Todo *todo = new Todo; 452 Todo *todo = new Todo;
424 writeTodo( todo ); 453 writeTodo( todo );
425 saveAsTemplate( todo, templateName ); 454 saveAsTemplate( todo, templateName );
426} 455}
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 0e847c2..70f00c6 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -65,299 +65,337 @@ void KOTodoViewItem::setSortKey(int column,const QString &key)
65} 65}
66 66
67#if QT_VERSION >= 0x030000 67#if QT_VERSION >= 0x030000
68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
69 int y,int h) 69 int y,int h)
70{ 70{
71 QListViewItem::paintBranches(p,cg,w,y,h); 71 QListViewItem::paintBranches(p,cg,w,y,h);
72} 72}
73#else 73#else
74#endif 74#endif
75 75
76void KOTodoViewItem::construct() 76void KOTodoViewItem::construct()
77{ 77{
78 // qDebug("KOTodoViewItem::construct() "); 78 // qDebug("KOTodoViewItem::construct() ");
79 m_init = true; 79 m_init = true;
80 QString keyd = "=="; 80 QString keyd = "==";
81 QString keyt = "=="; 81 QString keyt = "==";
82 QString skeyd = "=="; 82 QString skeyd = "==";
83 QString skeyt = "=="; 83 QString skeyt = "==";
84 84
85 setOn(mTodo->isCompleted()); 85 setOn(mTodo->isCompleted());
86 setText(0,mTodo->summary()); 86 setText(0,mTodo->summary());
87 setText(1,QString::number(mTodo->priority())); 87 setText(1,QString::number(mTodo->priority()));
88 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 88 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
89 if (mTodo->percentComplete()<100) { 89 if (mTodo->percentComplete()<100) {
90 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 90 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
91 else setSortKey(2,QString::number(mTodo->percentComplete())); 91 else setSortKey(2,QString::number(mTodo->percentComplete()));
92 } 92 }
93 else { 93 else {
94 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 94 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
95 else setSortKey(2,QString::number(99)); 95 else setSortKey(2,QString::number(99));
96 } 96 }
97 if (mTodo->hasDueDate()) { 97 if (mTodo->hasDueDate()) {
98 setText(3, mTodo->dtDueDateStr()); 98 setText(3, mTodo->dtDueDateStr());
99 QDate d = mTodo->dtDue().date(); 99 QDate d = mTodo->dtDue().date();
100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
101 // setSortKey(3,keyd); 101 // setSortKey(3,keyd);
102 if (mTodo->doesFloat()) { 102 if (mTodo->doesFloat()) {
103 setText(4,""); 103 setText(4,"");
104 } 104 }
105 else { 105 else {
106 setText(4,mTodo->dtDueTimeStr()); 106 setText(4,mTodo->dtDueTimeStr());
107 QTime t = mTodo->dtDue().time(); 107 QTime t = mTodo->dtDue().time();
108 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 108 keyt.sprintf("%02d%02d",t.hour(),t.minute());
109 //setSortKey(4,keyt); 109 //setSortKey(4,keyt);
110 } 110 }
111 } else { 111 } else {
112 setText(3,""); 112 setText(3,"");
113 setText(4,""); 113 setText(4,"");
114 } 114 }
115 setSortKey(3,keyd); 115 setSortKey(3,keyd);
116 setSortKey(4,keyt); 116 setSortKey(4,keyt);
117 117
118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
120 120
121 121
122 122
123 if (mTodo->hasStartDate()) { 123 if (mTodo->hasStartDate()) {
124 setText(5, mTodo->dtStartDateStr()); 124 setText(5, mTodo->dtStartDateStr());
125 QDate d = mTodo->dtStart().date(); 125 QDate d = mTodo->dtStart().date();
126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
127 127
128 if (mTodo->doesFloat()) { 128 if (mTodo->doesFloat()) {
129 setText(6,""); 129 setText(6,"");
130 } 130 }
131 else { 131 else {
132 setText(6,mTodo->dtStartTimeStr()); 132 setText(6,mTodo->dtStartTimeStr());
133 QTime t = mTodo->dtStart().time(); 133 QTime t = mTodo->dtStart().time();
134 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 134 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
135 135
136 } 136 }
137 } else { 137 } else {
138 setText(5,""); 138 setText(5,"");
139 setText(6,""); 139 setText(6,"");
140 } 140 }
141 setSortKey(5,skeyd); 141 setSortKey(5,skeyd);
142 setSortKey(6,skeyt); 142 setSortKey(6,skeyt);
143 143
144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
145 setText(8,mTodo->categoriesStr()); 145 setText(8,mTodo->categoriesStr());
146 146
147#if 0 147#if 0
148 // Find sort id in description. It's the text behind the last '#' character 148 // Find sort id in description. It's the text behind the last '#' character
149 // found in the description. White spaces are removed from beginning and end 149 // found in the description. White spaces are removed from beginning and end
150 // of sort id. 150 // of sort id.
151 int pos = mTodo->description().findRev('#'); 151 int pos = mTodo->description().findRev('#');
152 if (pos < 0) { 152 if (pos < 0) {
153 setText(6,""); 153 setText(6,"");
154 } else { 154 } else {
155 QString str = mTodo->description().mid(pos+1); 155 QString str = mTodo->description().mid(pos+1);
156 str.stripWhiteSpace(); 156 str.stripWhiteSpace();
157 setText(6,str); 157 setText(6,str);
158 } 158 }
159#endif 159#endif
160 160
161 m_known = false; 161 m_known = false;
162 m_init = false; 162 m_init = false;
163 163
164 setMyPixmap(); 164 setMyPixmap();
165 165
166} 166}
167void KOTodoViewItem::setMyPixmap() 167void KOTodoViewItem::setMyPixmap()
168{ 168{
169 int size = 5; 169 int size = 5;
170 QPixmap pixi = QPixmap( 1, 1 ); 170 QPixmap pixi = QPixmap( 1, 1 );
171 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 171 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
172// pixi = SmallIcon("redcross16"); 172// pixi = SmallIcon("redcross16");
173// } else { 173// } else {
174 QPainter p; 174 QPainter p;
175 175
176 int pixSize = 0; 176 int pixSize = 0;
177 QPixmap pPix = QPixmap( size, size ); 177 QPixmap pPix = QPixmap( size, size );
178 if ( mTodo->description().length() > 0 ) { 178 if ( mTodo->description().length() > 0 ) {
179 pixi.resize(size, pixSize+size); 179 pixi.resize(size, pixSize+size);
180 pPix.fill( Qt::darkGreen ); 180 pPix.fill( Qt::darkGreen );
181 p.begin( &pixi ); 181 p.begin( &pixi );
182 p. drawPixmap ( 0, pixSize, pPix); 182 p. drawPixmap ( 0, pixSize, pPix);
183 p.end(); 183 p.end();
184 pixSize += size; 184 pixSize += size;
185 } 185 }
186 if ( mTodo->isAlarmEnabled() ) { 186 if ( mTodo->isAlarmEnabled() ) {
187 pixi.resize(size, pixSize+size); 187 pixi.resize(size, pixSize+size);
188 pPix.fill( Qt::red ); 188 pPix.fill( Qt::red );
189 p.begin( &pixi ); 189 p.begin( &pixi );
190 p. drawPixmap ( 0, pixSize, pPix); 190 p. drawPixmap ( 0, pixSize, pPix);
191 p.end(); 191 p.end();
192 pixSize += size; 192 pixSize += size;
193 }
194 if ( mTodo->doesRecur() ) {
195 pixi.resize(size, pixSize+size);
196 pPix.fill( Qt::blue );
197 p.begin( &pixi );
198 p. drawPixmap ( 0, pixSize, pPix);
199 p.end();
200 pixSize += size;
193 } 201 }
194 // } 202 // }
195 if ( pixi.width() > 1 ) { 203 if ( pixi.width() > 1 ) {
196 setPixmap ( 0,pixi ) ; 204 setPixmap ( 0,pixi ) ;
197 } else { 205 } else {
198 setPixmap ( 0,QPixmap() ) ; 206 setPixmap ( 0,QPixmap() ) ;
199 } 207 }
200} 208}
201void KOTodoViewItem::stateChange(bool state) 209void KOTodoViewItem::stateChange(bool state)
202{ 210{
203 // qDebug("KOTodoViewItem::stateChange "); 211 // qDebug("KOTodoViewItem::stateChange %d ", state);
204 // do not change setting on startup 212 // do not change setting on startup
205 if ( m_init ) return; 213 if ( m_init ) return;
206 if (isOn()!=state) { 214 if (isOn()!=state) {
207 setOn(state); 215 setOn(state);
208 //qDebug("SETON "); 216 //qDebug("SETON ");
209 return; 217 return;
210 } 218 }
211 if ( mTodo->isCompleted() == state ) { 219 if ( mTodo->isCompleted() == state ) {
212 //qDebug("STATECHANGE:nothing to do "); 220 //qDebug("STATECHANGE:nothing to do ");
213 return; 221 return;
214 } 222 }
215 QString keyd = "=="; 223 QString keyd = "==";
216 QString keyt = "=="; 224 QString keyt = "==";
217 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 225 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
218 mTodo->setCompleted(state); 226 if ( mTodo->doesRecur() ){
227 QDateTime start = mTodo->dtStart();
228 mTodo->setCompleted(state);
229 if ( start != mTodo->dtStart() ) {
230 if ( state && !mTodo->isCompleted() ) {
231 setOn( false );
232 state = false;
233 }
234 }
235 } else
236 mTodo->setCompleted(state);
237
219 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 238 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
220 239
221 if (mTodo->hasDueDate()) { 240 if (mTodo->hasDueDate()) {
222 setText(3, mTodo->dtDueDateStr()); 241 setText(3, mTodo->dtDueDateStr());
223 QDate d = mTodo->dtDue().date(); 242 QDate d = mTodo->dtDue().date();
224 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 243 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
225 setSortKey(3,keyd); 244 setSortKey(3,keyd);
226 if (mTodo->doesFloat()) { 245 if (mTodo->doesFloat()) {
227 setText(4,""); 246 setText(4,"");
228 } 247 }
229 else { 248 else {
230 setText(4,mTodo->dtDueTimeStr()); 249 setText(4,mTodo->dtDueTimeStr());
231 QTime t = mTodo->dtDue().time(); 250 QTime t = mTodo->dtDue().time();
232 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 251 keyt.sprintf("%02d%02d",t.hour(),t.minute());
233 setSortKey(4,keyt); 252 setSortKey(4,keyt);
234 } 253 }
235 } 254 }
255 if (mTodo->hasStartDate()) {
256 QString skeyt = "==";
257 QString skeyd = "==";
258 setText(5, mTodo->dtStartDateStr());
259 QDate d = mTodo->dtStart().date();
260 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
261
262 if (mTodo->doesFloat()) {
263 setText(6,"");
264 }
265 else {
266 setText(6,mTodo->dtStartTimeStr());
267 QTime t = mTodo->dtStart().time();
268 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
269
270 }
271 setSortKey(5,skeyd);
272 setSortKey(6,skeyt);
273 }
236 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 274 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
237 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 275 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
238 276
239 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 277 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
240 if (mTodo->percentComplete()<100) { 278 if (mTodo->percentComplete()<100) {
241 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 279 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
242 else setSortKey(2,QString::number(mTodo->percentComplete())); 280 else setSortKey(2,QString::number(mTodo->percentComplete()));
243 } 281 }
244 else { 282 else {
245 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 283 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
246 else setSortKey(2,QString::number(99)); 284 else setSortKey(2,QString::number(99));
247 } 285 }
248 if ( state ) { 286 if ( state ) {
249 QListViewItem * myChild = firstChild(); 287 QListViewItem * myChild = firstChild();
250 KOTodoViewItem *item; 288 KOTodoViewItem *item;
251 while( myChild ) { 289 while( myChild ) {
252 //qDebug("stateCH "); 290 //qDebug("stateCH ");
253 item = static_cast<KOTodoViewItem*>(myChild); 291 item = static_cast<KOTodoViewItem*>(myChild);
254 item->stateChange(state); 292 item->stateChange(state);
255 myChild = myChild->nextSibling(); 293 myChild = myChild->nextSibling();
256 } 294 }
257 } else { 295 } else {
258 QListViewItem * myChild = parent(); 296 QListViewItem * myChild = parent();
259 if ( myChild ) 297 if ( myChild )
260 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); 298 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
261 } 299 }
262 mTodoView->modified(true); 300 mTodoView->modified(true);
263 setMyPixmap(); 301 setMyPixmap();
264 mTodoView->setTodoModified( mTodo ); 302 mTodoView->setTodoModified( mTodo );
265} 303}
266 304
267bool KOTodoViewItem::isAlternate() 305bool KOTodoViewItem::isAlternate()
268{ 306{
269 307
270 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 308 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
271 if (lv && lv->alternateBackground().isValid()) 309 if (lv && lv->alternateBackground().isValid())
272 { 310 {
273 KOTodoViewItem *above = 0; 311 KOTodoViewItem *above = 0;
274 above = static_cast<KOTodoViewItem *>(itemAbove()); 312 above = static_cast<KOTodoViewItem *>(itemAbove());
275 m_known = above ? above->m_known : true; 313 m_known = above ? above->m_known : true;
276 if (m_known) 314 if (m_known)
277 { 315 {
278 m_odd = above ? !above->m_odd : false; 316 m_odd = above ? !above->m_odd : false;
279 } 317 }
280 else 318 else
281 { 319 {
282 KOTodoViewItem *item; 320 KOTodoViewItem *item;
283 bool previous = true; 321 bool previous = true;
284 if (QListViewItem::parent()) 322 if (QListViewItem::parent())
285 { 323 {
286 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); 324 item = static_cast<KOTodoViewItem *>(QListViewItem::parent());
287 if (item) 325 if (item)
288 previous = item->m_odd; 326 previous = item->m_odd;
289 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 327 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
290 } 328 }
291 else 329 else
292 { 330 {
293 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 331 item = static_cast<KOTodoViewItem *>(lv->firstChild());
294 } 332 }
295 333
296 while(item) 334 while(item)
297 { 335 {
298 item->m_odd = previous = !previous; 336 item->m_odd = previous = !previous;
299 item->m_known = true; 337 item->m_known = true;
300 item = static_cast<KOTodoViewItem *>(item->nextSibling()); 338 item = static_cast<KOTodoViewItem *>(item->nextSibling());
301 } 339 }
302 } 340 }
303 return m_odd; 341 return m_odd;
304 } 342 }
305 return false; 343 return false;
306} 344}
307 345
308void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 346void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
309{ 347{
310 QColorGroup _cg = cg; 348 QColorGroup _cg = cg;
311 QColorGroup::ColorRole role; 349 QColorGroup::ColorRole role;
312 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 350 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
313 role = QColorGroup::Text; 351 role = QColorGroup::Text;
314 else 352 else
315 role = QColorGroup::Base; 353 role = QColorGroup::Base;
316 //#ifndef KORG_NOLVALTERNATION 354 //#ifndef KORG_NOLVALTERNATION
317 if (isAlternate()) 355 if (isAlternate())
318 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 356 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
319 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 357 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
320 QColor colorToSet; 358 QColor colorToSet;
321 if ( setColor ) { 359 if ( setColor ) {
322 QStringList categories = mTodo->categories(); 360 QStringList categories = mTodo->categories();
323 QString cat = categories.first(); 361 QString cat = categories.first();
324 if ( !cat.isEmpty()) { 362 if ( !cat.isEmpty()) {
325 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 363 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
326 } else 364 } else
327 setColor = false; 365 setColor = false;
328 } 366 }
329 367
330 int odue = mTodo->hasDueSubTodo( !isOpen()); 368 int odue = mTodo->hasDueSubTodo( !isOpen());
331 if (odue == 2) { 369 if (odue == 2) {
332 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 370 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
333 setColor = true; 371 setColor = true;
334 } else if ( odue == 1 ) { 372 } else if ( odue == 1 ) {
335 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 373 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
336 setColor = true; 374 setColor = true;
337 } 375 }
338 376
339 377
340 if ( setColor ) { 378 if ( setColor ) {
341 _cg.setColor(role,colorToSet ); 379 _cg.setColor(role,colorToSet );
342 if ( role == QColorGroup::Base) { 380 if ( role == QColorGroup::Base) {
343 int rgb = colorToSet.red(); 381 int rgb = colorToSet.red();
344 rgb += colorToSet.blue()/2; 382 rgb += colorToSet.blue()/2;
345 rgb += colorToSet.green(); 383 rgb += colorToSet.green();
346 if ( rgb < 200 ) 384 if ( rgb < 200 )
347 _cg.setColor(QColorGroup::Text,Qt::white ); 385 _cg.setColor(QColorGroup::Text,Qt::white );
348 } 386 }
349 } 387 }
350 //#endif 388 //#endif
351 if ( column > 0 ){ 389 if ( column > 0 ){
352 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 390 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
353 p->save(); 391 p->save();
354 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 392 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
355 393
356 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 394 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
357 // p->setPen(Qt::black ); //border 395 // p->setPen(Qt::black ); //border
358 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 396 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
359 QColor fc = KOPrefs::instance()->mHighlightColor; 397 QColor fc = KOPrefs::instance()->mHighlightColor;
360 if ( mTodo->percentComplete() == 100 ) 398 if ( mTodo->percentComplete() == 100 )
361 fc = darkGreen; 399 fc = darkGreen;
362 p->drawRect( 2, 2, width-4, height()-4); 400 p->drawRect( 2, 2, width-4, height()-4);
363 p->fillRect( 3, 3, progress, height()-6, 401 p->fillRect( 3, 3, progress, height()-6,
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index dbc159c..0684af2 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -522,128 +522,137 @@ QString Incidence::secrecyName(int secrecy)
522 default: 522 default:
523 return i18n("Undefined"); 523 return i18n("Undefined");
524 break; 524 break;
525 } 525 }
526} 526}
527 527
528QStringList Incidence::secrecyList() 528QStringList Incidence::secrecyList()
529{ 529{
530 QStringList list; 530 QStringList list;
531 list << secrecyName(SecrecyPublic); 531 list << secrecyName(SecrecyPublic);
532 list << secrecyName(SecrecyPrivate); 532 list << secrecyName(SecrecyPrivate);
533 list << secrecyName(SecrecyConfidential); 533 list << secrecyName(SecrecyConfidential);
534 534
535 return list; 535 return list;
536} 536}
537 537
538 538
539QPtrList<Alarm> Incidence::alarms() const 539QPtrList<Alarm> Incidence::alarms() const
540{ 540{
541 return mAlarms; 541 return mAlarms;
542} 542}
543 543
544Alarm* Incidence::newAlarm() 544Alarm* Incidence::newAlarm()
545{ 545{
546 Alarm* alarm = new Alarm(this); 546 Alarm* alarm = new Alarm(this);
547 mAlarms.append(alarm); 547 mAlarms.append(alarm);
548// updated(); 548// updated();
549 return alarm; 549 return alarm;
550} 550}
551 551
552void Incidence::addAlarm(Alarm *alarm) 552void Incidence::addAlarm(Alarm *alarm)
553{ 553{
554 mAlarms.append(alarm); 554 mAlarms.append(alarm);
555 updated(); 555 updated();
556} 556}
557 557
558void Incidence::removeAlarm(Alarm *alarm) 558void Incidence::removeAlarm(Alarm *alarm)
559{ 559{
560 mAlarms.removeRef(alarm); 560 mAlarms.removeRef(alarm);
561 updated(); 561 updated();
562} 562}
563 563
564void Incidence::clearAlarms() 564void Incidence::clearAlarms()
565{ 565{
566 mAlarms.clear(); 566 mAlarms.clear();
567 updated(); 567 updated();
568} 568}
569 569
570bool Incidence::isAlarmEnabled() const 570bool Incidence::isAlarmEnabled() const
571{ 571{
572 Alarm* alarm; 572 Alarm* alarm;
573 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 573 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
574 if (alarm->enabled()) 574 if (alarm->enabled())
575 return true; 575 return true;
576 } 576 }
577 return false; 577 return false;
578} 578}
579 579
580Recurrence *Incidence::recurrence() const 580Recurrence *Incidence::recurrence() const
581{ 581{
582 return mRecurrence; 582 return mRecurrence;
583} 583}
584void Incidence::setRecurrence( Recurrence * r) 584void Incidence::setRecurrence( Recurrence * r)
585{ 585{
586 delete mRecurrence; 586 delete mRecurrence;
587 mRecurrence = r; 587 mRecurrence = r;
588} 588}
589 589
590void Incidence::setLocation(const QString &location) 590void Incidence::setLocation(const QString &location)
591{ 591{
592 if (mReadOnly) return; 592 if (mReadOnly) return;
593 mLocation = location; 593 mLocation = location;
594 updated(); 594 updated();
595} 595}
596 596
597QString Incidence::location() const 597QString Incidence::location() const
598{ 598{
599 return mLocation; 599 return mLocation;
600} 600}
601 601
602ushort Incidence::doesRecur() const 602ushort Incidence::doesRecur() const
603{ 603{
604 if ( mRecurrence ) return mRecurrence->doesRecur(); 604 if ( mRecurrence ) return mRecurrence->doesRecur();
605 else return Recurrence::rNone; 605 else return Recurrence::rNone;
606} 606}
607 607
608QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 608QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
609{ 609{
610 QDateTime incidenceStart = dt; 610 QDateTime incidenceStart = dt;
611 *ok = false; 611 *ok = false;
612 if ( doesRecur() ) { 612 if ( doesRecur() ) {
613 bool last; 613 bool last;
614 recurrence()->getPreviousDateTime( incidenceStart , &last ); 614 recurrence()->getPreviousDateTime( incidenceStart , &last );
615 int count = 0; 615 int count = 0;
616 if ( !last ) { 616 if ( !last ) {
617 while ( !last ) { 617 while ( !last ) {
618 ++count; 618 ++count;
619 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 619 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
620 if ( recursOn( incidenceStart.date() ) ) { 620 if ( recursOn( incidenceStart.date() ) ) {
621 last = true; // exit while llop 621 last = true; // exit while llop
622 } else { 622 } else {
623 if ( last ) { // no alarm on last recurrence 623 if ( last ) { // no alarm on last recurrence
624 return QDateTime (); 624 return QDateTime ();
625 } 625 }
626 int year = incidenceStart.date().year(); 626 int year = incidenceStart.date().year();
627 // workaround for bug in recurrence 627 // workaround for bug in recurrence
628 if ( count == 100 || year < 1000 || year > 5000 ) { 628 if ( count == 100 || year < 1000 || year > 5000 ) {
629 return QDateTime (); 629 return QDateTime ();
630 } 630 }
631 incidenceStart = incidenceStart.addSecs( 1 ); 631 incidenceStart = incidenceStart.addSecs( 1 );
632 } 632 }
633 } 633 }
634 } else { 634 } else {
635 return QDateTime (); 635 return QDateTime ();
636 } 636 }
637 } else { 637 } else {
638 if ( hasStartDate () ) { 638 if ( hasStartDate () ) {
639 incidenceStart = dtStart(); 639 incidenceStart = dtStart();
640 } 640 }
641 if ( type() =="Todo" ) { 641 if ( type() =="Todo" ) {
642 if ( ((Todo*)this)->hasDueDate() ) 642 if ( ((Todo*)this)->hasDueDate() )
643 incidenceStart = ((Todo*)this)->dtDue(); 643 incidenceStart = ((Todo*)this)->dtDue();
644 } 644 }
645 } 645 }
646 if ( incidenceStart > dt ) 646 if ( incidenceStart > dt )
647 *ok = true; 647 *ok = true;
648 return incidenceStart; 648 return incidenceStart;
649} 649}
650QDateTime Incidence::dtStart() const
651{
652 if ( doesRecur() ) {
653 if ( type() == "Todo" ) {
654 ((Todo*)this)->checkSetCompletedFalse();
655 }
656 }
657 return mDtStart;
658}
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index 38d2aaa..0ae9656 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -144,165 +144,166 @@ class Incidence : public IncidenceBase
144 /** returns a reference to the event's description. */ 144 /** returns a reference to the event's description. */
145 QString description() const; 145 QString description() const;
146 146
147 /** sets the event's short summary. */ 147 /** sets the event's short summary. */
148 void setSummary(const QString &summary); 148 void setSummary(const QString &summary);
149 /** returns a reference to the event's summary. */ 149 /** returns a reference to the event's summary. */
150 QString summary() const; 150 QString summary() const;
151 151
152 /** set event's applicable categories */ 152 /** set event's applicable categories */
153 void setCategories(const QStringList &categories); 153 void setCategories(const QStringList &categories);
154 /** set event's categories based on a comma delimited string */ 154 /** set event's categories based on a comma delimited string */
155 void setCategories(const QString &catStr); 155 void setCategories(const QString &catStr);
156 /** return categories in a list */ 156 /** return categories in a list */
157 QStringList categories() const; 157 QStringList categories() const;
158 /** return categories as a comma separated string */ 158 /** return categories as a comma separated string */
159 QString categoriesStr(); 159 QString categoriesStr();
160 160
161 /** point at some other event to which the event relates. This function should 161 /** point at some other event to which the event relates. This function should
162 * only be used when constructing a calendar before the related Event 162 * only be used when constructing a calendar before the related Event
163 * exists. */ 163 * exists. */
164 void setRelatedToUid(const QString &); 164 void setRelatedToUid(const QString &);
165 /** what event does this one relate to? This function should 165 /** what event does this one relate to? This function should
166 * only be used when constructing a calendar before the related Event 166 * only be used when constructing a calendar before the related Event
167 * exists. */ 167 * exists. */
168 QString relatedToUid() const; 168 QString relatedToUid() const;
169 /** point at some other event to which the event relates */ 169 /** point at some other event to which the event relates */
170 void setRelatedTo(Incidence *relatedTo); 170 void setRelatedTo(Incidence *relatedTo);
171 /** what event does this one relate to? */ 171 /** what event does this one relate to? */
172 Incidence *relatedTo() const; 172 Incidence *relatedTo() const;
173 /** All events that are related to this event */ 173 /** All events that are related to this event */
174 QPtrList<Incidence> relations() const; 174 QPtrList<Incidence> relations() const;
175 /** Add an event which is related to this event */ 175 /** Add an event which is related to this event */
176 void addRelation(Incidence *); 176 void addRelation(Incidence *);
177 /** Remove event that is related to this event */ 177 /** Remove event that is related to this event */
178 void removeRelation(Incidence *); 178 void removeRelation(Incidence *);
179 179
180 /** returns the list of dates which are exceptions to the recurrence rule */ 180 /** returns the list of dates which are exceptions to the recurrence rule */
181 DateList exDates() const; 181 DateList exDates() const;
182 /** sets the list of dates which are exceptions to the recurrence rule */ 182 /** sets the list of dates which are exceptions to the recurrence rule */
183 void setExDates(const DateList &_exDates); 183 void setExDates(const DateList &_exDates);
184 void setExDates(const char *dates); 184 void setExDates(const char *dates);
185 /** Add a date to the list of exceptions of the recurrence rule. */ 185 /** Add a date to the list of exceptions of the recurrence rule. */
186 void addExDate(const QDate &date); 186 void addExDate(const QDate &date);
187 187
188 /** returns true if there is an exception for this date in the recurrence 188 /** returns true if there is an exception for this date in the recurrence
189 rule set, or false otherwise. */ 189 rule set, or false otherwise. */
190 bool isException(const QDate &qd) const; 190 bool isException(const QDate &qd) const;
191 191
192 /** add attachment to this event */ 192 /** add attachment to this event */
193 void addAttachment(Attachment *attachment); 193 void addAttachment(Attachment *attachment);
194 /** remove and delete a specific attachment */ 194 /** remove and delete a specific attachment */
195 void deleteAttachment(Attachment *attachment); 195 void deleteAttachment(Attachment *attachment);
196 /** remove and delete all attachments with this mime type */ 196 /** remove and delete all attachments with this mime type */
197 void deleteAttachments(const QString& mime); 197 void deleteAttachments(const QString& mime);
198 /** return list of all associated attachments */ 198 /** return list of all associated attachments */
199 QPtrList<Attachment> attachments() const; 199 QPtrList<Attachment> attachments() const;
200 /** find a list of attachments with this mime type */ 200 /** find a list of attachments with this mime type */
201 QPtrList<Attachment> attachments(const QString& mime) const; 201 QPtrList<Attachment> attachments(const QString& mime) const;
202 202
203 /** sets the event's status the value specified. See the enumeration 203 /** sets the event's status the value specified. See the enumeration
204 * above for possible values. */ 204 * above for possible values. */
205 void setSecrecy(int); 205 void setSecrecy(int);
206 /** return the event's secrecy. */ 206 /** return the event's secrecy. */
207 int secrecy() const; 207 int secrecy() const;
208 /** return the event's secrecy in string format. */ 208 /** return the event's secrecy in string format. */
209 QString secrecyStr() const; 209 QString secrecyStr() const;
210 /** return list of all availbale secrecy classes */ 210 /** return list of all availbale secrecy classes */
211 static QStringList secrecyList(); 211 static QStringList secrecyList();
212 /** return human-readable name of secrecy class */ 212 /** return human-readable name of secrecy class */
213 static QString secrecyName(int); 213 static QString secrecyName(int);
214 214
215 /** returns TRUE if the date specified is one on which the event will 215 /** returns TRUE if the date specified is one on which the event will
216 * recur. */ 216 * recur. */
217 bool recursOn(const QDate &qd) const; 217 bool recursOn(const QDate &qd) const;
218 218
219 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 219 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
220 220
221 /** set resources used, such as Office, Car, etc. */ 221 /** set resources used, such as Office, Car, etc. */
222 void setResources(const QStringList &resources); 222 void setResources(const QStringList &resources);
223 /** return list of current resources */ 223 /** return list of current resources */
224 QStringList resources() const; 224 QStringList resources() const;
225 225
226 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 226 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
227 void setPriority(int priority); 227 void setPriority(int priority);
228 /** get the event's priority */ 228 /** get the event's priority */
229 int priority() const; 229 int priority() const;
230 230
231 /** All alarms that are associated with this incidence */ 231 /** All alarms that are associated with this incidence */
232 QPtrList<Alarm> alarms() const; 232 QPtrList<Alarm> alarms() const;
233 /** Create a new alarm which is associated with this incidence */ 233 /** Create a new alarm which is associated with this incidence */
234 Alarm* newAlarm(); 234 Alarm* newAlarm();
235 /** Add an alarm which is associated with this incidence */ 235 /** Add an alarm which is associated with this incidence */
236 void addAlarm(Alarm*); 236 void addAlarm(Alarm*);
237 /** Remove an alarm that is associated with this incidence */ 237 /** Remove an alarm that is associated with this incidence */
238 void removeAlarm(Alarm*); 238 void removeAlarm(Alarm*);
239 /** Remove all alarms that are associated with this incidence */ 239 /** Remove all alarms that are associated with this incidence */
240 void clearAlarms(); 240 void clearAlarms();
241 /** return whether any alarm associated with this incidence is enabled */ 241 /** return whether any alarm associated with this incidence is enabled */
242 bool isAlarmEnabled() const; 242 bool isAlarmEnabled() const;
243 243
244 /** 244 /**
245 Return the recurrence rule associated with this incidence. If there is 245 Return the recurrence rule associated with this incidence. If there is
246 none, returns an appropriate (non-0) object. 246 none, returns an appropriate (non-0) object.
247 */ 247 */
248 Recurrence *recurrence() const; 248 Recurrence *recurrence() const;
249 void setRecurrence(Recurrence * r); 249 void setRecurrence(Recurrence * r);
250 /** 250 /**
251 Forward to Recurrence::doesRecur(). 251 Forward to Recurrence::doesRecur().
252 */ 252 */
253 ushort doesRecur() const; 253 ushort doesRecur() const;
254 254
255 /** set the event's/todo's location. Do _not_ use it with journal */ 255 /** set the event's/todo's location. Do _not_ use it with journal */
256 void setLocation(const QString &location); 256 void setLocation(const QString &location);
257 /** return the event's/todo's location. Do _not_ use it with journal */ 257 /** return the event's/todo's location. Do _not_ use it with journal */
258 QString location() const; 258 QString location() const;
259 /** returns TRUE or FALSE depending on whether the todo has a start date */ 259 /** returns TRUE or FALSE depending on whether the todo has a start date */
260 bool hasStartDate() const; 260 bool hasStartDate() const;
261 /** sets the event's hasStartDate value. */ 261 /** sets the event's hasStartDate value. */
262 void setHasStartDate(bool f); 262 void setHasStartDate(bool f);
263 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 263 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
264 bool cancelled() const; 264 bool cancelled() const;
265 void setCancelled( bool b ); 265 void setCancelled( bool b );
266 266
267 bool hasRecurrenceID() const; 267 bool hasRecurrenceID() const;
268 void setHasRecurrenceID( bool b ); 268 void setHasRecurrenceID( bool b );
269 269
270 void setRecurrenceID(QDateTime); 270 void setRecurrenceID(QDateTime);
271 QDateTime recurrenceID () const; 271 QDateTime recurrenceID () const;
272 QDateTime dtStart() const;
272 273
273 274
274protected: 275protected:
275 QPtrList<Alarm> mAlarms; 276 QPtrList<Alarm> mAlarms;
276 QPtrList<Incidence> mRelations; 277 QPtrList<Incidence> mRelations;
278 QDateTime mRecurrenceID;
279 bool mHasRecurrenceID;
277 private: 280 private:
278 int mRevision; 281 int mRevision;
279 bool mCancelled; 282 bool mCancelled;
280 283
281 // base components of jounal, event and todo 284 // base components of jounal, event and todo
282 QDateTime mRecurrenceID;
283 bool mHasRecurrenceID;
284 QDateTime mCreated; 285 QDateTime mCreated;
285 QString mDescription; 286 QString mDescription;
286 QString mSummary; 287 QString mSummary;
287 QStringList mCategories; 288 QStringList mCategories;
288 Incidence *mRelatedTo; 289 Incidence *mRelatedTo;
289 QString mRelatedToUid; 290 QString mRelatedToUid;
290 DateList mExDates; 291 DateList mExDates;
291 QPtrList<Attachment> mAttachments; 292 QPtrList<Attachment> mAttachments;
292 QStringList mResources; 293 QStringList mResources;
293 bool mHasStartDate; // if todo has associated start date 294 bool mHasStartDate; // if todo has associated start date
294 295
295 int mSecrecy; 296 int mSecrecy;
296 int mPriority; // 1 = highest, 2 = less, etc. 297 int mPriority; // 1 = highest, 2 = less, etc.
297 298
298 //QPtrList<Alarm> mAlarms; 299 //QPtrList<Alarm> mAlarms;
299 Recurrence *mRecurrence; 300 Recurrence *mRecurrence;
300 301
301 QString mLocation; 302 QString mLocation;
302}; 303};
303 304
304bool operator==( const Incidence&, const Incidence& ); 305bool operator==( const Incidence&, const Incidence& );
305 306
306} 307}
307 308
308#endif 309#endif
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 7525a4a..51f2e9d 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -54,256 +54,257 @@ IncidenceBase::IncidenceBase(const IncidenceBase &i) :
54 mDuration = i.mDuration; 54 mDuration = i.mDuration;
55 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
56 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
57 mUid = i.mUid; 57 mUid = i.mUid;
58 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
60 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
61 } 61 }
62 mFloats = i.mFloats; 62 mFloats = i.mFloats;
63 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
64 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
65 mTempSyncStat = i.mTempSyncStat; 65 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 66 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 67 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 68 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 69 // of the original object.
70 mObservers.clear(); 70 mObservers.clear();
71 71
72 mAttendees.setAutoDelete( true ); 72 mAttendees.setAutoDelete( true );
73} 73}
74 74
75IncidenceBase::~IncidenceBase() 75IncidenceBase::~IncidenceBase()
76{ 76{
77} 77}
78 78
79 79
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 81{
82 // do not compare mSyncStatus and mExternalId 82 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 83 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 84 return false; // no need to check further
85 } 85 }
86 if ( i1.attendees().count() > 0 ) { 86 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 88 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 89 if ( !( (*a1) == (*a2)) )
90 { 90 {
91 //qDebug("Attendee not equal "); 91 //qDebug("Attendee not equal ");
92 return false; 92 return false;
93 } 93 }
94 a1 = i1.attendees().next(); 94 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 95 a2 = i2.attendees().next();
96 } 96 }
97 } 97 }
98 //if ( i1.dtStart() != i2.dtStart() ) 98 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 99 // return false;
100#if 0 100#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 102 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 106 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 107
108#endif 108#endif
109 return ( i1.organizer() == i2.organizer() && 109 return ( i1.organizer() == i2.organizer() &&
110 // i1.uid() == i2.uid() && 110 // i1.uid() == i2.uid() &&
111 // Don't compare lastModified, otherwise the operator is not 111 // Don't compare lastModified, otherwise the operator is not
112 // of much use. We are not comparing for identity, after all. 112 // of much use. We are not comparing for identity, after all.
113 i1.doesFloat() == i2.doesFloat() && 113 i1.doesFloat() == i2.doesFloat() &&
114 i1.duration() == i2.duration() && 114 i1.duration() == i2.duration() &&
115 i1.hasDuration() == i2.hasDuration() && 115 i1.hasDuration() == i2.hasDuration() &&
116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
117 // no need to compare mObserver 117 // no need to compare mObserver
118} 118}
119 119
120 120
121QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 121QDateTime IncidenceBase::getEvenTime( QDateTime dt )
122{ 122{
123 QTime t = dt.time(); 123 QTime t = dt.time();
124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
125 return dt; 125 return dt;
126} 126}
127 127
128 128
129void IncidenceBase::setUid(const QString &uid) 129void IncidenceBase::setUid(const QString &uid)
130{ 130{
131 mUid = uid; 131 mUid = uid;
132 updated(); 132 updated();
133} 133}
134 134
135QString IncidenceBase::uid() const 135QString IncidenceBase::uid() const
136{ 136{
137 return mUid; 137 return mUid;
138} 138}
139 139
140void IncidenceBase::setLastModified(const QDateTime &lm) 140void IncidenceBase::setLastModified(const QDateTime &lm)
141{ 141{
142 // DON'T! updated() because we call this from 142 // DON'T! updated() because we call this from
143 // Calendar::updateEvent(). 143 // Calendar::updateEvent().
144 mLastModified = getEvenTime(lm); 144 mLastModified = getEvenTime(lm);
145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
146} 146}
147 147
148QDateTime IncidenceBase::lastModified() const 148QDateTime IncidenceBase::lastModified() const
149{ 149{
150 return mLastModified; 150 return mLastModified;
151} 151}
152 152
153void IncidenceBase::setOrganizer(const QString &o) 153void IncidenceBase::setOrganizer(const QString &o)
154{ 154{
155 // we don't check for readonly here, because it is 155 // we don't check for readonly here, because it is
156 // possible that by setting the organizer we are changing 156 // possible that by setting the organizer we are changing
157 // the event's readonly status... 157 // the event's readonly status...
158 mOrganizer = o; 158 mOrganizer = o;
159 if (mOrganizer.left(7).upper() == "MAILTO:") 159 if (mOrganizer.left(7).upper() == "MAILTO:")
160 mOrganizer = mOrganizer.remove(0,7); 160 mOrganizer = mOrganizer.remove(0,7);
161 161
162 updated(); 162 updated();
163} 163}
164 164
165QString IncidenceBase::organizer() const 165QString IncidenceBase::organizer() const
166{ 166{
167 return mOrganizer; 167 return mOrganizer;
168} 168}
169 169
170void IncidenceBase::setReadOnly( bool readOnly ) 170void IncidenceBase::setReadOnly( bool readOnly )
171{ 171{
172 mReadOnly = readOnly; 172 mReadOnly = readOnly;
173} 173}
174 174
175void IncidenceBase::setDtStart(const QDateTime &dtStart) 175void IncidenceBase::setDtStart(const QDateTime &dtStart)
176{ 176{
177// if (mReadOnly) return; 177// if (mReadOnly) return;
178 mDtStart = getEvenTime(dtStart); 178 mDtStart = getEvenTime(dtStart);
179 updated(); 179 updated();
180} 180}
181 181
182
182QDateTime IncidenceBase::dtStart() const 183QDateTime IncidenceBase::dtStart() const
183{ 184{
184 return mDtStart; 185 return mDtStart;
185} 186}
186 187
187QString IncidenceBase::dtStartTimeStr() const 188QString IncidenceBase::dtStartTimeStr() const
188{ 189{
189 return KGlobal::locale()->formatTime(dtStart().time()); 190 return KGlobal::locale()->formatTime(dtStart().time());
190} 191}
191 192
192QString IncidenceBase::dtStartDateStr(bool shortfmt) const 193QString IncidenceBase::dtStartDateStr(bool shortfmt) const
193{ 194{
194 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 195 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
195} 196}
196 197
197QString IncidenceBase::dtStartStr(bool shortfmt) const 198QString IncidenceBase::dtStartStr(bool shortfmt) const
198{ 199{
199 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 200 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
200} 201}
201 202
202 203
203bool IncidenceBase::doesFloat() const 204bool IncidenceBase::doesFloat() const
204{ 205{
205 return mFloats; 206 return mFloats;
206} 207}
207 208
208void IncidenceBase::setFloats(bool f) 209void IncidenceBase::setFloats(bool f)
209{ 210{
210 if (mReadOnly) return; 211 if (mReadOnly) return;
211 mFloats = f; 212 mFloats = f;
212 updated(); 213 updated();
213} 214}
214 215
215 216
216bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 217bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
217{ 218{
218 if (mReadOnly) return false; 219 if (mReadOnly) return false;
219 if (a->name().left(7).upper() == "MAILTO:") 220 if (a->name().left(7).upper() == "MAILTO:")
220 a->setName(a->name().remove(0,7)); 221 a->setName(a->name().remove(0,7));
221 222
222 QPtrListIterator<Attendee> qli(mAttendees); 223 QPtrListIterator<Attendee> qli(mAttendees);
223 224
224 qli.toFirst(); 225 qli.toFirst();
225 while (qli) { 226 while (qli) {
226 if (*qli.current() == *a) 227 if (*qli.current() == *a)
227 return false; 228 return false;
228 ++qli; 229 ++qli;
229 } 230 }
230 mAttendees.append(a); 231 mAttendees.append(a);
231 if (doupdate) updated(); 232 if (doupdate) updated();
232 return true; 233 return true;
233} 234}
234 235
235#if 0 236#if 0
236void IncidenceBase::removeAttendee(Attendee *a) 237void IncidenceBase::removeAttendee(Attendee *a)
237{ 238{
238 if (mReadOnly) return; 239 if (mReadOnly) return;
239 mAttendees.removeRef(a); 240 mAttendees.removeRef(a);
240 updated(); 241 updated();
241} 242}
242 243
243void IncidenceBase::removeAttendee(const char *n) 244void IncidenceBase::removeAttendee(const char *n)
244{ 245{
245 Attendee *a; 246 Attendee *a;
246 247
247 if (mReadOnly) return; 248 if (mReadOnly) return;
248 for (a = mAttendees.first(); a; a = mAttendees.next()) 249 for (a = mAttendees.first(); a; a = mAttendees.next())
249 if (a->getName() == n) { 250 if (a->getName() == n) {
250 mAttendees.remove(); 251 mAttendees.remove();
251 break; 252 break;
252 } 253 }
253} 254}
254#endif 255#endif
255 256
256void IncidenceBase::clearAttendees() 257void IncidenceBase::clearAttendees()
257{ 258{
258 if (mReadOnly) return; 259 if (mReadOnly) return;
259 mAttendees.clear(); 260 mAttendees.clear();
260} 261}
261 262
262#if 0 263#if 0
263Attendee *IncidenceBase::getAttendee(const char *n) const 264Attendee *IncidenceBase::getAttendee(const char *n) const
264{ 265{
265 QPtrListIterator<Attendee> qli(mAttendees); 266 QPtrListIterator<Attendee> qli(mAttendees);
266 267
267 qli.toFirst(); 268 qli.toFirst();
268 while (qli) { 269 while (qli) {
269 if (qli.current()->getName() == n) 270 if (qli.current()->getName() == n)
270 return qli.current(); 271 return qli.current();
271 ++qli; 272 ++qli;
272 } 273 }
273 return 0L; 274 return 0L;
274} 275}
275#endif 276#endif
276 277
277Attendee *IncidenceBase::attendeeByMail(const QString &email) 278Attendee *IncidenceBase::attendeeByMail(const QString &email)
278{ 279{
279 QPtrListIterator<Attendee> qli(mAttendees); 280 QPtrListIterator<Attendee> qli(mAttendees);
280 281
281 qli.toFirst(); 282 qli.toFirst();
282 while (qli) { 283 while (qli) {
283 if (qli.current()->email().lower() == email.lower()) 284 if (qli.current()->email().lower() == email.lower())
284 return qli.current(); 285 return qli.current();
285 ++qli; 286 ++qli;
286 } 287 }
287 return 0L; 288 return 0L;
288} 289}
289 290
290Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 291Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
291{ 292{
292 QPtrListIterator<Attendee> qli(mAttendees); 293 QPtrListIterator<Attendee> qli(mAttendees);
293 294
294 QStringList mails = emails; 295 QStringList mails = emails;
295 if (!email.isEmpty()) { 296 if (!email.isEmpty()) {
296 mails.append(email); 297 mails.append(email);
297 } 298 }
298 qli.toFirst(); 299 qli.toFirst();
299 while (qli) { 300 while (qli) {
300 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 301 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
301 if (qli.current()->email().lower() == (*it).lower()) 302 if (qli.current()->email().lower() == (*it).lower())
302 return qli.current(); 303 return qli.current();
303 } 304 }
304 305
305 ++qli; 306 ++qli;
306 } 307 }
307 return 0L; 308 return 0L;
308} 309}
309 310
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index f9a6558..8624786 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,172 +1,172 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 37
38/** 38/**
39 This class provides the base class common to all calendar components. 39 This class provides the base class common to all calendar components.
40*/ 40*/
41class IncidenceBase : public CustomProperties 41class IncidenceBase : public CustomProperties
42{ 42{
43 public: 43 public:
44 class Observer { 44 class Observer {
45 public: 45 public:
46 virtual void incidenceUpdated( IncidenceBase * ) = 0; 46 virtual void incidenceUpdated( IncidenceBase * ) = 0;
47 }; 47 };
48 48
49 IncidenceBase(); 49 IncidenceBase();
50 IncidenceBase(const IncidenceBase &); 50 IncidenceBase(const IncidenceBase &);
51 virtual ~IncidenceBase(); 51 virtual ~IncidenceBase();
52 52
53 virtual QCString type() const = 0; 53 virtual QCString type() const = 0;
54 54
55 /** Set the unique id for the event */ 55 /** Set the unique id for the event */
56 void setUid(const QString &); 56 void setUid(const QString &);
57 /** Return the unique id for the event */ 57 /** Return the unique id for the event */
58 QString uid() const; 58 QString uid() const;
59 59
60 /** Sets the time the incidence was last modified. */ 60 /** Sets the time the incidence was last modified. */
61 void setLastModified(const QDateTime &lm); 61 void setLastModified(const QDateTime &lm);
62 /** Return the time the incidence was last modified. */ 62 /** Return the time the incidence was last modified. */
63 QDateTime lastModified() const; 63 QDateTime lastModified() const;
64 64
65 /** sets the organizer for the event */ 65 /** sets the organizer for the event */
66 void setOrganizer(const QString &o); 66 void setOrganizer(const QString &o);
67 QString organizer() const; 67 QString organizer() const;
68 68
69 /** Set readonly status. */ 69 /** Set readonly status. */
70 virtual void setReadOnly( bool ); 70 virtual void setReadOnly( bool );
71 /** Return if the object is read-only. */ 71 /** Return if the object is read-only. */
72 bool isReadOnly() const { return mReadOnly; } 72 bool isReadOnly() const { return mReadOnly; }
73 73
74 /** for setting the event's starting date/time with a QDateTime. */ 74 /** for setting the event's starting date/time with a QDateTime. */
75 virtual void setDtStart(const QDateTime &dtStart); 75 virtual void setDtStart(const QDateTime &dtStart);
76 /** returns an event's starting date/time as a QDateTime. */ 76 /** returns an event's starting date/time as a QDateTime. */
77 QDateTime dtStart() const; 77 virtual QDateTime dtStart() const;
78 /** returns an event's starting time as a string formatted according to the 78 /** returns an event's starting time as a string formatted according to the
79 users locale settings */ 79 users locale settings */
80 QString dtStartTimeStr() const; 80 QString dtStartTimeStr() const;
81 /** returns an event's starting date as a string formatted according to the 81 /** returns an event's starting date as a string formatted according to the
82 users locale settings */ 82 users locale settings */
83 QString dtStartDateStr(bool shortfmt=true) const; 83 QString dtStartDateStr(bool shortfmt=true) const;
84 /** returns an event's starting date and time as a string formatted according 84 /** returns an event's starting date and time as a string formatted according
85 to the users locale settings */ 85 to the users locale settings */
86 QString dtStartStr(bool shortfmt=true) const; 86 QString dtStartStr(bool shortfmt=true) const;
87 87
88 virtual void setDuration(int seconds); 88 virtual void setDuration(int seconds);
89 int duration() const; 89 int duration() const;
90 void setHasDuration(bool); 90 void setHasDuration(bool);
91 bool hasDuration() const; 91 bool hasDuration() const;
92 92
93 /** Return true or false depending on whether the incidence "floats," 93 /** Return true or false depending on whether the incidence "floats,"
94 * i.e. has a date but no time attached to it. */ 94 * i.e. has a date but no time attached to it. */
95 bool doesFloat() const; 95 bool doesFloat() const;
96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
97 void setFloats(bool f); 97 void setFloats(bool f);
98 98
99 /** 99 /**
100 Add Attendee to this incidence. IncidenceBase takes ownership of the 100 Add Attendee to this incidence. IncidenceBase takes ownership of the
101 Attendee object. 101 Attendee object.
102 */ 102 */
103 bool addAttendee(Attendee *a, bool doupdate=true ); 103 bool addAttendee(Attendee *a, bool doupdate=true );
104// void removeAttendee(Attendee *a); 104// void removeAttendee(Attendee *a);
105// void removeAttendee(const char *n); 105// void removeAttendee(const char *n);
106 /** Remove all Attendees. */ 106 /** Remove all Attendees. */
107 void clearAttendees(); 107 void clearAttendees();
108 /** Return list of attendees. */ 108 /** Return list of attendees. */
109 QPtrList<Attendee> attendees() const { return mAttendees; }; 109 QPtrList<Attendee> attendees() const { return mAttendees; };
110 /** Return number of attendees. */ 110 /** Return number of attendees. */
111 int attendeeCount() const { return mAttendees.count(); }; 111 int attendeeCount() const { return mAttendees.count(); };
112 /** Return the Attendee with this email */ 112 /** Return the Attendee with this email */
113 Attendee* attendeeByMail(const QString &); 113 Attendee* attendeeByMail(const QString &);
114 /** Return first Attendee with one of this emails */ 114 /** Return first Attendee with one of this emails */
115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
116 116
117 /** pilot syncronization states */ 117 /** pilot syncronization states */
118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
119 /** Set synchronisation satus. */ 119 /** Set synchronisation satus. */
120 void setSyncStatus(int stat); 120 void setSyncStatus(int stat);
121 /** Return synchronisation status. */ 121 /** Return synchronisation status. */
122 int syncStatus() const; 122 int syncStatus() const;
123 123
124 /** Set Pilot Id. */ 124 /** Set Pilot Id. */
125 void setPilotId(int id); 125 void setPilotId(int id);
126 /** Return Pilot Id. */ 126 /** Return Pilot Id. */
127 int pilotId() const; 127 int pilotId() const;
128 128
129 void setTempSyncStat(int id); 129 void setTempSyncStat(int id);
130 int tempSyncStat() const; 130 int tempSyncStat() const;
131 void setIDStr( const QString & ); 131 void setIDStr( const QString & );
132 QString IDStr() const; 132 QString IDStr() const;
133 void setID( const QString &, const QString & ); 133 void setID( const QString &, const QString & );
134 QString getID( const QString & ); 134 QString getID( const QString & );
135 void setCsum( const QString &, const QString & ); 135 void setCsum( const QString &, const QString & );
136 QString getCsum( const QString & ); 136 QString getCsum( const QString & );
137 void removeID(const QString &); 137 void removeID(const QString &);
138 138
139 void registerObserver( Observer * ); 139 void registerObserver( Observer * );
140 void unRegisterObserver( Observer * ); 140 void unRegisterObserver( Observer * );
141 void updated(); 141 void updated();
142 142
143 protected: 143 protected:
144 QDateTime mDtStart;
144 bool mReadOnly; 145 bool mReadOnly;
145 QDateTime getEvenTime( QDateTime ); 146 QDateTime getEvenTime( QDateTime );
146 147
147 private: 148 private:
148 // base components 149 // base components
149 QDateTime mDtStart;
150 QString mOrganizer; 150 QString mOrganizer;
151 QString mUid; 151 QString mUid;
152 QDateTime mLastModified; 152 QDateTime mLastModified;
153 QPtrList<Attendee> mAttendees; 153 QPtrList<Attendee> mAttendees;
154 154
155 bool mFloats; 155 bool mFloats;
156 156
157 int mDuration; 157 int mDuration;
158 bool mHasDuration; 158 bool mHasDuration;
159 QString mExternalId; 159 QString mExternalId;
160 int mTempSyncStat; 160 int mTempSyncStat;
161 161
162 // PILOT SYNCHRONIZATION STUFF 162 // PILOT SYNCHRONIZATION STUFF
163 int mPilotId; // unique id for pilot sync 163 int mPilotId; // unique id for pilot sync
164 int mSyncStatus; // status (for sync) 164 int mSyncStatus; // status (for sync)
165 165
166 QPtrList<Observer> mObservers; 166 QPtrList<Observer> mObservers;
167}; 167};
168 168
169bool operator==( const IncidenceBase&, const IncidenceBase& ); 169bool operator==( const IncidenceBase&, const IncidenceBase& );
170} 170}
171 171
172#endif 172#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 9c04a7e..1f54c2f 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -186,229 +186,272 @@ QString Todo::dtDueTimeStr() const
186 186
187QString Todo::dtDueDateStr(bool shortfmt) const 187QString Todo::dtDueDateStr(bool shortfmt) const
188{ 188{
189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
190} 190}
191 191
192QString Todo::dtDueStr(bool shortfmt) const 192QString Todo::dtDueStr(bool shortfmt) const
193{ 193{
194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
195} 195}
196// retval 0 : no found 196// retval 0 : no found
197// 1 : due for date found 197// 1 : due for date found
198// 2 : overdue for date found 198// 2 : overdue for date found
199int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 199int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
200{ 200{
201 int retval = 0; 201 int retval = 0;
202 if ( isCompleted() ) 202 if ( isCompleted() )
203 return 0; 203 return 0;
204 if ( hasDueDate() ) { 204 if ( hasDueDate() ) {
205 if ( dtDue().date() < date ) 205 if ( dtDue().date() < date )
206 return 2; 206 return 2;
207 // we do not return, because we may find an overdue sub todo 207 // we do not return, because we may find an overdue sub todo
208 if ( dtDue().date() == date ) 208 if ( dtDue().date() == date )
209 retval = 1; 209 retval = 1;
210 } 210 }
211 if ( checkSubtodos ) { 211 if ( checkSubtodos ) {
212 Incidence *aTodo; 212 Incidence *aTodo;
213 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 213 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
214 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 214 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
215 if ( ret == 2 ) 215 if ( ret == 2 )
216 return 2; 216 return 2;
217 if ( ret == 1) 217 if ( ret == 1)
218 retval = 1; 218 retval = 1;
219 } 219 }
220 } 220 }
221 return retval; 221 return retval;
222} 222}
223int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 223int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
224{ 224{
225 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 225 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
226} 226}
227bool Todo::hasDueDate() const 227bool Todo::hasDueDate() const
228{ 228{
229 return mHasDueDate; 229 return mHasDueDate;
230} 230}
231 231
232void Todo::setHasDueDate(bool f) 232void Todo::setHasDueDate(bool f)
233{ 233{
234 if (mReadOnly) return; 234 if (mReadOnly) return;
235 mHasDueDate = f; 235 mHasDueDate = f;
236 updated(); 236 updated();
237} 237}
238 238
239 239
240#if 0 240#if 0
241void Todo::setStatus(const QString &statStr) 241void Todo::setStatus(const QString &statStr)
242{ 242{
243 if (mReadOnly) return; 243 if (mReadOnly) return;
244 QString ss(statStr.upper()); 244 QString ss(statStr.upper());
245 245
246 if (ss == "X-ACTION") 246 if (ss == "X-ACTION")
247 mStatus = NEEDS_ACTION; 247 mStatus = NEEDS_ACTION;
248 else if (ss == "NEEDS ACTION") 248 else if (ss == "NEEDS ACTION")
249 mStatus = NEEDS_ACTION; 249 mStatus = NEEDS_ACTION;
250 else if (ss == "ACCEPTED") 250 else if (ss == "ACCEPTED")
251 mStatus = ACCEPTED; 251 mStatus = ACCEPTED;
252 else if (ss == "SENT") 252 else if (ss == "SENT")
253 mStatus = SENT; 253 mStatus = SENT;
254 else if (ss == "TENTATIVE") 254 else if (ss == "TENTATIVE")
255 mStatus = TENTATIVE; 255 mStatus = TENTATIVE;
256 else if (ss == "CONFIRMED") 256 else if (ss == "CONFIRMED")
257 mStatus = CONFIRMED; 257 mStatus = CONFIRMED;
258 else if (ss == "DECLINED") 258 else if (ss == "DECLINED")
259 mStatus = DECLINED; 259 mStatus = DECLINED;
260 else if (ss == "COMPLETED") 260 else if (ss == "COMPLETED")
261 mStatus = COMPLETED; 261 mStatus = COMPLETED;
262 else if (ss == "DELEGATED") 262 else if (ss == "DELEGATED")
263 mStatus = DELEGATED; 263 mStatus = DELEGATED;
264 264
265 updated(); 265 updated();
266} 266}
267 267
268void Todo::setStatus(int status) 268void Todo::setStatus(int status)
269{ 269{
270 if (mReadOnly) return; 270 if (mReadOnly) return;
271 mStatus = status; 271 mStatus = status;
272 updated(); 272 updated();
273} 273}
274 274
275int Todo::status() const 275int Todo::status() const
276{ 276{
277 return mStatus; 277 return mStatus;
278} 278}
279 279
280QString Todo::statusStr() const 280QString Todo::statusStr() const
281{ 281{
282 switch(mStatus) { 282 switch(mStatus) {
283 case NEEDS_ACTION: 283 case NEEDS_ACTION:
284 return QString("NEEDS ACTION"); 284 return QString("NEEDS ACTION");
285 break; 285 break;
286 case ACCEPTED: 286 case ACCEPTED:
287 return QString("ACCEPTED"); 287 return QString("ACCEPTED");
288 break; 288 break;
289 case SENT: 289 case SENT:
290 return QString("SENT"); 290 return QString("SENT");
291 break; 291 break;
292 case TENTATIVE: 292 case TENTATIVE:
293 return QString("TENTATIVE"); 293 return QString("TENTATIVE");
294 break; 294 break;
295 case CONFIRMED: 295 case CONFIRMED:
296 return QString("CONFIRMED"); 296 return QString("CONFIRMED");
297 break; 297 break;
298 case DECLINED: 298 case DECLINED:
299 return QString("DECLINED"); 299 return QString("DECLINED");
300 break; 300 break;
301 case COMPLETED: 301 case COMPLETED:
302 return QString("COMPLETED"); 302 return QString("COMPLETED");
303 break; 303 break;
304 case DELEGATED: 304 case DELEGATED:
305 return QString("DELEGATED"); 305 return QString("DELEGATED");
306 break; 306 break;
307 } 307 }
308 return QString(""); 308 return QString("");
309} 309}
310#endif 310#endif
311 311
312bool Todo::isCompleted() const 312bool Todo::isCompleted() const
313{ 313{
314 if (mPercentComplete == 100) return true; 314 if (mPercentComplete == 100) {
315 else return false; 315 return true;
316 }
317 else return false;
316} 318}
317 319
318void Todo::setCompleted(bool completed) 320void Todo::setCompleted(bool completed)
319{ 321{
322 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
323 if ( !setRecurDates() )
324 completed = false;
325 }
320 if (completed) mPercentComplete = 100; 326 if (completed) mPercentComplete = 100;
321 else { 327 else {
322 mPercentComplete = 0; 328 mPercentComplete = 0;
323 mHasCompletedDate = false; 329 mHasCompletedDate = false;
324 } 330 }
325 updated(); 331 updated();
326} 332}
327 333
328QDateTime Todo::completed() const 334QDateTime Todo::completed() const
329{ 335{
330 return mCompleted; 336 return mCompleted;
331} 337}
332 338
333QString Todo::completedStr( bool shortF ) const 339QString Todo::completedStr( bool shortF ) const
334{ 340{
335 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 341 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
336} 342}
337 343
338void Todo::setCompleted(const QDateTime &completed) 344void Todo::setCompleted(const QDateTime &completed)
339{ 345{
340 //qDebug("Todo::setCompleted "); 346 //qDebug("Todo::setCompleted ");
341 if ( mHasCompletedDate ) { 347 if ( mHasCompletedDate ) {
342 // qDebug("has completed data - return "); 348 // qDebug("has completed data - return ");
343 return; 349 return;
344 } 350 }
345 mHasCompletedDate = true; 351 mHasCompletedDate = true;
346 mPercentComplete = 100; 352 mPercentComplete = 100;
347 mCompleted = getEvenTime(completed); 353 mCompleted = getEvenTime(completed);
348 updated(); 354 updated();
349} 355}
350 356
351bool Todo::hasCompletedDate() const 357bool Todo::hasCompletedDate() const
352{ 358{
353 return mHasCompletedDate; 359 return mHasCompletedDate;
354} 360}
355 361
356int Todo::percentComplete() const 362int Todo::percentComplete() const
357{ 363{
358 return mPercentComplete; 364 return mPercentComplete;
359} 365}
360 366bool Todo::setRecurDates()
361void Todo::setPercentComplete(int v)
362{ 367{
368 if ( !mHasRecurrenceID )
369 return true;
370 int secs = mDtStart.secsTo( dtDue() );
371 bool ok;
372 qDebug("--------------------setRecurDates() ");
373 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
374 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
375 if ( ok ) {
376 mRecurrenceID = next;
377 mDtStart = next;
378 setDtDue( next.addSecs( secs ) );
379 if ( QDateTime::currentDateTime() > next)
380 return false;
381 } else {
382 setHasRecurrenceID( false );
383 recurrence()->unsetRecurs();
384 }
385 return true;
386}
387void Todo::setPercentComplete(int v)
388{
389 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
390 if ( !setRecurDates() )
391 v = 0;
392 }
363 mPercentComplete = v; 393 mPercentComplete = v;
364 if ( v != 100 ) 394 if ( v != 100 )
365 mHasCompletedDate = false; 395 mHasCompletedDate = false;
366 updated(); 396 updated();
367} 397}
368QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 398QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
369{ 399{
370 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 400 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
371 *ok = false; 401 *ok = false;
372 return QDateTime (); 402 return QDateTime ();
373 } 403 }
374 QDateTime incidenceStart; 404 QDateTime incidenceStart;
375 incidenceStart = dtDue(); 405 incidenceStart = dtDue();
376 bool enabled = false; 406 bool enabled = false;
377 Alarm* alarm; 407 Alarm* alarm;
378 int off = 0; 408 int off = 0;
379 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 409 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
380 // if ( QDateTime::currentDateTime() > incidenceStart ){ 410 // if ( QDateTime::currentDateTime() > incidenceStart ){
381// *ok = false; 411// *ok = false;
382// return incidenceStart; 412// return incidenceStart;
383// } 413// }
384 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 414 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
385 if (alarm->enabled()) { 415 if (alarm->enabled()) {
386 if ( alarm->hasTime () ) { 416 if ( alarm->hasTime () ) {
387 if ( alarm->time() < alarmStart ) { 417 if ( alarm->time() < alarmStart ) {
388 alarmStart = alarm->time(); 418 alarmStart = alarm->time();
389 enabled = true; 419 enabled = true;
390 off = alarmStart.secsTo( incidenceStart ); 420 off = alarmStart.secsTo( incidenceStart );
391 } 421 }
392 422
393 } else { 423 } else {
394 int secs = alarm->startOffset().asSeconds(); 424 int secs = alarm->startOffset().asSeconds();
395 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 425 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
396 alarmStart = incidenceStart.addSecs( secs ); 426 alarmStart = incidenceStart.addSecs( secs );
397 enabled = true; 427 enabled = true;
398 off = -secs; 428 off = -secs;
399 } 429 }
400 } 430 }
401 } 431 }
402 } 432 }
403 if ( enabled ) { 433 if ( enabled ) {
404 if ( alarmStart > QDateTime::currentDateTime() ) { 434 if ( alarmStart > QDateTime::currentDateTime() ) {
405 *ok = true; 435 *ok = true;
406 * offset = off; 436 * offset = off;
407 return alarmStart; 437 return alarmStart;
408 } 438 }
409 } 439 }
410 *ok = false; 440 *ok = false;
411 return QDateTime (); 441 return QDateTime ();
412 442
413} 443}
414 444
445void Todo::checkSetCompletedFalse()
446{
447 if ( !hasRecurrenceID() ) {
448 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
449 }
450 // qDebug("Todo::checkSetCompletedFalse()");
451 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
452 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) {
453 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
454 setCompleted( false );
455 qDebug("Todo::checkSetCompletedFalse++++++++++++++++++++++++++++ ");
456 }
457}
diff --git a/libkcal/todo.h b/libkcal/todo.h
index 137b252..a22d4b7 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -1,134 +1,136 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef TODO_H 20#ifndef TODO_H
21#define TODO_H 21#define TODO_H
22// 22//
23// Todo component, representing a VTODO object 23// Todo component, representing a VTODO object
24// 24//
25 25
26#include "incidence.h" 26#include "incidence.h"
27 27
28namespace KCal { 28namespace KCal {
29 29
30/** 30/**
31 This class provides a Todo in the sense of RFC2445. 31 This class provides a Todo in the sense of RFC2445.
32*/ 32*/
33class Todo : public Incidence 33class Todo : public Incidence
34{ 34{
35 public: 35 public:
36 Todo(); 36 Todo();
37 Todo(const Todo &); 37 Todo(const Todo &);
38 ~Todo(); 38 ~Todo();
39 typedef ListBase<Todo> List; 39 typedef ListBase<Todo> List;
40 QCString type() const { return "Todo"; } 40 QCString type() const { return "Todo"; }
41 41
42 /** Return an exact copy of this todo. */ 42 /** Return an exact copy of this todo. */
43 Incidence *clone(); 43 Incidence *clone();
44 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; 44 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const;
45 45
46 /** for setting the todo's due date/time with a QDateTime. */ 46 /** for setting the todo's due date/time with a QDateTime. */
47 void setDtDue(const QDateTime &dtDue); 47 void setDtDue(const QDateTime &dtDue);
48 /** returns an event's Due date/time as a QDateTime. */ 48 /** returns an event's Due date/time as a QDateTime. */
49 QDateTime dtDue() const; 49 QDateTime dtDue() const;
50 /** returns an event's due time as a string formatted according to the 50 /** returns an event's due time as a string formatted according to the
51 users locale settings */ 51 users locale settings */
52 QString dtDueTimeStr() const; 52 QString dtDueTimeStr() const;
53 /** returns an event's due date as a string formatted according to the 53 /** returns an event's due date as a string formatted according to the
54 users locale settings */ 54 users locale settings */
55 QString dtDueDateStr(bool shortfmt=true) const; 55 QString dtDueDateStr(bool shortfmt=true) const;
56 /** returns an event's due date and time as a string formatted according 56 /** returns an event's due date and time as a string formatted according
57 to the users locale settings */ 57 to the users locale settings */
58 QString dtDueStr(bool shortfmt=true) const; 58 QString dtDueStr(bool shortfmt=true) const;
59 59
60 /** returns TRUE or FALSE depending on whether the todo has a due date */ 60 /** returns TRUE or FALSE depending on whether the todo has a due date */
61 bool hasDueDate() const; 61 bool hasDueDate() const;
62 /** sets the event's hasDueDate value. */ 62 /** sets the event's hasDueDate value. */
63 void setHasDueDate(bool f); 63 void setHasDueDate(bool f);
64 64
65 /* 65 /*
66 Looks for a subtodo (including itself ) which is not complete and is 66 Looks for a subtodo (including itself ) which is not complete and is
67 - overdue, or 67 - overdue, or
68 - due today. 68 - due today.
69 It returns 0 for nothing found, 69 It returns 0 for nothing found,
70 1 for found a todo which is due today and no overdue found 70 1 for found a todo which is due today and no overdue found
71 2 for found a overdue todo 71 2 for found a overdue todo
72 */ 72 */
73 int hasDueSubTodo( bool checkSubtodos = true ); 73 int hasDueSubTodo( bool checkSubtodos = true );
74 /* same as above, but a specific date can be specified*/ 74 /* same as above, but a specific date can be specified*/
75 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); 75 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos );
76 76
77 77
78 /** sets the event's status to the string specified. The string 78 /** sets the event's status to the string specified. The string
79 * must be a recognized value for the status field, i.e. a string 79 * must be a recognized value for the status field, i.e. a string
80 * equivalent of the possible status enumerations previously described. */ 80 * equivalent of the possible status enumerations previously described. */
81// void setStatus(const QString &statStr); 81// void setStatus(const QString &statStr);
82 /** sets the event's status to the value specified. See the enumeration 82 /** sets the event's status to the value specified. See the enumeration
83 * above for possible values. */ 83 * above for possible values. */
84// void setStatus(int); 84// void setStatus(int);
85 /** return the event's status. */ 85 /** return the event's status. */
86// int status() const; 86// int status() const;
87 /** return the event's status in string format. */ 87 /** return the event's status in string format. */
88// QString statusStr() const; 88// QString statusStr() const;
89 89
90 /** return, if this todo is completed */ 90 /** return, if this todo is completed */
91 bool isCompleted() const; 91 bool isCompleted() const;
92 /** set completed state of this todo */ 92 /** set completed state of this todo */
93 void setCompleted(bool); 93 void setCompleted(bool);
94 94
95 /** 95 /**
96 Return how many percent of the task are completed. Returns a value 96 Return how many percent of the task are completed. Returns a value
97 between 0 and 100. 97 between 0 and 100.
98 */ 98 */
99 int percentComplete() const; 99 int percentComplete() const;
100 /** 100 /**
101 Set how many percent of the task are completed. Valid values are in the 101 Set how many percent of the task are completed. Valid values are in the
102 range from 0 to 100. 102 range from 0 to 100.
103 */ 103 */
104 void setPercentComplete(int); 104 void setPercentComplete(int);
105 105
106 /** return date and time when todo was completed */ 106 /** return date and time when todo was completed */
107 QDateTime completed() const; 107 QDateTime completed() const;
108 QString completedStr(bool shortF = true) const; 108 QString completedStr(bool shortF = true) const;
109 /** set date and time of completion */ 109 /** set date and time of completion */
110 void setCompleted(const QDateTime &completed); 110 void setCompleted(const QDateTime &completed);
111 111
112 /** Return true, if todo has a date associated with completion */ 112 /** Return true, if todo has a date associated with completion */
113 bool hasCompletedDate() const; 113 bool hasCompletedDate() const;
114 bool contains ( Todo*); 114 bool contains ( Todo*);
115 void checkSetCompletedFalse();
116 bool setRecurDates();
115 117
116 private: 118 private:
117 bool accept(Visitor &v) { return v.visit(this); } 119 bool accept(Visitor &v) { return v.visit(this); }
118 120
119 QDateTime mDtDue; // due date of todo 121 QDateTime mDtDue; // due date of todo
120 122
121 bool mHasDueDate; // if todo has associated due date 123 bool mHasDueDate; // if todo has associated due date
122 124
123// int mStatus; // confirmed/delegated/tentative/etc 125// int mStatus; // confirmed/delegated/tentative/etc
124 126
125 QDateTime mCompleted; 127 QDateTime mCompleted;
126 bool mHasCompletedDate; 128 bool mHasCompletedDate;
127 129
128 int mPercentComplete; 130 int mPercentComplete;
129}; 131};
130 132
131 bool operator==( const Todo&, const Todo& ); 133 bool operator==( const Todo&, const Todo& );
132} 134}
133 135
134#endif 136#endif